From 31c5a24e81042a72391a000d5354a0ab0d1918cf Mon Sep 17 00:00:00 2001 From: ALONSO Laurent Date: Sat, 23 Oct 2021 13:40:49 +0200 Subject: [PATCH] continue to add methods to check bounds, to be continued, + try to do not add empty strings in encounter message + minimap: try to remove flickering on OsX + correct cScenario::get_ter_from_ground --- src/fileio/fileio_scen.cpp | 22 +++---- src/game/boe.graphics.cpp | 2 +- src/game/boe.infodlg.cpp | 3 +- src/game/boe.locutils.cpp | 1 + src/game/boe.minimap.cpp | 7 ++- src/game/boe.text.cpp | 7 ++- src/game/boe.town.cpp | 2 +- src/scenario/area.cpp | 21 +++++++ src/scenario/area.hpp | 9 ++- src/scenario/outdoors.hpp | 16 +++++ src/scenario/scenario.cpp | 4 +- src/scenedit/scen.actions.cpp | 20 +++--- src/scenedit/scen.fileio.cpp | 2 +- src/scenedit/scen.graphics.cpp | 13 +--- src/scenedit/scen.keydlgs.cpp | 20 +++--- src/universe/universe.cpp | 111 +++++++++++++++++---------------- 16 files changed, 153 insertions(+), 107 deletions(-) diff --git a/src/fileio/fileio_scen.cpp b/src/fileio/fileio_scen.cpp index d0594207..6afa2e99 100644 --- a/src/fileio/fileio_scen.cpp +++ b/src/fileio/fileio_scen.cpp @@ -1643,14 +1643,14 @@ void readOutdoorsFromXml(ticpp::Document&& data, cOutdoors& out) { } else if(type == "sign") { int sign; elem->GetAttribute("id", &sign); - if(sign >= out.sign_locs.size() && sign<10000) + if(sign >= out.sign_locs.size() && sign<1000) out.sign_locs.resize(sign + 1); elem->GetText(&out.get_sign_loc(sign).text, false); } else if(type == "area") { - if(num_rects >= out.area_desc.size()) + if(num_rects >= out.area_desc.size() && num_rects<1000) out.area_desc.resize(num_rects + 1); - static_cast(out.area_desc[num_rects]) = readRectFromXml(*elem); - elem->GetText(&out.area_desc[num_rects].descr, false); + static_cast(out.get_area_desc(num_rects)) = readRectFromXml(*elem); + elem->GetText(&out.get_area_desc(num_rects).descr, false); num_rects++; } else if(type == "string") { int str; @@ -1860,10 +1860,10 @@ void readTownFromXml(ticpp::Document&& data, cTown*& town, cScenario& scen) { if(!reqs.empty()) throw xMissingElem("creature", *reqs.begin(), elem->Row(), elem->Column(), fname); } else if(type == "area") { - if(num_rects >= town->area_desc.size()) + if(num_rects >= town->area_desc.size() && num_rects<1000) town->area_desc.resize(num_rects + 1); - static_cast(town->area_desc[num_rects]) = readRectFromXml(*elem); - elem->GetText(&town->area_desc[num_rects].descr, false); + static_cast(town->get_area_desc(num_rects)) = readRectFromXml(*elem); + elem->GetText(&town->get_area_desc(num_rects).descr, false); num_rects++; } else throw xBadNode(type, elem->Row(), elem->Column(), fname); } @@ -1995,9 +1995,9 @@ void loadOutMapData(map_data&& data, location which, cScenario& scen) { break; case eMapFeature::FIELD: if(feat.second == SPECIAL_SPOT) - out.special_spot[x][y] = true; + out.set_special_spot(x,y,true); else if(feat.second == SPECIAL_ROAD) - out.roads[x][y] = true; + out.set_road(x,y,true); else throw xMapParseError(map_out_bad_field, feat.second, y, x, data.file); break; case eMapFeature::SIGN: @@ -2346,7 +2346,7 @@ bool load_town_v1(fs::path scen_file, short which_town, cTown& the_town, legacy: std::string tmp=right_trim(temp_str); if(i == 0) the_town.name = tmp; else if(i >= 1 && i < 17) - the_town.area_desc[i-1].descr = tmp; + the_town.get_area_desc(i-1).descr = tmp; else if(i >= 17 && i < 20) the_town.comment[i-17] = tmp; else if(i >= 20 && i < 120) @@ -2460,7 +2460,7 @@ bool load_outdoors_v1(fs::path scen_file, location which_out,cOutdoors& the_out, std::string tmp=right_trim(temp_str); if(i == 0) the_out.name = tmp; else if(i == 9) the_out.comment = tmp; - else if(i < 9) the_out.area_desc[i-1].descr = tmp; + else if(i < 9) the_out.get_area_desc(i-1).descr = tmp; else if(i >= 10 && i < 100) the_out.get_special_string(i-10) = tmp; else if(i >= 100 && i < 108) diff --git a/src/game/boe.graphics.cpp b/src/game/boe.graphics.cpp index 98450c46..c37f52f2 100644 --- a/src/game/boe.graphics.cpp +++ b/src/game/boe.graphics.cpp @@ -865,7 +865,7 @@ void draw_terrain(short mode) { if((can_draw != 0) && (overall_mode != MODE_RESTING) && frills_on && draw_frills) place_trim((short) q,(short) r,where_draw,spec_terrain); // if((is_town() && univ.town.is_spot(where_draw.x,where_draw.y)) || -// (is_out() && univ.out.outdoors[univ.party.i_w_c.x][univ.party.i_w_c.y].special_spot[where_draw.x][where_draw.y])) +// (is_out() && univ.out.outdoors[univ.party.i_w_c.x][univ.party.i_w_c.y].is_special_spot(where_draw.x,where_draw.y))) // Draw_Some_Item(roads_gworld, calc_rect(6, 0), terrain_screen_gworld, loc(q,r), 1, 0); // TODO: Move draw_sfx, draw_items, draw_fields, draw_spec_items, etc to here diff --git a/src/game/boe.infodlg.cpp b/src/game/boe.infodlg.cpp index faba8b7f..3f7de93a 100644 --- a/src/game/boe.infodlg.cpp +++ b/src/game/boe.infodlg.cpp @@ -714,6 +714,7 @@ void cStringRecorder::operator()(cDialog& me) { } if(univ.party.record(type, str1, location)) give_help(58,0,&me); - univ.party.record(type, str2, location); + if (!str2.empty()) + univ.party.record(type, str2, location); } diff --git a/src/game/boe.locutils.cpp b/src/game/boe.locutils.cpp index 607a7c56..7e49f0fd 100644 --- a/src/game/boe.locutils.cpp +++ b/src/game/boe.locutils.cpp @@ -146,6 +146,7 @@ bool loc_off_world(location p1) { } bool loc_off_act_area(location p1) { + if (!univ.town->is_on_map(p1)) return true; if((p1.x > univ.town->in_town_rect.left) && (p1.x < univ.town->in_town_rect.right) && (p1.y > univ.town->in_town_rect.top) && (p1.y < univ.town->in_town_rect.bottom)) return false; diff --git a/src/game/boe.minimap.cpp b/src/game/boe.minimap.cpp index 4ac2ba08..01ce3886 100644 --- a/src/game/boe.minimap.cpp +++ b/src/game/boe.minimap.cpp @@ -6,6 +6,7 @@ // #include +#include #include #include "cursors.hpp" @@ -235,13 +236,17 @@ void draw(bool need_refresh) { else rect_draw_some_item(src_gw, custom_from, gworld, draw_rect); - if(is_out() ? univ.out->roads[where.x][where.y] : univ.town.is_road(where.x,where.y)) { + if(is_out() ? univ.out->is_road(where.x,where.y) : univ.town.is_road(where.x,where.y)) { draw_rect.inset(1,1); rect_draw_some_item(*ResMgr::textures.get("trim"),{8,112,12,116},gworld,draw_rect); } } gworld.display(); +#ifdef __APPLE__ + // this stops flickering if the display time is too long + glFlush(); +#endif } windows.setActive(false); diff --git a/src/game/boe.text.cpp b/src/game/boe.text.cpp index 574a0742..3ffe5a22 100644 --- a/src/game/boe.text.cpp +++ b/src/game/boe.text.cpp @@ -94,7 +94,7 @@ void put_pc_screen() { rectangle bottom_bar_rect = {99,0,116,271}; rectangle info_from = {0,1,12,13}, switch_from = {0, 13, 12, 25}; - pc_stats_gworld.setActive(); + pc_stats_gworld.setActive(false); // First clean up gworld with pretty patterns auto const &orig = *ResMgr::textures.get("statarea"); @@ -197,6 +197,7 @@ void put_pc_screen() { to_draw_rect = {101,251,114,267}; rect_draw_some_item(invenbtn_gworld, help_from_rect, pc_stats_gworld, to_draw_rect, sf::BlendAlpha); + pc_stats_gworld.setActive(); pc_stats_gworld.display(); // Sometimes this gets called when character is slain. when that happens, if items for @@ -718,13 +719,13 @@ short do_look(location space) { } } location lSpace=global_to_local(space); - if(univ.out->roads[lSpace.x][lSpace.y]) + if(univ.out->is_road(lSpace.x,lSpace.y)) add_string_to_buf(" Road"); if(out_boat_there(space)) add_string_to_buf(" Boat"); if(out_horse_there(space)) add_string_to_buf(" Horse"); - if(univ.out->special_spot[lSpace.x][lSpace.y]) + if(univ.out->is_special_spot(lSpace.x,lSpace.y)) add_string_to_buf(" Special Encounter"); } diff --git a/src/game/boe.town.cpp b/src/game/boe.town.cpp index 95984812..6db6ddbe 100644 --- a/src/game/boe.town.cpp +++ b/src/game/boe.town.cpp @@ -1144,7 +1144,7 @@ void erase_out_specials() { erase_hidden_towns(sector, i, j); erase_completed_specials(sector, [§or](location where){ - sector.special_spot[where.x][where.y] = false; + sector.set_special_spot(where.x,where.y,false); }); } } diff --git a/src/scenario/area.cpp b/src/scenario/area.cpp index a6106e44..4d9edd69 100644 --- a/src/scenario/area.cpp +++ b/src/scenario/area.cpp @@ -7,6 +7,27 @@ #include "area.hpp" +static info_rect_t getBadAreaDesc() +{ + info_rect_t bad_area={-1,-1,-1,-1,"Bad Aread Desc"}; + return bad_area; +} +info_rect_t const &cArea::get_area_desc(int num) const +{ + if (num>=0 && num=0 && num(dim)) {} - bool is_on_map(location loc) const { + bool is_on_map(location const &loc) const { return loc.x < max_dim && loc.y < max_dim && loc.x >= 0 && loc.y >= 0; } - + bool is_on_map(short x, short y) const { + return x < max_dim && y < max_dim && x >= 0 && y >= 0; + } + + info_rect_t const &get_area_desc(int num) const; + info_rect_t &get_area_desc(int num); sign_loc_t const &get_sign_loc(int num) const; sign_loc_t &get_sign_loc(int num); }; diff --git a/src/scenario/outdoors.hpp b/src/scenario/outdoors.hpp index 4622586d..709b10a7 100644 --- a/src/scenario/outdoors.hpp +++ b/src/scenario/outdoors.hpp @@ -77,6 +77,22 @@ public: std::string &get_special_string(int id); std::string const &get_special_string(int id) const; + bool is_road(int x, int y) const { + if (x<0 || x>=48 || y<0 || y>=48) return false; + return roads[x][y]; + } + void set_road(int x, int y, bool set) { + if (x<0 || x>=48 || y<0 || y>=48) return; + roads[x][y]=set; + } + bool is_special_spot(int x, int y) const { + if (x<0 || x>=48 || y<0 || y>=48) return false; + return special_spot[x][y]; + } + void set_special_spot(int x, int y, bool set) { + if (x<0 || x>=48 || y<0 || y>=48) return; + special_spot[x][y]=set; + } }; #endif diff --git a/src/scenario/scenario.cpp b/src/scenario/scenario.cpp index 10c57cab..aed8e51c 100644 --- a/src/scenario/scenario.cpp +++ b/src/scenario/scenario.cpp @@ -492,7 +492,7 @@ ter_num_t cScenario::get_ground_from_ter(ter_num_t ter){ } ter_num_t cScenario::get_ter_from_ground(unsigned short ground){ - ter_num_t archetype = -1; + short archetype = -1; for(int i = 0; i < ter_types.size(); i++) if(ter_types[i].ground_type == ground) { if(ter_types[i].is_archetype) @@ -500,7 +500,7 @@ ter_num_t cScenario::get_ter_from_ground(unsigned short ground){ else if(archetype < 0) archetype = i; } - return std::max(archetype, ter_num_t()); + return archetype<0 ? ter_num_t() : archetype; } ter_num_t cScenario::get_trim_terrain(unsigned short ground, unsigned short trim_g, eTrimType trim) { diff --git a/src/scenedit/scen.actions.cpp b/src/scenedit/scen.actions.cpp index 6acc9f6d..358863d4 100644 --- a/src/scenedit/scen.actions.cpp +++ b/src/scenedit/scen.actions.cpp @@ -605,11 +605,11 @@ static bool handle_rb_action(location the_point, bool option_hit) { current_terrain->area_desc.pop_back(); else if(j == size_before) break; - else current_terrain->area_desc[j] = {0, 0, 0, 0, "*"}; + else current_terrain->get_area_desc(j) = {0, 0, 0, 0, "*"}; } else { if(j == size_before) current_terrain->area_desc.emplace_back(0,0,0,0,"*"); - if(!edit_text_str(j,STRS_OUT_RECT) && j == size_before && current_terrain->area_desc[j].descr == "*") + if(!edit_text_str(j,STRS_OUT_RECT) && j == size_before && current_terrain->get_area_desc(j).descr == "*") current_terrain->area_desc.pop_back(); } start_string_editing(STRS_OUT_RECT,size_before == current_terrain->area_desc.size()); @@ -624,11 +624,11 @@ static bool handle_rb_action(location the_point, bool option_hit) { town->area_desc.pop_back(); else if(j == size_before) break; - else town->area_desc[j] = {0, 0, 0, 0, "*"}; + else town->get_area_desc(j) = {0, 0, 0, 0, "*"}; } else { if(j == size_before) town->area_desc.emplace_back(0,0,0,0,"*"); - if(!edit_text_str(j,STRS_TOWN_RECT) && j == size_before && town->area_desc[j].descr == "*") + if(!edit_text_str(j,STRS_TOWN_RECT) && j == size_before && town->get_area_desc(j).descr == "*") town->area_desc.pop_back(); } start_string_editing(STRS_TOWN_RECT,size_before == town->area_desc.size()); @@ -926,8 +926,8 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { case MODE_TOGGLE_SPECIAL_DOT: if(!editing_town){ if(!mouse_button_held) - mode_count = !current_terrain->special_spot[spot_hit.x][spot_hit.y]; - current_terrain->special_spot[spot_hit.x][spot_hit.y] = mode_count; + mode_count = !current_terrain->is_special_spot(spot_hit.x,spot_hit.y); + current_terrain->set_special_spot(spot_hit.x,spot_hit.y,mode_count); mouse_button_held = true; break; } @@ -937,8 +937,8 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { case MODE_TOGGLE_ROAD: if(!editing_town){ if(!mouse_button_held) - mode_count = !current_terrain->roads[spot_hit.x][spot_hit.y]; - current_terrain->roads[spot_hit.x][spot_hit.y] = mode_count; + mode_count = !current_terrain->is_road(spot_hit.x,spot_hit.y); + current_terrain->set_road(spot_hit.x,spot_hit.y,mode_count); mouse_button_held = true; break; } @@ -2571,11 +2571,11 @@ void start_string_editing(eStrMode mode,short just_redo_text) { set_rb(i,RB_TOWN_SIGN, i,str.str()); break; case 6: - str << i << " - " << current_terrain->area_desc[i].descr.substr(0,30); + str << i << " - " << current_terrain->get_area_desc(i).descr.substr(0,30); set_rb(i,RB_OUT_RECT, i,str.str()); break; case 7: - str << i << " - " << town->area_desc[i].descr.substr(0,30); + str << i << " - " << town->get_area_desc(i).descr.substr(0,30); set_rb(i,RB_TOWN_RECT, i,str.str()); break; } diff --git a/src/scenedit/scen.fileio.cpp b/src/scenedit/scen.fileio.cpp index f9d4d3b3..5b1105ae 100644 --- a/src/scenedit/scen.fileio.cpp +++ b/src/scenedit/scen.fileio.cpp @@ -888,7 +888,7 @@ map_data buildOutMapData(location which, cScenario& scenario) { terrain.set(x, y, sector.terrain[x][y]); if(sector.special_spot[x][y]) terrain.addFeature(x, y, eMapFeature::FIELD, SPECIAL_SPOT); - if(sector.roads[x][y]) + if(sector.is_road(x,y)) terrain.addFeature(x, y, eMapFeature::FIELD, SPECIAL_ROAD); } } diff --git a/src/scenedit/scen.graphics.cpp b/src/scenedit/scen.graphics.cpp index 1a01043e..ff575256 100644 --- a/src/scenedit/scen.graphics.cpp +++ b/src/scenedit/scen.graphics.cpp @@ -34,7 +34,6 @@ void undo_clip(); short find_index_spot(); bool is_s_d(); -void sort_specials(); extern cOutdoors* current_terrain; extern sf::RenderWindow mainPtr; @@ -1428,23 +1427,17 @@ bool is_special(short i,short j) { return false; } -void sort_specials() { -} - bool is_spot(short i,short j){ if(editing_town) return is_field_type(i,j,SPECIAL_SPOT); - else if(i >= 0 && i < 48 && j >= 0 && j < 48) - return current_terrain->special_spot[i][j]; - return false; + return current_terrain->is_special_spot(i,j); } bool is_road(short i,short j){ if(editing_town) return is_field_type(i,j,SPECIAL_ROAD); - else if(i >= 0 && i < 48 && j >= 0 && j < 48) - return current_terrain->roads[i][j]; - return false; + else + return current_terrain->is_road(i,j); } bool is_field_type(short i,short j,eFieldType field_type) { diff --git a/src/scenedit/scen.keydlgs.cpp b/src/scenedit/scen.keydlgs.cpp index 5a35df70..9ed492ac 100644 --- a/src/scenedit/scen.keydlgs.cpp +++ b/src/scenedit/scen.keydlgs.cpp @@ -74,8 +74,8 @@ static std::string& fetch_str(eStrMode str_mode, size_t which) { case 3: return scenario.get_journal_string(which); case 4: return current_terrain->get_sign_loc(which).text; case 5: return town->get_sign_loc(which).text; - case 6: return current_terrain->area_desc[which].descr; - case 7: return town->area_desc[which].descr; + case 6: return current_terrain->get_area_desc(which).descr; + case 7: return town->get_area_desc(which).descr; } throw "Invalid string mode " + std::to_string(str_mode) + " (valid are 0-5)"; } @@ -96,16 +96,16 @@ static std::string str_info(eStrMode str_mode, size_t which) { sout << ", " << town->get_sign_loc(which).y << ")"; break; case 6: - sout << "(" << current_terrain->area_desc[which].left; - sout << ", " << current_terrain->area_desc[which].top; - sout << ")|(" << current_terrain->area_desc[which].right; - sout << ", " << current_terrain->area_desc[which].bottom << ")"; + sout << "(" << current_terrain->get_area_desc(which).left; + sout << ", " << current_terrain->get_area_desc(which).top; + sout << ")|(" << current_terrain->get_area_desc(which).right; + sout << ", " << current_terrain->get_area_desc(which).bottom << ")"; break; case 7: - sout << "(" << town->area_desc[which].left; - sout << ", " << town->area_desc[which].top; - sout << ")|(" << town->area_desc[which].right; - sout << ", " << town->area_desc[which].bottom << ")"; + sout << "(" << town->get_area_desc(which).left; + sout << ", " << town->get_area_desc(which).top; + sout << ")|(" << town->get_area_desc(which).right; + sout << ", " << town->get_area_desc(which).bottom << ")"; break; } return sout.str(); diff --git a/src/universe/universe.cpp b/src/universe/universe.cpp index 9818d9b0..ced19230 100644 --- a/src/universe/universe.cpp +++ b/src/universe/universe.cpp @@ -87,13 +87,14 @@ void cUniverse::import_legacy(legacy::stored_outdoor_maps_type const &old){ void cCurTown::import_reset_fields_legacy(){ // boe does not use the stored sfx and misc_i // but discard them and recompute their values + auto const &terrain=record()->terrain; for (auto const &f : record()->preset_fields) { - if (f.loc.x<0 || f.loc.x>=64 || f.loc.y<0 || f.loc.y>=64) continue; + if (f.loc.x<0 || f.loc.x>=terrain.width() || + f.loc.y<0 || f.loc.y>=terrain.height()) continue; // only 08 && f.type<17) || (f.type>=30 & f.type<=37)) fields[f.loc.x][f.loc.y]|=f.type; } - auto const &terrain=record()->terrain; for (auto const &spec : record()->special_locs) { if (spec.spec<0 || spec.x<0 || spec.x>=terrain.width() || spec.y<0 || spec.y>=terrain.height()) continue; @@ -206,60 +207,61 @@ cTown*const cCurTown::record() const { } bool cCurTown::is_explored(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SPECIAL_EXPLORED; } bool cCurTown::is_force_wall(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & WALL_FORCE; } bool cCurTown::is_fire_wall(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & WALL_FIRE; } bool cCurTown::is_antimagic(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & FIELD_ANTIMAGIC; } bool cCurTown::is_scloud(short x, short y) const{ // stinking cloud - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & CLOUD_STINK; } bool cCurTown::is_ice_wall(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & WALL_ICE; } bool cCurTown::is_blade_wall(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & WALL_BLADES; } bool cCurTown::is_sleep_cloud(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & CLOUD_SLEEP; } bool cCurTown::is_block(short x, short y) const{ // currently unused - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & OBJECT_BLOCK; } bool cCurTown::is_spot(short x, short y) const{ + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SPECIAL_SPOT; } bool cCurTown::is_road(short x, short y) const{ + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SPECIAL_ROAD; } bool cCurTown::is_special(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; location check(x,y); for(int i = 0; i < record()->special_locs.size(); i++) if(check == record()->special_locs[i] && record()->special_locs[i].spec >= 0) @@ -268,89 +270,89 @@ bool cCurTown::is_special(short x, short y) const{ } bool cCurTown::is_web(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & FIELD_WEB; } bool cCurTown::is_crate(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & OBJECT_CRATE; } bool cCurTown::is_barrel(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & OBJECT_BARREL; } bool cCurTown::is_fire_barr(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & BARRIER_FIRE; } bool cCurTown::is_force_barr(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & BARRIER_FORCE; } bool cCurTown::is_quickfire(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & FIELD_QUICKFIRE; } bool cCurTown::is_sm_blood(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SFX_SMALL_BLOOD; } bool cCurTown::is_med_blood(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SFX_MEDIUM_BLOOD; } bool cCurTown::is_lg_blood(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SFX_LARGE_BLOOD; } bool cCurTown::is_sm_slime(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SFX_SMALL_SLIME; } bool cCurTown::is_lg_slime(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SFX_LARGE_SLIME; } bool cCurTown::is_ash(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SFX_ASH; } bool cCurTown::is_bones(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SFX_BONES; } bool cCurTown::is_rubble(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & SFX_RUBBLE; } bool cCurTown::is_force_cage(short x, short y) const{ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; return fields[x][y] & BARRIER_CAGE; } bool cCurTown::set_explored(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b) fields[x][y] |= SPECIAL_EXPLORED; else fields[x][y] &= ~SPECIAL_EXPLORED; return true; } bool cCurTown::set_force_wall(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on space, there's no room for field. if(is_impassable(x,y)) return false; @@ -367,7 +369,7 @@ bool cCurTown::set_force_wall(short x, short y, bool b){ } bool cCurTown::set_fire_wall(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on space, there's no room for field. if(is_impassable(x,y)) return false; @@ -386,7 +388,7 @@ bool cCurTown::set_fire_wall(short x, short y, bool b){ } bool cCurTown::set_antimagic(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on space, there's no room for a field. if(is_impassable(x,y)) return false; @@ -406,7 +408,7 @@ bool cCurTown::set_antimagic(short x, short y, bool b){ } bool cCurTown::set_scloud(short x, short y, bool b){ // stinking cloud - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on space, there's no room for cloud. if(is_impassable(x,y)) return false; @@ -423,7 +425,7 @@ bool cCurTown::set_scloud(short x, short y, bool b){ // stinking cloud } bool cCurTown::set_ice_wall(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on space, ther's no room for a field. if(is_impassable(x,y)) return false; @@ -442,7 +444,7 @@ bool cCurTown::set_ice_wall(short x, short y, bool b){ } bool cCurTown::set_blade_wall(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // if certain things are on space, there's no room for a field. if(is_impassable(x,y)) return false; @@ -457,7 +459,7 @@ bool cCurTown::set_blade_wall(short x, short y, bool b){ } bool cCurTown::set_sleep_cloud(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // if certain things are on space, there's no room for cloud. if(is_impassable(x,y)) return false; @@ -472,28 +474,28 @@ bool cCurTown::set_sleep_cloud(short x, short y, bool b){ } bool cCurTown::set_block(short x, short y, bool b){ // currently unused - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b) fields[x][y] |= OBJECT_BLOCK; else fields[x][y] &= ~OBJECT_BLOCK; return true; } bool cCurTown::set_spot(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b) fields[x][y] |= SPECIAL_SPOT; else fields[x][y] &= ~SPECIAL_SPOT; return true; } bool cCurTown::set_road(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b) fields[x][y] |= SPECIAL_ROAD; else fields[x][y] &= ~SPECIAL_ROAD; return true; } bool cCurTown::set_web(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on the space, there's no room for webs if(is_impassable(x,y)) return false; @@ -510,7 +512,7 @@ bool cCurTown::set_web(short x, short y, bool b){ } bool cCurTown::set_crate(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on the space, there's no room for a crate. if(is_fire_barr(x,y) || is_force_barr(x,y) || is_quickfire(x,y) || is_barrel(x,y)) return false; @@ -521,7 +523,7 @@ bool cCurTown::set_crate(short x, short y, bool b){ } bool cCurTown::set_barrel(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on the space, there's no room for a crate. if(is_fire_barr(x,y) || is_force_barr(x,y) || is_quickfire(x,y) || is_crate(x,y)) return false; @@ -532,7 +534,7 @@ bool cCurTown::set_barrel(short x, short y, bool b){ } bool cCurTown::set_fire_barr(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on the space, there's no room for a barrier. if(is_barrel(x,y) || is_force_barr(x,y) || is_quickfire(x,y) || is_crate(x,y)) return false; @@ -554,7 +556,7 @@ bool cCurTown::set_fire_barr(short x, short y, bool b){ } bool cCurTown::set_force_barr(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on the space, there's no room for a barrier. if(is_fire_barr(x,y) || is_barrel(x,y) || is_quickfire(x,y) || is_crate(x,y)) return false; @@ -576,7 +578,7 @@ bool cCurTown::set_force_barr(short x, short y, bool b){ } bool cCurTown::set_quickfire(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ // If certain things are on space, there's no room for quickfire. cTerrain const &terrain=univ.get_terrain(record()->terrain(x,y)); if(terrain.blockage == eTerObstruct::BLOCK_SIGHT) @@ -613,7 +615,7 @@ bool cCurTown::free_for_sfx(short x, short y) { } bool cCurTown::set_sm_blood(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ if(!free_for_sfx(x,y)) return false; if(is_med_blood(x,y) || is_lg_blood(x,y)) @@ -630,7 +632,7 @@ bool cCurTown::set_sm_blood(short x, short y, bool b){ } bool cCurTown::set_med_blood(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ if(!free_for_sfx(x,y)) return false; if(is_lg_blood(x,y)) @@ -648,7 +650,7 @@ bool cCurTown::set_med_blood(short x, short y, bool b){ } bool cCurTown::set_lg_blood(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ if(!free_for_sfx(x,y)) return false; set_sm_blood(x,y,false); @@ -665,6 +667,7 @@ bool cCurTown::set_lg_blood(short x, short y, bool b){ } bool cCurTown::set_sm_slime(short x, short y, bool b){ + if(!record()->is_on_map(x,y)) return false; if(b){ if(!free_for_sfx(x,y)) return false; if(is_lg_slime(x,y)) @@ -682,7 +685,7 @@ bool cCurTown::set_sm_slime(short x, short y, bool b){ } bool cCurTown::set_lg_slime(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ if(!free_for_sfx(x,y)) return false; set_sm_blood(x,y,false); @@ -699,7 +702,7 @@ bool cCurTown::set_lg_slime(short x, short y, bool b){ } bool cCurTown::set_ash(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ if(!free_for_sfx(x,y)) return false; set_sm_blood(x,y,false); @@ -716,7 +719,7 @@ bool cCurTown::set_ash(short x, short y, bool b){ } bool cCurTown::set_bones(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ if(!free_for_sfx(x,y)) return false; set_sm_blood(x,y,false); @@ -733,7 +736,7 @@ bool cCurTown::set_bones(short x, short y, bool b){ } bool cCurTown::set_rubble(short x, short y, bool b){ - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b){ if(!free_for_sfx(x,y)) return false; set_sm_blood(x,y,false); @@ -752,7 +755,7 @@ bool cCurTown::set_rubble(short x, short y, bool b){ bool cCurTown::set_force_cage(short x, short y, bool b){ // TODO: Consider whether placing a forcecage should erase anything already present, or fail due to something already present // TODO: Also consider checking for forcecage in some of the other placement functions. - if(x > record()->max_dim || y > record()->max_dim) return false; + if(!record()->is_on_map(x,y)) return false; if(b) fields[x][y] |= BARRIER_CAGE; else fields[x][y] &= ~BARRIER_CAGE; return true; @@ -896,7 +899,7 @@ bool cCurOut::is_spot(int x, int y) { if (sector_x<0 || sector_x>=univ.scenario.outdoors.width() || sector_y<0 || sector_y>=univ.scenario.outdoors.height()) return false; - return univ.scenario.outdoors[sector_x][sector_y]->special_spot[x][y]; + return univ.scenario.outdoors[sector_x][sector_y]->is_special_spot(x,y); } bool cCurOut::is_road(int x, int y) { @@ -909,7 +912,7 @@ bool cCurOut::is_road(int x, int y) { if (sector_x<0 || sector_x>=univ.scenario.outdoors.width() || sector_y<0 || sector_y>=univ.scenario.outdoors.height()) return false; - return univ.scenario.outdoors[sector_x][sector_y]->roads[x][y]; + return univ.scenario.outdoors[sector_x][sector_y]->is_road(x,y); } cUniverse::cUniverse(ePartyPreset party_type) : party(party_type), out(*this), town(*this) {}