KEYS updated, signed copy.
[realism.git] / main_game / basic_tiles.py
blob2c725c72f5497f3c757419f7478455ff3643dc14
1 # This file is part of Realism, which is Copyright FunnyMan3595 (Charlie Nolan)
2 # and licensed under the GNU GPL v3. For more details, see LICENSE in the main
3 # Realism directory.
5 # WARNING: All mod formats are under heavy development. They may change at any
6 # time, breaking old mods. For this reason, we DO NOT RECOMMEND making mods
7 # at this time.
9 # This file defines the basic map tiles used in the game. These tiles cannot
10 # be used directly in a map, but they are used by the standard map tiles. For
11 # instance, a standard "safe" tile is the combination of the "no_encounters"
12 # and "regen" basic tiles.
14 # This file has the same format as <module>/basic_tiles.py.
15 # For a complete guide to modding, see MODDING, in the Realism main directory.
17 # Like all the .py files, this is Python code. Most mod makers should be able
18 # to understand and adapt it, but knowledge of Python will help, and may allow
19 # you to do neat tricks.
21 '''Basic tiles are the fundamental pieces that you put together to create normal tiles. Each one handles one specific function, like random encounters or the regen when you take a step.'''
23 from engine.tile import *
24 from engine.shop import make_shop
26 class TileException(Exception):
27 pass
29 class empty(tile):
30 '''The base tile for all ordinary empty squares.'''
31 type = "empty"
33 class no_op(empty):
34 '''Dummy basic tile for anything that has no effect.'''
35 no_regen = no_encounters = no_op
37 class regen(empty):
38 '''Every time the player steps on this tile, each party member gets healed slightly.'''
39 def go_to(self, teleported = False):
40 went = super(regen, self).go_to(teleported)
41 if went:
42 self.hp_mp_ticks()
43 return went
45 class random_encounters(empty):
46 '''Every time the player steps on this tile, there is a chance he may be sent into a random encounter.'''
47 def go_to(self, teleported = False):
48 went = super(random_encounters, self).go_to(teleported)
49 if went:
50 self.maybe_fight()
51 return went
53 class door(empty):
54 '''A door. Walking into a door that's closed but unlocked will open it, but it takes a second attempt to move to this tile.'''
55 save = ("open","locked")
56 type = "door"
57 locked = False
58 open = False
59 def __init__(self, map_pos, *args):
60 super(door, self).__init__(map_pos)
61 def go_to(self, teleported = False):
62 if not self.open:
63 if not self.locked:
64 self.open = True
65 self.type = "door_open"
66 return False
67 return super(door, self).go_to(teleported)
69 class locked_door(door):
70 '''A door that starts locked.'''
71 locked = True
73 class warp_tile(empty):
74 '''A tile that attempts to warp the player to a new location on the map.'''
75 def __init__(self, map_pos, target_row, target_col, *args):
76 # Pass the buck.
77 super(warp_tile, self).__init__(map_pos)
79 # If we got ('s', 's'), the start square of the map, we preserve it.
80 # Otherwise, we process row and col into integers.
81 if target_row == target_col == 's':
82 row = col = 's'
83 else:
84 row = self.argument("target row", target_row, int)
85 col = self.argument("target col", target_col, int)
87 # Save the target position.
88 self.target_pos = (row, col)
90 class map_tile(warp_tile):
91 '''A tile that attempts to warp the player to a new map. If no location is specified, the player is warped to the map's start location. Usually, only teleporters will want to omit the location.'''
92 def __init__(self, map_pos, target_map, target_row = None, target_col = None, *args):
93 # If we got both row and col, we just pass those into warp_tile.
94 # If we got neither, we use ('s', 's'), the start square of the map.
95 if target_row != None and target_col == None:
96 raise MapException("target row without target col in tile map_tile on map", map_pos[0].name)
97 elif target_row == None:
98 (target_row, target_col) = ('s', 's')
100 # Pass the buck.
101 warp_tile.__init__(self, map_pos, target_row, target_col)
103 # Find and store the target map.
104 self.target_map = self.argument("target map", target_map, a_map)
106 class tutorial(empty):
107 '''The first time the player steps on a tutorial tile, they are given a tutorial, which must be defined as tutorial(self) on the final tile.'''
108 save = ("seen",)
109 seen = False
110 def __init__(self, map_pos, main_game = False, *args):
111 super(tutorial, self).__init__(map_pos)
112 self.main_game = self.argument("main game", main_game, bool)
114 def tutorial(self):
115 # TODO: Consider changing to raise.
116 print TileException("No tutorial defined for %s." % self.__class__.__name__)
118 def go_to(self, teleported = False):
119 went = super(tutorial, self).go_to(teleported)
120 if went and not self.seen:
121 self.tutorial()
122 self.seen = True
123 return went
125 class shop(tile):
126 '''Walking into a shop tile causes the player to enter a shop, regardless of whether he moves onto the tile.'''
127 type = "shop"
128 save = ("shop",)
129 level = 1
130 shop_args = {}
132 def __init__(self, map_pos, level=None, *args):
133 super(shop, self).__init__(map_pos, *args)
135 if level != None:
136 self.level = self.argument("shop level", level, int)
138 self.shop = make_shop(self.level, **self.shop_args)
140 def go_to(self, teleported = False):
141 game.ui.shop_mode(self.shop)
142 return super(shop, self).go_to(teleported)
144 class climb_tile(tile):
145 '''A climb tile is simply a tile with some element of height to it. A level 1 climb tile could be as little as a twig or bit of trash in the way. If the party's climb level is equal to or greater than the climb tile's level, they can pass.'''
146 type = "step"
147 level = 1
148 def __init__(self, map_pos, level = None, *args):
149 super(climb_tile, self).__init__(map_pos, *args)
151 if level != None:
152 self.level = self.argument("climb level", level, int)
154 def go_to(self, teleported = False):
155 if game.party.climb_level >= self.level:
156 return super(climb_tile, self).go_to(teleported)
157 else:
158 return False