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

Function Unit_Rotate

src/unit.c:65–96  ·  view source on GitHub ↗

* Rotate a unit (or his top). * * @param unit The Unit to operate on. * @param level 0 = base, 1 = top (turret etc). */

Source from the content-addressed store, hash-verified

63 * @param level 0 = base, 1 = top (turret etc).
64 */
65static void Unit_Rotate(Unit *unit, uint16 level)
66{
67 int8 target;
68 int8 current;
69 int8 newCurrent;
70 int16 diff;
71
72 assert(level == 0 || level == 1);
73
74 if (unit->orientation[level].speed == 0) return;
75
76 target = unit->orientation[level].target;
77 current = unit->orientation[level].current;
78 diff = target - current;
79
80 if (diff > 128) diff -= 256;
81 if (diff < -128) diff += 256;
82 diff = abs(diff);
83
84 newCurrent = current + unit->orientation[level].speed;
85
86 if (abs(unit->orientation[level].speed) >= diff) {
87 unit->orientation[level].speed = 0;
88 newCurrent = target;
89 }
90
91 unit->orientation[level].current = newCurrent;
92
93 if (Orientation_Orientation256ToOrientation16(newCurrent) == Orientation_Orientation256ToOrientation16(current) && Orientation_Orientation256ToOrientation8(newCurrent) == Orientation_Orientation256ToOrientation8(current)) return;
94
95 Unit_UpdateMap(2, unit);
96}
97
98static void Unit_MovementTick(Unit *unit)
99{

Callers 1

GameLoop_UnitFunction · 0.85

Tested by

no test coverage detected