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.
This commit is contained in:
Robert Müller 2023-03-03 18:20:08 +01:00
parent 1d9cbba326
commit 60c0da7c4d
4 changed files with 18 additions and 68 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}