From f609711e273686cd71a69b9384af6f4c0e4500cb Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Fri, 6 Feb 2015 16:54:05 -0500 Subject: [PATCH] Combine timer data into a single structure --- src/boe.specials.cpp | 24 ++++++++++++------------ src/boe.town.cpp | 9 +++------ src/classes/party.cpp | 17 +++++++---------- src/classes/party.h | 7 ------- src/classes/scenario.cpp | 6 +++--- src/classes/scenario.h | 3 +-- src/classes/special.h | 7 +++++++ src/classes/town.cpp | 8 ++++---- src/classes/town.h | 3 +-- src/scenedit/scen.core.cpp | 8 ++++---- src/scenedit/scen.fileio.cpp | 12 ++++++------ src/scenedit/scen.townout.cpp | 8 ++++---- 12 files changed, 52 insertions(+), 60 deletions(-) diff --git a/src/boe.specials.cpp b/src/boe.specials.cpp index 1fa1bdc6..2646f20d 100644 --- a/src/boe.specials.cpp +++ b/src/boe.specials.cpp @@ -1836,14 +1836,14 @@ void special_increase_age(long length, bool queue) { if(is_town() || (is_combat() && which_combat_type == 1)) { for(i = 0; i < 8; i++) - if(univ.town->timer_spec_times[i] > 0) { - short time = univ.town->timer_spec_times[i]; + if(univ.town->timers[i].time > 0) { + short time = univ.town->timers[i].time; for(unsigned long j = age_before; j <= current_age; j++) if(j % time == 0) { if(queue) { univ.party.age = j; - queue_special(eSpecCtx::TOWN_TIMER, 2, univ.town->timer_specs[i], null_loc); - } else run_special(eSpecCtx::TOWN_TIMER,2,univ.town->timer_specs[i],null_loc,&s1,&s2,&s3); + queue_special(eSpecCtx::TOWN_TIMER, 2, univ.town->timers[i].node, null_loc); + } else run_special(eSpecCtx::TOWN_TIMER,2,univ.town->timers[i].node,null_loc,&s1,&s2,&s3); } stat_area = true; if(s3 > 0) @@ -1852,14 +1852,14 @@ void special_increase_age(long length, bool queue) { } univ.party.age = current_age; for(i = 0; i < 20; i++) - if(univ.scenario.scenario_timer_times[i] > 0) { - short time = univ.scenario.scenario_timer_times[i]; + if(univ.scenario.scenario_timers[i].time > 0) { + short time = univ.scenario.scenario_timers[i].time; for(unsigned long j = age_before; j <= current_age; j++) if(j % time == 0) { if(queue) { univ.party.age = j; - queue_special(eSpecCtx::SCEN_TIMER, 0, univ.scenario.scenario_timer_specs[i], null_loc); - } else run_special(eSpecCtx::SCEN_TIMER,0,univ.scenario.scenario_timer_specs[i],null_loc,&s1,&s2,&s3); + queue_special(eSpecCtx::SCEN_TIMER, 0, univ.scenario.scenario_timers[i].node, null_loc); + } else run_special(eSpecCtx::SCEN_TIMER,0,univ.scenario.scenario_timers[i].node,null_loc,&s1,&s2,&s3); } stat_area = true; if(s3 > 0) @@ -1869,10 +1869,10 @@ void special_increase_age(long length, bool queue) { for(i = 0; i < univ.party.party_event_timers.size(); i++) { if(univ.party.party_event_timers[i].time <= length) { univ.party.age = age_before + univ.party.party_event_timers[i].time; - short which_type = univ.party.party_event_timers[i].global_or_town == 0 ? 0 : 2; + short which_type = univ.party.party_event_timers[i].node_type; if(queue) - queue_special(eSpecCtx::PARTY_TIMER, which_type, univ.party.party_event_timers[i].node_to_call, null_loc); - else run_special(eSpecCtx::PARTY_TIMER,which_type,univ.party.party_event_timers[i].node_to_call,null_loc,&s1,&s2,&s3); + queue_special(eSpecCtx::PARTY_TIMER, which_type, univ.party.party_event_timers[i].node, null_loc); + else run_special(eSpecCtx::PARTY_TIMER,which_type,univ.party.party_event_timers[i].node,null_loc,&s1,&s2,&s3); univ.party.party_event_timers[i].time = 0; stat_area = true; if(s3 > 0) @@ -3972,7 +3972,7 @@ void townmode_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type, } else change_level(univ.party.left_in, univ.party.left_at.x, univ.party.left_at.y); break; case eSpecType::TOWN_TIMER_START: - univ.party.start_timer(spec.ex1a, spec.ex1b, 1); + univ.party.start_timer(spec.ex1a, spec.ex1b, 2); break; // OBoE: Change town lighting case eSpecType::TOWN_CHANGE_LIGHTING: diff --git a/src/boe.town.cpp b/src/boe.town.cpp index f2a913a7..307998b9 100644 --- a/src/boe.town.cpp +++ b/src/boe.town.cpp @@ -592,12 +592,9 @@ location end_town_mode(short switching_level,location destination) { // returns to_return = univ.party.p_loc; - for(i = univ.party.party_event_timers.size() - 1; i >= 0; i++) - if(univ.party.party_event_timers[i].global_or_town == 1) { - cParty::timerIter iter = univ.party.party_event_timers.begin(); - iter += i; - univ.party.party_event_timers.erase(iter); - } + std::remove_if(univ.party.party_event_timers.begin(), univ.party.party_event_timers.end(), [](const cTimer& t) { + return t.node_type == 2; + }); } diff --git a/src/classes/party.cpp b/src/classes/party.cpp index 503fe290..f928f6f1 100644 --- a/src/classes/party.cpp +++ b/src/classes/party.cpp @@ -89,12 +89,9 @@ void cParty::append(legacy::party_record_type& old){ horses[i].append(old.horses[i]); cTimer t; t.time = old.party_event_timers[i]; - t.global_or_town = old.global_or_town[i]; - t.node_to_call = old.node_to_call[i]; + t.node_type = old.global_or_town[i]; + t.node = old.node_to_call[i]; party_event_timers.push_back(t); -// party_event_timers[i].time = old.party_event_timers[i]; -// party_event_timers[i].global_or_town = old.global_or_town[i]; -// party_event_timers[i].node_to_call = old.node_to_call[i]; } for(i = 0; i < 4; i++){ creature_save[i].append(old.creature_save[i]); @@ -478,8 +475,8 @@ bool cParty::start_timer(short time, short node, short type){ if(party_event_timers.size() == party_event_timers.max_size()) return false; // Shouldn't be reached cTimer t; t.time = time; - t.global_or_town = type; - t.node_to_call = node; + t.node_type = type; + t.node = node; party_event_timers.push_back(t); return(true); } @@ -614,8 +611,8 @@ void cParty::writeTo(std::ostream& file) const { file << '\f'; file << '\f'; for(unsigned int i = 0; i < party_event_timers.size(); i++) - file << "TIMER " << ' ' << party_event_timers[i].time << ' ' << party_event_timers[i].global_or_town - << ' ' << party_event_timers[i].node_to_call << '\f'; + file << "TIMER " << ' ' << party_event_timers[i].time << ' ' << party_event_timers[i].node_type + << ' ' << party_event_timers[i].node << '\f'; file << '\f'; for(int i = 0; i < 4; i++) for(int j = 0; j < 60; j++) { @@ -845,7 +842,7 @@ void cParty::readFrom(std::istream& file){ int i; bin >> i; cTimer timer; - bin >> timer.time >> timer.global_or_town >> timer.node_to_call; + bin >> timer.time >> timer.node_type >> timer.node; party_event_timers.push_back(timer); } else if(cur == "CREATURE") { int i, j; diff --git a/src/classes/party.h b/src/classes/party.h index af1f57a5..25c85cce 100644 --- a/src/classes/party.h +++ b/src/classes/party.h @@ -67,12 +67,6 @@ public: void append(int16_t(& old)[2], const cScenario& scenario); }; - class cTimer { - public: - long time; - short global_or_town; - short node_to_call; - }; // formerly party_record_type // TODO: Should we make age a long long? long next_pc_id = 1000; @@ -205,7 +199,6 @@ public: typedef std::vector::iterator encIter; typedef std::vector::iterator journalIter; typedef std::vector::iterator talkIter; - typedef std::vector::iterator timerIter; cParty(cUniverse& univ, long party_preset = 'dflt'); ~cParty(); }; diff --git a/src/classes/scenario.cpp b/src/classes/scenario.cpp index 7730bd39..01736c65 100644 --- a/src/classes/scenario.cpp +++ b/src/classes/scenario.cpp @@ -74,7 +74,7 @@ cScenario::cScenario(bool init_strings) { special_items[i].special = -1; } for(i = 0; i < 20; i++) { - scenario_timer_specs[i] = -1; + scenario_timers[i].node = -1; } for(i = 0; i < 400; i++) { scen_items[i] = cItem(); @@ -144,8 +144,8 @@ void cScenario::append(legacy::scenario_data_type& old){ ter_types[i].i = i; ter_types[i].append(old.ter_types[i]); } - for(i = 0; i < 20; i++) scenario_timer_times[i] = old.scenario_timer_times[i]; - for(i = 0; i < 20; i++) scenario_timer_specs[i] = old.scenario_timer_specs[i]; + for(i = 0; i < 20; i++) scenario_timers[i].time = old.scenario_timer_times[i]; + for(i = 0; i < 20; i++) scenario_timers[i].node = old.scenario_timer_specs[i]; scen_specials.resize(256); for(i = 0; i < 256; i++) scen_specials[i].append(old.scen_specials[i]); for(i = 0; i < 10; i++) storage_shortcuts[i] = old.storage_shortcuts[i]; diff --git a/src/classes/scenario.h b/src/classes/scenario.h index 2e13305e..69fdeb5d 100644 --- a/src/classes/scenario.h +++ b/src/classes/scenario.h @@ -78,8 +78,7 @@ public: std::array boats; std::array horses; std::array ter_types; - short scenario_timer_times[20]; - short scenario_timer_specs[20]; + std::array scenario_timers; std::vector scen_specials; cItemStorage storage_shortcuts[10]; location last_out_edited; diff --git a/src/classes/special.h b/src/classes/special.h index fd341857..528d9272 100644 --- a/src/classes/special.h +++ b/src/classes/special.h @@ -40,6 +40,13 @@ public: void writeTo(std::ostream& file, int n) const; }; +class cTimer { +public: + long time; + bool node_type; + short node; +}; + struct pending_special_type { spec_num_t spec; eSpecCtx mode; diff --git a/src/classes/town.cpp b/src/classes/town.cpp index 7e42faa4..09ea576d 100644 --- a/src/classes/town.cpp +++ b/src/classes/town.cpp @@ -64,8 +64,8 @@ void cTown::append(legacy::town_record_type& old){ spec_on_entry_if_dead = old.spec_on_entry_if_dead; spec_on_hostile = -1; for(i = 0; i < 8; i++){ - timer_spec_times[i] = old.timer_spec_times[i]; - timer_specs[i] = old.timer_specs[i]; + timers[i].time = old.timer_spec_times[i]; + timers[i].node = old.timer_specs[i]; } specials.resize(100); for(i = 0; i < 100; i++) @@ -98,8 +98,8 @@ cTown::cTown(cScenario& scenario, bool init_strings) : scenario(scenario) { sign_locs[i].x = 100; } for(i = 0; i < 8; i++) { - timer_spec_times[i] = 0; - timer_specs[i] = -1; + timers[i].time = 0; + timers[i].node = -1; } difficulty = 0; bg_town = bg_fight = -1; diff --git a/src/classes/town.h b/src/classes/town.h index d46ec7d7..5275102c 100644 --- a/src/classes/town.h +++ b/src/classes/town.h @@ -86,8 +86,7 @@ public: std::vector preset_fields; short spec_on_entry,spec_on_entry_if_dead; short spec_on_hostile; - std::array timer_spec_times; - std::array timer_specs; + std::array timers; std::vector specials; bool strong_barriers : 1; bool defy_mapping : 1; diff --git a/src/scenedit/scen.core.cpp b/src/scenedit/scen.core.cpp index 033d9268..85b0cf4c 100644 --- a/src/scenedit/scen.core.cpp +++ b/src/scenedit/scen.core.cpp @@ -3066,8 +3066,8 @@ static bool save_scenario_events(cDialog& me, std::string, eKeyMod) { for(i = 0; i < 10; i++) { std::string id = std::to_string(i + 1); - scenario.scenario_timer_times[i] = me["time" + id].getTextAsNum(); - scenario.scenario_timer_specs[i] = me["node" + id].getTextAsNum(); + scenario.scenario_timers[i].time = me["time" + id].getTextAsNum(); + scenario.scenario_timers[i].node = me["node" + id].getTextAsNum(); } return true; } @@ -3103,8 +3103,8 @@ void edit_scenario_events() { 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")); evt_dlg["edit" + id].attachClickHandler(edit_scenario_events_event_filter); - evt_dlg["time" + id].setTextToNum(scenario.scenario_timer_times[i]); - evt_dlg["node" + id].setTextToNum(scenario.scenario_timer_specs[i]); + evt_dlg["time" + id].setTextToNum(scenario.scenario_timers[i].time); + evt_dlg["node" + id].setTextToNum(scenario.scenario_timers[i].node); } evt_dlg.run(); diff --git a/src/scenedit/scen.fileio.cpp b/src/scenedit/scen.fileio.cpp index e5dff7bb..5ad3e613 100644 --- a/src/scenedit/scen.fileio.cpp +++ b/src/scenedit/scen.fileio.cpp @@ -285,10 +285,10 @@ static void writeScenarioToXml(ticpp::Printer&& data) { data.CloseElement("shop"); } for(int i = 0; i < 20; i++) { - if(scenario.scenario_timer_times[i] > 0) { + if(scenario.scenario_timers[i].time > 0) { data.OpenElement("timer"); - data.PushAttribute("time", scenario.scenario_timer_times[i]); - data.PushText(scenario.scenario_timer_specs[i]); + data.PushAttribute("time", scenario.scenario_timers[i].time); + data.PushText(scenario.scenario_timers[i].node); data.CloseElement("timer"); } } @@ -648,10 +648,10 @@ static void writeTownToXml(ticpp::Printer&& data, cTown& town) { } if(town.spec_on_hostile >= 0) data.PushElement("onoffend", town.spec_on_hostile); - for(size_t i = 0; i < town.timer_spec_times.size() && i < town.timer_specs.size(); i++) { + for(size_t i = 0; i < town.timers.size(); i++) { data.OpenElement("timer"); - data.PushAttribute("freq", town.timer_spec_times[i]); - data.PushText(town.timer_specs[i]); + data.PushAttribute("freq", town.timers[i].time); + data.PushText(town.timers[i].node); data.CloseElement("timer"); } data.OpenElement("flags"); diff --git a/src/scenedit/scen.townout.cpp b/src/scenedit/scen.townout.cpp index d3408f5c..7e0eefd3 100644 --- a/src/scenedit/scen.townout.cpp +++ b/src/scenedit/scen.townout.cpp @@ -741,8 +741,8 @@ static bool save_town_events(cDialog& me, std::string, eKeyMod) { if(!me.toast(true)) return true; for(int i = 0; i < 8; i++) { std::string id = std::to_string(i + 1); - town->timer_spec_times[i] = me["time" + id].getTextAsNum(); - town->timer_specs[i] = me["spec" + id].getTextAsNum(); + town->timers[i].time = me["time" + id].getTextAsNum(); + town->timers[i].node = me["spec" + id].getTextAsNum(); } return true; } @@ -751,8 +751,8 @@ static void put_town_events_in_dlog(cDialog& me) { short i; for(i = 0; i < 8; i++) { std::string id = std::to_string(i + 1); - me["time" + id].setTextToNum(town->timer_spec_times[i]); - me["spec" + id].setTextToNum(town->timer_specs[i]); + me["time" + id].setTextToNum(town->timers[i].time); + me["spec" + id].setTextToNum(town->timers[i].node); } }