WAGE: Implemented object taking logic

This commit is contained in:
Eugene Sandulenko 2015-12-24 14:12:19 +01:00
parent 88faad5d08
commit f76eb1831c
6 changed files with 76 additions and 12 deletions

View File

@ -192,6 +192,9 @@ Chr::Chr(String name, Common::SeekableReadStream *data) {
_weaponSound1 = readPascalString(data);
_weaponSound2 = readPascalString(data);
for (int i = 0; i < NUMBER_OF_ARMOR_TYPES; i++)
_armor[i] = NULL;
}
WeaponArray *Chr::getWeapons() {
@ -202,4 +205,38 @@ WeaponArray *Chr::getWeapons() {
return list;
}
int Chr::wearObjIfPossible(Obj *obj) {
switch (obj->_type) {
case Obj::HELMET:
if (_armor[HEAD_ARMOR] == NULL) {
_armor[HEAD_ARMOR] = obj;
return Chr::HEAD_ARMOR;
}
break;
case Obj::CHEST_ARMOR:
if (_armor[BODY_ARMOR] == NULL) {
_armor[BODY_ARMOR] = obj;
return Chr::BODY_ARMOR;
}
break;
case Obj::SHIELD:
if (_armor[SHIELD_ARMOR] == NULL) {
_armor[SHIELD_ARMOR] = obj;
return Chr::SHIELD_ARMOR;
}
break;
case Obj::SPIRITUAL_ARMOR:
if (_armor[MAGIC_ARMOR] == NULL) {
_armor[MAGIC_ARMOR] = obj;
return Chr::MAGIC_ARMOR;
}
break;
default:
return -1;
}
return -1;
}
} // End of namespace Wage

View File

@ -60,7 +60,7 @@ typedef Common::Array<Weapon *> WeaponArray;
class Context {
public:
enum StatVariables {
enum StatVariable {
/** The base physical accuracy of the player. */
PHYS_ACC_BAS = 0,
/** The current physical accuracy of the player. */
@ -141,7 +141,9 @@ public:
enum ChrArmorType {
HEAD_ARMOR = 0,
BODY_ARMOR = 1,
SHIELD_ARMOR = 2
SHIELD_ARMOR = 2,
MAGIC_ARMOR = 3,
NUMBER_OF_ARMOR_TYPES = 4
};
Chr(String name, Common::SeekableReadStream *data);
@ -201,7 +203,7 @@ public:
Scene *_currentScene;
Common::List<Obj> _inventory;
Obj *_armor[3];
Obj *_armor[NUMBER_OF_ARMOR_TYPES];
Context _context;
@ -276,6 +278,7 @@ public:
bool hasNativeWeapon2() {
return (_nativeWeapon2.size() > 0 && _operativeVerb2.size() > 0);
}
int wearObjIfPossible(Obj *obj);
};
class Weapon {
@ -301,7 +304,7 @@ public:
Obj() : _currentOwner(NULL), _currentScene(NULL) {}
Obj(String name, Common::SeekableReadStream *data);
enum ObjectTypes {
enum ObjectType {
REGULAR_WEAPON = 1,
THROW_WEAPON = 2,
MAGICAL_OBJECT = 3,
@ -313,7 +316,7 @@ public:
IMMOBILE_OBJECT = 9
};
enum AttackTypes {
enum AttackType {
CAUSES_PHYSICAL_DAMAGE = 0,
CAUSES_SPIRITUAL_DAMAGE = 1,
CAUSES_PHYSICAL_AND_SPIRITUAL_DAMAGE = 2,
@ -350,7 +353,6 @@ public:
if (currentScene != NULL)
_currentOwner = NULL;
}
};
class Scene : public Designed {

View File

@ -178,16 +178,14 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
delete weapons;
}
/*
// TODO: weapons, offer, etc...
} else if (inputClick instanceof Obj) {
Obj obj = (Obj) inputClick;
if (obj.getType() != Obj.IMMOBILE_OBJECT) {
} else if (_inputClick->_classType == OBJ) {
Obj *obj = (Obj *)_inputClick;
if (obj->_type != Obj::IMMOBILE_OBJECT) {
takeObj(obj);
} else {
appendText(obj.getClickMessage());
appendText(obj->_clickMessage);
}
*/
}
return _handled;
@ -737,6 +735,27 @@ bool Script::evalClickCondition(Operand *lhs, const char *op, Operand *rhs) {
return false;
}
void Script::takeObj(Obj *obj) {
if (_world->_player->_inventory.size() >= _world->_player->_maximumCarriedObjects) {
appendText("Your pack is full, you must drop something.");
} else {
_world->move(obj, _world->_player);
int type = _world->_player->wearObjIfPossible(obj);
if (type == Chr::HEAD_ARMOR) {
appendText(String("You are now wearing the ") + obj->_name + ".");
} else if (type == Chr::BODY_ARMOR) {
appendText(String("You are now wearing the ") + obj->_name + ".");
} else if (type == Chr::SHIELD_ARMOR) {
appendText(String("You are now wearing the ") + obj->_name + ".");
} else if (type == Chr::MAGIC_ARMOR) {
appendText(String("You are now wearing the ") + obj->_name + ".");
} else {
appendText(String("You now have the ") + obj->_name + ".");
}
appendText(obj->_clickMessage);
}
}
void Script::processMove() {
warning("STUB: processMove");
}

View File

@ -150,6 +150,7 @@ private:
bool eval(Operand *lhs, const char *op, Operand *rhs);
Operand *convertOperand(Operand *operand, int type);
bool evalClickCondition(Operand *lhs, const char *op, Operand *rhs);
void takeObj(Obj *obj);
void processMove();
void processLet();

View File

@ -350,4 +350,8 @@ Common::String *World::loadStringFromDITL(Common::MacResManager *resMan, int res
return NULL;
}
void World::move(Obj *obj, Chr *chr) {
warning("STUB: World::move()");
}
} // End of namespace Wage

View File

@ -60,6 +60,7 @@ public:
bool loadWorld(Common::MacResManager *resMan);
void loadExternalSounds(String fname);
Common::String *loadStringFromDITL(Common::MacResManager *resMan, int resourceId, int itemIndex);
void move(Obj *obj, Chr *chr);
String _name;
String _aboutMessage;