aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2016-01-27 20:46:11 +0100
committerEugene Sandulenko2016-02-14 17:12:54 +0100
commite22626529489301ecb0298c7dcf06a40c8b36d99 (patch)
tree542fbb8bf1701a2f5a778f0d56ac5c59c0470597
parentf813c0e556883254e9b9e2275535c4e7fc0859dc (diff)
downloadscummvm-rg350-e22626529489301ecb0298c7dcf06a40c8b36d99.tar.gz
scummvm-rg350-e22626529489301ecb0298c7dcf06a40c8b36d99.tar.bz2
scummvm-rg350-e22626529489301ecb0298c7dcf06a40c8b36d99.zip
WAGE: Implement attackHit()
-rw-r--r--engines/wage/combat.cpp89
1 files changed, 87 insertions, 2 deletions
diff --git a/engines/wage/combat.cpp b/engines/wage/combat.cpp
index f769e17312..6864805273 100644
--- a/engines/wage/combat.cpp
+++ b/engines/wage/combat.cpp
@@ -252,9 +252,94 @@ void WageEngine::decrementUses(Obj *obj) {
}
bool WageEngine::attackHit(Chr *attacker, Chr *victim, Obj *weapon, int targetIndex) {
- warning("STUB: attackHit");
+ bool receivedHitTextPrinted = false;
+ char buf[512];
- return false;
+ if (targetIndex != -1) {
+ Obj *armor = victim->_armor[targetIndex];
+ if (armor != NULL) {
+ // TODO: Absorb some damage.
+ snprintf(buf, 512, "%s%s's %s weakens the impact of %s%s's %s.",
+ victim->getDefiniteArticle(true), victim->_name.c_str(),
+ victim->_armor[targetIndex]->_name.c_str(),
+ attacker->getDefiniteArticle(false), attacker->_name.c_str(),
+ weapon->_name.c_str());
+ appendText(buf);
+ decrementUses(armor);
+ } else {
+ snprintf(buf, 512, "A hit to the %s!", targets[targetIndex]);
+ appendText(buf);
+ }
+ playSound(attacker->_scoresHitSound);
+ appendText(attacker->_scoresHitComment.c_str());
+ playSound(victim->_receivesHitSound);
+ appendText(victim->_receivesHitComment.c_str());
+ receivedHitTextPrinted = true;
+ } else if (weapon->_type == Obj::MAGICAL_OBJECT) {
+ appendText(weapon->_useMessage.c_str());
+ appendText("The spell is effective!");
+ }
+
+ bool causesPhysicalDamage = true;
+ bool causesSpiritualDamage = false;
+ bool freezesOpponent = false;
+ bool usesDecremented = false;
+
+ if (weapon->_type == Obj::THROW_WEAPON) {
+ _world->move(weapon, victim->_currentScene);
+ } else if (weapon->_type == Obj::MAGICAL_OBJECT) {
+ int type = weapon->_attackType;
+ causesPhysicalDamage = (type == Obj::CAUSES_PHYSICAL_DAMAGE || type == Obj::CAUSES_PHYSICAL_AND_SPIRITUAL_DAMAGE);
+ causesSpiritualDamage = (type == Obj::CAUSES_SPIRITUAL_DAMAGE || type == Obj::CAUSES_PHYSICAL_AND_SPIRITUAL_DAMAGE);
+ freezesOpponent = (type == Obj::FREEZES_OPPONENT);
+ }
+
+ if (causesPhysicalDamage) {
+ victim->_context._userVariables[PHYS_HIT_CUR] -= weapon->_damage;
+
+ /* Do it here to get the right order of messages in case of death. */
+ decrementUses(weapon);
+ usesDecremented = true;
+
+ if (victim->_context._userVariables[PHYS_HIT_CUR] < 0) {
+ playSound(victim->_dyingSound);
+ appendText(victim->_dyingWords.c_str());
+ snprintf(buf, 512, "%s%s is dead!", victim->getDefiniteArticle(true), victim->_name.c_str());
+ appendText(buf);
+
+ attacker->_context._kills++;
+ attacker->_context._experience += victim->_context._userVariables[SPIR_HIT_CUR] + victim->_context._userVariables[PHYS_HIT_CUR];
+
+ if (!victim->_playerCharacter && !victim->_inventory.empty()) {
+ Scene *currentScene = victim->_currentScene;
+
+ for (int i = victim->_inventory.size() - 1; i >= 0; i--) {
+ _world->move(victim->_inventory[i], currentScene);
+ }
+ Common::String *s = getGroundItemsList(currentScene);
+ appendText(s->c_str());
+ delete s;
+ }
+ _world->move(victim, _world->_storageScene);
+ } else if (attacker->_playerCharacter && !receivedHitTextPrinted) {
+ double physicalPercent = (double)victim->_context._userVariables[SPIR_HIT_CUR] /
+ victim->_context._userVariables[SPIR_HIT_BAS];
+ snprintf(buf, 512, "%s%s's condition appears to be %s.",
+ victim->getDefiniteArticle(true), victim->_name.c_str(),
+ getPercentMessage(physicalPercent));
+ appendText(buf);
+ }
+ }
+
+ if (causesSpiritualDamage) {
+ /* TODO */
+ }
+
+ if (freezesOpponent) {
+ victim->_context._frozen = true;
+ }
+
+ return usesDecremented;
}
void WageEngine::performMagic(Chr *attacker, Chr *victim, Obj *magicalObject) {