[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src Makefile.am actions.cpp game_events...
From: |
Philippe Plantier |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src Makefile.am actions.cpp game_events... |
Date: |
Sat, 23 Apr 2005 08:13:10 -0400 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Philippe Plantier <address@hidden> 05/04/23 12:13:10
Modified files:
src : Makefile.am actions.cpp game_events.cpp
playturn.cpp random.cpp random.hpp replay.cpp
Added files:
src : checksum.cpp checksum.hpp
Log message:
Added a checksum mechanism for checking recruited units. As it was not
really
playtested, make it only log the errors, but not throw them.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/checksum.cpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/checksum.hpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/Makefile.am.diff?tr1=1.92&tr2=1.93&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/actions.cpp.diff?tr1=1.208&tr2=1.209&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game_events.cpp.diff?tr1=1.144&tr2=1.145&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playturn.cpp.diff?tr1=1.361&tr2=1.362&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/random.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/random.hpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/replay.cpp.diff?tr1=1.107&tr2=1.108&r1=text&r2=text
Patches:
Index: wesnoth/src/Makefile.am
diff -u wesnoth/src/Makefile.am:1.92 wesnoth/src/Makefile.am:1.93
--- wesnoth/src/Makefile.am:1.92 Sun Apr 10 13:26:48 2005
+++ wesnoth/src/Makefile.am Sat Apr 23 12:13:10 2005
@@ -42,6 +42,7 @@
astarnode.cpp \
builder.cpp \
cavegen.cpp \
+ checksum.cpp \
clipboard.cpp \
config.cpp \
cursor.cpp \
@@ -134,6 +135,7 @@
astarnode.hpp \
builder.hpp \
cavegen.hpp \
+ checksum.hpp \
clipboard.hpp \
cursor.hpp \
config.hpp \
@@ -240,6 +242,7 @@
astarnode.cpp \
builder.cpp \
cavegen.cpp \
+ checksum.cpp \
clipboard.cpp \
config.cpp \
cursor.cpp \
@@ -323,6 +326,7 @@
astarnode.hpp \
builder.hpp \
cavegen.hpp \
+ checksum.hpp \
clipboard.hpp \
config.hpp \
cursor.hpp \
Index: wesnoth/src/actions.cpp
diff -u wesnoth/src/actions.cpp:1.208 wesnoth/src/actions.cpp:1.209
--- wesnoth/src/actions.cpp:1.208 Fri Apr 22 21:41:12 2005
+++ wesnoth/src/actions.cpp Sat Apr 23 12:13:10 2005
@@ -1,4 +1,4 @@
-/* $Id: actions.cpp,v 1.208 2005/04/22 21:41:12 Sirp Exp $ */
+/* $Id: actions.cpp,v 1.209 2005/04/23 12:13:10 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -14,6 +14,7 @@
#include "global.hpp"
#include "actions.hpp"
+#include "checksum.hpp"
#include "display.hpp"
#include "events.hpp"
#include "game_config.hpp"
@@ -38,6 +39,8 @@
#include "wassert.hpp"
#include "wml_separators.hpp"
#include "serialization/string_utils.hpp"
+#include "serialization/binary_wml.hpp"
+#include "serialization/parser.hpp"
#include "widgets/menu.hpp"
#include <cmath>
@@ -155,9 +158,39 @@
}
}
+ checksumstream cs;
+ config cfg_unit;
+ new_unit.write(cfg_unit);
+ ::write_compressed(cs,cfg_unit);
+
+ const config* ran_results = get_random_results();
+ if(ran_results != NULL) {
+ unsigned long rc = lexical_cast_default<unsigned long>
+ ((*ran_results)["checksum"], 0);
+ if((*ran_results)["checksum"].empty() || rc != cs.checksum()) {
+ ERR_NW << "SYNC: In recruit " << new_unit.type().id() <<
+ ": has checksum " << cs.checksum() <<
+ " while datasource has checksum " <<
+ rc << "\n";
+ // FIXME: this was not playtested, so I will disable it
+ // for release.
+ //if (!game_config::ignore_replay_errors) throw
replay::error();
+ }
+
+ } else {
+ config cfg;
+ cfg["checksum"] = lexical_cast<std::string>(cs.checksum());
+ set_random_results(cfg);
+ }
+
return std::string();
}
+void validate_recruit_unit()
+{
+
+}
+
gamemap::location under_leadership(const std::map<gamemap::location,unit>&
units,
const gamemap::location& loc, int* bonus)
{
Index: wesnoth/src/game_events.cpp
diff -u wesnoth/src/game_events.cpp:1.144 wesnoth/src/game_events.cpp:1.145
--- wesnoth/src/game_events.cpp:1.144 Mon Apr 18 19:25:04 2005
+++ wesnoth/src/game_events.cpp Sat Apr 23 12:13:10 2005
@@ -1,4 +1,4 @@
-/* $Id: game_events.cpp,v 1.144 2005/04/18 19:25:04 gruikya Exp $ */
+/* $Id: game_events.cpp,v 1.145 2005/04/23 12:13:10 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -240,6 +240,10 @@
log_scope2(engine, "handle_event_command");
LOG_NG << "handling command: '" << cmd << "'\n";
+ //Ensures the context for the synchronization [result] of this even is
+ //not the same one as the previous event's.
+ add_random_separator();
+
bool rval = true;
//sub commands that need to be handled in a guaranteed ordering
if(cmd == "command") {
Index: wesnoth/src/playturn.cpp
diff -u wesnoth/src/playturn.cpp:1.361 wesnoth/src/playturn.cpp:1.362
--- wesnoth/src/playturn.cpp:1.361 Thu Apr 21 12:28:14 2005
+++ wesnoth/src/playturn.cpp Sat Apr 23 12:13:10 2005
@@ -1,4 +1,4 @@
-/* $Id: playturn.cpp,v 1.361 2005/04/21 12:28:14 Sirp Exp $ */
+/* $Id: playturn.cpp,v 1.362 2005/04/23 12:13:10 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1442,12 +1442,13 @@
// Redo recall
std::vector<unit>& recall_list =
player->available_units;
unit& un = recall_list[action.recall_pos];
+
+
recorder.add_recall(action.recall_pos,action.recall_loc);
recruit_unit(map_,team_num_,units_,un,action.recall_loc,&gui_);
statistics::recall_unit(un);
team& current_team = teams_[team_num_-1];
current_team.spend_gold(game_config::recall_cost);
recall_list.erase(recall_list.begin()+action.recall_pos);
-
recorder.add_recall(action.recall_pos,action.recall_loc);
gui_.draw_tile(action.recall_loc.x,action.recall_loc.y);
}
@@ -2001,13 +2002,14 @@
if(res >= 0) {
unit& un = recall_list[res];
gamemap::location loc = last_hex_;
+ recorder.add_recall(res,loc);
const std::string err =
recruit_unit(map_,team_num_,units_,un,loc,&gui_);
if(!err.empty()) {
+ recorder.undo();
gui::show_dialog(gui_,NULL,"",err,gui::OK_ONLY);
} else {
statistics::recall_unit(un);
current_team.spend_gold(game_config::recall_cost);
- recorder.add_recall(res,loc);
undo_stack_.push_back(undo_action(un,loc,res));
redo_stack_.clear();
Index: wesnoth/src/random.cpp
diff -u wesnoth/src/random.cpp:1.1 wesnoth/src/random.cpp:1.2
--- wesnoth/src/random.cpp:1.1 Tue Mar 22 22:09:28 2005
+++ wesnoth/src/random.cpp Sat Apr 23 12:13:10 2005
@@ -1,4 +1,4 @@
-/* $Id: random.cpp,v 1.1 2005/03/22 22:09:28 ydirson Exp $ */
+/* $Id: random.cpp,v 1.2 2005/04/23 12:13:10 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Yann Dirson <address@hidden>
@@ -15,13 +15,15 @@
#include "random.hpp"
#include "wassert.hpp"
-rng::rng() : random_(NULL)
+rng::rng() : random_(NULL), separator_(false)
{}
-int rng::get_random()
+int rng::get_random(int value)
{
+ separator_ = false;
+
if(random_ == NULL) {
- return rand();
+ return value >= 0 ? value : rand();
}
//random numbers are in a 'list' meaning that each random
@@ -31,7 +33,9 @@
//the current node the new node
config* const random = random_->child("random");
if(random == NULL) {
- const int res = rand();
+ int res = value;
+ if(value < 0)
+ res = rand();
random_ = &random_->add_child("random");
char buf[100];
@@ -46,19 +50,45 @@
}
}
-const config* rng::get_random_results() const
+const config* rng::get_random_results()
{
wassert(random_ != NULL);
+
+ if(separator_) {
+ get_random(0);
+ }
return random_->child("results");
}
void rng::set_random_results(const config& cfg)
{
wassert(random_ != NULL);
+
+ if(separator_) {
+ get_random(0);
+ }
random_->clear_children("results");
random_->add_child("results",cfg);
}
+void rng::add_random_separator()
+{
+ separator_ = true;
+}
+
+config* rng::random()
+{
+ return random_;
+}
+
+config* rng::set_random(config* random)
+{
+ config* old = random_;
+ random_ = random;
+ separator_ = false;
+ return old;
+}
+
namespace {
rng* random_generator = NULL;
}
@@ -90,3 +120,10 @@
wassert(random_generator!=NULL);
random_generator->set_random_results(cfg);
}
+
+void add_random_separator()
+{
+ wassert(random_generator!=NULL);
+ random_generator->add_random_separator();
+}
+
Index: wesnoth/src/random.hpp
diff -u wesnoth/src/random.hpp:1.1 wesnoth/src/random.hpp:1.2
--- wesnoth/src/random.hpp:1.1 Tue Mar 22 22:09:28 2005
+++ wesnoth/src/random.hpp Sat Apr 23 12:13:10 2005
@@ -1,4 +1,4 @@
-/* $Id: random.hpp,v 1.1 2005/03/22 22:09:28 ydirson Exp $ */
+/* $Id: random.hpp,v 1.2 2005/04/23 12:13:10 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Yann Dirson <address@hidden>
@@ -19,17 +19,29 @@
int get_random();
const config* get_random_results();
void set_random_results(const config& cfg);
+/** Ensures that the next "random results" operations will not happen on the
+ * current random context, eventually adding a dummy random context if
+ * necessary.
+ */
+void add_random_separator();
class rng
{
public:
rng();
- int get_random();
- const config* get_random_results() const;
+ int get_random(int value=-1);
+
+ const config* get_random_results();
void set_random_results(const config& cfg);
+ void add_random_separator();
protected:
+ config* random();
+ config* set_random(config*);
+
+private:
config* random_;
+ bool separator_;
};
struct set_random_generator {
Index: wesnoth/src/replay.cpp
diff -u wesnoth/src/replay.cpp:1.107 wesnoth/src/replay.cpp:1.108
--- wesnoth/src/replay.cpp:1.107 Sun Apr 17 14:35:14 2005
+++ wesnoth/src/replay.cpp Sat Apr 23 12:13:10 2005
@@ -1,4 +1,4 @@
-/* $Id: replay.cpp,v 1.107 2005/04/17 14:35:14 gruikya Exp $ */
+/* $Id: replay.cpp,v 1.108 2005/04/23 12:13:10 gruikya Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -366,7 +366,6 @@
{
config* const cmd = add_command();
cmd->add_child("end_turn");
- random_ = current_;
}
void replay::speak(const config& cfg)
@@ -431,7 +430,8 @@
if(cmd.first != cmd.second) {
cfg_.remove_child("command",cmd.second - cmd.first - 1);
- current_ = random_ = NULL;
+ current_ = NULL;
+ set_random(NULL);
}
}
@@ -457,7 +457,7 @@
pos_ = ncommands()+1;
current_ = &cfg_.add_child("command");
if(update_random_context)
- random_ = current_;
+ set_random(current_);
return current_;
}
@@ -474,18 +474,15 @@
LOG_NW << "up to replay action " << pos_ << "/" << commands().size() <<
"\n";
- random_ = current_ = commands()[pos_];
+ current_ = commands()[pos_];
+ set_random(current_);
++pos_;
return current_;
}
void replay::pre_replay()
{
-
- if(pos_ >= commands().size())
- return;
-
- while(commands()[pos_]->child("start") != NULL) {
+ while(pos_ < commands().size() && commands()[pos_]->child("start") !=
NULL) {
if(get_next_action() == NULL)
return;
}
@@ -500,7 +497,7 @@
{
pos_ = commands().size();
current_ = NULL;
- random_ = NULL;
+ set_random(NULL);
}
void replay::clear()
@@ -508,7 +505,7 @@
cfg_ = config();
pos_ = 0;
current_ = NULL;
- random_ = NULL;
+ set_random(NULL);
skip_ = 0;
}
@@ -705,6 +702,7 @@
if (!game_config::ignore_replay_errors) throw
replay::error();
}
+
statistics::recruit_unit(new_unit);
current_team.spend_gold(u_type->second.cost());
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src Makefile.am actions.cpp game_events...,
Philippe Plantier <=