mail[Wesnoth-commits] r37164 - in /trunk/src: gamestatus.cpp gamestatus.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by e0204097 on July 22, 2009 - 17:58:
Author: euschn
Date: Wed Jul 22 17:58:07 2009
New Revision: 37164

URL: http://svn.gna.org/viewcvs/wesnoth?rev=37164&view=rev
Log:
added optional parameter merge_side to game_state::write_players()

Modified:
    trunk/src/gamestatus.cpp
    trunk/src/gamestatus.hpp

Modified: trunk/src/gamestatus.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.cpp?rev=37164&r1=37163&r2=37164&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Wed Jul 22 17:58:07 2009
@@ -18,6 +18,7 @@
  */
 
 #include "global.hpp"
+#include "config.hpp"
 
 #include "gamestatus.hpp"
 
@@ -163,7 +164,7 @@
                classification_()
                {}
 
-void write_players(game_state& gamestate, config& cfg)
+void write_players(game_state& gamestate, config& cfg, const bool merge_side)
 {
        // If there is already a player config available it means we are 
loading
        // from a savegame. Don't do anything then, the information is 
already there
@@ -174,7 +175,22 @@
        //take all sides information from the snapshot (assuming it only 
contains carryover information)
        //take all side tags and add them as players
        foreach(const config* snapshot_side, 
gamestate.snapshot.get_children("side")) {
-               cfg.add_child("player", *snapshot_side);
+               bool merged = false;
+               //if a side with the same save_id exists, we merge the player 
information into this side
+               //FIXME: carryover gold needs to be sorted here
+               if (merge_side) {
+                       if (config& c = cfg.find_child("side", "save_id", 
(*snapshot_side)["save_id"])) {
+                               c.merge_with(*snapshot_side);
+                               merged = true;
+                       } else if (config& c = cfg.find_child("side", "id", 
(*snapshot_side)["save_id"])) {
+                               c.merge_with(*snapshot_side);
+                               merged = true;
+                       }
+               }
+               
+               if (!merged) {
+                       cfg.add_child("player", *snapshot_side);
+               }
        }
 }
 

Modified: trunk/src/gamestatus.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.hpp?rev=37164&r1=37163&r2=37164&view=diff
==============================================================================
--- trunk/src/gamestatus.hpp (original)
+++ trunk/src/gamestatus.hpp Wed Jul 22 17:58:07 2009
@@ -152,7 +152,7 @@
 
 std::string generate_game_uuid();
 
-void write_players(game_state& gamestate, config& cfg);
+void write_players(game_state& gamestate, config& cfg, const bool merge_side 
= false);
 
 void extract_summary_from_config(config& cfg_save, config& cfg_summary);
 




Related Messages


Powered by MHonArc, Updated Wed Jul 22 18:40:57 2009