Mercurial > parpg-core
annotate src/parpg/gamemodel.py @ 9:01aa59a0efda
This is a test to see if pushing changes to the repo works as intended.
author | Martin Vohland <martin.vohland@googlemail.com> |
---|---|
date | Tue, 31 May 2011 07:37:40 +0200 |
parents | 1fd2201f5c36 |
children | d60f1dab8469 |
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 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
24 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
25 from gamestate import GameState |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
26 from objects import createObject |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
27 from objects.composed import CarryableItem, CarryableContainer |
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 inventory import Inventory |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
32 from parpg.dialogueparsers import YamlDialogueParser, DialogueFormatError |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
33 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
34 try: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
35 import xml.etree.cElementTree as ElementTree |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
36 except ImportError: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
37 import xml.etree.ElementTree as ElementTree |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
38 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
39 import yaml |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
40 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
41 logger = logging.getLogger('gamemodel') |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
42 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
43 class GameModel(object): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
44 """GameModel holds the logic for the game. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 function heavy controller.""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
49 ALL_AGENTS_KEY = "All" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
50 MAX_ID_NUMBER = 1000 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
51 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
52 def __init__(self, engine, settings): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
53 """Initialize the instance. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
54 @param engine: A fife.Engine object |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
55 @type emgome: fife.Engine |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
56 @param setting: The applications settigns |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
57 @type setting: parpg.settings.Settings object |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
58 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
59 self.settings = settings |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
60 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
61 self.map_change = False |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
62 self.load_saver = False |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
63 self.savegame = None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
64 quests_directory = os.path.join(self.settings.system_path, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
65 self.settings.parpg.QuestsPath) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
66 self.game_state = GameState(quests_dir=quests_directory) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
67 #self.game_state.quest_engine = |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
68 #self.game_state.quest_engine.readQuests() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
69 self.pc_run = 1 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
70 self.target_position = None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
71 self.target_map_name = None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
72 self.object_db = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
73 self.active_map = None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
74 self.map_files = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
75 self.agents = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
76 self.agents[self.ALL_AGENTS_KEY] = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
77 self.engine = engine |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
78 self.fife_model = engine.getModel() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
79 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
80 # set values from settings |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
81 maps_file = os.path.join(self.settings.system_path, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
82 self.settings.parpg.MapsPath, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
83 self.settings.parpg.MapsFile) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
84 self.game_state.maps_file = maps_file |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
85 all_agents_file = os.path.join(self.settings.system_path, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
86 self.settings.parpg.MapsPath, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
87 self.settings.parpg.AllAgentsFile) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
88 self.all_agents_file = all_agents_file |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
89 objects_dir = os.path.join(self.settings.system_path, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
90 self.settings.parpg.ObjectsPath) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
91 self.objects_directory = objects_dir |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
92 object_db_file = os.path.join(self.objects_directory, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
93 self.settings.parpg.ObjectDatabaseFile) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
94 self.object_db_file = object_db_file |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
95 dialogues_dir = os.path.join(self.settings.system_path, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
96 self.settings.parpg.DialoguesPath) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
97 self.dialogues_directory = dialogues_dir |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
98 self.dialogues = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
99 self.agent_import_files = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
100 self.obj_loader = XMLObjectLoader( |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
101 self.engine.getImagePool(), |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
102 self.engine.getAnimationPool(), |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
103 self.engine.getModel(), |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
104 self.engine.getVFS() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
105 ) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
106 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
107 def checkAttributes(self, attributes): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
108 """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
|
109 and fills them with values from the object database |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
110 @param attributes: attributes to check |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
111 @type attributes: Dictionary |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
112 @return: The modified attributes""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
113 if attributes.has_key("object_type"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
114 class_name = attributes.pop("object_type") |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
115 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
116 class_name = attributes["type"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
117 if not attributes.has_key("type"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
118 attributes["type"] = class_name |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
119 if self.object_db.has_key(class_name): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
120 db_attributes = deepcopy(self.object_db[class_name]) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
121 for key in db_attributes.keys(): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
122 if attributes.has_key(key): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
123 attributes[key] = attributes[key] or db_attributes[key] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
124 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
125 attributes[key] = db_attributes[key] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
126 return attributes |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
127 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
128 def isIDUsed(self, ID): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
129 if self.game_state.hasObject(ID): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
130 return True |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
131 for namespace in self.agents: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
132 if ID in self.agents[namespace]: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
133 return True |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
134 return False |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
135 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
136 def createUniqueID(self, ID): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
137 if self.isIDUsed(ID): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
138 id_number = 1 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
139 while self.isIDUsed(ID + "_" + str(id_number)): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
140 id_number += 1 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
141 if id_number > self.MAX_ID_NUMBER: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
142 raise ValueError( |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
143 "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
|
144 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
145 ID = ID + "_" + str(id_number) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
146 return ID |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
147 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
148 def createContainerItems(self, container_objs): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
149 """Create the items of a container from a dictionary |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
150 @param container_objs: Dictionary containing the items |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
151 @type container_objs: dict""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
152 items = [] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
153 for container_obj in container_objs: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
154 items.append(self.createContainerObject(container_obj)) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
155 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
156 return items |
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 createContainerObject(self, attributes): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
159 """Create an object that can be stored in |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
160 an container and return it |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
161 @param attributes: Dictionary of all object attributes |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
162 @type attributes: Dictionary |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
163 @return: The created object """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
164 # create the extra data |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
165 extra = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
166 extra['controller'] = self |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
167 attributes = self.checkAttributes(attributes) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
168 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
169 info = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
170 info.update(attributes) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
171 info.update(extra) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
172 ID = info.pop("id") if info.has_key("id") else info.pop("ID") |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
173 if not info.has_key("item_type"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
174 info["item_type"] = info["type"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
175 ID = self.createUniqueID(ID) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
176 if info.has_key("attributes"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
177 attributes = info["attributes"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
178 if "Container" in attributes: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
179 info["actions"]["Open"] = "" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
180 if info.has_key("Items"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
181 inventory_objs = info["Items"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
182 info["items"] = self.createContainerItems(inventory_objs) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
183 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
184 new_item = CarryableContainer(ID = ID, **info) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
185 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
186 new_item = CarryableItem(ID = ID, **info) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
187 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
188 new_item = CarryableItem(ID = ID, **info) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
189 self.game_state.addObject(None, new_item) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
190 return new_item |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
191 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
192 def createInventoryObject(self, container, attributes): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
193 """Create an inventory object and place it into a container |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
194 @type container: base.Container |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
195 @param container: Container where the item is on |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
196 @type attributes: Dictionary |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
197 @param attributes: Dictionary of all object attributes |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
198 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
199 index = attributes.pop("index") if attributes.has_key("index") else None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
200 slot = attributes.pop("slot") if attributes.has_key("slot") else None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
201 obj = self.createContainerObject(attributes) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
202 #obj = createObject(attributes, extra) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
203 if slot: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
204 container.moveItemToSlot(obj, slot) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
205 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
206 container.placeItem(obj, index) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
207 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
208 def deleteObject(self, object_id): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
209 """Removes an object from the game |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
210 @param object_id: ID of the object |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
211 @type object_id: str """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
212 del self.agents["All"][object_id] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
213 self.game_state.deleteObject(object_id) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
214 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
215 def save(self, path, filename): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
216 """Writes the saver to a file. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
217 @type filename: string |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
218 @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
|
219 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
220 fname = '/'.join([path, filename]) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
221 try: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
222 save_file = open(fname, 'w') |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
223 except(IOError): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
224 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
|
225 return |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
226 save_state = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
227 save_state["Agents"] = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
228 for map_name in self.agents: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
229 if map_name == self.ALL_AGENTS_KEY: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
230 continue |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
231 agents_dict = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
232 for agent in self.agents[map_name]: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
233 agent_obj = self.game_state.getObjectById(agent, map_name) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
234 agent_inst = self.game_state.maps[map_name].\ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
235 agent_layer.getInstance(agent) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
236 agent_dict = self.agents[map_name][agent] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
237 agent_dict.update(agent_obj.getStateForSaving()) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
238 agent_dict["Rotation"] = agent_inst.getRotation() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
239 agents_dict[agent] = agent_dict |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
240 save_state["Agents"][map_name] = agents_dict |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
241 agents_dict = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
242 for agent in self.agents["All"]: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
243 map_name = self.agents["All"][agent]["Map"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
244 agent_dict = self.agents["All"][agent] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
245 agent_obj = None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
246 if agent == "PlayerCharacter": |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
247 agent_obj = self.game_state.player_character |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
248 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
249 agent_obj = self.game_state.getObjectById(agent, map_name) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
250 if agent_obj: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
251 agent_inst = self.game_state.maps[map_name].\ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
252 agent_layer.getInstance(agent) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
253 agent_dict.update(agent_obj.getStateForSaving()) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
254 agent_dict["Rotation"] = agent_inst.getRotation() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
255 agent_dict["MapName"] = map_name |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
256 agents_dict[agent] = agent_dict |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
257 save_state["Agents"]["All"] = agents_dict |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
258 save_state["GameState"] = self.game_state.getStateForSaving() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
259 yaml.dump(save_state, save_file) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
260 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
261 save_file.close() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
262 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
263 def load(self, path, filename): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
264 """Loads a saver from a file. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
265 @type filename: string |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
266 @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
|
267 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
268 fname = '/'.join([path, filename]) |
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 try: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
271 load_file = open(fname, 'r') |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
272 except(IOError): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
273 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
|
274 return |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
275 self.deleteMaps() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
276 self.clearAgents() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
277 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
278 save_state = yaml.load(load_file) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
279 self.game_state.restoreFromState(save_state["GameState"]) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
280 maps = save_state["Agents"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
281 for map_name in maps: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
282 for agent_name in maps[map_name]: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
283 agent = {agent_name:maps[map_name][agent_name]} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
284 self.addAgent(map_name, agent) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
285 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
286 # Load the current map |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
287 if self.game_state.current_map_name: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
288 self.loadMap(self.game_state.current_map_name) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
289 load_file.close() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
290 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
291 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
292 # 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
|
293 # objects cannot be pickled |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
294 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
295 self.placeAgents() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
296 self.placePC() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
297 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
298 # 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
|
299 # In these cases we need a target position |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
300 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
301 def teleport(self, agent, position): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
302 """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
|
303 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
|
304 @type position: String Tuple |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
305 @param position: X,Y coordinates passed from engine.changeMap |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
306 @return: fife.Location""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
307 logging.debug(position) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
308 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
|
309 location = fife.Location(self.active_map.agent_layer) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
310 location.setMapCoordinates(coord) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
311 agent.teleport(location) |
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 getObjectAtCoords(self, coords): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
314 """Get the object which is at the given coords |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
315 @type coords: fife.Screenpoint |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
316 @param coords: Coordinates where to check for an object |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
317 @rtype: fife.Object |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
318 @return: An object or None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
319 instances = self.active_map.cameras[ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
320 self.active_map.my_cam_id].\ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
321 getMatchingInstances(coords, self.active_map.agent_layer) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
322 # no object returns an empty tuple |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
323 if(instances != ()): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
324 front_y = 0 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
325 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
326 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
327 for obj in instances: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
328 # 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
|
329 if(self.objectActive(obj.getId())): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
330 # check if the object is on the foreground |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
331 obj_map_coords = \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
332 obj.getLocation().getMapCoordinates() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
333 obj_screen_coords = self.active_map.\ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
334 cameras[self.active_map.my_cam_id]\ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
335 .toScreenCoordinates(obj_map_coords) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
336 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
337 if obj_screen_coords.y > front_y: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
338 #Object on the foreground |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
339 front_y = obj_screen_coords.y |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
340 return obj |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
341 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
342 return None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
343 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
344 return None |
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 getCoords(self, click): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
347 """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
|
348 @type click: fife.ScreenPoint |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
349 @param click: Screen coordinates |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
350 @rtype: fife.Location |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
351 @return: The map coordinates""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
352 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
|
353 toMapCoordinates(click, False) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
354 coord.z = 0 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
355 location = fife.Location(self.active_map.agent_layer) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
356 location.setMapCoordinates(coord) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
357 return location |
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 pause(self, paused): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
360 """ Pause/Unpause the game |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
361 @return: nothing""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
362 if self.active_map: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
363 self.active_map.pause(paused) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
364 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
365 def togglePause(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
366 """ Toggle paused state. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
367 @return: nothing""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
368 self.active_map.togglePause() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
369 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
370 def isPaused(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
371 """Returns wheter the game is paused or not""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
372 return self.active_map.isPaused() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
373 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
374 def readMapFiles(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
375 """Read all a available map-files and store them""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
376 maps_data = file(self.game_state.maps_file) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
377 self.map_files = yaml.load(maps_data)["Maps"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
378 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
379 def addAgent(self, namespace, agent): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
380 """Adds an agent to the agents dictionary |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
381 @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
|
382 @type namespace: str |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
383 @param agent: The agent to be added |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
384 @type agent: dict """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
385 from fife.extensions.serializers.xml_loader_tools import loadImportFile |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
386 if not self.agents.has_key(namespace): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
387 self.agents[namespace] = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
388 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
389 agent_values = agent.values()[0] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
390 unique_agent_id = self.createUniqueID(agent.keys()[0]) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
391 del agent[agent.keys()[0]] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
392 agent[unique_agent_id] = agent_values |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
393 self.agents[namespace].update(agent) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
394 object_model = "" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
395 if agent_values.has_key("ObjectModel"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
396 object_model = agent_values["ObjectModel"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
397 elif agent_values["ObjectType"] == "MapItem": |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
398 object_data = self.object_db[agent_values["ItemType"]] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
399 object_model = object_data["gfx"] if object_data.has_key("gfx") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
400 else "generic_item" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
401 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
402 object_model = self.object_db[agent_values["ObjectType"]]["gfx"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
403 import_file = self.agent_import_files[object_model] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
404 loadImportFile(self.obj_loader, import_file, self.engine) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
405 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
406 def readAgentsOfMap(self, map_name): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
407 """Read the agents of the map |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
408 @param map_name: Name of the map |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
409 @type map_name: str """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
410 #Get the agents of the map |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
411 map_agents_file = self.map_files[map_name].\ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
412 replace(".xml", "_agents.yaml") |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
413 agents_data = file(map_agents_file) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
414 agents = yaml.load_all(agents_data) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
415 for agent in agents: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
416 if not agent == None: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
417 self.addAgent(map_name, agent) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
418 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
419 def readAllAgents(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
420 """Read the agents of the all_agents_file and store them""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
421 agents_data = file(self.all_agents_file) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
422 agents = yaml.load_all(agents_data) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
423 for agent in agents: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
424 if not agent == None: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
425 self.addAgent(self.ALL_AGENTS_KEY, agent) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
426 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
427 def getAgentsOfMap(self, map_name): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
428 """Returns the agents that are on the given map |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
429 @param map_name: Name of the map |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
430 @type map_name: str |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
431 @return: A dictionary with the agents of the map""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
432 if not self.agents.has_key(map_name): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
433 return {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
434 ret_dict = self.agents[map_name].copy() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
435 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
|
436 .iteritems(): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
437 if agent_value["Map"] == map_name: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
438 ret_dict[agent_name] = agent_value |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
439 return ret_dict |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
440 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
441 def getAgentsOfActiveMap(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
442 """Returns the agents that are on active map |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
443 @return: A dictionary with the agents of the map """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
444 return self.getAgentsOfMap(self.active_map.map.getId()) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
445 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
446 def clearAgents(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
447 """Resets the agents dictionary""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
448 self.agents = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
449 self.agents[self.ALL_AGENTS_KEY] = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
450 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
451 def loadMap(self, map_name): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
452 """Load a new map. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
453 @type map_name: string |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
454 @param map_name: Name of the map to load |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
455 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
456 if not map_name in self.game_state.maps: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
457 map_file = self.map_files[map_name] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
458 new_map = GameMap(self.engine, self) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
459 self.game_state.maps[map_name] = new_map |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
460 new_map.load(map_file) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
461 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
462 def createAgent(self, agent, inst_id): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
463 object_type = agent["ObjectType"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
464 object_id = agent["ObjectModel"] \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
465 if agent.has_key("ObjectModel") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
466 else None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
467 if object_id == None: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
468 if object_type == "MapItem": |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
469 object_data = self.object_db[agent["ItemType"]] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
470 object_id = object_data["gfx"] if object_data.has_key("gfx") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
471 else "generic_item" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
472 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
473 object_id = self.object_db[object_type]["gfx"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
474 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
|
475 if not map_obj: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
476 logging.warning("Object with inst_id={0}, ns=PARPG, " |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
477 "could not be found. " |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
478 "Omitting...".format(str(obj_id))) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
479 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
480 x_pos = agent["Position"][0] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
481 y_pos = agent["Position"][1] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
482 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
|
483 else -0.1 if object_type == "MapItem" \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
484 else 0.0 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
485 stack_pos = agent["Stackposition"] if \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
486 agent.has_key("StackPosition") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
487 else None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
488 inst = self.active_map.agent_layer.\ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
489 createInstance(map_obj, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
490 fife.ExactModelCoordinate(x_pos, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
491 y_pos, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
492 z_pos), |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
493 inst_id) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
494 inst.setId(inst_id) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
495 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
496 rotation = agent["Rotation"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
497 inst.setRotation(rotation) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
498 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
499 fife.InstanceVisual.create(inst) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
500 if (stack_pos): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
501 inst.get2dGfxVisual().setStackPosition(int(stack_pos)) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
502 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
503 if (map_obj.getAction('default')): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
504 target = fife.Location(self.active_map.agent_layer) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
505 inst.act('default', target, True) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
506 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
507 inst_dict = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
508 inst_dict["id"] = inst_id |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
509 inst_dict["type"] = object_type |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
510 inst_dict["xpos"] = x_pos |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
511 inst_dict["ypos"] = y_pos |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
512 inst_dict["gfx"] = object_id |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
513 inst_dict["is_open"] = parseBool(agent["Open"]) \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
514 if agent.has_key("Open") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
515 else False |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
516 inst_dict["locked"] = parseBool(agent["Locked"]) \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
517 if agent.has_key("Locked") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
518 else False |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
519 inst_dict["name"] = agent["ViewName"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
520 inst_dict["real_name"] = agent["RealName"] \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
521 if agent.has_key("RealName") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
522 else agent["ViewName"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
523 inst_dict["text"] = agent["Text"] \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
524 if agent.has_key("Text") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
525 else None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
526 if self.dialogues.has_key(inst_id): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
527 inst_dict["dialogue"] = self.dialogues[inst_id] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
528 inst_dict["target_map_name"] = agent["TargetMap"] \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
529 if agent.\ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
530 has_key("TargetMap") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
531 else None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
532 inst_dict["target_x"] = agent["TargetPosition"][0] \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
533 if agent.\ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
534 has_key("TargetPosition") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
535 else None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
536 inst_dict["target_y"] = agent["TargetPosition"][1] \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
537 if agent.\ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
538 has_key("TargetPosition") \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
539 else None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
540 if agent.has_key("Inventory"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
541 inventory = Inventory() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
542 inventory_objs = agent["Inventory"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
543 for inventory_obj in inventory_objs: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
544 self.createInventoryObject(inventory, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
545 inventory_obj |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
546 ) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
547 inst_dict["inventory"] = inventory |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
548 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
549 if agent.has_key("Items"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
550 container_objs = agent["Items"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
551 items = self.createContainerItems(container_objs) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
552 inst_dict["items"] = items |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
553 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
554 if agent.has_key("ItemType"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
555 if not agent.has_key("item"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
556 item_data = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
557 item_data["type"] = agent["ItemType"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
558 item_data["ID"] = inst_id |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
559 item_data = self.createContainerObject(item_data) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
560 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
561 item_data = agent["item"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
562 inst_dict["item"] = item_data |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
563 inst_dict["item_type"] = agent["ItemType"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
564 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
565 self.createMapObject(self.active_map.agent_layer, inst_dict) |
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 placeAgents(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
568 """Places the current maps agents """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
569 if not self.active_map: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
570 return |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
571 agents = self.getAgentsOfMap(self.game_state.current_map_name) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
572 for agent in agents: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
573 if agent == "PlayerCharacter": |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
574 continue |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
575 if self.active_map.agent_layer.getInstances(agent): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
576 continue |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
577 self.createAgent(agents[agent], agent) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
578 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
579 def placePC(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
580 """Places the PlayerCharacter on the map""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
581 agent = self.agents[self.ALL_AGENTS_KEY]["PlayerCharacter"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
582 inst_id = "PlayerCharacter" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
583 self.createAgent(agent, inst_id) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
584 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
585 # create the PlayerCharacter agent |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
586 self.active_map.addPC() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
587 self.game_state.player_character.start() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
588 if agent.has_key("PeopleKnown"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
589 self.game_state.player_character.people_i_know = agent["PeopleKnown"] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
590 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
591 def changeMap(self, map_name, target_position = None): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
592 """Registers for a map change on the next pump(). |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
593 @type map_name: String |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
594 @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
|
595 @type map_file: String |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
596 @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
|
597 @type target_position: Tuple |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
598 @param target_position: Position of PlayerCharacter on target map. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
599 @return None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
600 # 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
|
601 if map_name != self.game_state.current_map_name: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
602 self.target_map_name = map_name |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
603 self.target_position = target_position |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
604 # issue the map change |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
605 self.map_change = True |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
606 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
607 def deleteMaps(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
608 """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
|
609 local map cache |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
610 @return: nothing""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
611 self.engine.getModel().deleteMaps() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
612 self.engine.getModel().deleteObjects() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
613 self.game_state.clearObjects() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
614 self.game_state.maps = {} |
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 def setActiveMap(self, map_name): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
617 """Sets the active map that is to be rendered. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
618 @type map_name: String |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
619 @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
|
620 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
621 # 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
|
622 # on the new map. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
623 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
|
624 # Make the new map active. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
625 self.active_map = self.game_state.maps[map_name] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
626 self.active_map.makeActive() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
627 self.game_state.current_map_name = map_name |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
628 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
629 def createMapObject (self, layer, attributes): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
630 """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
|
631 @type layer: fife.Layer |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
632 @param layer: FIFE layer object exists in |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
633 @type attributes: Dictionary |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
634 @param attributes: Dictionary of all object attributes |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
635 @type instance: fife.Instance |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
636 @param instance: FIFE instance corresponding to the object |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
637 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
638 # create the extra data |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
639 extra = {} |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
640 if layer is not None: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
641 extra['agent_layer'] = layer |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
642 attributes = self.checkAttributes(attributes) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
643 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
644 obj = createObject(attributes, extra) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
645 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
646 if obj.trueAttr("PC"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
647 self.addPC(layer, obj) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
648 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
649 self.addObject(layer, obj) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
650 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
651 def addPC(self, layer, player_char): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
652 """Add the PlayerCharacter to the map |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
653 @type layer: fife.Layer |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
654 @param layer: FIFE layer object exists in |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
655 @type player_char: PlayerCharacter |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
656 @param player_char: PlayerCharacter object |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
657 @type instance: fife.Instance |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
658 @param instance: FIFE instance of PlayerCharacter |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
659 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
660 # For now we copy the PlayerCharacter, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
661 # in the future we will need to copy |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
662 # PlayerCharacter specifics between the different PlayerCharacter's |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
663 self.game_state.player_character = player_char |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
664 self.game_state.player_character.setup() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
665 self.game_state.player_character.behaviour.speed = self.settings.parpg.PCSpeed |
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 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
668 def addObject(self, layer, obj): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
669 """Adds an object to the map. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
670 @type layer: fife.Layer |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
671 @param layer: FIFE layer object exists in |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
672 @type obj: GameObject |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
673 @param obj: corresponding object class |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
674 @type instance: fife.Instance |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
675 @param instance: FIFE instance of object |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
676 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
677 ref = self.game_state.getObjectById(obj.ID, \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
678 self.game_state.current_map_name) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
679 if ref is None: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
680 # no, add it to the game state |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
681 self.game_state.addObject(self.game_state.current_map_name, obj) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
682 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
683 # yes, use the current game state data |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
684 obj.X = ref.X |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
685 obj.Y = ref.Y |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
686 obj.gfx = ref.gfx |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
687 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
688 if obj.trueAttr("NPC"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
689 # create the agent |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
690 obj.setup() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
691 obj.behaviour.speed = self.settings.parpg.PCSpeed - 1 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
692 # create the PlayerCharacter agent |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
693 obj.start() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
694 if obj.trueAttr("AnimatedContainer"): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
695 # create the agent |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
696 obj.setup() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
697 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
698 def objectActive(self, ident): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
699 """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
|
700 False if it doesn't exist or not displayed |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
701 @type ident: string |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
702 @param ident: ID of object |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
703 @rtype: boolean |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
704 @return: Status of result (True/False)""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
705 for game_object in \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
706 self.game_state.getObjectsFromMap(self.game_state.current_map_name): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
707 if (game_object.ID == ident): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
708 # we found a match |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
709 return game_object |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
710 # no match |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
711 return False |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
712 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
713 def movePlayer(self, position): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
714 """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
|
715 @type position: fife.ScreenPoint |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
716 @param position: Screen position to move to |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
717 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
718 if(self.pc_run == 1): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
719 self.game_state.player_character.run(position) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
720 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
721 self.game_state.player_character.walk(position) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
722 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
723 def teleportAgent(self, agent, position): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
724 """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
|
725 @type position: fife.ScreenPoint |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
726 @param position: Screen position to teleport to |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
727 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
728 agent.teleport(position) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
729 self.agents[agent.ID]["Position"] = position |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
730 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
731 def readObjectDB(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
732 """Reads the Object Information Database from a file. """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
733 database_file = file(self.object_db_file, "r") |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
734 database = yaml.load_all(database_file) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
735 for object_info in database: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
736 self.object_db.update(object_info) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
737 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
738 def getAgentImportFiles(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
739 """Searches the agents directory for import files """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
740 files = locateFiles("*.xml", self.objects_directory) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
741 for xml_file in files: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
742 xml_file = os.path.relpath(xml_file).replace("\\", "/") |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
743 try: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
744 root = ElementTree.parse(xml_file).getroot() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
745 if root.tag == "object": |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
746 self.agent_import_files[root.attrib["id"]] = xml_file |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
747 except SyntaxError as error: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
748 assert(isinstance(error, SyntaxError)) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
749 logging.critical("Error parsing file {0}: " |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
750 "{1}".format(xml_file, error.msg)) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
751 sys.exit(1) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
752 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
753 def getDialogues(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
754 """Searches the dialogue directory for dialogues """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
755 files = locateFiles("*.yaml", self.dialogues_directory) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
756 dialogue_parser = YamlDialogueParser() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
757 for dialogue_filepath in files: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
758 dialogue_filepath = os.path.relpath(dialogue_filepath) \ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
759 .replace("\\", "/") |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
760 # 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
|
761 # parser now, YamlDialogueParser. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
762 # dialogues = yaml.load_all(file(dialogue_file, "r")) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
763 with file(dialogue_filepath, 'r') as dialogue_file: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
764 try: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
765 dialogue = dialogue_parser.load(dialogue_file) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
766 except (DialogueFormatError,) as error: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
767 logging.error('unable to load dialogue file {0}: {1}' |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
768 .format(dialogue_filepath, error)) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
769 else: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
770 self.dialogues[dialogue.npc_name] = dialogue |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
771 # 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
|
772 # multiple dialogues from a single file. Is this functionality |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
773 # used/necessary? |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
774 # for dialogue in dialogues: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
775 # self.dialogues[dialogue["NPC"]] = dialogue |