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

Function Script_Unit_IdleAction

src/script/unit.c:1748–1776  ·  view source on GitHub ↗

* Perform a random action when we are sitting idle, like rotating around. * * Stack: *none*. * * @param script The script engine to operate on. * @return The value 0. Always. */

Source from the content-addressed store, hash-verified

1746 * @return The value 0. Always.
1747 */
1748uint16 Script_Unit_IdleAction(ScriptEngine *script)
1749{
1750 Unit *u;
1751 uint16 random;
1752 uint16 movementType;
1753 uint16 i;
1754
1755 VARIABLE_NOT_USED(script);
1756
1757 u = g_scriptCurrentUnit;
1758
1759 random = Tools_RandomLCG_Range(0, 10);
1760 movementType = g_table_unitInfo[u->o.type].movementType;
1761
1762 if (movementType != MOVEMENT_FOOT && movementType != MOVEMENT_TRACKED && movementType != MOVEMENT_WHEELED) return 0;
1763
1764 if (movementType == MOVEMENT_FOOT && random > 8) {
1765 u->spriteOffset = Tools_Random_256() & 0x3F;
1766 Unit_UpdateMap(2, u);
1767 }
1768
1769 if (random > 2) return 0;
1770
1771 /* Ensure the order of Tools_Random_256() calls. */
1772 i = (Tools_Random_256() & 1) == 0 ? 1 : 0;
1773 Unit_SetOrientation(u, Tools_Random_256(), false, i);
1774
1775 return 0;
1776}
1777
1778/**
1779 * Makes the current unit to go to the closest structure of the given type.

Callers

nothing calls this directly

Calls 4

Tools_RandomLCG_RangeFunction · 0.85
Tools_Random_256Function · 0.85
Unit_UpdateMapFunction · 0.85
Unit_SetOrientationFunction · 0.85

Tested by

no test coverage detected