* 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). */
| 1669 | * @param level 0 = base, 1 = top (turret etc). |
| 1670 | */ |
| 1671 | void 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. |
no outgoing calls
no test coverage detected