Ensure stored PCs don't reference a party

This commit is contained in:
2016-08-15 02:06:46 -04:00
parent ac93dbe09f
commit 7b617702ff
5 changed files with 7 additions and 3 deletions

View File

@@ -3253,7 +3253,7 @@ void affect_spec(eSpecCtx which_mode,cSpecial cur_node,short cur_spec_type,
univ.party.stuff_done[spec.sd1][spec.sd2] = univ.party[pc_num].unique_id - 1000; univ.party.stuff_done[spec.sd1][spec.sd2] = univ.party[pc_num].unique_id - 1000;
if(spec.ex1a == 1) break; if(spec.ex1a == 1) break;
who->main_status += eMainStatus::SPLIT; who->main_status += eMainStatus::SPLIT;
univ.stored_pcs[who->unique_id] = who; univ.stored_pcs[who->unique_id] = who->leave_party();
univ.party.new_pc(pc_num); univ.party.new_pc(pc_num);
} }
break; break;

View File

@@ -232,6 +232,7 @@ void cParty::new_pc(size_t spot) {
void cParty::replace_pc(size_t spot, cPlayer* with) { void cParty::replace_pc(size_t spot, cPlayer* with) {
if(spot < 6 && with != nullptr) { if(spot < 6 && with != nullptr) {
with->join_party(*this);
delete adven[spot]; delete adven[spot];
adven[spot] = with; adven[spot] = with;
} }

View File

@@ -111,6 +111,9 @@ public:
short stat_adj(eSkill skill) const; short stat_adj(eSkill skill) const;
eBuyStatus ok_to_buy(short cost,cItem item) const; eBuyStatus ok_to_buy(short cost,cItem item) const;
void join_party(cParty& p) {party = &p;}
cPlayer* leave_party() {party = nullptr; return this;}
void append(legacy::pc_record_type old); void append(legacy::pc_record_type old);
cPlayer(cParty& party); cPlayer(cParty& party);
cPlayer(cParty& party,long key,short slot); cPlayer(cParty& party,long key,short slot);

View File

@@ -171,7 +171,7 @@ public:
void swap_buf(int newbuf) {std::swap(strbuf, extrabufs[newbuf]);} void swap_buf(int newbuf) {std::swap(strbuf, extrabufs[newbuf]);}
unsigned char& cpn_flag(unsigned int x, unsigned int y, std::string id = ""); unsigned char& cpn_flag(unsigned int x, unsigned int y, std::string id = "");
cScenario scenario; cScenario scenario;
cParty party; cParty party;
std::map<long,cPlayer*> stored_pcs; std::map<long,cPlayer*> stored_pcs;

View File

@@ -319,7 +319,7 @@ bool load_party_v2(fs::path file_to_load, cUniverse& univ){
std::string fname = "save/pc~" + std::to_string(next_uid) + ".txt"; std::string fname = "save/pc~" + std::to_string(next_uid) + ".txt";
cPlayer* stored_pc = new cPlayer(univ.party); cPlayer* stored_pc = new cPlayer(univ.party);
stored_pc->readFrom(partyIn.getFile(fname)); stored_pc->readFrom(partyIn.getFile(fname));
univ.stored_pcs[next_uid] = stored_pc; univ.stored_pcs[next_uid] = stored_pc->leave_party();
} }
} }