* Create a new soldier unit. * * Stack: 1 - Action for the new Unit. * * @param script The script engine to operate on. * @return 1 if a new Unit has been created, 0 otherwise. */
| 46 | * @return 1 if a new Unit has been created, 0 otherwise. |
| 47 | */ |
| 48 | uint16 Script_Unit_RandomSoldier(ScriptEngine *script) |
| 49 | { |
| 50 | Unit *u; |
| 51 | Unit *nu; |
| 52 | tile32 position; |
| 53 | |
| 54 | u = g_scriptCurrentUnit; |
| 55 | |
| 56 | if (Tools_Random_256() >= g_table_unitInfo[u->o.type].o.spawnChance) return 0; |
| 57 | |
| 58 | position = Tile_MoveByRandom(u->o.position, 20, true); |
| 59 | |
| 60 | nu = Unit_Create(UNIT_INDEX_INVALID, UNIT_SOLDIER, u->o.houseID, position, Tools_Random_256()); |
| 61 | |
| 62 | if (nu == NULL) return 0; |
| 63 | |
| 64 | nu->deviated = u->deviated; |
| 65 | |
| 66 | Unit_SetAction(nu, STACK_PEEK(1)); |
| 67 | |
| 68 | return 1; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Gets the best target for the current unit. |
nothing calls this directly
no test coverage detected