Add enum for creature status

This commit is contained in:
2024-08-21 23:41:57 -04:00
parent 20c53fb2ed
commit 23e0db9922
18 changed files with 157 additions and 139 deletions

View File

@@ -28,7 +28,7 @@ cCreature::cCreature(int num) : cCreature() {
}
void cCreature::import_legacy(legacy::creature_data_type old){
active = old.active;
active = eCreatureStatus(old.active);
attitude = eAttitude(old.attitude);
number = old.number;
cur_loc.x = old.m_loc.x;
@@ -261,7 +261,7 @@ void cCreature::sleep(eStatus which_status,int amount,int penalty) {
}
bool cCreature::is_alive() const {
return active > 0;
return active != eCreatureStatus::DEAD;
}
bool cCreature::is_friendly() const {

View File

@@ -16,10 +16,12 @@
class cTagFile_Page;
enum class eCreatureStatus { DEAD, IDLE, ALERTED };
class cCreature : public cMonster, public cTownperson, public iLiving {
public:
static const short charm_odds[21];
short active = 0;
eCreatureStatus active = eCreatureStatus::DEAD;
eAttitude attitude;
location cur_loc;
short summon_time = 0;
@@ -75,4 +77,7 @@ public:
void readFrom(const cTagFile_Page& file);
};
std::ostream& operator<< (std::ostream& out, eCreatureStatus status);
std::istream& operator>> (std::istream& in, eCreatureStatus& status);
#endif

View File

@@ -804,7 +804,7 @@ void cParty::writeTo(cTagFile& file) const {
}
for(int i = 0; i < creature_save.size(); i++) {
for(int j = 0; j < creature_save[i].size(); j++) {
if(creature_save[i][j].active > 0) {
if(creature_save[i][j].is_alive()) {
auto& creature_page = file.add();
creature_page["CREATURE"] << i << j;
creature_save[i][j].writeTo(creature_page);

View File

@@ -33,7 +33,7 @@ cCreature& cPopulation::operator[](size_t n){
void cPopulation::init(size_t n) {
if(n >= dudes.size()) dudes.resize(n + 1);
dudes[n].active = 1;
dudes[n].active = eCreatureStatus::IDLE;
}
// This function combines a cTownperson from a scenario town record with a cMonster from the scenario record
@@ -46,7 +46,7 @@ void cPopulation::assign(size_t n, const cTownperson& other, const cMonster& bas
static_cast<cTownperson&>(dudes[n]) = other;
static_cast<cMonster&>(dudes[n]) = base;
// Now set up extra stuff
dudes[n].active = 1; // TODO: Is this right?
dudes[n].active = eCreatureStatus::IDLE; // TODO: Is this right?
if(dudes[n].invisible) dudes[n].picture_num = 0;
dudes[n].m_health /= easy ? 2 : 1;
dudes[n].m_health *= difficulty_adjust;

View File

@@ -869,7 +869,7 @@ void cCurTown::writeTo(cTagFile& file) const {
}
}
for(int i = 0; i < monst.size(); i++) {
if(monst[i].active > 0) {
if(monst[i].is_alive()) {
auto& monst_page = file.add();
monst_page["CREATURE"] << i;
monst[i].writeTo(monst_page);
@@ -919,7 +919,7 @@ void cCurTown::readFrom(const cTagFile& file){
if(page["CREATURE"] >> i) {
monst.init(i);
monst[i].readFrom(page);
monst[i].active = true;
monst[i].active = eCreatureStatus::IDLE;
}
}
}
@@ -1375,7 +1375,7 @@ void cUniverse::clear_stored_pcs() {
short cCurTown::countMonsters() const {
short to_ret = 0;
for(short i = 0; i < monst.size(); i++)
if(monst[i].active > 0)
if(monst[i].is_alive())
to_ret++;
return to_ret;
}