fixed bug where an invalid side specification for a unit could crash the game

This commit is contained in:
uid68803 2004-01-12 16:50:46 +00:00
parent 2979c91358
commit ba11daeba6
3 changed files with 17 additions and 0 deletions

View file

@ -502,3 +502,12 @@ const std::string& team::music() const
{
return info_.music;
}
int team::nteams()
{
if(teams == NULL) {
return 0;
} else {
return teams->size();
}
}

View file

@ -111,6 +111,8 @@ public:
void refog();
const std::string& music() const;
static int nteams();
private:
int gold_;
std::set<gamemap::location> towers_;

View file

@ -417,6 +417,12 @@ void unit::read(game_data& data, const config& cfg)
backupMaxExperience_ = type_->experience_needed();
side_ = atoi(cfg["side"].c_str());
if(side_ <= 0)
side_ = 1;
if(side_ > team::nteams())
side_ = team::nteams();
description_ = cfg["user_description"];
underlying_description_ = cfg["description"];
if(description_ == "") {