Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,186 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/armoury.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"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
EMPTY_MESSAGE_MAP(Armoury, BuySellDialog);
Armoury::Armoury(Ultima1Game *game, int armouryNum) : BuySellDialog(game, game->_res->ARMOURY_NAMES[armouryNum]) {
Maps::Ultima1Map *map = static_cast<Maps::Ultima1Map *>(game->_map);
_startIndex = 1;
_endIndex = (map->_moveCounter > 3000) ? 5 : 3;
}
void Armoury::setMode(BuySell mode) {
Shared::Character &c = *_game->_party;
switch (mode) {
case BUY: {
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->BUY), false, true);
_mode = BUY;
setDirty();
getKeypress();
break;
}
case SELL:
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->SELL), false, true);
if (c._armour.hasNothing()) {
addInfoMsg(_game->_res->NOTHING);
closeShortly();
} else {
getKeypress();
}
_mode = SELL;
setDirty();
break;
default:
BuySellDialog::setMode(mode);
break;
}
}
void Armoury::draw() {
BuySellDialog::draw();
switch (_mode) {
case BUY:
drawBuy();
break;
case SELL:
drawSell();
break;
default:
break;
}
}
void Armoury::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, ++yp) {
const Armour &armour = *static_cast<Armour *>(c._armour[idx]);
line = Common::String::format("%c) %s", 'a' + idx, armour._name.c_str());
s.writeString(line, TextPoint(5, yp));
line = Common::String::format("-%4u", armour.getBuyCost());
s.writeString(line, TextPoint(22, yp));
}
}
void Armoury::drawSell() {
Shared::Gfx::VisualSurface s = getSurface();
const Shared::Character &c = *_game->_party;
int lineCount = c._armour.itemsCount();
int titleLines = String(_title).split("\r\n").size();
Common::String line;
if (lineCount == 0) {
centerText(_game->_res->NO_ARMOUR_TO_SELL, titleLines + 2);
} else {
for (uint idx = 1; idx < c._armour.size(); ++idx) {
const Armour &armour = *static_cast<Armour *>(c._armour[idx]);
if (!armour.empty()) {
line = Common::String::format("%c) %s", 'a' + idx, armour._name.c_str());
s.writeString(line, TextPoint(5, idx + titleLines + 1));
line = Common::String::format("-%4u", armour.getSellCost());
s.writeString(line, TextPoint(22, idx + titleLines + 1));
}
}
}
}
bool Armoury::CharacterInputMsg(CCharacterInputMsg *msg) {
Shared::Character &c = *_game->_party;
if (_mode == BUY) {
if (msg->_keyState.keycode >= (int)(Common::KEYCODE_a + _startIndex) &&
msg->_keyState.keycode <= (int)(Common::KEYCODE_a + _endIndex)) {
uint armourNum = msg->_keyState.keycode - Common::KEYCODE_a;
Armour &armour = *static_cast<Armour *>(c._armour[armourNum]);
if (armour.getBuyCost() <= c._coins) {
// Display the sold armour in the info area
addInfoMsg(armour._name);
// Remove coins for armour and add it to the inventory
c._coins -= armour.getBuyCost();
armour.incrQuantity();
// Show sold and close the dialog
setMode(SOLD);
return true;
}
}
nothing();
return true;
} else if (_mode == SELL && !c._armour.hasNothing()) {
if (msg->_keyState.keycode >= Common::KEYCODE_b &&
msg->_keyState.keycode < (Common::KEYCODE_a + (int)c._armour.size())) {
uint armourNum = msg->_keyState.keycode - Common::KEYCODE_a;
Armour &armour = *static_cast<Armour *>(c._armour[armourNum]);
if (!armour.empty()) {
// Display the sold armour in the info area
addInfoMsg(armour._name);
// Give coins for armour and remove it from the inventory
c._coins += armour.getSellCost();
if (armour.decrQuantity() && (int)armourNum == c._equippedArmour)
c.removeArmour();
// Close the dialog
setMode(DONE);
return true;
}
}
nothing();
return true;
} else {
return BuySellDialog::CharacterInputMsg(msg);
}
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@@ -0,0 +1,73 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_ARMOURY_H
#define ULTIMA_ULTIMA1_U1DIALOGS_ARMOURY_H
#include "ultima/ultima1/u1dialogs/buy_sell_dialog.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
/**
* Implements the buy/sell dialog for the armory
*/
class Armoury : public BuySellDialog {
DECLARE_MESSAGE_MAP;
bool CharacterInputMsg(CCharacterInputMsg *msg) override;
private:
// uint _armouryNum;
uint _startIndex, _endIndex;
private:
/**
* Draws the Buy dialog content
*/
void drawBuy();
/**
* Draws the Sell dialog content
*/
void drawSell();
protected:
/**
* Set the mode
*/
void setMode(BuySell mode) override;
public:
CLASSDEF;
/**
* Constructor
*/
Armoury(Ultima1Game *game, int armouryNum);
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,149 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/buy_sell_dialog.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/shared/core/str.h"
#include "ultima/shared/gfx/visual_surface.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
BEGIN_MESSAGE_MAP(BuySellDialog, Dialog)
ON_MESSAGE(ShowMsg)
ON_MESSAGE(FrameMsg)
ON_MESSAGE(CharacterInputMsg)
END_MESSAGE_MAP()
BuySellDialog::BuySellDialog(Ultima1Game *game, const Common::String &title) :
Dialog(game), _mode(SELECT), _title(title), _charInput(game), _closeCounter(0) {
_bounds = Rect(31, 23, 287, 127);
}
bool BuySellDialog::ShowMsg(CShowMsg *msg) {
addInfoMsg(_game->_res->BUY_SELL, false);
getKeypress();
return true;
}
bool BuySellDialog::FrameMsg(CFrameMsg *msg) {
if (_closeCounter > 0 && --_closeCounter == 0) {
_game->endOfTurn();
hide();
}
return true;
}
bool BuySellDialog::CharacterInputMsg(CCharacterInputMsg *msg) {
switch (_mode) {
case SELECT:
if (msg->_keyState.keycode == Common::KEYCODE_b)
setMode(BUY);
else if (msg->_keyState.keycode == Common::KEYCODE_s)
setMode(SELL);
else
nothing();
break;
case CANT_AFFORD:
addInfoMsg("", true, true);
break;
default:
break;
}
return true;
}
void BuySellDialog::draw() {
Dialog::draw();
Shared::Gfx::VisualSurface s = getSurface();
if (_mode != SELECT) {
// Draw the background and frame
s.clear();
s.frameRect(Rect(3, 3, _bounds.width() - 3, _bounds.height() - 3), getGame()->_borderColor);
// Draw the title
centerText(String(_title).split('\n'), 1);
}
switch (_mode) {
case SOLD:
centerText(getGame()->_res->SOLD, 5);
break;
case CANT_AFFORD:
centerText(getGame()->_res->CANT_AFFORD, 5);
break;
case DONE:
centerText(getGame()->_res->DONE, 5);
break;
default:
break;
}
}
void BuySellDialog::setMode(BuySell mode) {
_mode = mode;
setDirty();
switch (_mode) {
case BUY:
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->BUY), false, true);
getKeypress();
break;
case SELL:
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->SELL), false, true);
getKeypress();
break;
case CANT_AFFORD:
addInfoMsg(_game->_res->NOTHING);
_game->playFX(1);
break;
default:
break;
}
if (_mode == SOLD || _mode == CANT_AFFORD || _mode == DONE)
// Start dialog close countdown
closeShortly();
}
void BuySellDialog::nothing() {
addInfoMsg(_game->_res->NOTHING);
_game->endOfTurn();
hide();
}
} // End of namespace U1Dialogs
} // End of namespace Gfx
} // End of namespace Ultima

View File

@@ -0,0 +1,97 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_BUY_SELL_DIALOG_H
#define ULTIMA_ULTIMA1_U1DIALOGS_BUY_SELL_DIALOG_H
#include "ultima/ultima1/u1dialogs/dialog.h"
#include "ultima/shared/gfx/character_input.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
#define DIALOG_CLOSE_DELAY 50
enum BuySell { SELECT, BUY, SELL, SOLD, CANT_AFFORD, DONE };
using Shared::CShowMsg;
using Shared::CFrameMsg;
using Shared::CCharacterInputMsg;
/**
* Secondary base class for dialogs that have display for buying and selling
*/
class BuySellDialog : public Dialog {
DECLARE_MESSAGE_MAP;
bool ShowMsg(CShowMsg *msg);
bool FrameMsg(CFrameMsg *msg);
virtual bool CharacterInputMsg(CCharacterInputMsg *msg);
private:
Shared::Gfx::CharacterInput _charInput;
protected:
BuySell _mode;
Common::String _title;
uint _closeCounter;
protected:
/**
* Constructor
*/
BuySellDialog(Ultima1Game *game, const Common::String &title);
/**
* Nothing selected
*/
void nothing();
/**
* Set the mode
*/
virtual void setMode(BuySell mode);
/**
* Switches the dialog to displaying sold
*/
void showSold() { setMode(SOLD); }
/**
* Switches the dialog to displaying a can't afford message
*/
void cantAfford() { setMode(CANT_AFFORD); }
/**
* Sets the dialog to close after a brief pause
*/
void closeShortly() { _closeCounter = 3 * DIALOG_CLOSE_DELAY; }
public:
CLASSDEF;
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,87 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/combat.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/shared/gfx/text_cursor.h"
#include "ultima/shared/engine/messages.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
BEGIN_MESSAGE_MAP(Combat, Dialog)
ON_MESSAGE(KeypressMsg)
END_MESSAGE_MAP()
Combat::Combat(Ultima1Game *game, Shared::Maps::Direction direction, int weaponType,
const Common::String &weaponName) : FullScreenDialog(game), _direction(direction) {
}
bool Combat::KeypressMsg(CKeypressMsg *msg) {
if (_direction == Shared::Maps::DIR_NONE) {
switch (msg->_keyState.keycode) {
case Common::KEYCODE_LEFT:
case Common::KEYCODE_KP4:
_direction = Shared::Maps::DIR_LEFT;
break;
case Common::KEYCODE_RIGHT:
case Common::KEYCODE_KP6:
_direction = Shared::Maps::DIR_RIGHT;
break;
case Common::KEYCODE_UP:
case Common::KEYCODE_KP8:
_direction = Shared::Maps::DIR_UP;
break;
case Common::KEYCODE_DOWN:
case Common::KEYCODE_KP2:
_direction = Shared::Maps::DIR_DOWN;
break;
default:
nothing();
return true;
}
}
setDirty(true);
return true;
}
void Combat::draw() {
if (_direction == Shared::Maps::DIR_NONE)
drawSelection();
}
void Combat::drawSelection() {
}
void Combat::nothing() {
addInfoMsg(Common::String::format(" %s", _game->_res->NOTHING));
hide();
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@@ -0,0 +1,71 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_COMBAT_H
#define ULTIMA_ULTIMA1_U1DIALOGS_COMBAT_H
#include "ultima/ultima1/u1dialogs/full_screen_dialog.h"
#include "ultima/shared/maps/map_widget.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
using Shared::CKeypressMsg;
/**
* Implements player combat attacks
*/
class Combat : public FullScreenDialog {
DECLARE_MESSAGE_MAP;
bool KeypressMsg(CKeypressMsg *msg);
private:
Common::String _weaponName;
int _direction;
private:
/**
* Nothing selected
*/
void nothing();
/**
* Draw the selection prompt
*/
void drawSelection();
public:
CLASSDEF;
/**
* Constructor
*/
Combat(Ultima1Game *game, Shared::Maps::Direction direction, int weaponType, const Common::String &weaponName);
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,86 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/dialog.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/u1gfx/info.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
Dialog::Dialog(Ultima1Game *game) : Popup(game), _game(game) {
}
Maps::Ultima1Map *Dialog::getMap() {
return static_cast<Maps::Ultima1Map *>(_game->getMap());
}
void Dialog::addInfoMsg(const Common::String &text, bool newLine, bool replaceLine) {
Shared::TreeItem *infoArea = _game->findByName("Info");
Shared::CInfoMsg msg(text, newLine, replaceLine);
msg.execute(infoArea);
}
void Dialog::getKeypress() {
Shared::TreeItem *infoArea = _game->findByName("Info");
Shared::CInfoGetKeypress msg(this);
msg.execute(infoArea);
}
void Dialog::getInput(bool isNumeric, size_t maxCharacters) {
TreeItem *infoArea = _game->findByName("Info");
Shared::CInfoGetInput msg(this, isNumeric, maxCharacters);
msg.execute(infoArea);
}
void Dialog::draw() {
// Redraw the game's info area
U1Gfx::Info *infoArea = dynamic_cast<U1Gfx::Info *>(_game->findByName("Info"));
assert(infoArea);
infoArea->draw();
}
void Dialog::centerText(const Common::String &line, int yp) {
Shared::Gfx::VisualSurface s = getSurface();
s.writeString(line, TextPoint((_bounds.width() / 8 - line.size() + 1) / 2, yp));
}
void Dialog::centerText(const Shared::StringArray &lines, int yp) {
Shared::Gfx::VisualSurface s = getSurface();
for (uint idx = 0; idx < lines.size(); ++idx)
s.writeString(lines[idx], TextPoint((_bounds.width() / 8 - lines[idx].size() + 1) / 2, yp + idx));
}
void Dialog::hide() {
Popup::hide();
// Delete the dialog when hidden
delete this;
}
} // End of namespace U1Dialogs
} // End of namespace Gfx
} // End of namespace Ultima

View File

@@ -0,0 +1,105 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_DIALOG_H
#define ULTIMA_ULTIMA1_U1DIALOGS_DIALOG_H
#include "ultima/shared/gfx/popup.h"
#include "ultima/shared/gfx/character_input.h"
#include "ultima/shared/core/str.h"
namespace Ultima {
namespace Ultima1 {
class Ultima1Game;
namespace Maps {
class Ultima1Map;
}
namespace U1Dialogs {
/**
* Base class for Ultima 1 popup dialogs
*/
class Dialog : public Shared::Gfx::Popup {
protected:
Ultima1Game *_game;
Common::String _prompt;
protected:
/**
* Jumps up through the parents to find the root game
*/
Ultima1Game *getGame() { return _game; }
/**
* Return the game's map
*/
Maps::Ultima1Map *getMap();
/**
* Adds a text string to the info area
* @param text Text to add
* @param newLine Whether to apply a newline at the end
* @param replaceLine If true, replaces the current last line
*/
void addInfoMsg(const Common::String &text, bool newLine = true, bool replaceLine = false);
/**
* Prompts for a keypress
*/
void getKeypress();
/**
* Prompts for an input
*/
void getInput(bool isNumeric = true, size_t maxCharacters = 4);
/**
* Write a text line to the dialog
*/
void centerText(const Common::String &line, int yp);
/**
* Write a text line to the dialog
*/
void centerText(const Shared::StringArray &lines, int yp);
public:
/**
* Constructor
*/
Dialog(Ultima1Game *game);
/**
* Draws the visual item on the screen
*/
void draw() override;
/**
* Hide the dialog
*/
void hide() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,245 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/drop.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/shared/engine/messages.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
BEGIN_MESSAGE_MAP(Drop, Dialog)
ON_MESSAGE(ShowMsg)
ON_MESSAGE(CharacterInputMsg)
ON_MESSAGE(TextInputMsg)
END_MESSAGE_MAP()
Drop::Drop(Ultima1Game *game) : FullScreenDialog(game), _mode(SELECT) {
}
bool Drop::ShowMsg(CShowMsg *msg) {
addInfoMsg(_game->_res->DROP_PENCE_WEAPON_armour, false);
getKeypress();
return true;
}
bool Drop::CharacterInputMsg(CCharacterInputMsg *msg) {
Shared::Character &c = *_game->_party;
switch (_mode) {
case SELECT:
switch (msg->_keyState.keycode) {
case Common::KEYCODE_p:
setMode(DROP_PENCE);
break;
case Common::KEYCODE_w:
setMode(DROP_WEAPON);
break;
case Common::KEYCODE_a:
setMode(DROP_armour);
break;
default:
nothing();
break;
}
break;
case DROP_WEAPON:
if (msg->_keyState.keycode >= Common::KEYCODE_b && msg->_keyState.keycode < (Common::KEYCODE_b + (int)c._weapons.size())
&& !c._weapons[msg->_keyState.keycode - Common::KEYCODE_a]->empty()) {
// Drop the weapon
int weaponNum = msg->_keyState.keycode - Common::KEYCODE_a;
if (c._weapons[weaponNum]->decrQuantity() && c._equippedWeapon == weaponNum)
c.removeWeapon();
addInfoMsg(Common::String::format("%s%s", _game->_res->DROP_WEAPON,
_game->_res->WEAPON_NAMES_UPPERCASE[weaponNum]), true, true);
hide();
} else {
none();
}
break;
case DROP_armour:
if (msg->_keyState.keycode >= Common::KEYCODE_b && msg->_keyState.keycode < (Common::KEYCODE_b + (int)c._armour.size())
&& c._armour[msg->_keyState.keycode - Common::KEYCODE_a]->_quantity > 0) {
// Drop the armor
int armorNum = msg->_keyState.keycode - Common::KEYCODE_a;
if (c._armour[armorNum]->decrQuantity() && c._equippedArmour == armorNum)
c.removeArmour();
addInfoMsg(Common::String::format("%s%s", _game->_res->DROP_armour,
_game->_res->ARMOR_NAMES[armorNum]), true, true);
hide();
} else {
none();
}
break;
default:
break;
}
return true;
}
bool Drop::TextInputMsg(CTextInputMsg *msg) {
Shared::Character &c = *_game->_party;
assert(_mode == DROP_PENCE);
Ultima1Game *game = _game;
Maps::Ultima1Map *map = getMap();
uint amount = atoi(msg->_text.c_str());
if (msg->_escaped || !amount) {
none();
} else {
addInfoMsg(Common::String::format(" %u", amount));
if (amount > c._coins) {
addInfoMsg(game->_res->NOT_THAT_MUCH);
game->playFX(1);
} else {
c._coins -= amount;
hide();
map->dropCoins(amount);
}
}
return true;
}
void Drop::setMode(Mode mode) {
setDirty();
_mode = mode;
const Shared::Character &c = *_game->_party;
switch (mode) {
case DROP_PENCE:
addInfoMsg(_game->_res->DROP_PENCE, false, true);
getInput();
break;
case DROP_WEAPON:
if (c._weapons.hasNothing()) {
nothing();
} else {
addInfoMsg(_game->_res->DROP_WEAPON, false, true);
getKeypress();
}
break;
case DROP_armour:
if (c._armour.hasNothing()) {
nothing();
} else {
addInfoMsg(_game->_res->DROP_armour, false, true);
getKeypress();
}
break;
default:
break;
}
}
void Drop::nothing() {
addInfoMsg(Common::String::format("%s %s", _game->_res->ACTION_NAMES[3],
_game->_res->NOTHING), true, true);
hide();
}
void Drop::none() {
const char *DROPS[4] = { nullptr, _game->_res->DROP_PENCE, _game->_res->DROP_WEAPON, _game->_res->DROP_armour };
addInfoMsg(Common::String::format("%s%s", DROPS[_mode], _game->_res->NONE), true, true);
hide();
}
void Drop::draw() {
Dialog::draw();
switch (_mode) {
case DROP_WEAPON:
drawDropWeapon();
break;
case DROP_armour:
drawDropArmor();
break;
default:
break;
}
}
void Drop::drawDropWeapon() {
Shared::Gfx::VisualSurface s = getSurface();
drawFrame(_game->_res->ACTION_NAMES[3]);
// Count the number of different types of weapons
const Shared::Character &c = *_game->_party;
int numLines = 0;
for (uint idx = 1; idx < c._weapons.size(); ++idx) {
if (c._weapons[idx]->_quantity)
++numLines;
}
// Draw lines for weapons the player has
int yp = 10 - (numLines / 2);
for (uint idx = 1; idx < c._weapons.size(); ++idx) {
if (c._weapons[idx]->_quantity) {
Common::String text = Common::String::format("%c) %s", 'a' + idx,
_game->_res->WEAPON_NAMES_UPPERCASE[idx]);
s.writeString(text, TextPoint(15, yp++));
}
}
}
void Drop::drawDropArmor() {
Shared::Gfx::VisualSurface s = getSurface();
drawFrame(_game->_res->ACTION_NAMES[3]);
// Count the number of different types of armor
const Shared::Character &c = *_game->_party;
int numLines = 0;
for (uint idx = 1; idx < c._armour.size(); ++idx) {
if (c._armour[idx]->_quantity)
++numLines;
}
// Draw lines for armor the player has
int yp = 10 - (numLines / 2);
for (uint idx = 1; idx < c._armour.size(); ++idx) {
if (c._armour[idx]->_quantity) {
Common::String text = Common::String::format("%c) %s", 'a' + idx,
_game->_res->ARMOR_NAMES[idx]);
s.writeString(text, TextPoint(13, yp++));
}
}
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@@ -0,0 +1,91 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_DROP_H
#define ULTIMA_ULTIMA1_U1DIALOGS_DROP_H
#include "ultima/ultima1/u1dialogs/full_screen_dialog.h"
#include "ultima/shared/gfx/text_input.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
using Shared::CShowMsg;
using Shared::CCharacterInputMsg;
using Shared::CTextInputMsg;
/**
* Implements the drop dialog
*/
class Drop : public FullScreenDialog {
DECLARE_MESSAGE_MAP;
bool ShowMsg(CShowMsg *msg);
bool CharacterInputMsg(CCharacterInputMsg *msg);
bool TextInputMsg(CTextInputMsg *msg);
enum Mode { SELECT, DROP_PENCE, DROP_WEAPON, DROP_armour };
private:
Mode _mode;
private:
/**
* Sets the mode
*/
void setMode(Mode mode);
/**
* Nothing selected
*/
void nothing();
/**
* None response
*/
void none();
/**
* Draw the drop weapon display
*/
void drawDropWeapon();
/**
* Draw the drop armor display
*/
void drawDropArmor();
public:
CLASSDEF;
/**
* Constructor
*/
Drop(Ultima1Game *game);
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,57 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/full_screen_dialog.h"
#include "ultima/ultima1/u1gfx/drawing_support.h"
#include "ultima/ultima1/game.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
FullScreenDialog::FullScreenDialog(Ultima1Game *game) : Dialog(game) {
_bounds = Common::Rect(0, 0, 320, 200);
}
void FullScreenDialog::drawFrame(const Common::String &title) {
Shared::Gfx::VisualSurface s = getSurface();
U1Gfx::DrawingSupport ds(s);
s.fillRect(TextRect(0, 0, 40, 20), _game->_bgColor);
ds.drawGameFrame();
size_t titleLen = title.size() + 2;
size_t xStart = 20 - titleLen / 2;
ds.drawRightArrow(TextPoint(xStart - 1, 0));
s.fillRect(TextRect(xStart, 0, xStart + titleLen, 0), 0);
s.writeString(title, TextPoint(xStart + 1, 0));
ds.drawLeftArrow(TextPoint(xStart + titleLen, 0));
}
void FullScreenDialog::hide() {
Ultima1Game *game = _game;
Dialog::hide();
game->endOfTurn();
}
} // End of namespace U1Dialogs
} // End of namespace Gfx
} // End of namespace Ultima

View File

@@ -0,0 +1,57 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_FULL_SCREEN_DIALOG_H
#define ULTIMA_ULTIMA1_U1DIALOGS_FULL_SCREEN_DIALOG_H
#include "ultima/ultima1/u1dialogs/dialog.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
/**
* Base class for dialogs that cover the entire game area, with the exception of the
* info & status areas at the bottom of the screen
*/
class FullScreenDialog : public Dialog {
protected:
/**
* Draw the frame
*/
void drawFrame(const Common::String &title);
public:
/**
* Constructor
*/
FullScreenDialog(Ultima1Game *game);
/**
* Hide the popup
*/
void hide() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,111 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/grocery.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/game.h"
#include "ultima/shared/core/str.h"
#include "ultima/shared/engine/messages.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
BEGIN_MESSAGE_MAP(Grocery, BuySellDialog)
ON_MESSAGE(TextInputMsg)
END_MESSAGE_MAP()
Grocery::Grocery(Ultima1Game *game, int groceryNum) : BuySellDialog(game, game->_res->GROCERY_NAMES[groceryNum - 1]) {
Shared::Character &c = *game->_party;
_costPerPack = 5 - c._intelligence / 20;
}
void Grocery::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();
getInput(true, 3);
break;
case SELL:
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->SELL), false, true);
_mode = SELL;
closeShortly();
setDirty();
break;
default:
BuySellDialog::setMode(mode);
break;
}
}
void Grocery::draw() {
BuySellDialog::draw();
Shared::Gfx::VisualSurface s = getSurface();
Ultima1Game *game = getGame();
switch (_mode) {
case BUY:
centerText(Common::String::format(game->_res->GROCERY_PACKS1, _costPerPack), 4);
centerText(game->_res->GROCERY_PACKS2, 5);
centerText(game->_res->GROCERY_PACKS3, 6);
break;
case SELL:
centerText(game->_res->GROCERY_SELL, String(_title).split('\n').size() + 2);
break;
default:
break;
}
}
bool Grocery::TextInputMsg(CTextInputMsg *msg) {
assert(_mode == BUY);
Shared::Character &c = *_game->_party;
uint amount = atoi(msg->_text.c_str());
uint cost = amount * _costPerPack;
if (msg->_escaped || !amount) {
nothing();
} else if (cost > c._coins) {
cantAfford();
} else {
addInfoMsg(msg->_text);
c._coins -= cost;
c._food += amount * 10;
addInfoMsg(Common::String::format(_game->_res->GROCERY_PACKS_FOOD, amount));
_game->endOfTurn();
hide();
}
return true;
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@@ -0,0 +1,65 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_GROCERY_H
#define ULTIMA_ULTIMA1_U1DIALOGS_GROCERY_H
#include "ultima/ultima1/u1dialogs/buy_sell_dialog.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
using Shared::CFrameMsg;
using Shared::CTextInputMsg;
/**
* Implements the buy/sell dialog for grocers
*/
class Grocery : public BuySellDialog {
DECLARE_MESSAGE_MAP;
bool TextInputMsg(CTextInputMsg *msg);
private:
uint _costPerPack;
protected:
/**
* Set the mode
*/
void setMode(BuySell mode) override;
public:
CLASSDEF;
/**
* Constructor
*/
Grocery(Ultima1Game *game, int groceryNum);
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,219 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/king.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/shared/gfx/visual_surface.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
BEGIN_MESSAGE_MAP(King, Dialog)
ON_MESSAGE(ShowMsg)
ON_MESSAGE(CharacterInputMsg)
ON_MESSAGE(TextInputMsg)
END_MESSAGE_MAP()
King::King(Ultima1Game *game, uint kingIndex) : Dialog(game), _kingIndex(kingIndex), _mode(SELECT) {
_bounds = Rect(31, 23, 287, 127);
}
bool King::ShowMsg(CShowMsg *msg) {
addInfoMsg(_game->_res->KING_TEXT[0], false);
getKeypress();
return true;
}
void King::draw() {
Dialog::draw();
if (_mode != SERVICE)
return;
Shared::Gfx::VisualSurface s = getSurface();
// Draw the background and frame
s.clear();
s.frameRect(Rect(3, 3, _bounds.width() - 3, _bounds.height() - 3), getGame()->_borderColor);
if (_kingIndex % 1) {
// Kill a monster
centerText(_game->_res->KING_TEXT[8], 2);
Common::String name;
switch ((_kingIndex - 1) / 2) {
case 0:
// Gelatinous Cube
name = _game->_res->DUNGEON_MONSTER_NAMES[9];
break;
case 1:
// Carrion Creeper
name = _game->_res->DUNGEON_MONSTER_NAMES[14];
break;
case 2:
// Lich
name = _game->_res->DUNGEON_MONSTER_NAMES[18];
break;
case 3:
// Balron
name = _game->_res->DUNGEON_MONSTER_NAMES[23];
break;
default:
break;
}
centerText(name, 4);
} else {
// Find a location
centerText(_game->_res->KING_TEXT[9], 2);
switch (_kingIndex / 2) {
case 0:
centerText(_game->_res->LOCATION_NAMES[47], 4);
break;
case 1:
centerText(_game->_res->LOCATION_NAMES[45], 4);
break;
case 2:
centerText(_game->_res->LOCATION_NAMES[43], 4);
break;
case 3:
centerText(_game->_res->LOCATION_NAMES[41], 4);
break;
}
}
centerText(_game->_res->KING_TEXT[10], 6);
centerText(_game->_res->KING_TEXT[11], 7);
}
void King::setMode(KingMode mode) {
_mode = mode;
switch (_mode) {
case PENCE:
addInfoMsg(_game->_res->KING_TEXT[2]); // Pence
addInfoMsg(_game->_res->KING_TEXT[4], false); // How much?
getInput();
break;
case SERVICE:
addInfoMsg(_game->_res->KING_TEXT[3]);
if (_game->_quests[_kingIndex].isInProgress()) {
alreadyOnQuest();
return;
} else {
_game->_quests[_kingIndex].start();
addInfoMsg(_game->_res->PRESS_SPACE_TO_CONTINUE, false);
getKeypress();
}
break;
default:
break;
}
setDirty();
}
bool King::CharacterInputMsg(CCharacterInputMsg *msg) {
switch (_mode) {
case SELECT:
if (msg->_keyState.keycode == Common::KEYCODE_p)
setMode(PENCE);
else if (msg->_keyState.keycode == Common::KEYCODE_s)
setMode(SERVICE);
else
neither();
break;
case SERVICE:
addInfoMsg("");
_game->endOfTurn();
hide();
break;
default:
break;
}
return true;
}
bool King::TextInputMsg(CTextInputMsg *msg) {
assert(_mode == PENCE);
const Shared::Character &c = *_game->_party;
uint amount = atoi(msg->_text.c_str());
if (msg->_escaped || !amount) {
none();
} else if (amount > c._coins) {
notThatMuch();
} else {
addInfoMsg(Common::String::format("%u", amount));
giveHitPoints(amount * 3 / 2);
}
return true;
}
void King::neither() {
addInfoMsg(_game->_res->KING_TEXT[1]);
_game->endOfTurn();
hide();
}
void King::none() {
addInfoMsg(_game->_res->NONE);
_game->endOfTurn();
hide();
}
void King::notThatMuch() {
addInfoMsg(_game->_res->KING_TEXT[5]);
_game->endOfTurn();
hide();
}
void King::alreadyOnQuest() {
addInfoMsg(_game->_res->KING_TEXT[7]);
_game->endOfTurn();
hide();
}
void King::giveHitPoints(uint amount) {
Shared::Character &c = *_game->_party;
assert(amount <= c._coins);
c._coins -= amount;
c._hitPoints += amount;
addInfoMsg(Common::String::format(_game->_res->KING_TEXT[6], amount));
_game->endOfTurn();
hide();
}
} // End of namespace U1Dialogs
} // End of namespace Gfx
} // End of namespace Ultima

View File

@@ -0,0 +1,96 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_KING_H
#define ULTIMA_ULTIMA1_U1DIALOGS_KING_H
#include "ultima/ultima1/u1dialogs/dialog.h"
#include "ultima/shared/gfx/character_input.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
using Shared::CShowMsg;
using Shared::CCharacterInputMsg;
using Shared::CTextInputMsg;
/**
* Dialog for talking to kings
*/
class King : public Dialog {
DECLARE_MESSAGE_MAP;
bool ShowMsg(CShowMsg *msg);
bool CharacterInputMsg(CCharacterInputMsg *msg);
bool TextInputMsg(CTextInputMsg *msg);
enum KingMode { SELECT, PENCE, SERVICE };
private:
KingMode _mode;
uint _kingIndex;
private:
/**
* Set the mode
*/
void setMode(KingMode mode);
/**
* Neither option (buy, service) selected
*/
void neither();
/**
* No pence entered
*/
void none();
/**
* Not that much
*/
void notThatMuch();
/**
* Already on a quest
*/
void alreadyOnQuest();
/**
* Give hit points
*/
void giveHitPoints(uint amount);
public:
CLASSDEF;
/**
* Constructor
*/
King(Ultima1Game *game, uint kingIndex);
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,135 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/magic.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"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
EMPTY_MESSAGE_MAP(Magic, BuySellDialog);
Magic::Magic(Ultima1Game *game, int magicNum) : BuySellDialog(game, game->_res->MAGIC_NAMES[magicNum]) {
const Shared::Character &c = *game->_party;
_startIndex = 1 + (magicNum & 1);
_endIndex = (c._class == CLASS_WIZARD) ? c._spells.size() - 1 : 5;
}
void Magic::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();
getKeypress();
break;
}
case SELL:
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->SELL), false, true);
_mode = SELL;
closeShortly();
setDirty();
break;
default:
BuySellDialog::setMode(mode);
break;
}
}
void Magic::draw() {
BuySellDialog::draw();
Shared::Gfx::VisualSurface s = getSurface();
Ultima1Game *game = getGame();
switch (_mode) {
case BUY:
drawBuy();
break;
case SELL:
centerText(game->_res->DONT_BUY_SPELLS, String(_title).split('\n').size() + 2);
break;
default:
break;
}
}
void Magic::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 Spells::Spell &spell = *static_cast<Spells::Spell *>(c._spells[idx]);
line = Common::String::format("%c) %s", 'a' + idx, spell._name.c_str());
s.writeString(line, TextPoint(5, yp));
line = Common::String::format("-%4u", spell.getBuyCost());
s.writeString(line, TextPoint(22, yp));
}
}
bool Magic::CharacterInputMsg(CCharacterInputMsg *msg) {
Shared::Character &c = *_game->_party;
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 magicNum = msg->_keyState.keycode - Common::KEYCODE_a;
Spells::Spell &spell = *static_cast<Spells::Spell *>(c._spells[magicNum]);
if (spell.getBuyCost() <= c._coins) {
// Display the sold spell in the info area
addInfoMsg(spell._name);
// Remove coins for spell and add it to the inventory
c._coins -= spell.getBuyCost();
spell.incrQuantity();
// Show sold and close the dialog
setMode(SOLD);
return true;
}
}
nothing();
return true;
} else {
return BuySellDialog::CharacterInputMsg(msg);
}
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@@ -0,0 +1,70 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_MAGIC_H
#define ULTIMA_ULTIMA1_U1DIALOGS_MAGIC_H
#include "ultima/ultima1/u1dialogs/buy_sell_dialog.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
using Shared::CCharacterInputMsg;
/**
* Implements the buy/sell dialog for magic
*/
class Magic : public BuySellDialog {
DECLARE_MESSAGE_MAP;
bool CharacterInputMsg(CCharacterInputMsg *msg) override;
private:
// uint _magicNum;
uint _startIndex, _endIndex;
private:
/**
* Draws the Buy dialog content
*/
void drawBuy();
protected:
/**
* Set the mode
*/
void setMode(BuySell mode) override;
public:
CLASSDEF;
/**
* Constructor
*/
Magic(Ultima1Game *game, int magicNum);
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,248 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/ready.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/shared/gfx/text_cursor.h"
#include "ultima/shared/engine/messages.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
BEGIN_MESSAGE_MAP(Ready, Dialog)
ON_MESSAGE(ShowMsg)
ON_MESSAGE(CharacterInputMsg)
END_MESSAGE_MAP()
Ready::Ready(Ultima1Game *game) : FullScreenDialog(game), _mode(SELECT) {
}
bool Ready::ShowMsg(CShowMsg *msg) {
addInfoMsg(_game->_res->READY_WEAPON_armour_SPELL, false);
getKeypress();
return true;
}
bool Ready::CharacterInputMsg(CCharacterInputMsg *msg) {
Shared::Character &c = *_game->_party;
switch (_mode) {
case SELECT:
switch (msg->_keyState.keycode) {
case Common::KEYCODE_w:
setMode(READY_WEAPON);
break;
case Common::KEYCODE_a:
setMode(READY_armour);
break;
case Common::KEYCODE_s:
setMode(READY_SPELL);
break;
default:
addInfoMsg(Common::String::format("%s ", _game->_res->ACTION_NAMES[17]), false, true);
nothing();
break;
}
break;
case READY_WEAPON:
if (msg->_keyState.keycode >= Common::KEYCODE_a && msg->_keyState.keycode < (Common::KEYCODE_a + (int)c._weapons.size())) {
int index = msg->_keyState.keycode - Common::KEYCODE_a;
if (!c._weapons[index]->empty())
c._equippedWeapon = index;
}
addInfoMsg(Common::String::format("%s %s: %s", _game->_res->ACTION_NAMES[17],
_game->_res->WEAPON_armour_SPELL[0], c.equippedWeapon()->_longName.c_str()),
true, true);
hide();
break;
case READY_armour:
if (msg->_keyState.keycode >= Common::KEYCODE_a && msg->_keyState.keycode < (Common::KEYCODE_a + (int)c._armour.size())) {
int index = msg->_keyState.keycode - Common::KEYCODE_a;
if (!c._armour[index]->empty())
c._equippedArmour = index;
}
addInfoMsg(Common::String::format("%s %s: %s", _game->_res->ACTION_NAMES[17],
_game->_res->WEAPON_armour_SPELL[1], c.equippedArmour()->_name.c_str()),
true, true);
hide();
break;
case READY_SPELL:
if (msg->_keyState.keycode >= Common::KEYCODE_a && msg->_keyState.keycode < (Common::KEYCODE_a + (int)c._spells.size())) {
int index = msg->_keyState.keycode - Common::KEYCODE_a;
if (!c._spells[index]->empty())
c._equippedSpell = index;
}
addInfoMsg(Common::String::format("%s %s: %s", _game->_res->ACTION_NAMES[17],
_game->_res->WEAPON_armour_SPELL[2], c._spells[c._equippedSpell]->_name.c_str()),
true, true);
hide();
break;
default:
break;
}
return true;
}
void Ready::setMode(Mode mode) {
setDirty();
_mode = mode;
const Shared::Character &c = *_game->_party;
switch (mode) {
case READY_WEAPON:
if (c._weapons.hasNothing()) {
nothing();
} else {
addInfoMsg(Common::String::format("%s %s: ", _game->_res->ACTION_NAMES[17],
_game->_res->WEAPON_armour_SPELL[0]), false, true);
getKeypress();
}
break;
case READY_armour:
if (c._armour.hasNothing()) {
nothing();
} else {
addInfoMsg(Common::String::format("%s %s: ", _game->_res->ACTION_NAMES[17],
_game->_res->WEAPON_armour_SPELL[1]), false, true);
getKeypress();
}
break;
case READY_SPELL:
addInfoMsg(Common::String::format("%s %s: ", _game->_res->ACTION_NAMES[17],
_game->_res->WEAPON_armour_SPELL[2]), false, true);
getKeypress();
break;
default:
break;
}
}
void Ready::nothing() {
addInfoMsg(_game->_res->NOTHING);
hide();
}
void Ready::none() {
addInfoMsg(Common::String::format(" %s", _game->_res->NONE));
hide();
}
void Ready::draw() {
Dialog::draw();
switch (_mode) {
case READY_WEAPON:
drawReadyWeapon();
break;
case READY_armour:
drawReadyArmor();
break;
case READY_SPELL:
drawReadySpell();
break;
default:
break;
}
}
void Ready::drawReadyWeapon() {
Shared::Gfx::VisualSurface s = getSurface();
drawFrame(_game->_res->ACTION_NAMES[17]);
// Count the number of different types of weapons
const Shared::Character &c = *_game->_party;
int numLines = 0;
for (uint idx = 0; idx < c._weapons.size(); ++idx) {
if (!c._weapons[idx]->empty())
++numLines;
}
// Draw lines for weapons the player has
int yp = 10 - (numLines / 2);
for (uint idx = 0; idx < c._weapons.size(); ++idx) {
if (!c._weapons[idx]->empty()) {
Common::String text = Common::String::format("%c) %s", 'a' + idx, c._weapons[idx]->_longName.c_str());
s.writeString(text, TextPoint(15, yp++), (int)idx == c._equippedWeapon ? _game->_highlightColor : _game->_textColor);
}
}
}
void Ready::drawReadyArmor() {
Shared::Gfx::VisualSurface s = getSurface();
drawFrame(_game->_res->ACTION_NAMES[17]);
// Count the number of different types of weapons
const Shared::Character &c = *_game->_party;
int numLines = 0;
for (uint idx = 0; idx < c._armour.size(); ++idx) {
if (!c._armour[idx]->empty())
++numLines;
}
// Draw lines for armor the player has
int yp = 10 - (numLines / 2);
for (uint idx = 0; idx < c._armour.size(); ++idx) {
if (!c._armour[idx]->empty()) {
Common::String text = Common::String::format("%c) %s", 'a' + idx, c._armour[idx]->_name.c_str());
s.writeString(text, TextPoint(15, yp++), (int)idx == c._equippedArmour ? _game->_highlightColor : _game->_textColor);
}
}
}
void Ready::drawReadySpell() {
Shared::Gfx::VisualSurface s = getSurface();
drawFrame(_game->_res->ACTION_NAMES[17]);
// Count the number of different types of spells
const Shared::Character &c = *_game->_party;
int numLines = 0;
for (uint idx = 0; idx < c._spells.size(); ++idx) {
if (c._spells[idx]->_quantity)
++numLines;
}
// Draw lines for weapons the player has
int yp = 10 - (numLines / 2);
for (uint idx = 0; idx < c._spells.size(); ++idx) {
if (c._spells[idx]->_quantity) {
Common::String text = Common::String::format("%c) %s", 'a' + idx, c._spells[idx]->_name.c_str());
s.writeString(text, TextPoint(15, yp++), (int)idx == c._equippedSpell ? _game->_highlightColor : _game->_textColor);
}
}
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@@ -0,0 +1,93 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_READY_H
#define ULTIMA_ULTIMA1_U1DIALOGS_READY_H
#include "ultima/ultima1/u1dialogs/full_screen_dialog.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
using Shared::CShowMsg;
using Shared::CCharacterInputMsg;
/**
* Implements the Ready dialog
*/
class Ready : public FullScreenDialog {
DECLARE_MESSAGE_MAP;
bool ShowMsg(CShowMsg *msg);
bool CharacterInputMsg(CCharacterInputMsg *msg);
enum Mode { SELECT, READY_WEAPON, READY_armour, READY_SPELL };
private:
Mode _mode;
private:
/**
* Sets the mode
*/
void setMode(Mode mode);
/**
* Nothing selected
*/
void nothing();
/**
* None response
*/
void none();
/**
* Draw the ready weapon display
*/
void drawReadyWeapon();
/**
* Draw the ready armor display
*/
void drawReadyArmor();
/**
* Draw the ready spell display
*/
void drawReadySpell();
public:
CLASSDEF;
/**
* Constructor
*/
Ready(Ultima1Game *game);
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,175 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/stats.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/maps/map_overworld.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/widgets/transport.h"
#include "ultima/ultima1/u1gfx/drawing_support.h"
#include "ultima/shared/engine/messages.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
BEGIN_MESSAGE_MAP(Stats, FullScreenDialog)
ON_MESSAGE(ShowMsg)
ON_MESSAGE(CharacterInputMsg)
END_MESSAGE_MAP()
bool Stats::ShowMsg(CShowMsg *msg) {
addInfoMsg(_game->_res->PRESS_SPACE_TO_CONTINUE, false);
getKeypress();
return true;
}
bool Stats::CharacterInputMsg(CCharacterInputMsg *msg) {
if ((_startingIndex + 26U) < _stats.size()) {
_startingIndex += 26U;
setDirty();
getKeypress();
} else {
addInfoMsg("", false, true);
hide();
}
return true;
}
/**
* Counts the number of a given transport type
*/
template<class T>
void countTransport(Maps::MapOverworld *overworldMap, Common::Array<Stats::StatEntry> &stats, const char *name, byte textColor) {
// Count the number of transports that are of the given type
uint total = 0;
for (uint idx = 0; idx < overworldMap->_widgets.size(); ++idx) {
if (dynamic_cast<T *>(overworldMap->_widgets[idx].get()))
++total;
}
if (total > 0)
stats.push_back(Stats::StatEntry(Stats::formatStat(name, total), textColor));
}
void Stats::load() {
const Shared::Character &c = *_game->_party;
Maps::MapOverworld *overworld = getMap()->getOverworldMap();
// Basic attributes
const uint basicAttributes[7] = { c._hitPoints,c._strength, c._agility, c._stamina, c._charisma,c._wisdom, c._intelligence };
addStats(_game->_res->STAT_NAMES, basicAttributes, 0, 6);
// Money line(s)
if (c._coins % 10)
_stats.push_back(StatEntry(formatStat(_game->_res->STAT_NAMES[7], c._coins % 10), _game->_textColor));
if ((c._coins % 100) >= 10)
_stats.push_back(StatEntry(formatStat(_game->_res->STAT_NAMES[8], (c._coins / 10) % 10), _game->_textColor));
if (c._coins >= 100)
_stats.push_back(StatEntry(formatStat(_game->_res->STAT_NAMES[9], c._coins / 100), _game->_textColor));
// Enemy vessels
uint enemyVessels = overworld->getEnemyVesselCount();
if (enemyVessels != 0)
_stats.push_back(StatEntry(_game->_res->STAT_NAMES[9], enemyVessels));
// Armor, weapons, & spells
for (uint idx = 1; idx < c._armour.size(); ++idx) {
if (!c._armour[idx]->empty())
_stats.push_back(StatEntry(formatStat(c._armour[idx]->_name.c_str(), c._armour[idx]->_quantity),
(int)idx == c._equippedArmour ? _game->_highlightColor : _game->_textColor));
}
for (uint idx = 1; idx < c._weapons.size(); ++idx) {
if (!c._weapons[idx]->empty())
_stats.push_back(StatEntry(formatStat(c._weapons[idx]->_longName.c_str(), c._weapons[idx]->_quantity),
(int)idx == c._equippedWeapon ? _game->_highlightColor : _game->_textColor));
}
for (uint idx = 1; idx < c._spells.size(); ++idx) {
if (!c._spells[idx]->empty())
_stats.push_back(StatEntry(formatStat(c._spells[idx]->_name.c_str(), c._spells[idx]->_quantity),
(int)idx == c._equippedSpell ? _game->_highlightColor : _game->_textColor));
}
// Counts of transport types
countTransport<Widgets::Horse>(overworld, _stats, _game->_res->TRANSPORT_NAMES[1], _game->_textColor);
countTransport<Widgets::Cart>(overworld, _stats, _game->_res->TRANSPORT_NAMES[2], _game->_textColor);
countTransport<Widgets::Raft>(overworld, _stats, _game->_res->TRANSPORT_NAMES[3], _game->_textColor);
countTransport<Widgets::Frigate>(overworld, _stats, _game->_res->TRANSPORT_NAMES[4], _game->_textColor);
countTransport<Widgets::Aircar>(overworld, _stats, _game->_res->TRANSPORT_NAMES[5], _game->_textColor);
countTransport<Widgets::Shuttle>(overworld, _stats, _game->_res->TRANSPORT_NAMES[6], _game->_textColor);
countTransport<Widgets::TimeMachine>(overworld, _stats, _game->_res->TRANSPORT_NAMES[7], _game->_textColor);
// Add entries for any gems
addStats(_game->_res->GEM_NAMES, _game->_gems, 0, 3);
}
void Stats::addStats(const char *const *names, const uint *values, int start, int end, int equippedIndex) {
for (int idx = start; idx <= end; ++idx) {
if (values[idx]) {
Common::String line = formatStat(names[idx], values[idx]);
_stats.push_back(StatEntry(line, (idx == equippedIndex) ? _game->_highlightColor : _game->_textColor));
}
}
}
Common::String Stats::formatStat(const char *name, uint value) {
Common::String line(name);
Common::String val = Common::String::format("%u", value);
while ((line.size() + val.size()) < 17)
line += '.';
return line + val;
}
void Stats::draw() {
Dialog::draw();
drawFrame(_game->_res->INVENTORY);
Shared::Gfx::VisualSurface s = getSurface();
const Shared::Character &c = *_game->_party;
// Player name and description
s.writeString(Common::String::format(_game->_res->PLAYER, c._name.c_str()),
TextPoint(2, 2), _game->_edgeColor);
s.writeString(Common::String::format(_game->_res->PLAYER_DESC, c.getLevel(),
_game->_res->SEX_NAMES[c._sex], _game->_res->RACE_NAMES[c._race], _game->_res->CLASS_NAMES[c._class]),
TextPoint(2, 3), _game->_edgeColor);
// Display stats
for (uint idx = 0; idx < MIN(26U, _stats.size() - _startingIndex); ++idx) {
s.writeString(_stats[_startingIndex + idx]._line, TextPoint(idx >= 13 ? 21 : 2, (idx % 13) + 5), _stats[_startingIndex + idx]._color);
}
// Display a more sign if thare more than 26 remaining entries being displayed
if ((_startingIndex + 26) < _stats.size()) {
U1Gfx::DrawingSupport ds(s);
ds.drawRightArrow(TextPoint(16, 19));
s.writeString(_game->_res->MORE, TextPoint(17, 19));
ds.drawLeftArrow(TextPoint(23, 19));
}
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@@ -0,0 +1,101 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_STATS_H
#define ULTIMA_ULTIMA1_U1DIALOGS_STATS_H
#include "ultima/ultima1/u1dialogs/full_screen_dialog.h"
#include "common/array.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
using Shared::CShowMsg;
using Shared::CCharacterInputMsg;
/**
* Implements the stats/inventory dialog
*/
class Stats : public FullScreenDialog {
DECLARE_MESSAGE_MAP;
bool ShowMsg(CShowMsg *msg);
bool CharacterInputMsg(CCharacterInputMsg *msg);
public:
/**
* Contains the data for a single stat entry to display
*/
struct StatEntry {
Common::String _line;
byte _color;
StatEntry() : _color(0) {}
StatEntry(const Common::String &line, byte color) : _line(line), _color(color) {}
};
/**
* Format a name/value text with dots between them
* @param name Stat/item name
* @param value The value/quantity
* @returns The formatted display of name dots value
*/
static Common::String formatStat(const char *name, uint value);
private:
Common::Array<StatEntry> _stats;
uint _startingIndex;
private:
/**
* Loads the list of stats to display into an array
*/
void load();
/**
* Add a range of values into the stats list
* @param names Stat names
* @param values Values
* @param start Starting index
* @param end Ending index
* @param equippedIndex Equipped item index, if applicable
* @param row Starting text row
* @returns Ending text row
*/
void addStats(const char *const *names, const uint *values, int start, int end, int equippedIndex = -1);
public:
CLASSDEF;
/**
* Constructor
*/
Stats(Ultima1Game *game) : FullScreenDialog(game), _startingIndex(0) {
load();
}
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,203 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/tavern.h"
#include "ultima/ultima1/core/party.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/maps/map_city_castle.h"
#include "ultima/ultima1/game.h"
#include "ultima/shared/engine/messages.h"
#include "ultima/shared/core/str.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
BEGIN_MESSAGE_MAP(Tavern, BuySellDialog)
ON_MESSAGE(FrameMsg)
END_MESSAGE_MAP()
Tavern::Tavern(Ultima1Game *game, Maps::MapCityCastle *map, int tavernNum) :
BuySellDialog(game, game->_res->TAVERN_NAMES[tavernNum]), _map(map),
_countdown(0), _tipNumber(0), _buyDisplay(INITIAL) {
}
void Tavern::setMode(BuySell mode) {
switch (mode) {
case BUY:
_mode = BUY;
addInfoMsg(Common::String::format("%s%s%s", _game->_res->ACTION_NAMES[19], _game->_res->BUY, _game->_res->TAVERN_TEXT[3]), false, true);
setDirty();
delay(DIALOG_CLOSE_DELAY * 2);
break;
case SELL:
_mode = SELL;
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->SELL), false, true);
delay(DIALOG_CLOSE_DELAY * 2);
setDirty();
break;
default:
BuySellDialog::setMode(mode);
break;
}
}
bool Tavern::FrameMsg(CFrameMsg *msg) {
Shared::Character &c = *_game->_party;
if (_countdown > 0 && --_countdown == 0) {
switch (_mode) {
case BUY:
switch (_buyDisplay) {
case INITIAL:
if (c._coins == 0) {
close();
break;
}
if (++_map->_tipCounter > (c._stamina / 4) && _map->isWenchNearby()) {
_buyDisplay = TIP0;
_tipNumber = 0;
c._coins /= 2;
c._wisdom = MAX(c._wisdom - 1, 5U);
delay();
break;
}
// fall through
case TIP0:
if (_game->getRandomNumber(255) < 75) {
_buyDisplay = TIP_PAGE1;
_tipNumber = _game->getRandomNumber(11, 89) / 10;
delay((_tipNumber == 8) ? 7 * DIALOG_CLOSE_DELAY : 4 * DIALOG_CLOSE_DELAY);
} else {
close();
}
break;
case TIP_PAGE1:
if (_tipNumber == 8) {
_buyDisplay = TIP_PAGE2;
delay();
} else {
close();
}
break;
case TIP_PAGE2:
close();
break;
default:
break;
}
break;
case SELL:
addInfoMsg(_game->_res->NOTHING);
_game->endOfTurn();
hide();
break;
default:
break;
}
}
return true;
}
void Tavern::close() {
addInfoMsg("");
_game->endOfTurn();
hide();
}
void Tavern::draw() {
BuySellDialog::draw();
switch (_mode) {
case BUY:
drawBuy();
break;
case SELL:
drawSell();
break;
default:
break;
}
}
void Tavern::drawBuy() {
Shared::Gfx::VisualSurface s = getSurface();
const Shared::Character &c = *_game->_party;
int titleLines = String(_title).split("\r\n").size();
switch (_buyDisplay) {
case INITIAL:
if (c._coins == 0) {
// Broke
centerText(String(_game->_res->TAVERN_TEXT[0]).split("\r\n"), titleLines + 2);
} else {
// Initial ale give
centerText(String(_game->_res->TAVERN_TEXT[2]).split("\r\n"), titleLines + 2);
}
break;
case TIP0:
case TIP_PAGE1:
case TIP_PAGE2: {
if (_tipNumber != 0)
centerText(_game->_res->TAVERN_TIPS[0], 3);
switch (_tipNumber) {
case 2:
centerText(Common::String::format(_game->_res->TAVERN_TIPS[3],
_game->_res->TAVERN_TIPS[c._sex == Shared::SEX_MALE ? 11 : 12]), 4);
break;
case 8:
centerText(String(_game->_res->TAVERN_TIPS[_buyDisplay == TIP_PAGE1 ? 9 : 10]).split("\r\n"), 4);
break;
default:
centerText(String(_game->_res->TAVERN_TIPS[_tipNumber + 1]).split("\r\n"), 4);
break;
}
}
default:
break;
}
}
void Tavern::drawSell() {
int titleLines = String(_title).split("\r\n").size();
centerText(String(_game->_res->TAVERN_TEXT[1]).split("\r\n"), titleLines + 2);
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@@ -0,0 +1,93 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_TAVERN_H
#define ULTIMA_ULTIMA1_U1DIALOGS_TAVERN_H
#include "ultima/ultima1/u1dialogs/buy_sell_dialog.h"
namespace Ultima {
namespace Ultima1 {
namespace Maps {
class MapCityCastle;
}
namespace U1Dialogs {
/**
* Implements the buy/sell dialog for taverns
*/
class Tavern : public BuySellDialog {
DECLARE_MESSAGE_MAP;
bool FrameMsg(CFrameMsg *msg);
private:
Maps::MapCityCastle *_map;
//uint _tavernNum;
uint _tipNumber;
uint _countdown;
enum { INITIAL, TIP0, TIP_PAGE1, TIP_PAGE2 } _buyDisplay;
private:
/**
* Delay be a specified amount
*/
void delay(uint amount = 4 * DIALOG_CLOSE_DELAY) {
_countdown = amount;
setDirty();
}
/**
* Close the dialog
*/
void close();
/**
* Draws the Buy dialog content
*/
void drawBuy();
/**
* Draws the Sell dialog content
*/
void drawSell();
protected:
/**
* Set the mode
*/
void setMode(BuySell mode) override;
public:
CLASSDEF;
/**
* Constructor
*/
Tavern(Ultima1Game *game, Maps::MapCityCastle *map, int tavernNum);
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,229 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima1/u1dialogs/transports.h"
#include "ultima/ultima1/core/party.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/maps/map.h"
#include "ultima/ultima1/maps/map_city_castle.h"
#include "ultima/ultima1/maps/map_overworld.h"
#include "ultima/ultima1/maps/map_tile.h"
#include "ultima/ultima1/widgets/transport.h"
#include "ultima/ultima1/game.h"
#include "ultima/shared/engine/messages.h"
#include "ultima/shared/core/str.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
EMPTY_MESSAGE_MAP(Transports, BuySellDialog);
Transports::Transports(Ultima1Game *game, int transportsNum) : BuySellDialog(game, game->_res->WEAPONRY_NAMES[transportsNum]) {
loadOverworldFreeTiles();
}
void Transports::loadOverworldFreeTiles() {
Maps::MapOverworld *map = static_cast<Maps::Ultima1Map *>(_game->_map)->getOverworldMap();
Maps::Ultima1Map *currMap = static_cast<Maps::Ultima1Map *>(_game->_map);
Point delta;
Maps::U1MapTile mapTile;
_water = _woods = _grass = 0;
// Iterate through the tiles surrounding the city/castle
for (delta.y = -1; delta.y <= 1; ++delta.y) {
for (delta.x = -1; delta.x <= 1; ++delta.x) {
if (delta.x != 0 || delta.y != 0) {
map->getTileAt(map->getPosition() + delta, &mapTile);
if (!mapTile._widget) {
if (mapTile.isOriginalWater())
++_water;
else if (mapTile.isOriginalGrass())
++_grass;
else if (mapTile.isOriginalWoods())
++_woods;
}
}
}
}
// Count the number of transports
_transportCount = 0;
_hasShuttle = false;
for (uint idx = 0; idx < map->_widgets.size(); ++idx) {
if (dynamic_cast<Widgets::Transport *>(map->_widgets[idx].get()))
++_transportCount;
if (dynamic_cast<Widgets::Shuttle *>(map->_widgets[idx].get()))
_hasShuttle = true;
}
_hasFreeTiles = _water != 0 || _woods != 0 || _grass != 0;
_isClosed = !_hasFreeTiles || (_hasShuttle && _transportCount == 15)
|| (!_grass && _transportCount == 15);
bool flag = !_hasShuttle && _transportCount == 15;
_transports[0] = _transports[1] = (_woods || _grass) && !flag;
_transports[2] = _transports[3] = _water && !flag;
_transports[4] = currMap->_moveCounter > 3000 && _grass && !flag;
_transports[5] = currMap->_moveCounter > 3000 && _grass && !_hasShuttle;
}
void Transports::setMode(BuySell mode) {
_mode = mode;
setDirty();
switch (mode) {
case BUY: {
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->BUY), false, true);
if (_isClosed) {
addInfoMsg(_game->_res->NOTHING, false);
closeShortly();
} else {
getKeypress();
}
break;
}
case SELL:
addInfoMsg(Common::String::format("%s%s%s", _game->_res->ACTION_NAMES[19], _game->_res->SELL, _game->_res->NOTHING), false, true);
closeShortly();
break;
default:
BuySellDialog::setMode(mode);
break;
}
}
uint Transports::getBuyCost(int transportIndex) const {
const Shared::Character &c = *_game->_party;
return (200 - c._intelligence) / 5 * transportIndex * transportIndex;
}
void Transports::draw() {
BuySellDialog::draw();
switch (_mode) {
case BUY:
drawBuy();
break;
case SELL:
drawSell();
break;
default:
break;
}
}
void Transports::drawBuy() {
Shared::Gfx::VisualSurface s = getSurface();
int titleLines = String(_title).split("\r\n").size();
Common::String line;
if (_hasFreeTiles) {
for (int idx = 0, yp = titleLines + 2; idx < 6; ++idx) {
if (_transports[idx]) {
line = Common::String::format("%c) %s", 'a' + idx, _game->_res->TRANSPORT_NAMES[idx + 1]);
s.writeString(line, TextPoint(8, yp));
line = Common::String::format("- %u", getBuyCost(idx + 1));
s.writeString(line, TextPoint(19, yp));
++yp;
}
}
} else {
centerText(_game->_res->TRANSPORTS_TEXT[1], titleLines + 2);
}
}
void Transports::drawSell() {
int titleLines = String(_title).split("\r\n").size();
centerText(String(_game->_res->TRANSPORTS_TEXT[0]).split("\r\n"), titleLines + 2);
}
bool Transports::CharacterInputMsg(CCharacterInputMsg *msg) {
Shared::Character &c = *_game->_party;
int transportIndex = msg->_keyState.keycode - Common::KEYCODE_a;
if (_mode == BUY) {
if (msg->_keyState.keycode >= Common::KEYCODE_a &&
msg->_keyState.keycode <= Common::KEYCODE_f &&
_transports[transportIndex]) {
uint cost = getBuyCost(transportIndex + 1);
if (cost <= c._coins) {
// Display the bought transport name in the info area
addInfoMsg(_game->_res->TRANSPORT_NAMES[transportIndex + 1]);
// Remove the cost, and add in the new transport
c._coins -= cost;
addTransport(transportIndex);
// Show sold and close the dialog
setMode(SOLD);
return true;
}
}
nothing();
return true;
} else {
return BuySellDialog::CharacterInputMsg(msg);
}
}
void Transports::addTransport(int transportIndex) {
Maps::MapOverworld *map = static_cast<Maps::Ultima1Map *>(_game->_map)->getOverworldMap();
Point delta;
Maps::U1MapTile mapTile;
const char *const WIDGET_NAMES[6] = {
"Horse", "Cart", "Raft", "Frigate", "Aircar", "Shuttle"
};
// Iterate through the tiles surrounding the city/castle
for (delta.y = -1; delta.y <= 1; ++delta.y) {
for (delta.x = -1; delta.x <= 1; ++delta.x) {
map->getTileAt(map->getPosition() + delta, &mapTile);
if (!mapTile._widget && mapTile._locationNum == -1) {
if ((transportIndex <= 1 && (mapTile.isOriginalWoods() || (!_woods && mapTile.isOriginalGrass())))
|| (transportIndex >= 2 && transportIndex <= 3 && mapTile.isOriginalWater())
|| (transportIndex >= 4 && mapTile.isOriginalGrass())) {
// Add the transport onto the designated tile around the location
Shared::Maps::MapWidget *widget = map->createWidget(WIDGET_NAMES[transportIndex]);
assert(widget);
widget->_position = map->getPosition() + delta;
map->addWidget(widget);
return;
}
}
}
}
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@@ -0,0 +1,92 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_TRANSPORTS_H
#define ULTIMA_ULTIMA1_U1DIALOGS_TRANSPORTS_H
#include "ultima/ultima1/u1dialogs/buy_sell_dialog.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
using Shared::CCharacterInputMsg;
/**
* Implements the dialog for the transport merchant
*/
class Transports : public BuySellDialog {
DECLARE_MESSAGE_MAP;
bool CharacterInputMsg(CCharacterInputMsg *msg) override;
private:
uint _water, _woods, _grass;
bool _hasFreeTiles, _hasShuttle, _isClosed;
uint _transportCount;
bool _transports[6];
private:
/**
* Calculates the number of free tiles in the overworld
*/
void loadOverworldFreeTiles();
/**
* Draws the Buy dialog content
*/
void drawBuy();
/**
* Draws the Sell dialog content
*/
void drawSell();
/**
* Gets the cost for buying a given transport
*/
uint getBuyCost(int transportIndex) const;
/**
* Add a transport to the overworld map
*/
void addTransport(int transportIndex);
protected:
/**
* Set the mode
*/
void setMode(BuySell mode) override;
public:
CLASSDEF;
/**
* Constructor
*/
Transports(Ultima1Game *game, int transportNum);
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@@ -0,0 +1,193 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#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"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
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) {
Shared::Character &c = *_game->_party;
switch (mode) {
case BUY: {
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->BUY), false, true);
_mode = BUY;
setDirty();
getKeypress();
break;
}
case SELL:
addInfoMsg(Common::String::format("%s%s", _game->_res->ACTION_NAMES[19], _game->_res->SELL), false, true);
if (c._weapons.hasNothing()) {
addInfoMsg(_game->_res->NOTHING);
closeShortly();
} else {
getKeypress();
}
_mode = SELL;
setDirty();
break;
default:
BuySellDialog::setMode(mode);
break;
}
}
void Weaponry::draw() {
BuySellDialog::draw();
switch (_mode) {
case BUY:
drawBuy();
break;
case SELL:
drawSell();
break;
default:
break;
}
}
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;
int lineCount = c._weapons.itemsCount();
int titleLines = String(_title).split("\r\n").size();
Common::String line;
if (lineCount == 0) {
centerText(_game->_res->NO_WEAPONRY_TO_SELL, titleLines + 2);
} else {
for (uint idx = 1; idx < c._weapons.size(); ++idx) {
const Weapon &weapon = *static_cast<Weapon *>(c._weapons[idx]);
if (!weapon.empty()) {
line = Common::String::format("%c) %s", 'a' + idx, weapon._longName.c_str());
s.writeString(line, TextPoint(5, idx + titleLines + 1));
line = Common::String::format("-%4u", weapon.getSellCost());
s.writeString(line, TextPoint(22, idx + titleLines + 1));
}
}
}
}
bool Weaponry::CharacterInputMsg(CCharacterInputMsg *msg) {
Shared::Character &c = *_game->_party;
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 (!weapon.empty()) {
// Display the sold weapon in the info area
addInfoMsg(weapon._longName);
// Give coins for weapon and remove it from the inventory
c._coins += weapon.getSellCost();
if (weapon.decrQuantity() && (int)weaponNum == c._equippedWeapon)
c.removeWeapon();
// Close the dialog
setMode(DONE);
return true;
}
}
nothing();
return true;
} else {
return BuySellDialog::CharacterInputMsg(msg);
}
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@@ -0,0 +1,73 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ULTIMA_ULTIMA1_U1DIALOGS_WEAPONRY_H
#define ULTIMA_ULTIMA1_U1DIALOGS_WEAPONRY_H
#include "ultima/ultima1/u1dialogs/buy_sell_dialog.h"
namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
/**
* Implements the buy/sell dialog for grocers
*/
class Weaponry : public BuySellDialog {
DECLARE_MESSAGE_MAP;
bool CharacterInputMsg(CCharacterInputMsg *msg) override;
private:
// uint _weaponryNum;
uint _startIndex, _endIndex;
private:
/**
* Draws the Buy dialog content
*/
void drawBuy();
/**
* Draws the Sell dialog content
*/
void drawSell();
protected:
/**
* Set the mode
*/
void setMode(BuySell mode) override;
public:
CLASSDEF;
/**
* Constructor
*/
Weaponry(Ultima1Game *game, int weaponryNum);
/**
* Draws the visual item on the screen
*/
void draw() override;
};
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima
#endif