Reduce reliance on hard-coded limits

This commit is contained in:
2015-02-06 23:00:29 -05:00
parent a14d3b5ff8
commit 2cf301eece
14 changed files with 45 additions and 37 deletions

View File

@@ -542,7 +542,7 @@ bool handle_action(location the_point,sf::Event /*event*/) {
}
else { // MODE_ROOM_RECT
if(editing_town) {
for(x = 0; x < 16; x++)
for(x = 0; x < town->room_rect.size(); x++)
if(town->room_rect[x].right == 0) {
static_cast<rectangle&>(town->room_rect[x]) = working_rect;
town->room_rect[x].descr = "";
@@ -552,7 +552,7 @@ bool handle_action(location the_point,sf::Event /*event*/) {
}
}
else {
for(x = 0; x < 8; x++)
for(x = 0; x < current_terrain->info_rect.size(); x++)
if(current_terrain->info_rect[x].right == 0) {
static_cast<rectangle&>(current_terrain->info_rect[x]) = working_rect;
current_terrain->info_rect[x].descr = "";

View File

@@ -3064,7 +3064,7 @@ static bool save_scenario_events(cDialog& me, std::string, eKeyMod) {
if(!me.toast(true)) return true;
for(i = 0; i < 10; i++) {
for(i = 0; i < scenario.scenario_timers.size(); i++) {
std::string id = std::to_string(i + 1);
scenario.scenario_timers[i].time = me["time" + id].getTextAsNum();
scenario.scenario_timers[i].node = me["node" + id].getTextAsNum();
@@ -3098,7 +3098,7 @@ void edit_scenario_events() {
cDialog evt_dlg("edit-scenario-events");
evt_dlg["okay"].attachClickHandler(save_scenario_events);
for(int i = 0; i < 10; i++) {
for(int i = 0; i < scenario.scenario_timers.size(); i++) {
std::string id = std::to_string(i + 1);
evt_dlg["time" + id].attachFocusHandler(check_scenario_timer_time);
evt_dlg["node" + id].attachFocusHandler(std::bind(check_range_msg, _1, _2, _3, -1, 255, "The scenario special node", "-1 for no special"));

View File

@@ -284,7 +284,7 @@ static void writeScenarioToXml(ticpp::Printer&& data) {
data.CloseElement("entries");
data.CloseElement("shop");
}
for(int i = 0; i < 20; i++) {
for(int i = 0; i < scenario.scenario_timers.size(); i++) {
if(scenario.scenario_timers[i].time > 0) {
data.OpenElement("timer");
data.PushAttribute("time", scenario.scenario_timers[i].time);
@@ -671,7 +671,7 @@ static void writeTownToXml(ticpp::Printer&& data, cTown& town) {
if(town.is_hidden)
data.PushElement("hidden", true);
data.CloseElement("flags");
for(int i = 0; i < 4; i++) {
for(int i = 0; i < town.wandering.size(); i++) {
if(town.wandering[i].isNull()) continue;
data.OpenElement("wandering");
for(int j = 0; j < 4; j++) {
@@ -1083,7 +1083,7 @@ void scen_text_dump(){
fout << " Name: " << scenario.special_items[i].name << endl;
fout << " Description: " << scenario.special_items[i].descr << endl;
}
for(i = 0; i < 100; i++)
for(i = 0; i < scenario.spec_strs.size(); i++)
if(scenario.spec_strs[i][0] != '*')
fout << " Message " << i << ": " << scenario.spec_strs[i] << endl;
fout << endl << "Outdoor Sections Text:" << endl << endl;
@@ -1092,10 +1092,10 @@ void scen_text_dump(){
fout << " Section (x = " << (short)out_sec.x << ", y = " << (short)out_sec.y << "):" << endl;
fout << " Name: " << scenario.outdoors[out_sec.x][out_sec.y]->out_name;
fout << " Comment: " << scenario.outdoors[out_sec.x][out_sec.y]->comment;
for(i = 0; i < 8; i++)
for(i = 0; i < scenario.outdoors[out_sec.x][out_sec.y]->info_rect.size(); i++)
if(scenario.outdoors[out_sec.x][out_sec.y]->info_rect[i].descr[0] != '*')
fout << " Area Rectangle " << i << ": " << scenario.outdoors[out_sec.x][out_sec.y]->info_rect[i].descr << endl;
for(i = 0; i < 90; i++)
for(i = 0; i < scenario.outdoors[out_sec.x][out_sec.y]->spec_strs.size(); i++)
if(scenario.outdoors[out_sec.x][out_sec.y]->spec_strs[i][0] != '*')
fout << " Message " << i << ": " << scenario.outdoors[out_sec.x][out_sec.y]->spec_strs[i] << endl;
for(i = 0; i < 8; i++)
@@ -1109,7 +1109,7 @@ void scen_text_dump(){
fout << " Town " << j << ':' << endl;
fout << " Town Messages:" << endl;
fout << " Name: " << scenario.towns[i]->town_name << endl;
for(i = 0; i < 16; i++)
for(i = 0; i < scenario.towns[i]->room_rect.size(); i++)
if(scenario.towns[i]->room_rect[i].descr[0] != '*')
fout << " Area Rectangle " << i << ": " << scenario.towns[i]->room_rect[i].descr << endl;
fout << " Name: " << scenario.towns[i]->town_name << endl;
@@ -1117,7 +1117,7 @@ void scen_text_dump(){
if(scenario.towns[i]->comment[i][0] != '*')
fout << " Comment " << i << ": " << scenario.towns[i]->comment[i] << endl;
fout << " Name: " << scenario.towns[i]->town_name << endl;
for(i = 0; i < 100; i++)
for(i = 0; i < scenario.towns[i]->spec_strs.size(); i++)
if(scenario.towns[i]->spec_strs[i][0] != '*')
fout << " Message " << i << ": " << scenario.towns[i]->spec_strs[i] << endl;
fout << " Name: " << scenario.towns[i]->town_name << endl;

View File

@@ -787,7 +787,7 @@ void draw_terrain(){
if(editing_town) {
// draw info rects
for(i = 0; i < 16; i++)
for(i = 0; i < town->room_rect.size(); i++)
if(town->room_rect[i].left > 0) {
draw_rect.left = 22 + 28 * (town->room_rect[i].left - cen_x + 4);
draw_rect.right = 22 + 28 * (town->room_rect[i].right - cen_x + 4);
@@ -804,7 +804,7 @@ void draw_terrain(){
}
if(!editing_town) {
// draw info rects
for(i = 0; i < 8; i++)
for(i = 0; i < current_terrain->info_rect.size(); i++)
if(current_terrain->info_rect[i].left > 0) {
draw_rect.left = 22 + 28 * (current_terrain->info_rect[i].left - cen_x + 4);
draw_rect.right = 22 + 28 * (current_terrain->info_rect[i].right - cen_x + 4);

View File

@@ -366,7 +366,7 @@ void edit_sign(short which_sign,short picture) {
static bool save_roomdescs(cDialog& me, bool isTown, std::array<bool,16> str_do_delete) {
if(!me.toast(true)) return true;
int numDescs = isTown ? 16 : 8;
int numDescs = isTown ? town->room_rect.size() : current_terrain->info_rect.size();
for(int i = 0; i < numDescs; i++) {
std::string id = "desc" + std::to_string(i + 1);
if(isTown) {
@@ -383,7 +383,7 @@ static bool save_roomdescs(cDialog& me, bool isTown, std::array<bool,16> str_do_
}
static void put_roomdescs_in_dlog(cDialog& me, bool isTown, std::array<bool,16> str_do_delete) {
int numDescs = isTown ? 16 : 8;
int numDescs = isTown ? town->room_rect.size() : current_terrain->info_rect.size();
for(int i = 0; i < numDescs; i++) {
std::string id = std::to_string(i + 1);
std::ostringstream str;
@@ -608,16 +608,17 @@ static void save_out_wand(cDialog& me, short which, cOutdoors::cWandering& wand,
static bool edit_out_wand_event_filter(cDialog& me, std::string hit, short& which, cOutdoors::cWandering& wand, short mode) {
if(!me.toast(true)) return true;
save_out_wand(me, which, wand, mode);
size_t num_enc = (mode == 0) ? current_terrain->wandering.size() : current_terrain->special_enc.size();
if(hit == "left") {
me.untoast();
which--;
if(which < 0) which = 3;
if(which < 0) which = num_enc - 1;
wand = (mode == 0) ? current_terrain->wandering[which] : current_terrain->special_enc[which];
put_out_wand_in_dlog(me, which, wand);
} else if(hit == "right") {
me.untoast();
which++;
if(which > 3) which = 0;
if(which >= num_enc) which = 0;
wand = (mode == 0) ? current_terrain->wandering[which] : current_terrain->special_enc[which];
put_out_wand_in_dlog(me, which, wand);
}
@@ -739,7 +740,7 @@ void edit_town_details() {
static bool save_town_events(cDialog& me, std::string, eKeyMod) {
if(!me.toast(true)) return true;
for(int i = 0; i < 8; i++) {
for(int i = 0; i < town->timers.size(); i++) {
std::string id = std::to_string(i + 1);
town->timers[i].time = me["time" + id].getTextAsNum();
town->timers[i].node = me["spec" + id].getTextAsNum();
@@ -749,7 +750,7 @@ static bool save_town_events(cDialog& me, std::string, eKeyMod) {
static void put_town_events_in_dlog(cDialog& me) {
short i;
for(i = 0; i < 8; i++) {
for(i = 0; i < town->timers.size(); i++) {
std::string id = std::to_string(i + 1);
me["time" + id].setTextToNum(town->timers[i].time);
me["spec" + id].setTextToNum(town->timers[i].node);
@@ -864,7 +865,7 @@ void edit_advanced_town() {
static bool save_town_wand(cDialog& me, std::string, eKeyMod) {
if(!me.toast(true)) return true;
for(int i = 0; i < 4; i++) {
for(int i = 0; i < town->wandering.size(); i++) {
std::string base_id = "group" + std::to_string(i + 1) + "-monst";
for(int j = 0; j < 4; j++) {
std::string id = base_id + std::to_string(j + 1);
@@ -875,7 +876,7 @@ static bool save_town_wand(cDialog& me, std::string, eKeyMod) {
}
static void put_town_wand_in_dlog(cDialog& me) {
for(int i = 0; i < 4; i++) {
for(int i = 0; i < town->wandering.size(); i++) {
std::string base_id = "group" + std::to_string(i + 1) + "-monst";
for(int j = 0; j < 4; j++) {
std::string id = base_id + std::to_string(j + 1);