Several changes to the checksum function.
* Changed the name and calling method for the checksum function. * Made it no longer a member function since it doesn't need to know the internals of unit. * Add an extra flag so recruit can use this method in a few commits.
This commit is contained in:
parent
0dd72ff34f
commit
d9eacc1a65
3 changed files with 31 additions and 17 deletions
|
@ -203,9 +203,7 @@ void replay::add_unit_checksum(const gamemap::location& loc,config* const cfg)
|
|||
loc.write(cc);
|
||||
unit_map::const_iterator u = unit_map_ref->find(loc);
|
||||
wassert(u != unit_map_ref->end());
|
||||
std::string chk_value;
|
||||
u->second.write_checksum(chk_value);
|
||||
cc["value"] = chk_value;
|
||||
cc["value"] = get_checksum(u->second);
|
||||
}
|
||||
|
||||
void replay::add_start()
|
||||
|
@ -640,9 +638,7 @@ static void check_checksums(game_display& disp,const unit_map& units,const confi
|
|||
disp.add_chat_message("verification",1,message.str(),game_display::MESSAGE_PRIVATE,false);
|
||||
continue;
|
||||
}
|
||||
std::string check;
|
||||
u->second.write_checksum(check);
|
||||
if(check != (**ci)["value"]) {
|
||||
if(get_checksum(u->second) != (**ci)["value"]) {
|
||||
std::stringstream message;
|
||||
message << "checksum mismatch at " << loc.x+1 << "," << loc.y+1 << "!";
|
||||
disp.add_chat_message("verification",1,message.str(),game_display::MESSAGE_PRIVATE,false);
|
||||
|
|
28
src/unit.cpp
28
src/unit.cpp
|
@ -251,7 +251,7 @@ unit::unit(const game_data* gamedata, unit_map* unitmap, const gamemap* map,
|
|||
int side, bool use_traits, bool dummy_unit, unit_race::GENDER gender) :
|
||||
gender_(dummy_unit ? gender : generate_gender(*t,use_traits)), resting_(false), state_(STATE_STANDING), facing_(gamemap::location::NORTH_EAST),draw_bars_(false),
|
||||
gamedata_(gamedata),units_(unitmap),map_(map),gamestatus_(game_status),teams_(teams)
|
||||
{
|
||||
{
|
||||
goto_ = gamemap::location();
|
||||
side_ = side;
|
||||
movement_ = 0;
|
||||
|
@ -371,15 +371,6 @@ void unit::set_game_context(const game_data* gamedata, unit_map* unitmap, const
|
|||
gamestatus_ = game_status;
|
||||
teams_ = teams;
|
||||
}
|
||||
void unit::write_checksum(std::string& str) const
|
||||
{
|
||||
config unit_config;
|
||||
write(unit_config);
|
||||
unit_config["controller"] = "";
|
||||
// since the ai messes up the 'moves' attribute, ignore that for the checksum
|
||||
unit_config["moves"] = "";
|
||||
str = unit_config.hash();
|
||||
}
|
||||
|
||||
void unit::generate_traits()
|
||||
{
|
||||
|
@ -3177,3 +3168,20 @@ void unit::set_hidden(bool state) {
|
|||
// we need to get rid of haloes immediately to avoid display glitches
|
||||
clear_haloes();
|
||||
}
|
||||
|
||||
std::string get_checksum(const unit& u, const bool discard_description)
|
||||
{
|
||||
config unit_config;
|
||||
u.write(unit_config);
|
||||
unit_config["controller"] = "";
|
||||
// since the ai messes up the 'moves' attribute, ignore that for the checksum
|
||||
unit_config["moves"] = "";
|
||||
|
||||
if(discard_description) {
|
||||
unit_config["description"] = "";
|
||||
unit_config["user_description"] = "";
|
||||
}
|
||||
|
||||
return unit_config.hash();
|
||||
}
|
||||
|
||||
|
|
12
src/unit.hpp
12
src/unit.hpp
|
@ -63,7 +63,6 @@ class unit
|
|||
unit& operator=(const unit&);
|
||||
|
||||
void set_game_context(const game_data* gamedata, unit_map* unitmap, const gamemap* map, const gamestatus* game_status, const std::vector<team>* teams);
|
||||
void write_checksum(std::string& str) const;
|
||||
|
||||
// Advances this unit to another type
|
||||
void advance_to(const unit_type* t);
|
||||
|
@ -480,4 +479,15 @@ private:
|
|||
std::pair<gamemap::location,unit> *temp_;
|
||||
};
|
||||
|
||||
/**
|
||||
* gets a checksum for a unit, in MP games the descriptions are locally
|
||||
* generated and might differ, so it should be possible to discard them.
|
||||
* Not sure whether replays suffer the same problem.
|
||||
*
|
||||
* param discard_desc discards the descriptions for the checksum
|
||||
*
|
||||
* returns the checksum for a unit
|
||||
*/
|
||||
std::string get_checksum(const unit& u, const bool discard_description = false);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue