I’m trying to make a game with different sci-fi energy weapons in it, each of which has slightly different effectiveness etc etc. Here is the code that gives a basic gun that charges up:

```
Earth is a room.
A gun is a kind of device. A gun has a number called the power level.
A gun has a number called the charge level.
A gun has a number called the max charge.
A gun has a number called the charge speed.
A gun has a number called the energy efficiency.
Every turn:
repeat with X running through switched on guns:
if the charge level of X is the max charge of X:
next;
let ch be (charge speed of X * energy efficiency of X) / 10;
if the charge speed of X is greater than the power level of X:
if ch is greater than the max charge of X - the charge level of X:
let Y be max charge of X - the charge level of X;
let Y be Y / (energy efficiency of X * 10);
decrease the power level of X by Y;
now the charge level of X is the max charge of X;
else:
increase the charge level of X by (the power level of X * energy efficiency of X) / 10;
now the power level of X is 0;
else:
if ch is greater than the max charge of X - the charge level of X:
let Y be max charge of X - the charge level of X;
let Y be (Y / energy efficiency of X) * 10;
decrease the power level of X by Y;
now the charge level of X is the max charge of X;
else:
increase the charge level of X by ch;
decrease the power level of X by charge speed of X;
The player carries a laser pistol. The laser pistol is a gun. The power level is 400. The max charge is 145. The charge speed is 13. The energy efficiency is 12.
Carry out examining a gun:
say "Weapon stats:[line break]Current shot charge level: [charge level of noun]/[max charge of noun][line break]Power level: [power level of noun][line break]Battery discharge speed: [charge speed of noun] level[s] per turn[line break]Energy efficiency: [energy efficiency of noun]%[line break]";
now examine text printed is true.
```

In short, power level is the gun’s “battery,” charge level is the amount of damage that will be done when the gun is fired, max charge is the amount of energy that can be used in one shot, charge speed is the number of power level levels that are consumed per turn, and energy efficiency is the increase in charge level per 10 power levels consumed.

However this gives a truly annoying and slightly unbalanced response, the source of which I cannot figure out–obviously it is in the “every turn” rule, but I can’t see what the problem with it is.

```
>x pistol
Weapon stats:
Current shot charge level: 135/145
Power level: 283
Battery discharge speed: 13 levels per turn
Energy efficiency: 12%
The laser pistol is currently switched on.
>x pistol
Weapon stats:
Current shot charge level: 145/145
Power level: 283
Battery discharge speed: 13 levels per turn
Energy efficiency: 12%
The laser pistol is currently switched on.
```

This turn should have consumed several power levels (previously calculated to be 3 but that wasn’t reasonable, more like 8-9) but did not use any. Anyone know what’s wrong?