From 82d002629841841500506dc22f8a9b83731ba863 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 8 Jan 2016 22:12:47 +0100 Subject: WAGE: Started implementation of performCombatAction() --- engines/wage/entities.cpp | 10 +++++- engines/wage/entities.h | 67 +++-------------------------------------- engines/wage/module.mk | 1 + engines/wage/script.cpp | 2 +- engines/wage/wage.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++ engines/wage/wage.h | 1 + 6 files changed, 94 insertions(+), 64 deletions(-) diff --git a/engines/wage/entities.cpp b/engines/wage/entities.cpp index f24eea2673..753084ebe6 100644 --- a/engines/wage/entities.cpp +++ b/engines/wage/entities.cpp @@ -378,7 +378,7 @@ void Chr::resetState() { _context._statVariables[PHYS_SPE_BAS] = _context._statVariables[PHYS_SPE_CUR] = _runningSpeed; } -WeaponArray *Chr::getWeapons() { +WeaponArray *Chr::getWeapons(bool includeMagic) { WeaponArray *list = new WeaponArray; warning("STUB: getWeapons"); @@ -386,6 +386,14 @@ WeaponArray *Chr::getWeapons() { return list; } +ObjArray *Chr::getMagicalObjects() { + ObjArray *list = new ObjArray; + + warning("STUB: getMagicalObjects"); + + return list; +} + void Chr::wearObjs() { for (uint i = 0; i < _inventory.size(); i++) wearObjIfPossible(_inventory[i]); diff --git a/engines/wage/entities.h b/engines/wage/entities.h index ba190860ad..4cf756a64e 100644 --- a/engines/wage/entities.h +++ b/engines/wage/entities.h @@ -61,6 +61,9 @@ class Script; class Weapon; typedef Common::Array WeaponArray; +typedef Common::Array ObjArray; +typedef Common::Array ChrArray; +typedef Common::List ObjList; enum StatVariable { /** The base physical accuracy of the player. */ @@ -215,71 +218,11 @@ public: Context _context; - WeaponArray *getWeapons(); + WeaponArray *getWeapons(bool includeMagic); + ObjArray *getMagicalObjects(); String &getNameWithDefiniteArticle(bool capitalize); public: -#if 0 - Weapon[] getWeapons() { - ArrayList weapons = new ArrayList(); - if (hasNativeWeapon1()) { - weapons.add(new Weapon() { - String getName() { - return _getNativeWeapon1(); - } - String getOperativeVerb() { - return _getOperativeVerb1(); - } - int getType() { - return _Obj.REGULAR_WEAPON; - } - int getAccuracy() { - return _0; - } - int getDamage() { - return _getWeaponDamage1(); - } - String getSound() { - return _getWeaponSound1(); - } - void decrementNumberOfUses() {} - }); - } - if (hasNativeWeapon2()) { - weapons.add(new Weapon() { - String getName() { - return _getNativeWeapon2(); - } - String getOperativeVerb() { - return _getOperativeVerb2(); - } - int getType() { - return _Obj.REGULAR_WEAPON; - } - int getAccuracy() { - return _0; - } - int getDamage() { - return _getWeaponDamage2(); - } - String getSound() { - return _getWeaponSound2(); - } - void decrementNumberOfUses() {} - }); - } - for (Obj o : getInventory()) { - switch (o.getType()) { - case Obj.REGULAR_WEAPON: - case Obj.THROW_WEAPON: - case Obj.MAGICAL_OBJECT: - weapons.add(o); - } - } - return _(Weapon[]) weapons.toArray(new Weapon[0]); - } -#endif - bool hasNativeWeapon1() { return (_nativeWeapon1.size() > 0 && _operativeVerb1.size() > 0); } diff --git a/engines/wage/module.mk b/engines/wage/module.mk index 5356902474..216ac528fa 100644 --- a/engines/wage/module.mk +++ b/engines/wage/module.mk @@ -5,6 +5,7 @@ MODULE_OBJS := \ detection.o \ entities.o \ gui.o \ + randomhat.o \ script.o \ util.o \ wage.o \ diff --git a/engines/wage/script.cpp b/engines/wage/script.cpp index 4fdbddb501..71c75d9b40 100644 --- a/engines/wage/script.cpp +++ b/engines/wage/script.cpp @@ -199,7 +199,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i handleAcceptCommand(); } else { Chr *player = _world->_player; - WeaponArray *weapons = player->getWeapons(); + WeaponArray *weapons = player->getWeapons(true); for (WeaponArray::const_iterator weapon = weapons->begin(); weapon != weapons->end(); ++weapon) { if (tryAttack(*weapon, input)) { handleAttack(*weapon); diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp index d87a7c1413..8b7f4ff212 100644 --- a/engines/wage/wage.cpp +++ b/engines/wage/wage.cpp @@ -399,6 +399,83 @@ void WageEngine::encounter(Chr *player, Chr *chr) { void WageEngine::performCombatAction(Chr *npc, Chr *player) { warning("STUB WageEngine::performCombatAction()"); +#if 0 + if (npc->_frozen) + return; + + RandomHat hat; + + bool winning = (npc->_context._statVariables[PHYS_HIT_CUR] > player->_context._statVariables[PHYS_HIT_CUR]); + int validMoves = getValidMoveDirections(npc); + WeaponArray *weapons = npc->getWeapons(false); + ObjArray *magics = npc->getMagicalObjects(); + // TODO: Figure out under what circumstances we need to add +1 + // for the chance (e.g. only when all values were set to 0?). + if (winning) { + if (!_world->_weaponsMenuDisabled) { + if (weapons->size() > 0) + hat.addTokens(kTokWeapons, npc->_winningWeapons + 1); + if (magics->size() > 0) + hat.addTokens(kTokMagic, npc->_winningMagic); + } + if (validMoves != 0) + hat.addTokens(kTokRun, npc->_winningRun + 1); + if (npc->_inventory.size()) + hat.addTokens(kTokOffer, npc->_winningOffer + 1); + } else { + if (!_world->_weaponsMenuDisabled) { + if (npc.getWeapons(false).length > 0) + hat.addTokens(kTokWeapons, npc->_losingWeapons + 1); + if (magics->size() > 0) + hat.addTokens(kTokMagic, npc->_losingMagic); + } + if (validMoves != 0) + hat.addTokens(kTokRun, npc->_losingRun + 1); + if (npc->_inventory.size()) + hat.addTokens(kTokOffer, npc->_losingOffer + 1); + } + + ObjArray *objs = npc->_currentScene->_objs; + if (npc->_inventory.size() < npc->_maximumCarriedObjects) { + int cnt = 0; + for (ObjList::const_iterator it = objs.begin(); it != objs.end(); ++it, ++cnt) { + if ((*it)->_type != Obj::IMMOBILE_OBJECT) { + // TODO: I'm not sure what the chance should be here. + hat.addTokens(cnt, 123); + } + } + } + + int token = hat.drawToken(); + switch (token) { + case kTokWeapons: + // TODO: I think the monster should choose the "best" weapon. + performAttack(npc, player, weapons[_rnd.getRandomNumber(weapons->size() - 1)]); + break; + case kTokMagic: + // TODO: I think the monster should choose the "best" magic. + performMagic(npc, player, magics[_rnd.getRandomNumber(magics->size() - 1)]); + break; + case kTokRun: + performMove(npc, validMoves); + break; + case kTokOffer: + performOffer(npc, player); + break; + default: + performTake(npc, objs.get(token)); + break; + } + + delete weapons; + delete magics; +#endif +} + +int WageEngine::getValidMoveDirections(Chr *npc) { + warning("STUB: getValidMoveDirections()"); + + return 0; } void WageEngine::redrawScene() { diff --git a/engines/wage/wage.h b/engines/wage/wage.h index bbf3b991ab..6fb287cad4 100644 --- a/engines/wage/wage.h +++ b/engines/wage/wage.h @@ -127,6 +127,7 @@ private: void processTurnInternal(Common::String *textInput, Designed *clickInput); void regen(); void performCombatAction(Chr *npc, Chr *player); + int getValidMoveDirections(Chr *npc); public: Common::RandomSource *_rnd; -- cgit v1.2.3