Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions Source/automap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <algorithm>
#include <cstdint>

#include <fmt/format.h>

Check warning on line 11 in Source/automap.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/automap.cpp:11:1 [misc-include-cleaner]

included header format.h is not used directly

#include "control/control.hpp"
#include "engine/load_file.hpp"
Expand All @@ -24,7 +24,7 @@
#include "utils/is_of.hpp"
#include "utils/language.h"
#include "utils/ui_fwd.h"
#include "utils/utf8.hpp"

Check warning on line 27 in Source/automap.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/automap.cpp:27:1 [misc-include-cleaner]

included header utf8.hpp is not used directly

#ifdef _DEBUG
#include "debug.h"
Expand All @@ -34,7 +34,7 @@
namespace devilution {

namespace {
Point Automap;

Check warning on line 37 in Source/automap.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/automap.cpp:37:1 [misc-include-cleaner]

no header providing "devilution::Point" is directly included

enum MapColors : uint8_t {
/** color used to draw the player's arrow */
Expand Down Expand Up @@ -160,12 +160,12 @@
/**
* Maps from tile_id to automap type.
*/
std::array<AutomapTile, 256> AutomapTypeTiles;

Check warning on line 163 in Source/automap.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/automap.cpp:163:6 [misc-include-cleaner]

no header providing "std::array" is directly included

/**
* @brief Draw a diamond on top tile.
*/
void DrawDiamond(const Surface &out, Point center, uint8_t color)

Check warning on line 168 in Source/automap.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/automap.cpp:168:24 [misc-include-cleaner]

no header providing "devilution::Surface" is directly included
{
DrawMapLineNE(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileUp), AmLine(AmLineLength::FullTile), color);
DrawMapLineSE(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileUp), AmLine(AmLineLength::FullTile), color);
Expand All @@ -185,8 +185,8 @@
AmLineLength length;

switch (leveltype) {
case DTYPE_CATHEDRAL:

Check warning on line 188 in Source/automap.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/automap.cpp:188:7 [misc-include-cleaner]

no header providing "devilution::DTYPE_CATHEDRAL" is directly included
case DTYPE_CRYPT:

Check warning on line 189 in Source/automap.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/automap.cpp:189:7 [misc-include-cleaner]

no header providing "devilution::DTYPE_CRYPT" is directly included
lWidthOffset = AmWidthOffset::QuarterTileLeft;
lHeightOffset = AmHeightOffset::QuarterTileUp;

Expand All @@ -195,7 +195,7 @@

length = AmLineLength::HalfTile;
break;
case DTYPE_CATACOMBS:

Check warning on line 198 in Source/automap.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/automap.cpp:198:7 [misc-include-cleaner]

no header providing "devilution::DTYPE_CATACOMBS" is directly included
lWidthOffset = AmWidthOffset::ThreeQuartersTileLeft;
lHeightOffset = AmHeightOffset::QuarterTileDown;

Expand All @@ -204,7 +204,7 @@

length = AmLineLength::FullTile;
break;
case DTYPE_CAVES:

Check warning on line 207 in Source/automap.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/automap.cpp:207:7 [misc-include-cleaner]

no header providing "devilution::DTYPE_CAVES" is directly included
lWidthOffset = AmWidthOffset::QuarterTileLeft;
lHeightOffset = AmHeightOffset::ThreeQuartersTileDown;

Expand All @@ -214,7 +214,7 @@
length = AmLineLength::FullTile;
break;
default:
app_fatal("Invalid leveltype");

Check warning on line 217 in Source/automap.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/automap.cpp:217:3 [misc-include-cleaner]

no header providing "devilution::app_fatal" is directly included
}
if (!(neTile.hasFlag(AutomapTile::Flags::VerticalPassage) && leveltype == DTYPE_CATHEDRAL))
DrawMapLineNE(out, center + AmOffset(lWidthOffset, lHeightOffset), AmLine(length), colorDim);
Expand Down Expand Up @@ -1257,7 +1257,7 @@
{
Displacement screen = {};

if (GetAutomapType() == AutomapType::Minimap) {
if (IsMinimapAutomapType()) {
screen = {
MinimapRect.position.x + MinimapRect.size.width / 2,
MinimapRect.position.y + MinimapRect.size.height / 2
Expand Down Expand Up @@ -1291,7 +1291,7 @@
const int endY = std::clamp(tile.y + searchRadius, 0, MAXDUNY);

const AutomapType mapType = GetAutomapType();
const int scale = (mapType == AutomapType::Minimap) ? MinimapScale : AutoMapScale;
const int scale = IsMinimapAutomapType(mapType) ? MinimapScale : AutoMapScale;

for (int i = startX; i < endX; i++) {
for (int j = startY; j < endY; j++) {
Expand All @@ -1308,7 +1308,7 @@

screen += GetAutomapScreen();

if (mapType != AutomapType::Minimap && CanPanelsCoverView()) {
if (!IsMinimapAutomapType(mapType) && CanPanelsCoverView()) {
if (IsRightPanelOpen())
screen.x -= gnScreenWidth / 4;
if (IsLeftPanelOpen())
Expand Down Expand Up @@ -1352,7 +1352,7 @@
if (player.isWalking())
playerOffset = GetOffsetForWalking(player.AnimInfo, player._pdir);

const int scale = (GetAutomapType() == AutomapType::Minimap) ? MinimapScale : AutoMapScale;
const int scale = IsMinimapAutomapType() ? MinimapScale : AutoMapScale;

Point base = {
((playerOffset.deltaX + myPlayerOffset.deltaX) * scale / 100 / 2) + (px - py) * AmLine(AmLineLength::DoubleTile),
Expand Down Expand Up @@ -1547,7 +1547,6 @@
} // namespace

bool AutomapActive;
AutomapType CurrentAutomapType = AutomapType::Opaque;
uint8_t AutomapView[DMAXX][DMAXY];
int AutoMapScale;
int MinimapScale;
Expand All @@ -1557,6 +1556,7 @@
void InitAutomapOnce()
{
AutomapActive = false;
SetAutomapType(*GetOptions().Gameplay.automapType);
AutoMapScale = 50;

// Set the dimensions and screen position of the minimap relative to the screen dimensions
Expand All @@ -1577,6 +1577,16 @@
}
}

void SetAutomapType(AutomapType type)
{
GetOptions().Gameplay.automapType.SetValue(type);
}

AutomapType GetAutomapType()
{
return *GetOptions().Gameplay.automapType;
}

void InitAutomap()
{
size_t tileCount = 0;
Expand Down Expand Up @@ -1732,7 +1742,7 @@

void AutomapZoomIn()
{
int &scale = (GetAutomapType() == AutomapType::Minimap) ? MinimapScale : AutoMapScale;
int &scale = IsMinimapAutomapType() ? MinimapScale : AutoMapScale;

if (scale >= 200)
return;
Expand All @@ -1742,7 +1752,7 @@

void AutomapZoomOut()
{
int &scale = (GetAutomapType() == AutomapType::Minimap) ? MinimapScale : AutoMapScale;
int &scale = IsMinimapAutomapType() ? MinimapScale : AutoMapScale;

if (scale <= 25)
return;
Expand Down Expand Up @@ -1773,7 +1783,7 @@
if (myPlayer.isWalking())
myPlayerOffset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true);

const int scale = (GetAutomapType() == AutomapType::Minimap) ? MinimapScale : AutoMapScale;
const int scale = IsMinimapAutomapType() ? MinimapScale : AutoMapScale;
const int d = (scale * 64) / 100;
int cells = 2 * (gnScreenWidth / 2 / d) + 1;
if (((gnScreenWidth / 2) % d) != 0)
Expand Down
24 changes: 10 additions & 14 deletions Source/automap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "engine/surface.hpp"
#include "levels/gendung.h"
#include "utils/attributes.h"
#include "utils/is_of.hpp"

namespace devilution {

Expand Down Expand Up @@ -85,37 +86,32 @@ enum class AutomapType : uint8_t {
FIRST = Opaque,
Transparent,
Minimap,
LAST = Minimap
MinimapBorderless,
LAST = MinimapBorderless
};

extern DVL_API_FOR_TEST AutomapType CurrentAutomapType;
AutomapType GetAutomapType();

/**
* @brief Sets the map type. Does not change `AutomapActive`.
*/
inline void SetAutomapType(AutomapType type)
inline bool IsMinimapAutomapType(AutomapType type)
{
CurrentAutomapType = type;
return IsAnyOf(type, AutomapType::Minimap, AutomapType::MinimapBorderless);
}

/**
* @brief Sets the map type. Does not change `AutomapActive`.
*/
inline AutomapType GetAutomapType()
inline bool IsMinimapAutomapType()
{
return CurrentAutomapType;
return IsMinimapAutomapType(GetAutomapType());
}

inline Displacement AmOffset(AmWidthOffset x, AmHeightOffset y)
{
int scale = (GetAutomapType() == AutomapType::Minimap) ? MinimapScale : AutoMapScale;
int scale = IsMinimapAutomapType() ? MinimapScale : AutoMapScale;

return { scale * static_cast<int>(x) / 100, scale * static_cast<int>(y) / 100 };
}

inline int AmLine(AmLineLength l)
{
int scale = (GetAutomapType() == AutomapType::Minimap) ? MinimapScale : AutoMapScale;
int scale = IsMinimapAutomapType() ? MinimapScale : AutoMapScale;

return scale * static_cast<int>(l) / 100;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/control/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ void CycleAutomapType()
}
const AutomapType newType { static_cast<std::underlying_type_t<AutomapType>>(
(static_cast<unsigned>(GetAutomapType()) + 1) % enum_size<AutomapType>::value) };
SetAutomapType(newType);
GetOptions().Gameplay.automapType.SetValue(newType);
if (newType == AutomapType::FIRST) {
AutomapActive = false;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ void InitKeymapActions()
options.Keymapper.AddAction(
"CycleAutomapType",
N_("Cycle map type"),
N_("Opaque -> Transparent -> Minimap -> None"),
N_("Opaque -> Transparent -> Minimap -> Borderless Minimap -> None"),
SDLK_M,
CycleAutomapType,
nullptr,
Expand Down
2 changes: 1 addition & 1 deletion Source/engine/render/automap_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void DrawMapFreeLine(const Surface &out, Point from, Point to, uint8_t colorInde

void SetMapPixel(const Surface &out, Point position, uint8_t color)
{
if (GetAutomapType() == AutomapType::Minimap && !MinimapRect.contains(position))
if (IsMinimapAutomapType() && !MinimapRect.contains(position))
return;

if (GetAutomapType() == AutomapType::Transparent) {
Expand Down
8 changes: 8 additions & 0 deletions Source/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,13 @@ GameplayOptions::GameplayOptions()
, autoRefillBelt("Auto Refill Belt", OptionEntryFlags::None, N_("Auto Refill Belt"), N_("Refill belt from inventory when belt item is consumed."), false)
, disableCripplingShrines("Disable Crippling Shrines", OptionEntryFlags::None, N_("Disable Crippling Shrines"), N_("When enabled Cauldrons, Fascinating Shrines, Goat Shrines, Ornate Shrines, Sacred Shrines and Murphy's Shrines are not able to be clicked on and labeled as disabled."), false)
, quickCast("Quick Cast", OptionEntryFlags::None, N_("Quick Cast"), N_("Spell hotkeys instantly cast the spell, rather than switching the readied spell."), false)
, automapType("Automap Type", OptionEntryFlags::None, N_("Automap Type"), N_("Default automap type used when loading a game."), AutomapType::Opaque,
{
{ AutomapType::Opaque, N_("Opaque") },
{ AutomapType::Transparent, N_("Transparent") },
{ AutomapType::Minimap, N_("Minimap") },
{ AutomapType::MinimapBorderless, N_("Minimap Borderless") },
})
, numHealPotionPickup("Heal Potion Pickup", OptionEntryFlags::None, N_("Heal Potion Pickup"), N_("Number of Healing potions to pick up automatically."), 0, { 0, 1, 2, 4, 8, 16 })
, numFullHealPotionPickup("Full Heal Potion Pickup", OptionEntryFlags::None, N_("Full Heal Potion Pickup"), N_("Number of Full Healing potions to pick up automatically."), 0, { 0, 1, 2, 4, 8, 16 })
, numManaPotionPickup("Mana Potion Pickup", OptionEntryFlags::None, N_("Mana Potion Pickup"), N_("Number of Mana potions to pick up automatically."), 0, { 0, 1, 2, 4, 8, 16 })
Expand Down Expand Up @@ -916,6 +923,7 @@ std::vector<OptionEntryBase *> GameplayOptions::GetEntries()
&disableCripplingShrines,
&grabInput,
&pauseOnFocusLoss,
&automapType,
&skipLoadingScreenThresholdMs,
};
}
Expand Down
3 changes: 3 additions & 0 deletions Source/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <ankerl/unordered_dense.h>
#include <function_ref.hpp>

#include "automap.h"
#include "appfat.h"
#include "controls/controller_buttons.h"
#include "engine/size.hpp"
Expand Down Expand Up @@ -623,6 +624,8 @@ struct GameplayOptions : OptionCategoryBase {
OptionEntryBoolean disableCripplingShrines;
/** @brief Spell hotkeys instantly cast the spell. */
OptionEntryBoolean quickCast;
/** @brief Default automap type to use when loading a game. */
OptionEntryEnum<AutomapType> automapType;
/** @brief Number of Healing potions to pick up automatically */
OptionEntryInt<int> numHealPotionPickup;
/** @brief Number of Full Healing potions to pick up automatically */
Expand Down
Loading