[Scummvm-git-logs] scummvm master -> 8ba3df68219ff86f37d178bdce90b5a2ac3cdbe2

alxpnv a04198622 at gmail.com
Fri Jun 4 09:51:51 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8ba3df6821 ASYLUM: refactor inventory


Commit: 8ba3df68219ff86f37d178bdce90b5a2ac3cdbe2
    https://github.com/scummvm/scummvm/commit/8ba3df68219ff86f37d178bdce90b5a2ac3cdbe2
Author: alxpnv (alxpnv22 at yahoo.com)
Date: 2021-06-04T12:53:52+03:00

Commit Message:
ASYLUM: refactor inventory

Changed paths:
  A engines/asylum/resources/inventory.cpp
  A engines/asylum/resources/inventory.h
  R engines/asylum/resources/reaction.cpp
  R engines/asylum/resources/reaction.h
    engines/asylum/asylum.cpp
    engines/asylum/asylum.h
    engines/asylum/console.cpp
    engines/asylum/module.mk
    engines/asylum/puzzles/writings.cpp
    engines/asylum/resources/actor.cpp
    engines/asylum/resources/actor.h
    engines/asylum/resources/encounters.cpp
    engines/asylum/resources/encounters.h
    engines/asylum/resources/script.cpp
    engines/asylum/resources/script.h
    engines/asylum/resources/special.cpp
    engines/asylum/resources/worldstats.cpp
    engines/asylum/resources/worldstats.h
    engines/asylum/shared.h
    engines/asylum/views/scene.cpp
    engines/asylum/views/scene.h


diff --git a/engines/asylum/asylum.cpp b/engines/asylum/asylum.cpp
index 5a51b69b29..5d774d2c99 100644
--- a/engines/asylum/asylum.cpp
+++ b/engines/asylum/asylum.cpp
@@ -31,7 +31,6 @@
 
 #include "asylum/resources/actor.h"
 #include "asylum/resources/encounters.h"
-#include "asylum/resources/reaction.h"
 #include "asylum/resources/script.h"
 #include "asylum/resources/special.h"
 #include "asylum/resources/worldstats.h"
@@ -52,23 +51,8 @@
 
 namespace Asylum {
 
-// inventory ring is a circle of radius 80 centered at (-20, 20)
-static const int16 inventoryRingPoints[36][2] = {
-	{ -20,  100},
-	{ -20,  100}, { -20,  -60},
-	{ -20,  100}, { -89,  -20}, {  49,  -20},
-	{ -20,  100}, {-100,   20}, { -20,  -60}, {  60,   20},
-	{ -20,  100}, { -96,   45}, { -67,  -45}, {  27,  -45}, {  56,   45},
-	{ -20,  100}, { -89,   60}, { -89,  -20}, { -20,  -60}, {  49,  -20}, {  49,   60},
-	{ -20,  100}, { -82,   70}, { -98,    3}, { -56,  -51}, {  13,  -53}, {  57,   -1}, {  45,   67},
-	{ -20,  100}, { -77,   77}, {-100,   20}, { -77,  -37}, { -20,  -60}, {  37,  -37}, {  60,   20}, {  37,   77}
-};
-
-// first 8 triangular numbers
-static const uint32 inventoryRingOffsets[8] = {0, 1, 3, 6, 10, 15, 21, 28};
-
 AsylumEngine::AsylumEngine(OSystem *system, const ADGameDescription *gd) : Engine(system), _gameDescription(gd),
-	_console(NULL), _cursor(NULL), _encounter(NULL), _menu(NULL), _reaction(NULL), _resource(NULL), _savegame(NULL),
+	_console(NULL), _cursor(NULL), _encounter(NULL), _menu(NULL), _resource(NULL), _savegame(NULL),
 	_scene(NULL), _screen(NULL), _script(NULL), _special(NULL), _speech(NULL), _sound(NULL), _text(NULL),
 	_video(NULL), _handler(NULL), _puzzles(NULL) {
 
@@ -102,7 +86,6 @@ AsylumEngine::~AsylumEngine() {
 	delete _scene;
 	delete _encounter;
 	delete _puzzles;
-	delete _reaction;
 	delete _savegame;
 	delete _screen;
 	delete _script;
@@ -142,7 +125,6 @@ Common::Error AsylumEngine::run() {
 	_encounter = new Encounter(this);
 	_cursor    = new Cursor(this);
 	_puzzles   = new Puzzles(this);
-	_reaction  = new Reaction(this);
 	_savegame  = new Savegame(this);
 	_screen    = new Screen(this);
 	_script    = new ScriptManager(this);
@@ -516,19 +498,6 @@ void AsylumEngine::notify(AsylumEventType type, int32 param1, int32 param2) {
 	_handler->handleEvent(evt);
 }
 
-Common::Point AsylumEngine::getInventoryRingPoint(uint32 nPoints, uint32 index) const {
-	if (!_scene)
-		error("[AsylumEngine::getInventoryRingPoint] Subsystems not initialized properly!");
-
-	const int16 (*pointPtr)[2];
-	if (_scene->worldstats()->chapter == kChapter11)
-		pointPtr = &inventoryRingPoints[inventoryRingOffsets[7] + index + 3];
-	else
-		pointPtr = &inventoryRingPoints[inventoryRingOffsets[nPoints - 1] + index];
-
-	return Common::Point((*pointPtr)[0], (*pointPtr)[1]);
-}
-
 void AsylumEngine::updateReverseStereo() {
 	if (_scene && _scene->worldstats())
 		_scene->worldstats()->reverseStereo = Config.reverseStereo;
diff --git a/engines/asylum/asylum.h b/engines/asylum/asylum.h
index cb34a5c768..06aa5c7fff 100644
--- a/engines/asylum/asylum.h
+++ b/engines/asylum/asylum.h
@@ -63,7 +63,6 @@ class Cursor;
 class Encounter;
 class Menu;
 class Puzzles;
-class Reaction;
 class ResourceManager;
 class Savegame;
 class Scene;
@@ -142,7 +141,6 @@ public:
 	Cursor          *cursor()    { return _cursor; }
 	Encounter       *encounter() { return _encounter; }
 	Menu            *menu()      { return _menu; }
-	Reaction        *reaction()  { return _reaction; }
 	ResourceManager *resource()  { return _resource; }
 	Savegame        *savegame()  { return _savegame; }
 	Scene           *scene()     { return _scene; }
@@ -190,16 +188,6 @@ public:
 	 */
 	void updateReverseStereo();
 
-	/**
-	 * Gets an inventory ring point
-	 *
-	 * @param nPoints Number of Points
-	 * @param index   Point index
-	 *
-	 * @return        Inventory ring point
-	 */
-	Common::Point getInventoryRingPoint(uint32 nPoints, uint32 index) const;
-
 	// Serializable
 	void saveLoadWithSerializer(Common::Serializer &s);
 
@@ -214,7 +202,6 @@ private:
 	Cursor          *_cursor;
 	Encounter       *_encounter;
 	Menu            *_menu;
-	Reaction        *_reaction;
 	ResourceManager *_resource;
 	Savegame        *_savegame;
 	Scene           *_scene;
diff --git a/engines/asylum/console.cpp b/engines/asylum/console.cpp
index aeaa9740a7..61acfc726a 100644
--- a/engines/asylum/console.cpp
+++ b/engines/asylum/console.cpp
@@ -28,6 +28,7 @@
 
 #include "asylum/resources/actor.h"
 #include "asylum/resources/encounters.h"
+#include "asylum/resources/inventory.h"
 #include "asylum/resources/object.h"
 #include "asylum/resources/script.h"
 #include "asylum/resources/worldstats.h"
@@ -837,7 +838,7 @@ bool Console::cmdAddToInventory(int argc, const char **argv) {
 	uint32 index = atoi(argv[1]), count = argc == 3 ? atoi(argv[2]) : 0, maxIndex;
 
 	for (maxIndex = 0; maxIndex < 16; maxIndex++) {
-		if (!getWorld()->cursorResourcesAlternate[maxIndex])
+		if (!getWorld()->inventoryIconsActive[maxIndex])
 			break;
 	}
 
@@ -846,7 +847,7 @@ bool Console::cmdAddToInventory(int argc, const char **argv) {
 		return true;
 	}
 
-	getScene()->getActor()->addReactionHive(index, count);
+	getScene()->getActor()->inventory.add(index, count);
 
 	return true;
 }
@@ -860,7 +861,7 @@ bool Console::cmdRemoveFromInventory(int argc, const char **argv) {
 	uint32 index = atoi(argv[1]), count = argc == 3 ? atoi(argv[2]) : 0, maxIndex;
 
 	for (maxIndex = 0; maxIndex < 16; maxIndex++) {
-		if (!getWorld()->cursorResourcesAlternate[maxIndex])
+		if (!getWorld()->inventoryIconsActive[maxIndex])
 			break;
 	}
 
@@ -869,7 +870,7 @@ bool Console::cmdRemoveFromInventory(int argc, const char **argv) {
 		return true;
 	}
 
-	getScene()->getActor()->removeReactionHive(index, count);
+	getScene()->getActor()->inventory.remove(index, count);
 
 	return true;
 }
diff --git a/engines/asylum/module.mk b/engines/asylum/module.mk
index 30d9e426b1..930ef5a3a8 100644
--- a/engines/asylum/module.mk
+++ b/engines/asylum/module.mk
@@ -23,8 +23,8 @@ MODULE_OBJS := \
 	resources/data.o \
 	resources/object.o \
 	resources/encounters.o \
+	resources/inventory.o \
 	resources/polygons.o \
-	resources/reaction.o \
 	resources/script.o \
 	resources/special.o \
 	resources/worldstats.o \
diff --git a/engines/asylum/puzzles/writings.cpp b/engines/asylum/puzzles/writings.cpp
index f3b7e1a157..9b4273c8b2 100644
--- a/engines/asylum/puzzles/writings.cpp
+++ b/engines/asylum/puzzles/writings.cpp
@@ -49,7 +49,7 @@ PuzzleWritings::~PuzzleWritings() {
 // Event Handling
 //////////////////////////////////////////////////////////////////////////
 bool PuzzleWritings::init(const AsylumEvent &)  {
-	if (getScene()->getActor()->getField638() == 3)
+	if (getScene()->getActor()->inventory.getSelectedItem() == 3)
 		_hasGlassMagnifier = true;
 	else
 		_hasGlassMagnifier = false;
diff --git a/engines/asylum/resources/actor.cpp b/engines/asylum/resources/actor.cpp
index a64881cc5d..dbe79fe0b1 100644
--- a/engines/asylum/resources/actor.cpp
+++ b/engines/asylum/resources/actor.cpp
@@ -25,7 +25,6 @@
 #include "asylum/resources/encounters.h"
 #include "asylum/resources/object.h"
 #include "asylum/resources/polygons.h"
-#include "asylum/resources/reaction.h"
 #include "asylum/resources/special.h"
 #include "asylum/resources/script.h"
 #include "asylum/resources/worldstats.h"
@@ -46,7 +45,7 @@ namespace Asylum {
 
 #define DIR(val) (ActorDirection)((val) & 7)
 
-Actor::Actor(AsylumEngine *engine, ActorIndex index) : _vm(engine), _index(index) {
+Actor::Actor(AsylumEngine *engine, ActorIndex index) : _vm(engine), _index(index), inventory(engine, _numberValue01) {
  	// Init all variables
  	_resourceId = kResourceNone;
  	_objectIndex = 0;
@@ -65,8 +64,6 @@ Actor::Actor(AsylumEngine *engine, ActorIndex index) : _vm(engine), _index(index
  	_field_60 = 0;
  	_actionIdx3 = 0;
  	// TODO field_68 till field_617
- 	memset(&_reaction, 0, sizeof(_reaction));
- 	_field_638 = 0;
  	_walkingSound1 = 0;
  	_walkingSound2 = 0;
  	_walkingSound3 = 0;
@@ -152,10 +149,7 @@ void Actor::load(Common::SeekableReadStream *stream) {
 	// TODO skip field_68 till field_617
 	stream->skip(0x5B0);
 
-	for (int32 i = 0; i < 8; i++)
-		_reaction[i] = stream->readSint32LE();
-
-	_field_638     = stream->readSint32LE();
+	inventory.load(stream);
 	_walkingSound1 = stream->readSint32LE();
 	_walkingSound2 = stream->readSint32LE();
 	_walkingSound3 = stream->readSint32LE();
@@ -244,10 +238,8 @@ void Actor::saveLoadWithSerializer(Common::Serializer &s) {
 	// TODO skip field_68 till field_617
 	s.skip(0x5B0);
 
-	for (int32 i = 0; i < 8; i++)
-		s.syncAsSint32LE(_reaction[i]);
+	inventory.saveLoadWithSerializer(s);
 
-	s.syncAsSint32LE(_field_638);
 	s.syncAsSint32LE(_walkingSound1);
 	s.syncAsSint32LE(_walkingSound2);
 	s.syncAsSint32LE(_walkingSound3);
@@ -1823,74 +1815,6 @@ void Actor::move(ActorDirection actorDir, uint32 dist) {
 	}
 }
 
-void Actor::addReactionHive(int32 reactionIndex, int32 numberValue01Add) {
-	if (reactionIndex > 16)
-		return;
-
-	uint32 i;
-	for (i = 0; i < 8; i++)
-		if (!_reaction[i])
-			break;
-
-	if (i == 8)
-		return;
-
-	if (!hasMoreReactions(reactionIndex, 0))
-		_reaction[i] = reactionIndex;
-
-	if (numberValue01Add)
-		_numberValue01 += numberValue01Add;
-
-	getSound()->playSound(MAKE_RESOURCE(kResourcePackHive, 0));
-}
-
-void Actor::removeReactionHive(int32 reactionIndex, int32 numberValue01Substract) {
-	if (reactionIndex > 16)
-		return;
-
-	if (numberValue01Substract) {
-		_numberValue01 -= numberValue01Substract;
-		if (_numberValue01 < 0)
-			_numberValue01 = 0;
-	}
-
-	if (!numberValue01Substract || !_numberValue01) {
-
-		uint32 i = 0;
-		for (i = 0; i < 8; i++)
-			if (_reaction[i] == reactionIndex)
-				break;
-
-		if (i == 8)
-			return;
-
-		if (i == 7) {
-			_reaction[7] = 0;
-		} else {
-			memmove(&_reaction[i], &_reaction[i + 1], 32 - 4 * i);
-			_reaction[7] = 0;
-		}
-	}
-}
-
-bool Actor::hasMoreReactions(int32 reactionIndex, int32 testNumberValue01) const {
-	if (reactionIndex > 16)
-		return false;
-
-	uint32 i;
-	for (i = 0; i < 8; i++)
-		if (_reaction[i] == reactionIndex)
-			break;
-
-	if (i == 8)
-		return false;
-
-	if (testNumberValue01)
-		return _numberValue01 >= testNumberValue01;
-
-	return true;
-}
-
 bool Actor::canMoveCheckActors(Common::Point *point, ActorDirection dir) {
 	int32 dist = getAbsoluteDistanceForFrame(dir, (_frameIndex >= _frameCount) ? 2 * _frameCount - (_frameIndex + 1) : _frameIndex);
 
@@ -1986,27 +1910,22 @@ bool Actor::canMoveCheckActors(Common::Point *point, ActorDirection dir) {
 	return true;
 }
 
-void Actor::updateAndDraw() {
+void Actor::drawInventory() {
 	Actor *player = getScene()->getActor();
 	Common::Point mouse = getCursor()->position();
 	bool keepField = false;
 
-	// Get reaction count
-	uint32 count = 0;
-	for (int i = 0; i < 8; i++)
-		if (_reaction[i])
-			count++;
-
+	uint count = inventory.find();
 	for (uint32 i = 0; i < count; i++) {
 		// Compute points
 		Common::Point coords;
 		adjustCoordinates(&coords);
 
-		Common::Point ringPoint = _vm->getInventoryRingPoint(count, i);
+		Common::Point ringPoint = Inventory::getInventoryRingPoint(_vm, count, i);
 		Common::Point point = coords + Common::Point(player->getPoint2()->x + ringPoint.x, player->getPoint2()->y / 2 - ringPoint.y);
 
 		if (mouse.x < point.x || mouse.x > (point.x + 40) || mouse.y < point.y || mouse.y > (point.y + 40)) {
-			getScreen()->addGraphicToQueue(getWorld()->cursorResourcesAlternate[_reaction[i] + 15],
+			getScreen()->addGraphicToQueue(getWorld()->inventoryIconsNormal[inventory[i] - 1],
 			                               0,
 			                               point,
 			                               kDrawFlagNone,
@@ -2015,13 +1934,13 @@ void Actor::updateAndDraw() {
 		} else {
 			if (getWorld()->field_120 != (int32)(i + 1)) {
 				getSound()->playSound(MAKE_RESOURCE(kResourcePackSound, 3));
-				getReaction()->run(_reaction[i] - 1);
+				Inventory::describe(_vm, inventory[i] - 1);
 			}
 
 			getWorld()->field_120 = i + 1;
 			keepField = true;
 
-			getScreen()->addGraphicToQueue(getWorld()->cursorResourcesAlternate[_reaction[i] - 1],
+			getScreen()->addGraphicToQueue(getWorld()->inventoryIconsActive[inventory[i] - 1],
 			                               0,
 			                               point,
 			                               kDrawFlagNone,
@@ -2030,7 +1949,7 @@ void Actor::updateAndDraw() {
 		}
 
 		if (getWorld()->chapter == kChapter4)
-			updateNumbers(_reaction[i] - 1, point);
+			updateNumbers(inventory[i] - 1, point);
 	}
 
 	if (!keepField)
@@ -3335,8 +3254,8 @@ void Actor::resetActors() {
 	getWorld()->tickCount1 = _vm->getTick() + 3000;
 }
 
-void Actor::updateNumbers(int32 reaction, const Common::Point &point) {
-	if (reaction != 1)
+void Actor::updateNumbers(uint item, const Common::Point &point) {
+	if (item != 1)
 		return;
 
 	_numberPoint.x = point.x;
diff --git a/engines/asylum/resources/actor.h b/engines/asylum/resources/actor.h
index 0bf5b1e372..3108120733 100644
--- a/engines/asylum/resources/actor.h
+++ b/engines/asylum/resources/actor.h
@@ -30,6 +30,8 @@
 
 #include "asylum/shared.h"
 
+#include "asylum/resources/inventory.h"
+
 namespace Asylum {
 
 class AsylumEngine;
@@ -92,7 +94,7 @@ public:
 	//////////////////////////////////////////////////////////////////////////
 	int32 flags;
 	int32 actionType; // ActionType enum value
-
+	Inventory inventory;
 
 	void setActionIndex2(int32 index) { _actionIdx2 = index; }
 	void setObjectIndex(int32 index) { _objectIndex = index; }
@@ -102,14 +104,12 @@ public:
 	void setLastScreenUpdate(int32 tick) { _lastScreenUpdate = tick; }
 	void setNumberFlag01(int32 number) { _numberFlag01 = number; }
 	void setPriority(int32 priority) { _priority = priority; }
-	void setReaction(int32 index, int32 val) { _reaction[index] = val; }
 	void setResourceId(ResourceId id) { _resourceId = id; }
 	void setSoundResourceId(ResourceId id) { _soundResourceId = id; }
 	void setStatus(ActorStatus status) { _status = status; }
 	void setTransparency(int32 val) { _transparency = val; }
 	void setTickCount(int32 tickCount) { _tickCount = tickCount; }
 
-	void setField638(int32 val) { _field_638 = val; }
 	void setField934(int32 val) { _field_934 = val; }
 	void setField938(int32 val) { _field_938 = val; }
 	void setField944(int32 val) { _field_944 = val; }
@@ -126,7 +126,6 @@ public:
 	Common::Point *getPoint1() { return &_point1; }
 	Common::Point *getPoint2() { return &_point2; }
 	int32          getPriority() { return _priority; }
-	int32          getReactionValue(uint32 index) { return _reaction[index]; }
 	ResourceId     getResourceId() { return _resourceId; }
 	ResourceId     getResourcesId(uint32 index) { return _graphicResourceIds[index]; }
 	int32          getScriptIndex() { return _scriptIndex; }
@@ -135,7 +134,6 @@ public:
 	ActorStatus    getStatus()    { return _status; }
 	int32          getTickCount() { return _tickCount; }
 
-	int32          getField638() { return _field_638; }
 	int32          getField934() { return _field_934; }
 	int32          getField944() { return _field_944; }
 	int32          getField948() { return _field_948; }
@@ -294,11 +292,8 @@ public:
 	bool canInteract(Common::Point *point, int32* param);
 	bool canMove(Common::Point *point, ActorDirection direction, uint32 count, bool hasDelta);
 	void move(ActorDirection dir, uint32 distance);
-	void addReactionHive(int32 reactionIndex, int32 numberValue01Add);
-	void removeReactionHive(int32 reactionIndex, int32 numberValue01Substract);
-	bool hasMoreReactions(int32 reactionIndex, int32 testNumberValue01) const;
 	bool canMoveCheckActors(Common::Point *point, ActorDirection direction);
-	void updateAndDraw();
+	void drawInventory();
 	void update_409230();
 
 	/**
@@ -374,8 +369,6 @@ private:
 	int32  _field_60;
 	int32  _actionIdx3;
 	// TODO field_68 till field_617
-	int32  _reaction[8];
-	int32  _field_638;
 	ResourceId _walkingSound1;
 	ResourceId _walkingSound2;
 	ResourceId _walkingSound3;
@@ -511,12 +504,12 @@ private:
 	void resetActors();
 
 	/**
-	 * Updates the actor "number" data if the reaction is "1".
+	 * Updates the actor "number" data if the item is "1".
 	 *
-	 * @param reaction The reaction.
+	 * @param item     The item.
 	 * @param point    The coordinates
 	 */
-	void updateNumbers(int32 reaction, const Common::Point &point);
+	void updateNumbers(uint item, const Common::Point &point);
 
 	/**
 	 * Determine if the supplied point is in the action area
diff --git a/engines/asylum/resources/encounters.cpp b/engines/asylum/resources/encounters.cpp
index fb7f88d96b..627d2fe9c9 100644
--- a/engines/asylum/resources/encounters.cpp
+++ b/engines/asylum/resources/encounters.cpp
@@ -64,10 +64,10 @@ const char *opcodeNames[] = {
 	"SetVariable",
 	"IncrementScriptVariable",
 	"ProcessVariable3",
-	"AddRemoveReactionHive",
+	"AddRemoveInventoryItem",
 	"UNUSED (19)",
 	"UNUSED (20)",
-	"SetCounterFromActorReactions",
+	"SetCounterIfInventoryOmits",
 	"UNUSED (22)",
 	"PrepareMovie",
 	"SetClearGameFlag",
@@ -1631,15 +1631,15 @@ void Encounter::runScript() {
 			}
 			break;
 
-		case kOpcodeAddRemoveReactionHive:
+		case kOpcodeAddRemoveInventoryItem:
 			if (entry.param1)
-				getScene()->getActor()->removeReactionHive(getVariableInv(entry.param2), _scriptData.vars[1]);
+				getScene()->getActor()->inventory.remove(getVariableInv(entry.param2), _scriptData.vars[1]);
 			else
-				getScene()->getActor()->addReactionHive(getVariableInv(entry.param2), _scriptData.vars[1]);
+				getScene()->getActor()->inventory.add(getVariableInv(entry.param2), _scriptData.vars[1]);
 			break;
 
-		case kOpcodeSetCounterFromActorReactions:
-			_scriptData.counter = getScene()->getActor()->hasMoreReactions(getVariableInv(entry.param2), _scriptData.vars[1]) ? 0 : 1;
+		case kOpcodeSetCounterIfInventoryOmits:
+			_scriptData.counter = getScene()->getActor()->inventory.contains(getVariableInv(entry.param2), _scriptData.vars[1]) ? 0 : 1;
 			break;
 
 		case kOpcodePrepareMovie:
diff --git a/engines/asylum/resources/encounters.h b/engines/asylum/resources/encounters.h
index 86a5d68aa8..b4742025d4 100644
--- a/engines/asylum/resources/encounters.h
+++ b/engines/asylum/resources/encounters.h
@@ -286,8 +286,8 @@ private:
 		kOpcodeSetVariable                      = 15,
 		kOpcodeIncrementScriptVariable          = 16,
 		kOpcodeProcessVariable3                 = 17,
-		kOpcodeAddRemoveReactionHive            = 18,
-		kOpcodeSetCounterFromActorReactions     = 21,
+		kOpcodeAddRemoveInventoryItem           = 18,
+		kOpcodeSetCounterIfInventoryOmits       = 21,
 		kOpcodePrepareMovie                     = 23,
 		kOpcodeSetClearGameFlag                 = 24,
 		kOpcodeSetCounterFromGameFlag           = 25
diff --git a/engines/asylum/resources/inventory.cpp b/engines/asylum/resources/inventory.cpp
new file mode 100644
index 0000000000..3fb23f0e49
--- /dev/null
+++ b/engines/asylum/resources/inventory.cpp
@@ -0,0 +1,204 @@
+/* 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.
+ *
+ */
+
+#include "common/serializer.h"
+#include "common/stream.h"
+
+#include "asylum/resources/actor.h"
+#include "asylum/resources/worldstats.h"
+
+#include "asylum/system/speech.h"
+
+#include "asylum/views/scene.h"
+
+namespace Asylum {
+
+// inventory ring is centered at (-20, 20) and has radius 80
+static const int16 inventoryRingPoints[36][2] = {
+	{ -20,  100},
+	{ -20,  100}, { -20,  -60},
+	{ -20,  100}, { -89,  -20}, {  49,  -20},
+	{ -20,  100}, {-100,   20}, { -20,  -60}, {  60,   20},
+	{ -20,  100}, { -96,   45}, { -67,  -45}, {  27,  -45}, {  56,   45},
+	{ -20,  100}, { -89,   60}, { -89,  -20}, { -20,  -60}, {  49,  -20}, {  49,   60},
+	{ -20,  100}, { -82,   70}, { -98,    3}, { -56,  -51}, {  13,  -53}, {  57,   -1}, {  45,   67},
+	{ -20,  100}, { -77,   77}, {-100,   20}, { -77,  -37}, { -20,  -60}, {  37,  -37}, {  60,   20}, {  37,   77}
+};
+
+// first 8 triangular numbers
+static const uint inventoryRingOffsets[8] = {0, 1, 3, 6, 10, 15, 21, 28};
+
+static const int inventoryDescriptionIndices[12][11] = {
+	{ 61,  69,   0,   0,   0,   0,   0,   0,   0,   0,   0},
+	{107, 134, 104, 113,  -1, 112, 117, 109, 108, 111, 106},
+	{170, 182, 181, 172, 171, 169,   0,   0,   0,   0,   0},
+	{ 61,  -1,  66,  67,  68,  69,  70,  78,  77,   0,   0},
+	{197,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0},
+	{ 59,  81,  60,  84,  88,  54,  74, 139,  97, 121,   0},
+	{239, 234, 249, 259, 260, 272, 237, 262,   0,   0,   0},
+	{ 58,  59,  60, 111,  75,  76,  77,  78,   0,   0,   0},
+	{284, 285, 286, 329, 330, 331, 332, 322,   0, 465,   0},
+	{ -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0},
+	{ 69,  70,  78,   0,   0,   0,   0,   0,   0,   0,   0},
+	{  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0}
+};
+
+Inventory::Inventory(AsylumEngine *vm, int32 &multiple) : _vm(vm), _selectedItem(0), _multiple(multiple) {
+	memset(_items, 0, sizeof(_items));
+};
+
+void Inventory::load(Common::SeekableReadStream *stream) {
+	for (int i = 0; i < 8; i++)
+		_items[i] = stream->readUint32LE();
+
+	_selectedItem = stream->readUint32LE();
+}
+
+void Inventory::saveLoadWithSerializer(Common::Serializer &s) {
+	for (int i = 0; i < 8; i++)
+		s.syncAsUint32LE(_items[i]);
+
+	s.syncAsUint32LE(_selectedItem);
+}
+
+uint Inventory::find(uint item) const {
+	int i;
+
+	for (i = 0; i < 8; i++)
+		if (_items[i] == item)
+			break;
+
+	return i;
+}
+
+void Inventory::add(uint item, uint multipleIncr) {
+	if (item > 16)
+		return;
+
+	if (!contains(item, 0)) {
+		int i = find();
+
+		if (i == 8)
+			return;
+
+		_items[i] = item;
+	}
+
+	_multiple += multipleIncr;
+
+	getSound()->playSound(MAKE_RESOURCE(kResourcePackSound, 0));
+}
+
+void Inventory::remove(uint item, uint multipleDecr) {
+	if (item > 16)
+		return;
+
+	_multiple = _multiple >= multipleDecr ? _multiple - multipleDecr : 0;
+
+	if (!multipleDecr || !_multiple) {
+		int i = find(item);
+
+		if (i == 8)
+			return;
+
+		if (i < 7)
+			memmove(&_items[i], &_items[i + 1], (7 - i) * 4);
+
+		_items[7] = 0;
+	}
+}
+
+bool Inventory::contains(uint item, uint multiple) const {
+	if (item > 16)
+		return false;
+
+	int i = find(item);
+
+	if (i == 8)
+		return false;
+
+	if (multiple)
+		return _multiple >= multiple;
+
+	return true;
+}
+
+void Inventory::copyFrom(Inventory &inventory) {
+	for (int i = 0; i < 8; i++)
+		_items[i] = inventory[i];
+}
+
+Common::Point Inventory::getInventoryRingPoint(AsylumEngine *vm, uint nPoints, uint index) {
+	const int16 (*pointPtr)[2];
+
+	if (vm->scene()->worldstats()->chapter == kChapter11)
+		pointPtr = &inventoryRingPoints[inventoryRingOffsets[7] + index + 3];
+	else
+		pointPtr = &inventoryRingPoints[inventoryRingOffsets[nPoints - 1] + index];
+
+	return Common::Point((*pointPtr)[0], (*pointPtr)[1]);
+}
+
+void Inventory::describe(AsylumEngine *vm, uint itemIndex) {
+	uint index;
+	ResourceId resourceId;
+	ChapterIndex chapter = vm->scene()->worldstats()->chapter;
+
+	if (chapter == kChapterNone || itemIndex > 10)
+		return;
+
+	if (chapter == kChapter2 && itemIndex == 4)
+		index = vm->isGameFlagSet(kGameFlag186) ? 362 : 110;
+	else if (chapter == kChapter4 && itemIndex == 1)
+		index = vm->scene()->getActor()->getNumberValue01() != 1 ? 65 : 64;
+	else if (chapter == kChapter10 && itemIndex < 5)
+		index = 91 + itemIndex;
+	else
+		index = inventoryDescriptionIndices[chapter - 1][itemIndex];
+
+	switch (vm->scene()->worldstats()->actorType) {
+	default:
+		resourceId = (ResourceId)index;
+		break;
+
+	case kActorMax:
+		resourceId = MAKE_RESOURCE(kResourcePackSpeech, index < 259 ? index : index - 9);
+		break;
+
+	case kActorSarah:
+		resourceId = MAKE_RESOURCE(kResourcePackSharedSound, index + 1927);
+		break;
+
+	case kActorCyclops:
+		resourceId = MAKE_RESOURCE(kResourcePackSharedSound, index + 2084);
+		break;
+
+	case kActorAztec:
+		resourceId = MAKE_RESOURCE(kResourcePackSharedSound, index + 2234);
+		break;
+	}
+
+	if (vm->speech()->getSoundResourceId() != resourceId || !vm->sound()->isPlaying(resourceId))
+		vm->speech()->playPlayer(index);
+}
+
+} // End of namespace Asylum
diff --git a/engines/asylum/resources/reaction.h b/engines/asylum/resources/inventory.h
similarity index 50%
rename from engines/asylum/resources/reaction.h
rename to engines/asylum/resources/inventory.h
index 0a95e91307..332cdd72d2 100644
--- a/engines/asylum/resources/reaction.h
+++ b/engines/asylum/resources/inventory.h
@@ -20,28 +20,44 @@
  *
  */
 
-#ifndef ASYLUM_RESOURCES_REACTION_H
-#define ASYLUM_RESOURCES_REACTION_H
+#ifndef ASYLUM_RESOURCES_INVENTORY_H
+#define ASYLUM_RESOURCES_INVENTORY_H
 
-#include "common/scummsys.h"
+#include "common/serializer.h"
+#include "common/stream.h"
 
-namespace Asylum {
+#include "asylum/asylum.h"
 
-class AsylumEngine;
+namespace Asylum {
 
-class Reaction {
+class Inventory : public Common::Serializable {
 public:
-	Reaction(AsylumEngine *engine);
-	virtual ~Reaction() {};
+	Inventory(AsylumEngine *vm, int32 &multiple);
 
-	void run(uint32 reactionIndex);
+	uint find(uint item = 0) const;
+	void add(uint item, uint multipleIncr);
+	void remove(uint item, uint multipleDecr);
+	bool contains(uint item, uint multiple) const;
+	void copyFrom(Inventory &inventory);
 
-private:
-	AsylumEngine* _vm;
+	uint getSelectedItem() const { return _selectedItem; }
+	void selectItem(uint item) { _selectedItem = item; }
+
+	void load(Common::SeekableReadStream *stream);
+	void saveLoadWithSerializer(Common::Serializer &s);
 
-	void play(uint32 index);
+	uint32 &operator[](uint index) { return _items[index]; }
+
+	static Common::Point getInventoryRingPoint(AsylumEngine *vm, uint nPoints, uint index);
+	static void describe(AsylumEngine *vm, uint item);
+
+private:
+	uint32 _items[8];
+	uint32 _selectedItem;
+	int32 &_multiple;
+	AsylumEngine *_vm;
 };
 
 } // End of namespace Asylum
 
-#endif // ASYLUM_RESOURCES_REACTION_H
+#endif // ASYLUM_RESOURCES_INVENTORY_H
diff --git a/engines/asylum/resources/reaction.cpp b/engines/asylum/resources/reaction.cpp
deleted file mode 100644
index 4b8896f7a2..0000000000
--- a/engines/asylum/resources/reaction.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/* 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.
- *
- */
-
-#include "asylum/resources/reaction.h"
-
-#include "asylum/resources/actor.h"
-#include "asylum/resources/worldstats.h"
-
-#include "asylum/system/speech.h"
-
-#include "asylum/views/scene.h"
-
-#include "asylum/asylum.h"
-
-namespace Asylum {
-
-static const int32 reactions[12][11] = {
-	{ 61,  69,   0,   0,   0,   0,   0,   0,   0,   0,   0},
-	{107, 134, 104, 113,  -1, 112, 117, 109, 108, 111, 106},
-	{170, 182, 181, 172, 171, 169,   0,   0,   0,   0,   0},
-	{ 61,  -1,  66,  67,  68,  69,  70,  78,  77,   0,   0},
-	{197,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0},
-	{ 59,  81,  60,  84,  88,  54,  74, 139,  97, 121,   0},
-	{239, 234, 249, 259, 260, 272, 237, 262,   0,   0,   0},
-	{ 58,  59,  60, 111,  75,  76,  77,  78,   0,   0,   0},
-	{284, 285, 286, 329, 330, 331, 332, 322,   0, 465,   0},
-	{ -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0},
-	{ 69,  70,  78,   0,   0,   0,   0,   0,   0,   0,   0},
-	{  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0}
-};
-
-Reaction::Reaction(AsylumEngine *engine) : _vm(engine) {}
-
-void Reaction::run(uint32 reactionIndex) {
-	if (getWorld()->chapter == kChapterNone || reactionIndex > 10)
-		return;
-
-	if (getWorld()->chapter == kChapter2 && reactionIndex == 4)
-		play(_vm->isGameFlagSet(kGameFlag186) ? 362 : 110);
-	else if (getWorld()->chapter == kChapter4 && reactionIndex == 1)
-		play((getScene()->getActor()->getNumberValue01() != 1) ? 65 : 64);
-	else if (getWorld()->chapter == kChapter10 && reactionIndex < 5)
-		play(91 + reactionIndex);
-	else
-		play(reactions[getWorld()->chapter - 1][reactionIndex]);
-}
-
-void Reaction::play(uint32 index) {
-	ResourceId resourceId = kResourceNone;
-
-	switch (getWorld()->actorType) {
-	default:
-		resourceId = (ResourceId)index;
-		break;
-
-	case kActorMax:
-		resourceId = MAKE_RESOURCE(kResourcePackSpeech, index < 259 ? index : index - 9);
-		break;
-
-	case kActorSarah:
-		resourceId = MAKE_RESOURCE(kResourcePackSharedSound, index + 1927);
-		break;
-
-	case kActorCyclops:
-		resourceId = MAKE_RESOURCE(kResourcePackSharedSound, index + 2084);
-		break;
-
-	case kActorAztec:
-		resourceId = MAKE_RESOURCE(kResourcePackSharedSound, index + 2234);
-		break;
-	}
-
-	if (getSpeech()->getSoundResourceId() != resourceId || !getSound()->isPlaying(resourceId))
-		getSpeech()->playPlayer(index);
-}
-
-} // End of namespace Asylum
diff --git a/engines/asylum/resources/script.cpp b/engines/asylum/resources/script.cpp
index 5f0ec7abdf..953d07ade5 100644
--- a/engines/asylum/resources/script.cpp
+++ b/engines/asylum/resources/script.cpp
@@ -142,15 +142,15 @@ ScriptManager::ScriptManager(AsylumEngine *engine) : _vm(engine) {
 	ADD_OPCODE(JumpIfActionTalk);
 	ADD_OPCODE(SetActionTalk);
 	ADD_OPCODE(ClearActionTalk);
-	ADD_OPCODE(AddReactionHive);
-	ADD_OPCODE(RemoveReactionHive);
-	ADD_OPCODE(HasMoreReaction);
+	ADD_OPCODE(AddToInventory);
+	ADD_OPCODE(RemoveFromInventory);
+	ADD_OPCODE(JumpIfInventoryOmits);
 	ADD_OPCODE(RunEncounter);
 	ADD_OPCODE(JumpIfAction16);
 	ADD_OPCODE(SetAction16);
 	ADD_OPCODE(ClearAction16);
-	ADD_OPCODE(SetActorField638);
-	ADD_OPCODE(JumpIfActorField638);
+	ADD_OPCODE(SelectInventoryItem);
+	ADD_OPCODE(JumpIfInventoryItemNotSelected);
 	ADD_OPCODE(ChangeScene);
 	ADD_OPCODE(UpdateActor);
 	ADD_OPCODE(PlayMovie);
@@ -853,26 +853,26 @@ END_OPCODE
 
 //////////////////////////////////////////////////////////////////////////
 // Opcode 0x22
-IMPLEMENT_OPCODE(AddReactionHive)
+IMPLEMENT_OPCODE(AddToInventory)
 	Actor *actor = getScene()->getActor(cmd->param3 ? cmd->param3 : _currentQueueEntry->actorIndex);
 
-	actor->addReactionHive(cmd->param1, cmd->param2);
+	actor->inventory.add(cmd->param1, cmd->param2);
 END_OPCODE
 
 //////////////////////////////////////////////////////////////////////////
 // Opcode 0x23
-IMPLEMENT_OPCODE(RemoveReactionHive)
+IMPLEMENT_OPCODE(RemoveFromInventory)
 	Actor *actor = getScene()->getActor(cmd->param3 ? cmd->param3 : _currentQueueEntry->actorIndex);
 
-	actor->removeReactionHive(cmd->param1, cmd->param2);
+	actor->inventory.remove(cmd->param1, cmd->param2);
 END_OPCODE
 
 //////////////////////////////////////////////////////////////////////////
 // Opcode 0x24
-IMPLEMENT_OPCODE(HasMoreReaction)
+IMPLEMENT_OPCODE(JumpIfInventoryOmits)
 	Actor *actor = getScene()->getActor(cmd->param4 ? cmd->param4 : _currentQueueEntry->actorIndex);
 
-	if (!actor->hasMoreReactions(cmd->param1, cmd->param3))
+	if (!actor->inventory.contains(cmd->param1, cmd->param3))
 		_currentQueueEntry->currentLine = cmd->param2;
 END_OPCODE
 
@@ -916,18 +916,18 @@ END_OPCODE
 
 //////////////////////////////////////////////////////////////////////////
 // Opcode 0x29
-IMPLEMENT_OPCODE(SetActorField638)
+IMPLEMENT_OPCODE(SelectInventoryItem)
 	Actor *actor = getScene()->getActor(cmd->param1);
 
-	actor->setField638(cmd->param2);
+	actor->inventory.selectItem(cmd->param2);
 END_OPCODE
 
 //////////////////////////////////////////////////////////////////////////
 // Opcode 0x2A
-IMPLEMENT_OPCODE(JumpIfActorField638)
+IMPLEMENT_OPCODE(JumpIfInventoryItemNotSelected)
 	Actor *actor = getScene()->getActor(cmd->param1);
 
-	if (actor->getField638() != cmd->param2)
+	if (actor->inventory.getSelectedItem() != cmd->param2)
 		_currentQueueEntry->currentLine = cmd->param3;
 END_OPCODE
 
diff --git a/engines/asylum/resources/script.h b/engines/asylum/resources/script.h
index 38c5cb2dbd..4112d65fe7 100644
--- a/engines/asylum/resources/script.h
+++ b/engines/asylum/resources/script.h
@@ -382,15 +382,15 @@ private:
 	DECLARE_OPCODE(JumpIfActionTalk);
 	DECLARE_OPCODE(SetActionTalk);
 	DECLARE_OPCODE(ClearActionTalk);
-	DECLARE_OPCODE(AddReactionHive);
-	DECLARE_OPCODE(RemoveReactionHive);
-	DECLARE_OPCODE(HasMoreReaction);
+	DECLARE_OPCODE(AddToInventory);
+	DECLARE_OPCODE(RemoveFromInventory);
+	DECLARE_OPCODE(JumpIfInventoryOmits);
 	DECLARE_OPCODE(RunEncounter);
 	DECLARE_OPCODE(JumpIfAction16);
 	DECLARE_OPCODE(SetAction16);
 	DECLARE_OPCODE(ClearAction16);
-	DECLARE_OPCODE(SetActorField638);
-	DECLARE_OPCODE(JumpIfActorField638);
+	DECLARE_OPCODE(SelectInventoryItem);
+	DECLARE_OPCODE(JumpIfInventoryItemNotSelected);
 	DECLARE_OPCODE(ChangeScene);
 	DECLARE_OPCODE(UpdateActor);
 	DECLARE_OPCODE(PlayMovie);
diff --git a/engines/asylum/resources/special.cpp b/engines/asylum/resources/special.cpp
index 72eb38fa3e..4d6cf0af80 100644
--- a/engines/asylum/resources/special.cpp
+++ b/engines/asylum/resources/special.cpp
@@ -475,7 +475,7 @@ void Special::chapter7(Object *object, ActorIndex actorIndex) {
 			Actor *player = getScene()->getActor();
 
 			if (_vm->isGameFlagSet(kGameFlag1021)) {
-				if (player->getReactionValue(0)) {
+				if (player->inventory[0]) {
 
 					if (player->getStatus() == kActorStatusShowingInventory || player->getStatus() == kActorStatus10) {
 						getSound()->playSound(MAKE_RESOURCE(kResourcePackSound, 2));
@@ -494,9 +494,9 @@ void Special::chapter7(Object *object, ActorIndex actorIndex) {
 			}
 
 			if (_vm->isGameFlagSet(kGameFlag1023)) {
-				if (player->getField638()) {
-					getScript()->queueScript(getWorld()->actions[getWorld()->getActionAreaIndexById(player->getField638() == 3 ? 2447 : 2448)]->scriptIndex,
-					                         getSharedData()->getPlayerIndex());
+				if (player->inventory.getSelectedItem()) {
+					int32 areaIndex = getWorld()->getActionAreaIndexById(player->inventory.getSelectedItem() == 3 ? 2447 : 2448);
+					getScript()->queueScript(getWorld()->actions[areaIndex]->scriptIndex, getSharedData()->getPlayerIndex());
 					_vm->clearGameFlag(kGameFlag1023);
 				} else if (player->getStatus() != kActorStatusShowingInventory) {
 					_vm->clearGameFlag(kGameFlag1023);
@@ -572,7 +572,7 @@ void Special::chapter8(Object *object, ActorIndex actorIndex) {
 
 			if (object->getFrameIndex() == 23) {
 				if (_vm->isGameFlagNotSet(kGameFlag815))
-					actor0->addReactionHive(1, 0);
+					actor0->inventory.add(1, 0);
 
 				_vm->setGameFlag(kGameFlag815);
 			}
@@ -747,9 +747,9 @@ void Special::chapter11(Object *object, ActorIndex actorIndex) {
 
 			if (_vm->isGameFlagNotSet(kGameFlag1099)) {
 				_vm->setGameFlag(kGameFlag1099);
-				getScene()->getActor(9)->setReaction(0, 1);
-				getScene()->getActor(9)->setReaction(1, 2);
-				getScene()->getActor(9)->setReaction(2, 3);
+				getScene()->getActor(9)->inventory[0] = 1;
+				getScene()->getActor(9)->inventory[1] = 2;
+				getScene()->getActor(9)->inventory[2] = 3;
 			}
 
 			if (_vm->isGameFlagSet(kGameFlag561) && _vm->isGameFlagNotSet(kGameFlag562)) {
diff --git a/engines/asylum/resources/worldstats.cpp b/engines/asylum/resources/worldstats.cpp
index 9940a44e92..fc97ab5dd7 100644
--- a/engines/asylum/resources/worldstats.cpp
+++ b/engines/asylum/resources/worldstats.cpp
@@ -75,7 +75,10 @@ WorldStats::WorldStats(AsylumEngine *engine) : _vm(engine) {
 	musicStatusExt = 0;
 	numScripts = 0;
 	numPolygons = 0;
-	memset(&cursorResourcesAlternate, kResourceNone, sizeof(cursorResourcesAlternate));
+	memset(&inventoryIconsActive, kResourceNone, sizeof(inventoryIconsActive));
+	memset(&inventoryIconsNormal, kResourceNone, sizeof(inventoryIconsNormal));
+	memset(&inventoryCursorsNormal, kResourceNone, sizeof(inventoryCursorsNormal));
+	memset(&inventoryCursorsBlinking, kResourceNone, sizeof(inventoryCursorsBlinking));
 
 	field_E848C = 0;
 	field_E8490 = 0;
@@ -227,9 +230,15 @@ void WorldStats::load(Common::SeekableReadStream *stream) {
 	numScripts  = stream->readUint32LE();
 	numPolygons = stream->readUint32LE();
 
-	// Load the alternate cursor resources
-	for (uint32 i = 0; i < ARRAYSIZE(cursorResourcesAlternate); i++)
-		cursorResourcesAlternate[i] = (ResourceId)stream->readSint32LE();
+	// Load inventory resources
+	for (uint32 i = 0; i < ARRAYSIZE(inventoryIconsActive); i++)
+		inventoryIconsActive[i] = (ResourceId)stream->readSint32LE();
+	for (uint32 i = 0; i < ARRAYSIZE(inventoryIconsNormal); i++)
+		inventoryIconsNormal[i] = (ResourceId)stream->readSint32LE();
+	for (uint32 i = 0; i < ARRAYSIZE(inventoryCursorsNormal); i++)
+		inventoryCursorsNormal[i] = (ResourceId)stream->readSint32LE();
+	for (uint32 i = 0; i < ARRAYSIZE(inventoryCursorsBlinking); i++)
+		inventoryCursorsBlinking[i] = (ResourceId)stream->readSint32LE();
 
 	//////////////////////////////////////////////////////////////////////////
 	// Read actions
@@ -401,9 +410,15 @@ void WorldStats::saveLoadWithSerializer(Common::Serializer &s) {
 	s.syncAsUint32LE(numScripts);
 	s.syncAsUint32LE(numPolygons);
 
-	// Alternate cursor resources
-	for (int32 i = 0; i < ARRAYSIZE(cursorResourcesAlternate); i++)
-		s.syncAsSint32LE(cursorResourcesAlternate[i]);
+	// Inventory resources
+	for (uint32 i = 0; i < ARRAYSIZE(inventoryIconsActive); i++)
+		s.syncAsSint32LE(inventoryIconsActive[i]);
+	for (uint32 i = 0; i < ARRAYSIZE(inventoryIconsNormal); i++)
+		s.syncAsSint32LE(inventoryIconsNormal[i]);
+	for (uint32 i = 0; i < ARRAYSIZE(inventoryCursorsNormal); i++)
+		s.syncAsSint32LE(inventoryCursorsNormal[i]);
+	for (uint32 i = 0; i < ARRAYSIZE(inventoryCursorsBlinking); i++)
+		s.syncAsSint32LE(inventoryCursorsBlinking[i]);
 
 	//////////////////////////////////////////////////////////////////////////
 	// Read actions
diff --git a/engines/asylum/resources/worldstats.h b/engines/asylum/resources/worldstats.h
index 15cddaf30f..1f03b783d6 100644
--- a/engines/asylum/resources/worldstats.h
+++ b/engines/asylum/resources/worldstats.h
@@ -124,7 +124,10 @@ public:
 	// ActorData is stored in each actor instance
 	uint32 numScripts;
 	uint32 numPolygons;
-	ResourceId cursorResourcesAlternate[64];
+	ResourceId inventoryIconsActive[16];
+	ResourceId inventoryIconsNormal[16];
+	ResourceId inventoryCursorsNormal[16];
+	ResourceId inventoryCursorsBlinking[16];
 	Common::Array<ActionArea*> actions;  // maxsize 400
 	int32 field_E848C;
 	int32 field_E8490;
diff --git a/engines/asylum/shared.h b/engines/asylum/shared.h
index ac5487d698..220893bec9 100644
--- a/engines/asylum/shared.h
+++ b/engines/asylum/shared.h
@@ -375,15 +375,15 @@ enum OpcodeType {
 	kOpcodeJumpIfActionTalk,
 	kOpcodeSetActionTalk,
 	kOpcodeClearActionTalk,
-	kOpcodeAddReactionHive,
-	kOpcodeRemoveReactionHive,                  // 35
-	kOpcodeHasMoreReactions,
+	kOpcodeAddToInventory,
+	kOpcodeRemoveFromInventory,                 // 35
+	kOpcodeJumpIfInventoryOmits,
 	kOpcodeRunEncounter,
 	kOpcodeJumpIfAction16,
 	kOpcodeSetAction16,
 	kOpcodeClearAction16,                       // 40
-	kOpcodeSetActorField638,
-	kOpcodeJumpIfActorField638,
+	kOpcodeSelectInventoryItem,
+	kOpcodeJumpIfInventoryItemNotSelected,
 	kOpcodeChangeScene,
 	kOpcodeUpdateActor,
 	kOpcodePlayMovie,                           // 45
diff --git a/engines/asylum/views/scene.cpp b/engines/asylum/views/scene.cpp
index 72d356afd3..dd04479155 100644
--- a/engines/asylum/views/scene.cpp
+++ b/engines/asylum/views/scene.cpp
@@ -24,6 +24,7 @@
 
 #include "asylum/resources/actor.h"
 #include "asylum/resources/encounters.h"
+#include "asylum/resources/inventory.h"
 #include "asylum/resources/object.h"
 #include "asylum/resources/polygons.h"
 #include "asylum/resources/script.h"
@@ -542,9 +543,9 @@ bool Scene::clickDown(const AsylumEvent &evt) {
 		if (player->getStatus() == kActorStatusDisabled)
 			break;
 
-		if (player->getField638()) {
+		if (player->inventory.getSelectedItem()) {
 			if (hitTestPlayer()) {
-				player->setField638(0);
+				player->inventory.selectItem(0);
 				return true;
 			}
 
@@ -559,9 +560,9 @@ bool Scene::clickDown(const AsylumEvent &evt) {
 			return true;
 		}
 
-		if (!hitTestPlayer() || player->getStatus() >= kActorStatus11 || !player->getReactionValue(0)) {
+		if (!hitTestPlayer() || player->getStatus() >= kActorStatus11 || !player->inventory[0]) {
 			if (player->getStatus() == kActorStatusShowingInventory || player->getStatus() == kActorStatus10) {
-				playerReaction();
+				clickInventory();
 			} else {
 				HitType type = kHitNone;
 				int32 res = hitTest(type);
@@ -1152,20 +1153,20 @@ void Scene::updateCursor(ActorDirection direction, const Common::Rect &rect) {
 		return;
 	}
 
-	if (player->getField638()) {
+	if (player->inventory.getSelectedItem()) {
 		if (mouse.x >= rect.left && mouse.x <= rightLimit && mouse.y >= rect.top  && mouse.y <= rect.bottom && hitTestPlayer()) {
 
-			ResourceId id = _ws->cursorResourcesAlternate[player->getField638() + 31];
+			ResourceId id = _ws->inventoryCursorsNormal[player->inventory.getSelectedItem() - 1];
 			if (getCursor()->getResourceId() != id)
 				getCursor()->set(id, 0, kCursorAnimationNone);
 
 		} else {
 			if (hitTestScene(type) == -1) {
-				ResourceId id = _ws->cursorResourcesAlternate[player->getField638() + 31];
+				ResourceId id = _ws->inventoryCursorsNormal[player->inventory.getSelectedItem() - 1];
 				if (getCursor()->getResourceId() != id)
 					getCursor()->set(id, 0, kCursorAnimationNone);
 			} else {
-				ResourceId id = _ws->cursorResourcesAlternate[player->getField638() + 47];
+				ResourceId id = _ws->inventoryCursorsBlinking[player->inventory.getSelectedItem() - 1];
 				uint32 frameCount = GraphicResource::getFrameCount(_vm, id);
 				if (getCursor()->getResourceId() != id)
 					getCursor()->set(id, 0, (frameCount <= 1) ? kCursorAnimationNone : kCursorAnimationMirror);
@@ -1176,7 +1177,7 @@ void Scene::updateCursor(ActorDirection direction, const Common::Rect &rect) {
 	}
 
 	if (mouse.x >= rect.left && mouse.x <= rightLimit && mouse.y >= rect.top  && mouse.y <= rect.bottom && hitTestPlayer()) {
-		if (player->getReactionValue(0)) {
+		if (player->inventory[0]) {
 			if (getCursor()->getResourceId() != _ws->cursorResources[kCursorResourceGrabPointer])
 				getCursor()->set(_ws->cursorResources[kCursorResourceGrabPointer]);
 
@@ -1649,35 +1650,30 @@ void Scene::handleHit(int32 index, HitType type) {
 	}
 }
 
-void Scene::playerReaction() {
+void Scene::clickInventory() {
 	const Common::Point mouse = getCursor()->position();
 	Common::Point point;
 	Actor *player = getActor();
 
 	player->adjustCoordinates(&point);
 
-	uint32 count;
-	for (count = 0; count < 8; count++) {
-		if (!player->getReactionValue(count))
-			break;
-	}
+	uint count = player->inventory.find();
 
-	player->setField638(0);
+	player->inventory.selectItem(0);
 
 	if (count > 0) {
 		for (uint32 i = 0; i < count; i++) {
-			Common::Point ringPoint = _vm->getInventoryRingPoint(count, i);
+			Common::Point ringPoint = Inventory::getInventoryRingPoint(_vm, count, i);
 			int32 x = point.x + player->getPoint2()->x + ringPoint.x;
 			int32 y = point.y + player->getPoint2()->y / 2 - ringPoint.y;
 
 			if (mouse.x >= x && mouse.x <= (x + 40) && mouse.y >= y && mouse.y <= (y + 40)) {
-				// Handle reaction
 				getSound()->playSound(MAKE_RESOURCE(kResourcePackSound, 4));
 
 				if (_ws->chapter == kChapter9) {
 					switch (i) {
 					default:
-						player->setField638(player->getReactionValue(i));
+						player->inventory.selectItem(player->inventory[i]);
 						break;
 
 					case 0:
@@ -1693,7 +1689,7 @@ void Scene::playerReaction() {
 						break;
 					}
 				} else {
-					player->setField638(player->getReactionValue(i));
+					player->inventory.selectItem(player->inventory[i]);
 				}
 				break;
 			}
@@ -1706,7 +1702,7 @@ void Scene::playerReaction() {
 
 void Scene::hitAreaChapter2(int32 id) {
 	if (id == 783)
-		getActor()->setField638(6);
+		getActor()->inventory.selectItem(6);
 }
 
 void Scene::hitAreaChapter7(int32 id) {
@@ -2358,8 +2354,7 @@ void Scene::changePlayerUpdate(ActorIndex index) {
 	actor->setPosition(player->getPoint1()->x + player->getPoint2()->x, player->getPoint1()->y + player->getPoint2()->y, player->getDirection(), 0);
 	player->hide();
 
-	for (uint i = 0; i < 8; i++)
-		actor->setReaction(i, player->getReactionValue(i));
+	actor->inventory.copyFrom(player->inventory);
 }
 
 //////////////////////////////////////////////////////////////////////////
@@ -2419,7 +2414,7 @@ bool Scene::drawScene() {
 
 	Actor *player = getActor();
 	if (player->getStatus() == kActorStatusShowingInventory || player->getStatus() == kActorStatus10)
-		player->updateAndDraw();
+		player->drawInventory();
 	else
 		player->setNumberFlag01(0);
 
diff --git a/engines/asylum/views/scene.h b/engines/asylum/views/scene.h
index 69135a54b1..4302400fc0 100644
--- a/engines/asylum/views/scene.h
+++ b/engines/asylum/views/scene.h
@@ -401,10 +401,7 @@ private:
 	 */
 	void handleHit(int32 index, HitType type);
 
-	/**
-	 * Handle player reaction
-	 */
-	void playerReaction();
+	void clickInventory();
 
 	void hitAreaChapter2(int32 id);
 	bool _isCTRLPressed;




More information about the Scummvm-git-logs mailing list