Remove the limit on the number of placed specials per town or outdoor sector

This commit is contained in:
2015-02-01 21:30:52 -05:00
parent d42c4fff08
commit a2ae288022
6 changed files with 60 additions and 46 deletions

View File

@@ -83,6 +83,7 @@ struct info_rect_t : public rectangle {
struct spec_loc_t : public location {
long spec;
spec_loc_t(int x, int y, long spec) : location(x,y), spec(spec) {}
spec_loc_t(const location& loc) : location(loc) {}
spec_loc_t& operator=(const location& loc) {*this = spec_loc_t(loc); return *this;}
// Declaring one constructor suppresses all implicit constructors, so declare them explicitly

View File

@@ -66,6 +66,7 @@ void cOutdoors::append(legacy::outdoor_record_type& old){
}
}
}
special_locs.resize(18);
for(i = 0; i < 18; i++){
special_locs[i].x = old.special_locs[i].x;
special_locs[i].y = old.special_locs[i].y;
@@ -131,9 +132,6 @@ cOutdoors::cOutdoors(cScenario& scenario, bool init_strings) : scenario(scenario
terrain[i][j] = 5; // formerly 0
}
for(i = 0; i < 18; i++) {
special_locs[i].spec = -1;
}
for(i = 0; i < 8; i++) {
exit_locs[i] = d_loc;
sign_locs[i] = d_loc;

View File

@@ -60,7 +60,7 @@ public:
};
short x,y; // Used while loading legacy scenarios.
ter_num_t terrain[48][48];
std::array<spec_loc_t,18> special_locs;
std::vector<spec_loc_t> special_locs;
location exit_locs[8];
short exit_dests[8];
location sign_locs[8];

View File

@@ -35,6 +35,7 @@ void cTown::append(legacy::town_record_type& old){
}
preset_fields.clear();
preset_fields.reserve(50);
special_locs.resize(50);
for(i = 0; i < 50; i++){
special_locs[i].x = old.special_locs[i].x;
special_locs[i].y = old.special_locs[i].y;
@@ -84,9 +85,6 @@ cTown::cTown(cScenario& scenario, bool init_strings) : scenario(scenario) {
wandering[i] = d_wan;
wandering_locs[i] = d_loc;
}
for(i = 0; i < 50; i++) {
special_locs[i].spec = -1;
}
lighting_type = LIGHT_NORMAL;
for(i = 0; i < 4; i++) {
start_locs[i] = d_loc;

View File

@@ -73,7 +73,7 @@ public:
int bg_town, bg_fight;
cWandering wandering[4];
location wandering_locs[4];
std::array<spec_loc_t,50> special_locs;
std::vector<spec_loc_t> special_locs;
location sign_locs[15];
eLighting lighting_type;
location start_locs[4];

View File

@@ -785,17 +785,19 @@ bool handle_action(location the_point,sf::Event /*event*/) {
for(x = 0; x < town->special_locs.size(); x++)
if(town->special_locs[x] == spot_hit && town->special_locs[x].spec >= 0) {
copied_spec = town->special_locs[x].spec;
x = 500;
x = -1;
break;
}
}
if(!editing_town) {
for(x = 0; x < current_terrain->special_locs.size(); x++)
if(current_terrain->special_locs[x] == spot_hit && current_terrain->special_locs[x].spec >= 0) {
copied_spec = current_terrain->special_locs[x].spec;
x = 500;
x = -1;
break;
}
}
if(x < 500)
if(x < 0)
giveError("There wasn't a special on that spot.");
set_cursor(wand_curs);
overall_mode = MODE_DRAWING;
@@ -806,29 +808,32 @@ bool handle_action(location the_point,sf::Event /*event*/) {
break;
}
if(editing_town) {
for(x = 0; x < town->special_locs.size(); x++)
for(x = 0; x <= town->special_locs.size(); x++) {
if(x == town->special_locs.size())
town->special_locs.emplace_back(-1,-1,-1);
if(town->special_locs[x].spec < 0) {
town->special_locs[x] = spot_hit;
town->special_locs[x].spec = copied_spec;
x = 500;
break;
}
}
}
if(!editing_town) {
if((spot_hit.x == 0) || (spot_hit.x == 47) || (spot_hit.y == 0) || (spot_hit.y == 47)) {
cChoiceDlog("not-at-edge").show();
break;
}
for(x = 0; x < current_terrain->special_locs.size(); x++)
for(x = 0; x <= current_terrain->special_locs.size(); x++) {
if(x == current_terrain->special_locs.size())
current_terrain->special_locs.emplace_back(-1,-1,-1);
if(current_terrain->special_locs[x].spec < 0) {
current_terrain->special_locs[x] = spot_hit;
current_terrain->special_locs[x].spec = copied_spec;
x = 500;
break;
}
}
}
if(x < 500)
giveError("Each town can have at most 50 locations with special encounters. Each outdoor section can have at most 18. You'll need to erase some special spaces before you can place more.");
set_cursor(wand_curs);
overall_mode = MODE_DRAWING;
break;
@@ -838,7 +843,13 @@ bool handle_action(location the_point,sf::Event /*event*/) {
if(town->special_locs[x] == spot_hit && town->special_locs[x].spec >= 0) {
town->special_locs[x] = {-1,-1};
town->special_locs[x].spec = -1;
x = 500;
if(x == town->special_locs.size() - 1) {
// Delete not only the last entry but any other empty entries at the end of the list
do {
town->special_locs.pop_back();
} while(town->special_locs.back().spec < 0);
}
break;
}
}
if(!editing_town) {
@@ -846,7 +857,13 @@ bool handle_action(location the_point,sf::Event /*event*/) {
if(current_terrain->special_locs[x] == spot_hit && current_terrain->special_locs[x].spec >= 0) {
current_terrain->special_locs[x] = {-1,-1};
current_terrain->special_locs[x].spec = -1;
x = 500;
if(x == current_terrain->special_locs.size() - 1) {
// Delete not only the last entry but any other empty entries at the end of the list
do {
current_terrain->special_locs.pop_back();
} while(current_terrain->special_locs.back().spec < 0);
}
break;
}
}
set_cursor(wand_curs);
@@ -2793,21 +2810,20 @@ void place_edit_special(location loc) {
for(i = 0; i < town->special_locs.size(); i++)
if(town->special_locs[i] == loc && town->special_locs[i].spec >= 0) {
edit_spec_enc(town->special_locs[i].spec,2,nullptr);
i = 500;
break;
}
if(i < 500) { // new special
if(i == town->special_locs.size()) { // new special
spec = get_fresh_spec(2);
for(i = 0; i < town->special_locs.size(); i++)
for(i = 0; i <= town->special_locs.size(); i++) {
if(i == town->special_locs.size())
town->special_locs.emplace_back(-1,-1,-1);
if(town->special_locs[i].spec < 0) {
if(edit_spec_enc(spec,2,nullptr)) {
town->special_locs[i] = loc;
town->special_locs[i].spec = spec;
}
i = 500;
break;
}
if(i < 500) {
giveError("Each town can have at most 50 locations with special encounters. You'll need to erase some special spaces before you can place more.");
return;
}
}
}
@@ -2820,21 +2836,20 @@ void place_edit_special(location loc) {
for(i = 0; i < current_terrain->special_locs.size(); i++)
if(current_terrain->special_locs[i] == loc && current_terrain->special_locs[i].spec >= 0) {
edit_spec_enc(current_terrain->special_locs[i].spec,1,nullptr);
i = 500;
break;
}
if(i < 500) { // new special
if(i == current_terrain->special_locs.size()) { // new special
spec = get_fresh_spec(1);
for(i = 0; i < current_terrain->special_locs.size(); i++)
for(i = 0; i <= current_terrain->special_locs.size(); i++) {
if(i == current_terrain->special_locs.size())
current_terrain->special_locs.emplace_back(-1,-1,-1);
if(current_terrain->special_locs[i].spec < 0) {
if(edit_spec_enc(spec,1,nullptr)) {
current_terrain->special_locs[i] = loc;
current_terrain->special_locs[i].spec = spec;
}
i = 500;
break;
}
if(i < 500) {
giveError("Each outdoor can have at most 18 locations with special encounters. You'll need to erase some special spaces before you can place more.");
return;
}
}
}
@@ -2849,20 +2864,21 @@ void set_special(location spot_hit) {
if(town->special_locs[x] == spot_hit && town->special_locs[x].spec >= 0) {
y = edit_special_num(2,town->special_locs[x].spec);
if(y >= 0) town->special_locs[x].spec = y;
x = 500;
break;
}
if(x < 500) {
for(x = 0; x < town->special_locs.size(); x++)
if(x == town->special_locs.size()) {
for(x = 0; x <= town->special_locs.size(); x++) {
if(x == town->special_locs.size())
town->special_locs.emplace_back(-1,-1,-1);
if(town->special_locs[x].spec < 0) {
y = edit_special_num(2,0);
if(y >= 0) {
town->special_locs[x] = spot_hit;
town->special_locs[x].spec = y;
}
x = 500;
break;
}
if(x < 500)
giveError("Each town can have at most 50 locations with special encounters. Each outdoor section can have at most 18. You'll need to erase some special spaces before you can place more.");
}
}
}
if(!editing_town) {
@@ -2874,20 +2890,21 @@ void set_special(location spot_hit) {
if(current_terrain->special_locs[x] == spot_hit && current_terrain->special_locs[x].spec >= 0) {
y = edit_special_num(1,current_terrain->special_locs[x].spec);
if(y >= 0) current_terrain->special_locs[x].spec = y;
x = 500;
break;
}
if(x < 500) {
for(x = 0; x < current_terrain->special_locs.size(); x++)
if(x == current_terrain->special_locs.size()) {
for(x = 0; x <= current_terrain->special_locs.size(); x++) {
if(x == current_terrain->special_locs.size())
current_terrain->special_locs.emplace_back(-1,-1,-1);
if(current_terrain->special_locs[x].spec < 0) {
y = edit_special_num(1,current_terrain->special_locs[x].spec);
if(y >= 0) {
current_terrain->special_locs[x] = spot_hit;
current_terrain->special_locs[x].spec = y;
}
x = 500;
break;
}
if(x < 500)
giveError("Each town can have at most 50 locations with special encounters. Each outdoor section can have at most 18. You'll need to erase some special spaces before you can place more.");
}
}
}