Skip to content

Commit

Permalink
XEEN: Revert "XEEN: Change _gameFlags to it's own class"
Browse files Browse the repository at this point in the history
This reverts commit a37b0e8.
Turns out the overlapping byte access was for the questItems
array, but using Ids which start at 82 rather than 0
  • Loading branch information
dreammaster committed Dec 29, 2017
1 parent a37b0e8 commit fb73c1a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 81 deletions.
6 changes: 3 additions & 3 deletions engines/xeen/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1476,16 +1476,16 @@ void Combat::attack2(int damage, RangeType rangeType) {
if (monsterDied) {
if (!isDarkCc) {
if (_monster2Attack == 20 && party._mazeId == 41)
party._gameFlags.set(11, true);
party._gameFlags[0][11] = true;
if (_monster2Attack == 8 && party._mazeId == 78) {
party._gameFlags.set(60, true);
party._gameFlags[0][60] = true;
party._questFlags[0][23] = false;

for (uint idx = 0; idx < party._activeParty.size(); ++idx)
party._activeParty[idx].setAward(42, true);

if (_monster2Attack == 27 && party._mazeId == 29)
party._gameFlags.set(104, true);
party._gameFlags[0][104] = true;
}
}

Expand Down
4 changes: 2 additions & 2 deletions engines/xeen/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ void Interface::doStepCode() {
break;
}

if (_vm->_files->_isDarkCc && party._gameFlags.get(118, 1)) {
if (_vm->_files->_isDarkCc && party._gameFlags[1][118]) {
_falling = false;
} else {
if (_falling)
Expand Down Expand Up @@ -711,7 +711,7 @@ void Interface::startFalling(bool flag) {
Scripts &scripts = *_vm->_scripts;
bool isDarkCc = _vm->_files->_isDarkCc;

if (isDarkCc && party._gameFlags.get(118, 1)) {
if (isDarkCc && party._gameFlags[1][118]) {
_falling = 0;
return;
}
Expand Down
8 changes: 4 additions & 4 deletions engines/xeen/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ void Map::load(int mapId) {

if (isDarkCc && mapId == 50)
mazeDataP->setAllTilesStepped();
if (!isDarkCc && party._gameFlags.get(25) &&
if (!isDarkCc && party._gameFlags[0][25] &&
(mapId == 42 || mapId == 43 || mapId == 4)) {
mazeDataP->clearCellSurfaces();
}
Expand Down Expand Up @@ -1100,7 +1100,7 @@ void Map::load(int mapId) {
if ((_mobData._monsters[0]._position.x > 31 || _mobData._monsters[0]._position.y > 31) &&
(_mobData._monsters[1]._position.x > 31 || _mobData._monsters[1]._position.y > 31) &&
(_mobData._monsters[2]._position.x > 31 || _mobData._monsters[2]._position.y > 31)) {
party._gameFlags.set(56, true);
party._gameFlags[0][56] = true;
}
}
}
Expand Down Expand Up @@ -1135,7 +1135,7 @@ void Map::load(int mapId) {
_mobData._objects[29]._spriteId = 0;
_mobData._objects[29]._id = 8;
_mobData._objectSprites[i]._sprites.clear();
} else if (mapId == 12 && party._gameFlags.get(43) &&
} else if (mapId == 12 && party._gameFlags[0][43] &&
_mobData._objectSprites[i]._spriteId == 118 && !isDarkCc) {
filename = "085.obj";
_mobData._objectSprites[0]._spriteId = 85;
Expand Down Expand Up @@ -1445,7 +1445,7 @@ void Map::saveMap() {
for (uint idx = 0; idx < MIN(_mobData._monsters.size(), (uint)3); ++idx) {
MazeMonster &mon = _mobData._monsters[idx];
if (mon._position.x > 31 || mon._position.y > 31) {
party._gameFlags.set(56, true);
party._gameFlags[0][56] = true;
break;
}
}
Expand Down
45 changes: 10 additions & 35 deletions engines/xeen/party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,6 @@ Treasure::Treasure() {

/*------------------------------------------------------------------------*/

void Party::GameFlags::clear() {
Common::fill(&_flags[0][0], &_flags[0][0] + (FLAGS_COUNT / 8), 0);
Common::fill(&_flags[1][0], &_flags[1][0] + (FLAGS_COUNT / 8), 0);
}

bool Party::GameFlags::get(uint flagNum, uint sideNum) const {
if (flagNum >= FLAGS_COUNT) {
sideNum = flagNum / FLAGS_COUNT;
flagNum %= FLAGS_COUNT;
}

return (_flags[sideNum][flagNum / 8] & (1 << (flagNum % 8))) != 0;
}

void Party::GameFlags::set(uint flagNum, uint sideNum, bool value) {
byte &b = _flags[sideNum][flagNum / 8];
b &= ~(1 << (flagNum % 8));
if (value)
b |= 1 << (flagNum % 8);
}

void Party::GameFlags::synchronize(Common::Serializer &s) {
s.syncBytes(&_flags[0][0], FLAGS_COUNT / 8);
s.syncBytes(&_flags[1][0], FLAGS_COUNT / 8);
}

/*------------------------------------------------------------------------*/

XeenEngine *Party::_vm;

Party::Party(XeenEngine *vm) {
Expand Down Expand Up @@ -140,6 +112,8 @@ Party::Party(XeenEngine *vm) {
_totalTime = 0;
_rested = false;

Common::fill(&_gameFlags[0][0], &_gameFlags[0][256], false);
Common::fill(&_gameFlags[1][0], &_gameFlags[1][256], false);
Common::fill(&_worldFlags[0], &_worldFlags[128], false);
Common::fill(&_questFlags[0][0], &_questFlags[0][30], false);
Common::fill(&_questFlags[1][0], &_questFlags[1][30], false);
Expand Down Expand Up @@ -232,7 +206,8 @@ void Party::synchronize(Common::Serializer &s) {
s.syncAsUint32LE(_bankGems);
s.syncAsUint32LE(_totalTime);
s.syncAsByte(_rested);
_gameFlags.synchronize(s);
File::syncBitFlags(s, &_gameFlags[0][0], &_gameFlags[0][256]);
File::syncBitFlags(s, &_gameFlags[1][0], &_gameFlags[1][256]);
File::syncBitFlags(s, &_worldFlags[0], &_worldFlags[128]);
File::syncBitFlags(s, &_questFlags[0][0], &_questFlags[0][30]);
File::syncBitFlags(s, &_questFlags[1][0], &_questFlags[1][30]);
Expand Down Expand Up @@ -851,7 +826,7 @@ bool Party::giveTake(int takeMode, uint takeVal, int giveMode, uint giveVal, int
break;
}
case 20:
_gameFlags.set(takeVal, files._isDarkCc, false);
_gameFlags[files._isDarkCc][takeVal] = false;
break;
case 21: {
bool found = false;
Expand Down Expand Up @@ -1121,7 +1096,7 @@ bool Party::giveTake(int takeMode, uint takeVal, int giveMode, uint giveVal, int
break;
}
case 20:
_gameFlags.set(giveVal, files._isDarkCc, true);
_gameFlags[files._isDarkCc][giveVal] = true;
break;
case 21: {
int idx;
Expand Down Expand Up @@ -1430,10 +1405,10 @@ void Party::subPartyTime(int time) {
}

void Party::resetYearlyBits() {
_gameFlags.set(55, false);
_gameFlags.set(155, false);
_gameFlags.set(222, false);
_gameFlags.set(231, false);
_gameFlags[0][55] = false;
_gameFlags[0][155] = false;
_gameFlags[0][222] = false;
_gameFlags[0][231] = false;
}

const int BLACKSMITH_DATA1[4][4] = {
Expand Down
37 changes: 1 addition & 36 deletions engines/xeen/party.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ enum PartyBank {
WHERE_PARTY = 0, WHERE_BANK = 1
};

#define FLAGS_COUNT 256
#define ITEMS_COUNT 36
#define TOTAL_CHARACTERS 30
#define XEEN_TOTAL_CHARACTERS 24
Expand Down Expand Up @@ -83,40 +82,6 @@ class Treasure {
class Party {
friend class Character;
friend class InventoryItems;

class GameFlags {
private:
byte _flags[2][FLAGS_COUNT / 8];
public:
byte &_state;
public:
GameFlags() : _state(_flags[0][6]) { clear(); }

/**
* Clears the flags
*/
void clear();

/**
* Get a flag value
*/
bool get(uint flagNum, uint sideNum = 0) const;

/**
* Sets a flag value
*/
void set(uint flagNum, bool value) { set(flagNum % 256, flagNum / 256, value); }

/**
* Sets a flag value
*/
void set(uint flagNum, uint sideNum, bool value);

/**
* Synchronize flags
*/
void synchronize(Common::Serializer &s);
};
private:
static XeenEngine *_vm;
Character _itemsCharacter;
Expand Down Expand Up @@ -185,7 +150,7 @@ class Party {
uint _bankGems;
int _totalTime;
bool _rested;
GameFlags _gameFlags;
bool _gameFlags[2][256];
bool _worldFlags[128];
bool _questFlags[2][30];
int _questItems[TOTAL_QUEST_ITEMS];
Expand Down
2 changes: 1 addition & 1 deletion engines/xeen/scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ bool Scripts::ifProc(int action, uint32 val, int mode, int charIndex) {
if (files._isDarkCc)
val += 256;
assert(val < 512);
v = party._gameFlags.get(val) ? val : 0xffffffff;
v = party._gameFlags[val / 256][val % 256] ? val : 0xffffffff;
break;
case 21:
// Scans inventories for given item number
Expand Down

0 comments on commit fb73c1a

Please sign in to comment.