Fix underlying id generation for WML created units

Raise unit map duplicate id warning to error level

- This might fix bugs with invalid unit map iterators
This commit is contained in:
Pauli Nieminen 2008-09-12 21:51:35 +00:00
parent 876cdd3237
commit 3637d5defa
7 changed files with 44 additions and 49 deletions

View file

@ -29,6 +29,7 @@
#include "statistics.hpp"
#include "time_of_day.hpp"
#include "wesconfig.h"
#include "replay.hpp"
#include "serialization/binary_or_text.hpp"
#include "serialization/binary_wml.hpp"
#include "serialization/parser.hpp"
@ -443,6 +444,33 @@ static player_info read_player(const config* cfg)
return res;
}
game_state::game_state() :
label(),
version(),
campaign_type(),
campaign_define(),
campaign_xtra_defines(),
campaign(),
history(),
abbrev(),
scenario(),
next_scenario(),
completion(),
players(),
scoped_variables(),
wml_menu_items(),
difficulty("NORMAL"),
replay_data(),
starting_pos(),
snapshot(),
last_selected(gamemap::location::null_location),
rng_(),
variables(),
temporaries(),
generator_setter(&recorder)
{}
game_state::game_state(const config& cfg, bool show_replay) :
label(cfg["label"]),
version(cfg["version"]),
@ -465,7 +493,8 @@ game_state::game_state(const config& cfg, bool show_replay) :
last_selected(gamemap::location::null_location),
rng_(cfg),
variables(),
temporaries()
temporaries(),
generator_setter(&recorder)
{
log_scope("read_game");
@ -1194,7 +1223,8 @@ game_state::game_state(const game_state& state) :
last_selected(),
rng_(),
variables(),
temporaries()
temporaries(),
generator_setter(&recorder)
{
*this = state;
}

View file

@ -30,6 +30,7 @@
#include <string>
#include <vector>
class scoped_wml_variable;
struct wml_menu_item
@ -69,37 +70,12 @@ struct player_info
class game_state : public variable_set
{
public:
game_state() :
label(),
version(),
campaign_type(),
campaign_define(),
campaign_xtra_defines(),
campaign(),
history(),
abbrev(),
scenario(),
next_scenario(),
completion(),
players(),
scoped_variables(),
wml_menu_items(),
difficulty("NORMAL"),
replay_data(),
starting_pos(),
snapshot(),
last_selected(gamemap::location::null_location),
rng_(),
variables(),
temporaries()
{}
game_state();
game_state(const game_state& state);
game_state(const config& cfg, bool show_replay = false);
~game_state();
game_state& operator=(const game_state& state);
std::string label; //!< Name of the game (e.g. name of save file).
std::string version; //!< Version game was created with.
std::string campaign_type; //!< Type of the game - campaign, multiplayer etc.
@ -170,6 +146,7 @@ private:
rand_rng::simple_rng rng_ ;
config variables;
mutable config temporaries; // lengths of arrays, etc.
const rand_rng::set_random_generator generator_setter; //! Make sure that rng is initialized first
friend struct variable_info;
//! Loads the recall list.

View file

@ -51,7 +51,6 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
menu_handler_(NULL, units_, teams_, level, map_, game_config, status_, state_of_game, undo_stack_, redo_stack_),
soundsources_manager_(),
gui_(),
generator_setter(&recorder),
statistics_context_(level["name"]),
level_(level),
teams_(),

View file

@ -132,7 +132,6 @@ protected:
//other objects
boost::scoped_ptr<game_display> gui_;
const rand_rng::set_random_generator generator_setter;
const statistics::scenario_context statistics_context_;
const config& level_;
std::vector<team> teams_;

View file

@ -325,7 +325,6 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
bool save_game_after_scenario = true;
const rand_rng::set_random_generator generator_setter(&recorder);
LEVEL_RESULT res = LEVEL_CONTINUE;
try {

View file

@ -1402,24 +1402,14 @@ void unit::read(const config& cfg, bool use_traits, game_state* state)
variation_ = cfg["variation"];
id_ = cfg["id"];
name_ = cfg["name"];
// FIXME OBSOLETE This will go away in 1.5.3
if (id_.empty())
id_ = cfg["description"];
// FIXME OBSOLETE This will go away in 1.5.3
if (!cfg["user_description"].empty()) {
name_ = cfg["user_description"];
}
std::string custom_unit_desc = cfg["description"];
// FIXME OBSOLETE This will go away in 1.5.3
if (custom_unit_desc.empty())
custom_unit_desc = cfg["unit_description"];
underlying_id_ = id_;
if(id_.empty()) {
set_underlying_id();
if (id_.empty()) {
id_ = cfg["type"].c_str();
}
name_ = cfg["name"];
std::string custom_unit_desc = cfg["description"];
underlying_id_ = cfg["underlying_id"];
set_underlying_id();
role_ = cfg["role"];
ai_special_ = cfg["ai_special"];
@ -1714,7 +1704,8 @@ void unit::write(config& cfg) const
cfg["overlays"] = utils::join(overlays_);
cfg["name"] = name_;
cfg["id"] = underlying_id_;
cfg["id"] = id_;
cfg["underlying_id"] = underlying_id_;
if(can_recruit())
cfg["canrecruit"] = "yes";

View file

@ -463,7 +463,7 @@ void unit_map::add(std::pair<gamemap::location,unit> *p)
unit_id = id.str();
map_[unit_id] = std::pair<bool, std::pair<gamemap::location, unit>*>(true, p);
WRN_NG << "unit_map::add -- duplicate id in unit map: " << p->second.underlying_id()
ERR_NG << "unit_map::add -- duplicate id in unit map: " << p->second.underlying_id()
<< " added to location: (" << p->first.x+1 << "," << p->first.y+1
<< ") but exists already at: (" << iter->second.second->first.x+1
<< "," << iter->second.second->first.y+1 << ").\n";