Skip to content

Commit

Permalink
XEEN: Implemented giveExt method
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Dec 29, 2017
1 parent e28f2a7 commit 47d95c6
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 6 deletions.
105 changes: 102 additions & 3 deletions engines/xeen/party.cpp
Expand Up @@ -1391,9 +1391,108 @@ bool Party::giveTake(int takeMode, uint takeVal, int giveMode, uint giveVal, int
return false;
}

bool Party::giveTakeExt(int takeMode, uint takeVal, int giveMode, uint giveVal, int extMode, uint extVal, int charIdx) {
// TODO
return true;
bool Party::giveExt(int mode1, uint val1, int mode2, uint val2, int mode3, uint val3, int charId) {
Combat &combat = *g_vm->_combat;
FileManager &files = *g_vm->_files;
Interface &intf = *g_vm->_interface;
Map &map = *g_vm->_map;
Party &party = *g_vm->_party;
Scripts &scripts = *g_vm->_scripts;
Sound &sound = *g_vm->_sound;
Character &c = party._activeParty[charId];
int var1 = 0;
bool retFlag = false;

if (intf._objNumber && !scripts._animCounter) {
MazeObject &obj = map._mobData._objects[intf._objNumber - 1];
switch (obj._spriteId) {
case 15:
if (!files._isDarkCc)
break;
// Intentional fall-through

case 16:
case 58:
case 73:
obj._frame = 1;

if (obj._position.x != 20) {
if (g_vm->getRandomNumber(1, 4) == 1) {
combat.giveCharDamage(map.mazeData()._trapDamage,
(DamageType)_vm->getRandomNumber(0, 6), charId);
}

int unlockBox = map.mazeData()._difficulties._unlockBox;
if ((c.getThievery() + _vm->getRandomNumber(1, 20)) >= unlockBox) {
scripts._animCounter++;
g_vm->_mode = MODE_7;
c._experience += c.getCurrentLevel() * unlockBox * 10;

intf.draw3d(true, false);
Common::String msg = Common::String::format(Res.PICKS_THE_LOCK, c._name.c_str());
ErrorScroll::show(g_vm, msg);
} else {
sound.playFX(21);

obj._frame = 0;
scripts._animCounter = 0;
Common::String msg = Common::String::format(Res.UNABLE_TO_PICK_LOCK, c._name.c_str());
ErrorScroll::show(g_vm, msg);

scripts._animCounter = 255;
return true;
}
}
}
}

for (int paramCtr = 0; paramCtr < 3; ++paramCtr) {
int mode = (paramCtr == 0) ? mode1 : (paramCtr == 1 ? mode2 : mode3);
int val = (paramCtr == 0) ? val1 : (paramCtr == 1 ? val2 : val3);

switch (mode) {
case 34:
party._treasure._gold += val;
break;

case 35:
party._treasure._gems += val;
break;

case 66:
c = _itemsCharacter;
c.clear();

if (giveTake(0, 0, mode, val, charId))
return true;
break;

case 100:
_treasure._gold += g_vm->getRandomNumber(1, val);
break;

case 101:
_treasure._gems += g_vm->getRandomNumber(1, val);
break;

case 106:
party._food += g_vm->getRandomNumber(1, val);
break;

case 67:
retFlag = true;
// Intentional fall-through

default:
if (giveTake(0, 0, mode, val, charId))
return true;
else if (retFlag)
return false;
break;
}
}

return false;
}

int Party::howMuch() {
Expand Down
4 changes: 2 additions & 2 deletions engines/xeen/party.h
Expand Up @@ -227,9 +227,9 @@ class Party {
bool giveTake(int takeMode, uint takeVal, int giveMode, uint giveVal, int charIdx);

/**
* Gives and/or takes amounts from various character and/or party properties
* Gives up to three different item/amounts to various character and/or party properties
*/
bool giveTakeExt(int takeMode, uint takeVal, int giveMode, uint giveVal, int extMode, uint extVal, int charIdx);
bool giveExt(int mode1, uint val1, int mode2, uint val2, int mode3, uint val3, int charId);

/**
* Resets the inventory that Blacksmiths sell
Expand Down
4 changes: 4 additions & 0 deletions engines/xeen/resources.cpp
Expand Up @@ -1668,4 +1668,8 @@ const char *const Resources::WARZONE_LEVEL = "What level of monsters? (1-10)\n";

const char *const Resources::WARZONE_HOW_MANY = "How many monsters? (1-20)\n";

const char *const Resources::PICKS_THE_LOCK = "\x3""c\xB""010%s picks the lock!\nPress any key.";

const char *const Resources::UNABLE_TO_PICK_LOCK = "\x3""c\v010%s was unable to pick the lock!\nPress any key.";

} // End of namespace Xeen
2 changes: 2 additions & 0 deletions engines/xeen/resources.h
Expand Up @@ -351,6 +351,8 @@ class Resources {
static const char *const WARZONE_MAXED;
static const char *const WARZONE_LEVEL;
static const char *const WARZONE_HOW_MANY;
static const char *const PICKS_THE_LOCK;
static const char *const UNABLE_TO_PICK_LOCK;
public:
/**
* Initializes an instnace of the resources
Expand Down
2 changes: 1 addition & 1 deletion engines/xeen/scripts.cpp
Expand Up @@ -932,7 +932,7 @@ bool Scripts::cmdGiveExtended(ParamsIterator &params) {
}

_scriptExecuted = true;
bool result = party.giveTakeExt(mode1, val1, mode2, val2, mode3, val3,
bool result = party.giveExt(mode1, val1, mode2, val2, mode3, val3,
(_charIndex > 0) ? _charIndex - 1 : 0);

if (result) {
Expand Down

0 comments on commit 47d95c6

Please sign in to comment.