Skip to content

Commit

Permalink
Refactor fillStructureList to use std::vector
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagorb committed Jan 30, 2021
1 parent f831379 commit 11541ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/hci.cpp
Expand Up @@ -1699,8 +1699,13 @@ static void intAddObjectStats(BASE_OBJECT *psObj, UDWORD id)
//determine the Structures that can be built
if (objMode == IOBJ_BUILD)
{
numStatsListEntries = fillStructureList(apsStructStatsList,
selectedPlayer, MAXSTRUCTURES - 1, showFavorites);
auto structureList = fillStructureList(selectedPlayer, MAXSTRUCTURES - 1, showFavorites);
numStatsListEntries = structureList.size();
size_t current = 0;
for (auto structure: structureList)
{
apsStructStatsList[current++] = structure;
}

ppsStatsList = (BASE_STATS **)apsStructStatsList;
}
Expand Down
14 changes: 7 additions & 7 deletions src/structure.cpp
Expand Up @@ -3841,9 +3841,10 @@ fills the list with Structure that can be built. There is a limit on how many ca
be built at any one time. Pass back the number available.
There is now a limit of how many of each type of structure are allowed per mission
*/
UDWORD fillStructureList(STRUCTURE_STATS **ppList, UDWORD selectedPlayer, UDWORD limit, bool showFavorites)
std::vector<STRUCTURE_STATS *> fillStructureList(UDWORD selectedPlayer, UDWORD limit, bool showFavorites)
{
UDWORD inc, count;
std::vector<STRUCTURE_STATS *> structureList;
UDWORD inc;
bool researchModule, factoryModule, powerModule;
STRUCTURE *psCurr;
STRUCTURE_STATS *psBuilding;
Expand Down Expand Up @@ -3871,7 +3872,6 @@ UDWORD fillStructureList(STRUCTURE_STATS **ppList, UDWORD selectedPlayer, UDWORD
}
}

count = 0;
//set the list of Structures to build
for (inc = 0; inc < numStructureStats; inc++)
{
Expand Down Expand Up @@ -3944,15 +3944,15 @@ UDWORD fillStructureList(STRUCTURE_STATS **ppList, UDWORD selectedPlayer, UDWORD
}

debug(LOG_NEVER, "adding %s (%x)", getStatsName(psBuilding), apStructTypeLists[selectedPlayer][inc]);
ppList[count++] = psBuilding;
if (count == limit)
structureList.push_back(psBuilding);
if (structureList.size() == limit)
{
return count;
return structureList;
}
}
}
}
return count;
return structureList;
}


Expand Down
2 changes: 1 addition & 1 deletion src/structure.h
Expand Up @@ -117,7 +117,7 @@ bool destroyStruct(STRUCTURE *psDel, unsigned impactTime);
bool removeStruct(STRUCTURE *psDel, bool bDestroy);

//fills the list with Structures that can be built
UDWORD fillStructureList(STRUCTURE_STATS **ppList, UDWORD selectedPlayer, UDWORD limit, bool showFavorites);
std::vector<STRUCTURE_STATS *> fillStructureList(UDWORD selectedPlayer, UDWORD limit, bool showFavorites);

/// Checks if the two structures would be too close to build together.
bool isBlueprintTooClose(STRUCTURE_STATS const *stats1, Vector2i pos1, uint16_t dir1, STRUCTURE_STATS const *stats2, Vector2i pos2, uint16_t dir2);
Expand Down

0 comments on commit 11541ec

Please sign in to comment.