[Scummvm-cvs-logs] SF.net SVN: scummvm: [29060] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sun Sep 23 22:17:50 CEST 2007


Revision: 29060
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29060&view=rev
Author:   peres001
Date:     2007-09-23 13:17:50 -0700 (Sun, 23 Sep 2007)

Log Message:
-----------
Moved most of inventory-related code inside classes Inventory and InventoryRenderer. Shift is not completed, as new code doesn't handle selections yet (falling back to existent code).

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/exec_ns.cpp
    scummvm/trunk/engines/parallaction/inventory.cpp
    scummvm/trunk/engines/parallaction/inventory.h
    scummvm/trunk/engines/parallaction/menu.cpp
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h
    scummvm/trunk/engines/parallaction/parallaction_br.cpp
    scummvm/trunk/engines/parallaction/parallaction_ns.cpp
    scummvm/trunk/engines/parallaction/saveload.cpp

Modified: scummvm/trunk/engines/parallaction/exec_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_ns.cpp	2007-09-23 17:00:35 UTC (rev 29059)
+++ scummvm/trunk/engines/parallaction/exec_ns.cpp	2007-09-23 20:17:50 UTC (rev 29060)
@@ -641,13 +641,14 @@
 
 int16 Parallaction::pickupItem(Zone *z) {
 	int r = addInventoryItem(z->u.get->_icon);
-	if (r == 0)
+	if (r != -1)
 		addJob(kJobRemovePickedItem, z, kPriority17 );
 
-	return r;
+	return (r == -1);
 }
 
 void Parallaction_ns::jobRemovePickedItem(void *parm, Job *j) {
+	printf("picking up item\n");
 
 	Zone *z = (Zone*)parm;
 

Modified: scummvm/trunk/engines/parallaction/inventory.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/inventory.cpp	2007-09-23 17:00:35 UTC (rev 29059)
+++ scummvm/trunk/engines/parallaction/inventory.cpp	2007-09-23 20:17:50 UTC (rev 29060)
@@ -47,142 +47,174 @@
 #define INVENTORY_WIDTH 			(INVENTORY_ITEMS_PER_LINE*INVENTORYITEM_WIDTH)
 #define INVENTORY_HEIGHT			(INVENTORY_LINES*INVENTORYITEM_HEIGHT)
 
-static byte		*_buffer;
-uint16			 _numInvLines = 0;
-static Common::Point	 _invPosition;
+Inventory *_inv = 0;
+InventoryRenderer *_re = 0;
 
-InventoryItem _inventory[INVENTORY_MAX_ITEMS] = {
-	{ kZoneDoor,		1 },		// open/close icon
-	{ kZoneExamine, 	3 },		// examine icon
-	{ kZoneGet, 		2 },		// pick up/use icon
-	{ kZoneSpeak,		4 },		// speak icon
-	{ 0,	0 },					// items...
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 },
-	{ 0,	0 }
-};
+//	get inventory item index at position (x,y)
+//	in screen coordinates
+//
+int16 Parallaction::getHoverInventoryItem(int16 x, int16 y) {
+	return _re->hitTest(Common::Point(x,y));
+}
 
 
-int16 getNumUsedSlots() {
-	int16 num = 0;
-	while (num < INVENTORY_MAX_ITEMS && _inventory[num]._id != 0)
-		num++;
-	return num;
+int Parallaction::addInventoryItem(ItemName item) {
+	return _inv->addItem(item);
 }
 
+int Parallaction::addInventoryItem(ItemName item, uint32 value) {
+	return _inv->addItem(item, value);
+}
 
-//	get inventory item index at position (x,y)
-//	in screen coordinates
-//
-int16 Parallaction::getHoverInventoryItem(int16 x, int16 y) {
+void Parallaction::dropItem(uint16 v) {
+	printf("dropItem: %i (# = %i)\n", v, _inv->getNumItems());
+	_inv->removeItem(v);
+	printf("# = %i\n", _inv->getNumItems());
+}
 
-	int16 slot = getNumUsedSlots();
-	slot = (slot + 4) / INVENTORY_ITEMS_PER_LINE;
 
-	Common::Rect r(INVENTORY_WIDTH, _numInvLines * INVENTORYITEM_HEIGHT);
-	r.moveTo(_invPosition);
+bool Parallaction::isItemInInventory(int32 v) {
+	return (_inv->findItem(v) != -1);
+}
 
-	if (!r.contains(Common::Point(x,y)))
-		return -1;
+const InventoryItem* getInventoryItem(int16 pos) {
+	return _inv->getItem(pos);
+}
 
-	return ((x - _invPosition.x) / INVENTORYITEM_WIDTH) + (INVENTORY_ITEMS_PER_LINE * ((y - _invPosition.y) / INVENTORYITEM_HEIGHT));
+int16 getInventoryItemIndex(int16 pos) {
+	return _inv->getItemName(pos);
+}
 
+void initInventory() {
+	_inv = new Inventory(INVENTORY_MAX_ITEMS);
+	_re = new InventoryRenderer(_vm);
+	_re->bindInventory(_inv);
 }
 
-void drawInventoryItem(uint16 pos, InventoryItem *item) {
+void destroyInventory() {
+	delete _inv;
+	delete _re;
+}
 
-	uint16 line = pos / INVENTORY_ITEMS_PER_LINE;
-	uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
+void cleanInventory(bool keepVerbs) {
+	_inv->clear(keepVerbs);
+}
 
+
+
+
+
+void Parallaction_ns::jobShowInventory(void *parm, Job *j) {
 	Common::Rect r;
-	_vm->_char._objs->getRect(0, r);
+	_re->getRect(r);
+	_gfx->copyRect(Gfx::kBitBack, r, _re->getData(), INVENTORY_WIDTH);
+}
 
-	// FIXME: this will end up in a general blit function
-	byte* s = _vm->_char._objs->getData(item->_index);
-	byte* d = _buffer + col * INVENTORYITEM_WIDTH + line * r.height() * INVENTORY_WIDTH;
-	for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) {
-		memcpy(d, s, INVENTORYITEM_WIDTH);
+void Parallaction_ns::jobHideInventory(void *parm, Job *j) {
+	static uint16 count = 0;
+	_engineFlags |= kEngineBlockInput;
 
-		d += INVENTORY_WIDTH;
-		s += INVENTORYITEM_PITCH;
+	count++;
+	if (count == 2) {
+		count = 0;
+		j->_finished = 1;
+		_engineFlags &= ~kEngineBlockInput;
 	}
 
-	return;
+	Common::Rect r;
+	_re->getRect(r);
+	_gfx->restoreBackground(r);
 }
 
+void openInventory() {
+	_re->showInventory();
+}
 
+void closeInventory() {
+	_re->hideInventory();
+}
 
-void refreshInventory() {
-	for (uint16 i = 0; i < INVENTORY_MAX_ITEMS; i++)
-		drawInventoryItem(i, &_inventory[i]);
 
-	return;
+
+InventoryRenderer::InventoryRenderer(Parallaction *vm) : _vm(vm) {
+	_buffer = (byte*)malloc(INVENTORY_WIDTH * INVENTORY_HEIGHT);
 }
 
-int Parallaction::addInventoryItem(uint16 item) {
+InventoryRenderer::~InventoryRenderer() {
+	if (_buffer)
+		free(_buffer);
+	_buffer = 0;
+}
 
-	int16 slot = getNumUsedSlots();
-	if (slot == INVENTORY_MAX_ITEMS)
-		return -1;
+void InventoryRenderer::showInventory() {
+	if (!_inv)
+		error("InventoryRenderer not bound to inventory");
 
-	_inventory[slot]._id = MAKE_INVENTORY_ID(item);
-	_inventory[slot]._index = item;
+	_engineFlags |= kEngineInventory;
 
-	return 0;
-}
+	uint16 lines = getNumLines();
 
+	_pos.x = CLIP(_vm->_mousePos.x - (INVENTORY_WIDTH / 2), 0, (int)(_vm->_screenWidth - INVENTORY_WIDTH));
+	_pos.y = CLIP(_vm->_mousePos.y - 2 - (lines * INVENTORYITEM_HEIGHT), 0, (int)(_vm->_screenHeight - lines * INVENTORYITEM_HEIGHT));
 
-void Parallaction::dropItem(uint16 v) {
+	refresh();
+}
 
-	bool found = false;
-	for (uint16 slot = 0; slot < INVENTORY_MAX_ITEMS - 1; slot++) {
+void InventoryRenderer::hideInventory() {
+	if (!_inv)
+		error("InventoryRenderer not bound to inventory");
 
-		if (v == _inventory[slot]._index) {
-			found = true;
-		}
+	_engineFlags &= ~kEngineInventory;
+}
 
-		if (!found) continue;
+void InventoryRenderer::getRect(Common::Rect& r) const {
+	r.setWidth(INVENTORY_WIDTH);
+	r.setHeight(INVENTORYITEM_HEIGHT * getNumLines());
+	r.moveTo(_pos);
+}
 
-		memcpy(&_inventory[slot], &_inventory[slot+1], sizeof(InventoryItem));
-	}
+ItemPosition InventoryRenderer::hitTest(const Common::Point &p) const {
+	Common::Rect r;
+	getRect(r);
+	if (!r.contains(p))
+		return -1;
 
-	return;
+	return ((p.x - _pos.x) / INVENTORYITEM_WIDTH) + (INVENTORY_ITEMS_PER_LINE * ((p.y - _pos.y) / INVENTORYITEM_HEIGHT));
 }
 
 
-int16 Parallaction::isItemInInventory(int32 v) {
+void InventoryRenderer::drawItem(ItemPosition pos, ItemName name) {
+	uint16 line = pos / INVENTORY_ITEMS_PER_LINE;
+	uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
 
-	for (uint16 slot = 0; slot < INVENTORY_MAX_ITEMS; slot++) {
-		if (_inventory[slot]._id == (uint)v)
-			return 1;
+	Common::Rect r;
+	_vm->_char._objs->getRect(0, r);
+
+	// FIXME: this will end up in a general blit function
+
+	byte* s = _vm->_char._objs->getData(name);
+	byte* d = _buffer + col * INVENTORYITEM_WIDTH + line * r.height() * INVENTORY_WIDTH;
+	for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) {
+		memcpy(d, s, INVENTORYITEM_WIDTH);
+
+		d += INVENTORY_WIDTH;
+		s += INVENTORYITEM_PITCH;
 	}
+}
 
-	return 0;
+int16 InventoryRenderer::getNumLines() const {
+	int16 num = _inv->getNumItems();
+	return (num / INVENTORY_ITEMS_PER_LINE) + ((num % INVENTORY_ITEMS_PER_LINE) > 0 ? 1 : 0);
 }
 
 
+void InventoryRenderer::refresh() {
+	for (uint16 i = 0; i < INVENTORY_MAX_ITEMS; i++) {
+		ItemName name = _inv->getItemName(i);
+		drawItem(i, name);
+	}
+}
+
 void drawBorder(const Common::Rect& r, byte *buffer, byte color) {
 
 	byte *d = buffer + r.left + INVENTORY_WIDTH * r.top;
@@ -203,12 +235,14 @@
 //
 //	draws a color border around the specified position in the inventory
 //
-void highlightInventoryItem(int16 pos, byte color) {
+void highlightInventoryItem(ItemPosition pos, byte color) {
 
 	if (color != 12) color = 19;
 
 	if (pos == -1) return;
 
+	printf("highlight item: %i\n", pos);
+
 	uint16 line = pos / INVENTORY_ITEMS_PER_LINE;
 	uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
 
@@ -217,102 +251,104 @@
 	r.setWidth(INVENTORYITEM_WIDTH);
 	r.moveTo(col * INVENTORYITEM_WIDTH, line * r.height());
 
-	drawBorder(r, _buffer, color);
+	drawBorder(r, _re->getData(), color);
 
 	return;
 }
 
 
-int16 getInventoryItemIndex(int16 pos) {
-	// TODO: should assert against the number of items actually contained,
-	// not the theoretical limit.
-	assert(pos >= 0 && pos < INVENTORY_MAX_ITEMS);
-	return _inventory[pos]._index;
-}
 
 
 
-void Parallaction_ns::jobShowInventory(void *parm, Job *j) {
-//	printf("job_showInventory()...");
 
-	int16 slot = getNumUsedSlots();
-	_numInvLines = (slot + 4) / INVENTORY_ITEMS_PER_LINE;
 
-	Common::Rect r(INVENTORY_WIDTH, _numInvLines * INVENTORYITEM_HEIGHT);
 
-	r.moveTo(_invPosition);
 
-	_gfx->copyRect(Gfx::kBitBack, r, _buffer, INVENTORY_WIDTH);
 
-	return;
-}
 
+Inventory::Inventory(uint16 maxItems) : _maxItems(maxItems), _numItems(0) {
+	_items = (InventoryItem*)calloc(_maxItems, sizeof(InventoryItem));
 
+	addItem(1, kZoneDoor);
+	addItem(3, kZoneExamine);
+	addItem(2, kZoneGet);
+	addItem(4, kZoneSpeak);
+}
 
-void Parallaction_ns::jobHideInventory(void *parm, Job *j) {
-//	printf("job_hideInventory()\n");
 
-	static uint16 count = 0;
+Inventory::~Inventory() {
+	free(_items);
+}
 
-	_engineFlags |= kEngineBlockInput;
+ItemPosition Inventory::addItem(ItemName name, uint32 value) {
+	if (_numItems == INVENTORY_MAX_ITEMS)
+		return -1;
 
-	count++;
-	if (count == 2) {
-		count = 0;
-		j->_finished = 1;
-		_engineFlags &= ~kEngineBlockInput;
-	}
+	if (name == 0)
+		return -1;
 
-	Common::Rect r(INVENTORY_WIDTH, _numInvLines * INVENTORYITEM_HEIGHT);
-	r.moveTo(_invPosition);
+	_items[_numItems]._id = value;
+	_items[_numItems]._index = name;
 
-	_gfx->restoreBackground(r);
+	_numItems++;
 
-	return;
+	return _numItems;
 }
 
+ItemPosition Inventory::addItem(ItemName name) {
+	return addItem(name, MAKE_INVENTORY_ID(name));
+}
 
+ItemPosition Inventory::findItem(ItemName name) const {
+	for (ItemPosition slot = 0; slot < _numItems; slot++) {
+		if (name == _items[slot]._index)
+			return slot;
+	}
 
-void openInventory() {
-	_engineFlags |= kEngineInventory;
+	return -1;
+}
 
-	int16 slot = getNumUsedSlots();
-	uint16 lines = (slot + 4) / INVENTORY_ITEMS_PER_LINE;
+void Inventory::removeItem(ItemName name) {
+	ItemPosition pos = findItem(name);
+	if (pos == -1) {
+		printf("removeItem: name %i not found\n", name);
+		return;
+	}
 
-	_invPosition.x = CLIP(_vm->_mousePos.x - (INVENTORY_WIDTH / 2), 0, (int)(_vm->_screenWidth - INVENTORY_WIDTH));
-	_invPosition.y = CLIP(_vm->_mousePos.y - 2 - (lines * INVENTORYITEM_HEIGHT), 0, (int)(_vm->_screenHeight - lines * INVENTORYITEM_HEIGHT));
+	_numItems--;
 
-	refreshInventory();
+	if (_numItems != pos) {
+		memcpy(&_items[pos], &_items[pos+1], (_numItems - pos) * sizeof(InventoryItem));
+	}
 
-	return;
-
+	_items[_numItems]._id = 0;
+	_items[_numItems]._index = 0;
 }
 
+void Inventory::clear(bool keepVerbs) {
+	uint first = (keepVerbs ? INVENTORY_FIRST_ITEM : 0);
 
+	for (uint16 slot = first; slot < _maxItems; slot++) {
+		_items[slot]._id = 0;
+		_items[slot]._index = 0;
+	}
 
-void closeInventory() {
-	_engineFlags &= ~kEngineInventory;
+	_numItems = first;
 }
 
-void initInventory() {
-	_buffer = (byte*)malloc(INVENTORY_WIDTH * INVENTORY_HEIGHT);
+
+ItemName Inventory::getItemName(ItemPosition pos) const {
+	// TODO: should assert against the number of items actually contained,
+	// not the theoretical limit.
+	assert(pos >= 0 && pos < INVENTORY_MAX_ITEMS);
+	return _items[pos]._index;
 }
 
-void destroyInventory() {
-	if (_buffer)
-		free(_buffer);
-	_buffer = 0;
+const InventoryItem* Inventory::getItem(ItemPosition pos) const {
+	return &_items[pos];
 }
 
-void cleanInventory() {
 
-	for (uint16 slot = INVENTORY_FIRST_ITEM; slot < INVENTORY_MAX_ITEMS; slot++) {
-		_inventory[slot]._id = 0;
-		_inventory[slot]._index = 0;
-	}
 
-	return;
-}
 
-
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/inventory.h
===================================================================
--- scummvm/trunk/engines/parallaction/inventory.h	2007-09-23 17:00:35 UTC (rev 29059)
+++ scummvm/trunk/engines/parallaction/inventory.h	2007-09-23 20:17:50 UTC (rev 29060)
@@ -30,6 +30,7 @@
 
 namespace Parallaction {
 
+class Parallaction;
 
 struct InventoryItem {
 	uint32		_id;            // object name (lowest 16 bits are always zero)
@@ -42,20 +43,77 @@
 
 #define MAKE_INVENTORY_ID(x) (((x) & 0xFFFF) << 16)
 
+void initInventory();
+void destroyInventory();
 
-extern InventoryItem _inventory[];
 
-void initInventory();
-void destroyInventory();
+
 void openInventory();
 void closeInventory();
-void cleanInventory();
-void addInventoryItem(uint16 item);
+void highlightInventoryItem(int16 pos, byte color);
 
+
+void cleanInventory(bool keepVerbs = true);
+const InventoryItem* getInventoryItem(int16 pos);
 int16 getInventoryItemIndex(int16 pos);
-void highlightInventoryItem(int16 pos, byte color);
 
+typedef int16 ItemPosition;
+typedef uint16 ItemName;
 
+class Inventory {
+
+protected:
+	InventoryItem	*_items;
+	uint16			_maxItems;
+	uint16			_numItems;
+
+public:
+	Inventory(uint16 maxItems);
+	virtual ~Inventory();
+
+	ItemPosition addItem(ItemName name, uint32 value);
+	ItemPosition addItem(ItemName item);
+	void removeItem(ItemName name);
+	void clear(bool keepVerbs = true);
+
+	const InventoryItem* getItem(ItemPosition pos) const;
+	ItemName getItemName(ItemPosition pos) const;
+
+	ItemPosition findItem(ItemName name) const;
+
+	int16	getNumItems() const { return _numItems; }
+};
+
+
+
+class InventoryRenderer {
+	Parallaction	*_vm;
+	Inventory 		*_inv;
+	Common::Point	_pos;
+
+	byte			*_buffer;
+
+protected:
+	void drawItem(ItemPosition pos, ItemName name);
+	void refresh();
+
+public:
+	InventoryRenderer(Parallaction *vm);
+	virtual ~InventoryRenderer();
+
+	void bindInventory(Inventory *inv) { _inv = inv; }
+
+	void showInventory();
+	void hideInventory();
+
+	ItemPosition hitTest(const Common::Point &p) const;
+
+	byte*	getData() const { return _buffer; }
+
+	void	getRect(Common::Rect &r) const;
+	int16	getNumLines() const;
+};
+
 } // namespace Parallaction
 
 #endif

Modified: scummvm/trunk/engines/parallaction/menu.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/menu.cpp	2007-09-23 17:00:35 UTC (rev 29059)
+++ scummvm/trunk/engines/parallaction/menu.cpp	2007-09-23 20:17:50 UTC (rev 29060)
@@ -198,7 +198,7 @@
 	_vm->showSlide("lingua");
 	_vm->_gfx->displayString(60, 30, "SELECT LANGUAGE", 1);
 
-	_vm->changeCursor(kCursorArrow);
+	_vm->setArrowCursor();
 
 	do {
 		_vm->updateInput();
@@ -335,7 +335,7 @@
 	Graphics::Surface v14;
 	v14.create(BLOCK_WIDTH, BLOCK_HEIGHT, 1);
 
-	_vm->changeCursor(kCursorArrow);
+	_vm->setArrowCursor();
 	_vm->_soundMan->stopMusic();
 
 	_vm->_gfx->setFont(_vm->_menuFont);

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2007-09-23 17:00:35 UTC (rev 29059)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2007-09-23 20:17:50 UTC (rev 29060)
@@ -303,7 +303,7 @@
 	if (_hasLocationSound)
 		_soundMan->playSfx(_locationSound, 0, true);
 
-	changeCursor(kCursorArrow);
+	_vm->setArrowCursor();
 
 	if (_location._aCommands.size() > 0)
 		runCommands(_location._aCommands);
@@ -413,7 +413,7 @@
 		_hoverZone = NULL;
 		hideLabel(kPriority2);
 		if (hitZone(kZoneYou, _mousePos.x, _mousePos.y) == 0) {
-			changeCursor(kCursorArrow);
+			setArrowCursor();
 		}
 		removeJob(_jRunScripts);
 		_jDrawInventory = addJob(kJobShowInventory, 0, kPriority2);
@@ -422,10 +422,7 @@
 
 	case kEvCloseInventory: // closes inventory and possibly select item
 		closeInventory();
-		if ((data->_inventoryIndex != -1) && (_inventory[data->_inventoryIndex]._id != 0)) {
-			// activates item
-			changeCursor(data->_inventoryIndex);
-		}
+		setInventoryCursor(data->_inventoryIndex);
 		_jRunScripts = addJob(kJobRunScripts, 0, kPriority15);
 		addJob(kJobHideInventory, 0, kPriority20);
 		removeJob(_jDrawInventory);
@@ -437,12 +434,11 @@
 		_procCurrentHoverItem = data->_inventoryIndex;
 		break;
 
-	case kEvWalk: {
+	case kEvWalk:
 		debugC(2, kDebugInput, "processInput: kEvWalk");
 		_hoverZone = NULL;
-		changeCursor(kCursorArrow);
+		setArrowCursor();
 		_char.scheduleWalk(data->_mousePos.x, data->_mousePos.y);
-		}
 		break;
 
 	case kEvQuitGame:
@@ -452,13 +448,13 @@
 	case kEvSaveGame:
 		_hoverZone = NULL;
 		saveGame();
-		changeCursor(kCursorArrow);
+		setArrowCursor();
 		break;
 
 	case kEvLoadGame:
 		_hoverZone = NULL;
 		loadGame();
-		changeCursor(kCursorArrow);
+		setArrowCursor();
 		break;
 
 	}
@@ -552,7 +548,7 @@
 			}
 
 //			beep();
-			changeCursor(kCursorArrow);
+			setArrowCursor();
 			return &_input;
 		}
 
@@ -573,11 +569,11 @@
 		if ((_engineFlags & kEngineDragging) == 0) return &_input;
 
 		_engineFlags &= ~kEngineDragging;
-		Zone *z = hitZone(kZoneMerge, _activeItem._index, _inventory[_input._inventoryIndex]._index);
+		Zone *z = hitZone(kZoneMerge, _activeItem._index, getInventoryItemIndex(_input._inventoryIndex));
 
 		if (z != NULL) {
-			dropItem(z->u.merge->_obj1 - 4);
-			dropItem(z->u.merge->_obj2 - 4);
+			dropItem(z->u.merge->_obj1);
+			dropItem(z->u.merge->_obj2);
 			addInventoryItem(z->u.merge->_obj3);
 			runCommands(z->_commands);
 		}
@@ -623,31 +619,8 @@
 	g_system->showMouse(visible);
 }
 
-//	changes the mouse pointer
-//	index 0 means standard pointer (from pointer.cnv)
-//	index > 0 means inventory item
-//
-void Parallaction::changeCursor(int32 index) {
 
-	if (index == kCursorArrow) {		// standard mouse pointer
 
-		debugC(1, kDebugInput, "changeCursor(%i), label: %p", index, (const void*)_jDrawLabel);
-
-		hideLabel(kPriority15);
-
-		_activeItem._id = 0;
-
-	} else {
-		_activeItem._id = _inventory[index]._id;
-	}
-
-	setMousePointer(index);
-
-	return;
-}
-
-
-
 void Parallaction::freeCharacter() {
 	debugC(1, kDebugExec, "freeCharacter()");
 

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2007-09-23 17:00:35 UTC (rev 29059)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2007-09-23 20:17:50 UTC (rev 29060)
@@ -398,7 +398,6 @@
 	} _instRunCtxt;
 
 
-	void 		changeCursor(int32 index);
 	void		showCursor(bool visible);
 
 	Job 		*addJob(uint functionId, void *parm, uint16 tag);
@@ -553,17 +552,20 @@
 
 	void 		freeCharacter();
 
-	int 		addInventoryItem(uint16 item);
-	void 		dropItem(uint16 item);
+
+	int 		addInventoryItem(ItemName item, uint32 value);
+	int 		addInventoryItem(ItemName item);
+	void 		dropItem(ItemName item);
 	int16 		pickupItem(Zone *z);
-	int16 		isItemInInventory(int32 v);
+	bool 		isItemInInventory(int32 v);
 	int16		getHoverInventoryItem(int16 x, int16 y);
 
 public:
 	virtual	void callFunction(uint index, void* parm) { }
 	virtual void renderLabel(Graphics::Surface *cnv, char *text) { }
-	virtual void setMousePointer(int16 index) = 0;
 
+	virtual void setArrowCursor() = 0;
+	virtual void setInventoryCursor(int pos) = 0;
 
 	virtual void parseLocation(const char* name) = 0;
 
@@ -603,7 +605,7 @@
 
 	virtual	void callFunction(uint index, void* parm);
 	void renderLabel(Graphics::Surface *cnv, char *text);
-	void setMousePointer(int16 index);
+	void setMousePointer(uint32 value);
 
 	void	initJobs();
 
@@ -626,6 +628,10 @@
 	void changeLocation(char *location);
 	void changeCharacter(const char *name);
 
+	void setArrowCursor();
+	void setInventoryCursor(int pos);
+
+
 	void doLoadGame(uint16 slot);
 	void doSaveGame(uint16 slot, const char* name);
 	int  buildSaveFileList(Common::StringList& l);
@@ -908,6 +914,10 @@
 	void 		initParsers();
 	void		initJobs();
 
+	void setArrowCursor();
+	void setInventoryCursor(int pos);
+
+
 	typedef void (Parallaction_br::*JobFn)(void*, Job*);
 	const JobFn 	*_jobsFn;
 	JobOpcode* 		createJobOpcode(uint functionId, Job *job);

Modified: scummvm/trunk/engines/parallaction/parallaction_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction_br.cpp	2007-09-23 17:00:35 UTC (rev 29059)
+++ scummvm/trunk/engines/parallaction/parallaction_br.cpp	2007-09-23 20:17:50 UTC (rev 29060)
@@ -386,4 +386,17 @@
 	return new OpcodeImpl2<Parallaction_br>(this, _jobsFn[functionId], job);
 }
 
+
+void Parallaction_br::setArrowCursor() {
+
+
+
+}
+
+void Parallaction_br::setInventoryCursor(int pos) {
+
+
+
+}
+
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/parallaction_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2007-09-23 17:00:35 UTC (rev 29059)
+++ scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2007-09-23 20:17:50 UTC (rev 29060)
@@ -139,34 +139,48 @@
 	return;
 }
 
-void Parallaction_ns::setMousePointer(int16 index) {
+void Parallaction_ns::setArrowCursor() {
 
-	if (index == kCursorArrow) {		// standard mouse pointer
+	debugC(1, kDebugInput, "setting mouse cursor to arrow");
 
-		_system->setMouseCursor(_mouseArrow, MOUSEARROW_WIDTH, MOUSEARROW_HEIGHT, 0, 0, 0);
-		_system->showMouse(true);
+	// this stuff is needed to avoid artifacts with labels and selected items when switching cursors
+	hideLabel(kPriority15);
+	_activeItem._id = 0;
 
-	} else {
-		// inventory item pointer
-		byte *v8 = (byte*)_mouseComposedArrow->pixels;
+	_system->setMouseCursor(_mouseArrow, MOUSEARROW_WIDTH, MOUSEARROW_HEIGHT, 0, 0, 0);
+	_system->showMouse(true);
 
-		// FIXME: destination offseting is not clear
-		byte* s = _char._objs->getData(getInventoryItemIndex(index));
-		byte* d = v8 + 7 + MOUSECOMBO_WIDTH * 7;
+}
 
-		for (uint i = 0; i < INVENTORYITEM_HEIGHT; i++) {
-			memcpy(d, s, INVENTORYITEM_WIDTH);
+void Parallaction_ns::setInventoryCursor(int pos) {
 
-			s += INVENTORYITEM_PITCH;
-			d += MOUSECOMBO_WIDTH;
-		}
+	if (pos == -1)
+		return;
 
-		_system->setMouseCursor(v8, MOUSECOMBO_WIDTH, MOUSECOMBO_HEIGHT, 0, 0, 0);
+	const InventoryItem *item = getInventoryItem(pos);
+	if (item->_index == 0)
+		return;
+
+	_activeItem._id = item->_id;
+
+	byte *v8 = (byte*)_mouseComposedArrow->pixels;
+
+	// FIXME: destination offseting is not clear
+	byte* s = _char._objs->getData(item->_index);
+	byte* d = v8 + 7 + MOUSECOMBO_WIDTH * 7;
+
+	for (uint i = 0; i < INVENTORYITEM_HEIGHT; i++) {
+		memcpy(d, s, INVENTORYITEM_WIDTH);
+
+		s += INVENTORYITEM_PITCH;
+		d += MOUSECOMBO_WIDTH;
 	}
 
-	return;
+	_system->setMouseCursor(v8, MOUSECOMBO_WIDTH, MOUSECOMBO_HEIGHT, 0, 0, 0);
+
 }
 
+
 void Parallaction_ns::callFunction(uint index, void* parm) {
 	assert(index < 25);	// magic value 25 is maximum # of callables for Nippon Safes
 
@@ -238,7 +252,7 @@
 
 	_hoverZone = NULL;
 	if (_engineFlags & kEngineBlockInput) {
-		changeCursor( kCursorArrow );
+		setArrowCursor();
 	}
 
 	_animations.remove(&_char._ani);

Modified: scummvm/trunk/engines/parallaction/saveload.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/saveload.cpp	2007-09-23 17:00:35 UTC (rev 29059)
+++ scummvm/trunk/engines/parallaction/saveload.cpp	2007-09-23 20:17:50 UTC (rev 29060)
@@ -136,12 +136,19 @@
 	}
 	_locationNames[_si][0] = '\0';
 
+	cleanInventory(false);
+	ItemName name;
+	uint32 value;
+
 	for (_si = 0; _si < 30; _si++) {
 		f->readLine(s, 15);
-		_inventory[_si]._id = atoi(s);
+		value = atoi(s);
 
 		f->readLine(s, 15);
-		_inventory[_si]._index = atoi(s);
+		name = atoi(s);
+
+		printf("loadGame: inv[%i].id = %i, inv[%i].index = %i\n", _si, value, _si, name);
+		addInventoryItem(name, value);
 	}
 
 	delete f;
@@ -203,8 +210,10 @@
 		f->writeString(s);
 	}
 
+	const InventoryItem *item;
 	for (uint16 _si = 0; _si < 30; _si++) {
-		sprintf(s, "%u\n%d\n", _inventory[_si]._id, _inventory[_si]._index);
+		item = getInventoryItem(_si);
+		sprintf(s, "%u\n%d\n", item->_id, item->_index);
 		f->writeString(s);
 	}
 
@@ -373,7 +382,7 @@
 	GUI::TimedMessageDialog dialog("Loading game...", 1500);
 	dialog.runModal();
 
-	changeCursor(kCursorArrow);
+	setArrowCursor();
 
 	return;
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list