Package horizons :: Package world :: Package building :: Module war
[hide private]
[frames] | no frames]

Source Code for Module horizons.world.building.war

  1  # ################################################### 
  2  # Copyright (C) 2008-2017 The Unknown Horizons Team 
  3  # team@unknown-horizons.org 
  4  # This file is part of Unknown Horizons. 
  5  # 
  6  # Unknown Horizons is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the 
 18  # Free Software Foundation, Inc., 
 19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 20  # ################################################### 
 21   
 22  from horizons.constants import WEAPONS 
 23  from horizons.scheduler import Scheduler 
 24  from horizons.util.tile_orientation import get_tile_alignment_action 
 25  from horizons.world.building.buildable import BuildableLine, BuildableSingle 
 26  from horizons.world.building.building import BasicBuilding 
 27  from horizons.world.units.weaponholder import StationaryWeaponHolder 
 28   
 29   
30 -class Tower(BuildableSingle, StationaryWeaponHolder, BasicBuilding):
31 32 POSSIBLE_WEAPONS = [WEAPONS.CANNON] 33
34 - def __init__(self, *args, **kwargs):
35 super().__init__(*args, **kwargs) 36 # apply cannons already paid for 37 for weapon_type in self.__class__.POSSIBLE_WEAPONS: 38 for i in range(self.costs.get(weapon_type, 0)): 39 self.add_weapon_to_storage(weapon_type)
40
41 - def fire_all_weapons(self, dest, rotate=True):
42 super().fire_all_weapons(dest, rotate)
43
44 - def update_range(self, caller=None):
45 self._fix_weapon_range() 46 super().update_range(caller=caller)
47
48 - def _fix_weapon_range(self):
49 """Set all min weapon ranges to 0. 50 Since the tower can't move, melee units could just approach it and 51 destroy the tower""" 52 for weapon in self._weapon_storage: 53 weapon.weapon_range = (0, weapon.weapon_range[1])
54 55
56 -class Barrier(BasicBuilding, BuildableLine):
57 """Buildable barriers.""" 58
59 - def init(self):
60 # this does not belong in __init__, it's just here that all the data should be consistent 61 self.__init()
62
63 - def __init(self):
64 self.island.barrier_nodes.register(self) 65 66 # don't always recalculate while loading, we'd recalculate too often. 67 # do it once when everything is finished. 68 if not self.session.world.inited: 69 Scheduler().add_new_object(self.recalculate_orientation, self, run_in=0) 70 else: 71 self.recalculate_surrounding_tile_orientation() 72 self.recalculate_orientation()
73
74 - def remove(self):
75 super().remove() 76 self.island.barrier_nodes.unregister(self) 77 self.recalculate_surrounding_tile_orientation()
78
79 - def is_barrier(self, tile):
80 # Only consider barriers that the player build 81 return (tile is not None and 82 tile.object is not None and 83 tile.object.id == self.id and 84 tile.object.owner == self.owner)
85
87 for tile in self.island.get_surrounding_tiles(self.position): 88 if self.is_barrier(tile): 89 tile.object.recalculate_orientation()
90
91 - def recalculate_orientation(self):
92 def is_similar_tile(position): 93 tile = self.island.get_tile(position) 94 return self.is_barrier(tile)
95 96 origin = self.position.origin 97 action = get_tile_alignment_action(origin, is_similar_tile) 98 99 location = self._instance.getLocation() 100 self.act(action, location, True)
101