#################################
# BASIC Tenliners Contest 2016  #
#                               #
# FireFighter64                 #
# (c) 2016 Roman Werner @romwer #
# email: roman.werner@gmail.com #
#################################

The adventure starts now. Experience the daring job of a firefighter, withstand the wild water pressure of 17 bar and see your hero status raise with each successful mission. But beware! You need to sharpen and use your reflexes to avoid the imminent fire inferno.

Features
========
- Full packed action and challenges
- Hundreds of different locations
- Live status of achieved rank, money earned and water left in the tank
- Impressive 3D effect
- Multicoloured fire animation
- Slow motion mode à la Matrix for better control of the water jet
- Epic end sequence ;)


Task and Goal
=============
Begin a successful firefighter career and climb your steps up from an unexperienced Rookie to an honored Chief Fire Officer - and earn good money on the way.

Your task is to extinguish 10 fires as per location. Follow the searchlight that moves along the facade, and press the the fire button at the right moment to activate the water jet. For each extinguished fire you will earn $500. You will get additional $50 bonus for each remaining water unit left when all fires are out. Your rank will automatically increase after successful completion of a mission.

Important: Always keep an eye on your water supply at the bottom of the screen, otherwise it may happen that you lose your job and hero status rather quickly.


Rank/Career overview:
 0  - Rookie (beginner)
 1  - Firefighter Trainee
 2  - Firefighter Development
 3  - Firefighter
 4  - Crew Manager
 5  - Watch Manager
 6  - Station Manager
 7  - Group Manager
 8  - Area Manager
 9  - Deputy Chief Fire Officer
10  - Chief Fire Officer

When you reach the highest rank then you will be honored with a nice surprise!



Control:
========
Activate water jet:    Fire Button (Joystick Port 2)
Restart after the end: Press any key


Game Requirements:
==================
- C64/C128* with BASIC 2.0 runtime environment (or compatible)
- Joystick Port 2 (fire button)
- 1 Player

*Also playable on Windows/MacOS/iOS/Android (C64 Emulator required)


Starting in VICE: C64 emulator (http://vice-emu.sourceforge.net/):
==================================================================
Start the emulator and then drag and drop the "firefighter64.prg" into the VICE window.
-or-
Load the program with the command: load "firefighter64.prg",8
Then start the program with:       run


FireFighter64 BASIC program code:
=================================
0 clr:poke53280,0:poke53281,0:h=1984:p=1304:c=55576:n=111:d=102:m=599:g$="{home}{reverse off}{down}{down}{down}{light blue}u r "
1 g=10:r=15:s=s+w*50:print"{light blue}{clear}rank"ltab(9)"$"s"{down}{down}{down}{down}{down}{down}":fori=0to39:s$=s$+"{black} ":pokeh+i,247:next
2 deffnr(x)=int(rnd(1)*x):l$=left$(s$,fnr(33)*2):y=81:v=10:a$="{light gray}{cm m}{light gray}P{light gray}P{light gray}P{light gray}P{light gray}P{light gray}P{light gray}P{light gray}P"
3 b$=left$(a$,v+(fnr(5)*2)):l$=left$(l$+b$,78)+"{dark gray}P":l$=l$+right$(s$,80-len(l$)):j=56320
4 printl$;:s$=l$:r=r-1:on-(r>0)goto2:w=39:l=l+1:s$="":r$="{red}f":fori=0to9:print"{reverse on}{green}        ";
5 o=fnr(m):x(i)=o:on-(peek(p+o)<>80)goto5:pokep+o,d:pokec+o,2:next:ifl>vthend=83:r$="{green}h":goto9
6 fori=0tom:q=p+i:f=peek(q):pokeq,y:on-(peek(j)=n)goto7:pokec+x(iand7),iandvor2:pokeq,f:next:goto6
7 pokeh+w,32:w=w-1:fork=0to9:on-(x(k)=i)goto8:next:pokeq,f:pokec+i,14:on-(w<0)goto9:next:goto6
8 x(k)=-1:s=s+500:pokeq,f:pokec+i,14:print"{home}{reverse off}{light blue}"tab(v)s:g=g-1:on-(g=0)goto1:next:next:goto6
9 x=fnr(m):on-(peek(p+x)=32)goto9:pokep+x,d:pokec+x,7:printg$r$"ired!":on-(peek(197)=64)goto9:goto0


Tip: Copy/paste the program-Code into CBM prg Studio (http://www.ajordison.co.uk/).
There you can see the commands in nice color highlighting and you can directly execute the game in an emulator of your choice.

Here you have the same code (PUR-80) by using allowed command abbreviations - relevant for the contest:

0cL:pO53280,0:pO53281,0:h=1984:p=1304:c=55576:n=111:d=102:m=599:g$="hrdddbu r "
1g=10:r=15:s=s+w*50:?"bcrank"ltA9)"$"s"dddddd":fOi=0to39:s$=s$+"b ":pOh+i,247:nE
2dEfnr(x)=int(rN(1)*x):l$=leF(s$,fnr(33)*2):y=81:v=10:a$="gmgPgPgPgPgPgPgPgPgP"
3b$=leF(a$,v+(fnr(5)*2)):l$=leF(l$+b$,78)+"gP":l$=l$+rI(s$,80-len(l$)):j=56320
4?l$;:s$=l$:r=r-1:on-(r>0)gO2:w=39:l=l+1:s$="":r$="rf":fOi=0to9:?"rg        ";
5o=fnr(m):x(i)=o:on-(pE(p+o)<>80)gO5:pOp+o,d:pOc+o,2:nE:ifl>vtHd=83:r$="gh":gO9
6fOi=0tom:q=p+i:f=pE(q):pOq,y:on-(pE(j)=n)gO7:pOc+x(iand7),iaNvor2:pOq,f:nE:gO6
7pOh+w,32:w=w-1:fOk=0to9:on-(x(k)=i)gO8:nE:pOq,f:pOc+i,14:on-(w<0)gO9:nE:gO6
8x(k)=-1:s=s+500:pOq,f:pOc+i,14:?"hrb"tAv)s:g=g-1:on-(g=0)gO1:nE:nE:gO6
9x=fnr(m):on-(pE(p+x)=32)gO9:pOp+x,d:pOc+x,7:?g$r$"ired!":on-(pE(197)=64)gO9:gO0

         1         2         3         4         5         6         7         8
12345678901234567890123456789012345678901234567890123456789012345678901234567890


FireFighter64 Tenliner explained (000=row 0/100=row 1/...):
=============================================================
000 clr: rem Reset all variables to 0 (better than l=0:s=0:w=0:)
010 poke53280,0: rem Set frame color to black
020 poke53281,0: rem Set background color to black
030 h=1984: rem Startrow of Screen-RAM for water tank
040 p=1304: rem Startrow of Screen-RAM for facade
050 c=55576: rem Startrow Color-RAM for facade  
060 n=111: rem Constant for fire pressed value
070 d=102: rem Constant for PETSCII-value of the checkers symbol (=Fire)
080 m=599: rem Constant for max. number of characters to step through (15 rows of 40 characters, starting at 0)
090 g$="{home}{reverse off}{down}{down}{down}{light blue}u r ": rem Partial string for "You are F/Hired"-game over text

100 g=10: rem Number of fires to extuingish per level
110 r=15: rem Row counter for facade building (r=rows)
120 s=s+w*50: rem Add the remaining water units to the score when going to the next level
130 print"{light blue}{clear}rank"ltab(9)"$"s"{down}{down}{down}{down}{down}{down}": rem Display status information a the top
140 fori=0to39: rem In this 40x loop there are 2 things happening... :)
150 s$=s$+"{black} ": rem Fill base string with black spaces
160 pokeh+i,247: rem Build lower water level status bar based on PETSCII-value 247
170 next

190 rem *** Creating the group of buildings ***
191 rem The facade look & feel is being assembled in rows 200-430 (completing the base string x15).
192 rem For each line a house element will be added to the existing string at a random position.
193 rem The string in row 240 contains the actual graphic for one element.
194 rem Note: Maybe it makes you wonder why {light gray} is being repeated after each character.
195 rem The color/character-pairing is required so that the string always ends up exactly with 40 printable characters.
196 rem It would have been much simpler without the dark gray shadow, but it's much nicer looking that way. :)

200 deffnr(x)=int(rnd(1)*x): rem Function definition of r(x) to return a random value for range x. Used a couple of times.
210 l$=left$(s$,fnr(33)*2): rem Get the leftmost n (1-32) characters from the last base string.
220 y=81: rem Constant for PETSCII-value circle (=searchlight)
230 v=10: rem General constant for number 10 (fires, length of house element or color pink).
240 a$="{light gray}{cm m}{light gray}P{light gray}P{light gray}P{light gray}P{light gray}P{light gray}P{light gray}P{light gray}P"

300 b$=left$(a$,v+(fnr(5)*2)): rem Build a house element between 10-15 characters
310 l$=left$(l$+b$,78)+"{dark gray}P": rem Add the house element to the left part of the string and shorten it if bigger then 39 characters (color/char pairs).
320 l$=l$+right$(s$,80-len(l$)): rem Fill the rest with rightmost part of the previous string
330 j=56320: rem Constant for Joystick Port 2 address

400 printl$;: rem Print the 40-character-row
410 s$=l$: rem Replace base string with base string plus new element
420 r=r-1: rem Decrease row counter
430 on-(r>0)goto200: rem Repeat as long as there are still rows to be drawn.
440 w=39: rem Set water variable to maximum
450 l=l+1: rem Increase level variable by 1
460 s$="": rem Set base string back to empty. Only relevant for next level.
470 r$="{red}f": rem set "F"ired value as default - will be used in line 9
480 fori=0to9: rem Also in the following 10x loop there are 2 things happening :)
490 print"{reverse on}{green}        ";: rem 1. Print part of grass and 2. ...

500 o=fnr(m): rem Get a random position for a fire in the screen area
510 x(i)=o: rem Assign this position to a fire
520 on-(peek(p+o)<>80)goto500: rem No wall element at this position? Then try again with another value
530 pokep+o,d: rem Draw at this position the PETSCII checker symbol (=fire)
540 pokec+o,2: rem Write the color value light red to the same relative position but to the color-RAM
550 next: rem After this loop we have 10 relative screen positions stored in x()
560 ifl>vthend=83:r$="{green}h":goto900: rem Reached highest level/rank)? Then replace fire with heart symbol, set "H" for "Hired" and jump to end sequence

599 rem *** Here starts the main loop ***

600 fori=0tom: rem Loop 600x (40 characters x 15 rows) and do the following...
610 q=p+i: rem p+i is being used more than once. Makes the final code smaller.
620 f=peek(q): rem Save current character at this screen position.
630 pokeq,y: rem Write the PETSCII-symbol for circle (searchlight)
640 on-(peek(j)=n)goto700: rem Joystick button pressed? Then water on!
650 pokec+x(iand7),iandvor2: rem Set the fire color red(2) or light red(10) at one of the 10 fires.
660 pokeq,f: rem Replace the searchlight with the saved character.
670 next: rem Repeat until the bottom right corner is reached.
680 goto600: rem Then start again at the top left screen position.

699 rem *** Logic for when the Joystick button is being pressed ***

700 pokeh+w,32: rem Draw a space character at the current water level position.
710 w=w-1: rem decrease remaining water units by one.
720 fork=0to9: rem Check all 10 relative fire positions.
730 on-(x(k)=i)goto800: rem identical with current Position? Then extinguish fire!
740 next
750 pokeq,f: rem Replace the searchlight with the saved character.
760 pokec+i,14: rem Mark this position with light blue (=color of water).
770 on-(w<0)goto900: rem Water units all used up? Then go to "F"ired end sequence!
780 next: rem repeat until the bottom right corner is reached.
790 goto600: rem Then start again at the top left screen position.

799 rem: *** Logic for when a fire is being extinguished ***

800 x(k)=-1: rem Set the relative screen position of the fire to -1 (make it "out of scope").
810 s=s+500: rem Increase account by $500.
820 pokeq,f: rem Replace the searchlight with the saved character.
830 pokec+i,14: rem Mark this position with light blue (=color of water).
840 print"{home}{reverse off}{light blue}"tab(v)s: rem Update $ status on screen.
850 g=g-1: rem Extuingished another fire (minus 1).
860 on-(g=0)goto100: rem Extuingished all fires? Then go to another location (next level).
870 next: rem Do this until all 10 fire positions where checked.
880 next: rem repeat until the bottom right corner is reached.
890 goto600: rem Then start again at the top left screen position.

899 rem *** Logic for when Water is 0 (=Game Over) or Rank 10 has been reached (=Success) ***

900 x=fnr(m): rem Get random value for relative screen position.
910 on-(peek(p+x)=32)goto900: rem If there is a space character at this position then try again.
920 pokep+x,d: rem Draw a checker (fire) or a heart symbol (success) to that Screen-RAM position.
930 pokec+x,7: rem At the same relative position set the color yellow in the color RAM.
940 printg$r$"ired!": rem Print "Hired" or "Fired!" text.
950 on-(peek(197)=64)goto900: rem While no key is being pressed spread fire (or hearts) across the building blocks.
960 goto000: rem Restart game.

2016 rem basic tenliners contest / (c) roman werner @romwer roman.werner@gmail.com
