fixed bug where an invalid side specification for a unit could crash the game
This commit is contained in:
parent
2979c91358
commit
ba11daeba6
3 changed files with 17 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -111,6 +111,8 @@ public:
|
|||
void refog();
|
||||
|
||||
const std::string& music() const;
|
||||
|
||||
static int nteams();
|
||||
private:
|
||||
int gold_;
|
||||
std::set<gamemap::location> towers_;
|
||||
|
|
|
@ -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_ == "") {
|
||||
|
|
Loading…
Add table
Reference in a new issue