[Scummvm-git-logs] scummvm master -> 91e714964e172601db16b6bfb5a08cba3557a6a0

dreammaster dreammaster at scummvm.org
Sat Mar 17 02:05:46 CET 2018


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

Summary:
fe80dcb4fe XEEN: Don't add monsters in setSpeedTable if they're dead
91e714964e XEEN: Refactor item selection dialog into it's own dialog class


Commit: fe80dcb4fec0dcf033292523a2e3fa9bb5213574
    https://github.com/scummvm/scummvm/commit/fe80dcb4fec0dcf033292523a2e3fa9bb5213574
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2018-03-16T20:23:22-04:00

Commit Message:
XEEN: Don't add monsters in setSpeedTable if they're dead

I think this should fix a crash I rarely got in doMonsterTurn

Changed paths:
    engines/xeen/combat.cpp


diff --git a/engines/xeen/combat.cpp b/engines/xeen/combat.cpp
index 603b6ae..6c293bc 100644
--- a/engines/xeen/combat.cpp
+++ b/engines/xeen/combat.cpp
@@ -1108,7 +1108,7 @@ void Combat::setSpeedTable() {
 	// Populate the _speedTable list with the character/monster indexes
 	// in order of attacking speed
 	_speedTable.clear();
-	for (; maxSpeed >= 0; --maxSpeed) {
+	for (; maxSpeed > 0; --maxSpeed) {
 		for (uint idx = 0; idx < charSpeeds.size(); ++idx) {
 			if (charSpeeds[idx] == maxSpeed)
 				_speedTable.push_back(idx);


Commit: 91e714964e172601db16b6bfb5a08cba3557a6a0
    https://github.com/scummvm/scummvm/commit/91e714964e172601db16b6bfb5a08cba3557a6a0
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2018-03-16T21:05:40-04:00

Commit Message:
XEEN: Refactor item selection dialog into it's own dialog class

Changed paths:
    engines/xeen/dialogs/dialogs_items.cpp
    engines/xeen/dialogs/dialogs_items.h


diff --git a/engines/xeen/dialogs/dialogs_items.cpp b/engines/xeen/dialogs/dialogs_items.cpp
index 24d4603..82eeb9f 100644
--- a/engines/xeen/dialogs/dialogs_items.cpp
+++ b/engines/xeen/dialogs/dialogs_items.cpp
@@ -744,62 +744,16 @@ int ItemsDialog::doItemOptions(Character &c, int actionIndex, int itemIndex, Ite
 	Windows &windows = *_vm->_windows;
 	bool isDarkCc = _vm->_files->_isDarkCc;
 
-	XeenItem *itemCategories[4] = { &c._weapons[0], &c._armor[0], &c._accessories[0], &c._misc[0] };
-	XeenItem *items = itemCategories[category];
-	if (!items[0]._id)
+	InventoryItems &items = c._items[category];
+	if (items[0].empty())
 		// Inventory is empty
 		return category == CATEGORY_MISC ? 0 : 2;
 
-	Window &w = windows[11];
-	SpriteResource escSprites;
-	if (itemIndex < 0 || itemIndex > 8) {
-		saveButtons();
-
-		escSprites.load("esc.icn");
-		addButton(Common::Rect(235, 111, 259, 131), Common::KEYCODE_ESCAPE, &escSprites);
-		addButton(Common::Rect(8, 20, 263, 28), Common::KEYCODE_1);
-		addButton(Common::Rect(8, 29, 263, 37), Common::KEYCODE_2);
-		addButton(Common::Rect(8, 38, 263, 46), Common::KEYCODE_3);
-		addButton(Common::Rect(8, 47, 263, 55), Common::KEYCODE_4);
-		addButton(Common::Rect(8, 56, 263, 64), Common::KEYCODE_5);
-		addButton(Common::Rect(8, 65, 263, 73), Common::KEYCODE_6);
-		addButton(Common::Rect(8, 74, 263, 82), Common::KEYCODE_7);
-		addButton(Common::Rect(8, 83, 263, 91), Common::KEYCODE_8);
-		addButton(Common::Rect(8, 92, 263, 100), Common::KEYCODE_9);
-
-		w.open();
-		w.writeString(Common::String::format(Res.WHICH_ITEM, Res.ITEM_ACTIONS[actionIndex]));
-		_iconSprites.draw(0, 0, Common::Point(235, 111));
-		w.update();
-
-		while (!_vm->shouldExit()) {
-			while (!_buttonValue) {
-				events.pollEventsAndWait();
-				checkEvents(_vm);
-				if (_vm->shouldExit())
-					return false;
-			}
-
-			if (_buttonValue == Common::KEYCODE_ESCAPE) {
-				itemIndex = -1;
-				break;
-			} else if (_buttonValue >= Common::KEYCODE_1 && _buttonValue <= Common::KEYCODE_9) {
-				// Check whether there's an item at the selected index
-				int selectedIndex = _buttonValue - Common::KEYCODE_1;
-				if (!items[selectedIndex]._id)
-					continue;
-
-				itemIndex = selectedIndex;
-				break;
-			}
-		}
-
-		w.close();
-		restoreButtons();
-	}
+	if (itemIndex < 0 || itemIndex > 8)
+		itemIndex = ItemSelectionDialog::show(actionIndex, items);
 
 	if (itemIndex != -1) {
-		XeenItem &item = c._items[category][itemIndex];
+		XeenItem &item = items[itemIndex];
 
 		switch (mode) {
 		case ITEMMODE_CHAR_INFO:
@@ -1032,4 +986,67 @@ void ItemsDialog::itemToGold(Character &c, int itemIndex, ItemCategory category,
 	}
 }
 
+/*------------------------------------------------------------------------*/
+
+int ItemSelectionDialog::show(int actionIndex, InventoryItems &items) {
+	ItemSelectionDialog *dlg = new ItemSelectionDialog(g_vm, actionIndex, items);
+	int result = dlg->execute();
+	delete dlg;
+
+	return result;
+}
+
+void ItemSelectionDialog::loadButtons() {
+	_icons.load("esc.icn");
+	addButton(Common::Rect(235, 111, 259, 131), Common::KEYCODE_ESCAPE, &_icons);
+	addButton(Common::Rect(8, 20, 263, 28), Common::KEYCODE_1);
+	addButton(Common::Rect(8, 29, 263, 37), Common::KEYCODE_2);
+	addButton(Common::Rect(8, 38, 263, 46), Common::KEYCODE_3);
+	addButton(Common::Rect(8, 47, 263, 55), Common::KEYCODE_4);
+	addButton(Common::Rect(8, 56, 263, 64), Common::KEYCODE_5);
+	addButton(Common::Rect(8, 65, 263, 73), Common::KEYCODE_6);
+	addButton(Common::Rect(8, 74, 263, 82), Common::KEYCODE_7);
+	addButton(Common::Rect(8, 83, 263, 91), Common::KEYCODE_8);
+	addButton(Common::Rect(8, 92, 263, 100), Common::KEYCODE_9);
+}
+
+int ItemSelectionDialog::execute() {
+	EventsManager &events = *g_vm->_events;
+	Windows &windows = *g_vm->_windows;
+	Window &w = windows[13];
+
+	w.open();
+	w.writeString(Common::String::format(Res.WHICH_ITEM, Res.ITEM_ACTIONS[_actionIndex]));
+	_icons.draw(0, 0, Common::Point(235, 111));
+	w.update();
+
+	int itemIndex = -1;
+	while (!_vm->shouldExit()) {
+		_buttonValue = 0;
+		while (!_buttonValue) {
+			events.pollEventsAndWait();
+			checkEvents(_vm);
+			if (_vm->shouldExit())
+				return false;
+		}
+
+		if (_buttonValue == Common::KEYCODE_ESCAPE) {
+			itemIndex = -1;
+			break;
+		}
+		else if (_buttonValue >= Common::KEYCODE_1 && _buttonValue <= Common::KEYCODE_9) {
+			// Check whether there's an item at the selected index
+			int selectedIndex = _buttonValue - Common::KEYCODE_1;
+			if (!_items[selectedIndex]._id)
+				continue;
+
+			itemIndex = selectedIndex;
+			break;
+		}
+	}
+
+	w.close();
+	return itemIndex;
+}
+
 } // End of namespace Xeen
diff --git a/engines/xeen/dialogs/dialogs_items.h b/engines/xeen/dialogs/dialogs_items.h
index 3393064..cec7d24 100644
--- a/engines/xeen/dialogs/dialogs_items.h
+++ b/engines/xeen/dialogs/dialogs_items.h
@@ -71,6 +71,38 @@ public:
 	static Character *show(XeenEngine *vm, Character *c, ItemsMode mode);
 };
 
+class ItemSelectionDialog : public ButtonContainer {
+private:
+	SpriteResource _icons;
+	int _actionIndex;
+	InventoryItems &_items;
+
+	ItemSelectionDialog(XeenEngine *vm, int actionIndex, InventoryItems &items) : ButtonContainer(vm),
+			_actionIndex(actionIndex), _items(items) {
+		loadButtons();
+	}
+
+	/**
+	 * Executes the dialog
+	 * @returns					Selected item index
+	 */
+	int execute();
+
+	/**
+	 * Loads buttons
+	 */
+	void loadButtons();
+public:
+	/**
+	 * Shows the dialog
+	 * @param actionIndex		Current action type
+	 * @param items				Currently active items category
+	 * @returns					Selected item index
+	 */
+	static int show(int actionIndex, InventoryItems &items);
+};
+
+
 } // End of namespace Xeen
 
 #endif /* XEEN_DIALOGS_ITEMS_H */





More information about the Scummvm-git-logs mailing list