Strictify PC main status enum

This commit is contained in:
2014-12-01 21:38:20 -05:00
parent 4a68c16c2a
commit e6057387eb
22 changed files with 320 additions and 296 deletions

View File

@@ -129,7 +129,7 @@ cParty::cConvers& cParty::cConvers::operator = (legacy::talk_save_type old){
void cParty::add_pc(legacy::pc_record_type old){
for(int i = 0; i < 6; i++)
if(adven[i].main_status == 0){
if(adven[i].main_status == eMainStatus::ABSENT){
adven[i] = old;
break;
}
@@ -137,12 +137,12 @@ void cParty::add_pc(legacy::pc_record_type old){
void cParty::void_pcs(){
for(int i = 0; i < 6; i++)
adven[i].main_status = MAIN_STATUS_ABSENT;
adven[i].main_status = eMainStatus::ABSENT;
}
void cParty::add_pc(cPlayer new_pc){
for(int i = 0; i < 6; i++)
if(adven[i].main_status == MAIN_STATUS_ABSENT){
if(adven[i].main_status == eMainStatus::ABSENT){
adven[i] = new_pc;
break;
}
@@ -637,7 +637,7 @@ std::string cParty::start_split(short a,short b,snd_num_t noise,short who) {
univ.town.p_loc.y = b;
for (i = 0; i < 6; i++)
if (!stuff_done[304][who])
adven[i].main_status += MAIN_STATUS_SPLIT;
adven[i].main_status += eMainStatus::SPLIT;
if (noise > 0)
play_sound(10);
return "";
@@ -651,8 +651,8 @@ std::string cParty::end_split(snd_num_t noise) {
univ.town.p_loc = left_at();
univ.town.num = left_in();
for (i = 0; i < 6; i++){
if (univ.party[i].main_status >= MAIN_STATUS_SPLIT)
univ.party[i].main_status -= MAIN_STATUS_SPLIT;
if(isSplit(univ.party[i].main_status))
univ.party[i].main_status -= eMainStatus::SPLIT;
stuff_done[304][i] = true;
}
if (noise > 0)

View File

@@ -65,7 +65,7 @@ short cPlayer::get_tnl(){
cPlayer::cPlayer(){
short i;
main_status = MAIN_STATUS_ABSENT;
main_status = eMainStatus::ABSENT;
name = "\n";
for (i = 0; i < 30; i++)
@@ -102,7 +102,7 @@ cPlayer::cPlayer(){
cPlayer::cPlayer(long key,short slot){
short i;
main_status = MAIN_STATUS_ALIVE;
main_status = eMainStatus::ALIVE;
if(key == 'dbug'){
switch (slot) {
case 0:
@@ -178,7 +178,7 @@ cPlayer::cPlayer(long key,short slot){
{0,1,0,0,0, 0,0,0,0,0, 0,0,0,0,0}
};
main_status = MAIN_STATUS_ALIVE;
main_status = eMainStatus::ALIVE;
switch (slot) {
case 0:
name = "Jenneke";
@@ -235,13 +235,17 @@ cPlayer::cPlayer(long key,short slot){
}
void operator += (eMainStatus& stat, eMainStatus othr){
if(othr == MAIN_STATUS_SPLIT)
stat = (eMainStatus) (10 + stat);
if(othr == eMainStatus::SPLIT)
stat = (eMainStatus) (10 + (int)stat);
else if(stat == eMainStatus::SPLIT)
stat = (eMainStatus) (10 + (int)othr);
}
void operator -= (eMainStatus& stat, eMainStatus othr){
if(othr == MAIN_STATUS_SPLIT)
stat = (eMainStatus) (-10 + stat);
if(othr == eMainStatus::SPLIT)
stat = (eMainStatus) (-10 + (int)stat);
else if(stat == eMainStatus::SPLIT)
stat = (eMainStatus) (-10 + (int)othr);
}
void cPlayer::writeTo(std::ostream& file){
@@ -373,11 +377,12 @@ std::ostream& operator << (std::ostream& out, eMainStatus& e){
return out << (int) e;
}
// TODO: This should probably understand symbolic names as well as the numbers?
std::istream& operator >> (std::istream& in, eMainStatus& e){
int i;
in >> i;
if(i > 0 && i < 18 && i !=8 && i != 9)
e = (eMainStatus) i;
else e = MAIN_STATUS_ABSENT;
else e = eMainStatus::ABSENT;
return in;
}

View File

@@ -15,27 +15,45 @@ typedef signed short spec_num_t;
typedef signed short item_num_t;
typedef unsigned short str_num_t;
enum eMainStatus {
MAIN_STATUS_ABSENT = 0, // absent, empty slot
MAIN_STATUS_ALIVE = 1,
MAIN_STATUS_DEAD = 2,
MAIN_STATUS_DUST = 3,
MAIN_STATUS_STONE = 4,
MAIN_STATUS_FLED = 5,
MAIN_STATUS_SURFACE = 6, // fled to surface?
MAIN_STATUS_WON = 7,
MAIN_STATUS_SPLIT = 10,
// The rest are not really necessary, but are here for completeness so that all valid values have a name.
MAIN_STATUS_SPLIT_ABSENT = MAIN_STATUS_SPLIT + MAIN_STATUS_ABSENT,
MAIN_STATUS_SPLIT_ALIVE = MAIN_STATUS_SPLIT + MAIN_STATUS_ALIVE,
MAIN_STATUS_SPLIT_DEAD = MAIN_STATUS_SPLIT + MAIN_STATUS_DEAD,
MAIN_STATUS_SPLIT_DUST = MAIN_STATUS_SPLIT + MAIN_STATUS_DUST,
MAIN_STATUS_SPLIT_STONE = MAIN_STATUS_SPLIT + MAIN_STATUS_STONE,
MAIN_STATUS_SPLIT_FLED = MAIN_STATUS_SPLIT + MAIN_STATUS_FLED,
MAIN_STATUS_SPLIT_SURFACE = MAIN_STATUS_SPLIT + MAIN_STATUS_SURFACE,
MAIN_STATUS_SPLIT_WON = MAIN_STATUS_SPLIT + MAIN_STATUS_WON,
enum class eMainStatus {
ABSENT = 0, // absent, empty slot
ALIVE = 1,
DEAD = 2,
DUST = 3,
STONE = 4,
FLED = 5,
SURFACE = 6, // fled to surface?
WON = 7,
SPLIT = 10,
SPLIT_ABSENT = SPLIT + ABSENT,
SPLIT_ALIVE = SPLIT + ALIVE,
SPLIT_DEAD = SPLIT + DEAD,
SPLIT_DUST = SPLIT + DUST,
SPLIT_STONE = SPLIT + STONE,
SPLIT_FLED = SPLIT + FLED,
SPLIT_SURFACE = SPLIT + SURFACE,
SPLIT_WON = SPLIT + WON,
};
inline eMainStatus exceptSplit(eMainStatus stat) {
if(int(stat) >= 10)
return (eMainStatus) (-10 + (int)stat);
return stat;
}
inline bool isSplit(eMainStatus stat) {
return int(stat) >= 10;
}
inline bool isAbsent(eMainStatus stat) {
return stat == eMainStatus::ABSENT || int(stat) > 4;
}
inline bool isDead(eMainStatus stat) {
int code = (int) stat;
return code > 1 && code < 5;
}
/* adven[i].race */ //complete
enum eRace {
RACE_UNKNOWN = -1, // for parameters to some functions; not valid in the class

View File

@@ -833,7 +833,7 @@ short cUniverse::difficulty_adjust() {
if(!scenario.adjust_diff) return 1;
for (short i = 0; i < 6; i++)
if (party[i].main_status == 1)
if(party[i].main_status == eMainStatus::ALIVE)
party_level += party[i].level;
if ((scenario.difficulty <= 0) && (party_level >= 60))