From 9363ab2fcfedbcccf8e0bd3ab71656f6b77b32a3 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 21 Aug 2016 00:46:40 -0400 Subject: [PATCH] Eliminate function-scope loop index variables This makes all loop index variables local to their loop and fixes some issue arising from the loop variables being present through the whole function, such as using the wrong index variable. In addition, there has been some reduction of code duplication in the scenario editor. --- src/boe.actions.cpp | 181 +++++----- src/boe.combat.cpp | 286 +++++++-------- src/boe.dlgutil.cpp | 77 ++-- src/boe.fileio.cpp | 81 ++--- src/boe.graphics.cpp | 73 ++-- src/boe.graphutil.cpp | 36 +- src/boe.infodlg.cpp | 36 +- src/boe.itemdata.cpp | 6 +- src/boe.items.cpp | 40 +-- src/boe.locutils.cpp | 51 ++- src/boe.main.cpp | 4 +- src/boe.menus.mac.mm | 40 +-- src/boe.monster.cpp | 79 ++--- src/boe.newgraph.cpp | 109 +++--- src/boe.party.cpp | 241 ++++++------- src/boe.party.hpp | 4 +- src/boe.specials.cpp | 627 ++++++++++++++++----------------- src/boe.startup.cpp | 4 +- src/boe.text.cpp | 82 ++--- src/boe.town.cpp | 270 +++++++------- src/boe.townspec.cpp | 11 +- src/classes/outdoors.cpp | 24 +- src/classes/party.cpp | 45 +-- src/classes/pc.cpp | 35 +- src/classes/regtown.cpp | 39 +- src/classes/scenario.cpp | 29 +- src/classes/talking.cpp | 5 +- src/classes/town.cpp | 20 +- src/classes/universe.cpp | 13 +- src/pcedit/pc.action.cpp | 10 +- src/pcedit/pc.editors.cpp | 21 +- src/pcedit/pc.graphics.cpp | 30 +- src/pcedit/pc.main.cpp | 32 +- src/scenedit/scen.actions.cpp | 608 ++++++++++++-------------------- src/scenedit/scen.btnmg.cpp | 23 +- src/scenedit/scen.core.cpp | 50 +-- src/scenedit/scen.fileio.cpp | 7 +- src/scenedit/scen.graphics.cpp | 96 +++-- src/scenedit/scen.keydlgs.cpp | 59 ++-- src/scenedit/scen.keydlgs.hpp | 3 +- src/scenedit/scen.townout.cpp | 34 +- src/scenedit/scen.townout.hpp | 4 +- src/tools/fileio_scen.cpp | 71 ++-- src/tools/graphtool.cpp | 8 +- src/tools/mathutil.cpp | 4 +- src/tools/porting.cpp | 128 +++---- src/tools/soundtool.cpp | 4 +- 47 files changed, 1629 insertions(+), 2111 deletions(-) diff --git a/src/boe.actions.cpp b/src/boe.actions.cpp index 8e3586a3..c1e09094 100644 --- a/src/boe.actions.cpp +++ b/src/boe.actions.cpp @@ -129,11 +129,10 @@ bool current_bash_is_bash = false; extern void edit_stuff_done(); void init_screen_locs() { - short i,j,k,l; rectangle startup_base = {279,5,327,306}; rectangle shop_base = {63,12,99,267}; - for(i = 0; i < 7; i++) + for(short i = 0; i < 7; i++) shopping_rects[0][i] = shop_base; shopping_rects[0][SHOPRECT_ACTIVE_AREA].right -= 35; shopping_rects[0][SHOPRECT_GRAPHIC].right = shopping_rects[0][SHOPRECT_GRAPHIC].left + 28; @@ -148,14 +147,14 @@ void init_screen_locs() { shopping_rects[0][SHOPRECT_ITEM_HELP].bottom -= 21; shopping_rects[0][SHOPRECT_ITEM_HELP].right -= 19; shopping_rects[0][SHOPRECT_ITEM_HELP].left = shopping_rects[0][SHOPRECT_ITEM_HELP].right - 14; - for(i = 1; i < 8; i++) - for(j = 0; j < 7; j++) { + for(short i = 1; i < 8; i++) + for(short j = 0; j < 7; j++) { shopping_rects[i][j] = shopping_rects[0][j]; shopping_rects[i][j].offset(0,i * 36); } - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { startup_button[i] = startup_base; startup_button[i].offset(301 * (i / 3) - 18,48 * (i % 3)); } @@ -164,14 +163,14 @@ void init_screen_locs() { startup_top.left = 5; startup_top.right = startup_button[STARTBTN_JOIN].right; - for(i = 0; i < 200; i++) - for(j = 0; j < 8; j++) - for(k = 0; k < 64; k++)//// + for(short i = 0; i < 200; i++) + for(short j = 0; j < 8; j++) + for(short k = 0; k < 64; k++) univ.town_maps[i][j][k] = 0; - for(i = 0; i < 100; i++) - for(k = 0; k < 6; k++) - for(l = 0; l < 48; l++) + for(short i = 0; i < 100; i++) + for(short k = 0; k < 6; k++) + for(short l = 0; l < 48; l++) univ.out_maps[i][k][l] = 0; // name, use, give, drip, info, sell/id each one 13 down @@ -195,13 +194,13 @@ void init_screen_locs() { item_buttons[0][ITEMBTN_SPEC].left = 173; item_buttons[0][ITEMBTN_SPEC].right = 232; item_buttons[0][ITEMBTN_NAME].top += 3; - for(i = 1; i < 8; i++) - for(j = 0; j < 6; j++) { + for(short i = 1; i < 8; i++) + for(short j = 0; j < 6; j++) { item_buttons[i][j] = item_buttons[0][j]; item_buttons[i][j].offset(0,13 * i); } -/* for(i = 0; i < 8; i++) { +/* for(short i = 0; i < 8; i++) { item_screen_button_rects[i] = bottom_base; OffsetRect(&item_screen_button_rects[i],10 + i * 29,126); } @@ -232,8 +231,8 @@ void init_screen_locs() { pc_buttons[0][PCBTN_TRADE].left = 253; pc_buttons[0][PCBTN_TRADE].right = 262; pc_buttons[0][PCBTN_NAME].top += 3; - for(i = 1; i < 6; i++) - for(j = 0; j < 5; j++) { + for(short i = 1; i < 6; i++) + for(short j = 0; j < 5; j++) { pc_buttons[i][j] = pc_buttons[0][j]; pc_buttons[i][j].offset(0,13 * i); } @@ -1512,9 +1511,7 @@ void handle_monster_actions(bool& need_redraw, bool& need_reprint) { } bool someone_awake() { - short i; - - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE && univ.party[i].status[eStatus::ASLEEP] <= 0 && univ.party[i].status[eStatus::PARALYZED] <= 0) return true; @@ -1569,7 +1566,6 @@ void handle_menu_spell(eSpell spell_picked) { } void initiate_outdoor_combat(short i) { - short m,n; location to_place; draw_terrain(); @@ -1588,11 +1584,11 @@ void initiate_outdoor_combat(short i) { univ.party.out_c[i].exists = false; - for(m = 0; m < 6; m++) + for(short m = 0; m < 6; m++) if(univ.party[m].main_status == eMainStatus::ALIVE) to_place = univ.party[m].combat_pos; - for(m = 0; m < 6; m++) - for(n = 0; n < 24; n++) + for(short m = 0; m < 6; m++) + for(short n = 0; n < 24; n++) if(univ.party[m].main_status != eMainStatus::ALIVE && univ.party[m].items[n].variety != eItemType::NO_ITEM) { place_item(univ.party[m].items[n],to_place); univ.party[m].items[n].variety = eItemType::NO_ITEM; @@ -1606,7 +1602,6 @@ void initiate_outdoor_combat(short i) { bool handle_keystroke(sf::Event& event){ bool are_done = false; location pass_point; // TODO: This isn't needed - short i,j; std::ostringstream sout; using kb = sf::Keyboard; using Key = sf::Keyboard::Key; @@ -1673,7 +1668,7 @@ bool handle_keystroke(sf::Event& event){ chr2 = kb::D; if(chr2 == kb::Space) chr2 = kb::G; - for(i = 0; i < 9; i++) + for(short i = 0; i < 9; i++) if(chr2 == talk_chars[i] && (!talk_end_forced || i == 6 || i == 5)) { int j = talk_end_forced ? i - 5 : i; pass_point.x = talk_words[j].rect.left + 9 + ul.x; @@ -1688,7 +1683,7 @@ bool handle_keystroke(sf::Event& event){ play_sound(37); end_shop_mode(); } - for(i = 0; i < 8; i++) + for(short i = 0; i < 8; i++) if(chr2 == shop_chars[i]) { pass_point.x = shopping_rects[i][SHOPRECT_ACTIVE_AREA].left + 9 + ul.x; pass_point.y = shopping_rects[i][SHOPRECT_ACTIVE_AREA].top + 9 + ul.y; @@ -1697,7 +1692,7 @@ bool handle_keystroke(sf::Event& event){ are_done = handle_action(pass_event); } } else { - for(i = 0; i < 10; i++) + for(short i = 0; i < 10; i++) if(chr2 == keypad[i]) { if(i == 0) { chr2 = kb::Z; @@ -1811,13 +1806,13 @@ bool handle_keystroke(sf::Event& event){ if(!univ.debug_mode) break; univ.party.gold += 100; univ.party.food += 100; - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { univ.party[i].main_status = eMainStatus::ALIVE; univ.party[i].cur_health = univ.party[i].max_health; univ.party[i].cur_sp = 100; } award_party_xp(25); - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { auto& who = univ.party[i]; who.priest_spells.set(); who.mage_spells.set(); @@ -1891,7 +1886,7 @@ bool handle_keystroke(sf::Event& event){ if(!univ.debug_mode) break; univ.party.gold += 100; univ.party.food += 100; - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(isDead(univ.party[i].main_status)) univ.party[i].main_status = eMainStatus::ALIVE; } @@ -1904,7 +1899,7 @@ bool handle_keystroke(sf::Event& event){ case 'K': if(!univ.debug_mode) break; - for(i = 0; i < univ.town.monst.size(); i++) { + for(short i = 0; i < univ.town.monst.size(); i++) { if(is_combat() && univ.town.monst[i].active > 0 && !univ.town.monst[i].is_friendly()) univ.town.monst[i].active = 0; @@ -1943,26 +1938,27 @@ bool handle_keystroke(sf::Event& event){ break; case 'I': - if(!univ.debug_mode) break; - i = get_num_response(0, univ.scenario.scen_items.size()-1, "Which item?"); - j = univ.scenario.scen_items[i].ident; - univ.scenario.scen_items[i].ident = true; - univ.party.give_item(univ.scenario.scen_items[i], true); - univ.scenario.scen_items[i].ident = j; - print_buf(); - put_item_screen(stat_window); - put_pc_screen(); // In case the item was food or gold + if(univ.debug_mode) { + int i = get_num_response(0, univ.scenario.scen_items.size()-1, "Which item?"); + int j = univ.scenario.scen_items[i].ident; + univ.scenario.scen_items[i].ident = true; + univ.party.give_item(univ.scenario.scen_items[i], true); + univ.scenario.scen_items[i].ident = j; + print_buf(); + put_item_screen(stat_window); + put_pc_screen(); // In case the item was food or gold + } break; case 'Q': if(!univ.debug_mode) break; if(overall_mode == MODE_OUTDOORS) { - for(i = 0; i < 96; i++) - for(j = 0; j < 96; j++) + for(short i = 0; i < 96; i++) + for(short j = 0; j < 96; j++) make_explored(i,j); } else { - for(i = 0; i < 64; i++) - for(j = 0; j < 64; j++) + for(short i = 0; i < 64; i++) + for(short j = 0; j < 64; j++) make_explored(i,j); } clear_map(); @@ -1998,14 +1994,11 @@ bool handle_keystroke(sf::Event& event){ case 'T': if(!univ.debug_mode) break; short find_direction_from; - i = get_num_response(0, univ.scenario.towns.size() - 1, "Enter Town Number"); - if(i >= 0 && i < univ.scenario.towns.size()) { - if(univ.party.direction == 0) find_direction_from = 2; - else if(univ.party.direction == 4) find_direction_from = 0; - else if(univ.party.direction < 4) find_direction_from = 3; - else find_direction_from = 1; - start_town_mode(i, find_direction_from); - } + if(univ.party.direction == 0) find_direction_from = 2; + else if(univ.party.direction == 4) find_direction_from = 0; + else if(univ.party.direction < 4) find_direction_from = 3; + else find_direction_from = 1; + start_town_mode(get_num_response(0, univ.scenario.towns.size() - 1, "Enter Town Number"), find_direction_from); break; case 'W': @@ -2090,28 +2083,28 @@ bool handle_keystroke(sf::Event& event){ case 'm': case 'p': case 'l': case 'r': case 'w': case 't': case 'd': case 'g': case 'f': case 'M': case 'P': case 'A': - j = 50; + int btn = 50; if(overall_mode == MODE_SPELL_TARGET || overall_mode == MODE_FANCY_TARGET || overall_mode == MODE_TOWN_TARGET) { // cancel spell - if(chr == 'm') j = 0; - else if(chr == 'p') j = 1; + if(chr == 'm') btn = 0; + else if(chr == 'p') btn = 1; } // TODO: There's several weird things about this conditional. Why 'f' when the key to initiate this is 's'? Why is it checking for 't' (though that can never be true)? if(chr == 'f' && (overall_mode == MODE_FIRING || overall_mode == MODE_THROWING || chr == 't')) // cancel missile - j = 6; + btn = 6; if((overall_mode == MODE_OUTDOORS) || (overall_mode == MODE_TOWN) || (overall_mode == MODE_COMBAT)) { switch(chr) { - case 'M': spell_forced = true; j = 0; break; - case 'm': j = 0; break; - case 'P': spell_forced = true; j = 1; break; - case 'p': j = 1; break; - case 'l': j = 2; break; + case 'M': spell_forced = true; btn = 0; break; + case 'm': btn = 0; break; + case 'P': spell_forced = true; btn = 1; break; + case 'p': btn = 1; break; + case 'l': btn = 2; break; case 'r': if(overall_mode != MODE_OUTDOORS) return false; - j = 3; + btn = 3; break; case 't': if(overall_mode == MODE_TOWN) - j = 3; + btn = 3; else return false; break; case 'A': @@ -2128,7 +2121,7 @@ bool handle_keystroke(sf::Event& event){ break; case 'w': if(overall_mode == MODE_COMBAT) - j = 5; + btn = 5; else if(overall_mode == MODE_TOWN) { pass_point.x = 1001 + ul.x; pass_event.mouseButton.x = pass_point.x; @@ -2143,21 +2136,21 @@ bool handle_keystroke(sf::Event& event){ break; case 'd': if(overall_mode != MODE_COMBAT) return false; - j = 3; + btn = 3; break; case 'g': if(overall_mode == MODE_OUTDOORS) return false; - j = 4; + btn = 4; break; case 'f': if(overall_mode != MODE_TOWN) return false; - j = 7; + btn = 7; break; } } - if(j < 50) { - pass_point.x = bottom_buttons[j].left + 5; - pass_point.y = bottom_buttons[j].top + 5; + if(btn < 50) { + pass_point.x = bottom_buttons[btn].left + 5; + pass_point.y = bottom_buttons[btn].top + 5; pass_event.mouseButton.x = pass_point.x + ul.x; pass_event.mouseButton.y = pass_point.y + ul.y; are_done = handle_action(pass_event); @@ -2327,7 +2320,7 @@ void do_rest(long length, int hp_restore, int mp_restore) { } void increase_age() { - short i,j,item,how_many_short = 0,r1; + short item,how_many_short = 0,r1; // Increase age, adjust light level & stealth @@ -2420,7 +2413,7 @@ void increase_age() { } // Protection, etc. - for(i = 0; i < 6; i++) { // Process some status things, and check if stats updated + for(short i = 0; i < 6; i++) { // Process some status things, and check if stats updated if(univ.party[i].status[eStatus::INVULNERABLE] == 1 || abs(univ.party[i].status[eStatus::MAGIC_RESISTANCE]) == 1 || univ.party[i].status[eStatus::INVISIBLE] == 1 || univ.party[i].status[eStatus::MARTYRS_SHIELD] == 1 @@ -2439,7 +2432,7 @@ void increase_age() { // Food if((univ.party.age % 1000 == 0) && (overall_mode < MODE_COMBAT)) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) how_many_short++; how_many_short = take_food (how_many_short,false); @@ -2458,21 +2451,21 @@ void increase_age() { } // Poison, acid, disease damage - for(i = 0; i < 6; i++) // Poison + for(short i = 0; i < 6; i++) // Poison if(univ.party[i].status[eStatus::POISON] > 0) { i = 6; if(((overall_mode == MODE_OUTDOORS) && (univ.party.age % 50 == 0)) || ((overall_mode == MODE_TOWN) && (univ.party.age % 20 == 0))) { do_poison(); } } - for(i = 0; i < 6; i++) // Disease + for(short i = 0; i < 6; i++) // Disease if(univ.party[i].status[eStatus::DISEASE] > 0) { i = 6; if(((overall_mode == MODE_OUTDOORS) && (univ.party.age % 100 == 0)) || ((overall_mode == MODE_TOWN) && (univ.party.age % 25 == 0))) { handle_disease(); } } - for(i = 0; i < 6; i++) // Acid + for(short i = 0; i < 6; i++) // Acid if(univ.party[i].status[eStatus::ACID] > 0) { i = 6; handle_acid(); @@ -2486,7 +2479,7 @@ void increase_age() { } else { if(univ.party.age % 50 == 0) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE && univ.party[i].cur_health > univ.party[i].max_health) univ.party[i].cur_health--; // Bonus HP wears off univ.party.heal(1); @@ -2495,14 +2488,14 @@ void increase_age() { if(is_out()) { if(univ.party.age % 80 == 0) { univ.party.restore_sp(2); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].status[eStatus::DUMB] < 0) univ.party[i].status[eStatus::DUMB]++; } } else { if(univ.party.age % 40 == 0) { - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(univ.party[i].main_status == eMainStatus::ALIVE && univ.party[i].cur_sp > univ.party[i].max_sp) univ.party[i].cur_sp--; // Bonus SP wears off if(univ.party[i].status[eStatus::DUMB] < 0) @@ -2513,7 +2506,7 @@ void increase_age() { } // Recuperation and chronic disease disads - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { if(univ.party[i].traits[eTrait::RECUPERATION] && get_ran(1,0,10) == 1 && univ.party[i].cur_health < univ.party[i].max_health) { univ.party[i].heal(2); @@ -2527,13 +2520,13 @@ void increase_age() { // Blessing, slowed,etc. if(univ.party.age % 4 == 0) - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { move_to_zero(univ.party[i].status[eStatus::BLESS_CURSE]); move_to_zero(univ.party[i].status[eStatus::HASTE_SLOW]); if((item = univ.party[i].has_abil_equip(eItemAbil::REGENERATE)) < 24 && (univ.party[i].cur_health < univ.party[i].max_health) && ((overall_mode > MODE_OUTDOORS) || (get_ran(1,0,10) == 5))){ - j = get_ran(1,0,univ.party[i].items[item].abil_data[0] / 3); + int j = get_ran(1,0,univ.party[i].items[item].abil_data[0] / 3); if(univ.party[i].items[item].abil_data[0] / 3 == 0) j = get_ran(1,0,1); if(is_out()) j = j * 4; @@ -2651,7 +2644,6 @@ void handle_death() { } void start_new_game(bool force) { - short i; std::string choice; using kb = sf::Keyboard; @@ -2689,15 +2681,11 @@ void start_new_game(bool force) { edit_party(); // if no PCs left, forget it - for(i = 0 ; i < 6; i++) - if(univ.party[i].main_status == eMainStatus::ALIVE) - i = 100; - if(i == 6) + if(!univ.party.is_alive()) return; - // everyone gets a weapon - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(univ.party[i].main_status == eMainStatus::ALIVE) { univ.party[i].finish_create(); } @@ -2880,7 +2868,7 @@ bool outd_move_party(location destination,bool forced) { // if(forced) -// for(i = 0; i < 10; i++) +// for(short i = 0; i < 10; i++) // if(same_point(destination,party.out_c[i].m_loc)) // party.out_c[i].exists = false; @@ -3137,20 +3125,18 @@ bool town_move_party(location destination,short forced) { bool someone_poisoned() { - short i; - - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE && (univ.party[i].status[eStatus::POISON] > 0)) return true; return false; } short nearest_monster() { - short i = 100,j,s; + short i = 100; - for(j = 0; j < 10; j++) + for(short j = 0; j < 10; j++) if(univ.party.out_c[j].exists) { - s = dist(univ.party.out_loc,univ.party.out_c[j].m_loc); + short s = dist(univ.party.out_loc,univ.party.out_c[j].m_loc); i = min(i,s); } return i; @@ -3168,9 +3154,8 @@ short count_walls(location loc) { // TODO: Generalize this function unsigned char walls[31] = {5,6,7,8,9, 10,11,12,13,14, 15,16,17,18,19, 20,21,22,23,24, 25,26,27,28,29, 30,31,32,33,34, 35}; short answer = 0; - short k = 0; - for(k = 0; k < 31 ; k++) { + for(short k = 0; k < 31 ; k++) { if(univ.out[loc.x + 1][loc.y] == walls[k]) answer++; if(univ.out[loc.x - 1][loc.y] == walls[k]) diff --git a/src/boe.combat.cpp b/src/boe.combat.cpp index b625dd1e..c71c04fe 100644 --- a/src/boe.combat.cpp +++ b/src/boe.combat.cpp @@ -252,15 +252,15 @@ bool center_on_monst; void start_outdoor_combat(cOutdoors::cCreature encounter,location where,short num_walls) { - short i,j,how_many,num_tries = 0; + short how_many,num_tries = 0; short low[10] = {15,7,4,3,2,1,1,7,2,1}; short high[10] = {30,10,6,5,3,2,1,10,4,1}; rectangle town_rect(0,0,47,47); short nums[10]; - for(i = 0; i < 7; i++) + for(short i = 0; i < 7; i++) nums[i] = get_ran(1,low[i],high[i]); - for(i = 0; i < 3; i++) + for(short i = 0; i < 3; i++) nums[i + 7] = get_ran(1,low[i + 7],high[i + 7]); notify_out_combat_began(encounter.what_monst,nums); print_buf(); @@ -272,8 +272,8 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,location where,short nu // Basically, in outdoor combat, we create kind of a 48x48 town for // the combat to take place in - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++) { + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++) { univ.town.fields[i][j] = 0; } univ.town.prep_arena(); @@ -284,16 +284,16 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,location where,short nu univ.town.monst.clear(); - for(i = 0; i < 7; i++) { + for(short i = 0; i < 7; i++) { how_many = nums[i]; if(encounter.what_monst.monst[i] != 0) - for(j = 0; j < how_many; j++) + for(short j = 0; j < how_many; j++) set_up_monst(eAttitude::HOSTILE_A,encounter.what_monst.monst[i]); } - for(i = 0; i < 3; i++) { + for(short i = 0; i < 3; i++) { how_many = nums[i + 7]; if(encounter.what_monst.friendly[i] != 0) - for(j = 0; j < how_many; j++) + for(short j = 0; j < how_many; j++) set_up_monst(eAttitude::FRIENDLY,encounter.what_monst.friendly[i]); } @@ -302,7 +302,7 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,location where,short nu update_explored(univ.party[0].combat_pos); if(get_blockage(univ.town->terrain(univ.party[0].combat_pos.x,univ.party[0].combat_pos.y)) > 0) univ.town->terrain(univ.party[0].combat_pos.x,univ.party[0].combat_pos.y) = univ.town->terrain(0,0); - for(i = 1; i < 6; i++) { + for(short i = 1; i < 6; i++) { univ.party[i].combat_pos = univ.party[0].combat_pos; univ.party[i].combat_pos.x = univ.party[i].combat_pos.x + hor_vert_place[i].x; univ.party[i].combat_pos.y = univ.party[i].combat_pos.y + hor_vert_place[i].y; @@ -318,7 +318,7 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,location where,short nu } // place monsters, w. friendly monsts landing near PCs - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0) { univ.town.monst[i].target = 6; @@ -347,10 +347,10 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,location where,short nu combat_active_pc = 6; spell_caster = 6; missile_firer = 6; - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) univ.town.monst[i].target = 6; - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { univ.party[i].parry = 0; univ.party[i].last_attacked = nullptr; } @@ -375,7 +375,7 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,location where,short nu bool pc_combat_move(location destination) { std::string create_line; - short s1,s2,i,monst_exist; + short s1,s2,monst_exist; bool keep_going = true,forced = false,check_f = false; location monst_loc,store_loc; eDirection dir; @@ -457,7 +457,7 @@ bool pc_combat_move(location destination) { // Note: monst_hit == nullptr here means there is no PC on the space // monsters get back-shots - for(i = 0; i < univ.town.monst.size(); i++) { + for(short i = 0; i < univ.town.monst.size(); i++) { monst_loc = univ.town.monst[i].cur_loc; monst_exist = univ.town.monst[i].active; @@ -512,7 +512,7 @@ void char_stand_ready() { } void pc_attack(short who_att,iLiving* target) { - short r1,r2,weap1 = 24, weap2 = 24,i,skill_item; + short r1,r2,weap1 = 24, weap2 = 24,skill_item; short hit_adj, dam_adj; cPlayer& attacker = univ.party[who_att]; @@ -529,7 +529,7 @@ void pc_attack(short who_att,iLiving* target) { attacker.last_attacked = target; - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) if((attacker.items[i].variety == eItemType::ONE_HANDED || attacker.items[i].variety == eItemType::TWO_HANDED) && attacker.equip[i]) { if(weap1 == 24) weap1 = i; @@ -960,7 +960,6 @@ short calc_spec_dam(eItemAbil abil,short abil_str,short abil_dat,iLiving& monst, } void place_target(location target) { - short i; bool allow_obstructed = false, allow_antimagic = false; if(spell_being_cast == eSpell::DISPEL_BARRIER || (spell_being_cast == eSpell::NONE && spec_target_options % 10 == 1)) allow_obstructed = true; @@ -988,7 +987,7 @@ void place_target(location target) { add_string_to_buf(" Target in antimagic field."); return; } - for(i = 0; i < 8; i++) { + for(short i = 0; i < 8; i++) { if(spell_targets[i] == target) { add_string_to_buf(" Target removed."); num_targets_left++; @@ -997,7 +996,7 @@ void place_target(location target) { return; } } - for(i = 0; i < 8; i++) + for(short i = 0; i < 8; i++) if(spell_targets[i].x == 120) { add_string_to_buf(" Target added."); spell_targets[i] = target; @@ -1014,7 +1013,7 @@ void place_target(location target) { } void do_combat_cast(location target) { - short adjust,r1,r2,level,bonus = 1,i,item; + short adjust,r1,r2,level,bonus = 1,item; snd_num_t store_sound = 0; bool freebie = false,ap_taken = false,cost_taken = false; short num_targets = 1; @@ -1079,7 +1078,7 @@ void do_combat_cast(location target) { } combat_posing_monster = current_working_monster = current_pc; - for(i = 0; i < num_targets; i++) + for(short i = 0; i < num_targets; i++) if(spell_targets[i].x != 120) { target = spell_targets[i]; spell_targets[i].x = 120; // nullify target as it is used @@ -1591,7 +1590,7 @@ void do_combat_cast(location target) { do_missile_anim((num_targets > 1) ? 35 : 60,caster.combat_pos,store_sound); // process mass damage - for(i = 0; i < 8; i++) + for(short i = 0; i < 8; i++) if(boom_dam[i] > 0) hit_space(boom_targ[i],boom_dam[i],boom_type[i],1,0); @@ -1609,14 +1608,12 @@ void do_combat_cast(location target) { } void handle_marked_damage() { - short i; - - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].marked_damage > 0) { damage_pc(univ.party[i],univ.party[i].marked_damage,eDamageType::MARKED,eRace::UNKNOWN,0); univ.party[i].marked_damage = 0; } - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].marked_damage > 0) { damage_monst(univ.town.monst[i], current_pc, univ.town.monst[i].marked_damage, eDamageType::MARKED,0); @@ -1625,14 +1622,14 @@ void handle_marked_damage() { } void load_missile() { - short i,bow = 24,arrow = 24,thrown = 24,crossbow = 24,bolts = 24,no_ammo = 24; + short bow = 24,arrow = 24,thrown = 24,crossbow = 24,bolts = 24,no_ammo = 24; if(univ.party[current_pc].traits[eTrait::PACIFIST]) { add_string_to_buf("Shoot: You're a pacifist!"); return; } - for(i = 0; i < 24; i++) { + for(short i = 0; i < 24; i++) { if((univ.party[current_pc].equip[i]) && (univ.party[current_pc].items[i].variety == eItemType::THROWN_MISSILE)) thrown = i; @@ -2051,7 +2048,7 @@ bool pick_next_pc() { void combat_run_monst() { - short i,item; + short item; bool update_stat = false; @@ -2086,7 +2083,7 @@ void combat_run_monst() { univ.party.age++; if(univ.party.age % 4 == 0) - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(univ.party[i].status[eStatus::BLESS_CURSE] != 0 || univ.party[i].status[eStatus::HASTE_SLOW] != 0) update_stat = true; move_to_zero(univ.party[i].status[eStatus::BLESS_CURSE]); @@ -2097,7 +2094,7 @@ void combat_run_monst() { univ.party[i].heal(get_ran(1,0,univ.party[i].items[item].item_level + 1)); } } - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { if(univ.party[i].status[eStatus::INVULNERABLE] != 0 || univ.party[i].status[eStatus::MAGIC_RESISTANCE] != 0 || univ.party[i].status[eStatus::INVISIBLE] != 0 || univ.party[i].status[eStatus::MARTYRS_SHIELD] != 0 @@ -2228,7 +2225,7 @@ void do_monster_turn() { bool redraw_not_yet_done = true; bool special_called = false; location targ_space,move_targ,l; - short i,j,k,num_monst, target,r1,move_target; + short num_monst, target,r1,move_target; cCreature *cur_monst; bool pc_adj[6]; @@ -2238,7 +2235,7 @@ void do_monster_turn() { if(overall_mode < MODE_COMBAT) which_combat_type = 1; - for(i = 0; i < num_monst; i++) { // Give monsters ap's, check activity + for(short i = 0; i < num_monst; i++) { // Give monsters ap's, check activity cur_monst = &univ.town.monst[i]; @@ -2251,7 +2248,7 @@ void do_monster_turn() { if(r1 < 50) cur_monst->active = 2; - for(j = 0; j < univ.town.monst.size(); j++) + for(short j = 0; j < univ.town.monst.size(); j++) if(monst_near(j,cur_monst->cur_loc,5,1)) { cur_monst->active = 2; } @@ -2259,7 +2256,7 @@ void do_monster_turn() { if(cur_monst->active == 1 && !cur_monst->is_friendly()) { // Now it looks for PC-friendly monsters // dist check is for efficiency - for(j = 0; j < univ.town.monst.size(); j++) + for(short j = 0; j < univ.town.monst.size(); j++) if((univ.town.monst[j].active > 0) && univ.town.monst[j].is_friendly() && (dist(cur_monst->cur_loc,univ.town.monst[j].cur_loc) <= 6) && @@ -2270,7 +2267,7 @@ void do_monster_turn() { // See if friendly, fighting monster see hostile monster. If so, make mobile // dist check is for efficiency if(cur_monst->active == 1 && cur_monst->attitude == eAttitude::FRIENDLY) { - for(j = 0; j < univ.town.monst.size(); j++) + for(short j = 0; j < univ.town.monst.size(); j++) if(univ.town.monst[j].active > 0 && !univ.town.monst[j].is_friendly() && (dist(cur_monst->cur_loc,univ.town.monst[j].cur_loc) <= 6) && (can_see_light(cur_monst->cur_loc,univ.town.monst[j].cur_loc,sight_obscurity) < 5)) { @@ -2319,7 +2316,7 @@ void do_monster_turn() { } - for(i = 0; i < num_monst; i++) { // Begin main monster loop, do monster actions + for(short i = 0; i < num_monst; i++) { // Begin main monster loop, do monster actions // If party dead, no point if(!univ.party.is_alive()) return; @@ -2329,7 +2326,7 @@ void do_monster_turn() { cur_monst = &univ.town.monst[i]; - for(j = 0; j < 6; j++) + for(short j = 0; j < 6; j++) if(univ.party[j].main_status == eMainStatus::ALIVE && monst_adjacent(univ.party[j].combat_pos,i)) pc_adj[j] = true; else pc_adj[j] = false; @@ -2560,8 +2557,7 @@ void do_monster_turn() { if(acted_yet) { print_buf(); - if(j == 0) - pause(8); + pause(8); flushingInput = true; } @@ -2574,7 +2570,7 @@ void do_monster_turn() { if(!cur_monst->is_friendly() && move_target < 6) // Monsters seeking party do so if(univ.party[move_target].main_status == eMainStatus::ALIVE) { seek_party (i,cur_monst->cur_loc,univ.party[move_target].combat_pos); - for(k = 0; k < 6; k++) + for(short k = 0; k < 6; k++) if(univ.party[k].parry > 99 && monst_adjacent(univ.party[k].combat_pos,i) && (cur_monst->active > 0) && !univ.party[k].traits[eTrait::PACIFIST]) { univ.party[k].parry = 0; @@ -2585,7 +2581,7 @@ void do_monster_turn() { if(move_target >= 100) // Monsters seeking monsters do so if(univ.town.monst[move_target - 100].active > 0) { seek_party (i,cur_monst->cur_loc,univ.town.monst[move_target - 100].cur_loc); - for(k = 0; k < 6; k++) + for(short k = 0; k < 6; k++) if(univ.party[k].parry > 99 && monst_adjacent(univ.party[k].combat_pos,i) && cur_monst->active > 0 && !cur_monst->is_friendly() && !univ.party[k].traits[eTrait::PACIFIST]) { @@ -2613,7 +2609,7 @@ void do_monster_turn() { // pcs attack any fleeing monsters if((overall_mode >= MODE_COMBAT) && (overall_mode < MODE_TALKING)) - for(k = 0; k < 6; k++) + 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 && univ.party[k].status[eStatus::INVISIBLE] == 0 && !univ.party[k].traits[eTrait::PACIFIST]) { @@ -2661,8 +2657,8 @@ void do_monster_turn() { case eMonstSummon::TYPE: what_summon = abil.summon.what; break; case eMonstSummon::LEVEL: what_summon = get_summon_monster(minmax(0, 4, abil.summon.what)); break; case eMonstSummon::SPECIES: - for(k = 0; k < 200; k++) { - j = get_ran(1,0,univ.scenario.scen_monsters.size() - 1); + for(short k = 0; k < 200; k++) { + int j = get_ran(1,0,univ.scenario.scen_monsters.size() - 1); if(univ.scenario.scen_monsters[j].m_type == eRace(abil.summon.what)) { what_summon = j; break; @@ -2704,7 +2700,7 @@ void do_monster_turn() { } - for(i = 0; i < num_monst; i++) { // Begin monster time stuff loop + for(short i = 0; i < num_monst; i++) { // Begin monster time stuff loop // If party dead, no point if(!univ.party.is_alive()) return; @@ -2752,8 +2748,7 @@ void do_monster_turn() { add_string_to_buf("Diseased monsters:"); printed_disease = true; } - k = get_ran(1,1,5); - switch(k) { + switch(get_ran(1,1,5)) { case 1: case 2: cur_monst->poison(2); break; case 3: cur_monst->slow(2); break; case 4: cur_monst->curse(2); break; @@ -2782,14 +2777,14 @@ void do_monster_turn() { center = univ.party.town_loc; if(had_monst) put_pc_screen(); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) univ.party[i].parry = 0; monsters_going = false; } void monster_attack(short who_att,iLiving* target) { - short r1,r2,i,store_hp,sound_type = 0; + short r1,r2,store_hp,sound_type = 0; eDamageType dam_type = eDamageType::WEAPON; cCreature* attacker = &univ.town.monst[who_att]; @@ -2825,7 +2820,7 @@ void monster_attack(short who_att,iLiving* target) { return; } - for(i = 0; i < attacker->a.size(); i++) { + for(short i = 0; i < attacker->a.size(); i++) { if(attacker->a[i].dice > 0 && target->is_alive()) { // sprintf ((char *) create_line, " Attacks %s.",(char *) univ.party[target].name); // add_string_to_buf((char *) create_line); @@ -3018,7 +3013,7 @@ void monster_attack(short who_att,iLiving* target) { } void monst_fire_missile(short m_num,short bless,std::pair abil,location source,iLiving* target) { - short i,j,r2; + short r2; location targ_space; if(target == nullptr) return; @@ -3163,13 +3158,13 @@ void monst_fire_missile(short m_num,short bless,std::pair a if(abil.first == eMonstAbil::DRAIN_SP && pc_target != nullptr && pc_target->cur_sp < 4) { // modify target if target has no sp // TODO: What if it's a monster with no sp? - for(i = 0; i < 8; i++) { - j = get_ran(1,0,5); + for(short i = 0; i < 8; i++) { + int j = get_ran(1,0,5); if(univ.party[j].main_status == eMainStatus::ALIVE && univ.party[j].cur_sp > 4 && (can_see_light(source,univ.party[j].combat_pos,sight_obscurity) < 5) && (dist(source,univ.party[j].combat_pos) <= 8)) { target = &univ.party[j]; - i = 8; targ_space = univ.party[j].combat_pos; + break; } } } @@ -3394,7 +3389,7 @@ bool monst_breathe(cCreature *caster,location targ_space,uAbility abil) { } bool monst_cast_mage(cCreature *caster,short targ) { - short r1,j,i,level,target_levels,friend_levels_near,x; + short r1,level,target_levels,friend_levels_near,x; bool acted = false; location target,ashes_loc,l; cCreature *affected; @@ -3594,7 +3589,8 @@ bool monst_cast_mage(cCreature *caster,short targ) { place_spell_pattern(square,target,eDamageType::FIRE,r1,7); ashes_loc = target; break; - case eSpell::SUMMON_WEAK: case eSpell::SUMMON: case eSpell::SUMMON_MAJOR: + case eSpell::SUMMON_WEAK: case eSpell::SUMMON: case eSpell::SUMMON_MAJOR: { + int j; play_sound(25); if(spell == eSpell::SUMMON_WEAK) { r1 = get_summon_monster(1); @@ -3615,13 +3611,14 @@ bool monst_cast_mage(cCreature *caster,short targ) { j = get_ran(1,2,3); } sf::sleep(time_in_ticks(12)); // gives sound time to end - x = get_ran(4,1,4); - for(i = 0; i < j; i++){ + int x = get_ran(4,1,4); + for(short i = 0; i < j; i++){ play_sound(-61); if(!summon_monster(r1,caster->cur_loc,x,caster->attitude,caster->is_friendly())) { add_string_to_buf(" Summon failed."); i = j;} } break; + } case eSpell::WEB: play_sound(25); place_spell_pattern(radius2,target,FIELD_WEB,7); @@ -3640,10 +3637,10 @@ bool monst_cast_mage(cCreature *caster,short targ) { case eSpell::SLOW_GROUP: play_sound(25); if(!caster->is_friendly()) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_near(i,caster->cur_loc,8)) univ.party[i].slow(2 + caster->level / 4); - for(i = 0; i < univ.town.monst.size(); i++) { + for(short i = 0; i < univ.town.monst.size(); i++) { if(univ.town.monst[i].active != 0 && !caster->is_friendly(univ.town.monst[i]) && (dist(caster->cur_loc,univ.town.monst[i].cur_loc) <= 7)) univ.town.monst[i].slow(2 + caster->level / 4); @@ -3651,7 +3648,7 @@ bool monst_cast_mage(cCreature *caster,short targ) { break; case eSpell::HASTE_MAJOR: play_sound(25); - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((monst_near(i,caster->cur_loc,8,0)) && (caster->attitude == univ.town.monst[i].attitude)) { affected = &univ.town.monst[i]; @@ -3691,7 +3688,7 @@ bool monst_cast_mage(cCreature *caster,short targ) { break; case eSpell::BLESS_MAJOR: play_sound(25); - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((monst_near(i,caster->cur_loc,8,0)) && (caster->attitude == univ.town.monst[i].attitude)) { affected = &univ.town.monst[i]; @@ -3731,7 +3728,7 @@ bool monst_cast_mage(cCreature *caster,short targ) { } bool monst_cast_priest(cCreature *caster,short targ) { - short r1,r2,i,x,level,target_levels,friend_levels_near; + short r1,r2,x,level,target_levels,friend_levels_near; bool acted = false; location target,l; cCreature *affected; @@ -3915,7 +3912,7 @@ bool monst_cast_priest(cCreature *caster,short targ) { case eSpell::STICKS_TO_SNAKES: // sticks to snakes play_sound(24); r1 = get_ran(1,1,4) + 2; - for(i = 0; i < r1; i++) { + for(short i = 0; i < r1; i++) { play_sound(-61); r2 = get_ran(1,0,7); x = get_ran(3,1,4); @@ -3931,7 +3928,7 @@ bool monst_cast_priest(cCreature *caster,short targ) { x = get_ran(3,1,4) + 1; play_sound(-61); summon_monster(126,caster->cur_loc,x,caster->attitude,caster->is_friendly()); - for(i = 0; i < 4; i++) { + for(short i = 0; i < 4; i++) { play_sound(-61); if(!summon_monster(125,caster->cur_loc,x,caster->attitude,caster->is_friendly())) i = 4; @@ -3942,14 +3939,14 @@ bool monst_cast_priest(cCreature *caster,short targ) { r1 = get_ran(2,0,2); r2 = get_ran(1,0,2); if(!caster->is_friendly()) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_near(i,caster->cur_loc,8)) { if(spell == eSpell::CURSE_ALL) univ.party[i].curse(2 + r1); if(spell == eSpell::PESTILENCE) univ.party[i].disease(2 + r2); } - for(i = 0; i < univ.town.monst.size(); i++) { + for(short i = 0; i < univ.town.monst.size(); i++) { if(univ.town.monst[i].active != 0 && !caster->is_friendly(univ.town.monst[i]) && (dist(caster->cur_loc,univ.town.monst[i].cur_loc) <= 7)) { if(spell == eSpell::CURSE_ALL) @@ -3977,7 +3974,7 @@ bool monst_cast_priest(cCreature *caster,short targ) { play_sound(24); // TODO: What's r2 for here? Should it be used for Revive All? r1 = get_ran(2,1,4); r2 = get_ran(3,1,6); - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((monst_near(i,caster->cur_loc,8,0)) && (caster->attitude == univ.town.monst[i].attitude)) { affected = &univ.town.monst[i]; @@ -4069,10 +4066,9 @@ location find_fireball_loc(location where,short radius,short mode,short *m) { } location closest_pc_loc(location where) { - short i; location pc_where(120,120); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) if((dist(where,univ.party[i].combat_pos)) < (dist(where,pc_where))) pc_where = univ.party[i].combat_pos; @@ -4080,16 +4076,16 @@ location closest_pc_loc(location where) { } short count_levels(location where,short radius) { - short i,store = 0; + short store = 0; - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(monst_near(i,where,radius,0)) { if(!univ.town.monst[i].is_friendly()) store = store - univ.town.monst[i].level; else store = store + univ.town.monst[i].level; } if(is_combat()) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_near(i,where,radius)) store = store + 10; } @@ -4131,7 +4127,7 @@ void fireball_space(location loc,short dam) { // 50 + i - 80 : id6 fire damage 90 + i - 120 : id6 cold damage 130 + i - 160 : id6 magic dam. // if prep for anim is true, supporess look checks and go fast static void place_spell_pattern(effect_pat_type pat,location center,unsigned short type,short who_hit) { - short i,j,r1,k = 0; + short r1 = 0; unsigned short effect; location spot_hit; location s_loc; @@ -4147,9 +4143,9 @@ static void place_spell_pattern(effect_pat_type pat,location center,unsigned sho active = univ.town->in_town_rect; // eliminate barriers that can't be seen - for(i = minmax(active.left + 1,active.right - 1,center.x - 4); + for(short i = minmax(active.left + 1,active.right - 1,center.x - 4); i <= minmax(active.left + 1,active.right - 1,center.x + 4); i++) - for(j = minmax(active.top + 1,active.bottom - 1,center.y - 4); + for(short j = minmax(active.top + 1,active.bottom - 1,center.y - 4); j <= minmax(active.top + 1,active.bottom - 1,center.y + 4); j++) { s_loc.x = i; s_loc.y = j; if(can_see_light(center,s_loc,sight_obscurity) == 5) @@ -4158,8 +4154,8 @@ static void place_spell_pattern(effect_pat_type pat,location center,unsigned sho // First actually make barriers, then draw them, then inflict damaging effects. - for(i = minmax(0,univ.town->max_dim() - 1,center.x - 4); i <= minmax(0,univ.town->max_dim() - 1,center.x + 4); i++) - for(j = minmax(0,univ.town->max_dim() - 1,center.y - 4); j <= minmax(0,univ.town->max_dim() - 1,center.y + 4); j++) { + for(short i = minmax(0,univ.town->max_dim() - 1,center.x - 4); i <= minmax(0,univ.town->max_dim() - 1,center.x + 4); i++) + for(short j = minmax(0,univ.town->max_dim() - 1,center.y - 4); j <= minmax(0,univ.town->max_dim() - 1,center.y + 4); j++) { effect = pat.pattern[i - center.x + 4][j - center.y + 4]; if(effect == FIELD_SMASH || sight_obscurity(i,j) < 5) { switch(effect) { @@ -4246,9 +4242,9 @@ static void place_spell_pattern(effect_pat_type pat,location center,unsigned sho fast_bang = 2; // Damage to pcs - for(k = 0; k < 6; k++) - for(i = minmax(0,univ.town->max_dim() - 1,center.x - 4); i <= minmax(0,univ.town->max_dim() - 1,center.x + 4); i++) - for(j = minmax(0,univ.town->max_dim() - 1,center.y - 4); j <= minmax(0,univ.town->max_dim() - 1,center.y + 4); j++) { + for(short k = 0; k < 6; k++) + for(short i = minmax(0,univ.town->max_dim() - 1,center.x - 4); i <= minmax(0,univ.town->max_dim() - 1,center.x + 4); i++) + for(short j = minmax(0,univ.town->max_dim() - 1,center.y - 4); j <= minmax(0,univ.town->max_dim() - 1,center.y + 4); j++) { spot_hit.x = i; spot_hit.y = j; if(sight_obscurity(i,j) < 5 && univ.party[k].main_status == eMainStatus::ALIVE @@ -4320,12 +4316,12 @@ static void place_spell_pattern(effect_pat_type pat,location center,unsigned sho fast_bang = 0; // Damage to monsters - for(k = 0; k < univ.town.monst.size(); k++) + for(short k = 0; k < univ.town.monst.size(); k++) if((univ.town.monst[k].active > 0) && (dist(center,univ.town.monst[k].cur_loc) <= 5)) { monster_hit = false; // First actually make barriers, then draw them, then inflict damaging effects. - for(i = minmax(0,univ.town->max_dim() - 1,center.x - 4); i <= minmax(0,univ.town->max_dim() - 1,center.x + 4); i++) - for(j = minmax(0,univ.town->max_dim() - 1,center.y - 4); j <= minmax(0,univ.town->max_dim() - 1,center.y + 4); j++) { + for(short i = minmax(0,univ.town->max_dim() - 1,center.x - 4); i <= minmax(0,univ.town->max_dim() - 1,center.x + 4); i++) + for(short j = minmax(0,univ.town->max_dim() - 1,center.y - 4); j <= minmax(0,univ.town->max_dim() - 1,center.y + 4); j++) { spot_hit.x = i; spot_hit.y = j; @@ -4444,23 +4440,19 @@ void place_spell_pattern(effect_pat_type pat,location center,eDamageType type,sh } void modify_pattern(effect_pat_type *pat,unsigned short type) { - short i,j; - - for(i = 0; i < 9; i++) - for(j = 0; j < 9; j++) + for(short i = 0; i < 9; i++) + for(short j = 0; j < 9; j++) if(pat->pattern[i][j] > 0) pat->pattern[i][j] = type; } void do_shockwave(location target) { - short i; - start_missile_anim(); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if((dist(target,univ.party[i].combat_pos) > 0) && (dist(target,univ.party[i].combat_pos) < 11) && univ.party[i].main_status == eMainStatus::ALIVE) damage_pc(univ.party[i], get_ran(2 + dist(target,univ.party[i].combat_pos) / 2, 1, 6), eDamageType::UNBLOCKABLE,eRace::UNKNOWN,0); - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active != 0) && (dist(target,univ.town.monst[i].cur_loc) > 0) && (dist(target,univ.town.monst[i].cur_loc) < 11) && (can_see_light(target,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) @@ -4471,15 +4463,13 @@ void do_shockwave(location target) { } void radius_damage(location target,short radius, short dam, eDamageType type) { - short i; - // TODO: Why no booms in town mode? if(is_town()) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if((dist(target,univ.party.town_loc) > 0) && (dist(target,univ.party.town_loc) <= radius) && univ.party[i].main_status == eMainStatus::ALIVE) damage_pc(univ.party[i], dam, type,eRace::UNKNOWN,0); - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active != 0) && (dist(target,univ.town.monst[i].cur_loc) > 0) && (dist(target,univ.town.monst[i].cur_loc) <= radius) && (can_see_light(target,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) @@ -4488,11 +4478,11 @@ void radius_damage(location target,short radius, short dam, eDamageType type) { } start_missile_anim(); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if((dist(target,univ.party[i].combat_pos) > 0) && (dist(target,univ.party[i].combat_pos) <= radius) && univ.party[i].main_status == eMainStatus::ALIVE) damage_pc(univ.party[i], dam, type,eRace::UNKNOWN,0); - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active != 0) && (dist(target,univ.town.monst[i].cur_loc) > 0) && (dist(target,univ.town.monst[i].cur_loc) <= radius) && (can_see_light(target,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) @@ -4511,7 +4501,6 @@ void hit_pcs_in_space(location target,short dam,eDamageType type,short report,sh //short report; // 0 - no 1 - print result //hit_all; // 0 - nail top thing 1 - hit all in space + 10 ... no monsters void hit_space(location target,short dam,eDamageType type,short report,short hit_all) { - short i; bool stop_hitting = false,hit_monsters = true; if((target.x < 0) || (target.x > 63) || (target.y < 0) || (target.y > 63)) @@ -4531,7 +4520,7 @@ void hit_space(location target,short dam,eDamageType type,short report,short hit return; } - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((hit_monsters) && (univ.town.monst[i].active != 0) && !stop_hitting) if(univ.town.monst[i].on_space(target)) { if(processing_fields) @@ -4541,7 +4530,7 @@ void hit_space(location target,short dam,eDamageType type,short report,short hit } if(overall_mode >= MODE_COMBAT) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE && !stop_hitting) if(univ.party[i].combat_pos == target) { damage_pc(univ.party[i],dam,type,eRace::UNKNOWN,0); @@ -4563,16 +4552,16 @@ void hit_space(location target,short dam,eDamageType type,short report,short hit void do_poison() { - short i,r1 = 0; + short r1 = 0; bool some_poison = false; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) if(univ.party[i].status[eStatus::POISON] > 0) some_poison = true; if(some_poison) { add_string_to_buf("Poison:"); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) if(univ.party[i].status[eStatus::POISON] > 0) { r1 = get_ran(univ.party[i].status[eStatus::POISON],1,6); @@ -4592,17 +4581,17 @@ void do_poison() { void handle_disease() { - short i,r1 = 0; + short r1 = 0; bool disease = false; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) if(univ.party[i].status[eStatus::DISEASE] > 0) disease = true; if(disease) { add_string_to_buf("Disease:"); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) if(univ.party[i].status[eStatus::DISEASE] > 0) { r1 = get_ran(1,1,10); @@ -4638,17 +4627,17 @@ void handle_disease() { } void handle_acid() { - short i,r1 = 0; + short r1 = 0; bool some_acid = false; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) if(univ.party[i].status[eStatus::ACID] > 0) some_acid = true; if(some_acid) { add_string_to_buf("Acid:"); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) if(univ.party[i].status[eStatus::ACID] > 0) { r1 = get_ran(univ.party[i].status[eStatus::ACID],1,6); @@ -4691,9 +4680,7 @@ bool hit_end_c_button() { } bool out_monst_all_dead() { - short i; - - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0 && !univ.town.monst[i].is_friendly()) { //print_nums(5555,i,univ.town.monst[i].number); //print_nums(5555,univ.town.monst[i].m_loc.x,univ.town.monst[i].m_loc.y); @@ -4703,9 +4690,7 @@ bool out_monst_all_dead() { } void end_combat() { - short i; - - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(univ.party[i].main_status == eMainStatus::FLED) univ.party[i].main_status = eMainStatus::ALIVE; univ.party[i].status[eStatus::POISONED_WEAPON] = 0; @@ -4808,7 +4793,7 @@ bool combat_cast_mage_spell() { } void combat_immed_mage_cast(short current_pc, eSpell spell_num, bool freebie) { - short target, i, num_opp = 0, r1; + short target, num_opp = 0, r1; snd_num_t store_sound = 0; miss_num_t store_m_type = 0; short bonus = freebie ? 1 : univ.party[current_pc].stat_adj(eSkill::INTELLIGENCE); @@ -4852,8 +4837,7 @@ void combat_immed_mage_cast(short current_pc, eSpell spell_num, bool freebie) { break; default: - i = (spell_num == eSpell::HASTE_MINOR) ? 2 : max(2,level / 2 + bonus); - univ.party[target].slow(-i); + univ.party[target].slow((spell_num == eSpell::HASTE_MINOR) ? -2 : -max(2,level / 2 + bonus)); c_line += " hasted."; store_m_type = 8; break; @@ -4869,7 +4853,7 @@ void combat_immed_mage_cast(short current_pc, eSpell spell_num, bool freebie) { univ.party[current_pc].cur_sp -= (*spell_num).cost; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { univ.party[i].slow(-(spell_num == eSpell::HASTE_MAJOR ? 1 + level / 8 + bonus : 3 + bonus)); if(spell_num == eSpell::BLESS_MAJOR) { @@ -4905,7 +4889,7 @@ void combat_immed_mage_cast(short current_pc, eSpell spell_num, bool freebie) { add_string_to_buf(" Error: Mage group spell " + (*spell_num).name() + " not implemented for combat mode.", 4); break; } - for(i = 0; i < univ.town.monst.size(); i++) { + for(short i = 0; i < univ.town.monst.size(); i++) { if(univ.town.monst[i].active != 0 && !univ.town.monst[i].is_friendly() && (dist(univ.party[current_pc].combat_pos,univ.town.monst[i].cur_loc) <= (*spell_num).range) && (can_see_light(univ.party[current_pc].combat_pos,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) { @@ -5053,7 +5037,7 @@ void combat_immed_priest_cast(short current_pc, eSpell spell_num, bool freebie) case eSpell::BLESS_PARTY: if(!freebie) univ.party[current_pc].cur_sp -= (*spell_num).cost; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { univ.party[i].curse(-(level / 3)); add_missile(univ.party[i].combat_pos,8,0,0,0); @@ -5072,7 +5056,7 @@ void combat_immed_priest_cast(short current_pc, eSpell spell_num, bool freebie) if(!freebie) univ.party[current_pc].cur_sp -= (*spell_num).cost; store_sound = 24; - for(i = 0; i < univ.town.monst.size(); i++) { + for(short i = 0; i < univ.town.monst.size(); i++) { if(univ.town.monst[i].active != 0 && !univ.town.monst[i].is_friendly() && (dist(univ.party[current_pc].combat_pos,univ.town.monst[i].cur_loc) <= (*spell_num).range)) { // TODO: Should this ^ also check that you can see each target? ie can_see_light(...) < 5 @@ -5201,14 +5185,13 @@ void start_spell_targeting(eSpell num, bool freebie, int spell_range, eSpellPat } void start_fancy_spell_targeting(eSpell num, bool freebie, int spell_range, eSpellPat pat, int targets) { - short i; location null_loc(120,0); // First, remember what spell was cast. spell_being_cast = num; spell_freebie = freebie; - for(i = 0; i < 8; i++) + for(short i = 0; i < 8; i++) spell_targets[i] = null_loc; add_string_to_buf(" Target spell."); if(num == eSpell::NONE); @@ -5338,7 +5321,7 @@ void process_force_cage(location loc, short i, short adjust) { } void process_fields() { - short i,j,k,r1; + short r1; location loc; short qf[64][64]; rectangle r; @@ -5348,12 +5331,12 @@ void process_fields() { if(univ.town.quickfire_present) { r = univ.town->in_town_rect; - for(i = 0; i < univ.town->max_dim(); i++) - for(j = 0; j < univ.town->max_dim(); j++) + for(short i = 0; i < univ.town->max_dim(); i++) + for(short j = 0; j < univ.town->max_dim(); j++) qf[i][j] = (univ.town.is_quickfire(i,j)) ? 2 : 0; - for(k = 0; k < ((is_combat()) ? 4 : 1); k++) { - for(i = r.left + 1; i < r.right ; i++) - for(j = r.top + 1; j < r.bottom ; j++) + for(short k = 0; k < ((is_combat()) ? 4 : 1); k++) { + for(short i = r.left + 1; i < r.right ; i++) + for(short j = r.top + 1; j < r.bottom ; j++) if(univ.town.is_quickfire(i,j)) { r1 = get_ran(1,1,8); if(r1 != 1) { @@ -5363,8 +5346,8 @@ void process_fields() { qf[i][j - 1] = 1; } } - for(i = r.left + 1; i < r.right ; i++) - for(j = r.top + 1; j < r.bottom ; j++) + for(short i = r.left + 1; i < r.right ; i++) + for(short j = r.top + 1; j < r.bottom ; j++) if(qf[i][j] > 0) { ter_num_t ter = univ.town->terrain(i,j); if(univ.scenario.ter_types[ter].special == eTerSpec::CRUMBLING && univ.scenario.ter_types[ter].flag2 > 0) { @@ -5378,7 +5361,7 @@ void process_fields() { } } - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0) monst_inflict_fields(i); @@ -5386,8 +5369,8 @@ void process_fields() { // First fry PCs, then call to handle damage to monsters processing_fields = true; // this, in hit_space, makes damage considered to come from whole party - for(i = 0; i < univ.town->max_dim(); i++) - for(j = 0; j < univ.town->max_dim(); j++) { + for(short i = 0; i < univ.town->max_dim(); i++) + for(short j = 0; j < univ.town->max_dim(); j++) { if(univ.town.is_force_wall(i,j)) { r1 = get_ran(3,1,6); loc.x = i; loc.y = j; @@ -5457,8 +5440,8 @@ void process_fields() { monsters_going = true; // this changes who the damage is considered to come from in hit_space if(univ.town.quickfire_present) { - for(i = 0; i < univ.town->max_dim(); i++) - for(j = 0; j < univ.town->max_dim(); j++) + for(short i = 0; i < univ.town->max_dim(); i++) + for(short j = 0; j < univ.town->max_dim(); j++) if(univ.town.is_quickfire(i,j)) { loc.x = i; loc.y = j; r1 = get_ran(2,1,8); @@ -5472,7 +5455,6 @@ void process_fields() { void scloud_space(short m,short n) { // TODO: Is it correct for these to not affect monsters? location target; - short i; target.x = (char) m; target.y = (char) n; @@ -5480,51 +5462,43 @@ void scloud_space(short m,short n) { univ.town.set_scloud(m,n,true); if(overall_mode >= MODE_COMBAT) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) if(univ.party[i].combat_pos == target) { univ.party[i].curse(get_ran(1,1,2)); } if(overall_mode < MODE_COMBAT) if(target == univ.party.town_loc) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) univ.party[i].curse(get_ran(1,1,2)); } } void web_space(short m,short n) { - location target; - short i; - - target.x = (char) m; - target.y = (char) n; + location target(m, n); univ.town.set_web(m,n,true); if(overall_mode >= MODE_COMBAT) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) if(univ.party[i].combat_pos == target) { univ.party[i].web(3); } if(overall_mode < MODE_COMBAT) if(target == univ.party.town_loc) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) univ.party[i].web(3); } } void sleep_cloud_space(short m,short n) { - location target; - short i; - - target.x = (char) m; - target.y = (char) n; + location target(m, n); univ.town.set_sleep_cloud(m,n,true); if(overall_mode >= MODE_COMBAT) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) if(univ.party[i].combat_pos == target) { univ.party[i].sleep(eStatus::ASLEEP,3,0); diff --git a/src/boe.dlgutil.cpp b/src/boe.dlgutil.cpp index 0cfa01cd..eb9ee7d5 100644 --- a/src/boe.dlgutil.cpp +++ b/src/boe.dlgutil.cpp @@ -208,7 +208,6 @@ void end_shop_mode() { } void handle_shop_event(location p) { - short i; unsigned long store_what_picked; if(p.in(talk_help_rect)) { @@ -229,7 +228,7 @@ void handle_shop_event(location p) { p.x -= 5; p.y -= 5; - for(i = 0; i < 8; i++) { + for(short i = 0; i < 8; i++) { store_what_picked = shop_array[i + shop_sbar->getPosition()]; if(store_what_picked >= 30) break; if(active_shop.getItem(store_what_picked).type == eShopItemType::EMPTY) @@ -675,7 +674,7 @@ static void show_job_bank(int which_bank, std::string title) { } void handle_talk_event(location p) { - short i,get_pc,s1 = -1,s2 = -1,s3 = -1; + short get_pc,s1 = -1,s2 = -1,s3 = -1; char asked[4]; short a,b,c,d; @@ -921,44 +920,46 @@ void handle_talk_event(location p) { save_talk_str1 = save_talk_str2; save_talk_str2 = ""; break; + } else { + using namespace std::placeholders; + auto& boats = univ.party.boats; + b = minmax(0, boats.size() - 1, b); + c = minmax(0, boats.size() - b, c); + auto iter = std::find_if(boats.begin() + b, boats.begin() + b + c, std::bind(&cVehicle::property, _1)); + if(iter != boats.end()) { + univ.party.gold -= a; + put_pc_screen(); + iter->property = false; + save_talk_str2 = ""; + } else { + save_talk_str1 = "There are no boats left."; + save_talk_str2 = ""; + can_save_talk = false; + } } - else { - for(i = b; i <= b + c; i++) - if((i >= 0) && (i < univ.party.boats.size()) && (univ.party.boats[i].property)) { - univ.party.gold -= a; - put_pc_screen(); - univ.party.boats[i].property = false; - save_talk_str2 = ""; - i = 1000; - } - if(i >= 1000) - break; - } - save_talk_str1 = "There are no boats left."; - save_talk_str2 = ""; - can_save_talk = false; break; case eTalkNode::BUY_HORSE: if(univ.party.gold < a) { save_talk_str1 = save_talk_str2; save_talk_str2 = ""; break; + } else { + using namespace std::placeholders; + auto& horses = univ.party.horses; + b = minmax(0, horses.size() - 1, b); + c = minmax(0, horses.size() - b, c); + auto iter = std::find_if(horses.begin() + b, horses.begin() + b + c, std::bind(&cVehicle::property, _1)); + if(iter != horses.end()) { + univ.party.gold -= a; + put_pc_screen(); + iter->property = false; + save_talk_str2 = ""; + } else { + save_talk_str1 = "There are no horses left."; + save_talk_str2 = ""; + can_save_talk = false; + } } - else { - for(i = b; i <= b + c; i++) - if((i >= 0) && (i < univ.party.horses.size()) && (univ.party.horses[i].property)) { - univ.party.gold -= a; - put_pc_screen(); - univ.party.horses[i].property = false; - save_talk_str2 = ""; - i = 1000; - } - if(i >= 1000) - break; - } - save_talk_str1 = "There are no horses left."; - save_talk_str2 = ""; - can_save_talk = false; break; case eTalkNode::BUY_SPEC_ITEM: if(univ.party.spec_items.count(a)) { @@ -1223,10 +1224,7 @@ void pick_preferences() { } static void put_party_stats(cDialog& me) { - short i; - - - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { std::string n = boost::lexical_cast(i + 1); if(univ.party[i].main_status != eMainStatus::ABSENT) { me["name" + n].setText(univ.party[i].name); @@ -1358,11 +1356,10 @@ void tip_of_day() { } static void put_scen_info(cDialog& me) { - unsigned int i; std::ostringstream sout; static const char *difficulty[] = {"Low","Medium","High","Very High"}; - for(i = 0; i < 3; i++) { + for(short i = 0; i < 3; i++) { sout.clear(); sout.str(""); sout << i + 1; @@ -1417,7 +1414,7 @@ short pick_a_scen() { build_scen_headers(); store_num_scen = scen_headers.size(); -// for(i = 0; i < 25; i++) +// for(short i = 0; i < 25; i++) // if(scen_headers[i].flag1 != 0) // store_num_scen++; store_scen_page_on = 0; diff --git a/src/boe.fileio.cpp b/src/boe.fileio.cpp index 2af5a6ce..f9ad1baa 100644 --- a/src/boe.fileio.cpp +++ b/src/boe.fileio.cpp @@ -130,8 +130,6 @@ void finish_load_party(){ } void shift_universe_left() { - short i,j; - make_cursor_watch(); save_outdoor_maps(); @@ -139,15 +137,15 @@ void shift_universe_left() { univ.party.i_w_c.x++; univ.party.out_loc.x += 48; - for(i = 48; i < 96; i++) - for(j = 0; j < 96; j++) + for(short i = 48; i < 96; i++) + for(short j = 0; j < 96; j++) univ.out.out_e[i][j] = univ.out.out_e[i - 48][j]; - for(i = 0; i < 48; i++) - for(j = 0; j < 96; j++) + for(short i = 0; i < 48; i++) + for(short j = 0; j < 96; j++) univ.out.out_e[i][j] = 0; - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { if(univ.party.out_c[i].m_loc.x > 48) univ.party.out_c[i].exists = false; if(univ.party.out_c[i].exists) @@ -160,22 +158,20 @@ void shift_universe_left() { } void shift_universe_right() { - short i,j; - make_cursor_watch(); save_outdoor_maps(); univ.party.outdoor_corner.x++; univ.party.i_w_c.x--; univ.party.out_loc.x -= 48; - for(i = 0; i < 48; i++) - for(j = 0; j < 96; j++) + for(short i = 0; i < 48; i++) + for(short j = 0; j < 96; j++) univ.out.out_e[i][j] = univ.out.out_e[i + 48][j]; - for(i = 48; i < 96; i++) - for(j = 0; j < 96; j++) + for(short i = 48; i < 96; i++) + for(short j = 0; j < 96; j++) univ.out.out_e[i][j] = 0; - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { if(univ.party.out_c[i].m_loc.x < 48) univ.party.out_c[i].exists = false; if(univ.party.out_c[i].exists) @@ -187,22 +183,20 @@ void shift_universe_right() { } void shift_universe_up() { - short i,j; - make_cursor_watch(); save_outdoor_maps(); univ.party.outdoor_corner.y--; univ.party.i_w_c.y++; univ.party.out_loc.y += 48; - for(i = 0; i < 96; i++) - for(j = 48; j < 96; j++) + for(short i = 0; i < 96; i++) + for(short j = 48; j < 96; j++) univ.out.out_e[i][j] = univ.out.out_e[i][j - 48]; - for(i = 0; i < 96; i++) - for(j = 0; j < 48; j++) + for(short i = 0; i < 96; i++) + for(short j = 0; j < 48; j++) univ.out.out_e[i][j] = 0; - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { if(univ.party.out_c[i].m_loc.y > 48) univ.party.out_c[i].exists = false; if(univ.party.out_c[i].exists) @@ -215,8 +209,6 @@ void shift_universe_up() { } void shift_universe_down() { - short i,j; - make_cursor_watch(); save_outdoor_maps(); @@ -224,14 +216,14 @@ void shift_universe_down() { univ.party.i_w_c.y--; univ.party.out_loc.y = univ.party.out_loc.y - 48; - for(i = 0; i < 96; i++) - for(j = 0; j < 48; j++) + for(short i = 0; i < 96; i++) + for(short j = 0; j < 48; j++) univ.out.out_e[i][j] = univ.out.out_e[i][j + 48]; - for(i = 0; i < 96; i++) - for(j = 48; j < 96; j++) + for(short i = 0; i < 96; i++) + for(short j = 48; j < 96; j++) univ.out.out_e[i][j] = 0; - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { if(univ.party.out_c[i].m_loc.y < 48) univ.party.out_c[i].exists = false; if(univ.party.out_c[i].exists) @@ -245,8 +237,6 @@ void shift_universe_down() { void position_party(short out_x,short out_y,short pc_pos_x,short pc_pos_y) { - short i,j; - if((pc_pos_x != minmax(0,47,pc_pos_x)) || (pc_pos_y != minmax(0,47,pc_pos_y)) || (out_x != minmax(0,univ.scenario.outdoors.width() - 1,out_x)) || (out_y != minmax(0,univ.scenario.outdoors.height() - 1,out_y))) { showError("The scenario has tried to place you in an out of bounds outdoor location."); @@ -264,20 +254,19 @@ void position_party(short out_x,short out_y,short pc_pos_x,short pc_pos_y) { } univ.party.i_w_c.x = (univ.party.out_loc.x > 47) ? 1 : 0; univ.party.i_w_c.y = (univ.party.out_loc.y > 47) ? 1 : 0; - for(i = 0; i < 10; i++) + for(short i = 0; i < 10; i++) univ.party.out_c[i].exists = false; - for(i = 0; i < 96; i++) - for(j = 0; j < 96; j++) + for(short i = 0; i < 96; i++) + for(short j = 0; j < 96; j++) univ.out.out_e[i][j] = 0; build_outdoors(); } void build_outdoors() { - short i,j; size_t x = univ.party.outdoor_corner.x, y = univ.party.outdoor_corner.y; - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++) { + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++) { univ.out[i][j] = univ.scenario.outdoors[x][y]->terrain[i][j]; if(x + 1 < univ.scenario.outdoors.width()) univ.out[48 + i][j] = univ.scenario.outdoors[x+1][y]->terrain[i][j]; @@ -294,7 +283,7 @@ void build_outdoors() { if(overall_mode != MODE_STARTUP) erase_out_specials(); - for(i = 0; i < 10; i++) + for(short i = 0; i < 10; i++) if(univ.party.out_c[i].exists) if((univ.party.out_c[i].m_loc.x < 0) || (univ.party.out_c[i].m_loc.y < 0) || (univ.party.out_c[i].m_loc.x > 95) || (univ.party.out_c[i].m_loc.y > 95)) @@ -313,10 +302,8 @@ short onm(char x_sector,char y_sector) { // This adds the current outdoor map info to the saved outdoor map info void save_outdoor_maps() { - short i,j; - - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++) { + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++) { if(univ.out.out_e[i][j] > 0) univ.out_maps[onm(univ.party.outdoor_corner.x,univ.party.outdoor_corner.y)][i / 8][j] = univ.out_maps[onm(univ.party.outdoor_corner.x,univ.party.outdoor_corner.y)][i / 8][j] | @@ -344,10 +331,8 @@ void save_outdoor_maps() { } void add_outdoor_maps() { // This takes the existing outdoor map info and supplements it with the saved map info - short i,j; - - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++) { + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++) { if((univ.out.out_e[i][j] == 0) && ((univ.out_maps[onm(univ.party.outdoor_corner.x,univ.party.outdoor_corner.y)][i / 8][j] & (char) (1 << i % 8)) != 0)) @@ -377,9 +362,7 @@ void add_outdoor_maps() { // This takes the existing outdoor map info and supple void fix_boats() { - short i; - - for(i = 0; i < univ.party.boats.size(); i++) + for(short i = 0; i < univ.party.boats.size(); i++) if((univ.party.boats[i].exists) && (univ.party.boats[i].which_town == 200)) { if(univ.party.boats[i].sector.x == univ.party.outdoor_corner.x) univ.party.boats[i].loc.x = univ.party.boats[i].loc_in_sec.x; @@ -392,7 +375,7 @@ void fix_boats() { univ.party.boats[i].loc.y = univ.party.boats[i].loc_in_sec.y + 48; else univ.party.boats[i].loc.y = 500; } - for(i = 0; i < univ.party.horses.size(); i++) + for(short i = 0; i < univ.party.horses.size(); i++) if((univ.party.horses[i].exists) && (univ.party.horses[i].which_town == 200)) { if(univ.party.horses[i].sector.x == univ.party.outdoor_corner.x) univ.party.horses[i].loc.x = univ.party.horses[i].loc_in_sec.x; diff --git a/src/boe.graphics.cpp b/src/boe.graphics.cpp index 50ae7fe3..73568d60 100644 --- a/src/boe.graphics.cpp +++ b/src/boe.graphics.cpp @@ -180,7 +180,6 @@ void draw_startup(short but_type) { rectangle to_rect; rectangle r1 = {-1000,-1000,5,1000},r2 = {-1000,-1000,1000,5},r3 = {418,-1000,2000,1000}, r4 = {-1000,579,1000,2500}; - short i; sf::Texture& startup_gworld = *ResMgr::get("startup"); to_rect = startup_from[0]; @@ -189,7 +188,7 @@ void draw_startup(short but_type) { to_rect = startup_top; to_rect.offset(ul); - for(i = 0; i < 5; i++) { + for(short i = 0; i < 5; i++) { rect_draw_some_item(startup_gworld,startup_from[1],startup_button[i],ul); draw_start_button(i,but_type); } @@ -213,7 +212,6 @@ void draw_startup_anim(bool advance) { void draw_startup_stats() { rectangle from_rect,to_rect,party_to = {0,0,36,28},pc_rect,frame_rect; - short i; TextStyle style; style.font = FONT_DUNGEON; @@ -240,7 +238,7 @@ void draw_startup_stats() { win_draw_string(mainPtr,to_rect,"Your party:",eTextMode::WRAP,style,ul); style.pointSize = 12; style.font = FONT_BOLD; - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { pc_rect = startup_top; pc_rect.right = pc_rect.left + 300; pc_rect.bottom = pc_rect.top + 79; @@ -622,14 +620,13 @@ void draw_buttons(short mode) { } void draw_text_bar() { - short i; location loc; loc = (is_out()) ? global_to_local(univ.party.out_loc) : univ.party.town_loc; bool in_area = false; if(is_out()) { - for(i = 0; i < univ.out->info_rect.size(); i++) + for(short i = 0; i < univ.out->info_rect.size(); i++) if(loc.in(univ.out->info_rect[i])) { put_text_bar(univ.out->info_rect[i].descr); in_area = true; @@ -639,7 +636,7 @@ void draw_text_bar() { } } if(is_town()) { - for(i = 0; i < univ.town->room_rect.size(); i++) + for(short i = 0; i < univ.town->room_rect.size(); i++) if(loc.in(univ.town->room_rect[i])) { put_text_bar(univ.town->room_rect[i].descr); in_area = true; @@ -656,7 +653,7 @@ void draw_text_bar() { } if((is_combat()) && (monsters_going)) // Print bar for 1st monster with >0 ap - that is monster that is going - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && (univ.town.monst[i].ap > 0)) { put_text_bar(print_monster_going(univ.town.monst[i].number,univ.town.monst[i].ap)); i = 400; @@ -723,14 +720,12 @@ extern std::list posted_labels; //mode ... if 1, don't place on screen after redoing // if 2, only redraw over active monst void draw_terrain(short mode) { - char q,r; location where_draw; location sector_p_in,view_loc; char can_draw; ter_num_t spec_terrain; bool off_terrain = false,draw_frills = true; bool frills_on = get_bool_pref("DrawTerrainShoreFrills", true); - short i,j; if(overall_mode == MODE_TALKING || overall_mode == MODE_SHOPPING || overall_mode == MODE_STARTUP) return; @@ -738,10 +733,10 @@ void draw_terrain(short mode) { if(mode == 2) { if(current_working_monster < 0) return; supressing_some_spaces = true; - for(i = 0; i < 4; i++) ok_space[i].x = -1; + for(short i = 0; i < 4; i++) ok_space[i].x = -1; if(current_working_monster >= 100) { - for(i = 0; i < univ.town.monst[current_working_monster - 100].x_width; i++) - for(j = 0; j < univ.town.monst[current_working_monster - 100].y_width; j++) { + for(short i = 0; i < univ.town.monst[current_working_monster - 100].x_width; i++) + for(short j = 0; j < univ.town.monst[current_working_monster - 100].y_width; j++) { ok_space[i + 2 * j].x = univ.town.monst[current_working_monster - 100].cur_loc.x + i; ok_space[i + 2 * j].y = univ.town.monst[current_working_monster - 100].cur_loc.y + j; ok_space[i + 2 * j].x = ok_space[i + 2 * j].x - center.x + 4; @@ -758,8 +753,8 @@ void draw_terrain(short mode) { mainPtr.setActive(); - for(i = 0; i < 13; i++) - for(j = 0; j < 13; j++) { + for(short i = 0; i < 13; i++) + for(short j = 0; j < 13; j++) { light_area[i][j] = 0; unexplored_area[i][j] = 0; } @@ -776,8 +771,8 @@ void draw_terrain(short mode) { if(is_combat()) view_loc = univ.party[(current_pc < 6) ? current_pc : first_active_pc()].combat_pos; - for(i = 0; i < 13; i++) - for(j = 0; j < 13; j++) { + for(short i = 0; i < 13; i++) + for(short j = 0; j < 13; j++) { where_draw = (is_out()) ? univ.party.out_loc : center; where_draw.x += i - 6; where_draw.y += j - 6; @@ -790,8 +785,8 @@ void draw_terrain(short mode) { } forcecage_locs.clear(); - for(q = 0; q < 9; q++) { - for(r = 0; r < 9; r++) { + for(short q = 0; q < 9; q++) { + for(short r = 0; r < 9; r++) { where_draw = (is_out()) ? univ.party.out_loc : center; where_draw.x += q - 4; where_draw.y += r - 4; @@ -1162,9 +1157,8 @@ void draw_trim(short q,short r,short which_trim,ter_num_t ground_ter) { trim_rects[9].offset(98,0); trim_rects[10].offset(84,18); trim_rects[11].offset(98,18); - int i; - for(i = 0; i < 12; i++) trim_rects[i].offset(112,36); - for(i = 0; i < 8 ; i++) walkway_rects[i].offset((i%4)*28,(i/4)*36); + for(short i = 0; i < 12; i++) trim_rects[i].offset(112,36); + for(short i = 0; i < 8 ; i++) walkway_rects[i].offset((i%4)*28,(i/4)*36); walkway_rects[8].offset(196,0); } sf::Color test_color = {0,0,0}, store_color; @@ -1486,11 +1480,10 @@ void draw_pointing_arrows() { {7,100,15,108},{7,170,15,178},{140,7,148,15},{212,7,220,15}, {346,100,354,108},{346,170,354,178},{140,274,148,282},{212,274,220,282} }; - short i; if(monsters_going || !scrollableModes.count(overall_mode)) return; - for(i = 0; i < 4; i++) { + for(short i = 0; i < 4; i++) { rect_draw_some_item(terrain_screen_gworld.getTexture(),sources[i],dests[i * 2],ul,sf::BlendAlpha); rect_draw_some_item(terrain_screen_gworld.getTexture(),sources[i],dests[i * 2 + 1],ul,sf::BlendAlpha); } @@ -1513,13 +1506,12 @@ void redraw_terrain() { void draw_targets(location center) { rectangle source_rect = {74,36,85,47},dest_rect; - short i = 0; if(!univ.party.is_alive()) return; sf::Texture& src_gworld = *ResMgr::get("trim"); - for(i = 0; i < 8; i++) + for(short i = 0; i < 8; i++) if((spell_targets[i].x != 120) && (point_onscreen(center,spell_targets[i]))) { dest_rect = coord_to_rect(spell_targets[i].x - center.x + 4,spell_targets[i].y - center.y + 4); rect_draw_some_item(src_gworld,calc_rect(6,0),dest_rect,ul,sf::BlendAlpha); @@ -1557,7 +1549,6 @@ void erase_spot(short i,short j) { void draw_targeting_line(location where_curs) { location which_space,store_loc; - short i,j,k,l; rectangle redraw_rect,redraw_rect2,terrain_rect = {0,0,351,279},target_rect; location from_loc; rectangle on_screen_terrain_area = {23, 23, 346, 274}; @@ -1571,15 +1562,13 @@ void draw_targeting_line(location where_curs) { on_screen_terrain_area.offset(ul); if(where_curs.in(on_screen_terrain_area)) { // && (point_onscreen(center,univ.party[current_pc].combat_pos))){ - i = (where_curs.x - 23 - ul.x) / 28; - j = (where_curs.y - 23 - ul.y) / 36; - which_space.x = center.x + (short) i - 4; - which_space.y = center.y + (short) j - 4; + which_space.x = center.x + (where_curs.x - 23 - ul.x) / 28 - 4; + which_space.y = center.y + (where_curs.y - 23 - ul.y) / 36 - 4; - k = (short) (from_loc.x - center.x + 4); - l = (short) (from_loc.y - center.y + 4); - k = (k * 28) + 32 + ul.x; - l = (l * 36) + 36 + ul.y; + int xBound = (short) (from_loc.x - center.x + 4); + int yBound = (short) (from_loc.y - center.y + 4); + xBound = (xBound * 28) + 32 + ul.x; + yBound = (yBound * 36) + 36 + ul.y; if((can_see_light(from_loc,which_space,sight_obscurity) < 5) && (dist(from_loc,which_space) <= current_spell_range)) { @@ -1587,16 +1576,16 @@ void draw_targeting_line(location where_curs) { terrain_rect.offset(5 + ul.x,5 + ul.y); mainPtr.setActive(); clip_rect(mainPtr, terrain_rect); - draw_line(mainPtr, where_curs, location(k, l), 2, {128,128,128}, sf::BlendAdd); - redraw_rect.left = min(where_curs.x,k) - 4; - redraw_rect.right = max(where_curs.x,k) + 4; - redraw_rect.top = min(where_curs.y,l) - 4; - redraw_rect.bottom = max(where_curs.y,l) + 4; + draw_line(mainPtr, where_curs, location(xBound, yBound), 2, {128,128,128}, sf::BlendAdd); + redraw_rect.left = min(where_curs.x,xBound) - 4; + redraw_rect.right = max(where_curs.x,xBound) + 4; + redraw_rect.top = min(where_curs.y,yBound) - 4; + redraw_rect.bottom = max(where_curs.y,yBound) + 4; redraw_rect2 = redraw_rect & terrain_rect; // Now place targeting pattern - for(i = 0; i < 9; i++) - for(j = 0; j < 9; j++) { + for(short i = 0; i < 9; i++) + for(short j = 0; j < 9; j++) { store_loc.x = center.x + i - 4; store_loc.y = center.y + j - 4; if((abs(store_loc.x - which_space.x) <= 4) && diff --git a/src/boe.graphutil.cpp b/src/boe.graphutil.cpp index d2423759..25790ea8 100644 --- a/src/boe.graphutil.cpp +++ b/src/boe.graphutil.cpp @@ -116,7 +116,6 @@ void draw_one_terrain_spot (short i,short j,short terrain_to_draw) { } void draw_monsters() { - short i,j = 0,k; short width,height; rectangle source_rect,to_rect; location where_draw,store_loc; @@ -129,25 +128,26 @@ void draw_monsters() { }; if(is_out()) - for(i = 0; i < 10; i++) + for(short i = 0; i < 10; i++) if(univ.party.out_c[i].exists) { if((point_onscreen(univ.party.out_loc, univ.party.out_c[i].m_loc)) && (can_see_light(univ.party.out_loc, univ.party.out_c[i].m_loc,sight_obscurity) < 5)) { where_draw.x = univ.party.out_c[i].m_loc.x - univ.party.out_loc.x + 4; where_draw.y = univ.party.out_c[i].m_loc.y - univ.party.out_loc.y + 4; - for(j = 0; univ.party.out_c[i].what_monst.monst[j] == 0 && j < 7; j++); - short picture_wanted; - if(j == 7) univ.party.out_c[i].exists = false; // begin watch out - else { - picture_wanted = get_monst_picnum(univ.party.out_c[i].what_monst.monst[j]); - } // end watch out + for(short j = 0; univ.party.out_c[i].what_monst.monst[j] == 0 && j < 7; j++) { + if(j == 7) univ.party.out_c[i].exists = false; // begin watch out + else { + picture_wanted = get_monst_picnum(univ.party.out_c[i].what_monst.monst[j]); + get_monst_dims(univ.party.out_c[i].what_monst.monst[j],&width,&height); + break; + } // end watch out + } if(univ.party.out_c[i].exists) { - get_monst_dims(univ.party.out_c[i].what_monst.monst[j],&width,&height); if(picture_wanted >= 1000) { - for(k = 0; k < width * height; k++) { + for(short k = 0; k < width * height; k++) { sf::Texture* src_gw; graf_pos_ref(src_gw, source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000 + ((univ.party.out_c[i].direction < 4) ? 0 : (width * height)) + k); @@ -157,7 +157,7 @@ void draw_monsters() { } } if(picture_wanted < 1000) { - for(k = 0; k < width * height; k++) { + for(short k = 0; k < width * height; k++) { source_rect = get_monster_template_rect(picture_wanted,(univ.party.out_c[i].direction < 4) ? 0 : 1,k); to_rect = monst_rects[(width - 1) * 2 + height - 1][k]; to_rect.offset(13 + 28 * where_draw.x,13 + 36 * where_draw.y); @@ -170,14 +170,14 @@ void draw_monsters() { } } if(is_town() || is_combat()) { - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active != 0 && !univ.town.monst[i].invisible && univ.town.monst[i].status[eStatus::INVISIBLE] <= 0) if(point_onscreen(center,univ.town.monst[i].cur_loc) && party_can_see_monst(i)) { where_draw.x = univ.town.monst[i].cur_loc.x - center.x + 4; where_draw.y = univ.town.monst[i].cur_loc.y - center.y + 4; get_monst_dims(univ.town.monst[i].number,&width,&height); - for(k = 0; k < width * height; k++) { + for(short k = 0; k < width * height; k++) { store_loc = where_draw; store_loc.x += k % width; store_loc.y += k / width; @@ -319,10 +319,9 @@ void draw_items(location where){ void draw_outd_boats(location center) { location where_draw; rectangle source_rect; - short i; sf::Texture& vehicle_gworld = *ResMgr::get("vehicle"); - for(i = 0; i < univ.party.boats.size(); i++) + for(short i = 0; i < univ.party.boats.size(); i++) if((point_onscreen(center, univ.party.boats[i].loc)) && (univ.party.boats[i].exists) && (univ.party.boats[i].which_town == 200) && (can_see_light(center, univ.party.boats[i].loc,sight_obscurity) < 5) && (univ.party.in_boat != i)) { @@ -330,7 +329,7 @@ void draw_outd_boats(location center) { where_draw.y = univ.party.boats[i].loc.y - center.y + 4; Draw_Some_Item(vehicle_gworld, calc_rect(0,0), terrain_screen_gworld, where_draw, 1, 0); } - for(i = 0; i < univ.party.horses.size(); i++) + for(short i = 0; i < univ.party.horses.size(); i++) if((point_onscreen(center, univ.party.horses[i].loc)) && (univ.party.horses[i].exists) && (univ.party.horses[i].which_town == 200) && (can_see_light(center, univ.party.horses[i].loc,sight_obscurity) < 5) && (univ.party.in_horse != i)) { @@ -343,10 +342,9 @@ void draw_outd_boats(location center) { void draw_town_boat(location center) { location where_draw; rectangle source_rect; - short i; sf::Texture& vehicle_gworld = *ResMgr::get("vehicle"); - for(i = 0; i < univ.party.boats.size(); i++) + for(short i = 0; i < univ.party.boats.size(); i++) if((univ.party.boats[i].which_town == univ.party.town_num) && ((point_onscreen(center, univ.party.boats[i].loc)) && (can_see_light(center, univ.party.boats[i].loc,sight_obscurity) < 5) && (univ.party.in_boat != i) @@ -355,7 +353,7 @@ void draw_town_boat(location center) { where_draw.y = univ.party.boats[i].loc.y - center.y + 4; Draw_Some_Item(vehicle_gworld, calc_rect(1,0), terrain_screen_gworld, where_draw, 1, 0); } - for(i = 0; i < univ.party.horses.size(); i++) + for(short i = 0; i < univ.party.horses.size(); i++) if((univ.party.horses[i].which_town == univ.party.town_num) && ((point_onscreen(center, univ.party.horses[i].loc)) && (can_see_light(center, univ.party.horses[i].loc,sight_obscurity) < 5) && (univ.party.in_horse != i) diff --git a/src/boe.infodlg.cpp b/src/boe.infodlg.cpp index 5663fb0f..b8463235 100644 --- a/src/boe.infodlg.cpp +++ b/src/boe.infodlg.cpp @@ -366,7 +366,7 @@ static void put_monst_info(cDialog& me, const cCreature& store_m) { i++; } - for(i = 0; i < store_m.a.size(); i++) { + for(short i = 0; i < store_m.a.size(); i++) { if(store_m.a[i].dice > 0) { if(store_m.a[i].sides == 0) continue; std::ostringstream sout(std::ios_base::ate); @@ -401,12 +401,11 @@ static bool display_monst_event_filter(cDialog& me, std::string item_hit, cCreat // This is a bit hacky; keep a cPopulation here to handle the full roster; it's treated like a rotating buffer. static cPopulation roster; roster.init(60); - short i; if(item_hit == "left") { if(position == 0) { - for(i = 255; on_monst_menu[i] < 0 && i > 0; i--); - position = i; + for(short i = 255; on_monst_menu[i] < 0 && i > 0; i--) + position = i; } else position--; @@ -497,14 +496,11 @@ void display_alchemy() { } static void display_pc_info(cDialog& me, const short pc) { - short i,store; std::ostringstream to_draw; short weap1 = 24,weap2 = 24,hit_adj = 0, dam_adj = 0,skill_item; - store = univ.party[pc].cur_weight(); - i = univ.party[pc].max_weight(); - to_draw << univ.party[pc].name << " is carrying " << store << " stones out of " << i << '.'; + to_draw << univ.party[pc].name << " is carrying " << univ.party[pc].cur_weight() << " stones out of " << univ.party[pc].max_weight() << '.'; me["weight"].setText(to_draw.str()); to_draw.str(""); @@ -515,7 +511,7 @@ static void display_pc_info(cDialog& me, const short pc) { me["sp"].setText(to_draw.str()); to_draw.str(""); - for(i = 0; i < 19; i++) { + for(short i = 0; i < 19; i++) { eSkill skill = eSkill(i); int bonus = univ.party[pc].get_prot_level(eItemAbil::BOOST_STAT, i); to_draw << univ.party[pc].skills[skill]; @@ -523,21 +519,19 @@ static void display_pc_info(cDialog& me, const short pc) { me[skill_ids[i]].setText(to_draw.str()); to_draw.str(""); } - store = total_encumbrance(pc); - me["encumb"].setTextToNum(store); + me["encumb"].setTextToNum(total_encumbrance(pc)); me["name"].setText(univ.party[pc].name); me["lvl"].setTextToNum(univ.party[pc].level); me["xp"].setTextToNum(univ.party[pc].experience); me["skp"].setTextToNum(univ.party[pc].skill_pts); - store = univ.party[pc].level * univ.party[pc].get_tnl(); - me["progress"].setTextToNum(store); + me["progress"].setTextToNum(univ.party[pc].level * univ.party[pc].get_tnl()); pic_num_t pic = univ.party[pc].which_graphic; if(pic >= 100 && pic < 1000) dynamic_cast(me["pic"]).setPict(pic - 100,PIC_MONST); else dynamic_cast(me["pic"]).setPict(pic,PIC_PC); // Fight bonuses - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) if((univ.party[pc].items[i].variety == eItemType::ONE_HANDED || univ.party[pc].items[i].variety == eItemType::TWO_HANDED) && (univ.party[pc].equip[i])) { if(weap1 == 24) @@ -622,7 +616,6 @@ static bool give_pc_extra_info(cDialog& me, std::string item_hit, const short pc void give_pc_info(short pc_num) { using namespace std::placeholders; - short i; std::string str; make_cursor_sword(); @@ -631,7 +624,7 @@ void give_pc_info(short pc_num) { pcInfo.attachClickHandlers(std::bind(give_pc_info_event_filter, _1, _2, std::ref(pc_num)), {"done", "left", "right"}); pcInfo.attachClickHandlers(std::bind(give_pc_extra_info, _1, _2, std::ref(pc_num)), {"seemage", "seepriest", "trait", "seealch"}); - for(i = 0; i < 19; i++) { + for(short i = 0; i < 19; i++) { std::string lbl= "lbl" + boost::lexical_cast(i + 1); str = get_str("skills",1 + i * 2); pcInfo[lbl].setText(str); @@ -642,8 +635,6 @@ void give_pc_info(short pc_num) { } static bool adventure_notes_event_filter(cDialog& me, std::string item_hit, eKeyMod) { - unsigned short i; - if(item_hit == "done") me.toast(true); else if(item_hit == "left") { if(store_page_on == 0) @@ -660,7 +651,7 @@ static bool adventure_notes_event_filter(cDialog& me, std::string item_hit, eKey iter += which_to_delete; univ.party.special_notes.erase(iter); } - for(i = 0; i < 3; i++) { + for(short i = 0; i < 3; i++) { std::string n = boost::lexical_cast(i + 1); if(univ.party.special_notes.size() > i) { me["str" + n].setText(univ.party.special_notes[i].the_str); @@ -669,7 +660,7 @@ static bool adventure_notes_event_filter(cDialog& me, std::string item_hit, eKey else me["del" + n].hide(); } // TODO: What's this second loop for? - for(i = store_page_on * 3; i < (store_page_on * 3) + 3; i++) { + for(short i = store_page_on * 3; i < (store_page_on * 3) + 3; i++) { std::string n = boost::lexical_cast(i + 1); if(univ.party.special_notes.size() > i) { me["str" + n].setText(univ.party.special_notes[i].the_str); @@ -684,9 +675,6 @@ static bool adventure_notes_event_filter(cDialog& me, std::string item_hit, eKey } void adventure_notes() { - - unsigned short i; - store_num_i = 0; store_num_i = univ.party.special_notes.size(); store_page_on = 0; @@ -701,7 +689,7 @@ void adventure_notes() { cDialog encNotes("adventure-notes"); encNotes.attachClickHandlers(adventure_notes_event_filter, {"done", "left", "rigth", "del1", "del2", "del3"}); - for(i = 0; i < 3; i++) { + for(short i = 0; i < 3; i++) { std::string n = boost::lexical_cast(i + 1); if(univ.party.special_notes.size() > i) { encNotes["str" + n].setText(univ.party.special_notes[i].the_str); diff --git a/src/boe.itemdata.cpp b/src/boe.itemdata.cpp index ecb2d98e..d08ae878 100644 --- a/src/boe.itemdata.cpp +++ b/src/boe.itemdata.cpp @@ -42,7 +42,7 @@ cItem get_food() { cItem pull_item_of_type(unsigned int loot_max,short min_val,short max_val,eItemType t1, eItemType t2, eItemType t3) { - short i,j,val; + short val; cItem temp_i; // occasionally get nice item @@ -50,8 +50,8 @@ cItem pull_item_of_type(unsigned int loot_max,short min_val,short max_val,eItemT loot_max += 2; max_val += 2000; } - for(i = 0; i < 80; i++) { - j = get_ran(1,0,univ.scenario.scen_items.size() - 1); + for(short i = 0; i < 80; i++) { + int j = get_ran(1,0,univ.scenario.scen_items.size() - 1); temp_i = get_stored_item(j); if(temp_i.variety == eItemType::NO_ITEM) continue; if((temp_i.variety == t1) || (temp_i.variety == t2) || (temp_i.variety == t3)) { diff --git a/src/boe.items.cpp b/src/boe.items.cpp index c15ca982..7ef03a63 100644 --- a/src/boe.items.cpp +++ b/src/boe.items.cpp @@ -174,14 +174,12 @@ void drop_item(short pc_num,short item_num,location where_drop) { } bool place_item(cItem item,location where,bool contained) { - short i; - if(contained && !is_container(where)) contained = false; bool is_pushable_ctr = contained && (univ.town.is_barrel(where.x,where.y) || univ.town.is_crate(where.x,where.y)); - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety == eItemType::NO_ITEM) { univ.town.items[i] = item; univ.town.items[i].item_loc = where; @@ -241,10 +239,10 @@ void give_thing(short pc_num, short item_num) { // Procedure only ready for town and outdoor short dist_from_party(location where) { - short store = 1000, i; + short store = 1000; if((overall_mode >= MODE_COMBAT) && (overall_mode < MODE_TALKING)) { - for(i = 0; i < 6; i++) + 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)); } @@ -265,16 +263,16 @@ void set_item_flag(cItem* item) { //short pc_num; // if 6, any short get_item(location place,short pc_num,bool check_container) { - short i,taken = 0; + short taken = 0; bool item_near = false; short mass_get = 1; - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0 && !univ.town.monst[i].is_friendly() && (can_see_light(place,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) mass_get = 0; - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM) if(((adjacent(place,univ.town.items[i].item_loc)) || (mass_get == 1 && !check_container && @@ -289,7 +287,7 @@ short get_item(location place,short pc_num,bool check_container) { } if(item_near) if(display_item(place,pc_num,mass_get,check_container)) { // if true, there was a theft - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0 && univ.town.monst[i].is_friendly() && (can_see_light(place,univ.town.monst[i].cur_loc,sight_obscurity) < 5)) { make_town_hostile(); @@ -317,7 +315,7 @@ void make_town_hostile() { // Set Attitude node adapted from *i, meant to replace make_town_hostile node void set_town_attitude(short lo,short hi,eAttitude att) { - short i,num; + short num; short a[3] = {}; // Dummy values to pass to run_special. if(which_combat_type == 0) @@ -338,7 +336,7 @@ void set_town_attitude(short lo,short hi,eAttitude att) { if(hi < lo) std::swap(lo, hi); - for(i = lo; i <= hi; i++) { + for(short i = lo; i <= hi; i++) { if(univ.town.monst[i].active > 0 && univ.town.monst[i].summon_time == 0){ univ.town.monst[i].attitude = att; num = univ.town.monst[i].number; @@ -368,7 +366,6 @@ void set_town_attitude(short lo,short hi,eAttitude att) { static void put_item_graphics(cDialog& me, size_t& first_item_shown, short& current_getting_pc, const std::vector& item_array) { - short i; cItem item; char key_stash[2] = "a"; @@ -379,7 +376,7 @@ static void put_item_graphics(cDialog& me, size_t& first_item_shown, short& curr } - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { std::ostringstream sout; sout << "pc" << i + 1; std::string id = sout.str(); @@ -407,7 +404,7 @@ static void put_item_graphics(cDialog& me, size_t& first_item_shown, short& curr me["down"].hide(); else me["down"].show(); - for(i = 0; i < 8; i++) { + for(short i = 0; i < 8; i++) { std::ostringstream sout; sout << "item" << i + 1; std::string pict = sout.str() + "-g", name = sout.str() + "-name"; @@ -445,7 +442,7 @@ static void put_item_graphics(cDialog& me, size_t& first_item_shown, short& curr me["prompt"].setText(sout.str()); } - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { std::ostringstream sout; sout << "pc" << i + 1 << "-g"; @@ -537,13 +534,12 @@ static bool display_item_event_filter(cDialog& me, std::string id, size_t& first bool display_item(location from_loc,short /*pc_num*/,short mode, bool check_container) { // short item_array[130]; std::vector item_array; - short i; make_cursor_sword(); short current_getting_pc = current_pc; - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM) { if(((adjacent(from_loc,univ.town.items[i].item_loc)) || (mode == 1 && !check_container && @@ -730,7 +726,7 @@ short item_val(cItem item) { void place_treasure(location where,short level,short loot,short mode) { cItem new_item; - short amt,r1,i,j; + short amt,r1; // Make these static const because they are never changed. // Saves them being initialized every time the function is called. static const short treas_chart[5][6] = { @@ -785,7 +781,7 @@ void place_treasure(location where,short level,short loot,short mode) { || ((r1 < 6) && (univ.party.get_level() < 30)) || (loot > 2) ) place_item(new_item,where); } - for(j = 0; j < 5; j++) { + for(short j = 0; j < 5; j++) { r1 = get_ran(1,1,100); if((treas_chart[loot][j] >= 0) && (r1 <= treas_odds[loot][j] + check_party_stat(eSkill::LUCK, 0))) { r1 = get_ran(1,0,9); @@ -835,7 +831,7 @@ void place_treasure(location where,short level,short loot,short mode) { new_item.variety = eItemType::NO_ITEM; if(new_item.variety != eItemType::NO_ITEM) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if((univ.party[i].main_status == eMainStatus::ALIVE) && get_ran(1,1,100) < id_odds[univ.party[i].skill(eSkill::ITEM_LORE)]) new_item.ident = true; @@ -1010,7 +1006,7 @@ static bool select_pc_event_filter (cDialog& me, std::string item_hit, eKeyMod) // mode determines which PCs can be picked // 0 - only living pcs, 1 - any pc, 2 - only dead pcs, 3 - only living pcs with inventory space short char_select_pc(short mode,const char *title) { - short item_hit,i; + short item_hit; make_cursor_sword(); @@ -1019,7 +1015,7 @@ short char_select_pc(short mode,const char *title) { selectPc["title"].setText(title); - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { std::string n = boost::lexical_cast(i + 1); bool can_pick = true; if(univ.party[i].main_status == eMainStatus::ABSENT || univ.party[i].main_status == eMainStatus::FLED) diff --git a/src/boe.locutils.cpp b/src/boe.locutils.cpp index ee798e51..3b6be93d 100644 --- a/src/boe.locutils.cpp +++ b/src/boe.locutils.cpp @@ -277,7 +277,7 @@ void update_explored(location dest) { // All purpose function to check is spot is free for travel into. bool is_blocked(location to_check) { - short i,gr; + short gr; ter_num_t ter; if(is_out()) { @@ -286,7 +286,7 @@ bool is_blocked(location to_check) { } if(to_check == univ.party.out_loc) return true; - for(i = 0; i < univ.party.out_c.size(); i++) + for(short i = 0; i < univ.party.out_c.size(); i++) if((univ.party.out_c[i].exists)) if(univ.party.out_c[i].m_loc == to_check) return true; @@ -314,7 +314,7 @@ bool is_blocked(location to_check) { if(to_check == univ.party.town_loc) return true; if(is_combat()) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE && to_check == univ.party[i].combat_pos) return true; @@ -335,14 +335,13 @@ bool is_blocked(location to_check) { } bool monst_can_be_there(location loc,short m_num) { - short i,j; location destination; // First clear monst away so it doesn't block itself univ.town.monst[m_num].cur_loc.x += 100; - for(i = 0; i < univ.town.monst[m_num].x_width; i++) - for(j = 0; j < univ.town.monst[m_num].y_width; j++) { + for(short i = 0; i < univ.town.monst[m_num].x_width; i++) + for(short j = 0; j < univ.town.monst[m_num].y_width; j++) { destination.x = loc.x + i; destination.y = loc.y + j; if((is_blocked(destination)) || (loc_off_act_area(destination))) { @@ -355,11 +354,10 @@ bool monst_can_be_there(location loc,short m_num) { } bool monst_adjacent(location loc,short m_num) { - short i,j; location destination; - for(i = 0; i < univ.town.monst[m_num].x_width; i++) - for(j = 0; j < univ.town.monst[m_num].y_width; j++) { + for(short i = 0; i < univ.town.monst[m_num].x_width; i++) + for(short j = 0; j < univ.town.monst[m_num].y_width; j++) { destination.x = univ.town.monst[m_num].cur_loc.x + i; destination.y = univ.town.monst[m_num].cur_loc.y + j; if(adjacent(destination,loc)) @@ -369,11 +367,10 @@ bool monst_adjacent(location loc,short m_num) { } bool monst_can_see(short m_num,location l) { - short i,j; location destination; - for(i = 0; i < univ.town.monst[m_num].x_width; i++) - for(j = 0; j < univ.town.monst[m_num].y_width; j++) { + for(short i = 0; i < univ.town.monst[m_num].x_width; i++) + for(short j = 0; j < univ.town.monst[m_num].y_width; j++) { destination.x = univ.town.monst[m_num].cur_loc.x + i; destination.y = univ.town.monst[m_num].cur_loc.y + j; if(can_see_light(destination,l,sight_obscurity) < 5) @@ -383,11 +380,10 @@ bool monst_can_see(short m_num,location l) { } bool party_can_see_monst(short m_num) { - short i,j; location destination; - for(i = 0; i < univ.town.monst[m_num].x_width; i++) - for(j = 0; j < univ.town.monst[m_num].y_width; j++) { + for(short i = 0; i < univ.town.monst[m_num].x_width; i++) + for(short j = 0; j < univ.town.monst[m_num].y_width; j++) { destination.x = univ.town.monst[m_num].cur_loc.x + i; destination.y = univ.town.monst[m_num].cur_loc.y + j; if(party_can_see(destination) < 6) @@ -397,11 +393,10 @@ bool party_can_see_monst(short m_num) { } bool can_see_monst(location l,short m_num) { - short i,j; location destination; - for(i = 0; i < univ.town.monst[m_num].x_width; i++) - for(j = 0; j < univ.town.monst[m_num].y_width; j++) { + for(short i = 0; i < univ.town.monst[m_num].x_width; i++) + for(short j = 0; j < univ.town.monst[m_num].y_width; j++) { destination.x = univ.town.monst[m_num].cur_loc.x + i; destination.y = univ.town.monst[m_num].cur_loc.y + j; if(can_see_light(l,destination,sight_obscurity) < 5) @@ -411,13 +406,11 @@ bool can_see_monst(location l,short m_num) { } bool outd_is_blocked(location to_check) { - short i; - if(overall_mode == MODE_OUTDOORS) { if(impassable(univ.out[to_check.x][to_check.y])) { return true; } - for(i = 0; i < 10; i++) + for(short i = 0; i < 10; i++) if((univ.party.out_c[i].exists)) if(univ.party.out_c[i].m_loc == to_check) return true; @@ -472,13 +465,13 @@ short get_blockage(ter_num_t terrain_type) { short light_radius() { - short store = 1,i; + short store = 1; short extra_levels[6] = {10,20,50,75,110,140}; if(((which_combat_type == 0) && (is_combat())) || (is_out()) || (univ.town->lighting_type == 0)) return 200; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party.light_level > extra_levels[i]) store++; return store; @@ -501,7 +494,7 @@ bool pt_in_light(location from_where,location to_where) { // Assumes, of course, } bool combat_pt_in_light(location to_where) { - short i,rad; + short rad; if((univ.town->lighting_type == 0) || (which_combat_type == 0)) return true; @@ -512,7 +505,7 @@ bool combat_pt_in_light(location to_where) { return true; rad = light_radius(); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { if(dist(univ.party[i].combat_pos,to_where) <= rad) return true; @@ -522,9 +515,7 @@ bool combat_pt_in_light(location to_where) { } bool party_sees_a_monst() { // Returns true is a hostile monster is in sight. - short i; - - for(i = 0; i < univ.town.monst.size(); i++) { + for(short i = 0; i < univ.town.monst.size(); i++) { if(univ.town.monst[i].active > 0) if(!univ.town.monst[i].is_friendly() && (party_can_see_monst(i))) @@ -537,8 +528,6 @@ bool party_sees_a_monst() { // Returns true is a hostile monster is in sight. // Returns 6 if can't see, O.W. returns the # of a PC that can see short party_can_see(location where) { - short i; - if(is_out()) { if((point_onscreen(univ.party.out_loc,where)) && (can_see_light(univ.party.out_loc,where,sight_obscurity) < 5)) return 1; @@ -558,7 +547,7 @@ short party_can_see(location where) { if((which_combat_type != 0) && !combat_pt_in_light(where)) return 6; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { if(can_see_light(univ.party[i].combat_pos,where,sight_obscurity) < 5) return i; diff --git a/src/boe.main.cpp b/src/boe.main.cpp index 10a39790..06da303a 100644 --- a/src/boe.main.cpp +++ b/src/boe.main.cpp @@ -385,7 +385,7 @@ void handle_menu_choice(eMenu item_hit) { std::string choice = cChoiceDlog("restart-game",{"okay","cancel"}).show(); if(choice == "cancel") return; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) univ.party[i].main_status = eMainStatus::ABSENT; party_in_memory = false; reload_startup(); @@ -482,7 +482,7 @@ void handle_menu_choice(eMenu item_hit) { print_buf(); break; } - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ABSENT) i = 20; if(i == 6) { diff --git a/src/boe.menus.mac.mm b/src/boe.menus.mac.mm index 332f36f7..34d61c2d 100644 --- a/src/boe.menus.mac.mm +++ b/src/boe.menus.mac.mm @@ -59,17 +59,17 @@ void showMenuBar() { } void adjust_monst_menu() { - short i,monst_pos = 0; + short monst_pos = 0; NSMenu* monst_menu; if(overall_mode == MODE_STARTUP) return; monst_menu = [[menu_bar_handle itemWithTitle: @"Monsters"] submenu]; id targ = [[monst_menu itemAtIndex: 0] target]; - for(i = 0; i < 256; i++) { + for(short i = 0; i < 256; i++) { on_monst_menu[i] = -1; } - for(i = 1; i < 256; i++) { + for(short i = 1; i < 256; i++) { if(i == 1 || univ.party.m_noted.count(i) > 0) { on_monst_menu[monst_pos] = i; monst_pos++; @@ -79,7 +79,7 @@ void adjust_monst_menu() { while([monst_menu numberOfItems] > 2) { [monst_menu removeItemAtIndex: 2]; } - for(i = 0; i < 256; i++) { + for(short i = 0; i < 256; i++) { if(on_monst_menu[i] >= 0) { std::string monst_name = univ.scenario.scen_monsters[on_monst_menu[i]].m_name; NSString* str = [NSString stringWithUTF8String: monst_name.c_str()]; @@ -163,10 +163,8 @@ void init_menubar() { } void init_spell_menus() { - short i,j; - - for(i = 0; i < 2; i++) - for(j = 0; j < 62; j++) + for(short i = 0; i < 2; i++) + for(short j = 0; j < 62; j++) on_spell_menu[i][j] = -1; } @@ -174,7 +172,7 @@ void init_spell_menus() { void adjust_spell_menus() { - short i,j,spell_pos = 0; + short spell_pos = 0; NSMenu* spell_menu; short old_on_spell_menu[2][62]; bool need_menu_change = false; @@ -182,29 +180,29 @@ void adjust_spell_menus() { if(overall_mode == MODE_STARTUP || current_pc == 6) return; - for(i = 0; i < 2; i++) - for(j = 0; j < 62; j++) + for(short i = 0; i < 2; i++) + for(short j = 0; j < 62; j++) old_on_spell_menu[i][j] = on_spell_menu[i][j]; spell_menu = [[menu_bar_handle itemWithTitle: @"Cast Mage"] submenu]; id targ = [[spell_menu itemAtIndex: 0] target]; - for(i = 0; i < 62; i++) { + for(short i = 0; i < 62; i++) { on_spell_menu[0][i] = -1; } - for(i = 0; i < 62; i++) - if(pc_can_cast_spell(current_pc,cSpell::fromNum(eSkill::MAGE_SPELLS,i))) { + for(short i = 0; i < 62; i++) + if(pc_can_cast_spell(univ.party[current_pc],cSpell::fromNum(eSkill::MAGE_SPELLS,i))) { on_spell_menu[0][spell_pos] = i; spell_pos++; } - for(i = 0; i < 62; i++) + for(short i = 0; i < 62; i++) if(on_spell_menu[0][i] != old_on_spell_menu[0][i]) need_menu_change = true; if(need_menu_change) { while([spell_menu numberOfItems] > 2) { [spell_menu removeItemAtIndex: 2]; } - for(i = 0; i < 62; i++) + for(short i = 0; i < 62; i++) if(on_spell_menu[0][i] >= 0) { eSpell spell = cSpell::fromNum(eSkill::MAGE_SPELLS, on_spell_menu[0][i]); std::ostringstream sout; @@ -222,22 +220,22 @@ void adjust_spell_menus() { spell_menu = [[menu_bar_handle itemWithTitle: @"Cast Priest"] submenu]; - for(i = 0; i < 62; i++) { + for(short i = 0; i < 62; i++) { on_spell_menu[1][i] = -1; } - for(i = 0; i < 62; i++) - if(pc_can_cast_spell(current_pc,cSpell::fromNum(eSkill::PRIEST_SPELLS,i))) { + for(short i = 0; i < 62; i++) + if(pc_can_cast_spell(univ.party[current_pc],cSpell::fromNum(eSkill::PRIEST_SPELLS,i))) { on_spell_menu[1][spell_pos] = i; spell_pos++; } - for(i = 0; i < 62; i++) + for(short i = 0; i < 62; i++) if(on_spell_menu[1][i] != old_on_spell_menu[1][i]) need_menu_change = true; if(need_menu_change) { while([spell_menu numberOfItems] > 2) { [spell_menu removeItemAtIndex: 2]; } - for(i = 0; i < 62; i++) + for(short i = 0; i < 62; i++) if(on_spell_menu[1][i] >= 0) { eSpell spell = cSpell::fromNum(eSkill::MAGE_SPELLS, on_spell_menu[1][i]); std::ostringstream sout; diff --git a/src/boe.monster.cpp b/src/boe.monster.cpp index 42602d10..0706dcc3 100644 --- a/src/boe.monster.cpp +++ b/src/boe.monster.cpp @@ -28,20 +28,20 @@ extern bool processing_fields,monsters_going; extern cUniverse univ; short out_enc_lev_tot(short which) { - short count = 0,i; + short count = 0; short num[7] = {22,8,4,4,3,2,1}; if(univ.party.out_c[which].what_monst.cant_flee) return 10000; - for(i = 0; i < 7; i++) + for(short i = 0; i < 7; i++) if(univ.party.out_c[which].what_monst.monst[i] != 0) count += univ.scenario.scen_monsters[univ.party.out_c[which].what_monst.monst[i]].level * num[i]; return count; } void create_wand_monst() { - short r1,r2,r3,i = 0,num_tries = 0; + short r1,r2,r3,num_tries = 0; location p_loc; r1 = get_ran(1,0,univ.out->wandering.size() - 1); @@ -60,7 +60,7 @@ void create_wand_monst() { while(point_onscreen(univ.town->wandering_locs[r2],univ.party.town_loc) && !loc_off_act_area(univ.town->wandering_locs[r2]) && num_tries++ < 100) r2 = get_ran(1,0,3); - for(i = 0; i < 4; i++) { + for(short i = 0; i < 4; i++) { if(univ.town->wandering[r1].monst[i] != 0) { // place a monster p_loc = univ.town->wandering_locs[r2]; p_loc.x += get_ran(1,0,4) - 2; @@ -175,12 +175,12 @@ void set_up_monst(eAttitude mode,mon_num_t m_num) { } void do_monsters() { - short i,j,r1,target; + short r1,target; location l1,l2; bool acted_yet = false; if(overall_mode == MODE_TOWN) - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active != 0 && univ.town.monst[i].status[eStatus::ASLEEP] <= 0 && univ.town.monst[i].status[eStatus::PARALYZED] <= 0) { // have to pick targets @@ -249,7 +249,7 @@ void do_monsters() { play_sound(18); else play_sound(46); } - for(j = 0; j < univ.town.monst.size(); j++) + for(short j = 0; j < univ.town.monst.size(); j++) if((univ.town.monst[j].active == 2) && ((dist(univ.town.monst[i].cur_loc,univ.town.monst[j].cur_loc) <= 5))) univ.town.monst[i].active = 2; @@ -257,7 +257,7 @@ void do_monsters() { } if(overall_mode == MODE_OUTDOORS) { - for(i = 0; i < 10; i++) + for(short i = 0; i < 10; i++) if(univ.party.out_c[i].exists) { acted_yet = false; l1 = univ.party.out_c[i].m_loc; @@ -410,9 +410,9 @@ short monst_pick_target(short which_m) { } short monst_pick_target_monst(cCreature *which_m) { - short min_dist = 1000,i,cur_targ = 6; + short min_dist = 1000,cur_targ = 6; - for(i = 0; i < univ.town.monst.size(); i++) { + for(short i = 0; i < univ.town.monst.size(); i++) { if(univ.town.monst[i].active > 0 && !which_m->is_friendly(univ.town.monst[i]) && // allve + they hate each other ((dist(which_m->cur_loc,univ.town.monst[i].cur_loc) < min_dist) || ((dist(which_m->cur_loc,univ.town.monst[i].cur_loc) == min_dist) && (get_ran(1,0,7) < 4))) && @@ -469,9 +469,9 @@ short select_active_pc() { } short closest_pc(location where) { - short how_close = 200,i,store = 6; + short how_close = 200,store = 6; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE && dist(where,univ.party[i].combat_pos) < how_close) { store = i; how_close = dist(where,univ.party[i].combat_pos); @@ -481,9 +481,9 @@ short closest_pc(location where) { //mode; // 1 - closest hostile to PCs 2 - closest friendly to PCs short closest_monst(location where,bool friendly) { - short how_close = 200,i,store = 6; + short how_close = 200,store = 6; - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].is_friendly() == friendly && (dist(where,univ.town.monst[i].cur_loc) < how_close)) { store = i; @@ -494,7 +494,7 @@ short closest_monst(location where,bool friendly) { short switch_target_to_adjacent(short which_m,short orig_target) { location monst_loc; - short i,num_adj = 0; + short num_adj = 0; monst_loc = univ.town.monst[which_m].cur_loc; @@ -504,7 +504,7 @@ short switch_target_to_adjacent(short which_m,short orig_target) { if((univ.town.monst[orig_target - 100].active > 0) && (monst_adjacent(univ.town.monst[orig_target - 100].cur_loc,which_m))) return orig_target; - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && !univ.town.monst[i].is_friendly() && (monst_adjacent(univ.town.monst[i].cur_loc,which_m))) @@ -529,13 +529,13 @@ short switch_target_to_adjacent(short which_m,short orig_target) { // Anyone unarmored? Heh heh heh... if(is_combat()) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE && monst_adjacent(univ.party[i].combat_pos,which_m) && (get_encumbrance(i) < 2)) return i; // Check for a nice, adjacent, friendly monster and maybe attack - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && univ.town.monst[i].is_friendly() && (monst_adjacent(univ.town.monst[i].cur_loc,which_m)) && @@ -544,14 +544,14 @@ short switch_target_to_adjacent(short which_m,short orig_target) { // OK. Now if this monster has PCs adjacent, pick one at randomn and hack. Otherwise, // stick with orig. target. - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE && monst_adjacent(univ.party[i].combat_pos,which_m)) num_adj++; if(num_adj == 0) return orig_target; - i = 0; + short i = 0; num_adj = get_ran(1,1,num_adj); while(num_adj > 1 || univ.party[i].main_status != eMainStatus::ALIVE || !monst_adjacent(univ.party[i].combat_pos,which_m)) { if(univ.party[i].main_status == eMainStatus::ALIVE && monst_adjacent(univ.party[i].combat_pos,which_m)) @@ -564,7 +564,6 @@ short switch_target_to_adjacent(short which_m,short orig_target) { bool rand_move(mon_num_t i) { bool acted_yet = false; - short j; location store_loc; // first, if outdoor, just roam. @@ -582,7 +581,7 @@ bool rand_move(mon_num_t i) { if(!acted_yet) { univ.town.monst[i].targ_loc.x = 0; - for(j = 0; j < 3; j++) { + for(short j = 0; j < 3; j++) { store_loc = univ.town.monst[i].cur_loc; store_loc.x += get_ran(1,0,24) - 12; store_loc.y += get_ran(1,0,24) - 12; @@ -593,7 +592,7 @@ bool rand_move(mon_num_t i) { if(univ.town.monst[i].targ_loc.x == 0) { // maybe pick a wand loc, else juist pick a loc - j = get_ran(1,0,univ.town->wandering_locs.size() - 1); + short j = get_ran(1,0,univ.town->wandering_locs.size() - 1); store_loc = univ.town->wandering_locs[j]; if(!loc_off_act_area(store_loc) && (get_ran(1,0,1) == 1)) @@ -789,7 +788,7 @@ bool monster_placid(short m_num) { // This damages a monster by any fields it's in, and destroys any barrels or crates // it's stiing on. void monst_inflict_fields(short which_monst) { - short i,j,r1,k; + short r1; location where_check; cCreature *which_m; @@ -799,8 +798,8 @@ void monst_inflict_fields(short which_monst) { which_m = &univ.town.monst[which_monst]; bool have_radiate = which_m->abil[eMonstAbil::RADIATE].active; eFieldType which_radiate = which_m->abil[eMonstAbil::RADIATE].radiate.type; - for(i = 0; i < univ.town.monst[which_monst].x_width; i++) - for(j = 0; j < univ.town.monst[which_monst].y_width; j++) + for(short i = 0; i < univ.town.monst[which_monst].x_width; i++) + for(short j = 0; j < univ.town.monst[which_monst].y_width; j++) if(univ.town.monst[which_monst].active > 0) { where_check.x = univ.town.monst[which_monst].cur_loc.x + i; where_check.y = univ.town.monst[which_monst].cur_loc.y + j; @@ -856,13 +855,13 @@ void monst_inflict_fields(short which_monst) { process_force_cage(where_check, univ.get_target_i(*which_m)); } if(univ.town.monst[which_monst].active > 0) - for(i = 0; i < univ.town.monst[which_monst].x_width; i++) - for(j = 0; j < univ.town.monst[which_monst].y_width; j++) { + for(short i = 0; i < univ.town.monst[which_monst].x_width; i++) + for(short j = 0; j < univ.town.monst[which_monst].y_width; j++) { where_check.x = univ.town.monst[which_monst].cur_loc.x + i; where_check.y = univ.town.monst[which_monst].cur_loc.y + j; if((univ.town.is_crate(where_check.x,where_check.y)) || (univ.town.is_barrel(where_check.x,where_check.y)) ) - for(k = 0; k < univ.town.items.size(); k++) + for(short k = 0; k < univ.town.items.size(); k++) if(univ.town.items[k].variety != eItemType::NO_ITEM && univ.town.items[k].contained && (univ.town.items[k].item_loc == where_check)) univ.town.items[k].contained = univ.town.items[k].held = false; @@ -881,7 +880,7 @@ void monst_inflict_fields(short which_monst) { //mode; // 1 - town 2 - combat bool monst_check_special_terrain(location where_check,short mode,short which_monst) { ter_num_t ter = 0; - short r1,i,guts = 0; + short r1,guts = 0; bool can_enter = true,mage = false; location from_loc,to_loc; bool do_look = false; // If becomes true, terrain changed, so need to update what party sees @@ -980,7 +979,7 @@ bool monst_check_special_terrain(location where_check,short mode,short which_mon univ.town.set_crate(where_check.x,where_check.y,false); if(to_loc.x > 0) univ.town.set_crate(to_loc.x,to_loc.y, true); - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].item_loc == where_check && univ.town.items[i].contained && univ.town.items[i].held) univ.town.items[i].item_loc = to_loc; @@ -994,7 +993,7 @@ bool monst_check_special_terrain(location where_check,short mode,short which_mon univ.town.set_barrel(where_check.x,where_check.y,false); if(to_loc.x > 0) univ.town.set_barrel(to_loc.x,to_loc.y,true); - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].item_loc == where_check && univ.town.items[i].contained && univ.town.items[i].held) univ.town.items[i].item_loc = to_loc; @@ -1053,7 +1052,7 @@ bool monst_check_special_terrain(location where_check,short mode,short which_mon if(is_town()) update_explored(univ.party.town_loc); if(is_combat()) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) update_explored(univ.party[i].combat_pos); } @@ -1170,11 +1169,9 @@ bool summon_monster(mon_num_t which,location where,short duration,eAttitude give } void activate_monsters(short code,short /*attitude*/) { - short i; - if(code == 0) return; - for(i = 0; i < univ.town->creatures.size(); i++) + for(short i = 0; i < univ.town->creatures.size(); i++) if(univ.town->creatures[i].spec_enc_code == code) { cTownperson& monst = univ.town->creatures[i]; univ.town.monst.assign(i, monst, univ.scenario.scen_monsters[monst.number], univ.party.easy_mode, univ.difficulty_adjust()); @@ -1190,12 +1187,12 @@ void activate_monsters(short code,short /*attitude*/) { } short get_encumbrance(short pc_num) { - short store = 0,i,what_val; + short store = 0,what_val; what_val = univ.party[pc_num].free_weight(); if(what_val < 0) store += what_val / -10; - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) if(univ.party[pc_num].equip[i]) { what_val = univ.party[pc_num].items[i].awkward; if(univ.party[pc_num].items[i].ability == eItemAbil::ENCUMBERING) @@ -1210,10 +1207,8 @@ short get_encumbrance(short pc_num) { } mon_num_t get_summon_monster(short summon_class) { - short i,j; - - for(i = 0; i < 200; i++) { - j = get_ran(1,0,255); + for(short i = 0; i < 200; i++) { + short j = get_ran(1,0,255); if(univ.scenario.scen_monsters[j].summon_type == summon_class) { return j; } diff --git a/src/boe.newgraph.cpp b/src/boe.newgraph.cpp index b6f16be5..daa34b91 100644 --- a/src/boe.newgraph.cpp +++ b/src/boe.newgraph.cpp @@ -117,7 +117,6 @@ char last_light_mask[13][13]; void apply_unseen_mask() { rectangle base_rect = {9,9,53,45},to_rect,big_to = {13,13,337,265}; - short i,j; bool need_bother = false; if(!get_bool_pref("DrawTerrainFrills", true) || fog_lifted) @@ -128,15 +127,15 @@ void apply_unseen_mask() { if(!(is_out()) && (univ.town->lighting_type > 0)) return; - for(i = 0; i < 11; i++) - for(j = 0; j < 11; j++) + for(short i = 0; i < 11; i++) + for(short j = 0; j < 11; j++) if(unexplored_area[i + 1][j + 1] == 1) need_bother = true; if(!need_bother) return; - for(i = 0; i < 11; i++) - for(j = 0; j < 11; j++) + for(short i = 0; i < 11; i++) + for(short j = 0; j < 11; j++) if(unexplored_area[i + 1][j + 1] == 1) { to_rect = base_rect; @@ -150,7 +149,6 @@ void apply_light_mask(bool onWindow) { static Region dark_mask_region; rectangle temp = {0,0,108,84},paint_rect,base_rect = {0,0,36,28}; rectangle big_to = {13,13,337,265}; - short i,j; bool same_mask = true; if(!get_bool_pref("DrawTerrainFrills", true) > 0 || fog_lifted) return; @@ -166,16 +164,16 @@ void apply_light_mask(bool onWindow) { } // Process the light array - for(i = 1; i < 12; i++) - for(j = 1; j < 12; j++) + for(short i = 1; i < 12; i++) + for(short j = 1; j < 12; j++) if((light_area[i - 1][j - 1] >= 1) && (light_area[i + 1][j - 1] >= 1) && (light_area[i - 1][j] >= 1) && (light_area[i + 1][j] >= 1) && (light_area[i - 1][j + 1] >= 1) && (light_area[i + 1][j + 1] >= 1) && (light_area[i][j - 1] >= 1) && (light_area[i][j + 1] >= 1)) { light_area[i][j] = 2; } - for(i = 1; i < 12; i++) - for(j = 1; j < 12; j++) + for(short i = 1; i < 12; i++) + for(short j = 1; j < 12; j++) if((light_area[i - 1][j - 1] >= 2) && (light_area[i + 1][j - 1] >= 2) && (light_area[i - 1][j] >= 2) && (light_area[i + 1][j] >= 2) && (light_area[i - 1][j + 1] >= 2) && (light_area[i + 1][j + 1] >= 2) && @@ -183,8 +181,8 @@ void apply_light_mask(bool onWindow) { light_area[i][j] = 3; } - for(i = 0; i < 13; i++) - for(j = 0; j < 13; j++) + for(short i = 0; i < 13; i++) + for(short j = 0; j < 13; j++) if(last_light_mask[i][j] != light_area[i][j]) same_mask = false; @@ -193,19 +191,19 @@ void apply_light_mask(bool onWindow) { } std::cout << "Current light mask:\n"; - for(i = 0; i < 13; i++) { - for(j = 0; j < 13; j++) + for(short i = 0; i < 13; i++) { + for(short j = 0; j < 13; j++) std::cout << int(light_area[j][i]) << ' '; std::cout << '\n'; } dark_mask_region.clear(); dark_mask_region.addRect(big_to); - for(i = 0; i < 13; i++) - for(j = 0; j < 13; j++) + for(short i = 0; i < 13; i++) + for(short j = 0; j < 13; j++) last_light_mask[i][j] = light_area[i][j]; - for(i = 1; i < 12; i++) - for(j = 1; j < 12; j++) { + for(short i = 1; i < 12; i++) + for(short j = 1; j < 12; j++) { if(light_area[i][j] == 2) { int xOffset = 13 + 28 * (i - 3), yOffset = 13 + 36 * (j - 3); Region oval_region; @@ -232,18 +230,16 @@ void apply_light_mask(bool onWindow) { } void start_missile_anim() { - short i; - if(boom_anim_active) return; boom_anim_active = true; - for(i = 0; i < 30; i++) { + for(short i = 0; i < 30; i++) { store_missiles[i].missile_type = -1; store_booms[i].boom_type = -1; } - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) univ.party[i].marked_damage = 0; - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) univ.town.monst[i].marked_damage = 0; have_missile = false; have_boom = false; @@ -254,17 +250,15 @@ void end_missile_anim() { } void add_missile(location dest,miss_num_t missile_type,short path_type,short x_adj,short y_adj) { - short i; - if(!boom_anim_active) return; if(!get_bool_pref("DrawTerrainFrills", true)) return; // lose redundant missiles - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) if((store_missiles[i].missile_type >= 0) && (dest == store_missiles[i].dest)) return; - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) if(store_missiles[i].missile_type < 0) { have_missile = true; store_missiles[i].dest = dest; @@ -298,10 +292,8 @@ void run_a_boom(location boom_where,short type,short x_adj,short y_adj,short snd } void mondo_boom(location l,short type,short snd) { - short i; - start_missile_anim(); - for(i = 0; i < 12; i++) + for(short i = 0; i < 12; i++) add_explosion(l,-1,1,type,0,0); do_explosion_anim(5,0,snd); @@ -309,21 +301,19 @@ void mondo_boom(location l,short type,short snd) { } void add_explosion(location dest,short val_to_place,short place_type,short boom_type,short x_adj,short y_adj) { - short i; - if(!get_bool_pref("DrawTerrainFrills", true)) return; if(!boom_anim_active) return; // lose redundant explosions - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) if((store_booms[i].boom_type >= 0) && (dest == store_booms[i].dest) && (place_type == 0)) { if(val_to_place > 0) store_booms[i].val_to_place = val_to_place; return; } - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) if(store_booms[i].boom_type < 0) { have_boom = true; store_booms[i].offset = (i == 0) ? 0 : -1 * get_ran(1,0,2); @@ -340,11 +330,11 @@ void add_explosion(location dest,short val_to_place,short place_type,short boom_ void do_missile_anim(short num_steps,location missile_origin,short sound_num) { // TODO: Get rid of temp_rect, at least rectangle temp_rect, missile_origin_base = {1,1,17,17},to_rect,from_rect; - short i,store_missile_dir; + short store_missile_dir; location start_point,finish_point[30]; location screen_ul; - short x1[30],x2[30],y1[30],y2[30],t; // for path paramaterization + short x1[30],x2[30],y1[30],y2[30]; // for path paramaterization rectangle missile_place_rect[30],missile_origin_rect[30]; location current_terrain_ul; @@ -353,11 +343,9 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) { return; } - for(i = 0; i < 30; i++) - if(store_missiles[i].missile_type >= 0) - i = 50; - if(i == 30) - return; + if(std::all_of(store_missiles, store_missiles + 30, [](const store_missile_type& m) { + return m.missile_type == 0; + })) return; // initialize general data // TODO: This is probably yet another relic of the Exile III demo @@ -378,14 +366,14 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) { // init missile paths - for(i = 0; i < 30; i++) { + for(short i = 0; i < 30; i++) { if((store_missiles[i].missile_type >= 0) && (missile_origin == store_missiles[i].dest)) store_missiles[i].missile_type = -1; } screen_ul.x = center.x - 4; screen_ul.y = center.y - 4; start_point.x = 13 + 14 + 28 * (short) (missile_origin.x - screen_ul.x); start_point.y = 13 + 18 + 36 * (short) (missile_origin.y - screen_ul.y); - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) if(store_missiles[i].missile_type >= 0) { finish_point[i].x = 1 + 13 + 14 + store_missiles[i].x_adj + 28 * (short) (store_missiles[i].dest.x - screen_ul.x); finish_point[i].y = 1 + 13 + 18 + store_missiles[i].y_adj + 36 * (short) (store_missiles[i].dest.y - screen_ul.y); @@ -413,9 +401,9 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) { sf::Texture& missiles_gworld = *ResMgr::get("missiles"); // Now, at last, launch missile - for(t = 0; t < num_steps; t++) { + for(short t = 0; t < num_steps; t++) { draw_terrain(); - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) if(store_missiles[i].missile_type >= 0) { // Where place? temp_rect = missile_origin_base; @@ -464,7 +452,7 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) { } // Exit gracefully, and clean up screen - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) store_missiles[i].missile_type = -1; to_rect = rectangle(terrain_screen_gworld); @@ -512,10 +500,10 @@ short get_missile_direction(location origin_point,location the_point) { void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) { rectangle active_area_rect,to_rect,from_rect; rectangle base_rect = {0,0,36,28},text_rect; - short i,temp_val,temp_val2; + short temp_val,temp_val2; location screen_ul; - short t,cur_boom_type = 0; + short cur_boom_type = 0; location current_terrain_ul; short boom_type_sound[6] = {5,10,53,53,53,75}; @@ -524,11 +512,9 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) { return; } - for(i = 0; i < 30; i++) - if(store_booms[i].boom_type >= 0) - i = 50; - if(i == 30) - return; + if(std::all_of(store_booms, store_booms + 30, [](const store_boom_type& b) { + return b.boom_type == 0; + })) return; // initialize general data if(overall_mode == MODE_STARTUP) { @@ -555,7 +541,7 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) { // init missile paths screen_ul.x = center.x - 4; screen_ul.y = center.y - 4; - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) if((store_booms[i].boom_type >= 0) && (special_draw < 2)) { cur_boom_type = store_booms[i].boom_type; explode_place_rect[i] = base_rect; @@ -582,11 +568,11 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) { sf::Texture& boom_gworld = *ResMgr::get("booms"); // Now, at last, do explosion - for(t = (special_draw == 2) ? 6 : 0; t < ((special_draw == 1) ? 6 : 11); t++) { // t goes up to 10 to make sure screen gets cleaned up + for(short t = (special_draw == 2) ? 6 : 0; t < ((special_draw == 1) ? 6 : 11); t++) { // t goes up to 10 to make sure screen gets cleaned up draw_terrain(); // Now put in explosions - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) if(store_booms[i].boom_type >= 0) { if((t + store_booms[i].offset >= 0) && (t + store_booms[i].offset <= 7)) { if(cur_boom_type >= 1000) { @@ -622,7 +608,7 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) { } // Exit gracefully, and clean up screen - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) if(special_draw != 1) store_booms[i].boom_type = -1; } @@ -658,7 +644,6 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) { rectangle title_rect = {15,48,42,260}; rectangle dest_rect,help_from = {85,36,101,54}; - short i; // In the 0..65535 range, these blue components were: 0, 32767, 14535, 26623, 59391 // The green components on the second line were 40959 and 24575 // TODO: The Windows version appears to use completely different colours? @@ -698,7 +683,7 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) { // Place store icon if(!pressed) { - i = active_shop.getFace(); + int i = active_shop.getFace(); rectangle from_rect = {0,0,32,32}; from_rect.offset(32 * (i % 10),32 * (i / 10)); rect_draw_some_item(*ResMgr::get("talkportraits"), from_rect, talk_gworld, face_rect); @@ -751,7 +736,7 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) { sf::Texture& invenbtn_gworld = *ResMgr::get("invenbtns"); // Place all the items - for(i = 0; i < 8; i++) { + for(short i = 0; i < 8; i++) { current_pos = i + shop_sbar->getPosition(); if(shop_array[current_pos] < 0) break; // theoretically, this shouldn't happen @@ -943,8 +928,6 @@ void place_talk_str(std::string str_to_place,std::string str_to_place2,short col rectangle dest_rect,help_from = {46,60,59,76}; sf::Text str_to_draw; - short i; - // In the 0..65535 range, these blue components were: 0, 32767, 14535, 26623, 59391 // The green components on the second line were 40959 and 24575 sf::Color c[8] = { @@ -998,7 +981,7 @@ void place_talk_str(std::string str_to_place,std::string str_to_place2,short col if(color == 0) style.colour = c[5]; else style.colour = c[6]; - for(i = 0; i < 9; i++) { + for(short i = 0; i < 9; i++) { if(!talk_end_forced || i == 6 || i == 5) { word_rect_t preset_word(preset_words[i], preset_rects[i]); preset_word.on = c[5]; diff --git a/src/boe.party.cpp b/src/boe.party.cpp index 912fcdb6..87292cac 100644 --- a/src/boe.party.cpp +++ b/src/boe.party.cpp @@ -109,12 +109,11 @@ short store_pc_graphic; // Then, it inits the party properly for starting the scenario based // on the loaded scenario static void init_party_scen_data() { - short i,j,k,l; bool stored_item = false; univ.party.age = 0; - for(i = 0; i < 310; i++) - for(j = 0; j < 50; j++) + for(short i = 0; i < 310; i++) + for(short j = 0; j < 50; j++) PSD[i][j] = 0; univ.party.light_level = 0; univ.party.outdoor_corner.x = univ.scenario.out_sec_start.x; @@ -125,7 +124,7 @@ static void init_party_scen_data() { univ.party.loc_in_sec.y = univ.scenario.out_start.y; univ.party.out_loc.x = univ.scenario.out_start.x; univ.party.out_loc.y = univ.scenario.out_start.y; - for(i = 0; i < univ.scenario.boats.size(); i++) { + for(short i = 0; i < univ.scenario.boats.size(); i++) { if(univ.scenario.boats[i].which_town >= 0 && univ.scenario.boats[i].loc.x >= 0) { if(!univ.party.boats[i].exists) { univ.party.boats[i] = univ.scenario.boats[i]; @@ -135,7 +134,7 @@ static void init_party_scen_data() { } } } - for(i = 0; i < univ.scenario.horses.size(); i++) { + for(short i = 0; i < univ.scenario.horses.size(); i++) { if(univ.scenario.horses[i].which_town >= 0 && univ.scenario.horses[i].loc.x >= 0) { if(!univ.party.horses[i].exists) { univ.party.horses[i] = univ.scenario.horses[i]; @@ -149,17 +148,17 @@ static void init_party_scen_data() { univ.party.in_horse = -1; for(auto& pop : univ.party.creature_save) pop.which_town = 200; - for(i = 0; i < 10; i++) + for(short i = 0; i < 10; i++) univ.party.out_c[i].exists = false; - for(i = 0; i < 5; i++) - for(j = 0; j < 10; j++) + for(short i = 0; i < 5; i++) + for(short j = 0; j < 10; j++) univ.party.magic_store_items[i][j].variety = eItemType::NO_ITEM; -// for(i = 0; i < 50; i++) +// for(short i = 0; i < 50; i++) // univ.party.journal_str[i] = -1; -// for(i = 0; i < 140; i++) -// for(j = 0; j < 2; j++) +// for(short i = 0; i < 140; i++) +// for(short j = 0; j < 2; j++) // univ.party.special_notes_str[i][j] = 0; -// for(i = 0; i < 120; i++) +// for(short i = 0; i < 120; i++) // univ.party.talk_save[i].personality = -1; // TODO: The journal at least should persist across scenarios; the special and talk notes, maybe, maybe not univ.party.special_notes.clear(); @@ -168,16 +167,16 @@ static void init_party_scen_data() { univ.party.direction = DIR_N; univ.party.at_which_save_slot = 0; univ.party.can_find_town.resize(univ.scenario.towns.size()); - for(i = 0; i < univ.scenario.towns.size(); i++) + for(short i = 0; i < univ.scenario.towns.size(); i++) univ.party.can_find_town[i] = !univ.scenario.towns[i]->is_hidden; - for(i = 0; i < 20; i++) + for(short i = 0; i < 20; i++) univ.party.key_times[i] = 30000; univ.party.party_event_timers.clear(); - for(i = 0; i < univ.scenario.special_items.size(); i++) { + for(short i = 0; i < univ.scenario.special_items.size(); i++) { if(univ.scenario.special_items[i].flags >= 10) univ.party.spec_items.insert(i); } - for(i = 0; i < univ.scenario.quests.size(); i++) { + for(short i = 0; i < univ.scenario.quests.size(); i++) { if(univ.scenario.quests[i].flags >= 10) { univ.party.quest_status[i] = eQuestStatus::STARTED; univ.party.quest_start[i] = 1; @@ -188,43 +187,38 @@ static void init_party_scen_data() { univ.party.m_killed.clear(); univ.party.m_killed.resize(univ.scenario.towns.size()); - for(i = 0; i < 200; i++) - for(j = 0; j < 8; j++) + for(short i = 0; i < 200; i++) + for(short j = 0; j < 8; j++) univ.party.item_taken[i][j] = 0; refresh_store_items(); - for(i = 0; i < 96; i++) - for(j = 0; j < 96; j++) + for(short i = 0; i < 96; i++) + for(short j = 0; j < 96; j++) univ.out.out_e[i][j] = 0; - for(i = 0; i < 3;i++) - for(j = 0; j < univ.party.stored_items[i].size(); j++) + for(short i = 0; i < 3;i++) + for(short j = 0; j < univ.party.stored_items[i].size(); j++) if(univ.party.stored_items[i][j].variety != eItemType::NO_ITEM) stored_item = true; if(stored_item) if(cChoiceDlog("keep-stored-items", {"yes", "no"}).show() == "yes") { std::vector saved_item_refs; - for(i = 0; i < 3;i++) - for(j = 0; j < univ.party.stored_items[i].size(); j++) + for(short i = 0; i < 3;i++) + for(short j = 0; j < univ.party.stored_items[i].size(); j++) if(univ.party.stored_items[i][j].variety != eItemType::NO_ITEM) saved_item_refs.push_back(&univ.party.stored_items[i][j]); short pc = 0; while(univ.party[pc].main_status != eMainStatus::ALIVE && pc < 6) pc++; show_get_items("Choose stored items to keep:", saved_item_refs, pc, true); } - for(i = 0; i < 3;i++) + for(short i = 0; i < 3;i++) univ.party.stored_items[i].clear(); - for(i = 0; i < 200; i++) - for(j = 0; j < 8; j++) - for(k = 0; k < 64; k++) - univ.town_maps[i][j][k] = 0; - - for(i = 0; i < 100; i++) - for(k = 0; k < 6; k++) - for(l = 0; l < 48; l++) + for(short i = 0; i < 100; i++) + for(short k = 0; k < 6; k++) + for(short l = 0; l < 48; l++) univ.out_maps[i][k][l] = 0; } @@ -233,7 +227,6 @@ static void init_party_scen_data() { // mode and load in the scen and init the party info // party record already contains scen name void put_party_in_scen(std::string scen_name) { - short i,j; bool item_took = false; // Drop debug mode @@ -241,15 +234,16 @@ void put_party_in_scen(std::string scen_name) { univ.ghost_mode = false; univ.node_step_through = false; - for(j = 0; j < 6; j++) { + for(short j = 0; j < 6; j++) { univ.party[j].status.clear(); if(isSplit(univ.party[j].main_status)) univ.party[j].main_status -= eMainStatus::SPLIT; univ.party[j].cur_health = univ.party[j].max_health; univ.party[j].cur_sp = univ.party[j].max_sp; } - for(j = 0; j < 6; j++) - for(i = 23; i >= 0; i--) { + // TODO: The above probably belongs in init_party_scen_data + for(short j = 0; j < 6; j++) + for(short i = 23; i >= 0; i--) { cItem& thisItem = univ.party[j].items[i]; thisItem.special_class = 0; if(thisItem.ability == eItemAbil::CALL_SPECIAL) { @@ -313,13 +307,13 @@ void put_party_in_scen(std::string scen_name) { adjust_monst_menu(); // Throw up intro dialog - for(j = 0; j < univ.scenario.intro_strs.size(); j++) + for(short j = 0; j < univ.scenario.intro_strs.size(); j++) if(!univ.scenario.intro_strs[j].empty()) { std::array buttons = {0,-1,-1}; custom_choice_dialog(univ.scenario.intro_strs, univ.scenario.intro_mess_pic, PIC_SCEN, buttons); j = 6; } - short k; + short i,j,k; run_special(eSpecCtx::STARTUP, 0, univ.scenario.init_spec, loc(0,0), &i, &j, &k); give_help(1,2); @@ -369,14 +363,13 @@ bool take_sp(short pc_num,short amt) { } void increase_light(short amt) { - short i; location where; univ.party.light_level += amt; if(univ.party.light_level < 0) univ.party.light_level = 0; if(is_combat()) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { update_explored(univ.party[i].combat_pos); } @@ -389,9 +382,7 @@ void increase_light(short amt) { } void award_party_xp(short amt) { - short i; - - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) award_xp(i,amt); } @@ -526,13 +517,13 @@ short check_party_stat(eSkill which_stat, short mode) { } bool poison_weapon(short pc_num, short how_much,bool safe) { - short i,weap = 24,p_level,r1; + short weap = 24,p_level,r1; short p_chance[21] = { 40,72,81,85,88,89,90, 91,92,93,94,94,95,95,96,97,98,100,100,100,100}; // TODO: This doesn't allow you to choose between poisoning a melee weapon and poisoning arrows, except by temporarily dequipping one - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) if((univ.party[pc_num].equip[i]) && (is_poisonable_weap(pc_num,i))) { weap = i; i = 30; @@ -618,7 +609,7 @@ bool repeat_cast_ok(eSkill type) { what_spell = univ.party[who_would_cast].last_cast[type]; else what_spell = type == eSkill::MAGE_SPELLS ? store_mage : store_priest; - if(!pc_can_cast_spell(who_would_cast,what_spell)) { + if(!pc_can_cast_spell(univ.party[who_would_cast],what_spell)) { add_string_to_buf("Repeat cast: Can't cast."); return false; } @@ -644,7 +635,6 @@ bool repeat_cast_ok(eSkill type) { //which; // 100 + x : priest spell x void give_party_spell(short which) { - short i; bool sound_done = false; if((which < 0) || (which > 161) || ((which > 61) && (which < 100))) { @@ -654,7 +644,7 @@ void give_party_spell(short which) { // TODO: This seems like the wrong sounds // TODO: The order of checking seems wrong here; why check for alive after checking for the spell? if(which < 100) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(!univ.party[i].mage_spells[which]) { univ.party[i].mage_spells[which] = true; if(univ.party[i].main_status == eMainStatus::ALIVE) @@ -666,7 +656,7 @@ void give_party_spell(short which) { }; } if(which >= 100) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(!univ.party[i].priest_spells[which - 100]) { univ.party[i].priest_spells[which - 100] = true; if(univ.party[i].main_status == eMainStatus::ALIVE) @@ -680,7 +670,7 @@ void give_party_spell(short which) { } void do_mage_spell(short pc_num,eSpell spell_num,bool freebie) { - short i,j,item,target,r1,adj,store; + short item,target,r1,adj,store; location where; if(univ.party[pc_num].traits[eTrait::PACIFIST] && !(*spell_num).peaceful) { @@ -713,8 +703,8 @@ void do_mage_spell(short pc_num,eSpell spell_num,bool freebie) { if(!freebie) univ.party[pc_num].cur_sp -= (*spell_num).cost; ASB("All of your items are identified."); - for(i = 0; i < 6; i++) - for(j = 0; j < 24; j++) + for(short i = 0; i < 6; i++) + for(short j = 0; j < 24; j++) univ.party[i].items[j].ident = true; break; @@ -739,25 +729,23 @@ void do_mage_spell(short pc_num,eSpell spell_num,bool freebie) { break; case eSpell::SUMMON_WEAK: store = level / 5 + adj / 3 + get_ran(1,0,2); - j = minmax(1,7,store); r1 = get_summon_monster(1); //// if(r1 < 0) break; if(!freebie) univ.party[pc_num].cur_sp -= (*spell_num).cost; store = get_ran(4,1,4) + adj; - for(i = 0; i < j; i++) + for(short i = 0; i < minmax(1,7,store); i++) if(!summon_monster(r1,where,store,eAttitude::FRIENDLY,true)) add_string_to_buf(" Summon failed."); break; case eSpell::SUMMON: store = level / 7 + adj / 3 + get_ran(1,0,1); - j = minmax(1,6,store); r1 = get_summon_monster(2); //// if(r1 < 0) break; if(!freebie) univ.party[pc_num].cur_sp -= (*spell_num).cost; store = get_ran(5,1,4) + adj; - for(i = 0; i < j; i++) + for(short i = 0; i < minmax(1,6,store); i++) if(!summon_monster(r1,where,store,eAttitude::FRIENDLY,true)) add_string_to_buf(" Summon failed."); break; @@ -770,13 +758,12 @@ void do_mage_spell(short pc_num,eSpell spell_num,bool freebie) { break; case eSpell::SUMMON_MAJOR: store = level / 10 + adj / 3 + get_ran(1,0,1); - j = minmax(1,5,store); r1 = get_summon_monster(3); //// if(r1 < 0) break; if(!freebie) univ.party[pc_num].cur_sp -= (*spell_num).cost; store = get_ran(7,1,4) + adj; - for(i = 0; i < j; i++) + for(short i = 0; i < minmax(1,5,store); i++) if(!summon_monster(r1,where,store,eAttitude::FRIENDLY,true)) add_string_to_buf(" Summon failed."); break; @@ -825,8 +812,8 @@ void do_mage_spell(short pc_num,eSpell spell_num,bool freebie) { univ.party[pc_num].cur_sp -= (*spell_num).cost; add_string_to_buf(" As the sapphire dissolves, you have a vision.", 2); } - for(i = 0; i < 64; i++) - for(j = 0; j < 64; j++) + for(short i = 0; i < 64; i++) + for(short j = 0; j < 64; j++) make_explored(i,j); clear_map(); } @@ -872,7 +859,7 @@ void do_mage_spell(short pc_num,eSpell spell_num,bool freebie) { univ.party[pc_num].cur_sp -= (*spell_num).cost; if(spell_num == eSpell::PROTECTION && target < 6) { univ.party[target].status[eStatus::INVULNERABLE] += 2 + adj + get_ran(2,1,2); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { univ.party[i].status[eStatus::MAGIC_RESISTANCE] += 4 + level / 3 + adj; } @@ -1607,36 +1594,36 @@ void dispel_fields(short i,short j,short mode) { break_force_cage(loc(i,j)); } -bool pc_can_cast_spell(short pc_num,eSkill type) { - if(type == eSkill::MAGE_SPELLS && pc_can_cast_spell(pc_num, eSpell::LIGHT)) +bool pc_can_cast_spell(const cPlayer& pc,eSkill type) { + if(type == eSkill::MAGE_SPELLS && pc_can_cast_spell(pc, eSpell::LIGHT)) return true; - if(type == eSkill::PRIEST_SPELLS && pc_can_cast_spell(pc_num, eSpell::HEAL_MINOR)) + if(type == eSkill::PRIEST_SPELLS && pc_can_cast_spell(pc, eSpell::HEAL_MINOR)) return true; // If they can't cast the most basic level 1 spell, let's just make sure they can't cast any spells. // Find a spell they definitely know, and see if they can cast that. - if(type == eSkill::MAGE_SPELLS && univ.party[pc_num].mage_spells.any()) { + if(type == eSkill::MAGE_SPELLS && pc.mage_spells.any()) { for(int i = 0; i < 62; i++) - if(univ.party[pc_num].mage_spells[i]) - return pc_can_cast_spell(pc_num, eSpell(i)); + if(pc.mage_spells[i]) + return pc_can_cast_spell(pc, eSpell(i)); } - if(type == eSkill::PRIEST_SPELLS && univ.party[pc_num].priest_spells.any()) { + if(type == eSkill::PRIEST_SPELLS && pc.priest_spells.any()) { for(int i = 0; i < 62; i++) - if(univ.party[pc_num].priest_spells[i]) - return pc_can_cast_spell(pc_num, eSpell(i + 100)); + if(pc.priest_spells[i]) + return pc_can_cast_spell(pc, eSpell(i + 100)); } // If we get this far, either they don't know any spells (very unlikely) or they can't cast any of the spells they know. return false; } -bool pc_can_cast_spell(short pc_num,eSpell spell_num) { +bool pc_can_cast_spell(const cPlayer& pc,eSpell spell_num) { short level,store_w_cast; eSkill type = (*spell_num).type; level = (*spell_num).level; - int effective_skill = univ.party[pc_num].skill(type); - if(univ.party[pc_num].status[eStatus::DUMB] < 0) - effective_skill -= univ.party[pc_num].status[eStatus::DUMB]; + int effective_skill = pc.skill(type); + if(pc.status[eStatus::DUMB] < 0) + effective_skill -= pc.status[eStatus::DUMB]; if(overall_mode >= MODE_TALKING) return false; // From Windows version. It does kinda make sense, though this function shouldn't even be called in these modes. @@ -1644,20 +1631,20 @@ bool pc_can_cast_spell(short pc_num,eSpell spell_num) { return false; if(effective_skill < level) return false; - if(univ.party[pc_num].main_status != eMainStatus::ALIVE) + if(pc.main_status != eMainStatus::ALIVE) return false; - if(univ.party[pc_num].cur_sp < (*spell_num).cost) + if(pc.cur_sp < (*spell_num).cost) return false; // TODO: Maybe get rid of the casts here? - if(type == eSkill::MAGE_SPELLS && !univ.party[pc_num].mage_spells[int(spell_num)]) + if(type == eSkill::MAGE_SPELLS && !pc.mage_spells[int(spell_num)]) return false; - if(type == eSkill::PRIEST_SPELLS && !univ.party[pc_num].priest_spells[int(spell_num) - 100]) + if(type == eSkill::PRIEST_SPELLS && !pc.priest_spells[int(spell_num) - 100]) return false; - if(univ.party[pc_num].status[eStatus::DUMB] >= 8 - level) + if(pc.status[eStatus::DUMB] >= 8 - level) return false; - if(univ.party[pc_num].status[eStatus::PARALYZED] != 0) + if(pc.status[eStatus::PARALYZED] != 0) return false; - if(univ.party[pc_num].status[eStatus::ASLEEP] > 0) + if(pc.status[eStatus::ASLEEP] > 0) return false; store_w_cast = (*spell_num).when_cast; @@ -1673,9 +1660,7 @@ bool pc_can_cast_spell(short pc_num,eSpell spell_num) { // MARK: Begin spellcasting dialog static void draw_caster_buttons(cDialog& me, const eSkill store_situation) { - short i; - - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { std::string id = "caster" + boost::lexical_cast(i + 1); if(!can_choose_caster) { if(i == pc_casting) { @@ -1686,7 +1671,7 @@ static void draw_caster_buttons(cDialog& me, const eSkill store_situation) { } } else { - if(pc_can_cast_spell(i,store_situation)) { + if(pc_can_cast_spell(univ.party[i],store_situation)) { me[id].show(); } else { @@ -1767,9 +1752,7 @@ static void put_target_status_graphics(cDialog& me, short for_pc) { } static void draw_spell_pc_info(cDialog& me) { - short i; - - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { std::string n = boost::lexical_cast(i + 1); if(univ.party[i].main_status != eMainStatus::ABSENT) { me["pc" + n].setText(univ.party[i].name); @@ -1785,10 +1768,7 @@ static void draw_spell_pc_info(cDialog& me) { static void put_pc_caster_buttons(cDialog& me) { - - short i; - - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { std::string n = boost::lexical_cast(i + 1); if(me["caster" + n].isVisible()) { if(i == pc_casting) @@ -1815,9 +1795,9 @@ static void put_pc_target_buttons(cDialog& me, short& store_last_target_darkened // TODO: This stuff may be better handled by using an LED group with a custom focus handler static void put_spell_led_buttons(cDialog& me, const eSkill store_situation,const short store_spell) { - short i,spell_for_this_button; + short spell_for_this_button; - for(i = 0; i < 38; i++) { + for(short i = 0; i < 38; i++) { spell_for_this_button = (on_which_spell_page == 0) ? i : spell_index[i]; std::string id = "spell" + boost::lexical_cast(i + 1); cLed& led = dynamic_cast(me[id]); @@ -1827,7 +1807,7 @@ static void put_spell_led_buttons(cDialog& me, const eSkill store_situation,cons if(store_spell == spell_for_this_button) { led.setState(led_green); } - else if(pc_can_cast_spell(pc_casting,spell)) { + else if(pc_can_cast_spell(univ.party[pc_casting],spell)) { led.setState(led_red); } else { @@ -1838,14 +1818,12 @@ static void put_spell_led_buttons(cDialog& me, const eSkill store_situation,cons } static void put_spell_list(cDialog& me, const eSkill store_situation) { - short i; - if(on_which_spell_page == 0) { me["col1"].setText("Level 1:"); me["col2"].setText("Level 2:"); me["col3"].setText("Level 3:"); me["col4"].setText("Level 4:"); - for(i = 0; i < 38; i++) { + for(short i = 0; i < 38; i++) { std::ostringstream name; std::string id = "spell" + boost::lexical_cast(i + 1); name << get_str("magic-names", i + (store_situation == eSkill::MAGE_SPELLS ? 1 : 101)); @@ -1864,7 +1842,7 @@ static void put_spell_list(cDialog& me, const eSkill store_situation) { me["col2"].setText("Level 6:"); me["col3"].setText("Level 7:"); me["col4"].setText(""); - for(i = 0; i < 38; i++) { + for(short i = 0; i < 38; i++) { std::ostringstream name; std::string id = "spell" + boost::lexical_cast(i + 1); if(spell_index[i] < 90) { @@ -1886,7 +1864,7 @@ static bool pick_spell_caster(cDialog& me, std::string id, const eSkill store_si // TODO: This visibility check is probably not needed; wouldn't the dialog framework only trigger on visible elements? if(me[id].isVisible()) { pc_casting = item_hit; - if(!pc_can_cast_spell(pc_casting,cSpell::fromNum(store_situation,store_spell))) { + if(!pc_can_cast_spell(univ.party[pc_casting],cSpell::fromNum(store_situation,store_spell))) { if(store_situation == eSkill::MAGE_SPELLS) store_spell = 70; else store_spell = 70; @@ -2032,7 +2010,6 @@ eSpell pick_spell(short pc_num,eSkill type) { // 70 - no spell OW spell num eSpell store_spell = type == eSkill::MAGE_SPELLS ? store_mage : store_priest; short former_target = store_spell_target; short dark = 6; - can_choose_caster = (pc_num < 6) ? false : true; pc_casting = type == eSkill::MAGE_SPELLS ? store_last_cast_mage : store_last_cast_priest; if(pc_casting == 6) @@ -2045,17 +2022,16 @@ eSpell pick_spell(short pc_num,eSkill type) { // 70 - no spell OW spell num if(pc_num == 6) { // See if can keep same caster can_choose_caster = true; - if(!pc_can_cast_spell(pc_casting,type)) { - int i; - for(i = 0; i < 6; i++) - if(pc_can_cast_spell(i,type)) { - pc_casting = i; - i = 500; - } - if(i == 6) { + if(!pc_can_cast_spell(univ.party[pc_casting],type)) { + using namespace std::placeholders; + auto iter = std::find_if(univ.party.begin(), univ.party.end(), [type](const cPlayer& who) { + return pc_can_cast_spell(who, type); + }); + if(iter == univ.party.end()) { add_string_to_buf("Cast: Nobody can."); return eSpell::NONE; } + pc_casting = iter - univ.party.begin(); } } else { @@ -2084,7 +2060,7 @@ eSpell pick_spell(short pc_num,eSkill type) { // 70 - no spell OW spell num } // Keep the stored spell, if it's still castable - if(!pc_can_cast_spell(pc_casting,store_spell)) { + if(!pc_can_cast_spell(univ.party[pc_casting],store_spell)) { if(type == eSkill::MAGE_SPELLS) { store_spell = eSpell::LIGHT; } @@ -2127,7 +2103,7 @@ eSpell pick_spell(short pc_num,eSkill type) { // 70 - no spell OW spell num cLed& led = dynamic_cast(castSpell[id]); led.attachKey(key); castSpell.addLabelFor(id, {static_cast(i > 25 ? toupper(key.c) : key.c)}, LABEL_LEFT, 8, true); - led.setState((pc_can_cast_spell(pc_casting,cSpell::fromNum(type,on_which_spell_page == 0 ? i : spell_index[i]))) + led.setState((pc_can_cast_spell(univ.party[pc_casting],cSpell::fromNum(type,on_which_spell_page == 0 ? i : spell_index[i]))) ? led_red : led_green); led.attachClickHandler(std::bind(pick_spell_select_led, _1, _2, _3, type, std::ref(dark), std::ref(former_spell))); } @@ -2258,7 +2234,7 @@ static bool alch_choice_event_filter(cDialog& me, std::string item_hit, eKeyMod) eAlchemy alch_choice(short pc_num) { short difficulty[20] = {1,1,1,3,3, 4,5,5,7,9, 9,10,12,12,9, 14,19,10,16,20}; - short i,store_alchemy_pc; + short store_alchemy_pc; make_cursor_sword(); @@ -2266,7 +2242,7 @@ eAlchemy alch_choice(short pc_num) { cDialog chooseAlchemy("pick-potion"); chooseAlchemy.attachClickHandlers(alch_choice_event_filter, {"cancel", "help"}); - for(i = 0; i < 20; i++) { + for(short i = 0; i < 20; i++) { std::string n = boost::lexical_cast(i + 1); chooseAlchemy["label" + n].setText(get_str("magic-names", i + 200)); chooseAlchemy["potion" + n].attachClickHandler(alch_choice_event_filter); @@ -2371,27 +2347,24 @@ bool flying() { } void hit_party(short how_much,eDamageType damage_type,short snd_type) { - short i; bool dummy; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) dummy = damage_pc(univ.party[i],how_much,damage_type,eRace::UNKNOWN,snd_type); put_pc_screen(); } void slay_party(eMainStatus mode) { - short i; - boom_anim_active = false; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) univ.party[i].main_status = mode; put_pc_screen(); } bool damage_pc(cPlayer& which_pc,short how_much,eDamageType damage_type,eRace type_of_attacker, short sound_type,bool do_print) { - short i, r1,level; + short r1,level; if(which_pc.main_status != eMainStatus::ALIVE) return false; @@ -2411,7 +2384,7 @@ bool damage_pc(cPlayer& which_pc,short how_much,eDamageType damage_type,eRace ty // armor if(damage_type == eDamageType::WEAPON || damage_type == eDamageType::UNDEAD || damage_type == eDamageType::DEMON) { how_much -= minmax(-5,5,which_pc.status[eStatus::BLESS_CURSE]); - for(i = 0; i < 24; i++) { + for(short i = 0; i < 24; i++) { if((which_pc.items[i].variety != eItemType::NO_ITEM) && (which_pc.equip[i])) { if(isArmourType(which_pc.items[i].variety)) { r1 = get_ran(1,1,which_pc.items[i].item_level); @@ -2583,7 +2556,7 @@ void petrify_pc(cPlayer& which_pc,int strength) { } void kill_pc(cPlayer& which_pc,eMainStatus type) { - short i = 24; + short i_weap = 24; bool dummy,no_save = false; location item_loc; @@ -2593,7 +2566,7 @@ void kill_pc(cPlayer& which_pc,eMainStatus type) { } if(type != eMainStatus::STONE) - i = which_pc.has_abil_equip(eItemAbil::LIFE_SAVING); + i_weap = which_pc.has_abil_equip(eItemAbil::LIFE_SAVING); int luck = which_pc.skill(eSkill::LUCK); if(!no_save && type != eMainStatus::ABSENT && luck > 0 && @@ -2601,11 +2574,11 @@ void kill_pc(cPlayer& which_pc,eMainStatus type) { add_string_to_buf(" But you luck out!"); which_pc.cur_health = 0; } - else if(i == 24 || type == eMainStatus::ABSENT) { + else if(i_weap == 24 || type == eMainStatus::ABSENT) { if(combat_active_pc < 6 && &which_pc == &univ.party[combat_active_pc]) combat_active_pc = 6; - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) which_pc.equip[i] = false; item_loc = (overall_mode >= MODE_COMBAT) ? which_pc.combat_pos : univ.party.town_loc; @@ -2636,7 +2609,7 @@ void kill_pc(cPlayer& which_pc,eMainStatus type) { } if(overall_mode != MODE_OUTDOORS) - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) if(which_pc.items[i].variety != eItemType::NO_ITEM) { dummy = place_item(which_pc.items[i],item_loc); which_pc.items[i].variety = eItemType::NO_ITEM; @@ -2648,7 +2621,7 @@ void kill_pc(cPlayer& which_pc,eMainStatus type) { } else { add_string_to_buf(" Life saved!"); - which_pc.take_item(i); + which_pc.take_item(i_weap); which_pc.heal(200); } if(univ.party[current_pc].main_status != eMainStatus::ALIVE) @@ -2658,14 +2631,12 @@ void kill_pc(cPlayer& which_pc,eMainStatus type) { } void set_pc_moves() { - short i,r; - - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status != eMainStatus::ALIVE) univ.party[i].ap = 0; else { univ.party[i].ap = univ.party[i].traits[eTrait::SLUGGISH] ? 3 : 4; - r = get_encumbrance(i); + short r = get_encumbrance(i); univ.party[i].ap = minmax(1,8,univ.party[i].ap - (r / 3)); if(int speed = univ.party[i].get_prot_level(eItemAbil::SPEED)) @@ -2697,16 +2668,16 @@ void take_ap(short num) { } short trait_present(eTrait which_trait) { - short i,ret = 0; - for(i = 0; i < 6; i++) + short ret = 0; + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE && univ.party[i].traits[which_trait]) ret += 1; return ret; } short race_present(eRace which_race) { - short i,ret = 0; - for(i = 0; i < 6; i++) + short ret = 0; + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE && univ.party[i].race == which_race) ret += 1; return ret; diff --git a/src/boe.party.hpp b/src/boe.party.hpp index abca046e..b84a9b90 100644 --- a/src/boe.party.hpp +++ b/src/boe.party.hpp @@ -25,8 +25,8 @@ bool cast_spell_on_space(location where, eSpell spell); void crumble_wall(location where); void do_mindduel(short pc_num,cCreature *monst); void dispel_fields(short i,short j,short mode); -bool pc_can_cast_spell(short pc_num,eSpell spell_num); -bool pc_can_cast_spell(short pc_num,eSkill spell_num); +bool pc_can_cast_spell(const cPlayer& pc,eSpell spell_num); +bool pc_can_cast_spell(const cPlayer& pc,eSkill spell_num); eSpell pick_spell(short pc_num,eSkill type); void start_town_targeting(eSpell s_num,short who_c,bool freebie,eSpellPat pat = PAT_SINGLE); void do_alchemy(); diff --git a/src/boe.specials.cpp b/src/boe.specials.cpp index 8983298f..57b7d63f 100644 --- a/src/boe.specials.cpp +++ b/src/boe.specials.cpp @@ -120,7 +120,7 @@ bool handle_wandering_specials (short /*which*/,short mode) { // sets forced to true if definitely can enter bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc,bool *forced) { ter_num_t ter; - short r1,i,door_pc,pic_type = 0,ter_pic = 0; + short r1,door_pc,pic_type = 0,ter_pic = 0; eTerSpec ter_special; std::string choice; int ter_flag1,ter_flag2,ter_flag3; @@ -172,7 +172,7 @@ bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc, if(mode == eSpecCtx::OUT_MOVE) { out_where = global_to_local(where_check); - for(i = 0; i < univ.out->special_locs.size(); i++) + for(short i = 0; i < univ.out->special_locs.size(); i++) if(out_where == univ.out->special_locs[i]) { spec_num = univ.out->special_locs[i].spec; // call special @@ -203,7 +203,7 @@ bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc, } if((mode == eSpecCtx::TOWN_MOVE || (mode == eSpecCtx::COMBAT_MOVE && which_combat_type == 1)) && can_enter && univ.town.is_special(where_check.x,where_check.y)) { - for(i = 0; i < univ.town->special_locs.size(); i++) + for(short i = 0; i < univ.town->special_locs.size(); i++) if(where_check == univ.town->special_locs[i]) { spec_num = univ.town->special_locs[i].spec; bool runSpecial = false; @@ -242,7 +242,7 @@ bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc, if(univ.town.is_web(where_check.x,where_check.y) && univ.party[current_pc].race != eRace::BUG) { add_string_to_buf(" Webs!"); if(mode != eSpecCtx::COMBAT_MOVE) { - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { r1 = get_ran(1,2,3); univ.party[i].web(r1); } @@ -257,7 +257,7 @@ bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc, univ.town.set_crate(where_check.x,where_check.y,false); if(to_loc.x > 0) univ.town.set_crate(to_loc.x,to_loc.y,true); - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].item_loc == where_check && univ.town.items[i].contained && univ.town.items[i].held) univ.town.items[i].item_loc = to_loc; @@ -268,7 +268,7 @@ bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc, univ.town.set_barrel(where_check.x,where_check.y,false); if(to_loc.x > 0) univ.town.set_barrel(to_loc.x,to_loc.y,true); - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].item_loc == where_check && univ.town.items[i].contained && univ.town.items[i].held) univ.town.items[i].item_loc = to_loc; @@ -369,8 +369,7 @@ bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc, if(mode == eSpecCtx::OUT_MOVE && out_boat_there(where_check) < 30) break; //one_sound(17); - if(mode == eSpecCtx::COMBAT_MOVE) i = univ.get_target_i(which_pc); else i = 0; - for( ; i < 6; i++) + for(short i = mode == eSpecCtx::COMBAT_MOVE ? univ.get_target_i(which_pc) : 0 ; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { if(get_ran(1,1,100) <= ter_flag2) { switch((eStatus)ter_flag3){ @@ -555,7 +554,7 @@ void use_spec_item(short item) { void use_item(short pc,short item) { bool take_charge = true,inept_ok = false; - short level,i,j,item_use_code,str,r1; + short level,item_use_code,str,r1; short sp[3] = {}; // Dummy values to pass to run_special; not actually used std::string str1, str2; // Used by books eStatus status; @@ -662,7 +661,7 @@ void use_item(short pc,short item) { univ.party.apply_status(eStatus::POISONED_WEAPON,-str); else univ.party[pc].apply_status(eStatus::POISONED_WEAPON,-str); } else if(the_item.abil_group()) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) take_charge = take_charge || poison_weapon(i,str,true); } else take_charge = poison_weapon(pc,str,true); break; @@ -873,7 +872,7 @@ void use_item(short pc,short item) { univ.party[pc].sleep(eStatus::FORCECAGE, str, str / 2); break; case eItemUse::HELP_ALL: - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) process_force_cage(univ.party[i].get_loc(), i, str); break; case eItemUse::HARM_ALL: @@ -904,7 +903,7 @@ void use_item(short pc,short item) { break; case eItemUse::HARM_ALL: ASB(" You all feel terrible."); - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { drain_pc(i,str * 5); damage_pc(univ.party[i],20 * str,eDamageType::UNBLOCKABLE,eRace::HUMAN,0); univ.party[i].disease(2 * str); @@ -931,7 +930,7 @@ void use_item(short pc,short item) { break; case eItemUse::HARM_ALL: ASB(" You all feel forgetful."); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) drain_pc(i,str * 5); break; } @@ -950,12 +949,12 @@ void use_item(short pc,short item) { break; case eItemUse::HELP_ALL: ASB(" You all feel much smarter."); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) univ.party[i].skill_pts += str; break; case eItemUse::HARM_ALL: ASB(" You all feel forgetful."); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) univ.party[i].skill_pts = max(0,univ.party[i].skill_pts - str); break; } @@ -996,7 +995,7 @@ void use_item(short pc,short item) { break; case eItemUse::HARM_ALL: ASB(" You all feel drained."); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) univ.party[i].cur_sp = max(0,univ.party[i].cur_sp - str * 5); break; } @@ -1013,7 +1012,7 @@ void use_item(short pc,short item) { case eItemAbil::AFFECT_PARTY_STATUS: if(the_item.abil_harms()) { ePartyStatus status = ePartyStatus(the_item.abil_data[1]); - i = univ.party.status[status]; + int i = univ.party.status[status]; switch(status) { case ePartyStatus::STEALTH: ASB(" Your footsteps become louder."); str *= 5; break; case ePartyStatus::FIREWALK: ASB(" The chill recedes from your feet."); str *= 2; break; @@ -1141,9 +1140,9 @@ void use_item(short pc,short item) { add_string_to_buf(" Summon failed."); break; case eItemAbil::MASS_SUMMONING: - r1 = get_ran(str,1,4); - j = get_ran(1,3,5); - for(i = 0; i < j; i++) + r1 = get_ran(str,1,4); // TODO: This value was never used, so why is it here? + r1 = get_ran(1,3,5); + for(short i = 0; i < r1; i++) if(!summon_monster(univ.party[pc].items[item].abil_data[1],user_loc,r1,eAttitude::FRIENDLY,true)) add_string_to_buf(" Summon failed."); break; @@ -1153,15 +1152,15 @@ void use_item(short pc,short item) { break; case eItemAbil::MESSAGE: take_charge = false; - j = univ.party[pc].items[item].desc.find("|||"); - str1 = univ.party[pc].items[item].desc.substr(j + 3); - j = str1.find("|||"); - if(j != std::string::npos) { - str2 = str1.substr(j + 3); - str1 = str1.substr(0, j); + r1 = univ.party[pc].items[item].desc.find("|||"); + str1 = univ.party[pc].items[item].desc.substr(r1 + 3); + r1 = str1.find("|||"); + if(r1 != std::string::npos) { + str2 = str1.substr(r1 + 3); + str1 = str1.substr(0, r1); } - j = univ.party[pc].items[item].graphic_num; - cStrDlog(str1, str2, "Reading " + univ.party[pc].items[item].name, j, PIC_ITEM).show(); + r1 = univ.party[pc].items[item].graphic_num; + cStrDlog(str1, str2, "Reading " + univ.party[pc].items[item].name, r1, PIC_ITEM).show(); break; // Now for all the non-usable abilities. These are enumerated here so that the compiler can catch if we've missed one. case eItemAbil::ACCURACY: case eItemAbil::ANTIMAGIC_WEAPON: case eItemAbil::ASPTONGUE: case eItemAbil::BOOST_MAGIC: @@ -1198,7 +1197,6 @@ void use_item(short pc,short item) { // Returns true if an action is actually carried out. This can only be reached in town. bool use_space(location where) { ter_num_t ter; - short i; location from_loc,to_loc; ter = univ.town->terrain(where.x,where.y); @@ -1220,7 +1218,7 @@ bool use_space(location where) { add_string_to_buf(" You push the crate."); univ.town.set_crate(where.x,where.y,false); univ.town.set_crate(to_loc.x,to_loc.y,true); - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].item_loc == where && univ.town.items[i].contained && univ.town.items[i].held) univ.town.items[i].item_loc = to_loc; @@ -1234,7 +1232,7 @@ bool use_space(location where) { add_string_to_buf(" You push the barrel."); univ.town.set_barrel(where.x, where.y,false); univ.town.set_barrel(to_loc.x,to_loc.y,true); - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].item_loc == where && univ.town.items[i].contained && univ.town.items[i].held) univ.town.items[i].item_loc = to_loc; @@ -1266,6 +1264,7 @@ bool use_space(location where) { if(is_town() || (is_combat() && which_combat_type == 1)) spec_type = 2; else spec_type = 1; } + short i; // Dummy variable run_special(eSpecCtx::USE_SPACE,spec_type,univ.scenario.ter_types[ter].flag1,where,&i,&i,&i); return true; } @@ -1280,9 +1279,9 @@ bool use_space(location where) { bool adj_town_look(location where) { ter_num_t terrain; bool can_open = true,item_there = false,got_special = false; - short i = 0,s1 = 0, s2 = 0, s3 = 0; + short s1 = 0, s2 = 0, s3 = 0; - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM && (univ.town.items[i].contained) && (where == univ.town.items[i].item_loc)) item_there = true; @@ -1292,7 +1291,7 @@ bool adj_town_look(location where) { if(!adjacent(univ.party.town_loc,where)) add_string_to_buf(" Not close enough to search."); else { - for(i = 0; i < univ.town->special_locs.size(); i++) + for(short i = 0; i < univ.town->special_locs.size(); i++) if(where == univ.town->special_locs[i]) { if(get_blockage(univ.town->terrain(where.x,where.y)) > 0) { // tell party you find something, if looking at a space they can't step in @@ -1333,7 +1332,6 @@ void out_move_party(short x,short y) { // mode - 0=full teleport flash 1=no teleport flash 2=only fade flash 3=only arrival flash void teleport_party(short x,short y,short mode) { // TODO: Teleport sound? (Sound 10) - short i; location l; bool fadeIn = false, fadeOut = false; if(mode == 0 || mode == 2) fadeOut = true; @@ -1351,7 +1349,7 @@ void teleport_party(short x,short y,short mode) { if(fadeOut) { start_missile_anim(); - for(i = 0; i < 9; i++) + for(short i = 0; i < 9; i++) add_explosion(l,-1,1,1,0,0); do_explosion_anim(5,1); can_draw_pcs = false; @@ -1371,7 +1369,7 @@ void teleport_party(short x,short y,short mode) { if(fadeIn) { start_missile_anim(); - for(i = 0; i < 14; i++) + for(short i = 0; i < 14; i++) add_explosion(center,-1,1,1,0,0); do_explosion_anim(5,1); } @@ -1385,12 +1383,11 @@ void teleport_party(short x,short y,short mode) { void fade_party() { - short i; location l; l = univ.party.town_loc; start_missile_anim(); - for(i = 0; i < 14; i++) + for(short i = 0; i < 14; i++) add_explosion(l,-1,1,1,0,0); do_explosion_anim(5,1); univ.party.town_loc.x = 100; @@ -1667,7 +1664,6 @@ void kill_monst(cCreature& which_m,short who_killed,eMainStatus type) { // This is very fragile, and only hands a few cases. void push_things() { bool redraw = false; - short i,k; ter_num_t ter; location l; @@ -1676,7 +1672,7 @@ void push_things() { if(!univ.town.belt_present) return; - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0) { l = univ.town.monst[i].cur_loc; ter = univ.town->terrain(l.x,l.y); @@ -1693,7 +1689,7 @@ void push_things() { redraw = true; } } - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM) { l = univ.town.items[i].item_loc; ter = univ.town->terrain(l.x,l.y); @@ -1742,7 +1738,7 @@ void push_things() { ASB("You crash into the block."); hit_party(get_ran(1, 1, 6), eDamageType::WEAPON); } - for(k = 0; k < univ.town.items.size(); k++) + for(short k = 0; k < univ.town.items.size(); k++) if(univ.town.items[k].variety != eItemType::NO_ITEM && univ.town.items[k].held && (univ.town.items[k].item_loc == univ.party.town_loc)) univ.town.items[k].contained = univ.town.items[k].held = false; @@ -1750,7 +1746,7 @@ void push_things() { } } if(is_combat()) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { ter = univ.town->terrain(univ.party[i].combat_pos.x,univ.party[i].combat_pos.y); l = univ.party[i].combat_pos; @@ -1780,7 +1776,7 @@ void push_things() { ASB("You crash into the block."); damage_pc(univ.party[i],get_ran(1, 1, 6), eDamageType::WEAPON,eRace::UNKNOWN,0); } - for(k = 0; k < univ.town.items.size(); k++) + for(short k = 0; k < univ.town.items.size(); k++) if(univ.town.items[k].variety != eItemType::NO_ITEM && univ.town.items[k].held && (univ.town.items[k].item_loc == univ.party[i].combat_pos)) univ.town.items[k].contained = univ.town.items[k].held = false; @@ -1795,7 +1791,6 @@ void push_things() { } void special_increase_age(long length, bool queue) { - size_t i; short s1,s2,s3; bool redraw = false,stat_area = false; location trigger_loc; @@ -1851,11 +1846,11 @@ void special_increase_age(long length, bool queue) { // Angered job boards slowly forgive you if(univ.party.age % 30 == 0) - for(i = 0; i < univ.party.job_banks.size(); i++) + for(short i = 0; i < univ.party.job_banks.size(); i++) move_to_zero(univ.party.job_banks[i].anger); if(is_town() || (is_combat() && which_combat_type == 1)) { - for(i = 0; i < univ.town->timers.size(); i++) + for(short i = 0; i < univ.town->timers.size(); i++) if(univ.town->timers[i].time > 0) { short time = univ.town->timers[i].time; for(unsigned long j = age_before + (time == 1); j <= current_age; j++) @@ -1871,7 +1866,7 @@ void special_increase_age(long length, bool queue) { } } univ.party.age = current_age; - for(i = 0; i < univ.scenario.scenario_timers.size(); i++) + for(short i = 0; i < univ.scenario.scenario_timers.size(); i++) if(univ.scenario.scenario_timers[i].time > 0) { short time = univ.scenario.scenario_timers[i].time; for(unsigned long j = age_before + (time == 1); j <= current_age; j++) @@ -1887,7 +1882,7 @@ void special_increase_age(long length, bool queue) { } univ.party.age = current_age; auto party_timers = univ.party.party_event_timers; - for(i = 0; i < party_timers.size(); i++) { + for(short i = 0; i < party_timers.size(); i++) { if(party_timers[i].time <= length) { univ.party.age = age_before + party_timers[i].time; short which_type = party_timers[i].node_type; @@ -2250,7 +2245,7 @@ void general_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, *next_spec = spec.ex1b; break; case eSpecType::BUY_ITEMS_OF_TYPE: - for(i = 0; i < 144; i++) + for(short i = 0; i < 144; i++) if(univ.party.check_class(spec.ex1a,true)) store_val++; if(store_val == 0) { @@ -2268,7 +2263,7 @@ void general_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, case eSpecType::SET_SDF_ROW: if(spec.sd1 != minmax(0,299,spec.sd1)) showError("Stuff Done flag out of range."); - else for(i = 0; i < 50; i++) PSD[spec.sd1][i] = spec.ex1a; + else for(short i = 0; i < 50; i++) PSD[spec.sd1][i] = spec.ex1a; break; case eSpecType::COPY_SDF: if(!univ.party.sd_legit(spec.sd1,spec.sd2) || !univ.party.sd_legit(spec.ex1a,spec.ex1b)) @@ -2536,12 +2531,11 @@ void oneshot_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, short* next_spec,short* next_spec_type,short* a,short* b,short* redraw) { bool check_mess = true,set_sd = true; std::array strs; - short i,j; std::array buttons = {-1,-1,-1}; cSpecial spec; cItem store_i; location l; - std::string choice; + int dlg_res; spec = cur_node; *next_spec = cur_node.jumpto; @@ -2585,7 +2579,7 @@ void oneshot_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, check_mess = false; if(spec.m1 < 0) break; - for(i = 0; i < 3; i++) + for(short i = 0; i < 3; i++) get_strs(strs[i * 2],strs[i * 2 + 1],cur_spec_type, spec.m1 + i * 2,spec.m1 + i * 2 + 1); if(spec.m3 > 0) { buttons[0] = 1; @@ -2602,30 +2596,30 @@ void oneshot_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, showError("Dialog box ended up with no buttons."); break; } - i = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons); + dlg_res = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons); if(spec.m3 > 0) { - if(i == 1) { + if(dlg_res == 1) { if((spec.ex1a >= 0) || (spec.ex2a >= 0)) { set_sd = false; } } - if(i == 2) *next_spec = spec.ex1b; - if(i == 3) *next_spec = spec.ex2b; + if(dlg_res == 2) *next_spec = spec.ex1b; + if(dlg_res == 3) *next_spec = spec.ex2b; } else { - if(i == 1) *next_spec = spec.ex1b; - if(i == 2) *next_spec = spec.ex2b; + if(dlg_res == 1) *next_spec = spec.ex1b; + if(dlg_res == 2) *next_spec = spec.ex2b; } break; case eSpecType::ONCE_GIVE_ITEM_DIALOG: check_mess = false; if(spec.m1 < 0) break; - for(i = 0; i < 3; i++) + for(short i = 0; i < 3; i++) get_strs(strs[i * 2],strs[i * 2 + 1],cur_spec_type, spec.m1 + i * 2,spec.m1 + i * 2 + 1); buttons[0] = 20; buttons[1] = 19; - i = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons); - if(i == 1) {set_sd = false; *next_spec = -1;} + dlg_res = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons); + if(dlg_res == 1) {set_sd = false; *next_spec = -1;} else { store_i = get_stored_item(spec.ex1a); if((spec.ex1a >= 0) && (!univ.party.give_item(store_i,true))) { @@ -2664,23 +2658,23 @@ void oneshot_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, if((spec.m1 >= 0) || (spec.m2 >= 0)) { get_strs(strs[0],strs[1], cur_spec_type, spec.m1, spec.m2); buttons[0] = 3; buttons[1] = 2; - i = custom_choice_dialog(strs,spec.pic,ePicType(spec.pictype),buttons); + dlg_res = custom_choice_dialog(strs,spec.pic,ePicType(spec.pictype),buttons); // TODO: Make custom_choice_dialog return string? } - else i = cChoiceDlog("basic-trap",{"yes","no"}).show() == "no"; - if(i == 1) { + else dlg_res = cChoiceDlog("basic-trap",{"yes","no"}).show() == "no"; + if(dlg_res == 1) { set_sd = false; *next_spec = -1; *a = 1; } else { if(!is_combat()) { - j = char_select_pc(0,"Trap! Who will disarm?"); - if(j == 6){ + dlg_res = char_select_pc(0,"Trap! Who will disarm?"); + if(dlg_res == 6){ *a = 1; set_sd = false; } - } else j = current_pc; - bool disarmed = run_trap(j,eTrapType(spec.ex1a),spec.ex1b,spec.ex2a); + } else dlg_res = current_pc; + bool disarmed = run_trap(dlg_res,eTrapType(spec.ex1a),spec.ex1b,spec.ex2a); if(!disarmed && spec.ex1a == TRAP_CUSTOM) { if(spec.jumpto >= 0) queue_special(which_mode, cur_spec_type, spec.jumpto, loc(univ.party.get_ptr(10), univ.party.get_ptr(11))); @@ -2706,7 +2700,7 @@ void oneshot_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, short *next_spec,short* /*next_spec_type*/,short *a,short *b,short *redraw) { bool check_mess = true; - short i,r1; + short r1; iLiving* pc = current_pc_picked_in_spec_enc; short pc_num = univ.get_target_i(*current_pc_picked_in_spec_enc); std::string str; @@ -2722,7 +2716,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, // TODO: I think this is for compatibility with old scenarios? If so, remove it and just convert data on load. // (Actually, I think the only compatibility thing is that it's <= instead of ==) if(spec.ex2a <= 0) { - + int i; if(spec.ex1a == 2) current_pc_picked_in_spec_enc = &univ.party; else if(spec.ex1a == 1) { @@ -2774,7 +2768,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, if(pc == -1) pc = 1000 + spec.ex2c; can_pick = false; // Assume ID is invalid unless proven otherwise cPlayer* found = nullptr; - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(univ.party[i].unique_id == pc) { can_pick = true; found = &univ.party[i]; @@ -2811,7 +2805,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, else *next_spec = spec.ex1b; } else if(spec.ex2a == 1) { // Pick random PC (from *i) - + int i; if(spec.ex1a == 0) { bool can_pick = false; int tries = 0; @@ -2868,7 +2862,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, break; case eSpecType::AFFECT_XP: if(pc_num >= 100) break; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_num == 6 || pc_num == i) { if(spec.ex1a < 0) univ.party[i].experience = univ.party[i].level * univ.party[i].get_tnl(); @@ -2878,14 +2872,14 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, break; case eSpecType::AFFECT_SKILL_PTS: if(pc_num >= 100) break; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_num == 6 || pc_num == i) univ.party[i].skill_pts = minmax(0, 100, univ.party[i].skill_pts + spec.ex1a * ((spec.ex1b != 0) ? -1: 1)); break; case eSpecType::AFFECT_DEADNESS: if(pc_num < 100) { - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_num == 6 || pc_num == i) { if(spec.ex1b == 0) { if(spec.ex1a == 3 && is_combat() && which_combat_type == 0 && univ.party[i].main_status == eMainStatus::FLED) @@ -3019,7 +3013,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, break; case eStatus::POISONED_WEAPON: if(pc_num >= 100) break; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_num == 6 || pc_num == i) { if(spec.ex1b == 0) poison_weapon(i, spec.ex1a, true); @@ -3057,7 +3051,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, showError("Skill is out of range."); break; } - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if((pc_num == 6 || pc_num == i) && get_ran(1,1,100) < spec.pic) { eSkill skill = eSkill(spec.ex2a); int adj = spec.ex1a * (spec.ex1b != 0 ? -1: 1); @@ -3075,7 +3069,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, lvl += spec.ex1a; else lvl -= spec.ex1a; dynamic_cast(pc)->level = lvl; - } else for(i = 0; i < 6; i++) + } else for(short i = 0; i < 6; i++) if(pc_num == 6 || pc_num == i) { int cur = univ.party[i].get_level(); int lvl = cur; @@ -3108,17 +3102,18 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, showError("Invalid monster stat (0-7)"); break; } - i = spec.ex1a; + // Blah, let's hackily reuse pc_num... + pc_num = spec.ex1a; if(spec.ex1b > 0) - i = -i; + pc_num = -pc_num; switch(spec.ex2a) { - case 0: dynamic_cast(pc)->m_health += i; break; - case 1: dynamic_cast(pc)->max_mp += i; break; - case 2: dynamic_cast(pc)->armor += i; break; - case 3: dynamic_cast(pc)->skill += i; break; - case 4: dynamic_cast(pc)->speed += i; break; - case 5: dynamic_cast(pc)->mu += i; break; - case 6: dynamic_cast(pc)->cl += i; break; + case 0: dynamic_cast(pc)->m_health += pc_num; break; + case 1: dynamic_cast(pc)->max_mp += pc_num; break; + case 2: dynamic_cast(pc)->armor += pc_num; break; + case 3: dynamic_cast(pc)->skill += pc_num; break; + case 4: dynamic_cast(pc)->speed += pc_num; break; + case 5: dynamic_cast(pc)->mu += pc_num; break; + case 6: dynamic_cast(pc)->cl += pc_num; break; } break; case eSpecType::AFFECT_MAGE_SPELL: @@ -3127,7 +3122,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, showError("Mage spell is out of range (0 - 61). See docs."); break; } - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_num == 6 || pc_num == i) univ.party[i].mage_spells[spec.ex1a] = !spec.ex1b; break; @@ -3137,7 +3132,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, showError("Priest spell is out of range (0 - 61). See docs."); break; } - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_num == 6 || pc_num == i) univ.party[i].priest_spells[spec.ex1a] = !spec.ex1b; break; @@ -3189,14 +3184,14 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, showError("Trait is out of range (0 - 15)."); break; } - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_num == 6 || pc_num == i) univ.party[i].traits[eTrait(spec.ex1a)] = !spec.ex1b; break; case eSpecType::AFFECT_AP: if(!is_combat()) break; if(pc_num == 6) { - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(spec.ex1b) univ.party[i].ap += spec.ex1a; else univ.party[i].ap -= spec.ex1a; @@ -3218,7 +3213,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, else if(cCreature* monst = dynamic_cast(pc)) monst->m_name = str; else if(dynamic_cast(pc)) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) univ.party[i].name = str; break; case eSpecType::CREATE_NEW_PC: @@ -3302,7 +3297,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, else if(spec.ex2c == 1) equip_type = GIVE_EQUIP_TRY; else if(spec.ex2c >= 2) equip_type = GIVE_EQUIP_FORCE; bool success = true; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(pc_num == 6 || pc_num == i) success = success && univ.party[i].give_item(to_give, equip_type | GIVE_ALLOW_OVERLOAD); if(!success) @@ -3336,7 +3331,6 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, short *next_spec,short* /*next_spec_type*/,short *a,short *b,short *redraw) { bool check_mess = false; std::string str1, str2, str3; - short i,j,k; cSpecial spec; location l; @@ -3398,7 +3392,7 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, if(is_out()) break; l.x = spec.ex1a; l.y = spec.ex1b; - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].special_class == (unsigned)spec.ex2a && l == univ.town.items[i].item_loc) { *next_spec = spec.ex2b; @@ -3413,9 +3407,9 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, *next_spec = spec.ex1b; break; case eSpecType::IF_EQUIP_ITEM_CLASS: - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) - for(j = 0; j < 24; j++) + for(short j = 0; j < 24; j++) if(univ.party[i].items[j].variety != eItemType::NO_ITEM && univ.party[i].items[j].special_class == (unsigned)spec.ex1a && univ.party[i].equip[j]) { *next_spec = spec.ex1b; @@ -3435,48 +3429,48 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, if(is_out()) break; if(!isValidField(spec.m1, false)) { showError("Scenario tried to check for invalid field type (1...24)"); - break; - } - i = 0; - for(j = spec.ex1b; j < min(spec.ex2b, univ.town->max_dim()); j++) - for(k = spec.ex1a; k < min(spec.ex2a, univ.town->max_dim()); k++) { - switch(eFieldType(spec.m1)) { - // These values are not allowed - case SPECIAL_EXPLORED: case SPECIAL_SPOT: case SPECIAL_ROAD: - case FIELD_DISPEL: case FIELD_SMASH: - break; - // Walls - case WALL_FIRE: i += univ.town.is_fire_wall(i,j); break; - case WALL_FORCE: i += univ.town.is_force_wall(i,j); break; - case WALL_ICE: i += univ.town.is_ice_wall(i,j); break; - case WALL_BLADES: i += univ.town.is_blade_wall(i,j); break; - // Clouds - case CLOUD_STINK: i += univ.town.is_scloud(i,j); break; - case CLOUD_SLEEP: i += univ.town.is_sleep_cloud(i,j); break; - // Advanced - case FIELD_QUICKFIRE: i += univ.town.is_quickfire(i,j); break; - case FIELD_ANTIMAGIC: i += univ.town.is_antimagic(i,j); break; - case BARRIER_FIRE: i += univ.town.is_fire_barr(i,j); break; - case BARRIER_FORCE: i += univ.town.is_force_barr(i,j); break; - case BARRIER_CAGE: i += univ.town.is_force_cage(i,j); break; - // Objects - case FIELD_WEB: i += univ.town.is_web(i,j); break; - case OBJECT_BARREL: i += univ.town.is_barrel(i,j); break; - case OBJECT_CRATE: i += univ.town.is_crate(i,j); break; - case OBJECT_BLOCK: i += univ.town.is_block(i,j); break; - // Sfx - case SFX_SMALL_BLOOD: i += univ.town.is_sm_blood(i,j); break; - case SFX_MEDIUM_BLOOD: i += univ.town.is_med_blood(i,j); break; - case SFX_LARGE_BLOOD: i += univ.town.is_lg_blood(i,j); break; - case SFX_SMALL_SLIME: i += univ.town.is_sm_slime(i,j); break; - case SFX_LARGE_SLIME: i += univ.town.is_lg_slime(i,j); break; - case SFX_ASH: i += univ.town.is_ash(i,j); break; - case SFX_BONES: i += univ.town.is_bones(i,j); break; - case SFX_RUBBLE: i += univ.town.is_rubble(i,j); break; + } else { + int i = 0; + for(short j = spec.ex1b; j < min(spec.ex2b, univ.town->max_dim()); j++) + for(short k = spec.ex1a; k < min(spec.ex2a, univ.town->max_dim()); k++) { + switch(eFieldType(spec.m1)) { + // These values are not allowed + case SPECIAL_EXPLORED: case SPECIAL_SPOT: case SPECIAL_ROAD: + case FIELD_DISPEL: case FIELD_SMASH: + break; + // Walls + case WALL_FIRE: i += univ.town.is_fire_wall(i,j); break; + case WALL_FORCE: i += univ.town.is_force_wall(i,j); break; + case WALL_ICE: i += univ.town.is_ice_wall(i,j); break; + case WALL_BLADES: i += univ.town.is_blade_wall(i,j); break; + // Clouds + case CLOUD_STINK: i += univ.town.is_scloud(i,j); break; + case CLOUD_SLEEP: i += univ.town.is_sleep_cloud(i,j); break; + // Advanced + case FIELD_QUICKFIRE: i += univ.town.is_quickfire(i,j); break; + case FIELD_ANTIMAGIC: i += univ.town.is_antimagic(i,j); break; + case BARRIER_FIRE: i += univ.town.is_fire_barr(i,j); break; + case BARRIER_FORCE: i += univ.town.is_force_barr(i,j); break; + case BARRIER_CAGE: i += univ.town.is_force_cage(i,j); break; + // Objects + case FIELD_WEB: i += univ.town.is_web(i,j); break; + case OBJECT_BARREL: i += univ.town.is_barrel(i,j); break; + case OBJECT_CRATE: i += univ.town.is_crate(i,j); break; + case OBJECT_BLOCK: i += univ.town.is_block(i,j); break; + // Sfx + case SFX_SMALL_BLOOD: i += univ.town.is_sm_blood(i,j); break; + case SFX_MEDIUM_BLOOD: i += univ.town.is_med_blood(i,j); break; + case SFX_LARGE_BLOOD: i += univ.town.is_lg_blood(i,j); break; + case SFX_SMALL_SLIME: i += univ.town.is_sm_slime(i,j); break; + case SFX_LARGE_SLIME: i += univ.town.is_lg_slime(i,j); break; + case SFX_ASH: i += univ.town.is_ash(i,j); break; + case SFX_BONES: i += univ.town.is_bones(i,j); break; + case SFX_RUBBLE: i += univ.town.is_rubble(i,j); break; + } } - } - if(i >= spec.sd1 && i <= spec.sd2) - *next_spec = spec.m2; + if(i >= spec.sd1 && i <= spec.sd2) + *next_spec = spec.m2; + } break; case eSpecType::IF_PARTY_SIZE: if(spec.ex2a < 1) { @@ -3495,33 +3489,26 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, case eSpecType::IF_SPECIES: if(spec.ex1a < 0 || spec.ex1a > 21) { showError("Species out of range (0-21)"); - break; + } else { + int i = race_present(eRace(spec.ex1a)), j = minmax(1, party_size(true), spec.ex2a); + if(spec.ex2b == -2 && i <= j) *next_spec = spec.ex1b; + if(spec.ex2b == -1 && i < j) *next_spec = spec.ex1b; + if(spec.ex2b == 0 && i == j) *next_spec = spec.ex1b; + if(spec.ex2b == 1 && i > j) *next_spec = spec.ex1b; + if(spec.ex2b == 2 && i >= j) *next_spec = spec.ex1b; } - i = 0; - j = min(spec.ex2a,party_size(true)); - if(j < 1) - j = 1; - i = race_present(eRace(spec.ex1a)); - if(spec.ex2b == -2 && i <= j) *next_spec = spec.ex1b; - if(spec.ex2b == -1 && i < j) *next_spec = spec.ex1b; - if(spec.ex2b == 0 && i == j) *next_spec = spec.ex1b; - if(spec.ex2b == 1 && i > j) *next_spec = spec.ex1b; - if(spec.ex2b == 2 && i >= j) *next_spec = spec.ex1b; break; case eSpecType::IF_TRAIT: if(spec.ex1a < 0 || spec.ex1a > 15) { showError("Invalid trait (0...15)"); - break; + } else { + int i = trait_present(eTrait(spec.ex1a)), j = minmax(1, party_size(true), spec.ex2a); + if(spec.ex2b == -2 && i <= j) *next_spec = spec.ex1b; + if(spec.ex2b == -1 && i < j) *next_spec = spec.ex1b; + if(spec.ex2b == 0 && i == j) *next_spec = spec.ex1b; + if(spec.ex2b == 1 && i > j) *next_spec = spec.ex1b; + if(spec.ex2b == 2 && i >= j) *next_spec = spec.ex1b; } - j = min(spec.ex2a,party_size(true)); - if(j < 1) - j = 1; - i = trait_present((eTrait)spec.ex1a); - if(spec.ex2b == -2 && i <= j) *next_spec = spec.ex1b; - if(spec.ex2b == -1 && i < j) *next_spec = spec.ex1b; - if(spec.ex2b == 0 && i == j) *next_spec = spec.ex1b; - if(spec.ex2b == 1 && i > j) *next_spec = spec.ex1b; - if(spec.ex2b == 2 && i >= j) *next_spec = spec.ex1b; break; case eSpecType::IF_STATISTIC: if((spec.ex2a < 0 || spec.ex2a > 20) && (spec.ex2a < 100 || spec.ex2a > 104)) { @@ -3552,18 +3539,11 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, check_mess = false; get_strs(str1,str1,0,spec.m1,-1); str3 = get_text_response(str1); - j = 1; k = 1; spec.pic = minmax(0,50,spec.pic); get_strs(str1,str2,0,spec.ex1a,spec.ex2a); - for(i = 0; i < spec.pic;i++) { - if((spec.ex1a < 0) || (str3[i] != str1[i])) - j = 0; - if((spec.ex2a < 0) || (str3[i] != str2[i])) - k = 0; - } - if(j == 1) + if(spec.ex1a >= 0 && str3.compare(0, spec.pic, str1, 0, spec.pic) == 0) *next_spec = spec.ex1b; - else if(k == 1) + if(spec.ex2a >= 0 && str3.compare(0, spec.pic, str2, 0, spec.pic) == 0) *next_spec = spec.ex2b; break; /* This is a little complicated. @@ -3584,13 +3564,13 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, ex#c - Special to jump to if test # succeeds but the other test fails. jumpto - Special to jump to if both tests fail. */ - case eSpecType::IF_NUM_RESPONSE: + case eSpecType::IF_NUM_RESPONSE: { check_mess = false; if(spec.m2 > spec.m3) std::swap(spec.m2,spec.m3); get_strs(str1,str1,0,spec.m1,-1); - i = get_num_response(spec.m2,spec.m3,str1); + int i = get_num_response(spec.m2,spec.m3,str1); setsd(spec.sd1, spec.sd2, abs(i)); - j = 0; + int j = 0; spec.pic = minmax(0,2,spec.pic); switch(spec.pic) { // Comparison mode case 0: // Is in range? @@ -3622,6 +3602,7 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, if(j == 2) *next_spec = spec.ex2c; if(j == 3) *next_spec = spec.pictype; break; + } case eSpecType::IF_SDF_EQ: if(univ.party.sd_legit(spec.sd1,spec.sd2)) { if(PSD[spec.sd1][spec.sd2] == spec.ex1a) @@ -3629,9 +3610,8 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, } break; case eSpecType::IF_ALIVE: - i = 0; - if(spec.ex1a == -1) - i = current_pc_picked_in_spec_enc->is_alive(); + if(spec.ex1a == -1 && current_pc_picked_in_spec_enc->is_alive()) + *next_spec = spec.ex1b; else if(dynamic_cast(current_pc_picked_in_spec_enc)) { int pc = univ.get_target_i(*current_pc_picked_in_spec_enc); eMainStatus stat; @@ -3655,43 +3635,59 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, stat = eMainStatus::ABSENT; break; } - if(stat == eMainStatus::SPLIT) - i = univ.party.is_split(); - else for(j = 0; j < 6; j++) - if(pc == 6 || pc == i) - i += univ.party[j].main_status == stat; + bool pass = false; + if(stat == eMainStatus::SPLIT && univ.party.is_split()) + pass = true; + else if(pc < 6 && univ.party[pc].main_status == stat) + pass = true; + else { + int n = std::count_if(univ.party.begin(), univ.party.end(), [stat](const cPlayer& who) { + return who.main_status == stat; + }); + pass = n > 0; + } + if(pass) *next_spec = spec.ex1b; } - if(i > 0) *next_spec = spec.ex1b; break; case eSpecType::IF_MAGE_SPELL: - i = 0; if(cPlayer* who = dynamic_cast(current_pc_picked_in_spec_enc)) { int pc = univ.get_target_i(*who); if(spec.ex1a < 0 || spec.ex1a >= 62) break; - for(j = 0; j < 6; j++) - if(pc == 6 || pc == i) - i += univ.party[j].mage_spells[spec.ex1a]; + bool pass = false; + if(pc < 6 && univ.party[pc].mage_spells[spec.ex1a]) + pass = true; + else { + int n = std::count_if(univ.party.begin(), univ.party.end(), [&spec](const cPlayer& who) { + return who.mage_spells[spec.ex1a]; + }); + pass = n + 0; + } + if(pass) *next_spec = spec.ex1b; } else { // TODO: Implement for monsters // Currently they have a fixed spell list depending solely on caster level } - if(i > 0) *next_spec = spec.ex1b; break; case eSpecType::IF_PRIEST_SPELL: - i = 0; if(cPlayer* who = dynamic_cast(current_pc_picked_in_spec_enc)) { int pc = univ.get_target_i(*who); if(spec.ex1a < 0 || spec.ex1a >= 62) break; - for(j = 0; j < 6; j++) - if(pc == 6 || pc == i) - i += univ.party[j].priest_spells[spec.ex1a]; + bool pass = false; + if(pc < 6 && univ.party[pc].priest_spells[spec.ex1a]) + pass = true; + else { + int n = std::count_if(univ.party.begin(), univ.party.end(), [&spec](const cPlayer& who) { + return who.priest_spells[spec.ex1a]; + }); + pass = n + 0; + } + if(pass) *next_spec = spec.ex1b; } else { // TODO: Implement for monsters // Currently they have a fixed spell list depending solely on caster level } - if(i > 0) *next_spec = spec.ex1b; break; case eSpecType::IF_RECIPE: if(spec.ex1a < 0 || spec.ex1a >= 20) { @@ -3704,34 +3700,35 @@ void ifthen_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, case eSpecType::IF_STATUS: if(spec.ex1a < 0 || spec.ex1a > 14) { showError("Invalid status effect (0...14)"); - break; - } - if(dynamic_cast(current_pc_picked_in_spec_enc)) { - k = spec.ex2b == 2 ? std::numeric_limits::max() : 0; - j = 0; - for(i = 0; i < 6; i++, j++) - if(univ.party[i].main_status == eMainStatus::ALIVE) { - eStatus stat = eStatus(spec.ex1a); - if(spec.ex2b < 2) - k += univ.party[i].status[stat]; - else if(spec.ex2b == 3) - k = max(univ.party[i].status[stat], k); - else if(spec.ex2b == 2) - k = min(univ.party[i].status[stat], k); - } - if(spec.ex2b == 1 && j > 0) - k /= j; } else { - if(current_pc_picked_in_spec_enc->is_alive()) - k = current_pc_picked_in_spec_enc->status[eStatus(spec.ex1a)]; - else k = 0; + int k = 0; + if(dynamic_cast(current_pc_picked_in_spec_enc)) { + k = spec.ex2b == 2 ? std::numeric_limits::max() : 0; + int j = 0; + for(short i = 0; i < 6; i++, j++) + if(univ.party[i].main_status == eMainStatus::ALIVE) { + eStatus stat = eStatus(spec.ex1a); + if(spec.ex2b < 2) + k += univ.party[i].status[stat]; + else if(spec.ex2b == 3) + k = max(univ.party[i].status[stat], k); + else if(spec.ex2b == 2) + k = min(univ.party[i].status[stat], k); + } + if(spec.ex2b == 1 && j > 0) + k /= j; + } else { + if(current_pc_picked_in_spec_enc->is_alive()) + k = current_pc_picked_in_spec_enc->status[eStatus(spec.ex1a)]; + else k = 0; + } + int j = spec.ex2a; + if(spec.ex2c == -2 && k <= j) *next_spec = spec.ex1b; + if(spec.ex2c == -1 && k < j) *next_spec = spec.ex1b; + if(spec.ex2c == 0 && k == j) *next_spec = spec.ex1b; + if(spec.ex2c == 1 && k > j) *next_spec = spec.ex1b; + if(spec.ex2c == 2 && k >= j) *next_spec = spec.ex1b; } - j = spec.ex2a; - if(spec.ex2c == -2 && k <= j) *next_spec = spec.ex1b; - if(spec.ex2c == -1 && k < j) *next_spec = spec.ex1b; - if(spec.ex2c == 0 && k == j) *next_spec = spec.ex1b; - if(spec.ex2c == 1 && k > j) *next_spec = spec.ex1b; - if(spec.ex2c == 2 && k >= j) *next_spec = spec.ex1b; break; case eSpecType::IF_QUEST: if(spec.ex1a < 0 || spec.ex1a >= univ.scenario.quests.size()) { @@ -3799,7 +3796,7 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, }; bool check_mess = true; std::array strs; - short i,r1; + short r1; std::array buttons = {-1,-1,-1}; cSpecial spec; location l; @@ -3886,7 +3883,7 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, *redraw = 1; break; case eSpecType::TOWN_NUKE_MONSTS: - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0 && (univ.town.monst[i].number == spec.ex1a || spec.ex1a == 0 || (spec.ex1a == -1 && univ.town.monst[i].is_friendly()) || @@ -3991,11 +3988,11 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, *next_spec = -1; } else { - for(i = 0; i < 3; i++) + for(short i = 0; i < 3; i++) get_strs(strs[i * 2],strs[i * 2 + 1],cur_spec_type, spec.m1 + i * 2 ,spec.m1 + i * 2 + 1); buttons[0] = 9; buttons[1] = 35; - i = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons); - if(i == 1) {*next_spec = -1;} + if(custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons) == 1) + *next_spec = -1; else { int x = univ.party.get_ptr(10), y = univ.party.get_ptr(11); ter = coord_to_ter(x, y); @@ -4023,11 +4020,10 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, check_mess = false; } else { - for(i = 0; i < 3; i++) + for(short i = 0; i < 3; i++) get_strs(strs[i * 2],strs[i * 2 + 1], cur_spec_type,spec.m1 + i * 2, spec.m1 + i * 2 + 1); buttons[0] = 9; buttons[1] = 8; - i = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons); - if(i == 1) { + if(custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons) == 1) { *next_spec = -1; if(which_mode == eSpecCtx::OUT_MOVE || which_mode == eSpecCtx::TOWN_MOVE || which_mode == eSpecCtx::COMBAT_MOVE) *a = 1; @@ -4057,12 +4053,10 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, *next_spec = -1; } else { - for(i = 0; i < 3; i++) + for(short i = 0; i < 3; i++) get_strs(strs[i * 2],strs[i * 2 + 1],cur_spec_type, spec.m1 + i * 2, spec.m1 + i * 2 + 1); buttons[0] = 20; buttons[1] = 24; - if(spec.ex2b == 1) - i = 2; - else i = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons); + int i = spec.ex2b == 1 ? 2 : custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons); *a = 1; if(i == 1) { *next_spec = -1; @@ -4182,14 +4176,15 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, univ.town.monst[spec.ex1a].attitude = eAttitude(spec.ex1b); break; case eSpecType::TOWN_RUN_MISSILE: - if(which_mode == eSpecCtx::TALK) - break; - if(iLiving* targ = univ.target_there(loc(spec.ex2a, spec.ex2b), TARG_MONST)) { - cCreature* who = dynamic_cast(targ); - i = 14 * who->x_width - 1; - r1 = 18 * who->y_width - 1; - } else i = r1 = 0; - run_a_missile(l, loc(spec.ex2a, spec.ex2b), spec.pic, spec.ex1c, spec.ex2c, i, r1, 100); + if(which_mode != eSpecCtx::TALK) { + int i; + if(iLiving* targ = univ.target_there(loc(spec.ex2a, spec.ex2b), TARG_MONST)) { + cCreature* who = dynamic_cast(targ); + i = 14 * who->x_width - 1; + r1 = 18 * who->y_width - 1; + } else i = r1 = 0; + run_a_missile(l, loc(spec.ex2a, spec.ex2b), spec.pic, spec.ex1c, spec.ex2c, i, r1, 100); + } break; case eSpecType::TOWN_BOOM_SPACE: // TODO: This should work, but does it need a bit of extra logic? @@ -4199,22 +4194,22 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, break; case eSpecType::TOWN_MONST_ATTACK: // TODO: I'm not certain if this will work. - if(which_mode == eSpecCtx::TALK) - break; - i = combat_posing_monster; - if(l.y >= 0) { - iLiving* who = univ.target_there(l); - if(who != nullptr) - combat_posing_monster = univ.get_target_i(*who); - if(combat_posing_monster == 6) - combat_posing_monster = -1; - } else combat_posing_monster = spec.ex1a; - if(combat_posing_monster < 0 || combat_posing_monster - 100 >= univ.town.monst.size()) { + if(which_mode != eSpecCtx::TALK) { + int i = combat_posing_monster; + if(l.y >= 0) { + iLiving* who = univ.target_there(l); + if(who != nullptr) + combat_posing_monster = univ.get_target_i(*who); + if(combat_posing_monster == 6) + combat_posing_monster = -1; + } else combat_posing_monster = spec.ex1a; + if(combat_posing_monster < 0 || combat_posing_monster - 100 >= univ.town.monst.size()) { + combat_posing_monster = i; + break; + } + redraw_screen(REFRESH_TERRAIN); combat_posing_monster = i; - break; } - redraw_screen(REFRESH_TERRAIN); - combat_posing_monster = i; break; case eSpecType::TOWN_SET_CENTER: if(l.x >= 0 && l.y >= 0) center = l; @@ -4304,65 +4299,63 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, case eSpecType::TOWN_RELOCATE_CREATURE: if(spec.ex2b > 5) { showError("Invalid positioning mode (0-5)"); - break; - } - if(spec.ex2a < 0) - i = univ.get_target_i(*current_pc_picked_in_spec_enc); - else i = spec.ex2a; - if(spec.ex2b == 5) { - spec.ex2b = 0; - if(i >= 100) { - std::set checked; - std::queue to_check; - location cur_check = l; - for(int tries = 0; tries < 100 && !monst_can_be_there(cur_check, i - 100); tries++) { - for(int x = -1; x <= 1; x++) { - for(int y = -1; y <= 1; y++) { - if(x == 0 && y == 0) - continue; - location next(l.x+x,l.y+y); - if(next.x < 0 || next.y < 0 || next.x >= univ.town->max_dim() || next.y >= univ.town->max_dim()) - continue; - if(!checked.count(next)) - to_check.push(next); - checked.insert(cur_check); - } - } - cur_check = to_check.front(); - to_check.pop(); - } - if(monst_can_be_there(cur_check, i - 100)) - l = cur_check; - } - } - if(spec.ex2b > 1) { - if(spec.ex2b <= 3) l.x *= -1; - if(spec.ex2b >= 3) l.y *= -1; - } - if(i < 6) { - start_cartoon(); - if(spec.ex2b == 0) - univ.party[i].combat_pos = l; - else { - univ.party[i].combat_pos.x += l.x; - univ.party[i].combat_pos.y += l.y; - } - } else if(i >= 100) { - i -= 100; - if(spec.ex2b == 0) - univ.town.monst[i].cur_loc = l; - else { - univ.town.monst[i].cur_loc.x += l.x; - univ.town.monst[i].cur_loc.y += l.y; - } } else { - showError("Invalid positioning target!"); - break; + int i = spec.ex2a < 0 ? univ.get_target_i(*current_pc_picked_in_spec_enc) : spec.ex2a; + if(spec.ex2b == 5) { + spec.ex2b = 0; + if(i >= 100) { + std::set checked; + std::queue to_check; + location cur_check = l; + for(int tries = 0; tries < 100 && !monst_can_be_there(cur_check, i - 100); tries++) { + for(int x = -1; x <= 1; x++) { + for(int y = -1; y <= 1; y++) { + if(x == 0 && y == 0) + continue; + location next(l.x+x,l.y+y); + if(next.x < 0 || next.y < 0 || next.x >= univ.town->max_dim() || next.y >= univ.town->max_dim()) + continue; + if(!checked.count(next)) + to_check.push(next); + checked.insert(cur_check); + } + } + cur_check = to_check.front(); + to_check.pop(); + } + if(monst_can_be_there(cur_check, i - 100)) + l = cur_check; + } + } + if(spec.ex2b > 1) { + if(spec.ex2b <= 3) l.x *= -1; + if(spec.ex2b >= 3) l.y *= -1; + } + if(i < 6) { + start_cartoon(); + if(spec.ex2b == 0) + univ.party[i].combat_pos = l; + else { + univ.party[i].combat_pos.x += l.x; + univ.party[i].combat_pos.y += l.y; + } + } else if(i >= 100) { + i -= 100; + if(spec.ex2b == 0) + univ.town.monst[i].cur_loc = l; + else { + univ.town.monst[i].cur_loc.x += l.x; + univ.town.monst[i].cur_loc.y += l.y; + } + } else { + showError("Invalid positioning target!"); + break; + } + redraw_screen(REFRESH_TERRAIN); + if(spec.ex2c > 0) + sf::sleep(sf::milliseconds(spec.ex2c)); + *redraw = 1; } - redraw_screen(REFRESH_TERRAIN); - if(spec.ex2c > 0) - sf::sleep(sf::milliseconds(spec.ex2c)); - *redraw = 1; break; case eSpecType::TOWN_PLACE_LABEL: check_mess = false; @@ -4398,7 +4391,6 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, void rect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, short *next_spec,short* /*next_spec_type*/,short *a,short *b,short *redraw){ bool check_mess = true; - short i,j,k; cSpecial spec; location l; ter_num_t ter; @@ -4407,8 +4399,8 @@ void rect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, *next_spec = cur_node.jumpto; *redraw = 1; - for(i = spec.ex1b;i <= spec.ex2b;i++) - for(j = spec.ex1a; j <= spec.ex2a; j++) { + for(short i = spec.ex1b;i <= spec.ex2b;i++) + for(short j = spec.ex1a; j <= spec.ex2a; j++) { l.x = i; l.y = j; // If pict non-zero, exclude rectangle interior if(spec.pic > 0 && i > spec.ex1b && i < spec.ex2b && j > spec.ex1a && j < spec.ex2a) @@ -4467,7 +4459,7 @@ void rect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, if(is_out()) return; i = is_container(loc(spec.sd1,spec.sd2)); - for(k = 0; k < univ.town.items.size(); k++) + for(short k = 0; k < univ.town.items.size(); k++) if(univ.town.items[k].variety != eItemType::NO_ITEM && univ.town.items[k].item_loc == l) { univ.town.items[k].item_loc.x = spec.sd1; univ.town.items[k].item_loc.y = spec.sd2; @@ -4481,7 +4473,7 @@ void rect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, case eSpecType::RECT_DESTROY_ITEMS: if(is_out()) return; - for(k = 0; k < univ.town.items.size(); k++) + for(short k = 0; k < univ.town.items.size(); k++) if(univ.town.items[k].variety != eItemType::NO_ITEM && univ.town.items[k].item_loc == l) { univ.town.items[k].variety = eItemType::NO_ITEM; } @@ -4542,7 +4534,6 @@ void outdoor_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, std::string str1, str2; cSpecial spec; location l; - int i; spec = cur_node; *next_spec = cur_node.jumpto; @@ -4571,8 +4562,9 @@ void outdoor_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, *redraw = 1; *a = 1; break; - case eSpecType::OUT_FORCE_TOWN: + case eSpecType::OUT_FORCE_TOWN: { l = {spec.ex2a, spec.ex2b}; + int i = 0; if(l.x < 0 || l.y < 0 || l.x >= 64 || l.y >= 64) i = 9; else if(spec.ex1b == 0) i = 2; @@ -4581,6 +4573,7 @@ void outdoor_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, else i = 1; if(i == 9) force_town_enter(spec.ex1a, l); start_town_mode(spec.ex1a, i); + } break; default: showError("Special node type \"" + (*cur_node.type).name() + "\" is either miscategorized or unimplemented!"); diff --git a/src/boe.startup.cpp b/src/boe.startup.cpp index c408ffe4..7945ecb9 100644 --- a/src/boe.startup.cpp +++ b/src/boe.startup.cpp @@ -38,13 +38,13 @@ rectangle startup_button[6]; bool handle_startup_press(location the_point) { using kb = sf::Keyboard; std::string scen_name; - short i,scen; + short scen; bool force_party = false; the_point.x -= ul.x; the_point.y -= ul.y; - for(i = 0; i < 5; i++) + for(short i = 0; i < 5; i++) if(the_point.in(startup_button[i])) { draw_start_button(i,5); mainPtr.display(); // TODO: I suspect this won't work diff --git a/src/boe.text.cpp b/src/boe.text.cpp index 724ff1c6..8d4a45be 100644 --- a/src/boe.text.cpp +++ b/src/boe.text.cpp @@ -81,7 +81,6 @@ extern std::map> statIcons; // Draws the pc area in upper right void put_pc_screen() { - short i = 0,j; rectangle erase_rect = {17,2,98,269},to_draw_rect,from_rect; rectangle food_rect[2] = {{103,34,114,76}, {103,3,114,40}}; rectangle gold_rect[2] = {{103,106,114,147}, {103,75,114,104}}; @@ -118,9 +117,9 @@ void put_pc_screen() { style.colour = sf::Color::Black; sf::Texture& invenbtn_gworld = *ResMgr::get("invenbtns"); - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(univ.party[i].main_status != eMainStatus::ABSENT) { - for(j = 0; j < 5; j++) + for(short j = 0; j < 5; j++) pc_area_button_active[i][j] = 1; if(i == current_pc) { style.italic = true; @@ -189,7 +188,7 @@ void put_pc_screen() { rect_draw_some_item(invenbtn_gworld,from_rect,pc_stats_gworld,to_draw_rect,sf::BlendAlpha); } else { - for(j = 0; j < 5; j++) + for(short j = 0; j < 5; j++) pc_area_button_active[i][j] = 0; } } @@ -221,7 +220,7 @@ void put_item_screen(short screen_num) { std::ostringstream sout; long i_num; long item_offset; - short i = 0,j,pc; + short pc; rectangle erase_rect = {17,2,122,255},dest_rect; rectangle upper_frame_rect = {3,3,15,268}; @@ -235,8 +234,8 @@ void put_item_screen(short screen_num) { // Draw buttons at bottom item_offset = item_sbar->getPosition(); - for(i = 0; i < 8; i++) - for(j = 0; j < 6; j++) + for(short i = 0; i < 8; i++) + for(short j = 0; j < 6; j++) item_area_button_active[i][j] = false; TextStyle style; @@ -247,7 +246,7 @@ void put_item_screen(short screen_num) { case ITEM_WIN_SPECIAL: win_draw_string(item_stats_gworld,upper_frame_rect,"Special items:",eTextMode::WRAP,style); style.colour = sf::Color::Black; - for(i = 0; i < 8; i++) { + for(short i = 0; i < 8; i++) { i_num = i + item_offset; if(i_num < spec_item_array.size()) { win_draw_string(item_stats_gworld,item_buttons[i][ITEMBTN_NAME],univ.scenario.special_items[spec_item_array[i_num]].name,eTextMode::WRAP,style); @@ -262,7 +261,7 @@ void put_item_screen(short screen_num) { case ITEM_WIN_QUESTS: win_draw_string(item_stats_gworld,upper_frame_rect,"Quests/Jobs:",eTextMode::WRAP,style); style.colour = sf::Color::Black; - for(i = 0; i < 8; i++) { + for(short i = 0; i < 8; i++) { i_num = i + item_offset; if(i_num < spec_item_array.size()) { int which_quest = spec_item_array[i_num] % 10000; @@ -291,7 +290,7 @@ void put_item_screen(short screen_num) { win_draw_string(item_stats_gworld,upper_frame_rect,sout.str(),eTextMode::WRAP,style); style.colour = sf::Color::Black; - for(i = 0; i < 8; i++) { + for(short i = 0; i < 8; i++) { i_num = i + item_offset; sout.str(""); sout << i_num + 1 << '.'; @@ -356,7 +355,7 @@ void put_item_screen(short screen_num) { } } // end of if item is there - } // end of for(i = 0; i < 8; i++) + } // end of for(short i = 0; i < 8; i++) break; } @@ -502,7 +501,6 @@ void place_item_bottom_buttons() { rectangle pc_from_rect = {0,0,36,28},but_from_rect = {30,60,46,78},to_rect; rectangle spec_from_rect = {0,60,15,95}, job_from_rect = {15,60,30,95}, help_from_rect = {46,60,59,76}; // TODO: What about when the buttons are pressed? - short i; TextStyle style; style.lineHeight = 10; style.pointSize = 12; @@ -510,7 +508,7 @@ void place_item_bottom_buttons() { style.colour = sf::Color::Yellow; sf::Texture& invenbtn_gworld = *ResMgr::get("invenbtns"); - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(univ.party[i].main_status == eMainStatus::ALIVE) { item_bottom_button_active[i] = true; to_rect = item_screen_button_rects[i]; @@ -553,7 +551,7 @@ void place_item_bottom_buttons() { } void set_stat_window(short new_stat) { - short i,array_pos = 0; + short array_pos = 0; stat_window = new_stat; if(stat_window < ITEM_WIN_SPECIAL && univ.party[stat_window].main_status != eMainStatus::ALIVE) @@ -563,7 +561,7 @@ void set_stat_window(short new_stat) { switch(stat_window) { case ITEM_WIN_SPECIAL: std::fill(spec_item_array.begin(), spec_item_array.end(), -1); - for(i = 0; i < univ.scenario.special_items.size(); i++) + for(short i = 0; i < univ.scenario.special_items.size(); i++) if(univ.party.spec_items.count(i)) { spec_item_array.push_back(i); array_pos++; @@ -573,7 +571,7 @@ void set_stat_window(short new_stat) { break; case ITEM_WIN_QUESTS: std::fill(spec_item_array.begin(), spec_item_array.end(), -1); - for(i = 0; i < univ.scenario.quests.size(); i++) + for(short i = 0; i < univ.scenario.quests.size(); i++) if(univ.party.quest_status[i] == eQuestStatus::STARTED) { spec_item_array.push_back(i); array_pos++; @@ -597,9 +595,7 @@ void set_stat_window(short new_stat) { } short first_active_pc() { - short i = 0; - - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) return i; return 6; @@ -607,7 +603,6 @@ short first_active_pc() { void refresh_stat_areas(short mode) { - short i; sf::BlendMode x; rectangle dest_rect,parts_of_area_to_draw[3] = {{0,0,17,271},{16,0,123,256},{123,0,144,271}}; @@ -617,7 +612,7 @@ void refresh_stat_areas(short mode) { if(mode == 1) x = sf::BlendAdd; else x = sf::BlendNone; rect_draw_some_item (pc_stats_gworld.getTexture(), oldRect, dest_rect,ul, x); - for(i = 0; i < 3; i++) { + for(short i = 0; i < 3; i++) { dest_rect = parts_of_area_to_draw[i]; dest_rect.offset(ITEM_WIN_UL_X,ITEM_WIN_UL_Y); rect_draw_some_item(item_stats_gworld.getTexture(), parts_of_area_to_draw[i], dest_rect,ul, x); @@ -631,9 +626,9 @@ void refresh_stat_areas(short mode) { // get job info gone short total_encumbrance(short pc_num) { - short store = 0,i,what_val; + short store = 0,what_val; - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) if(univ.party[pc_num].equip[i]) { what_val = univ.party[pc_num].items[i].awkward; store += what_val; @@ -694,7 +689,7 @@ void print_party_stats() { short do_look(location space) { - short i,j,num_items = 0; + short num_items = 0; bool gold_here = false, food_here = false, is_lit = true; location from_where; std::string msg; @@ -706,7 +701,7 @@ short do_look(location space) { (overall_mode == MODE_LOOK_TOWN && space == univ.party.town_loc)) add_string_to_buf(" Your party"); if(overall_mode == MODE_LOOK_COMBAT) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(space == univ.party[i].combat_pos && univ.party[i].main_status == eMainStatus::ALIVE && (is_lit) && (can_see_light(univ.party[current_pc].combat_pos,space,sight_obscurity) < 5)) { msg = " " + univ.party[i].name; @@ -714,7 +709,7 @@ short do_look(location space) { } if((overall_mode == MODE_LOOK_TOWN) || (overall_mode == MODE_LOOK_COMBAT)) { - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active != 0) && (is_lit) && univ.town.monst[i].on_space(space) && ((overall_mode == MODE_LOOK_TOWN) || (can_see_light(univ.party[current_pc].combat_pos,space,sight_obscurity) < 5)) @@ -732,10 +727,10 @@ short do_look(location space) { } } if(overall_mode == MODE_LOOK_OUTDOORS) { - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { if((univ.party.out_c[i].exists) && (space == univ.party.out_c[i].m_loc)) { - for(j = 0; j < 7; j++) + for(short j = 0; j < 7; j++) if(univ.party.out_c[i].what_monst.monst[j] != 0) { msg = get_m_name(univ.party.out_c[i].what_monst.monst[j]); msg = " " + msg; @@ -813,7 +808,7 @@ short do_look(location space) { if(univ.town.is_rubble(space.x,space.y)) add_string_to_buf(" Rubble"); - for(i = 0; i < univ.town.items.size(); i++) { + for(short i = 0; i < univ.town.items.size(); i++) { if(univ.town.items[i].variety != eItemType::NO_ITEM && space == univ.town.items[i].item_loc && (is_lit)) { if(univ.town.items[i].variety == eItemType::GOLD) @@ -829,7 +824,7 @@ short do_look(location space) { add_string_to_buf(" Food"); if(num_items > 8) add_string_to_buf(" Many items"); - else for(i = 0; i < univ.town.items.size(); i++) { + else for(short i = 0; i < univ.town.items.size(); i++) { if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].variety != eItemType::GOLD && univ.town.items[i].variety != eItemType::FOOD && (space == univ.town.items[i].item_loc) && (!univ.town.items[i].contained)) { if(univ.town.items[i].ident) @@ -851,18 +846,14 @@ short do_look(location space) { } short town_boat_there(location where) { - short i; - - for(i = 0; i < univ.party.boats.size(); i++) + for(short i = 0; i < univ.party.boats.size(); i++) if(univ.party.boats[i].exists && univ.party.boats[i].which_town == univ.party.town_num && (where == univ.party.boats[i].loc)) return i; return univ.party.boats.size(); } short out_boat_there(location where) { - short i; - - for(i = 0; i < univ.party.boats.size(); i++) + for(short i = 0; i < univ.party.boats.size(); i++) if((univ.party.boats[i].exists) && (where == univ.party.boats[i].loc) && (univ.party.boats[i].which_town == 200)) return i; @@ -870,30 +861,25 @@ short out_boat_there(location where) { } short town_horse_there(location where) { - short i; - - for(i = 0; i < univ.party.horses.size(); i++) + for(short i = 0; i < univ.party.horses.size(); i++) if(univ.party.horses[i].exists && univ.party.horses[i].which_town == univ.party.town_num && (where == univ.party.horses[i].loc)) return i; return univ.party.horses.size(); } short out_horse_there(location where) { - short i; - - for(i = 0; i < univ.party.horses.size(); i++) + for(short i = 0; i < univ.party.horses.size(); i++) if((univ.party.horses[i].exists) && (where == univ.party.horses[i].loc) && (univ.party.horses[i].which_town == 200)) return i; return univ.party.horses.size(); } void notify_out_combat_began(cOutdoors::cWandering encounter,short *nums) { - short i; std::string msg; add_string_to_buf("COMBAT!"); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(encounter.monst[i] != 0) { msg = get_m_name(encounter.monst[i]); std::ostringstream sout; @@ -1017,9 +1003,9 @@ void add_string_to_buf(std::string str, unsigned short indent) { while(text_buffer[prev_pointer].line[--last] == ' '); bool is_dup = false; if(last == new_last) { - size_t i, num_pos = 0; + size_t num_pos = 0; enum {begin, f_space, f_lparen, f_x, f_num, f_rparen, err} state = begin; - for(i = last; i < 50 && text_buffer[prev_pointer].line[i]; i++) { + for(short i = last; i < 50 && text_buffer[prev_pointer].line[i]; i++) { if(state == f_x) num_pos = i; if(isdigit(text_buffer[prev_pointer].line[i]) && (state == f_x || state == f_num)) state = f_num; @@ -1076,9 +1062,7 @@ void add_string_to_buf(std::string str, unsigned short indent) { } void init_buf() { - short i; - - for(i = 0; i < TEXT_BUF_LEN; i++) + for(short i = 0; i < TEXT_BUF_LEN; i++) sprintf((char *) text_buffer[buf_pointer].line, " "); } diff --git a/src/boe.town.cpp b/src/boe.town.cpp index b6e360b5..40bfe56c 100644 --- a/src/boe.town.cpp +++ b/src/boe.town.cpp @@ -67,8 +67,7 @@ void force_town_enter(short which_town,location where_start) { //short entry_dir; // if 9, go to forced void start_town_mode(short which_town, short entry_dir) { - short i,m,n; - short j,k,town_number; + short town_number; short at_which_save_slot,former_town; bool monsters_loaded = false,town_toast = false; location loc; @@ -88,17 +87,17 @@ void start_town_mode(short which_town, short entry_dir) { } // Now adjust town number as necessary. - for(i = 0; i < univ.scenario.town_mods.size(); i++) + for(short i = 0; i < univ.scenario.town_mods.size(); i++) if(univ.scenario.town_mods[i].spec >= 0 && univ.scenario.town_mods[i].spec < 200 && town_number == univ.scenario.town_mods[i].spec && univ.party.sd_legit(univ.scenario.town_mods[i].x,univ.scenario.town_mods[i].y)) { former_town = town_number; town_number += PSD[univ.scenario.town_mods[i].x][univ.scenario.town_mods[i].y]; // Now update horses & boats - for(i = 0; i < univ.party.horses.size(); i++) + for(short i = 0; i < univ.party.horses.size(); i++) if((univ.party.horses[i].exists) && (univ.party.horses[i].which_town == former_town)) univ.party.horses[i].which_town = town_number; - for(i = 0; i < univ.party.boats.size(); i++) + for(short i = 0; i < univ.party.boats.size(); i++) if((univ.party.boats[i].exists) && (univ.party.boats[i].which_town == former_town)) univ.party.boats[i].which_town = town_number; } @@ -126,8 +125,8 @@ void start_town_mode(short which_town, short entry_dir) { univ.town.belt_present = false; // Set up map, using stored map - for(i = 0; i < univ.town->max_dim(); i++) - for(j = 0; j < univ.town->max_dim(); j++) { + for(short i = 0; i < univ.town->max_dim(); i++) + for(short j = 0; j < univ.town->max_dim(); j++) { if(univ.town_maps[univ.party.town_num][i / 8][j] & (char)(1 << i % 8)) make_explored(i,j); @@ -149,7 +148,7 @@ void start_town_mode(short which_town, short entry_dir) { univ.town.monst = pop; monsters_loaded = true; - for(j = 0; j < univ.town.monst.size(); j++) { + for(short j = 0; j < univ.town.monst.size(); j++) { if(loc_off_act_area(univ.town.monst[j].cur_loc)) univ.town.monst[j].active = 0; if(univ.town.monst[j].active == 2) @@ -163,15 +162,15 @@ void start_town_mode(short which_town, short entry_dir) { univ.town.monst[j].active = 0; univ.town.monst[j].target = 6; // Bonus SP and HP wear off - if(univ.town.monst[i].mp > univ.town.monst[i].max_mp) - univ.town.monst[i].mp = univ.town.monst[i].max_mp; - if(univ.town.monst[i].health > univ.town.monst[i].m_health) - univ.town.monst[i].health = univ.town.monst[i].m_health; + if(univ.town.monst[j].mp > univ.town.monst[j].max_mp) + univ.town.monst[j].mp = univ.town.monst[j].max_mp; + if(univ.town.monst[j].health > univ.town.monst[j].m_health) + univ.town.monst[j].health = univ.town.monst[j].m_health; } // Now, travelling NPCs might have arrived. Go through and put them in. // These should have protected status (i.e. spec1 >= 200, spec1 <= 204) - for(j = 0; j < univ.town.monst.size(); j++) { + for(short j = 0; j < univ.town.monst.size(); j++) { switch(univ.town.monst[j].time_flag){ case eMonstTime::ALWAYS: break; // Nothing to do. case eMonstTime::SOMETIMES_A: case eMonstTime::SOMETIMES_B: case eMonstTime::SOMETIMES_C: @@ -218,19 +217,21 @@ void start_town_mode(short which_town, short entry_dir) { case eMonstTime::APPEAR_AFTER_CHOP: // TODO: Should these two cases be separated? if(univ.town->town_chop_time > 0 && day_reached(univ.town->town_chop_time,univ.town->town_chop_key)) - univ.town.monst[i].active += 10; + univ.town.monst[j].active += 10; else if(univ.town->is_cleaned_out(univ.party.m_killed[univ.party.town_num])) - univ.town.monst[i].active += 10; - else univ.town.monst[i].active = 0; - if(univ.town.monst[i].active >= 10) - univ.town.monst[i].time_flag = eMonstTime::ALWAYS; + univ.town.monst[j].active += 10; + else univ.town.monst[j].active = 0; + if(univ.town.monst[j].active >= 10) + univ.town.monst[j].time_flag = eMonstTime::ALWAYS; break; } } - for(j = 0; j < univ.town->max_dim(); j++) - for(k = 0; k < univ.town->max_dim(); k++) { // now load in saved setup, + for(short j = 0; j < univ.town->max_dim(); j++) + for(short k = 0; k < univ.town->max_dim(); k++) { // now load in saved setup, // except that pushable things restore to orig locs + // TODO: THIS IS A TEMPORARY HACK TO GET i VALUE + int i = std::find_if(univ.party.creature_save.begin(), univ.party.creature_save.end(), [&pop](cPopulation& p) {return &p == &pop;}) - univ.party.creature_save.begin(); temp = univ.party.setup[i][j][k] << 8; temp &= ~(OBJECT_CRATE | OBJECT_BARREL | OBJECT_BLOCK); univ.town.fields[j][k] |= temp; @@ -238,7 +239,7 @@ void start_town_mode(short which_town, short entry_dir) { } if(!monsters_loaded) { - for(i = 0; i < univ.town->creatures.size(); i++){ + for(short i = 0; i < univ.town->creatures.size(); i++){ if(univ.town->creatures[i].number == 0) { if(i >= univ.town.monst.size()) continue; univ.town.monst[i].active = 0; @@ -273,14 +274,14 @@ void start_town_mode(short which_town, short entry_dir) { } break; case eMonstTime::APPEAR_WHEN_EVENT: - if(univ.party.key_times.find(univ.town.monst[j].time_code) == univ.party.key_times.end()) + if(univ.party.key_times.find(univ.town.monst[i].time_code) == univ.party.key_times.end()) univ.town.monst[i].active = 0; // Event hasn't happened yet else if(univ.party.calc_day() < univ.party.key_times[univ.town.monst[i].time_code]) univ.town.monst[i].active = 0; // This would only be reached if the time was set back (or in a legacy save) break; case eMonstTime::DISAPPEAR_WHEN_EVENT: - if(univ.party.key_times.find(univ.town.monst[j].time_code) == univ.party.key_times.end()) + if(univ.party.key_times.find(univ.town.monst[i].time_code) == univ.party.key_times.end()) break; // Event hasn't happened yet if(univ.party.calc_day() >= univ.party.key_times[univ.town.monst[i].time_code]) univ.town.monst[i].active = 0; @@ -309,7 +310,7 @@ void start_town_mode(short which_town, short entry_dir) { // Now munch all large monsters that are misplaced // only large monsters, as some smaller monsters are intentionally placed // where they cannot be - for(i = 0; i < univ.town.monst.size(); i++) { + for(short i = 0; i < univ.town.monst.size(); i++) { if(univ.town.monst[i].active > 0) if(((univ.town.monst[i].x_width > 1) || (univ.town.monst[i].y_width > 1)) && !monst_can_be_there(univ.town.monst[i].cur_loc,i)) @@ -325,7 +326,7 @@ void start_town_mode(short which_town, short entry_dir) { if(univ.town->town_chop_time > 0) { if(day_reached(univ.town->town_chop_time,univ.town->town_chop_key)) { add_string_to_buf("Area has been abandoned."); - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].active > 0) && (univ.town.monst[i].active < 10) && !univ.town.monst[i].is_friendly()) univ.town.monst[i].active += 10; @@ -333,7 +334,7 @@ void start_town_mode(short which_town, short entry_dir) { } } if(town_toast) { - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active >= 10) univ.town.monst[i].active -= 10; else univ.town.monst[i].active = 0; @@ -341,14 +342,14 @@ void start_town_mode(short which_town, short entry_dir) { handle_town_specials(town_number, (short) town_toast,(entry_dir < 9) ? univ.town->start_locs[entry_dir] : town_force_loc); // Flush excess doomguards and viscous goos - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if((univ.town.monst[i].abil[eMonstAbil::SPLITS].active) && (i >= univ.town->creatures.size() || univ.town.monst[i].number != univ.town->creatures[i].number)) univ.town.monst[i].active = 0; // Set up field booleans, correct for doors - for(j = 0; j < univ.town->max_dim(); j++) - for(k = 0; k < univ.town->max_dim(); k++) { + for(short j = 0; j < univ.town->max_dim(); j++) + for(short k = 0; k < univ.town->max_dim(); k++) { loc.x = j; loc.y = k; if(is_door(loc)) { univ.town.set_web(j,k,false); @@ -365,30 +366,29 @@ void start_town_mode(short which_town, short entry_dir) { // Set up items, maybe place items already there univ.town.items.clear(); - for(j = 0; j < 3; j++) + for(short j = 0; j < 3; j++) if(univ.scenario.store_item_towns[j] == town_number) { univ.town.items = univ.party.stored_items[j]; } - for(i = 0; i < univ.town->preset_items.size(); i++) + for(short i = 0; i < univ.town->preset_items.size(); i++) if((univ.town->preset_items[i].code >= 0) && (((univ.party.item_taken[univ.party.town_num][i / 8] & (1 << i % 8)) == 0) || (univ.town->preset_items[i].always_there))) { - j = univ.town.items.size(); // place the preset item, if party hasn't gotten it already univ.town.items.push_back(get_stored_item(univ.town->preset_items[i].code)); // Don't place special items if already in the party's possession - if(univ.town.items[j].variety == eItemType::SPECIAL && univ.party.spec_items.count(univ.town.items[j].item_level)) + if(univ.town.items[i].variety == eItemType::SPECIAL && univ.party.spec_items.count(univ.town.items[i].item_level)) break; // Don't place quest items if party already started - if(univ.town.items[j].variety == eItemType::QUEST && univ.party.quest_status[univ.town.items[j].item_level] != eQuestStatus::AVAILABLE) + if(univ.town.items[i].variety == eItemType::QUEST && univ.party.quest_status[univ.town.items[i].item_level] != eQuestStatus::AVAILABLE) break; - univ.town.items[j].item_loc = univ.town->preset_items[i].loc; + univ.town.items[i].item_loc = univ.town->preset_items[i].loc; // Not use the items data flags, starting with forcing an ability if(univ.town->preset_items[i].ability >= 0) { // TODO: What other ways might there be to use this? - switch(univ.town.items[j].variety) { + switch(univ.town.items[i].variety) { case eItemType::ONE_HANDED: case eItemType::TWO_HANDED: { if(univ.town->preset_items[i].ability > int(eEnchant::BLESSED)) @@ -396,8 +396,8 @@ void start_town_mode(short which_town, short entry_dir) { // TODO: This array and accompanying calculation is now duplicated here and in place_buy_button() const short aug_cost[10] = {4,7,10,8, 15,15,10, 0,0,0}; int ench = univ.town->preset_items[i].ability; - int val = max(aug_cost[ench] * 100, univ.town.items[j].value * (5 + aug_cost[ench])); - univ.town.items[j].enchant_weapon(eEnchant(ench), val); + int val = max(aug_cost[ench] * 100, univ.town.items[i].value * (5 + aug_cost[ench])); + univ.town.items[i].enchant_weapon(eEnchant(ench), val); break; } default: break; // Silence compiler warning @@ -405,34 +405,34 @@ void start_town_mode(short which_town, short entry_dir) { } if(univ.town->preset_items[i].charges > 0) { - eItemType variety = univ.town.items[j].variety; - if(univ.town.items[j].charges > 0) - univ.town.items[j].charges = univ.town->preset_items[i].charges; + eItemType variety = univ.town.items[i].variety; + if(univ.town.items[i].charges > 0) + univ.town.items[i].charges = univ.town->preset_items[i].charges; else if(variety == eItemType::GOLD || variety == eItemType::FOOD) - univ.town.items[j].item_level = univ.town->preset_items[i].charges; + univ.town.items[i].item_level = univ.town->preset_items[i].charges; } if(town_toast) - univ.town.items[j].property = false; + univ.town.items[i].property = false; else - univ.town.items[j].property = univ.town->preset_items[i].property; - univ.town.items[j].contained = univ.town->preset_items[i].contained; - int x = univ.town.items[j].item_loc.x, y = univ.town.items[j].item_loc.y; - if(univ.town.items[j].contained && (univ.town.is_barrel(x,y) || univ.town.is_crate(x,y))) - univ.town.items[j].held = true; - univ.town.items[j].is_special = i + 1; + univ.town.items[i].property = univ.town->preset_items[i].property; + univ.town.items[i].contained = univ.town->preset_items[i].contained; + int x = univ.town.items[i].item_loc.x, y = univ.town.items[i].item_loc.y; + if(univ.town.items[i].contained && (univ.town.is_barrel(x,y) || univ.town.is_crate(x,y))) + univ.town.items[i].held = true; + univ.town.items[i].is_special = i + 1; } - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(loc_off_act_area(univ.town.monst[i].cur_loc)) univ.town.monst[i].active = 0; - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(loc_off_act_area(univ.town.items[i].item_loc)) univ.town.items[i].variety = eItemType::NO_ITEM; // Clean out unwanted monsters - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.party.sd_legit(univ.town.monst[i].spec1,univ.town.monst[i].spec2)) { if(PSD[univ.town.monst[i].spec1][univ.town.monst[i].spec2] > 0) univ.town.monst[i].active = 0; @@ -477,23 +477,23 @@ void start_town_mode(short which_town, short entry_dir) { update_explored(univ.party.town_loc); // If a PC dead, drop his items - for(m = 0; m < 6; m++) { + for(short m = 0; m < 6; m++) { if(univ.party[m].main_status == eMainStatus::ALIVE || isSplit(univ.party[m].main_status)) continue; - for(n = 0; n < 24; n++) + for(short n = 0; n < 24; n++) if(univ.party[m].items[n].variety != eItemType::NO_ITEM) { place_item(univ.party[m].items[n],univ.party.town_loc); univ.party[m].items[n].variety = eItemType::NO_ITEM; } } - for(i = 0; i < univ.town.monst.size(); i++) { + for(short i = 0; i < univ.town.monst.size(); i++) { univ.town.monst[i].targ_loc.x = 0; univ.town.monst[i].targ_loc.y = 0; } // check horses - for(i = 0; i < univ.party.boats.size(); i++) { + for(short i = 0; i < univ.party.boats.size(); i++) { if(univ.scenario.boats[i].which_town >= 0 && univ.scenario.boats[i].loc.x >= 0) { if(!univ.party.boats[i].exists) { univ.party.boats[i] = univ.scenario.boats[i]; @@ -501,7 +501,7 @@ void start_town_mode(short which_town, short entry_dir) { } } } - for(i = 0; i < univ.party.horses.size(); i++) { + for(short i = 0; i < univ.party.horses.size(); i++) { if(univ.scenario.horses[i].which_town >= 0 && univ.scenario.horses[i].loc.x >= 0) { if(!univ.party.horses[i].exists) { univ.party.horses[i] = univ.scenario.horses[i]; @@ -522,13 +522,12 @@ void start_town_mode(short which_town, short entry_dir) { location end_town_mode(short switching_level,location destination) { // returns new party location location to_return; bool data_saved = false,combat_end = false; - short i,j,k; if(is_combat()) combat_end = true; // Bonus SP and HP wear off - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(univ.party[i].cur_sp > univ.party[i].max_sp) univ.party[i].cur_sp = univ.party[i].max_sp; if(univ.party[i].cur_health > univ.party[i].max_health) @@ -539,24 +538,26 @@ location end_town_mode(short switching_level,location destination) { // returns for(auto& pop : univ.party.creature_save) if(pop.which_town == univ.party.town_num) { pop = univ.town.monst; - for(j = 0; j < univ.town->max_dim(); j++) - for(k = 0; k < univ.town->max_dim(); k++) + // TODO: THIS IS A TEMPORARY HACK TO GET i VALUE + int i = std::find_if(univ.party.creature_save.begin(), univ.party.creature_save.end(), [&pop](cPopulation& p) {return &p == &pop;}) - univ.party.creature_save.begin(); + for(short j = 0; j < univ.town->max_dim(); j++) + for(short k = 0; k < univ.town->max_dim(); k++) univ.party.setup[i][j][k] = (univ.town.fields[j][k] & 0xff00) >> 8; data_saved = true; } if(!data_saved) { univ.party.creature_save[univ.party.at_which_save_slot] = univ.town.monst; - for(j = 0; j < univ.town->max_dim(); j++) - for(k = 0; k < univ.town->max_dim(); k++) + for(short j = 0; j < univ.town->max_dim(); j++) + for(short k = 0; k < univ.town->max_dim(); k++) univ.party.setup[univ.party.at_which_save_slot][j][k] = (univ.town.fields[j][k] & 0xff00) >> 8; univ.party.at_which_save_slot = (univ.party.at_which_save_slot == 3) ? 0 : univ.party.at_which_save_slot + 1; } // Store items, if necessary - for(j = 0; j < 3; j++) + for(short j = 0; j < 3; j++) if(univ.scenario.store_item_towns[j] == univ.party.town_num) { univ.party.stored_items[j].clear(); - for(i = 0; i < univ.town.items.size(); i++) + for(short i = 0; i < univ.town.items.size(); i++) if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].is_special == 0 && univ.town.items[i].item_loc.x >= univ.scenario.store_item_rects[j].left && univ.town.items[i].item_loc.x <= univ.scenario.store_item_rects[j].right && @@ -567,8 +568,8 @@ location end_town_mode(short switching_level,location destination) { // returns } // Now store map - for(i = 0; i < univ.town->max_dim(); i++) - for(j = 0; j < univ.town->max_dim(); j++) + for(short i = 0; i < univ.town->max_dim(); i++) + for(short j = 0; j < univ.town->max_dim(); j++) if(is_explored(i,j)) { univ.town_maps[univ.party.town_num][i / 8][j] = univ.town_maps[univ.party.town_num][i / 8][j] | (char) (1 << i % 8); @@ -628,7 +629,7 @@ location end_town_mode(short switching_level,location destination) { // returns univ.party.status[ePartyStatus::STEALTH] = 0; univ.party.status[ePartyStatus::DETECT_LIFE] = 0; // TODO: Yes? No? Maybe? - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) erase_if(univ.party[i].status, [](std::pair kv) -> bool { if(kv.first == eStatus::POISON) return false; if(kv.first == eStatus::DISEASE) return false; @@ -661,14 +662,12 @@ void handle_leave_town_specials(short /*town_number*/, short which_spec,location } bool abil_exists(eItemAbil abil) { // use when outdoors - short i,j; - - for(i = 0; i < 6; i++) - for(j = 0; j < 24; j++) + for(short i = 0; i < 6; i++) + for(short j = 0; j < 24; j++) if(univ.party[i].items[j].variety != eItemType::NO_ITEM && univ.party[i].items[j].ability == abil) return true; - for(i = 0; i < 3; i++) - for(j = 0; j < univ.town.items.size(); j++) + for(short i = 0; i < 3; i++) + for(short j = 0; j < univ.town.items.size(); j++) if(univ.party.stored_items[i][j].variety != eItemType::NO_ITEM && univ.party.stored_items[i][j].ability == abil) return true; @@ -679,11 +678,9 @@ bool abil_exists(eItemAbil abil) { // use when outdoors void start_town_combat(eDirection direction) { - short i; - place_party(direction); if(current_pc == 6) - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::ALIVE) { current_pc = i; break; @@ -694,10 +691,10 @@ void start_town_combat(eDirection direction) { overall_mode = MODE_COMBAT; combat_active_pc = 6; - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) univ.town.monst[i].target = 6; - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { univ.party[i].last_attacked = nullptr; univ.party[i].parry = 0; univ.party[i].direction = direction; @@ -719,7 +716,7 @@ void start_town_combat(eDirection direction) { } eDirection end_town_combat() { - short num_tries = 0,r1,i; + short num_tries = 0,r1; int in_cage = 0; location cage_loc; bool same_cage = true; @@ -746,7 +743,7 @@ eDirection end_town_combat() { current_pc = store_current_pc; if(univ.party[current_pc].main_status != eMainStatus::ALIVE) current_pc = first_active_pc(); - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { univ.party[i].parry = 0; univ.party[i].combat_pos = {-1,-1}; } @@ -769,9 +766,9 @@ void place_party(short direction) { true,true,true,true,true,true,true}; location pos_locs[14]; location check_loc; - short x_adj,y_adj,how_many_ok = 1,where_in_a = 0,i; + short x_adj,y_adj,how_many_ok = 1,where_in_a = 0; - for(i = 0; i < 14; i++) { + for(short i = 0; i < 14; i++) { check_loc = univ.party.town_loc; if(direction % 4 < 2) x_adj = ((direction % 2 == 0) ? hor_vert_place[i].x : diag_place[i].x); @@ -799,8 +796,7 @@ void place_party(short direction) { if(i == 0) spot_ok[i] = true; } - i = 0; - while(i < 6) { + for(short i = 0; i < 6; i++) { if(univ.party[i].main_status == eMainStatus::ALIVE) { if(how_many_ok == 1) univ.party[i].combat_pos = pos_locs[where_in_a]; @@ -815,12 +811,11 @@ void place_party(short direction) { // } } } - i++; } } void create_out_combat_terrain(short ter_type,short num_walls,bool is_road) { - short i,j,k,r1,arena; + short r1,arena; static const short ter_base[20] = { 2,0,36,50,71, 0,0,0, 0,2, 2,2, 2, 0, 0, 36,0,2, 0,2, @@ -920,8 +915,8 @@ void create_out_combat_terrain(short ter_type,short num_walls,bool is_road) { town_bounds.right = minmax(0,town_size - 1, town_bounds.right); town_bounds.top = minmax(0,town_size - 1, town_bounds.top); town_bounds.bottom = minmax(0,town_size - 1, town_bounds.bottom); - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++) { + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++) { // This test also accounts for small towns since the town boundary is never larger than the town if(town_bounds.contains(i + offset, j + offset)) univ.town->terrain(i,j) = univ.scenario.towns[arena]->terrain(i + offset,j + offset); @@ -935,16 +930,16 @@ void create_out_combat_terrain(short ter_type,short num_walls,bool is_road) { return; } - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++) { + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++) { univ.town.fields[i][j] = 0; if((j <= 8) || (j >= 35) || (i <= 8) || (i >= 35)) univ.town->terrain(i,j) = 90; else univ.town->terrain(i,j) = ter_base[arena]; } - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++) - for(k = 0; k < 5; k++) + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++) + for(short k = 0; k < 5; k++) if((univ.town->terrain(i,j) != 90) && (get_ran(1,1,1000) < terrain_odds[arena][k * 2 + 1])) univ.town->terrain(i,j) = terrain_odds[arena][k * 2]; @@ -954,31 +949,31 @@ void create_out_combat_terrain(short ter_type,short num_walls,bool is_road) { if(arena == 3 || (is_road && surface_arenas.count(arena))) { univ.town->terrain(0,0) = 83; - for(i = (is_bridge ? 15 : 19); i < (is_bridge ? 26 : 23); i++) - for(j = 9; j < 35; j++) + for(short i = (is_bridge ? 15 : 19); i < (is_bridge ? 26 : 23); i++) + for(short j = 9; j < 35; j++) univ.town->terrain(i,j) = 83; } if(arena == 4 || (is_road && cave_arenas.count(arena))) { univ.town->terrain(0,0) = 82; - for(i = (is_bridge ? 15 : 19); i < (is_bridge ? 26 : 23); i++) - for(j = 9; j < 35; j++) + for(short i = (is_bridge ? 15 : 19); i < (is_bridge ? 26 : 23); i++) + for(short j = 9; j < 35; j++) univ.town->terrain(i,j) = 82; } if(arena == 18 || arena == 19) { - for(i = 12; i < 15; i++) - for(j = 9; j < 35; j++) + for(short i = 12; i < 15; i++) + for(short j = 9; j < 35; j++) if(j != 17 && j != 26) univ.town->terrain(i,j) = ter_type; - for(i = 17; i < 20; i++) - for(j = 9; j < 35; j++) + for(short i = 17; i < 20; i++) + for(short j = 9; j < 35; j++) if(j != 17 && j != 26) univ.town->terrain(i,j) = ter_type; - for(i = 22; i < 25; i++) - for(j = 9; j < 35; j++) + for(short i = 22; i < 25; i++) + for(short j = 9; j < 35; j++) if(j != 17 && j != 26) univ.town->terrain(i,j) = ter_type; - for(i = 27; i < 30; i++) - for(j = 9; j < 35; j++) + for(short i = 27; i < 30; i++) + for(short j = 9; j < 35; j++) if(j != 17 && j != 26) univ.town->terrain(i,j) = ter_type; } @@ -988,71 +983,71 @@ void create_out_combat_terrain(short ter_type,short num_walls,bool is_road) { // Now place special lakes, etc. if(arena == 2 || arena == 15) - for(i = 0; i < 15; i++) + for(short i = 0; i < 15; i++) if(get_ran(1,0,5) == 1) { stuff_ul = special_ter_locs[i]; - for(j = 0; j < 4; j++) - for(k = 0; k < 4; k++) + for(short j = 0; j < 4; j++) + for(short k = 0; k < 4; k++) univ.town->terrain(stuff_ul.x + j,stuff_ul.y + k) = mntn_pillar[k][j]; } if(univ.town->terrain(0,0) == 0) - for(i = 0; i < 15; i++) + for(short i = 0; i < 15; i++) if(get_ran(1,0,25) == 1) { stuff_ul = special_ter_locs[i]; - for(j = 0; j < 4; j++) - for(k = 0; k < 4; k++) + for(short j = 0; j < 4; j++) + for(short k = 0; k < 4; k++) univ.town->terrain(stuff_ul.x + j,stuff_ul.y + k) = cave_pillar[k][j]; } if(univ.town->terrain(0,0) == 0) - for(i = 0; i < 15; i++) + for(short i = 0; i < 15; i++) if(get_ran(1,0,40) == 1) { stuff_ul = special_ter_locs[i]; - for(j = 0; j < 4; j++) - for(k = 0; k < 4; k++) + for(short j = 0; j < 4; j++) + for(short k = 0; k < 4; k++) univ.town->terrain(stuff_ul.x + j,stuff_ul.y + k) = cave_lake[k][j]; } if(univ.town->terrain(0,0) == 2) - for(i = 0; i < 15; i++) + for(short i = 0; i < 15; i++) if(get_ran(1,0,40) == 1) { stuff_ul = special_ter_locs[i]; - for(j = 0; j < 4; j++) - for(k = 0; k < 4; k++) + for(short j = 0; j < 4; j++) + for(short k = 0; k < 4; k++) univ.town->terrain(stuff_ul.x + j,stuff_ul.y + k) = surf_lake[k][j]; } if(arena == 14) - for(i = 0; i < 15; i++) + for(short i = 0; i < 15; i++) if(get_ran(1,0,5) == 1) { stuff_ul = special_ter_locs[i]; - for(j = 0; j < 4; j++) - for(k = 0; k < 4; k++) + for(short j = 0; j < 4; j++) + for(short k = 0; k < 4; k++) univ.town->terrain(stuff_ul.x + j,stuff_ul.y + k) = cave_fume[k][j]; } if(arena == 15) - for(i = 0; i < 15; i++) + for(short i = 0; i < 15; i++) if(get_ran(1,0,5) == 1) { stuff_ul = special_ter_locs[i]; - for(j = 0; j < 4; j++) - for(k = 0; k < 4; k++) + for(short j = 0; j < 4; j++) + for(short k = 0; k < 4; k++) univ.town->terrain(stuff_ul.x + j,stuff_ul.y + k) = surf_fume[k][j]; } if(arena == 16) { stuff_ul = loc(18,14); - for(j = 0; j < 4; j++) - for(k = 0; k < 4; k++) + for(short j = 0; j < 4; j++) + for(short k = 0; k < 4; k++) univ.town->terrain(stuff_ul.x + j,stuff_ul.y + k) = cave_camp[k][j]; } if(arena == 17) { stuff_ul = loc(18,14); - for(j = 0; j < 4; j++) - for(k = 0; k < 4; k++) + for(short j = 0; j < 4; j++) + for(short k = 0; k < 4; k++) univ.town->terrain(stuff_ul.x + j,stuff_ul.y + k) = surf_camp[k][j]; } if(ter_base[ter_type] == 0) { - for(i = 0; i < num_walls; i++) { + for(short i = 0; i < num_walls; i++) { r1 = get_ran(1,0,3); - for(j = 9; j < 35; j++) + for(short j = 9; j < 35; j++) switch(r1) { case 0: univ.town->terrain(j,8) = 6; @@ -1078,9 +1073,9 @@ void create_out_combat_terrain(short ter_type,short num_walls,bool is_road) { univ.town->terrain(8,35) = 20; } if(ter_base[ter_type] == 36) { - for(i = 0; i < num_walls; i++) { + for(short i = 0; i < num_walls; i++) { r1 = get_ran(1,0,3); - for(j = 9; j < 35; j++) + for(short j = 9; j < 35; j++) switch(r1) { case 0: univ.town->terrain(j,8) = 24; @@ -1113,12 +1108,10 @@ void create_out_combat_terrain(short ter_type,short num_walls,bool is_road) { void elim_monst(unsigned short which,short spec_a,short spec_b) { - short i; - if(!univ.party.sd_legit(spec_a,spec_b)) return; if(PSD[spec_a][spec_b] > 0) { - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].number == which) { univ.town.monst[i].active = 0; } @@ -1228,14 +1221,14 @@ void bash_door(location where,short pc_num) { void erase_specials() { location where; - short k,sd1,sd2; + short sd1,sd2; cSpecial sn; if((is_combat()) && (which_combat_type == 0)) return; if(!is_town() && !is_combat()) return; - for(k = 0; k < univ.town->special_locs.size(); k++) { + for(short k = 0; k < univ.town->special_locs.size(); k++) { if(univ.town->special_locs[k].spec < 0 || univ.town->special_locs[k].spec >= univ.town->specials.size()) continue; sn = univ.town->specials[univ.town->special_locs[k].spec]; @@ -1321,7 +1314,6 @@ void clear_map() { void draw_map(bool need_refresh) { if(!map_visible) return; - short i; pic_num_t pic; rectangle the_rect,map_world_rect = {0,0,384,384}; location where; @@ -1517,7 +1509,7 @@ void draw_map(bool need_refresh) { // Now place PCs and monsters if(draw_pcs) { if((is_town()) && (univ.party.status[ePartyStatus::DETECT_LIFE] > 0)) - for(i = 0; i < univ.town.monst.size(); i++) + for(short i = 0; i < univ.town.monst.size(); i++) if(univ.town.monst[i].active > 0) { where = univ.town.monst[i].cur_loc; if((is_explored(where.x,where.y)) && diff --git a/src/boe.townspec.cpp b/src/boe.townspec.cpp index bfe34242..690baec4 100644 --- a/src/boe.townspec.cpp +++ b/src/boe.townspec.cpp @@ -40,7 +40,7 @@ void activate_monster_enc(short enc_num,std::string list,short str,short strsnd, // 7 - level drain 8 - alert 9 - big flames 10 - dumbfound 11 - disease 1 // 12 - disease all bool run_trap(short pc_num,eTrapType trap_type,short trap_level,short diff) { - short r1,skill,i,num_hits = 1; + short r1,skill,num_hits = 1; short trap_odds[30] = {5,30,35,42,48, 55,63,69,75,77, 78,80,82,84,86, 88,90,92,94,96,98,99,99,99,99,99,99,99,99,99}; @@ -54,7 +54,7 @@ bool run_trap(short pc_num,eTrapType trap_type,short trap_level,short diff) { cPlayer& disarmer = univ.party[pc_num]; if(pc_num < 6) { - i = disarmer.stat_adj(eSkill::DEXTERITY); + int i = disarmer.stat_adj(eSkill::DEXTERITY); i += disarmer.get_prot_level(eItemAbil::THIEVING) / 2; skill = minmax(0,20,disarmer.skill(eSkill::DISARM_TRAPS) + + disarmer.skill(eSkill::LUCK) / 2 + 1 - univ.town.difficulty + 2 * i); @@ -74,7 +74,7 @@ bool run_trap(short pc_num,eTrapType trap_type,short trap_level,short diff) { switch(trap_type) { case TRAP_BLADE: - for(i = 0; i < num_hits; i++) { + for(short i = 0; i < num_hits; i++) { add_string_to_buf(" A knife flies out!"); r1 = get_ran(2 + univ.town.difficulty / 14,1,10); damage_pc(disarmer,r1,eDamageType::WEAPON,eRace::UNKNOWN,0); @@ -96,7 +96,7 @@ bool run_trap(short pc_num,eTrapType trap_type,short trap_level,short diff) { break; case TRAP_EXPLOSION: - for(i = 0; i < num_hits; i++) { + for(short i = 0; i < num_hits; i++) { add_string_to_buf(" There is an explosion."); r1 = get_ran(3 + univ.town.difficulty / 13,1,8); hit_party(r1,eDamageType::FIRE); @@ -161,9 +161,8 @@ bool run_trap(short pc_num,eTrapType trap_type,short trap_level,short diff) { location get_spec_loc(short which) { location where; - short i; - for(i = 0; i < univ.town->special_locs.size(); i++) + for(short i = 0; i < univ.town->special_locs.size(); i++) if(univ.town->special_locs[i].spec == which) return univ.town->special_locs[i]; return where; diff --git a/src/classes/outdoors.cpp b/src/classes/outdoors.cpp index 7224e6b3..c3a95caa 100644 --- a/src/classes/outdoors.cpp +++ b/src/classes/outdoors.cpp @@ -18,22 +18,21 @@ #include "scenario.hpp" void cOutdoors::append(legacy::outdoor_record_type& old){ - int i,j; ambient_sound = AMBIENT_NONE; // Collect a list of unused special nodes, to be used for fixing specials that could be triggered in a boat. std::vector unused_special_slots; - for(i = 0; i < 60; i++) { + for(short i = 0; i < 60; i++) { if(old.specials[i].type == 0 && old.specials[i].jumpto == -1) { // Also make sure no specials jump to it bool is_free = true; - for(j = 0; j < 60; j++) { + for(short j = 0; j < 60; j++) { if(old.specials[j].jumpto == i) is_free = false; } if(is_free) unused_special_slots.push_back(i); } } - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++){ + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++){ terrain[i][j] = old.terrain[i][j]; if(scenario->ter_types[terrain[i][j]].i == 3000) // marker to indicate it used to be a special spot special_spot[i][j] = true; @@ -69,7 +68,7 @@ void cOutdoors::append(legacy::outdoor_record_type& old){ } } special_locs.resize(18); - for(i = 0; i < 18; i++){ + for(short i = 0; i < 18; i++){ special_locs[i].x = old.special_locs[i].x; special_locs[i].y = old.special_locs[i].y; if(old.special_locs[i].x == 100) @@ -79,7 +78,7 @@ void cOutdoors::append(legacy::outdoor_record_type& old){ city_locs.resize(8); sign_locs.resize(8); info_rect.resize(8); - for(i = 0; i < 8; i++){ + for(short i = 0; i < 8; i++){ city_locs[i].x = old.exit_locs[i].x; city_locs[i].y = old.exit_locs[i].y; city_locs[i].spec = old.exit_dests[i]; @@ -90,14 +89,14 @@ void cOutdoors::append(legacy::outdoor_record_type& old){ info_rect[i].bottom = old.info_rect[i].bottom; info_rect[i].right = old.info_rect[i].right; } - for(i = 0; i < 4; i++){ + for(short i = 0; i < 4; i++){ wandering[i].append(old.wandering[i]); special_enc[i].append(old.special_enc[i]); wandering_locs[i].x = old.wandering_locs[i].x; wandering_locs[i].y = old.wandering_locs[i].y; } specials.resize(60); - for(i = 0; i < 60; i++) + for(short i = 0; i < 60; i++) specials[i].append(old.specials[i]); } @@ -109,19 +108,18 @@ cOutdoors::cWandering::cWandering() { } cOutdoors::cOutdoors(cScenario& scenario) : scenario(&scenario) { - short i,j; location locs[4] = {loc(8,8),loc(32,8),loc(8,32),loc(32,32)}; bg_out = bg_fight = bg_town = bg_dungeon = -1; out_sound = 0; - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++) { + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++) { terrain[i][j] = scenario.default_ground; special_spot[i][j] = false; roads[i][j] = false; } - for(i = 0; i < wandering_locs.size(); i++) { + for(short i = 0; i < wandering_locs.size(); i++) { wandering_locs[i] = locs[i]; } out_name = "Area name"; diff --git a/src/classes/party.cpp b/src/classes/party.cpp index 37ca4026..91016861 100644 --- a/src/classes/party.cpp +++ b/src/classes/party.cpp @@ -54,15 +54,14 @@ cParty::~cParty() { } void cParty::append(legacy::party_record_type& old, const cScenario& scen){ - int i,j; age = old.age; gold = old.gold; food = old.food; - for(i = 0; i < 310; i++) - for(j = 0; j < 10; j++) + for(short i = 0; i < 310; i++) + for(short j = 0; j < 10; j++) stuff_done[i][j] = old.stuff_done[i][j]; - for(i = 0; i < 200; i++) - for(j = 0; j < 8; j++) + for(short i = 0; i < 200; i++) + for(short j = 0; j < 8; j++) item_taken[i][j] = old.item_taken[i][j]; light_level = old.light_level; if(stuff_done[305][0] > 0) @@ -86,7 +85,7 @@ void cParty::append(legacy::party_record_type& old, const cScenario& scen){ left_in = -1; } party_event_timers.reserve(30); - for(i = 0; i < 30; i++){ + for(short i = 0; i < 30; i++){ boats[i].append(old.boats[i]); horses[i].append(old.horses[i]); cTimer t; @@ -95,23 +94,23 @@ void cParty::append(legacy::party_record_type& old, const cScenario& scen){ t.node = old.node_to_call[i]; party_event_timers.push_back(t); } - for(i = 0; i < 4; i++){ + for(short i = 0; i < 4; i++){ creature_save[i].append(old.creature_save[i]); imprisoned_monst[i] = old.imprisoned_monst[i]; } in_boat = old.in_boat; in_horse = old.in_horse; - for(i = 0; i < 10; i++){ + for(short i = 0; i < 10; i++){ out_c[i].append(old.out_c[i]); - for(j = 0; j < 5; j++) + for(short j = 0; j < 5; j++) magic_store_items[j][i].append(old.magic_store_items[j][i]); } - for(i = 0; i < 256; i++) + for(short i = 0; i < 256; i++) if(old.m_seen[i]) m_noted.insert(i); journal.reserve(50); // The journal wasn't used before, so let's not bother converting it -// for(i = 0; i < 50; i++){ +// for(short i = 0; i < 50; i++){ // cJournal j; // j.day = old.journal_day[i]; // journal.push_back(j); @@ -119,14 +118,14 @@ void cParty::append(legacy::party_record_type& old, const cScenario& scen){ // } if(!scen_name.empty()) { special_notes.reserve(140); - for(i = 0; i < 140; i++){ + for(short i = 0; i < 140; i++){ if(old.special_notes_str[i][0] <= 0) continue; cEncNote n; n.append(old.special_notes_str[i], scen); special_notes.push_back(n); } talk_save.reserve(120); - for(i = 0; i < 120; i++){ + for(short i = 0; i < 120; i++){ cConvers t; t.append(old.talk_save[i], scen); talk_save.push_back(t); @@ -134,15 +133,15 @@ void cParty::append(legacy::party_record_type& old, const cScenario& scen){ } direction = eDirection(old.direction); at_which_save_slot = old.at_which_save_slot; - for(i = 0; i < 20 ; i++) + for(short i = 0; i < 20 ; i++) alchemy[i] = old.alchemy[i]; can_find_town.resize(200); m_killed.resize(200); - for(i = 0; i < 200; i++){ + for(short i = 0; i < 200; i++){ can_find_town[i] = old.can_find_town[i]; m_killed[i] = old.m_killed[i]; } - for(i = 0; i < 100; i++) + for(short i = 0; i < 100; i++) key_times[i] = old.key_times[i]; total_m_killed = old.total_m_killed; total_dam_done = old.total_dam_done; @@ -513,13 +512,11 @@ bool cParty::take_abil(eItemAbil abil, short dat) { } bool cParty::check_class(unsigned int item_class,bool take) { - short i,j; - if(item_class == 0) return false; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(adven[i]->main_status == eMainStatus::ALIVE) - for(j = 23; j >= 0; j--) + for(short j = 23; j >= 0; j--) if(adven[i]->items[j].variety != eItemType::NO_ITEM && (adven[i]->items[j].special_class == item_class)) { if(take) { if(adven[i]->items[j].charges > 1) @@ -1073,8 +1070,6 @@ bool cParty::pc_present(short i) const { extern cUniverse univ; bool cParty::start_split(short x,short y,snd_num_t noise,short who) { - short i; - if(who >= 6 || who < 0) return false; if(is_split()) return false; @@ -1083,7 +1078,7 @@ bool cParty::start_split(short x,short y,snd_num_t noise,short who) { left_in = town_num; town_loc.x = x; town_loc.y = y; - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(i != who) adven[i]->main_status += eMainStatus::SPLIT; adven[i]->status[eStatus::FORCECAGE] = 0; @@ -1093,11 +1088,9 @@ bool cParty::start_split(short x,short y,snd_num_t noise,short who) { } bool cParty::end_split(snd_num_t noise) { - short i; - if(!is_split()) return false; - for(i = 0; i < 6; i++){ + for(short i = 0; i < 6; i++){ if(isSplit(univ.party[i].main_status)) univ.party[i].main_status -= eMainStatus::SPLIT; } diff --git a/src/classes/pc.cpp b/src/classes/pc.cpp index 45308427..e060f938 100644 --- a/src/classes/pc.cpp +++ b/src/classes/pc.cpp @@ -25,10 +25,9 @@ extern std::map excluding_types; extern short skill_bonus[21]; void cPlayer::append(legacy::pc_record_type old){ - int i; main_status = (eMainStatus) old.main_status; name = old.name; - for(i = 0; i < 19; i++) { + for(short i = 0; i < 19; i++) { eSkill skill = eSkill(i); skills[skill] = old.skills[i]; } @@ -40,16 +39,16 @@ void cPlayer::append(legacy::pc_record_type old){ skill_pts = old.skill_pts; level = old.level; // TODO: Why are advan and exp_adj commented out? - for(i = 0; i < 15; i++){ + for(short i = 0; i < 15; i++){ status[(eStatus) i] = old.status[i]; eTrait trait = eTrait(i); traits[trait] = old.traits[i]; } - for(i = 0; i < 24; i++){ + for(short i = 0; i < 24; i++){ items[i].append(old.items[i]); equip[i] = old.equip[i]; } - for(i = 0; i < 62; i++){ + for(short i = 0; i < 62; i++){ priest_spells[i] = old.priest_spells[i]; mage_spells[i] = old.mage_spells[i]; } @@ -830,7 +829,6 @@ void cPlayer::finish_create() { } cPlayer::cPlayer(cParty& party) : party(&party) { - short i; main_status = eMainStatus::ABSENT; name = "\n"; @@ -844,12 +842,12 @@ cPlayer::cPlayer(cParty& party) : party(&party) { experience = 0; skill_pts = 65; level = 1; - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) items[i] = cItem(); - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) equip[i] = false; - for(i = 0; i < 62; i++) { + for(short i = 0; i < 62; i++) { priest_spells[i] = i < 30; mage_spells[i] = i < 30; } @@ -864,7 +862,6 @@ cPlayer::cPlayer(cParty& party) : party(&party) { } cPlayer::cPlayer(cParty& party,long key,short slot) : cPlayer(party) { - short i; main_status = eMainStatus::ALIVE; unique_id = slot + 1000; party.next_pc_id = max(unique_id + 1, party.next_pc_id); @@ -892,7 +889,7 @@ cPlayer::cPlayer(cParty& party,long key,short slot) : cPlayer(party) { skills[eSkill::STRENGTH] = 20; skills[eSkill::DEXTERITY] = 20; skills[eSkill::INTELLIGENCE] = 20; - for(i = 3; i < 19; i++) { + for(short i = 3; i < 19; i++) { eSkill skill = eSkill(i); skills[skill] = 8; } @@ -903,9 +900,9 @@ cPlayer::cPlayer(cParty& party,long key,short slot) : cPlayer(party) { experience = 0; skill_pts = 60; level = 1; - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) items[i] = cItem(); - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) equip[i] = false; priest_spells.set(); @@ -914,7 +911,7 @@ cPlayer::cPlayer(cParty& party,long key,short slot) : cPlayer(party) { if(slot == 2) which_graphic++; weap_poisoned = 24; // was 16, as an E2 relic - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { eTrait trait = eTrait(i); traits[trait] = true; } @@ -985,7 +982,7 @@ cPlayer::cPlayer(cParty& party,long key,short slot) : cPlayer(party) { } - for(i = 0; i < 19; i++) { + for(short i = 0; i < 19; i++) { eSkill skill = eSkill(i); skills[skill] = pc_stats[slot][skill]; } @@ -995,17 +992,17 @@ cPlayer::cPlayer(cParty& party,long key,short slot) : cPlayer(party) { skill_pts = 0; level = 1; - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) items[i] = cItem(); - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) equip[i] = false; cur_sp = pc_sp[slot]; max_sp = pc_sp[slot]; - for(i = 0; i < 62; i++) { + for(short i = 0; i < 62; i++) { priest_spells[i] = i < 30; mage_spells[i] = i < 30; } - for(i = 0; i < 15; i++) { + for(short i = 0; i < 15; i++) { eTrait trait = eTrait(i); traits[trait] = pc_t[slot].count(trait); } diff --git a/src/classes/regtown.cpp b/src/classes/regtown.cpp index 10857c46..3d72de64 100644 --- a/src/classes/regtown.cpp +++ b/src/classes/regtown.cpp @@ -19,24 +19,23 @@ #include "fileio.hpp" void cTinyTown::append(legacy::tiny_tr_type& old, int){ - int i,j; cField the_field, the_road; the_field.type = SPECIAL_SPOT; the_road.type = SPECIAL_ROAD; // Collect a list of unused special nodes, to be used for fixing specials that could be triggered in a boat. std::vector unused_special_slots; - for(i = 0; i < 100; i++) { + for(short i = 0; i < 100; i++) { if(specials[i].type == eSpecType::NONE && specials[i].jumpto == -1) { // Also make sure no specials jump to it bool is_free = true; - for(j = 0; j < 100; j++) { + for(short j = 0; j < 100; j++) { if(specials[j].jumpto == i) is_free = false; } if(is_free) unused_special_slots.push_back(i); } } - for(i = 0; i < 32; i++) - for(j = 0; j < 32; j++) { + for(short i = 0; i < 32; i++) + for(short j = 0; j < 32; j++) { ter[i][j] = old.terrain[i][j]; light[i / 8][j] = old.lighting[i / 8][j]; if(scenario->ter_types[ter[i][j]].i == 3000) { // marker to indicate it used to be a special spot @@ -106,37 +105,36 @@ void cTinyTown::append(legacy::tiny_tr_type& old, int){ } } room_rect.resize(16); - for(i = 0; i < 16; i++) { + for(short i = 0; i < 16; i++) { room_rect[i].top = old.room_rect[i].top; room_rect[i].left = old.room_rect[i].left; room_rect[i].bottom = old.room_rect[i].bottom; room_rect[i].right = old.room_rect[i].right; } creatures.resize(30); - for(i = 0; i < 30; i++) { + for(short i = 0; i < 30; i++) { creatures[i].append(old.creatures[i]); } } void cMedTown::append(legacy::ave_tr_type& old, int){ - int i,j; cField the_field, the_road; the_field.type = SPECIAL_SPOT; the_road.type = SPECIAL_ROAD; // Collect a list of unused special nodes, to be used for fixing specials that could be triggered in a boat. std::vector unused_special_slots; - for(i = 0; i < 100; i++) { + for(short i = 0; i < 100; i++) { if(specials[i].type == eSpecType::NONE && specials[i].jumpto == -1) { // Also make sure no specials jump to it bool is_free = true; - for(j = 0; j < 100; j++) { + for(short j = 0; j < 100; j++) { if(specials[j].jumpto == i) is_free = false; } if(is_free) unused_special_slots.push_back(i); } } - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++) { + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++) { ter[i][j] = old.terrain[i][j]; light[i / 8][j] = old.lighting[i / 8][j]; if(scenario->ter_types[ter[i][j]].i == 3000) { // marker to indicate it used to be a special spot @@ -206,37 +204,36 @@ void cMedTown::append(legacy::ave_tr_type& old, int){ } } room_rect.resize(16); - for(i = 0; i < 16; i++) { + for(short i = 0; i < 16; i++) { room_rect[i].top = old.room_rect[i].top; room_rect[i].left = old.room_rect[i].left; room_rect[i].bottom = old.room_rect[i].bottom; room_rect[i].right = old.room_rect[i].right; } creatures.resize(40); - for(i = 0; i < 40; i++) { + for(short i = 0; i < 40; i++) { creatures[i].append(old.creatures[i]); } } void cBigTown::append(legacy::big_tr_type& old, int){ - int i,j; cField the_field, the_road; the_field.type = SPECIAL_SPOT; the_road.type = SPECIAL_ROAD; // Collect a list of unused special nodes, to be used for fixing specials that could be triggered in a boat. std::vector unused_special_slots; - for(i = 0; i < 100; i++) { + for(short i = 0; i < 100; i++) { if(specials[i].type == eSpecType::NONE && specials[i].jumpto == -1) { // Also make sure no specials jump to it bool is_free = true; - for(j = 0; j < 100; j++) { + for(short j = 0; j < 100; j++) { if(specials[j].jumpto == i) is_free = false; } if(is_free) unused_special_slots.push_back(i); } } - for(i = 0; i < 64; i++) - for(j = 0; j < 64; j++) { + for(short i = 0; i < 64; i++) + for(short j = 0; j < 64; j++) { ter[i][j] = old.terrain[i][j]; light[i / 8][j] = old.lighting[i / 8][j]; if(scenario->ter_types[ter[i][j]].i == 3000) { // marker to indicate it used to be a special spot @@ -306,14 +303,14 @@ void cBigTown::append(legacy::big_tr_type& old, int){ } } room_rect.resize(16); - for(i = 0; i < 16; i++) { + for(short i = 0; i < 16; i++) { room_rect[i].top = old.room_rect[i].top; room_rect[i].left = old.room_rect[i].left; room_rect[i].bottom = old.room_rect[i].bottom; room_rect[i].right = old.room_rect[i].right; } creatures.resize(60); - for(i = 0; i < 60; i++) { + for(short i = 0; i < 60; i++) { creatures[i].append(old.creatures[i]); } } diff --git a/src/classes/scenario.cpp b/src/classes/scenario.cpp index c8206c4e..d9afdd30 100644 --- a/src/classes/scenario.cpp +++ b/src/classes/scenario.cpp @@ -58,7 +58,6 @@ cScenario& cScenario::operator=(cScenario&& other) { } cScenario::cScenario() { - short i; std::string temp_str; format.ver[0] = 1; @@ -78,13 +77,13 @@ cScenario::cScenario() { bg_fight = 4; bg_town = 13; bg_dungeon = 9; - for(i = 0; i < town_mods.size(); i++) { + for(short i = 0; i < town_mods.size(); i++) { town_mods[i].spec = -1; } - for(i = 0; i < 3; i++) { + for(short i = 0; i < 3; i++) { store_item_towns[i] = -1; } - for(i = 0; i < scenario_timers.size(); i++) { + for(short i = 0; i < scenario_timers.size(); i++) { scenario_timers[i].node = -1; } scen_name = "Scen name"; @@ -103,7 +102,6 @@ cScenario::cItemStorage::cItemStorage() : ter_type(-1), property(0) { void cScenario::append(legacy::scenario_data_type& old){ is_legacy = true; - int i; difficulty = old.difficulty; intro_pic = old.intro_pic; default_ground = old.default_ground * 2; @@ -115,14 +113,14 @@ void cScenario::append(legacy::scenario_data_type& old){ out_start.x = old.out_start.x; out_start.y = old.out_start.y; which_town_start = old.which_town_start; - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { town_mods[i].spec = old.town_to_add_to[i]; town_mods[i].x = old.flag_to_add_to_town[i][0]; town_mods[i].y = old.flag_to_add_to_town[i][1]; storage_shortcuts[i] = old.storage_shortcuts[i]; } // TODO: Combine store_item_rects and store_item_towns into a structure - for(i = 0; i < 3; i++) { + for(short i = 0; i < 3; i++) { store_item_rects[i].top = old.store_item_rects[i].top; store_item_rects[i].left = old.store_item_rects[i].left; store_item_rects[i].bottom = old.store_item_rects[i].bottom; @@ -130,27 +128,27 @@ void cScenario::append(legacy::scenario_data_type& old){ store_item_towns[i] = old.store_item_towns[i]; } special_items.resize(50); - for(i = 0; i < 50; i++) { + for(short i = 0; i < 50; i++) { special_items[i].flags = old.special_items[i]; special_items[i].special = old.special_item_special[i]; } rating = eContentRating(old.rating); // TODO: Is this used anywhere? uses_custom_graphics = old.uses_custom_graphics; - for(i = 0; i < 30; i++) { + for(short i = 0; i < 30; i++) { boats[i].append(old.scen_boats[i]); horses[i].append(old.scen_horses[i]); } ter_types.resize(256); scen_specials.resize(256); scen_monsters.resize(256); - for(i = 0; i < 256; i++){ + for(short i = 0; i < 256; i++){ ter_types[i].i = i; ter_types[i].append(old.ter_types[i]); scen_monsters[i].append(old.scen_monsters[i]); scen_specials[i].append(old.scen_specials[i]); } - for(i = 0; i < 20; i++) { + for(short i = 0; i < 20; i++) { scenario_timers[i].time = old.scenario_timer_times[i]; scenario_timers[i].node = old.scenario_timer_specs[i]; } @@ -169,22 +167,21 @@ cScenario::cItemStorage& cScenario::cItemStorage::operator = (legacy::item_stora } void cScenario::append(legacy::scen_item_data_type& old){ - short i; scen_items.resize(400); - for(i = 0; i < 400; i++) + for(short i = 0; i < 400; i++) scen_items[i].append(old.scen_items[i]); - for(i = 0; i < 256; i++) { + for(short i = 0; i < 256; i++) { scen_monsters[i].m_name = old.monst_names[i]; if(scen_monsters[i].m_type == eRace::UNDEAD && scen_monsters[i].m_name.find("Skeleton") != std::string::npos) scen_monsters[i].m_type = eRace::SKELETAL; if(scen_monsters[i].m_type == eRace::HUMANOID && scen_monsters[i].m_name.find("Goblin") != std::string::npos) scen_monsters[i].m_type = eRace::GOBLIN; } - for(i = 0; i < 256; i++) + for(short i = 0; i < 256; i++) ter_types[i].name = old.ter_names[i]; // Some default shops - the five magic shops and the healing shop. cShop magic_shop('junk'); - for(i = 0; i < 5; i++) + for(short i = 0; i < 5; i++) shops.push_back(magic_shop); shops.push_back(cShop('heal')); } diff --git a/src/classes/talking.cpp b/src/classes/talking.cpp index 85bd6cf8..0b02adcc 100644 --- a/src/classes/talking.cpp +++ b/src/classes/talking.cpp @@ -16,11 +16,10 @@ #include "oldstructs.hpp" void cSpeech::append(legacy::talking_record_type& old, std::vector& shops){ - int i,j; talk_nodes.resize(60); - for(i = 0; i < 60; i++){ + for(short i = 0; i < 60; i++){ talk_nodes[i].personality = old.talk_nodes[i].personality; - for(j = 0; j < 4; j++){ + for(short j = 0; j < 4; j++){ talk_nodes[i].link1[j] = old.talk_nodes[i].link1[j]; talk_nodes[i].link2[j] = old.talk_nodes[i].link2[j]; talk_nodes[i].extras[j] = old.talk_nodes[i].extras[j]; diff --git a/src/classes/town.cpp b/src/classes/town.cpp index 2ea72eef..e570d593 100644 --- a/src/classes/town.cpp +++ b/src/classes/town.cpp @@ -22,10 +22,9 @@ void cTown::append(legacy::ave_tr_type&, int){} void cTown::append(legacy::tiny_tr_type&, int){} void cTown::append(legacy::town_record_type& old){ - int i; town_chop_time = old.town_chop_time; town_chop_key = old.town_chop_key; - for(i = 0; i < 4; i++){ + for(short i = 0; i < 4; i++){ start_locs[i].x = old.start_locs[i].x; start_locs[i].y = old.start_locs[i].y; exits[i].x = old.exit_locs[i].x; @@ -36,7 +35,7 @@ void cTown::append(legacy::town_record_type& old){ preset_fields.clear(); preset_fields.reserve(50); special_locs.resize(50); - for(i = 0; i < 50; i++){ + for(short i = 0; i < 50; i++){ special_locs[i].x = old.special_locs[i].x; special_locs[i].y = old.special_locs[i].y; if(old.special_locs[i].x == 100) @@ -47,7 +46,7 @@ void cTown::append(legacy::town_record_type& old){ preset_fields.push_back(temp); } sign_locs.resize(15); - for(i = 0; i < 15; i++){ + for(short i = 0; i < 15; i++){ sign_locs[i].x = old.sign_locs[i].x; sign_locs[i].y = old.sign_locs[i].y; } @@ -57,36 +56,35 @@ void cTown::append(legacy::town_record_type& old){ in_town_rect.bottom = old.in_town_rect.bottom; in_town_rect.right = old.in_town_rect.right; preset_items.resize(64); - for(i = 0; i < 64; i++){ + for(short i = 0; i < 64; i++){ preset_items[i].append(old.preset_items[i]); } max_num_monst = old.max_num_monst; spec_on_entry = old.spec_on_entry; spec_on_entry_if_dead = old.spec_on_entry_if_dead; spec_on_hostile = -1; - for(i = 0; i < 8; i++){ + for(short i = 0; i < 8; i++){ timers[i].time = old.timer_spec_times[i]; timers[i].node = old.timer_specs[i]; } specials.resize(100); - for(i = 0; i < 100; i++) + for(short i = 0; i < 100; i++) specials[i].append(old.specials[i]); difficulty = old.difficulty; strong_barriers = defy_scrying = defy_mapping = false; } cTown::cTown(cScenario& scenario) : scenario(&scenario) { - short i; cTown::cWandering d_wan = {0,0,0,0}; town_chop_time = -1; town_chop_key = -1; - for(i = 0; i < wandering.size(); i++) { + for(short i = 0; i < wandering.size(); i++) { wandering[i] = d_wan; wandering_locs[i].x = 100; } lighting_type = LIGHT_NORMAL; - for(i = 0; i < 4; i++) { + for(short i = 0; i < 4; i++) { start_locs[i].x = 100; exits[i].spec = -1; exits[i].x = -1; @@ -96,7 +94,7 @@ cTown::cTown(cScenario& scenario) : scenario(&scenario) { spec_on_entry = -1; spec_on_entry_if_dead = -1; spec_on_hostile = -1; - for(i = 0; i < 8; i++) { + for(short i = 0; i < 8; i++) { timers[i].time = 0; timers[i].node = -1; } diff --git a/src/classes/universe.cpp b/src/classes/universe.cpp index c8fd5f34..440f66d8 100644 --- a/src/classes/universe.cpp +++ b/src/classes/universe.cpp @@ -39,21 +39,20 @@ void cCurTown::append(legacy::current_town_type& old){ } void cCurTown::append(legacy::big_tr_type& old){ - int i,j; - for(i = 0; i < record()->max_dim(); i++) - for(j = 0; j < record()->max_dim(); j++) + for(short i = 0; i < record()->max_dim(); i++) + for(short j = 0; j < record()->max_dim(); j++) record()->terrain(i,j) = old.terrain[i][j]; - for(i = 0; i < 16; i++){ + for(short i = 0; i < 16; i++){ record()->room_rect[i].top = old.room_rect[i].top; record()->room_rect[i].left = old.room_rect[i].left; record()->room_rect[i].bottom = old.room_rect[i].bottom; record()->room_rect[i].right = old.room_rect[i].right; } record()->creatures.resize(60); - for(i = 0; i < 60; i++) + for(short i = 0; i < 60; i++) record()->creatures[i].append(old.creatures[i]); - for(i = 0; i < record()->max_dim() / 8; i++) - for(j = 0; j < record()->max_dim(); j++) + for(short i = 0; i < record()->max_dim() / 8; i++) + for(short j = 0; j < record()->max_dim(); j++) record()->lighting(i,j) = old.lighting[i][j]; } diff --git a/src/pcedit/pc.action.cpp b/src/pcedit/pc.action.cpp index 2f1a2830..0ef0ed96 100644 --- a/src/pcedit/pc.action.cpp +++ b/src/pcedit/pc.action.cpp @@ -30,8 +30,6 @@ extern rectangle pc_race_rect; extern rectangle edit_rect[5]; bool handle_action(sf::Event event) { - short i; - location the_point; bool to_return = false; @@ -41,14 +39,14 @@ bool handle_action(sf::Event event) { if(file_in_mem.empty()) return false; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if((the_point.in(pc_area_buttons[i][0])) && (univ.party[i].main_status != eMainStatus::ABSENT)) { do_button_action(0,i); current_active_pc = i; redraw_screen(); } - for(i = 0; i < 5; i++) + for(short i = 0; i < 5; i++) if((the_point.in(edit_rect[i])) && (univ.party[current_active_pc].main_status != eMainStatus::ABSENT)) { do_button_action(0,i + 10); @@ -71,13 +69,13 @@ bool handle_action(sf::Event event) { break; } } - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) if((the_point.in(item_string_rects[i][1])) && // drop item univ.party[current_active_pc].items[i].variety != eItemType::NO_ITEM) { flash_rect(item_string_rects[i][1]); univ.party[current_active_pc].take_item(i); } - for(i = 0; i < 24; i++) + for(short i = 0; i < 24; i++) if((the_point.in(item_string_rects[i][2])) && // identify item univ.party[current_active_pc].items[i].variety != eItemType::NO_ITEM) { flash_rect(item_string_rects[i][2]); diff --git a/src/pcedit/pc.editors.cpp b/src/pcedit/pc.editors.cpp index fc574f04..21d563a5 100644 --- a/src/pcedit/pc.editors.cpp +++ b/src/pcedit/pc.editors.cpp @@ -60,10 +60,9 @@ const char* skill_ids[19] = { }; static void put_pc_spells(cDialog& me, short store_trait_mode) { - short i; store_trait_mode %= 10; - for(i = 0; i < 62; i++) { + for(short i = 0; i < 62; i++) { std::string id = "spell" + boost::lexical_cast(i + 1); cLed& cur = dynamic_cast(me[id]); if(((store_trait_mode == 0) && univ.party[which_pc_displayed].mage_spells[i]) || @@ -99,7 +98,6 @@ static bool display_pc_event_filter(cDialog& me, std::string item_hit, const sho void display_pc(short pc_num,short mode, cDialog* parent) { using namespace std::placeholders; - short i; std::string label_str; if(univ.party[pc_num].main_status == eMainStatus::ABSENT) { @@ -114,7 +112,7 @@ void display_pc(short pc_num,short mode, cDialog* parent) { cDialog pcInfo("pc-spell-info", parent); pcInfo.attachClickHandlers(std::bind(display_pc_event_filter, _1, _2, mode),{"done","left","right"}); - for(i = 0; i < 62; i++) { + for(short i = 0; i < 62; i++) { std::string id = "spell" + boost::lexical_cast(i + 1); label_str = get_str("magic-names", i + (mode % 10 == 0 ? 1 : 101)); pcInfo[id].setText(label_str); @@ -129,18 +127,18 @@ void display_pc(short pc_num,short mode, cDialog* parent) { } static void display_traits_graphics(cDialog& me) { - short i,store; + short store; if(store_pc->race <= eRace::VAHNATAI) { std::string race = "race" + boost::lexical_cast(int(store_pc->race) + 1); dynamic_cast(me["race"]).setSelected(race); } - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { std::string id = "good" + boost::lexical_cast(i + 1); eTrait trait = eTrait(i); dynamic_cast(me[id]).setState(store_pc->traits[trait] ? led_red : led_off); } - for(i = 0; i < 7; i++) { + for(short i = 0; i < 7; i++) { std::string id = "bad" + boost::lexical_cast(i + 1); eTrait trait = eTrait(i + 10); dynamic_cast(me[id]).setState(store_pc->traits[trait] ? led_red : led_off); @@ -232,13 +230,11 @@ extern const eItemAbil alch_ingred2[20] = { }; void display_alchemy(bool allowEdit,cDialog* parent) { - short i; - make_cursor_sword(); cChoiceDlog showAlch("pc-alchemy-info", {"done"}, parent); - for(i = 0; i < 20; i++) { + for(short i = 0; i < 20; i++) { std::string id = "potion" + boost::lexical_cast(i + 1); std::string name = get_str("magic-names", i + 200) + " ("; name += std::to_string(alch_difficulty[i]); @@ -255,7 +251,7 @@ void display_alchemy(bool allowEdit,cDialog* parent) { showAlch.show(); if(!allowEdit) return; - for(i = 0; i < 20; i++) { + for(short i = 0; i < 20; i++) { std::string id = "potion" + boost::lexical_cast(i + 1); cLed& led = dynamic_cast(showAlch->getControl(id)); if(led.getState() == led_red) univ.party.alchemy[i] = true; @@ -336,9 +332,8 @@ static bool can_change_skill(eSkill skill, xp_dlog_state& save, bool increase) { } static void draw_xp_skills(cDialog& me,xp_dlog_state& save) { - short i; // TODO: Wouldn't it make more sense for it to be red when you can't buy the skill rather than red when you can? - for(i = 0; i < 19; i++) { + for(short i = 0; i < 19; i++) { cControl& cur = me[skill_ids[i]]; eSkill skill = eSkill(i); if(can_change_skill(skill, save, true)) diff --git a/src/pcedit/pc.graphics.cpp b/src/pcedit/pc.graphics.cpp index f10f79a8..8694b913 100644 --- a/src/pcedit/pc.graphics.cpp +++ b/src/pcedit/pc.graphics.cpp @@ -49,9 +49,6 @@ cCustomGraphics spec_scen_g; // not actually needed; just here to silence compil // (actually, it WILL be needed eventually) void init_main_buttons() { - - short i; - rectangle base_rect; // Initialize pc_info_rect in center @@ -69,7 +66,7 @@ void init_main_buttons() { pc_area_buttons[0][0].top=pc_info_rect.top; pc_area_buttons[0][0].bottom=pc_area_buttons[0][0].top + 56; - for(i=0; i<6; i++) { + for(short i = 0; i < 6; i++) { pc_area_buttons[i][0].left = 20; pc_area_buttons[i][0].right = pc_area_buttons[0][0].left + 56; pc_area_buttons[i][2].left = 20; @@ -91,7 +88,7 @@ void init_main_buttons() { } // Initialize the edit_rect buttons edit_rect[0].top = pc_info_rect.top; - for(i = 0; i < 5; i++) { + for(short i = 0; i < 5; i++) { edit_rect[i].top = edit_rect[0].top + 66*i; edit_rect[i].bottom = edit_rect[i].top + 53; edit_rect[i].left = 510; @@ -127,7 +124,7 @@ void init_main_buttons() { base_rect.right = name_rect.right - 1; base_rect.bottom = base_rect.top + (pc_info_rect.bottom - skill_rect.bottom)/30; - for(i = 0; i < 19; i++) { + for(short i = 0; i < 19; i++) { pc_skills_rect[i] = base_rect; pc_skills_rect[i].offset((i / 10) * ((name_rect.right)-(name_rect.left)), (i % 10) * (pc_info_rect.bottom - name_rect.bottom)/30); } @@ -142,7 +139,7 @@ void init_main_buttons() { base_rect.left = status_rect.left + 1; base_rect.right = name_rect.right - 1; base_rect.bottom = base_rect.top + (pc_info_rect.bottom - status_rect.bottom)/15; - for(i = 0; i < 14; i++) { + for(short i = 0; i < 14; i++) { pc_status_rect[i] = base_rect; pc_status_rect[i].offset((i / 7) * ((name_rect.right)-(name_rect.left)), (i % 7) * 9); } @@ -159,7 +156,7 @@ void init_main_buttons() { base_rect.left = traits_rect.left + 1; base_rect.right = name_rect.right - 1; base_rect.bottom = base_rect.top + 10; - for(i = 0; i < 16; i++) { + for(short i = 0; i < 16; i++) { pc_traits_rect[i] = base_rect; pc_traits_rect[i].offset((i / 8) * ((name_rect.right)-(name_rect.left)), (i % 8) * 9); } @@ -170,11 +167,11 @@ void init_main_buttons() { item_string_rects[0][0].left = pc_info_rect.left + (pc_info_rect.right - pc_info_rect.left)/2 + 2; item_string_rects[0][0].right = pc_info_rect.right; item_string_rects[0][0].bottom = item_string_rects[0][0].top + 12; - for(i = 1; i < 24; i++) { + for(short i = 1; i < 24; i++) { item_string_rects[i][0] = item_string_rects[0][0]; item_string_rects[i][0].offset(0,13 * i); } - for(i = 0; i < 24; i++) { + for(short i = 0; i < 24; i++) { item_string_rects[i][1] = item_string_rects[i][0]; item_string_rects[i][1].right -= 14; item_string_rects[i][1].left = item_string_rects[i][1].right - 14; @@ -311,7 +308,6 @@ void do_button_action(short /*which_pc*/,short which_button) { //short clear_first; // 0 - redraw over, 1 - don't redraw over void draw_items() { - short i; rectangle d_from = {12,28,24,42},i_from = {12,42,24,56},dest_rect; if(file_in_mem.empty()) // save file loaded @@ -333,7 +329,7 @@ void draw_items() { return; // If PC is dead, it has no items } sf::Texture& invenbtn_gworld = *ResMgr::get("invenbtns"); - for(i = 0; i < 24; i++) // Loop through items and draw each + for(short i = 0; i < 24; i++) // Loop through items and draw each if(univ.party[current_active_pc].items[i].variety != eItemType::NO_ITEM) { // i.e. does item exist std::string to_draw = std::to_string(i + 1) + ". "; if(!univ.party[current_active_pc].items[i].ident) @@ -362,7 +358,7 @@ void draw_items() { //short mode; // 0 - 5 this pc, 6 - all //short clear_first; // 1 - redraw over what's already there, 0 - don't redraw over void display_party() { - short i,k,string_num, cur_rect=0; + short string_num, cur_rect=0; rectangle from_rect,no_party_rect,temp_rect; TextStyle style; @@ -381,7 +377,7 @@ void display_party() { win_draw_string(mainPtr,from_rect,"Party not in a scenario.",eTextMode::WRAP,style); else win_draw_string(mainPtr,from_rect,"Party is in a scenario (day " + std::to_string(1 + univ.party.age / 3700) + ").",eTextMode::WRAP,style); - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { if(i == current_active_pc) // active pc is drawn in blue fill_rect(mainPtr, pc_area_buttons[i][0], sf::Color::Blue); else fill_rect(mainPtr, pc_area_buttons[i][0], sf::Color::Black); @@ -454,7 +450,7 @@ void display_party() { style.font = FONT_PLAIN; style.lineHeight = 9; string_num=1; - for( k = 0; k < 19 ; ++k) { + for(short k = 0; k < 19 ; ++k) { temp_rect = pc_skills_rect[k]; temp_rect.left = pc_skills_rect[k].left + 80; if(k < 10) temp_rect.left += 4; @@ -585,7 +581,7 @@ void display_party() { style.pointSize = 10; style.font = FONT_BOLD; win_draw_string(mainPtr,traits_rect,"Traits:",eTextMode::WRAP,style); - //for(k = 0 ; k < 16; k++) + //for(short k = 0 ; k < 16; k++) //frame_dlog_rect(GetWindowPort(mainPtr),pc_traits_rect[k],0); style.pointSize = 9; style.font = FONT_PLAIN; @@ -743,7 +739,7 @@ void display_party() { } // Closes the for i=6 loop style.lineHeight = 16; - for(i = 0; i < 5; i++) { + for(short i = 0; i < 5; i++) { from_rect = (current_pressed_button == i + 10) ? ed_buttons_from[1] : ed_buttons_from[0]; rect_draw_some_item(buttons_gworld,from_rect,mainPtr,edit_rect[i]); style.colour = sf::Color::White; diff --git a/src/pcedit/pc.main.cpp b/src/pcedit/pc.main.cpp index 5a062538..fec9a98c 100644 --- a/src/pcedit/pc.main.cpp +++ b/src/pcedit/pc.main.cpp @@ -163,8 +163,8 @@ static void display_strings(short nstr, pic_num_t pic) { } void handle_menu_choice(eMenu item_hit) { - int i,j,k; fs::path file; + bool result; switch(item_hit) { case eMenu::NONE: break; case eMenu::ABOUT: @@ -178,11 +178,11 @@ void handle_menu_choice(eMenu item_hit) { if(!file.empty()) save_party(file, univ); break; case eMenu::FILE_OPEN: - i = verify_restore_quit("save-open"); + result = verify_restore_quit("save-open"); if(false) case eMenu::FILE_REVERT: - i = cChoiceDlog("save-revert", {"okay", "cancel"}).show() == "okay"; - if(i) { + result = cChoiceDlog("save-revert", {"okay", "cancel"}).show() == "okay"; + if(result) { file = item_hit == eMenu::FILE_OPEN ? nav_get_party() : file_in_mem; if(!file.empty()) { if(load_party(file, univ)) { @@ -231,7 +231,7 @@ void handle_menu_choice(eMenu item_hit) { } cChoiceDlog("reunited").show(); univ.party.town_loc = univ.party.left_at; - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status >= eMainStatus::SPLIT) univ.party[i].main_status -= eMainStatus::SPLIT; break; @@ -244,17 +244,17 @@ void handle_menu_choice(eMenu item_hit) { break; case eMenu::HEAL_DAMAGE: display_strings(1,15); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) univ.party[i].cur_health = univ.party[i].max_health; break; case eMenu::RESTORE_MANA: display_strings(2,15); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) univ.party[i].cur_sp = univ.party[i].max_sp; break; case eMenu::RAISE_DEAD: display_strings(3,15); - for(i = 0; i < 6; i++) + for(short i = 0; i < 6; i++) if(univ.party[i].main_status == eMainStatus::DEAD || univ.party[i].main_status == eMainStatus::DUST || univ.party[i].main_status == eMainStatus::STONE) univ.party[i].main_status = eMainStatus::ALIVE; @@ -275,9 +275,9 @@ void handle_menu_choice(eMenu item_hit) { break; case eMenu::OWN_VEHICLES: display_strings(6,7); - for(i = 0; i < univ.party.boats.size(); i++) + for(short i = 0; i < univ.party.boats.size(); i++) univ.party.boats[i].property = false; - for(i = 0; i < univ.party.horses.size(); i++) + for(short i = 0; i < univ.party.horses.size(); i++) univ.party.horses[i].property = false; break; case eMenu::EDIT_DAY: @@ -285,16 +285,16 @@ void handle_menu_choice(eMenu item_hit) { break; case eMenu::ADD_OUT_MAPS: display_strings(13,15); - for(i = 0; i < 100; i++) - for(j = 0; j < 6; j++) - for(k = 0; k < 48; k++) + for(short i = 0; i < 100; i++) + for(short j = 0; j < 6; j++) + for(short k = 0; k < 48; k++) univ.out_maps[i][j][k] = 255; break; case eMenu::ADD_TOWN_MAPS: display_strings(14,15); - for(i = 0; i < 200; i++) - for(j = 0; j < 8; j++) - for(k = 0; k < 64; k++) + for(short i = 0; i < 200; i++) + for(short j = 0; j < 8; j++) + for(short k = 0; k < 64; k++) univ.town_maps[i][j][k] = 255; break; case eMenu::EDIT_MAGE: diff --git a/src/scenedit/scen.actions.cpp b/src/scenedit/scen.actions.cpp index c0595ace..dc2bff6b 100644 --- a/src/scenedit/scen.actions.cpp +++ b/src/scenedit/scen.actions.cpp @@ -108,16 +108,14 @@ void init_current_terrain() { } void init_screen_locs() { - int i; - - for(i = 0; i < 4; i++) + for(short i = 0; i < 4; i++) border_rect[i] = terrain_rect; border_rect[0].bottom = border_rect[0].top + 8; border_rect[1].right = border_rect[1].left + 8; border_rect[2].top = border_rect[2].bottom - 8; border_rect[3].left = border_rect[3].right - 8; - for(i = 0; i < 256; i++) { + for(short i = 0; i < 256; i++) { terrain_rects[i] = terrain_rect_base; terrain_rects[i].offset(3 + (i % 16) * (terrain_rect_base.right + 1), 3 + (i / 16) * (terrain_rect_base.bottom + 1)); @@ -698,7 +696,6 @@ static bool handle_rb_action(location the_point, bool option_hit) { } static bool handle_terrain_action(location the_point, bool ctrl_hit) { - int x, i; if(mouse_spot.x >= 0 && mouse_spot.y >= 0) { if(cur_viewing_mode == 0) { spot_hit.x = cen_x + mouse_spot.x - 4; @@ -773,35 +770,19 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { change_made = true; } else { // MODE_ROOM_RECT - if(editing_town) { - for(x = 0; x < town->room_rect.size(); x++) - if(town->room_rect[x].right == 0) { - static_cast(town->room_rect[x]) = working_rect; - town->room_rect[x].descr = ""; - if(!edit_area_rect_str(x,1)) - town->room_rect[x].right = 0; - break; - } - if(x == town->room_rect.size()) { - town->room_rect.emplace_back(working_rect); - if(!edit_area_rect_str(x,1)) - town->room_rect.pop_back(); - } - } - else { - for(x = 0; x < current_terrain->info_rect.size(); x++) - if(current_terrain->info_rect[x].right == 0) { - static_cast(current_terrain->info_rect[x]) = working_rect; - current_terrain->info_rect[x].descr = ""; - if(!edit_area_rect_str(x,0)) - current_terrain->info_rect[x].right = 0; - break; - } - if(x == current_terrain->info_rect.size()) { - current_terrain->info_rect.emplace_back(working_rect); - if(!edit_area_rect_str(x,0)) - current_terrain->info_rect.pop_back(); - } + auto& room_rects = editing_town ? town->room_rect : current_terrain->info_rect; + auto iter = std::find_if(room_rects.begin(), room_rects.end(), [](const info_rect_t& r) { + return r.right == 0; + }); + if(iter != room_rects.end()) { + static_cast(*iter) = working_rect; + iter->descr = ""; + if(!edit_area_rect_str(*iter)) + iter->right = 0; + } else { + room_rects.emplace_back(working_rect); + if(!edit_area_rect_str(room_rects.back())) + room_rects.pop_back(); } change_made = true; } @@ -863,24 +844,24 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { break; case MODE_PLACE_ITEM: // If we just placed this item there, forget it - if(mouse_button_held && store_place_item.loc == spot_hit) - break; - mouse_button_held = true; - for(x = 0; x < town->preset_items.size(); x++) - if(town->preset_items[x].code < 0) { - town->preset_items[x] = {spot_hit, mode_count, scenario.scen_items[mode_count]}; - if(container_there(spot_hit)) town->preset_items[x].contained = true; - store_place_item = town->preset_items[x]; - break; + if(!mouse_button_held || store_place_item.loc != spot_hit) { + mouse_button_held = true; + auto iter = std::find_if(town->preset_items.begin(), town->preset_items.end(), [](const cTown::cItem& item) { + return item.code < 0; + }); + if(iter != town->preset_items.end()) { + *iter = {spot_hit, mode_count, scenario.scen_items[mode_count]}; + if(container_there(spot_hit)) iter->contained = true; + store_place_item = *iter; + } else { + town->preset_items.push_back({spot_hit, mode_count, scenario.scen_items[mode_count]}); + if(container_there(spot_hit)) town->preset_items.back().contained = true; + store_place_item = town->preset_items.back(); } - if(x == town->preset_items.size()) { - town->preset_items.push_back({spot_hit, mode_count, scenario.scen_items[mode_count]}); - if(container_there(spot_hit)) town->preset_items.back().contained = true; - store_place_item = town->preset_items.back(); } break; case MODE_EDIT_ITEM: - for(x = 0; x < town->preset_items.size(); x++) + for(short x = 0; x < town->preset_items.size(); x++) if((spot_hit.x == town->preset_items[x].loc.x) && (spot_hit.y == town->preset_items[x].loc.y) && (town->preset_items[x].code >= 0)) { edit_placed_item(x); @@ -891,34 +872,34 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { case MODE_PLACE_SAME_CREATURE: if(last_placed_monst.number == 0) { showError("Either no monster has been placed, or the last time you tried to place a monster the operation failed."); - break; - } - for(i = 0; i < town->creatures.size(); i++) - if(town->creatures[i].number == 0) { - town->creatures[i] = last_placed_monst; - town->creatures[i].start_loc = spot_hit; - break; + } else { + auto iter = std::find_if(town->creatures.begin(), town->creatures.end(), [](const cTownperson& who) { + return who.number == 0; + }); + if(iter != town->creatures.end()) { + *iter = last_placed_monst; + iter->start_loc = spot_hit; + } else { // Placement failed + town->creatures.push_back(last_placed_monst); + town->creatures.back().start_loc = spot_hit; } - if(i == town->creatures.size()) { // Placement failed - town->creatures.push_back(last_placed_monst); - town->creatures.back().start_loc = spot_hit; } overall_mode = MODE_DRAWING; break; case MODE_PLACE_CREATURE: // If we just placed this same creature here, forget it - if(mouse_button_held && last_placed_monst.start_loc == spot_hit) - break; - mouse_button_held = true; - for(i = 0; i < town->creatures.size(); i++) - if(town->creatures[i].number == 0) { - town->creatures[i] = {spot_hit, static_cast(mode_count), scenario.scen_monsters[mode_count]}; - last_placed_monst = town->creatures[i]; - break; + if(!mouse_button_held || last_placed_monst.start_loc != spot_hit) { + mouse_button_held = true; + auto iter = std::find_if(town->creatures.begin(), town->creatures.end(), [](const cTownperson& who) { + return who.number == 0; + }); + if(iter != town->creatures.end()) { + *iter = {spot_hit, static_cast(mode_count), scenario.scen_monsters[mode_count]}; + last_placed_monst = *iter; + } else { // Placement failed + town->creatures.push_back({spot_hit, static_cast(mode_count), scenario.scen_monsters[mode_count]}); + last_placed_monst = town->creatures.back(); } - if(i == town->creatures.size()) { // Placement failed - town->creatures.push_back({spot_hit, static_cast(mode_count), scenario.scen_monsters[mode_count]}); - last_placed_monst = town->creatures.back(); } break; @@ -1000,49 +981,38 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { case MODE_PLACE_SAME_ITEM: if(store_place_item.code < 0) { showError("Either no item has been placed, or the last time you tried to place an item the operation failed."); - break; - } - for(x = 0; x < town->preset_items.size(); x++) - if(town->preset_items[x].code < 0) { - town->preset_items[x] = store_place_item; - town->preset_items[x].loc = spot_hit; - town->preset_items[x].contained = container_there(spot_hit); - break; + } else { + auto iter = std::find_if(town->preset_items.begin(), town->preset_items.end(), [](const cTown::cItem& item) { + return item.code < 0; + }); + if(iter != town->preset_items.end()) { + *iter = store_place_item; + iter->loc = spot_hit; + iter->contained = container_there(spot_hit); + } else { + town->preset_items.push_back(store_place_item); + town->preset_items.back().loc = spot_hit; + town->preset_items.back().contained = container_there(spot_hit); } - if(x == town->preset_items.size()) { - town->preset_items.push_back(store_place_item); - town->preset_items.back().loc = spot_hit; - town->preset_items.back().contained = container_there(spot_hit); } overall_mode = MODE_DRAWING; break; case MODE_EDIT_SIGN: //edit sign - if(editing_town) { - for(x = 0; x < town->sign_locs.size(); x++) - if((town->sign_locs[x].x == spot_hit.x) && (town->sign_locs[x].y == spot_hit.y)) { - edit_sign(x,scenario.ter_types[town->terrain(spot_hit.x,spot_hit.y)].picture); - break; - } - if(x == town->sign_locs.size()) { - town->sign_locs.emplace_back(spot_hit); - edit_sign(x,scenario.ter_types[town->terrain(spot_hit.x,spot_hit.y)].picture); - } - } - if(!editing_town) { - for(x = 0; x < current_terrain->sign_locs.size(); x++) - if((current_terrain->sign_locs[x].x == spot_hit.x) && (current_terrain->sign_locs[x].y == spot_hit.y)) { - edit_sign(x,scenario.ter_types[current_terrain->terrain[spot_hit.x][spot_hit.y]].picture); - x = 30; - } - if(x == current_terrain->sign_locs.size()) { - current_terrain->sign_locs.emplace_back(spot_hit); - edit_sign(x,scenario.ter_types[town->terrain(spot_hit.x,spot_hit.y)].picture); - } + { + auto& signs = editing_town ? town->sign_locs : current_terrain->sign_locs; + auto iter = std::find(signs.begin(), signs.end(), spot_hit); + short picture = scenario.ter_types[editing_town ? town->terrain(spot_hit.x,spot_hit.y) : current_terrain->terrain[spot_hit.x][spot_hit.y]].picture; + if(iter != signs.end()) { + edit_sign(*iter, iter - signs.begin(), picture); + } else { + signs.emplace_back(spot_hit); + edit_sign(signs.back(), signs.size() - 1, picture); } overall_mode = MODE_DRAWING; break; + } case MODE_EDIT_CREATURE: //edit monst - for(x = 0; x < town->creatures.size(); x++) + for(short x = 0; x < town->creatures.size(); x++) if(monst_on_space(spot_hit,x)) { edit_placed_monst(x); last_placed_monst = town->creatures[x]; @@ -1054,53 +1024,31 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { overall_mode = MODE_DRAWING; break; case MODE_COPY_SPECIAL: //copy special - if(editing_town) { - for(x = 0; x < town->special_locs.size(); x++) - if(town->special_locs[x] == spot_hit && town->special_locs[x].spec >= 0) { - copied_spec = town->special_locs[x].spec; - x = -1; - break; - } - } - if(!editing_town) { - for(x = 0; x < current_terrain->special_locs.size(); x++) - if(current_terrain->special_locs[x] == spot_hit && current_terrain->special_locs[x].spec >= 0) { - copied_spec = current_terrain->special_locs[x].spec; - x = -1; - break; - } - } - if(x != -1) - showError("There wasn't a special on that spot."); + { + auto& specials = editing_town ? town->special_locs : current_terrain->special_locs; + auto iter = std::find_if(town->special_locs.begin(), town->special_locs.end(), [](const spec_loc_t& loc) { + return loc == spot_hit && loc.spec >= 0; + }); + if(iter != specials.end()) + copied_spec = iter->spec; + else showError("There wasn't a special on that spot."); overall_mode = MODE_DRAWING; break; + } case MODE_PASTE_SPECIAL: //paste special if(copied_spec < 0) { showError("You need to select a special to copy first."); + } else if(!editing_town && (spot_hit.x == 0 || spot_hit.x == 47 || spot_hit.y == 0 || spot_hit.y == 47)) { + cChoiceDlog("not-at-edge").show(); break; - } - if(editing_town) { - for(x = 0; x <= town->special_locs.size(); x++) { - if(x == town->special_locs.size()) - town->special_locs.emplace_back(-1,-1,-1); - if(town->special_locs[x].spec < 0) { - town->special_locs[x] = spot_hit; - town->special_locs[x].spec = copied_spec; - break; - } - } - } - if(!editing_town) { - if((spot_hit.x == 0) || (spot_hit.x == 47) || (spot_hit.y == 0) || (spot_hit.y == 47)) { - cChoiceDlog("not-at-edge").show(); - break; - } - for(x = 0; x <= current_terrain->special_locs.size(); x++) { - if(x == current_terrain->special_locs.size()) - current_terrain->special_locs.emplace_back(-1,-1,-1); - if(current_terrain->special_locs[x].spec < 0) { - current_terrain->special_locs[x] = spot_hit; - current_terrain->special_locs[x].spec = copied_spec; + } else { + auto& specials = editing_town ? town->special_locs : current_terrain->special_locs; + for(short x = 0; x <= specials.size(); x++) { + if(x == specials.size()) + specials.emplace_back(-1,-1,-1); + if(specials[x].spec < 0) { + specials[x] = spot_hit; + specials[x].spec = copied_spec; break; } } @@ -1108,36 +1056,23 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { overall_mode = MODE_DRAWING; break; case MODE_ERASE_SPECIAL: //erase special - if(editing_town) { - for(x = 0; x < town->special_locs.size(); x++) - if(town->special_locs[x] == spot_hit && town->special_locs[x].spec >= 0) { - town->special_locs[x] = {-1,-1}; - town->special_locs[x].spec = -1; - if(x == town->special_locs.size() - 1) { - // Delete not only the last entry but any other empty entries at the end of the list - do { - town->special_locs.pop_back(); - } while(town->special_locs.back().spec < 0); - } - break; + { + auto& specials = editing_town ? town->special_locs : current_terrain->special_locs; + for(short x = 0; x < specials.size(); x++) + if(specials[x] == spot_hit && specials[x].spec >= 0) { + specials[x] = {-1,-1}; + specials[x].spec = -1; + if(x == specials.size() - 1) { + // Delete not only the last entry but any other empty entries at the end of the list + do { + specials.pop_back(); + } while(specials.back().spec < 0); } - } - if(!editing_town) { - for(x = 0; x < current_terrain->special_locs.size(); x++) - if(current_terrain->special_locs[x] == spot_hit && current_terrain->special_locs[x].spec >= 0) { - current_terrain->special_locs[x] = {-1,-1}; - current_terrain->special_locs[x].spec = -1; - if(x == current_terrain->special_locs.size() - 1) { - // Delete not only the last entry but any other empty entries at the end of the list - do { - current_terrain->special_locs.pop_back(); - } while(current_terrain->special_locs.back().spec < 0); - } - break; - } - } + break; + } overall_mode = MODE_DRAWING; break; + } case MODE_PLACE_SPECIAL: //edit special set_special(spot_hit); overall_mode = MODE_DRAWING; @@ -1147,7 +1082,7 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { overall_mode = MODE_DRAWING; break; case MODE_ERASE_TOWN_ENTRANCE: - for(x = current_terrain->city_locs.size() - 1; x >= 0; x--) { + for(short x = current_terrain->city_locs.size() - 1; x >= 0; x--) { if(current_terrain->city_locs[x] == spot_hit) current_terrain->city_locs.erase(current_terrain->city_locs.begin() + x); } @@ -1166,7 +1101,7 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { change_made = true; break; case MODE_ERASE_CREATURE: //delete monst - for(x = 0; x < town->creatures.size(); x++) + for(short x = 0; x < town->creatures.size(); x++) if(monst_on_space(spot_hit,x)) { town->creatures[x].number = 0; break; @@ -1176,7 +1111,7 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { overall_mode = MODE_DRAWING; break; case MODE_ERASE_ITEM: // delete item - for(x = 0; x < town->preset_items.size(); x++) + for(short x = 0; x < town->preset_items.size(); x++) if((spot_hit.x == town->preset_items[x].loc.x) && (spot_hit.y == town->preset_items[x].loc.y) && (town->preset_items[x].code >= 0)) { town->preset_items[x].code = -1; @@ -1631,13 +1566,13 @@ void flash_rect(rectangle /*to_flash*/) { void swap_terrain() { - short a,b,c,i,j; + short a,b,c; ter_num_t ter; if(!change_ter(a,b,c)) return; - for(i = 0; i < ((editing_town) ? town->max_dim() : 48); i++) - for(j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) { + for(short i = 0; i < ((editing_town) ? town->max_dim() : 48); i++) + for(short j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) { ter = editing_town ? town->terrain(i,j) : current_terrain->terrain[i][j]; if((ter == a) && (get_ran(1,1,100) <= c)) { if(editing_town) @@ -1678,14 +1613,14 @@ void handle_keystroke(sf::Event event) { location pass_point; Key chr2 = event.key.code; char chr; - short i,j,store_ter; + short store_ter; obscureCursor(); if(overall_mode >= MODE_MAIN_SCREEN) return; - for(i = 0; i < 10; i++) + for(short i = 0; i < 10; i++) if(chr2 == keypad[i] || (i % 2 == 0 && i > 0 && chr2 == arrows[i / 2 - 1])) { if(i == 0) { chr = 'z'; @@ -1779,7 +1714,7 @@ void handle_keystroke(sf::Event event) { handle_action(pass_point,event); break; case 'I': - for(i = 0; i < town->preset_items.size(); i++) { + for(short i = 0; i < town->preset_items.size(); i++) { if((town->preset_items[i].loc.x < 0) || (town->preset_items[i].loc.y < 0)) town->preset_items[i].code = -1; @@ -1807,9 +1742,9 @@ void handle_keystroke(sf::Event event) { default: if(chr >= 'a' && chr <= 'z') { - for(i = 0; i < scenario.ter_types.size(); i++) { - j = current_terrain_type + i + 1; - j = j % scenario.ter_types.size(); + for(short i = 0; i < scenario.ter_types.size(); i++) { + int j = current_terrain_type + i + 1; + j %= scenario.ter_types.size(); if(scenario.ter_types[j].shortcut_key == chr) { set_new_terrain(j); place_location(); @@ -1852,10 +1787,9 @@ void handle_scroll(sf::Event& event) { void change_circle_terrain(location center,short radius,ter_num_t terrain_type,short probability) { // prob is 0 - 20, 0 no, 20 always location l; - short i,j; - for(i = 0; i < ((editing_town) ? town->max_dim() : 48); i++) - for(j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) { + for(short i = 0; i < ((editing_town) ? town->max_dim() : 48); i++) + for(short j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) { l.x = i; l.y = j; if((dist(center,l) <= radius) && (get_ran(1,1,20) <= probability)) @@ -1866,10 +1800,9 @@ void change_circle_terrain(location center,short radius,ter_num_t terrain_type,s void change_rect_terrain(rectangle r,ter_num_t terrain_type,short probability,bool hollow) { // prob is 0 - 20, 0 no, 20 always location l; - short i,j; - for(i = 0; i < ((editing_town) ? town->max_dim() : 48); i++) - for(j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) { + for(short i = 0; i < ((editing_town) ? town->max_dim() : 48); i++) + for(short j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) { l.x = i; l.y = j; if((i >= r.left) && (i <= r.right) && (j >= r.top) && (j <= r.bottom) @@ -1906,11 +1839,10 @@ void flood_fill_terrain(location start, ter_num_t terrain_type) { } void frill_up_terrain() { - short i,j; ter_num_t terrain_type; - for(i = 0; i < ((editing_town) ? town->max_dim() : 48); i++) - for(j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) { + for(short i = 0; i < ((editing_town) ? town->max_dim() : 48); i++) + for(short j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) { terrain_type = editing_town ? town->terrain(i,j) : current_terrain->terrain[i][j]; for(size_t k = 0; k < scenario.ter_types.size(); k++) { @@ -1928,11 +1860,10 @@ void frill_up_terrain() { } void unfrill_terrain() { - short i,j; ter_num_t terrain_type; - for(i = 0; i < ((editing_town) ? town->max_dim() : 48); i++) - for(j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) { + for(short i = 0; i < ((editing_town) ? town->max_dim() : 48); i++) + for(short j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) { terrain_type = editing_town ? town->terrain(i,j) : current_terrain->terrain[i][j]; cTerrain& ter = scenario.ter_types[terrain_type]; @@ -1983,22 +1914,16 @@ static const std::array trim_diffs = {{ }}; void set_terrain(location l,ter_num_t terrain_type) { - short i,j,which_sign = -1; - ter_num_t ter; location l2; - i = l.x; - j = l.y; - //if((l.x < 0) || (l.x > town->max_dim() - 1) || (l.y < 0) || (l.y > town->max_dim() - 1)) - // return; - if((editing_town) && ((i < 0) || (i > town->max_dim() - 1) || (j < 0) || (j > town->max_dim() - 1))) + if((editing_town) && ((l.x < 0) || (l.x > town->max_dim() - 1) || (l.y < 0) || (l.y > town->max_dim() - 1))) return ; - if(!editing_town && ((i < 0) || (i > 47) || (j < 0) || (j > 47))) + if(!editing_town && ((l.x < 0) || (l.x > 47) || (l.y < 0) || (l.y > 47))) return ; if(editing_town) - town->terrain(i,j) = terrain_type; - else current_terrain->terrain[i][j] = terrain_type; + town->terrain(l.x,l.y) = terrain_type; + else current_terrain->terrain[l.x][l.y] = terrain_type; l2 = l; // Large objects (eg rubble) @@ -2008,8 +1933,8 @@ void set_terrain(location l,ter_num_t terrain_type) { location obj_dim = scenario.ter_types[terrain_type].obj_size; while(obj_loc.x > 0) l2.x-- , obj_loc.x--; while(obj_loc.y > 0) l2.y-- , obj_loc.y--; - for(i = 0; i < obj_dim.x; i++) - for(j = 0; j < obj_dim.y; j++){ + for(short i = 0; i < obj_dim.x; i++) + for(short j = 0; j < obj_dim.y; j++){ if(editing_town) town->terrain(l2.x + i,l2.y + j) = find_object_part(q,i,j,terrain_type); else current_terrain->terrain[l2.x + i][l2.y + j] = find_object_part(q,i,j,terrain_type); @@ -2048,57 +1973,28 @@ void set_terrain(location l,ter_num_t terrain_type) { adjust_space(l3); } - if(scenario.ter_types[terrain_type].special == eTerSpec::IS_A_SIGN && editing_town) { - for(i = 0; i < town->sign_locs.size(); i++) - if(which_sign < 0) { - if((town->sign_locs[i].x == l.x) && (town->sign_locs[i].y == l.y)) - which_sign = i; - } - if(which_sign < 0) { - for(i = 0; i < town->sign_locs.size(); i++) - if(town->sign_locs[i].x == 100) - which_sign = i; - else { - ter = town->terrain(town->sign_locs[i].x,town->sign_locs[i].y); - if(scenario.ter_types[ter].special != eTerSpec::IS_A_SIGN) - which_sign = i; - } - } - if(which_sign < 0) { - which_sign = town->sign_locs.size(); - town->sign_locs.emplace_back(); - } - static_cast(town->sign_locs[which_sign]) = l; - edit_sign(which_sign,scenario.ter_types[terrain_type].picture); - mouse_button_held = false; - } - if(scenario.ter_types[terrain_type].special == eTerSpec::IS_A_SIGN && !editing_town) { - if((l.x == 0) || (l.x == 47) || (l.y == 0) || (l.y == 47)) { + if(scenario.ter_types[terrain_type].special == eTerSpec::IS_A_SIGN) { + if(!editing_town && (l.x == 0 || l.x == 47 || l.y == 0 || l.y == 47)) { cChoiceDlog("not-at-edge").show(); mouse_button_held = false; return; } - for(i = 0; i < current_terrain->sign_locs.size(); i++) - if(which_sign < 0) { - if((current_terrain->sign_locs[i].x == l.x) && (current_terrain->sign_locs[i].y == l.y)) - which_sign = i; + auto& signs = editing_town ? town->sign_locs : current_terrain->sign_locs; + auto iter = std::find(signs.begin(), signs.end(), l); + if(iter == signs.end()) { + iter = std::find_if(signs.begin(), signs.end(), [](const sign_loc_t& sign) { + if(sign.x == 100) return true; + ter_num_t ter = editing_town ? town->terrain(sign.x,sign.y) : current_terrain->terrain[sign.x][sign.y]; + return scenario.ter_types[ter].special != eTerSpec::IS_A_SIGN; + }); + if(iter == signs.end()) { + signs.emplace_back(); + iter = signs.end() - 1; } - if(which_sign < 0) { - for(i = 0; i < current_terrain->sign_locs.size(); i++) - if(current_terrain->sign_locs[i].x == 100) - which_sign = i; - else { - ter = current_terrain->terrain[current_terrain->sign_locs[i].x][current_terrain->sign_locs[i].y]; - if(scenario.ter_types[ter].special != eTerSpec::IS_A_SIGN) - which_sign = i; - } } - if(which_sign < 0) { - which_sign = current_terrain->sign_locs.size(); - current_terrain->sign_locs.emplace_back(); - } - static_cast(current_terrain->sign_locs[which_sign]) = l; - edit_sign(which_sign,scenario.ter_types[terrain_type].picture); + static_cast(*iter) = l; + ter_num_t terrain_type = editing_town ? town->terrain(iter->x,iter->y) : current_terrain->terrain[iter->x][iter->y]; + edit_sign(*iter, iter - signs.begin(), scenario.ter_types[terrain_type].picture); mouse_button_held = false; } } @@ -2212,15 +2108,13 @@ void adjust_space(location l) { bool place_item(location spot_hit,short which_item,bool property,bool always,short odds) { // odds 0 - 100, with 100 always - short x; - if((which_item < 0) || (which_item >= scenario.scen_items.size())) return true; if(scenario.scen_items[which_item].variety == eItemType::NO_ITEM) return true; if(get_ran(1,1,100) > odds) return false; - for(x = 0; x < town->preset_items.size(); x++) + for(short x = 0; x < town->preset_items.size(); x++) if(town->preset_items[x].code < 0) { town->preset_items[x] = {spot_hit, which_item, scenario.scen_items[which_item]}; town->preset_items[x].contained = container_there(spot_hit); @@ -2237,16 +2131,14 @@ bool place_item(location spot_hit,short which_item,bool property,bool always,sho void place_items_in_town() { location l; - short i,j,k,x; - - for(i = 0; i < town->max_dim(); i++) - for(j = 0; j < town->max_dim(); j++) { + for(short i = 0; i < town->max_dim(); i++) + for(short j = 0; j < town->max_dim(); j++) { l.x = i; l.y = j; - for(k = 0; k < 10; k++) + for(short k = 0; k < 10; k++) if(town->terrain(i,j) == scenario.storage_shortcuts[k].ter_type) { - for(x = 0; x < 10; x++) + for(short x = 0; x < 10; x++) place_item(l,scenario.storage_shortcuts[k].item_num[x], scenario.storage_shortcuts[k].property,false, scenario.storage_shortcuts[k].item_odds[x]); @@ -2256,149 +2148,91 @@ void place_items_in_town() { } void place_edit_special(location loc) { - short i,spec; - + if(!editing_town && (loc.x == 0 || loc.x == 47 || loc.y == 0 || loc.y == 47)) { + cChoiceDlog("not-at-edge").show(); + return; + } + auto& specials = editing_town ? town->special_locs : current_terrain->special_locs; if(editing_town) { - for(i = 0; i < town->special_locs.size(); i++) - if(town->special_locs[i] == loc && town->special_locs[i].spec >= 0) { - edit_spec_enc(town->special_locs[i].spec,2,nullptr); - break; + for(short i = 0; i < specials.size(); i++) + if(specials[i] == loc && specials[i].spec >= 0) { + edit_spec_enc(specials[i].spec, editing_town ? 2 : 1, nullptr); + return; } - if(i == town->special_locs.size()) { // new special - spec = get_fresh_spec(2); - for(i = 0; i <= town->special_locs.size(); i++) { - if(i == town->special_locs.size()) - town->special_locs.emplace_back(-1,-1,-1); - if(town->special_locs[i].spec < 0) { - if(edit_spec_enc(spec,2,nullptr)) { - town->special_locs[i] = loc; - town->special_locs[i].spec = spec; - } - break; + // new special + short spec = get_fresh_spec(editing_town ? 2 : 1); + for(short i = 0; i <= specials.size(); i++) { + if(i == specials.size()) + specials.emplace_back(-1,-1,-1); + if(specials[i].spec < 0) { + if(edit_spec_enc(spec, editing_town ? 2: 1, nullptr)) { + specials[i] = loc; + specials[i].spec = spec; } + break; } } } - - if(!editing_town) { - if((loc.x == 0) || (loc.x == 47) || (loc.y == 0) || (loc.y == 47)) { - cChoiceDlog("not-at-edge").show(); - return; - } - for(i = 0; i < current_terrain->special_locs.size(); i++) - if(current_terrain->special_locs[i] == loc && current_terrain->special_locs[i].spec >= 0) { - edit_spec_enc(current_terrain->special_locs[i].spec,1,nullptr); - break; - } - if(i == current_terrain->special_locs.size()) { // new special - spec = get_fresh_spec(1); - for(i = 0; i <= current_terrain->special_locs.size(); i++) { - if(i == current_terrain->special_locs.size()) - current_terrain->special_locs.emplace_back(-1,-1,-1); - if(current_terrain->special_locs[i].spec < 0) { - if(edit_spec_enc(spec,1,nullptr)) { - current_terrain->special_locs[i] = loc; - current_terrain->special_locs[i].spec = spec; - } - break; - } - } - } - } - } void set_special(location spot_hit) { - short x,y; - - if(editing_town) { - for(x = 0; x < town->special_locs.size(); x++) - if(town->special_locs[x] == spot_hit && town->special_locs[x].spec >= 0) { - y = edit_special_num(2,town->special_locs[x].spec); - if(y >= 0) town->special_locs[x].spec = y; - break; - } - if(x == town->special_locs.size()) { - for(x = 0; x <= town->special_locs.size(); x++) { - if(x == town->special_locs.size()) - town->special_locs.emplace_back(-1,-1,-1); - if(town->special_locs[x].spec < 0) { - y = edit_special_num(2,0); - if(y >= 0) { - town->special_locs[x] = spot_hit; - town->special_locs[x].spec = y; - } - break; - } - } - } + if(!editing_town && (spot_hit.x == 0 || spot_hit.x == 47 || spot_hit.y == 0 || spot_hit.y == 47)) { + cChoiceDlog("not-at-edge").show(); + return; } - if(!editing_town) { - if((spot_hit.x == 0) || (spot_hit.x == 47) || (spot_hit.y == 0) || (spot_hit.y == 47)) { - cChoiceDlog("not-at-edge").show(); + auto& specials = editing_town ? town->special_locs : current_terrain->special_locs; + for(short x = 0; x < specials.size(); x++) + if(specials[x] == spot_hit && specials[x].spec >= 0) { + int spec = edit_special_num(editing_town ? 2 : 1,specials[x].spec); + if(spec >= 0) specials[x].spec = spec; return; } - for(x = 0; x < current_terrain->special_locs.size(); x++) - if(current_terrain->special_locs[x] == spot_hit && current_terrain->special_locs[x].spec >= 0) { - y = edit_special_num(1,current_terrain->special_locs[x].spec); - if(y >= 0) current_terrain->special_locs[x].spec = y; - break; - } - if(x == current_terrain->special_locs.size()) { - for(x = 0; x <= current_terrain->special_locs.size(); x++) { - if(x == current_terrain->special_locs.size()) - current_terrain->special_locs.emplace_back(-1,-1,-1); - if(current_terrain->special_locs[x].spec < 0) { - y = edit_special_num(1,current_terrain->special_locs[x].spec); - if(y >= 0) { - current_terrain->special_locs[x] = spot_hit; - current_terrain->special_locs[x].spec = y; - } - break; - } + for(short x = 0; x <= specials.size(); x++) { + if(x == specials.size()) + specials.emplace_back(-1,-1,-1); + if(specials[x].spec < 0) { + int spec = edit_special_num(editing_town ? 2 : 1, 0); + if(spec >= 0) { + specials[x] = spot_hit; + specials[x].spec = spec; } + break; } } - } void town_entry(location spot_hit) { - short x,y; - ter_num_t ter; - - ter = current_terrain->terrain[spot_hit.x][spot_hit.y]; + ter_num_t ter = current_terrain->terrain[spot_hit.x][spot_hit.y]; if(scenario.ter_types[ter].special != eTerSpec::TOWN_ENTRANCE) { showError("This space isn't a town entrance. Town entrances are marked by a small brown castle icon."); return; } // clean up old town entries - for(x = 0; x < current_terrain->city_locs.size(); x++) + for(short x = 0; x < current_terrain->city_locs.size(); x++) if(current_terrain->city_locs[x].spec >= 0) { ter = current_terrain->terrain[current_terrain->city_locs[x].x][current_terrain->city_locs[x].y]; if(scenario.ter_types[ter].special != eTerSpec::TOWN_ENTRANCE) current_terrain->city_locs[x].spec = -1; } - y = -2; - for(x = 0; x < current_terrain->city_locs.size(); x++) - if(current_terrain->city_locs[x] == spot_hit) { - y = pick_town_num("select-town-enter",current_terrain->city_locs[x].spec,scenario); - if(y >= 0) current_terrain->city_locs[x].spec = y; - } - if(y == -2) { - for(x = 0; x < current_terrain->city_locs.size(); x++) - if(current_terrain->city_locs[x].spec < 0) { - y = pick_town_num("select-town-enter",0,scenario); - if(y >= 0) { - current_terrain->city_locs[x].spec = y; - current_terrain->city_locs[x] = spot_hit; - } - x = 500; + auto iter = std::find(current_terrain->city_locs.begin(), current_terrain->city_locs.end(), spot_hit); + if(iter != current_terrain->city_locs.end()) { + int town = pick_town_num("select-town-enter",iter->spec,scenario); + if(town >= 0) iter->spec = town; + } else { + iter = std::find_if(current_terrain->city_locs.begin(), current_terrain->city_locs.end(), [](const spec_loc_t& loc) { + return loc.spec < 0; + }); + if(iter != current_terrain->city_locs.end()) { + int town = pick_town_num("select-town-enter",0,scenario); + if(town >= 0) { + *iter = spot_hit; + iter->spec = town; } - if(y == -2) { - y = pick_town_num("select-town-enter",0,scenario); - if(y >= 0) { + } else { + int town = pick_town_num("select-town-enter",0,scenario); + if(town >= 0) { current_terrain->city_locs.emplace_back(spot_hit); - current_terrain->city_locs.back().spec = y; + current_terrain->city_locs.back().spec = town; } } } @@ -2482,7 +2316,6 @@ void set_up_main_screen() { } void start_town_edit() { - short i,j; std::ostringstream strb; small_any_drawn = false; cen_x = town->max_dim() / 2; @@ -2503,8 +2336,8 @@ void start_town_edit() { set_string("Drawing mode",scenario.ter_types[current_terrain_type].name); place_location(); copied_spec = -1; - for(i = 0; i < town->max_dim(); i++) - for(j = 0; j < town->max_dim(); j++) + for(short i = 0; i < town->max_dim(); i++) + for(short j = 0; j < town->max_dim(); j++) if(town->terrain(i,j) == 0) current_ground = 0; else if(town->terrain(i,j) == 2) @@ -2513,7 +2346,6 @@ void start_town_edit() { } void start_out_edit() { - short i,j; std::ostringstream strb; small_any_drawn = false; cen_x = 24; @@ -2535,8 +2367,8 @@ void start_out_edit() { set_string("Drawing mode",scenario.ter_types[current_terrain_type].name); place_location(); copied_spec = -1; - for(i = 0; i < 48; i++) - for(j = 0; j < 48; j++) + for(short i = 0; i < 48; i++) + for(short j = 0; j < 48; j++) if(current_terrain->terrain[i][j] == 0) current_ground = 0; else if(current_terrain->terrain[i][j] == 2) @@ -2559,7 +2391,6 @@ void start_terrain_editing() { void start_monster_editing(bool just_redo_text) { int num_options = scenario.scen_monsters.size() + 1; - short i; if(!just_redo_text) { overall_mode = MODE_MAIN_SCREEN; @@ -2570,7 +2401,7 @@ void start_monster_editing(bool just_redo_text) { reset_rb(); right_sbar->setMaximum(num_options - 1 - NRSONPAGE); } - for(i = 1; i < num_options; i++) { + for(short i = 1; i < num_options; i++) { std::string title; if(i == scenario.scen_monsters.size()) title = "Create New Monster"; @@ -2585,7 +2416,6 @@ void start_monster_editing(bool just_redo_text) { void start_item_editing(bool just_redo_text) { int num_options = scenario.scen_items.size() + 1; - short i; bool draw_full = false; if(!just_redo_text) { @@ -2601,7 +2431,7 @@ void start_item_editing(bool just_redo_text) { reset_rb(); right_sbar->setMaximum(num_options - NRSONPAGE); } - for(i = 0; i < num_options; i++) { + for(short i = 0; i < num_options; i++) { std::string title; if(i == scenario.scen_items.size()) title = "Create New Item"; @@ -2616,7 +2446,6 @@ void start_item_editing(bool just_redo_text) { void start_special_item_editing(bool just_redo_text) { int num_options = scenario.special_items.size() + 1; - short i; if(!just_redo_text) { if(overall_mode < MODE_MAIN_SCREEN) @@ -2629,7 +2458,7 @@ void start_special_item_editing(bool just_redo_text) { reset_rb(); right_sbar->setMaximum(num_options - NRSONPAGE); } - for(i = 0; i < num_options; i++) { + for(short i = 0; i < num_options; i++) { std::string title; if(i == scenario.special_items.size()) title = "Create New Special Item"; @@ -2816,7 +2645,6 @@ void start_special_editing(short mode,short just_redo_text) { // if restoring is 1, this is just a redraw, so don't move scroll bar position void start_dialogue_editing(short restoring) { - short i,j; char s[15] = " , "; if(overall_mode < MODE_MAIN_SCREEN) @@ -2830,14 +2658,14 @@ void start_dialogue_editing(short restoring) { reset_rb(); right_sbar->setMaximum(70 - NRSONPAGE); } - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { std::ostringstream strb; strb << "Personality " << (i + cur_town * 10) << " - " << town->talking.people[i].title; set_rb(i,RB_PERSONALITY, i, strb.str()); } size_t n_nodes = town->talking.talk_nodes.size(); - for(i = 0; i < n_nodes; i++) { - for(j = 0; j < 4; j++) { + for(short i = 0; i < n_nodes; i++) { + for(short j = 0; j < 4; j++) { s[j] = town->talking.talk_nodes[i].link1[j]; s[j + 6] = town->talking.talk_nodes[i].link2[j]; } diff --git a/src/scenedit/scen.btnmg.cpp b/src/scenedit/scen.btnmg.cpp index b455d037..c42fe117 100644 --- a/src/scenedit/scen.btnmg.cpp +++ b/src/scenedit/scen.btnmg.cpp @@ -25,15 +25,13 @@ extern std::shared_ptr right_sbar; // for following, lb stands for left button(s) void init_lb() { - short i; - for(i = 0; i < NLS; i++) { + for(short i = 0; i < NLS; i++) { left_button_status[i] = {LB_CLEAR, LB_NO_ACTION, ""}; } } void reset_lb() { - short i; - for(i = 0; i < NLS; i++) { + for(short i = 0; i < NLS; i++) { left_button_status[i] = {LB_CLEAR, LB_NO_ACTION, ""}; draw_lb_slot(i,0); } @@ -42,16 +40,13 @@ void reset_lb() { // is slot >= 0, force that slot // if -1, use 1st free slot void set_lb(short slot, eLBMode mode, eLBAction action, std::string label, bool do_draw) { - short i; - if(slot < 0) { - for(i = 0; i < NLS; i++) - if(left_button_status[i].mode == LB_CLEAR) { - slot = i; - i = NLS + 5000; - } - if(i < NLS + 5000) + auto iter = std::find_if(left_button_status.begin(), left_button_status.end(), [](const lb_t& btn) { + return btn.mode == LB_CLEAR; + }); + if(iter == left_button_status.end()) return; + slot = iter - left_button_status.begin(); } left_button_status[slot].mode = mode; left_button_status[slot].action = action; @@ -78,10 +73,8 @@ void reset_rb() { // is slot >= 0, force that slot // if -1, use 1st free slot void set_rb(short slot, eRBAction action, int n, std::string label, bool do_draw) { - short i; - if(slot < 0) { - for(i = 0; i < NRS; i++) + for(short i = 0; i < NRS; i++) if(right_button_status[i].action == RB_CLEAR) { slot = i; break; diff --git a/src/scenedit/scen.core.cpp b/src/scenedit/scen.core.cpp index 8828fd04..ead9de11 100644 --- a/src/scenedit/scen.core.cpp +++ b/src/scenedit/scen.core.cpp @@ -2473,9 +2473,7 @@ bool edit_shop(size_t which_shop, cDialog* parent) { } static void put_save_rects_in_dlog(cDialog& me) { - short i; - - for(i = 0; i < 3; i++) { + for(short i = 0; i < 3; i++) { std::string id = std::to_string(i + 1); me["top" + id].setTextToNum(scenario.store_item_rects[i].top); me["left" + id].setTextToNum(scenario.store_item_rects[i].left); @@ -2487,9 +2485,7 @@ static void put_save_rects_in_dlog(cDialog& me) { } static bool save_save_rects(cDialog& me) { - short i; - - for(i = 0; i < 3; i++) { + for(short i = 0; i < 3; i++) { std::string id = std::to_string(i + 1); scenario.store_item_rects[i].top = me["top" + id].getTextAsNum(); scenario.store_item_rects[i].left = me["left" + id].getTextAsNum(); @@ -2538,9 +2534,7 @@ void edit_save_rects() { } static bool save_vehicles(cDialog& me, cVehicle* vehicles, const short page) { - short i; - - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { std::string id = std::to_string(i + 1); vehicles[6 * page + i].which_town = me["town" + id].getTextAsNum(); if(cre(vehicles[6 * page + i].which_town, @@ -2557,9 +2551,7 @@ static bool save_vehicles(cDialog& me, cVehicle* vehicles, const short page) { } static void put_vehicles_in_dlog(cDialog& me, cVehicle* vehicles, const short page) { - short i; - - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { std::string id = std::to_string(i + 1); me["num" + id].setTextToNum(6 * page + i); me["town" + id].setTextToNum(vehicles[6 * page + i].which_town); @@ -2613,9 +2605,7 @@ void edit_boats() { } static bool save_add_town(cDialog& me) { - short i; - - for(i = 0; i < scenario.town_mods.size(); i++) { + for(short i = 0; i < scenario.town_mods.size(); i++) { std::string id = std::to_string(i + 1); scenario.town_mods[i].spec = me["town" + id].getTextAsNum(); if(cre(scenario.town_mods[i].spec, @@ -2631,9 +2621,7 @@ static bool save_add_town(cDialog& me) { } static void put_add_town_in_dlog(cDialog& me) { - short i; - - for(i = 0; i < scenario.town_mods.size(); i++) { + for(short i = 0; i < scenario.town_mods.size(); i++) { std::string id = std::to_string(i + 1); me["town" + id].setTextToNum(scenario.town_mods[i].spec); me["flag" + id + "-x"].setTextToNum(scenario.town_mods[i].x); @@ -2661,13 +2649,11 @@ void edit_add_town() { } static bool save_item_placement(cDialog& me, cScenario::cItemStorage& storage, short which) { - short i; - storage.property = dynamic_cast(me["owned"]).getState() != led_off; storage.ter_type = me["ter"].getTextAsNum(); if(cre(storage.ter_type, -1,255,"Terrain Type must be from 0 to 255 (or -1 for No Shortcut).","",&me)) return false; - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { std::string id = std::to_string(i + 1); storage.item_num[i] = me["item" + id].getTextAsNum(); if(cre(storage.item_num[i], @@ -2681,12 +2667,10 @@ static bool save_item_placement(cDialog& me, cScenario::cItemStorage& storage, s } static void put_item_placement_in_dlog(cDialog& me, const cScenario::cItemStorage& storage, short which) { - short i; - me["num"].setTextToNum(which); dynamic_cast(me["owned"]).setState(storage.property ? led_red : led_off); me["ter"].setTextToNum(storage.ter_type); - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { std::string id = std::to_string(i + 1); me["item" + id].setTextToNum(storage.item_num[i]); me["odds" + id].setTextToNum(storage.item_odds[i]); @@ -2694,8 +2678,6 @@ static void put_item_placement_in_dlog(cDialog& me, const cScenario::cItemStorag } static bool edit_item_placement_event_filter(cDialog& me, std::string hit, cScenario::cItemStorage& storage, short& which) { - short i; - if(hit == "okay") { if(save_item_placement(me, storage, which)) me.toast(true); @@ -2714,7 +2696,7 @@ static bool edit_item_placement_event_filter(cDialog& me, std::string hit, cScen storage = scenario.storage_shortcuts[which]; put_item_placement_in_dlog(me, storage, which); } else if(hit == "choose-ter") { - i = me["ter"].getTextAsNum(); + short i = me["ter"].getTextAsNum(); storage.ter_type = i; i = choose_text(STRT_TER,i,&me,"Which Terrain?"); if(i >= 0){ @@ -2755,7 +2737,6 @@ void edit_item_placement() { } static bool save_scen_details(cDialog& me, std::string, eKeyMod) { - short i; if(!me.toast(true)) return true; { @@ -2771,7 +2752,7 @@ static bool save_scen_details(cDialog& me, std::string, eKeyMod) { } } scenario.adjust_diff = dynamic_cast(me["adjust"]).getState() != led_red; - for(i = 0; i < 3; i++) + for(short i = 0; i < 3; i++) scenario.format.ver[i] = me["ver" + std::to_string(i + 1)].getTextAsNum(); scenario.who_wrote[0] = me["who1"].getText().substr(0, 100); scenario.who_wrote[1] = me["who2"].getText().substr(0, 100); @@ -2921,7 +2902,6 @@ bool build_scenario() { short width, height, lg, med, sm; bool default_town, grass; std::string author, title; - short i; cTown* warriors_grove = nullptr; std::vector warriors_grove_shops; @@ -3100,15 +3080,15 @@ bool build_scenario() { std::swap(scenario.shops, warriors_grove_shops); } - for(i = 0; i < lg; i++) { + for(short i = 0; i < lg; i++) { scenario.addTown(); scenario.towns.back()->town_name = "Large town " + std::to_string(i + 1); } - for(i = 0; i < med; i++) { + for(short i = 0; i < med; i++) { scenario.addTown(); scenario.towns.back()->town_name = "Medium town " + std::to_string(i + 1); } - for(i = 0; i < sm; i++) { + for(short i = 0; i < sm; i++) { scenario.addTown(); scenario.towns.back()->town_name = "Small town " + std::to_string(i + 1); } @@ -3121,11 +3101,9 @@ bool build_scenario() { } static bool save_scenario_events(cDialog& me, std::string, eKeyMod) { - short i; - if(!me.toast(true)) return true; - for(i = 0; i < scenario.scenario_timers.size(); i++) { + for(short i = 0; i < scenario.scenario_timers.size(); i++) { std::string id = std::to_string(i + 1); scenario.scenario_timers[i].time = me["time" + id].getTextAsNum(); scenario.scenario_timers[i].node = me["node" + id].getTextAsNum(); diff --git a/src/scenedit/scen.fileio.cpp b/src/scenedit/scen.fileio.cpp index 962832e9..9e9d9512 100644 --- a/src/scenedit/scen.fileio.cpp +++ b/src/scenedit/scen.fileio.cpp @@ -1138,19 +1138,18 @@ void save_scenario(bool rename) { } void start_data_dump() { - short i; using std::endl; std::string scen_name = scenario.scen_name; std::ofstream fout((scenario.scen_file.parent_path()/(scen_name + " Data.txt")).string().c_str()); fout << "Scenario data for " << scen_name << ':' << endl << endl; fout << "Terrain types for " << scen_name << ':' << endl; - for(i = 0; i < scenario.ter_types.size(); i++) + for(short i = 0; i < scenario.ter_types.size(); i++) fout << " Terrain type " << i << ": " << scenario.ter_types[i].name << endl; fout << endl << "Monster types for " << scen_name << ':' << endl; - for(i = 0; i < scenario.scen_monsters.size(); i++) + for(short i = 0; i < scenario.scen_monsters.size(); i++) fout << " Monster type " << i << ": " << scenario.scen_monsters[i].m_name << endl; fout << endl << "Item types for " << scen_name << ':' << endl; - for(i = 0; i < scenario.scen_items.size(); i++) + for(short i = 0; i < scenario.scen_items.size(); i++) fout << " Item type " << i << ": " << scenario.scen_items[i].full_name << endl; fout.close(); } diff --git a/src/scenedit/scen.graphics.cpp b/src/scenedit/scen.graphics.cpp index b6a9e3c5..3f5bb072 100644 --- a/src/scenedit/scen.graphics.cpp +++ b/src/scenedit/scen.graphics.cpp @@ -315,23 +315,22 @@ void Set_up_win() { terrain_buttons_rect.offset(RIGHT_AREA_UL_X, RIGHT_AREA_UL_Y); palette_button_base.offset(RIGHT_AREA_UL_X, RIGHT_AREA_UL_Y); - short i,j; - for(i = 0; i < 10; i++) - for(j = 0; j < 6; j++) { + for(short i = 0; i < 10; i++) + for(short j = 0; j < 6; j++) { palette_buttons[i][j] = palette_button_base; palette_buttons[i][j].offset(i * 25, j * 17); } - for(i = 0; i < 10; i++) - for(j = /*2*/0; j < 6; j++) + for(short i = 0; i < 10; i++) + for(short j = /*2*/0; j < 6; j++) palette_buttons[i][j].offset(0, 3); - for(i = 0; i < 10; i++) - for(j = /*3*/0; j < 6; j++) + for(short i = 0; i < 10; i++) + for(short j = /*3*/0; j < 6; j++) palette_buttons[i][j].offset(0, 3); - for(i = 0; i < 10; i++) - for(j = /*4*/0; j < 6; j++) + for(short i = 0; i < 10; i++) + for(short j = /*4*/0; j < 6; j++) palette_buttons[i][j].offset(0, 3); - for(i = 0; i < NLS; i++) { + for(short i = 0; i < NLS; i++) { left_buttons[i][0] = left_button_base; left_buttons[i][0].offset(0,i * 16); left_buttons[i][1] = left_buttons[i][0]; @@ -344,7 +343,7 @@ void Set_up_win() { right_button_base.top = RIGHT_AREA_UL_Y + 1; right_button_base.bottom = right_button_base.top + 12; right_button_base.right = right_button_base.left + RIGHT_AREA_WIDTH - 20; - for(i = 0; i < NRSONPAGE; i++) { + for(short i = 0; i < NRSONPAGE; i++) { right_buttons[i] = right_button_base; right_buttons[i].offset(0,i * 12); } @@ -421,9 +420,7 @@ void draw_main_screen() { } void draw_lb() { - short i; - - for(i = 0; i < NLS; i++) + for(short i = 0; i < NLS; i++) draw_lb_slot(i,0); } @@ -483,7 +480,7 @@ void draw_rb_slot (short which,short mode) { } void set_up_terrain_buttons(bool reset) { - short i,j,pic,small_i; + short pic,small_i; rectangle ter_from,ter_from_base = {0,0,36,28}, ter_plus_from = {148,235,164,251}; rectangle tiny_from,tiny_to; @@ -506,7 +503,7 @@ void set_up_terrain_buttons(bool reset) { // first make terrain buttons sf::Texture& editor_mixed = *ResMgr::get("edbuttons"); - for(i = first; i < end; i++) { + for(short i = first; i < end; i++) { rectangle draw_rect = terrain_rects[i - first]; draw_rect.offset(RIGHT_AREA_UL_X, RIGHT_AREA_UL_Y); switch(draw_mode){ @@ -668,8 +665,8 @@ void set_up_terrain_buttons(bool reset) { if(overall_mode < MODE_MAIN_SCREEN) { palette_to.offset(5,terrain_rects[255].bottom + 14); palette_to.right++; - for(i = 0; i < 10; i++){ - for(j = 0; j < 6; j++){ + for(short i = 0; i < 10; i++){ + for(short j = 0; j < 6; j++){ auto cur_palette_buttons = editing_town ? town_buttons : out_buttons; if(cur_palette_buttons[j][i] != PAL_BLANK) { palette_from = palette_button_base; @@ -686,7 +683,6 @@ void set_up_terrain_buttons(bool reset) { } void draw_terrain(){ - short q,r,i; location which_pt,where_draw; rectangle draw_rect,clipping_rect = {8,8,332,260}; ter_num_t t_to_draw; @@ -701,8 +697,8 @@ void draw_terrain(){ if(cur_viewing_mode == 0) { tileImage(mainPtr,terrain_rect,bg[17]); frame_rect(mainPtr, terrain_rect, sf::Color::Black); - for(q = 0; q < 9; q++) - for(r = 0; r < 9; r++) { + for(short q = 0; q < 9; q++) + for(short r = 0; r < 9; r++) { where_draw.x = q; where_draw.y = r; if(editing_town) { @@ -752,14 +748,14 @@ void draw_terrain(){ which_pt.y =cen_y + r - 4; if(!editing_town) { - for(i = 0; i < scenario.boats.size(); i++) { + for(short i = 0; i < scenario.boats.size(); i++) { if(scenario.boats[i].which_town == 200 && scenario.boats[i].sector == cur_out && scenario.boats[i].loc == which_pt) rect_draw_some_item(vehicle_gworld,boat_rect,mainPtr,destrec,sf::BlendAlpha); } - for(i = 0; i < scenario.horses.size(); i++) { + for(short i = 0; i < scenario.horses.size(); i++) { source_rect = boat_rect; source_rect.offset(0,36); if(scenario.horses[i].which_town == 200 && @@ -771,13 +767,13 @@ void draw_terrain(){ } if(editing_town) { - for(i = 0; i < scenario.boats.size(); i++) { + for(short i = 0; i < scenario.boats.size(); i++) { if(scenario.boats[i].which_town == cur_town && scenario.boats[i].loc == which_pt) rect_draw_some_item(vehicle_gworld,boat_rect,mainPtr,destrec,sf::BlendAlpha); } - for(i = 0; i < scenario.horses.size(); i++) { + for(short i = 0; i < scenario.horses.size(); i++) { source_rect = boat_rect; source_rect.offset(0,36); if(scenario.horses[i].which_town == cur_town && @@ -817,7 +813,7 @@ void draw_terrain(){ from_rect = calc_rect(0,0); rect_draw_some_item(fields_gworld,from_rect,mainPtr,destrec,sf::BlendAlpha); } - for(i = 0; i < 8; i++) { + for(short i = 0; i < 8; i++) { eFieldType sfx = eFieldType(SFX_SMALL_BLOOD + i); if(is_field_type(cen_x + q - 4,cen_y + r - 4,sfx)) { from_rect = calc_rect(i,3); @@ -908,7 +904,7 @@ void draw_terrain(){ if(editing_town) { // draw info rects - for(i = 0; i < town->room_rect.size(); i++) + for(short i = 0; i < town->room_rect.size(); i++) if(town->room_rect[i].left > 0) { draw_rect.left = 22 + 28 * (town->room_rect[i].left - cen_x + 4); draw_rect.right = 22 + 28 * (town->room_rect[i].right - cen_x + 4); @@ -929,7 +925,7 @@ void draw_terrain(){ } if(!editing_town) { // draw info rects - for(i = 0; i < current_terrain->info_rect.size(); i++) + for(short i = 0; i < current_terrain->info_rect.size(); i++) if(current_terrain->info_rect[i].left > 0) { draw_rect.left = 22 + 28 * (current_terrain->info_rect[i].left - cen_x + 4); draw_rect.right = 22 + 28 * (current_terrain->info_rect[i].right - cen_x + 4); @@ -964,8 +960,8 @@ void draw_terrain(){ yMax = cen_y + 5; } else yMax = std::min(yMax, 324 / size); std::cout << "Drawing map for x = " << xMin << "..." << xMax << " and y = " << yMin << "..." << yMax << std::endl; - for(q = xMin; q < xMax; q++) - for(r = yMin; r < yMax; r++) { + for(short q = xMin; q < xMax; q++) + for(short r = yMin; r < yMax; r++) { if(q - xMin < 0 || q - xMin >= max_dim || r - yMin < 0 || r - yMin >= max_dim) t_to_draw = 90; else t_to_draw = editing_town ? town->terrain(q,r) : current_terrain->terrain[q][r]; @@ -977,19 +973,19 @@ void draw_terrain(){ } void draw_monsts() { - short i,k,width,height,m_start_pic; + short width,height,m_start_pic; sf::Texture* from_gworld; rectangle source_rect; location where_draw,store_loc; - for(i = 0; i < town->creatures.size(); i++) + for(short i = 0; i < town->creatures.size(); i++) if(town->creatures[i].number != 0) { where_draw.x = town->creatures[i].start_loc.x - cen_x + 4; where_draw.y = town->creatures[i].start_loc.y - cen_y + 4; width = scenario.scen_monsters[town->creatures[i].number].x_width; height = scenario.scen_monsters[town->creatures[i].number].y_width; - for(k = 0; k < width * height; k++) { + for(short k = 0; k < width * height; k++) { store_loc = where_draw; if((where_draw.x == minmax(0,8,where_draw.x)) && (where_draw.y == minmax(0,8,where_draw.y)) && @@ -1048,12 +1044,11 @@ static rectangle get_item_template_rect (short type_wanted) { } void draw_items() { - short i; rectangle source_rect,dest_rect; location where_draw; short pic_num; - for(i = 0; i < town->preset_items.size(); i++) { + for(short i = 0; i < town->preset_items.size(); i++) { if(town->preset_items[i].code >= 0) { where_draw.x = town->preset_items[i].loc.x - cen_x + 4; where_draw.y = town->preset_items[i].loc.y - cen_y + 4; @@ -1088,9 +1083,8 @@ void draw_items() { void force_tiny_redraw() { -// short q,r; -// for(q = 0; q < 8; q++) -// for(r = 0; r < 64; r++) +// for(short q = 0; q < 8; q++) +// for(short r = 0; r < 64; r++) // ter_changed[q][r] = 255; } @@ -1231,12 +1225,11 @@ rectangle get_template_rect (unsigned short type_wanted) { } void draw_frames() { - char q,r,i; location which_pt; rectangle draw_rect; - for(q = 0; q < 9; q++) { - for(r = 0; r < 9; r++) { + for(short q = 0; q < 9; q++) { + for(short r = 0; r < 9; r++) { which_pt.x = cen_x + q - 4; which_pt.y = cen_y + r - 4; draw_rect.top = 23 + r * 36; @@ -1244,13 +1237,13 @@ void draw_frames() { draw_rect.left = 23 + q * 28; draw_rect.right = 50 + q * 28; draw_rect.offset(TER_RECT_UL_X,TER_RECT_UL_Y); - for(i = 0; i < town->wandering_locs.size(); i++) + for(short i = 0; i < town->wandering_locs.size(); i++) if((which_pt.x == town->wandering_locs[i].x) && (which_pt.y == town->wandering_locs[i].y)) { frame_rect(mainPtr, draw_rect, sf::Color::Red); } - for(i = 0; i < town->start_locs.size(); i++) + for(short i = 0; i < town->start_locs.size(); i++) if((which_pt.x == town->start_locs[i].x) && (which_pt.y == town->start_locs[i].y)) { frame_rect(mainPtr, draw_rect, sf::Color::Magenta); @@ -1505,15 +1498,14 @@ void set_string(std::string string,std::string string2) { } bool is_special(short i,short j) { - short k; location check(i,j); if(editing_town) - for(k = 0; k < town->special_locs.size(); k++) + for(short k = 0; k < town->special_locs.size(); k++) if(town->special_locs[k] == check && town->special_locs[k].spec >= 0) return true; if(!editing_town) - for(k = 0; k < current_terrain->special_locs.size(); k++) + for(short k = 0; k < current_terrain->special_locs.size(); k++) if(current_terrain->special_locs[k] == check && current_terrain->special_locs[k].spec >= 0) return true; @@ -1540,9 +1532,7 @@ bool is_road(short i,short j){ } bool is_field_type(short i,short j,eFieldType field_type) { - unsigned short k; - - for(k = 0; k < town->preset_fields.size(); k++) + for(short k = 0; k < town->preset_fields.size(); k++) if((town->preset_fields[k].type == field_type) && (town->preset_fields[k].loc.x == i) && (town->preset_fields[k].loc.y == j)) @@ -1551,11 +1541,9 @@ bool is_field_type(short i,short j,eFieldType field_type) { } void make_field_type(short i,short j,eFieldType field_type) { - unsigned short k; - if(is_field_type(i,j,field_type)) return; - for(k = 0; k < town->preset_fields.size(); k++) + for(short k = 0; k < town->preset_fields.size(); k++) if(town->preset_fields[k].type == 0) { town->preset_fields[k].loc.x = i; town->preset_fields[k].loc.y = j; @@ -1571,9 +1559,7 @@ void make_field_type(short i,short j,eFieldType field_type) { void take_field_type(short i,short j,eFieldType field_type) { - unsigned short k; - - for(k = 0; k < town->preset_fields.size(); k++) + for(short k = 0; k < town->preset_fields.size(); k++) if((town->preset_fields[k].type == field_type) && (town->preset_fields[k].loc.x == i) && (town->preset_fields[k].loc.y == j)) { diff --git a/src/scenedit/scen.keydlgs.cpp b/src/scenedit/scen.keydlgs.cpp index 5eb22320..92e93d38 100644 --- a/src/scenedit/scen.keydlgs.cpp +++ b/src/scenedit/scen.keydlgs.cpp @@ -474,14 +474,12 @@ bool edit_text_str(short which_str,eStrMode mode) { return dlog.accepted() || which_str != first; } -static bool edit_area_rect_event_filter(cDialog& me, std::string item_hit, short which_str, short str_mode) { +static bool edit_area_rect_event_filter(cDialog& me, std::string item_hit, info_rect_t& r) { if(item_hit == "okay") { me.setResult(true); me.toast(true); std::string str = me["area"].getText().substr(0,29); - if(str_mode == 0) - current_terrain->info_rect[which_str].descr = str; - else town->room_rect[which_str].descr = str; + r.descr = str; } else if(item_hit == "cancel") { me.setResult(false); me.toast(false); @@ -490,15 +488,13 @@ static bool edit_area_rect_event_filter(cDialog& me, std::string item_hit, short } // mode 0 - out 1 - town -bool edit_area_rect_str(short which_str,short mode) { +bool edit_area_rect_str(info_rect_t& r) { using namespace std::placeholders; cDialog dlog("set-area-desc"); - dlog.attachClickHandlers(std::bind(edit_area_rect_event_filter, _1, _2, which_str, mode), {"okay", "cancel"}); + dlog.attachClickHandlers(std::bind(edit_area_rect_event_filter, _1, _2, std::ref(r)), {"okay", "cancel"}); - if(mode == 0) - dlog["area"].setText(current_terrain->info_rect[which_str].descr); - else dlog["area"].setText(town->room_rect[which_str].descr); + dlog["area"].setText(r.descr); dlog.run(); @@ -1016,19 +1012,19 @@ short get_fresh_spec(short which_mode) { static bool edit_spec_text_event_filter(cDialog& me, std::string item_hit, eStrMode str_mode, short* str1, short* str2) { std::string str; - size_t i; if(item_hit == "okay") { str = me["str1"].getText(); if(!str.empty()) { if(*str1 < 0) { size_t n = num_strs(str_mode); - for(i = 0; i < n; i++) { + for(short i = 0; i < n; i++) { std::string& str = fetch_str(str_mode, i); - if(!str.empty() && str[0] == '*') + if(!str.empty() && str[0] == '*') { + *str1 = i; break; + } } - *str1 = i; } fetch_str(str_mode, *str1) = str; } @@ -1036,12 +1032,13 @@ static bool edit_spec_text_event_filter(cDialog& me, std::string item_hit, eStrM if(!str.empty()) { if(*str2 < 0) { size_t n = num_strs(str_mode); - for(i = 0; i < n; i++) { + for(short i = 0; i < n; i++) { std::string& str = fetch_str(str_mode, i); - if(!str.empty() && str[0] == '*') + if(!str.empty() && str[0] == '*') { + *str2 = i; break; + } } - *str2 = i; } fetch_str(str_mode, *str2) = str; } @@ -1074,10 +1071,9 @@ void edit_spec_text(eStrMode mode,short *str1,short *str2,cDialog* parent) { static bool edit_dialog_text_event_filter(cDialog& me, std::string item_hit, eStrMode str_mode, short* str1){ std::string str; - short i; if(item_hit == "okay") { - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { std::string id = "str" + std::to_string(i + 1); str = me[id].getText(); if(i == 0 && str.empty()) break; @@ -1090,23 +1086,23 @@ static bool edit_dialog_text_event_filter(cDialog& me, std::string item_hit, eSt // mode 0 - scen 1 - out 2 - town void edit_dialog_text(eStrMode mode,short *str1,cDialog* parent) { - size_t i,j; - if(*str1 >= num_strs(mode) - 6) *str1 = -1; // first, assign the 6 strs for the dialog. if(*str1 < 0) { size_t n = num_strs(mode); - for(i = 0; i < n; i++) { - for(j = i; j < i + 6; j++) { + for(short i = 0; i < n; i++) { + short n = 0; + for(short j = i; j < i + 6; j++, n++) { std::string str = fetch_str(mode, j); if(!str.empty() && str[0] != '*') break; } - if(j == i + 6) + if(n == 6) { + *str1 = i; break; + } } - *str1 = i; for(short i = *str1; i < *str1 + 6; i++) fetch_str(mode, i).clear(); } @@ -1120,7 +1116,7 @@ void edit_dialog_text(eStrMode mode,short *str1,cDialog* parent) { edit.attachClickHandlers(std::bind(edit_dialog_text_event_filter, _1, _2, mode, str1), {"okay", "cancel"}); if(*str1 >= 0) { - for(i = 0; i < 6; i++) { + for(short i = 0; i < 6; i++) { std::string id = "str" + std::to_string(i + 1); edit[id].setText(fetch_str(mode, *str1 + i)); } @@ -1130,7 +1126,6 @@ void edit_dialog_text(eStrMode mode,short *str1,cDialog* parent) { } static bool edit_special_num_event_filter(cDialog& me, std::string item_hit, short spec_mode) { - short i; size_t num_specs; switch(spec_mode) { case 0: num_specs = scenario.scen_specials.size(); @@ -1140,7 +1135,7 @@ static bool edit_special_num_event_filter(cDialog& me, std::string item_hit, sho if(item_hit == "cancel") me.setResult(-1); else if(item_hit == "okay") { - i = me["num"].getTextAsNum(); + short i = me["num"].getTextAsNum(); if(i < 0 || i >= num_specs) { showWarning("There is no special node with that number. The available range is 0 to " + std::to_string(num_specs - 1) + ".","The node has been set anyway. To create it, select Edit Special Nodes from the menu, scroll to the bottom, and select Create new Node.",&me); } @@ -1164,15 +1159,13 @@ short edit_special_num(short mode,short what_start) { } static bool edit_scen_intro_event_filter(cDialog& me, std::string item_hit, eKeyMod) { - short i; - if(item_hit == "okay") { scenario.intro_pic = me["picnum"].getTextAsNum(); if(scenario.intro_pic > 29) { showError("Intro picture number is out of range.","",&me); return true; } - for(i = 0; i < scenario.intro_strs.size(); i++) { + for(short i = 0; i < scenario.intro_strs.size(); i++) { std::string id = "str" + std::to_string(i + 1); scenario.intro_strs[i] = me[id].getText(); } @@ -1181,7 +1174,7 @@ static bool edit_scen_intro_event_filter(cDialog& me, std::string item_hit, eKey me.toast(false); } else if(item_hit == "choose") { pic_num_t pic = me["picnum"].getTextAsNum(); - i = choose_graphic(pic,PIC_SCEN,&me); + short i = choose_graphic(pic,PIC_SCEN,&me); if(i != NO_PIC) { me["picnum"].setTextToNum(i); dynamic_cast(me["pic"]).setPict(i); @@ -1191,13 +1184,11 @@ static bool edit_scen_intro_event_filter(cDialog& me, std::string item_hit, eKey } void edit_scen_intro() { - short i; - cDialog edit("edit-intro"); edit.attachClickHandlers(edit_scen_intro_event_filter, {"okay", "cancel", "choose"}); edit["picnum"].setTextToNum(scenario.intro_pic); - for(i = 0; i < scenario.intro_strs.size(); i++) { + for(short i = 0; i < scenario.intro_strs.size(); i++) { std::string id = "str" + std::to_string(i + 1); edit[id].setText(scenario.intro_strs[i]); } diff --git a/src/scenedit/scen.keydlgs.hpp b/src/scenedit/scen.keydlgs.hpp index e0f1b3bf..319c1743 100644 --- a/src/scenedit/scen.keydlgs.hpp +++ b/src/scenedit/scen.keydlgs.hpp @@ -1,6 +1,7 @@ #include #include "pict.hpp" // for ePicType +#include "location.hpp" // for info_rect_t class cDialog; enum eStrType { @@ -30,7 +31,7 @@ void edit_spec_text(eStrMode mode,short *str1,short *str2,cDialog* parent); void edit_dialog_text(eStrMode mode,short *str1,cDialog* parent); short edit_special_num(short mode,short what_start); void edit_scen_intro(); -bool edit_area_rect_str(short which_str,short mode); +bool edit_area_rect_str(info_rect_t& r); void make_cursor_sword() ; size_t num_strs(eStrMode str_mode); diff --git a/src/scenedit/scen.townout.cpp b/src/scenedit/scen.townout.cpp index 9d6a291d..66c24e93 100644 --- a/src/scenedit/scen.townout.cpp +++ b/src/scenedit/scen.townout.cpp @@ -342,11 +342,9 @@ void edit_placed_item(short which_i) { item_dlg.run(); } -static bool edit_sign_event_filter(cDialog& me, short which_sign) { +static bool edit_sign_event_filter(cDialog& me, sign_loc_t& which_sign) { if(!me.toast(true)) return true; - if(editing_town) - town->sign_locs[which_sign].text = me["text"].getText(); - else current_terrain->sign_locs[which_sign].text = me["text"].getText(); + which_sign.text = me["text"].getText(); #if 0 // TODO: Apparently there used to be left/right buttons on this dialog. if(item_hit == 3) which_sign--; @@ -359,13 +357,13 @@ static bool edit_sign_event_filter(cDialog& me, short which_sign) { return true; } -void edit_sign(short which_sign,short picture) { +void edit_sign(sign_loc_t& which_sign,short num,short picture) { using namespace std::placeholders; location view_loc; cDialog sign_dlg("edit-sign"); sign_dlg["cancel"].attachClickHandler(std::bind(&cDialog::toast, &sign_dlg, false)); - sign_dlg["okay"].attachClickHandler(std::bind(edit_sign_event_filter, _1, which_sign)); + sign_dlg["okay"].attachClickHandler(std::bind(edit_sign_event_filter, _1, std::ref(which_sign))); cPict& icon = dynamic_cast(sign_dlg["pic"]); if(picture >= 960 && picture < 1000) icon.setPict(picture, PIC_TER_ANIM); @@ -373,10 +371,8 @@ void edit_sign(short which_sign,short picture) { icon.setPict(picture - 2000, PIC_CUSTOM_TER_ANIM); else icon.setPict(picture, PIC_TER); // automatically adjusts for custom graphics - sign_dlg["num"].setTextToNum(which_sign); - if(!editing_town) - sign_dlg["text"].setText(current_terrain->sign_locs[which_sign].text); - else sign_dlg["text"].setText(town->sign_locs[which_sign].text); + sign_dlg["num"].setTextToNum(num); + sign_dlg["text"].setText(which_sign.text); sign_dlg.run(); } @@ -505,17 +501,15 @@ void outdoor_details() { } static void put_out_wand_in_dlog(cDialog& me, short which, const cOutdoors::cWandering& wand) { - short i; - me["num"].setTextToNum(which); - for(i = 0; i < 7; i++) { + for(short i = 0; i < 7; i++) { std::string id = "foe" + std::to_string(i + 1); if(wand.monst[i] == 0) me[id].setText("Empty"); // TODO: Wait a second, if 0 is no monster, does that mean it's impossible to use monster 0? Should 1 be subtracted here? else me[id].setText(scenario.scen_monsters[wand.monst[i]].m_name); } - for(i = 0; i < 3; i++) { + for(short i = 0; i < 3; i++) { std::string id = "ally" + std::to_string(i + 1); if(wand.friendly[i] == 0) me[id].setText("Empty"); @@ -696,8 +690,7 @@ static bool save_town_events(cDialog& me, std::string, eKeyMod) { } static void put_town_events_in_dlog(cDialog& me) { - short i; - for(i = 0; i < town->timers.size(); i++) { + for(short i = 0; i < town->timers.size(); i++) { std::string id = std::to_string(i + 1); me["time" + id].setTextToNum(town->timers[i].time); me["spec" + id].setTextToNum(town->timers[i].node); @@ -749,8 +742,7 @@ static bool save_advanced_town(cDialog& me, std::string, eKeyMod) { } static void put_advanced_town_in_dlog(cDialog& me) { - short i; - for(i = 0; i < town->exits.size(); i++) { + for(short i = 0; i < town->exits.size(); i++) { std::string id = std::to_string(i + 1); me["onexit" + id].setTextToNum(town->exits[i].spec); me["exit" + id + "-x"].setTextToNum(town->exits[i].x); @@ -1200,8 +1192,6 @@ location pick_out(location default_loc,cScenario& scenario) { } bool new_town(short which_town) { - short i,j; - cChoiceDlog new_dlg("new-town", {"okay", "cancel"}); new_dlg->getControl("num").setTextToNum(which_town); if(new_dlg.show() == "cancel") return false; @@ -1218,8 +1208,8 @@ bool new_town(short which_town) { scenario.last_town_edited = cur_town; town->town_name = new_dlg->getControl("name").getText().substr(0,30); - for(i = 0; i < town->max_dim(); i++) - for(j = 0; j < town->max_dim(); j++) + for(short i = 0; i < town->max_dim(); i++) + for(short j = 0; j < town->max_dim(); j++) if(preset == "cave") { town->terrain(i,j) = 0; } else { diff --git a/src/scenedit/scen.townout.hpp b/src/scenedit/scen.townout.hpp index c81f70fd..5050ec61 100644 --- a/src/scenedit/scen.townout.hpp +++ b/src/scenedit/scen.townout.hpp @@ -1,7 +1,9 @@ +#include "location.hpp" // for sign_loc_t + void edit_placed_monst(short which_m); cTownperson edit_placed_monst_adv(cTownperson monst_record, short which, class cDialog& parent); -void edit_sign(short which_sign,short picture); +void edit_sign(sign_loc_t& which_sign,short num,short picture); short pick_town_num(std::string which_dlog,short def,cScenario& scenario); bool change_ter(short& change_from,short& change_to,short& chance); void edit_out_wand(short mode); diff --git a/src/tools/fileio_scen.cpp b/src/tools/fileio_scen.cpp index 93d8fefe..9d079734 100644 --- a/src/tools/fileio_scen.cpp +++ b/src/tools/fileio_scen.cpp @@ -114,7 +114,6 @@ template static void port_shop_spec_node(cSpecial& spec, std static const std::string err_prefix = "Error loading Blades of Exile Scenario: "; bool load_scenario_v1(fs::path file_to_load, cScenario& scenario, bool only_header){ - short i,n; bool file_ok = false; long len; char temp_str[256]; @@ -155,16 +154,14 @@ bool load_scenario_v1(fs::path file_to_load, cScenario& scenario, bool only_head } len = (long) sizeof(legacy::scenario_data_type); - n = fread(temp_scenario, len, 1, file_id); - if(n < 1){ + if(fread(temp_scenario, len, 1, file_id) < 1) { showError(err_prefix + "Failed to read scenario data.", get_file_error()); fclose(file_id); return false; } port_scenario(temp_scenario); len = sizeof(legacy::scen_item_data_type); // item data - n = fread(item_data, len, 1, file_id); - if(n < 1){ + if(fread(item_data, len, 1, file_id) < 1) { showError(err_prefix + "Failed to read scenario items.", get_file_error()); fclose(file_id); return false; @@ -177,9 +174,9 @@ bool load_scenario_v1(fs::path file_to_load, cScenario& scenario, bool only_head scenario.special_items.resize(50); scenario.journal_strs.resize(50); scenario.spec_strs.resize(100); - for(i = 0; i < 270; i++) { + for(short i = 0; i < 270; i++) { len = (long) (temp_scenario->scen_str_len[i]); - n = fread(temp_str, len, 1, file_id); + fread(temp_str, len, 1, file_id); temp_str[len] = 0; if(i == 0) scenario.scen_name = temp_str; else if(i == 1 || i == 2) @@ -2168,20 +2165,19 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, bool only_head } static long get_town_offset(short which_town, legacy::scenario_data_type& scenario){ - int i,j; long len_to_jump,store; len_to_jump = sizeof(scenario_header_flags); len_to_jump += sizeof(legacy::scenario_data_type); len_to_jump += sizeof(legacy::scen_item_data_type); - for(i = 0; i < 300; i++) + for(short i = 0; i < 300; i++) len_to_jump += (long) scenario.scen_str_len[i]; store = 0; - for(i = 0; i < 100; i++) - for(j = 0; j < 2; j++) + for(short i = 0; i < 100; i++) + for(short j = 0; j < 2; j++) store += (long) (scenario.out_data_size[i][j]); - for(i = 0; i < which_town; i++) - for(j = 0; j < 5; j++) + for(short i = 0; i < which_town; i++) + for(short j = 0; j < 5; j++) store += (long) (scenario.town_data_size[i][j]); len_to_jump += store; @@ -2189,7 +2185,6 @@ static long get_town_offset(short which_town, legacy::scenario_data_type& scenar } bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy::scenario_data_type& scenario, std::vector& shops) { - short i,n; long len,len_to_jump = 0; char temp_str[256]; legacy::town_record_type store_town; @@ -2205,16 +2200,14 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy: } len_to_jump = get_town_offset(which_town, scenario); - n = fseek(file_id, len_to_jump, SEEK_SET); - if(n != 0) { + if(fseek(file_id, len_to_jump, SEEK_SET) != 0) { showError(err_prefix + "Failure seeking to town record.", get_file_error()); fclose(file_id); return false; } len = sizeof(legacy::town_record_type); - n = fread(&store_town, len, 1, file_id); - if(n < 1) { + if(fread(&store_town, len, 1, file_id) < 1) { showError(err_prefix + "Could not read town record.", get_file_error()); fclose(file_id); return false; @@ -2224,7 +2217,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy: switch(scenario.town_size[which_town]) { case 0: len = sizeof(legacy::big_tr_type); - n = fread(&t_d, len, 1, file_id); + fread(&t_d, len, 1, file_id); port_t_d(&t_d); the_town.append(store_town); the_town.append(t_d, which_town); @@ -2232,7 +2225,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy: case 1: len = sizeof(legacy::ave_tr_type); - n = fread(&ave_t, len, 1, file_id); + fread(&ave_t, len, 1, file_id); port_ave_t(&ave_t); the_town.append(store_town); the_town.append(ave_t, which_town); @@ -2240,7 +2233,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy: case 2: len = sizeof(legacy::tiny_tr_type); - n = fread(&tiny_t, len, 1, file_id); + fread(&tiny_t, len, 1, file_id); port_tiny_t(&tiny_t); the_town.append(store_town); the_town.append(tiny_t, which_town); @@ -2250,9 +2243,9 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy: the_town.spec_strs.resize(100); the_town.sign_locs.resize(20); the_town.room_rect.resize(16); - for(i = 0; i < 140; i++) { + for(short i = 0; i < 140; i++) { len = (long) (store_town.strlens[i]); - n = fread(temp_str, len, 1, file_id); + fread(temp_str, len, 1, file_id); temp_str[len] = 0; if(i == 0) the_town.town_name = temp_str; else if(i >= 1 && i < 17) @@ -2266,8 +2259,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy: } len = sizeof(legacy::talking_record_type); - n = fread(&store_talk, len, 1, file_id); - if(n < 1) { + if(fread(&store_talk, len, 1, file_id) < 1) { showError(err_prefix + "Could not read dialogue record.", get_file_error()); fclose(file_id); return false; @@ -2275,9 +2267,9 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy: port_talk_nodes(&store_talk); the_town.talking.talk_nodes.resize(60); - for(i = 0; i < 170; i++) { + for(short i = 0; i < 170; i++) { len = (long) (store_talk.strlens[i]); - n = fread(temp_str, len, 1, file_id); + fread(temp_str, len, 1, file_id); temp_str[len] = 0; if(i >= 0 && i < 10) the_town.talking.people[i].title = temp_str; @@ -2302,8 +2294,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy: // And lastly, calculate lighting the_town.set_up_lights(); - n = fclose(file_id); - if(n != 0) { + if(fclose(file_id) != 0) { showError(err_prefix + "An error occurred while closing the file.", get_file_error()); } @@ -2311,18 +2302,18 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy: } static long get_outdoors_offset(location& which_out, legacy::scenario_data_type& scenario){ - int i,j,out_sec_num; + int out_sec_num; long len_to_jump,store; out_sec_num = scenario.out_width * which_out.y + which_out.x; len_to_jump = sizeof(scenario_header_flags); len_to_jump += sizeof(legacy::scenario_data_type); len_to_jump += sizeof(legacy::scen_item_data_type); - for(i = 0; i < 300; i++) + for(short i = 0; i < 300; i++) len_to_jump += (long) scenario.scen_str_len[i]; store = 0; - for(i = 0; i < out_sec_num; i++) - for(j = 0; j < 2; j++) + for(short i = 0; i < out_sec_num; i++) + for(short j = 0; j < 2; j++) store += (long) (scenario.out_data_size[i][j]); len_to_jump += store; @@ -2331,7 +2322,6 @@ static long get_outdoors_offset(location& which_out, legacy::scenario_data_type& //mode -> 0 - primary load 1 - add to top 2 - right 3 - bottom 4 - left bool load_outdoors_v1(fs::path scen_file, location which_out,cOutdoors& the_out, legacy::scenario_data_type& scenario){ - short i,n; long len,len_to_jump; char temp_str[256]; legacy::outdoor_record_type store_out; @@ -2343,16 +2333,14 @@ bool load_outdoors_v1(fs::path scen_file, location which_out,cOutdoors& the_out, } len_to_jump = get_outdoors_offset(which_out, scenario); - n = fseek(file_id, len_to_jump, SEEK_SET); - if(n != 0) { + if(fseek(file_id, len_to_jump, SEEK_SET) != 0) { showError(err_prefix + "Failure seeking to outdoor record.", get_file_error()); fclose(file_id); return false; } len = sizeof(legacy::outdoor_record_type); - n = fread(&store_out, len, 1, file_id); - if(n < 1) { + if(fread(&store_out, len, 1, file_id) < 1) { showError(err_prefix + "Could not read outdoor record.", get_file_error()); fclose(file_id); return false; @@ -2365,9 +2353,9 @@ bool load_outdoors_v1(fs::path scen_file, location which_out,cOutdoors& the_out, the_out.spec_strs.resize(90); the_out.sign_locs.resize(8); the_out.info_rect.resize(8); - for(i = 0; i < 108; i++) { + for(short i = 0; i < 108; i++) { len = (long) (store_out.strlens[i]); - n = fread(temp_str, len, 1, file_id); + fread(temp_str, len, 1, file_id); temp_str[len] = 0; if(i == 0) the_out.out_name = temp_str; else if(i == 9) the_out.comment = temp_str; @@ -2378,8 +2366,7 @@ bool load_outdoors_v1(fs::path scen_file, location which_out,cOutdoors& the_out, the_out.sign_locs[i-100].text = temp_str; } - n = fclose(file_id); - if(n != 0) { + if(fclose(file_id) != 0) { showError(err_prefix + "Something went wrong when closing the file.", get_file_error()); } return true; diff --git a/src/tools/graphtool.cpp b/src/tools/graphtool.cpp index 7d605c7e..ec6c8bd5 100644 --- a/src/tools/graphtool.cpp +++ b/src/tools/graphtool.cpp @@ -81,7 +81,6 @@ void init_graph_tool(){ delete[] fbuf; delete[] vbuf; } while(false); - int i; static const location pat_offs[17] = { {0,3}, {1,1}, {2,1}, {2,0}, {3,0}, {3,1}, {1,3}, {0,0}, @@ -92,7 +91,7 @@ void init_graph_tool(){ 2, 3, 4, 5, 6, 8, 9, 10, 11,12,13,14,15,16,17,19,20 }; - for(i = 0; i < 17; i++){ + for(short i = 0; i < 17; i++){ bg_rects[pat_i[i]] = {0,0,64,64}; bg_rects[pat_i[i]].offset(64 * pat_offs[i].x,64 * pat_offs[i].y); } @@ -273,7 +272,7 @@ void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,std::stri short line_height = options.style.lineHeight; sf::Text str_to_draw; options.style.applyTo(str_to_draw); - short str_len,i; + short str_len; unsigned short last_line_break = 0,last_word_break = 0; short total_width = 0; short adjust_x = 0,adjust_y = 0; @@ -308,7 +307,8 @@ void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,std::stri if(mode == eTextMode::WRAP) { moveTo = location(dest_rect.left + 1 + adjust_x, dest_rect.top + 1 + adjust_y + 9); - for(i = 0; text_len(i) != text_len(i + 1) && i < str_len;i++) { + short i; + for(i = 0; text_len(i) != text_len(i + 1) && i < str_len; i++) { if(((text_len(i) - text_len(last_line_break) > (dest_rect.width() - 6)) && (last_word_break >= last_line_break)) || (str[i] == '|')) { if(str[i] == '|') { diff --git a/src/tools/mathutil.cpp b/src/tools/mathutil.cpp index b1fd0763..8b6d6a87 100644 --- a/src/tools/mathutil.cpp +++ b/src/tools/mathutil.cpp @@ -11,12 +11,12 @@ short get_ran (short times,short min,short max){ long int store; - short i, to_ret = 0; + short to_ret = 0; if(max < min) max = min; if(max == min) return times * min; - for(i = 1; i < times + 1; i++) { + for(short i = 1; i < times + 1; i++) { store = rand(); to_ret += min + (store % (max - min + 1)); } diff --git a/src/tools/porting.cpp b/src/tools/porting.cpp index 385bb36a..465aee14 100644 --- a/src/tools/porting.cpp +++ b/src/tools/porting.cpp @@ -11,42 +11,38 @@ extern bool cur_scen_is_mac, mac_is_intel; void port_town(legacy::town_record_type* dummy_town_ptr){ - short i; - if(cur_scen_is_mac != mac_is_intel) return; flip_short(&dummy_town_ptr->town_chop_time); flip_short(&dummy_town_ptr->town_chop_key); flip_short(&dummy_town_ptr->lighting); - for(i =0 ; i < 4; i++) + for(short i = 0; i < 4; i++) flip_short(&dummy_town_ptr->exit_specs[i]); flip_rect(&dummy_town_ptr->in_town_rect); - for(i =0 ; i < 64; i++) { + for(short i = 0; i < 64; i++) { flip_short(&dummy_town_ptr->preset_items[i].item_code); flip_short(&dummy_town_ptr->preset_items[i].ability); } - for(i =0 ; i < 50; i++) { + for(short i = 0; i < 50; i++) { flip_short(&dummy_town_ptr->preset_fields[i].field_type); } flip_short(&dummy_town_ptr->max_num_monst); flip_short(&dummy_town_ptr->spec_on_entry); flip_short(&dummy_town_ptr->spec_on_entry_if_dead); - for(i =0 ; i < 8; i++) + for(short i = 0; i < 8; i++) flip_short(&dummy_town_ptr->timer_spec_times[i]); - for(i =0 ; i < 8; i++) + for(short i = 0; i < 8; i++) flip_short(&dummy_town_ptr->timer_specs[i]); flip_short(&dummy_town_ptr->difficulty); - for(i =0 ; i < 100; i++) + for(short i = 0; i < 100; i++) flip_spec_node(&dummy_town_ptr->specials[i]); } void port_talk_nodes(legacy::talking_record_type* dummy_talk_ptr) { - short i; - if(cur_scen_is_mac != mac_is_intel) return; - for(i = 0; i < 60; i++) { + for(short i = 0; i < 60; i++) { flip_short(&dummy_talk_ptr->talk_nodes[i].personality); flip_short(&dummy_talk_ptr->talk_nodes[i].type); flip_short(&dummy_talk_ptr->talk_nodes[i].extras[0]); @@ -57,13 +53,12 @@ void port_talk_nodes(legacy::talking_record_type* dummy_talk_ptr) { } void port_t_d(legacy::big_tr_type* old) { - short i; if(cur_scen_is_mac != mac_is_intel) return; - for(i =0 ; i < 16; i++) + for(short i = 0; i < 16; i++) flip_rect(&old->room_rect[i]); - for(i =0 ; i < 60; i++) { + for(short i = 0; i < 60; i++) { flip_short(&old->creatures[i].spec1); flip_short(&old->creatures[i].spec2); flip_short(&old->creatures[i].monster_time); @@ -74,13 +69,12 @@ void port_t_d(legacy::big_tr_type* old) { } void port_ave_t(legacy::ave_tr_type* old) { - short i; if(cur_scen_is_mac != mac_is_intel) return; - for(i =0 ; i < 16; i++) + for(short i = 0; i < 16; i++) flip_rect(&old->room_rect[i]); - for(i =0 ; i < 40; i++) { + for(short i = 0; i < 40; i++) { flip_short(&old->creatures[i].spec1); flip_short(&old->creatures[i].spec2); flip_short(&old->creatures[i].monster_time); @@ -91,13 +85,12 @@ void port_ave_t(legacy::ave_tr_type* old) { } void port_tiny_t(legacy::tiny_tr_type* old) { - short i; if(cur_scen_is_mac != mac_is_intel) return; - for(i =0 ; i < 16; i++) + for(short i = 0; i < 16; i++) flip_rect(&old->room_rect[i]); - for(i =0 ; i < 30; i++) { + for(short i = 0; i < 30; i++) { flip_short(&old->creatures[i].spec1); flip_short(&old->creatures[i].spec2); flip_short(&old->creatures[i].monster_time); @@ -108,8 +101,6 @@ void port_tiny_t(legacy::tiny_tr_type* old) { } void port_scenario(legacy::scenario_data_type* temp_scenario) { - short i,j; - if(cur_scen_is_mac != mac_is_intel) return; flip_short(&temp_scenario->flag_a); @@ -124,28 +115,28 @@ void port_scenario(legacy::scenario_data_type* temp_scenario) { flip_short(&temp_scenario->intro_mess_pic); flip_short(&temp_scenario->intro_mess_len); flip_short(&temp_scenario->which_town_start); - for(i = 0; i < 200; i++) - for(j = 0; j < 5; j++) + for(short i = 0; i < 200; i++) + for(short j = 0; j < 5; j++) flip_short(&temp_scenario->town_data_size[i][j]); - for(i = 0; i < 10; i++) + for(short i = 0; i < 10; i++) flip_short(&temp_scenario->town_to_add_to[i]); - for(i = 0; i < 10; i++) - for(j = 0; j < 2; j++) + for(short i = 0; i < 10; i++) + for(short j = 0; j < 2; j++) flip_short(&temp_scenario->flag_to_add_to_town[i][j]); - for(i = 0; i < 100; i++) - for(j = 0; j < 2; j++) + for(short i = 0; i < 100; i++) + for(short j = 0; j < 2; j++) flip_short(&temp_scenario->out_data_size[i][j]); - for(i = 0; i < 3; i++) + for(short i = 0; i < 3; i++) flip_rect(&temp_scenario->store_item_rects[i]); - for(i = 0; i < 3; i++) + for(short i = 0; i < 3; i++) flip_short(&temp_scenario->store_item_towns[i]); - for(i = 0; i < 50; i++) + for(short i = 0; i < 50; i++) flip_short(&temp_scenario->special_items[i]); - for(i = 0; i < 50; i++) + for(short i = 0; i < 50; i++) flip_short(&temp_scenario->special_item_special[i]); flip_short(&temp_scenario->rating); flip_short(&temp_scenario->uses_custom_graphics); - for(i = 0; i < 256; i++) { + for(short i = 0; i < 256; i++) { flip_short(&temp_scenario->scen_monsters[i].health); flip_short(&temp_scenario->scen_monsters[i].m_health); flip_short(&temp_scenario->scen_monsters[i].max_mp); @@ -160,26 +151,26 @@ void port_scenario(legacy::scenario_data_type* temp_scenario) { flip_short(&temp_scenario->scen_monsters[i].picture_num); } - for(i = 0; i < 256; i++) { + for(short i = 0; i < 256; i++) { flip_short(&temp_scenario->ter_types[i].picture); } - for(i = 0; i < 30; i++) { + for(short i = 0; i < 30; i++) { flip_short(&temp_scenario->scen_boats[i].which_town); } - for(i = 0; i < 30; i++) { + for(short i = 0; i < 30; i++) { flip_short(&temp_scenario->scen_horses[i].which_town); } - for(i = 0; i < 20; i++) + for(short i = 0; i < 20; i++) flip_short(&temp_scenario->scenario_timer_times[i]); - for(i = 0; i < 20; i++) + for(short i = 0; i < 20; i++) flip_short(&temp_scenario->scenario_timer_specs[i]); - for(i = 0; i < 256; i++) { + for(short i = 0; i < 256; i++) { flip_spec_node(&temp_scenario->scen_specials[i]); } - for(i = 0; i < 10; i++) { + for(short i = 0; i < 10; i++) { flip_short(&temp_scenario->storage_shortcuts[i].ter_type); flip_short(&temp_scenario->storage_shortcuts[i].property); - for(j = 0; j < 10; j++) { + for(short j = 0; j < 10; j++) { flip_short(&temp_scenario->storage_shortcuts[i].item_num[j]); flip_short(&temp_scenario->storage_shortcuts[i].item_odds[j]); } @@ -189,12 +180,10 @@ void port_scenario(legacy::scenario_data_type* temp_scenario) { void port_item_list(legacy::scen_item_data_type* old){ - short i; - if(cur_scen_is_mac != mac_is_intel) return; - for(i = 0; i < 400; i++) { + for(short i = 0; i < 400; i++) { flip_short(&(old->scen_items[i].variety)); flip_short(&(old->scen_items[i].item_level)); flip_short(&(old->scen_items[i].value)); @@ -202,12 +191,10 @@ void port_item_list(legacy::scen_item_data_type* old){ } void port_out(legacy::outdoor_record_type *out) { - short i; - if(cur_scen_is_mac != mac_is_intel) return; - for(i = 0; i < 4; i++) { + for(short i = 0; i < 4; i++) { flip_short(&(out->wandering[i].spec_on_meet)); flip_short(&(out->wandering[i].spec_on_win)); flip_short(&(out->wandering[i].spec_on_flee)); @@ -221,42 +208,41 @@ void port_out(legacy::outdoor_record_type *out) { flip_short(&(out->special_enc[i].end_spec1)); flip_short(&(out->special_enc[i].end_spec2)); } - for(i = 0; i < 8; i++) + for(short i = 0; i < 8; i++) flip_rect(&(out->info_rect[i])); - for(i = 0; i < 60; i++) + for(short i = 0; i < 60; i++) flip_spec_node(&(out->specials[i])); } void port_party(legacy::party_record_type* old){ - int i,j,k; flip_long(&old->age); flip_short(&old->gold); flip_short(&old->food); flip_short(&old->light_level); - for(i = 0; i < 30; i++){ + for(short i = 0; i < 30; i++){ flip_short(&old->boats[i].which_town); flip_short(&old->horses[i].which_town); flip_short(&old->party_event_timers[i]); flip_short(&old->global_or_town[i]); flip_short(&old->node_to_call[i]); } - for(i = 0; i < 4; i++){ + for(short i = 0; i < 4; i++){ flip_short(&old->creature_save[i].which_town); flip_short(&old->creature_save[i].hostile); - for(j = 0; j < 60; j++){ + for(short j = 0; j < 60; j++){ flip_short(&old->creature_save[i].dudes[j].active); flip_short(&old->creature_save[i].dudes[j].attitude); flip_short(&old->creature_save[i].dudes[j].m_d.health); flip_short(&old->creature_save[i].dudes[j].m_d.m_health); flip_short(&old->creature_save[i].dudes[j].m_d.mp); flip_short(&old->creature_save[i].dudes[j].m_d.max_mp); - for(k = 0; k < 3; k++) + for(short k = 0; k < 3; k++) flip_short(&old->creature_save[i].dudes[j].m_d.a[k]); flip_short(&old->creature_save[i].dudes[j].m_d.morale); flip_short(&old->creature_save[i].dudes[j].m_d.m_morale); flip_short(&old->creature_save[i].dudes[j].m_d.corpse_item); flip_short(&old->creature_save[i].dudes[j].m_d.corpse_item_chance); - for(k = 0; k < 15; k++) + for(short k = 0; k < 15; k++) flip_short(&old->creature_save[i].dudes[j].m_d.status[k]); flip_short(&old->creature_save[i].dudes[j].m_d.picture_num); flip_short(&old->creature_save[i].dudes[j].summoned); @@ -271,7 +257,7 @@ void port_party(legacy::party_record_type* old){ } flip_short(&old->in_boat); flip_short(&old->in_horse); - for(i = 0; i < 10; i++){ + for(short i = 0; i < 10; i++){ flip_short(&old->out_c[i].direction); flip_short(&old->out_c[i].what_monst.spec_on_meet); flip_short(&old->out_c[i].what_monst.spec_on_win); @@ -280,19 +266,19 @@ void port_party(legacy::party_record_type* old){ flip_short(&old->out_c[i].what_monst.end_spec1); flip_short(&old->out_c[i].what_monst.end_spec2); } - for(i = 0; i < 5; i++) - for(j = 0; j < 10; j++){ + for(short i = 0; i < 5; i++) + for(short j = 0; j < 10; j++){ flip_short(&old->magic_store_items[i][j].variety); flip_short(&old->magic_store_items[i][j].item_level); flip_short(&old->magic_store_items[i][j].value); } - for(i = 0; i < 50; i++) + for(short i = 0; i < 50; i++) flip_short(&old->journal_day[i]); - for(i = 0; i < 140; i++){ + for(short i = 0; i < 140; i++){ flip_short(&old->special_notes_str[i][0]); flip_short(&old->special_notes_str[i][1]); } - for(i = 0; i < 120; i++){ + for(short i = 0; i < 120; i++){ flip_short(&old->talk_save[i].personality); flip_short(&old->talk_save[i].town_num); flip_short(&old->talk_save[i].str1); @@ -300,9 +286,9 @@ void port_party(legacy::party_record_type* old){ } flip_short(&old->direction); flip_short(&old->at_which_save_slot); - for(i = 0; i < 100; i++) + for(short i = 0; i < 100; i++) flip_short(&old->key_times[i]); - for(i = 0; i < 200; i++) + for(short i = 0; i < 200; i++) flip_short(&old->m_killed[i]); flip_long(&old->total_m_killed); flip_long(&old->total_dam_done); @@ -311,9 +297,8 @@ void port_party(legacy::party_record_type* old){ } void port_pc(legacy::pc_record_type* old){ - int i; flip_short(&old->main_status); - for(i = 0; i < 30; i++) + for(short i = 0; i < 30; i++) flip_short(&old->skills[i]); flip_short(&old->max_health); flip_short(&old->cur_health); @@ -322,9 +307,9 @@ void port_pc(legacy::pc_record_type* old){ flip_short(&old->experience); flip_short(&old->skill_pts); flip_short(&old->level); - for(i = 0; i < 15; i++) + for(short i = 0; i < 15; i++) flip_short(&old->status[i]); - for(i = 0; i < 10; i++){ + for(short i = 0; i < 10; i++){ flip_short(&old->items[i].variety); flip_short(&old->items[i].item_level); flip_short(&old->items[i].value); @@ -337,26 +322,25 @@ void port_pc(legacy::pc_record_type* old){ } void port_c_town(legacy::current_town_type* old){ - int i,j; flip_short(&old->town_num); flip_short(&old->difficulty); port_town(&old->town); flip_short(&old->monst.which_town); flip_short(&old->monst.hostile); - for(j = 0; j < 60; j++){ + for(short j = 0; j < 60; j++){ flip_short(&old->monst.dudes[j].active); flip_short(&old->monst.dudes[j].attitude); flip_short(&old->monst.dudes[j].m_d.health); flip_short(&old->monst.dudes[j].m_d.m_health); flip_short(&old->monst.dudes[j].m_d.mp); flip_short(&old->monst.dudes[j].m_d.max_mp); - for(i = 0; i < 3; i++) + for(short i = 0; i < 3; i++) flip_short(&old->monst.dudes[j].m_d.a[i]); flip_short(&old->monst.dudes[j].m_d.morale); flip_short(&old->monst.dudes[j].m_d.m_morale); flip_short(&old->monst.dudes[j].m_d.corpse_item); flip_short(&old->monst.dudes[j].m_d.corpse_item_chance); - for(i = 0; i < 15; i++) + for(short i = 0; i < 15; i++) flip_short(&old->monst.dudes[j].m_d.status[i]); flip_short(&old->monst.dudes[j].m_d.picture_num); flip_short(&old->monst.dudes[j].summoned); diff --git a/src/tools/soundtool.cpp b/src/tools/soundtool.cpp index 38db3452..6f150b95 100644 --- a/src/tools/soundtool.cpp +++ b/src/tools/soundtool.cpp @@ -39,9 +39,7 @@ std::unordered_map sound_delay = { short store_last_sound_played; bool sound_going(snd_num_t which_s) { - short i; - - for(i = 0; i < 4; i++) + for(short i = 0; i < 4; i++) if(snd_played[i] == which_s) return chan[i]->getStatus() == sf::Sound::Playing; return false;