# Fixed Point Maths

## version 5 by Michael Callaghan

Example: *** Ballistics - Shows the use of real numbers in ballistic calculations

"Ballistics" by Michael Callaghan

Include Fixed Point Maths by Michael Callaghan.

The Firing Range is a room.

The large gun is in the firing range. The description is "A large field artillery gun. Towards the base of the gun you find a small brass handle that seems to be turnable. By it is a note that says hit your target at a range of 1,918 metres. You have 5 projectiles to fire. When you are ready, simply fire the gun."

The large gun has a number called angle. The angle of the large gun is 12.
The large gun has a number called projectiles. The projectiles of the gun is 5.

A brass handle is part of the large gun. The description is "The brass handle can be turned to adjust the angle of the gun. A pointer shows the angle that you have set. It currently points to [angle of the large gun] degrees."

say "Try turning the handle to a number."

say "Try turning the handle to a number."

Understand "turn [something] to [a number]" as adjusting it to.
Understand "turn [something] to [a number] degrees" as adjusting it to.

Adjusting it to is an action applying to one thing and one number.

if the noun is the gun:
say "Try turning the handle to a number." instead.

if the number understood is less than 1 or the number understood is greater than 90:
say "That is physically impossible. The gun can be set to an angle from 1 to 90 degrees." instead.

now the angle of the gun is the number understood.

say "You turn the handle and set the angle of the gun to [angle of the gun] degrees."

Understand "fire [something]" as firing. Firing is an action applying to one thing.

Check firing:
if the noun is not the gun:
say "Only the gun can be fired."

Carry out firing:
decrease the projectiles of the gun by 1;

Report firing:
say "The gun recoils violently and lets out a deep throated roar as the projectile is launched.";
say "After a few seconds, you see the projectile land at [distance as an integer] metres.";
if the distance as an integer is 1918:
end the story finally saying "Congratulations, you have passed your basic field artillery exam.";
if the distance as an integer is less than 10:
say "The projectile goes straight up and comes down destroying both you and the gun.";
end the story finally saying "You have failed in a spectacular way.";
if the projectiles of the gun is 0:
say "You are out of projectiles.";
end the story finally saying "You have failed your basic field artillery exam."

To decide what real number is distance:
let velocity be 200.0000;
let gravity be 9.8100;
let cosangle be the cosine of the angle of the gun;
let sinangle be the sine of the angle of the gun;
let result be velocity real times cosangle;
let result be result real divided by gravity;
let temp1 be 4 real times gravity;
let temp1 be temp1 real times sinangle;
let temp2 be velocity real times sinangle;
let temp2 be temp2 to the power 2;
let temp1 be temp1 real plus temp2;
let temp1 be the real square root of temp1;
let result be result real times temp1;
decide on result.

Test me with "x gun / x handle / turn handle to 45 / fire gun / turn handle to 30 / fire gun / turn handle to 36 / fire gun / turn handle to 35 / fire gun".