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