changeset 44:98f26f7636d8

Changes to make PARPG "runable" with grease. (With the correct modified assets)
author KarstenBock@gmx.net
date Tue, 06 Sep 2011 15:22:51 +0200
parents 8f9e9f47c363
children b8f421f74280
files behaviours/base.py dialoguecontroller.py entities/__init__.py gamemap.py gamemodel.py gamescenecontroller.py gamesceneview.py gamestate.py gui/hud.py objects/action.py
diffstat 10 files changed, 64 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/behaviours/base.py	Tue Sep 06 15:21:36 2011 +0200
+++ b/behaviours/base.py	Tue Sep 06 15:22:51 2011 +0200
@@ -53,7 +53,7 @@
         if self.agent is not None:
             self.agent.removeActionListener(self)
             
-        self.agent = layer.getInstance(self.parent.ID)
+        self.agent = layer.getInstance(self.parent.fifeagent.identifier)
         self.agent.addActionListener(self)
         self.state = _AGENT_STATE_NONE
         self.idle_counter = 1
--- a/dialoguecontroller.py	Tue Sep 06 15:21:36 2011 +0200
+++ b/dialoguecontroller.py	Tue Sep 06 15:22:51 2011 +0200
@@ -44,7 +44,7 @@
     def startTalk(self, npc):
         if npc.dialogue is not None:
             self.model.active_map.centerCameraOnPlayer()            
-            npc.talk(self.model.game_state.player_character)
+            npc.talk(self.model.game_state.getObjectById("PlayerCharacter").fifeagent)
             self.dialogue = self.view.hud.showDialogue(npc)
             self.dialogue.initiateDialogue()
             self.model.pause(True)
--- a/entities/__init__.py	Tue Sep 06 15:21:36 2011 +0200
+++ b/entities/__init__.py	Tue Sep 06 15:22:51 2011 +0200
@@ -47,4 +47,7 @@
         info[key] = val
 
     # this is for testing purposes
-    return getAllEntities()[ent_type](world, **info)
+    try:
+        return getAllEntities()[ent_type](world, **info)
+    except KeyError:
+        return None
--- a/gamemap.py	Tue Sep 06 15:21:36 2011 +0200
+++ b/gamemap.py	Tue Sep 06 15:22:51 2011 +0200
@@ -137,7 +137,7 @@
         """Add the player character to the map
            @return: None"""
         # Update gamestate.player_character
-        self.model.game_state.player_character.behaviour.onNewMap(self.agent_layer)
+        self.model.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.onNewMap(self.agent_layer)
         self.centerCameraOnPlayer()
 
     def toggleRenderer(self, r_name):
@@ -167,5 +167,5 @@
     def centerCameraOnPlayer(self):
         """Center the camera on the player"""
         camera = self.cameras[self.my_cam_id]
-        player_agent = self.model.game_state.player_character.behaviour.agent
+        player_agent = self.model.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.agent
         camera.setLocation(player_agent.getLocation())
--- a/gamemodel.py	Tue Sep 06 15:21:36 2011 +0200
+++ b/gamemodel.py	Tue Sep 06 15:22:51 2011 +0200
@@ -237,7 +237,7 @@
             agent_dict = self.agents["All"][agent]
             agent_obj = None
             if agent == "PlayerCharacter":
-                agent_obj = self.game_state.player_character
+                agent_obj = self.game_state.getObjectById("PlayerCharacter").fifeagent
             else:
                 agent_obj = self.game_state.getObjectById(agent, map_name)
             if agent_obj:
@@ -521,17 +521,20 @@
             inst_dict["target_x"] = agent["TargetPosition"][0]
             inst_dict["target_y"] = agent["TargetPosition"][1]
         if agent.has_key("Inventory"):
-            inventory = Inventory()
-            inventory_objs = agent["Inventory"]
-            for inventory_obj in inventory_objs:
-                self.createInventoryObject(inventory,
-                                           inventory_obj 
-                                           )
-            inst_dict["inventory"] = inventory
+            #TODO: Fix setting of inventory
+            #inventory = Inventory()
+            #inventory_objs = agent["Inventory"]
+            #for inventory_obj in inventory_objs:
+            #    self.createInventoryObject(inventory,
+            #                               inventory_obj 
+            #                               )
+            #inst_dict["inventory"] = inventory
+            pass
 
         if agent.has_key("Items"):
             container_objs = agent["Items"]
-            items = self.createContainerItems(container_objs)
+            #TODO: Create inventory items
+            items = []#self.createContainerItems(container_objs)
             inst_dict["items"] = items
             
         if agent.has_key("ItemType"):
@@ -539,7 +542,7 @@
                 item_data = {}
                 item_data["type"] = agent["ItemType"]
                 item_data["ID"] = inst_id 
-                item_data = self.createContainerObject(item_data)
+                #TODO item_data = self.createContainerObject(item_data)
             else:
                 item_data = agent["item"]
             inst_dict["item"] = item_data
@@ -565,17 +568,17 @@
                 continue
             self.createAgent(agents[agent], agent, world)
 
-    def placePC(self):
+    def placePC(self, world):
         """Places the PlayerCharacter on the map"""
         agent = self.agents[self.ALL_AGENTS_KEY]["PlayerCharacter"]
         inst_id = "PlayerCharacter"
-        self.createAgent(agent, inst_id)
+        self.createAgent(agent, inst_id, world)
         
         # create the PlayerCharacter agent
         self.active_map.addPC()
-        self.game_state.player_character.start()
+        #self.game_state.getObjectById("PlayerCharacter").fifeagent.start()
         if agent.has_key("PeopleKnown"):
-            self.game_state.player_character.people_i_know = agent["PeopleKnown"]
+            self.game_state.getObjectById("PlayerCharacter").fifeagent.people_i_know = agent["PeopleKnown"]
                       
     def changeMap(self, map_name, target_position = None):
         """Registers for a map change on the next pump().
@@ -630,12 +633,10 @@
             extra['layer'] = layer
         attributes = self.checkAttributes(attributes)
         
+        obj_type = attributes["type"]
         obj = createEntity(attributes, extra)
-        
-        if obj.trueAttr("PC"):
-            self.addPC(layer, obj)
-        else:
-            self.addObject(layer, obj) 
+        if obj:
+            self.addObject(layer, obj, obj_type) 
 
     def addPC(self, layer, player_char):
         """Add the PlayerCharacter to the map
@@ -649,12 +650,12 @@
         # For now we copy the PlayerCharacter, 
         # in the future we will need to copy
         # PlayerCharacter specifics between the different PlayerCharacter's
-        self.game_state.player_character = player_char
-        self.game_state.player_character.setup()        
-        self.game_state.player_character.behaviour.speed = self.settings.parpg.PCSpeed
+        self.game_state.getObjectById("PlayerCharacter").fifeagent = player_char
+        self.game_state.getObjectById("PlayerCharacter").fifeagent.setup()        
+        self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.speed = self.settings.parpg.PCSpeed
 
 
-    def addObject(self, layer, obj):
+    def addObject(self, layer, obj, obj_type):
         """Adds an object to the map.
            @type layer: fife.Layer
            @param layer: FIFE layer object exists in
@@ -663,26 +664,27 @@
            @type instance: fife.Instance
            @param instance: FIFE instance of object
            @return: None"""
-        ref = self.game_state.getObjectById(obj.ID, \
+        ref = self.game_state.getObjectById(obj.fifeagent.identifier,
                                             self.game_state.current_map_name) 
         if ref is None:
             # no, add it to the game state
             self.game_state.addObject(self.game_state.current_map_name, obj)
         else:
             # yes, use the current game state data
-            obj.X = ref.X
-            obj.Y = ref.Y
-            obj.gfx = ref.gfx  
+            obj.fifeagent.pos.X = ref.X
+            obj.fifeagent.pos.Y = ref.Y
+            obj.fifeagent.gfx = ref.gfx  
              
-        if obj.trueAttr("NPC"):
+        if obj_type == "Character":
+            obj.fifeagent.behaviour.parent = obj
             # create the agent
-            obj.setup()
-            obj.behaviour.speed = self.settings.parpg.PCSpeed - 1
+            #obj.setup()
+            #obj.behaviour.speed = self.settings.parpg.PCSpeed
             # create the PlayerCharacter agent
-            obj.start()
-        if obj.trueAttr("AnimatedContainer"):
+            #obj.start()
+        #if obj.trueAttr("AnimatedContainer"):
             # create the agent
-            obj.setup()
+            #obj.setup()
 
     def objectActive(self, ident):
         """Given the objects ID, pass back the object if it is active,
@@ -693,7 +695,7 @@
            @return: Status of result (True/False)"""
         for game_object in \
            self.game_state.getObjectsFromMap(self.game_state.current_map_name):
-            if (game_object.ID == ident):
+            if (game_object.fifeagent.identifier == ident):
                 # we found a match
                 return game_object
         # no match
@@ -705,9 +707,9 @@
            @param position: Screen position to move to
            @return: None"""
         if(self.pc_run == 1):
-            self.game_state.player_character.run(position)
+            self.game_state.getObjectById("PlayerCharacter").fifeagent.run(position)
         else:
-            self.game_state.player_character.walk(position)
+            self.game_state.getObjectById("PlayerCharacter").fifeagent.walk(position)
         
     def teleportAgent(self, agent, position):
         """Code called when an agent should teleport to another location
--- a/gamescenecontroller.py	Tue Sep 06 15:21:36 2011 +0200
+++ b/gamescenecontroller.py	Tue Sep 06 15:22:51 2011 +0200
@@ -240,7 +240,7 @@
                                     .getExactLayerCoordinates()
                 commands = ({"Command": "ResetMouseCursor"}, 
                             {"Command": "StopDragging"})
-                self.model.game_state.player_character.approach([coord.x, 
+                self.model.game_state.getObjectById("PlayerCharacter").fifeagent.approach([coord.x, 
                                                                  coord.y],
                                     DropItemAction(self, 
                                                    data_drag.dragged_item, 
@@ -327,8 +327,8 @@
         if self.model.map_change:
             self.pause(True)
             if self.model.active_map:
-                player_char = self.model.game_state.player_character
-                self.model.game_state.player_character = None
+                player_char = self.model.game_state.getObjectById("PlayerCharacter").fifeagent
+                self.model.game_state.getObjectById("PlayerCharacter").fifeagent = None
                 pc_agent = self.model.agents[self.model.ALL_AGENTS_KEY]\
                                                 ["PlayerCharacter"]
                 pc_agent.update(player_char.getStateForSaving())
@@ -346,7 +346,7 @@
             self.model.readAgentsOfMap(self.model.target_map_name)
             
             self.model.placeAgents(self)
-            self.model.placePC()
+            self.model.placePC(self)
             self.model.map_change = False
             # The PlayerCharacter has an inventory, and also some 
             # filling of the ready slots in the HUD. 
@@ -411,7 +411,7 @@
         npc = self.model.game_state.getObjectById(npc_info.ID,
                                             self.model.game_state.\
                                                 current_map_name)
-        self.model.game_state.player_character.approach([npc.getLocation().\
+        self.model.game_state.getObjectById("PlayerCharacter").fifeagent.approach([npc.getLocation().\
                                      getLayerCoordinates().x,
                                      npc.getLocation().\
                                      getLayerCoordinates().y],
@@ -445,7 +445,7 @@
                 # is it a Door?
                 if obj.trueAttr("door"):
                     actions.append(["Change Map", "Change Map",
-                       self.model.game_state.player_character.approach, 
+                       self.model.game_state.getObjectById("PlayerCharacter").fifeagent.approach, 
                        [obj.X, obj.Y],
                        ChangeMapAction(self, obj.target_map_name,
                                        obj.target_pos)])
--- a/gamesceneview.py	Tue Sep 06 15:21:36 2011 +0200
+++ b/gamesceneview.py	Tue Sep 06 15:22:51 2011 +0200
@@ -62,7 +62,7 @@
     def onWalk(self, click):
         """Callback sample for the context menu."""
         self.hud.hideContainer()
-        self.model.game_state.player_character.run(click)
+        self.model.game_state.getObjectById("PlayerCharacter").fifeagent.run(click)
 
     def refreshTopLayerTransparencies(self):
         """Fade or unfade TopLayer instances if the PlayerCharacter 
@@ -72,7 +72,7 @@
 
         # get the PlayerCharacter's screen coordinates
         camera = self.model.active_map.cameras[self.model.active_map.my_cam_id]
-        point = self.model.game_state.player_character.\
+        point = self.model.game_state.getObjectById("PlayerCharacter").fifeagent.\
                                         behaviour.agent.getLocation()
         scr_coords = camera.toScreenCoordinates(point.getMapCoordinates())
 
@@ -123,7 +123,7 @@
                     item = self.model.objectActive(self.highlight_obj)
                     if item is not None:
                         self.displayObjectText(self.highlight_obj, 
-                                                    item.name)
+                                                    item.description.view_name)
             else:
                 self.model.active_map.outline_renderer.removeAllOutlines()
                 self.highlight_obj = None  
--- a/gamestate.py	Tue Sep 06 15:21:36 2011 +0200
+++ b/gamestate.py	Tue Sep 06 15:22:51 2011 +0200
@@ -36,7 +36,7 @@
         @type object: GameObject
         @type map_id: str or None
         """
-        object_id = game_object.ID
+        object_id = game_object.fifeagent.identifier
         if not self.object_ids.has_key(object_id):
             if map_id:
                 self.objects[map_id][object_id] = game_object
--- a/gui/hud.py	Tue Sep 06 15:21:36 2011 +0200
+++ b/gui/hud.py	Tue Sep 06 15:22:51 2011 +0200
@@ -163,7 +163,7 @@
 #            'toggleInventoryButton': self.toggleInventoryButton,
 #        }
 #        self.inventory_storage = \
-#            self.model.game_state.player_character.inventory
+#            self.model.game_state.getObjectById("PlayerCharacter").fifeagent.inventory
 #        if self.inventory == None:
 #            self.inventory = inventorygui.InventoryGUI(self.controller,
 #                                                       self.inventory_storage,
@@ -508,5 +508,5 @@
                     self.controller,
                     npc,
                     self.model.game_state.quest_engine,
-                    self.model.game_state.player_character)
+                    self.model.game_state.getObjectById("PlayerCharacter").fifeagent)
         return dialogue
--- a/objects/action.py	Tue Sep 06 15:21:36 2011 +0200
+++ b/objects/action.py	Tue Sep 06 15:22:51 2011 +0200
@@ -289,7 +289,7 @@
     def execute(self):
         """Talk with the NPC when close enough, otherwise move closer.
            @return: None"""
-        player_char = self.model.game_state.player_character
+        player_char = self.model.game_state.getObjectById("PlayerCharacter").fifeagent
         npc_coordinates = self.npc.getLocation().getLayerCoordinates()
         pc_coordinates = player_char.behaviour.agent.\
                             getLocation().getLayerCoordinates()
@@ -320,8 +320,8 @@
             else:
                 self.npc.behaviour.agent.say("Leave me alone!", 1000)
                 
-            self.model.game_state.player_character.behaviour.idle()
-            self.model.game_state.player_character.nextAction = None
+            self.model.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.idle()
+            self.model.game_state.getObjectById("PlayerCharacter").fifeagent.nextAction = None
             super(TalkAction, self).execute()
 
 class UseAction(Action):
@@ -369,7 +369,7 @@
     def execute(self):
         real_item = self.map_item.item
         self.model.deleteObject(self.map_item.ID)
-        self.model.game_state.player_character.\
+        self.model.game_state.getObjectById("PlayerCharacter").fifeagent.\
                                 inventory.placeItem(real_item)
         self.view.hud.inventory.updateInventoryButtons()
         super(PickUpAction, self).execute()
@@ -387,7 +387,7 @@
         map_item_values["ObjectType"] = "MapItem"
         map_item_values["ItemType"] = self.item.item_type
         map_item_values["Map"] = map_name
-        coords = self.model.game_state.player_character.\
+        coords = self.model.game_state.getObjectById("PlayerCharacter").fifeagent.\
                                         getLocation().getExactLayerCoordinates()
         map_item_values["Position"] = (coords.x, coords.y)
         map_item_values["Rotation"] = 0
@@ -424,7 +424,7 @@
         has_fruit = False
         has_wood = False
         has_bottle = False
-        player_character = self.model.game_state.player_character
+        player_character = self.model.game_state.getObjectById("PlayerCharacter").fifeagent
         for item in self.pot.items.itervalues():
             if item.item_type == "Questionable water":
                 if has_water: