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