From 17ad90ece1134d6dffa5f4a749ecf71cdd155b01 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sat, 21 Jan 2023 20:42:07 -0500 Subject: [PATCH] Check for out-of-bound terrains when building roads Thanks to @fosnola for noticing this. --- src/game/boe.graphics.cpp | 10 ++++++++-- src/game/boe.locutils.cpp | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/game/boe.graphics.cpp b/src/game/boe.graphics.cpp index 44b04906..6799a6da 100644 --- a/src/game/boe.graphics.cpp +++ b/src/game/boe.graphics.cpp @@ -1187,6 +1187,7 @@ static bool can_build_roads_on(ter_num_t ter) { } static bool connect_roads(ter_num_t ter){ + if(ter >= univ.scenario.ter_types.size()) return false; eTrimType trim = univ.scenario.ter_types[ter].trim_type; eTerSpec spec = univ.scenario.ter_types[ter].special; if(trim == eTrimType::CITY) @@ -1252,10 +1253,15 @@ void place_road(short q,short r,location where,bool here) { ter_num_t ter = coord_to_ter(where.x, where.y); ter_num_t ref = coord_to_ter(where.x,where.y); bool horz = false, vert = false; - eTrimType trim = univ.scenario.ter_types[ref].trim_type; + eTrimType trim = eTrimType::NONE, vertTrim = eTrimType::NONE; + if(ref < univ.scenario.ter_types.size()) { + trim = univ.scenario.ter_types[ref].trim_type; + } + if(ter < univ.scenario.ter_types.size()) { + vertTrim = univ.scenario.ter_types[ter].trim_type; + } if(where.y > 0) ter = coord_to_ter(where.x,where.y - 1); - eTrimType vertTrim = univ.scenario.ter_types[ter].trim_type; if((where.y == 0) || connect_roads(ter)) vert = can_build_roads_on(ref); else if((vertTrim == eTrimType::S && trim == eTrimType::N) || (vertTrim == eTrimType::N && trim == eTrimType::S)) diff --git a/src/game/boe.locutils.cpp b/src/game/boe.locutils.cpp index 18df6680..c65b8d63 100644 --- a/src/game/boe.locutils.cpp +++ b/src/game/boe.locutils.cpp @@ -442,6 +442,7 @@ bool outd_is_special(location to_check) { } bool impassable(ter_num_t terrain_to_check) { + if(terrain_to_check >= univ.scenario.ter_types.size()) return true; if(univ.scenario.ter_types[terrain_to_check].blocksMove()) return true; else return false;