Fix fields array not matching the size of the town
The fields array was fixed at 64x64, which is fine for all towns supported in legacy BoE. However, we intend to support even larger towns in the future, and also it seems silly to hold so much extra space for a smaller town. So now, the fields array is a 2D vector that matches the size of the terrain vector. The setup array is similarly a list of 2D vectors. This radically changes the format used to store the setup array in a saved game. Older saves won't crash the game, but fields will be messed up or missing. Resetting towns is recommended.
This commit is contained in:
@@ -274,10 +274,6 @@ void start_outdoor_combat(cOutdoors::cCreature encounter,location where,short nu
|
||||
|
||||
// Basically, in outdoor combat, we create kind of a 48x48 town for
|
||||
// the combat to take place in
|
||||
for(short i = 0; i < 48; i++)
|
||||
for(short j = 0; j < 48; j++) {
|
||||
univ.town.fields[i][j] = 0;
|
||||
}
|
||||
univ.town.prep_arena();
|
||||
univ.town->in_town_rect = town_rect;
|
||||
|
||||
|
@@ -715,8 +715,6 @@ bool combat_move_monster(short which,location destination) {
|
||||
location find_clear_spot(location from_where,short mode) {
|
||||
location loc,store_loc;
|
||||
short num_tries = 0,r1;
|
||||
// Here 254 indicates the low byte of the town fields, minus explored spaces (which is lowest bit).
|
||||
unsigned long blocking_fields = SPECIAL_SPOT | OBJECT_CRATE | OBJECT_BARREL | OBJECT_BLOCK | FIELD_QUICKFIRE | 254;
|
||||
|
||||
while(num_tries < 75) {
|
||||
num_tries++;
|
||||
@@ -729,7 +727,7 @@ location find_clear_spot(location from_where,short mode) {
|
||||
&& can_see_light(from_where,loc,combat_obscurity) == 0
|
||||
&& (!is_combat() || univ.target_there(loc,TARG_PC) == nullptr)
|
||||
&& (!(is_town()) || (loc != univ.party.town_loc))
|
||||
&& (!(univ.town.fields[loc.x][loc.y] & blocking_fields))) {
|
||||
&& (!univ.town.is_summon_safe(loc.x, loc.y))) {
|
||||
if((mode == 0) || ((mode == 1) && (adjacent(from_where,loc))))
|
||||
return loc;
|
||||
else store_loc = loc;
|
||||
|
@@ -75,7 +75,6 @@ void start_town_mode(short which_town, short entry_dir) {
|
||||
short at_which_save_slot,former_town;
|
||||
bool monsters_loaded = false,town_toast = false;
|
||||
location loc;
|
||||
unsigned short temp;
|
||||
bool play_town_sound = false;
|
||||
|
||||
if(town_force < 200)
|
||||
@@ -230,15 +229,9 @@ void start_town_mode(short which_town, short entry_dir) {
|
||||
}
|
||||
}
|
||||
|
||||
for(short j = 0; j < univ.town->max_dim; j++)
|
||||
for(short k = 0; k < univ.town->max_dim; k++) { // now load in saved setup,
|
||||
// except that pushable things restore to orig locs
|
||||
// TODO: THIS IS A TEMPORARY HACK TO GET i VALUE
|
||||
int i = std::find_if(univ.party.creature_save.begin(), univ.party.creature_save.end(), [&pop](cPopulation& p) {return &p == &pop;}) - univ.party.creature_save.begin();
|
||||
temp = univ.party.setup[i][j][k] << 8;
|
||||
temp &= ~(OBJECT_CRATE | OBJECT_BARREL | OBJECT_BLOCK);
|
||||
univ.town.fields[j][k] |= temp;
|
||||
}
|
||||
// TODO: THIS IS A TEMPORARY HACK TO GET i VALUE
|
||||
int i = std::find_if(univ.party.creature_save.begin(), univ.party.creature_save.end(), [&pop](cPopulation& p) {return &p == &pop;}) - univ.party.creature_save.begin();
|
||||
univ.town.update_fields(univ.party.setup[i]);
|
||||
}
|
||||
|
||||
if(!monsters_loaded) {
|
||||
@@ -547,16 +540,13 @@ location end_town_mode(short switching_level,location destination) { // returns
|
||||
pop = univ.town.monst;
|
||||
// TODO: THIS IS A TEMPORARY HACK TO GET i VALUE
|
||||
int i = std::find_if(univ.party.creature_save.begin(), univ.party.creature_save.end(), [&pop](cPopulation& p) {return &p == &pop;}) - univ.party.creature_save.begin();
|
||||
for(short j = 0; j < univ.town->max_dim; j++)
|
||||
for(short k = 0; k < univ.town->max_dim; k++)
|
||||
univ.party.setup[i][j][k] = (univ.town.fields[j][k] & 0xff00) >> 8;
|
||||
univ.town.save_setup(univ.party.setup[i]);
|
||||
data_saved = true;
|
||||
break;
|
||||
}
|
||||
if(!data_saved) {
|
||||
univ.party.creature_save[univ.party.at_which_save_slot] = univ.town.monst;
|
||||
for(short j = 0; j < univ.town->max_dim; j++)
|
||||
for(short k = 0; k < univ.town->max_dim; k++)
|
||||
univ.party.setup[univ.party.at_which_save_slot][j][k] = (univ.town.fields[j][k] & 0xff00) >> 8;
|
||||
univ.town.save_setup(univ.party.setup[univ.party.at_which_save_slot]);
|
||||
univ.party.at_which_save_slot = (univ.party.at_which_save_slot == 3) ? 0 : univ.party.at_which_save_slot + 1;
|
||||
}
|
||||
|
||||
@@ -930,7 +920,6 @@ void create_out_combat_terrain(short ter_type,short num_walls,bool is_road) {
|
||||
|
||||
for(short i = 0; i < 48; i++)
|
||||
for(short j = 0; j < 48; j++) {
|
||||
univ.town.fields[i][j] = 0;
|
||||
if((j <= 8) || (j >= 35) || (i <= 8) || (i >= 35))
|
||||
univ.town->terrain(i,j) = 90;
|
||||
else univ.town->terrain(i,j) = ter_base[arena];
|
||||
|
Reference in New Issue
Block a user