Mercurial > rinkhals
comparison gamelib/gameboard.py @ 378:71f5897ac5ef
Fences are now buildings, with appropriate (but ugly) UI changes.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 24 Oct 2009 19:08:54 +0000 |
parents | d2acf43aba6f |
children | a8a7ada27fa2 |
comparison
equal
deleted
inserted
replaced
377:0dc9d17c689e | 378:71f5897ac5ef |
---|---|
75 self.add_counter(mklabel("Day:"), self.day_counter) | 75 self.add_counter(mklabel("Day:"), self.day_counter) |
76 self.add_counter(mklabel("Groats:"), self.cash_counter) | 76 self.add_counter(mklabel("Groats:"), self.cash_counter) |
77 self.add_counter(mklabel("Eggs:"), self.egg_counter) | 77 self.add_counter(mklabel("Eggs:"), self.egg_counter) |
78 self.add_counter(icons.CHKN_ICON, self.chicken_counter) | 78 self.add_counter(icons.CHKN_ICON, self.chicken_counter) |
79 self.add_counter(icons.KILLED_FOX, self.killed_foxes) | 79 self.add_counter(icons.KILLED_FOX, self.killed_foxes) |
80 self.add_spacer(15) | 80 self.add_spacer(5) |
81 | 81 |
82 self.add_tool_button("Move Hen", constants.TOOL_PLACE_ANIMALS, | 82 self.add_tool_button("Move Hen", constants.TOOL_PLACE_ANIMALS, |
83 None, cursors.cursors['select']) | 83 None, cursors.cursors['select']) |
84 self.add_tool_button("Cut Trees", constants.TOOL_LOGGING, | 84 self.add_tool_button("Cut Trees", constants.TOOL_LOGGING, |
85 constants.LOGGING_PRICE, cursors.cursors['ball']) | 85 constants.LOGGING_PRICE, cursors.cursors['ball']) |
86 self.add_spacer(15) | 86 self.add_spacer(5) |
87 | 87 |
88 self.add_heading("Sell ...") | 88 self.add_heading("Sell ...") |
89 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN, | 89 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN, |
90 constants.SELL_PRICE_CHICKEN, cursors.cursors['sell']) | 90 constants.SELL_PRICE_CHICKEN, cursors.cursors['sell']) |
91 self.add_tool_button("Egg", constants.TOOL_SELL_EGG, | 91 self.add_tool_button("Egg", constants.TOOL_SELL_EGG, |
92 constants.SELL_PRICE_EGG, cursors.cursors['sell']) | 92 constants.SELL_PRICE_EGG, cursors.cursors['sell']) |
93 self.add_tool_button("Building", constants.TOOL_SELL_BUILDING, | 93 self.add_tool_button("Building", constants.TOOL_SELL_BUILDING, |
94 None, cursors.cursors['sell']) | 94 None, cursors.cursors['sell']) |
95 self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT, | 95 self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT, |
96 None, cursors.cursors['sell']) | 96 None, cursors.cursors['sell']) |
97 self.add_spacer(15) | 97 self.add_spacer(5) |
98 | 98 |
99 self.add_heading("Buy ...") | 99 self.add_heading("Buy ...") |
100 | |
101 self.add_tool_button("Fence", constants.TOOL_BUY_FENCE, | |
102 "%s/%s" % (constants.BUY_PRICE_FENCE, | |
103 constants.REPAIR_PRICE_FENCE)) | |
104 | 100 |
105 for building_cls in buildings.BUILDINGS: | 101 for building_cls in buildings.BUILDINGS: |
106 self.add_tool_button(building_cls.NAME.title(), building_cls, | 102 self.add_tool_button(building_cls.NAME.title(), building_cls, |
107 None, cursors.cursors.get('build', None)) | 103 None, cursors.cursors.get('build', None)) |
108 | 104 |
110 self.add_tool_button(equipment_cls.NAME.title(), | 106 self.add_tool_button(equipment_cls.NAME.title(), |
111 equipment_cls, | 107 equipment_cls, |
112 equipment_cls.BUY_PRICE, | 108 equipment_cls.BUY_PRICE, |
113 cursors.cursors.get('buy', None)) | 109 cursors.cursors.get('buy', None)) |
114 | 110 |
111 self.add_spacer(5) | |
112 self.add_tool_button("Repair", constants.TOOL_REPAIR_BUILDING, None, cursors.cursors['repair']) | |
113 | |
114 self.add_spacer(5) | |
115 self.add_tool("Price Reference", self.show_prices) | |
115 self.add_spacer(10) | 116 self.add_spacer(10) |
116 self.add_tool("Price Reference", self.show_prices) | |
117 self.add_spacer(20) | |
118 | 117 |
119 self.fin_tool = self.add_tool("Finished Day", self.day_done) | 118 self.fin_tool = self.add_tool("Finished Day", self.day_done) |
120 | 119 |
121 self.anim_clear_tool = False # Flag to clear the tool on an anim loop | 120 self.anim_clear_tool = False # Flag to clear the tool on an anim loop |
122 # pgu's tool widget fiddling happens after the tool action, so calling | 121 # pgu's tool widget fiddling happens after the tool action, so calling |
161 if hasattr(thing, 'style'): | 160 if hasattr(thing, 'style'): |
162 thing.style.width = max_width + 10 | 161 thing.style.width = max_width + 10 |
163 | 162 |
164 tbl = gui.Table() | 163 tbl = gui.Table() |
165 tbl.tr() | 164 tbl.tr() |
166 doc = gui.Document(width=380) | 165 doc = gui.Document(width=510) |
167 space = doc.style.font.size(" ") | 166 space = doc.style.font.size(" ") |
168 for header in ['Item', 'Buy Price', 'Sell Price']: | 167 for header in ['Item', 'Buy Price', 'Sell Price', 'Repair Price']: |
169 doc.add(make_box(header)) | 168 doc.add(make_box(header)) |
170 doc.br(space[1]) | 169 doc.br(space[1]) |
171 for building in buildings.BUILDINGS: | 170 for building in buildings.BUILDINGS: |
172 doc.add(make_box(building.NAME)) | 171 doc.add(make_box(building.NAME)) |
173 doc.add(make_box('%d' % building.BUY_PRICE)) | 172 doc.add(make_box('%d' % building.BUY_PRICE)) |
174 doc.add(make_box('%d' % building.SELL_PRICE)) | 173 doc.add(make_box('%d' % building.SELL_PRICE)) |
174 if building.BREAKABLE: | |
175 doc.add(make_box('%d' % building.REPAIR_PRICE)) | |
176 else: | |
177 doc.add(make_box('N/A')) | |
175 doc.br(space[1]) | 178 doc.br(space[1]) |
176 for equip in equipment.EQUIPMENT: | 179 for equip in equipment.EQUIPMENT: |
177 doc.add(make_box(equip.NAME)) | 180 doc.add(make_box(equip.NAME)) |
178 doc.add(make_box('%d' % equip.BUY_PRICE)) | 181 doc.add(make_box('%d' % equip.BUY_PRICE)) |
179 doc.add(make_box('%d' % equip.SELL_PRICE)) | 182 doc.add(make_box('%d' % equip.SELL_PRICE)) |
183 doc.add(make_box('N/A')) | |
180 doc.br(space[1]) | 184 doc.br(space[1]) |
181 | 185 |
182 doc.add(make_box("Fence")) | |
183 doc.add(make_box('%d' % constants.BUY_PRICE_FENCE)) | |
184 doc.add(make_box('%d' % constants.SELL_PRICE_FENCE)) | |
185 | |
186 doc.add(make_box("Repair Fence")) | |
187 doc.add(make_box('%d' % constants.REPAIR_PRICE_FENCE)) | |
188 doc.add(make_box('')) | |
189 | |
190 fix_widths(doc) | 186 fix_widths(doc) |
191 for word in "Damaged equipment or broken fences will be sold for" \ | 187 for word in "Damaged equipment or buildings will be sold for" \ |
192 " less than the sell price.".split(): | 188 " less than the sell price.".split(): |
193 doc.add(gui.Label(word)) | 189 doc.add(gui.Label(word)) |
194 doc.space(space) | 190 doc.space(space) |
195 close_button = gui.Button("Close") | 191 close_button = gui.Button("Close") |
196 tbl.td(doc) | 192 tbl.td(doc) |
383 sprite_curs = None | 379 sprite_curs = None |
384 if buildings.is_building(tool): | 380 if buildings.is_building(tool): |
385 sprite_curs = sprite_cursor.SpriteCursor(tool.IMAGE, self.tv, tool.BUY_PRICE) | 381 sprite_curs = sprite_cursor.SpriteCursor(tool.IMAGE, self.tv, tool.BUY_PRICE) |
386 elif equipment.is_equipment(tool): | 382 elif equipment.is_equipment(tool): |
387 sprite_curs = sprite_cursor.SpriteCursor(tool.CHICKEN_IMAGE_FILE, self.tv) | 383 sprite_curs = sprite_cursor.SpriteCursor(tool.CHICKEN_IMAGE_FILE, self.tv) |
388 elif tool == constants.TOOL_BUY_FENCE: | |
389 sprite_curs = sprite_cursor.SpriteCursor("tiles/fence.png", self.tv) | |
390 self.set_cursor(cursor, sprite_curs) | 384 self.set_cursor(cursor, sprite_curs) |
391 | 385 |
392 def set_cursor(self, cursor=None, sprite_curs=None): | 386 def set_cursor(self, cursor=None, sprite_curs=None): |
393 if cursor: | 387 if cursor: |
394 pygame.mouse.set_cursor(*cursor) | 388 pygame.mouse.set_cursor(*cursor) |
439 self.sell_chicken(self.tv.screen_to_tile(e.pos)) | 433 self.sell_chicken(self.tv.screen_to_tile(e.pos)) |
440 elif self.selected_tool == constants.TOOL_SELL_EGG: | 434 elif self.selected_tool == constants.TOOL_SELL_EGG: |
441 self.sell_egg(self.tv.screen_to_tile(e.pos)) | 435 self.sell_egg(self.tv.screen_to_tile(e.pos)) |
442 elif self.selected_tool == constants.TOOL_PLACE_ANIMALS: | 436 elif self.selected_tool == constants.TOOL_PLACE_ANIMALS: |
443 self.place_animal(self.tv.screen_to_tile(e.pos)) | 437 self.place_animal(self.tv.screen_to_tile(e.pos)) |
444 elif self.selected_tool == constants.TOOL_BUY_FENCE: | |
445 self.buy_fence(self.tv.screen_to_tile(e.pos)) | |
446 elif self.selected_tool == constants.TOOL_SELL_BUILDING: | 438 elif self.selected_tool == constants.TOOL_SELL_BUILDING: |
447 self.sell_building(self.tv.screen_to_tile(e.pos)) | 439 self.sell_building(self.tv.screen_to_tile(e.pos)) |
448 elif self.selected_tool == constants.TOOL_SELL_EQUIPMENT: | 440 elif self.selected_tool == constants.TOOL_SELL_EQUIPMENT: |
449 self.sell_equipment(self.tv.screen_to_tile(e.pos)) | 441 self.sell_equipment(self.tv.screen_to_tile(e.pos)) |
442 elif self.selected_tool == constants.TOOL_REPAIR_BUILDING: | |
443 self.repair_building(self.tv.screen_to_tile(e.pos)) | |
450 elif self.selected_tool == constants.TOOL_LOGGING: | 444 elif self.selected_tool == constants.TOOL_LOGGING: |
451 self.logging_forest(self.tv.screen_to_tile(e.pos)) | 445 self.logging_forest(self.tv.screen_to_tile(e.pos)) |
452 elif buildings.is_building(self.selected_tool): | 446 elif buildings.is_building(self.selected_tool): |
453 self.buy_building(self.tv.screen_to_tile(e.pos), self.selected_tool) | 447 self.buy_building(self.tv.screen_to_tile(e.pos), self.selected_tool) |
454 elif equipment.is_equipment(self.selected_tool): | 448 elif equipment.is_equipment(self.selected_tool): |
538 else: | 532 else: |
539 self.select_animal_to_place(chicken) | 533 self.select_animal_to_place(chicken) |
540 pygame.mouse.set_cursor(*cursors.cursors['chicken']) | 534 pygame.mouse.set_cursor(*cursors.cursors['chicken']) |
541 return | 535 return |
542 building = self.get_building(tile_pos) | 536 building = self.get_building(tile_pos) |
543 if building: | 537 if building and building.ABODE: |
544 if self.animal_to_place: | 538 if self.animal_to_place: |
545 try: | 539 try: |
546 place = building.first_empty_place() | 540 place = building.first_empty_place() |
547 self.relocate_animal(self.animal_to_place, place=place) | 541 self.relocate_animal(self.animal_to_place, place=place) |
548 self.animal_to_place.equip(equipment.Nest()) | 542 self.animal_to_place.equip(equipment.Nest()) |
684 button.connect(gui.CLICK, evict_callback) | 678 button.connect(gui.CLICK, evict_callback) |
685 tbl.td(button, colspan=2, **kwargs) | 679 tbl.td(button, colspan=2, **kwargs) |
686 | 680 |
687 self.open_dialog(tbl, close_callback=close_callback) | 681 self.open_dialog(tbl, close_callback=close_callback) |
688 | 682 |
689 def buy_fence(self, tile_pos): | |
690 this_tile = self.tv.get(tile_pos) | |
691 if this_tile not in [self.GRASSLAND, self.BROKEN_FENCE]: | |
692 return | |
693 if this_tile == self.GRASSLAND: | |
694 cost = constants.BUY_PRICE_FENCE | |
695 else: | |
696 cost = constants.REPAIR_PRICE_FENCE | |
697 if any((chicken.pos.x, chicken.pos.y) == tile_pos for chicken in self.chickens): | |
698 return | |
699 | |
700 if self.cash < cost: | |
701 print "You can't afford a fence." | |
702 return | |
703 self.add_cash(-cost) | |
704 self.tv.set(tile_pos, self.FENCE) | |
705 | |
706 def sell_fence(self, tile_pos): | |
707 this_tile = self.tv.get(tile_pos) | |
708 if this_tile not in [self.FENCE, self.BROKEN_FENCE]: | |
709 return | |
710 if this_tile == self.FENCE: | |
711 self.add_cash(constants.SELL_PRICE_FENCE) | |
712 elif this_tile == self.BROKEN_FENCE: | |
713 self.add_cash(constants.SELL_PRICE_BROKEN_FENCE) | |
714 self.tv.set(tile_pos, self.GRASSLAND) | |
715 | |
716 def logging_forest(self, tile_pos): | 683 def logging_forest(self, tile_pos): |
717 if self.tv.get(tile_pos) != self.WOODLAND: | 684 if self.tv.get(tile_pos) != self.WOODLAND: |
718 return | 685 return |
719 if self.cash < constants.LOGGING_PRICE: | 686 if self.cash < constants.LOGGING_PRICE: |
720 return | 687 return |
747 return False | 714 return False |
748 | 715 |
749 chicken = self.get_outside_chicken(tile_pos) | 716 chicken = self.get_outside_chicken(tile_pos) |
750 if chicken is None: | 717 if chicken is None: |
751 building = self.get_building(tile_pos) | 718 building = self.get_building(tile_pos) |
752 if building is None: | 719 if not (building and building.ABODE): |
753 return | 720 return |
754 # Bounce through open dialog once more | 721 # Bounce through open dialog once more |
755 self.open_building_dialog(building, do_equip) | 722 self.open_building_dialog(building, do_equip) |
756 else: | 723 else: |
757 do_equip(chicken) | 724 do_equip(chicken) |
758 | 725 |
759 def sell_building(self, tile_pos): | 726 def sell_building(self, tile_pos): |
760 if self.tv.get(tile_pos) in [self.FENCE, self.BROKEN_FENCE]: | |
761 return self.sell_fence(tile_pos) | |
762 building = self.get_building(tile_pos) | 727 building = self.get_building(tile_pos) |
763 if building is None: | 728 if building is None: |
764 return | 729 return |
765 if list(building.occupants()): | 730 if list(building.occupants()): |
766 warning = gui.Button("Occupied buildings may not be sold.") | 731 warning = gui.Button("Occupied buildings may not be sold.") |
767 self.open_dialog(warning) | 732 self.open_dialog(warning) |
768 return | 733 return |
769 self.add_cash(building.sell_price()) | 734 self.add_cash(building.sell_price()) |
770 building.remove(self.tv) | 735 building.remove(self.tv) |
771 self.remove_building(building) | 736 self.remove_building(building) |
737 | |
738 def repair_building(self, tile_pos): | |
739 building = self.get_building(tile_pos) | |
740 if not (building and building.broken()): | |
741 return | |
742 self.add_cash(-building.repair_price()) | |
743 building.repair(self.tv) | |
772 | 744 |
773 def sell_equipment(self, tile_pos): | 745 def sell_equipment(self, tile_pos): |
774 x, y = 0, 0 | 746 x, y = 0, 0 |
775 def do_sell(chicken, update_button=None): | 747 def do_sell(chicken, update_button=None): |
776 if not chicken.equipment: | 748 if not chicken.equipment: |