Skip to content

Commit

Permalink
WAGE: Implemented World::move(Obj *obj, Chr *chr)
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Dec 27, 2015
1 parent 59b2809 commit 5f2ef62
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
29 changes: 28 additions & 1 deletion engines/wage/entities.cpp
Expand Up @@ -124,6 +124,33 @@ Obj::Obj(String name, Common::SeekableReadStream *data) : _currentOwner(NULL), _
_sound = readPascalString(data);
}

Chr *Obj::removeFromChr() {
if (_currentOwner != NULL) {
for (int i = _currentOwner->_inventory.size() - 1; i >= 0; i--)
if (_currentOwner->_inventory[i] == this)
_currentOwner->_inventory.remove_at(i);

for (int i = 0; i < Chr::NUMBER_OF_ARMOR_TYPES; i++) {
if (_currentOwner->_armor[i] == this) {
_currentOwner->_armor[i] = NULL;
}
}
}

return _currentOwner;
}

Designed *Obj::removeFromCharOrScene() {
Designed *from = removeFromChr();

if (_currentScene != NULL) {
_currentScene->_objs.remove(this);
from = _currentScene;
}

return from;
}

Chr::Chr(String name, Common::SeekableReadStream *data) {
_name = name;
_classType = CHR;
Expand Down Expand Up @@ -207,7 +234,7 @@ WeaponArray *Chr::getWeapons() {

void Chr::wearObjs() {
for (int i = 0; i < _inventory.size(); i++)
wearObjIfPossible(&_inventory[i]);
wearObjIfPossible(_inventory[i]);
}

int Chr::wearObjIfPossible(Obj *obj) {
Expand Down
9 changes: 6 additions & 3 deletions engines/wage/entities.h
Expand Up @@ -201,7 +201,7 @@ class Chr : public Designed {
String _dyingWords;

Scene *_currentScene;
Common::Array<Obj> _inventory;
Common::Array<Obj *> _inventory;

Obj *_armor[NUMBER_OF_ARMOR_TYPES];

Expand Down Expand Up @@ -354,6 +354,9 @@ class Obj : public Weapon, public Designed {
if (currentScene != NULL)
_currentOwner = NULL;
}

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

class Scene : public Designed {
Expand Down Expand Up @@ -383,8 +386,8 @@ class Scene : public Designed {
int _worldX;
int _worldY;

Common::List<Obj> _objs;
Common::List<Chr> _chrs;
Common::List<Obj *> _objs;
Common::List<Chr *> _chrs;

Scene() {}
Scene(String name, Common::SeekableReadStream *data);
Expand Down
4 changes: 4 additions & 0 deletions engines/wage/wage.cpp
Expand Up @@ -210,4 +210,8 @@ void WageEngine::performInitialSetup() {
}
}

void WageEngine::onMove(Designed *what, Designed *from, Designed *to) {
warning("STUB WageEngine::onMove()");
}

} // End of namespace Wage
8 changes: 5 additions & 3 deletions engines/wage/wage.h
Expand Up @@ -61,10 +61,11 @@ struct ADGameDescription;
namespace Wage {

class Console;
class World;
class Scene;
class Obj;
class Chr;
class Designed;
class Obj;
class Scene;
class World;

using Common::String;

Expand Down Expand Up @@ -131,6 +132,7 @@ class WageEngine : public Engine {
void appendText(String str);
Obj *getOffer();
void processEvents();
void onMove(Designed *what, Designed *from, Designed *to);

private:
Console *_console;
Expand Down
15 changes: 14 additions & 1 deletion engines/wage/world.cpp
Expand Up @@ -352,8 +352,21 @@ Common::String *World::loadStringFromDITL(Common::MacResManager *resMan, int res
return NULL;
}

bool ChrComparator(Obj *l, Obj *r) {
return l->_index < r->_index;
}

void World::move(Obj *obj, Chr *chr) {
warning("STUB: World::move(obj, chr)");
if (obj == NULL)
return;

Designed *from = obj->removeFromCharOrScene();
obj->_currentOwner = chr;
chr->_inventory.push_back(obj);

Common::sort(chr->_inventory.begin(), chr->_inventory.end(), ChrComparator);

_engine->onMove(obj, from, chr);
}

void World::move(Obj *obj, Scene *scene) {
Expand Down

0 comments on commit 5f2ef62

Please sign in to comment.