Eliminate data size members from the scenario record

- Also move town_hidden array to the town record flags
This commit is contained in:
2015-01-12 13:02:37 -05:00
parent ac7a1c1d88
commit 3a285f47da
20 changed files with 104 additions and 174 deletions

View File

@@ -207,11 +207,11 @@ bool handle_action(location the_point,sf::Event /*event*/) {
giveError("You need to save the changes made to your scenario before you can add a new town.");
return are_done;
}
if(scenario.num_towns >= 200) {
if(scenario.towns.size() >= 200) {
giveError("You have reached the limit of 200 towns you can have in one scenario.");
return are_done;
}
if(new_town(scenario.num_towns))
if(new_town(scenario.towns.size()))
set_up_main_screen();
break;
case 6:
@@ -586,20 +586,15 @@ bool handle_action(location the_point,sf::Event /*event*/) {
giveError("Either no monster has been placed, or the last time you tried to place a monster the operation failed.");
break;
}
for(i = 0; i < 60; i++)
for(i = 0; i < town->max_monst(); i++)
if(town->creatures(i).number == 0) {
town->creatures(i) = last_placed_monst;
town->creatures(i).start_loc = spot_hit;
if((i >= 30) && (scenario.town_size[cur_town] == 2)) {
giveError("Small towns can have at most 30 preset monsters."); // error
town->creatures(i).number = 0;
}
else if((i >= 40) && (scenario.town_size[cur_town] == 1)) {
giveError("Medium towns can have at most 40 preset monsters."); // error
town->creatures(i).number = 0;
}
i = 60;
break;
}
if(i == town->max_monst()) { // Placement failed
giveError("The town only has room for " + std::to_string(town->max_monst()) + " preset monsters.");
}
overall_mode = MODE_DRAWING;
set_cursor(wand_curs);
break;
@@ -622,20 +617,11 @@ bool handle_action(location the_point,sf::Event /*event*/) {
town->creatures(i).personality = -1;
town->creatures(i).special_on_kill = -1;
town->creatures(i).facial_pic = scenario.scen_monsters[mode_count].default_facial_pic;
if((i >= 30) && (scenario.town_size[cur_town] == 2)) {
giveError("Small towns can have at most 30 preset monsters."); // error
town->creatures(i).number = 0;
}
else if((i >= 40) && (scenario.town_size[cur_town] == 1)) {
giveError("Medium towns can have at most 40 preset monsters."); // error
town->creatures(i).number = 0;
}
last_placed_monst = town->creatures(i);
i = 70;
break;
}
if((i < 70) && (scenario.town_size[cur_town] == 0)) {
giveError("Large towns can have at most 60 preset monsters."); // error
if(i == town->max_monst()) { // Placement failed
giveError("The town only has room for " + std::to_string(town->max_monst()) + " preset monsters.");
}
overall_mode = MODE_DRAWING;
set_cursor(wand_curs);

View File

@@ -1605,29 +1605,14 @@ bool build_scenario() {
// TODO: Append i+1 to each town name
for(i = 0; i < lg; i++) {
which_town = scenario.num_towns;
scenario.num_towns++;
scenario.town_size[which_town] = 0;
scenario.town_hidden[which_town] = 0;
cur_town = which_town;
scenario.addTown<cBigTown>();
town->town_name = "Large town";
}
for(i = 0; i < med; i++) {
which_town = scenario.num_towns;
scenario.num_towns++;
scenario.town_size[which_town] = 1;
scenario.town_hidden[which_town] = 0;
cur_town = which_town;
scenario.addTown<cMedTown>();
town->town_name = "Medium town";
}
for(i = 0; i < sm; i++) {
which_town = scenario.num_towns;
scenario.num_towns++;
scenario.town_size[which_town] = 2;
scenario.town_hidden[which_town] = 0;
cur_town = which_town;
scenario.addTown<cTinyTown>();
town->town_name = "Small town";
}
@@ -1663,7 +1648,7 @@ void set_starting_loc() {
cDialog loc_dlg("set-start-loc");
loc_dlg["cancel"].attachClickHandler(std::bind(&cDialog::toast, &loc_dlg, false));
loc_dlg["okay"].attachClickHandler(set_starting_loc_filter);
loc_dlg["town-num"].attachFocusHandler(std::bind(check_range, _1, _2, _3, 0, scenario.num_towns - 1, "The starting town"));
loc_dlg["town-num"].attachFocusHandler(std::bind(check_range, _1, _2, _3, 0, scenario.towns.size() - 1, "The starting town"));
loc_dlg.attachFocusHandlers(check_location_bounds, {"town-x", "town-y"});
loc_dlg["town-num"].setTextToNum(scenario.which_town_start);

View File

@@ -649,8 +649,8 @@ void scen_text_dump(){
if(scenario.spec_strs[i][0] != '*')
fout << " Message " << i << ": " << scenario.spec_strs[i] << endl;
fout << endl << "Outdoor Sections Text:" << endl << endl;
for(out_sec.x = 0; out_sec.x < scenario.out_width ; out_sec.x++) {
for(out_sec.y = 0; out_sec.y < scenario.out_height ; out_sec.y++) {
for(out_sec.x = 0; out_sec.x < scenario.outdoors.width(); out_sec.x++) {
for(out_sec.y = 0; out_sec.y < scenario.outdoors.height(); out_sec.y++) {
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;
@@ -667,7 +667,7 @@ void scen_text_dump(){
}
}
fout << "Town Text:" << endl << endl;
for(short j = 0; j < scenario.num_towns; j++) {
for(short j = 0; j < scenario.towns.size(); j++) {
fout << " Town " << j << ':' << endl;
fout << " Town Messages:" << endl;
fout << " Name: " << scenario.towns[i]->town_name << endl;

View File

@@ -598,19 +598,19 @@ void draw_terrain(){
short ter_x = cen_x + q - 4, ter_y = cen_y + r - 4;
if(ter_x == -1 && ter_y == -1 && cur_out.x > 0 && cur_out.y > 0)
t_to_draw = scenario.outdoors[cur_out.x - 1][cur_out.y - 1]->terrain[47][47];
else if(ter_x == -1 && ter_y == 48 && cur_out.x > 0 && cur_out.y < scenario.out_height - 1)
else if(ter_x == -1 && ter_y == 48 && cur_out.x > 0 && cur_out.y < scenario.outdoors.height() - 1)
t_to_draw = scenario.outdoors[cur_out.x - 1][cur_out.y + 1]->terrain[47][0];
else if(ter_x == 48 && ter_y == -1 && cur_out.x < scenario.out_width - 1 && cur_out.y > 0)
else if(ter_x == 48 && ter_y == -1 && cur_out.x < scenario.outdoors.width() - 1 && cur_out.y > 0)
t_to_draw = scenario.outdoors[cur_out.x + 1][cur_out.y - 1]->terrain[0][47];
else if(ter_x == 48 && ter_y == 48 && cur_out.x < scenario.out_width - 1 && cur_out.y < scenario.out_height - 1)
else if(ter_x == 48 && ter_y == 48 && cur_out.x < scenario.outdoors.width() - 1 && cur_out.y < scenario.outdoors.height() - 1)
t_to_draw = scenario.outdoors[cur_out.x + 1][cur_out.y + 1]->terrain[0][0];
else if(ter_x == -1 && ter_y >= 0 && ter_y < 48 && cur_out.x > 0)
t_to_draw = scenario.outdoors[cur_out.x - 1][cur_out.y]->terrain[47][ter_y];
else if(ter_y == -1 && ter_x >= 0 && ter_x < 48 && cur_out.y > 0)
t_to_draw = scenario.outdoors[cur_out.x][cur_out.y - 1]->terrain[ter_x][47];
else if(ter_x == 48 && ter_y >= 0 && ter_y < 48 && cur_out.x < scenario.out_width - 1)
else if(ter_x == 48 && ter_y >= 0 && ter_y < 48 && cur_out.x < scenario.outdoors.width() - 1)
t_to_draw = scenario.outdoors[cur_out.x + 1][cur_out.y]->terrain[0][ter_y];
else if(ter_y == 48 && ter_x >= 0 && ter_x < 48 && cur_out.y < scenario.out_height - 1)
else if(ter_y == 48 && ter_x >= 0 && ter_x < 48 && cur_out.y < scenario.outdoors.height() - 1)
t_to_draw = scenario.outdoors[cur_out.x][cur_out.y + 1]->terrain[ter_x][0];
else if(ter_x == -1 || ter_x == 48 || ter_y == -1 || ter_y == 48)
t_to_draw = 90;

View File

@@ -243,11 +243,11 @@ void handle_menu_choice(eMenu item_hit) {
giveError("You need to save the changes made to your scenario before you can add a new town.");
return;
}
if(scenario.num_towns >= 200) {
if(scenario.towns.size() >= 200) {
giveError("You have reached the limit of 200 towns you can have in one scenario.");
return;
}
if(new_town(scenario.num_towns))
if(new_town(scenario.towns.size()))
set_up_main_screen();
change_made = true;
break;
@@ -315,15 +315,15 @@ void handle_menu_choice(eMenu item_hit) {
giveError("You need to save the changes made to your scenario before you can delete a town.");
return;
}
if(scenario.num_towns == 1) {
if(scenario.towns.size() == 1) {
giveError("You can't delete the last town in a scenario. All scenarios must have at least 1 town.");
return;
}
if(scenario.num_towns - 1 == cur_town) {
if(scenario.towns.size() - 1 == cur_town) {
giveError("You can't delete the last town in a scenario while you're working on it. Load a different town, and try this again.");
return;
}
if(scenario.num_towns - 1 == scenario.which_town_start) {
if(scenario.towns.size() - 1 == scenario.which_town_start) {
giveError("You can't delete the last town in a scenario while it's the town the party starts the scenario in. Change the parties starting point and try this again.");
return;
}

View File

@@ -365,7 +365,7 @@ short pick_town_num(std::string which_dlog,short def,cScenario& scenario) {
cDialog town_dlg(which_dlog);
town_dlg["cancel"].attachClickHandler(std::bind(&cDialog::toast, &town_dlg, false));
town_dlg["okay"].attachClickHandler(save_town_num);
town_dlg["town"].attachFocusHandler(std::bind(check_range, _1, _2, _3, 0, scenario.num_towns - 1, "Town number"));
town_dlg["town"].attachFocusHandler(std::bind(check_range, _1, _2, _3, 0, scenario.towns.size() - 1, "Town number"));
town_dlg["choose"].attachClickHandler([&scenario](cDialog& me, std::string, eKeyMod) -> bool {
int i = me["town"].getTextAsNum();
if(&scenario != &::scenario)
@@ -379,7 +379,7 @@ short pick_town_num(std::string which_dlog,short def,cScenario& scenario) {
town_dlg["town"].setTextToNum(def);
std::string prompt = town_dlg["prompt"].getText();
prompt += " (0 - " + std::to_string(scenario.num_towns - 1) + ')';
prompt += " (0 - " + std::to_string(scenario.towns.size() - 1) + ')';
town_dlg["prompt"].setText(prompt);
town_dlg.setResult<short>(-1);
@@ -685,7 +685,7 @@ static bool save_advanced_town(cDialog& me, std::string, eKeyMod) {
}
town->spec_on_entry = me["onenter"].getTextAsNum();
town->spec_on_entry_if_dead = me["onenterdead"].getTextAsNum();
scenario.town_hidden[cur_town] = dynamic_cast<cLed&>(me["hidden"]).getState() != led_off;
town->is_hidden = dynamic_cast<cLed&>(me["hidden"]).getState() != led_off;
return true;
}
@@ -699,7 +699,7 @@ static void put_advanced_town_in_dlog(cDialog& me) {
}
me["onenter"].setTextToNum(town->spec_on_entry);
me["onenterdead"].setTextToNum(town->spec_on_entry_if_dead);
dynamic_cast<cLed&>(me["hidden"]).setState(scenario.town_hidden[cur_town] ? led_red : led_off);
dynamic_cast<cLed&>(me["hidden"]).setState(town->is_hidden ? led_red : led_off);
}
void edit_advanced_town() {
@@ -1060,19 +1060,19 @@ static bool pick_out_event_filter(cDialog& me, std::string item_hit, location& c
if(cur_loc.x == 0) beep();
else cur_loc.x--;
} else if(item_hit == "xplus") {
if(cur_loc.x >= scenario.out_width - 1) beep();
if(cur_loc.x >= scenario.outdoors.width() - 1) beep();
else cur_loc.x++;
} else if(item_hit == "yminus") {
if(cur_loc.y == 0) beep();
else cur_loc.y--;
} else if(item_hit == "yplus") {
if(cur_loc.y >= scenario.out_height - 1) beep();
if(cur_loc.y >= scenario.outdoors.height() - 1) beep();
else cur_loc.y++;
} else if(item_hit == "choose") {
int i = cur_loc.x * scenario.out_width + cur_loc.y;
int i = cur_loc.x * scenario.outdoors.width() + cur_loc.y;
i = choose_text(STRT_SECTOR, i, &me, "Which sector?");
cur_loc.x = i / scenario.out_width;
cur_loc.y = i % scenario.out_width;
cur_loc.x = i / scenario.outdoors.width();
cur_loc.y = i % scenario.outdoors.width();
}
put_out_loc_in_dlog(me, cur_loc);
return true;
@@ -1094,8 +1094,8 @@ location pick_out(location default_loc) {
out_dlg["cancel"].attachClickHandler(std::bind(finish_pick_out, _1, false, std::ref(default_loc), prev_loc));
out_dlg.attachClickHandlers(std::bind(pick_out_event_filter, _1, _2, std::ref(default_loc)), {"xplus", "xminus", "yplus", "yminus", "choose"});
out_dlg["width"].setTextToNum(scenario.out_width);
out_dlg["height"].setTextToNum(scenario.out_height);
out_dlg["width"].setTextToNum(scenario.outdoors.width());
out_dlg["height"].setTextToNum(scenario.outdoors.height());
put_out_loc_in_dlog(out_dlg, default_loc);
out_dlg.run();
@@ -1113,12 +1113,10 @@ bool new_town(short which_town) {
std::string size = dynamic_cast<cLedGroup&>(new_dlg->getControl("size")).getSelected();
std::string preset = dynamic_cast<cLedGroup&>(new_dlg->getControl("preset")).getSelected();
scenario.num_towns++;
if(size == "lg") scenario.towns.push_back(new cBigTown(scenario));
else if(size == "med") scenario.towns.push_back(new cMedTown(scenario));
else if(size == "sm") scenario.towns.push_back(new cTinyTown(scenario));
scenario.town_hidden[which_town] = 0;
cur_town = which_town;
town = scenario.towns[cur_town];
scenario.last_town_edited = cur_town;
@@ -1143,15 +1141,9 @@ bool new_town(short which_town) {
// before calling this, be sure to do all checks to make sure it's safe.
void delete_last_town() {
scenario.num_towns--;
scenario.town_size[scenario.num_towns] = 0;
scenario.town_hidden[scenario.num_towns] = 0;
scenario.town_data_size[scenario.num_towns][0] = 0;
scenario.town_data_size[scenario.num_towns][1] = 0;
scenario.town_data_size[scenario.num_towns][2] = 0;
scenario.town_data_size[scenario.num_towns][3] = 0;
scenario.town_data_size[scenario.num_towns][4] = 0;
save_scenario(scenario.scen_file);
cTown* last_town = scenario.towns.back();
scenario.towns.pop_back();
delete last_town;
}
cTown* pick_import_town(short def) {