Skip to content

Commit

Permalink
XEEN: Cleanup of party code split, moved roster and party to engine
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jan 2, 2015
1 parent 27e020c commit 9a8cb48
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 304 deletions.
1 change: 1 addition & 0 deletions engines/xeen/party.cpp
Expand Up @@ -25,6 +25,7 @@
#include "xeen/party.h"
#include "xeen/files.h"
#include "xeen/xeen.h"
#include "xeen/saves.h"

namespace Xeen {

Expand Down
288 changes: 2 additions & 286 deletions engines/xeen/saves.cpp
Expand Up @@ -28,294 +28,10 @@

namespace Xeen {

AttributePair::AttributePair() {
_temporary = _permanent = 0;
SavesManager::SavesManager(XeenEngine *vm, Party &party, Roster &roster) :
_vm(vm), _party(party), _roster(roster) {
}

void AttributePair::synchronize(Common::Serializer &s) {
s.syncAsByte(_permanent);
s.syncAsByte(_temporary);
}

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

Party::Party() {
_partyCount = 0;
_realPartyCount = 0;
Common::fill(&_partyMembers[0], &_partyMembers[8], 0);
_mazeDirection = DIR_NORTH;
_mazeId = _priorMazeId = 0;
_levitateActive = false;
_automapOn = false;
_wizardEyeActive = false;
_clairvoyanceActive = false;
_walkOnWaterActive = false;
_blessedActive = false;
_powerShieldActive = false;
_holyBonusActive = false;
_heroismActive = false;
_difficulty = ADVENTURER;
_cloudsEnd = false;
_darkSideEnd = false;
_worldEnd = false;
hour_maybe = 0;
_day = 0;
_year = 0;
_minutes = 0;
_food = 0;
_lightCount = 0;
_torchCount = 0;
_fireResistence = 0;
_electricityResistence = 0;
_coldResistence = 0;
_poisonResistence = 0;
_deathCount = 0;
_winCount = 0;
_lossCount = 0;
_gold = 0;
_gems = 0;
_bankGold = 0;
_bankGems = 0;
_totalTime = 0;
_rested = false;

Common::fill(&_gameFlags[0], &_gameFlags[512], false);
Common::fill(&_autoNotes[0], &_autoNotes[128], false);
Common::fill(&_quests[0], &_quests[64], false);
Common::fill(&_questItems[0], &_questItems[85], 0);

for (int i = 0; i < TOTAL_CHARACTERS; ++i)
Common::fill(&_characterFlags[i][0], &_characterFlags[i][24], false);
}

void Party::synchronize(Common::Serializer &s) {
byte dummy[30];
Common::fill(&dummy[0], &dummy[30], 0);

s.syncAsByte(_partyCount);
s.syncAsByte(_realPartyCount);
for (int i = 0; i < 8; ++i)
s.syncAsByte(_partyMembers[i]);
s.syncAsByte(_mazeDirection);
s.syncAsByte(_mazePosition.x);
s.syncAsByte(_mazePosition.y);
s.syncAsByte(_mazeId);

// Game configuration flags not used in this implementation
s.syncBytes(dummy, 3);

s.syncAsByte(_priorMazeId);
s.syncAsByte(_levitateActive);
s.syncAsByte(_automapOn);
s.syncAsByte(_wizardEyeActive);
s.syncAsByte(_clairvoyanceActive);
s.syncAsByte(_walkOnWaterActive);
s.syncAsByte(_blessedActive);
s.syncAsByte(_powerShieldActive);
s.syncAsByte(_holyBonusActive);
s.syncAsByte(_heroismActive);
s.syncAsByte(_difficulty);

for (int i = 0; i < ITEMS_COUNT; ++i)
_blacksmithWeapons[i].synchronize(s);
for (int i = 0; i < ITEMS_COUNT; ++i)
_blacksmithArmor[i].synchronize(s);
for (int i = 0; i < ITEMS_COUNT; ++i)
_blacksmithAccessories[i].synchronize(s);
for (int i = 0; i < ITEMS_COUNT; ++i)
_blacksmithMisc[i].synchronize(s);

s.syncAsUint16LE(_cloudsEnd);
s.syncAsUint16LE(_darkSideEnd);
s.syncAsUint16LE(_worldEnd);
s.syncAsUint16LE(hour_maybe);
s.syncAsUint16LE(_day);
s.syncAsUint16LE(_year);
s.syncAsUint16LE(_minutes);
s.syncAsUint16LE(_food);
s.syncAsUint16LE(_lightCount);
s.syncAsUint16LE(_torchCount);
s.syncAsUint16LE(_fireResistence);
s.syncAsUint16LE(_electricityResistence);
s.syncAsUint16LE(_coldResistence);
s.syncAsUint16LE(_poisonResistence);
s.syncAsUint16LE(_deathCount);
s.syncAsUint16LE(_winCount);
s.syncAsUint16LE(_lossCount);
s.syncAsUint32LE(_gold);
s.syncAsUint32LE(_gems);
s.syncAsUint32LE(_bankGold);
s.syncAsUint32LE(_bankGems);
s.syncAsUint32LE(_totalTime);
s.syncAsByte(_rested);
SavesManager::syncBitFlags(s, &_gameFlags[0], &_gameFlags[512]);
SavesManager::syncBitFlags(s, &_autoNotes[0], &_autoNotes[128]);
SavesManager::syncBitFlags(s, &_quests[0], &_quests[64]);

for (int i = 0; i < 85; ++i)
s.syncAsByte(_questItems[i]);

for (int i = 0; i < ITEMS_COUNT; ++i)
_blacksmithWeapons2[i].synchronize(s);
for (int i = 0; i < ITEMS_COUNT; ++i)
_blacksmithArmor2[i].synchronize(s);
for (int i = 0; i < ITEMS_COUNT; ++i)
_blacksmithAccessories2[i].synchronize(s);
for (int i = 0; i < ITEMS_COUNT; ++i)
_blacksmithMisc2[i].synchronize(s);

for (int i = 0; i < TOTAL_CHARACTERS; ++i)
SavesManager::syncBitFlags(s, &_characterFlags[i][0], &_characterFlags[i][24]);
s.syncBytes(&dummy[0], 30);
}

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

Conditions::Conditions() {
_cursed = 0;
_heartBroken = 0;
_weak = 0;
_poisoned = 0;
_diseased = 0;
_insane = 0;
_inLove = 0;
_drunk = 0;
_asleep = 0;
_depressed = 0;
_confused = 0;
_paralyzed = 0;
_unconscious = 0;
_dead = 0;
_stoned = 0;
_eradicated = 0;
}

void Conditions::synchronize(Common::Serializer &s) {
s.syncAsByte(_cursed);
s.syncAsByte(_heartBroken);
s.syncAsByte(_weak);
s.syncAsByte(_poisoned);
s.syncAsByte(_diseased);
s.syncAsByte(_insane);
s.syncAsByte(_inLove);
s.syncAsByte(_drunk);
s.syncAsByte(_asleep);
s.syncAsByte(_depressed);
s.syncAsByte(_confused);
s.syncAsByte(_paralyzed);
s.syncAsByte(_unconscious);
s.syncAsByte(_dead);
s.syncAsByte(_stoned);
s.syncAsByte(_eradicated);
}

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

PlayerStruct::PlayerStruct() {
_sex = MALE;
_race = HUMAN;
_xeenSide = 0;
_class = KNIGHT;
_ACTemp = 0;
_dbDay = 0;
_tempAge = 0;
Common::fill(&_skills[0], &_skills[18], 0);
Common::fill(&_awards[0], &_awards[512], false);
Common::fill(&_spells[9], &_spells[312], false);
_lloydMap = 0;
_hasSpells = false;
_currentSpell = 0;
_quickOption = 0;
_lloydSide = 0;
_townUnknown = 0;
_unknown2 = 0;
_currentHp = 0;
_currentSp = 0;
_ybDay = 0;
_experience = 0;
_currentAdventuringSpell = 0;
_currentCombatSpell = 0;
}

void PlayerStruct::synchronize(Common::Serializer &s) {
char name[16];
Common::fill(&name[0], &name[16], '\0');
strncpy(name, _name.c_str(), 16);
s.syncBytes((byte *)name, 16);

if (s.isLoading())
_name = Common::String(name);

s.syncAsByte(_sex);
s.syncAsByte(_race);
s.syncAsByte(_xeenSide);
s.syncAsByte(_class);

_might.synchronize(s);
_intellect.synchronize(s);
_personality.synchronize(s);
_endurance.synchronize(s);
_speed.synchronize(s);
_accuracy.synchronize(s);
_luck.synchronize(s);
s.syncAsByte(_ACTemp);
_level.synchronize(s);
s.syncAsByte(_dbDay);
s.syncAsByte(_tempAge);

for (int i = 0; i < 18; ++i)
s.syncAsByte(_skills[i]);
SavesManager::syncBitFlags(s, &_awards[0], &_awards[512]);
SavesManager::syncBitFlags(s, &_spells[0], &_spells[312]);

s.syncAsByte(_lloydMap);
s.syncAsByte(_lloydPosition.x);
s.syncAsByte(_lloydPosition.y);
s.syncAsByte(_hasSpells);
s.syncAsByte(_currentSpell);
s.syncAsByte(_quickOption);

for (int i = 0; i < 9; ++i)
_weapons[i].synchronize(s);
for (int i = 0; i < 9; ++i)
_armor[i].synchronize(s);
for (int i = 0; i < 9; ++i)
_accessories[i].synchronize(s);
for (int i = 0; i < 9; ++i)
_misc[i].synchronize(s);

s.syncAsByte(_lloydSide);
_fireResistence.synchronize(s);
_coldResistence.synchronize(s);
_electricityResistence.synchronize(s);
_poisonResistence.synchronize(s);
_energyResistence.synchronize(s);
_magicResistence.synchronize(s);

_conditions.synchronize(s);

s.syncAsUint16LE(_townUnknown);
s.syncAsByte(_unknown2);
s.syncAsUint16LE(_currentHp);
s.syncAsUint16LE(_currentSp);
s.syncAsUint16LE(_ybDay);
s.syncAsUint32LE(_experience);
s.syncAsByte(_currentAdventuringSpell);
s.syncAsByte(_currentCombatSpell);
}

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

void Roster::synchronize(Common::Serializer &s) {
if (s.isLoading())
resize(30);

for (uint i = 0; i < 30; ++i)
(*this)[i].synchronize(s);
}

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

/**
* Synchronizes a boolean array as a bitfield set
*/
Expand Down
18 changes: 13 additions & 5 deletions engines/xeen/saves.h
Expand Up @@ -25,21 +25,29 @@

#include "common/scummsys.h"
#include "common/savefile.h"
#include "graphics/surface.h"
#include "xeen/party.h"

namespace Xeen {

struct XeenSavegameHeader {
uint8 _version;
Common::String _saveName;
Graphics::Surface *_thumbnail;
int _year, _month, _day;
int _hour, _minute;
int _totalFrames;
};

class SavesManager {
private:
XeenEngine *_vm;
public:
Party _party;
Roster _roster;
Party &_party;
Roster &_roster;
public:
static void syncBitFlags(Common::Serializer &s, bool *startP, bool *endP);
public:
SavesManager(XeenEngine *vm) : _vm(vm) {}

SavesManager(XeenEngine *vm, Party &party, Roster &roster);
void reset();
};

Expand Down
9 changes: 6 additions & 3 deletions engines/xeen/xeen.cpp
Expand Up @@ -42,6 +42,7 @@ XeenEngine::XeenEngine(OSystem *syst, const XeenGameDescription *gameDesc)
_sound = nullptr;
_eventData = nullptr;
Common::fill(&_activeRoster[0], &_activeRoster[MAX_ACTIVE_PARTY], nullptr);
_isEarlyGame = false;
}

XeenEngine::~XeenEngine() {
Expand All @@ -64,7 +65,7 @@ void XeenEngine::initialize() {
FileManager::init(this);
_debugger = new Debugger(this);
_events = new EventsManager(this);
_saves = new SavesManager(this);
_saves = new SavesManager(this, _party, _roster);
_screen = new Screen(this);
_screen->setupWindows();
_sound = new SoundManager(this);
Expand Down Expand Up @@ -254,9 +255,11 @@ void XeenEngine::drawUI() {

// Get mappings to the active characters in the party
Common::fill(&_activeRoster[0], &_activeRoster[MAX_ACTIVE_PARTY], nullptr);
for (int i = 0; i < _saves->_party._partyCount; ++i) {
_activeRoster[i] = &_saves->_roster[_saves->_party._partyMembers[i]];
for (int i = 0; i < _party._partyCount; ++i) {
_activeRoster[i] = &_roster[_party._partyMembers[i]];
}

_isEarlyGame = _party._minutes >= 300;
}

} // End of namespace Xeen

0 comments on commit 9a8cb48

Please sign in to comment.