MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Structure_Find

Function Structure_Find

src/pool/structure.c:40–81  ·  view source on GitHub ↗

* Find the first matching Structure based on the PoolFindStruct filter data. * * @param find A pointer to a PoolFindStruct which contains filter data and * last known tried index. Calling this functions multiple times with the * same 'find' parameter walks over all possible values matching the filter. * @return The Structure, or NULL if nothing matches (anymore). */

Source from the content-addressed store, hash-verified

38 * @return The Structure, or NULL if nothing matches (anymore).
39 */
40Structure *Structure_Find(PoolFindStruct *find)
41{
42 if (find->index >= g_structureFindCount + 3 && find->index != 0xFFFF) return NULL;
43 find->index++; /* First, we always go to the next index */
44
45 assert(g_structureFindCount <= STRUCTURE_INDEX_MAX_SOFT);
46 for (; find->index < g_structureFindCount + 3; find->index++) {
47 Structure *s = NULL;
48
49 if (find->index < g_structureFindCount) {
50 s = g_structureFindArray[find->index];
51 } else {
52 /* There are 3 special structures that are never in the Find array */
53 assert(find->index - g_structureFindCount < 3);
54 switch (find->index - g_structureFindCount) {
55 case 0:
56 s = Structure_Get_ByIndex(STRUCTURE_INDEX_WALL);
57 if (s->o.index != STRUCTURE_INDEX_WALL) continue;
58 break;
59
60 case 1:
61 s = Structure_Get_ByIndex(STRUCTURE_INDEX_SLAB_2x2);
62 if (s->o.index != STRUCTURE_INDEX_SLAB_2x2) continue;
63 break;
64
65 case 2:
66 s = Structure_Get_ByIndex(STRUCTURE_INDEX_SLAB_1x1);
67 if (s->o.index != STRUCTURE_INDEX_SLAB_1x1) continue;
68 break;
69 }
70 }
71 if (s == NULL) continue;
72
73 if (s->o.flags.s.isNotOnMap && g_validateStrictIfZero == 0) continue;
74 if (find->houseID != HOUSE_INVALID && find->houseID != s->o.houseID) continue;
75 if (find->type != STRUCTURE_INDEX_INVALID && find->type != s->o.type) continue;
76
77 return s;
78 }
79
80 return NULL;
81}
82
83/**
84 * Initialize the Structure array.

Callers 15

GameLoop_StructureFunction · 0.85
Map_FindLocationTileFunction · 0.85
Map_SelectNextFunction · 0.85
GameLoop_HouseFunction · 0.85
Unit_FindClosestRefineryFunction · 0.85
Unit_UntargetMeFunction · 0.85

Calls 1

Structure_Get_ByIndexFunction · 0.85

Tested by

no test coverage detected