Changeset 574


Ignore:
Timestamp:
07/08/10 18:00:37 (9 years ago)
Author:
beliar
Message:

Patch by Beliar:

  • Quest states are now saved and restored too
  • People met are now restored from saves too (there where saved before but not restored)

Note that old savegames are not working anymore.

Location:
trunk/game/scripts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/gamemodel.py

    r571 r574  
    2727from common.utils import parseBool 
    2828from inventory import Inventory 
    29 from scripts.quest_engine import QuestEngine 
    3029 
    3130try: 
     
    5554        self.load_saver = False 
    5655        self.savegame = None 
    57         self.game_state = GameState() 
    58         self.game_state.quest_engine = QuestEngine(\ 
    59                                             settings.get("PARPG", 
    60                                                          "QuestsDirectory")) 
    61         self.game_state.quest_engine.readQuests() 
     56        self.game_state = GameState(QuestsDir = settings.get("PARPG", 
     57                                                             "QuestsDirectory")) 
     58        #self.game_state.quest_engine =  
     59        #self.game_state.quest_engine.readQuests() 
    6260        self.pc_run = 1 
    6361        self.target_position = None 
     
    497495        self.active_map.addPC() 
    498496        self.game_state.PlayerCharacter.start() 
     497        if agent.has_key("PeopleKnown"): 
     498            self.game_state.PlayerCharacter.peopleIknow = agent["PeopleKnown"] 
    499499                       
    500500    def changeMap(self, map_name, target_position = None): 
     
    513513            # issue the map change 
    514514            self.map_change = True 
    515         else: 
    516             #set the player position on the current map 
    517             self.teleport(target_position) 
    518515 
    519516    def deleteMaps(self): 
  • trunk/game/scripts/gamestate.py

    r571 r574  
    1616#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>. 
    1717 
    18 from scripts import quest_engine 
     18from scripts.quest_engine import QuestEngine 
    1919 
    2020class GameState(object): 
    2121    """This class holds the current state of the game.""" 
    22     def __init__(self): 
     22    def __init__(self, QuestsDir = None): 
    2323        self.PlayerCharacter = None 
    24         self.quest_engine = None 
     24        self.quest_engine = QuestEngine(QuestsDir) 
     25        self.quest_engine.readQuests() 
    2526        self.objects = {} 
    2627        self.object_ids = {} 
     
    113114        ret_dict = {} 
    114115        ret_dict["CurrentMap"] = self.current_map_name 
     116        ret_dict["Quests"] = self.quest_engine.getStateForSaving() 
    115117        return ret_dict 
    116118 
     
    118120        """Restores the state""" 
    119121        self.current_map_name = state["CurrentMap"] 
     122        self.quest_engine.readQuests() 
     123        self.quest_engine.restoreFromState(state["Quests"]) 
    120124         
  • trunk/game/scripts/quest_engine.py

    r571 r574  
    149149        """Reads in the quests in the quest directory""" 
    150150        files = locateFiles("*.yaml", self.quest_dir) 
     151        self.quests = {} 
     152        self.active_quests = [] 
     153        self.finished_quests = [] 
     154        self.failed_quests = [] 
    151155        for quest_file in files: 
    152156            quest_file = os.path.relpath(quest_file).replace("\\", "/") 
     
    234238        @return: False when it's not in the failed quests log""" 
    235239        return quest_id in self.failed_quests 
     240     
     241    def getStateForSaving(self): 
     242        """Prepares state for saving 
     243        @type state: dictionary 
     244        @param state: State of the object   
     245        """ 
     246        ret_dict = {} 
     247        variables_dict = ret_dict["Variables"] = {} 
     248        for quest in self.quests.itervalues(): 
     249            quest_dict = variables_dict[quest.quest_id] = {} 
     250            for variable, data in quest.quest_variables.iteritems(): 
     251                quest_dict[variable] = data["value"] 
     252        ret_dict["ActiveQuests"] = self.active_quests 
     253        ret_dict["FinishedQuests"] = self.finished_quests 
     254        ret_dict["FailedQuests"] = self.failed_quests 
     255        return ret_dict 
     256 
     257    def restoreFromState(self, state): 
     258        """Restores the state""" 
     259        variables_dict = state["Variables"] 
     260        for quest_id, variables in variables_dict.iteritems(): 
     261            for variable, value in variables.iteritems(): 
     262                self.quests[quest_id].setValue(variable, value) 
     263        self.active_quests = state["ActiveQuests"] 
     264        self.finished_quests = state["FinishedQuests"] 
     265        self.failed_quests = state["FailedQuests"] 
Note: See TracChangeset for help on using the changeset viewer.