Author: esr
Date: Mon Mar 3 22:25:46 2008
New Revision: 24288
URL: http://svn.gna.org/viewcvs/wesnoth?rev=24288&view=rev
Log:
The game engine now embedds a list of unique game-save IDs into each
savefile in the "history" attribute. For the first save of a campaign
the history list is a singleton containing the ID of that save; for
all subsequent saves, a new ID is appended following a comma. Thus
the IDs of every one of a save's ancestors are available in the save.
Modified:
trunk/src/game.cpp
trunk/src/gamestatus.cpp
trunk/src/gamestatus.hpp
trunk/src/playcampaign.cpp
Modified: trunk/src/game.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=24288&r1=24287&r2=24288&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Mon Mar 3 22:25:46 2008
@@ -926,6 +926,7 @@
const config& campaign = *campaigns[cmenu.result()];
state_.campaign = campaign["id"];
+ state_.history = generate_game_uuid();
state_.abbrev = campaign["abbrev"];
state_.scenario = campaign["first_scenario"];
Modified: trunk/src/gamestatus.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.cpp?rev=24288&r1=24287&r2=24288&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Mon Mar 3 22:25:46 2008
@@ -39,6 +39,8 @@
#include <iostream>
#include <iterator>
#include <sstream>
+#include <sys/time.h>
+#include <time.h>
#define DBG_NG lg::debug(lg::engine)
#define LOG_NG lg::info(lg::engine)
@@ -176,6 +178,17 @@
}
}
+std::string generate_game_uuid()
+{
+ struct timeval ts;
+ std::stringstream uuid;
+ gettimeofday(&ts, NULL);
+
+ uuid << preferences::login() << "@" << ts.tv_sec << "." << ts.tv_usec;
+
+ return uuid.str();
+}
+
//! Reads turns and time information from parameters.
//! It sets random starting ToD and current_tod to config.
gamestatus::gamestatus(const config& time_cfg, int num_turns, game_state*
s_o_g) :
@@ -433,6 +446,7 @@
campaign_define(cfg["campaign_define"]),
campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"])),
campaign(cfg["campaign"]),
+ history(cfg["history"]),
abbrev(cfg["abbrev"]),
scenario(cfg["scenario"]),
next_scenario(cfg["next_scenario"]),
@@ -574,6 +588,7 @@
{
log_scope("write_game");
cfg["label"] = gamestate.label;
+ cfg["history"] = gamestate.history;
cfg["abbrev"] = gamestate.abbrev;
cfg["version"] = game_config::version;
@@ -636,6 +651,7 @@
log_scope("write_game");
out.write_key_val("label", gamestate.label);
+ out.write_key_val("history", gamestate.history);
out.write_key_val("abbrev", gamestate.abbrev);
out.write_key_val("version", game_config::version);
out.write_key_val("scenario", gamestate.scenario);
@@ -1198,6 +1214,7 @@
return *this;
}
+ history = state.history;
abbrev = state.abbrev;
label = state.label;
version = state.version;
Modified: trunk/src/gamestatus.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.hpp?rev=24288&r1=24287&r2=24288&view=diff
==============================================================================
--- trunk/src/gamestatus.hpp (original)
+++ trunk/src/gamestatus.hpp Mon Mar 3 22:25:46 2008
@@ -102,6 +102,7 @@
campaign_define(),
campaign_xtra_defines(),
campaign(),
+ history(),
abbrev(),
scenario(),
next_scenario(),
@@ -135,7 +136,8 @@
std::vector<std::string> campaign_xtra_defines; //!< more
customization of data
std::string campaign; //!< the campaign
being played
- std::string abbrev; //!< the campaign
abbreviation
+ std::string history; //!< ancestral IDs
+ std::string abbrev; //!< the campaign
abbreviation
std::string scenario; //!< the scenario
being played
std::string next_scenario; //!< the scenario
coming next (for campaigns)
std::string completion; //!< running. victory,
or defeat
@@ -284,6 +286,8 @@
const game_state* state_of_game_;
};
+std::string generate_game_uuid();
+
//! Holds all the data needed to start a scenario.
//! I.e. this is the object serialized to disk when saving/loading a game.
//! It is also the object which needs to be created to start a new game.
Modified: trunk/src/playcampaign.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playcampaign.cpp?rev=24288&r1=24287&r2=24288&view=diff
==============================================================================
--- trunk/src/playcampaign.cpp (original)
+++ trunk/src/playcampaign.cpp Mon Mar 3 22:25:46 2008
@@ -339,6 +339,12 @@
}
}
+ // This is the magic moment when game history links
+ // are created
+ if (!gamestate.history.empty())
+ gamestate.history += ",";
+ gamestate.history += generate_game_uuid();
+
// If the entire scenario should be randomly generated
if((*scenario)["scenario_generation"] != "") {
LOG_G << "randomly generating scenario...\n";
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits