diff --git a/src/boe.actions.cpp b/src/boe.actions.cpp index 656c4fac..051f988b 100644 --- a/src/boe.actions.cpp +++ b/src/boe.actions.cpp @@ -456,7 +456,7 @@ static void handle_look(location destination, bool& need_redraw, bool& need_repr print_buf(); need_reprint = false; if(overall_mode == MODE_LOOK_TOWN) { - for(int k = 0; k < 15; k++) { + for(int k = 0; k < univ.town->sign_locs.size(); k++) { if(destination == univ.town->sign_locs[k]) { need_reprint = true; if(adjacent(univ.town->sign_locs[k],univ.town.p_loc)) @@ -465,7 +465,7 @@ static void handle_look(location destination, bool& need_redraw, bool& need_repr } } } else if(overall_mode == MODE_LOOK_OUTDOORS) { - for(int k = 0; k < 8; k++) { + for(int k = 0; k < univ.out->sign_locs.size(); k++) { if(destination == univ.out->sign_locs[k]) { need_reprint = true; if(adjacent(univ.out->sign_locs[k],univ.party.loc_in_sec)) @@ -526,11 +526,11 @@ static void handle_move(location destination, bool& did_something, bool& need_re else if(univ.party.direction < 4) find_direction_from = 3; else find_direction_from = 1; - for(int i = 0; i < 8; i++) + for(int i = 0; i < univ.out->exit_locs.size(); i++) if(univ.party.loc_in_sec == univ.out->exit_locs[i]) { - short which_t = univ.out->exit_dests[i]; + short which_t = univ.out->exit_locs[i].spec; if(which_t >= 0) - start_town_mode(univ.out->exit_dests[i], find_direction_from); + start_town_mode(univ.out->exit_locs[i].spec, find_direction_from); if(is_town()) { need_redraw = false; i = 8; diff --git a/src/boe.dlgutil.cpp b/src/boe.dlgutil.cpp index 94bb08a3..0dbc529f 100644 --- a/src/boe.dlgutil.cpp +++ b/src/boe.dlgutil.cpp @@ -866,7 +866,7 @@ void handle_talk_event(location p) { } else { for(i = b; i <= b + c; i++) - if((i >= 0) && (i < 30) && (univ.party.boats[i].property)) { + 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; @@ -892,7 +892,7 @@ void handle_talk_event(location p) { } else { for(i = b; i <= b + c; i++) - if((i >= 0) && (i < 30) && (univ.party.horses[i].property)) { + 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; diff --git a/src/boe.fileio.cpp b/src/boe.fileio.cpp index 6966d62d..61946f64 100644 --- a/src/boe.fileio.cpp +++ b/src/boe.fileio.cpp @@ -408,7 +408,7 @@ void add_outdoor_maps() { // This takes the existing outdoor map info and supple void fix_boats() { short i; - for(i = 0; i < 30; i++) + for(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; @@ -421,7 +421,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 < 30; i++) + for(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.graphutil.cpp b/src/boe.graphutil.cpp index fe92b680..d7270b00 100644 --- a/src/boe.graphutil.cpp +++ b/src/boe.graphutil.cpp @@ -342,7 +342,7 @@ void draw_outd_boats(location center) { rectangle source_rect; short i; - for(i = 0; i < 30; i++) + for(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)) { @@ -350,7 +350,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 < 30; i++) + for(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)) { @@ -365,7 +365,7 @@ void draw_town_boat(location center) { rectangle source_rect; short i; - for(i = 0; i < 30; i++) + for(i = 0; i < univ.party.boats.size(); i++) if((univ.party.boats[i].which_town == univ.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) @@ -374,7 +374,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 < 30; i++) + for(i = 0; i < univ.party.horses.size(); i++) if((univ.party.horses[i].which_town == univ.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.party.cpp b/src/boe.party.cpp index 27d00d8c..bbe7da81 100644 --- a/src/boe.party.cpp +++ b/src/boe.party.cpp @@ -122,17 +122,15 @@ static void init_party_scen_data() { univ.party.loc_in_sec.y = univ.scenario.out_start.y; univ.party.p_loc.x = univ.scenario.out_start.x; univ.party.p_loc.y = univ.scenario.out_start.y; - for(i = 0; i < 30; i++) - univ.party.boats[i] = univ.scenario.boats[i]; - for(i = 0; i < 30; i++) - univ.party.horses[i] = univ.scenario.horses[i]; - for(i = 0; i < 30; i++) { + for(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]; univ.party.boats[i].exists = true; } } + } + for(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]; diff --git a/src/boe.specials.cpp b/src/boe.specials.cpp index 2ab9c972..e1cdd380 100644 --- a/src/boe.specials.cpp +++ b/src/boe.specials.cpp @@ -2175,13 +2175,13 @@ void general_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, break; case eSpecType::CHANGE_HORSE_OWNER: check_mess = true; - if(spec.ex1a != minmax(0,29,spec.ex1a)) + if(spec.ex1a != minmax(0,univ.party.horses.size() - 1,spec.ex1a)) giveError("Horse out of range."); else univ.party.horses[spec.ex1a].property = (spec.ex2a == 0) ? 1 : 0; break; case eSpecType::CHANGE_BOAT_OWNER: check_mess = true; - if(spec.ex1a != minmax(0,29,spec.ex1a)) + if(spec.ex1a != minmax(0,univ.party.boats.size() - 1,spec.ex1a)) giveError("Boat out of range."); else univ.party.boats[spec.ex1a].property = (spec.ex2a == 0) ? 1 : 0; break; diff --git a/src/boe.text.cpp b/src/boe.text.cpp index fb27a39a..3d9fa347 100644 --- a/src/boe.text.cpp +++ b/src/boe.text.cpp @@ -801,8 +801,7 @@ short do_look(location space) { short town_boat_there(location where) { short i; - // Num boats stores highest # of boat in town - for(i = 0; i < 30; i++) + for(i = 0; i < univ.party.boats.size(); i++) if((univ.party.boats[i].exists) && (univ.party.boats[i].which_town == univ.town.num) && (where == univ.party.boats[i].loc)) return i; @@ -811,7 +810,7 @@ short town_boat_there(location where) { short out_boat_there(location where) { short i; - for(i = 0; i < 30; i++) + for(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; @@ -821,8 +820,7 @@ short out_boat_there(location where) { short town_horse_there(location where) { short i; - // Num boats stores highest # of boat in town - for(i = 0; i < 30; i++) + for(i = 0; i < univ.party.horses.size(); i++) if((univ.party.horses[i].exists) && (univ.party.horses[i].which_town == univ.town.num) && (where == univ.party.horses[i].loc)) return i; @@ -831,7 +829,7 @@ short town_horse_there(location where) { short out_horse_there(location where) { short i; - for(i = 0; i < 30; i++) + for(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; diff --git a/src/boe.town.cpp b/src/boe.town.cpp index 66018213..78a9c676 100644 --- a/src/boe.town.cpp +++ b/src/boe.town.cpp @@ -130,10 +130,10 @@ void start_town_mode(short which_town, short entry_dir) { former_town = town_number; town_number += PSD[univ.scenario.flag_to_add_to_town[i][0]][univ.scenario.flag_to_add_to_town[i][1]]; // Now update horses & boats - for(i = 0; i < 30; i++) + for(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 < 30; i++) + for(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; } @@ -509,13 +509,15 @@ void start_town_mode(short which_town, short entry_dir) { } // check horses - for(i = 0; i < 30; i++) { + for(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]; univ.party.boats[i].exists = true; } } + } + for(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]; @@ -1260,21 +1262,23 @@ void erase_out_specials() { for(short j = 0; j < 2; j++) if(quadrant_legal(i,j)) { cOutdoors& sector = *univ.scenario.outdoors[univ.party.outdoor_corner.x + i][univ.party.outdoor_corner.y + j]; - for(short k = 0; k < sector.special_locs.size(); k++) { - if(k < 8 && sector.exit_dests[k] >= 0 && + for(short k = 0; k < sector.exit_locs.size(); k++) { + if(sector.exit_locs[k].spec >= 0 && univ.scenario.ter_types[sector.terrain[sector.exit_locs[k].x][sector.exit_locs[k].y]].special == eTerSpec::TOWN_ENTRANCE && (sector.exit_locs[k].x == minmax(0,47,sector.exit_locs[k].x)) && (sector.exit_locs[k].y == minmax(0,47,sector.exit_locs[k].y))) { - if(!univ.party.can_find_town[sector.exit_dests[k]]) { + if(!univ.party.can_find_town[sector.exit_locs[k].spec]) { univ.out[48 * i + sector.exit_locs[k].x][48 * j + sector.exit_locs[k].y] = univ.scenario.ter_types[sector.terrain[sector.exit_locs[k].x][sector.exit_locs[k].y]].flag1; } - else if(univ.party.can_find_town[sector.exit_dests[k]]) { + else if(univ.party.can_find_town[sector.exit_locs[k].spec]) { univ.out[48 * i + sector.exit_locs[k].x][48 * j + sector.exit_locs[k].y] = sector.terrain[sector.exit_locs[k].x][sector.exit_locs[k].y]; } } + } + for(int k = 0; k < sector.special_locs.size(); k++) { if(sector.special_locs[k].spec < 0) continue; // TODO: Is this needed? Seems to be important, so why was it commented out? out_num = univ.scenario.outdoors.width() * (univ.party.outdoor_corner.y + j) + univ.party.outdoor_corner.x + i; diff --git a/src/classes/outdoors.cpp b/src/classes/outdoors.cpp index 28c0e505..2cf25119 100644 --- a/src/classes/outdoors.cpp +++ b/src/classes/outdoors.cpp @@ -77,7 +77,7 @@ void cOutdoors::append(legacy::outdoor_record_type& old){ for(i = 0; i < 8; i++){ exit_locs[i].x = old.exit_locs[i].x; exit_locs[i].y = old.exit_locs[i].y; - exit_dests[i] = old.exit_dests[i]; + exit_locs[i].spec = old.exit_dests[i]; sign_locs[i].x = old.sign_locs[i].x; sign_locs[i].y = old.sign_locs[i].y; info_rect[i].top = old.info_rect[i].top; diff --git a/src/classes/outdoors.h b/src/classes/outdoors.h index b98e8c56..7723caac 100644 --- a/src/classes/outdoors.h +++ b/src/classes/outdoors.h @@ -61,9 +61,8 @@ public: short x,y; // Used while loading legacy scenarios. ter_num_t terrain[48][48]; std::vector special_locs; - location exit_locs[8]; - short exit_dests[8]; - location sign_locs[8]; + std::array exit_locs; + std::array sign_locs; std::array wandering, special_enc; location wandering_locs[4]; std::vector specials; diff --git a/src/classes/town.h b/src/classes/town.h index e49423cd..353f2756 100644 --- a/src/classes/town.h +++ b/src/classes/town.h @@ -74,7 +74,7 @@ public: cWandering wandering[4]; location wandering_locs[4]; std::vector special_locs; - location sign_locs[15]; + std::array sign_locs; eLighting lighting_type; location start_locs[4]; location exit_locs[4]; diff --git a/src/pcedit/pc.main.cpp b/src/pcedit/pc.main.cpp index b9ed4cd8..330ec44b 100644 --- a/src/pcedit/pc.main.cpp +++ b/src/pcedit/pc.main.cpp @@ -262,10 +262,10 @@ void handle_menu_choice(eMenu item_hit) { break; case eMenu::OWN_VEHICLES: display_strings(6,7); - for(i = 0; i < 30; i++) { + for(i = 0; i < univ.party.boats.size(); i++) univ.party.boats[i].property = false; + for(i = 0; i < univ.party.horses.size(); i++) univ.party.horses[i].property = false; - } break; case eMenu::EDIT_DAY: edit_day(); diff --git a/src/scenedit/scen.actions.cpp b/src/scenedit/scen.actions.cpp index 4af92632..5f2a272c 100644 --- a/src/scenedit/scen.actions.cpp +++ b/src/scenedit/scen.actions.cpp @@ -754,7 +754,7 @@ bool handle_action(location the_point,sf::Event /*event*/) { break; case MODE_EDIT_SIGN: //edit sign if(editing_town) { - for(x = 0; x < 15; x++) + 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); x = 30; @@ -764,7 +764,7 @@ bool handle_action(location the_point,sf::Event /*event*/) { } } if(!editing_town) { - for(x = 0; x < 8; x++) + 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; @@ -1854,12 +1854,12 @@ void set_terrain(location l,ter_num_t terrain_type) { l.y--; if(scenario.ter_types[terrain_type].special == eTerSpec::IS_A_SIGN && editing_town) { - for(i = 0; i < 15; i++) + 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; } - for(i = 0; i < 15; i++) + for(i = 0; i < town->sign_locs.size(); i++) if(which_sign < 0) { if(town->sign_locs[i].x == 100) which_sign = i; @@ -1889,12 +1889,12 @@ void set_terrain(location l,ter_num_t terrain_type) { mouse_button_held = false; return; } - for(i = 0; i < 8; i++) + 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; } - for(i = 0; i < 8; i++) + for(i = 0; i < current_terrain->sign_locs.size(); i++) if(which_sign < 0) { if(current_terrain->sign_locs[i].x == 100) which_sign = i; @@ -2928,25 +2928,25 @@ void town_entry(location spot_hit) { giveError("This space isn't a town entrance. Town entrances are marked by a small brown castle icon."); return; } - // clean up old town entrys - for(x = 0; x < 8; x++) - if(current_terrain->exit_locs[x].x < 100) { + // clean up old town entries + for(x = 0; x < current_terrain->exit_locs.size(); x++) + if(current_terrain->exit_locs[x].spec >= 0) { ter = current_terrain->terrain[current_terrain->exit_locs[x].x][current_terrain->exit_locs[x].y]; if(scenario.ter_types[ter].special != eTerSpec::TOWN_ENTRANCE) - current_terrain->exit_locs[x].x = 100; + current_terrain->exit_locs[x].spec = -1; } y = -2; - for(x = 0; x < 8; x++) - if((current_terrain->exit_locs[x].x == spot_hit.x) && (current_terrain->exit_locs[x].y == spot_hit.y)) { - y = pick_town_num("select-town-enter",current_terrain->exit_dests[x],scenario); - if(y >= 0) current_terrain->exit_dests[x] = y; + for(x = 0; x < current_terrain->exit_locs.size(); x++) + if(current_terrain->exit_locs[x] == spot_hit) { + y = pick_town_num("select-town-enter",current_terrain->exit_locs[x].spec,scenario); + if(y >= 0) current_terrain->exit_locs[x].spec = y; } if(y == -2) { - for(x = 0; x < 8; x++) - if(current_terrain->exit_locs[x].x == 100) { + for(x = 0; x < current_terrain->exit_locs.size(); x++) + if(current_terrain->exit_locs[x].spec < 0) { y = pick_town_num("select-town-enter",0,scenario); if(y >= 0) { - current_terrain->exit_dests[x] = y; + current_terrain->exit_locs[x].spec = y; current_terrain->exit_locs[x] = spot_hit; } x = 500; diff --git a/src/scenedit/scen.fileio.cpp b/src/scenedit/scen.fileio.cpp index a7cfadb6..386e51a1 100644 --- a/src/scenedit/scen.fileio.cpp +++ b/src/scenedit/scen.fileio.cpp @@ -690,9 +690,9 @@ map_data buildOutMapData(location which) { if(sector.special_locs[i].spec >= 0) terrain.addFeature(sector.special_locs[i].x, sector.special_locs[i].y, eMapFeature::SPECIAL_NODE, sector.special_locs[i].spec); } - for(size_t i = 0; i < 8; i++) { - if(sector.exit_dests[i] >= 0) - terrain.addFeature(sector.exit_locs[i].x, sector.exit_locs[i].y, eMapFeature::TOWN, sector.exit_dests[i]); + for(size_t i = 0; i < sector.exit_locs.size(); i++) { + if(sector.exit_locs[i].spec >= 0) + terrain.addFeature(sector.exit_locs[i].x, sector.exit_locs[i].y, eMapFeature::TOWN, sector.exit_locs[i].spec); } for(size_t i = 0; i < sector.sign_strs.size(); i++) { if(!sector.sign_strs[i].empty()) @@ -701,12 +701,14 @@ map_data buildOutMapData(location which) { for(size_t i = 0; i < 4; i++) { terrain.addFeature(sector.wandering_locs[i].x, sector.wandering_locs[i].y, eMapFeature::WANDERING, i); } - for(size_t i = 0; i < 30; i++) { + for(size_t i = 0; i < scenario.boats.size(); i++) { if(scenario.boats[i].which_town == 200 && scenario.boats[i].sector == which) { int j = i; if(scenario.boats[i].property) j *= -1; terrain.addFeature(scenario.boats[i].loc.x, scenario.boats[i].loc.y, eMapFeature::HORSE, j); } + } + for(size_t i = 0; i < scenario.horses.size(); i++) { if(scenario.horses[i].which_town == 200 && scenario.horses[i].sector == which) { int j = i; if(scenario.horses[i].property) j *= -1; @@ -747,12 +749,14 @@ map_data buildTownMapData(size_t which) { if(town.creatures[i].number > 0) terrain.addFeature(town.creatures[i].start_loc.x, town.creatures[i].start_loc.y, eMapFeature::CREATURE, i); } - for(size_t i = 0; i < 30; i++) { + for(size_t i = 0; i < scenario.boats.size(); i++) { if(scenario.boats[i].which_town == which) { int j = i; if(scenario.boats[i].property) j *= -1; terrain.addFeature(scenario.boats[i].loc.x, scenario.boats[i].loc.y, eMapFeature::HORSE, j); } + } + for(size_t i = 0; i < scenario.horses.size(); i++) { if(scenario.horses[i].which_town == which) { int j = i; if(scenario.horses[i].property) j *= -1; diff --git a/src/scenedit/scen.graphics.cpp b/src/scenedit/scen.graphics.cpp index 49fc9881..2312ff7a 100644 --- a/src/scenedit/scen.graphics.cpp +++ b/src/scenedit/scen.graphics.cpp @@ -687,14 +687,14 @@ void draw_terrain(){ } if(editing_town) { - for(i = 0; i < 30; i++) { + for(i = 0; i < scenario.boats.size(); i++) { if((scenario.boats[i].which_town == cur_town) && (scenario.boats[i].loc.x == cen_x + q - 4) && (scenario.boats[i].loc.y == cen_y + r - 4)) Draw_Some_Item(vehicle_gworld,boat_rect,ter_draw_gworld,where_draw,sf::BlendAlpha); } - for(i = 0; i < 30; i++) { + for(i = 0; i < scenario.horses.size(); i++) { source_rect = boat_rect; source_rect.offset(0,36); if((scenario.horses[i].which_town == cur_town) &&