Skip to content

Commit

Permalink
WAGE: Implement performAttack()
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Feb 14, 2016
1 parent 6c205ad commit c76b7ec
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
60 changes: 59 additions & 1 deletion engines/wage/combat.cpp
Expand Up @@ -177,8 +177,66 @@ void WageEngine::performCombatAction(Chr *npc, Chr *player) {
delete magics;
}

const char *targets[] = { "head", "chest", "side" };

void WageEngine::performAttack(Chr *attacker, Chr *victim, Obj *weapon) {
warning("STUB: performAttack()");
if (_world->_weaponMenuDisabled)
return;

// TODO: verify that a player not aiming will always target the chest??
int targetIndex = -1;
char buf[256];

if (weapon->_type != Obj::MAGICAL_OBJECT) {
if (attacker->_playerCharacter) {
targetIndex = _aim;
} else {
targetIndex = _rnd->getRandomNumber(ARRAYSIZE(targets) - 1);
_opponentAim = targetIndex + 1;
}

if (!attacker->_playerCharacter) {
snprintf(buf, 256, "%s%s %ss %s%s at %s%s's %s.",
attacker->getDefiniteArticle(true), attacker->_name.c_str(),
weapon->_operativeVerb.c_str(),
prependGenderSpecificPronoun(attacker->_gender), weapon->_name.c_str(),
victim->getDefiniteArticle(true), victim->_name.c_str(),
targets[targetIndex]);
appendText(buf);
}
} else if (!attacker->_playerCharacter) {
snprintf(buf, 256, "%s%s %ss %s%s at %s%s.",
attacker->getDefiniteArticle(true), attacker->_name.c_str(),
weapon->_operativeVerb.c_str(),
prependGenderSpecificPronoun(attacker->_gender), weapon->_name.c_str(),
victim->getDefiniteArticle(true), victim->_name.c_str());
appendText(buf);
}

playSound(weapon->_sound);

bool usesDecremented = false;
int chance = _rnd->getRandomNumber(255);
// TODO: what about obj accuracy
if (chance < attacker->_physicalAccuracy) {
usesDecremented = attackHit(attacker, victim, weapon, targetIndex);
} else if (weapon->_type != Obj::MAGICAL_OBJECT) {
appendText((char *)"A miss!");
} else if (attacker->_playerCharacter) {
appendText((char *)"The spell has no effect.");
}

if (!usesDecremented) {
decrementUses(weapon);
}
}

void WageEngine::decrementUses(Obj *obj) {
warning("STUB: decrementUses()");
}

bool WageEngine::attackHit(Chr *attacker, Chr *victim, Obj *weapon, int targetIndex) {
warning("STUB: attackHit");
}

void WageEngine::performMagic(Chr *attacker, Chr *victim, Obj *magicalObject) {
Expand Down
1 change: 1 addition & 0 deletions engines/wage/wage.cpp
Expand Up @@ -64,6 +64,7 @@ WageEngine::WageEngine(OSystem *syst, const ADGameDescription *desc) : Engine(sy
_rnd = new Common::RandomSource("wage");

_aim = -1;
_opponentAim = -1;
_temporarilyHidden = false;
_isGameOver = false;
_monster = NULL;
Expand Down
3 changes: 3 additions & 0 deletions engines/wage/wage.h
Expand Up @@ -135,6 +135,8 @@ class WageEngine : public Engine {
void performMove(Chr *chr, int validMoves);
void performOffer(Chr *attacker, Chr *victim);
void performTake(Chr *npc, Obj *obj);
void decrementUses(Obj *obj);
bool attackHit(Chr *attacker, Chr *victim, Obj *weapon, int targetIndex);

void doClose();

Expand All @@ -151,6 +153,7 @@ class WageEngine : public Engine {
Chr *_running;
Obj *_offer;
int _aim;
int _opponentAim;
bool _temporarilyHidden;
bool _isGameOver;
bool _commandWasQuick;
Expand Down

0 comments on commit c76b7ec

Please sign in to comment.