Mercurial > parpg-source
comparison gamemodel.py @ 150:80672955ab70
PARPG now works with, and needs Fife 0.3.3.
author | KarstenBock@gmx.net |
---|---|
date | Tue, 11 Oct 2011 14:47:37 +0200 |
parents | 53faff63037f |
children | 4dc7951c3bfc |
comparison
equal
deleted
inserted
replaced
149:86656563555e | 150:80672955ab70 |
---|---|
92 self.object_db_file = '/'.join([objects_directory, | 92 self.object_db_file = '/'.join([objects_directory, |
93 settings.parpg.ObjectDatabaseFile]) | 93 settings.parpg.ObjectDatabaseFile]) |
94 self.dialogue_directory = settings.parpg.DialoguesPath | 94 self.dialogue_directory = settings.parpg.DialoguesPath |
95 self.dialogues = {} | 95 self.dialogues = {} |
96 self.agent_import_files = {} | 96 self.agent_import_files = {} |
97 self.obj_loader = XMLObjectLoader( | 97 self.obj_loader = XMLObjectLoader(self.engine) |
98 self.engine.getImagePool(), | |
99 self.engine.getAnimationPool(), | |
100 self.engine.getModel(), | |
101 self.engine.getVFS() | |
102 ) | |
103 | 98 |
104 def checkAttributes(self, attributes, template): | 99 def checkAttributes(self, attributes, template): |
105 """Checks for attributes that where not given in the map file | 100 """Checks for attributes that where not given in the map file |
106 and fills them with values from the object database | 101 and fills them with values from the object database |
107 @param attributes: attributes to check | 102 @param attributes: attributes to check |
132 id_number = 1 | 127 id_number = 1 |
133 while self.isIDUsed(ID + "_" + str(id_number)): | 128 while self.isIDUsed(ID + "_" + str(id_number)): |
134 id_number += 1 | 129 id_number += 1 |
135 if id_number > self.MAX_ID_NUMBER: | 130 if id_number > self.MAX_ID_NUMBER: |
136 raise ValueError( | 131 raise ValueError( |
137 "Number exceeds MAX_ID_NUMBER:" + str(self.MAX_ID_NUMBER)) | 132 "Number exceeds MAX_ID_NUMBER:" + |
133 str(self.MAX_ID_NUMBER) | |
134 ) | |
138 | 135 |
139 ID = ID + "_" + str(id_number) | 136 ID = ID + "_" + str(id_number) |
140 return ID | 137 return ID |
141 | 138 |
142 def moveObject(self, object_id, new_map): | 139 def moveObject(self, object_id, new_map): |
205 | 202 |
206 load_file.close() | 203 load_file.close() |
207 | 204 |
208 def teleport(self, agent, position): | 205 def teleport(self, agent, position): |
209 """Called when a an agent is moved instantly to a new position. | 206 """Called when a an agent is moved instantly to a new position. |
210 The setting of position may wan to be created as its own method down the road. | 207 The setting of position may wan to be created as its own method down |
208 the road. | |
211 @type position: String Tuple | 209 @type position: String Tuple |
212 @param position: X,Y coordinates passed from engine.changeMap | 210 @param position: X,Y coordinates passed from engine.changeMap |
213 @return: fife.Location""" | 211 @return: fife.Location""" |
214 logging.debug(position) | 212 logging.debug(position) |
215 coord = fife.DoublePoint3D(float(position[0]), float(position[1]), 0) | 213 coord = fife.DoublePoint3D(float(position[0]), float(position[1]), 0) |
301 object_model = "" | 299 object_model = "" |
302 if agent_values["Entity"].has_key("graphics") \ | 300 if agent_values["Entity"].has_key("graphics") \ |
303 and agent_values["Entity"]["graphics"].has_key("gfx"): | 301 and agent_values["Entity"]["graphics"].has_key("gfx"): |
304 object_model = agent_values["Entity"]["graphics"]["gfx"] | 302 object_model = agent_values["Entity"]["graphics"]["gfx"] |
305 elif agent_values.has_key("Template"): | 303 elif agent_values.has_key("Template"): |
306 object_model = self.object_db[agent_values["Template"]]["graphics"]["gfx"] | 304 template = self.object_db[agent_values["Template"]] |
305 object_model = template["graphics"]["gfx"] | |
307 else: | 306 else: |
308 object_model = self.GENERIC_ITEM_GFX | 307 object_model = self.GENERIC_ITEM_GFX |
309 import_file = self.agent_import_files[object_model] | 308 import_file = self.agent_import_files[object_model] |
310 loadImportFile(self.obj_loader, import_file, self.engine) | 309 loadImportFile(self.obj_loader, import_file, self.engine) |
311 | 310 |
425 entity_data["containable"].has_key("item_type") | 424 entity_data["containable"].has_key("item_type") |
426 ): | 425 ): |
427 entity_data["containable"]["item_type"] = template | 426 entity_data["containable"]["item_type"] = template |
428 | 427 |
429 | 428 |
430 obj = self.createMapObject(self.active_map.agent_layer, entity_data, inst_id, world) | 429 obj = self.createMapObject(self.active_map.agent_layer, |
430 entity_data, inst_id, world) | |
431 | 431 |
432 if agent.has_key("Inventory"): | 432 if agent.has_key("Inventory"): |
433 inv = agent["Inventory"] | 433 inv = agent["Inventory"] |
434 self.createInventoryItems(inv, obj, world) | 434 self.createInventoryItems(inv, obj, world) |
435 | 435 |
438 item = None | 438 item = None |
439 if data.has_key("type"): | 439 if data.has_key("type"): |
440 item_type = data["type"] | 440 item_type = data["type"] |
441 item_data = {} | 441 item_data = {} |
442 item_data = self.checkAttributes(item_data, item_type) | 442 item_data = self.checkAttributes(item_data, item_type) |
443 if item_data.has_key("containable") and item_data.has_key("equipable"): | 443 if (item_data.has_key("containable") and |
444 item_data.has_key("equipable")): | |
444 item = self.createItem( | 445 item = self.createItem( |
445 self.createUniqueID(data["ID"]), | 446 self.createUniqueID(data["ID"]), |
446 item_data, world, item_type) | 447 item_data, world, item_type) |
447 else: | 448 else: |
448 raise Exception("Item %s is not containable or equipable." % item_type) | 449 raise Exception( |
450 "Item %s is not containable or equipable." % | |
451 item_type | |
452 ) | |
449 else: | 453 else: |
450 identifier = data["ID"] | 454 identifier = data["ID"] |
451 if self.game_state.hasObject(identifier): | 455 if self.game_state.hasObject(identifier): |
452 item = self.game_state.getObjectById(identifier) | 456 item = self.game_state.getObjectById(identifier) |
453 else: | 457 else: |
531 | 535 |
532 # create the PlayerCharacter agent | 536 # create the PlayerCharacter agent |
533 self.active_map.addPC() | 537 self.active_map.addPC() |
534 #self.game_state.getObjectById("PlayerCharacter").fifeagent.start() | 538 #self.game_state.getObjectById("PlayerCharacter").fifeagent.start() |
535 if agent.has_key("PeopleKnown"): | 539 if agent.has_key("PeopleKnown"): |
536 self.game_state.getObjectById("PlayerCharacter").fifeagent.people_i_know = agent["PeopleKnown"] | 540 player = self.game_state.getObjectById("PlayerCharacter") |
541 player.fifeagent.people_i_know = agent["PeopleKnown"] | |
537 | 542 |
538 def changeMap(self, map_name, target_position = None): | 543 def changeMap(self, map_name, target_position = None): |
539 """Registers for a map change on the next pump(). | 544 """Registers for a map change on the next pump(). |
540 @type map_name: String | 545 @type map_name: String |
541 @param map_name: Id of the map to teleport to | 546 @param map_name: Id of the map to teleport to |
605 @param instance: FIFE instance of PlayerCharacter | 610 @param instance: FIFE instance of PlayerCharacter |
606 @return: None""" | 611 @return: None""" |
607 # For now we copy the PlayerCharacter, | 612 # For now we copy the PlayerCharacter, |
608 # in the future we will need to copy | 613 # in the future we will need to copy |
609 # PlayerCharacter specifics between the different PlayerCharacter's | 614 # PlayerCharacter specifics between the different PlayerCharacter's |
610 self.game_state.getObjectById("PlayerCharacter").fifeagent = player_char | 615 player = self.game_state.getObjectById("PlayerCharacter") |
611 self.game_state.getObjectById("PlayerCharacter").fifeagent.setup() | 616 player.fifeagent = player_char |
612 self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.speed = self.settings.parpg.PCSpeed | 617 player.fifeagent.setup() |
618 player.fifeagent.behaviour.speed = self.settings.parpg.PCSpeed | |
613 | 619 |
614 | 620 |
615 def addObject(self, layer, obj): | 621 def addObject(self, layer, obj): |
616 """Adds an object to the map. | 622 """Adds an object to the map. |
617 @type layer: fife.Layer | 623 @type layer: fife.Layer |
623 @return: None""" | 629 @return: None""" |
624 ref = self.game_state.getObjectById(obj.general.identifier, | 630 ref = self.game_state.getObjectById(obj.general.identifier, |
625 self.game_state.current_map_name) | 631 self.game_state.current_map_name) |
626 if ref is None: | 632 if ref is None: |
627 # no, add it to the game state | 633 # no, add it to the game state |
628 self.game_state.addObject(obj.general.identifier, self.game_state.current_map_name, obj) | 634 self.game_state.addObject(obj.general.identifier, |
635 self.game_state.current_map_name, obj) | |
629 else: | 636 else: |
630 # yes, use the current game state data | 637 # yes, use the current game state data |
631 obj.fifeagent.pos.X = ref.X | 638 obj.fifeagent.pos.X = ref.X |
632 obj.fifeagent.pos.Y = ref.Y | 639 obj.fifeagent.pos.Y = ref.Y |
633 obj.fifeagent.gfx = ref.gfx | 640 obj.fifeagent.gfx = ref.gfx |
665 def movePlayer(self, position): | 672 def movePlayer(self, position): |
666 """Code called when the player should move to another location | 673 """Code called when the player should move to another location |
667 @type position: fife.ScreenPoint | 674 @type position: fife.ScreenPoint |
668 @param position: Screen position to move to | 675 @param position: Screen position to move to |
669 @return: None""" | 676 @return: None""" |
677 player = self.game_state.getObjectById("PlayerCharacter") | |
670 if(self.pc_run == 1): | 678 if(self.pc_run == 1): |
671 self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.run(position) | 679 player.fifeagent.behaviour.run(position) |
672 else: | 680 else: |
673 self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.walk(position) | 681 player.fifeagent.behaviour.walk(position) |
674 | 682 |
675 def teleportAgent(self, agent, position): | 683 def teleportAgent(self, agent, position): |
676 """Code called when an agent should teleport to another location | 684 """Code called when an agent should teleport to another location |
677 @type position: fife.ScreenPoint | 685 @type position: fife.ScreenPoint |
678 @param position: Screen position to teleport to | 686 @param position: Screen position to teleport to |