Browse Source

Apply clang-tidy to more code and do some related cleanups

pull/2050/head
Anders Jenbo 5 years ago
parent
commit
6ce8f13751
  1. 8
      Source/control.cpp
  2. 2
      Source/controls/modifier_hints.cpp
  3. 54
      Source/engine/render/text_render.cpp
  4. 120
      Source/gmenu.cpp
  5. 4
      Source/gmenu.h
  6. 6
      Source/help.cpp
  7. 704
      Source/inv.cpp
  8. 10
      Source/inv.h
  9. 8
      Source/minitext.cpp
  10. 6
      Source/player.cpp
  11. 2
      Source/player.h
  12. 477
      Source/stores.cpp
  13. 4
      test/inv_test.cpp

8
Source/control.cpp

@ -5,8 +5,8 @@
*/
#include "control.h"
#include <cstddef>
#include <array>
#include <cstddef>
#include <fmt/format.h>
@ -320,7 +320,7 @@ static void DrawSpell(const CelOutputBuffer &out)
DrawSpellCel(out, PANEL_X + 565, PANEL_Y + 119, *pSpellCels, 27);
}
static void PrintSBookHotkey(CelOutputBuffer out, int x, int y, const std::string &text)
static void PrintSBookHotkey(const CelOutputBuffer& out, int x, int y, const std::string &text)
{
x -= GetLineWidth(text.c_str()) + 5;
x += SPLICONLENGTH;
@ -550,7 +550,7 @@ void DrawPanelBox(const CelOutputBuffer &out, int x, int y, int w, int h, int sx
* @param y0 Top of the flask cel section to draw.
* @param y1 Bottom of the flask cel section to draw.
*/
static void DrawFlaskTop(const CelOutputBuffer &out, int sx, int sy, CelOutputBuffer celBuf, int y0, int y1)
static void DrawFlaskTop(const CelOutputBuffer &out, int sx, int sy, const CelOutputBuffer& celBuf, int y0, int y1)
{
const BYTE *src = celBuf.at(0, y0);
BYTE *dst = out.at(sx, sy);
@ -1757,7 +1757,7 @@ void control_remove_gold(int pnum, int goldIndex)
plr[pnum].HoldItem._ivalue = dropGoldValue;
plr[pnum].HoldItem._iStatFlag = true;
control_set_gold_curs(pnum);
plr[pnum]._pGold = CalculateGold(pnum);
plr[pnum]._pGold = CalculateGold(plr[pnum]);
dropGoldValue = 0;
}

2
Source/controls/modifier_hints.cpp

@ -46,7 +46,7 @@ struct CircleMenuHint {
{
}
int Width() const
[[nodiscard]] int Width() const
{
return 2 * xMid;
}

54
Source/engine/render/text_render.cpp

@ -4,11 +4,11 @@
* Text rendering.
*/
#include "engine.h"
#include "text_render.hpp"
#include "DiabloUI/ui_item.h"
#include "cel_render.hpp"
#include "engine.h"
#include "palette.h"
#include "DiabloUI/ui_item.h"
namespace devilution {
@ -19,7 +19,7 @@ namespace {
* small, medium and large sized fonts; which corresponds to smaltext.cel,
* medtexts.cel and bigtgold.cel respectively.
*/
const uint8_t gbFontTransTbl[256] = {
const uint8_t FontIndex[256] = {
// clang-format off
'\0', 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
@ -41,7 +41,7 @@ const uint8_t gbFontTransTbl[256] = {
};
/** Maps from font index to cel frame number. */
const uint8_t fontframe[3][128] = {
const uint8_t FontFrame[3][128] = {
{
// clang-format off
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -84,7 +84,7 @@ const uint8_t fontframe[3][128] = {
* Maps from cel frame number to character width. Note, the character width
* may be distinct from the frame width, which is the same for every cel frame.
*/
const uint8_t fontkern[3][68] = {
const uint8_t FontKern[3][68] = {
{
// clang-format off
8, 10, 7, 9, 8, 7, 6, 8, 8, 3,
@ -119,11 +119,11 @@ const uint8_t fontkern[3][68] = {
};
enum text_color : uint8_t {
COL_WHITE,
COL_BLUE,
COL_RED,
COL_GOLD,
COL_BLACK,
ColorWhite,
ColorBlue,
ColorRed,
ColorGold,
ColorBlack,
};
int LineHeights[3] = { 12, 38, 50 };
@ -135,22 +135,22 @@ uint8_t fontColorTableGold[256];
uint8_t fontColorTableBlue[256];
uint8_t fontColorTableRed[256];
static void DrawChar(const CelOutputBuffer &out, Point point, GameFontTables size, int nCel, text_color color)
void DrawChar(const CelOutputBuffer &out, Point point, GameFontTables size, int nCel, text_color color)
{
switch (color) {
case COL_WHITE:
case ColorWhite:
CelDrawTo(out, point.x, point.y, *fonts[size], nCel);
return;
case COL_BLUE:
case ColorBlue:
CelDrawLightTo(out, point.x, point.y, *fonts[size], nCel, fontColorTableBlue);
break;
case COL_RED:
case ColorRed:
CelDrawLightTo(out, point.x, point.y, *fonts[size], nCel, fontColorTableRed);
break;
case COL_GOLD:
case ColorGold:
CelDrawLightTo(out, point.x, point.y, *fonts[size], nCel, fontColorTableGold);
break;
case COL_BLACK:
case ColorBlack:
light_table_index = 15;
CelDrawLightTo(out, point.x, point.y, *fonts[size], nCel, nullptr);
return;
@ -214,8 +214,8 @@ int GetLineWidth(const char *text, GameFontTables size, int spacing, int *charac
if (text[i] == '\n')
break;
uint8_t frame = fontframe[size][gbFontTransTbl[static_cast<uint8_t>(text[i])]];
lineWidth += fontkern[size][frame] + spacing;
uint8_t frame = FontFrame[size][FontIndex[static_cast<uint8_t>(text[i])]];
lineWidth += FontKern[size][frame] + spacing;
}
if (charactersInLine != nullptr)
@ -247,8 +247,8 @@ void WordWrapGameString(char *text, size_t width, GameFontTables size, int spaci
continue;
}
uint8_t frame = fontframe[size][gbFontTransTbl[static_cast<uint8_t>(text[i])]];
lineWidth += fontkern[size][frame] + spacing;
uint8_t frame = FontFrame[size][FontIndex[static_cast<uint8_t>(text[i])]];
lineWidth += FontKern[size][frame] + spacing;
if (lineWidth - spacing <= width) {
continue; // String is still within the limit, continue to the next line
@ -286,15 +286,15 @@ int DrawString(const CelOutputBuffer &out, const char *text, const SDL_Rect &rec
else if ((flags & UIS_HUGE) != 0)
size = GameFontBig;
text_color color = COL_GOLD;
text_color color = ColorGold;
if ((flags & UIS_SILVER) != 0)
color = COL_WHITE;
color = ColorWhite;
else if ((flags & UIS_BLUE) != 0)
color = COL_BLUE;
color = ColorBlue;
else if ((flags & UIS_RED) != 0)
color = COL_RED;
color = ColorRed;
else if ((flags & UIS_BLACK) != 0)
color = COL_BLACK;
color = ColorBlack;
const int w = rect.w != 0 ? rect.w : out.w() - rect.x;
const int h = rect.h != 0 ? rect.h : out.h() - rect.y;
@ -325,8 +325,8 @@ int DrawString(const CelOutputBuffer &out, const char *text, const SDL_Rect &rec
unsigned i = 0;
for (; i < textLength; i++) {
uint8_t frame = fontframe[size][gbFontTransTbl[static_cast<uint8_t>(text[i])]];
int symbolWidth = fontkern[size][frame];
uint8_t frame = FontFrame[size][FontIndex[static_cast<uint8_t>(text[i])]];
int symbolWidth = FontKern[size][frame];
if (text[i] == '\n' || sx + symbolWidth > rightMargin) {
if (sy + lineHeight >= bottomMargin)
break;

120
Source/gmenu.cpp

@ -73,21 +73,19 @@ bool gmenu_is_active()
return sgpCurrentMenu != nullptr;
}
static void gmenu_up_down(bool isDown)
static void GmenuUpDown(bool isDown)
{
int i;
if (sgpCurrItem == nullptr) {
return;
}
mouseNavigation = false;
i = sgCurrentMenuIdx;
if (sgCurrentMenuIdx) {
while (i) {
int i = sgCurrentMenuIdx;
if (sgCurrentMenuIdx != 0) {
while (i != 0) {
i--;
if (isDown) {
sgpCurrItem++;
if (!sgpCurrItem->fnMenu)
if (sgpCurrItem->fnMenu == nullptr)
sgpCurrItem = &sgpCurrentMenu[0];
} else {
if (sgpCurrItem == sgpCurrentMenu)
@ -95,7 +93,7 @@ static void gmenu_up_down(bool isDown)
sgpCurrItem--;
}
if ((sgpCurrItem->dwFlags & GMENU_ENABLED) != 0) {
if (i)
if (i != 0)
PlaySFX(IS_TITLEMOV);
return;
}
@ -103,15 +101,13 @@ static void gmenu_up_down(bool isDown)
}
}
static void gmenu_left_right(bool isRight)
static void GmenuLeftRight(bool isRight)
{
int step, steps;
if ((sgpCurrItem->dwFlags & GMENU_SLIDER) == 0)
return;
step = sgpCurrItem->dwFlags & 0xFFF;
steps = (int)(sgpCurrItem->dwFlags & 0xFFF000) >> 12;
int step = sgpCurrItem->dwFlags & 0xFFF;
int steps = (int)(sgpCurrItem->dwFlags & 0xFFF000) >> 12;
if (isRight) {
if (step == steps)
return;
@ -128,8 +124,6 @@ static void gmenu_left_right(bool isRight)
void gmenu_set_items(TMenuItem *pItem, void (*gmFunc)())
{
int i;
PauseMode = 0;
mouseNavigation = false;
sgpCurrentMenu = pItem;
@ -140,25 +134,25 @@ void gmenu_set_items(TMenuItem *pItem, void (*gmFunc)())
}
sgCurrentMenuIdx = 0;
if (sgpCurrentMenu != nullptr) {
for (i = 0; sgpCurrentMenu[i].fnMenu != nullptr; i++) {
for (int i = 0; sgpCurrentMenu[i].fnMenu != nullptr; i++) {
sgCurrentMenuIdx++;
}
}
// BUGFIX: OOB access when sgCurrentMenuIdx is 0; should be set to NULL instead. (fixed)
sgpCurrItem = sgCurrentMenuIdx > 0 ? &sgpCurrentMenu[sgCurrentMenuIdx - 1] : nullptr;
gmenu_up_down(true);
GmenuUpDown(true);
}
static void gmenu_clear_buffer(const CelOutputBuffer &out, int x, int y, int width, int height)
static void GmenuClearBuffer(const CelOutputBuffer &out, int x, int y, int width, int height)
{
BYTE *i = out.at(x, y);
while (height--) {
while ((height--) != 0) {
memset(i, 205, width);
i -= out.pitch();
}
}
static int gmenu_get_lfont(TMenuItem *pItem)
static int GmenuGetLfont(TMenuItem *pItem)
{
if ((pItem->dwFlags & GMENU_SLIDER) != 0)
return 490;
@ -166,21 +160,21 @@ static int gmenu_get_lfont(TMenuItem *pItem)
return GetLineWidth(_(pItem->pszStr), GameFontBig, 2);
}
static void gmenu_draw_menu_item(const CelOutputBuffer &out, TMenuItem *pItem, int y)
static void GmenuDrawMenuItem(const CelOutputBuffer &out, TMenuItem *pItem, int y)
{
int w = gmenu_get_lfont(pItem);
int w = GmenuGetLfont(pItem);
if ((pItem->dwFlags & GMENU_SLIDER) != 0) {
int x = 16 + w / 2;
CelDrawTo(out, x + PANEL_LEFT, y - 10, *optbar_cel, 1);
int step = pItem->dwFlags & 0xFFF;
int nSteps = std::max<int>((pItem->dwFlags & 0xFFF000) >> 12, 2);
int pos = step * 256 / nSteps;
gmenu_clear_buffer(out, x + 2 + PANEL_LEFT, y - 12, pos + 13, 28);
GmenuClearBuffer(out, x + 2 + PANEL_LEFT, y - 12, pos + 13, 28);
CelDrawTo(out, x + 2 + pos + PANEL_LEFT, y - 12, *option_cel, 1);
}
int x = (gnScreenWidth - w) / 2;
uint16_t style = (pItem->dwFlags & GMENU_ENABLED) ? UIS_SILVER : UIS_BLACK;
uint16_t style = (pItem->dwFlags & GMENU_ENABLED) != 0 ? UIS_SILVER : UIS_BLACK;
DrawString(out, _(pItem->pszStr), { x, y, 0, 0 }, style | UIS_HUGE, 2);
if (pItem == sgpCurrItem) {
CelDrawTo(out, x - 54, y + 1, *PentSpin_cel, PentSpn2Spin());
@ -191,18 +185,15 @@ static void gmenu_draw_menu_item(const CelOutputBuffer &out, TMenuItem *pItem, i
static void GameMenuMove()
{
static AxisDirectionRepeater repeater;
const AxisDirection move_dir = repeater.Get(GetLeftStickOrDpadDirection());
if (move_dir.x != AxisDirectionX_NONE)
gmenu_left_right(move_dir.x == AxisDirectionX_RIGHT);
if (move_dir.y != AxisDirectionY_NONE)
gmenu_up_down(move_dir.y == AxisDirectionY_DOWN);
const AxisDirection moveDir = repeater.Get(GetLeftStickOrDpadDirection());
if (moveDir.x != AxisDirectionX_NONE)
GmenuLeftRight(moveDir.x == AxisDirectionX_RIGHT);
if (moveDir.y != AxisDirectionY_NONE)
GmenuUpDown(moveDir.y == AxisDirectionY_DOWN);
}
void gmenu_draw(const CelOutputBuffer &out)
{
int y;
TMenuItem *i;
if (sgpCurrentMenu != nullptr) {
GameMenuMove();
if (gmenu_current_option != nullptr)
@ -217,11 +208,11 @@ void gmenu_draw(const CelOutputBuffer &out)
}
}
CelDrawTo(out, (gnScreenWidth - sgpLogo->Width()) / 2, 102 + UI_OFFSET_Y, *sgpLogo, LogoAnim_frame);
y = 160 + UI_OFFSET_Y;
i = sgpCurrentMenu;
int y = 160 + UI_OFFSET_Y;
TMenuItem *i = sgpCurrentMenu;
if (sgpCurrentMenu->fnMenu != nullptr) {
while (i->fnMenu != nullptr) {
gmenu_draw_menu_item(out, i, y);
GmenuDrawMenuItem(out, i, y);
i++;
y += 45;
}
@ -247,58 +238,61 @@ bool gmenu_presskeys(int vkey)
case DVL_VK_SPACE:
return false;
case DVL_VK_LEFT:
gmenu_left_right(false);
GmenuLeftRight(false);
break;
case DVL_VK_RIGHT:
gmenu_left_right(true);
GmenuLeftRight(true);
break;
case DVL_VK_UP:
gmenu_up_down(false);
GmenuUpDown(false);
break;
case DVL_VK_DOWN:
gmenu_up_down(true);
GmenuUpDown(true);
break;
}
return true;
}
static bool gmenu_get_mouse_slider(int *plOffset)
static bool GmenuMouseNavigation()
{
*plOffset = 282;
if (MouseX < 282 + PANEL_LEFT) {
*plOffset = 0;
return false;
}
if (MouseX > 538 + PANEL_LEFT) {
*plOffset = 256;
return false;
}
*plOffset = MouseX - 282 - PANEL_LEFT;
return true;
}
bool gmenu_on_mouse_move()
static int GmenuGetMouseSlider()
{
int step, nSteps;
if (MouseX < 282 + PANEL_LEFT) {
return 0;
}
if (MouseX > 538 + PANEL_LEFT) {
return 256;
}
return MouseX - 282 - PANEL_LEFT;
}
bool gmenu_on_mouse_move()
{
if (!mouseNavigation)
return false;
gmenu_get_mouse_slider(&step);
nSteps = (int)(sgpCurrItem->dwFlags & 0xFFF000) >> 12;
step *= nSteps;
int step = (int)(sgpCurrItem->dwFlags & 0xFFF000) >> 12;
step *= GmenuGetMouseSlider();
step /= 256;
sgpCurrItem->dwFlags &= 0xFFFFF000;
sgpCurrItem->dwFlags |= step;
sgpCurrItem->fnMenu(false);
return true;
}
bool gmenu_left_mouse(bool isDown)
{
TMenuItem *pItem;
int i, w, dummy;
if (!isDown) {
if (mouseNavigation) {
mouseNavigation = false;
@ -316,15 +310,15 @@ bool gmenu_left_mouse(bool isDown)
if (MouseY - (117 + UI_OFFSET_Y) < 0) {
return true;
}
i = (MouseY - (117 + UI_OFFSET_Y)) / 45;
int i = (MouseY - (117 + UI_OFFSET_Y)) / 45;
if (i >= sgCurrentMenuIdx) {
return true;
}
pItem = &sgpCurrentMenu[i];
TMenuItem *pItem = &sgpCurrentMenu[i];
if ((sgpCurrentMenu[i].dwFlags & GMENU_ENABLED) == 0) {
return true;
}
w = gmenu_get_lfont(pItem);
int w = GmenuGetLfont(pItem);
if (MouseX < gnScreenWidth / 2 - w / 2) {
return true;
}
@ -334,7 +328,7 @@ bool gmenu_left_mouse(bool isDown)
sgpCurrItem = pItem;
PlaySFX(IS_TITLEMOV);
if ((pItem->dwFlags & GMENU_SLIDER) != 0) {
mouseNavigation = gmenu_get_mouse_slider(&dummy);
mouseNavigation = GmenuMouseNavigation();
gmenu_on_mouse_move();
} else {
sgpCurrItem->fnMenu(true);
@ -355,12 +349,8 @@ void gmenu_enable(TMenuItem *pMenuItem, bool enable)
*/
void gmenu_slider_set(TMenuItem *pItem, int min, int max, int value)
{
int nSteps;
assert(pItem);
nSteps = (int)(pItem->dwFlags & 0xFFF000) >> 12;
if (nSteps < 2)
nSteps = 2;
int nSteps = std::max((int)(pItem->dwFlags & 0xFFF000) >> 12, 2);
pItem->dwFlags &= 0xFFFFF000;
pItem->dwFlags |= ((max - min - 1) / 2 + (value - min) * nSteps) / (max - min);
}
@ -370,12 +360,8 @@ void gmenu_slider_set(TMenuItem *pItem, int min, int max, int value)
*/
int gmenu_slider_get(TMenuItem *pItem, int min, int max)
{
int nSteps, step;
step = pItem->dwFlags & 0xFFF;
nSteps = (int)(pItem->dwFlags & 0xFFF000) >> 12;
if (nSteps < 2)
nSteps = 2;
int step = pItem->dwFlags & 0xFFF;
int nSteps = std::max((int)(pItem->dwFlags & 0xFFF000) >> 12, 2);
return min + (step * (max - min) + (nSteps - 1) / 2) / nSteps;
}

4
Source/gmenu.h

@ -32,8 +32,8 @@ bool gmenu_presskeys(int vkey);
bool gmenu_on_mouse_move();
bool gmenu_left_mouse(bool isDown);
void gmenu_enable(TMenuItem *pMenuItem, bool enable);
void gmenu_slider_set(TMenuItem *pItem, int min, int max, int gamma);
void gmenu_slider_set(TMenuItem *pItem, int min, int max, int value);
int gmenu_slider_get(TMenuItem *pItem, int min, int max);
void gmenu_slider_steps(TMenuItem *pItem, int dwTicks);
void gmenu_slider_steps(TMenuItem *pItem, int steps);
} // namespace devilution

6
Source/help.cpp

@ -19,7 +19,7 @@ namespace devilution {
unsigned int SkipLines;
bool helpflag;
const char *const gszHelpText[] = {
const char *const HelpText[] = {
N_("$Keyboard Shortcuts:"),
N_("F1: Open Help Screen"),
N_("Esc: Display Main Menu"),
@ -98,7 +98,7 @@ void InitHelp()
helpflag = false;
char tempstr[512];
for (auto text : gszHelpText) {
for (const auto *text : HelpText) {
strcpy(tempstr, _(text));
WordWrapGameString(tempstr, 577);
@ -106,7 +106,7 @@ void InitHelp()
size_t previous = 0;
while (true) {
size_t next = paragraph.find("\n", previous);
size_t next = paragraph.find('\n', previous);
HelpTextLines.emplace_back(paragraph.substr(previous, next));
if (next == std::string::npos)
break;

704
Source/inv.cpp

File diff suppressed because it is too large Load Diff

10
Source/inv.h

@ -101,14 +101,14 @@ bool AutoEquip(int playerNumber, const ItemStruct &item, bool persistItem = true
bool AutoPlaceItemInInventory(PlayerStruct &player, const ItemStruct &item, bool persistItem = false);
bool AutoPlaceItemInInventorySlot(PlayerStruct &player, int slotIndex, const ItemStruct &item, bool persistItem);
bool AutoPlaceItemInBelt(int playerNumber, const ItemStruct &item, bool persistItem = false);
bool GoldAutoPlace(int pnum);
bool GoldAutoPlaceInInventorySlot(int pnum, int slotIndex);
bool GoldAutoPlace(PlayerStruct &player);
bool GoldAutoPlaceInInventorySlot(PlayerStruct &player, int slotIndex);
void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff);
void inv_update_rem_item(int pnum, BYTE iv);
void RemoveSpdBarItem(int pnum, int iv);
void CheckInvItem(bool isShiftHeld = false);
void CheckInvScrn(bool isShiftHeld);
void CheckItemStats(int pnum);
void CheckItemStats(PlayerStruct &player);
void InvGetItem(int pnum, ItemStruct *item, int ii);
void AutoGetItem(int pnum, ItemStruct *item, int ii);
int FindGetItem(int idx, uint16_t ci, int iseed);
@ -117,7 +117,7 @@ bool CanPut(int x, int y);
bool TryInvPut();
void DrawInvMsg(const char *msg);
int InvPutItem(int pnum, Point position);
int SyncPutItem(int pnum, Point position, int idx, uint16_t icreateinfo, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, DWORD ibuff, int to_hit, int max_dam, int min_str, int min_mag, int min_dex, int ac);
int SyncPutItem(int pnum, Point position, int idx, uint16_t icreateinfo, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, DWORD ibuff, int toHit, int maxDam, int minStr, int minMag, int minDex, int ac);
char CheckInvHLight();
void RemoveScroll(int pnum);
bool UseScroll();
@ -125,7 +125,7 @@ void UseStaffCharge(int pnum);
bool UseStaff();
bool UseInvItem(int pnum, int cii);
void DoTelekinesis();
int CalculateGold(int pnum);
int CalculateGold(PlayerStruct &player);
bool DropItemBeforeTrig();
/* data */

8
Source/minitext.cpp

@ -47,7 +47,7 @@ void LoadText(const char *text)
size_t previous = 0;
while (true) {
size_t next = paragraphs.find("\n", previous);
size_t next = paragraphs.find('\n', previous);
TextLines.emplace_back(paragraphs.substr(previous, next));
if (next == std::string::npos)
break;
@ -65,8 +65,8 @@ int CalculateTextSpeed(int nSFX)
const int numLines = TextLines.size();
#ifndef NOSOUND
Uint32 SfxFrames = GetSFXLength(nSFX);
assert(SfxFrames != 0);
Uint32 sfxFrames = GetSFXLength(nSFX);
assert(sfxFrames != 0);
#else
// Sound is disabled -- estimate length from the number of lines.
Uint32 SfxFrames = numLines * 3000;
@ -75,7 +75,7 @@ int CalculateTextSpeed(int nSFX)
int textHeight = LineHeight * numLines;
textHeight += LineHeight * 5; // adjust so when speaker is done two line are left
return SfxFrames / textHeight;
return sfxFrames / textHeight;
}
int CalculateTextPosition()

6
Source/player.cpp

@ -2029,7 +2029,7 @@ void DropHalfPlayersGold(int pnum)
}
}
}
player._pGold = CalculateGold(pnum);
player._pGold = CalculateGold(player);
}
void StripTopGold(int pnum)
@ -2054,12 +2054,12 @@ void StripTopGold(int pnum)
GetGoldSeed(pnum, &player.HoldItem);
player.HoldItem._ivalue = val;
SetPlrHandGoldCurs(&player.HoldItem);
if (!GoldAutoPlace(pnum))
if (!GoldAutoPlace(player))
PlrDeadItem(player, &player.HoldItem, 0, 0);
}
}
}
player._pGold = CalculateGold(pnum);
player._pGold = CalculateGold(player);
player.HoldItem = tmpItem;
}

2
Source/player.h

@ -375,7 +375,7 @@ struct PlayerStruct {
void Say(HeroSpeech speechId) const;
/**
* @brief Says a speech line after a given delay.
* @param delay Multiple of 20ms wait before starting the speech
* @param delay Multiple of 50ms wait before starting the speech
*/
void Say(HeroSpeech speechId, int delay) const;
/**

477
Source/stores.cpp

@ -61,7 +61,7 @@ _speech_id gossipstart;
_speech_id gossipend;
/** Maps from towner IDs to NPC names. */
const char *const talkname[] = {
const char *const TownerNames[] = {
"Griswold",
"Pepin",
"",
@ -81,10 +81,8 @@ void DrawSTextBack(const CelOutputBuffer &out)
void DrawSSlider(const CelOutputBuffer &out, int y1, int y2)
{
int yd1, yd2, yd3;
yd1 = y1 * 12 + 44 + UI_OFFSET_Y;
yd2 = y2 * 12 + 44 + UI_OFFSET_Y;
int yd1 = y1 * 12 + 44 + UI_OFFSET_Y;
int yd2 = y2 * 12 + 44 + UI_OFFSET_Y;
if (stextscrlubtn != -1)
CelDrawTo(out, PANEL_X + 601, yd1, *pSTextSlidCels, 12);
else
@ -94,7 +92,8 @@ void DrawSSlider(const CelOutputBuffer &out, int y1, int y2)
else
CelDrawTo(out, PANEL_X + 601, yd2, *pSTextSlidCels, 9);
yd1 += 12;
for (yd3 = yd1; yd3 < yd2; yd3 += 12) {
int yd3 = yd1;
for (; yd3 < yd2; yd3 += 12) {
CelDrawTo(out, PANEL_X + 601, yd3, *pSTextSlidCels, 14);
}
if (stextsel == 22)
@ -139,8 +138,6 @@ void AddSText(int x, int y, const char *str, uint16_t flags, bool sel)
void PrintStoreItem(ItemStruct *x, int l, uint16_t flags)
{
char sstr[128];
char str, dex;
BYTE mag;
sstr[0] = '\0';
if (x->_iIdentified) {
@ -152,18 +149,18 @@ void PrintStoreItem(ItemStruct *x, int l, uint16_t flags)
}
if (x->_iSufPower != -1) {
PrintItemPower(x->_iSufPower, x);
if (sstr[0])
if (sstr[0] != '\0')
strcat(sstr, _(", "));
strcat(sstr, tempstr);
}
}
if (x->_iMiscId == IMISC_STAFF && x->_iMaxCharges) {
if (x->_iMiscId == IMISC_STAFF && x->_iMaxCharges != 0) {
strcpy(tempstr, fmt::format(_("Charges: {:d}/{:d}"), x->_iCharges, x->_iMaxCharges).c_str());
if (sstr[0])
if (sstr[0] != '\0')
strcat(sstr, _(", "));
strcat(sstr, tempstr);
}
if (sstr[0]) {
if (sstr[0] != '\0') {
AddSText(40, l, sstr, flags, false);
l++;
}
@ -172,7 +169,7 @@ void PrintStoreItem(ItemStruct *x, int l, uint16_t flags)
strcpy(sstr, fmt::format(_("Damage: {:d}-{:d} "), x->_iMinDam, x->_iMaxDam).c_str());
if (x->_iClass == ICLASS_ARMOR)
strcpy(sstr, fmt::format(_("Armor: {:d} "), x->_iAC).c_str());
if (x->_iMaxDur != DUR_INDESTRUCTIBLE && x->_iMaxDur) {
if (x->_iMaxDur != DUR_INDESTRUCTIBLE && x->_iMaxDur != 0) {
strcpy(tempstr, fmt::format(_("Dur: {:d}/{:d}, "), x->_iDurability, x->_iMaxDur).c_str());
strcat(sstr, tempstr);
} else {
@ -180,18 +177,18 @@ void PrintStoreItem(ItemStruct *x, int l, uint16_t flags)
}
if (x->_itype == ITYPE_MISC)
sstr[0] = '\0';
str = x->_iMinStr;
mag = x->_iMinMag;
dex = x->_iMinDex;
int8_t str = x->_iMinStr;
uint8_t mag = x->_iMinMag;
int8_t dex = x->_iMinDex;
if (str == 0 && mag == 0 && dex == 0) {
strcat(sstr, _("No required attributes"));
} else {
strcpy(tempstr, _("Required:"));
if (str)
if (str != 0)
strcpy(tempstr + strlen(tempstr), fmt::format(_(" {:d} Str"), str).c_str());
if (mag)
if (mag != 0)
strcpy(tempstr + strlen(tempstr), fmt::format(_(" {:d} Mag"), mag).c_str());
if (dex)
if (dex != 0)
strcpy(tempstr + strlen(tempstr), fmt::format(_(" {:d} Dex"), dex).c_str());
strcat(sstr, tempstr);
}
@ -229,26 +226,23 @@ void S_StartSmith()
void S_ScrollSBuy(int idx)
{
int l, ls;
ls = idx;
ClearSText(5, 21);
stextup = 5;
for (l = 5; l < 20; l += 4) {
if (!smithitem[ls].isEmpty()) {
uint16_t iclr = smithitem[ls].getTextColor();
for (int l = 5; l < 20; l += 4) {
if (!smithitem[idx].isEmpty()) {
uint16_t iclr = smithitem[idx].getTextColor();
if (smithitem[ls]._iMagical) {
AddSText(20, l, smithitem[ls]._iIName, iclr, true);
if (smithitem[idx]._iMagical != 0) {
AddSText(20, l, smithitem[idx]._iIName, iclr, true);
} else {
AddSText(20, l, smithitem[ls]._iName, iclr, true);
AddSText(20, l, smithitem[idx]._iName, iclr, true);
}
AddSTextVal(l, smithitem[ls]._iIvalue);
PrintStoreItem(&smithitem[ls], l + 1, iclr);
AddSTextVal(l, smithitem[idx]._iIvalue);
PrintStoreItem(&smithitem[idx], l + 1, iclr);
stextdown = l;
ls++;
idx++;
}
}
@ -280,20 +274,18 @@ void S_StartSBuy()
stextsmax = 0;
}
void S_ScrollSPBuy(int idx)
void S_ScrollSPBuy(int boughtitems)
{
int l, boughtitems;
ClearSText(5, 21);
boughtitems = idx;
stextup = 5;
for (idx = 0; boughtitems; idx++) {
int idx = 0;
for (; boughtitems != 0; idx++) {
if (!premiumitems[idx].isEmpty())
boughtitems--;
}
for (l = 5; l < 20 && idx < SMITH_PREMIUM_ITEMS; l += 4) {
for (int l = 5; l < 20 && idx < SMITH_PREMIUM_ITEMS; l += 4) {
if (!premiumitems[idx].isEmpty()) {
uint16_t iclr = premiumitems[idx].getTextColor();
AddSText(20, l, premiumitems[idx]._iIName, iclr, true);
@ -318,7 +310,7 @@ bool S_StartSPBuy()
if (!premiumitems[i].isEmpty())
storenumh++;
}
if (!storenumh) {
if (storenumh == 0) {
StartStore(STORE_SMITH);
stextsel = 14;
return false;
@ -387,7 +379,7 @@ void S_ScrollSSell(int idx)
if (!storehold[idx].isEmpty()) {
uint16_t iclr = storehold[idx].getTextColor();
if (storehold[idx]._iMagical && storehold[idx]._iIdentified) {
if (storehold[idx]._iMagical != 0 && storehold[idx]._iIdentified) {
AddSText(20, l, storehold[idx]._iIName, iclr, true);
AddSTextVal(l, storehold[idx]._iIvalue);
} else {
@ -408,17 +400,14 @@ void S_ScrollSSell(int idx)
void S_StartSSell()
{
int i;
bool sellok;
stextsize = true;
sellok = false;
bool sellok = false;
storenumh = 0;
for (i = 0; i < 48; i++)
for (int i = 0; i < 48; i++)
storehold[i]._itype = ITYPE_NONE;
for (i = 0; i < plr[myplr]._pNumInv; i++) {
for (int i = 0; i < plr[myplr]._pNumInv; i++) {
if (storenumh >= 48)
break;
if (SmithSellOk(i)) {
@ -428,15 +417,14 @@ void S_StartSSell()
if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified)
storehold[storenumh]._ivalue = storehold[storenumh]._iIvalue;
if ((storehold[storenumh]._ivalue >>= 2) == 0)
storehold[storenumh]._ivalue = 1;
storehold[storenumh]._ivalue = std::max(storehold[storenumh]._ivalue / 4, 1);
storehold[storenumh]._iIvalue = storehold[storenumh]._ivalue;
storehidx[storenumh++] = i;
storehidx[storenumh] = i;
storenumh++;
}
}
for (i = 0; i < MAXBELTITEMS; i++) {
for (int i = 0; i < MAXBELTITEMS; i++) {
if (storenumh >= 48)
break;
if (SmithSellOk(-(i + 1))) {
@ -446,11 +434,10 @@ void S_StartSSell()
if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified)
storehold[storenumh]._ivalue = storehold[storenumh]._iIvalue;
if (!(storehold[storenumh]._ivalue >>= 2))
storehold[storenumh]._ivalue = 1;
storehold[storenumh]._ivalue = std::max(storehold[storenumh]._ivalue / 4, 1);
storehold[storenumh]._iIvalue = storehold[storenumh]._ivalue;
storehidx[storenumh++] = -(i + 1);
storehidx[storenumh] = -(i + 1);
storenumh++;
}
}
@ -577,26 +564,23 @@ void S_StartWitch()
void S_ScrollWBuy(int idx)
{
int l, ls;
ls = idx;
ClearSText(5, 21);
stextup = 5;
for (l = 5; l < 20; l += 4) {
if (!witchitem[ls].isEmpty()) {
uint16_t iclr = witchitem[ls].getTextColor();
for (int l = 5; l < 20; l += 4) {
if (!witchitem[idx].isEmpty()) {
uint16_t iclr = witchitem[idx].getTextColor();
if (witchitem[ls]._iMagical) {
AddSText(20, l, witchitem[ls]._iIName, iclr, true);
if (witchitem[idx]._iMagical != 0) {
AddSText(20, l, witchitem[idx]._iIName, iclr, true);
} else {
AddSText(20, l, witchitem[ls]._iName, iclr, true);
AddSText(20, l, witchitem[idx]._iName, iclr, true);
}
AddSTextVal(l, witchitem[ls]._iIvalue);
PrintStoreItem(&witchitem[ls], l + 1, iclr);
AddSTextVal(l, witchitem[idx]._iIvalue);
PrintStoreItem(&witchitem[idx], l + 1, iclr);
stextdown = l;
ls++;
idx++;
}
}
@ -1114,15 +1098,15 @@ void S_StartIdShow()
void S_StartTalk()
{
int i, sn, sn2, la;
int la;
stextsize = false;
stextscrl = false;
strcpy(tempstr, fmt::format(_("Talk to {:s}"), talkname[talker]).c_str());
strcpy(tempstr, fmt::format(_("Talk to {:s}"), TownerNames[talker]).c_str());
AddSText(0, 2, tempstr, UIS_GOLD | UIS_CENTER, false);
AddSLine(5);
if (gbIsSpawn) {
strcpy(tempstr, fmt::format(_("Talking to {:s}"), talkname[talker]).c_str());
strcpy(tempstr, fmt::format(_("Talking to {:s}"), TownerNames[talker]).c_str());
AddSText(0, 10, tempstr, UIS_SILVER | UIS_CENTER, false);
AddSText(0, 12, _("is not available"), UIS_SILVER | UIS_CENTER, false);
AddSText(0, 14, _("in the shareware"), UIS_SILVER | UIS_CENTER, false);
@ -1131,8 +1115,8 @@ void S_StartTalk()
return;
}
sn = 0;
for (i = 0; i < MAXQUESTS; i++) {
int sn = 0;
for (int i = 0; i < MAXQUESTS; i++) {
if (quests[i]._qactive == QUEST_ACTIVE && Qtalklist[talker][i] != TEXT_NONE && quests[i]._qlog)
sn++;
}
@ -1145,9 +1129,9 @@ void S_StartTalk()
la = 2;
}
sn2 = sn - 2;
int sn2 = sn - 2;
for (i = 0; i < MAXQUESTS; i++) {
for (int i = 0; i < MAXQUESTS; i++) {
if (quests[i]._qactive == QUEST_ACTIVE && Qtalklist[talker][i] != TEXT_NONE && quests[i]._qlog) {
AddSText(0, sn, _(questlist[i]._qlstr), UIS_SILVER | UIS_CENTER, true);
sn += la;
@ -1283,16 +1267,14 @@ void S_SBuyEnter()
*/
void SmithBuyPItem()
{
int i, xx, idx;
TakePlrsMoney(plr[myplr].HoldItem._iIvalue);
if (plr[myplr].HoldItem._iMagical == ITEM_QUALITY_NORMAL)
plr[myplr].HoldItem._iIdentified = false;
StoreAutoPlace();
idx = stextvhold + ((stextlhold - stextup) / 4);
xx = 0;
for (i = 0; idx >= 0; i++) {
int idx = stextvhold + ((stextlhold - stextup) / 4);
int xx = 0;
for (int i = 0; idx >= 0; i++) {
if (!premiumitems[i].isEmpty()) {
idx--;
xx = i;
@ -1306,65 +1288,62 @@ void SmithBuyPItem()
void S_SPBuyEnter()
{
int i, idx, xx;
bool done;
if (stextsel == 22) {
StartStore(STORE_SMITH);
stextsel = 14;
} else {
stextshold = STORE_SPBUY;
stextlhold = stextsel;
stextvhold = stextsval;
xx = stextsval + ((stextsel - stextup) / 4);
idx = 0;
for (i = 0; xx >= 0; i++) {
if (!premiumitems[i].isEmpty()) {
xx--;
idx = i;
}
}
if (plr[myplr]._pGold < premiumitems[idx]._iIvalue) {
StartStore(STORE_NOMONEY);
} else {
plr[myplr].HoldItem = premiumitems[idx];
NewCursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM);
done = false;
if (AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem, false)) {
done = true;
}
return;
}
if (done || AutoPlaceItemInInventory(plr[myplr], plr[myplr].HoldItem, false))
StartStore(STORE_CONFIRM);
else
StartStore(STORE_NOROOM);
NewCursor(CURSOR_HAND);
stextshold = STORE_SPBUY;
stextlhold = stextsel;
stextvhold = stextsval;
int xx = stextsval + ((stextsel - stextup) / 4);
int idx = 0;
for (int i = 0; xx >= 0; i++) {
if (!premiumitems[i].isEmpty()) {
xx--;
idx = i;
}
}
if (plr[myplr]._pGold < premiumitems[idx]._iIvalue) {
StartStore(STORE_NOMONEY);
return;
}
plr[myplr].HoldItem = premiumitems[idx];
NewCursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM);
bool done = AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem, false);
if (done || AutoPlaceItemInInventory(plr[myplr], plr[myplr].HoldItem, false))
StartStore(STORE_CONFIRM);
else
StartStore(STORE_NOROOM);
NewCursor(CURSOR_HAND);
}
bool StoreGoldFit(int idx)
{
int i, sz, cost, numsqrs;
cost = storehold[idx]._iIvalue;
sz = cost / MaxGold;
int cost = storehold[idx]._iIvalue;
int sz = cost / MaxGold;
if (cost % MaxGold != 0)
sz++;
NewCursor(storehold[idx]._iCurs + CURSOR_FIRSTITEM);
numsqrs = cursW / 28 * (cursH / 28);
int numsqrs = cursW / 28 * (cursH / 28);
NewCursor(CURSOR_HAND);
if (numsqrs >= sz)
return true;
for (i = 0; i < NUM_INV_GRID_ELEM; i++) {
for (int i = 0; i < NUM_INV_GRID_ELEM; i++) {
if (plr[myplr].InvGrid[i] == 0)
numsqrs++;
}
for (i = 0; i < plr[myplr]._pNumInv; i++) {
for (int i = 0; i < plr[myplr]._pNumInv; i++) {
if (plr[myplr].InvList[i]._itype == ITYPE_GOLD && plr[myplr].InvList[i]._ivalue != MaxGold) {
if (cost + plr[myplr].InvList[i]._ivalue <= MaxGold)
cost = 0;
@ -1374,7 +1353,7 @@ bool StoreGoldFit(int idx)
}
sz = cost / MaxGold;
if (cost % MaxGold)
if ((cost % MaxGold) != 0)
sz++;
return numsqrs >= sz;
@ -1386,23 +1365,18 @@ bool StoreGoldFit(int idx)
*/
void PlaceStoreGold(int v)
{
bool done;
int ii, xx, yy, i;
done = false;
for (i = 0; i < NUM_INV_GRID_ELEM && !done; i++) {
yy = 10 * (i / 10);
xx = i % 10;
for (int i = 0; i < NUM_INV_GRID_ELEM; i++) {
int xx = i % 10;
int yy = 10 * (i / 10);
if (plr[myplr].InvGrid[xx + yy] == 0) {
ii = plr[myplr]._pNumInv;
int ii = plr[myplr]._pNumInv;
GetGoldSeed(myplr, &golditem);
plr[myplr].InvList[ii] = golditem;
plr[myplr]._pNumInv++;
plr[myplr].InvGrid[xx + yy] = plr[myplr]._pNumInv;
plr[myplr].InvList[ii]._ivalue = v;
SetGoldCurs(myplr, ii);
done = true;
return;
}
}
}
@ -1412,14 +1386,13 @@ void PlaceStoreGold(int v)
*/
void StoreSellItem()
{
int i, idx, cost;
idx = stextvhold + ((stextlhold - stextup) / 4);
int idx = stextvhold + ((stextlhold - stextup) / 4);
if (storehidx[idx] >= 0)
plr[myplr].RemoveInvItem(storehidx[idx]);
else
RemoveSpdBarItem(myplr, -(storehidx[idx] + 1));
cost = storehold[idx]._iIvalue;
int cost = storehold[idx]._iIvalue;
storenumh--;
if (idx != storenumh) {
while (idx < storenumh) {
@ -1429,7 +1402,7 @@ void StoreSellItem()
}
}
plr[myplr]._pGold += cost;
for (i = 0; i < plr[myplr]._pNumInv && cost > 0; i++) {
for (int i = 0; i < plr[myplr]._pNumInv && cost > 0; i++) {
if (plr[myplr].InvList[i]._itype == ITYPE_GOLD && plr[myplr].InvList[i]._ivalue != MaxGold) {
if (cost + plr[myplr].InvList[i]._ivalue <= MaxGold) {
plr[myplr].InvList[i]._ivalue += cost;
@ -1453,23 +1426,22 @@ void StoreSellItem()
void S_SSellEnter()
{
int idx;
if (stextsel == 22) {
StartStore(STORE_SMITH);
stextsel = 16;
} else {
stextlhold = stextsel;
idx = stextsval + ((stextsel - stextup) / 4);
stextshold = STORE_SSELL;
stextvhold = stextsval;
plr[myplr].HoldItem = storehold[idx];
if (StoreGoldFit(idx))
StartStore(STORE_CONFIRM);
else
StartStore(STORE_NOROOM);
return;
}
stextlhold = stextsel;
int idx = stextsval + ((stextsel - stextup) / 4);
stextshold = STORE_SSELL;
stextvhold = stextsval;
plr[myplr].HoldItem = storehold[idx];
if (StoreGoldFit(idx))
StartStore(STORE_CONFIRM);
else
StartStore(STORE_NOROOM);
}
/**
@ -1477,14 +1449,13 @@ void S_SSellEnter()
*/
void SmithRepairItem()
{
int i, idx;
TakePlrsMoney(plr[myplr].HoldItem._iIvalue);
idx = stextvhold + ((stextlhold - stextup) / 4);
int idx = stextvhold + ((stextlhold - stextup) / 4);
storehold[idx]._iDurability = storehold[idx]._iMaxDur;
i = storehidx[idx];
int i = storehidx[idx];
if (i < 0) {
if (i == -1)
plr[myplr].InvBody[INVLOC_HEAD]._iDurability = plr[myplr].InvBody[INVLOC_HEAD]._iMaxDur;
@ -1494,29 +1465,30 @@ void SmithRepairItem()
plr[myplr].InvBody[INVLOC_HAND_LEFT]._iDurability = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMaxDur;
if (i == -4)
plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iDurability = plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iMaxDur;
} else {
plr[myplr].InvList[i]._iDurability = plr[myplr].InvList[i]._iMaxDur;
return;
}
plr[myplr].InvList[i]._iDurability = plr[myplr].InvList[i]._iMaxDur;
}
void S_SRepairEnter()
{
int idx;
if (stextsel == 22) {
StartStore(STORE_SMITH);
stextsel = 18;
} else {
stextshold = STORE_SREPAIR;
stextlhold = stextsel;
stextvhold = stextsval;
idx = stextsval + ((stextsel - stextup) / 4);
plr[myplr].HoldItem = storehold[idx];
if (plr[myplr]._pGold < storehold[idx]._iIvalue)
StartStore(STORE_NOMONEY);
else
StartStore(STORE_CONFIRM);
return;
}
stextshold = STORE_SREPAIR;
stextlhold = stextsel;
stextvhold = stextsval;
int idx = stextsval + ((stextsel - stextup) / 4);
plr[myplr].HoldItem = storehold[idx];
if (plr[myplr]._pGold < storehold[idx]._iIvalue)
StartStore(STORE_NOMONEY);
else
StartStore(STORE_CONFIRM);
}
void S_WitchEnter()
@ -1529,16 +1501,16 @@ void S_WitchEnter()
gossipstart = TEXT_ADRIA2;
gossipend = TEXT_ADRIA13;
StartStore(STORE_GOSSIP);
return;
break;
case 14:
StartStore(STORE_WBUY);
return;
break;
case 16:
StartStore(STORE_WSELL);
return;
break;
case 18:
StartStore(STORE_WRECHARGE);
return;
break;
case 20:
stextflag = STORE_NONE;
break;
@ -1550,9 +1522,7 @@ void S_WitchEnter()
*/
void WitchBuyItem()
{
int idx;
idx = stextvhold + ((stextlhold - stextup) / 4);
int idx = stextvhold + ((stextlhold - stextup) / 4);
if (idx < 3)
plr[myplr].HoldItem._iSeed = AdvanceRndSeed();
@ -1576,56 +1546,53 @@ void WitchBuyItem()
void S_WBuyEnter()
{
int idx;
bool done;
if (stextsel == 22) {
StartStore(STORE_WITCH);
stextsel = 14;
} else {
stextlhold = stextsel;
stextvhold = stextsval;
stextshold = STORE_WBUY;
idx = stextsval + ((stextsel - stextup) / 4);
return;
}
if (plr[myplr]._pGold < witchitem[idx]._iIvalue) {
StartStore(STORE_NOMONEY);
} else {
plr[myplr].HoldItem = witchitem[idx];
NewCursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM);
done = false;
if (AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem, false)) {
done = true;
}
stextlhold = stextsel;
stextvhold = stextsval;
stextshold = STORE_WBUY;
if (done || AutoPlaceItemInInventory(plr[myplr], plr[myplr].HoldItem, false) || AutoPlaceItemInBelt(myplr, plr[myplr].HoldItem, false))
StartStore(STORE_CONFIRM);
else
StartStore(STORE_NOROOM);
int idx = stextsval + ((stextsel - stextup) / 4);
NewCursor(CURSOR_HAND);
}
if (plr[myplr]._pGold < witchitem[idx]._iIvalue) {
StartStore(STORE_NOMONEY);
return;
}
plr[myplr].HoldItem = witchitem[idx];
NewCursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM);
bool done = AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem, false);
if (done || AutoPlaceItemInInventory(plr[myplr], plr[myplr].HoldItem, false) || AutoPlaceItemInBelt(myplr, plr[myplr].HoldItem, false))
StartStore(STORE_CONFIRM);
else
StartStore(STORE_NOROOM);
NewCursor(CURSOR_HAND);
}
void S_WSellEnter()
{
int idx;
if (stextsel == 22) {
StartStore(STORE_WITCH);
stextsel = 16;
} else {
stextlhold = stextsel;
idx = stextsval + ((stextsel - stextup) / 4);
stextshold = STORE_WSELL;
stextvhold = stextsval;
plr[myplr].HoldItem = storehold[idx];
if (StoreGoldFit(idx))
StartStore(STORE_CONFIRM);
else
StartStore(STORE_NOROOM);
return;
}
stextlhold = stextsel;
stextshold = STORE_WSELL;
stextvhold = stextsval;
int idx = stextsval + ((stextsel - stextup) / 4);
plr[myplr].HoldItem = storehold[idx];
if (StoreGoldFit(idx))
StartStore(STORE_CONFIRM);
else
StartStore(STORE_NOROOM);
}
/**
@ -1633,14 +1600,12 @@ void S_WSellEnter()
*/
void WitchRechargeItem()
{
int i, idx;
TakePlrsMoney(plr[myplr].HoldItem._iIvalue);
idx = stextvhold + ((stextlhold - stextup) / 4);
int idx = stextvhold + ((stextlhold - stextup) / 4);
storehold[idx]._iCharges = storehold[idx]._iMaxCharges;
i = storehidx[idx];
int i = storehidx[idx];
if (i < 0)
plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMaxCharges;
else
@ -1651,22 +1616,22 @@ void WitchRechargeItem()
void S_WRechargeEnter()
{
int idx;
if (stextsel == 22) {
StartStore(STORE_WITCH);
stextsel = 18;
} else {
stextshold = STORE_WRECHARGE;
stextlhold = stextsel;
stextvhold = stextsval;
idx = stextsval + ((stextsel - stextup) / 4);
plr[myplr].HoldItem = storehold[idx];
if (plr[myplr]._pGold < storehold[idx]._iIvalue)
StartStore(STORE_NOMONEY);
else
StartStore(STORE_CONFIRM);
return;
}
stextshold = STORE_WRECHARGE;
stextlhold = stextsel;
stextvhold = stextsval;
int idx = stextsval + ((stextsel - stextup) / 4);
plr[myplr].HoldItem = storehold[idx];
if (plr[myplr]._pGold < storehold[idx]._iIvalue)
StartStore(STORE_NOMONEY);
else
StartStore(STORE_CONFIRM);
}
void S_BoyEnter()
@ -1681,16 +1646,20 @@ void S_BoyEnter()
TakePlrsMoney(50);
StartStore(STORE_BBOY);
}
} else if ((stextsel == 8 && !boyitem.isEmpty()) || (stextsel == 12 && boyitem.isEmpty())) {
talker = TOWN_PEGBOY;
stextshold = STORE_BOY;
stextlhold = stextsel;
gossipstart = TEXT_WIRT2;
gossipend = TEXT_WIRT12;
StartStore(STORE_GOSSIP);
} else {
return;
}
if ((stextsel != 8 && !boyitem.isEmpty()) || (stextsel != 12 && boyitem.isEmpty())) {
stextflag = STORE_NONE;
return;
}
talker = TOWN_PEGBOY;
stextshold = STORE_BOY;
stextlhold = stextsel;
gossipstart = TEXT_WIRT2;
gossipend = TEXT_WIRT12;
StartStore(STORE_GOSSIP);
}
void BoyBuyItem()
@ -2112,23 +2081,18 @@ void InitStores()
void SetupTownStores()
{
int i, l;
SetRndSeed(glSeedTbl[currlevel] * SDL_GetTicks());
int l = plr[myplr]._pLevel / 2;
if (!gbIsMultiplayer) {
l = 0;
for (i = 0; i < NUMLEVELS; i++) {
for (int i = 0; i < NUMLEVELS; i++) {
if (plr[myplr]._pLvlVisited[i])
l = i;
}
} else {
l = plr[myplr]._pLevel / 2;
}
l += 2;
if (l < 6)
l = 6;
if (l > 16)
l = 16;
l = clamp(l + 2, 6, 16);
SpawnStoreGold();
SpawnSmith(l);
SpawnWitch(l);
@ -2190,19 +2154,18 @@ void PrintSString(const CelOutputBuffer &out, int margin, int line, const char *
void DrawSLine(const CelOutputBuffer &out, int y)
{
const int sy = y * 12;
BYTE *src, *dst;
int width;
if (stextsize) {
src = out.at(PANEL_LEFT + 26, 25 + UI_OFFSET_Y);
dst = out.at(26 + PANEL_X, sy + 38 + UI_OFFSET_Y);
width = 587; // BUGFIX: should be 587, not 586 (fixed)
} else {
src = out.at(PANEL_LEFT + 346, 25 + UI_OFFSET_Y);
dst = out.at(346 + PANEL_X, sy + 38 + UI_OFFSET_Y);
width = 267; // BUGFIX: should be 267, not 266 (fixed)
int sx = 26;
int sy = y * 12;
int width = 587;
if (!stextsize) {
sx += SPANEL_WIDTH;
width -= SPANEL_WIDTH;
}
BYTE *src = out.at(PANEL_LEFT + sx, UI_OFFSET_Y + 25);
BYTE *dst = out.at(PANEL_X + sx, UI_OFFSET_Y + sy + 38);
for (int i = 0; i < 3; i++, src += out.pitch(), dst += out.pitch())
memcpy(dst, src, width);
}
@ -2362,9 +2325,9 @@ void DrawSText(const CelOutputBuffer &out)
}
for (i = 0; i < STORE_LINES; i++) {
if (stext[i]._sline)
if (stext[i]._sline != 0)
DrawSLine(out, i);
if (stext[i]._sstr[0])
if (stext[i]._sstr[0] != '\0')
PrintSString(out, stext[i]._sx, i, stext[i]._sstr, stext[i].flags, stext[i]._sval);
}
@ -2456,14 +2419,14 @@ void STextUp()
if (stextscrl) {
if (stextsel == stextup) {
if (stextsval)
if (stextsval != 0)
stextsval--;
return;
}
stextsel--;
while (!stext[stextsel]._ssel) {
if (!stextsel)
if (stextsel == 0)
stextsel = STORE_LINES - 1;
else
stextsel--;
@ -2471,13 +2434,13 @@ void STextUp()
return;
}
if (!stextsel)
if (stextsel == 0)
stextsel = STORE_LINES - 1;
else
stextsel--;
while (!stext[stextsel]._ssel) {
if (!stextsel)
if (stextsel == 0)
stextsel = STORE_LINES - 1;
else
stextsel--;
@ -2526,7 +2489,7 @@ void STextPrior()
PlaySFX(IS_TITLEMOV);
if (stextsel != -1 && stextscrl) {
if (stextsel == stextup) {
if (stextsval)
if (stextsval != 0)
stextsval -= 4;
if (stextsval < 0)
stextsval = 0;
@ -2565,7 +2528,7 @@ void TakePlrsMoney(int cost)
{
int i;
plr[myplr]._pGold = CalculateGold(myplr) - cost;
plr[myplr]._pGold = CalculateGold(plr[myplr]) - cost;
for (i = 0; i < MAXBELTITEMS && cost > 0; i++) {
if (plr[myplr].SpdList[i]._itype == ITYPE_GOLD && plr[myplr].SpdList[i]._ivalue != MaxGold) {
if (cost < plr[myplr].SpdList[i]._ivalue) {

4
test/inv_test.cpp

@ -113,7 +113,7 @@ TEST(Inv, CalculateGold)
plr[myplr].InvList[2]._ivalue = 3;
plr[myplr].InvList[3]._ivalue = 30;
EXPECT_EQ(CalculateGold(myplr), 333);
EXPECT_EQ(CalculateGold(plr[myplr]), 333);
}
// Test automatic gold placing
@ -131,7 +131,7 @@ TEST(Inv, GoldAutoPlace)
plr[myplr].HoldItem._itype = ITYPE_GOLD;
plr[myplr].HoldItem._ivalue = GOLD_MAX_LIMIT - 100;
GoldAutoPlace(myplr);
GoldAutoPlace(plr[myplr]);
// We expect the inventory:
// | 5000 | 900 | ...
EXPECT_EQ(plr[myplr].InvList[0]._ivalue, GOLD_MAX_LIMIT);

Loading…
Cancel
Save