Mercurial > rinkhals
annotate gamelib/buildings.py @ 459:e9393970b5f6
picture icons for all counters
author | Adrianna Pińska <adrianna.pinska@gmail.com> |
---|---|
date | Mon, 23 Nov 2009 20:12:03 +0000 |
parents | e945c4186ee5 |
children | b74b3a37cf1d |
rev | line source |
---|---|
43 | 1 """Classes for various buildings in the game.""" |
2 | |
3 from pgu.vid import Sprite | |
204 | 4 from pygame.locals import SRCALPHA |
5 import pygame | |
43 | 6 |
7 import imagecache | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
8 import tiles |
204 | 9 import constants |
415
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
10 import serializer |
204 | 11 |
231
857040b211d5
Note why we're disabling a warning.
Simon Cross <hodgestar@gmail.com>
parents:
224
diff
changeset
|
12 # ignore os.popen3 warning generated by pygame.font.SysFont |
204 | 13 import warnings |
14 warnings.filterwarnings("ignore", "os.popen3 is deprecated.") | |
43 | 15 |
439
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
16 class Place(serializer.Simplifiable): |
125 | 17 """Space within a building that can be occupied.""" |
18 | |
439
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
19 SIMPLIFY = [ |
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
20 'occupant', |
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
21 'building', |
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
22 'offset', |
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
23 ] |
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
24 |
125 | 25 def __init__(self, building, offset): |
26 self.occupant = None | |
27 self.building = building | |
28 self.offset = offset | |
29 | |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
30 def set_occupant(self, occupant, _update=True, _predator=False): |
204 | 31 self.clear_occupant(_update=False) |
125 | 32 self.occupant = occupant |
33 self.occupant.abode = self | |
204 | 34 if _update: |
35 self.building.update_occupant_count() | |
125 | 36 |
204 | 37 def clear_occupant(self, _update=True): |
125 | 38 if self.occupant is not None: |
39 self.occupant.abode = None | |
40 self.occupant = None | |
204 | 41 if _update: |
42 self.building.update_occupant_count() | |
125 | 43 |
44 def get_pos(self): | |
45 bpos = self.building.pos | |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
46 return (bpos[0] + self.offset[0], bpos[1] + self.offset[1], |
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
47 self.offset[2]) |
125 | 48 |
439
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
49 class Floor(serializer.Simplifiable): |
125 | 50 """A set of places within a building. Places on a |
51 floor are organised into rows and columns. | |
52 """ | |
53 | |
439
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
54 SIMPLIFY = [ |
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
55 'title', |
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
56 'places', |
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
57 ] |
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
58 |
125 | 59 def __init__(self, title, places): |
60 self.title = title # str | |
61 self.places = places # list of lists of places | |
62 | |
63 def rows(self): | |
64 for row in self.places: | |
65 yield row | |
66 | |
67 def width(self): | |
68 return max(len(row) for row in self.places) | |
69 | |
70 class BuildingFullError(Exception): | |
71 pass | |
72 | |
415
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
73 class Building(Sprite, serializer.Simplifiable): |
43 | 74 """Base class for buildings""" |
75 | |
109
48019afde338
Equipment purchasing and some toolbar tweaks.
Jeremy Thurgood <firxen@gmail.com>
parents:
108
diff
changeset
|
76 IS_BUILDING = True |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
77 GRASSLAND = tiles.REVERSE_TILE_MAP['grassland'] |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
78 MODIFY_KNIFE_RANGE = lambda s, x: 0 |
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
79 MODIFY_GUN_RANGE = lambda s, x: -1 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
80 BREAKABLE = False |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
81 ABODE = False |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
82 FLOORS = None |
414
9096c237928c
Dear most illustrious brother, I seek your cooperation with the refactoring of egg layerings and the reloading of guns. Please to provide bank details.
Jeremy Thurgood <firxen@gmail.com>
parents:
397
diff
changeset
|
83 HENHOUSE = False |
437
95b81e917399
Buildings block line-of-sight, except for occupants.
Jeremy Thurgood <firxen@gmail.com>
parents:
428
diff
changeset
|
84 BLOCKS_VISION = True |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
85 |
415
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
86 SIMPLIFY = [ |
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
87 'pos', |
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
88 'size', |
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
89 'tile_no', |
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
90 '_buy_price', |
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
91 '_sell_price', |
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
92 '_repair_price', |
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
93 '_sun_on', |
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
94 '_broken', |
439
cf4b020e6385
Start of serializer for buildings and support for reference cycles.
Simon Cross <hodgestar@gmail.com>
parents:
437
diff
changeset
|
95 '_floors', |
415
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
96 ] |
8f012ef1f64f
Start of ability to serialize game state.
Simon Cross <hodgestar@gmail.com>
parents:
414
diff
changeset
|
97 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
98 def __init__(self, pos): |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
99 """Initial image, tile vid position, size and tile number for building.""" |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
100 self._set_images() |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
101 self.pos = pos |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
102 self.size = self.SIZE |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
103 self.tile_no = self.TILE_NO |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
104 self._buy_price = self.BUY_PRICE |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
105 self._sell_price = self.SELL_PRICE |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
106 self._repair_price = getattr(self, 'REPAIR_PRICE', None) |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
107 self._sun_on = True |
204 | 108 self._font = pygame.font.SysFont('Vera', 30, bold=True) |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
109 self._font_image = pygame.Surface(self.images['fixed']['day'].get_size(), flags=SRCALPHA) |
204 | 110 self._font_image.fill((0, 0, 0, 0)) |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
111 self._broken = False |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
112 self._predators = [] |
125 | 113 |
114 self._floors = [] | |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
115 if self.FLOORS: |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
116 for f, z in enumerate(self.FLOORS): |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
117 places = [] |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
118 for j in range(self.size[1]): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
119 row = [] |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
120 for i in range(self.size[0]): |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
121 row.append(Place(self, (i, j, z))) |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
122 places.append(row) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
123 floor = Floor("Floor %s" % (f+1,), places) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
124 self._floors.append(floor) |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
125 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
126 # 0: the main image |
204 | 127 # 1: above, -1: below |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
128 self.draw_stack = {"main": (0, self.images['fixed']['day'])} |
204 | 129 |
43 | 130 # Create the building somewhere far off screen |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
131 Sprite.__init__(self, self.images['fixed']['day'], (-1000, -1000)) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
132 |
423
97dd557504a2
Override make methods for simplifiable objects.
Simon Cross <hodgestar@gmail.com>
parents:
415
diff
changeset
|
133 def make(cls): |
97dd557504a2
Override make methods for simplifiable objects.
Simon Cross <hodgestar@gmail.com>
parents:
415
diff
changeset
|
134 """Override default Simplifiable object creation.""" |
97dd557504a2
Override make methods for simplifiable objects.
Simon Cross <hodgestar@gmail.com>
parents:
415
diff
changeset
|
135 return cls((0, 0)) |
97dd557504a2
Override make methods for simplifiable objects.
Simon Cross <hodgestar@gmail.com>
parents:
415
diff
changeset
|
136 make = classmethod(make) |
97dd557504a2
Override make methods for simplifiable objects.
Simon Cross <hodgestar@gmail.com>
parents:
415
diff
changeset
|
137 |
440
e945c4186ee5
Restore buildings properly.
Simon Cross <hodgestar@gmail.com>
parents:
439
diff
changeset
|
138 def unsimplify(cls, *args, **kwargs): |
e945c4186ee5
Restore buildings properly.
Simon Cross <hodgestar@gmail.com>
parents:
439
diff
changeset
|
139 """Override default Simplifiable unsimplification.""" |
e945c4186ee5
Restore buildings properly.
Simon Cross <hodgestar@gmail.com>
parents:
439
diff
changeset
|
140 obj = super(Building, cls).unsimplify(*args, **kwargs) |
e945c4186ee5
Restore buildings properly.
Simon Cross <hodgestar@gmail.com>
parents:
439
diff
changeset
|
141 obj._set_main_image() |
e945c4186ee5
Restore buildings properly.
Simon Cross <hodgestar@gmail.com>
parents:
439
diff
changeset
|
142 obj.update_occupant_count() |
e945c4186ee5
Restore buildings properly.
Simon Cross <hodgestar@gmail.com>
parents:
439
diff
changeset
|
143 return obj |
e945c4186ee5
Restore buildings properly.
Simon Cross <hodgestar@gmail.com>
parents:
439
diff
changeset
|
144 unsimplify = classmethod(unsimplify) |
e945c4186ee5
Restore buildings properly.
Simon Cross <hodgestar@gmail.com>
parents:
439
diff
changeset
|
145 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
146 def _set_images(self): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
147 self.images = {'fixed': { |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
148 'day': imagecache.load_image(self.IMAGE), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
149 'night': imagecache.load_image(self.IMAGE, ('night',)), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
150 'selected': imagecache.load_image(self.SELECTED_IMAGE), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
151 }} |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
152 if self.BREAKABLE: |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
153 self.images['broken'] = { |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
154 'day': imagecache.load_image(self.IMAGE_BROKEN), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
155 'night': imagecache.load_image(self.IMAGE_BROKEN, ('night',)), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
156 'selected': imagecache.load_image(self.SELECTED_IMAGE_BROKEN), |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
157 } |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
158 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
159 def _set_main_image(self): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
160 image_set = self.images[{True: 'broken',False: 'fixed'}[self._broken]] |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
161 self._replace_main(image_set[{True: 'day', False: 'night'}[self._sun_on]]) |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
162 |
204 | 163 def _redraw(self): |
164 items = self.draw_stack.values() | |
165 items.sort(key=lambda x: x[0]) | |
166 image = items.pop(0)[1].copy() | |
167 for _lvl, overlay in items: | |
168 image.blit(overlay, (0, 0)) | |
169 self.setimage(image) | |
170 | |
171 def _replace_main(self, new_main): | |
172 self.draw_stack["main"] = (0, new_main) | |
173 self._redraw() | |
174 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
175 def tile_positions(self): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
176 """Return pairs of (x, y) tile positions for each of the tile positions |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
177 occupied by the building. |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
178 """ |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
179 xpos, ypos = self.pos |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
180 xsize, ysize = self.size |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
181 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
182 for dx in xrange(xsize): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
183 for dy in xrange(ysize): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
184 yield (xpos + dx, ypos + dy) |
43 | 185 |
224
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
186 def adjacent_tiles(self): |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
187 """Return pairs of (x, y) tile positions for each of the tiles |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
188 adjacent to the building. |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
189 """ |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
190 xpos, ypos = self.pos |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
191 xsize, ysize = self.size |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
192 |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
193 for dx in xrange(xsize): # top and bottom |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
194 yield (xpos + dx, ypos - 1) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
195 yield (xpos + dx, ypos + ysize) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
196 |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
197 for dy in xrange(ysize): # left and right |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
198 yield (xpos - 1, ypos + dy) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
199 yield (xpos + xsize, ypos + dy) |
c279ad59b8e2
Chicks fill hen house, then adjacent spaces, then die.
Simon Cross <hodgestar@gmail.com>
parents:
204
diff
changeset
|
200 |
43 | 201 def loop(self, tv, _sprite): |
202 ppos = tv.tile_to_view(self.pos) | |
203 self.rect.x = ppos[0] | |
204 self.rect.y = ppos[1] | |
205 | |
206 def move(self, state): | |
207 """Given the game state, return a new position for the object""" | |
208 # Default is not to move | |
209 return self.pos | |
210 | |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
211 def place(self, tv): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
212 """Check that the building can be placed at its current position |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
213 and place it if possible. |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
214 """ |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
215 # check that all spaces under the structure are grassland |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
216 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
217 if not tv.get(tile_pos) == self.GRASSLAND: |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
218 return False |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
219 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
220 # place tile |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
221 for tile_pos in self.tile_positions(): |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
222 tv.set(tile_pos, self.tile_no) |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
223 |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
224 return True |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
225 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
226 def covers(self, tile_pos): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
227 """Return True if build covers tile_pos, False otherwise.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
228 xpos, ypos = self.pos |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
229 xsize, ysize = self.size |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
230 return (xpos <= tile_pos[0] < xpos + xsize) and \ |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
231 (ypos <= tile_pos[1] < ypos + ysize) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
232 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
233 def broken(self): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
234 return self._broken |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
235 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
236 def damage(self, tv): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
237 if not self.BREAKABLE: |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
238 return False |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
239 self._broken = True |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
240 self._sell_price = self.SELL_PRICE_BROKEN |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
241 self.tile_no = self.TILE_NO_BROKEN |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
242 for tile_pos in self.tile_positions(): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
243 tv.set(tile_pos, self.tile_no) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
244 self._set_main_image() |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
245 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
246 def repair(self, tv): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
247 self._broken = False |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
248 self._sell_price = self.SELL_PRICE |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
249 self.tile_no = self.TILE_NO |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
250 for tile_pos in self.tile_positions(): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
251 tv.set(tile_pos, self.tile_no) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
252 self._set_main_image() |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
253 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
254 def remove(self, tv): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
255 """Remove the building from its current position.""" |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
256 # remove tile |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
257 for tile_pos in self.tile_positions(): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
258 tv.set(tile_pos, self.GRASSLAND) |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
259 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
260 def buy_price(self): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
261 return self._buy_price |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
262 |
65
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
263 def sell_price(self): |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
264 return self._sell_price |
7e9c8ad06d32
Implement building selling.
Simon Cross <hodgestar@gmail.com>
parents:
64
diff
changeset
|
265 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
266 def repair_price(self): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
267 return self._repair_price |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
268 |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
269 def selected(self, selected): |
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
270 if selected: |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
271 self._replace_main(self.images[{True: 'broken',False: 'fixed'}[self._broken]]['selected']) |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
272 else: |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
273 self._set_main_image() |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
274 |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
275 def sun(self, sun_on): |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
276 self._sun_on = sun_on |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
277 self._set_main_image() |
204 | 278 |
279 def update_occupant_count(self): | |
280 count = len(list(self.occupants())) | |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
281 if count == 0 and not self._predators: |
204 | 282 if "count" in self.draw_stack: |
283 del self.draw_stack["count"] | |
284 else: | |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
285 # Render chicken count |
204 | 286 image = self._font_image.copy() |
287 w, h = image.get_size() | |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
288 if count: |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
289 text = self._font.render(str(count), True, |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
290 constants.FG_COLOR) |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
291 # Blit to the right |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
292 x, y = text.get_size() |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
293 image.blit(text, (w - x, h - y)) |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
294 # Render predator count |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
295 if self._predators: |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
296 text = self._font.render(str(len(self._predators)), True, |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
297 constants.PREDATOR_COUNT_COLOR) |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
298 # Blit to the left |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
299 x, y = text.get_size() |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
300 image.blit(text, (0, h - y)) |
204 | 301 self.draw_stack["count"] = (1, image) |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
302 |
204 | 303 self._redraw() |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
304 |
125 | 305 def floors(self): |
306 return self._floors | |
307 | |
308 def places(self): | |
309 for floor in self._floors: | |
310 for row in floor.rows(): | |
311 for place in row: | |
312 yield place | |
313 | |
314 def max_floor_width(self): | |
315 return max(floor.width() for floor in self._floors) | |
316 | |
317 def first_empty_place(self): | |
318 for place in self.places(): | |
319 if place.occupant is None: | |
320 return place | |
321 raise BuildingFullError() | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
322 |
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
323 def add_occupant(self, occupant): |
125 | 324 place = self.first_empty_place() |
325 place.set_occupant(occupant) | |
108
437cbd856a03
Add occupants and abodes. Allowing moving chickens around.
Simon Cross <hodgestar@gmail.com>
parents:
65
diff
changeset
|
326 |
125 | 327 def occupants(self): |
328 for place in self.places(): | |
329 if place.occupant is not None: | |
330 yield place.occupant | |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
331 |
397
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
332 def add_predator(self, animal): |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
333 animal.building = self |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
334 self._predators.append(animal) |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
335 self.update_occupant_count() |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
336 |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
337 def remove_predator(self, animal): |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
338 if animal in self._predators: |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
339 self._predators.remove(animal) |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
340 animal.building = None |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
341 self.update_occupant_count() |
532f1ea476ff
Make foxes enter buildings, with a seperate count for them
Neil Muller <drnlmuller@gmail.com>
parents:
395
diff
changeset
|
342 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
343 class Abode(Building): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
344 ABODE = True |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
345 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
346 class HenHouse(Abode): |
43 | 347 """A HenHouse.""" |
348 | |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
349 TILE_NO = tiles.REVERSE_TILE_MAP['henhouse'] |
428
a356e57529ea
buildings cost wood
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
423
diff
changeset
|
350 BUY_PRICE = 20 |
a356e57529ea
buildings cost wood
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
423
diff
changeset
|
351 SELL_PRICE = 18 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
352 SIZE = (3, 2) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
353 IMAGE = 'sprites/henhouse.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
354 SELECTED_IMAGE = 'sprites/select_henhouse.png' |
177
b400991ccce1
pedantic building renaming
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
170
diff
changeset
|
355 NAME = 'Henhouse' |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
356 FLOORS = [0] |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
357 |
414
9096c237928c
Dear most illustrious brother, I seek your cooperation with the refactoring of egg layerings and the reloading of guns. Please to provide bank details.
Jeremy Thurgood <firxen@gmail.com>
parents:
397
diff
changeset
|
358 HENHOUSE = True |
9096c237928c
Dear most illustrious brother, I seek your cooperation with the refactoring of egg layerings and the reloading of guns. Please to provide bank details.
Jeremy Thurgood <firxen@gmail.com>
parents:
397
diff
changeset
|
359 |
125 | 360 class DoubleStoryHenHouse(HenHouse): |
361 """A double story hen house.""" | |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
362 |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
363 TILE_NO = tiles.REVERSE_TILE_MAP['hendominium'] |
428
a356e57529ea
buildings cost wood
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
423
diff
changeset
|
364 BUY_PRICE = 60 |
a356e57529ea
buildings cost wood
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
423
diff
changeset
|
365 SELL_PRICE = 30 |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
366 SIZE = (2, 3) |
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
125
diff
changeset
|
367 IMAGE = 'sprites/hendominium.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
368 SELECTED_IMAGE = 'sprites/select_hendominium.png' |
125 | 369 NAME = 'Hendominium' |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
370 FLOORS = [0, 1] |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
371 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
372 class GuardTower(Abode): |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
373 """A GuardTower.""" |
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
374 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
375 TILE_NO = tiles.REVERSE_TILE_MAP['guardtower'] |
428
a356e57529ea
buildings cost wood
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
423
diff
changeset
|
376 BUY_PRICE = 40 |
a356e57529ea
buildings cost wood
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
423
diff
changeset
|
377 SELL_PRICE = 30 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
378 SIZE = (2, 2) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
379 IMAGE = 'sprites/watchtower.png' |
170
92d11e0544bc
Switch building to selected image when building is selected.
Simon Cross <hodgestar@gmail.com>
parents:
144
diff
changeset
|
380 SELECTED_IMAGE = 'sprites/select_watchtower.png' |
177
b400991ccce1
pedantic building renaming
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
170
diff
changeset
|
381 NAME = 'Watchtower' |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
378
diff
changeset
|
382 FLOORS = [2] |
57
08665fa60345
Implement henhouses and henhouse adding.
Simon Cross <hodgestar@gmail.com>
parents:
43
diff
changeset
|
383 |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
384 MODIFY_GUN_RANGE = lambda s, x: (3*x)/2 |
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
385 MODIFY_GUN_BASE_HIT = lambda s, x: x-5 |
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
386 MODIFY_GUN_RANGE_PENALTY = lambda s, x: x-1 |
199
696936621a93
Buildings can affect visual acuity.
Jeremy Thurgood <firxen@gmail.com>
parents:
198
diff
changeset
|
387 MODIFY_VISION_BONUS = lambda s, x: x+10 |
696936621a93
Buildings can affect visual acuity.
Jeremy Thurgood <firxen@gmail.com>
parents:
198
diff
changeset
|
388 MODIFY_VISION_RANGE_PENALTY = lambda s, x: x-2 |
437
95b81e917399
Buildings block line-of-sight, except for occupants.
Jeremy Thurgood <firxen@gmail.com>
parents:
428
diff
changeset
|
389 BLOCKS_VISION = False |
198
355eaae40b1f
Buildings now affect weapon range and accuracy.
Jeremy Thurgood <firxen@gmail.com>
parents:
177
diff
changeset
|
390 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
391 class Fence(Building): |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
392 """A fence.""" |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
393 |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
394 TILE_NO = tiles.REVERSE_TILE_MAP['fence'] |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
395 TILE_NO_BROKEN = tiles.REVERSE_TILE_MAP['broken fence'] |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
396 BREAKABLE = True |
428
a356e57529ea
buildings cost wood
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
423
diff
changeset
|
397 BUY_PRICE = 10 |
a356e57529ea
buildings cost wood
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
423
diff
changeset
|
398 SELL_PRICE = 5 |
a356e57529ea
buildings cost wood
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
423
diff
changeset
|
399 REPAIR_PRICE = 5 |
a356e57529ea
buildings cost wood
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
423
diff
changeset
|
400 SELL_PRICE_BROKEN = 1 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
401 SIZE = (1, 1) |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
402 IMAGE = 'tiles/fence.png' |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
403 SELECTED_IMAGE = 'tiles/fence.png' |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
404 IMAGE_BROKEN = 'tiles/broken_fence.png' |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
405 SELECTED_IMAGE_BROKEN = 'tiles/broken_fence.png' |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
406 NAME = 'Fence' |
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
407 |
437
95b81e917399
Buildings block line-of-sight, except for occupants.
Jeremy Thurgood <firxen@gmail.com>
parents:
428
diff
changeset
|
408 BLOCKS_VISION = False |
95b81e917399
Buildings block line-of-sight, except for occupants.
Jeremy Thurgood <firxen@gmail.com>
parents:
428
diff
changeset
|
409 |
378
71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
Jeremy Thurgood <firxen@gmail.com>
parents:
268
diff
changeset
|
410 |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
411 def is_building(obj): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
412 """Return true if obj is a build class.""" |
109
48019afde338
Equipment purchasing and some toolbar tweaks.
Jeremy Thurgood <firxen@gmail.com>
parents:
108
diff
changeset
|
413 return getattr(obj, "IS_BUILDING", False) and hasattr(obj, "NAME") |
64
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
414 |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
415 BUILDINGS = [] |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
416 for name in dir(): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
417 obj = eval(name) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
418 try: |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
419 if is_building(obj): |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
420 BUILDINGS.append(obj) |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
421 except TypeError: |
99fbb652ce8d
Refactor buildings so that new ones can be added just by adding a class to buildings.py.
Simon Cross <hodgestar@gmail.com>
parents:
63
diff
changeset
|
422 pass |