SUBMARINE
by M. Fox, Aldridge, West Midlands
from Your Computer, November 1982

THIS IS A complex game of naval strategy in about 12K of RAM, based on
a visual map of the area of battle and is an excellent example of the
use of multi-dimensional arrays for the storage of certain types of
data.

You are the captain of a submarine attacking a horde of enemy ships at
anchor in a lagoon. You have to destroy them without running out of
power, being destroyed by depth-charges, eaten by sea monsters,
hitting a mine or running aground. The game is relatively self-
explanatory when being played but the actual commands do need some
explanation.

First, you may move in any one of eight directions using the command 1:
	8	1	2
	7		3
	6	5	4
100 power moves you one square. You must be careful not to ram
anything when moving. After you move, the sea-monsters also move -
this is done in fast mode to save time. During this process **BADOOM**
represents the demise of a sea-monster on a mine.

Second, you have two options for the command 2, Sonar. Option 1 draws
a map of the battle area, in which:
  Edge of the battle area
*  Mine
X  Your submarine
S  Enemy ship
H  Your HQ
$  Sea monster
+ Island

The second Sonar option enables you to track the path that a torpedo
or missile would take. It prints a list of the things that it would hit.

Torpedoes, command 3, is used to launch a torpedo which has a range of
three. They cannot destroy islands. Missiles, launched by command 4,
have a variable range and use fuel. 100 fuel is equal to one square
range. Missiles can destroy islands but ignore sea monsters.

Command 5, Repairs, is a command enabling you to repair damage -
though it does use some power. There is a Status/Damage Report
command. The Headquarters command, number 7, enables you to get extra
supplies and power. It can only be used with over 16 enemy ships and
you must be within two squares of your HQ.

Command 8, Sabotage, is a useful way of getting rid of enemy ships,
and has a range of two. Conversion is used to convert fuel to power or
power to fuel, at a one to one exchange rate. This is command 9. The
symbol 0 gives a list of the commands. If you enter a wrong command
Break the program and Goto 240. It is advisable to start games with a map.

The map is held in the array A(15,20) and is set up in lines 10 to
140. If the number 0 is held in the array then the corresponding
square on the map is empty, 1 represents a mine, 2 your submarine, 3
an enemy ship, 4 your HQ, 5 a sea monster and 6 an island. This
enables the printing of the map to be a very easy process - a string
is set up containing the symbols used for each character on the map,
line 2055
	LET A$=" *XSH$+"
Then that string is sliced and the character from the section of the
string of the value of that square of the array, + 1, is printed -
lines 2052 to 2150.

All the inputs wherever possible are done by INKEY$ to make the game
easier and more pleasant to play. The crew, power, fuel, torpedoes and
missiles are located at lines 160 to 200. Lines 230 to 260 input your
choice of command and 270 to 290 print the possible options. Damage is
kept in the variable D(9) corresponding to the command option. Damage
is caused by the enemy depth- charging you after the commands
Movement, Torpedoes, Missiles, Sabotage and Conversion. This is done
at 6200 onwards to 6640 where a varying degree of damage is selected
and inflicted from No Damage, 6260, to Critical Damage, 6490, where
you have to send Help in a code which is printed on the screen for one
second then removed - if you get it wrong no help comes and you die.
The time can be changed at line 6550. You may find that you need 100 -
two seconds - to start with, but later this will become too easy.
After every command where damage is received, 1,3,4,8 and 9, the
damage is automatically repaired by 1 at 5200.

Lines 1000 to 1080 collect the information for movement - direction
and distance; 1090-1190 move the submarine checking if it hits
anything and making sure that it does not go off the edge. Some clever
manoeuvres can be devised making use of this facility. If you hit
something when moving line 1160 sends you to 1200 which prints the
message.

After Movement, the sea monsters move. These home in on you by one
square each time. This is done in Fast mode at 5210. It scans the
board square by square, 5240-5260, and when it finds a sea monster it
homes him in by one square, 5270-5320, and if he has landed safely it
saves his co-ordinates in B - number of sea monsters found so far, 1 -
and B(A,2) then removes the old image, 5450- 5470. If a sea monster
lands on a mine both it and the mine are removed from the map, 5530-
5550. If it lands on you then it eats your whole submarine and you
lose. If it lands on anything else it is replaced in its old position
and does not destroy it. Sea monsters can be blocked this way and it
is a good strategic move. At the end of this process lines 5570-5600
restore the re-positioned sea monsters to the map.

Lines 2160 to 2270 produce the torpedo or missile tracking by
searching an area of three squares all around you in horizontal
stripes going down.

The torpedo routine at 3000 is used for both torpedoes and missiles,
3030 to 3070 checking the area, in the same way as 2160-2270, and
3100-3160 printing the appropriate message. The short section at 4000
merely sets up missiles before jumping to 3030.

At 5000-5050 is the damage-repair routine. A status report is printed
at 6000; 7000 is the HQ facility resetting your power and fuel. The
sabotage routine is 8000. It checks an area two squares around you and
destroys a random selection of the ships in that area around you. At
9000 is the conversion routine for converting fuel to power and power
to fuel on a one-to-one basis.

Due to its immense size and the heartbreak if it is lost after typing
it all in, it is best to save this program twice. This takes about
four minutes each when finished. Remember to Clear the variables when
saving, as these can add another minute to the time. This is done by
9900-9930. Do not forget to put in line 6475, which is at the end of
the listing. To make the game harder or easier you can alter the
original power, line 170; fuel, line 180; torpedoes, line 190;
missiles, line 200; crew, line 160; ships, line 10; mines, line 50;
sea monsters, line 70; and islands, line 80.

The variables are: A(15,20) is the map; ZC is the flag for whether to
move sea monsters or not - 1 means yes, 2 means no; S represents
number of ships left; S1 + S2 are the co-ordinates of your submarine;
S3 + S4 are the co-ordinates of your HQ; D(9) is damage; P is power; F
is fuel; C is crew; T is torpedoes; M is missiles; D is whether or not
an HQ is allowed to be used - 1 means yes, 0 means no;
P1,A,N,X,Y,M,R$,G$,A$,V,W,Z+SC are general usage variables.
