* Better Patch for Configfile handling
[opeanno-debian-packaging.git] / game / world / building / path.py
blob7d4042172838c5394975093d400d6c15050e015f
1 # ###################################################
2 # Copyright (C) 2008 The OpenAnno Team
3 # team@openanno.org
4 # This file is part of OpenAnno.
6 # OpenAnno 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.
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.
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 # ###################################################
22 from building import Building
23 import fife
24 import game.main
25 import math
26 import weakref
27 from buildable import BuildableLine, BuildableSingle
29 class Path(Building, BuildableLine):
30 speed = 42 # probably obsolete
31 def init(self):
32 """
33 """
34 super(Path, self).init()
35 origin = self.position.origin
36 self.island = weakref.ref(game.main.session.world.get_island(origin.x, origin.y))
37 for tile in self.island().get_surrounding_tiles(origin):
38 if tile is not None and isinstance(tile.object, Path):
39 tile.object.recalculateOrientation()
40 self.recalculateOrientation()
41 self.island().registerPath(self)
43 def load(self, db, worldid):
44 super(Path, self).load(db, worldid)
45 self.recalculateOrientation()
46 self.island().registerPath(self)
48 def remove(self):
49 super(Path, self).remove()
50 origin = self.position.origin
51 self.island().unregisterPath(self)
52 island = game.main.session.world.get_island(origin.x, origin.y)
53 for tile in self.island().get_surrounding_tiles(origin):
54 if tile is not None and isinstance(tile.object, Path):
55 tile.object.recalculateOrientation()
57 def recalculateOrientation(self):
58 """
59 """
60 action = ''
61 origin = self.position.origin
62 tile = self.island().get_tile(origin.offset(0, -1))
63 if tile is not None and isinstance(tile.object, (Path, Bridge)):
64 action += 'a'
65 tile = self.island().get_tile(origin.offset(1, 0))
66 if tile is not None and isinstance(tile.object, (Path, Bridge)):
67 action += 'b'
68 tile = self.island().get_tile(origin.offset(0, 1))
69 if tile is not None and isinstance(tile.object, (Path, Bridge)):
70 action += 'c'
71 tile = self.island().get_tile(origin.offset(-1, 0))
72 if tile is not None and isinstance(tile.object, (Path, Bridge)):
73 action += 'd'
74 if action == '':
75 action = 'default'
76 location = self._instance.getLocation()
77 location.setLayerCoordinates(fife.ModelCoordinate(int(origin.x + 1), int(origin.y), 0))
78 self.act(action, location, True)
80 @classmethod
81 def getInstance(cls, *args, **kwargs):
82 kwargs['layer'] = 1
83 return super(Path, cls).getInstance(*args, **kwargs)
85 class Bridge(Building, BuildableSingle):
86 #@classmethod
87 #def getInstance(cls, x, y, action=None, **trash):
88 # super(Bridge, cls).getInstance(x = x, y = y, action = 'default', **trash)
90 def init(self):
91 """
92 """
93 super(Bridge, self).init()
94 origin = self.position.origin
95 self.island = weakref.ref(game.main.session.world.get_island(origin.x, origin.y))
96 for tile in self.island().get_surrounding_tiles(origin):
97 if tile is not None and isinstance(tile.object, Path):
98 tile.object.recalculateOrientation()
100 @classmethod
101 def getInstance(cls, *args, **kwargs):
102 kwargs['layer'] = 1
103 return super(Bridge, cls).getInstance(*args, **kwargs)