Make monster/item lists in party town record dynamic

This commit is contained in:
2015-01-23 02:53:36 -05:00
parent d9b9130d00
commit f574281c3f
21 changed files with 85 additions and 182 deletions

View File

@@ -15,6 +15,7 @@
#include "oldstructs.h"
void cPopulation::append(legacy::creature_list_type old){
dudes.resize(60);
for(int i = 0; i < 60; i++)
dudes[i].append(old.dudes[i]);
which_town = old.which_town;
@@ -33,6 +34,8 @@ cCreature& cPopulation::operator[](size_t n){
// into a cCreature, and prepares it for use in-game according to the user's preferences and party strength
// replaces return_monster_template() from boe.monsters.cpp
void cPopulation::assign(size_t n, const cTownperson& other, const cMonster& base, bool easy, int difficulty_adjust){
// Make sure the space exists
if(n >= dudes.size()) dudes.resize(n + 1);
// First copy over the superclass fields
static_cast<cTownperson&>(dudes[n]) = other;
static_cast<cMonster&>(dudes[n]) = base;
@@ -57,3 +60,8 @@ void cPopulation::assign(size_t n, const cTownperson& other, const cMonster& bas
dudes[n].target = 6; // No target
dudes[n].summoned = 0;
}
void cPopulation::readFrom(std::istream& in, size_t n) {
if(n >= dudes.size()) dudes.resize(n + 1);
dudes[n].readFrom(in);
}

View File

@@ -10,6 +10,7 @@
#define BOE_DATA_CREATLIST_H
#include "monster.h"
#include <iosfwd>
namespace legacy {
struct creature_list_type;
@@ -29,14 +30,16 @@ class cPopulation { // formerly creature_list_type
//
// cCreature& operator = (legacy::creature_data_type old);
// };
cCreature dudes[60];
std::vector<cCreature> dudes;
public:
short which_town;
short friendly;
void append(legacy::creature_list_type old);
void assign(size_t n, const cTownperson& other, const cMonster& base, bool easy, int difficulty_adjust);
size_t size() {return 60;}
void readFrom(std::istream& in, size_t n);
size_t size() const {return dudes.size();}
void clear() {dudes.clear();}
cCreature& operator[](size_t n);
const cCreature& operator[](size_t n) const;
cPopulation() : which_town(200) {}

View File

@@ -1093,15 +1093,15 @@ void cMonster::readFrom(std::istream& file) {
void cCreature::writeTo(std::ostream& file) const {
file << "MONSTER " << number << '\n';
file << "ATTITUDE " << attitude << '\n';
file << "STARTATT " << unsigned(start_attitude) << '\n';
file << "STARTATT " << start_attitude << '\n';
file << "STARTLOC " << start_loc.x << ' ' << start_loc.y << '\n';
file << "LOCATION " << cur_loc.x << ' ' << cur_loc.y << '\n';
file << "MOBILITY " << unsigned(mobility) << '\n';
file << "MOBILITY " << mobility << '\n';
file << "TIMEFLAG " << time_flag << '\n';
file << "SUMMONED " << summoned << '\n';
file << "SPEC " << spec1 << ' ' << spec2 << '\n';
file << "SPECCODE " << int(spec_enc_code) << '\n';
file << "TIMECODE " << int(time_code) << '\n';
file << "SPECCODE " << spec_enc_code << '\n';
file << "TIMECODE " << time_code << '\n';
file << "TIME " << monster_time << '\n';
file << "TALK " << personality << '\n';
file << "DEATH " << special_on_kill << '\n';
@@ -1116,6 +1116,7 @@ void cCreature::writeTo(std::ostream& file) const {
file << "CURSP " << mp << '\n';
file << "MORALE " << morale << '\n';
file << "DIRECTION " << unsigned(direction) << '\n';
// TODO: Should we be saving "max_mp" and/or "m_morale"?
}
void cCreature::readFrom(std::istream& file) {

View File

@@ -145,6 +145,7 @@ void cParty::append(legacy::party_record_type& old){
}
void cParty::append(legacy::stored_items_list_type& old,short which_list){
stored_items[which_list].resize(115);
for(int i = 0; i < 115; i++)
stored_items[which_list][i].append(old.items[i]);
}
@@ -479,7 +480,7 @@ void cParty::writeTo(std::ostream& file) const {
}
file << '\f';
for(int i = 0; i < 3; i++)
for(int j = 0; j < 115; j++)
for(size_t j = 0; j < stored_items[i].size(); j++)
if(stored_items[i][j].variety != eItemType::NO_ITEM){
file << "STORED " << i << ' ' << j << '\n';
stored_items[i][j].writeTo(file);
@@ -697,6 +698,9 @@ void cParty::readFrom(std::istream& file){
} else if(cur == "STORED") {
int i, j;
bin >> i >> j;
if(i < 0 || i >= 3 || j < 0) continue;
if(j >= stored_items[i].size())
stored_items[i].resize(j + 1);
stored_items[i][j].readFrom(bin);
} else if(cur == "SUMMON") {
size_t i;

View File

@@ -109,7 +109,7 @@ private:
std::array<cPlayer*,6> adven;
public:
unsigned short setup[4][64][64]; // formerly setup_save_type
std::array<std::array<cItem,115>,3> stored_items; // formerly stored_items_list_type
std::array<std::vector<cItem>,3> stored_items; // formerly stored_items_list_type
std::vector<cMonster> summons; // an array of monsters which can be summoned by the party's items yet don't originate from this scenario
unsigned short scen_won, scen_played; // numbers of scenarios won and played respectively by this party

View File

@@ -37,9 +37,6 @@ void cTown::append(legacy::town_record_type& old){
special_locs[i].x = old.special_locs[i].x;
special_locs[i].y = old.special_locs[i].y;
spec_id[i] = old.spec_id[i];
// preset_fields[i].loc.x = old.preset_fields[i].field_loc.x;
// preset_fields[i].loc.y = old.preset_fields[i].field_loc.y;
// preset_fields[i].type = old.preset_fields[i].field_type;
cField temp;
temp.append(old.preset_fields[i]);
preset_fields.push_back(temp);
@@ -55,14 +52,6 @@ void cTown::append(legacy::town_record_type& old){
in_town_rect.right = old.in_town_rect.right;
preset_items.resize(64);
for(i = 0; i < 64; i++){
// preset_items[i].loc.x = old.preset_items[i].item_loc.x;
// preset_items[i].loc.y = old.preset_items[i].item_loc.y;
// preset_items[i].code = old.preset_items[i].item_code;
// preset_items[i].ability = old.preset_items[i].ability;
// preset_items[i].charges = old.preset_items[i].charges;
// preset_items[i].always_there = old.preset_items[i].always_there;
// preset_items[i].property = old.preset_items[i].property;
// preset_items[i].contained = old.preset_items[i].contained;
preset_items[i].append(old.preset_items[i]);
}
max_num_monst = old.max_num_monst;

View File

@@ -58,6 +58,7 @@ void cCurTown::append(legacy::big_tr_type& old){
}
void cCurTown::append(legacy::town_item_list& old){
items.resize(115);
for(int i = 0; i < 115; i++)
items[i].append(old.items[i]);
}
@@ -771,14 +772,14 @@ void cCurTown::writeTo(std::ostream& file) const {
file << "INBOAT " << in_boat << '\n';
file << "AT " << p_loc.x << ' ' << p_loc.y << '\n';
file << '\f';
for(int i = 0; i < 115; i++)
for(size_t i = 0; i < items.size(); i++)
if(items[i].variety != eItemType::NO_ITEM){
file << "ITEM " << i << '\n';
items[i].writeTo(file);
file << '\f';
}
file << '\f';
for(int i = 0; i < 60; i++) {
for(int i = 0; i < monst.size(); i++) {
if(monst[i].active > 0) {
file << "CREATURE " << i << '\n';
monst[i].writeTo(file);
@@ -828,12 +829,14 @@ void cCurTown::readFrom(std::istream& file){
} else if(cur == "ITEM") {
int i;
bin >> i;
if(i >= items.size())
items.resize(i + 1);
items[i].readFrom(bin);
} else if(cur == "CREATURE") {
int i;
bin >> i;
monst.readFrom(bin, i);
monst[i].active = true;
monst[i].readFrom(bin);
} else if(cur == "TERRAIN")
univ.scenario.towns[num]->readTerrainFrom(bin);
bin.clear();

View File

@@ -50,7 +50,7 @@ public:
bool in_boat; // is this really needed?
location p_loc;
std::array<cItem,115> items; // formerly town_item_list type
std::vector<cItem> items; // formerly town_item_list type
unsigned long fields[64][64];