Changeset 478
- Timestamp:
- 02/03/10 14:54:21 (10 years ago)
- Location:
- trunk/game/scripts
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/game/scripts/engine.py
r476 r478 59 59 return 60 60 61 # save the PC coordinates before we destroy the behaviour61 # save the PC coordinates 62 62 coords = self.game_state.PC.behaviour.agent.getLocation().\ 63 63 getMapCoordinates() 64 64 self.game_state.saved_pc_coordinates = (coords.x, coords.y) 65 65 66 # can't pickle SwigPyObjects67 behaviours = {}68 behaviour_player = self.game_state.PC.behaviour69 self.game_state.PC.behaviour = None70 71 # Backup the behaviours72 for map_id in self.game_state.objects:73 behaviours[map_id] = {}74 for (object_id, npc) in self.game_state.objects[map_id].items():75 if npc.trueAttr("NPC"):76 behaviours[map_id][object_id] = npc.behaviour77 npc.behaviour = None78 79 66 # Pickle it 80 67 pickle.dump(self.game_state, f) 81 f.close() 82 83 # Restore behaviours 84 for map_id in behaviours: 85 for (object_id, behaviour) in behaviours[map_id].items(): 86 self.game_state.objects[map_id][object_id].behaviour = \ 87 behaviours[map_id][object_id] 88 89 self.game_state.PC.behaviour = behaviour_player 68 f.close() 90 69 91 70 def load(self, path, filename): … … 112 91 # objects cannot be pickled 113 92 for map_id in self.game_state.objects: 114 for (object_id, npc) in self.game_state.objects[map_id].items():115 if npc.trueAttr("NPC"):116 npc.createBehaviour(self.view.active_map.agent_layer)93 for (object_id, obj) in self.game_state.objects[map_id].items(): 94 if obj.trueAttr("NPC") or obj.trueAttr("AnimatedContainer"): 95 obj.createBehaviour(self.view.active_map.agent_layer) 117 96 118 97 # Fix the player behaviour … … 194 173 # create the PC agent 195 174 obj.start() 175 if obj.trueAttr("AnimatedContainer"): 176 # create the agent 177 obj.setup() 196 178 197 179 def objectActive(self, ident): -
trunk/game/scripts/objects/actors.py
r477 r478 126 126 self.layer_id = agent_layer.getId() 127 127 self.createBehaviour(agent_layer) 128 129 def __getstate__(self): 130 odict = self.__dict__.copy() 131 del odict["behaviour"] 132 return odict; 133 134 def __setstate__(self, state): 135 self.__dict__.update(state) 128 136 129 137 def meet(self, npc): … … 281 289 self.dialogue = kwargs.get('dialogue') 282 290 291 def __getstate__(self): 292 odict = self.__dict__.copy() 293 del odict["behaviour"] 294 return odict; 295 296 def __setstate__(self, state): 297 self.__dict__.update(state) 298 283 299 def createBehaviour(self, layer): 284 300 """Creates the behaviour for this actor. -
trunk/game/scripts/objects/containers.py
r477 r478 35 35 self.placeItem(CarryableItem(ID=987,name="Dagger456")) 36 36 37 class Footlocker(ImmovableContainer, fife.InstanceActionListener): 38 def __init__ (self, ID, agent_layer=None, name = 'Footlocker', 39 text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs): 40 ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, 41 text = text, **kwargs) 42 self.placeItem(CarryableItem(ID=987,name="Dagger456")) 37 class ContainerBehaviour(fife.InstanceActionListener): 38 def __init__(self, parent = None, agent_layer = None): 39 fife.InstanceActionListener.__init__(self) 40 self.parent = parent 41 self.layer = agent_layer 42 self.state = _AGENT_STATE_CLOSED 43 self.agent = None 43 44 44 fife.InstanceActionListener.__init__(self) 45 self.layer = agent_layer 46 self.agent = self.layer.getInstance(self.ID) 45 def attachToLayer(self, agent_ID): 46 """ Attaches to a certain layer 47 @type agent_ID: String 48 @param agent_ID: ID of the layer to attach to. 49 @return: None""" 50 self.agent = self.layer.getInstance(agent_ID) 47 51 self.agent.addActionListener(self) 48 52 self.state = _AGENT_STATE_CLOSED … … 66 70 67 71 def open (self): 68 super (Footlocker,self).open()69 72 if self.state != _AGENT_STATE_OPENED and self.state != _AGENT_STATE_OPENING: 70 73 self.agent.act('open', self.agent.getLocation()) … … 72 75 73 76 def close(self): 74 super (Footlocker,self).close()75 77 if self.state != _AGENT_STATE_CLOSED and self.state != _AGENT_STATE_CLOSING: 76 78 self.agent.act('close', self.agent.getLocation()) 77 self.state = _AGENT_STATE_CLOSING 79 self.state = _AGENT_STATE_CLOSING 80 81 class Footlocker(ImmovableContainer): 82 def __init__ (self, ID, agent_layer=None, name = 'Footlocker', 83 text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs): 84 ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, 85 text = text, **kwargs) 86 self.placeItem(CarryableItem(ID=987,name="Dagger456")) 87 88 self.is_AnimatedContainer = True 89 self.createBehaviour(agent_layer) 90 91 def __getstate__(self): 92 odict = self.__dict__.copy() 93 del odict["behaviour"] 94 return odict; 95 96 def __setstate__(self, state): 97 self.__dict__.update(state) 98 99 def createBehaviour(self, layer): 100 self.behaviour = ContainerBehaviour(self, layer) 101 102 def setup(self): 103 """@return: None""" 104 self.behaviour.attachToLayer(self.ID) 105 106 def open (self): 107 super (Footlocker,self).open() 108 self.behaviour.open() 109 110 def close(self): 111 super (Footlocker,self).close() 112 self.behaviour.close()
Note: See TracChangeset
for help on using the changeset viewer.