give a warning on wrong side= attributes.

previously the game ignores the side= attribute when the game was
started the normal way, and refused to load start-of-scenario of
scenario that ha a side with a wrong side= attribute.

Now in both cases it loads the scenario sucesfully but gives a warning.
This commit is contained in:
gfgtdf 2016-08-08 17:34:33 +02:00
parent 92cd7fee25
commit 7ab539fb3d
4 changed files with 15 additions and 24 deletions

View file

@ -898,6 +898,11 @@ side_engine::side_engine(const config& cfg, connect_engine& parent_engine,
("recruit", cfg_["recruit"])
);
if (cfg_["side"].to_int(index_ + 1) != index_ + 1) {
ERR_CF << "found invalid side=" << cfg_["side"].to_int(index_ + 1) << " in definition of side number " << index_ + 1 << std::endl;
}
cfg_["side"] = index_ + 1;
// Check if this side should give its control to some other side.
const size_t side_cntr_index = cfg_["controller"].to_int(-1) - 1;
if (side_cntr_index < parent_.side_engines().size()) {
@ -908,6 +913,7 @@ side_engine::side_engine(const config& cfg, connect_engine& parent_engine,
cfg_["previous_save_id"] = parent_.side_engines()[side_cntr_index]->previous_save_id();
ERR_MP << "contoller=<number> is deperecated\n";
}
if(!parent_.params_.saved_game && cfg_["save_id"].str().empty()) {
assert(cfg_["id"].empty()); // we already setted "save_id" to "id" if "id" existed.
cfg_["save_id"] = parent_.scenario()["id"].str() + "_" + std::to_string(index);
@ -1008,10 +1014,6 @@ config side_engine::new_config() const
res.append(faction);
}
if (!cfg_.has_attribute("side") || cfg_["side"].to_int() != index_ + 1) {
res["side"] = index_ + 1;
}
res["controller"] = controller_names[controller_];
// the hosts recieves the serversided controller tweaks after the start event, but
// for mp sync it's very important that the controller types are correct

View file

@ -189,9 +189,9 @@ void game_state::init(const config& level, play_controller & pc)
first_human_team_ = team_num;
}
}
team_builder_ptr tb_ptr = create_team_builder(side,
board_.teams_, level, board_);
++team_num;
team_builder_ptr tb_ptr = create_team_builder(side,
board_.teams_, level, board_, team_num);
build_team_stage_one(tb_ptr);
team_builders.push_back(tb_ptr);
}

View file

@ -38,14 +38,14 @@ static lg::log_domain log_engine_tc("engine/team_construction");
class team_builder {
public:
team_builder(const config& side_cfg, std::vector<team>& teams,
const config& level, game_board& board)
const config& level, game_board& board, int num)
: gold_info_ngold_(0)
, leader_configs_()
, level_(level)
, board_(board)
, player_exists_(false)
, seen_ids_()
, side_(0)
, side_(num)
, side_cfg_(side_cfg)
, t_(nullptr)
, teams_(teams)
@ -113,21 +113,10 @@ protected:
void init()
{
side_ = side_cfg_["side"].to_int(1);
if (side_ == 0) // Otherwise falls into the next error, with a very confusing message
throw config::error("Side number 0 encountered. Side numbers start at 1");
if (unsigned(side_ - 1) >= teams_.size()) {
std::stringstream ss;
ss << "Side number " << side_ << " higher than number of sides (" << teams_.size() << ")";
throw config::error(ss.str());
}
if (teams_[side_ - 1].side() != 0) {
std::stringstream ss;
ss << "Duplicate definition of side " << side_;
throw config::error(ss.str());
if (side_cfg_["side"].to_int(side_) != side_) {
ERR_NG_TC << "found invalid side=" << side_cfg_["side"].to_int(side_) << " in definition of side number " << side_ << std::endl;
}
t_ = &teams_[side_ - 1];
log_step("init");
//track whether a [player] tag with persistence information exists (in addition to the [side] tag)
@ -302,9 +291,9 @@ protected:
team_builder_ptr create_team_builder(const config& side_cfg,
std::vector<team>& teams,
const config& level, game_board& board)
const config& level, game_board& board, int num)
{
return team_builder_ptr(new team_builder(side_cfg, teams, level, board));
return team_builder_ptr(new team_builder(side_cfg, teams, level, board, num));
}
void build_team_stage_one(team_builder_ptr tb_ptr)

View file

@ -30,7 +30,7 @@ typedef std::shared_ptr<team_builder> team_builder_ptr;
//create an object responsible for creating and populating a team from a config
team_builder_ptr create_team_builder(const config& side_cfg,
std::vector<team>& teams,
const config& level, game_board& board);
const config& level, game_board& board, int num);
//do first stage of team initialization (everything except unit placement)
void build_team_stage_one(team_builder_ptr tb_ptr);