1 # This file contains several imports inside functions, to avoid poluting the
2 # namespace, which is imported by tiles.py.
5 def get_map_specials(game_map
):
6 from game_map
import special_keys
7 for key
in special_keys
:
8 yield game_map
.map_key
[key
][0]
10 def default_action(my_tile
):
11 # Do nothing if the player didn't move.
12 if my_tile
.pos
[0] < 1 or not my_tile
.passable():
15 game_map
= my_tile
.game_map
17 # Gain health and mana.
18 game_map
.hp_mp_ticks()
20 # If there's any more "grace period" left after a battle, use some.
21 if game_map
.delay_left
> 0:
22 game_map
.delay_left
-= 1
25 # Otherwise, see if there's a random encounter.
26 from random
import randint
27 from engine
.battle
import simple_battle
28 (chance
, delay
, minlvl
, maxlvl
, mincrits
, maxcrits
, crittypes
, tileset
) = \
29 get_map_specials(game_map
)
31 if randint(1,100) < int(chance
):
33 # Add the grace period.
34 game_map
.delay_left
= int(delay
)
35 # Determine the level and number of monsters.
36 level
= randint(int(minlvl
),int(maxlvl
))
37 crits
= randint(int(mincrits
),int(maxcrits
))
39 simple_battle(level
, crits
)
41 def safe_action(my_tile
):
42 # Do nothing if the player didn't move.
43 if my_tile
.pos
[0] < 1 or not my_tile
.passable():
46 # Just gain health and mana.
47 my_tile
.game_map
.hp_mp_ticks()
49 def shop_action(my_tile
):
51 game
.ui
.map_mode(my_tile
.shop
)
53 def save_action(my_tile
):
57 def no_action(my_tile
):
58 # No action, so we do nothing. How zen of us.
61 def can_climb(my_tile
, climb_difficulty
):
66 def __init__(self
, map_pos
, tile_type
, passable
= True, action
= default_action
, floater
= None, vars = {}, save
= ()):
68 # Internal import to avoid polluting the main namespace, which gets exported
70 from new
import instancemethod
as im
73 (self
.game_map
, self
.pos
) = map_pos
75 # The type of tile. Wall, open, door, etc.
78 # Function called to determine if the player can move to this tile.
79 # None indicates that the player was sent to another map, so we reset this
81 if passable
in (True, False, None):
82 method
= lambda self
: passable
83 elif type(passable
) == int:
84 method
= lambda self
: can_climb(self
, passable
)
87 self
.passable
= im(method
, self
, tile
)
89 # Function called when the player tries to move to this tile.
90 self
.action
= im(action
, self
, tile
)
92 # A creature or object on this tile that may move.
93 self
.floater
= floater
95 # Vars are any miscellaneous variables that are needed for the tile.
96 self
.__dict
__.update(vars)
98 # Save contains the list of variable names that need to be saved.
99 # This list *must not* change.