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

Function Unit_SetSpeed

src/unit.c:1902–1942  ·  view source on GitHub ↗

* Set the speed of a Unit. * * @param unit The Unit to operate on. * @param speed The new speed of the unit (a percent value between 0 and 255). */

Source from the content-addressed store, hash-verified

1900 * @param speed The new speed of the unit (a percent value between 0 and 255).
1901 */
1902void Unit_SetSpeed(Unit *unit, uint16 speed)
1903{
1904 uint16 speedPerTick;
1905
1906 assert(unit != NULL);
1907
1908 speedPerTick = 0;
1909
1910 unit->speed = 0;
1911 unit->speedRemainder = 0;
1912 unit->speedPerTick = 0;
1913
1914 if (unit->o.type == UNIT_HARVESTER) {
1915 speed = ((255 - unit->amount) * speed) / 256;
1916 }
1917
1918 if (speed == 0 || speed >= 256) {
1919 unit->movingSpeed = 0;
1920 return;
1921 }
1922
1923 unit->movingSpeed = speed & 0xFF;
1924 speed = g_table_unitInfo[unit->o.type].movingSpeedFactor * speed / 256;
1925
1926 /* Units in the air don't feel the effect of gameSpeed */
1927 if (g_table_unitInfo[unit->o.type].movementType != MOVEMENT_WINGER) {
1928 speed = Tools_AdjustToGameSpeed(speed, 1, 255, false);
1929 }
1930
1931 speedPerTick = speed << 4;
1932 speed = speed >> 4;
1933
1934 if (speed != 0) {
1935 speedPerTick = 255;
1936 } else {
1937 speed = 1;
1938 }
1939
1940 unit->speed = speed & 0xFF;
1941 unit->speedPerTick = speedPerTick & 0xFF;
1942}
1943
1944/**
1945 * Create a new bullet Unit.

Callers 8

Scenario_Load_UnitFunction · 0.85
Unit_CreateFunction · 0.85
Unit_StartMovementFunction · 0.85
Unit_MoveFunction · 0.85
Script_Unit_StopFunction · 0.85
Script_Unit_SetSpeedFunction · 0.85
Script_Unit_MoveToTargetFunction · 0.85

Calls 1

Tools_AdjustToGameSpeedFunction · 0.85

Tested by

no test coverage detected