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

Function Script_Unit_Rotate

src/script/unit.c:726–759  ·  view source on GitHub ↗

* Rotate the unit to aim at the enemy. * * Stack: *none*. * * @param script The script engine to operate on. * @return 0 if the enemy is no longer there or if we are looking at him, 1 otherwise. */

Source from the content-addressed store, hash-verified

724 * @return 0 if the enemy is no longer there or if we are looking at him, 1 otherwise.
725 */
726uint16 Script_Unit_Rotate(ScriptEngine *script)
727{
728 const UnitInfo *ui;
729 Unit *u;
730 uint16 index;
731 int8 current;
732 tile32 tile;
733 int8 orientation;
734
735 VARIABLE_NOT_USED(script);
736
737 u = g_scriptCurrentUnit;
738 ui = &g_table_unitInfo[u->o.type];
739
740 if (ui->movementType != MOVEMENT_WINGER && (u->currentDestination.x != 0 || u->currentDestination.y != 0)) return 1;
741
742 index = ui->o.flags.hasTurret ? 1 : 0;
743
744 /* Check if we are already rotating */
745 if (u->orientation[index].speed != 0) return 1;
746 current = u->orientation[index].current;
747
748 if (!Tools_Index_IsValid(u->targetAttack)) return 0;
749
750 /* Check where we should rotate to */
751 tile = Tools_Index_GetTile(u->targetAttack);
752 orientation = Tile_GetDirection(u->o.position, tile);
753
754 /* If we aren't already looking at it, rotate */
755 if (orientation == current) return 0;
756 Unit_SetOrientation(u, orientation, false, index);
757
758 return 1;
759}
760
761/**
762 * Get the direction to a tile or our current direction.

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