* Call a specified type of unit owned by the house to you. * * @param type The type of the Unit to find. * @param houseID The houseID of the Unit to find. * @param target To where the found Unit should move. * @param createCarryall Create a carryall if none found. * @return The found Unit, or NULL if none found. */
| 2129 | * @return The found Unit, or NULL if none found. |
| 2130 | */ |
| 2131 | Unit *Unit_CallUnitByType(UnitType type, uint8 houseID, uint16 target, bool createCarryall) |
| 2132 | { |
| 2133 | PoolFindStruct find; |
| 2134 | Unit *unit = NULL; |
| 2135 | |
| 2136 | find.houseID = houseID; |
| 2137 | find.type = type; |
| 2138 | find.index = 0xFFFF; |
| 2139 | |
| 2140 | while (true) { |
| 2141 | Unit *u; |
| 2142 | |
| 2143 | u = Unit_Find(&find); |
| 2144 | if (u == NULL) break; |
| 2145 | if (u->o.linkedID != 0xFF) continue; |
| 2146 | if (u->targetMove != 0) continue; |
| 2147 | unit = u; |
| 2148 | } |
| 2149 | |
| 2150 | if (createCarryall && unit == NULL && type == UNIT_CARRYALL) { |
| 2151 | tile32 position; |
| 2152 | |
| 2153 | g_validateStrictIfZero++; |
| 2154 | position.x = 0; |
| 2155 | position.y = 0; |
| 2156 | unit = Unit_Create(UNIT_INDEX_INVALID, type, houseID, position, 96); |
| 2157 | g_validateStrictIfZero--; |
| 2158 | |
| 2159 | if (unit != NULL) unit->o.flags.s.byScenario = true; |
| 2160 | } |
| 2161 | |
| 2162 | if (unit != NULL) { |
| 2163 | unit->targetMove = target; |
| 2164 | |
| 2165 | Object_Script_Variable4_Set(&unit->o, target); |
| 2166 | } |
| 2167 | |
| 2168 | return unit; |
| 2169 | } |
| 2170 | |
| 2171 | /** |
| 2172 | * Handles what happens when the given unit enters into the given structure. |
no test coverage detected