annotate gamemodel.py @ 105:dc573ac08355

Fixed graphical representation of lockables, that are open, when creating the agent.
author KarstenBock@gmx.net
date Fri, 30 Sep 2011 14:11:02 +0200
parents 824f3068ef2a
children edadf3ff8a9a
rev   line source
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
1 # This file is part of PARPG.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
2
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
3 # PARPG is free software: you can redistribute it and/or modify
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
6 # (at your option) any later version.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
7
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
8 # PARPG is distributed in the hope that it will be useful,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
11 # GNU General Public License for more details.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
12
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
15
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
16 # there should be NO references to FIFE here!
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
17 import sys
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
18 import os.path
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
19 import logging
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
20 from copy import deepcopy
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
21
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
22 from fife import fife
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
23 from fife.extensions.serializers.xmlobject import XMLObjectLoader
65
e856b604b650 Changed "import bGrease" to "import parpg.bGrease".
KarstenBock@gmx.net
parents: 61
diff changeset
24 from parpg.bGrease.geometry import Vec2d
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
25
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
26 from parpg import vfs
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
27 from gamestate import GameState
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
28 from gamemap import GameMap
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
29 from common.utils import locateFiles
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
30 from common.utils import parseBool
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
31 from parpg.dialogueparsers import YamlDialogueParser, DialogueFormatError
39
3011bc71ab20 Added funcionality to load Entities from file
KarstenBock@gmx.net
parents: 2
diff changeset
32 from parpg.entities import createEntity
3011bc71ab20 Added funcionality to load Entities from file
KarstenBock@gmx.net
parents: 2
diff changeset
33 from parpg import behaviours
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
34 from parpg import components
75
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
35 from parpg.components import fifeagent, container, equip
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
36
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
37 try:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
38 import xml.etree.cElementTree as ElementTree
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
39 except ImportError:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
40 import xml.etree.ElementTree as ElementTree
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
41
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
42 import yaml
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
43
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
44 logger = logging.getLogger('gamemodel')
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
45
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
46 class GameModel(object):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
47 """GameModel holds the logic for the game.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
48 Since some data (object position and so forth) is held in the
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
49 fife, and would be pointless to replicate, we hold a instance of
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
50 the fife view here. This also prevents us from just having a
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
51 function heavy controller."""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
52 ALL_AGENTS_KEY = "All"
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
53 MAX_ID_NUMBER = 1000
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
54
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
55 def __init__(self, engine, settings):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
56 """Initialize the instance.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
57 @param engine: A fife.Engine object
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
58 @type emgome: fife.Engine
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
59 @param setting: The applications settigns
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
60 @type setting: parpg.settings.Settings object
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
61 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
62 self.settings = settings
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
63
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
64 self.map_change = False
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
65 self.load_saver = False
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
66 self.savegame = None
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
67 quests_directory = settings.parpg.QuestsPath
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
68 self.game_state = GameState(quests_dir=quests_directory)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
69 #self.game_state.quest_engine =
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
70 #self.game_state.quest_engine.readQuests()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
71 self.pc_run = 1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
72 self.target_position = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
73 self.target_map_name = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
74 self.object_db = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
75 self.active_map = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
76 self.map_files = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
77 self.agents = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
78 self.agents[self.ALL_AGENTS_KEY] = {}
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
79 self.items = {}
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
80 self.engine = engine
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
81 self.fife_model = engine.getModel()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
82
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
83 # set values from settings
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
84 maps_directory = settings.parpg.MapsPath
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
85 self.game_state.maps_file = '/'.join([maps_directory,
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
86 settings.parpg.MapsFile])
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
87 self.all_agents_file = '/'.join([maps_directory,
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
88 settings.parpg.AllAgentsFile])
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
89 objects_directory = self.settings.parpg.ObjectsPath
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
90 self.objects_directory = objects_directory
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
91 self.object_db_file = '/'.join([objects_directory,
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
92 settings.parpg.ObjectDatabaseFile])
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
93 self.dialogue_directory = settings.parpg.DialoguesPath
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
94 self.dialogues = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
95 self.agent_import_files = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
96 self.obj_loader = XMLObjectLoader(
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
97 self.engine.getImagePool(),
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
98 self.engine.getAnimationPool(),
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
99 self.engine.getModel(),
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
100 self.engine.getVFS()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
101 )
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
102
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
103 def checkAttributes(self, attributes, template):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
104 """Checks for attributes that where not given in the map file
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
105 and fills them with values from the object database
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
106 @param attributes: attributes to check
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
107 @type attributes: Dictionary
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
108 @param template: Template from which the values will be used
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
109 @return: The modified attributes"""
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
110 if self.object_db.has_key(template):
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
111 db_attributes = deepcopy(self.object_db[template])
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
112 for key in db_attributes.keys():
83
43e7a8d94446 Fixed bug in checkAttributes that caused that values where not correctly set from the Template.
KarstenBock@gmx.net
parents: 78
diff changeset
113 if attributes.has_key(key):
43e7a8d94446 Fixed bug in checkAttributes that caused that values where not correctly set from the Template.
KarstenBock@gmx.net
parents: 78
diff changeset
114 tmp_attributes = db_attributes[key]
43e7a8d94446 Fixed bug in checkAttributes that caused that values where not correctly set from the Template.
KarstenBock@gmx.net
parents: 78
diff changeset
115 tmp_attributes.update(attributes[key])
43e7a8d94446 Fixed bug in checkAttributes that caused that values where not correctly set from the Template.
KarstenBock@gmx.net
parents: 78
diff changeset
116 attributes[key] = tmp_attributes
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
117 else:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
118 attributes[key] = db_attributes[key]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
119 return attributes
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
120
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
121 def isIDUsed(self, ID):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
122 if self.game_state.hasObject(ID):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
123 return True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
124 for namespace in self.agents:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
125 if ID in self.agents[namespace]:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
126 return True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
127 return False
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
128
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
129 def createUniqueID(self, ID):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
130 if self.isIDUsed(ID):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
131 id_number = 1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
132 while self.isIDUsed(ID + "_" + str(id_number)):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
133 id_number += 1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
134 if id_number > self.MAX_ID_NUMBER:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
135 raise ValueError(
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
136 "Number exceeds MAX_ID_NUMBER:" + str(self.MAX_ID_NUMBER))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
137
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
138 ID = ID + "_" + str(id_number)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
139 return ID
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
140
84
bb9e2f2548c6 Added moveObject method to the GameModel class.
KarstenBock@gmx.net
parents: 83
diff changeset
141 def moveObject(self, object_id, new_map):
bb9e2f2548c6 Added moveObject method to the GameModel class.
KarstenBock@gmx.net
parents: 83
diff changeset
142 """Moves the object to a new map, or in a container
bb9e2f2548c6 Added moveObject method to the GameModel class.
KarstenBock@gmx.net
parents: 83
diff changeset
143 @param object_id: ID of the object
bb9e2f2548c6 Added moveObject method to the GameModel class.
KarstenBock@gmx.net
parents: 83
diff changeset
144 @type object_id: str
bb9e2f2548c6 Added moveObject method to the GameModel class.
KarstenBock@gmx.net
parents: 83
diff changeset
145 @param new_map: ID of the new map, or None
bb9e2f2548c6 Added moveObject method to the GameModel class.
KarstenBock@gmx.net
parents: 83
diff changeset
146 @type object_id: str """
101
824f3068ef2a Fixed Saving and Loading.
KarstenBock@gmx.net
parents: 100
diff changeset
147 game_object = self.deleteObject(object_id)
84
bb9e2f2548c6 Added moveObject method to the GameModel class.
KarstenBock@gmx.net
parents: 83
diff changeset
148 self.game_state.addObject(object_id, new_map, game_object)
bb9e2f2548c6 Added moveObject method to the GameModel class.
KarstenBock@gmx.net
parents: 83
diff changeset
149
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
150 def deleteObject(self, object_id):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
151 """Removes an object from the game
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
152 @param object_id: ID of the object
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
153 @type object_id: str """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
154 del self.agents["All"][object_id]
101
824f3068ef2a Fixed Saving and Loading.
KarstenBock@gmx.net
parents: 100
diff changeset
155 return self.game_state.deleteObject(object_id)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
156
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
157 def save(self, path, filename):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
158 """Writes the saver to a file.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
159 @type filename: string
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
160 @param filename: the name of the file to write to
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
161 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
162 fname = '/'.join([path, filename])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
163 try:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
164 save_file = open(fname, 'w')
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
165 except(IOError):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
166 sys.stderr.write("Error: Can't create save game: " + fname + "\n")
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
167 return
101
824f3068ef2a Fixed Saving and Loading.
KarstenBock@gmx.net
parents: 100
diff changeset
168
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
169 save_state = {}
101
824f3068ef2a Fixed Saving and Loading.
KarstenBock@gmx.net
parents: 100
diff changeset
170 save_state["Agents"] = self.agents
824f3068ef2a Fixed Saving and Loading.
KarstenBock@gmx.net
parents: 100
diff changeset
171 save_state["Items"] = self.items
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
172 save_state["GameState"] = self.game_state.getStateForSaving()
101
824f3068ef2a Fixed Saving and Loading.
KarstenBock@gmx.net
parents: 100
diff changeset
173
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
174 yaml.dump(save_state, save_file)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
175
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
176 save_file.close()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
177
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
178 def load(self, path, filename):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
179 """Loads a saver from a file.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
180 @type filename: string
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
181 @param filename: the name of the file (including path) to load from
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
182 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
183 fname = '/'.join([path, filename])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
184
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
185 try:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
186 load_file = open(fname, 'r')
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
187 except(IOError):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
188 sys.stderr.write("Error: Can't find save game file\n")
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
189 return
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
190 self.deleteMaps()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
191 self.clearAgents()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
192
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
193 save_state = yaml.load(load_file)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
194 self.game_state.restoreFromState(save_state["GameState"])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
195 maps = save_state["Agents"]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
196 for map_name in maps:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
197 for agent_name in maps[map_name]:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
198 agent = {agent_name:maps[map_name][agent_name]}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
199 self.addAgent(map_name, agent)
101
824f3068ef2a Fixed Saving and Loading.
KarstenBock@gmx.net
parents: 100
diff changeset
200 self.items = save_state["Items"]
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
201
101
824f3068ef2a Fixed Saving and Loading.
KarstenBock@gmx.net
parents: 100
diff changeset
202 load_file.close()
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
203
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
204 def teleport(self, agent, position):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
205 """Called when a an agent is moved instantly to a new position.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
206 The setting of position may wan to be created as its own method down the road.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
207 @type position: String Tuple
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
208 @param position: X,Y coordinates passed from engine.changeMap
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
209 @return: fife.Location"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
210 logging.debug(position)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
211 coord = fife.DoublePoint3D(float(position[0]), float(position[1]), 0)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
212 location = fife.Location(self.active_map.agent_layer)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
213 location.setMapCoordinates(coord)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
214 agent.teleport(location)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
215
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
216 def getObjectAtCoords(self, coords):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
217 """Get the object which is at the given coords
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
218 @type coords: fife.Screenpoint
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
219 @param coords: Coordinates where to check for an object
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
220 @rtype: fife.Object
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
221 @return: An object or None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
222 instances = self.active_map.cameras[
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
223 self.active_map.my_cam_id].\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
224 getMatchingInstances(coords, self.active_map.agent_layer)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
225 # no object returns an empty tuple
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
226 if(instances != ()):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
227 front_y = 0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
228
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
229
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
230 for obj in instances:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
231 # check to see if this in our list at all
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
232 if(self.objectActive(obj.getId())):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
233 # check if the object is on the foreground
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
234 obj_map_coords = \
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
235 obj.getLocation().getMapCoordinates()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
236 obj_screen_coords = self.active_map.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
237 cameras[self.active_map.my_cam_id]\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
238 .toScreenCoordinates(obj_map_coords)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
239
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
240 if obj_screen_coords.y > front_y:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
241 #Object on the foreground
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
242 front_y = obj_screen_coords.y
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
243 return obj
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
244 else:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
245 return None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
246 else:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
247 return None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
248
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
249 def getCoords(self, click):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
250 """Get the map location x, y coordinates from the screen coordinates
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
251 @type click: fife.ScreenPoint
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
252 @param click: Screen coordinates
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
253 @rtype: fife.Location
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
254 @return: The map coordinates"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
255 coord = self.active_map.cameras[self.active_map.my_cam_id].\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
256 toMapCoordinates(click, False)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
257 coord.z = 0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
258 location = fife.Location(self.active_map.agent_layer)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
259 location.setMapCoordinates(coord)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
260 return location
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
261
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
262 def pause(self, paused):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
263 """ Pause/Unpause the game
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
264 @return: nothing"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
265 if self.active_map:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
266 self.active_map.pause(paused)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
267
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
268 def togglePause(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
269 """ Toggle paused state.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
270 @return: nothing"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
271 self.active_map.togglePause()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
272
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
273 def isPaused(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
274 """Returns wheter the game is paused or not"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
275 return self.active_map.isPaused()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
276
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
277 def readMapFiles(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
278 """Read all a available map-files and store them"""
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
279 maps_file = vfs.VFS.open(self.game_state.maps_file)
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
280 self.map_files = yaml.load(maps_file)["Maps"]
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
281
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
282 def addAgent(self, namespace, agent):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
283 """Adds an agent to the agents dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
284 @param namespace: the namespace where the agent is to be added to
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
285 @type namespace: str
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
286 @param agent: The agent to be added
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
287 @type agent: dict """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
288 from fife.extensions.serializers.xml_loader_tools import loadImportFile
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
289 if not self.agents.has_key(namespace):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
290 self.agents[namespace] = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
291
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
292 agent_values = agent.values()[0]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
293 unique_agent_id = self.createUniqueID(agent.keys()[0])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
294 del agent[agent.keys()[0]]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
295 agent[unique_agent_id] = agent_values
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
296 self.agents[namespace].update(agent)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
297 object_model = ""
92
84b5808d995c Added Graphics component.
KarstenBock@gmx.net
parents: 90
diff changeset
298 if agent_values["Entity"].has_key("graphics") \
84b5808d995c Added Graphics component.
KarstenBock@gmx.net
parents: 90
diff changeset
299 and agent_values["Entity"]["graphics"].has_key("gfx"):
84b5808d995c Added Graphics component.
KarstenBock@gmx.net
parents: 90
diff changeset
300 object_model = agent_values["Entity"]["graphics"]["gfx"]
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
301 else:
92
84b5808d995c Added Graphics component.
KarstenBock@gmx.net
parents: 90
diff changeset
302 object_model = self.object_db[agent_values["Template"]]["graphics"]["gfx"]
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
303 import_file = self.agent_import_files[object_model]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
304 loadImportFile(self.obj_loader, import_file, self.engine)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
305
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
306 def readAgentsOfMap(self, map_name):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
307 """Read the agents of the map
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
308 @param map_name: Name of the map
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
309 @type map_name: str """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
310 #Get the agents of the map
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
311 map_agents_file = self.map_files[map_name].\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
312 replace(".xml", "_agents.yaml")
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
313 agents_data = vfs.VFS.open(map_agents_file)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
314 agents = yaml.load_all(agents_data)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
315 for agent in agents:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
316 if not agent == None:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
317 self.addAgent(map_name, agent)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
318
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
319 def readAllAgents(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
320 """Read the agents of the all_agents_file and store them"""
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
321 agents_file = vfs.VFS.open(self.all_agents_file)
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
322 agents = yaml.load_all(agents_file)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
323 for agent in agents:
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
324 if agent is not None:
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
325 self.addAgent(self.ALL_AGENTS_KEY, agent)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
326
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
327 def getAgentsOfMap(self, map_name):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
328 """Returns the agents that are on the given map
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
329 @param map_name: Name of the map
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
330 @type map_name: str
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
331 @return: A dictionary with the agents of the map"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
332 if not self.agents.has_key(map_name):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
333 return {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
334 ret_dict = self.agents[map_name].copy()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
335 for agent_name, agent_value in self.agents[self.ALL_AGENTS_KEY]\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
336 .iteritems():
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
337 if agent_value["Map"] == map_name:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
338 ret_dict[agent_name] = agent_value
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
339 return ret_dict
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
340
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
341 def getAgentsOfActiveMap(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
342 """Returns the agents that are on active map
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
343 @return: A dictionary with the agents of the map """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
344 return self.getAgentsOfMap(self.active_map.map.getId())
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
345
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
346 def clearAgents(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
347 """Resets the agents dictionary"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
348 self.agents = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
349 self.agents[self.ALL_AGENTS_KEY] = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
350
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
351 def loadMap(self, map_name):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
352 """Load a new map.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
353 @type map_name: string
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
354 @param map_name: Name of the map to load
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
355 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
356 if not map_name in self.game_state.maps:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
357 map_file = self.map_files[map_name]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
358 new_map = GameMap(self.engine, self)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
359 self.game_state.maps[map_name] = new_map
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
360 new_map.load(map_file)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
361
39
3011bc71ab20 Added funcionality to load Entities from file
KarstenBock@gmx.net
parents: 2
diff changeset
362 def createAgent(self, agent, inst_id, world):
99
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
363 if self.game_state.hasObject(inst_id):
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
364 return None
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
365 entity_data = deepcopy(agent["Entity"])
92
84b5808d995c Added Graphics component.
KarstenBock@gmx.net
parents: 90
diff changeset
366 entity_data["fifeagent"] = {}
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
367 if agent.has_key("Template"):
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
368 entity_data = self.checkAttributes(entity_data, agent["Template"])
92
84b5808d995c Added Graphics component.
KarstenBock@gmx.net
parents: 90
diff changeset
369 object_id = entity_data["graphics"]["gfx"] \
84b5808d995c Added Graphics component.
KarstenBock@gmx.net
parents: 90
diff changeset
370 if entity_data["graphics"].has_key("gfx") \
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
371 else "generic_item"
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
372 map_obj = self.fife_model.getObject(str(object_id), "PARPG")
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
373 if not map_obj:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
374 logging.warning("Object with inst_id={0}, ns=PARPG, "
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
375 "could not be found. "
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
376 "Omitting...".format(str(object_id)))
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
377
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
378 x_pos = agent["Position"][0]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
379 y_pos = agent["Position"][1]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
380 z_pos = agent["Position"][2] if len(agent["Position"]) == 3 \
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
381 else 0.0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
382 stack_pos = agent["Stackposition"] if \
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
383 agent.has_key("StackPosition") \
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
384 else None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
385 inst = self.active_map.agent_layer.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
386 createInstance(map_obj,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
387 fife.ExactModelCoordinate(x_pos,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
388 y_pos,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
389 z_pos),
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
390 inst_id)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
391 inst.setId(inst_id)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
392
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
393 rotation = agent["Rotation"]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
394 inst.setRotation(rotation)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
395
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
396 fife.InstanceVisual.create(inst)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
397 if (stack_pos):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
398 inst.get2dGfxVisual().setStackPosition(int(stack_pos))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
399
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
400 if (map_obj.getAction('default')):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
401 target = fife.Location(self.active_map.agent_layer)
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
402 inst.act('default', target, True)
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
403
90
4a8a0cd7f79a Added Behaviour component.
KarstenBock@gmx.net
parents: 89
diff changeset
404 if entity_data.has_key("behaviour"):
4a8a0cd7f79a Added Behaviour component.
KarstenBock@gmx.net
parents: 89
diff changeset
405 entity_data["fifeagent"]["behaviour"] = \
4a8a0cd7f79a Added Behaviour component.
KarstenBock@gmx.net
parents: 89
diff changeset
406 getattr(behaviours,
4a8a0cd7f79a Added Behaviour component.
KarstenBock@gmx.net
parents: 89
diff changeset
407 entity_data["behaviour"]["behaviour_type"])()
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
408 else:
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
409 entity_data["fifeagent"]["behaviour"] = behaviours.Base()
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
410 if self.dialogues.has_key(inst_id):
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
411 entity_data["dialogue"] = {}
75
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
412 entity_data["dialogue"]["dialogue"] = self.dialogues[inst_id]
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
413
86
a9cc5559ec2a Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents: 84
diff changeset
414 obj = self.createMapObject(self.active_map.agent_layer, entity_data, inst_id, world)
75
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
415
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
416 if agent.has_key("Inventory"):
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
417 inv = agent["Inventory"]
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
418 slots = inv["Slots"]
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
419 obj.container.children = list()
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
420 for x in xrange(slots):
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
421 obj.container.children.append(None)
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
422 items = inv["Items"] if inv.has_key("Items") else list()
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
423 for data in items:
99
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
424 item = None
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
425 if data.has_key("type"):
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
426 item_type = data["type"]
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
427 item_data = {}
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
428 item_data = self.checkAttributes(item_data, item_type)
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
429 if item_data.has_key("containable"):
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
430 item = self.create_item(
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
431 self.createUniqueID(data["ID"]),
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
432 item_data, world, item_type)
99
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
433 else:
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
434 raise Exception("Item %s is not containable." % item_type)
75
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
435 else:
99
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
436 identifier = data["ID"]
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
437 if self.game_state.hasObject(identifier):
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
438 item = self.game_state.getObjectById(identifier)
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
439 else:
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
440 item_data = self.items[identifier]["Entity"]
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
441 item_type = item_data["containable"]["item_type"]
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
442 item = self.create_item(identifier, item_data,
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
443 world, item_type)
99
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
444
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
445 container.put_item(obj.container, item.containable)
75
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
446
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
447 if agent.has_key("Equipment"):
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
448 for slot, data in agent["Equipment"].iteritems():
99
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
449 item = None
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
450 if data.has_key("type"):
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
451 item_type = data["type"]
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
452 item_data = {}
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
453 item_data = self.checkAttributes(item_data, item_type)
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
454 if item_data.has_key("containable") and item_data.has_key("equipable"):
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
455 item = self.create_item(
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
456 self.createUniqueID(data["ID"]),
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
457 item_data, world, item_type)
99
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
458 else:
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
459 raise Exception("Item %s is not containable or equipable." % item_type)
75
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
460 else:
99
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
461 identifier = data["ID"]
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
462 if self.game_state.hasObject(identifier):
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
463 item = self.game_state.getObjectById(identifier)
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
464 else:
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
465 item_data = self.items[identifier]["Entity"]
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
466 item_type = item_data["containable"]["item_type"]
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
467 item = self.create_item(identifier, item_data,
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
468 world, item_type)
99
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
469 equip.equip(obj.equip, item.equipable, slot)
105
dc573ac08355 Fixed graphical representation of lockables, that are open, when creating the agent.
KarstenBock@gmx.net
parents: 101
diff changeset
470 if (obj.fifeagent and (obj.lockable and not obj.lockable.closed)):
dc573ac08355 Fixed graphical representation of lockables, that are open, when creating the agent.
KarstenBock@gmx.net
parents: 101
diff changeset
471 obj.fifeagent.behaviour.animate("opened", repeating=True)
99
6e4daff93e7d If Items in containers or being equipped have no type the game will now try to get the object using the ID.
KarstenBock@gmx.net
parents: 98
diff changeset
472 return obj
78
a57ec730e753 Fixed item_type not being set when creating items.
KarstenBock@gmx.net
parents: 76
diff changeset
473
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
474 def create_item(self, identifier, item_data, world, item_type):
86
a9cc5559ec2a Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents: 84
diff changeset
475 item = createEntity(item_data, identifier, world, None)
78
a57ec730e753 Fixed item_type not being set when creating items.
KarstenBock@gmx.net
parents: 76
diff changeset
476 item.containable.item_type = item_type
86
a9cc5559ec2a Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents: 84
diff changeset
477 self.game_state.addObject(identifier, None, item)
78
a57ec730e753 Fixed item_type not being set when creating items.
KarstenBock@gmx.net
parents: 76
diff changeset
478 return item
75
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
479
39
3011bc71ab20 Added funcionality to load Entities from file
KarstenBock@gmx.net
parents: 2
diff changeset
480 def placeAgents(self, world):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
481 """Places the current maps agents """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
482 if not self.active_map:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
483 return
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
484 agents = self.getAgentsOfMap(self.game_state.current_map_name)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
485 for agent in agents:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
486 if agent == "PlayerCharacter":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
487 continue
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
488 if self.active_map.agent_layer.getInstances(agent):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
489 continue
39
3011bc71ab20 Added funcionality to load Entities from file
KarstenBock@gmx.net
parents: 2
diff changeset
490 self.createAgent(agents[agent], agent, world)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
491
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
492 def placePC(self, world):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
493 """Places the PlayerCharacter on the map"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
494 agent = self.agents[self.ALL_AGENTS_KEY]["PlayerCharacter"]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
495 inst_id = "PlayerCharacter"
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
496 self.createAgent(agent, inst_id, world)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
497
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
498 # create the PlayerCharacter agent
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
499 self.active_map.addPC()
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
500 #self.game_state.getObjectById("PlayerCharacter").fifeagent.start()
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
501 if agent.has_key("PeopleKnown"):
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
502 self.game_state.getObjectById("PlayerCharacter").fifeagent.people_i_know = agent["PeopleKnown"]
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
503
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
504 def changeMap(self, map_name, target_position = None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
505 """Registers for a map change on the next pump().
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
506 @type map_name: String
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
507 @param map_name: Id of the map to teleport to
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
508 @type map_file: String
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
509 @param map_file: Filename of the map to teleport to
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
510 @type target_position: Tuple
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
511 @param target_position: Position of PlayerCharacter on target map.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
512 @return None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
513 # set the parameters for the map change if moving to a new map
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
514 if map_name != self.game_state.current_map_name:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
515 self.target_map_name = map_name
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
516 self.target_position = target_position
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
517 # issue the map change
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
518 self.map_change = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
519
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
520 def deleteMaps(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
521 """Clear all currently loaded maps from FIFE as well as clear our
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
522 local map cache
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
523 @return: nothing"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
524 self.engine.getModel().deleteMaps()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
525 self.engine.getModel().deleteObjects()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
526 self.game_state.clearObjects()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
527 self.game_state.maps = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
528
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
529 def setActiveMap(self, map_name):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
530 """Sets the active map that is to be rendered.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
531 @type map_name: String
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
532 @param map_name: The name of the map to load
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
533 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
534 # Turn off the camera on the old map before we turn on the camera
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
535 # on the new map.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
536 self.active_map.cameras[self.active_map.my_cam_id].setEnabled(False)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
537 # Make the new map active.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
538 self.active_map = self.game_state.maps[map_name]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
539 self.active_map.makeActive()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
540 self.game_state.current_map_name = map_name
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
541
86
a9cc5559ec2a Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents: 84
diff changeset
542 def createMapObject (self, layer, attributes, inst_id, world):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
543 """Create an object and add it to the current map.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
544 @type layer: fife.Layer
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
545 @param layer: FIFE layer object exists in
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
546 @type attributes: Dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
547 @param attributes: Dictionary of all object attributes
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
548 @type instance: fife.Instance
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
549 @param instance: FIFE instance corresponding to the object
75
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
550 @return: The created object"""
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
551 # create the extra data
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
552 extra = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
553 if layer is not None:
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
554 extra['fifeagent'] = {}
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
555 extra['fifeagent']['layer'] = layer
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
556
86
a9cc5559ec2a Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents: 84
diff changeset
557 obj = createEntity(attributes, inst_id, world, extra)
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
558 if obj:
75
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
559 self.addObject(layer, obj)
9e03f7816061 (Re)added setting of inventory and equipment in the object files.
KarstenBock@gmx.net
parents: 65
diff changeset
560 return obj
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
561
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
562 def addPC(self, layer, player_char):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
563 """Add the PlayerCharacter to the map
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
564 @type layer: fife.Layer
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
565 @param layer: FIFE layer object exists in
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
566 @type player_char: PlayerCharacter
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
567 @param player_char: PlayerCharacter object
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
568 @type instance: fife.Instance
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
569 @param instance: FIFE instance of PlayerCharacter
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
570 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
571 # For now we copy the PlayerCharacter,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
572 # in the future we will need to copy
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
573 # PlayerCharacter specifics between the different PlayerCharacter's
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
574 self.game_state.getObjectById("PlayerCharacter").fifeagent = player_char
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
575 self.game_state.getObjectById("PlayerCharacter").fifeagent.setup()
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
576 self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.speed = self.settings.parpg.PCSpeed
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
577
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
578
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
579 def addObject(self, layer, obj):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
580 """Adds an object to the map.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
581 @type layer: fife.Layer
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
582 @param layer: FIFE layer object exists in
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
583 @type obj: GameObject
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
584 @param obj: corresponding object class
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
585 @type instance: fife.Instance
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
586 @param instance: FIFE instance of object
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
587 @return: None"""
86
a9cc5559ec2a Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents: 84
diff changeset
588 ref = self.game_state.getObjectById(obj.general.identifier,
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
589 self.game_state.current_map_name)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
590 if ref is None:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
591 # no, add it to the game state
86
a9cc5559ec2a Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents: 84
diff changeset
592 self.game_state.addObject(obj.general.identifier, self.game_state.current_map_name, obj)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
593 else:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
594 # yes, use the current game state data
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
595 obj.fifeagent.pos.X = ref.X
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
596 obj.fifeagent.pos.Y = ref.Y
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
597 obj.fifeagent.gfx = ref.gfx
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
598
61
2727d6b78978 Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents: 57
diff changeset
599 if obj.fifeagent.behaviour:
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
600 obj.fifeagent.behaviour.parent = obj
46
bf506f739322 Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
KarstenBock@gmx.net
parents: 44
diff changeset
601 fifeagent.setup_behaviour(obj.fifeagent)
bf506f739322 Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
KarstenBock@gmx.net
parents: 44
diff changeset
602 obj.fifeagent.behaviour.speed = self.settings.parpg.PCSpeed
bf506f739322 Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
KarstenBock@gmx.net
parents: 44
diff changeset
603 #Start the behaviour
bf506f739322 Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
KarstenBock@gmx.net
parents: 44
diff changeset
604 obj.fifeagent.behaviour.idle()
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
605 # create the agent
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
606 #obj.setup()
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
607 #obj.behaviour.speed = self.settings.parpg.PCSpeed
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
608 # create the PlayerCharacter agent
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
609 #obj.start()
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
610 #if obj.trueAttr("AnimatedContainer"):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
611 # create the agent
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 41
diff changeset
612 #obj.setup()
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
613
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
614 def objectActive(self, ident):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
615 """Given the objects ID, pass back the object if it is active,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
616 False if it doesn't exist or not displayed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
617 @type ident: string
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
618 @param ident: ID of object
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
619 @rtype: boolean
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
620 @return: Status of result (True/False)"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
621 for game_object in \
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
622 self.game_state.getObjectsFromMap(self.game_state.current_map_name):
86
a9cc5559ec2a Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents: 84
diff changeset
623 if (game_object.general.identifier == ident):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
624 # we found a match
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
625 return game_object
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
626 # no match
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
627 return False
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
628
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
629 def movePlayer(self, position):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
630 """Code called when the player should move to another location
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
631 @type position: fife.ScreenPoint
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
632 @param position: Screen position to move to
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
633 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
634 if(self.pc_run == 1):
52
3dfd26b1c7ef Modifications to make the player agent move around by clicking with the mouse.
KarstenBock@gmx.net
parents: 46
diff changeset
635 self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.run(position)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
636 else:
52
3dfd26b1c7ef Modifications to make the player agent move around by clicking with the mouse.
KarstenBock@gmx.net
parents: 46
diff changeset
637 self.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.walk(position)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
638
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
639 def teleportAgent(self, agent, position):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
640 """Code called when an agent should teleport to another location
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
641 @type position: fife.ScreenPoint
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
642 @param position: Screen position to teleport to
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
643 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
644 agent.teleport(position)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
645 self.agents[agent.ID]["Position"] = position
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
646
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
647 def readObjectDB(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
648 """Reads the Object Information Database from a file. """
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
649 database_file = vfs.VFS.open(self.object_db_file)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
650 database = yaml.load_all(database_file)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
651 for object_info in database:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
652 self.object_db.update(object_info)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
653
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
654 def updateObjectDB(self, world):
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
655 """Updates the values in the object database with the worlds values"""
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
656
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
657 for entity in world.entities:
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
658 identifier = entity.general.identifier
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
659 agent_data = {}
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
660 map_id = self.game_state.getMapOfObject(identifier)
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
661 if map_id:
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
662 if self.agents[self.ALL_AGENTS_KEY].has_key(identifier):
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
663 agent_data = self.agents[self.ALL_AGENTS_KEY][identifier]
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
664 else:
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
665 agent_data = self.agents[map_id][identifier]
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
666 else:
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
667 if not self.items.has_key(identifier):
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
668 self.items[identifier] = {}
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
669 agent_data = self.items[identifier]
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
670 entity_data = {}
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
671 entity_data["general"] = {"identifier": identifier}
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
672 for name, component in components.components.iteritems():
90
4a8a0cd7f79a Added Behaviour component.
KarstenBock@gmx.net
parents: 89
diff changeset
673 if getattr(entity, name):
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
674 comp_data = {}
98
c0db5f521695 updateObjectDB of GameModel now uses saveable_fields.
KarstenBock@gmx.net
parents: 92
diff changeset
675 comp_vals = getattr(entity, name)
c0db5f521695 updateObjectDB of GameModel now uses saveable_fields.
KarstenBock@gmx.net
parents: 92
diff changeset
676 #Items that are in containers will be saved with them.
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
677 for field in component.saveable_fields:
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
678 try:
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
679 comp_data[field] = getattr(comp_vals, field)
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
680 except AttributeError:
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
681 #The entity doesn't have this specific value,
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
682 #ignore it
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
683 pass
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
684 if comp_data:
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
685 entity_data[name] = comp_data
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
686 if name == "fifeagent":
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
687 if entity.fifeagent.layer:
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
688 layer = entity.fifeagent.layer
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
689 inst = layer.getInstance(identifier)
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
690 loc = inst.getLocation().getExactLayerCoordinates()
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
691 agent_data["Position"] = (loc.x, loc.y, loc.z)
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
692 agent_data["Map"] = map_id
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
693 agent_data["Rotation"] = inst.getRotation()
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
694 elif name == "container" and hasattr(comp_vals,
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
695 "children"):
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
696 inventory_data = {}
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
697 inventory_data["Slots"] = len(comp_vals.children)
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
698 items = []
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
699 for child in comp_vals.children:
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
700 if not child:
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
701 continue
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
702 items.append(
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
703 {"ID": child.entity.general.identifier}
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
704 )
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
705 inventory_data["Items"] = items
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
706 agent_data["Inventory"] = inventory_data
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
707 elif name == "equip":
100
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
708 equip_data = {}
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
709 for field in component.fields:
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
710 if(hasattr(comp_vals, field)):
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
711 equipable = getattr(comp_vals, field)
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
712 if equipable:
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
713 equip_data[field] = {
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
714 "ID":
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
715 equipable.entity.general.identifier
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
716 }
485d866a847f updateObjectDB now saves equipment and inventory too.
KarstenBock@gmx.net
parents: 99
diff changeset
717 agent_data["Equipment"] = equip_data
88
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
718 agent_data["Entity"] = entity_data
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
719
0411a4bcceee Fixed moving between maps.
KarstenBock@gmx.net
parents: 86
diff changeset
720
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
721 def getAgentImportFiles(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
722 """Searches the agents directory for import files """
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
723 filepaths = locateFiles("*.xml", self.objects_directory)
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
724 for filepath in filepaths:
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
725 try:
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
726 xml_file = vfs.VFS.open(filepath)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
727 root = ElementTree.parse(xml_file).getroot()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
728 if root.tag == "object":
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
729 self.agent_import_files[root.attrib["id"]] = filepath
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
730 except SyntaxError as error:
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
731 logging.error("Error parsing file {0}: {1}".format(filepath,
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
732 error))
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
733
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
734 def getDialogues(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
735 """Searches the dialogue directory for dialogues """
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
736 files = locateFiles("*.yaml", self.dialogue_directory)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
737 dialogue_parser = YamlDialogueParser()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
738 for dialogue_filepath in files:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
739 # Note Technomage 2010-11-13: the new DialogueEngine uses its own
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
740 # parser now, YamlDialogueParser.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
741 # dialogues = yaml.load_all(file(dialogue_file, "r"))
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
742 dialogue_file = vfs.VFS.open(dialogue_filepath)
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
743 try:
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
744 dialogue = dialogue_parser.load(dialogue_file)
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
745 except DialogueFormatError as error:
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
746 logging.error('unable to load dialogue file {0}: {1}'
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
747 .format(dialogue_filepath, error))
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
748 else:
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
749 self.dialogues[dialogue.npc_name] = dialogue
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
750 # Note Technomage 2010-11-13: the below code is used to load
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
751 # multiple dialogues from a single file. Is this functionality
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
752 # used/necessary?
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
753 # for dialogue in dialogues:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
754 # self.dialogues[dialogue["NPC"]] = dialogue