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

Function Script_Unit_SetTarget

src/script/unit.c:834–862  ·  view source on GitHub ↗

* Set a new target, and rotate towards him if needed. * * Stack: 1 - An encoded tile of the unit/tile to target. * * @param script The script engine to operate on. * @return The new target. */

Source from the content-addressed store, hash-verified

832 * @return The new target.
833 */
834uint16 Script_Unit_SetTarget(ScriptEngine *script)
835{
836 Unit *u;
837 uint16 target;
838 tile32 tile;
839 int8 orientation;
840
841 u = g_scriptCurrentUnit;
842
843 target = STACK_PEEK(1);
844
845 if (target == 0 || !Tools_Index_IsValid(target)) {
846 u->targetAttack = 0;
847 return 0;
848 }
849
850 tile = Tools_Index_GetTile(target);
851
852 orientation = Tile_GetDirection(u->o.position, tile);
853
854 u->targetAttack = target;
855 if (!g_table_unitInfo[u->o.type].o.flags.hasTurret) {
856 u->targetMove = target;
857 Unit_SetOrientation(u, orientation, false, 0);
858 }
859 Unit_SetOrientation(u, orientation, false, 1);
860
861 return u->targetAttack;
862}
863
864/**
865 * Sets the action for the current unit.

Callers

nothing calls this directly

Calls 4

Tools_Index_IsValidFunction · 0.85
Tools_Index_GetTileFunction · 0.85
Tile_GetDirectionFunction · 0.85
Unit_SetOrientationFunction · 0.85

Tested by

no test coverage detected