Combine timer data into a single structure
This commit is contained in:
@@ -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:
|
||||
|
@@ -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;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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<cEncNote>::iterator encIter;
|
||||
typedef std::vector<cJournal>::iterator journalIter;
|
||||
typedef std::vector<cConvers>::iterator talkIter;
|
||||
typedef std::vector<cTimer>::iterator timerIter;
|
||||
cParty(cUniverse& univ, long party_preset = 'dflt');
|
||||
~cParty();
|
||||
};
|
||||
|
@@ -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];
|
||||
|
@@ -78,8 +78,7 @@ public:
|
||||
std::array<cVehicle,30> boats;
|
||||
std::array<cVehicle,30> horses;
|
||||
std::array<cTerrain,256> ter_types;
|
||||
short scenario_timer_times[20];
|
||||
short scenario_timer_specs[20];
|
||||
std::array<cTimer,20> scenario_timers;
|
||||
std::vector<cSpecial> scen_specials;
|
||||
cItemStorage storage_shortcuts[10];
|
||||
location last_out_edited;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -86,8 +86,7 @@ public:
|
||||
std::vector<cField> preset_fields;
|
||||
short spec_on_entry,spec_on_entry_if_dead;
|
||||
short spec_on_hostile;
|
||||
std::array<short,8> timer_spec_times;
|
||||
std::array<short,8> timer_specs;
|
||||
std::array<cTimer,8> timers;
|
||||
std::vector<cSpecial> specials;
|
||||
bool strong_barriers : 1;
|
||||
bool defy_mapping : 1;
|
||||
|
@@ -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();
|
||||
|
@@ -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");
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user