comparison src/parpg/gamemodel.py @ 146:6e1eb964a6e5

Fixed dropping items on the map.
author KarstenBock@gmx.net
date Mon, 03 Oct 2011 18:25:31 +0200
parents c9fba51214ed
children 7214224b8d83
comparison
equal deleted inserted replaced
145:3dddf09377b8 146:6e1eb964a6e5
49 fife, and would be pointless to replicate, we hold a instance of 49 fife, and would be pointless to replicate, we hold a instance of
50 the fife view here. This also prevents us from just having a 50 the fife view here. This also prevents us from just having a
51 function heavy controller.""" 51 function heavy controller."""
52 ALL_AGENTS_KEY = "All" 52 ALL_AGENTS_KEY = "All"
53 MAX_ID_NUMBER = 1000 53 MAX_ID_NUMBER = 1000
54 GENERIC_ITEM_GFX = "generic_item"
54 55
55 def __init__(self, engine, settings): 56 def __init__(self, engine, settings):
56 """Initialize the instance. 57 """Initialize the instance.
57 @param engine: A fife.Engine object 58 @param engine: A fife.Engine object
58 @type emgome: fife.Engine 59 @type emgome: fife.Engine
144 @type object_id: str 145 @type object_id: str
145 @param new_map: ID of the new map, or None 146 @param new_map: ID of the new map, or None
146 @type object_id: str """ 147 @type object_id: str """
147 game_object = self.deleteObject(object_id) 148 game_object = self.deleteObject(object_id)
148 self.game_state.addObject(object_id, new_map, game_object) 149 self.game_state.addObject(object_id, new_map, game_object)
149 150
150 def deleteObject(self, object_id): 151 def deleteObject(self, object_id):
151 """Removes an object from the game 152 """Removes an object from the game
152 @param object_id: ID of the object 153 @param object_id: ID of the object
153 @type object_id: str """ 154 @type object_id: str """
154 del self.agents["All"][object_id] 155 if self.agents["All"].has_key(object_id):
156 del self.agents["All"][object_id]
157 else:
158 del self.items[object_id]
155 return self.game_state.deleteObject(object_id) 159 return self.game_state.deleteObject(object_id)
156 160
157 def save(self, path, filename): 161 def save(self, path, filename):
158 """Writes the saver to a file. 162 """Writes the saver to a file.
159 @type filename: string 163 @type filename: string
296 self.agents[namespace].update(agent) 300 self.agents[namespace].update(agent)
297 object_model = "" 301 object_model = ""
298 if agent_values["Entity"].has_key("graphics") \ 302 if agent_values["Entity"].has_key("graphics") \
299 and agent_values["Entity"]["graphics"].has_key("gfx"): 303 and agent_values["Entity"]["graphics"].has_key("gfx"):
300 object_model = agent_values["Entity"]["graphics"]["gfx"] 304 object_model = agent_values["Entity"]["graphics"]["gfx"]
305 elif agent_values.has_key("Template"):
306 object_model = self.object_db[agent_values["Template"]]["graphics"]["gfx"]
301 else: 307 else:
302 object_model = self.object_db[agent_values["Template"]]["graphics"]["gfx"] 308 object_model = self.GENERIC_ITEM_GFX
303 import_file = self.agent_import_files[object_model] 309 import_file = self.agent_import_files[object_model]
304 loadImportFile(self.obj_loader, import_file, self.engine) 310 loadImportFile(self.obj_loader, import_file, self.engine)
305 311
306 def readAgentsOfMap(self, map_name): 312 def readAgentsOfMap(self, map_name):
307 """Read the agents of the map 313 """Read the agents of the map
365 return None 371 return None
366 entity_data = deepcopy(agent["Entity"]) 372 entity_data = deepcopy(agent["Entity"])
367 entity_data["fifeagent"] = {} 373 entity_data["fifeagent"] = {}
368 if agent.has_key("Template"): 374 if agent.has_key("Template"):
369 entity_data = self.checkAttributes(entity_data, agent["Template"]) 375 entity_data = self.checkAttributes(entity_data, agent["Template"])
370 object_id = entity_data["graphics"]["gfx"] \ 376 object_id = (entity_data["graphics"]["gfx"]
371 if entity_data["graphics"].has_key("gfx") \ 377 if entity_data.has_key("graphics") and
372 else "generic_item" 378 entity_data["graphics"].has_key("gfx")
379 else self.GENERIC_ITEM_GFX
380 )
373 map_obj = self.fife_model.getObject(str(object_id), "PARPG") 381 map_obj = self.fife_model.getObject(str(object_id), "PARPG")
374 if not map_obj: 382 if not map_obj:
375 logging.warning("Object with inst_id={0}, ns=PARPG, " 383 logging.warning("Object with inst_id={0}, ns=PARPG, "
376 "could not be found. " 384 "could not be found. "
377 "Omitting...".format(str(object_id))) 385 "Omitting...".format(str(object_id)))
472 if (obj.fifeagent and (obj.lockable and not obj.lockable.closed)): 480 if (obj.fifeagent and (obj.lockable and not obj.lockable.closed)):
473 obj.fifeagent.behaviour.animate("opened", repeating=True) 481 obj.fifeagent.behaviour.animate("opened", repeating=True)
474 return obj 482 return obj
475 483
476 def create_item(self, identifier, item_data, world, item_type): 484 def create_item(self, identifier, item_data, world, item_type):
485 if not item_data["description"].has_key("view_name"):
486 item_data["description"]["view_name"] = (
487 item_data["description"]["real_name"])
477 item = createEntity(item_data, identifier, world, None) 488 item = createEntity(item_data, identifier, world, None)
478 item.containable.item_type = item_type 489 item.containable.item_type = item_type
479 self.game_state.addObject(identifier, None, item) 490 self.game_state.addObject(identifier, None, item)
480 return item 491 return item
481 492
488 if agent == "PlayerCharacter": 499 if agent == "PlayerCharacter":
489 continue 500 continue
490 if self.active_map.agent_layer.getInstances(agent): 501 if self.active_map.agent_layer.getInstances(agent):
491 continue 502 continue
492 self.createAgent(agents[agent], agent, world) 503 self.createAgent(agents[agent], agent, world)
504 self.updateObjectDB(world)
493 505
494 def placePC(self, world): 506 def placePC(self, world):
495 """Places the PlayerCharacter on the map""" 507 """Places the PlayerCharacter on the map"""
496 agent = self.agents[self.ALL_AGENTS_KEY]["PlayerCharacter"] 508 agent = self.agents[self.ALL_AGENTS_KEY]["PlayerCharacter"]
497 inst_id = "PlayerCharacter" 509 inst_id = "PlayerCharacter"