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

Function Unit_SetOrientation

src/unit.c:1671–1696  ·  view source on GitHub ↗

* Set the new orientation of the unit. * * @param unit The Unit to operate on. * @param orientation The new orientation of the unit. * @param rotateInstantly If true, rotation is instant. Else the unit turns over the next few ticks slowly. * @param level 0 = base, 1 = top (turret etc). */

Source from the content-addressed store, hash-verified

1669 * @param level 0 = base, 1 = top (turret etc).
1670 */
1671void Unit_SetOrientation(Unit *unit, int8 orientation, bool rotateInstantly, uint16 level)
1672{
1673 int16 diff;
1674
1675 assert(level == 0 || level == 1);
1676
1677 if (unit == NULL) return;
1678
1679 unit->orientation[level].speed = 0;
1680 unit->orientation[level].target = orientation;
1681
1682 if (rotateInstantly) {
1683 unit->orientation[level].current = orientation;
1684 return;
1685 }
1686
1687 if (unit->orientation[level].current == orientation) return;
1688
1689 unit->orientation[level].speed = g_table_unitInfo[unit->o.type].turningSpeed * 4;
1690
1691 diff = orientation - unit->orientation[level].current;
1692
1693 if ((diff > -128 && diff < 0) || diff > 128) {
1694 unit->orientation[level].speed = -unit->orientation[level].speed;
1695 }
1696}
1697
1698/**
1699 * Selects the given unit.

Callers 14

Scenario_Load_UnitFunction · 0.85
GameLoop_UnitFunction · 0.85
Unit_CreateFunction · 0.85
Unit_StartMovementFunction · 0.85
Unit_MoveFunction · 0.85
Script_Unit_MoveToTargetFunction · 0.85
Script_Unit_RotateFunction · 0.85
Script_Unit_SetTargetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected