From d42c4fff08a445d41a9563d4299330d6aa831c43 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 1 Feb 2015 20:51:42 -0500 Subject: [PATCH] Alter boat specials fix to insert new special nodes if there's no unused ones, taking advantage of the fact that the lists of special nodes are now dynamically sized --- src/classes/regtown.cpp | 60 ++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/src/classes/regtown.cpp b/src/classes/regtown.cpp index 5e7604d10..4f2431f2e 100644 --- a/src/classes/regtown.cpp +++ b/src/classes/regtown.cpp @@ -54,20 +54,22 @@ void cTinyTown::append(legacy::tiny_tr_type& old, int town_num){ } } if(found_spec >= 0) { + int found_spec_id = special_locs[found_spec].spec; + cSpecial* node; if(!unused_special_slots.empty()) { - int found_spec_id = special_locs[found_spec].spec, use_slot = unused_special_slots.back(); + int use_slot = unused_special_slots.back(); unused_special_slots.pop_back(); - cSpecial& node = specials[use_slot]; - node.type = eSpecType::IF_IN_BOAT; - node.ex1b = -1; // any boat; - node.ex1c = -1; // do nothing - node.jumpto = found_spec_id; // else jump here + node = &specials[use_slot]; special_locs[found_spec].spec = use_slot; } else { - std::stringstream sout; - sout << "In town \"" << town_num << "\" at (" << i << ',' << j << "); special node ID " << special_locs[found_spec].spec; - giveError("Warning: A special node was found that could be triggered from in a boat, which is probably not what the designer intended. An attempt to fix this has failed because there were not enough unused special nodes.", sout.str()); + special_locs[found_spec].spec = specials.size(); + specials.emplace_back(); + node = &specials.back(); } + node->type = eSpecType::IF_IN_BOAT; + node->ex1b = -1; // any boat; + node->ex1c = -1; // do nothing + node->jumpto = found_spec_id; // else jump here } } } @@ -119,20 +121,22 @@ void cMedTown::append(legacy::ave_tr_type& old, int town_num){ } } if(found_spec >= 0) { + int found_spec_id = special_locs[found_spec].spec; + cSpecial* node; if(!unused_special_slots.empty()) { - int found_spec_id = special_locs[found_spec].spec, use_slot = unused_special_slots.back(); + int use_slot = unused_special_slots.back(); unused_special_slots.pop_back(); - cSpecial& node = specials[use_slot]; - node.type = eSpecType::IF_IN_BOAT; - node.ex1b = -1; // any boat; - node.ex1c = -1; // do nothing - node.jumpto = found_spec_id; // else jump here + node = &specials[use_slot]; special_locs[found_spec].spec = use_slot; } else { - std::stringstream sout; - sout << "In town " << town_num << " at (" << i << ',' << j << "); special node ID " << special_locs[found_spec].spec; - giveError("Warning: A special node was found that could be triggered from in a boat, which is probably not what the designer intended. An attempt to fix this has failed because there were not enough unused special nodes.", sout.str()); + special_locs[found_spec].spec = specials.size(); + specials.emplace_back(); + node = &specials.back(); } + node->type = eSpecType::IF_IN_BOAT; + node->ex1b = -1; // any boat; + node->ex1c = -1; // do nothing + node->jumpto = found_spec_id; // else jump here } } } @@ -184,20 +188,22 @@ void cBigTown::append(legacy::big_tr_type& old, int town_numo){ } } if(found_spec >= 0) { + int found_spec_id = special_locs[found_spec].spec; + cSpecial* node; if(!unused_special_slots.empty()) { - int found_spec_id = special_locs[found_spec].spec, use_slot = unused_special_slots.back(); + int use_slot = unused_special_slots.back(); unused_special_slots.pop_back(); - cSpecial& node = specials[use_slot]; - node.type = eSpecType::IF_IN_BOAT; - node.ex1b = -1; // any boat; - node.ex1c = -1; // do nothing - node.jumpto = found_spec_id; // else jump here + node = &specials[use_slot]; special_locs[found_spec].spec = use_slot; } else { - std::stringstream sout; - sout << "In town " << town_numo << " at (" << i << ',' << j << "); special node ID " << special_locs[found_spec].spec; - giveError("Warning: A special node was found that could be triggered from in a boat, which is probably not what the designer intended. An attempt to fix this has failed because there were not enough unused special nodes.", sout.str()); + special_locs[found_spec].spec = specials.size(); + specials.emplace_back(); + node = &specials.back(); } + node->type = eSpecType::IF_IN_BOAT; + node->ex1b = -1; // any boat; + node->ex1c = -1; // do nothing + node->jumpto = found_spec_id; // else jump here } } }