continue to protect vector against bad index + simplify some code...

This commit is contained in:
ALONSO Laurent
2021-10-24 14:22:42 +02:00
committed by Celtic Minstrel
parent f3a96391b5
commit 66ad6bdefa
22 changed files with 203 additions and 168 deletions

View File

@@ -410,7 +410,7 @@ static bool handle_rb_action(location the_point, bool option_hit) {
current_terrain->specials.pop_back();
else if(j == size_before)
break;
else current_terrain->specials[j] = cSpecial();
else current_terrain->get_special(j) = cSpecial();
} else {
if(j == size_before)
current_terrain->specials.emplace_back();
@@ -428,7 +428,7 @@ static bool handle_rb_action(location the_point, bool option_hit) {
town->specials.pop_back();
else if(j == size_before)
break;
else town->specials[j] = cSpecial();
else town->get_special(j) = cSpecial();
} else {
if(j == size_before)
town->specials.emplace_back();
@@ -2159,9 +2159,9 @@ void place_edit_special(location loc) {
return;
}
auto& specials = editing_town ? town->special_locs : current_terrain->special_locs;
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);
for(auto &special : specials)
if(special == loc && special.spec >= 0) {
edit_spec_enc(special.spec, editing_town ? 2 : 1, nullptr);
return;
}
// new special
@@ -2185,10 +2185,10 @@ void set_special(location spot_hit) {
return;
}
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;
for(auto &special : specials)
if(special == spot_hit && special.spec >= 0) {
int spec = edit_special_num(editing_town ? 2 : 1,special.spec);
if(spec >= 0) special.spec = spec;
return;
}
for(short x = 0; x <= specials.size(); x++) {

View File

@@ -602,8 +602,8 @@ static bool commit_spec_enc(cDialog& me, std::string item_hit, node_stack_t& edi
int mode = edit_stack.top().mode, node = edit_stack.top().which;
switch(mode) {
case 0: scenario.scen_specials[node] = edit_stack.top().node; break;
case 1: current_terrain->specials[node] = edit_stack.top().node; break;
case 2: town->specials[node] = edit_stack.top().node; break;
case 1: current_terrain->get_special(node) = edit_stack.top().node; break;
case 2: town->get_special(node) = edit_stack.top().node; break;
}
edit_stack.pop();
if(item_hit == "okay") {
@@ -860,9 +860,9 @@ static bool edit_spec_enc_value(cDialog& me, std::string item_hit, node_stack_t&
if(mode == 0)
node_to_change_to = &scenario.scen_specials[store];
else if(mode == 1)
node_to_change_to = &current_terrain->specials[store];
node_to_change_to = &current_terrain->get_special(store);
else if(mode == 2)
node_to_change_to = &town->specials[store];
node_to_change_to = &town->get_special(store);
if (node_to_change_to) {
if(node_to_change_to->pic < 0)
node_to_change_to->pic = 0;
@@ -941,7 +941,7 @@ bool edit_spec_enc(short which_node,short mode,cDialog* parent) {
node_stack_t edit_stack;
if(mode == 0) {
if(which_node >= scenario.scen_specials.size()) {
if(which_node<0 || which_node >= scenario.scen_specials.size()) {
showError("That special node does not exist. You can create a new node by setting the field to -1 and trying again.", parent);
return false;
}
@@ -949,7 +949,7 @@ bool edit_spec_enc(short which_node,short mode,cDialog* parent) {
scenario.scen_specials[which_node].pic = 0;
the_node = scenario.scen_specials[which_node];
} else if(mode == 1) {
if(which_node >= current_terrain->specials.size()) {
if(which_node<0 || which_node >= current_terrain->specials.size()) {
showError("That special node does not exist. You can create a new node by setting the field to -1 and trying again.", parent);
return false;
}
@@ -957,7 +957,7 @@ bool edit_spec_enc(short which_node,short mode,cDialog* parent) {
current_terrain->specials[which_node].pic = 0;
the_node = current_terrain->specials[which_node];
} else if(mode == 2) {
if(which_node >= town->specials.size()) {
if(which_node<0 || which_node >= town->specials.size()) {
showError("That special node does not exist. You can create a new node by setting the field to -1 and trying again.", parent);
return false;
}