* Move the unit to the first available structure it can find of the required * type. * * Stack: 1 - Type of structure. * * @param script The script engine to operate on. * @return An encoded structure index. */
| 1362 | * @return An encoded structure index. |
| 1363 | */ |
| 1364 | uint16 Script_Unit_MoveToStructure(ScriptEngine *script) |
| 1365 | { |
| 1366 | Unit *u; |
| 1367 | PoolFindStruct find; |
| 1368 | |
| 1369 | u = g_scriptCurrentUnit; |
| 1370 | |
| 1371 | if (u->o.linkedID != 0xFF) { |
| 1372 | Structure *s; |
| 1373 | |
| 1374 | s = Tools_Index_GetStructure(Unit_Get_ByIndex(u->o.linkedID)->originEncoded); |
| 1375 | |
| 1376 | if (s != NULL && s->state == STRUCTURE_STATE_IDLE && s->o.script.variables[4] == 0) { |
| 1377 | uint16 encoded; |
| 1378 | |
| 1379 | encoded = Tools_Index_Encode(s->o.index, IT_STRUCTURE); |
| 1380 | |
| 1381 | Object_Script_Variable4_Link(Tools_Index_Encode(u->o.index, IT_UNIT), encoded); |
| 1382 | |
| 1383 | u->targetMove = u->o.script.variables[4]; |
| 1384 | |
| 1385 | return encoded; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | find.houseID = Unit_GetHouseID(u); |
| 1390 | find.index = 0xFFFF; |
| 1391 | find.type = STACK_PEEK(1); |
| 1392 | |
| 1393 | while (true) { |
| 1394 | Structure *s; |
| 1395 | uint16 encoded; |
| 1396 | |
| 1397 | s = Structure_Find(&find); |
| 1398 | if (s == NULL) break; |
| 1399 | |
| 1400 | if (s->state != STRUCTURE_STATE_IDLE) continue; |
| 1401 | if (s->o.script.variables[4] != 0) continue; |
| 1402 | |
| 1403 | encoded = Tools_Index_Encode(s->o.index, IT_STRUCTURE); |
| 1404 | |
| 1405 | Object_Script_Variable4_Link(Tools_Index_Encode(u->o.index, IT_UNIT), encoded); |
| 1406 | |
| 1407 | u->targetMove = encoded; |
| 1408 | |
| 1409 | return encoded; |
| 1410 | } |
| 1411 | |
| 1412 | return 0; |
| 1413 | } |
| 1414 | |
| 1415 | /** |
| 1416 | * Gets the amount of the unit linked to current unit, or current unit if not linked. |
nothing calls this directly
no test coverage detected