Browse Source

General clean up

pull/2319/merge
Anders Jenbo 5 years ago
parent
commit
9ebdb6db69
  1. 12
      Source/DiabloUI/credits.cpp
  2. 4
      Source/DiabloUI/credits_lines.cpp
  3. 4
      Source/DiabloUI/credits_lines.h
  4. 6
      Source/DiabloUI/selhero.cpp
  5. 2
      Source/automap.cpp
  6. 2
      Source/control.cpp
  7. 2
      Source/controls/devices/joystick.cpp
  8. 1
      Source/controls/game_controls.cpp
  9. 14
      Source/controls/keymapper.cpp
  10. 12
      Source/controls/keymapper.hpp
  11. 332
      Source/controls/plrctrls.cpp
  12. 6
      Source/controls/touch.cpp
  13. 49
      Source/diablo.cpp
  14. 56
      Source/drlg_l1.cpp
  15. 22
      Source/drlg_l2.cpp
  16. 42
      Source/drlg_l3.cpp
  17. 44
      Source/drlg_l4.cpp
  18. 20
      Source/gmenu.cpp
  19. 8
      Source/help.cpp
  20. 2
      Source/interfac.cpp
  21. 3
      Source/items.cpp
  22. 6
      Source/lighting.cpp
  23. 10
      Source/monster.cpp
  24. 4
      Source/nthread.h
  25. 4
      Source/options.cpp
  26. 25
      Source/path.cpp
  27. 4
      Source/path.h
  28. 8
      Source/player.cpp
  29. 9
      Source/qol/autopickup.cpp
  30. 16
      Source/scrollrt.cpp
  31. 2
      Source/setmaps.cpp
  32. 2
      Source/setmaps.h
  33. 12
      Source/sound.cpp
  34. 22
      Source/stores.cpp
  35. 2
      Source/stores.h
  36. 12
      Source/utils/soundsample.cpp

12
Source/DiabloUI/credits.cpp

@ -26,7 +26,7 @@ const int ShadowOffsetX = 2;
const int ShadowOffsetY = 2; const int ShadowOffsetY = 2;
const int LINE_H = 22; const int LINE_H = 22;
char const *const *text; char const *const *Text;
std::size_t textLines; std::size_t textLines;
// The maximum number of visible lines is the number of whole lines // The maximum number of visible lines is the number of whole lines
@ -66,7 +66,7 @@ SDL_Surface *RenderText(const char *text, SDL_Color color)
CachedLine PrepareLine(std::size_t index) CachedLine PrepareLine(std::size_t index)
{ {
const char *contents = _(text[index]); const char *contents = _(Text[index]);
while (contents[0] == '\t') while (contents[0] == '\t')
++contents; ++contents;
@ -182,7 +182,7 @@ void CreditsRenderer::Render()
Sint16 destX = PANEL_LEFT + VIEWPORT.x + 31; Sint16 destX = PANEL_LEFT + VIEWPORT.x + 31;
int j = 0; int j = 0;
while (text[line.mIndex][j++] == '\t') while (Text[line.mIndex][j++] == '\t')
destX += 40; destX += 40;
SDL_Rect dstRect = { destX, destY, 0, 0 }; SDL_Rect dstRect = { destX, destY, 0, 0 };
@ -234,8 +234,8 @@ bool TextDialog()
bool UiCreditsDialog() bool UiCreditsDialog()
{ {
text = CREDITS_LINES; Text = CreditLines;
textLines = CREDITS_LINES_SIZE; textLines = CreditLinesSize;
LoadArt("ui_art\\creditsw.pcx", &ArtBackgroundWidescreen); LoadArt("ui_art\\creditsw.pcx", &ArtBackgroundWidescreen);
LoadBackgroundArt("ui_art\\credits.pcx"); LoadBackgroundArt("ui_art\\credits.pcx");
@ -245,7 +245,7 @@ bool UiCreditsDialog()
bool UiSupportDialog() bool UiSupportDialog()
{ {
text = SupportLines; Text = SupportLines;
textLines = SupportLinesSize; textLines = SupportLinesSize;
if (gbIsHellfire) { if (gbIsHellfire) {

4
Source/DiabloUI/credits_lines.cpp

@ -3,7 +3,7 @@
namespace devilution { namespace devilution {
const char *const CREDITS_LINES[] = { const char *const CreditLines[] = {
N_("Game Design"), N_("Game Design"),
" Blizzard North", " Blizzard North",
"", "",
@ -552,6 +552,6 @@ const char *const CREDITS_LINES[] = {
" " " "
}; };
const std::size_t CREDITS_LINES_SIZE = sizeof(CREDITS_LINES) / sizeof(CREDITS_LINES[0]); const std::size_t CreditLinesSize = sizeof(CreditLines) / sizeof(CreditLines[0]);
} // namespace devilution } // namespace devilution

4
Source/DiabloUI/credits_lines.h

@ -2,7 +2,7 @@
namespace devilution { namespace devilution {
extern const char *const CREDITS_LINES[]; extern const char *const CreditLines[];
extern const std::size_t CREDITS_LINES_SIZE; extern const std::size_t CreditLinesSize;
} // namespace devilution } // namespace devilution

6
Source/DiabloUI/selhero.cpp

@ -44,8 +44,6 @@ std::vector<UiItemBase *> vecSelDlgItems;
UiImage *SELHERO_DIALOG_HERO_IMG; UiImage *SELHERO_DIALOG_HERO_IMG;
bool bUIElementsLoaded = false;
void SelheroListFocus(int value); void SelheroListFocus(int value);
void SelheroListSelect(int value); void SelheroListSelect(int value);
void SelheroListEsc(); void SelheroListEsc();
@ -92,8 +90,6 @@ void SelheroFree()
SelheroFreeDlgItems(); SelheroFreeDlgItems();
SelheroFreeListItems(); SelheroFreeListItems();
UnloadScrollBar(); UnloadScrollBar();
bUIElementsLoaded = false;
} }
void SelheroSetStats() void SelheroSetStats()
@ -572,8 +568,6 @@ static void UiSelHeroDialog(
_selhero_selections *dlgresult, _selhero_selections *dlgresult,
char (*name)[16]) char (*name)[16])
{ {
bUIElementsLoaded = true;
do { do {
gfnHeroInfo = fninfo; gfnHeroInfo = fninfo;
gfnHeroCreate = fncreate; gfnHeroCreate = fncreate;

2
Source/automap.cpp

@ -400,7 +400,7 @@ void DrawAutomapText(const Surface &out)
} }
if (setlevel) { if (setlevel) {
DrawString(out, _(quest_level_names[setlvlnum]), linePosition); DrawString(out, _(QuestLevelNames[setlvlnum]), linePosition);
return; return;
} }

2
Source/control.cpp

@ -445,7 +445,7 @@ void DrawSpellList(const Surface &out)
} }
for (int t = 0; t < 4; t++) { for (int t = 0; t < 4; t++) {
if (myPlayer._pSplHotKey[t] == pSpell && myPlayer._pSplTHotKey[t] == pSplType) { if (myPlayer._pSplHotKey[t] == pSpell && myPlayer._pSplTHotKey[t] == pSplType) {
auto hotkeyName = keymapper.keyNameForAction(quickSpellActionIndexes[t]); auto hotkeyName = keymapper.KeyNameForAction(quickSpellActionIndexes[t]);
PrintSBookHotkey(out, location, hotkeyName); PrintSBookHotkey(out, location, hotkeyName);
strcpy(tempstr, fmt::format(_("Spell Hotkey {:s}"), hotkeyName.c_str()).c_str()); strcpy(tempstr, fmt::format(_("Spell Hotkey {:s}"), hotkeyName.c_str()).c_str());
AddPanelString(tempstr); AddPanelString(tempstr);

2
Source/controls/devices/joystick.cpp

@ -245,7 +245,6 @@ bool Joystick::ProcessAxisMotion(const SDL_Event &event)
default: default:
return false; return false;
} }
return true;
} }
void Joystick::Add(int deviceIndex) void Joystick::Add(int deviceIndex)
@ -311,7 +310,6 @@ Joystick *Joystick::Get(const SDL_Event &event)
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP: case SDL_JOYBUTTONUP:
return Get(event.jbutton.which); return Get(event.jbutton.which);
return Get(event.jbutton.which);
default: default:
return nullptr; return nullptr;
#else #else

1
Source/controls/game_controls.cpp

@ -157,7 +157,6 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
case ControllerButton_BUTTON_START: case ControllerButton_BUTTON_START:
case ControllerButton_BUTTON_BACK: case ControllerButton_BUTTON_BACK:
return true; return true;
break;
default: default:
break; break;
} }

14
Source/controls/keymapper.cpp

@ -38,14 +38,14 @@ Keymapper::Keymapper(SetConfigKeyFunction setKeyFunction, GetConfigKeyFunction g
} }
} }
Keymapper::ActionIndex Keymapper::addAction(const Action &action) Keymapper::ActionIndex Keymapper::AddAction(const Action &action)
{ {
actions.emplace_back(action); actions.emplace_back(action);
return actions.size() - 1; return actions.size() - 1;
} }
void Keymapper::keyPressed(int key) const void Keymapper::KeyPressed(int key) const
{ {
auto it = keyIDToAction.find(key); auto it = keyIDToAction.find(key);
if (it == keyIDToAction.end()) if (it == keyIDToAction.end())
@ -61,7 +61,7 @@ void Keymapper::keyPressed(int key) const
action(); action();
} }
std::string Keymapper::keyNameForAction(ActionIndex actionIndex) const std::string Keymapper::KeyNameForAction(ActionIndex actionIndex) const
{ {
assert(actionIndex < actions.size()); assert(actionIndex < actions.size());
auto key = actions[actionIndex].key; auto key = actions[actionIndex].key;
@ -70,7 +70,7 @@ std::string Keymapper::keyNameForAction(ActionIndex actionIndex) const
return it->second; return it->second;
} }
void Keymapper::save() const void Keymapper::Save() const
{ {
// Use the action vector to go though the actions to keep the same order. // Use the action vector to go though the actions to keep the same order.
for (const auto &action : actions) { for (const auto &action : actions) {
@ -89,12 +89,12 @@ void Keymapper::save() const
} }
} }
void Keymapper::load() void Keymapper::Load()
{ {
keyIDToAction.clear(); keyIDToAction.clear();
for (auto &action : actions) { for (auto &action : actions) {
auto key = getActionKey(action); auto key = GetActionKey(action);
action.key = key; action.key = key;
if (key == DVL_VK_INVALID) { if (key == DVL_VK_INVALID) {
// Skip if the action has no key bound to it. // Skip if the action has no key bound to it.
@ -106,7 +106,7 @@ void Keymapper::load()
} }
} }
int Keymapper::getActionKey(const Keymapper::Action &action) int Keymapper::GetActionKey(const Keymapper::Action &action)
{ {
auto key = getKeyFunction(action.name); auto key = getKeyFunction(action.name);
if (key.empty()) if (key.empty())

12
Source/controls/keymapper.hpp

@ -59,14 +59,14 @@ public:
*/ */
Keymapper(SetConfigKeyFunction setKeyFunction, GetConfigKeyFunction getKeyFunction); Keymapper(SetConfigKeyFunction setKeyFunction, GetConfigKeyFunction getKeyFunction);
ActionIndex addAction(const Action &action); ActionIndex AddAction(const Action &action);
void keyPressed(int key) const; void KeyPressed(int key) const;
std::string keyNameForAction(ActionIndex actionIndex) const; std::string KeyNameForAction(ActionIndex actionIndex) const;
void save() const; void Save() const;
void load(); void Load();
private: private:
int getActionKey(const Action &action); int GetActionKey(const Action &action);
std::vector<Action> actions; std::vector<Action> actions;
std::unordered_map<int, std::reference_wrapper<Action>> keyIDToAction; std::unordered_map<int, std::reference_wrapper<Action>> keyIDToAction;

332
Source/controls/plrctrls.cpp

@ -45,7 +45,7 @@ bool InGameMenu()
namespace { namespace {
int slot = SLOTXY_INV_FIRST; int Slot = SLOTXY_INV_FIRST;
/** /**
* Number of angles to turn to face the coordinate * Number of angles to turn to face the coordinate
@ -257,9 +257,9 @@ void FindMeleeTarget()
SearchNode node = queue.front(); SearchNode node = queue.front();
queue.pop_front(); queue.pop_front();
for (int i = 0; i < 8; i++) { for (auto pathDir : PathDirs) {
const int dx = node.x + pathxdir[i]; const int dx = node.x + pathDir.deltaX;
const int dy = node.y + pathydir[i]; const int dy = node.y + pathDir.deltaY;
if (visited[dx][dy]) if (visited[dx][dy])
continue; // already visisted continue; // already visisted
@ -577,9 +577,9 @@ Size GetItemSizeOnSlot(int slot, char &itemInvId)
if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) {
int ig = slot - SLOTXY_INV_FIRST; int ig = slot - SLOTXY_INV_FIRST;
auto &myPlayer = Players[MyPlayerId]; auto &myPlayer = Players[MyPlayerId];
char ii = myPlayer.InvGrid[ig]; int8_t ii = myPlayer.InvGrid[ig];
if (ii != 0) { if (ii != 0) {
int iv = ii; int8_t iv = ii;
if (ii <= 0) { if (ii <= 0) {
iv = -ii; iv = -ii;
} }
@ -605,29 +605,29 @@ Size GetItemSizeOnSlot(int slot, char &itemInvId)
void ResetInvCursorPosition() void ResetInvCursorPosition()
{ {
Point mousePos {}; Point mousePos {};
if (slot < SLOTXY_INV_FIRST) { if (Slot < SLOTXY_INV_FIRST) {
mousePos = InvGetEquipSlotCoordFromInvSlot((inv_xy_slot)slot); mousePos = InvGetEquipSlotCoordFromInvSlot((inv_xy_slot)Slot);
} else if (slot < SLOTXY_BELT_FIRST) { } else if (Slot < SLOTXY_BELT_FIRST) {
char itemInvId; char itemInvId;
auto itemSize = GetItemSizeOnSlot(slot, itemInvId); auto itemSize = GetItemSizeOnSlot(Slot, itemInvId);
// search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId // search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId
if (itemInvId < 0) { if (itemInvId < 0) {
for (int s = 0; s < SLOTXY_INV_LAST - SLOTXY_INV_FIRST; ++s) { for (int s = 0; s < SLOTXY_INV_LAST - SLOTXY_INV_FIRST; ++s) {
if (Players[MyPlayerId].InvGrid[s] == -itemInvId) { if (Players[MyPlayerId].InvGrid[s] == -itemInvId) {
slot = SLOTXY_INV_FIRST + s; Slot = SLOTXY_INV_FIRST + s;
break; break;
} }
} }
} }
// offset the slot to always move to the top-left most slot of that item // offset the slot to always move to the top-left most slot of that item
slot -= ((itemSize.height - 1) * INV_ROW_SLOT_SIZE); Slot -= ((itemSize.height - 1) * INV_ROW_SLOT_SIZE);
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
mousePos.x += ((itemSize.width - 1) * InventorySlotSizeInPixels.width) / 2; mousePos.x += ((itemSize.width - 1) * InventorySlotSizeInPixels.width) / 2;
mousePos.y += ((itemSize.height - 1) * InventorySlotSizeInPixels.height) / 2; mousePos.y += ((itemSize.height - 1) * InventorySlotSizeInPixels.height) / 2;
} else { } else {
mousePos = BeltGetSlotCoord(slot); mousePos = BeltGetSlotCoord(Slot);
} }
mousePos.x += (InventorySlotSizeInPixels.width / 2); mousePos.x += (InventorySlotSizeInPixels.width / 2);
@ -649,271 +649,271 @@ void InvMove(AxisDirection dir)
return; return;
char itemInvId; char itemInvId;
auto itemSize = GetItemSizeOnSlot(slot, itemInvId); auto itemSize = GetItemSizeOnSlot(Slot, itemInvId);
Point mousePos = MousePosition; Point mousePos = MousePosition;
const bool isHoldingItem = pcurs > 1; const bool isHoldingItem = pcurs > 1;
// normalize slots // normalize slots
if (slot < 0) if (Slot < 0)
slot = 0; Slot = 0;
else if (slot >= SLOTXY_HEAD_FIRST && slot <= SLOTXY_HEAD_LAST) else if (Slot >= SLOTXY_HEAD_FIRST && Slot <= SLOTXY_HEAD_LAST)
slot = SLOTXY_HEAD_FIRST; Slot = SLOTXY_HEAD_FIRST;
else if (slot >= SLOTXY_HAND_LEFT_FIRST && slot <= SLOTXY_HAND_LEFT_LAST) else if (Slot >= SLOTXY_HAND_LEFT_FIRST && Slot <= SLOTXY_HAND_LEFT_LAST)
slot = SLOTXY_HAND_LEFT_FIRST; Slot = SLOTXY_HAND_LEFT_FIRST;
else if (slot >= SLOTXY_CHEST_FIRST && slot <= SLOTXY_CHEST_LAST) else if (Slot >= SLOTXY_CHEST_FIRST && Slot <= SLOTXY_CHEST_LAST)
slot = SLOTXY_CHEST_FIRST; Slot = SLOTXY_CHEST_FIRST;
else if (slot >= SLOTXY_HAND_RIGHT_FIRST && slot <= SLOTXY_HAND_RIGHT_LAST) else if (Slot >= SLOTXY_HAND_RIGHT_FIRST && Slot <= SLOTXY_HAND_RIGHT_LAST)
slot = SLOTXY_HAND_RIGHT_FIRST; Slot = SLOTXY_HAND_RIGHT_FIRST;
else if (slot > SLOTXY_BELT_LAST) else if (Slot > SLOTXY_BELT_LAST)
slot = SLOTXY_BELT_LAST; Slot = SLOTXY_BELT_LAST;
const int initialSlot = slot; const int initialSlot = Slot;
auto &myPlayer = Players[MyPlayerId]; auto &myPlayer = Players[MyPlayerId];
// when item is on cursor (pcurs > 1), this is the real cursor XY // when item is on cursor (pcurs > 1), this is the real cursor XY
if (dir.x == AxisDirectionX_LEFT) { if (dir.x == AxisDirectionX_LEFT) {
if (isHoldingItem) { if (isHoldingItem) {
if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) {
if (slot == SLOTXY_INV_ROW1_FIRST || slot == SLOTXY_INV_ROW2_FIRST || slot == SLOTXY_INV_ROW3_FIRST || slot == SLOTXY_INV_ROW4_FIRST) { if (Slot == SLOTXY_INV_ROW1_FIRST || Slot == SLOTXY_INV_ROW2_FIRST || Slot == SLOTXY_INV_ROW3_FIRST || Slot == SLOTXY_INV_ROW4_FIRST) {
slot += INV_ROW_SLOT_SIZE - icursW28; Slot += INV_ROW_SLOT_SIZE - icursW28;
} else { } else {
slot -= 1; Slot -= 1;
} }
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot > SLOTXY_BELT_FIRST && slot <= SLOTXY_BELT_LAST) { } else if (Slot > SLOTXY_BELT_FIRST && Slot <= SLOTXY_BELT_LAST) {
slot -= 1; Slot -= 1;
mousePos = BeltGetSlotCoord(slot); mousePos = BeltGetSlotCoord(Slot);
} else if (myPlayer.HoldItem._itype == ITYPE_RING) { } else if (myPlayer.HoldItem._itype == ITYPE_RING) {
slot = SLOTXY_RING_LEFT; Slot = SLOTXY_RING_LEFT;
mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT);
} else if (myPlayer.HoldItem.isWeapon() || myPlayer.HoldItem.isShield()) { } else if (myPlayer.HoldItem.isWeapon() || myPlayer.HoldItem.isShield()) {
if (slot == SLOTXY_HAND_LEFT_FIRST) { if (Slot == SLOTXY_HAND_LEFT_FIRST) {
slot = SLOTXY_HAND_RIGHT_FIRST; Slot = SLOTXY_HAND_RIGHT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT);
} else if (slot == SLOTXY_HAND_RIGHT_FIRST) { } else if (Slot == SLOTXY_HAND_RIGHT_FIRST) {
slot = SLOTXY_HAND_LEFT_FIRST; Slot = SLOTXY_HAND_LEFT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT);
} }
} }
} else { } else {
if (slot == SLOTXY_HAND_RIGHT_FIRST) { if (Slot == SLOTXY_HAND_RIGHT_FIRST) {
slot = SLOTXY_CHEST_FIRST; Slot = SLOTXY_CHEST_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); mousePos = InvGetEquipSlotCoord(INVLOC_CHEST);
} else if (slot == SLOTXY_CHEST_FIRST) { } else if (Slot == SLOTXY_CHEST_FIRST) {
slot = SLOTXY_HAND_LEFT_FIRST; Slot = SLOTXY_HAND_LEFT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT);
} else if (slot == SLOTXY_AMULET) { } else if (Slot == SLOTXY_AMULET) {
slot = SLOTXY_HEAD_FIRST; Slot = SLOTXY_HEAD_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HEAD); mousePos = InvGetEquipSlotCoord(INVLOC_HEAD);
} else if (slot == SLOTXY_RING_RIGHT) { } else if (Slot == SLOTXY_RING_RIGHT) {
slot = SLOTXY_RING_LEFT; Slot = SLOTXY_RING_LEFT;
mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT);
} else if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { } else if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) {
if (slot == SLOTXY_INV_ROW1_FIRST || slot == SLOTXY_INV_ROW2_FIRST || slot == SLOTXY_INV_ROW3_FIRST || slot == SLOTXY_INV_ROW4_FIRST) { if (Slot == SLOTXY_INV_ROW1_FIRST || Slot == SLOTXY_INV_ROW2_FIRST || Slot == SLOTXY_INV_ROW3_FIRST || Slot == SLOTXY_INV_ROW4_FIRST) {
slot += INV_ROW_SLOT_SIZE - 1; Slot += INV_ROW_SLOT_SIZE - 1;
} else { } else {
slot -= 1; Slot -= 1;
} }
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot > SLOTXY_BELT_FIRST && slot <= SLOTXY_BELT_LAST) { } else if (Slot > SLOTXY_BELT_FIRST && Slot <= SLOTXY_BELT_LAST) {
slot -= 1; Slot -= 1;
mousePos = BeltGetSlotCoord(slot); mousePos = BeltGetSlotCoord(Slot);
} }
} }
} else if (dir.x == AxisDirectionX_RIGHT) { } else if (dir.x == AxisDirectionX_RIGHT) {
if (isHoldingItem) { if (isHoldingItem) {
if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) {
if ( if (
slot == SLOTXY_INV_ROW1_LAST + 1 - icursW28 || slot == SLOTXY_INV_ROW2_LAST + 1 - icursW28 || slot == SLOTXY_INV_ROW3_LAST + 1 - icursW28 || slot == SLOTXY_INV_ROW4_LAST + 1 - icursW28) { Slot == SLOTXY_INV_ROW1_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW2_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW3_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW4_LAST + 1 - icursW28) {
slot -= INV_ROW_SLOT_SIZE - icursW28; Slot -= INV_ROW_SLOT_SIZE - icursW28;
} else { } else {
slot += 1; Slot += 1;
} }
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot >= SLOTXY_BELT_FIRST && slot < SLOTXY_BELT_LAST) { } else if (Slot >= SLOTXY_BELT_FIRST && Slot < SLOTXY_BELT_LAST) {
slot += 1; Slot += 1;
mousePos = BeltGetSlotCoord(slot); mousePos = BeltGetSlotCoord(Slot);
} else if (myPlayer.HoldItem._itype == ITYPE_RING) { } else if (myPlayer.HoldItem._itype == ITYPE_RING) {
slot = SLOTXY_RING_RIGHT; Slot = SLOTXY_RING_RIGHT;
mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT);
} else if (myPlayer.HoldItem.isWeapon() || myPlayer.HoldItem.isShield()) { } else if (myPlayer.HoldItem.isWeapon() || myPlayer.HoldItem.isShield()) {
if (slot == SLOTXY_HAND_LEFT_FIRST) { if (Slot == SLOTXY_HAND_LEFT_FIRST) {
slot = SLOTXY_HAND_RIGHT_FIRST; Slot = SLOTXY_HAND_RIGHT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT);
} else if (slot == SLOTXY_HAND_RIGHT_FIRST) { } else if (Slot == SLOTXY_HAND_RIGHT_FIRST) {
slot = SLOTXY_HAND_LEFT_FIRST; Slot = SLOTXY_HAND_LEFT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT);
} }
} }
} else { } else {
if (slot == SLOTXY_RING_LEFT) { if (Slot == SLOTXY_RING_LEFT) {
slot = SLOTXY_RING_RIGHT; Slot = SLOTXY_RING_RIGHT;
mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT);
} else if (slot == SLOTXY_HAND_LEFT_FIRST) { } else if (Slot == SLOTXY_HAND_LEFT_FIRST) {
slot = SLOTXY_CHEST_FIRST; Slot = SLOTXY_CHEST_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); mousePos = InvGetEquipSlotCoord(INVLOC_CHEST);
} else if (slot == SLOTXY_CHEST_FIRST) { } else if (Slot == SLOTXY_CHEST_FIRST) {
slot = SLOTXY_HAND_RIGHT_FIRST; Slot = SLOTXY_HAND_RIGHT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT);
} else if (slot == SLOTXY_HEAD_FIRST) { } else if (Slot == SLOTXY_HEAD_FIRST) {
slot = SLOTXY_AMULET; Slot = SLOTXY_AMULET;
mousePos = InvGetEquipSlotCoord(INVLOC_AMULET); mousePos = InvGetEquipSlotCoord(INVLOC_AMULET);
} else if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { } else if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) {
if ( if (
slot == SLOTXY_INV_ROW1_LAST + 1 - itemSize.width || slot == SLOTXY_INV_ROW2_LAST + 1 - itemSize.width || slot == SLOTXY_INV_ROW3_LAST + 1 - itemSize.width || slot == SLOTXY_INV_ROW4_LAST + 1 - itemSize.width) { Slot == SLOTXY_INV_ROW1_LAST + 1 - itemSize.width || Slot == SLOTXY_INV_ROW2_LAST + 1 - itemSize.width || Slot == SLOTXY_INV_ROW3_LAST + 1 - itemSize.width || Slot == SLOTXY_INV_ROW4_LAST + 1 - itemSize.width) {
slot -= INV_ROW_SLOT_SIZE - itemSize.width; Slot -= INV_ROW_SLOT_SIZE - itemSize.width;
} else { } else {
slot += itemSize.width; Slot += itemSize.width;
} }
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot >= SLOTXY_BELT_FIRST && slot < SLOTXY_BELT_LAST) { } else if (Slot >= SLOTXY_BELT_FIRST && Slot < SLOTXY_BELT_LAST) {
slot += 1; Slot += 1;
mousePos = BeltGetSlotCoord(slot); mousePos = BeltGetSlotCoord(Slot);
} }
} }
} }
if (dir.y == AxisDirectionY_UP) { if (dir.y == AxisDirectionY_UP) {
if (isHoldingItem) { if (isHoldingItem) {
if (slot >= SLOTXY_INV_ROW2_FIRST) { // general inventory if (Slot >= SLOTXY_INV_ROW2_FIRST) { // general inventory
slot -= INV_ROW_SLOT_SIZE; Slot -= INV_ROW_SLOT_SIZE;
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot >= SLOTXY_INV_FIRST) { } else if (Slot >= SLOTXY_INV_FIRST) {
if (myPlayer.HoldItem._itype == ITYPE_RING) { if (myPlayer.HoldItem._itype == ITYPE_RING) {
if (slot >= SLOTXY_INV_ROW1_FIRST && slot <= SLOTXY_INV_ROW1_FIRST + (INV_ROW_SLOT_SIZE / 2) - 1) { if (Slot >= SLOTXY_INV_ROW1_FIRST && Slot <= SLOTXY_INV_ROW1_FIRST + (INV_ROW_SLOT_SIZE / 2) - 1) {
slot = SLOTXY_RING_LEFT; Slot = SLOTXY_RING_LEFT;
mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT);
} else { } else {
slot = SLOTXY_RING_RIGHT; Slot = SLOTXY_RING_RIGHT;
mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT);
} }
} else if (myPlayer.HoldItem.isWeapon()) { } else if (myPlayer.HoldItem.isWeapon()) {
slot = SLOTXY_HAND_LEFT_FIRST; Slot = SLOTXY_HAND_LEFT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT);
} else if (myPlayer.HoldItem.isShield()) { } else if (myPlayer.HoldItem.isShield()) {
slot = SLOTXY_HAND_RIGHT_FIRST; Slot = SLOTXY_HAND_RIGHT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT);
} else if (myPlayer.HoldItem.isHelm()) { } else if (myPlayer.HoldItem.isHelm()) {
slot = SLOTXY_HEAD_FIRST; Slot = SLOTXY_HEAD_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HEAD); mousePos = InvGetEquipSlotCoord(INVLOC_HEAD);
} else if (myPlayer.HoldItem.isArmor()) { } else if (myPlayer.HoldItem.isArmor()) {
slot = SLOTXY_CHEST_FIRST; Slot = SLOTXY_CHEST_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); mousePos = InvGetEquipSlotCoord(INVLOC_CHEST);
} else if (myPlayer.HoldItem._itype == ITYPE_AMULET) { } else if (myPlayer.HoldItem._itype == ITYPE_AMULET) {
slot = SLOTXY_AMULET; Slot = SLOTXY_AMULET;
mousePos = InvGetEquipSlotCoord(INVLOC_AMULET); mousePos = InvGetEquipSlotCoord(INVLOC_AMULET);
} }
} }
} else { } else {
if (slot >= SLOTXY_INV_ROW1_FIRST && slot < SLOTXY_INV_ROW1_FIRST + 3) { // first 3 general slots if (Slot >= SLOTXY_INV_ROW1_FIRST && Slot < SLOTXY_INV_ROW1_FIRST + 3) { // first 3 general slots
slot = SLOTXY_RING_LEFT; Slot = SLOTXY_RING_LEFT;
mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT);
} else if (slot >= SLOTXY_INV_ROW1_FIRST + 3 && slot < SLOTXY_INV_ROW1_FIRST + 7) { // middle 4 general slots } else if (Slot >= SLOTXY_INV_ROW1_FIRST + 3 && Slot < SLOTXY_INV_ROW1_FIRST + 7) { // middle 4 general slots
slot = SLOTXY_CHEST_FIRST; Slot = SLOTXY_CHEST_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); mousePos = InvGetEquipSlotCoord(INVLOC_CHEST);
} else if (slot >= SLOTXY_INV_ROW1_FIRST + 7 && slot < SLOTXY_INV_ROW1_LAST) { // last 3 general slots } else if (Slot >= SLOTXY_INV_ROW1_FIRST + 7 && Slot < SLOTXY_INV_ROW1_LAST) { // last 3 general slots
slot = SLOTXY_RING_RIGHT; Slot = SLOTXY_RING_RIGHT;
mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT);
} else if (slot == SLOTXY_CHEST_FIRST || slot == SLOTXY_HAND_LEFT_FIRST) { } else if (Slot == SLOTXY_CHEST_FIRST || Slot == SLOTXY_HAND_LEFT_FIRST) {
slot = SLOTXY_HEAD_FIRST; Slot = SLOTXY_HEAD_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HEAD); mousePos = InvGetEquipSlotCoord(INVLOC_HEAD);
} else if (slot == SLOTXY_RING_LEFT) { } else if (Slot == SLOTXY_RING_LEFT) {
slot = SLOTXY_HAND_LEFT_FIRST; Slot = SLOTXY_HAND_LEFT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT);
} else if (slot == SLOTXY_RING_RIGHT) { } else if (Slot == SLOTXY_RING_RIGHT) {
slot = SLOTXY_HAND_RIGHT_FIRST; Slot = SLOTXY_HAND_RIGHT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT);
} else if (slot == SLOTXY_HAND_RIGHT_FIRST) { } else if (Slot == SLOTXY_HAND_RIGHT_FIRST) {
slot = SLOTXY_AMULET; Slot = SLOTXY_AMULET;
mousePos = InvGetEquipSlotCoord(INVLOC_AMULET); mousePos = InvGetEquipSlotCoord(INVLOC_AMULET);
} else if (slot >= SLOTXY_INV_ROW2_FIRST) { } else if (Slot >= SLOTXY_INV_ROW2_FIRST) {
slot -= INV_ROW_SLOT_SIZE; Slot -= INV_ROW_SLOT_SIZE;
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} }
} }
} else if (dir.y == AxisDirectionY_DOWN) { } else if (dir.y == AxisDirectionY_DOWN) {
if (isHoldingItem) { if (isHoldingItem) {
if (slot == SLOTXY_HEAD_FIRST || slot == SLOTXY_CHEST_FIRST) { if (Slot == SLOTXY_HEAD_FIRST || Slot == SLOTXY_CHEST_FIRST) {
slot = SLOTXY_INV_ROW1_FIRST + 4; Slot = SLOTXY_INV_ROW1_FIRST + 4;
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot == SLOTXY_RING_LEFT || slot == SLOTXY_HAND_LEFT_FIRST) { } else if (Slot == SLOTXY_RING_LEFT || Slot == SLOTXY_HAND_LEFT_FIRST) {
slot = SLOTXY_INV_ROW1_FIRST + 1; Slot = SLOTXY_INV_ROW1_FIRST + 1;
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot == SLOTXY_RING_RIGHT || slot == SLOTXY_HAND_RIGHT_FIRST || slot == SLOTXY_AMULET) { } else if (Slot == SLOTXY_RING_RIGHT || Slot == SLOTXY_HAND_RIGHT_FIRST || Slot == SLOTXY_AMULET) {
slot = SLOTXY_INV_ROW1_LAST - 1; Slot = SLOTXY_INV_ROW1_LAST - 1;
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot <= (SLOTXY_INV_ROW4_LAST - (icursH28 * INV_ROW_SLOT_SIZE))) { } else if (Slot <= (SLOTXY_INV_ROW4_LAST - (icursH28 * INV_ROW_SLOT_SIZE))) {
slot += INV_ROW_SLOT_SIZE; Slot += INV_ROW_SLOT_SIZE;
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot <= SLOTXY_INV_LAST && myPlayer.HoldItem._itype == ITYPE_MISC && icursW28 == 1 && icursH28 == 1) { // forcing only 1x1 misc items } else if (Slot <= SLOTXY_INV_LAST && myPlayer.HoldItem._itype == ITYPE_MISC && icursW28 == 1 && icursH28 == 1) { // forcing only 1x1 misc items
slot += INV_ROW_SLOT_SIZE; Slot += INV_ROW_SLOT_SIZE;
if (slot > SLOTXY_BELT_LAST) if (Slot > SLOTXY_BELT_LAST)
slot = SLOTXY_BELT_LAST; Slot = SLOTXY_BELT_LAST;
mousePos = BeltGetSlotCoord(slot); mousePos = BeltGetSlotCoord(Slot);
} }
} else { } else {
if (slot == SLOTXY_HEAD_FIRST) { if (Slot == SLOTXY_HEAD_FIRST) {
slot = SLOTXY_CHEST_FIRST; Slot = SLOTXY_CHEST_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); mousePos = InvGetEquipSlotCoord(INVLOC_CHEST);
} else if (slot == SLOTXY_CHEST_FIRST) { } else if (Slot == SLOTXY_CHEST_FIRST) {
slot = SLOTXY_INV_ROW1_FIRST + (INV_ROW_SLOT_SIZE / 2); Slot = SLOTXY_INV_ROW1_FIRST + (INV_ROW_SLOT_SIZE / 2);
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot == SLOTXY_HAND_LEFT_FIRST) { } else if (Slot == SLOTXY_HAND_LEFT_FIRST) {
slot = SLOTXY_RING_LEFT; Slot = SLOTXY_RING_LEFT;
mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT);
} else if (slot == SLOTXY_RING_LEFT) { } else if (Slot == SLOTXY_RING_LEFT) {
slot = SLOTXY_INV_ROW1_FIRST + 1; Slot = SLOTXY_INV_ROW1_FIRST + 1;
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot == SLOTXY_RING_RIGHT) { } else if (Slot == SLOTXY_RING_RIGHT) {
slot = SLOTXY_INV_ROW1_LAST - 1; Slot = SLOTXY_INV_ROW1_LAST - 1;
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot == SLOTXY_AMULET) { } else if (Slot == SLOTXY_AMULET) {
slot = SLOTXY_HAND_RIGHT_FIRST; Slot = SLOTXY_HAND_RIGHT_FIRST;
mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT);
} else if (slot == SLOTXY_HAND_RIGHT_FIRST) { } else if (Slot == SLOTXY_HAND_RIGHT_FIRST) {
slot = SLOTXY_RING_RIGHT; Slot = SLOTXY_RING_RIGHT;
mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT);
} else if (slot <= (SLOTXY_INV_ROW4_LAST - (itemSize.height * INV_ROW_SLOT_SIZE))) { } else if (Slot <= (SLOTXY_INV_ROW4_LAST - (itemSize.height * INV_ROW_SLOT_SIZE))) {
slot += itemSize.height * INV_ROW_SLOT_SIZE; Slot += itemSize.height * INV_ROW_SLOT_SIZE;
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
} else if (slot <= SLOTXY_INV_LAST) { } else if (Slot <= SLOTXY_INV_LAST) {
slot += itemSize.height * INV_ROW_SLOT_SIZE; Slot += itemSize.height * INV_ROW_SLOT_SIZE;
if (slot > SLOTXY_BELT_LAST) if (Slot > SLOTXY_BELT_LAST)
slot = SLOTXY_BELT_LAST; Slot = SLOTXY_BELT_LAST;
mousePos = BeltGetSlotCoord(slot); mousePos = BeltGetSlotCoord(Slot);
} }
} }
} }
// no movement was made // no movement was made
if (slot == initialSlot) if (Slot == initialSlot)
return; return;
// get item under new slot if navigating on the inventory // get item under new slot if navigating on the inventory
if (!isHoldingItem && slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { if (!isHoldingItem && Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) {
itemSize = GetItemSizeOnSlot(slot, itemInvId); itemSize = GetItemSizeOnSlot(Slot, itemInvId);
// search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId // search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId
if (itemInvId < 0) { if (itemInvId < 0) {
for (int s = 0; s < SLOTXY_INV_LAST - SLOTXY_INV_FIRST; ++s) { for (int s = 0; s < SLOTXY_INV_LAST - SLOTXY_INV_FIRST; ++s) {
if (myPlayer.InvGrid[s] == -itemInvId) { if (myPlayer.InvGrid[s] == -itemInvId) {
slot = SLOTXY_INV_FIRST + s; Slot = SLOTXY_INV_FIRST + s;
break; break;
} }
} }
} }
// offset the slot to always move to the top-left most slot of that item // offset the slot to always move to the top-left most slot of that item
slot -= ((itemSize.height - 1) * INV_ROW_SLOT_SIZE); Slot -= ((itemSize.height - 1) * INV_ROW_SLOT_SIZE);
mousePos = InvGetSlotCoord(slot); mousePos = InvGetSlotCoord(Slot);
mousePos.x += ((itemSize.width - 1) * InventorySlotSizeInPixels.width) / 2; mousePos.x += ((itemSize.width - 1) * InventorySlotSizeInPixels.width) / 2;
mousePos.y += ((itemSize.height - 1) * InventorySlotSizeInPixels.height) / 2; mousePos.y += ((itemSize.height - 1) * InventorySlotSizeInPixels.height) / 2;
} }
// move cursor to the center of the slot if not holding anything or top left is holding an object // move cursor to the center of the slot if not holding anything or top left is holding an object
if (isHoldingItem) { if (isHoldingItem) {
if (slot >= SLOTXY_INV_FIRST) if (Slot >= SLOTXY_INV_FIRST)
mousePos.y -= InventorySlotSizeInPixels.height; mousePos.y -= InventorySlotSizeInPixels.height;
else else
mousePos.y -= (int)((icursH28 / 2.0) * InventorySlotSizeInPixels.height) + (InventorySlotSizeInPixels.height / 2); mousePos.y -= (int)((icursH28 / 2.0) * InventorySlotSizeInPixels.height) + (InventorySlotSizeInPixels.height / 2);
@ -1297,7 +1297,7 @@ void HandleRightStickMotion()
*/ */
void FocusOnInventory() void FocusOnInventory()
{ {
slot = SLOTXY_INV_FIRST; Slot = SLOTXY_INV_FIRST;
ResetInvCursorPosition(); ResetInvCursorPosition();
} }

6
Source/controls/touch.cpp

@ -318,12 +318,12 @@ static void PreprocessFingerMotion(SDL_Event *event)
devilution::OutputToLogical(&x, &y); devilution::OutputToLogical(&x, &y);
} else { } else {
// for relative mode, use the pointer speed setting // for relative mode, use the pointer speed setting
constexpr float speedFactor = 1.25F; constexpr float SpeedFactor = 1.25F;
// convert touch events to relative mouse pointer events // convert touch events to relative mouse pointer events
// Whenever an SDL_event involving the mouse is processed, // Whenever an SDL_event involving the mouse is processed,
x = static_cast<int>(mouse_x + (event->tfinger.dx * speedFactor * devilution::GetOutputSurface()->w)); x = static_cast<int>(mouse_x + (event->tfinger.dx * SpeedFactor * devilution::GetOutputSurface()->w));
y = static_cast<int>(mouse_y + (event->tfinger.dy * speedFactor * devilution::GetOutputSurface()->h)); y = static_cast<int>(mouse_y + (event->tfinger.dy * SpeedFactor * devilution::GetOutputSurface()->h));
} }
x = clip(x, 0, devilution::GetOutputSurface()->w); x = clip(x, 0, devilution::GetOutputSurface()->w);

49
Source/diablo.cpp

@ -973,7 +973,7 @@ static void PressKey(int vkey)
if (sgnTimeoutCurs != CURSOR_NONE) { if (sgnTimeoutCurs != CURSOR_NONE) {
return; return;
} }
keymapper.keyPressed(vkey); keymapper.KeyPressed(vkey);
if (vkey == DVL_VK_RETURN) { if (vkey == DVL_VK_RETURN) {
if (GetAsyncKeyState(DVL_VK_MENU)) if (GetAsyncKeyState(DVL_VK_MENU))
dx_reinit(); dx_reinit();
@ -1005,7 +1005,7 @@ static void PressKey(int vkey)
return; return;
} }
keymapper.keyPressed(vkey); keymapper.KeyPressed(vkey);
if (vkey == DVL_VK_RETURN) { if (vkey == DVL_VK_RETURN) {
if (GetAsyncKeyState(DVL_VK_MENU)) { if (GetAsyncKeyState(DVL_VK_MENU)) {
@ -1959,20 +1959,20 @@ bool isPlayerDead()
void initKeymapActions() void initKeymapActions()
{ {
keymapper.addAction({ keymapper.AddAction({
"Help", "Help",
DVL_VK_F1, DVL_VK_F1,
helpKeyPressed, helpKeyPressed,
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
#ifdef _DEBUG #ifdef _DEBUG
keymapper.addAction({ keymapper.AddAction({
"ItemInfo", "ItemInfo",
DVL_VK_INVALID, DVL_VK_INVALID,
itemInfoKeyPressed, itemInfoKeyPressed,
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
keymapper.addAction({ keymapper.AddAction({
"QuestDebug", "QuestDebug",
DVL_VK_INVALID, DVL_VK_INVALID,
PrintDebugQuest, PrintDebugQuest,
@ -1980,7 +1980,7 @@ void initKeymapActions()
}); });
#endif #endif
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
quickSpellActionIndexes[i] = keymapper.addAction({ quickSpellActionIndexes[i] = keymapper.AddAction({
std::string("QuickSpell") + std::to_string(i + 1), std::string("QuickSpell") + std::to_string(i + 1),
DVL_VK_F5 + i, DVL_VK_F5 + i,
[i]() { [i]() {
@ -1994,43 +1994,43 @@ void initKeymapActions()
}); });
} }
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
keymapper.addAction({ keymapper.AddAction({
QuickMessages[i].key, QuickMessages[i].key,
DVL_VK_F9 + i, DVL_VK_F9 + i,
[i]() { DiabloHotkeyMsg(i); }, [i]() { DiabloHotkeyMsg(i); },
}); });
} }
keymapper.addAction({ keymapper.AddAction({
"DecreaseGamma", "DecreaseGamma",
'G', 'G',
DecreaseGamma, DecreaseGamma,
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
keymapper.addAction({ keymapper.AddAction({
"IncreaseGamma", "IncreaseGamma",
'F', 'F',
IncreaseGamma, IncreaseGamma,
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
keymapper.addAction({ keymapper.AddAction({
"Inventory", "Inventory",
'I', 'I',
inventoryKeyPressed, inventoryKeyPressed,
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
keymapper.addAction({ keymapper.AddAction({
"Character", "Character",
'C', 'C',
characterSheetKeyPressed, characterSheetKeyPressed,
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
keymapper.addAction({ keymapper.AddAction({
"QuestLog", "QuestLog",
'Q', 'Q',
questLogKeyPressed, questLogKeyPressed,
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
keymapper.addAction({ keymapper.AddAction({
"Zoom", "Zoom",
'Z', 'Z',
[] { [] {
@ -2039,19 +2039,19 @@ void initKeymapActions()
}, },
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
keymapper.addAction({ keymapper.AddAction({
"DisplaySpells", "DisplaySpells",
'S', 'S',
displaySpellsKeyPressed, displaySpellsKeyPressed,
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
keymapper.addAction({ keymapper.AddAction({
"SpellBook", "SpellBook",
'B', 'B',
spellBookKeyPressed, spellBookKeyPressed,
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
keymapper.addAction({ keymapper.AddAction({
"GameInfo", "GameInfo",
'V', 'V',
[] { [] {
@ -2061,13 +2061,16 @@ void initKeymapActions()
_("Nightmare"), _("Nightmare"),
_("Hell"), _("Hell"),
}; };
strcpy(pszStr, fmt::format(_(/* TRANSLATORS: {:s} means: Character Name, Game Version, Game Difficulty. */ "{:s}, version = {:s}, mode = {:s}"), gszProductName, PROJECT_VERSION, difficulties[sgGameInitInfo.nDifficulty]).c_str()); strcpy(pszStr, fmt::format(_(/* TRANSLATORS: {:s} means: Character Name, Game Version, Game Difficulty. */
"{:s}, version = {:s}, mode = {:s}"),
gszProductName, PROJECT_VERSION, difficulties[sgGameInitInfo.nDifficulty])
.c_str());
NetSendCmdString(1 << MyPlayerId, pszStr); NetSendCmdString(1 << MyPlayerId, pszStr);
}, },
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
keymapper.addAction({ keymapper.AddAction({
std::string("BeltItem") + std::to_string(i + 1), std::string("BeltItem") + std::to_string(i + 1),
'1' + i, '1' + i,
[i] { [i] {
@ -2079,25 +2082,25 @@ void initKeymapActions()
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
} }
keymapper.addAction({ keymapper.AddAction({
"QuickSave", "QuickSave",
DVL_VK_F2, DVL_VK_F2,
[] { gamemenu_save_game(false); }, [] { gamemenu_save_game(false); },
[&]() { return !gbIsMultiplayer && !isPlayerDead(); }, [&]() { return !gbIsMultiplayer && !isPlayerDead(); },
}); });
keymapper.addAction({ keymapper.AddAction({
"QuickLoad", "QuickLoad",
DVL_VK_F3, DVL_VK_F3,
[] { gamemenu_load_game(false); }, [] { gamemenu_load_game(false); },
[&]() { return !gbIsMultiplayer && gbValidSaveFile; }, [&]() { return !gbIsMultiplayer && gbValidSaveFile; },
}); });
keymapper.addAction({ keymapper.AddAction({
"QuitGame", "QuitGame",
DVL_VK_INVALID, DVL_VK_INVALID,
[] { gamemenu_quit_game(false); }, [] { gamemenu_quit_game(false); },
}); });
#ifdef _DEBUG #ifdef _DEBUG
keymapper.addAction({ keymapper.AddAction({
"CheatExperience", "CheatExperience",
DVL_VK_INVALID, DVL_VK_INVALID,
[] { [] {
@ -2109,7 +2112,7 @@ void initKeymapActions()
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
#endif #endif
keymapper.addAction({ keymapper.AddAction({
"StopHero", "StopHero",
DVL_VK_INVALID, DVL_VK_INVALID,
[] { Players[MyPlayerId].Stop(); }, [] { Players[MyPlayerId].Stop(); },

56
Source/drlg_l1.cpp

@ -759,7 +759,7 @@ static void DrlgL1Shadows()
} }
} }
static int DrlgPlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int noquad, int ldir) static int DrlgPlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int noquad)
{ {
int sx; int sx;
int sy; int sy;
@ -2286,20 +2286,20 @@ static void DrlgL5(lvl_entry entry)
if (QuestStatus(Q_PWATER)) { if (QuestStatus(Q_PWATER)) {
if (entry == ENTRY_MAIN) { if (entry == ENTRY_MAIN) {
if (DrlgPlaceMiniSet(PWATERIN, 1, 1, 0, 0, true, -1, 0) < 0) if (DrlgPlaceMiniSet(PWATERIN, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
} else { } else {
if (DrlgPlaceMiniSet(PWATERIN, 1, 1, 0, 0, false, -1, 0) < 0) if (DrlgPlaceMiniSet(PWATERIN, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
ViewY--; ViewY--;
} }
} }
if (QuestStatus(Q_LTBANNER)) { if (QuestStatus(Q_LTBANNER)) {
if (entry == ENTRY_MAIN) { if (entry == ENTRY_MAIN) {
if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1, 0) < 0) if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
} else { } else {
if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0) if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
if (entry == ENTRY_PREV) { if (entry == ENTRY_PREV) {
ViewX = 2 * setpc_x + 20; ViewX = 2 * setpc_x + 20;
@ -2311,49 +2311,49 @@ static void DrlgL5(lvl_entry entry)
} else if (entry == ENTRY_MAIN) { } else if (entry == ENTRY_MAIN) {
if (currlevel < 21) { if (currlevel < 21) {
if (!Players[MyPlayerId].pOriginalCathedral) { if (!Players[MyPlayerId].pOriginalCathedral) {
if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1, 0) < 0) if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
} else { } else {
if (DrlgPlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, true, -1, 0) < 0) if (DrlgPlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
else if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) else if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
} }
} else if (currlevel == 21) { } else if (currlevel == 21) {
if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, false, -1, 6) < 0) if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
ViewY++; ViewY++;
} else { } else {
if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1, 0) < 0) if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
if (currlevel != 24) { if (currlevel != 24) {
if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
} }
ViewY++; ViewY++;
} }
} else if (!Players[MyPlayerId].pOriginalCathedral && entry == ENTRY_PREV) { } else if (!Players[MyPlayerId].pOriginalCathedral && entry == ENTRY_PREV) {
if (currlevel < 21) { if (currlevel < 21) {
if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0) if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, true, -1, 1) < 0) if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
ViewY--; ViewY--;
} else if (currlevel == 21) { } else if (currlevel == 21) {
if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, false, -1, 6) < 0) if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, true, -1, 1) < 0) if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
ViewY += 3; ViewY += 3;
} else { } else {
if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1, 0) < 0) if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
if (currlevel != 24) { if (currlevel != 24) {
if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, true, -1, 1) < 0) if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
} }
ViewY += 3; ViewY += 3;
@ -2361,27 +2361,27 @@ static void DrlgL5(lvl_entry entry)
} else { } else {
if (currlevel < 21) { if (currlevel < 21) {
if (!Players[MyPlayerId].pOriginalCathedral) { if (!Players[MyPlayerId].pOriginalCathedral) {
if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0) if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
} else { } else {
if (DrlgPlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0) if (DrlgPlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
else if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, true, -1, 1) < 0) else if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
ViewY--; ViewY--;
} }
} else if (currlevel == 21) { } else if (currlevel == 21) {
if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, true, -1, 6) < 0) if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
} else { } else {
if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1, 0) < 0) if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1) < 0)
doneflag = false; doneflag = false;
if (currlevel != 24) { if (currlevel != 24) {
if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0)
doneflag = false; doneflag = false;
} }
} }
@ -2462,7 +2462,7 @@ static void DrlgL5(lvl_entry entry)
if (currlevel < 21) { if (currlevel < 21) {
DrlgL1Shadows(); DrlgL1Shadows();
DrlgPlaceMiniSet(LAMPS, 5, 10, 0, 0, false, -1, 4); DrlgPlaceMiniSet(LAMPS, 5, 10, 0, 0, false, -1);
DrlgL1Floor(); DrlgL1Floor();
} }

22
Source/drlg_l2.cpp

@ -1612,7 +1612,7 @@ int Patterns[100][10] = {
} // namespace } // namespace
static bool DrlgL2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) static bool DrlgL2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview)
{ {
int sw = miniset[0]; int sw = miniset[0];
int sh = miniset[1]; int sh = miniset[1];
@ -1775,7 +1775,7 @@ static void DrlgL2Subs()
static void DrlgL2Shadows() static void DrlgL2Shadows()
{ {
int8_t sd[2][2]; uint8_t sd[2][2];
for (int y = 1; y < DMAXY; y++) { for (int y = 1; y < DMAXY; y++) {
for (int x = 1; x < DMAXX; x++) { for (int x = 1; x < DMAXX; x++) {
@ -2965,29 +2965,29 @@ static void DrlgL2(lvl_entry entry)
DrlgL2FloodTVal(); DrlgL2FloodTVal();
DrlgL2TransFix(); DrlgL2TransFix();
if (entry == ENTRY_MAIN) { if (entry == ENTRY_MAIN) {
doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, true, 0); doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, true);
if (doneflag) { if (doneflag) {
doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false, 1); doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false);
if (doneflag && currlevel == 5) { if (doneflag && currlevel == 5) {
doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false, 6); doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false);
} }
} }
ViewY -= 2; ViewY -= 2;
} else if (entry == ENTRY_PREV) { } else if (entry == ENTRY_PREV) {
doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false, 0); doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false);
if (doneflag) { if (doneflag) {
doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, true, 1); doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, true);
if (doneflag && currlevel == 5) { if (doneflag && currlevel == 5) {
doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false, 6); doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false);
} }
} }
ViewX--; ViewX--;
} else { } else {
doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false, 0); doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false);
if (doneflag) { if (doneflag) {
doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false, 1); doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false);
if (doneflag && currlevel == 5) { if (doneflag && currlevel == 5) {
doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, true, 6); doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, true);
} }
} }
ViewY -= 2; ViewY -= 2;

42
Source/drlg_l3.cpp

@ -1598,7 +1598,7 @@ static void DrlgL3PoolFix()
} }
} }
static bool DrlgL3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) static bool DrlgL3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview)
{ {
int sx; int sx;
int sy; int sy;
@ -2257,67 +2257,67 @@ static void DrlgL3(lvl_entry entry)
DrlgL3MakeMegas(); DrlgL3MakeMegas();
if (entry == ENTRY_MAIN) { if (entry == ENTRY_MAIN) {
if (currlevel < 17) { if (currlevel < 17) {
genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, true, 0); genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, true);
} else { } else {
if (currlevel != 17) if (currlevel != 17)
genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, true, 0); genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, true);
else else
genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true, 6); genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true);
} }
if (!genok) { if (!genok) {
if (currlevel < 17) { if (currlevel < 17) {
genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false, 1); genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false);
} else { } else {
if (currlevel != 20) if (currlevel != 20)
genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false, 1); genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false);
} }
if (!genok && currlevel == 9) { if (!genok && currlevel == 9) {
genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false, 6); genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false);
} }
} }
} else if (entry == ENTRY_PREV) { } else if (entry == ENTRY_PREV) {
if (currlevel < 17) { if (currlevel < 17) {
genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, false, 0); genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, false);
} else { } else {
if (currlevel != 17) if (currlevel != 17)
genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, false, 0); genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, false);
else else
genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, false, 6); genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, false);
} }
if (!genok) { if (!genok) {
if (currlevel < 17) { if (currlevel < 17) {
genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, true, 1); genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, true);
ViewX += 2; ViewX += 2;
ViewY -= 2; ViewY -= 2;
} else { } else {
if (currlevel != 20) { if (currlevel != 20) {
genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, true, 1); genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, true);
ViewX += 2; ViewX += 2;
ViewY -= 2; ViewY -= 2;
} }
} }
if (!genok && currlevel == 9) { if (!genok && currlevel == 9) {
genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false, 6); genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false);
} }
} }
} else { } else {
if (currlevel < 17) { if (currlevel < 17) {
genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, false, 0); genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, false);
} else { } else {
if (currlevel != 17) if (currlevel != 17)
genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, false, 0); genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, false);
else else
genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true, 6); genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true);
} }
if (!genok) { if (!genok) {
if (currlevel < 17) { if (currlevel < 17) {
genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false, 1); genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false);
} else { } else {
if (currlevel != 20) if (currlevel != 20)
genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false, 1); genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false);
} }
if (!genok && currlevel == 9) { if (!genok && currlevel == 9) {
genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, true, 6); genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, true);
} }
} }
} }
@ -2494,9 +2494,7 @@ void CreateL3Dungeon(uint32_t rseed, lvl_entry entry)
DoLighting({ i, j }, 7, -1); DoLighting({ i, j }, 7, -1);
} else if (dPiece[i][j] >= 154 && dPiece[i][j] <= 161) { } else if (dPiece[i][j] >= 154 && dPiece[i][j] <= 161) {
DoLighting({ i, j }, 7, -1); DoLighting({ i, j }, 7, -1);
} else if (dPiece[i][j] == 150) { } else if (IsAnyOf(dPiece[i][j], 150, 152)) {
DoLighting({ i, j }, 7, -1);
} else if (dPiece[i][j] == 152) {
DoLighting({ i, j }, 7, -1); DoLighting({ i, j }, 7, -1);
} }
} }

44
Source/drlg_l4.cpp

@ -1094,7 +1094,7 @@ void DRLG_LoadDiabQuads(bool preflag)
} }
} }
static bool DrlgL4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) static bool DrlgL4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview)
{ {
int sx; int sx;
int sy; int sy;
@ -1393,72 +1393,72 @@ static void DrlgL4(lvl_entry entry)
} }
if (QuestStatus(Q_WARLORD)) { if (QuestStatus(Q_WARLORD)) {
if (entry == ENTRY_MAIN) { if (entry == ENTRY_MAIN) {
doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true);
if (doneflag && currlevel == 13) { if (doneflag && currlevel == 13) {
doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false);
} }
ViewX++; ViewX++;
} else if (entry == ENTRY_PREV) { } else if (entry == ENTRY_PREV) {
doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false);
if (doneflag && currlevel == 13) { if (doneflag && currlevel == 13) {
doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false);
} }
ViewX = 2 * setpc_x + 22; ViewX = 2 * setpc_x + 22;
ViewY = 2 * setpc_y + 22; ViewY = 2 * setpc_y + 22;
} else { } else {
doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false);
if (doneflag && currlevel == 13) { if (doneflag && currlevel == 13) {
doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true, 6); doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true);
} }
ViewX++; ViewX++;
} }
} else if (currlevel != 15) { } else if (currlevel != 15) {
if (entry == ENTRY_MAIN) { if (entry == ENTRY_MAIN) {
doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true);
if (doneflag && currlevel != 16) { if (doneflag && currlevel != 16) {
doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false, 1); doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false);
} }
if (doneflag && currlevel == 13) { if (doneflag && currlevel == 13) {
doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false);
} }
ViewX++; ViewX++;
} else if (entry == ENTRY_PREV) { } else if (entry == ENTRY_PREV) {
doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false);
if (doneflag && currlevel != 16) { if (doneflag && currlevel != 16) {
doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, true, 1); doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, true);
} }
if (doneflag && currlevel == 13) { if (doneflag && currlevel == 13) {
doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false);
} }
ViewY++; ViewY++;
} else { } else {
doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false);
if (doneflag && currlevel != 16) { if (doneflag && currlevel != 16) {
doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false, 1); doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false);
} }
if (doneflag && currlevel == 13) { if (doneflag && currlevel == 13) {
doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true, 6); doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true);
} }
ViewX++; ViewX++;
} }
} else { } else {
if (entry == ENTRY_MAIN) { if (entry == ENTRY_MAIN) {
doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true);
if (doneflag) { if (doneflag) {
if (!gbIsMultiplayer && Quests[Q_DIABLO]._qactive != QUEST_ACTIVE) { if (!gbIsMultiplayer && Quests[Q_DIABLO]._qactive != QUEST_ACTIVE) {
doneflag = DrlgL4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, false, 1); doneflag = DrlgL4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, false);
} else { } else {
doneflag = DrlgL4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, false, 1); doneflag = DrlgL4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, false);
} }
} }
ViewX++; ViewX++;
} else { } else {
doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false);
if (doneflag) { if (doneflag) {
if (!gbIsMultiplayer && Quests[Q_DIABLO]._qactive != QUEST_ACTIVE) { if (!gbIsMultiplayer && Quests[Q_DIABLO]._qactive != QUEST_ACTIVE) {
doneflag = DrlgL4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, true, 1); doneflag = DrlgL4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, true);
} else { } else {
doneflag = DrlgL4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, true, 1); doneflag = DrlgL4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, true);
} }
} }
ViewY++; ViewY++;

20
Source/gmenu.cpp

@ -107,8 +107,8 @@ static void GmenuLeftRight(bool isRight)
if ((sgpCurrItem->dwFlags & GMENU_SLIDER) == 0) if ((sgpCurrItem->dwFlags & GMENU_SLIDER) == 0)
return; return;
int step = sgpCurrItem->dwFlags & 0xFFF; uint16_t step = sgpCurrItem->dwFlags & 0xFFF;
int steps = (int)(sgpCurrItem->dwFlags & 0xFFF000) >> 12; uint16_t steps = (sgpCurrItem->dwFlags & 0xFFF000) >> 12;
if (isRight) { if (isRight) {
if (step == steps) if (step == steps)
return; return;
@ -166,9 +166,9 @@ static void GmenuDrawMenuItem(const Surface &out, TMenuItem *pItem, int y)
if ((pItem->dwFlags & GMENU_SLIDER) != 0) { if ((pItem->dwFlags & GMENU_SLIDER) != 0) {
int x = 16 + w / 2; int x = 16 + w / 2;
CelDrawTo(out, { x + PANEL_LEFT, y - 10 }, *optbar_cel, 1); CelDrawTo(out, { x + PANEL_LEFT, y - 10 }, *optbar_cel, 1);
int step = pItem->dwFlags & 0xFFF; uint16_t step = pItem->dwFlags & 0xFFF;
int nSteps = std::max<int>((pItem->dwFlags & 0xFFF000) >> 12, 2); uint16_t steps = std::max<uint16_t>((pItem->dwFlags & 0xFFF000) >> 12, 2);
int pos = step * 256 / nSteps; uint16_t pos = step * 256 / steps;
GmenuClearBuffer(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); CelDrawTo(out, { x + 2 + pos + PANEL_LEFT, y - 12 }, *option_cel, 1);
} }
@ -280,7 +280,7 @@ bool gmenu_on_mouse_move()
if (!mouseNavigation) if (!mouseNavigation)
return false; return false;
int step = (int)(sgpCurrItem->dwFlags & 0xFFF000) >> 12; uint16_t step = (sgpCurrItem->dwFlags & 0xFFF000) >> 12;
step *= GmenuGetMouseSlider(); step *= GmenuGetMouseSlider();
step /= 256; step /= 256;
@ -350,7 +350,7 @@ void gmenu_enable(TMenuItem *pMenuItem, bool enable)
void gmenu_slider_set(TMenuItem *pItem, int min, int max, int value) void gmenu_slider_set(TMenuItem *pItem, int min, int max, int value)
{ {
assert(pItem); assert(pItem);
int nSteps = std::max((int)(pItem->dwFlags & 0xFFF000) >> 12, 2); uint16_t nSteps = std::max<uint16_t>((pItem->dwFlags & 0xFFF000) >> 12, 2);
pItem->dwFlags &= 0xFFFFF000; pItem->dwFlags &= 0xFFFFF000;
pItem->dwFlags |= ((max - min - 1) / 2 + (value - min) * nSteps) / (max - min); pItem->dwFlags |= ((max - min - 1) / 2 + (value - min) * nSteps) / (max - min);
} }
@ -360,9 +360,9 @@ void gmenu_slider_set(TMenuItem *pItem, int min, int max, int value)
*/ */
int gmenu_slider_get(TMenuItem *pItem, int min, int max) int gmenu_slider_get(TMenuItem *pItem, int min, int max)
{ {
int step = pItem->dwFlags & 0xFFF; uint16_t step = pItem->dwFlags & 0xFFF;
int nSteps = std::max((int)(pItem->dwFlags & 0xFFF000) >> 12, 2); uint16_t steps = std::max<uint16_t>((pItem->dwFlags & 0xFFF000) >> 12, 2);
return min + (step * (max - min) + (nSteps - 1) / 2) / nSteps; return min + (step * (max - min) + (steps - 1) / 2) / steps;
} }
/** /**

8
Source/help.cpp

@ -96,13 +96,13 @@ std::vector<std::string> HelpTextLines;
void InitHelp() void InitHelp()
{ {
HelpFlag = false; HelpFlag = false;
char tempstr[512]; char tempString[512];
for (const auto *text : HelpText) { for (const auto *text : HelpText) {
strcpy(tempstr, _(text)); strcpy(tempString, _(text));
WordWrapGameString(tempstr, 577); WordWrapGameString(tempString, 577);
const string_view paragraph = tempstr; const string_view paragraph = tempString;
size_t previous = 0; size_t previous = 0;
while (true) { while (true) {

2
Source/interfac.cpp

@ -79,7 +79,7 @@ static Cutscenes PickCutscene(interface_mode uMsg)
default: default:
return CutLevel1; return CutLevel1;
} }
}; }
case WM_DIABWARPLVL: case WM_DIABWARPLVL:
return CutPortal; return CutPortal;
case WM_DIABSETLVL: case WM_DIABSETLVL:

3
Source/items.cpp

@ -1706,6 +1706,7 @@ void SaveItemPower(int i, item_effect_type power, int param1, int param2, int mi
r2 = RndPL(51, 75); r2 = RndPL(51, 75);
if (param1 == 151) if (param1 == 151)
r2 = RndPL(76, 100); r2 = RndPL(76, 100);
Items[i]._iPLToHit += r2; Items[i]._iPLToHit += r2;
break; break;
case IPL_TOHIT_DAMP_CURSE: case IPL_TOHIT_DAMP_CURSE:
@ -1714,6 +1715,7 @@ void SaveItemPower(int i, item_effect_type power, int param1, int param2, int mi
r2 = RndPL(1, 5); r2 = RndPL(1, 5);
if (param1 == 50) if (param1 == 50)
r2 = RndPL(6, 10); r2 = RndPL(6, 10);
Items[i]._iPLToHit -= r2; Items[i]._iPLToHit -= r2;
break; break;
case IPL_ACP: case IPL_ACP:
@ -1994,7 +1996,6 @@ void SaveItemPower(int i, item_effect_type power, int param1, int param2, int mi
case IPL_FIRERESCLVL: case IPL_FIRERESCLVL:
Items[i]._iPLFR = 30 - Players[MyPlayerId]._pLevel; Items[i]._iPLFR = 30 - Players[MyPlayerId]._pLevel;
Items[i]._iPLFR = std::max<int16_t>(Items[i]._iPLFR, 0); Items[i]._iPLFR = std::max<int16_t>(Items[i]._iPLFR, 0);
break; break;
case IPL_FIRERES_CURSE: case IPL_FIRERES_CURSE:
Items[i]._iPLFR -= r; Items[i]._iPLFR -= r;

6
Source/lighting.cpp

@ -416,10 +416,10 @@ const char CrawlTable[2749] = {
}; };
/* /*
* VisionCrawlTable specifies the X- Y-coordinate offsets of lighting visions. * X- Y-coordinate offsets of lighting visions.
* The last entry-pair is only for alignment. * The last entry-pair is only for alignment.
*/ */
const BYTE VisionCrawlTable[23][30] = { const uint8_t VisionCrawlTable[23][30] = {
// clang-format off // clang-format off
{ 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0 }, { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0 },
{ 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1 }, { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1 },

10
Source/monster.cpp

@ -204,21 +204,19 @@ void InitMonsterTRN(CMonster &monst)
void InitLevelMonsters() void InitLevelMonsters()
{ {
int i;
LevelMonsterTypeCount = 0; LevelMonsterTypeCount = 0;
monstimgtot = 0; monstimgtot = 0;
MissileFileFlag = 0; MissileFileFlag = 0;
for (i = 0; i < MAX_LVLMTYPES; i++) { for (auto &levelMonsterType : LevelMonsterTypes) {
LevelMonsterTypes[i].mPlaceFlags = 0; levelMonsterType.mPlaceFlags = 0;
} }
ClrAllMonsters(); ClrAllMonsters();
ActiveMonsterCount = 0; ActiveMonsterCount = 0;
totalmonsters = MAXMONSTERS; totalmonsters = MAXMONSTERS;
for (i = 0; i < MAXMONSTERS; i++) { for (int i = 0; i < MAXMONSTERS; i++) {
ActiveMonsters[i] = i; ActiveMonsters[i] = i;
} }
@ -2347,7 +2345,7 @@ bool M_DoTalk(int i)
MonsterStruct *monst = &Monsters[i]; MonsterStruct *monst = &Monsters[i];
M_StartStand(i, Monsters[i]._mdir); M_StartStand(i, Monsters[i]._mdir);
monst->_mgoal = MGOAL_TALKING; // CODEFIX: apply Monst instead of Monsters[i] in the rest of the function monst->_mgoal = MGOAL_TALKING; // CODEFIX: apply Monst instead of monster[i] in the rest of the function
if (effect_is_playing(Texts[Monsters[i].mtalkmsg].sfxnr)) if (effect_is_playing(Texts[Monsters[i].mtalkmsg].sfxnr))
return false; return false;
InitQTextMsg(Monsters[i].mtalkmsg); InitQTextMsg(Monsters[i].mtalkmsg);

4
Source/nthread.h

@ -20,10 +20,10 @@ extern DWORD gdwNormalMsgSize;
extern float gfProgressToNextGameTick; // the progress as a fraction (0.0f to 1.0f) in time to the next game tick extern float gfProgressToNextGameTick; // the progress as a fraction (0.0f to 1.0f) in time to the next game tick
void nthread_terminate_game(const char *pszFcn); void nthread_terminate_game(const char *pszFcn);
DWORD nthread_send_and_recv_turn(DWORD cur_turn, int turn_delta); DWORD nthread_send_and_recv_turn(DWORD curTurn, int turnDelta);
bool nthread_recv_turns(bool *pfSendAsync = nullptr); bool nthread_recv_turns(bool *pfSendAsync = nullptr);
void nthread_set_turn_upper_bit(); void nthread_set_turn_upper_bit();
void nthread_start(bool set_turn_upper_bit); void nthread_start(bool setTurnUpperBit);
void nthread_cleanup(); void nthread_cleanup();
void nthread_ignore_mutex(bool bStart); void nthread_ignore_mutex(bool bStart);
bool nthread_has_500ms_passed(); bool nthread_has_500ms_passed();

4
Source/options.cpp

@ -214,7 +214,7 @@ void LoadOptions()
GetIniValue("Language", "Code", sgOptions.Language.szCode, sizeof(sgOptions.Language.szCode), "en"); GetIniValue("Language", "Code", sgOptions.Language.szCode, sizeof(sgOptions.Language.szCode), "en");
keymapper.load(); keymapper.Load();
sbWasOptionsLoaded = true; sbWasOptionsLoaded = true;
} }
@ -298,7 +298,7 @@ void SaveOptions()
SetIniValue("Language", "Code", sgOptions.Language.szCode); SetIniValue("Language", "Code", sgOptions.Language.szCode);
keymapper.save(); keymapper.Save();
SaveIni(); SaveIni();
} }

25
Source/path.cpp

@ -30,8 +30,18 @@ PATHNODE *pnode_tblptr[MAXPATHNODES];
PATHNODE *path_2_nodes; PATHNODE *path_2_nodes;
/** For iterating over the 8 possible movement directions */ /** For iterating over the 8 possible movement directions */
const char pathxdir[8] = { -1, -1, 1, 1, -1, 0, 1, 0 }; const Displacement PathDirs[8] = {
const char pathydir[8] = { -1, 1, -1, 1, 0, -1, 0, 1 }; // clang-format off
{ -1, -1 },
{ -1, 1 },
{ 1, -1 },
{ 1, 1 },
{ -1, 0 },
{ 0, -1 },
{ 1, 0 },
{ 0, 1 },
// clang-format on
};
/* data */ /* data */
@ -179,12 +189,11 @@ bool path_solid_pieces(PATHNODE *pPath, int dx, int dy)
*/ */
bool path_get_path(bool (*posOk)(int, Point), int posOkArg, PATHNODE *pPath, int x, int y) bool path_get_path(bool (*posOk)(int, Point), int posOkArg, PATHNODE *pPath, int x, int y)
{ {
for (int i = 0; i < 8; i++) { for (auto dir : PathDirs) {
int dx = pPath->position.x + pathxdir[i]; Point tile = pPath->position + dir;
int dy = pPath->position.y + pathydir[i]; bool ok = posOk(posOkArg, tile);
bool ok = posOk(posOkArg, { dx, dy }); if ((ok && path_solid_pieces(pPath, tile.x, tile.y)) || (!ok && tile == Point { x, y })) {
if ((ok && path_solid_pieces(pPath, dx, dy)) || (!ok && dx == x && dy == y)) { if (!path_parent_path(pPath, tile.x, tile.y, x, y))
if (!path_parent_path(pPath, dx, dy, x, y))
return false; return false;
} }
} }

4
Source/path.h

@ -7,6 +7,7 @@
#include <SDL.h> #include <SDL.h>
#include "engine/direction.hpp"
#include "engine/point.hpp" #include "engine/point.hpp"
namespace devilution { namespace devilution {
@ -39,7 +40,6 @@ PATHNODE *path_new_step();
/* rdata */ /* rdata */
extern const char pathxdir[8]; extern const Displacement PathDirs[8];
extern const char pathydir[8];
} // namespace devilution } // namespace devilution

8
Source/player.cpp

@ -1677,11 +1677,11 @@ static void PlrDeadItem(PlayerStruct &player, ItemStruct *itm, Displacement dire
for (int k = 1; k < 50; k++) { for (int k = 1; k < 50; k++) {
for (int j = -k; j <= k; j++) { for (int j = -k; j <= k; j++) {
for (int i = -k; i <= k; i++) { for (int i = -k; i <= k; i++) {
Point target = player.position.tile + Displacement { i, j }; Point next = player.position.tile + Displacement { i, j };
if (ItemSpaceOk(target)) { if (ItemSpaceOk(next)) {
RespawnDeadItem(itm, target); RespawnDeadItem(itm, next);
player.HoldItem = *itm; player.HoldItem = *itm;
NetSendCmdPItem(false, CMD_RESPAWNITEM, target); NetSendCmdPItem(false, CMD_RESPAWNITEM, next);
return; return;
} }
} }

9
Source/qol/autopickup.cpp

@ -44,11 +44,10 @@ void AutoGoldPickup(int pnum)
if (!HasRoomForGold()) if (!HasRoomForGold())
return; return;
for (int dir = 0; dir < 8; dir++) { for (auto pathDir : PathDirs) {
int x = Players[pnum].position.tile.x + pathxdir[dir]; Point tile = Players[pnum].position.tile + pathDir;
int y = Players[pnum].position.tile.y + pathydir[dir]; if (dItem[tile.x][tile.y] != 0) {
if (dItem[x][y] != 0) { int itemIndex = dItem[tile.x][tile.y] - 1;
int itemIndex = dItem[x][y] - 1;
if (Items[itemIndex]._itype == ITYPE_GOLD) { if (Items[itemIndex]._itype == ITYPE_GOLD) {
NetSendCmdGItem(true, CMD_REQUESTAGITEM, pnum, pnum, itemIndex); NetSendCmdGItem(true, CMD_REQUESTAGITEM, pnum, pnum, itemIndex);
Items[itemIndex]._iRequest = true; Items[itemIndex]._iRequest = true;

16
Source/scrollrt.cpp

@ -207,7 +207,6 @@ uint32_t sgdwCursHgtOld;
bool dRendered[MAXDUNX][MAXDUNY]; bool dRendered[MAXDUNX][MAXDUNY];
int frames;
bool frameflag; bool frameflag;
int frameend; int frameend;
int framerate; int framerate;
@ -452,8 +451,7 @@ static void DrawMonster(const Surface &out, int x, int y, int mx, int my, int m)
Cl2DrawLightTbl(out, mx, my, cel, nCel, 1); Cl2DrawLightTbl(out, mx, my, cel, nCel, 1);
return; return;
} }
int trans = 0;
char trans = 0;
if (Monsters[m]._uniqtype != 0) if (Monsters[m]._uniqtype != 0)
trans = Monsters[m]._uniqtrans + 4; trans = Monsters[m]._uniqtrans + 4;
if (Monsters[m]._mmode == MM_STONE) if (Monsters[m]._mmode == MM_STONE)
@ -612,20 +610,20 @@ void DrawDeadPlayer(const Surface &out, int x, int y, int sx, int sy)
*/ */
static void DrawObject(const Surface &out, int x, int y, int ox, int oy, bool pre) static void DrawObject(const Surface &out, int x, int y, int ox, int oy, bool pre)
{ {
if (dObject[x][y] == 0 || LightTableIndex >= LightsMax) int8_t bv = dObject[x][y];
if (bv == 0 || LightTableIndex >= LightsMax)
return; return;
Point objectPosition {}; Point objectPosition {};
int8_t bv = -1; if (bv > 0) {
if (dObject[x][y] > 0) { bv = bv - 1;
bv = dObject[x][y] - 1;
if (Objects[bv]._oPreFlag != pre) if (Objects[bv]._oPreFlag != pre)
return; return;
objectPosition.x = ox - CalculateWidth2(Objects[bv]._oAnimWidth); objectPosition.x = ox - CalculateWidth2(Objects[bv]._oAnimWidth);
objectPosition.y = oy; objectPosition.y = oy;
} else { } else {
bv = -(dObject[x][y] + 1); bv = -(bv + 1);
if (Objects[bv]._oPreFlag != pre) if (Objects[bv]._oPreFlag != pre)
return; return;
int xx = Objects[bv].position.x - x; int xx = Objects[bv].position.x - x;
@ -827,7 +825,7 @@ static void DrawMonsterHelper(const Surface &out, int x, int y, int oy, int sx,
*/ */
static void DrawPlayerHelper(const Surface &out, int x, int y, int sx, int sy) static void DrawPlayerHelper(const Surface &out, int x, int y, int sx, int sy)
{ {
int p = dPlayer[x][y]; int8_t p = dPlayer[x][y];
p = p > 0 ? p - 1 : -(p + 1); p = p > 0 ? p - 1 : -(p + 1);
if (p < 0 || p >= MAX_PLRS) { if (p < 0 || p >= MAX_PLRS) {

2
Source/setmaps.cpp

@ -73,7 +73,7 @@ BYTE SkelChamTrans3[] = {
}; };
/** Maps from quest level to quest level names. */ /** Maps from quest level to quest level names. */
const char *const quest_level_names[] = { const char *const QuestLevelNames[] = {
"", "",
N_("Skeleton King's Lair"), N_("Skeleton King's Lair"),
N_("Chamber of Bone"), N_("Chamber of Bone"),

2
Source/setmaps.h

@ -11,6 +11,6 @@ int ObjIndex(int x, int y);
void LoadSetMap(); void LoadSetMap();
/* rdata */ /* rdata */
extern const char *const quest_level_names[]; extern const char *const QuestLevelNames[];
} // namespace devilution } // namespace devilution

12
Source/sound.cpp

@ -161,7 +161,6 @@ void snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
std::unique_ptr<TSnd> sound_file_load(const char *path, bool stream) std::unique_ptr<TSnd> sound_file_load(const char *path, bool stream)
{ {
int error = 0;
auto snd = std::make_unique<TSnd>(); auto snd = std::make_unique<TSnd>();
snd->start_tc = SDL_GetTicks() - 80 - 1; snd->start_tc = SDL_GetTicks() - 80 - 1;
@ -169,8 +168,7 @@ std::unique_ptr<TSnd> sound_file_load(const char *path, bool stream)
#ifndef STREAM_ALL_AUDIO #ifndef STREAM_ALL_AUDIO
if (stream) { if (stream) {
#endif #endif
error = snd->DSB.SetChunkStream(path); if (snd->DSB.SetChunkStream(path) != 0) {
if (error != 0) {
ErrSdl(); ErrSdl();
} }
#ifndef STREAM_ALL_AUDIO #ifndef STREAM_ALL_AUDIO
@ -182,13 +180,13 @@ std::unique_ptr<TSnd> sound_file_load(const char *path, bool stream)
DWORD dwBytes = SFileGetFileSize(file); DWORD dwBytes = SFileGetFileSize(file);
auto waveFile = MakeArraySharedPtr<std::uint8_t>(dwBytes); auto waveFile = MakeArraySharedPtr<std::uint8_t>(dwBytes);
SFileReadFileThreadSafe(file, waveFile.get(), dwBytes); SFileReadFileThreadSafe(file, waveFile.get(), dwBytes);
error = snd->DSB.SetChunk(waveFile, dwBytes); int error = snd->DSB.SetChunk(waveFile, dwBytes);
SFileCloseFileThreadSafe(file); SFileCloseFileThreadSafe(file);
if (error != 0) {
ErrSdl();
}
} }
#endif #endif
if (error != 0) {
ErrSdl();
}
return snd; return snd;
} }

22
Source/stores.cpp

@ -408,7 +408,7 @@ void ScrollSmithSell(int idx)
void StartSmithSell() void StartSmithSell()
{ {
stextsize = true; stextsize = true;
bool sellok = false; bool sellOk = false;
storenumh = 0; storenumh = 0;
for (auto &item : storehold) { for (auto &item : storehold) {
@ -417,11 +417,11 @@ void StartSmithSell()
const auto &myPlayer = Players[MyPlayerId]; const auto &myPlayer = Players[MyPlayerId];
for (int i = 0; i < myPlayer._pNumInv; i++) { for (int8_t i = 0; i < myPlayer._pNumInv; i++) {
if (storenumh >= 48) if (storenumh >= 48)
break; break;
if (SmithSellOk(i)) { if (SmithSellOk(i)) {
sellok = true; sellOk = true;
storehold[storenumh] = myPlayer.InvList[i]; storehold[storenumh] = myPlayer.InvList[i];
if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified) if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified)
@ -438,7 +438,7 @@ void StartSmithSell()
if (storenumh >= 48) if (storenumh >= 48)
break; break;
if (SmithSellOk(-(i + 1))) { if (SmithSellOk(-(i + 1))) {
sellok = true; sellOk = true;
storehold[storenumh] = myPlayer.SpdList[i]; storehold[storenumh] = myPlayer.SpdList[i];
if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified) if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified)
@ -451,7 +451,7 @@ void StartSmithSell()
} }
} }
if (!sellok) { if (!sellOk) {
stextscrl = false; stextscrl = false;
/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */
@ -771,7 +771,7 @@ bool WitchRechargeOk(int i)
return false; return false;
} }
void AddStoreHoldRecharge(ItemStruct itm, int i) void AddStoreHoldRecharge(ItemStruct itm, int8_t i)
{ {
storehold[storenumh] = itm; storehold[storenumh] = itm;
storehold[storenumh]._ivalue += spelldata[itm._iSpell].sStaffCost; storehold[storenumh]._ivalue += spelldata[itm._iSpell].sStaffCost;
@ -1060,7 +1060,7 @@ bool IdItemOk(ItemStruct *i)
return !i->_iIdentified; return !i->_iIdentified;
} }
void AddStoreHoldId(ItemStruct itm, int i) void AddStoreHoldId(ItemStruct itm, int8_t i)
{ {
storehold[storenumh] = itm; storehold[storenumh] = itm;
storehold[storenumh]._ivalue = 100; storehold[storenumh]._ivalue = 100;
@ -1549,7 +1549,7 @@ void SmithRepairItem()
int idx = stextvhold + ((stextlhold - stextup) / 4); int idx = stextvhold + ((stextlhold - stextup) / 4);
storehold[idx]._iDurability = storehold[idx]._iMaxDur; storehold[idx]._iDurability = storehold[idx]._iMaxDur;
int i = storehidx[idx]; int8_t i = storehidx[idx];
if (i < 0) { if (i < 0) {
if (i == -1) if (i == -1)
@ -1709,7 +1709,7 @@ void WitchRechargeItem()
int idx = stextvhold + ((stextlhold - stextup) / 4); int idx = stextvhold + ((stextlhold - stextup) / 4);
storehold[idx]._iCharges = storehold[idx]._iMaxCharges; storehold[idx]._iCharges = storehold[idx]._iMaxCharges;
int i = storehidx[idx]; int8_t i = storehidx[idx];
if (i < 0) if (i < 0)
myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges = myPlayer.InvBody[INVLOC_HAND_LEFT]._iMaxCharges; myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges = myPlayer.InvBody[INVLOC_HAND_LEFT]._iMaxCharges;
else else
@ -1863,7 +1863,7 @@ void StorytellerIdentifyItem()
{ {
auto &myPlayer = Players[MyPlayerId]; auto &myPlayer = Players[MyPlayerId];
int idx = storehidx[((stextlhold - stextup) / 4) + stextvhold]; int8_t idx = storehidx[((stextlhold - stextup) / 4) + stextvhold];
if (idx < 0) { if (idx < 0) {
if (idx == -1) if (idx == -1)
myPlayer.InvBody[INVLOC_HEAD]._iIdentified = true; myPlayer.InvBody[INVLOC_HEAD]._iIdentified = true;
@ -2169,7 +2169,7 @@ ItemStruct witchitem[WITCH_ITEMS];
int boylevel; int boylevel;
ItemStruct boyitem; ItemStruct boyitem;
void AddStoreHoldRepair(ItemStruct *itm, int i) void AddStoreHoldRepair(ItemStruct *itm, int8_t i)
{ {
ItemStruct *item; ItemStruct *item;
int v; int v;

2
Source/stores.h

@ -94,7 +94,7 @@ extern int boylevel;
/** Current item sold by Wirt */ /** Current item sold by Wirt */
extern ItemStruct boyitem; extern ItemStruct boyitem;
void AddStoreHoldRepair(ItemStruct *itm, int i); void AddStoreHoldRepair(ItemStruct *itm, int8_t i);
void InitStores(); void InitStores();
void SetupTownStores(); void SetupTownStores();
void FreeStoreMem(); void FreeStoreMem();

12
Source/utils/soundsample.cpp

@ -74,7 +74,7 @@ void SoundSample::Release()
file_data_ = nullptr; file_data_ = nullptr;
file_data_size_ = 0; file_data_size_ = 0;
#endif #endif
}; }
/** /**
* @brief Check if a the sound is being played atm * @brief Check if a the sound is being played atm
@ -82,7 +82,7 @@ void SoundSample::Release()
bool SoundSample::IsPlaying() bool SoundSample::IsPlaying()
{ {
return stream_ && stream_->isPlaying(); return stream_ && stream_->isPlaying();
}; }
/** /**
* @brief Start playing the sound * @brief Start playing the sound
@ -103,7 +103,7 @@ void SoundSample::Play(int logSoundVolume, int logUserVolume, int logPan)
LogError(LogCategory::Audio, "Aulib::Stream::play (from SoundSample::Play): {}", SDL_GetError()); LogError(LogCategory::Audio, "Aulib::Stream::play (from SoundSample::Play): {}", SDL_GetError());
return; return;
} }
}; }
/** /**
* @brief Stop playing the sound * @brief Stop playing the sound
@ -112,7 +112,7 @@ void SoundSample::Stop()
{ {
if (stream_) if (stream_)
stream_->stop(); stream_->stop();
}; }
int SoundSample::SetChunkStream(std::string filePath) int SoundSample::SetChunkStream(std::string filePath)
{ {
@ -153,7 +153,7 @@ int SoundSample::SetChunk(ArraySharedPtr<std::uint8_t> fileData, std::size_t dwB
} }
return 0; return 0;
}; }
#endif #endif
/** /**
@ -164,6 +164,6 @@ int SoundSample::GetLength() const
if (!stream_) if (!stream_)
return 0; return 0;
return std::chrono::duration_cast<std::chrono::milliseconds>(stream_->duration()).count(); return std::chrono::duration_cast<std::chrono::milliseconds>(stream_->duration()).count();
}; }
} // namespace devilution } // namespace devilution

Loading…
Cancel
Save