Refactor CRaceHelper::IsStart function

Avoid duplicate calculation by extraction result of `GetPureMapIndex` in variable.

Rename variable `Indices` to `Index`.

Include `vector` instead of `list`, as the former is used but the latter is not.
This commit is contained in:
Robert Müller 2024-08-04 14:03:54 +02:00
parent 00d941a309
commit 6dba8851a5

View file

@ -1,5 +1,5 @@
#include <cctype> #include <cctype>
#include <list> #include <vector>
#include <game/client/gameclient.h> #include <game/client/gameclient.h>
#include <game/mapitems.h> #include <game/mapitems.h>
@ -78,18 +78,21 @@ bool CRaceHelper::IsStart(CGameClient *pClient, vec2 Prev, vec2 Pos)
{ {
std::vector<int> vIndices = pCollision->GetMapIndices(Prev, Pos); std::vector<int> vIndices = pCollision->GetMapIndices(Prev, Pos);
if(!vIndices.empty()) if(!vIndices.empty())
for(int &Indice : vIndices) {
for(const int Index : vIndices)
{ {
if(pCollision->GetTileIndex(Indice) == TILE_START) if(pCollision->GetTileIndex(Index) == TILE_START)
return true; return true;
if(pCollision->GetFTileIndex(Indice) == TILE_START) if(pCollision->GetFTileIndex(Index) == TILE_START)
return true; return true;
} }
}
else else
{ {
if(pCollision->GetTileIndex(pCollision->GetPureMapIndex(Pos)) == TILE_START) const int Index = pCollision->GetPureMapIndex(Pos);
if(pCollision->GetTileIndex(Index) == TILE_START)
return true; return true;
if(pCollision->GetFTileIndex(pCollision->GetPureMapIndex(Pos)) == TILE_START) if(pCollision->GetFTileIndex(Index) == TILE_START)
return true; return true;
} }
} }