Mercurial > parpg-source
annotate entities/__init__.py @ 183:7b6aba7839ea
getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
This WILL break old saves.
author | Beliar <KarstenBock@gmx.net> |
---|---|
date | Thu, 15 Mar 2012 16:24:05 +0100 |
parents | a9cc5559ec2a |
children |
rev | line source |
---|---|
86
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
1 # This file is part of PARPG. |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
2 |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
3 # PARPG is free software: you can redistribute it and/or modify |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
4 # it under the terms of the GNU General Public License as published by |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
5 # the Free Software Foundation, either version 3 of the License, or |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
6 # (at your option) any later version. |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
7 |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
8 # PARPG is distributed in the hope that it will be useful, |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
11 # GNU General Public License for more details. |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
12 |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
13 # You should have received a copy of the GNU General Public License |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
15 |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
16 import sys |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
17 |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
18 from general import General |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
19 |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
20 def createEntity(info, identifier, world, extra = None): |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
21 """Called when we need to get an actual object. |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
22 @type info: dict |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
23 @param info: stores information about the object we want to create |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
24 @type extra: dict |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
25 @param extra: stores additionally required attributes |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
26 @return: the object""" |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
27 # First, we try to get the world, which every game_obj needs. |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
28 extra = extra or {} |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
29 |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
30 # add the extra info |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
31 for key, val in extra.items(): |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
32 info[key].update(val) |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
33 |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
34 # this is for testing purposes |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
35 new_ent = General(world, identifier) |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
36 for component, data in info.items(): |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
37 comp_obj = getattr(new_ent, component) |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
38 for key, value in data.items(): |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
39 setattr(comp_obj, key, value) |
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
40 return new_ent |