Skip to content

Commit

Permalink
WAGE: Implement getWeapons(). Got rid of class Weapon
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Feb 14, 2016
1 parent efdf51d commit c7eed7f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 37 deletions.
4 changes: 2 additions & 2 deletions engines/wage/combat.cpp
Expand Up @@ -106,7 +106,7 @@ void WageEngine::performCombatAction(Chr *npc, Chr *player) {

bool winning = (npc->_context._statVariables[PHYS_HIT_CUR] > player->_context._statVariables[PHYS_HIT_CUR]);
int validMoves = getValidMoveDirections(npc);
WeaponArray *weapons = npc->getWeapons(false);
ObjArray *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?).
Expand Down Expand Up @@ -177,7 +177,7 @@ void WageEngine::performCombatAction(Chr *npc, Chr *player) {
delete magics;
}

void WageEngine::performAttack(Chr *attacker, Chr *victim, Weapon *weapon) {
void WageEngine::performAttack(Chr *attacker, Chr *victim, Obj *weapon) {
warning("STUB: performAttack()");
}

Expand Down
50 changes: 47 additions & 3 deletions engines/wage/entities.cpp
Expand Up @@ -361,6 +361,32 @@ Chr::Chr(String name, Common::SeekableReadStream *data) {
for (int i = 0; i < NUMBER_OF_ARMOR_TYPES; i++)
_armor[i] = NULL;

_weapon1 = NULL;
_weapon2 = NULL;

// Create native weapons
if (_nativeWeapon1.size() && _operativeVerb1.size()) {
_weapon1 = new Obj;

_weapon1->_name = _nativeWeapon1;
_weapon1->_operativeVerb = _operativeVerb1;
_weapon1->_type = Obj::REGULAR_WEAPON;
_weapon1->_accuracy = 0;
_weapon1->_damage = _weaponDamage1;
_weapon1->_sound = _weaponSound1;
}

if (_nativeWeapon2.size() && _operativeVerb2.size()) {
_weapon2 = new Obj;

_weapon2->_name = _nativeWeapon2;
_weapon2->_operativeVerb = _operativeVerb2;
_weapon2->_type = Obj::REGULAR_WEAPON;
_weapon2->_accuracy = 0;
_weapon2->_damage = _weaponDamage2;
_weapon2->_sound = _weaponSound2;
}

delete data;
}

Expand All @@ -378,10 +404,28 @@ void Chr::resetState() {
_context._statVariables[PHYS_SPE_BAS] = _context._statVariables[PHYS_SPE_CUR] = _runningSpeed;
}

WeaponArray *Chr::getWeapons(bool includeMagic) {
WeaponArray *list = new WeaponArray;
ObjArray *Chr::getWeapons(bool includeMagic) {
ObjArray *list = new ObjArray;

if (_weapon1)
list->push_back(_weapon1);

if (_weapon2)
list->push_back(_weapon2);

warning("STUB: getWeapons");
for (uint i = 0; i < _inventory.size(); i++)
switch (_inventory[i]->_type) {
case Obj::REGULAR_WEAPON:
case Obj::THROW_WEAPON:
list->push_back(_inventory[i]);
break;
case Obj::MAGICAL_OBJECT:
if (includeMagic)
list->push_back(_inventory[i]);
break;
default:
break;
}

return list;
}
Expand Down
30 changes: 8 additions & 22 deletions engines/wage/entities.h
Expand Up @@ -58,9 +58,7 @@ class Design;
class Obj;
class Scene;
class Script;
class Weapon;

typedef Common::Array<Weapon *> WeaponArray;
typedef Common::Array<Obj *> ObjArray;
typedef Common::Array<Chr *> ChrArray;
typedef Common::List<Obj *> ObjList;
Expand Down Expand Up @@ -219,18 +217,14 @@ class Chr : public Designed {

Context _context;

WeaponArray *getWeapons(bool includeMagic);
ObjArray *getWeapons(bool includeMagic);
ObjArray *getMagicalObjects();
const char *getDefiniteArticle(bool capitalize);

public:
bool hasNativeWeapon1() {
return (_nativeWeapon1.size() > 0 && _operativeVerb1.size() > 0);
}
Obj *_weapon1;
Obj *_weapon2;

bool hasNativeWeapon2() {
return (_nativeWeapon2.size() > 0 && _operativeVerb2.size() > 0);
}
public:
int wearObjIfPossible(Obj *obj);
void wearObjs();

Expand Down Expand Up @@ -299,21 +293,13 @@ class Obj : public Designed {
_currentOwner = NULL;
}

Chr *removeFromChr();
Designed *removeFromCharOrScene();
};

class Weapon : public Obj {
public:
int _numberOfUses;

Weapon() : _numberOfUses(0) {}

void decrementNumberOfUses() {
if (_numberOfUses != -1) {
if (_numberOfUses != -1)
_numberOfUses--;
}
}

Chr *removeFromChr();
Designed *removeFromCharOrScene();
};

class Scene : public Designed {
Expand Down
4 changes: 2 additions & 2 deletions engines/wage/menu.cpp
Expand Up @@ -278,10 +278,10 @@ void Menu::regenWeaponsMenu() {

void Menu::createWeaponsMenu(MenuItem *menu) {
Chr *player = _gui->_engine->_world->_player;
WeaponArray *weapons = player->getWeapons(true);
ObjArray *weapons = player->getWeapons(true);

for (int i = 0; i < weapons->size(); i++) {
Weapon *obj = (*weapons)[i];
Obj *obj = (*weapons)[i];
if (obj->_type == Obj::REGULAR_WEAPON ||
obj->_type == Obj::THROW_WEAPON ||
obj->_type == Obj::MAGICAL_OBJECT) {
Expand Down
8 changes: 4 additions & 4 deletions engines/wage/script.cpp
Expand Up @@ -199,8 +199,8 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
handleAcceptCommand();
} else {
Chr *player = _world->_player;
WeaponArray *weapons = player->getWeapons(true);
for (WeaponArray::const_iterator weapon = weapons->begin(); weapon != weapons->end(); ++weapon) {
ObjArray *weapons = player->getWeapons(true);
for (ObjArray::const_iterator weapon = weapons->begin(); weapon != weapons->end(); ++weapon) {
if (tryAttack(*weapon, input)) {
handleAttack(*weapon);
break;
Expand Down Expand Up @@ -1076,13 +1076,13 @@ void Script::handleOfferCommand(const char *target) {
warning("STUB: handleOfferCommand");
}

bool Script::tryAttack(Weapon *weapon, Common::String &input) {
bool Script::tryAttack(Obj *weapon, Common::String &input) {
warning("STUB: tryAttack");

return false;
}

void Script::handleAttack(Weapon *weapon) {
void Script::handleAttack(Obj *weapon) {
warning("STUB: handleAttack");
}

Expand Down
4 changes: 2 additions & 2 deletions engines/wage/script.h
Expand Up @@ -186,8 +186,8 @@ class Script {
void handleWearCommand(const char *target);
void handleOfferCommand(const char *target);

bool tryAttack(Weapon *weapon, Common::String &input);
void handleAttack(Weapon *weapon);
bool tryAttack(Obj *weapon, Common::String &input);
void handleAttack(Obj *weapon);

Common::Array<ScriptText *> _scriptText;
void convertToText();
Expand Down
3 changes: 1 addition & 2 deletions engines/wage/wage.h
Expand Up @@ -67,7 +67,6 @@ class Dialog;
class Gui;
class Obj;
class Scene;
class Weapon;
class World;

using Common::String;
Expand Down Expand Up @@ -131,7 +130,7 @@ class WageEngine : public Engine {
void processTurnInternal(Common::String *textInput, Designed *clickInput);
void performCombatAction(Chr *npc, Chr *player);
int getValidMoveDirections(Chr *npc);
void performAttack(Chr *attacker, Chr *victim, Weapon *weapon);
void performAttack(Chr *attacker, Chr *victim, Obj *weapon);
void performMagic(Chr *attacker, Chr *victim, Obj *magicalObject);
void performMove(Chr *chr, int validMoves);
void performOffer(Chr *attacker, Chr *victim);
Expand Down

0 comments on commit c7eed7f

Please sign in to comment.