Skip to content

Commit

Permalink
XEEN: Implemented calcItemCost
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Feb 3, 2015
1 parent 2b8303c commit 3767f31
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 10 deletions.
125 changes: 123 additions & 2 deletions engines/xeen/dialogs_items.cpp
Expand Up @@ -94,8 +94,9 @@ Character *ItemsDialog::execute(Character *c, ItemsMode mode) {
drawButtons(&screen);
}

Common::StringArray lines;
int arr[40];
Common::fill(&arr[0], &arr[40], false);
Common::fill(&arr[0], &arr[40], 0);
int var2 = -1;

if (mode == ITEMMODE_CHAR_INFO || typeNum != 3) {
Expand Down Expand Up @@ -132,8 +133,20 @@ Character *ItemsDialog::execute(Character *c, ItemsMode mode) {
if (c->_weapons[idx]._id) {
if (mode == ITEMMODE_CHAR_INFO || mode == ITEMMODE_8
|| mode == ITEMMODE_6 || mode == ITEMMODE_4) {
// TODO
lines.push_back(Common::String::format(ITEMS_DIALOG_LINE1,
arr[idx], idx + 1,
c->assembleItemName(idx, arr[idx], typeNum)));
} else {
lines.push_back(Common::String::format(ITEMS_DIALOG_LINE2,
arr[idx], idx + 1,
c->assembleItemName(idx, arr[idx], typeNum),
calcItemCost(c, idx, mode,
mode == ITEMMODE_TO_GOLD ? 1 : c->_skills[MERCHANT],
typeNum)
));
}

// TODO
} else if (_itemsDrawList[idx]._sprites == nullptr) {
// TODO
}
Expand Down Expand Up @@ -289,4 +302,112 @@ void ItemsDialog::setEquipmentIcons() {
}
}

/**
* Calculate the cost of an item
*/
int ItemsDialog::calcItemCost(Character *c, int itemIndex, int mode,
int skillLevel, int typeNum) {
int amount1 = 0, amount2 = 0, amount3 = 0, amount4 = 0;
int result = 0;
int level = skillLevel & 0x7f;

switch (mode) {
case ITEMMODE_BLACKSMITH:
level = 0;
break;
case ITEMMODE_2:
case ITEMMODE_TO_GOLD:
level = level == 0 ? 1 : 0;
break;
case ITEMMODE_10:
level = 2;
break;
case ITEMMODE_9:
level = 3;
break;
default:
break;
}

switch (typeNum) {
case 0:
case 1:
case 2: {
// 0=Weapons, 1=Armor, 2=Accessories
XeenItem &i = (mode == 0) ? c->_weapons[itemIndex] :
(mode == 1 ? c->_armor[itemIndex] : c->_accessories[itemIndex]);
amount1 = (mode == 0) ? WEAPON_BASE_COSTS[i._id] :
(mode == 1 ? ARMOR_BASE_COSTS[i._id] : ACCESSORY_BASE_COSTS[i._id]);

if (i._material > 36 && i._material < 59) {
switch (i._material) {
case 37:
amount1 /= 10;
break;
case 38:
amount1 /= 4;
break;
case 39:
amount1 /= 2;
break;
case 40:
amount1 /= 4;
break;
default:
amount1 *= METAL_BASE_MULTIPLIERS[i._material - 37];
break;
}
}

if (i._material < 37)
amount2 = ELEMENTAL_DAMAGE[i._material] * 100;
else if (i._material > 58)
amount3 = METAL_BASE_MULTIPLIERS[i._material] * 100;

switch (mode) {
case ITEMMODE_BLACKSMITH:
case ITEMMODE_2:
case ITEMMODE_9:
case ITEMMODE_10:
case ITEMMODE_TO_GOLD:
result = (amount1 + amount2 + amount3 + amount4) / ITEM_SKILL_DIVISORS[level];
if (!result)
result = 1;
break;
default:
break;
}
break;
}

case 3: {
// Misc
XeenItem &i = c->_misc[itemIndex];
amount1 = MISC_MATERIAL_COSTS[i._material];
amount4 = MISC_BASE_COSTS[i._id];

switch (mode) {
case ITEMMODE_BLACKSMITH:
case ITEMMODE_2:
case ITEMMODE_9:
case ITEMMODE_10:
case ITEMMODE_TO_GOLD:
result = (amount1 + amount2 + amount3 + amount4) / ITEM_SKILL_DIVISORS[level];
if (!result)
result = 1;
break;
default:
break;
}
break;
}

default:
break;
}

return (mode == ITEMMODE_CHAR_INFO) ? 0 : result;
}


} // End of namespace Xeen
6 changes: 4 additions & 2 deletions engines/xeen/dialogs_items.h
Expand Up @@ -30,8 +30,8 @@
namespace Xeen {

enum ItemsMode {
ITEMMODE_CHAR_INFO = 0, ITEMMODE_BLACKSMITH = 1, ITEMMODE_4 = 4,
ITEMMODE_6 = 6, ITEMMODE_COMBAT = 7, ITEMMODE_8 = 8,
ITEMMODE_CHAR_INFO = 0, ITEMMODE_BLACKSMITH = 1, ITEMMODE_2 = 2,
ITEMMODE_4 = 4, ITEMMODE_6 = 6, ITEMMODE_COMBAT = 7, ITEMMODE_8 = 8,
ITEMMODE_9 = 9, ITEMMODE_10 = 10, ITEMMODE_TO_GOLD = 11
};

Expand All @@ -54,6 +54,8 @@ class ItemsDialog : public ButtonContainer {
void blackData2CharData();

void setEquipmentIcons();

int calcItemCost(Character *c, int itemIndex, int mode, int skillLevel, int typeNum);
public:
static Character *show(XeenEngine *vm, Character *c, ItemsMode mode);
};
Expand Down
39 changes: 35 additions & 4 deletions engines/xeen/resources.cpp
Expand Up @@ -986,14 +986,15 @@ const char *const QUICK_REFERENCE =

const uint BLACKSMITH_MAP_IDS[2][4] = { { 28, 30, 73, 49 }, { 29, 31, 37, 43 } };

char *const ITEMS_DIALOG_TEXT1 =
const char *const ITEMS_DIALOG_TEXT1 =
"\r\x2\x3""c\v021\t017\f37W\fdeap\t051\f37A\fdrmor\t085A"
"\f37c\fdces\t119\f37M\fdisc\t153%s\t187%s\t221%s"
"\t255%s\t289Exit";

char *const ITEMS_DIALOG_TEXT2 =
const char *const ITEMS_DIALOG_TEXT2 =
"\r\x2\x3""c\v021\t017\f37W\fdeap\t051\f37A\fdrmor\t085A"
"\f37c\fdces\t119\f37M\fdisc\t153\f37%s\t289Exit";
const char *const ITEMS_DIALOG_LINE1 = "\x3r\f%02u\f023%2d)\x3l\t028%s\n";
const char *const ITEMS_DIALOG_LINE2 = "\x3r\f%02u\t023%2d)\x3l\t028%s\x3r\t000%lu\n";

const char *const BTN_BUY = "\f37B\fduy";
const char *const BTN_SELL = "\f37S\fdell";
Expand Down Expand Up @@ -1037,8 +1038,38 @@ const char *const ACCESSORY_NAMES[11] = {
const char *const MISC_NAMES[22] = {
nullptr, "rod ", "jewel ", "gem ", "box ", "orb ", "horn ", "coin ",
"wand ", "whistle ", "potion ", "scroll ", "RogueVM",
"bogus", "bogus", "bogus", "bogus", "bogus",
"bogusg", "bogus", "bogus", "bogus", "bogus",
"bogus", "bogus", "bogus", "bogus"
};

const int WEAPON_BASE_COSTS[35] = {
0, 50, 15, 100, 80, 40, 60, 1, 10, 150, 30, 60, 8, 50,
100, 15, 30, 15, 200, 80, 250, 150, 400, 100, 40, 120,
300, 100, 200, 300, 25, 100, 50, 15, 0
};
const int ARMOR_BASE_COSTS[25] = {
0, 20, 100, 200, 400, 600, 1000, 2000, 100, 60, 40, 250, 200, 100
};
const int ACCESSORY_BASE_COSTS[11] = {
0, 100, 100, 250, 100, 50, 300, 200, 500, 1000, 2000
};
const int MISC_MATERIAL_COSTS[22] = {
0, 50, 1000, 500, 10, 100, 20, 10, 50, 10, 10, 100,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
const int MISC_BASE_COSTS[76] = {
0, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 200, 200, 200, 200, 200, 200, 200, 200,
200, 200, 200, 200, 200, 200, 200, 300, 300, 300, 300, 300,
300, 300, 300, 300, 300, 400, 400, 400, 400, 400, 400, 400,
400, 400, 400, 500, 500, 500, 500, 500, 500, 500, 500, 500,
500, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600
};
const int METAL_BASE_MULTIPLIERS[22] = {
10, 25, 5, 75, 2, 5, 10, 20, 50, 2, 3, 5, 10, 20, 30, 40,
50, 60, 70, 80, 90, 100
};
const int ITEM_SKILL_DIVISORS[4] = { 1, 2, 100, 10 };

} // End of namespace Xeen
14 changes: 12 additions & 2 deletions engines/xeen/resources.h
Expand Up @@ -329,8 +329,10 @@ extern const char *const QUICK_REFERENCE;

extern const uint BLACKSMITH_MAP_IDS[2][4];

extern char *const ITEMS_DIALOG_TEXT1;
extern char *const ITEMS_DIALOG_TEXT2;
extern const char *const ITEMS_DIALOG_TEXT1;
extern const char *const ITEMS_DIALOG_TEXT2;
extern const char *const ITEMS_DIALOG_LINE1;
extern const char *const ITEMS_DIALOG_LINE2;

extern const char *const BTN_BUY;
extern const char *const BTN_SELL;
Expand All @@ -354,6 +356,14 @@ extern const char *const ARMOR_NAMES[14];
extern const char *const ACCESSORY_NAMES[11];
extern const char *const MISC_NAMES[22];

extern const int WEAPON_BASE_COSTS[35];
extern const int ARMOR_BASE_COSTS[25];
extern const int ACCESSORY_BASE_COSTS[11];
extern const int MISC_MATERIAL_COSTS[22];
extern const int MISC_BASE_COSTS[76];
extern const int METAL_BASE_MULTIPLIERS[22];
extern const int ITEM_SKILL_DIVISORS[4];

} // End of namespace Xeen

#endif /* XEEN_RESOURCES_H */

0 comments on commit 3767f31

Please sign in to comment.