Game modes cleanup

- Fix some cases where modes were still referenced by number
- Replace most cases of mode range-comparison with is_out(), is_town(), and/or is_combat()

There could be some minor errors in the replacements.
This commit is contained in:
2020-02-04 00:02:08 -05:00
parent 02d98db391
commit 72bd8265fa
12 changed files with 76 additions and 92 deletions

View File

@@ -231,9 +231,7 @@ void init_screen_locs() {
}
bool prime_time() {
if((overall_mode < MODE_TALK_TOWN) || (overall_mode == MODE_COMBAT))
return true;
return false;
return overall_mode == MODE_OUTDOORS || overall_mode == MODE_TOWN || overall_mode == MODE_COMBAT;
}
static void handle_spellcast(eSkill which_type, bool& did_something, bool& need_redraw, bool& need_reprint) {
@@ -1750,7 +1748,7 @@ bool handle_keystroke(const sf::Event& event){
print_buf();
break;
case 'z': // Show active PC's inventory
if(((overall_mode >= MODE_COMBAT) && (overall_mode < MODE_TALKING)) || (overall_mode == MODE_LOOK_COMBAT)) {
if(is_combat()) {
set_stat_window_for_pc(univ.cur_pc);
put_item_screen(stat_window);
} else {
@@ -2188,7 +2186,7 @@ void post_load() {
//mode; // 0 - normal 1 - save as
void do_save(short mode) {
if(overall_mode > MODE_TOWN && overall_mode != MODE_STARTUP) {
if(overall_mode != MODE_TOWN && overall_mode != MODE_OUTDOORS && overall_mode != MODE_STARTUP) {
add_string_to_buf("Save: Only while outdoors, or in town and not looking/casting.", 2);
print_buf();
return;
@@ -2261,7 +2259,7 @@ void do_rest(long length, int hp_restore, int mp_restore) {
pc.disease(6);
}
cInvenSlot item = pc.has_abil_equip(eItemAbil::REGENERATE);
if(item && pc.cur_health < pc.max_health && (overall_mode > MODE_OUTDOORS || get_ran(1,0,10) == 5)){
if(item && pc.cur_health < pc.max_health && (overall_mode != MODE_OUTDOORS || get_ran(1,0,10) == 5)){
int j = get_ran(1,0,item->abil_data[0] / 3);
if(item->abil_data[0] / 3 == 0)
j = get_ran(1,0,1);
@@ -2328,7 +2326,7 @@ void increase_age() {
move_to_zero(univ.party.status[ePartyStatus::FLIGHT]);
if(overall_mode > MODE_OUTDOORS && univ.town->lighting_type >= LIGHT_DRAINS) {
if(overall_mode != MODE_OUTDOORS && univ.town->lighting_type >= LIGHT_DRAINS) {
increase_light(-9);
if(univ.town->lighting_type == LIGHT_NONE) {
if(univ.party.light_level > 0)
@@ -2390,7 +2388,7 @@ void increase_age() {
}
// Food
if((univ.party.age % 1000 == 0) && (overall_mode < MODE_COMBAT)) {
if(univ.party.age % 1000 == 0 && !is_combat()) {
for(cPlayer& pc : univ.party)
if(pc.main_status == eMainStatus::ALIVE)
how_many_short++;
@@ -2400,7 +2398,8 @@ void increase_age() {
play_sound(66);
r1 = get_ran(3,1,6);
hit_party(r1,eDamageType::SPECIAL);
if(overall_mode < MODE_COMBAT)
// Might seem redudant but maybe hit_party could change the mode if TPK?
if(!is_combat())
boom_space(univ.party.out_loc,overall_mode,0,r1,0);
}
else {
@@ -2483,7 +2482,7 @@ void increase_age() {
move_to_zero(pc.status[eStatus::BLESS_CURSE]);
move_to_zero(pc.status[eStatus::HASTE_SLOW]);
if(cInvenSlot item = pc.has_abil_equip(eItemAbil::REGENERATE)) {
if(pc.cur_health < pc.max_health && (overall_mode > MODE_OUTDOORS || get_ran(1,0,10) == 5)) {
if(pc.cur_health < pc.max_health && (overall_mode != MODE_OUTDOORS || get_ran(1,0,10) == 5)) {
int j = get_ran(1,0,item->abil_data[0] / 3);
if(item->abil_data[0] / 3 == 0)
j = get_ran(1,0,1);

View File

@@ -75,7 +75,7 @@ void set_up_apple_events(int, char*[]) {
return NSTerminateNow;
}
if(overall_mode < MODE_TALK_TOWN || (overall_mode == MODE_STARTUP && party_in_memory)) {
if(overall_mode == MODE_TOWN || overall_mode == MODE_OUTDOORS || (overall_mode == MODE_STARTUP && party_in_memory)) {
std::string choice = cChoiceDlog("quit-confirm-save", {"save", "quit", "cancel"}).show();
if(choice == "cancel") return NSTerminateCancel;
if(choice == "save")

View File

@@ -2198,7 +2198,7 @@ void do_monster_turn() {
monsters_going = true; // This affects how graphics are drawn.
num_monst = univ.town.monst.size();
if(overall_mode < MODE_COMBAT)
if(!is_combat())
which_combat_type = 1;
for(short i = 0; i < num_monst; i++) { // Give monsters ap's, check activity
@@ -2574,7 +2574,7 @@ void do_monster_turn() {
}
// pcs attack any fleeing monsters
if((overall_mode >= MODE_COMBAT) && (overall_mode < MODE_TALKING))
if(is_combat())
for(short k = 0; k < 6; k++)
if(univ.party[k].main_status == eMainStatus::ALIVE && !monst_adjacent(univ.party[k].combat_pos,i)
&& pc_adj[k] && !cur_monst->is_friendly() && cur_monst->active > 0 &&
@@ -2739,7 +2739,7 @@ void do_monster_turn() {
}
// If in town, need to restore center
if(overall_mode < MODE_COMBAT)
if(!is_combat())
center = univ.party.town_loc;
if(had_monst)
put_pc_screen();
@@ -2990,7 +2990,7 @@ void monst_fire_missile(short m_num,short bless,std::pair<eMonstAbil,uAbility> a
cPlayer* pc_target = dynamic_cast<cPlayer*>(target);
cCreature* m_target = dynamic_cast<cCreature*>(target);
if(((overall_mode >= MODE_COMBAT) && (overall_mode <= MODE_TALKING)) && (center_on_monst)) {
if(is_combat() && center_on_monst) {
frame_space(source,0,univ.town.monst[m_num].x_width,univ.town.monst[m_num].y_width);
if(m_target != nullptr)
frame_space(targ_space,1,m_target->x_width,m_target->y_width);
@@ -3344,7 +3344,7 @@ bool monst_breathe(cCreature *caster,location targ_space,uAbility abil) {
caster->breathe_note();
short level = get_ran(abil.gen.strength,1,8);
if(overall_mode < MODE_COMBAT)
if(!is_combat())
level = level / 3;
start_missile_anim();
hit_space(targ_space,level,abil.gen.dmg,1,1);
@@ -4497,20 +4497,19 @@ void hit_space(location target,short dam,eDamageType type,short report,short hit
stop_hitting = (hit_all == 1) ? false : true;
}
if(overall_mode >= MODE_COMBAT)
if(is_combat()) {
for(cPlayer& pc : univ.party)
if(pc.main_status == eMainStatus::ALIVE && !stop_hitting)
if(pc.combat_pos == target) {
damage_pc(pc,dam,type,eRace::UNKNOWN,0);
stop_hitting = (hit_all == 1) ? false : true;
}
if(overall_mode < MODE_COMBAT)
if(target == univ.party.town_loc) {
fast_bang = 1;
hit_party(dam,type);
fast_bang = 0;
stop_hitting = (hit_all == 1) ? false : true;
}
} else if(target == univ.party.town_loc) {
fast_bang = 1;
hit_party(dam,type);
fast_bang = 0;
stop_hitting = (hit_all == 1) ? false : true;
}
if((report == 1) && (hit_all == 0) && !stop_hitting)
add_string_to_buf(" Missed.");
@@ -4609,7 +4608,7 @@ void handle_acid() {
damage_pc(pc,r1,eDamageType::MAGIC,eRace::UNKNOWN,0);
move_to_zero(pc.status[eStatus::ACID]);
}
if(overall_mode < MODE_COMBAT)
if(!is_combat())
boom_space(univ.party.out_loc,overall_mode,3,r1,8);
}
}
@@ -5417,18 +5416,17 @@ void scloud_space(short m,short n) {
univ.town.set_scloud(m,n,true);
if(overall_mode >= MODE_COMBAT)
if(is_combat()) {
for(cPlayer& pc : univ.party)
if(pc.main_status == eMainStatus::ALIVE)
if(pc.combat_pos == target) {
pc.curse(get_ran(1,1,2));
}
if(overall_mode < MODE_COMBAT)
if(target == univ.party.town_loc) {
for(cPlayer& pc : univ.party)
if(pc.main_status == eMainStatus::ALIVE)
pc.curse(get_ran(1,1,2));
}
} else if(target == univ.party.town_loc) {
for(cPlayer& pc : univ.party)
if(pc.main_status == eMainStatus::ALIVE)
pc.curse(get_ran(1,1,2));
}
}
void web_space(short m,short n) {
@@ -5436,33 +5434,31 @@ void web_space(short m,short n) {
univ.town.set_web(m,n,true);
if(overall_mode >= MODE_COMBAT)
if(is_combat()) {
for(cPlayer& pc : univ.party)
if(pc.main_status == eMainStatus::ALIVE)
if(pc.combat_pos == target) {
pc.web(3);
}
if(overall_mode < MODE_COMBAT)
if(target == univ.party.town_loc) {
for(cPlayer& pc : univ.party)
pc.web(3);
}
} else if(target == univ.party.town_loc) {
for(cPlayer& pc : univ.party)
pc.web(3);
}
}
void sleep_cloud_space(short m,short n) {
location target(m, n);
univ.town.set_sleep_cloud(m,n,true);
if(overall_mode >= MODE_COMBAT)
if(is_combat()) {
for(cPlayer& pc : univ.party)
if(pc.main_status == eMainStatus::ALIVE)
if(pc.combat_pos == target) {
pc.sleep(eStatus::ASLEEP,3,0);
}
if(overall_mode < MODE_COMBAT)
if(target == univ.party.town_loc) {
univ.party.sleep(eStatus::ASLEEP,3,0);
}
} else if(target == univ.party.town_loc) {
univ.party.sleep(eStatus::ASLEEP,3,0);
}
}

View File

@@ -14,18 +14,21 @@
/* overall mode; some seem to be missing */
enum eGameMode {
MODE_OUTDOORS = 0,
// Town modes
MODE_TOWN = 1,
MODE_TALK_TOWN = 2, // looking for someone to talk
MODE_TOWN_TARGET = 3, // spell target, that is
MODE_USE_TOWN = 4,
MODE_DROP_TOWN = 5,
MODE_BASH_TOWN = 6, // unused
// Combat modes
MODE_COMBAT = 10,
MODE_SPELL_TARGET = 11,
MODE_FIRING = 12, // firing from bow or crossbow
MODE_THROWING = 13, // throwing missile
MODE_FANCY_TARGET = 14, // spell target, that is; I think it's for multitarget spells
MODE_DROP_COMBAT = 15,
// Other modes
MODE_TALKING = 20,
MODE_SHOPPING = 21,
MODE_LOOK_OUTDOORS = 35, // looking at something

View File

@@ -896,7 +896,7 @@ void draw_terrain(short mode) {
draw_monsters();
}
if((overall_mode < MODE_COMBAT) || (overall_mode == MODE_LOOK_OUTDOORS) || ((overall_mode == MODE_LOOK_TOWN) && (point_onscreen(univ.party.town_loc,center)))
if(is_out() || (is_town() && point_onscreen(univ.party.town_loc,center))
|| (overall_mode == MODE_RESTING))
draw_party_symbol(center);
else if(overall_mode != MODE_LOOK_TOWN)
@@ -921,7 +921,7 @@ void draw_terrain(short mode) {
if(mode == 0) {
redraw_terrain();
draw_text_bar();
if((overall_mode >= MODE_COMBAT) && (overall_mode != MODE_LOOK_OUTDOORS) && (overall_mode != MODE_LOOK_TOWN) && (overall_mode != MODE_RESTING))
if(is_combat())
frame_active_pc(center);
if(overall_mode == MODE_FANCY_TARGET)
draw_targets(center);
@@ -1358,7 +1358,7 @@ void boom_space(location where,short mode,short type,short damage,short sound) {
return;
// Redraw terrain in proper position
if(((!point_onscreen(center,where) && (overall_mode >= MODE_COMBAT)) || (overall_mode == MODE_OUTDOORS))
if(((!point_onscreen(center,where) && is_combat()) || (overall_mode == MODE_OUTDOORS))
) {
play_sound(sound_to_play);
@@ -1427,7 +1427,7 @@ void boom_space(location where,short mode,short type,short damage,short sound) {
sf::sleep(time_in_ticks(del_len));
}
redraw_terrain();
if((overall_mode >= MODE_COMBAT/*9*/) && (overall_mode != MODE_LOOK_OUTDOORS) && (overall_mode != MODE_LOOK_TOWN) && (overall_mode != MODE_RESTING))
if(is_combat())
frame_active_pc(center);
}

View File

@@ -231,7 +231,7 @@ void give_thing(short pc_num, short item_num) {
short dist_from_party(location where) {
short store = 1000;
if((overall_mode >= MODE_COMBAT) && (overall_mode < MODE_TALKING)) {
if(is_combat()) {
for(short i = 0; i < 6; i++)
if(univ.party[i].main_status == eMainStatus::ALIVE)
store = min(store,dist(univ.party[i].combat_pos,where));

View File

@@ -215,15 +215,7 @@ short combat_obscurity(short x, short y) {
}
ter_num_t coord_to_ter(short x,short y) {
ter_num_t what_terrain;
if((overall_mode == MODE_OUTDOORS) || (overall_mode == MODE_LOOK_OUTDOORS))
what_terrain = univ.out[x][y];
else if(((overall_mode > MODE_OUTDOORS) && (overall_mode < MODE_COMBAT))|| (overall_mode == MODE_LOOK_TOWN))
what_terrain = univ.town->terrain(x,y);
else
what_terrain = univ.town->terrain(x,y);
return what_terrain;
return is_out() ? univ.out[x][y] : univ.town->terrain(x,y);
}
////
@@ -250,7 +242,7 @@ void update_explored(location dest) {
which_party_sec.x = univ.party.outdoor_corner.x + univ.party.i_w_c.x;
which_party_sec.y = univ.party.outdoor_corner.y + univ.party.i_w_c.y;
if(overall_mode == MODE_OUTDOORS) {
if(is_out()) {
univ.out.out_e[dest.x][dest.y] = 2;
for(look.x = shortdest.x - 4; look.x < shortdest.x + 5; look.x++)
for(look.y = shortdest.y - 4; look.y < shortdest.y + 5; look.y++) {
@@ -261,11 +253,7 @@ void update_explored(location dest) {
univ.out.out_e[look.x][look.y] = 1;
//}
}
}
if(overall_mode > MODE_OUTDOORS) {
} else {
make_explored(dest.x,dest.y);
for(look2.x = max(0,dest.x - 4); look2.x < min(univ.town->max_dim,dest.x + 5); look2.x++)
for(look2.y = max(0,dest.y - 4); look2.y < min(univ.town->max_dim,dest.y + 5); look2.y++)

View File

@@ -283,17 +283,16 @@ void handle_one_event(const sf::Event& event) {
All_Done = true;
break;
}
if(overall_mode > MODE_TOWN){
std::string choice = cChoiceDlog("quit-confirm-nosave", {"quit", "cancel"}).show();
if(choice == "cancel")
break;
}
else {
if(overall_mode == MODE_TOWN || overall_mode == MODE_OUTDOORS){
std::string choice = cChoiceDlog("quit-confirm-save", {"save", "quit", "cancel"}).show();
if(choice == "cancel")
break;
if(choice == "save")
save_party(univ.file, univ);
} else {
std::string choice = cChoiceDlog("quit-confirm-nosave", {"quit", "cancel"}).show();
if(choice == "cancel")
break;
}
All_Done = true;
default:
@@ -459,12 +458,7 @@ void handle_menu_choice(eMenu item_hit) {
All_Done = true;
break;
}
if(overall_mode > MODE_TOWN) {
std::string choice = cChoiceDlog("quit-confirm-nosave",{"quit","cancel"}).show();
if(choice == "cancel")
return;
}
else {
if(overall_mode == MODE_TOWN || overall_mode == MODE_OUTDOORS) {
std::string choice = cChoiceDlog("quit-confirm-save",{"quit","save","cancel"}).show();
if(choice == "cancel")
break;
@@ -475,6 +469,10 @@ void handle_menu_choice(eMenu item_hit) {
}
save_party(univ.file, univ);
}
} else {
std::string choice = cChoiceDlog("quit-confirm-nosave",{"quit","cancel"}).show();
if(choice == "cancel")
return;
}
All_Done = true;
break;
@@ -697,11 +695,11 @@ void move_sound(ter_num_t ter,short step){
on_swamp = true;
} else on_swamp = false;
if(!monsters_going && (overall_mode < MODE_COMBAT) && (univ.party.in_boat >= 0)) {
if(!monsters_going && !is_combat() && (univ.party.in_boat >= 0)) {
if(spec == eTerSpec::TOWN_ENTRANCE)
return;
play_sound(48); //play boat sound
} else if(!monsters_going && (overall_mode < MODE_COMBAT) && (univ.party.in_horse >= 0)) {
} else if(!monsters_going && !is_combat() && (univ.party.in_horse >= 0)) {
play_sound(85); //so play horse sound
} else switch(univ.scenario.ter_types[ter].step_sound){
case eStepSnd::SQUISH:

View File

@@ -642,7 +642,7 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) {
"Expensive","Exorbitant","Utterly Ridiculous"};
cItem base_item;
if(overall_mode != 21) {
if(overall_mode != MODE_SHOPPING) {
return;
}

View File

@@ -15,6 +15,7 @@
#include "boe.specials.hpp"
#include "boe.infodlg.hpp"
#include "boe.items.hpp"
#include "boe.actions.hpp"
#include <cstring>
#include <queue>
#include "boe.party.hpp"
@@ -485,11 +486,10 @@ bool repeat_cast_ok(eSkill type) {
eSpellSelect store_select;
eSpell what_spell;
if(overall_mode == MODE_COMBAT)
if(!prime_time()) return false;
else if(overall_mode == MODE_COMBAT)
who_would_cast = univ.cur_pc;
else if(overall_mode < MODE_TALK_TOWN)
who_would_cast = pc_casting;
else return false;
else who_would_cast = pc_casting;
if(is_combat())
what_spell = univ.party[who_would_cast].last_cast[type];
@@ -900,7 +900,7 @@ void do_priest_spell(short pc_num,eSpell spell_num,bool freebie) {
break;
case eSpell::WORD_RECALL:
if(overall_mode > MODE_OUTDOORS) {
if(!is_out()) {
add_string_to_buf(" Can only cast outdoors.");
return;
}
@@ -2476,7 +2476,7 @@ void kill_pc(cPlayer& which_pc,eMainStatus type) {
for(short i = 0; i < which_pc.items.size(); i++)
which_pc.equip[i] = false;
item_loc = (overall_mode >= MODE_COMBAT) ? which_pc.combat_pos : univ.party.town_loc;
item_loc = is_combat() ? which_pc.combat_pos : univ.party.town_loc;
if(!is_out()) {
if(type == eMainStatus::DUST)

View File

@@ -259,7 +259,7 @@ bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc,
if(!can_enter)
return false;
if((!is_out()) && (overall_mode < MODE_TALKING)) {
if(!is_out()) {
check_fields(where_check,mode,which_pc);
if(univ.town.is_web(where_check.x,where_check.y) && univ.current_pc().race != eRace::BUG) {
@@ -532,7 +532,7 @@ void check_fields(location where_check,eSpecCtx mode,cPlayer& which_pc) {
r1 = get_ran(2,1,6);
if(mode == eSpecCtx::COMBAT_MOVE)
damage_pc(which_pc,r1,eDamageType::COLD,eRace::UNKNOWN,0);
if(overall_mode < MODE_COMBAT)
if(!is_combat())
boom_space(univ.party.town_loc,overall_mode,4,r1,7);
}
if(univ.town.is_blade_wall(where_check.x,where_check.y)) {

View File

@@ -1330,8 +1330,8 @@ void draw_map(bool need_refresh) {
// area_to_draw_on is final draw to rect
// extern short store_pre_shop_mode,store_pre_talk_mode;
if((is_out()) || ((is_combat()) && (which_combat_type == 0)) ||
((overall_mode == MODE_TALKING) && (store_pre_talk_mode == 0)) ||
((overall_mode == MODE_SHOPPING) && (store_pre_shop_mode == 0))) {
((overall_mode == MODE_TALKING) && (store_pre_talk_mode == MODE_OUTDOORS)) ||
((overall_mode == MODE_SHOPPING) && (store_pre_shop_mode == MODE_OUTDOORS))) {
view_rect.left = minmax(0,8,univ.party.loc_in_sec.x - 20);
view_rect.right = view_rect.left + 40;
view_rect.top = minmax(0,8,univ.party.loc_in_sec.y - 20);
@@ -1362,8 +1362,8 @@ void draw_map(bool need_refresh) {
}
}
if((is_out()) || ((is_combat()) && (which_combat_type == 0)) ||
((overall_mode == MODE_TALKING) && (store_pre_talk_mode == 0)) ||
((overall_mode == MODE_SHOPPING) && (store_pre_shop_mode == 0)) ||
((overall_mode == MODE_TALKING) && (store_pre_talk_mode == MODE_OUTDOORS)) ||
((overall_mode == MODE_SHOPPING) && (store_pre_shop_mode == MODE_OUTDOORS)) ||
is_town() || is_combat()) {
area_to_draw_from = view_rect;
area_to_draw_from.width() = 40;
@@ -1398,8 +1398,8 @@ void draw_map(bool need_refresh) {
if((is_out()) ||
((is_combat()) && (which_combat_type == 0)) ||
((overall_mode == MODE_TALKING) && (store_pre_talk_mode == 0)) ||
((overall_mode == MODE_SHOPPING) && (store_pre_shop_mode == 0)))
((overall_mode == MODE_TALKING) && (store_pre_talk_mode == MODE_OUTDOORS)) ||
((overall_mode == MODE_SHOPPING) && (store_pre_shop_mode == MODE_OUTDOORS)))
out_mode = true;
else out_mode = false;