comparison gamestate.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 0d0422243490
children 9e7f494cc850
comparison
equal deleted inserted replaced
182:f131a1b01254 183:7b6aba7839ea
33 "meet":self.meet, 33 "meet":self.meet,
34 "met":self.met, 34 "met":self.met,
35 "sqrt":math.sqrt, 35 "sqrt":math.sqrt,
36 "log":math.log, 36 "log":math.log,
37 } 37 }
38 self.locals = {}
38 39
39 40
40 def addObject(self, object_id, map_id, game_object): 41 def addObject(self, object_id, map_id, game_object):
41 """Adds an object to the objects and object_ids 42 """Adds an object to the objects and object_ids
42 dictionaries. 43 dictionaries.
143 """ 144 """
144 ret_dict = {} 145 ret_dict = {}
145 ret_dict["CurrentMap"] = self.current_map_name 146 ret_dict["CurrentMap"] = self.current_map_name
146 ret_dict["Quests"] = self.quest_engine.getStateForSaving() 147 ret_dict["Quests"] = self.quest_engine.getStateForSaving()
147 ret_dict["NPCsMet"] = self.npcs_met 148 ret_dict["NPCsMet"] = self.npcs_met
149 ret_dict["locals"] = self.locals
148 return ret_dict 150 return ret_dict
149 151
150 def restoreFromState(self, state): 152 def restoreFromState(self, state):
151 """Restores the state""" 153 """Restores the state"""
152 self.current_map_name = state["CurrentMap"] 154 self.current_map_name = state["CurrentMap"]
153 self.npcs_met = state["NPCsMet"] 155 self.npcs_met = state["NPCsMet"]
156 self.locals = state["locals"]
154 self.quest_engine.readQuests() 157 self.quest_engine.readQuests()
155 self.quest_engine.restoreFromState(state["Quests"]) 158 self.quest_engine.restoreFromState(state["Quests"])
156 159
157 def meet(self, npc): 160 def meet(self, npc):
158 """Record that the PC has met a certain NPC 161 """Record that the PC has met a certain NPC
172 return npc in self.npcs_met 175 return npc in self.npcs_met
173 176
174 def getGameEnvironment(self): 177 def getGameEnvironment(self):
175 """Returns a 2 item list containing the entities and functions that 178 """Returns a 2 item list containing the entities and functions that
176 can work with it. This can be used in functions like eval or exec""" 179 can work with it. This can be used in functions like eval or exec"""
177 vals = {} 180 globals = {}
178 vals.update(self.getObjectDictOfMap(self.current_map_name)) 181 globals.update(self.funcs)
179 return self.funcs, vals 182 globals.update(self.getObjectDictOfMap(self.current_map_name))
183
184 return globals, self.locals