mirror of
https://github.com/scummvm/scummvm.git
synced 2026-11-18 21:34:48 +00:00
ULTIMA1: Added Weaponry buying
This commit is contained in:
1 parent
e2ddf798c7
commit
65713e088a
4 files changed
+71
-12
No files matched your search
@@ -142,6 +142,10 @@ uint Weapon::getMagicDamage() const {
|
||||
return damage;
|
||||
}
|
||||
|
||||
uint Weapon::getBuyCost() const {
|
||||
return ((255 - _character->_intelligence) * _type * _type) / 256 + 5;
|
||||
}
|
||||
|
||||
uint Weapon::getSellCost() const {
|
||||
return ((_character->_intelligence + 40) * _type * _type) / 256 + 1;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,11 @@ public:
|
||||
*/
|
||||
uint getMagicDamage() const;
|
||||
|
||||
/**
|
||||
* Gets how much the weapon can be bought for
|
||||
*/
|
||||
uint getBuyCost() const;
|
||||
|
||||
/**
|
||||
* Gets how much the weapon can sell for
|
||||
*/
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "ultima/ultima1/u1dialogs/weaponry.h"
|
||||
#include "ultima/ultima1/core/party.h"
|
||||
#include "ultima/ultima1/core/resources.h"
|
||||
#include "ultima/ultima1/maps/map.h"
|
||||
#include "ultima/ultima1/game.h"
|
||||
#include "ultima/shared/engine/messages.h"
|
||||
#include "ultima/shared/core/str.h"
|
||||
@@ -35,6 +36,15 @@ EMPTY_MESSAGE_MAP(Weaponry, BuySellDialog);
|
||||
|
||||
Weaponry::Weaponry(Ultima1Game *game, int weaponryNum) : BuySellDialog(game, game->_res->WEAPONRY_NAMES[weaponryNum]),
|
||||
_weaponryNum(weaponryNum) {
|
||||
Maps::Ultima1Map *map = static_cast<Maps::Ultima1Map *>(game->_map);
|
||||
|
||||
int offset = (weaponryNum + 1) % 2 + 1;
|
||||
int index = (map->_moveCounter % 0x7fff) / 1500;
|
||||
if (index > 3 || map->_moveCounter > 3000)
|
||||
index = 3;
|
||||
|
||||
_startIndex = offset;
|
||||
_endIndex = offset + (index + 1) * 2;
|
||||
}
|
||||
|
||||
void Weaponry::setMode(BuySell mode) {
|
||||
@@ -43,13 +53,10 @@ void Weaponry::setMode(BuySell mode) {
|
||||
switch (mode) {
|
||||
case BUY: {
|
||||
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->BUY), false, true);
|
||||
|
||||
_mode = BUY;
|
||||
setDirty();
|
||||
|
||||
// Set up a flag list of which weapons the store sells
|
||||
_weaponsPresent.resize(c._weapons.size());
|
||||
|
||||
getInput(true, 3);
|
||||
getKeypress();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -75,11 +82,10 @@ void Weaponry::setMode(BuySell mode) {
|
||||
|
||||
void Weaponry::draw() {
|
||||
BuySellDialog::draw();
|
||||
// Ultima1Game *game = getGame();
|
||||
|
||||
switch (_mode) {
|
||||
case BUY:
|
||||
// centerText(game->_res->Weaponry_PACKS3, 6);
|
||||
drawBuy();
|
||||
break;
|
||||
|
||||
case SELL:
|
||||
@@ -91,6 +97,22 @@ void Weaponry::draw() {
|
||||
}
|
||||
}
|
||||
|
||||
void Weaponry::drawBuy() {
|
||||
Shared::Gfx::VisualSurface s = getSurface();
|
||||
const Shared::Character &c = *_game->_party;
|
||||
int titleLines = String(_title).split("\r\n").size();
|
||||
Common::String line;
|
||||
|
||||
for (uint idx = _startIndex, yp = titleLines + 2; idx <= _endIndex; idx += 2, ++yp) {
|
||||
const Weapon &weapon = *static_cast<Weapon *>(c._weapons[idx]);
|
||||
|
||||
line = Common::String::format("%c) %s", 'a' + idx, weapon._longName.c_str());
|
||||
s.writeString(line, TextPoint(5, yp));
|
||||
line = Common::String::format("-%4u", weapon.getBuyCost());
|
||||
s.writeString(line, TextPoint(22, yp));
|
||||
}
|
||||
}
|
||||
|
||||
void Weaponry::drawSell() {
|
||||
Shared::Gfx::VisualSurface s = getSurface();
|
||||
const Shared::Character &c = *_game->_party;
|
||||
@@ -116,14 +138,37 @@ void Weaponry::drawSell() {
|
||||
bool Weaponry::CharacterInputMsg(CCharacterInputMsg &msg) {
|
||||
Shared::Character &c = *_game->_party;
|
||||
|
||||
if (_mode == SELL && !c._weapons.hasNothing()) {
|
||||
if (_mode == BUY) {
|
||||
if (msg._keyState.keycode >= (int)(Common::KEYCODE_a + _startIndex) &&
|
||||
msg._keyState.keycode <= (int)(Common::KEYCODE_a + _endIndex) &&
|
||||
(int)(msg._keyState.keycode - Common::KEYCODE_a - _startIndex) % 2 == 0) {
|
||||
uint weaponNum = msg._keyState.keycode - Common::KEYCODE_a;
|
||||
Weapon &weapon = *static_cast<Weapon *>(c._weapons[weaponNum]);
|
||||
|
||||
if (weapon.getBuyCost() <= c._coins) {
|
||||
// Display the sold weapon in the info area
|
||||
addInfoMsg(weapon._longName);
|
||||
|
||||
// Remove coins for weapon and add it to the inventory
|
||||
c._coins -= weapon.getBuyCost();
|
||||
weapon.incrQuantity();
|
||||
|
||||
// Show sold and close the dialog
|
||||
setMode(SOLD);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
nothing();
|
||||
return true;
|
||||
} else if (_mode == SELL && !c._weapons.hasNothing()) {
|
||||
if (msg._keyState.keycode >= Common::KEYCODE_b &&
|
||||
msg._keyState.keycode < (Common::KEYCODE_a + (int)c._weapons.size())) {
|
||||
uint weaponNum = msg._keyState.keycode - Common::KEYCODE_a;
|
||||
Weapon &weapon = *static_cast<Weapon *>(c._weapons[weaponNum]);
|
||||
|
||||
if (!c._weapons[weaponNum]->empty()) {
|
||||
if (!weapon.empty()) {
|
||||
// Display the sold weapon in the info area
|
||||
Weapon &weapon = *static_cast<Weapon *>(c._weapons[weaponNum]);
|
||||
addInfoMsg(weapon._longName);
|
||||
|
||||
// Give coins for weapon and remove it from the inventory
|
||||
|
||||
@@ -37,10 +37,15 @@ class Weaponry : public BuySellDialog {
|
||||
virtual bool CharacterInputMsg(CCharacterInputMsg &msg) override;
|
||||
private:
|
||||
uint _weaponryNum;
|
||||
Common::Array<bool> _weaponsPresent;
|
||||
uint _startIndex, _endIndex;
|
||||
private:
|
||||
/**
|
||||
* Draws the Sell dialog
|
||||
* Draws the Buy dialog content
|
||||
*/
|
||||
void drawBuy();
|
||||
|
||||
/**
|
||||
* Draws the Sell dialog content
|
||||
*/
|
||||
void drawSell();
|
||||
protected:
|
||||
|
||||
Reference in new issue
Block a user