* 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). */
| 38 | * @return The Structure, or NULL if nothing matches (anymore). |
| 39 | */ |
| 40 | Structure *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. |
no test coverage detected