From c23c5d900ef40dfd147a19e3580f1bfd30af79b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 3 Mar 2023 18:00:41 +0100 Subject: [PATCH 1/9] Remove dead code --- src/game/editor/editor.h | 37 +-------------------------------- src/game/editor/layer_tiles.cpp | 5 ----- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index ad255bfee..9a17b8e3e 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -220,44 +220,9 @@ public: bool IsEmpty() const { - return m_vpLayers.size() == 0; // stupid function, since its bad for Fillselection: TODO add a function for Fillselection that returns whether a specific tile is used in the given layer + return m_vpLayers.empty(); } - /*bool IsUsedInThisLayer(int Layer, int Index) // <--------- this is what i meant but cause i don't know which Indexes belongs to which layers i can't finish yet - { - switch Layer - { - case LAYERTYPE_GAME: // security - return true; - case LAYERTYPE_FRONT: - return true; - case LAYERTYPE_TELE: - { - if (Index ==) // you could add an 2D array into mapitems.h which defines which Indexes belong to which layer(s) - } - case LAYERTYPE_SPEEDUP: - { - if (Index == TILE_BOOST) - return true; - else - return false; - } - case LAYERTYPE_SWITCH: - { - - } - case LAYERTYPE_TUNE: - { - if (Index == TILE_TUNE) - return true; - else - return false; - } - default: - return false; - } - }*/ - void OnEdited() { if(!m_CustomParallaxZoom) diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index 04c9fd6b3..a7d2165af 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -1120,7 +1120,6 @@ void CLayerTiles::ModifyEnvelopeIndex(INDEX_MODIFY_FUNC Func) CLayerTele::CLayerTele(int w, int h) : CLayerTiles(w, h) { - //m_Type = LAYERTYPE_TELE; str_copy(m_aName, "Tele", sizeof(m_aName)); m_Tele = 1; @@ -1353,7 +1352,6 @@ bool CLayerTele::ContainsElementWithId(int Id) CLayerSpeedup::CLayerSpeedup(int w, int h) : CLayerTiles(w, h) { - //m_Type = LAYERTYPE_SPEEDUP; str_copy(m_aName, "Speedup", sizeof(m_aName)); m_Speedup = 1; @@ -1591,7 +1589,6 @@ void CLayerSpeedup::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect) CLayerFront::CLayerFront(int w, int h) : CLayerTiles(w, h) { - //m_Type = LAYERTYPE_FRONT; str_copy(m_aName, "Front", sizeof(m_aName)); m_Front = 1; } @@ -1638,7 +1635,6 @@ void CLayerFront::Resize(int NewW, int NewH) CLayerSwitch::CLayerSwitch(int w, int h) : CLayerTiles(w, h) { - //m_Type = LAYERTYPE_SWITCH; str_copy(m_aName, "Switch", sizeof(m_aName)); m_Switch = 1; @@ -1895,7 +1891,6 @@ bool CLayerSwitch::ContainsElementWithId(int Id) CLayerTune::CLayerTune(int w, int h) : CLayerTiles(w, h) { - //m_Type = LAYERTYPE_TUNE; str_copy(m_aName, "Tune", sizeof(m_aName)); m_Tune = 1; From 245703798bdf15761b0740fbf64b282234b524e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 3 Mar 2023 17:55:39 +0100 Subject: [PATCH 2/9] Use `bool` for `IsCheckTeleport` and `IsCheckEvilTeleport` The tele tile number is not used for `TILE_TELECHECKIN` and `TILE_TELECHECKINEVIL` and the results of these functions were always implicitly converted to `bool` while assuming that the tele number was not `0` for these tiles. --- src/game/collision.cpp | 28 ++++++++-------------------- src/game/collision.h | 4 ++-- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/game/collision.cpp b/src/game/collision.cpp index 07e327e79..4d2f6560a 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -634,30 +634,18 @@ int CCollision::IsEvilTeleport(int Index) const return 0; } -int CCollision::IsCheckTeleport(int Index) const +bool CCollision::IsCheckTeleport(int Index) const { - if(Index < 0) - return 0; - if(!m_pTele) - return 0; - - if(m_pTele[Index].m_Type == TILE_TELECHECKIN) - return m_pTele[Index].m_Number; - - return 0; + if(Index < 0 || !m_pTele) + return false; + return m_pTele[Index].m_Type == TILE_TELECHECKIN; } -int CCollision::IsCheckEvilTeleport(int Index) const +bool CCollision::IsCheckEvilTeleport(int Index) const { - if(Index < 0) - return 0; - if(!m_pTele) - return 0; - - if(m_pTele[Index].m_Type == TILE_TELECHECKINEVIL) - return m_pTele[Index].m_Number; - - return 0; + if(Index < 0 || !m_pTele) + return false; + return m_pTele[Index].m_Type == TILE_TELECHECKINEVIL; } int CCollision::IsTeleCheckpoint(int Index) const diff --git a/src/game/collision.h b/src/game/collision.h index 905b2c239..2f7908df8 100644 --- a/src/game/collision.h +++ b/src/game/collision.h @@ -84,8 +84,8 @@ public: int GetFTileFlags(int Index) const; int IsTeleport(int Index) const; int IsEvilTeleport(int Index) const; - int IsCheckTeleport(int Index) const; - int IsCheckEvilTeleport(int Index) const; + bool IsCheckTeleport(int Index) const; + bool IsCheckEvilTeleport(int Index) const; int IsTeleportWeapon(int Index) const; int IsTeleportHook(int Index) const; int IsTeleCheckpoint(int Index) const; From 9c841f1e431e3a4be80cd79d7de5b67bea062427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 3 Mar 2023 17:57:25 +0100 Subject: [PATCH 3/9] Add `IsTeleTileNumberUsed` function To check whether the number of a tele tile is used or not. --- src/game/editor/layer_tiles.cpp | 6 +----- src/game/mapitems.cpp | 6 ++++++ src/game/mapitems.h | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index a7d2165af..286c3536e 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -1335,11 +1335,7 @@ bool CLayerTele::ContainsElementWithId(int Id) { for(int x = 0; x < m_Width; ++x) { - if(m_pTeleTile[y * m_Width + x].m_Type == TILE_TELECHECKIN) - continue; - if(m_pTeleTile[y * m_Width + x].m_Type == TILE_TELECHECKINEVIL) - continue; - if(m_pTeleTile[y * m_Width + x].m_Number == Id) + if(IsTeleTileNumberUsed(m_pTeleTile[y * m_Width + x].m_Type) && m_pTeleTile[y * m_Width + x].m_Number == Id) { return true; } diff --git a/src/game/mapitems.cpp b/src/game/mapitems.cpp index d683cd7cf..c65c42031 100644 --- a/src/game/mapitems.cpp +++ b/src/game/mapitems.cpp @@ -57,6 +57,12 @@ bool IsValidTeleTile(int Index) Index == TILE_TELECHECKINEVIL); } +bool IsTeleTileNumberUsed(int Index) +{ + return Index != TILE_TELECHECKIN && + Index != TILE_TELECHECKINEVIL; +} + bool IsValidSpeedupTile(int Index) { return Index == TILE_BOOST; diff --git a/src/game/mapitems.h b/src/game/mapitems.h index a3cbf6ee0..b778c322b 100644 --- a/src/game/mapitems.h +++ b/src/game/mapitems.h @@ -489,6 +489,7 @@ public: bool IsValidGameTile(int Index); bool IsValidFrontTile(int Index); bool IsValidTeleTile(int Index); +bool IsTeleTileNumberUsed(int Index); // Assumes that Index is a valid tele tile index bool IsValidSpeedupTile(int Index); bool IsValidSwitchTile(int Index); bool IsValidTuneTile(int Index); From 1d9cbba326624cb5a9eabe91152645d232538144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 4 Mar 2023 12:17:23 +0100 Subject: [PATCH 4/9] Add `IsSwitchTile(Flags|Number|Delay)Used` functions To check whether the flags, number or delay of a switch tile is used or not. --- src/game/mapitems.cpp | 22 ++++++++++++++++++++++ src/game/mapitems.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/src/game/mapitems.cpp b/src/game/mapitems.cpp index c65c42031..a9620bc98 100644 --- a/src/game/mapitems.cpp +++ b/src/game/mapitems.cpp @@ -87,6 +87,28 @@ bool IsValidSwitchTile(int Index) (IsValidEntity(Index) && Index >= ENTITY_OFFSET + ENTITY_ARMOR_1)); } +bool IsSwitchTileFlagsUsed(int Index) +{ + return Index != TILE_FREEZE && + Index != TILE_DFREEZE && + Index != TILE_DUNFREEZE; +} + +bool IsSwitchTileNumberUsed(int Index) +{ + return Index != TILE_JUMP && + Index != TILE_HIT_ENABLE && + Index != TILE_HIT_DISABLE && + Index != TILE_ALLOW_TELE_GUN && + Index != TILE_ALLOW_BLUE_TELE_GUN; +} + +bool IsSwitchTileDelayUsed(int Index) +{ + return Index != TILE_DFREEZE && + Index != TILE_DUNFREEZE; +} + bool IsValidTuneTile(int Index) { return Index == TILE_TUNE; diff --git a/src/game/mapitems.h b/src/game/mapitems.h index b778c322b..efd7e0090 100644 --- a/src/game/mapitems.h +++ b/src/game/mapitems.h @@ -492,6 +492,9 @@ bool IsValidTeleTile(int Index); bool IsTeleTileNumberUsed(int Index); // Assumes that Index is a valid tele tile index bool IsValidSpeedupTile(int Index); bool IsValidSwitchTile(int Index); +bool IsSwitchTileFlagsUsed(int Index); // Assumes that Index is a valid switch tile index +bool IsSwitchTileNumberUsed(int Index); // Assumes that Index is a valid switch tile index +bool IsSwitchTileDelayUsed(int Index); // Assumes that Index is a valid switch tile index bool IsValidTuneTile(int Index); bool IsValidEntity(int Index); bool IsRotatableTile(int Index); From 60c0da7c4ddc11dcb9e3d5527d5a02f49e6fb3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 3 Mar 2023 18:20:08 +0100 Subject: [PATCH 5/9] Use `IsValid***Tile` functions Use the utility function to check if tele/speedup/switch/tune tile indices are valid. Using `IsValidSwitchTile` fixes that the switch number and delay were not updated when selecting freeze, deep freeze, deep unfreeze, live freeze and live unfreeze tiles, as those tiles were missing in the existing condition. --- src/game/client/components/maplayers.cpp | 2 +- src/game/client/render_map.cpp | 2 +- src/game/editor/io.cpp | 56 +++++------------------- src/game/editor/layer_tiles.cpp | 26 ++--------- 4 files changed, 18 insertions(+), 68 deletions(-) diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index bddc47faf..e045be585 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -667,7 +667,7 @@ void CMapLayers::OnMapLoad() Flags = 0; if(CurOverlay == 1) { - if(Index != TILE_TELECHECKIN && Index != TILE_TELECHECKINEVIL) + if(IsTeleTileNumberUsed(Index)) Index = ((CTeleTile *)pTiles)[y * pTMap->m_Width + x].m_Number; else Index = 0; diff --git a/src/game/client/render_map.cpp b/src/game/client/render_map.cpp index 918414776..4d1ed1b7e 100644 --- a/src/game/client/render_map.cpp +++ b/src/game/client/render_map.cpp @@ -456,7 +456,7 @@ void CRenderTools::RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale int c = mx + my * w; unsigned char Index = pTele[c].m_Number; - if(Index && pTele[c].m_Type != TILE_TELECHECKIN && pTele[c].m_Type != TILE_TELECHECKINEVIL) + if(Index && IsTeleTileNumberUsed(pTele[c].m_Type)) { char aBuf[16]; str_format(aBuf, sizeof(aBuf), "%d", Index); diff --git a/src/game/editor/io.cpp b/src/game/editor/io.cpp index 59f3b947a..6a2b18a17 100644 --- a/src/game/editor/io.cpp +++ b/src/game/editor/io.cpp @@ -707,27 +707,15 @@ bool CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Stora unsigned int Size = DataFile.GetDataSize(pTilemapItem->m_Tele); if(Size >= (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CTeleTile)) { - static const int s_aTilesRep[] = { - TILE_TELEIN, - TILE_TELEINEVIL, - TILE_TELEOUT, - TILE_TELECHECK, - TILE_TELECHECKIN, - TILE_TELECHECKINEVIL, - TILE_TELECHECKOUT, - TILE_TELEINWEAPON, - TILE_TELEINHOOK}; CTeleTile *pLayerTeleTiles = ((CLayerTele *)pTiles)->m_pTeleTile; mem_copy(pLayerTeleTiles, pTeleData, (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CTeleTile)); for(int i = 0; i < pTiles->m_Width * pTiles->m_Height; i++) { - pTiles->m_pTiles[i].m_Index = 0; - for(int TilesRep : s_aTilesRep) - { - if(pLayerTeleTiles[i].m_Type == TilesRep) - pTiles->m_pTiles[i].m_Index = TilesRep; - } + if(IsValidTeleTile(pLayerTeleTiles[i].m_Type)) + pTiles->m_pTiles[i].m_Index = pLayerTeleTiles[i].m_Type; + else + pTiles->m_pTiles[i].m_Index = 0; } } DataFile.UnloadData(pTilemapItem->m_Tele); @@ -744,8 +732,8 @@ bool CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Stora for(int i = 0; i < pTiles->m_Width * pTiles->m_Height; i++) { - if(pLayerSpeedupTiles[i].m_Force > 0) - pTiles->m_pTiles[i].m_Index = TILE_BOOST; + if(IsValidSpeedupTile(pLayerSpeedupTiles[i].m_Type) && pLayerSpeedupTiles[i].m_Force > 0) + pTiles->m_pTiles[i].m_Index = pLayerSpeedupTiles[i].m_Type; else pTiles->m_pTiles[i].m_Index = 0; } @@ -768,29 +756,12 @@ bool CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Stora unsigned int Size = DataFile.GetDataSize(pTilemapItem->m_Switch); if(Size >= (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CSwitchTile)) { - const int s_aTilesComp[] = { - TILE_SWITCHTIMEDOPEN, - TILE_SWITCHTIMEDCLOSE, - TILE_SWITCHOPEN, - TILE_SWITCHCLOSE, - TILE_FREEZE, - TILE_DFREEZE, - TILE_DUNFREEZE, - TILE_LFREEZE, - TILE_LUNFREEZE, - TILE_HIT_ENABLE, - TILE_HIT_DISABLE, - TILE_JUMP, - TILE_ADD_TIME, - TILE_SUBTRACT_TIME, - TILE_ALLOW_TELE_GUN, - TILE_ALLOW_BLUE_TELE_GUN}; CSwitchTile *pLayerSwitchTiles = ((CLayerSwitch *)pTiles)->m_pSwitchTile; mem_copy(pLayerSwitchTiles, pSwitchData, (size_t)pTiles->m_Width * pTiles->m_Height * sizeof(CSwitchTile)); for(int i = 0; i < pTiles->m_Width * pTiles->m_Height; i++) { - if(((pLayerSwitchTiles[i].m_Type > (ENTITY_CRAZY_SHOTGUN + ENTITY_OFFSET) && ((CLayerSwitch *)pTiles)->m_pSwitchTile[i].m_Type < (ENTITY_DRAGGER_WEAK + ENTITY_OFFSET)) || ((CLayerSwitch *)pTiles)->m_pSwitchTile[i].m_Type == (ENTITY_LASER_O_FAST + 1 + ENTITY_OFFSET))) + if(((pLayerSwitchTiles[i].m_Type > (ENTITY_CRAZY_SHOTGUN + ENTITY_OFFSET) && pLayerSwitchTiles[i].m_Type < (ENTITY_DRAGGER_WEAK + ENTITY_OFFSET)) || pLayerSwitchTiles[i].m_Type == (ENTITY_LASER_O_FAST + 1 + ENTITY_OFFSET))) continue; else if(pLayerSwitchTiles[i].m_Type >= (ENTITY_ARMOR_1 + ENTITY_OFFSET) && pLayerSwitchTiles[i].m_Type <= (ENTITY_DOOR + ENTITY_OFFSET)) { @@ -799,13 +770,10 @@ bool CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Stora continue; } - for(int TilesComp : s_aTilesComp) + if(IsValidSwitchTile(pLayerSwitchTiles[i].m_Type)) { - if(pLayerSwitchTiles[i].m_Type == TilesComp) - { - pTiles->m_pTiles[i].m_Index = TilesComp; - pTiles->m_pTiles[i].m_Flags = pLayerSwitchTiles[i].m_Flags; - } + pTiles->m_pTiles[i].m_Index = pLayerSwitchTiles[i].m_Type; + pTiles->m_pTiles[i].m_Flags = pLayerSwitchTiles[i].m_Flags; } } } @@ -822,8 +790,8 @@ bool CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Stora for(int i = 0; i < pTiles->m_Width * pTiles->m_Height; i++) { - if(pLayerTuneTiles[i].m_Type == TILE_TUNE) - pTiles->m_pTiles[i].m_Index = TILE_TUNE; + if(IsValidTuneTile(pLayerTuneTiles[i].m_Type)) + pTiles->m_pTiles[i].m_Index = pLayerTuneTiles[i].m_Type; else pTiles->m_pTiles[i].m_Index = 0; } diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index 286c3536e..014bc7241 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -259,11 +259,7 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect) for(int x = 0; x < r.w; x++) { pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x] = ((CLayerTele *)this)->m_pTeleTile[(r.y + y) * m_Width + (r.x + x)]; - if(pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x].m_Type == TILE_TELEIN || pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x].m_Type == TILE_TELEOUT || pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x].m_Type == TILE_TELEINEVIL - // || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELECHECKINEVIL - || pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x].m_Type == TILE_TELECHECK || pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x].m_Type == TILE_TELECHECKOUT - // || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELECHECKIN - || pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x].m_Type == TILE_TELEINWEAPON || pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x].m_Type == TILE_TELEINHOOK) + if(IsValidTeleTile(pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x].m_Type) && IsTeleTileNumberUsed(pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x].m_Type)) { m_pEditor->m_TeleNumber = pGrabbed->m_pTeleTile[y * pGrabbed->m_Width + x].m_Number; } @@ -297,7 +293,7 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect) for(int x = 0; x < r.w; x++) { pGrabbed->m_pSpeedupTile[y * pGrabbed->m_Width + x] = ((CLayerSpeedup *)this)->m_pSpeedupTile[(r.y + y) * m_Width + (r.x + x)]; - if(pGrabbed->m_pSpeedupTile[y * pGrabbed->m_Width + x].m_Type == TILE_BOOST) + if(IsValidSpeedupTile(pGrabbed->m_pSpeedupTile[y * pGrabbed->m_Width + x].m_Type)) { m_pEditor->m_SpeedupAngle = pGrabbed->m_pSpeedupTile[y * pGrabbed->m_Width + x].m_Angle; m_pEditor->m_SpeedupForce = pGrabbed->m_pSpeedupTile[y * pGrabbed->m_Width + x].m_Force; @@ -335,21 +331,7 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect) for(int x = 0; x < r.w; x++) { pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x] = ((CLayerSwitch *)this)->m_pSwitchTile[(r.y + y) * m_Width + (r.x + x)]; - if(pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == ENTITY_DOOR + ENTITY_OFFSET || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_HIT_ENABLE || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_HIT_DISABLE || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_SWITCHOPEN || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_SWITCHCLOSE || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_SWITCHTIMEDOPEN || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_SWITCHTIMEDCLOSE || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == ENTITY_LASER_LONG + ENTITY_OFFSET || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == ENTITY_LASER_MEDIUM + ENTITY_OFFSET || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == ENTITY_LASER_SHORT + ENTITY_OFFSET || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_JUMP || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_ADD_TIME || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_SUBTRACT_TIME || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_ALLOW_TELE_GUN || - pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type == TILE_ALLOW_BLUE_TELE_GUN) + if(IsValidSwitchTile(pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Type)) { m_pEditor->m_SwitchNum = pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Number; m_pEditor->m_SwitchDelay = pGrabbed->m_pSwitchTile[y * pGrabbed->m_Width + x].m_Delay; @@ -386,7 +368,7 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect) for(int x = 0; x < r.w; x++) { pGrabbed->m_pTuneTile[y * pGrabbed->m_Width + x] = ((CLayerTune *)this)->m_pTuneTile[(r.y + y) * m_Width + (r.x + x)]; - if(pGrabbed->m_pTuneTile[y * pGrabbed->m_Width + x].m_Type == TILE_TUNE) + if(IsValidTuneTile(pGrabbed->m_pTuneTile[y * pGrabbed->m_Width + x].m_Type)) { m_pEditor->m_TuningNum = pGrabbed->m_pTuneTile[y * pGrabbed->m_Width + x].m_Number; } From 2e5f37c61ba90c11659f6aafe6f0f1db9004bb26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 4 Mar 2023 12:22:47 +0100 Subject: [PATCH 6/9] Don't render switch number and delay for tiles where they are unused --- src/game/client/render_map.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/client/render_map.cpp b/src/game/client/render_map.cpp index 4d1ed1b7e..4c7c43349 100644 --- a/src/game/client/render_map.cpp +++ b/src/game/client/render_map.cpp @@ -575,7 +575,7 @@ void CRenderTools::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float int c = mx + my * w; unsigned char Index = pSwitch[c].m_Number; - if(Index) + if(Index && IsSwitchTileNumberUsed(pSwitch[c].m_Type)) { char aBuf[16]; str_format(aBuf, sizeof(aBuf), "%d", Index); @@ -585,7 +585,7 @@ void CRenderTools::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float } unsigned char Delay = pSwitch[c].m_Delay; - if(Delay) + if(Delay && IsSwitchTileDelayUsed(pSwitch[c].m_Type)) { char aBuf[16]; str_format(aBuf, sizeof(aBuf), "%d", Delay); From 6d23f3e5bd9b319178cb7a2ea0741a00bdfc0116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 3 Mar 2023 18:20:55 +0100 Subject: [PATCH 7/9] Always set number `255` for tele tiles that don't use the number Because code previously cast this number to `bool`, we can't use `0` to denote tele tiles where the number is unused. --- src/game/editor/layer_tiles.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index 014bc7241..16b52bd45 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -1179,12 +1179,20 @@ void CLayerTele::BrushDraw(CLayer *pBrush, float wx, float wy) if((m_pEditor->m_AllowPlaceUnusedTiles || IsValidTeleTile(pTeleLayer->m_pTiles[y * pTeleLayer->m_Width + x].m_Index)) && pTeleLayer->m_pTiles[y * pTeleLayer->m_Width + x].m_Index != TILE_AIR) { - if(m_pEditor->m_TeleNumber != pTeleLayer->m_TeleNum) + if(!IsTeleTileNumberUsed(pTeleLayer->m_pTiles[y * pTeleLayer->m_Width + x].m_Index)) + { + // Tele tile number is unused. Set a known value which is not 0, + // as tiles with number 0 would be ignored by previous versions. + m_pTeleTile[fy * m_Width + fx].m_Number = 255; + } + else if(m_pEditor->m_TeleNumber != pTeleLayer->m_TeleNum) { m_pTeleTile[fy * m_Width + fx].m_Number = m_pEditor->m_TeleNumber; } else if(pTeleLayer->m_pTeleTile[y * pTeleLayer->m_Width + x].m_Number) + { m_pTeleTile[fy * m_Width + fx].m_Number = pTeleLayer->m_pTeleTile[y * pTeleLayer->m_Width + x].m_Number; + } else { if(!m_pEditor->m_TeleNumber) From c4eca1a0bac203f7310196424ded41bd616c6888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 4 Mar 2023 12:22:18 +0100 Subject: [PATCH 8/9] Always set number `0` for switch tiles that don't use the number And use the new `IsSwitchTile(Flags|Number|Delay)Used` functions accordingly. --- src/game/editor/layer_tiles.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index 16b52bd45..42afda57f 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -1721,6 +1721,19 @@ void CLayerSwitch::BrushDraw(CLayer *pBrush, float wx, float wy) m_pSwitchTile[fy * m_Width + fx].m_Flags = pSwitchLayer->m_pTiles[y * pSwitchLayer->m_Width + x].m_Flags; m_pTiles[fy * m_Width + fx].m_Index = pSwitchLayer->m_pTiles[y * pSwitchLayer->m_Width + x].m_Index; m_pTiles[fy * m_Width + fx].m_Flags = pSwitchLayer->m_pTiles[y * pSwitchLayer->m_Width + x].m_Flags; + + if(!IsSwitchTileFlagsUsed(pSwitchLayer->m_pTiles[y * pSwitchLayer->m_Width + x].m_Index)) + { + m_pSwitchTile[fy * m_Width + fx].m_Flags = 0; + } + if(!IsSwitchTileNumberUsed(pSwitchLayer->m_pTiles[y * pSwitchLayer->m_Width + x].m_Index)) + { + m_pSwitchTile[fy * m_Width + fx].m_Number = 0; + } + if(!IsSwitchTileDelayUsed(pSwitchLayer->m_pTiles[y * pSwitchLayer->m_Width + x].m_Index)) + { + m_pSwitchTile[fy * m_Width + fx].m_Delay = 0; + } } else { @@ -1730,16 +1743,6 @@ void CLayerSwitch::BrushDraw(CLayer *pBrush, float wx, float wy) m_pSwitchTile[fy * m_Width + fx].m_Delay = 0; m_pTiles[fy * m_Width + fx].m_Index = 0; } - - if(pSwitchLayer->m_pTiles[y * pSwitchLayer->m_Width + x].m_Index == TILE_FREEZE) - { - m_pSwitchTile[fy * m_Width + fx].m_Flags = 0; - } - else if(pSwitchLayer->m_pTiles[y * pSwitchLayer->m_Width + x].m_Index == TILE_DFREEZE || pSwitchLayer->m_pTiles[y * pSwitchLayer->m_Width + x].m_Index == TILE_DUNFREEZE) - { - m_pSwitchTile[fy * m_Width + fx].m_Flags = 0; - m_pSwitchTile[fy * m_Width + fx].m_Delay = 0; - } } FlagModified(sx, sy, pSwitchLayer->m_Width, pSwitchLayer->m_Height); } From 97052e4752c803395a2a3a3996f218401c2fe733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 4 Mar 2023 12:18:04 +0100 Subject: [PATCH 9/9] Ignore switch tiles that don't use number for free slot finder --- src/game/editor/layer_tiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index 42afda57f..e49956afd 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -1865,7 +1865,7 @@ bool CLayerSwitch::ContainsElementWithId(int Id) { for(int x = 0; x < m_Width; ++x) { - if(m_pSwitchTile[y * m_Width + x].m_Number == Id) + if(IsSwitchTileNumberUsed(m_pSwitchTile[y * m_Width + x].m_Type) && m_pSwitchTile[y * m_Width + x].m_Number == Id) { return true; }