Skip to content

Commit 11541ec

Browse files
committed
Refactor fillStructureList to use std::vector
1 parent f831379 commit 11541ec

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/hci.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1699,8 +1699,13 @@ static void intAddObjectStats(BASE_OBJECT *psObj, UDWORD id)
16991699
//determine the Structures that can be built
17001700
if (objMode == IOBJ_BUILD)
17011701
{
1702-
numStatsListEntries = fillStructureList(apsStructStatsList,
1703-
selectedPlayer, MAXSTRUCTURES - 1, showFavorites);
1702+
auto structureList = fillStructureList(selectedPlayer, MAXSTRUCTURES - 1, showFavorites);
1703+
numStatsListEntries = structureList.size();
1704+
size_t current = 0;
1705+
for (auto structure: structureList)
1706+
{
1707+
apsStructStatsList[current++] = structure;
1708+
}
17041709

17051710
ppsStatsList = (BASE_STATS **)apsStructStatsList;
17061711
}

src/structure.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -3841,9 +3841,10 @@ fills the list with Structure that can be built. There is a limit on how many ca
38413841
be built at any one time. Pass back the number available.
38423842
There is now a limit of how many of each type of structure are allowed per mission
38433843
*/
3844-
UDWORD fillStructureList(STRUCTURE_STATS **ppList, UDWORD selectedPlayer, UDWORD limit, bool showFavorites)
3844+
std::vector<STRUCTURE_STATS *> fillStructureList(UDWORD selectedPlayer, UDWORD limit, bool showFavorites)
38453845
{
3846-
UDWORD inc, count;
3846+
std::vector<STRUCTURE_STATS *> structureList;
3847+
UDWORD inc;
38473848
bool researchModule, factoryModule, powerModule;
38483849
STRUCTURE *psCurr;
38493850
STRUCTURE_STATS *psBuilding;
@@ -3871,7 +3872,6 @@ UDWORD fillStructureList(STRUCTURE_STATS **ppList, UDWORD selectedPlayer, UDWORD
38713872
}
38723873
}
38733874

3874-
count = 0;
38753875
//set the list of Structures to build
38763876
for (inc = 0; inc < numStructureStats; inc++)
38773877
{
@@ -3944,15 +3944,15 @@ UDWORD fillStructureList(STRUCTURE_STATS **ppList, UDWORD selectedPlayer, UDWORD
39443944
}
39453945

39463946
debug(LOG_NEVER, "adding %s (%x)", getStatsName(psBuilding), apStructTypeLists[selectedPlayer][inc]);
3947-
ppList[count++] = psBuilding;
3948-
if (count == limit)
3947+
structureList.push_back(psBuilding);
3948+
if (structureList.size() == limit)
39493949
{
3950-
return count;
3950+
return structureList;
39513951
}
39523952
}
39533953
}
39543954
}
3955-
return count;
3955+
return structureList;
39563956
}
39573957

39583958

src/structure.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bool destroyStruct(STRUCTURE *psDel, unsigned impactTime);
117117
bool removeStruct(STRUCTURE *psDel, bool bDestroy);
118118

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

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

0 commit comments

Comments
 (0)