2016-01-09 00:20:35 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* MIT License:
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
* conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wage/wage.h"
|
|
|
|
#include "wage/entities.h"
|
|
|
|
#include "wage/randomhat.h"
|
|
|
|
#include "wage/world.h"
|
|
|
|
|
|
|
|
namespace Wage {
|
|
|
|
|
|
|
|
Obj *WageEngine::getOffer() {
|
2016-01-17 22:11:19 +00:00
|
|
|
if (_offer != NULL) {
|
|
|
|
Chr *owner = _offer->_currentOwner;
|
|
|
|
if (owner == NULL || owner->_playerCharacter || owner->_currentScene != _world->_player->_currentScene) {
|
|
|
|
_offer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _offer;
|
2016-01-09 00:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Chr *WageEngine::getMonster() {
|
|
|
|
if (_monster != NULL && _monster->_currentScene != _world->_player->_currentScene) {
|
|
|
|
_monster = NULL;
|
|
|
|
}
|
|
|
|
return _monster;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WageEngine::encounter(Chr *player, Chr *chr) {
|
2016-01-17 22:25:47 +00:00
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
snprintf(buf, 512, "You encounter %s%s.", chr->_nameProperNoun ? "" : getIndefiniteArticle(chr->_name),
|
|
|
|
chr->_name.c_str());
|
|
|
|
appendText(buf);
|
2016-01-09 00:20:35 +00:00
|
|
|
|
|
|
|
if (!chr->_initialComment.empty())
|
|
|
|
appendText(chr->_initialComment);
|
|
|
|
|
|
|
|
if (chr->_armor[Chr::HEAD_ARMOR] != NULL) {
|
2016-01-17 22:25:47 +00:00
|
|
|
snprintf(buf, 512, "%s%s is wearing %s.", chr->getDefiniteArticle(true), chr->_name.c_str(),
|
|
|
|
getIndefiniteArticle(chr->_armor[Chr::HEAD_ARMOR]->_name));
|
|
|
|
appendText(buf);
|
2016-01-09 00:20:35 +00:00
|
|
|
}
|
|
|
|
if (chr->_armor[Chr::BODY_ARMOR] != NULL) {
|
2016-01-17 22:25:47 +00:00
|
|
|
snprintf(buf, 512, "%s is protected by %s%s.", getGenderSpecificPronoun(chr->_gender, true),
|
|
|
|
prependGenderSpecificPronoun(chr->_gender), chr->_armor[Chr::BODY_ARMOR]->_name.c_str());
|
|
|
|
appendText(buf);
|
2016-01-09 00:20:35 +00:00
|
|
|
}
|
|
|
|
if (chr->_armor[Chr::SHIELD_ARMOR] != NULL) {
|
|
|
|
Obj *obj = chr->_armor[Chr::SHIELD_ARMOR];
|
2016-01-17 22:25:47 +00:00
|
|
|
|
|
|
|
snprintf(buf, 512, "%s carries %s%s.", getGenderSpecificPronoun(chr->_gender, true),
|
|
|
|
obj->_namePlural ? "" : getIndefiniteArticle(obj->_name), obj->_name.c_str());
|
|
|
|
appendText(buf);
|
2016-01-09 00:20:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WageEngine::performCombatAction(Chr *npc, Chr *player) {
|
|
|
|
if (npc->_context._frozen)
|
|
|
|
return;
|
|
|
|
|
2016-01-09 00:48:38 +00:00
|
|
|
RandomHat hat(_rnd);
|
2016-01-09 00:20:35 +00:00
|
|
|
|
|
|
|
bool winning = (npc->_context._statVariables[PHYS_HIT_CUR] > player->_context._statVariables[PHYS_HIT_CUR]);
|
|
|
|
int validMoves = getValidMoveDirections(npc);
|
2016-01-21 07:48:36 +00:00
|
|
|
ObjArray *weapons = npc->getWeapons(false);
|
2016-01-09 00:20:35 +00:00
|
|
|
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->_weaponMenuDisabled) {
|
|
|
|
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->_weaponMenuDisabled) {
|
|
|
|
if (weapons->size() > 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);
|
|
|
|
}
|
|
|
|
|
2016-01-09 00:34:06 +00:00
|
|
|
ObjList *objs = &npc->_currentScene->_objs;
|
2016-01-09 00:20:35 +00:00
|
|
|
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->operator[](_rnd->getRandomNumber(weapons->size() - 1)));
|
|
|
|
break;
|
|
|
|
case kTokMagic:
|
|
|
|
// TODO: I think the monster should choose the "best" magic.
|
|
|
|
performMagic(npc, player, magics->operator[](_rnd->getRandomNumber(magics->size() - 1)));
|
|
|
|
break;
|
|
|
|
case kTokRun:
|
|
|
|
performMove(npc, validMoves);
|
|
|
|
break;
|
|
|
|
case kTokOffer:
|
|
|
|
performOffer(npc, player);
|
|
|
|
break;
|
2016-01-09 00:48:38 +00:00
|
|
|
case kTokNone:
|
|
|
|
break;
|
2016-01-09 00:20:35 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
int cnt = 0;
|
|
|
|
for (ObjList::const_iterator it = objs->begin(); it != objs->end(); ++it, ++cnt)
|
|
|
|
if (cnt == token)
|
|
|
|
performTake(npc, *it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete weapons;
|
|
|
|
delete magics;
|
|
|
|
}
|
|
|
|
|
2016-01-21 12:34:20 +00:00
|
|
|
const char *targets[] = { "head", "chest", "side" };
|
|
|
|
|
2016-01-21 07:48:36 +00:00
|
|
|
void WageEngine::performAttack(Chr *attacker, Chr *victim, Obj *weapon) {
|
2016-01-21 12:34:20 +00:00
|
|
|
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");
|
2016-01-21 13:25:48 +00:00
|
|
|
|
|
|
|
return false;
|
2016-01-09 00:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WageEngine::performMagic(Chr *attacker, Chr *victim, Obj *magicalObject) {
|
2016-01-21 13:25:48 +00:00
|
|
|
switch (magicalObject->_attackType) {
|
|
|
|
case Obj::HEALS_PHYSICAL_DAMAGE:
|
|
|
|
case Obj::HEALS_SPIRITUAL_DAMAGE:
|
|
|
|
case Obj::HEALS_PHYSICAL_AND_SPIRITUAL_DAMAGE:
|
|
|
|
performHealingMagic(attacker, magicalObject);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
performAttack(attacker, victim, magicalObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WageEngine::performHealingMagic(Chr *chr, Obj *magicalObject) {
|
|
|
|
warning("STUB: performHealingMagic()");
|
2016-01-09 00:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WageEngine::performMove(Chr *chr, int validMoves) {
|
|
|
|
warning("STUB: performMove()");
|
|
|
|
}
|
|
|
|
|
|
|
|
void WageEngine::performOffer(Chr *attacker, Chr *victim) {
|
2016-01-09 12:40:19 +00:00
|
|
|
/* TODO: choose in a smarter way? */
|
|
|
|
Obj *obj = attacker->_inventory[0];
|
2016-01-17 22:25:47 +00:00
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
snprintf(buf, 512, "%s%s offers %s%s.", attacker->getDefiniteArticle(true), attacker->_name.c_str(),
|
|
|
|
obj->_namePlural ? "some " : getIndefiniteArticle(obj->_name), obj->_name.c_str());
|
|
|
|
|
|
|
|
appendText(buf);
|
2016-01-09 12:40:19 +00:00
|
|
|
|
|
|
|
_offer = obj;
|
2016-01-09 00:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WageEngine::performTake(Chr *npc, Obj *obj) {
|
2016-01-17 22:25:47 +00:00
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
snprintf(buf, 512, "%s%s picks up the %s%s.", npc->getDefiniteArticle(true), npc->_name.c_str(),
|
|
|
|
getIndefiniteArticle(obj->_name), obj->_name.c_str());
|
|
|
|
|
|
|
|
appendText(buf);
|
2016-01-09 12:19:46 +00:00
|
|
|
|
|
|
|
_world->move(obj, npc);
|
2016-01-09 00:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int WageEngine::getValidMoveDirections(Chr *npc) {
|
|
|
|
warning("STUB: getValidMoveDirections()");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WageEngine::regen() {
|
|
|
|
Chr *player = _world->_player;
|
|
|
|
int curHp = player->_context._statVariables[PHYS_HIT_CUR];
|
|
|
|
int maxHp = player->_context._statVariables[PHYS_HIT_BAS];
|
|
|
|
int delta = maxHp - curHp;
|
|
|
|
|
|
|
|
if (delta > 0) {
|
|
|
|
int bonus = (int)(delta / (8 + _rnd->getRandomNumber(2)));
|
|
|
|
player->_context._statVariables[PHYS_HIT_CUR] += bonus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Wage
|