* Pickup a unit (either from structure or on the map). The unit that does the * picking up returns the unit to his last position. * * Stack: *none*. * * @param script The script engine to operate on. * @return The value 0. Always. */
| 223 | * @return The value 0. Always. |
| 224 | */ |
| 225 | uint16 Script_Unit_Pickup(ScriptEngine *script) |
| 226 | { |
| 227 | Unit *u; |
| 228 | |
| 229 | VARIABLE_NOT_USED(script); |
| 230 | |
| 231 | u = g_scriptCurrentUnit; |
| 232 | |
| 233 | if (u->o.linkedID != 0xFF) return 0; |
| 234 | |
| 235 | switch (Tools_Index_GetType(u->targetMove)) { |
| 236 | case IT_STRUCTURE: { |
| 237 | Structure *s; |
| 238 | Unit *u2; |
| 239 | |
| 240 | s = Tools_Index_GetStructure(u->targetMove); |
| 241 | |
| 242 | /* There was nothing to pickup here */ |
| 243 | if (s->state != STRUCTURE_STATE_READY) { |
| 244 | Object_Script_Variable4_Clear(&u->o); |
| 245 | u->targetMove = 0; |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | u->o.flags.s.inTransport = true; |
| 250 | |
| 251 | Object_Script_Variable4_Clear(&u->o); |
| 252 | u->targetMove = 0; |
| 253 | |
| 254 | u2 = Unit_Get_ByIndex(s->o.linkedID); |
| 255 | |
| 256 | /* Pickup the unit */ |
| 257 | u->o.linkedID = u2->o.index & 0xFF; |
| 258 | s->o.linkedID = u2->o.linkedID; |
| 259 | u2->o.linkedID = 0xFF; |
| 260 | |
| 261 | if (s->o.linkedID == 0xFF) Structure_SetState(s, STRUCTURE_STATE_IDLE); |
| 262 | |
| 263 | /* Check if the unit has a return-to position or try to find spice in case of a harvester */ |
| 264 | if (u2->targetLast.x != 0 || u2->targetLast.y != 0) { |
| 265 | u->targetMove = Tools_Index_Encode(Tile_PackTile(u2->targetLast), IT_TILE); |
| 266 | } else if (u2->o.type == UNIT_HARVESTER && Unit_GetHouseID(u2) != g_playerHouseID) { |
| 267 | u->targetMove = Tools_Index_Encode(Map_SearchSpice(Tile_PackTile(u->o.position), 20), IT_TILE); |
| 268 | } |
| 269 | |
| 270 | Unit_UpdateMap(2, u); |
| 271 | |
| 272 | return 1; |
| 273 | } |
| 274 | |
| 275 | case IT_UNIT: { |
| 276 | Unit *u2; |
| 277 | Structure *s = NULL; |
| 278 | PoolFindStruct find; |
| 279 | int16 minDistance = 0; |
| 280 | |
| 281 | u2 = Tools_Index_GetUnit(u->targetMove); |
| 282 |
nothing calls this directly
no test coverage detected