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

Function Script_Unit_SetDestination

src/script/unit.c:796–824  ·  view source on GitHub ↗

* Set the new destination of the unit. * * Stack: 1 - An encoded index where to move to. * * @param script The script engine to operate on. * @return The value 0. Always. */

Source from the content-addressed store, hash-verified

794 * @return The value 0. Always.
795 */
796uint16 Script_Unit_SetDestination(ScriptEngine *script)
797{
798 Unit *u;
799 uint16 encoded;
800
801 u = g_scriptCurrentUnit;
802 encoded = STACK_PEEK(1);
803
804 if (encoded == 0 || !Tools_Index_IsValid(encoded)) {
805 u->targetMove = 0;
806 return 0;
807 }
808
809 if (u->o.type == UNIT_HARVESTER) {
810 Structure *s;
811
812 s = Tools_Index_GetStructure(encoded);
813 if (s == NULL) {
814 u->targetMove = encoded;
815 u->route[0] = 0xFF;
816 return 0;
817 }
818
819 if (s->o.script.variables[4] != 0) return 0;
820 }
821
822 Unit_SetDestination(u, encoded);
823 return 0;
824}
825
826/**
827 * Set a new target, and rotate towards him if needed.

Callers

nothing calls this directly

Calls 3

Tools_Index_IsValidFunction · 0.85
Tools_Index_GetStructureFunction · 0.85
Unit_SetDestinationFunction · 0.85

Tested by

no test coverage detected