From bcc96b00ede4135291e202f5b88876a109fbe8f7 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Fri, 31 Mar 2023 19:45:23 +0300 Subject: [PATCH 01/29] forced reduction of the tile index when an index beyond the slot size is requested. --- src/include/tileset.h | 1 + src/map/mapfield.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/include/tileset.h b/src/include/tileset.h index e501f3fafd..42bc2de70d 100644 --- a/src/include/tileset.h +++ b/src/include/tileset.h @@ -90,6 +90,7 @@ constexpr uint8_t MapFieldSubtilesMax {16}; constexpr uint8_t MapFieldSubtilesUnpassableShift {48}; constexpr tile_flags MapFieldSubtilesUnpassableMask {tile_flags(0xFFFF) << MapFieldSubtilesUnpassableShift}; /// Up to 16 unpassable subtiles, never used in MapField, only in CTile +constexpr tile_index ExtendedTilesetBeginIdx {0x1010}; /// the extended tiles indexes start form here /** ** These are used for lookup tiles types diff --git a/src/map/mapfield.cpp b/src/map/mapfield.cpp index 3abb05edd0..505ad014a6 100644 --- a/src/map/mapfield.cpp +++ b/src/map/mapfield.cpp @@ -84,7 +84,14 @@ bool CMapField::IsTerrainResourceOnMap() const void CMapField::setTileIndex(const CTileset &tileset, const tile_index tileIndex, const int value, const uint8_t elevation, const int subtile /* = -1 */) { - const CTile &tile = tileset.tiles[tileIndex]; + uint8_t compShift = 0; // [0..F] in case then current tileset slot length is shorter then map's original + + if (tileIndex >= ExtendedTilesetBeginIdx) { // tile from extended tileset + while(tileset.tiles[tileIndex - compShift].tile == 0 && ((tileIndex & 0xF) - compShift) > 0) { + compShift++; + } + } + const CTile &tile = tileset.tiles[tileIndex - compShift]; this->tile = tile.tile; this->Value = value; this->ElevationLevel = elevation; @@ -116,7 +123,7 @@ void CMapField::setTileIndex(const CTileset &tileset, const tile_index tileIndex #endif this->cost = 1 << (tile.flag & MapFieldSpeedMask); #ifdef DEBUG - this->tilesetTile = tileIndex; + this->tilesetTile = tileIndex - compShift; #endif } From 48926818a69cc36ee77fdfb48dacb9f4e7d1f11a Mon Sep 17 00:00:00 2001 From: alyokhin Date: Sun, 12 Nov 2023 22:50:37 +0300 Subject: [PATCH 02/29] Replace lua check args macros with functions --- src/include/script.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/include/script.h b/src/include/script.h index a6c76f6324..9bc7aa499e 100644 --- a/src/include/script.h +++ b/src/include/script.h @@ -92,12 +92,24 @@ extern int LuaCall(lua_State *L, int narg, int nresults, int base, bool exitOnEr lua_error(l); \ } while (0) -#define LuaCheckArgs(l, args) \ - do { \ - if (lua_gettop(l) != args) { \ - LuaError(l, "incorrect argument"); \ - } \ - } while (0) +static void LuaCheckArgs(lua_State *l, const int args) +{ + if (lua_gettop(l) != args) { + LuaError(l, "incorrect argument"); + } +} + +static void LuaCheckArgs_min(lua_State *l, const int args) +{ + if (lua_gettop(l) < args) { + LuaError(l, "incorrect argument"); + } +} + +static const int LuaGetArgsNum(lua_State *l) +{ + return lua_gettop(l); +} #if LUA_VERSION_NUM <= 501 From fcf60e1b789a85ef86fd19c55314f45f4ca9d0e0 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Sun, 12 Nov 2023 23:18:11 +0300 Subject: [PATCH 03/29] Lua_register'ed get method for Map.Info.Highgrouns. Also moved a couple of map-related lua_registered methods from 'script_ui' to 'script_map' --- src/include/map.h | 6 +++++ src/map/map.cpp | 2 ++ src/map/script_map.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++ src/ui/script_ui.cpp | 46 ---------------------------------- 4 files changed, 64 insertions(+), 46 deletions(-) diff --git a/src/include/map.h b/src/include/map.h index dcf69505d8..fc48b4f669 100644 --- a/src/include/map.h +++ b/src/include/map.h @@ -129,6 +129,9 @@ class CMapInfo bool IsPointOnMap(const Vec2i &pos) const { return IsPointOnMap(pos.x, pos.y); } + bool IsHighgroundsEnabled() const { return Highgrounds; } + void EnableHighgrounds(const bool enable = true) { Highgrounds = enable; } + void Clear(); public: @@ -141,6 +144,9 @@ class CMapInfo PlayerTypes PlayerType[PlayerMax]; /// Same player->Type int PlayerSide[PlayerMax]; /// Same player->Side unsigned int MapUID; /// Unique Map ID (hash) + +private: + bool Highgrounds = false; /// Map has highgrounds }; /*---------------------------------------------------------------------------- diff --git a/src/map/map.cpp b/src/map/map.cpp index b31c5615b9..f707002f2f 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -316,6 +316,8 @@ void CMapInfo::Clear() memset(this->PlayerSide, 0, sizeof(this->PlayerSide)); memset(this->PlayerType, 0, sizeof(this->PlayerType)); this->MapUID = 0; + + this->Highgrounds = false; } CMap::~CMap() diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index 54aeddcccc..3c377486b2 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -1056,6 +1056,59 @@ static int CclGetIsGameHoster(lua_State *l) return 1; } +/** +** Description +** +** Set basic map caracteristics. +** +** @param l Lua state. +** +** Example: +** +**
PresentMap("Map description", 1, 128, 128, 17)
+*/ +static int CclPresentMap(lua_State *l) +{ + LuaCheckArgs_min(l, 5); + + Map.Info.Description = LuaToString(l, 1); + // Number of players in LuaToNumber(l, 3); // Not used yet. + Map.Info.MapWidth = LuaToNumber(l, 3); + Map.Info.MapHeight = LuaToNumber(l, 4); + Map.Info.MapUID = LuaToNumber(l, 5); + + if(LuaGetArgsNum(l) >= 6) { + Map.Info.EnableHighgrounds(LuaToNumber(l, 6)); + } + + return 0; +} + +static int CclIsHighgroundsEnabled(lua_State *l) +{ + lua_pushboolean(l, Map.Info.IsHighgroundsEnabled()); + return 0; +} + +/** +** Description +** +** Define the lua file that will build the map +** +** @param l Lua state. +** +** Example: +** +**
-- Load map setup from file +** DefineMapSetup("Setup.sms")
+*/ +static int CclDefineMapSetup(lua_State *l) +{ + LuaCheckArgs(l, 1); + Map.Info.Filename = LuaToString(l, 1); + + return 1; +} /** ** Register CCL features for map. */ @@ -1114,6 +1167,9 @@ void MapCclRegister() lua_register(Lua, "GetIsGameHoster", CclGetIsGameHoster); + lua_register(Lua, "PresentMap", CclPresentMap); + lua_register(Lua, "isHighgroundsEnabled", CclIsHighgroundsEnabled); + lua_register(Lua, "DefineMapSetup", CclDefineMapSetup); } //@} diff --git a/src/ui/script_ui.cpp b/src/ui/script_ui.cpp index 1001d3497d..a2d53a0450 100644 --- a/src/ui/script_ui.cpp +++ b/src/ui/script_ui.cpp @@ -1245,49 +1245,6 @@ static int CclSetGroupKeys(lua_State *l) return 0; } -/** -** Description -** -** Set basic map caracteristics. -** -** @param l Lua state. -** -** Example: -** -**
PresentMap("Map description", 1, 128, 128, 17)
-*/ -static int CclPresentMap(lua_State *l) -{ - LuaCheckArgs(l, 5); - - Map.Info.Description = LuaToString(l, 1); - // Number of players in LuaToNumber(l, 3); // Not used yet. - Map.Info.MapWidth = LuaToNumber(l, 3); - Map.Info.MapHeight = LuaToNumber(l, 4); - Map.Info.MapUID = LuaToNumber(l, 5); - - return 0; -} - -/** -** Description -** -** Define the lua file that will build the map -** -** @param l Lua state. -** -** Example: -** -**
-- Load map setup from file -** DefineMapSetup("Setup.sms")
-*/ -static int CclDefineMapSetup(lua_State *l) -{ - LuaCheckArgs(l, 1); - Map.Info.Filename = LuaToString(l, 1); - - return 0; -} /** ** Description ** @@ -1357,9 +1314,6 @@ void UserInterfaceCclRegister() lua_register(Lua, "DefineButtonStyle", CclDefineButtonStyle); - lua_register(Lua, "PresentMap", CclPresentMap); - lua_register(Lua, "DefineMapSetup", CclDefineMapSetup); - // // Look and feel of units // From 92c6d8c9ecc06507a56988e8820296366fce6944 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Mon, 13 Nov 2023 20:59:19 +0300 Subject: [PATCH 04/29] Register enable highground func, some fixes --- src/map/script_map.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index 3c377486b2..1a343358a2 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -1078,16 +1078,25 @@ static int CclPresentMap(lua_State *l) Map.Info.MapUID = LuaToNumber(l, 5); if(LuaGetArgsNum(l) >= 6) { - Map.Info.EnableHighgrounds(LuaToNumber(l, 6)); + Map.Info.EnableHighgrounds(LuaToBoolean(l, 6)); } return 0; } +static int CclMapEnableHighgrounds(lua_State *l) +{ + LuaCheckArgs(l, 1); + + Map.Info.EnableHighgrounds(LuaToBoolean(l, 1)); + + return 0; +} + static int CclIsHighgroundsEnabled(lua_State *l) { lua_pushboolean(l, Map.Info.IsHighgroundsEnabled()); - return 0; + return 1; } /** @@ -1168,7 +1177,9 @@ void MapCclRegister() lua_register(Lua, "GetIsGameHoster", CclGetIsGameHoster); lua_register(Lua, "PresentMap", CclPresentMap); + lua_register(Lua, "MapEnableHighgrounds", CclMapEnableHighgrounds); lua_register(Lua, "isHighgroundsEnabled", CclIsHighgroundsEnabled); + lua_register(Lua, "DefineMapSetup", CclDefineMapSetup); } From 25ef33a7d294ffb0f3675b038f508780add608d2 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Tue, 14 Nov 2023 13:37:43 +0300 Subject: [PATCH 05/29] Fix typo --- src/map/script_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index 1a343358a2..4d704edc36 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -1178,7 +1178,7 @@ void MapCclRegister() lua_register(Lua, "PresentMap", CclPresentMap); lua_register(Lua, "MapEnableHighgrounds", CclMapEnableHighgrounds); - lua_register(Lua, "isHighgroundsEnabled", CclIsHighgroundsEnabled); + lua_register(Lua, "IsHighgroundsEnabled", CclIsHighgroundsEnabled); lua_register(Lua, "DefineMapSetup", CclDefineMapSetup); } From b60d1d2d3c197b6ec59ac4a01bcac6b1eb8ddb43 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Tue, 14 Nov 2023 20:35:33 +0300 Subject: [PATCH 06/29] Added information about enabled highgrounds into the map presentation file generator. --- src/game/game.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index c8275a44fb..e92aaddbb7 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -289,9 +289,10 @@ static bool WriteMapPresentation(const fs::path &mapname, CMap &map, Vec2i newSi newSize.y = map.Info.MapHeight; } - f->printf("PresentMap(\"%s\", %d, %d, %d, %d)\n", + f->printf("PresentMap(\"%s\", %d, %d, %d, %d%s)\n", map.Info.Description.c_str(), numplayers, newSize.x, newSize.y, - map.Info.MapUID + 1); + map.Info.MapUID + 1, + Map.Info.IsHighgroundsEnabled()? ", true" : ""); if (map.Info.Filename.find(".sms") == std::string::npos && !map.Info.Filename.empty()) { f->printf("DefineMapSetup(\"%s\")\n", map.Info.Filename.c_str()); From 27c3f66a05273a58be0f003374f73ab66c2d5e6c Mon Sep 17 00:00:00 2001 From: alyokhin Date: Tue, 14 Nov 2023 20:49:56 +0300 Subject: [PATCH 07/29] "Layers" -> "Overlays" --- src/editor/editloop.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/editor/editloop.cpp b/src/editor/editloop.cpp index ad5ec6f95a..7f8108a479 100644 --- a/src/editor/editloop.cpp +++ b/src/editor/editloop.cpp @@ -1,4 +1,4 @@ -// _________ __ __ +// _________ __ __ // / _____// |_____________ _/ |______ ____ __ __ ______ // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | @@ -2137,7 +2137,7 @@ void EditorMainLoop() editorContainer->add(toolDropdown.get(), 0, 0); } - std::vector overlaysListStrings = { "Layers: None", "Unpassable", "No building allowed", "Elevation", "Opaque" }; + std::vector overlaysListStrings = { "Overlays: None", "Unpassable", "No building allowed", "Elevation", "Opaque" }; auto overlaysList = std::make_unique(overlaysListStrings); overlaysDropdown = std::make_unique(overlaysList.get()); auto overlaysDropdownListener = std::make_unique([&overlaysListStrings](const std::string&) { From 1161285a277de6074372822bdda71dc580d8f97a Mon Sep 17 00:00:00 2001 From: alyokhin Date: Tue, 14 Nov 2023 21:22:42 +0300 Subject: [PATCH 08/29] PresentMap args changed to some more human readable format. --- src/game/game.cpp | 2 +- src/map/script_map.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index e92aaddbb7..f63f1d6f23 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -292,7 +292,7 @@ static bool WriteMapPresentation(const fs::path &mapname, CMap &map, Vec2i newSi f->printf("PresentMap(\"%s\", %d, %d, %d, %d%s)\n", map.Info.Description.c_str(), numplayers, newSize.x, newSize.y, map.Info.MapUID + 1, - Map.Info.IsHighgroundsEnabled()? ", true" : ""); + Map.Info.IsHighgroundsEnabled()? ", \"highgrounds-enabled\"" : ""); if (map.Info.Filename.find(".sms") == std::string::npos && !map.Info.Filename.empty()) { f->printf("DefineMapSetup(\"%s\")\n", map.Info.Filename.c_str()); diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index 4d704edc36..8cd4498448 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -903,9 +903,15 @@ static int CclGenerateExtendedTileset(lua_State *luaStack) if (!Map.Tileset->insertTiles(parser.getTiles())) { LuaError(luaStack, "Tiles number limit exceeded."); } + + /// FIXME: Save resulted tileset graphic into png-file. Debug purposes. + IMG_SavePNG(Map.TileGraphic->Surface, "originalTilesetGraphics.png"); /// Add new graphic Map.TileGraphic->AppendFrames(parser.getGraphic()); + /// FIXME: Save resulted tileset graphic into png-file. Debug purposes. + IMG_SavePNG(Map.TileGraphic->Surface, "extendedTilesetGraphics.png"); + return 0; } @@ -1078,7 +1084,10 @@ static int CclPresentMap(lua_State *l) Map.Info.MapUID = LuaToNumber(l, 5); if(LuaGetArgsNum(l) >= 6) { - Map.Info.EnableHighgrounds(LuaToBoolean(l, 6)); + const std::string_view highgrounds = LuaToString(l, 6); + if (highgrounds == "highgrounds-enabled") { + Map.Info.EnableHighgrounds(true); + } } return 0; From 425fa26e4046cd697df89f997829fb0098533988 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Wed, 22 Nov 2023 21:53:06 +0300 Subject: [PATCH 09/29] Added drop down list's methods to set/get selected Items instead of it's indexes --- src/guichan/include/guichan/listmodel.h | 11 +++++- src/include/widgets.h | 4 +++ src/tolua/ui.pkg | 2 ++ src/ui/widgets.cpp | 47 ++++++++++++++++++++++++- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/guichan/include/guichan/listmodel.h b/src/guichan/include/guichan/listmodel.h index 44a8673c48..bfb8100bb8 100644 --- a/src/guichan/include/guichan/listmodel.h +++ b/src/guichan/include/guichan/listmodel.h @@ -8,7 +8,7 @@ * * Copyright (c) 2004, 2005 darkbits Js_./ * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// * _Qhm`] _f "'c 1!5m * Visit: http://guichan.darkbits.org )Qk

list, element); + if (result != this->list.end()) { + return result - this->list.begin(); + } else { + return -1; + } + +} + +/*---------------------------------------------------------------------------- +-- LuaListModel +----------------------------------------------------------------------------*/ /** ** Set the list @@ -1735,6 +1750,16 @@ void LuaListModel::setList(lua_State *lua, lua_Object *lo) } } +int LuaListModel::getIdxOfElement(std::string_view element) +{ + auto result = ranges::find(this->list, element); + if (result != this->list.end()) { + return result - this->list.begin(); + } else { + return -1; + } +} + /*---------------------------------------------------------------------------- -- ImageListBox ----------------------------------------------------------------------------*/ @@ -2610,6 +2635,13 @@ int ImageDropDownWidget::getSelected() return mListBox.getSelected(); } +std::string ImageDropDownWidget::getSelectedItem() +{ + Assert(mScrollArea && mScrollArea->getContent() != nullptr); + + return listmodel.getElementAt(mListBox.getSelected()); +} + void ImageDropDownWidget::setSelected(int selected) { Assert(mScrollArea && mScrollArea->getContent() != nullptr); @@ -2620,6 +2652,19 @@ void ImageDropDownWidget::setSelected(int selected) } } +int ImageDropDownWidget::setSelectedItem(lua_State *lua, lua_Object *lo) +{ + Assert(mScrollArea && mScrollArea->getContent() != nullptr); + + auto item = LuaToString(lua, *lo); + int idx = this->listmodel.getIdxOfElement(item); + if (idx >= 0) + { + this->setSelected(idx); + } + return idx; +} + void ImageDropDownWidget::adjustHeight() { Assert(mScrollArea && mScrollArea->getContent() != nullptr); From 1cd638b89d827697429f14d359f8821f1071b9a2 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Thu, 23 Nov 2023 13:19:11 +0300 Subject: [PATCH 10/29] Fix accidentally damaged character --- src/guichan/include/guichan/listmodel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guichan/include/guichan/listmodel.h b/src/guichan/include/guichan/listmodel.h index bfb8100bb8..565066f399 100644 --- a/src/guichan/include/guichan/listmodel.h +++ b/src/guichan/include/guichan/listmodel.h @@ -8,7 +8,7 @@ * * Copyright (c) 2004, 2005 darkbits Js_./ * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// * _Qhm`] _f "'c 1!5m * Visit: http://guichan.darkbits.org )Qk

Date: Thu, 23 Nov 2023 13:25:19 +0300 Subject: [PATCH 11/29] Removed few debug lines of code --- src/map/script_map.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index 8cd4498448..7a23c4e0ea 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -903,15 +903,9 @@ static int CclGenerateExtendedTileset(lua_State *luaStack) if (!Map.Tileset->insertTiles(parser.getTiles())) { LuaError(luaStack, "Tiles number limit exceeded."); } - - /// FIXME: Save resulted tileset graphic into png-file. Debug purposes. - IMG_SavePNG(Map.TileGraphic->Surface, "originalTilesetGraphics.png"); /// Add new graphic Map.TileGraphic->AppendFrames(parser.getGraphic()); - /// FIXME: Save resulted tileset graphic into png-file. Debug purposes. - IMG_SavePNG(Map.TileGraphic->Surface, "extendedTilesetGraphics.png"); - return 0; } From 889aa3c2f66521191ca7209c3ad08129181ec33d Mon Sep 17 00:00:00 2001 From: alyokhin Date: Fri, 24 Nov 2023 19:51:34 +0300 Subject: [PATCH 12/29] check for call without arguments --- src/map/script_map.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index 7a23c4e0ea..9b26f3ecdb 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -1080,7 +1080,7 @@ static int CclPresentMap(lua_State *l) if(LuaGetArgsNum(l) >= 6) { const std::string_view highgrounds = LuaToString(l, 6); if (highgrounds == "highgrounds-enabled") { - Map.Info.EnableHighgrounds(true); + Map.Info.EnableHighgrounds(); } } @@ -1089,10 +1089,8 @@ static int CclPresentMap(lua_State *l) static int CclMapEnableHighgrounds(lua_State *l) { - LuaCheckArgs(l, 1); - - Map.Info.EnableHighgrounds(LuaToBoolean(l, 1)); - + Map.Info.EnableHighgrounds(LuaGetArgsNum(l) >= 1 ? LuaToBoolean(l, 1) : true); + return 0; } From b830561e48d3efb65e72fb697b54615f9bde95cf Mon Sep 17 00:00:00 2001 From: Alyokhin Date: Sun, 26 Nov 2023 00:07:38 +0300 Subject: [PATCH 13/29] Update src/include/map.h Co-authored-by: Joris Dauphin --- src/include/map.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/map.h b/src/include/map.h index fc48b4f669..caeb4c0619 100644 --- a/src/include/map.h +++ b/src/include/map.h @@ -146,7 +146,7 @@ class CMapInfo unsigned int MapUID; /// Unique Map ID (hash) private: - bool Highgrounds = false; /// Map has highgrounds + bool HighgroundsEnabled = false; /// Map has highgrounds }; /*---------------------------------------------------------------------------- From f6231bfe97438217fbac7e2435577fb5904a61a3 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Sun, 26 Nov 2023 00:21:23 +0300 Subject: [PATCH 14/29] removed unnecessary const, optimized variable name --- src/include/map.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/include/map.h b/src/include/map.h index fc48b4f669..32f409d5a5 100644 --- a/src/include/map.h +++ b/src/include/map.h @@ -129,8 +129,8 @@ class CMapInfo bool IsPointOnMap(const Vec2i &pos) const { return IsPointOnMap(pos.x, pos.y); } - bool IsHighgroundsEnabled() const { return Highgrounds; } - void EnableHighgrounds(const bool enable = true) { Highgrounds = enable; } + bool IsHighgroundsEnabled() const { return HighgroundsEnabled; } + void EnableHighgrounds(bool enable = true) { HighgroundsEnabled = enable; } void Clear(); @@ -146,7 +146,7 @@ class CMapInfo unsigned int MapUID; /// Unique Map ID (hash) private: - bool Highgrounds = false; /// Map has highgrounds + bool HighgroundsEnabled = false; /// Map has highgrounds }; /*---------------------------------------------------------------------------- From 5baf6438e969f83117101cc0098301c1d85b4634 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Sun, 26 Nov 2023 00:28:25 +0300 Subject: [PATCH 15/29] change from static to inline for functions in a header file --- src/include/script.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/include/script.h b/src/include/script.h index 9bc7aa499e..23725cbe18 100644 --- a/src/include/script.h +++ b/src/include/script.h @@ -92,21 +92,21 @@ extern int LuaCall(lua_State *L, int narg, int nresults, int base, bool exitOnEr lua_error(l); \ } while (0) -static void LuaCheckArgs(lua_State *l, const int args) +inline void LuaCheckArgs(lua_State *l, int args) { if (lua_gettop(l) != args) { LuaError(l, "incorrect argument"); } } -static void LuaCheckArgs_min(lua_State *l, const int args) +inline void LuaCheckArgs_min(lua_State *l, int args) { if (lua_gettop(l) < args) { LuaError(l, "incorrect argument"); } } -static const int LuaGetArgsNum(lua_State *l) +inline int LuaGetArgsNum(lua_State *l) { return lua_gettop(l); } From aaf7b0b19387f855599bb7a53584e1817d4d5a81 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Sun, 26 Nov 2023 00:29:17 +0300 Subject: [PATCH 16/29] Highgrounds->HighgroundsEnabled --- src/map/map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/map.cpp b/src/map/map.cpp index f707002f2f..f89b96166e 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -317,7 +317,7 @@ void CMapInfo::Clear() memset(this->PlayerType, 0, sizeof(this->PlayerType)); this->MapUID = 0; - this->Highgrounds = false; + this->HighgroundsEnabled = false; } CMap::~CMap() From 473fae69206f00d6185159d16a79c98b5d0396c4 Mon Sep 17 00:00:00 2001 From: Alyokhin Date: Sun, 26 Nov 2023 00:30:39 +0300 Subject: [PATCH 17/29] Update src/map/script_map.cpp Co-authored-by: Joris Dauphin --- src/map/script_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index 9b26f3ecdb..daa2a6bea3 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -1065,7 +1065,7 @@ static int CclGetIsGameHoster(lua_State *l) ** ** Example: ** -**

PresentMap("Map description", 1, 128, 128, 17)
+**
PresentMap("Map description", PlayerCount, Width, Height, uid_number [, "highgrounds-enabled"])
*/ static int CclPresentMap(lua_State *l) { From 63dae4ef7d9484ee5f5f94e070080449a0f18f9b Mon Sep 17 00:00:00 2001 From: Alyokhin Date: Sun, 26 Nov 2023 00:31:04 +0300 Subject: [PATCH 18/29] Update src/map/mapfield.cpp Co-authored-by: Joris Dauphin --- src/map/mapfield.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/mapfield.cpp b/src/map/mapfield.cpp index 505ad014a6..03acf4a9da 100644 --- a/src/map/mapfield.cpp +++ b/src/map/mapfield.cpp @@ -84,7 +84,7 @@ bool CMapField::IsTerrainResourceOnMap() const void CMapField::setTileIndex(const CTileset &tileset, const tile_index tileIndex, const int value, const uint8_t elevation, const int subtile /* = -1 */) { - uint8_t compShift = 0; // [0..F] in case then current tileset slot length is shorter then map's original + uint8_t compShift = 0; // [0..F] in case that current tileset slot length is shorter than map's original if (tileIndex >= ExtendedTilesetBeginIdx) { // tile from extended tileset while(tileset.tiles[tileIndex - compShift].tile == 0 && ((tileIndex & 0xF) - compShift) > 0) { From 5601b3f88f0cf6e00a042526ed929707b63d3b89 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Sun, 26 Nov 2023 00:31:24 +0300 Subject: [PATCH 19/29] typo --- src/map/mapfield.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/mapfield.cpp b/src/map/mapfield.cpp index 505ad014a6..03acf4a9da 100644 --- a/src/map/mapfield.cpp +++ b/src/map/mapfield.cpp @@ -84,7 +84,7 @@ bool CMapField::IsTerrainResourceOnMap() const void CMapField::setTileIndex(const CTileset &tileset, const tile_index tileIndex, const int value, const uint8_t elevation, const int subtile /* = -1 */) { - uint8_t compShift = 0; // [0..F] in case then current tileset slot length is shorter then map's original + uint8_t compShift = 0; // [0..F] in case that current tileset slot length is shorter than map's original if (tileIndex >= ExtendedTilesetBeginIdx) { // tile from extended tileset while(tileset.tiles[tileIndex - compShift].tile == 0 && ((tileIndex & 0xF) - compShift) > 0) { From 166fefd3a57b601161dd6934389a268349c09773 Mon Sep 17 00:00:00 2001 From: Alyokhin Date: Sun, 26 Nov 2023 00:31:25 +0300 Subject: [PATCH 20/29] Update src/map/script_map.cpp Co-authored-by: Joris Dauphin --- src/map/script_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index daa2a6bea3..de511d84ff 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -1072,7 +1072,7 @@ static int CclPresentMap(lua_State *l) LuaCheckArgs_min(l, 5); Map.Info.Description = LuaToString(l, 1); - // Number of players in LuaToNumber(l, 3); // Not used yet. + // Number of players in LuaToNumber(l, 2); // Not used yet. Map.Info.MapWidth = LuaToNumber(l, 3); Map.Info.MapHeight = LuaToNumber(l, 4); Map.Info.MapUID = LuaToNumber(l, 5); From 2d5ff4e724cd7cbb477c3e1239d0051cc6e61dbf Mon Sep 17 00:00:00 2001 From: Alyokhin Date: Sun, 26 Nov 2023 00:33:31 +0300 Subject: [PATCH 21/29] Update src/map/script_map.cpp Co-authored-by: Joris Dauphin --- src/map/script_map.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index de511d84ff..f38b166e9e 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -1081,6 +1081,8 @@ static int CclPresentMap(lua_State *l) const std::string_view highgrounds = LuaToString(l, 6); if (highgrounds == "highgrounds-enabled") { Map.Info.EnableHighgrounds(); + } else { + LuaError(l, "Unknown value %s\n", highgrounds.data()); } } From 5e49b8dc156083b9d2f9f8677d69b809f3b7b1aa Mon Sep 17 00:00:00 2001 From: Alyokhin Date: Sun, 26 Nov 2023 00:40:50 +0300 Subject: [PATCH 22/29] Update src/map/script_map.cpp Co-authored-by: Joris Dauphin --- src/map/script_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index f38b166e9e..aed5f7016a 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -1119,7 +1119,7 @@ static int CclDefineMapSetup(lua_State *l) LuaCheckArgs(l, 1); Map.Info.Filename = LuaToString(l, 1); - return 1; + return 0; } /** ** Register CCL features for map. From d2d6b13ccbf807f11a54b8ecca8ca3904ea62e6e Mon Sep 17 00:00:00 2001 From: Alyokhin Date: Sun, 26 Nov 2023 00:44:12 +0300 Subject: [PATCH 23/29] Update src/include/script.h Co-authored-by: Joris Dauphin --- src/include/script.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/script.h b/src/include/script.h index 9bc7aa499e..3133cf3038 100644 --- a/src/include/script.h +++ b/src/include/script.h @@ -92,7 +92,7 @@ extern int LuaCall(lua_State *L, int narg, int nresults, int base, bool exitOnEr lua_error(l); \ } while (0) -static void LuaCheckArgs(lua_State *l, const int args) +inline void LuaCheckArgs(lua_State *l, const int args) { if (lua_gettop(l) != args) { LuaError(l, "incorrect argument"); From 5ab28043645481c2e60d8d737a4afd4939d50a3e Mon Sep 17 00:00:00 2001 From: alyokhin Date: Sun, 26 Nov 2023 00:45:55 +0300 Subject: [PATCH 24/29] change return to 0, because t Nothing is returned in Lua --- src/map/script_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index 9b26f3ecdb..f08b1de8cc 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -1117,7 +1117,7 @@ static int CclDefineMapSetup(lua_State *l) LuaCheckArgs(l, 1); Map.Info.Filename = LuaToString(l, 1); - return 1; + return 0; } /** ** Register CCL features for map. From b9f41e6f5fe7715e3329fc4419892aa0dc8887e0 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Sun, 26 Nov 2023 01:42:05 +0300 Subject: [PATCH 25/29] Revert changes of guichan. --- src/guichan/include/guichan/listmodel.h | 9 --------- src/include/widgets.h | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/guichan/include/guichan/listmodel.h b/src/guichan/include/guichan/listmodel.h index 565066f399..c2ae11b966 100644 --- a/src/guichan/include/guichan/listmodel.h +++ b/src/guichan/include/guichan/listmodel.h @@ -86,15 +86,6 @@ namespace gcn */ virtual std::string getElementAt(int i) = 0; - /** - * Gets an index of a given element's value (if present) - * - * @param element a value of elements to find - * @return an index of element if present, -1 otherwise. - */ - - virtual int getIdxOfElement(std::string_view element) = 0; - virtual ~ListModel() {} }; } diff --git a/src/include/widgets.h b/src/include/widgets.h index ec5ab3ea56..a0552c7dc1 100644 --- a/src/include/widgets.h +++ b/src/include/widgets.h @@ -319,7 +319,7 @@ class StringListModel : public gcn::ListModel int getNumberOfElements() override { return list.size(); } std::string getElementAt(int i) override { return list[i]; } - int getIdxOfElement(std::string_view element) override; + int getIdxOfElement(std::string_view element); }; class LuaListModel : public gcn::ListModel @@ -331,7 +331,7 @@ class LuaListModel : public gcn::ListModel void setList(lua_State *lua, lua_Object *lo); int getNumberOfElements() override { return list.size(); } std::string getElementAt(int i) override { return list[i]; } - int getIdxOfElement(std::string_view element) override; + int getIdxOfElement(std::string_view element); }; class ImageListBox : public gcn::ListBox From 3e08359e3f7e2321d3c94f1b5ca6c620a5cb1d6a Mon Sep 17 00:00:00 2001 From: Alyokhin Date: Mon, 27 Nov 2023 16:41:58 +0300 Subject: [PATCH 26/29] Revert accidental changes in editloop.cpp --- src/editor/editloop.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor/editloop.cpp b/src/editor/editloop.cpp index 7f8108a479..a82274af3a 100644 --- a/src/editor/editloop.cpp +++ b/src/editor/editloop.cpp @@ -1,4 +1,4 @@ -// _________ __ __ +// _________ __ __ // / _____// |_____________ _/ |______ ____ __ __ ______ // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | From c936051f92c4c3ec78076b36c931b6ad35b9a1e1 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Mon, 27 Nov 2023 17:04:53 +0300 Subject: [PATCH 27/29] Revert accidental changes in the lismodel.h --- src/guichan/include/guichan/listmodel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guichan/include/guichan/listmodel.h b/src/guichan/include/guichan/listmodel.h index c2ae11b966..44a8673c48 100644 --- a/src/guichan/include/guichan/listmodel.h +++ b/src/guichan/include/guichan/listmodel.h @@ -8,7 +8,7 @@ * * Copyright (c) 2004, 2005 darkbits Js_./ * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// * _Qhm`] _f "'c 1!5m * Visit: http://guichan.darkbits.org )Qk

Date: Tue, 28 Nov 2023 10:57:24 +0300 Subject: [PATCH 28/29] fixed variable name in case we will add more optional args --- src/map/script_map.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index aed5f7016a..4d02023499 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -1078,11 +1078,11 @@ static int CclPresentMap(lua_State *l) Map.Info.MapUID = LuaToNumber(l, 5); if(LuaGetArgsNum(l) >= 6) { - const std::string_view highgrounds = LuaToString(l, 6); - if (highgrounds == "highgrounds-enabled") { + const std::string_view value = LuaToString(l, 6); + if (value == "highgrounds-enabled") { Map.Info.EnableHighgrounds(); } else { - LuaError(l, "Unknown value %s\n", highgrounds.data()); + LuaError(l, "Unknown value %s\n", value.data()); } } From dc9cc18e0f59e872aced7afa5e5b57f36ae7d2a0 Mon Sep 17 00:00:00 2001 From: alyokhin Date: Tue, 28 Nov 2023 16:41:09 +0300 Subject: [PATCH 29/29] Remove 'FIXME' comment --- src/map/fov.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/fov.cpp b/src/map/fov.cpp index a76669e4fd..63b8caed93 100644 --- a/src/map/fov.cpp +++ b/src/map/fov.cpp @@ -138,7 +138,7 @@ void CFieldOfView::Refresh(const CPlayer &player, const CUnit &unit, const Vec2i return; } if (GameSettings.FoV == FieldOfViewTypes::cShadowCasting && !unit.Type->AirUnit) { - /// FIXME: add high-/lowground + OpaqueFields = unit.Type->BoolFlag[ELEVATED_INDEX].value ? 0 : this->Settings.OpaqueFields; if (GameSettings.Inside) { OpaqueFields &= ~(MapFieldRocks); /// because of rocks-flag is used as an obstacle for ranged attackers