Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

None #562

Merged
merged 2 commits into from
Nov 12, 2023
Merged

None #562

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: 13 additions & 13 deletions src/editor/editloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ enum class EditorActionType {
};

enum EditorOverlays {
cNone,
cUnpassable,
cNoBuildingAllowed,
cElevation,
cOpaque
NoOverlays,
Unpassable,
NoBuildingAllowed,
Elevation,
Opaque
};
struct EditorAction {
EditorActionType Type;
Expand Down Expand Up @@ -851,7 +851,7 @@ static void DrawIntoButtonArea()

static void DrawInfoHighlightedOverlay()
{
if (overlaysDropdown->getSelected() == EditorOverlays::cElevation) {
if (overlaysDropdown->getSelected() == EditorOverlays::Elevation) {
CLabel(GetGameFont())
.Draw(overlaysDropdown->getX() + overlaysDropdown->getWidth() + 5,
2,
Expand Down Expand Up @@ -1548,13 +1548,13 @@ static void EditorCallbackKeyDown(unsigned key, unsigned keychar)
}
break;
case ']': /// Increace highlighted elevation level
if (overlaysDropdown->getSelected() == EditorOverlays::cElevation
if (overlaysDropdown->getSelected() == EditorOverlays::Elevation
&& Editor.HighlightElevationLevel < 255) {
Editor.HighlightElevationLevel++;
}
break;
case '[': /// Decreace highlighted elevation level
if (overlaysDropdown->getSelected() == EditorOverlays::cElevation
if (overlaysDropdown->getSelected() == EditorOverlays::Elevation
&& Editor.HighlightElevationLevel > 0) {
Editor.HighlightElevationLevel--;
}
Expand Down Expand Up @@ -2153,20 +2153,20 @@ void EditorMainLoop()
auto overlaysDropdownListener = std::make_unique<LambdaActionListener>([&overlaysListStrings](const std::string&) {
const int selected = overlaysDropdown->getSelected();
switch (selected) {
case EditorOverlays::cNone:
case EditorOverlays::NoOverlays:
Editor.OverlayHighlighter = nullptr;
return;
case EditorOverlays::cUnpassable:
case EditorOverlays::Unpassable:
Editor.OverlayHighlighter = OverlayUnpassable;
return;
case EditorOverlays::cNoBuildingAllowed:
case EditorOverlays::NoBuildingAllowed:
Editor.OverlayHighlighter = OverlayNoBuildingAllowed;
return;
case EditorOverlays::cElevation:
case EditorOverlays::Elevation:
Editor.HighlightElevationLevel = 1;
Editor.OverlayHighlighter = OverlayElevation;
return;
case EditorOverlays::cOpaque:
case EditorOverlays::Opaque:
Editor.OverlayHighlighter = OverlayOpaque;
return;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/game/replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ static int CclReplayLog(lua_State *l)
*/
bool IsReplayGame()
{
return ReplayGameType != EReplayType::None;
return ReplayGameType != EReplayType::NoReplay;
}

/**
Expand Down Expand Up @@ -632,7 +632,7 @@ void CleanReplayLog()
// }
GameObserve = false;
NetPlayers = 0;
ReplayGameType = EReplayType::None;
ReplayGameType = EReplayType::NoReplay;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/include/missile.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
**
** Class of the missile-type, defines the basic effects of the
** missile. Look at the different class identifiers for more
** information (::MissileClass::None, ...).
** information (::MissileClass::Nothing, ...).
**
** MissileType::NumBounces
**
Expand Down Expand Up @@ -323,7 +323,7 @@ class LuaCallback;
*/
enum class MissileClass
{
None, /// Missile does nothing
Nothing, /// Missile does nothing
PointToPoint, /// Missile flies from x,y to x1,y1
PointToPointWithHit, /// Missile flies from x,y to x1,y1 then shows hit animation.
PointToPointCycleOnce, /// Missile flies from x,y to x1,y1 and animates ONCE from start to finish and back
Expand Down Expand Up @@ -384,7 +384,7 @@ class MissileType
bool IgnoreWalls = true; /// missile ignores Wall units on it's way
bool KillFirstUnit = false; /// missile kills first unit blocking it's way

MissileClass Class = MissileClass::None; /// missile class
MissileClass Class = MissileClass::Nothing; /// missile class
int NumBounces = 0; /// number of bounces
int ParabolCoefficient = 2048; /// parabol coefficient in parabolic missile
int StartDelay = 0; /// missile start delay
Expand Down
2 changes: 1 addition & 1 deletion src/include/replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
----------------------------------------------------------------------------*/

enum class EReplayType {
None, /// No replay
NoReplay, /// No replay
SinglePlayer, /// Single player replay
MultiPlayer /// Multi player replay
}; /// Replay types
Expand Down
4 changes: 2 additions & 2 deletions src/include/tileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,11 @@ class CTilesetGraphicGenerator
return image;
}
private:
enum class SrcImageOption { cNone = 0, cBaseGraphics = 1, cNewGraphics = 2 };
enum class ESrcImageOption { NoGraphics = 0, BaseGraphics = 1, NewGraphics = 2 };

private:
uint16_t checkForLayers(lua_State *luaStack) const;
std::vector<tile_index> parseSrcRange(lua_State *luaStack, SrcImageOption &isImg) const;
std::vector<tile_index> parseSrcRange(lua_State *luaStack, ESrcImageOption &isImg) const;
auto parseLayer(lua_State *luaStack, const bool isSingleLayer = false) const;
std::set<uint32_t> parseArgsAsColors(lua_State *luaStack, const int firstArgPos = 2) const;
uint32_t getPixel(const void *const pixel, const uint8_t bpp) const;
Expand Down
11 changes: 4 additions & 7 deletions src/include/unittype.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
#include <algorithm>
#include <map>

// Fix problems with defined None in X.h included though SDL.h
#undef None

/*----------------------------------------------------------------------------
-- Declarations
----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -512,7 +509,7 @@ class CBuildRestrictionLuaCallback : public CBuildRestriction

enum class EMouseAction
{
None = 0, /// Nothing
NoAction = 0, /// Nothing
Attack = 1, /// Attack
Move = 2, /// Move
Harvest = 3, /// Harvest resources
Expand All @@ -522,7 +519,7 @@ enum class EMouseAction

enum class ECanTargetFlag
{
None = 0,
NulFlag = 0,
Land = 1, /// Can attack land units
Sea = 2, /// Can attack sea units
Air = 4, /// Can attack air units
Expand Down Expand Up @@ -659,9 +656,9 @@ class CUnitType
// TODO: not used
int AnnoyComputerFactor = 0; /// How much this annoys the computer
int AiAdjacentRange = -1; /// Min radius for AI build surroundings checking
EMouseAction MouseAction = EMouseAction::None; /// Right click action
EMouseAction MouseAction = EMouseAction::NoAction; /// Right click action
uint8_t RotationSpeed = 128; /// Max unit.Direction change per frame. 128 is maximum
ECanTargetFlag CanTarget = ECanTargetFlag::None; /// Which units can it attack
ECanTargetFlag CanTarget = ECanTargetFlag::NulFlag; /// Which units can it attack

bool Flip = false; /// Flip image when facing left
bool LandUnit = false; /// Land animated
Expand Down
37 changes: 17 additions & 20 deletions src/map/script_tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,28 +769,29 @@ uint16_t CTilesetGraphicGenerator::checkForLayers(lua_State *luaStack) const
** @param isImg if 'img' tag is exist then it will be setted by this function to true, false otherwise
** @return vector of parsed indexes
**/
std::vector<tile_index> CTilesetGraphicGenerator::parseSrcRange(lua_State *luaStack, SrcImageOption &isImg) const
std::vector<tile_index> CTilesetGraphicGenerator::parseSrcRange(lua_State *luaStack, ESrcImageOption &isImg) const
{
isImg = SrcImageOption::cNone;
isImg = ESrcImageOption::NoGraphics;

if (lua_istable(luaStack, -1)) {

lua_rawgeti(luaStack, -1, 1); /// #1<
lua_rawgeti(luaStack, -1, 1); /// #1<
/// check if "img"/"img-base" tag is present
if (lua_isstring_strict(luaStack, -1)) {
const std::string parsingValue { LuaToString(luaStack, -1) };
const auto parsingValue = LuaToString(luaStack, -1);
if (parsingValue == "img") {
isImg = SrcImageOption::cNewGraphics;
isImg = ESrcImageOption::NewGraphics;
} else if (parsingValue == "img-base") {
isImg = SrcImageOption::cBaseGraphics;
isImg = ESrcImageOption::BaseGraphics;
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi.
This else shouldn't be here.
Here we just check if first string (and if it is a string) is "img" or "img-base" to select image source, if not - it's not an error, because there is another options and they will be parsed in the CTilesetParser::parseTilesRange().

Now we have spammed output with stratagus/src/map/script_tileset.cpp:786: parseSrcRange: Unknown tag 'slot' msg - and "slot" here is an acceptable value. *It spammed in the "highground" branch of wargus

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just created #566 to revert that.

ErrorPrint("Unknown tag '%s'", parsingValue.data());
}
}
lua_pop(luaStack, 1); /// #1>
lua_pop(luaStack, 1); /// #1>
} else if (!lua_isnumber(luaStack, -1)) {
LuaError(luaStack, "incorrect argument");
}

return { CTilesetParser::parseTilesRange(luaStack, isImg != SrcImageOption::cNone ? 2 : 1) };
return { CTilesetParser::parseTilesRange(luaStack, isImg != ESrcImageOption::NoGraphics ? 2 : 1) };
}

/**
Expand Down Expand Up @@ -822,36 +823,32 @@ auto CTilesetGraphicGenerator::parseLayer(lua_State *luaStack, const bool isSing
}
}

SrcImageOption isImg = SrcImageOption::cNone;
ESrcImageOption isImg = ESrcImageOption::NoGraphics;
std::vector<tile_index> srcIndexes { parseSrcRange(luaStack, isImg) };

if (needToPopSrcBack) {
lua_pop(luaStack, 1); /// #1>
}

const bool isUntouchedSrcGraphicsOnly = (isSingleLayer /* there is an only layer */
&& isImg != SrcImageOption::cNewGraphics /* this leyer consist of indexes of base graphics */
&& !withModifier) /* there are no any modifiers */
? true
: false;
const bool isUntouchedSrcGraphicsOnly =
isSingleLayer && isImg != ESrcImageOption::NewGraphics && !withModifier;

std::vector<graphic_index> parsedIndexes;
sequence_of_images parsedImages;

for (auto const srcIndex : srcIndexes) {
if (isImg == SrcImageOption::cNone
if (isImg == ESrcImageOption::NoGraphics
&& (srcIndex == 0 || SrcTileset->tiles[srcIndex].tile == 0)) { /// empty frame|separator
parsedIndexes.push_back(0);
continue;
}
const graphic_index frameIdx =
isImg != SrcImageOption::cNone ? srcIndex : SrcTileset->tiles[srcIndex].tile;
isImg != ESrcImageOption::NoGraphics ? srcIndex : SrcTileset->tiles[srcIndex].tile;
if (isUntouchedSrcGraphicsOnly) {
parsedIndexes.push_back(frameIdx);

} else {
const CGraphic *srcGraphic = isImg == SrcImageOption::cNewGraphics ? SrcImgGraphic
: SrcTilesetGraphic;
const CGraphic *srcGraphic =
isImg == ESrcImageOption::NewGraphics ? SrcImgGraphic : SrcTilesetGraphic;
auto image { newBlankImage() };
srcGraphic->DrawFrame(frameIdx, 0, 0, image.get());
parsedImages.push_back(std::move(image));
Expand Down
4 changes: 2 additions & 2 deletions src/missile/missile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Missile::Init(const MissileType &mtype, const PixelPos &startPos, const PixelPos
std::unique_ptr<Missile> missile;

switch (mtype.Class) {
case MissileClass::None: missile = std::make_unique<MissileNone>(); break;
case MissileClass::Nothing: missile = std::make_unique<MissileNone>(); break;
case MissileClass::PointToPoint: missile = std::make_unique<MissilePointToPoint>(); break;
case MissileClass::PointToPointWithHit: missile = std::make_unique<MissilePointToPointWithHit>(); break;
case MissileClass::PointToPointCycleOnce: missile = std::make_unique<MissilePointToPointCycleOnce>(); break;
Expand Down Expand Up @@ -318,7 +318,7 @@ void FireMissile(CUnit &unit, CUnit *goal, const Vec2i &goalPos)

// No missile hits immediately!
if (
unit.Type->Missile.Missile->Class == MissileClass::None
unit.Type->Missile.Missile->Class == MissileClass::Nothing
|| (unit.Type->Animations && unit.Type->Animations->Attack && unit.Type->Animations->RangedAttack && !unit.IsAttackRanged(goal, goalPos)) // treat melee attacks from units that have both attack and ranged attack animations as having missile class none
) {
// No goal, take target coordinates
Expand Down
2 changes: 1 addition & 1 deletion src/missile/script_missile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static const std::map<std::string_view, MissileClass> MissileClassNames = {
{"missile-class-flame-shield", MissileClass::FlameShield},
{"missile-class-hit", MissileClass::Hit},
{"missile-class-land-mine", MissileClass::LandMine},
{"missile-class-none", MissileClass::None},
{"missile-class-none", MissileClass::Nothing},
{"missile-class-parabolic", MissileClass::Parabolic},
{"missile-class-point-to-point", MissileClass::PointToPoint},
{"missile-class-point-to-point-bounce", MissileClass::PointToPointBounce},
Expand Down
2 changes: 1 addition & 1 deletion src/ui/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ static void InputKey(int key)
#ifdef DEBUG
if (starts_with(Input, "ffw ")) {
#else
if (starts_with(Input, "ffw ") && ReplayGameType != EReplayType::None) {
if (starts_with(Input, "ffw ") && ReplayGameType != EReplayType::NoReplay) {
#endif
FastForwardCycle = atoi(&Input[4]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/unit/script_unittype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static void UpdateDefaultBoolFlags(CUnitType &type)
static std::optional<EMouseAction> ToEMouseAction(std::string_view s)
{
if (s == "none") {
return EMouseAction::None;
return EMouseAction::NoAction;
} else if (s == "attack") {
return EMouseAction::Attack;
} else if (s == "move") {
Expand Down
8 changes: 4 additions & 4 deletions src/unit/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3260,17 +3260,17 @@ bool CanTarget(const CUnitType &source, const CUnitType &dest)
{
if (dest.BoolFlag[SHOREBUILDING_INDEX].value) {
return (source.CanTarget & (ECanTargetFlag::Land | ECanTargetFlag::Sea))
!= ECanTargetFlag::None;
!= ECanTargetFlag::NulFlag;
}
return (source.CanTarget & ECanTargetFlag::Land) != ECanTargetFlag::None;
return (source.CanTarget & ECanTargetFlag::Land) != ECanTargetFlag::NulFlag;
}
case EMovement::Fly:
{
return (source.CanTarget & ECanTargetFlag::Air) != ECanTargetFlag::None;
return (source.CanTarget & ECanTargetFlag::Air) != ECanTargetFlag::NulFlag;
}
case EMovement::Naval:
{
return (source.CanTarget & ECanTargetFlag::Sea) != ECanTargetFlag::None;
return (source.CanTarget & ECanTargetFlag::Sea) != ECanTargetFlag::NulFlag;
}
default: return 0;
}
Expand Down