[Scummvm-git-logs] scummvm master -> 41d7c1f66e8fd7e3a8e833edb616ba346d84570f

dreammaster dreammaster at scummvm.org
Fri Dec 1 02:31:40 CET 2017


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:
41d7c1f66e XEEN: Added enum for consumable types and party/bank use


Commit: 41d7c1f66e8fd7e3a8e833edb616ba346d84570f
    https://github.com/scummvm/scummvm/commit/41d7c1f66e8fd7e3a8e833edb616ba346d84570f
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-11-30T20:30:56-05:00

Commit Message:
XEEN: Added enum for consumable types and party/bank use

Changed paths:
    engines/xeen/dialogs_items.cpp
    engines/xeen/dialogs_spells.cpp
    engines/xeen/party.cpp
    engines/xeen/party.h
    engines/xeen/town.cpp
    engines/xeen/town.h


diff --git a/engines/xeen/dialogs_items.cpp b/engines/xeen/dialogs_items.cpp
index 8401635..867bc7d 100644
--- a/engines/xeen/dialogs_items.cpp
+++ b/engines/xeen/dialogs_items.cpp
@@ -909,7 +909,7 @@ int ItemsDialog::doItemOptions(Character &c, int actionIndex, int itemIndex, Ite
 				Common::String desc = c._items[category].getFullDescription(itemIndex);
 				if (Confirm::show(_vm, Common::String::format(Res.BUY_X_FOR_Y_GOLD,
 						desc.c_str(), cost))) {
-					if (party.subtract(0, cost, 0, WT_FREEZE_WAIT)) {
+					if (party.subtract(CONS_GOLD, cost, WHERE_PARTY, WT_FREEZE_WAIT)) {
 						if (isDarkCc) {
 							sound.stopSound();
 							sound.playSound("choice2.voc");
@@ -990,7 +990,7 @@ int ItemsDialog::doItemOptions(Character &c, int actionIndex, int itemIndex, Ite
 					c._items[category].getFullDescription(itemIndex).c_str(),
 					cost);
 
-				if (Confirm::show(_vm, msg) && party.subtract(0, cost, 0)) {
+				if (Confirm::show(_vm, msg) && party.subtract(CONS_GOLD, cost, WHERE_PARTY)) {
 					item._bonusFlags &= ~ITEMFLAG_BROKEN;
 				}
 			}
@@ -1003,7 +1003,7 @@ int ItemsDialog::doItemOptions(Character &c, int actionIndex, int itemIndex, Ite
 				c._items[category].getFullDescription(itemIndex).c_str(),
 				cost);
 
-			if (Confirm::show(_vm, msg) && party.subtract(0, cost, 0)) {
+			if (Confirm::show(_vm, msg) && party.subtract(CONS_GOLD, cost, WHERE_PARTY)) {
 				Common::String details = c._items[category].getIdentifiedDetails(itemIndex);
 				Common::String desc = c._items[category].getFullDescription(itemIndex);
 				Common::String str = Common::String::format(Res.IDENTIFY_ITEM_MSG,
diff --git a/engines/xeen/dialogs_spells.cpp b/engines/xeen/dialogs_spells.cpp
index f83a41c..abdc802 100644
--- a/engines/xeen/dialogs_spells.cpp
+++ b/engines/xeen/dialogs_spells.cpp
@@ -236,7 +236,7 @@ Character *SpellsDialog::execute(ButtonContainer *priorDialog, Character *c, int
 						Common::String::format(Res.SPELLS_PURCHASE, spellName.c_str(), spellCost);
 
 					if (Confirm::show(_vm, msg, castingCopy + 1)) {
-						if (party.subtract(0, spellCost, 0, WT_FREEZE_WAIT)) {
+						if (party.subtract(CONS_GOLD, spellCost, WHERE_PARTY, WT_FREEZE_WAIT)) {
 							++c->_spells[spellIndex];
 							sound.stopSound();
 							intf._overallFrame = 0;
diff --git a/engines/xeen/party.cpp b/engines/xeen/party.cpp
index 901fe61..732e9fa 100644
--- a/engines/xeen/party.cpp
+++ b/engines/xeen/party.cpp
@@ -478,54 +478,52 @@ void Party::handleLight() {
 		(map.mazeData()._mazeFlags2 & FLAG_IS_DARK) == 0 ? 4 : 0;
 }
 
-int Party::subtract(int mode, uint amount, int whereId, ErrorWaitType wait) {
-	switch (mode) {
-	case 0:
+int Party::subtract(ConsumableType consumableId, uint amount, PartyBank whereId, ErrorWaitType wait) {
+	switch (consumableId) {
+	case CONS_GOLD:
 		// Gold
 		if (whereId) {
 			if (amount <= _bankGold) {
 				_bankGold -= amount;
 			} else {
-				notEnough(0, whereId, false, wait);
+				notEnough(CONS_GOLD, whereId, false, wait);
 				return false;
 			}
-		}
-		else {
+		} else {
 			if (amount <= _gold) {
 				_gold -= amount;
 			} else {
-				notEnough(0, whereId, false, wait);
+				notEnough(CONS_GOLD, whereId, false, wait);
 				return false;
 			}
 		}
 		break;
 
-	case 1:
+	case CONS_GEMS:
 		// Gems
 		if (whereId) {
 			if (amount <= _bankGems) {
 				_bankGems -= amount;
 			} else {
-				notEnough(0, whereId, false, wait);
+				notEnough(CONS_GEMS, whereId, false, wait);
 				return false;
 			}
-		}
-		else {
+		} else {
 			if (amount <= _gems) {
 				_gems -= amount;
 			} else {
-				notEnough(0, whereId, false, wait);
+				notEnough(CONS_GEMS, whereId, false, wait);
 				return false;
 			}
 		}
 		break;
 
-	case 2:
+	case CONS_FOOD:
 		// Food
 		if (amount > _food) {
 			_food -= amount;
 		} else {
-			notEnough(5, 0, 0, wait);
+			notEnough(CONS_FOOD, WHERE_PARTY, 0, wait);
 			return false;
 		}
 		break;
@@ -537,7 +535,8 @@ int Party::subtract(int mode, uint amount, int whereId, ErrorWaitType wait) {
 	return true;
 }
 
-void Party::notEnough(int consumableId, int whereId, bool mode, ErrorWaitType wait) {
+void Party::notEnough(ConsumableType consumableId, PartyBank whereId, bool mode, ErrorWaitType wait) {
+	assert(consumableId < 4 && whereId < 2);
 	Common::String msg = Common::String::format(
 		mode ? Res.NO_X_IN_THE_Y : Res.NOT_ENOUGH_X_IN_THE_Y,
 		Res.CONSUMABLE_NAMES[consumableId], Res.WHERE_NAMES[whereId]);
@@ -870,11 +869,11 @@ bool Party::giveTake(int takeMode, uint takeVal, int giveMode, uint giveVal, int
 		changeTime(takeVal);
 		break;
 	case 34:
-		if (!subtract(0, takeVal, 0, WT_3))
+		if (!subtract(CONS_GOLD, takeVal, WHERE_PARTY, WT_3))
 			return true;
 		break;
 	case 35:
-		if (!subtract(1, takeVal, 0, WT_3))
+		if (!subtract(CONS_GEMS, takeVal, WHERE_PARTY, WT_3))
 			return true;
 		break;
 	case 37:
@@ -959,7 +958,7 @@ bool Party::giveTake(int takeMode, uint takeVal, int giveMode, uint giveVal, int
 		ps._level._permanent -= takeVal;
 		break;
 	case 65:
-		if (!subtract(2, takeVal, 0, WT_3))
+		if (!subtract(CONS_FOOD, takeVal, WHERE_PARTY, WT_3))
 			return true;
 		break;
 	case 69:
diff --git a/engines/xeen/party.h b/engines/xeen/party.h
index 55e18fc..f6df5ff 100644
--- a/engines/xeen/party.h
+++ b/engines/xeen/party.h
@@ -40,6 +40,14 @@ enum Direction {
 
 enum Difficulty { ADVENTURER = 0, WARRIOR = 1 };
 
+enum ConsumableType {
+	CONS_GOLD = 0, CONS_GEMS = 1, CONS_FOOD = 2, CONS_CONDITION = 3
+};
+
+enum PartyBank {
+	WHERE_PARTY = 0, WHERE_BANK = 1
+};
+
 #define ITEMS_COUNT 36
 #define TOTAL_CHARACTERS 30
 #define XEEN_TOTAL_CHARACTERS 24
@@ -191,9 +199,9 @@ public:
 
 	void handleLight();
 
-	int subtract(int mode, uint amount, int whereId, ErrorWaitType wait = WT_FREEZE_WAIT);
+	int subtract(ConsumableType consumableId, uint amount, PartyBank whereId, ErrorWaitType wait = WT_FREEZE_WAIT);
 
-	void notEnough(int consumableId, int whereId, bool mode, ErrorWaitType wait);
+	void notEnough(ConsumableType consumableId, PartyBank whereId, bool mode, ErrorWaitType wait);
 
 	void checkPartyDead();
 
diff --git a/engines/xeen/town.cpp b/engines/xeen/town.cpp
index 74aad09..2a3f58e 100644
--- a/engines/xeen/town.cpp
+++ b/engines/xeen/town.cpp
@@ -529,13 +529,13 @@ Character *Town::doTownOptions(Character *c) {
 
 Character *Town::doBankOptions(Character *c) {
 	if (_buttonValue == Common::KEYCODE_d)
-		_buttonValue = 0;
+		_buttonValue = WHERE_PARTY;
 	else if (_buttonValue == Common::KEYCODE_w)
-		_buttonValue = 1;
+		_buttonValue = WHERE_BANK;
 	else
 		return c;
 
-	depositWithdrawl(_buttonValue);
+	depositWithdrawl((PartyBank)_buttonValue);
 	return c;
 }
 
@@ -620,7 +620,7 @@ Character *Town::doTavernOptions(Character *c) {
 	case Common::KEYCODE_d:
 		// Drink
 		if (!c->noActions()) {
-			if (party.subtract(0, 1, 0, WT_2)) {
+			if (party.subtract(CONS_GOLD, 1, WHERE_PARTY, WT_2)) {
 				sound.stopSound();
 				sound.playSound("gulp.voc");
 				_v21 = 1;
@@ -678,7 +678,7 @@ Character *Town::doTavernOptions(Character *c) {
 		if (YesNo::show(_vm, false, true)) {
 			if (party._food >= _v22) {
 				ErrorScroll::show(_vm, Res.FOOD_PACKS_FULL, WT_2);
-			} else if (party.subtract(0, _v23, 0, WT_2)) {
+			} else if (party.subtract(CONS_GOLD, _v23, WHERE_PARTY, WT_2)) {
 				party._food = _v22;
 				sound.stopSound();
 				sound.playSound(isDarkCc ? "thanks2.voc" : "thankyou.voc", 1);
@@ -757,7 +757,7 @@ Character *Town::doTavernOptions(Character *c) {
 					drawButtons(&windows[0]);
 					windows[10].update();
 					townWait();
-				} else if (party.subtract(0, 1, 0, WT_2)) {
+				} else if (party.subtract(CONS_GOLD, 1, WHERE_PARTY, WT_2)) {
 					sound.stopSound();
 					sound.playSound(isDarkCc ? "thanks2.voc" : "thankyou.voc", 1);
 
@@ -817,7 +817,7 @@ Character *Town::doTempleOptions(Character *c) {
 		break;
 
 	case Common::KEYCODE_d:
-		if (_donation && party.subtract(0, _donation, 0, WT_2)) {
+		if (_donation && party.subtract(CONS_GOLD, _donation, WHERE_PARTY, WT_2)) {
 			sound.stopSound();
 			sound.playSound("coina.voc", 1);
 			_dayOfWeek = (_dayOfWeek + 1) / 10;
@@ -842,7 +842,7 @@ Character *Town::doTempleOptions(Character *c) {
 		break;
 
 	case Common::KEYCODE_h:
-		if (_healCost && party.subtract(0, _healCost, 0, WT_2)) {
+		if (_healCost && party.subtract(CONS_GOLD, _healCost, WHERE_PARTY, WT_2)) {
 			c->_magicResistence._temporary = 0;
 			c->_energyResistence._temporary = 0;
 			c->_poisonResistence._temporary = 0;
@@ -869,7 +869,7 @@ Character *Town::doTempleOptions(Character *c) {
 		break;
 
 	case Common::KEYCODE_u:
-		if (_uncurseCost && party.subtract(0, _uncurseCost, 0, WT_2)) {
+		if (_uncurseCost && party.subtract(CONS_GOLD, _uncurseCost, WHERE_PARTY, WT_2)) {
 			for (int idx = 0; idx < 9; ++idx) {
 				c->_weapons[idx]._bonusFlags &= ~ITEMFLAG_CURSED;
 				c->_armor[idx]._bonusFlags &= ~ITEMFLAG_CURSED;
@@ -928,7 +928,7 @@ Character *Town::doTrainingOptions(Character *c) {
 			sound.playSound(name);
 
 		} else if (!c->noActions()) {
-			if (party.subtract(0, (c->_level._permanent * c->_level._permanent) * 10, 0, WT_2)) {
+			if (party.subtract(CONS_GOLD, (c->_level._permanent * c->_level._permanent) * 10, WHERE_PARTY, WT_2)) {
 				_drawFrameIndex = 0;
 				sound.stopSound();
 				sound.playSound(isDarkCc ? "prtygd.voc" : "trainin2.voc", 1);
@@ -957,13 +957,13 @@ Character *Town::doTrainingOptions(Character *c) {
 	return c;
 }
 
-void Town::depositWithdrawl(int choice) {
+void Town::depositWithdrawl(PartyBank whereId) {
 	Party &party = *_vm->_party;
 	Sound &sound = *_vm->_sound;
 	Windows &windows = *_vm->_windows;
 	int gold, gems;
 
-	if (choice) {
+	if (whereId == WHERE_BANK) {
 		gold = party._bankGold;
 		gems = party._bankGems;
 	} else {
@@ -978,7 +978,7 @@ void Town::depositWithdrawl(int choice) {
 	_buttons[2]._value = Common::KEYCODE_ESCAPE;
 
 	Common::String msg = Common::String::format(Res.GOLD_GEMS,
-		Res.DEPOSIT_WITHDRAWL[choice],
+		Res.DEPOSIT_WITHDRAWL[whereId],
 		XeenEngine::printMil(gold).c_str(),
 		XeenEngine::printMil(gems).c_str());
 
@@ -989,15 +989,15 @@ void Town::depositWithdrawl(int choice) {
 
 	sound.stopSound();
 	File voc("coina.voc");
-	bool flag = false;
+	ConsumableType consType = CONS_GOLD;
 
 	do {
 		switch (townWait()) {
 		case Common::KEYCODE_o:
-			flag = false;
+			consType = CONS_GOLD;
 			break;
 		case Common::KEYCODE_e:
-			flag = true;
+			consType = CONS_GEMS;
 			break;
 		case Common::KEYCODE_ESCAPE:
 			break;
@@ -1005,27 +1005,27 @@ void Town::depositWithdrawl(int choice) {
 			continue;
 		}
 
-		if ((choice && !party._bankGems && flag) ||
-			(choice && !party._bankGold && !flag) ||
-			(!choice && !party._gems && flag) ||
-			(!choice && !party._gold && !flag)) {
-			party.notEnough(flag, choice, 1, WT_2);
+		if ((whereId == WHERE_BANK && !party._bankGems && consType == CONS_GEMS) ||
+			(whereId == WHERE_BANK && !party._bankGold && consType == CONS_GOLD) ||
+			(whereId == WHERE_PARTY && !party._gems && consType == CONS_GEMS) ||
+			(whereId == WHERE_PARTY && !party._gold && consType == CONS_GOLD)) {
+			party.notEnough(consType, whereId, WHERE_BANK, WT_2);
 		} else {
 			windows[35].writeString(Res.AMOUNT);
 			int amount = NumericInput::show(_vm, 35, 10, 77);
 
 			if (amount) {
-				if (flag) {
-					if (party.subtract(true, amount, choice, WT_2)) {
-						if (choice) {
+				if (consType == CONS_GEMS) {
+					if (party.subtract(CONS_GEMS, amount, whereId, WT_2)) {
+						if (whereId == WHERE_BANK) {
 							party._gems += amount;
 						} else {
 							party._bankGems += amount;
 						}
 					}
 				} else {
-					if (party.subtract(false, amount, choice, WT_2)) {
-						if (choice) {
+					if (party.subtract(CONS_GOLD, amount, whereId, WT_2)) {
+						if (whereId == WHERE_BANK) {
 							party._gold += amount;
 						} else {
 							party._bankGold += amount;
@@ -1034,7 +1034,7 @@ void Town::depositWithdrawl(int choice) {
 				}
 			}
 
-			if (choice) {
+			if (whereId == WHERE_BANK) {
 				gold = party._bankGold;
 				gems = party._bankGems;
 			} else {
@@ -1043,7 +1043,7 @@ void Town::depositWithdrawl(int choice) {
 			}
 
 			sound.playSound(voc);
-			msg = Common::String::format(Res.GOLD_GEMS_2, Res.DEPOSIT_WITHDRAWL[choice],
+			msg = Common::String::format(Res.GOLD_GEMS_2, Res.DEPOSIT_WITHDRAWL[whereId],
 				XeenEngine::printMil(gold).c_str(), XeenEngine::printMil(gems).c_str());
 			windows[35].writeString(msg);
 			windows[35].update();
diff --git a/engines/xeen/town.h b/engines/xeen/town.h
index 618c4c5..8b05ee2 100644
--- a/engines/xeen/town.h
+++ b/engines/xeen/town.h
@@ -101,7 +101,7 @@ private:
 
 	Character *doTrainingOptions(Character *c);
 
-	void depositWithdrawl(int choice);
+	void depositWithdrawl(PartyBank whereId);
 public:
 	Town(XeenEngine *vm);
 





More information about the Scummvm-git-logs mailing list