Fix use of a static bitset to record whether items (in a dynamic vector) have been taken
This commit is contained in:
@@ -248,7 +248,7 @@ short dist_from_party(location where) {
|
||||
void set_item_flag(cItem* item) {
|
||||
if((item->is_special > 0) && (item->is_special < 65)) {
|
||||
item->is_special--;
|
||||
univ.town->item_taken.set(item->is_special);
|
||||
univ.town->set_item_taken(item->is_special);
|
||||
item->is_special = 0;
|
||||
}
|
||||
}
|
||||
|
@@ -383,7 +383,7 @@ void start_town_mode(short which_town, short entry_dir) {
|
||||
continue;
|
||||
}
|
||||
// Don't place the item if the party already took it, unless it's always there
|
||||
if(univ.town->item_taken[i] && !preset.always_there) {
|
||||
if(univ.town->is_item_taken(i) && !preset.always_there) {
|
||||
univ.town.items.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
@@ -245,3 +245,17 @@ void cTown::writeTerrainTo(std::ostream& file) {
|
||||
void cTown::readTerrainFrom(std::istream& file) {
|
||||
readArray(file, terrain, max_dim, max_dim);
|
||||
}
|
||||
|
||||
bool cTown::is_item_taken(size_t i) const {
|
||||
if(i >= item_taken.size()) return false;
|
||||
return item_taken[i];
|
||||
}
|
||||
|
||||
void cTown::clear_items_taken() {
|
||||
item_taken.clear();
|
||||
}
|
||||
|
||||
void cTown::set_item_taken(size_t i, bool val) {
|
||||
if(i >= item_taken.size()) item_taken.resize(i + 1);
|
||||
item_taken.set(i, val);
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@
|
||||
#include <vector>
|
||||
#include <iosfwd>
|
||||
#include <array>
|
||||
#include <bitset>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
#include "location.hpp"
|
||||
#include "special.hpp"
|
||||
#include "monster.hpp"
|
||||
@@ -41,6 +41,7 @@ enum eLighting {
|
||||
class cScenario;
|
||||
|
||||
class cTown : public cArea { // formerly town_record_type
|
||||
friend class cParty; // so the read/save functions can access item_taken directly
|
||||
protected:
|
||||
cScenario* scenario;
|
||||
public:
|
||||
@@ -95,8 +96,10 @@ public:
|
||||
std::array<std::string,3> comment;
|
||||
std::vector<std::string> spec_strs;
|
||||
cSpeech talking;
|
||||
private:
|
||||
// Persistent data for saved games
|
||||
std::bitset<64> item_taken;
|
||||
boost::dynamic_bitset<> item_taken;
|
||||
public:
|
||||
bool can_find;
|
||||
long m_killed;
|
||||
|
||||
@@ -112,6 +115,10 @@ public:
|
||||
void reattach(cScenario& to);
|
||||
void writeTerrainTo(std::ostream& file);
|
||||
void readTerrainFrom(std::istream& file);
|
||||
// Work with the item_taken bitset
|
||||
bool is_item_taken(size_t i) const;
|
||||
void clear_items_taken();
|
||||
void set_item_taken(size_t i, bool val = true);
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& out, eLighting light);
|
||||
|
@@ -274,7 +274,7 @@ void cParty::import_legacy(legacy::party_record_type& old, cUniverse& univ){
|
||||
univ.scenario.towns[i]->can_find = old.can_find_town[i];
|
||||
univ.scenario.towns[i]->m_killed = old.m_killed[i];
|
||||
for(short j = 0; j < 64; j++)
|
||||
univ.scenario.towns[i]->item_taken[j] = old.item_taken[i][j / 8] & (1 << j % 8);
|
||||
univ.scenario.towns[i]->set_item_taken(j, old.item_taken[i][j / 8] & (1 << j % 8));
|
||||
}
|
||||
for(short i = 0; i < 100; i++)
|
||||
key_times[i] = old.key_times[i];
|
||||
|
@@ -1361,7 +1361,7 @@ void cUniverse::enter_scenario(const std::string& name) {
|
||||
for(auto town : scenario.towns) {
|
||||
town->can_find = !town->is_hidden;
|
||||
town->m_killed = 0;
|
||||
town->item_taken.reset();
|
||||
town->clear_items_taken();
|
||||
for(auto& m : town->maps)
|
||||
m.reset();
|
||||
}
|
||||
|
Reference in New Issue
Block a user