Better range check for Set Monster Attitude

This commit is contained in:
2025-05-09 19:53:50 -05:00
parent d41b8d97c5
commit 287c6d4ac7
3 changed files with 16 additions and 4 deletions

View File

@@ -4147,9 +4147,10 @@ void townmode_spec(const runtime_state& ctx) {
else increase_light(-spec.ex2a); else increase_light(-spec.ex2a);
} }
break; break;
case eSpecType::TOWN_SET_ATTITUDE: case eSpecType::TOWN_SET_ATTITUDE:{
if((spec.ex1a < 0) || (spec.ex1a > 59)){ int num_monst = univ.town.monst.size();
showError("Tried to change the attitude of a nonexistent monster (should be 0...59)."); if((spec.ex1a < 0) || (spec.ex1a >= num_monst)){
showError("Tried to change the attitude of nonexistent monster " + std::to_string(spec.ex1a) + " of 0..." + std::to_string(num_monst));
break; break;
} }
if(spec.ex1b < 0 || spec.ex1b > 3){ if(spec.ex1b < 0 || spec.ex1b > 3){
@@ -4157,7 +4158,7 @@ void townmode_spec(const runtime_state& ctx) {
break; break;
} }
univ.town.monst[spec.ex1a].attitude = eAttitude(spec.ex1b); univ.town.monst[spec.ex1a].attitude = eAttitude(spec.ex1b);
break; }break;
case eSpecType::TOWN_RUN_MISSILE: case eSpecType::TOWN_RUN_MISSILE:
if(ctx.which_mode != eSpecCtx::TALK) { if(ctx.which_mode != eSpecCtx::TALK) {
int i; int i;

View File

@@ -31,6 +31,15 @@ cCreature& cPopulation::operator[](size_t n){
return dudes[n]; return dudes[n];
} }
const cCreature& cPopulation::at(size_t n) const {
return dudes.at(n);
}
cCreature& cPopulation::at(size_t n){
return dudes.at(n);
}
void cPopulation::init(size_t n) { void cPopulation::init(size_t n) {
if(n >= dudes.size()) dudes.resize(n + 1); if(n >= dudes.size()) dudes.resize(n + 1);
dudes[n].active = eCreatureStatus::IDLE; dudes[n].active = eCreatureStatus::IDLE;

View File

@@ -32,6 +32,8 @@ public:
void clear() {dudes.clear();} void clear() {dudes.clear();}
cCreature& operator[](size_t n); cCreature& operator[](size_t n);
const cCreature& operator[](size_t n) const; const cCreature& operator[](size_t n) const;
cCreature& at(size_t n);
const cCreature& at(size_t n) const;
cPopulation() : which_town(200), hostile(false) {} cPopulation() : which_town(200), hostile(false) {}
std::deque<cCreature>::iterator begin() {return dudes.begin();} std::deque<cCreature>::iterator begin() {return dudes.begin();}
std::deque<cCreature>::iterator end() {return dudes.end();} std::deque<cCreature>::iterator end() {return dudes.end();}