# [i7] Fuel management

I’d like to add a fuel management angle to my game.

You sail a yacht that uses a special hand-wavium engine. (You can guess from the name how that works!) It sucks in sea water and forces it out as thrust. It also gathers power from the operation, but the faster you go the more power you use and the less power you gather. i.e.:

Go slow - takes longer to get to the destination but stored power is built up.
Go fast - takes less turns to get to the destination but batteries are run down and may be depleted.
Medium speed - a sweet point balancing the two, where energy usage and energy harvesting are balanced.

I had something working in an old (Inform 6) version of my game but haven’t been able to do the same under Inform 7.

Any help appreciated.

1 Like

Here’s a try:

There is a number variable called distance travelled.

Yacht is a room. "You are [distance travelled] nautical miles from shore. The only thing to look at is the cool engine."

The engine is scenery in the yacht. The engine has a number called speed. The engine has a number called stored power. The engine has a number called absorption. The speed of the engine is 5. The absorption of the engine is 3. The stored power of the engine is 10.

The description of the engine is "The engine is currently chugging along at [speed] knots and has [stored power] megajoules of energy stored up. I have no idea whether those units are remotely commensurable."

Every turn:
if speed of the engine is greater than stored power of the engine plus absorption of the engine:
let N be stored power of the engine plus absorption of the engine;
say "After [N] nautical miles the engine conks out. You'll have to slow down so as to absorb more power.";
increase distance travelled by N;
now stored power of the engine is 0;
otherwise:
increase distance travelled by speed of the engine;
increase stored power of the engine by absorption of the engine;
decrease stored power of the engine by speed of the engine;
say "You go [speed of the engine] nautical miles and are now [distance travelled] nautical miles from shore."

Setting it numerically to is an action applying to one thing and one number. Understand "set [something] to [number]" as setting it numerically to.

Check setting it numerically to when the noun is not the engine:
say "You can't set that." instead.

Check setting the engine numerically to a number when the number understood is less than 0:
say "You can't set the engine to go backward." instead.

Carry out setting the engine numerically to a number:
now the speed of the engine is the number understood.

Report setting the engine numerically to a number:
say "You set the engine to [number understood] knots."

There are lots of choices that could be made differently (for instance, making the numbers properties of the engine means having to type “of the engine” lots of times). Also if you set the speed to an invalid number, then the engine still chugs along at the previous speed–that may not be desirable. But I hope this is helpful!