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

Source Code for Module horizons.world.building.path

 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.component.componentholder import ComponentHolder 
23  from horizons.constants import LAYERS 
24  from horizons.scheduler import Scheduler 
25  from horizons.util.tile_orientation import get_tile_alignment_action 
26  from horizons.world.building.buildable import BuildableLine 
27  from horizons.world.building.building import BasicBuilding 
28   
29   
30 -class Path(ComponentHolder):
31 """Object with path functionality""" 32 walkable = True 33 34 # no __init__ 35
36 - def load(self, db, worldid):
37 super().load(db, worldid)
38
39 - def init(self):
40 # this does not belong in __init__, it's just here that all the data should be consistent 41 self.__init()
42
43 - def __init(self):
44 self.island.path_nodes.register_road(self) 45 if self.session.world.inited: 46 self.recalculate_surrounding_tile_orientation() 47 self.recalculate_orientation() 48 else: 49 # don't always recalculate while loading, we'd recalculate too often. 50 # do it once when everything is finished. 51 Scheduler().add_new_object(self.recalculate_orientation, self, run_in=0)
52
53 - def remove(self):
54 super().remove() 55 self.island.path_nodes.unregister_road(self) 56 self.recalculate_surrounding_tile_orientation()
57
58 - def is_road(self, tile):
59 return (tile is not None and 60 tile.object is not None and 61 self.island.path_nodes.is_road(tile.x, tile.y) and 62 tile.object.owner == self.owner)
63
65 for tile in self.island.get_surrounding_tiles(self.position): 66 if self.is_road(tile): 67 tile.object.recalculate_orientation()
68
69 - def recalculate_orientation(self):
70 def is_similar_tile(position): 71 tile = self.island.get_tile(position) 72 return self.is_road(tile)
73 74 origin = self.position.origin 75 action = get_tile_alignment_action(origin, is_similar_tile) 76 77 location = self._instance.getLocation() 78 self.act(action, location, True)
79 80
81 -class Road(Path, BasicBuilding, BuildableLine):
82 """Actual buildable road.""" 83 layer = LAYERS.FIELDS
84