1 # ###################################################
2 # Copyright (C) 2008 The OpenAnno Team
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
27 from buildable
import BuildableLine
, BuildableSingle
29 class Path(Building
, BuildableLine
):
30 speed
= 42 # probably obsolete
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
)
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
):
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
)):
65 tile
= self
.island().get_tile(origin
.offset(1, 0))
66 if tile
is not None and isinstance(tile
.object, (Path
, Bridge
)):
68 tile
= self
.island().get_tile(origin
.offset(0, 1))
69 if tile
is not None and isinstance(tile
.object, (Path
, Bridge
)):
71 tile
= self
.island().get_tile(origin
.offset(-1, 0))
72 if tile
is not None and isinstance(tile
.object, (Path
, Bridge
)):
76 location
= self
._instance
.getLocation()
77 location
.setLayerCoordinates(fife
.ModelCoordinate(int(origin
.x
+ 1), int(origin
.y
), 0))
78 self
.act(action
, location
, True)
81 def getInstance(cls
, *args
, **kwargs
):
83 return super(Path
, cls
).getInstance(*args
, **kwargs
)
85 class Bridge(Building
, BuildableSingle
):
87 #def getInstance(cls, x, y, action=None, **trash):
88 # super(Bridge, cls).getInstance(x = x, y = y, action = 'default', **trash)
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()
101 def getInstance(cls
, *args
, **kwargs
):
103 return super(Bridge
, cls
).getInstance(*args
, **kwargs
)