Reduce reliance on hard-coded limits
This commit is contained in:
@@ -568,7 +568,8 @@ static void handle_talk(location destination, bool& did_something, bool& need_re
|
||||
if(univ.town.monst[i].summon_time == 0)
|
||||
small_talk = -univ.town.monst[i].personality;
|
||||
std::string str = "No response.";
|
||||
if(small_talk > 1000) str = univ.scenario.spec_strs[small_talk - 1000];
|
||||
if(small_talk > 1000 && small_talk < 1000 + univ.scenario.spec_strs.size())
|
||||
str = univ.scenario.spec_strs[small_talk - 1000];
|
||||
// TODO: Come up with a set of pre-cooked responses.
|
||||
add_string_to_buf("Talk: " + str, 4);
|
||||
} else {
|
||||
|
@@ -675,7 +675,7 @@ void draw_text_bar() {
|
||||
|
||||
bool in_area = false;
|
||||
if(is_out()) {
|
||||
for(i = 0; i < 8; i++)
|
||||
for(i = 0; i < univ.out->info_rect.size(); i++)
|
||||
if(loc.in(univ.out->info_rect[i])) {
|
||||
put_text_bar(univ.out->info_rect[i].descr);
|
||||
in_area = true;
|
||||
@@ -685,7 +685,7 @@ void draw_text_bar() {
|
||||
}
|
||||
}
|
||||
if(is_town()) {
|
||||
for(i = 0; i < 16; i++)
|
||||
for(i = 0; i < univ.town->room_rect.size(); i++)
|
||||
if(loc.in(univ.town->room_rect[i])) {
|
||||
put_text_bar(univ.town->room_rect[i].descr);
|
||||
in_area = true;
|
||||
|
@@ -43,7 +43,7 @@ void create_wand_monst() {
|
||||
short r1,r2,r3,i = 0,num_tries = 0;
|
||||
location p_loc;
|
||||
|
||||
r1 = get_ran(1,0,3);
|
||||
r1 = get_ran(1,0,univ.out->wandering.size() - 1);
|
||||
if(overall_mode == MODE_OUTDOORS) {
|
||||
if(!univ.out->wandering[r1].isNull()) {
|
||||
r2 = get_ran(1,0,3);
|
||||
@@ -55,7 +55,7 @@ void create_wand_monst() {
|
||||
} else if(!univ.town->wandering[r1].isNull() && univ.town.countMonsters() <= 50
|
||||
&& univ.party.m_killed[univ.town.num] < univ.town->max_num_monst) {
|
||||
// won't place wandering if more than 50 monsters
|
||||
r2 = get_ran(1,0,3);
|
||||
r2 = get_ran(1,0,univ.town->wandering.size() - 1);
|
||||
while(point_onscreen(univ.town->wandering_locs[r2],univ.town.p_loc) &&
|
||||
!loc_off_act_area(univ.town->wandering_locs[r2]) && num_tries++ < 100)
|
||||
r2 = get_ran(1,0,3);
|
||||
|
@@ -1835,7 +1835,7 @@ void special_increase_age(long length, bool queue) {
|
||||
move_to_zero(univ.party.job_banks[i].anger);
|
||||
|
||||
if(is_town() || (is_combat() && which_combat_type == 1)) {
|
||||
for(i = 0; i < 8; i++)
|
||||
for(i = 0; i < univ.town->timers.size(); 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++)
|
||||
@@ -1851,7 +1851,7 @@ void special_increase_age(long length, bool queue) {
|
||||
}
|
||||
}
|
||||
univ.party.age = current_age;
|
||||
for(i = 0; i < 20; i++)
|
||||
for(i = 0; i < univ.scenario.scenario_timers.size(); 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++)
|
||||
@@ -4342,10 +4342,16 @@ void handle_message(eSpecCtx which_mode,short cur_type,short mess1,short mess2,s
|
||||
}
|
||||
|
||||
void get_strs(std::string& str1,std::string& str2,short cur_type,short which_str1,short which_str2) {
|
||||
short num_strs[3] = {260,108,135};
|
||||
size_t num_strs;
|
||||
if(cur_type == 0)
|
||||
num_strs = univ.scenario.spec_strs.size();
|
||||
else if(cur_type == 1)
|
||||
num_strs = univ.out->spec_strs.size();
|
||||
else if(cur_type == 2)
|
||||
num_strs = univ.town->spec_strs.size();
|
||||
|
||||
if(((which_str1 >= 0) && (which_str1 != minmax(0,num_strs[cur_type],which_str1))) ||
|
||||
((which_str2 >= 0) && (which_str2 != minmax(0,num_strs[cur_type],which_str2)))) {
|
||||
if(((which_str1 >= 0) && (which_str1 != minmax(0,num_strs,which_str1))) ||
|
||||
((which_str2 >= 0) && (which_str2 != minmax(0,num_strs,which_str2)))) {
|
||||
giveError("The scenario attempted to access a message out of range.");
|
||||
return;
|
||||
}
|
||||
@@ -4377,7 +4383,7 @@ void set_campaign_flag(short sdf_a, short sdf_b, short cpf_a, short cpf_b, short
|
||||
// get_send = false: Send value in SDF to Campaign Flag
|
||||
// get_send = true: Retrieve value from Campaign Flag and put in SDF
|
||||
try {
|
||||
if(str >= 0) {
|
||||
if(str >= 0 && str < univ.scenario.spec_strs.size()) {
|
||||
std::string cp_id = univ.scenario.spec_strs[str];
|
||||
if(get_send)
|
||||
univ.party.stuff_done[sdf_a][sdf_b] = univ.party.cpn_flag(cpf_a, cpf_b, cp_id);
|
||||
|
@@ -86,7 +86,7 @@ public:
|
||||
cPopulation creature_save[4];
|
||||
short in_boat;
|
||||
short in_horse;
|
||||
cOutdoors::cCreature out_c[10];
|
||||
std::array<cOutdoors::cCreature,10> out_c;
|
||||
std::map<int,std::array<cItem,30>> magic_store_items;
|
||||
std::map<int,std::map<int,int>> store_limited_stock;
|
||||
std::vector<job_bank_t> job_banks;
|
||||
|
@@ -73,7 +73,7 @@ cScenario::cScenario(bool init_strings) {
|
||||
for(i = 0; i < 50; i++) {
|
||||
special_items[i].special = -1;
|
||||
}
|
||||
for(i = 0; i < 20; i++) {
|
||||
for(i = 0; i < scenario_timers.size(); i++) {
|
||||
scenario_timers[i].node = -1;
|
||||
}
|
||||
for(i = 0; i < 400; i++) {
|
||||
|
@@ -44,7 +44,7 @@ public:
|
||||
cNode() {std::fill(extras, extras + 4, -1);}
|
||||
};
|
||||
cPersonality people[10];
|
||||
cNode talk_nodes[60];
|
||||
std::array<cNode,60> talk_nodes;
|
||||
|
||||
void append(legacy::talking_record_type& old, std::vector<shop_info_t>& shops);
|
||||
void writeTo(std::ostream& file) const;
|
||||
|
@@ -80,7 +80,7 @@ cTown::cTown(cScenario& scenario, bool init_strings) : scenario(scenario) {
|
||||
|
||||
town_chop_time = -1;
|
||||
town_chop_key = -1;
|
||||
for(i = 0; i < 4; i++) {
|
||||
for(i = 0; i < wandering.size(); i++) {
|
||||
wandering[i] = d_wan;
|
||||
wandering_locs[i].x = 100;
|
||||
}
|
||||
|
@@ -71,7 +71,7 @@ public:
|
||||
};
|
||||
short town_chop_time,town_chop_key;
|
||||
int bg_town, bg_fight;
|
||||
cWandering wandering[4];
|
||||
std::array<cWandering,4> wandering;
|
||||
location wandering_locs[4];
|
||||
std::vector<spec_loc_t> special_locs;
|
||||
std::array<sign_loc_t,20> sign_locs;
|
||||
|
@@ -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 = "";
|
||||
|
@@ -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"));
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user