home *** CD-ROM | disk | FTP | other *** search
- Chapter6 PAGE 1 STARTREK THE COMPUTER PROGRAM
-
-
- CHAPTER 6
-
- 6.1 Short Range Sensors
-
- The Short Range Sensors are the means by which a short range
- radar scan is performed. They let the player examine everything
- that is in the Quadrant as well providing game status
- information.
-
- There are 64 sectors in the quadrant which is also organized
- as 8 rows of 8 sectors. In order for the computer to access each
- sector some technique must be employed to store the quadrant and
- the contents of the sectors into the computer.
-
- We have already discussed that the contents of the quadrant
- are stored in an array variable Q(I,J) as an array of rows and
- columns where I represents the row and J the column. The
- Quadrant array can thus be considered as having two dimensions
- and the contents of any quadrant can be defined using Q(I,J)
- where I and J define the row and column co-ordinates respectively
- (ie. Q(2,6) refers to the contents of a quadrant that is two rows
- down from the top corner and 6 columns along the row).
-
- Each quadrant itself contains 64 sectors, also arranged as
- an 8 by 8 array. The ground rules of the game only allow one
- object to be in a sector at any one time. The contents of the
- sectors are kept track of in an array similar to the quadrant
- array Q, but this time called S(I,J). For example, S(2,6) refers
- to the actual sector, the contents of the location in the array
- define what is in the sector. The contents can be set by using
- the LET statement such as
- LET S(2,6) = 1.
- The contents of any sector can be assigned a number
- corresponding to the occupant as follows,
-
- 1 represents a blank or empty sector
- 2 represents a star
- 3 represents the Enterprise
- 4 represents a Klingon (an enemy vessel)
- 5 represents a starbase
-
- An example of a Short Range Sensor scan is shown below.
-
- SHORT RANGE SENSORS IN QUADRANT 4,6
-
- 1 2 3 4 5 6 7 8 SCORE 511.3
- 1 . . . . . . . . TIME LEFT 23.9
- 2 * . . . . . . . CONDITION RED
- 3 . . . K . . . K SHIELDS 255.6
- 4 . . . . . . . . ENERGY 3456.0
- 5 . . . . * . . . PHOTON TORPEDOES 3
- 6 . . . * * . * . STARBASES 2
- 7 . . . . . E . . KLINGONS LEFT 21
- 8 . . . . . * . . KLINGONS CAPTURED 0
-
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 2 STARTREK THE COMPUTER PROGRAM
-
-
- The occupants of the sector in the basic game can be any one
- of the following,
-
- . represents a blank or empty sector
- * represents a star
- E represents the Enterprise
- K represents a Klingon (an enemy vessel)
- B represents a starbase
-
- The game status information alongside the radar display is
- as follows;
-
- TIME LEFT The amount of play time left in the game.
-
- CONDITION The state of the Enterprise. There are three
- possible conditions,
-
- RED Battle area, enemy in quadrant
-
- YELLOW One of the sub-systems aboard the
- Enterprise is damaged, or the Energy level has
- fallen to below 400 units.
-
- GREEN Everything is fine, no enemy detected, no
- damage, and sufficient available energy aboard the
- ship.
-
- SHIELDS The amount of energy allocated to the ship's
- shields. If this energy level is ever beaten down
- to zero by the enemy, the Enterprise is destroyed
- and you lose the game.
-
- ENERGY The amount of energy on board the Enterprise. If
- this ever falls to zero, the Enterprise becomes a
- derelict in space, and you lose the game.
-
- PHOTON TORPEDOES The number of photon torpedoes remaining on
- board the Enterprise.
-
- STARBASES The number of starbase in the galaxy, even if you
- have not located them all.
-
- KLINGONS LEFT The number of enemy ships in the galaxy.
- Should you destroy them all, you will win the game.
-
- KLINGONS CAPTURED The number of enemy vessels you have
- captured. Each one captured is a bonus multiplier
- on your score.
-
- The flow chart for the Short Range Sensor routine is shown
- in figure 6.1.
-
- In order to perform a short range sensor scan, we first
- have to test if the short range scanners are damaged. If they are
- damaged, the contents of the quadrant cannot be scanned let alone
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 3 STARTREK THE COMPUTER PROGRAM
-
-
- displayed. Thus a message that tells the player that the sensors
- are broken is displayed.
-
- Assuming workable sensors, a test is performed to determine
- if the Enterprise is inside the galaxy. If it is inside the
- galaxy, and if the computer is up, the quadrant data is loaded
- into the Map. If the computer is down, the scan will take place,
- the information will be displayed on the screen, but the data
- will not be put into the map. The display heading is generated
- and the column numbers and score displayed.
-
- The display routine comprises a similar pair of loops to the
- map routine. Here the contents of the sector are shown as a
- letter, followed by a "space" character. At the end of each row,
- one item of game status information is displayed. The cursor is
- then moved to the start of the next line, and the loops continue.
-
- The BASIC language implementation of the flowchart can take
- the form shown in figure 6.2.
-
- Line 400 contains the REMark or comment. Line 410 tests the
- state of the sensors. If they are damaged, ie IF D(I) > 0 then a
- message that the sensors are damaged is displayed and the
- subroutine exits at this time, as since the sensors are damaged,
- there is no point is continuing in the sequence.
-
- Line 420 checks to see if the quadrant is outside the
- galaxy. If it is, the program flow advances to line 440 skipping
- the scanning of the quadrant. If this test was not present,
- BASIC would output an error message when it tries to update the
- Q(I,J) array for quadrants outside the galaxy. The reason for
- the error messages is that when Q1 or Q2 have negative values,
- the statement Q(Q1,Q2) is invalid. There is also no space
- allocated in the array for when Q1 and Q2 have values greater
- than 7. to store any data. The test used the OR statement to
- determine if any one of four conditions is met. If anyone of
- them is, the Enterprise is outside the Galaxy, because in order
- to be in the galaxy, the Q1 and Q2 co-ordinates of the ship must
- have values in the range of 0 to 7.
-
- The state of the ship's computer (D(5)) is tested in line
- 430. If it is working, ie. IF D(5) = 0 then the Map can be
- updated. The map is updated by the statement Q(Q1,Q2) =
- ADS(Q(Q1,Q2)) which makes the contents of the quadrant a positive
- number. This is the normal scanning technique as used
- previously. If the computer was damaged, the contents of the
- quadrant are not entered into the map, but the radar display is
- still performed beginning at line 440.
-
- Line 440 first uses the subroutine starting at line 70 to
- display the heading. It then determines the current condition of
- the Enterprise by calling the subroutine beginning at line 3400.
- It next displays the column number using the statement
- PRINT " 1 2 3 4 5 6 7 8";
- which is a simple method of doing the job. The Long Range Sensor
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 4 STARTREK THE COMPUTER PROGRAM
-
-
- display used a different technique which was more complex. Two
- different techniques for doing almost the same job have thus been
- presented for your review. Which one is correct? They are both
- correct. In your future programs use the one you like best. The
- line is then tabbed across to the 20th character position by the
- TAB(20) ; and the subroutine starting at line 170 is invoked to
- display the current score. The line then sets up the row loop.
-
- Line 450 contains the column loop. It first displays the
- contents of each sector along the row and then tabs the cursor to
- the 20th character position along the display line. Before we
- look at line 450, consider for a minute how the contents of the
- sectors are distinguished. The contents of each sector S(I,J),
- can be set up to be an integer between 1 and 5 where
-
- 1 represents a blank or empty sector
- 2 represents a star
- 3 represents the Enterprise
- 4 represents a Klingon (an enemy vessel)
- 5 represents a starbase.
-
- So if for example, for any sector with co-ordinates (I,J),
- if S(I,J) = 4, there is a Klingon in that sector. Each of the
- objects that can be in a sector are represented by a letter as
- follows
-
- . for a blank or empty sector
- * for a star
- E for the Enterprise
- K for a Klingon (an enemy vessel)
- B for a starbase.
-
- These letters are stored as a string S$ in the order
- corresponding to the number associated with the object. This
- means that S$ = ".*EKB" because the correspondence is as follows.
-
- 1 . for a blank or empty sector
- 2 * for a star
- 3 E for the Enterprise
- 4 K for a Klingon (an enemy vessel)
- 5 B for a starbase.
-
- In order to display the letter for the object, we have to
- pick the correct letter out of S$. For example, if S(I,J) = 4
- the fourth letter in S$ which happens to be a "K" is to be
- displayed, because the number 4 in S(I,J) corresponds to the
- presence of a Klingon.
-
- Line 450 displays the corresponding letters by using the
- PRINT MID$(S$,N,L) function in the form PRINT MID$(S$,S(I,J),Z);
- " "; which operates as follows. The Z at the end (the number 1
- corresponding to the 'L') tells the computer that a one character
- string long is to be displayed. S$ tells the computer which
- string to search for the letter. The starting location of the
- string to be displayed is set by the contents of S(I,J). Thus
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 5 STARTREK THE COMPUTER PROGRAM
-
-
- for each sector in the quadrant, the value of S(I,J) is
- determined. The letter corresponding to the number stored in the
- S(I,J) array is then displayed followed by a "space" character.
- The J loop repeats until the contents of all the sectors in a
- particular row have been displayed. At the end of the row, the
- cursor is moved to the position of the 20th character along the
- line by the PRINT TAB(20) ; statement. Note the use of the semi
- colon after both the MID$ and TAB print statements to stop the
- cursor advancing to the next line.
-
- If you look back to the example of the Short Range Sensor
- display, you will see that a different item of status information
- is displayed at the end of each line. Line 460 routes the
- computer to the correct item to be displayed by the use of the
- 'ON' statement. Lines 500 to 570 inclusive display the data
- elements. Since the value of the line counter (I), varies
- between 0 and 7, while the 'ON' statement requires a number equal
- to 1 or more, I+Z is used to convert the line count of 0-7 to the
- range of 1-8 needed for the ON statement.
-
- When the 'ON' statement is encountered the program flow
- branches to the destination specified by the order of the line
- numbers. In our case after the first row is displayed, when I+Z
- = 1, the program will branch to line 470. After the second row,
- to line 480, after the third row to line 490, and so on.
-
- Each of these lines are similar. They first display the
- name of the data element. The cursor position is then moved to
- the 38th character position along the line by the 'TAB(38);'
- statement and the contents of the actual element then displayed.
- After each element has been displayed the program flow branches
- forward to line 550 which increments the row loop counter, and
- when it times out, terminates the command function (subroutine).
-
- The variables used to store the game status items are as follows.
-
- T = The DAYS LEFT in the game
- C$ = The CONDITION of the Enterprise
- E1 = Energy in the SHIELDS
- E = The total ENERGY of the Enterprise
- P = The number of PHOTON TORPEDOES left
- B9 = The number of STARBASES remaining (multiplied by 10)
- K9 = The number of KLINGONS LEFT in the galaxy (multiplied by 10)
- K4 = The number of KLINGONS CAPTURED"
-
- Since both B9 and K9 are stored multiplied by 100, they have
- to be divided by 100 before being displayed, hence for example,
- the K9/100 in the PRINT statement of line 530.
-
- The subroutine to calculate and display the score begins at
- line 170 with the usual REMark statement. The score changes as a
- function of the time elapsed since the game started, the number
- of Klingons destroyed and the number of Klingons captured or
- suicided. Line 180 computes a value for the score and places it
- in the temporary variable 'N' using the statement
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 6 STARTREK THE COMPUTER PROGRAM
-
-
- 180 N=INT(((K8-K9)/100)*(K5/2.5+K4+Z)^2*100/(T9-T)) : IF N<0 THEN N=0
-
- Consider the statement in sections. The number of Klingons
- destroyed is computed using the
- INT((K8-K9)/100)
- statement. The result is then divided by the elapsed time
- calculated in the
- (T9-T)
- statement. If the score was just a function of the number of
- enemy ships destroyed in the elapsed time so far, the value of N
- would be
- 180 N=INT(((K8-K9)/100)/(T9-T)).
- However a multiplier is put in
- to make capturing Klingons worth while even though they tend to
- damage the Enterprise during the capturing process. This
- multiplication factor is given by the statement
- (K5/2.5+K4+Z)^2*100
- which represents one hundred time the square of the number of
- Klingons captured (K4) added to the number of Klingons that have
- suicided (K5) divided by two and a half. This complex multiplier
- generously rewards the player for taking the time and effort to
- capture Klingons and also gives a small amount of compensation
- for those that were destroyed by their own captain rather than be
- captured. If the value computed for N by the expression
- N=INT(((K8-K9)/100)*(K5/2.5+K4+Z)^2*100/(T9-T))
- is negative, the value of N is set to zero by the statement
- IF N<0 THEN N=0
- at the end of the line.
-
- Line 190 displays the score in a formatted position in the
- display using the 'PRINT "SCORE";TAB(38);N' statements and
- terminates the subroutine with the 'RETURN' statement at the end
- of the line.
-
- At this carefully time copy lines 400 to 550 and line 170 to
- 190 from figure 6.2 into your program and save it. Do not try to
- execute the Short Range Sensor command at this time. If you do,
- you will get error messages, because certain prerequisites have
- not been met.
-
- 6.2 The VISUAL Command
-
- Now would be a good time to look at the VISual command,
- since it essentially performs a subset of the Short Range Sensor
- command. The Visual command displays the contents of the
- sectors adjacent to the Enterprise. If the co-ordinates of the
- Enterprise in the Quadrant are S1 and S2 (ie S(S1,S2) = 3), then
- to display the contents of the adjacent sectors to the Enterprise
- the row and column loop counters just have to work on S1 and S2
- plus or minus 1.
-
- The visual command is normally only used when the Short
- Range Sensors are damaged.
-
- Samples of the VISUAL command display are
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 7 STARTREK THE COMPUTER PROGRAM
-
-
-
- (a) . . . . . (b) . . . . . (c) $ $ . . .
- . . . . . . . . . . $ $ * * .
- . . E K . . B E K . $ $ E . .
- $ $ $ $ $ . . . . . $ $ . . .
- $ $ $ $ $ . . . . . $ $ . . .
-
- the first one (a) shows the Enterprise and a Klingon on the
- bottom row of the quadrant. The second (b) shows the Enterprise,
- a starbase and a Klingon somewhere in the middle sectors of the
- quadrant, and the last one (c) places the Enterprise in the first
- column of sectors. Two stars are also shown in the row above the
- Enterprise.
-
- The flow chart for the VISUAL command is shown in figure
- 6.3.
-
- The Visual command always works because you can always see
- out of the windows. The command is thus two loops for displaying
- the contents of the sectors adjacent to the Enterprise. Care
- must be taken so that sectors that are outside the quadrant are
- treated differently to sectors inside the quadrant. This is
- because the computer will output an error message if an attempt
- to access an illegal value of S(I,J) is made. and of course I
- and J will have illegal values for sectors outside the quadrant
- (ie less than 0 or greater than 7). These sectors are displayed
- as dollar signs to enable the player to locate the Enterprise
- within a quadrant should the Short Range Sensors be damaged.
-
- The Visual Command subroutine may be written in BASIC as
- shown in figure 6.4.
-
- It begins at line 2500 with the usual REMark statement. The
- heading is displayed when line 2510 invokes the subroutine
- starting at line 70. Two loops are invoked using a FOR/NEXT loop
- format as
- FOR I = S1-2 TO S1+2 : FOR J = S2-2 TO S2+2.
-
- Line 2520 tests to see if the sector whose contents are
- being displayed are inside the quadrant by using the logical 'OR'
- statement. The statement
- IF I<0 OR I>7 OR J<0 OR J>7 THEN
- will only be true if any one of the four conditions being tested
- are met. That is, if the value of I or J are less than 0 or
- greater than 7. If they are the 'PRINT "$"; : GOTO 2540' part of
- the line displays the dollar sign and advances the program past
- line 2530 which does the displaying of the letter associated with
- the contents of a sector as discussed above by means of the
- 'PRINT MID$(S$,S(I,J),Z);' statement. Line 2540 displays the
- "space" character then advances the column counter. After a row
- has been displayed, a 'PRINT' statement moves the cursor to the
- next line and the row counter is incremented. When that loop is
- terminated, the 'last command flag' (C9) is set to one to to
- inhibit line 3090 (in the main command loop) from moving any
- Klingons in the quadrant. The subroutine terminates at the
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 8 STARTREK THE COMPUTER PROGRAM
-
-
- RETURN statement.
-
- At this time carefully copy lines 2500 to 2540 from figure
- 6.4 into your computer program, don't forget to update the date
- in line 10, and save them. Again do not try to execute the
- command at this time or you will get error messages because
- before the contents of a quadrant can be displayed visually or as
- a short range radar display, they have to be set up first. The
- contents of the Q(I,J) array corresponding to a particular
- quadrant have to be transformed into values that can be used to
- position the different objects into various sectors. Consider
- the sample short range radar display shown above.
-
- There are two Klingons, no starbases and six stars in the
- Quadrant. The Quadrant co-ordinates are 4,6 so we know that
- Q(4,6) = 206. Thus before a Short Range Sensor command can be
- performed, that 206 has to be transformed so that the Klingons,
- stars and the Enterprise can be positioned in the various sectors
- within the quadrant.
-
- The flow chart to set up a new quadrant and position the
- objects within it is shown in figure 6.5. The first thing that
- is done is to clean up the quadrant by making all the sectors
- blank. This takes care of any previous contents of the array
- associated with any previous quadrant. The number of
- Klingons,starbases and stars in the quadrant are then computed.
- The Enterprise is then positioned in the quadrant followed by the
- Starbase if any, the stars and then the Klingons, again if any.
- If there are enemy ships in the quadrant, a 'RED ALERT' message
- is displayed. The program then checks to see if the player has
- put the shield up. If they are down, a message is displayed to
- that effect. The message is put out by the "Starfleet Command
- Training Simulator" part of the program.
-
- The BASIC language implementation of the flowchart could be
- as shown in figure 6.6. It begins at line 3200 with the
- customary REMark statement. Line 3210 then sets every sector in
- the quadrant to blank (ie it sets S(I,J) = 1). The real thing
- then begins at line 3220.
-
- Line 3220 tests for,and sets up the contents of, a quadrant
- that is outside the galaxy. By definition, there are no
- starbases or klingons outside the galaxy. There is also a remote
- possibility of the presence of a rogue star outside the galaxy.
- The test to see if the quadrant is inside the galaxy begins with
- the now familiar 'OR' test on the four requirements for being
- within the galaxy
- IF Q1<0 OR Q1>7 OR Q2<0 OR Q2>7 THEN
- if the test is true the program continues along the line. If the
- test is false, and the Enterprise is somewhere inside the galaxy,
- the program continues with the next line (line 3230). If the
- Enterprise is outside the galaxy, the Starbase and Klingon
- variables are set to zero by the statements
- K=0 : B=0 :.
-
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 9 STARTREK THE COMPUTER PROGRAM
-
-
- A random number between 0 and 1.199 is then computed and
- converted to an integer by the statement
- S=INT(RND(Z)*1.2).
- The probability of S being equal to one is thus quite low. The
- line terminates with the 'GOTO 3250' statement which bypasses the
- regular setting up code.
-
- Line 3230 uses N as a temporary variable. N is given the
- absolute value of the contents of the quadrant using the 'N =
- ABS(Q(Q1,Q2))' statement. Since the number of Klingons is equal
- to the hundreds digit, N can be divided by 100 to find out how
- many Klingons are in the Quadrant. Suppose for example the
- quadrant Q(Q1,Q2) = 306, there will be 3 Klingons, no starbases
- and 6 stars in the quadrant. N is thus 306. If N is divided by
- 100 it will have a value of 3.06. It is then converted to an
- integer (no decimal point) by using the INTeger function in
- BASIC. The statement thus used to find the value of the number
- of Klingons in the quadrant (represented by the variable K) is,
- 'K = INT(N/100)'.
-
- N is again used as a temporary variable in the detection of
- the presence of a starbase. The original value of N is the total
- contents of the quadrant. K is the number of Klingons. If the
- number of Klingons in the quadrant is multiplied by 100 and then
- subtracted from the original number, all that will be left is the
- number of stars and starbases. In our example we would see 306-
- 300 or 6. This function is performed in BASIC by the identity
- 'N = N - K*100'.
-
- The presence of a starbase can be detected in a number of
- ways. The technique used here is similar to that used to
- determine the number of Klingons, namely 'B = INT(N/10)'. This
- sets the value of 'B' to either '1' or '0' depending if a base is
- there or is not. An alternative method could be to test to see
- if N is greater than 10 and if so, set the value of B to 1, else
- make it a 0. That could be written in BASIC as
- IF N > 10 THEN B = Z ELSE B = 0.
- an approach that would lock the game into only having one
- starbase per quadrant. The technique used in line 3230 is more
- general and does not care how many bases are in the quadrant.
-
- Line 3240 computes the number of stars in the quadrant by
- subtracting the number of Klingons (multiplied by 100) and the
- number of starbases (multiplied by 10) from the original contents
- of the quadrant using the statement
- S = ABS(Q(Q1,Q2))-(K*100+B*10).
- It has to use the 'ABS(Q(Q1,Q2))' value because the value of N
- was changed by the operation that just preceded it and is no
- longer equal to the contents of the quadrant.
-
- Line 3250 invokes the subroutine beginning at line 50 to get
- two random numbers. The co-ordinates of the Enterprise within
- the quadrant (S1 and S2) are then set up. S1 is the row position
- and S2 the column position. The subroutine used X and Y as dummy
- variables for the purpose of communicating with the calling
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 10 STARTREK THE COMPUTER PROGRAM
-
-
- routine (the two numbers have to be passed somehow). We could
- have defined two special variable R1 and R2 for example, for this
- purpose, but did not. X and Y can be reused elsewhere in the
- program whenever a temporary variable is required. Reusing
- variables is a good idea in that it saves memory (since each
- variable occupies memory, and the more there are, the more memory
- is used). It is not a good idea in the sense that if you are not
- careful which and where variables are reused, strange things will
- happen when you un-intentionally re-use a variable. The contents
- of the quadrant occupied by the Enterprise are set to 3 by the
- 'S(X,Y) = 3' part of the line.
-
- The last part of the line tests to see if a starbase is
- present in the quadrant. if B = 0 then one is not and the
- program flow skips to line 3270. If one is, line 3260 positions
- it as follows. The random number generator subroutine that
- starts at line 50 is called. It returns two numbers (X and Y)
- which are now assumed to be the co-ordinates of the quadrant that
- the base is to be located in. If the contents of the quadrant
- are not equal to 1, ie the quadrant is not blank, a new random
- quadrant is chosen. If the quadrant is blank, it is set to 5, to
- signify the presence of the base. The BASIC language
- implementation of the operation is
- IF S(X,Y) <> Z THEN 32650 ELSE S(X,Y) = 5
- where <> means "is not equal to". Literally is means, "is less
- than, or, is greater than". If a number is less than or greater
- than another number, they certainly cannot be equal.
-
- For each star in the quadrant, the FOR/NEXT loop in lines
- 3270 and 3280 locate a blank sector and position a star in it in
- a similar manner.
-
- The last part of line 3290 tests for the absence of
- Klingons. If the value of K = 0 then no Klingons are present in
- the quadrant and the program flow branches forward to line 3340.
- If there are Klingons in the quadrant, they are positioned in a
- likewise manner by the FOR/NEXT loop in lines 3300 to 3320. Line
- 3300 sets up the individual Klingon data. The row (K1(I)) and
- column (K2(I)) co-ordinates are first set up, and then the energy
- available to the Klingon is then calculated. All Klingons are
- given a random amount of energy between 0 and 999 units. The
- amount of energy is stored in the K3(I) array. The last part of
- the line displays a "RED ALERT" message using a FOR/NEXT loop to
- display the words "RED ALERT" three times using the statements
- 'FOR I = 0 TO 3 : PRINT "RED ALERT " : NEXT'
- The task could have been written using a different statement as
- shown below
- PRINT "RED ALERT RED ALERT RED ALERT".
- You will find many places where a particular task can be
- implemented in a number of ways, most of them equally correct.
-
- Line 3330 outputs a "beep" or tome to the terminal. The
- standard ASCII control character used to sound a bell tone at the
- console terminal is 7. The character is a non printing one. The
- 'CHR$(7)' function tells BASIC to output the control character 7
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 11 STARTREK THE COMPUTER PROGRAM
-
-
- to the terminal. If you remember, CHR$(26) was used earlier to
- clear the screen. The last part of the line samples the amount
- of energy in the Shields. if it is zero, the shields are down and
- the player has moved the Enterprise into a quadrant containing
- enemy vessels. That is a definite NO-NO! A message to that
- effect is displayed. There is also a good probability as you
- will find later, that the Enterprise will be destroyed by the
- Klingons.
-
- Copy lines 3200 to 3340 from figure 6.6 into your computer
- program at this time and save it. Then try to RUN the program.
- The Visual and Short Range Sensor displays should work and show
- active displays. The CONDITION will be blank because C$ has not
- yet been set up. If your program is not performing correctly and
- you are getting error messages, debug it and eliminate them at
- this time, then save the corrected or debugged version of the
- program. Add a temporary line or statement to define C$ =
- "DEBUG" in case the absence of a defined value for C$ is
- bothering your computer.
-
- A static display like this is dull so lets fudge a move
- command to position the Enterprise in different quadrants. For
- debugging, we can put in a temporary move command as shown below
- which will allow different quadrants to be scanned.
-
- 1300 REM NAV WARP ENGINES/NAVIGATION
- 1310
- 1305 GOSUB 50 : Q1 = X : Q2 = Y : GOSUB 3200
- 1315 PRINT "MOVED TO QUADRANT ";Q1+Z;",";Q2+Z
- 1750 RETURN
-
- These lines perform a "move" operation on the Enterprise by
- relocating it at random throughout the galaxy each time the Move
- command is invoked. Note the use of numbers ending in 5
- signifying by our convention that they are temporary lines to be
- deleted later. These lines are inserted following line 1300.
- Line 1310 is left blank. Just enter the line number followed by
- a carriage return. This procedure will delete the current line
- 1310 which contains a 'GOTO 1000' instruction.
-
- Line 1605 uses the random number subroutine to set up the
- Galactic Quadrant co-ordinates (Q1 and Q2) of the Enterprise. The
- set up subroutine of line 3200 is then invoked to position the
- contents of the quadrant in the relevant sectors. The variables
- Q1 and Q2 are used to remember in which quadrant the Enterprise
- is located at any stage of the game, in a similar manner to the
- use of S1 and S2 to note which sector inside a quadrant the
- Enterprise is occupying. Q1 and Q2 are important when moving the
- Enterprise around the galaxy and S1 and S2 are important when
- things will begin to happen inside the quadrant.
-
- Line 1615 displays a message that the Enterprise has moved
- and also displays the destination. The +Z in the PRINT statement
- is used to convert the 0-7 co-ordinates that the computer uses
- tot he 1-8 that the player uses. The point has been discussed
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 12 STARTREK THE COMPUTER PROGRAM
-
-
- earlier. The subroutine terminates at line 1625.
-
- Enter lines 1605 to 1625 and run the program. You should
- now be able to move the Enterprise around the galaxy and get
- different displays when executing the Short Range Sensor, Visual,
- Map and Long Range Sensor commands while moving around the
- different quadrants in the galaxy.
-
- Stop the program execution (^C) and enter D(5) = 2. Then
- let the program CONTinue. You will now find that the Map does not
- work. The computer is down. Move to a new quadrant and to a
- Long Range Sensor Scan. Then use the Damage Control to repair
- the computer and try the Map display again. If all has gone
- well, you will find that the information about the quadrant that
- the Enterprise is currently located in has not been entered into
- the Map. If it has, you either have a bug in your version of the
- Program, or the data was entered by a previous Long Range Sensor
- scan. Stop the program, enter D(5) = 2 and move again. Now
- exercise the Map, repair the computer and try the map again. The
- map should not show the contents of the Enterprise's quadrant.
- Do a Long Range Sensor scan and then a Map command. The map
- should now be updated.
-
- At this time, a lot has been accomplished. All that is left
- as far as the quadrant is concerned is to set up the Condition
- (C$), ie determine the Condition of the starship. If you
- remember the condition was defined as follows.
-
- RED Battle area, enemy in quadrant
- YELLOW One of the sub-systems aboard the Enterprise is
- damaged, or the Energy level has fallen to below 400
- units.
- GREEN Everything is fine, no enemy detected, damage, and
- sufficient energy aboard the ship.
-
- The flow chart to determine the condition of the Enterprise
- is shown in figure 6.7.
-
- The first thing that happens is that the contents of the
- sectors adjacent to the Enterprise are sampled to see if the
- Enterprise is located next to a starbase. If the Enterprise is
- located in a sector adjacent to a base, then a further test is
- performed to see if the Enterprise is already docked. If the
- Enterprise is already docked, the parameters (Energy and Photon
- Torpedoes) are reset to their initial values. This allows the
- player to blast away at any Klingons in the sector while the Base
- continually resupplies the ship.
-
- If the Enterprise is not yet docked, then a test is
- performed to determine if any Klingons are in the quadrant. If
- there are, there is a possibility that the starbase will not be
- able to lower its shields (presumably it is also under attack by
- the enemy) to allow the Enterprise to dock. This possibility is
- set at 50%. Thus if there are Klingons in the quadrant, there is
- a 50% probability that the Enterprise will not be able to dock.
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 13 STARTREK THE COMPUTER PROGRAM
-
-
- Its too bad if you are badly hit and are limping home to base
- with the Klingons firing at you. If you are really unlucky they
- might even destroy the Enterprise while it is waiting to dock.
- The docking procedure, displays a message that docking is taking
- place, deducts half a stardate from the time left in the game and
- updates the ship's Energy and weapon parameters. The condition
- of the ship is also set to "DOCKED" at this time.
-
- On the other hand, if the Enterprise is not located in a
- quadrant that is adjacent to a base, the program first tests to
- see if any Klingons are present in the quadrant. If they are,
- the condition is set to "RED". If no Klingons are there, then
- the condition can be either "YELLOW" or "GREEN".
-
- The condition can be "YELLOW" if one of the subsystems is
- damaged, or if the total remaining energy aboard the Enterprise
- is less than 400 units (10% of the initial value). If either of
- those conditions are met, the condition is set to YELLOW. If
- none are met, all is assumed to be OK and the condition is set to
- "GREEN".
-
- The BASIC language implementation of the flowchart is as
- shown in figure 6.8. The subroutine begins at line 3400 with the
- usual REMark. Line 3410 commences two loops that perform the
- sector scan. The technique used is almost the same as that used
- in the Visual command. Here instead of accepting what ever is in
- the sector, we just need to know if one contains a base. The row
- and column loops scan one sector in each side of the Enterprise,
- including the one occupied by the Enterprise itself. We know
- that that test will fail, but so what? The search routine is
- simplified if we can treat all sectors in the same way. We thus
- just performs a continuous scan on nine sectors (three per row).
-
- Line 3420 checks to see if a sector is outside the quadrant.
- If it is the program skips forward to line 3440 bypassing line
- 3430 which does the actual test to see if the sector contains a
- Starbase using the statement
- IF S(I,J) = 5 THEN 3450.
- If the sector does contain a base, the loop is terminated by the
- branch to line 3450. The test is skipped for sectors outside the
- galaxy because S(I,J) is invalid if I or J are less than 0 or
- greater than 7. Line 3440 terminates the loops and then directs
- the program to continue at line 3490 in the event that a Starbase
- was not found.
-
- If a base was located, the program picks up at line 3450
- which tests to see if the Enterprise is already docked. The
- value of C$ is used as the condition flag. If it is "DOCKED"
- then the Enterprise is already docked and the parameters are
- updated using the subroutine starting at line 90 and repairs all
- the subsystems by calling the subroutine starting at line 3550
- which sets all sub-systems to "working" (D(I)=0). The routine
- then branches forward to line 3540.
-
- It is simpler to just set all the sub-systems to zero rather
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 14 STARTREK THE COMPUTER PROGRAM
-
-
- than test each one and set it to zero if it is non zero. The
- computer is fast, the player will never notice the difference in
- execution time between the two different methods. Setting them
- all to zero irrespective of the way way they were results in them
- all being zero, and that is what we want. Programs should use
- the "KISS" principle as well as being structured. KISS by the
- way is an acronym for
- KEEP IT SIMPLE STUPID.
-
- If the Enterprise is not docked, line 3460 tests to see if
- there are any Klingons in the Quadrant. The test statement
- includes the logical 'AND' statement. This means that both test
- conditions have to true before the program will continue at the
- line number specified by the 'THEN' part of the test.
-
- The first part of the test (IF K>0 ) tests to see if the
- number of Klingons in the sector is greater than zero. If it is,
- then there are enemy vessels in the quadrant. At this time,
- their numbers do not matter. The second part of the test (RND(Z)
- < .5 ) uses the random number function built into BASIC to
- generate a random number between 0 and 0.99999. The number is
- then compared with a constant (0.5). If the random number is
- less than 0.5 (a 50% probability), the test is true and the
- program flow continues at line 3490. Note that if the first test
- fails, Microsoft BASIC will ignore the second test and continue
- program execution at the next line number.
-
- The docking procedure begins at line 3470. The first thing
- that happens, is that a message is displayed telling the player
- that the Enterprise is docking. The display message is in two
- parts. D$(6) is used to save space in the program source code.
- We have previously defined D$(6) to contain the word "SHIELDS "
- (see line 4580). Then the subroutine starting at line 3550 is
- invoked to repair all of the on-board sub-systems. Once the
- systems are repaired, a message to that effect is displayed at
- the console by the last part of the line. Line 3480 invokes the
- parameter updating subroutine starting at line 90, then subtracts
- half a stardate from the game time remaining ( T = T - .5 ) and
- sets the value of C$ to "DOCKED". The program flow then branches
- forward to line 3540.
-
- Line 3490 is where we pick up if the Enterprise is not
- located adjacent to a starbase. It tests the value of K to
- determine if any of the enemy are present in the quadrant. If
- the value of K is greater than zero, namely there is at least one
- Klingon in the quadrant, then C$ is set to "RED" and the program
- skips to line 3540. If there aren't any Klingons in the
- quadrant, then the program continues at line 3500.
-
- Line 3500 examines the state of the sub-systems using a
- FOR/NEXT loop. If any sub-system has a value of D(I) greater
- than 0, it is damaged. The contents of C$ are set to "YELLOW"
- and the program flow leaves the loop by GOing TO line 3540. We
- don't care which one is damaged, we only care if any one of them
- is. If the test fails, then all the subsystems are in working
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-
- Chapter6 PAGE 15 STARTREK THE COMPUTER PROGRAM
-
-
- order, and the loop times out naturally. The program then tests
- the amount of Energy remaining aboard the starship to see if it
- is less than 10% of the initial value. If it is, the contents of
- C$ are also set to "YELLOW" else the amount of energy is greater
- than 10% of the initial value, (and nothing is damaged) and the
- contents of C$ are set to "GREEN". The subroutine terminates at
- line 3440.
-
- This subroutine has itself called two subroutines, one at
- line 90, the second at line 3550. When one subroutine calls an
- other the second subroutine is called a "nested" subroutine. The
- terminology is the same as that used to refer to loops.
-
- Copy lines 3400 to 3540 from figure 6.8 into your program,
- check your spelling, then SAVE it and RUN it. The game should
- behave as before, but now, the condition should show up as "RED"
- or "GREEN" depending on the presence or absence of Klingons in
- the quadrant. Break the program and set the amount of energy to
- less than 400 units (enter E = 200 for example). CONTinue the
- program and see if the condition changes between YELLOW and RED.
- Stop the program (^C again), re RUN it and this time break it and
- damage a subsystem (enter D(I) = 3, where I is the number of your
- choice). Now again test that the condition varies between YELLOW
- and RED. Repair the damaged sub-system and verify that the
- condition now changes between GREEN and RED. At this time save
- the program because it should be working properly. Delete line
- 1305 and 1315 so as to avoid any trouble when the real "MOV"
- command is implemented.
-
- At this time the program should be as shown in figure 6.9.
- Once the Short Range Sensors and the Visual commands have been
- programmed, the next stage is to implement the real move command.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Copyright (c) Joe Kasser 1989
-
-
-
-
-