Skip to content

Commit

Permalink
XEEN: Starting of combat UI, moved _combatParty into Combat class
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Feb 16, 2015
1 parent e7ffed7 commit 30d9495
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 30 deletions.
12 changes: 4 additions & 8 deletions engines/xeen/combat.cpp
Expand Up @@ -22,6 +22,7 @@

#include "common/algorithm.h"
#include "common/rect.h"
#include "xeen/character.h"
#include "xeen/combat.h"
#include "xeen/interface.h"
#include "xeen/xeen.h"
Expand Down Expand Up @@ -94,16 +95,13 @@ Combat::Combat(XeenEngine *vm): _vm(vm) {
_whosTurn = -1;
_itemFlag = false;
_monstersAttacking = false;
_combatMode = 0;
}

void Combat::clear() {
Common::fill(&_attackMonsters[0], &_attackMonsters[26], -1);
}

void Combat::doCombat() {
error("TODO: doCombat");
}

void Combat::giveCharDamage(int damage, DamageType attackType, int charIndex) {
Party &party = *_vm->_party;
Screen &screen = *_vm->_screen;
Expand Down Expand Up @@ -414,9 +412,9 @@ void Combat::monstersAttack() {
if (_vm->_mode != MODE_COMBAT) {
// Combat wasn't previously active, but it is now. Set up
// the combat party from the currently active party
party._combatParty.clear();
_combatParty.clear();
for (uint idx = 0; idx < party._activeParty.size(); ++idx)
party._combatParty.push_back(&party._activeParty[idx]);
_combatParty.push_back(&party._activeParty[idx]);
}

for (int idx = 0; idx < 36; ++idx) {
Expand Down Expand Up @@ -523,8 +521,6 @@ void Combat::endAttack() {
OutdoorDrawList &outdoorList = intf._outdoorList;

for (uint idx = 0; idx < party._activeParty.size(); ++idx) {
Character &c = party._activeParty[idx];

if (map._isOutdoors) {
outdoorList._attackImgs1[idx]._scale = 0;
outdoorList._attackImgs2[idx]._scale = 0;
Expand Down
7 changes: 5 additions & 2 deletions engines/xeen/combat.h
Expand Up @@ -50,11 +50,15 @@ enum SpecialAttack {
};

class XeenEngine;
class Character;

class Combat {
private:
XeenEngine *_vm;
public:
Common::Array<Character *> _combatParty;
Common::Array<int> _charsBlocked;
Common::Array<int> _charsGone;
SpriteResource _powSprites;
int _attackMonsters[26];
int _charsArray1[12];
Expand All @@ -71,6 +75,7 @@ class Combat {
bool _rangeAttacking[MAX_NUM_MONSTERS];
int _gmonHit[36];
bool _monstersAttacking;
int _combatMode;

void monstersAttack();

Expand All @@ -93,8 +98,6 @@ class Combat {

void clear();

void doCombat();

void giveCharDamage(int damage, DamageType attackType, int charIndex);

void moveMonsters();
Expand Down
11 changes: 6 additions & 5 deletions engines/xeen/dialogs_char_info.cpp
Expand Up @@ -36,18 +36,19 @@ void CharacterInfo::show(XeenEngine *vm, int charIndex) {
}

void CharacterInfo::execute(int charIndex) {
Screen &screen = *_vm->_screen;
Combat &combat = *_vm->_combat;
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Party &party = *_vm->_party;

Screen &screen = *_vm->_screen;

bool redrawFlag = true;
Mode oldMode = _vm->_mode;
_vm->_mode = MODE_CHARACTER_INFO;
loadDrawStructs();
addButtons();

Character *c = (oldMode != MODE_COMBAT) ? &party._activeParty[charIndex] : party._combatParty[charIndex];
Character *c = (oldMode != MODE_COMBAT) ? &party._activeParty[charIndex] : combat._combatParty[charIndex];
intf.highlightChar(charIndex);
Window &w = screen._windows[24];
w.open();
Expand Down Expand Up @@ -86,9 +87,9 @@ void CharacterInfo::execute(int charIndex) {
case Common::KEYCODE_F5:
case Common::KEYCODE_F6:
_buttonValue -= Common::KEYCODE_F1;
if (_buttonValue < (int)(oldMode == MODE_COMBAT ? party._combatParty.size() : party._activeParty.size())) {
if (_buttonValue < (int)(oldMode == MODE_COMBAT ? combat._combatParty.size() : party._activeParty.size())) {
charIndex = _buttonValue;
c = (oldMode != MODE_COMBAT) ? &party._activeParty[charIndex] : party._combatParty[charIndex];
c = (oldMode != MODE_COMBAT) ? &party._activeParty[charIndex] : combat._combatParty[charIndex];
} else {
_vm->_mode = MODE_CHARACTER_INFO;
}
Expand Down
5 changes: 3 additions & 2 deletions engines/xeen/dialogs_items.cpp
Expand Up @@ -37,6 +37,7 @@ Character *ItemsDialog::show(XeenEngine *vm, Character *c, ItemsMode mode) {
}

Character *ItemsDialog::execute(Character *c, ItemsMode mode) {
Combat &combat = *_vm->_combat;
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Party &party = *_vm->_party;
Expand Down Expand Up @@ -337,11 +338,11 @@ Character *ItemsDialog::execute(Character *c, ItemsMode mode) {
_buttonValue -= Common::KEYCODE_F1;

if (_buttonValue < (int)(_vm->_mode == MODE_COMBAT ?
party._combatParty.size() : party._activeParty.size())) {
combat._combatParty.size() : party._activeParty.size())) {
// Character number is valid
redrawFlag = REDRAW_TEXT;
Character *newChar = _vm->_mode == MODE_COMBAT ?
party._combatParty[_buttonValue] : &party._activeParty[_buttonValue];
combat._combatParty[_buttonValue] : &party._activeParty[_buttonValue];

if (mode == ITEMMODE_BLACKSMITH) {
_oldCharacter = newChar;
Expand Down
4 changes: 2 additions & 2 deletions engines/xeen/dialogs_quick_ref.cpp
Expand Up @@ -41,9 +41,9 @@ void QuickReferenceDialog::execute() {

events.setCursor(0);

for (uint idx = 0; idx < (combat._globalCombat == 2 ? party._combatParty.size() :
for (uint idx = 0; idx < (combat._globalCombat == 2 ? combat._combatParty.size() :
party._activeParty.size()); ++idx) {
Character &c = combat._globalCombat == 2 ? *party._combatParty[idx] :
Character &c = combat._globalCombat == 2 ? *combat._combatParty[idx] :
party._activeParty[idx];
Condition condition = c.worstCondition();
lines[idx] = Common::String::format(QUICK_REF_LINE,
Expand Down
47 changes: 42 additions & 5 deletions engines/xeen/interface.cpp
Expand Up @@ -43,16 +43,17 @@ PartyDrawer::PartyDrawer(XeenEngine *vm): _vm(vm) {
}

void PartyDrawer::drawParty(bool updateFlag) {
Combat &combat = *_vm->_combat;
Party &party = *_vm->_party;
Resources &res = *_vm->_resources;
Screen &screen = *_vm->_screen;
bool inCombat = _vm->_mode == MODE_COMBAT;
_restoreSprites.draw(screen, 0, Common::Point(8, 149));

// Handle drawing the party faces
uint partyCount = inCombat ? party._combatParty.size() : party._activeParty.size();
uint partyCount = inCombat ? combat._combatParty.size() : party._activeParty.size();
for (uint idx = 0; idx < partyCount; ++idx) {
Character &ps = inCombat ? *party._combatParty[idx] : party._activeParty[idx];
Character &ps = inCombat ? *combat._combatParty[idx] : party._activeParty[idx];
Condition charCondition = ps.worstCondition();
int charFrame = FACE_CONDITION_FRAMES[charCondition];

Expand All @@ -64,7 +65,7 @@ void PartyDrawer::drawParty(bool updateFlag) {
}

for (uint idx = 0; idx < partyCount; ++idx) {
Character &ps = inCombat ? *party._combatParty[idx] : party._activeParty[idx];
Character &ps = inCombat ? *combat._combatParty[idx] : party._activeParty[idx];

// Draw the Hp bar
int maxHp = ps.getMaxHP();
Expand Down Expand Up @@ -212,7 +213,7 @@ void Interface::mainIconsPrint() {
screen._windows[34].update();
}

void Interface::setMainButtons() {
void Interface::setMainButtons(bool combatMode) {
clearButtons();

addButton(Common::Rect(235, 75, 259, 95), Common::KEYCODE_s, &_iconSprites);
Expand All @@ -236,6 +237,18 @@ void Interface::setMainButtons() {
addButton(Common::Rect(239, 37, 312, 47), Common::KEYCODE_2, &_iconSprites, false);
addButton(Common::Rect(239, 47, 312, 57), Common::KEYCODE_3, &_iconSprites, false);
addPartyButtons(_vm);

if (combatMode) {
_buttons[0]._value = Common::KEYCODE_f;
_buttons[1]._value = Common::KEYCODE_c;
_buttons[2]._value = Common::KEYCODE_a;
_buttons[3]._value = Common::KEYCODE_u;
_buttons[4]._value = Common::KEYCODE_r;
_buttons[5]._value = Common::KEYCODE_b;
_buttons[6]._value = Common::KEYCODE_o;
_buttons[7]._value = Common::KEYCODE_i;
_buttons[16]._value = 0;
}
}

/**
Expand Down Expand Up @@ -1215,7 +1228,7 @@ void Interface::draw3d(bool updateFlag) {
|| combat._attackMonsters[2] != -1) {
if ((_vm->_mode == MODE_1 || _vm->_mode == MODE_SLEEPING) &&
!combat._monstersAttacking && !_charsShooting && _vm->_moveMonsters) {
combat.doCombat();
doCombat();
if (scripts._eventSkipped)
scripts.checkEvents();
}
Expand Down Expand Up @@ -1795,4 +1808,28 @@ void Interface::assembleBorder() {
screen._windows[12].frame();
}

void Interface::doCombat() {
Combat &combat = *_vm->_combat;
EventsManager &events = *_vm->_events;
Screen &screen = *_vm->_screen;
bool isDarkCc = _vm->_files->_isDarkCc;
bool upDoorText = _upDoorText;

_upDoorText = false;
combat._combatMode = 2;
_vm->_mode = MODE_COMBAT;

_iconSprites.load("combat.icn");
for (int idx = 1; idx < 16; ++idx)
_mainList[idx]._sprites = nullptr;

// Set the combat buttons
setMainButtons(true);
mainIconsPrint();



error("TODO");
}

} // End of namespace Xeen
4 changes: 3 additions & 1 deletion engines/xeen/interface.h
Expand Up @@ -84,7 +84,7 @@ class Interface: public ButtonContainer, public InterfaceMap, public PartyDrawer

void setupBackground();

void setMainButtons();
void setMainButtons(bool combatMode = false);

void chargeStep();

Expand Down Expand Up @@ -139,6 +139,8 @@ class Interface: public ButtonContainer, public InterfaceMap, public PartyDrawer
void draw3d(bool updateFlag);

void assembleBorder();

void doCombat();
};

} // End of namespace Xeen
Expand Down
6 changes: 3 additions & 3 deletions engines/xeen/party.cpp
Expand Up @@ -105,7 +105,6 @@ Party::Party(XeenEngine *vm) {
for (int i = 0; i < TOTAL_CHARACTERS; ++i)
Common::fill(&_characterFlags[i][0], &_characterFlags[i][24], false);

_combatPartyCount = 0;
_partyDead = false;
_newDay = false;
_isNight = false;
Expand Down Expand Up @@ -531,10 +530,11 @@ void Party::notEnough(int consumableId, int whereId, bool mode, ErrorWaitType wa
}

void Party::checkPartyDead() {
Combat &combat = *_vm->_combat;
bool inCombat = _vm->_mode == MODE_COMBAT;

for (uint charIdx = 0; charIdx < (inCombat ? _combatParty.size() : _activeParty.size()); ++charIdx) {
Character &c = inCombat ? *_combatParty[charIdx] : _activeParty[charIdx];
for (uint charIdx = 0; charIdx < (inCombat ? combat._combatParty.size() : _activeParty.size()); ++charIdx) {
Character &c = inCombat ? *combat._combatParty[charIdx] : _activeParty[charIdx];
Condition cond = c.worstCondition();
if (cond <= CONFUSED || cond == NO_CONDITION) {
_dead = false;
Expand Down
2 changes: 0 additions & 2 deletions engines/xeen/party.h
Expand Up @@ -115,8 +115,6 @@ class Party {
// Other party related runtime data
Roster _roster;
Common::Array<Character> _activeParty;
Common::Array<Character *> _combatParty;
int _combatPartyCount;
bool _partyDead;
bool _newDay;
bool _isNight;
Expand Down

0 comments on commit 30d9495

Please sign in to comment.