Skip to content

Commit

Permalink
XEEN: Add invincible debugger command
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jan 20, 2018
1 parent 1bff4cf commit a837733
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
15 changes: 13 additions & 2 deletions engines/xeen/character.cpp
Expand Up @@ -1287,7 +1287,7 @@ void Character::setValue(int id, uint value) {
// Set condition
if (value == 16) {
// Clear all the conditions
Common::fill(&_conditions[CURSED], &_conditions[NO_CONDITION], false);
clearConditions();
} else if (value == 6) {
_conditions[value] = 1;
} else {
Expand Down Expand Up @@ -1785,7 +1785,14 @@ void Character::addHitPoints(int amount) {
}

void Character::subtractHitPoints(int amount) {
Sound &sound = *Party::_vm->_sound;
Debugger &debugger = *g_vm->_debugger;
Sound &sound = *g_vm->_sound;

// If invincibility is turned on in the debugger, ignore all damage
if (debugger._invincible)
return;

// Subtract the given HP amount
_currentHp -= amount;
bool flag = _currentHp <= 10;

Expand Down Expand Up @@ -1847,4 +1854,8 @@ int Character::getClassCategory() const {
}
}

void Character::clearConditions() {
Common::fill(&_conditions[CURSED], &_conditions[NO_CONDITION], false);
}

} // End of namespace Xeen
5 changes: 5 additions & 0 deletions engines/xeen/character.h
Expand Up @@ -529,6 +529,11 @@ class Character {
* Returns a category index for a character, used such for indexing into spell data
*/
int getClassCategory() const;

/**
* Clears the character of any currently set conditions
*/
void clearConditions();
};

} // End of namespace Xeen
Expand Down
8 changes: 7 additions & 1 deletion engines/xeen/combat.cpp
Expand Up @@ -267,6 +267,7 @@ void Combat::giveCharDamage(int damage, DamageType attackType, int charIndex) {
}

void Combat::doCharDamage(Character &c, int charNum, int monsterDataIndex) {
Debugger &debugger = *g_vm->_debugger;
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Map &map = *_vm->_map;
Expand Down Expand Up @@ -434,7 +435,12 @@ void Combat::doCharDamage(Character &c, int charNum, int monsterDataIndex) {
break;
}

c.subtractHitPoints(damage);
if (debugger._invincible)
// Invincibility mode is on, so reset conditions that were set
c.clearConditions();
else
// Standard gameplay, deal out the damage
c.subtractHitPoints(damage);
}

events.ipause(2);
Expand Down
10 changes: 9 additions & 1 deletion engines/xeen/debugger.cpp
Expand Up @@ -44,7 +44,8 @@ static int strToInt(const char *s) {

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

Debugger::Debugger(XeenEngine *vm) : GUI::Debugger(), _vm(vm) {
Debugger::Debugger(XeenEngine *vm) : GUI::Debugger(), _vm(vm),
_invincible(false) {
registerCmd("continue", WRAP_METHOD(Debugger, cmdExit));
registerCmd("spell", WRAP_METHOD(Debugger, cmdSpell));
registerCmd("spells", WRAP_METHOD(Debugger, cmdSpells));
Expand All @@ -53,6 +54,7 @@ Debugger::Debugger(XeenEngine *vm) : GUI::Debugger(), _vm(vm) {
registerCmd("gems", WRAP_METHOD(Debugger, cmdGems));
registerCmd("map", WRAP_METHOD(Debugger, cmdMap));
registerCmd("pos", WRAP_METHOD(Debugger, cmdPos));
registerCmd("invincible", WRAP_METHOD(Debugger, cmdInvincible));

This comment has been minimized.

Copy link
@sev-

sev- Jan 21, 2018

Member

iddqd


_spellId = -1;
}
Expand Down Expand Up @@ -192,4 +194,10 @@ bool Debugger::cmdPos(int argc, const char **argv) {
}
}

bool Debugger::cmdInvincible(int argc, const char **argv) {
_invincible = (argc < 2) || strcmp(argv[1], "off");
debugPrintf("Invincibility is %s\n", _invincible ? "on" : "off");
return true;
}

} // End of namespace Xeen
7 changes: 7 additions & 0 deletions engines/xeen/debugger.h
Expand Up @@ -69,6 +69,13 @@ class Debugger : public GUI::Debugger {
* Changes the party's position in the current map
*/
bool cmdPos(int argc, const char **argv);

/**
* Flags whether to make the party invincible
*/
bool cmdInvincible(int argc, const char **argv);
public:
bool _invincible;
public:
Debugger(XeenEngine *vm);

Expand Down

0 comments on commit a837733

Please sign in to comment.