Mercurial > parpg-core
comparison src/parpg/gamemodel.py @ 116:9b5498e3bda0
Move the identifier field from the FifeAgent component to the new General component.
Added General Entity.
author | KarstenBock@gmx.net |
---|---|
date | Sat, 24 Sep 2011 15:48:24 +0200 |
parents | b10d12fbbb3f |
children | 29869273f9e1 |
comparison
equal
deleted
inserted
replaced
115:a85d58fcd253 | 116:9b5498e3bda0 |
---|---|
435 if (map_obj.getAction('default')): | 435 if (map_obj.getAction('default')): |
436 target = fife.Location(self.active_map.agent_layer) | 436 target = fife.Location(self.active_map.agent_layer) |
437 inst.act('default', target, True) | 437 inst.act('default', target, True) |
438 | 438 |
439 | 439 |
440 entity_data["fifeagent"]["identifier"] = inst_id | |
441 if entity_data["fifeagent"].has_key("behaviour"): | 440 if entity_data["fifeagent"].has_key("behaviour"): |
442 entity_data["fifeagent"]["behaviour"] = getattr(behaviours, entity_data["fifeagent"]["behaviour"])() | 441 entity_data["fifeagent"]["behaviour"] = getattr(behaviours, entity_data["fifeagent"]["behaviour"])() |
443 else: | 442 else: |
444 entity_data["fifeagent"]["behaviour"] = behaviours.Base() | 443 entity_data["fifeagent"]["behaviour"] = behaviours.Base() |
445 if self.dialogues.has_key(inst_id): | 444 if self.dialogues.has_key(inst_id): |
446 entity_data["dialogue"] = {} | 445 entity_data["dialogue"] = {} |
447 entity_data["dialogue"]["dialogue"] = self.dialogues[inst_id] | 446 entity_data["dialogue"]["dialogue"] = self.dialogues[inst_id] |
448 | 447 |
449 obj = self.createMapObject(self.active_map.agent_layer, entity_data, world) | 448 obj = self.createMapObject(self.active_map.agent_layer, entity_data, inst_id, world) |
450 | 449 |
451 if agent.has_key("Inventory"): | 450 if agent.has_key("Inventory"): |
452 inv = agent["Inventory"] | 451 inv = agent["Inventory"] |
453 slots = inv["Slots"] | 452 slots = inv["Slots"] |
454 obj.container.children = list() | 453 obj.container.children = list() |
475 equip.equip(obj.equip, item.equipable, slot) | 474 equip.equip(obj.equip, item.equipable, slot) |
476 else: | 475 else: |
477 raise Exception("Item %s is not containable or equipable." % item_type) | 476 raise Exception("Item %s is not containable or equipable." % item_type) |
478 | 477 |
479 def create_item(self, item_data, world, item_type, data): | 478 def create_item(self, item_data, world, item_type, data): |
480 item = createEntity(item_data, world, None) | 479 identifier = self.createUniqueID(data["ID"]) |
480 item = createEntity(item_data, identifier, world, None) | |
481 item.containable.item_type = item_type | 481 item.containable.item_type = item_type |
482 self.game_state.addObject(self.createUniqueID(data["ID"]), None, item) | 482 self.game_state.addObject(identifier, None, item) |
483 return item | 483 return item |
484 | 484 |
485 def placeAgents(self, world): | 485 def placeAgents(self, world): |
486 """Places the current maps agents """ | 486 """Places the current maps agents """ |
487 if not self.active_map: | 487 if not self.active_map: |
542 # Make the new map active. | 542 # Make the new map active. |
543 self.active_map = self.game_state.maps[map_name] | 543 self.active_map = self.game_state.maps[map_name] |
544 self.active_map.makeActive() | 544 self.active_map.makeActive() |
545 self.game_state.current_map_name = map_name | 545 self.game_state.current_map_name = map_name |
546 | 546 |
547 def createMapObject (self, layer, attributes, world): | 547 def createMapObject (self, layer, attributes, inst_id, world): |
548 """Create an object and add it to the current map. | 548 """Create an object and add it to the current map. |
549 @type layer: fife.Layer | 549 @type layer: fife.Layer |
550 @param layer: FIFE layer object exists in | 550 @param layer: FIFE layer object exists in |
551 @type attributes: Dictionary | 551 @type attributes: Dictionary |
552 @param attributes: Dictionary of all object attributes | 552 @param attributes: Dictionary of all object attributes |
557 extra = {} | 557 extra = {} |
558 if layer is not None: | 558 if layer is not None: |
559 extra['fifeagent'] = {} | 559 extra['fifeagent'] = {} |
560 extra['fifeagent']['layer'] = layer | 560 extra['fifeagent']['layer'] = layer |
561 | 561 |
562 obj = createEntity(attributes, world, extra) | 562 obj = createEntity(attributes, inst_id, world, extra) |
563 if obj: | 563 if obj: |
564 self.addObject(layer, obj) | 564 self.addObject(layer, obj) |
565 return obj | 565 return obj |
566 | 566 |
567 def addPC(self, layer, player_char): | 567 def addPC(self, layer, player_char): |
588 @type obj: GameObject | 588 @type obj: GameObject |
589 @param obj: corresponding object class | 589 @param obj: corresponding object class |
590 @type instance: fife.Instance | 590 @type instance: fife.Instance |
591 @param instance: FIFE instance of object | 591 @param instance: FIFE instance of object |
592 @return: None""" | 592 @return: None""" |
593 ref = self.game_state.getObjectById(obj.fifeagent.identifier, | 593 ref = self.game_state.getObjectById(obj.general.identifier, |
594 self.game_state.current_map_name) | 594 self.game_state.current_map_name) |
595 if ref is None: | 595 if ref is None: |
596 # no, add it to the game state | 596 # no, add it to the game state |
597 self.game_state.addObject(obj.fifeagent.identifier, self.game_state.current_map_name, obj) | 597 self.game_state.addObject(obj.general.identifier, self.game_state.current_map_name, obj) |
598 else: | 598 else: |
599 # yes, use the current game state data | 599 # yes, use the current game state data |
600 obj.fifeagent.pos.X = ref.X | 600 obj.fifeagent.pos.X = ref.X |
601 obj.fifeagent.pos.Y = ref.Y | 601 obj.fifeagent.pos.Y = ref.Y |
602 obj.fifeagent.gfx = ref.gfx | 602 obj.fifeagent.gfx = ref.gfx |
623 @param ident: ID of object | 623 @param ident: ID of object |
624 @rtype: boolean | 624 @rtype: boolean |
625 @return: Status of result (True/False)""" | 625 @return: Status of result (True/False)""" |
626 for game_object in \ | 626 for game_object in \ |
627 self.game_state.getObjectsFromMap(self.game_state.current_map_name): | 627 self.game_state.getObjectsFromMap(self.game_state.current_map_name): |
628 if (game_object.fifeagent.identifier == ident): | 628 if (game_object.general.identifier == ident): |
629 # we found a match | 629 # we found a match |
630 return game_object | 630 return game_object |
631 # no match | 631 # no match |
632 return False | 632 return False |
633 | 633 |