MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Script_Unit_RandomSoldier

Function Script_Unit_RandomSoldier

src/script/unit.c:48–69  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

46 * @return 1 if a new Unit has been created, 0 otherwise.
47 */
48uint16 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.

Callers

nothing calls this directly

Calls 4

Tools_Random_256Function · 0.85
Tile_MoveByRandomFunction · 0.85
Unit_CreateFunction · 0.85
Unit_SetActionFunction · 0.85

Tested by

no test coverage detected