Browse Source

🎨 Fix line endings in Source/qol/*

pull/1809/head
Gleb Mazovetskiy 5 years ago committed by Anders Jenbo
parent
commit
8257837801
  1. 122
      Source/qol/autopickup.cpp
  2. 26
      Source/qol/autopickup.h
  3. 124
      Source/qol/common.cpp
  4. 104
      Source/qol/common.h

122
Source/qol/autopickup.cpp

@ -1,61 +1,61 @@
/** /**
* @file autopickup.cpp * @file autopickup.cpp
* *
* QoL feature for automatically picking up gold * QoL feature for automatically picking up gold
*/ */
#include "options.h" #include "options.h"
#include "player.h" #include "player.h"
namespace devilution { namespace devilution {
namespace { namespace {
bool HasRoomForGold() bool HasRoomForGold()
{ {
for (int idx : plr[myplr].InvGrid) { for (int idx : plr[myplr].InvGrid) {
// Secondary item cell. No need to check those as we'll go through the main item cells anyway. // Secondary item cell. No need to check those as we'll go through the main item cells anyway.
if (idx < 0) if (idx < 0)
continue; continue;
// Empty cell. 1x1 space available. // Empty cell. 1x1 space available.
if (idx == 0) if (idx == 0)
return true; return true;
// Main item cell. Potentially a gold pile so check it. // Main item cell. Potentially a gold pile so check it.
auto item = plr[myplr].InvList[idx - 1]; auto item = plr[myplr].InvList[idx - 1];
if (item._itype == ITYPE_GOLD && item._ivalue < MaxGold) if (item._itype == ITYPE_GOLD && item._ivalue < MaxGold)
return true; return true;
} }
return false; return false;
} }
} // namespace } // namespace
void AutoGoldPickup(int pnum) void AutoGoldPickup(int pnum)
{ {
if (!sgOptions.Gameplay.bAutoGoldPickup) if (!sgOptions.Gameplay.bAutoGoldPickup)
return; return;
if (pnum != myplr) if (pnum != myplr)
return; return;
if (leveltype == DTYPE_TOWN) if (leveltype == DTYPE_TOWN)
return; return;
if (!HasRoomForGold()) if (!HasRoomForGold())
return; return;
for (int dir = 0; dir < 8; dir++) { for (int dir = 0; dir < 8; dir++) {
int x = plr[pnum].position.tile.x + pathxdir[dir]; int x = plr[pnum].position.tile.x + pathxdir[dir];
int y = plr[pnum].position.tile.y + pathydir[dir]; int y = plr[pnum].position.tile.y + pathydir[dir];
if (dItem[x][y] != 0) { if (dItem[x][y] != 0) {
int itemIndex = dItem[x][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;
PlaySFX(IS_IGRAB); PlaySFX(IS_IGRAB);
} }
} }
} }
} }
} // namespace devilution } // namespace devilution

26
Source/qol/autopickup.h

@ -1,13 +1,13 @@
/** /**
* @file autopickup.h * @file autopickup.h
* *
* QoL feature for automatically picking up gold * QoL feature for automatically picking up gold
*/ */
#pragma once #pragma once
namespace devilution { namespace devilution {
void AutoGoldPickup(int pnum); void AutoGoldPickup(int pnum);
} // namespace devilution } // namespace devilution

124
Source/qol/common.cpp

@ -1,62 +1,62 @@
/** /**
* @file common.h * @file common.h
* *
* Common functions for QoL features * Common functions for QoL features
*/ */
#include <SDL.h> #include <SDL.h>
#include "common.h" #include "common.h"
#include "control.h" #include "control.h"
#include "engine.h" #include "engine.h"
#include "qol/monhealthbar.h" #include "qol/monhealthbar.h"
#include "qol/xpbar.h" #include "qol/xpbar.h"
namespace devilution { namespace devilution {
int GetTextWidth(const char *s) int GetTextWidth(const char *s)
{ {
int l = 0; int l = 0;
while (*s) { while (*s) {
l += fontkern[fontframe[gbFontTransTbl[static_cast<BYTE>(*s++)]]] + 1; l += fontkern[fontframe[gbFontTransTbl[static_cast<BYTE>(*s++)]]] + 1;
} }
return l; return l;
} }
void FastDrawHorizLine(const CelOutputBuffer &out, int x, int y, int width, Uint8 col) void FastDrawHorizLine(const CelOutputBuffer &out, int x, int y, int width, Uint8 col)
{ {
memset(out.at(x, y), col, width); memset(out.at(x, y), col, width);
} }
void FastDrawVertLine(const CelOutputBuffer &out, int x, int y, int height, Uint8 col) void FastDrawVertLine(const CelOutputBuffer &out, int x, int y, int height, Uint8 col)
{ {
BYTE *p = out.at(x, y); BYTE *p = out.at(x, y);
for (int j = 0; j < height; j++) { for (int j = 0; j < height; j++) {
*p = col; *p = col;
p += out.pitch(); p += out.pitch();
} }
} }
char *PrintWithSeparator(char *out, long long n) char *PrintWithSeparator(char *out, long long n)
{ {
if (n < 1000) { if (n < 1000) {
return out + sprintf(out, "%lld", n); return out + sprintf(out, "%lld", n);
} }
char *append = PrintWithSeparator(out, n / 1000); char *append = PrintWithSeparator(out, n / 1000);
return append + sprintf(append, ",%03lld", n % 1000); return append + sprintf(append, ",%03lld", n % 1000);
} }
void FreeQol() void FreeQol()
{ {
FreeMonsterHealthBar(); FreeMonsterHealthBar();
FreeXPBar(); FreeXPBar();
} }
void InitQol() void InitQol()
{ {
InitMonsterHealthBar(); InitMonsterHealthBar();
InitXPBar(); InitXPBar();
} }
} // namespace devilution } // namespace devilution

104
Source/qol/common.h

@ -1,52 +1,52 @@
/** /**
* @file common.h * @file common.h
* *
* Common functions for QoL features * Common functions for QoL features
*/ */
#pragma once #pragma once
#include <SDL.h> #include <SDL.h>
namespace devilution { namespace devilution {
struct CelOutputBuffer; struct CelOutputBuffer;
/** /**
* @brief Return width (in pixels) of the passed in string, when printed with smaltext.cel. Does not consider line breaks. * @brief Return width (in pixels) of the passed in string, when printed with smaltext.cel. Does not consider line breaks.
* @param s String for which to compute width * @param s String for which to compute width
* @return Pixel width of the string * @return Pixel width of the string
*/ */
int GetTextWidth(const char *s); int GetTextWidth(const char *s);
/** /**
* @brief Quickly draw a horizontal line (via memset). Does not clip to output buffer. * @brief Quickly draw a horizontal line (via memset). Does not clip to output buffer.
* @param out Destination buffer * @param out Destination buffer
* @param x Start X coordinate (left end) * @param x Start X coordinate (left end)
* @param y Vertical location of line * @param y Vertical location of line
* @param width Number of pixels to fill * @param width Number of pixels to fill
* @param col Color index to use for filling * @param col Color index to use for filling
*/ */
void FastDrawHorizLine(const CelOutputBuffer &out, int x, int y, int width, Uint8 col); void FastDrawHorizLine(const CelOutputBuffer &out, int x, int y, int width, Uint8 col);
/** /**
* @brief Quickly draw a vertical line. Does not clip to output buffer. * @brief Quickly draw a vertical line. Does not clip to output buffer.
* @param out Destination buffer * @param out Destination buffer
* @param x Horizontal location of line * @param x Horizontal location of line
* @param y Start Y coordinate (top end) * @param y Start Y coordinate (top end)
* @param height Number of pixels to fill * @param height Number of pixels to fill
* @param col Color index to use for filling * @param col Color index to use for filling
*/ */
void FastDrawVertLine(const CelOutputBuffer &out, int x, int y, int height, Uint8 col); void FastDrawVertLine(const CelOutputBuffer &out, int x, int y, int height, Uint8 col);
/** /**
* @brief Prints integer into buffer, using ',' as thousands separator. * @brief Prints integer into buffer, using ',' as thousands separator.
* @param out Destination buffer * @param out Destination buffer
* @param n Number to print * @param n Number to print
* @return Address of first character after printed number * @return Address of first character after printed number
*/ */
char *PrintWithSeparator(char *out, long long n); char *PrintWithSeparator(char *out, long long n);
void FreeQol(); void FreeQol();
void InitQol(); void InitQol();
} // namespace devilution } // namespace devilution

Loading…
Cancel
Save