Skip to content

Commit

Permalink
addFlagPosition: Check if FlagPosition is already in list
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Apr 14, 2021
1 parent 583630f commit db2b23d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/objmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,27 @@ bool createFlagPosition(FLAG_POSITION **ppsNew, UDWORD player)
return true;
}

static bool isFlagPositionInList(FLAG_POSITION *psFlagPosToAdd)
{
ASSERT_OR_RETURN(false, psFlagPosToAdd != nullptr, "Invalid FlagPosition pointer");
ASSERT_OR_RETURN(false, psFlagPosToAdd->player < MAX_PLAYERS, "Invalid FlagPosition player: %u", psFlagPosToAdd->player);
for (FLAG_POSITION* psCurr = apsFlagPosLists[psFlagPosToAdd->player]; (psCurr != nullptr); psCurr = psCurr->psNext)
{
if (psCurr == psFlagPosToAdd)
{
return true;
}
}
return false;
}

/* add the Flag Position to the Flag Position Lists */
void addFlagPosition(FLAG_POSITION *psFlagPosToAdd)
{
ASSERT_OR_RETURN(, psFlagPosToAdd != nullptr, "Invalid FlagPosition pointer");
ASSERT_OR_RETURN(, psFlagPosToAdd->coords.x != ~0, "flag has invalid position");
ASSERT_OR_RETURN(, psFlagPosToAdd->player < MAX_PLAYERS, "Invalid FlagPosition player: %u", psFlagPosToAdd->player);
ASSERT_OR_RETURN(, !isFlagPositionInList(psFlagPosToAdd), "FlagPosition is already in the list!");

psFlagPosToAdd->psNext = apsFlagPosLists[psFlagPosToAdd->player];
apsFlagPosLists[psFlagPosToAdd->player] = psFlagPosToAdd;
Expand Down

0 comments on commit db2b23d

Please sign in to comment.