Decoded: Sopwith (1984) by David L. Clark
Source file: SWMOVE.C
Beginner friendly, line-by-line code walkthrough by MaiZure

SWMOVE.C manages user input and executes actions

Original code:
http://davidlclark.com/page/sopwith-source-code

Original code with line numbers
http://www.maizure.org/projects/decoded-sopwith/SWMOVE_linenum.txt

1     COMMENT
2     COMMENT
3     BLANK
4     COMMENT
5     COMMENT
6     COMMENT
7     COMMENT
8     COMMENT
9     COMMENT
10    COMMENT
11    COMMENT
12    COMMENT
13    COMMENT
14    BLANK
15    COMMENT
16    BLANK
17    COMMENT
18    COMMENT
19    COMMENT
20    COMMENT
21    COMMENT
22    COMMENT
23    COMMENT
24    COMMENT
25    COMMENT
26    COMMENT
27    COMMENT
28    COMMENT
29    COMMENT
30    COMMENT
31    COMMENT
32    COMMENT
33    Include the main game header (sw.h)
34    BLANK
35    BLANK
36    BLANK
37    Import the display boundary locations from SWMAIN.C
38    Import the display shift amount SWMAIN.C
39    Import object pointer to the top of the object list
40    Import object pointer to the first element of the free object list
41    Import object pointer to both ends of the delete list
42    Import plane object list
43    Import other object list
44    Import the computer plane pointer arrays
45    Import the left computer territory array
46    Import the right computer territory array
47    Import the game play mode from SWMAIN.C
48    Import the multiplayer communication buffer
49    Import the sine table
50    Import the ground height array
51    Import the keydelay setting
52    Import the multiplayer key buffer
53    Import the plane graphic
54    Import the crashing plane graphic
55    Import the bomb graphic
56    Import the missile graphic
57    Import the flare graphic
58    Import the building graphics
59    Import the plane playing away graphics
60    Import the broken building graphic
61    Import the explosion graphics
62    Import the bird flock graphics
63    Import the bird graphics
64    Import the ox graphics
65    Import a display function
66    Import the performance counters
67    Import the flag for computer plane movement
68    Import the flag for player plane movement
69    Import the current object index
70    Import the player object index
71    Import the sound on/off fralg
72    Import the end game status of players
73    Import the end game counter
74    Import the victory flag
75    Import the current game number (used for difficulty)
76    Import the game speed boundaries
77    Import the maximum target range value
78    Import the keyboard couner
79    Import the end game status
80    BLANK
81    Import the missiles enabled flag
82    BLANK
83    Import the quit flag
84    BLANK
85    BLANK
86    BLANK
87    BLANK

MOVE ALL OBJECTS
88    Declare and define swmove with no arguments
89    BLOCK START - swmove, main update loop for all objects
90    Declares two local object pointers
91    BLANK
92    BLOCK START - handle recently deleted objects, deleted object pending?
93    Point the end of the list to the free list
94    Make the free list the top of the delete list
95    Remove the delete list
96    BLOCK END - handle recently deleted objects
97    BLANK
98    If the input counter has exceed the keydelay threshold..
99    Reset the counter to 0
100   BLANK
101   Point to the first object in the game
102   BLOCK START - process all objects for movement
103   Set the second pointer to the next object
104   Cycle the draw flag to the delete flag (cycling XOR drawing efforts)
105   Move the current graphic to the old graphic
106   Peforms the move function for the object and saves the result
107   If we're in a multiplayer game...
108   and this is another player's plane...
109   ...and we've reached the proper delay point..
110   Check if we're in a direct multiplayer and...
111   Send the move command to the multiplayer interface
112   Otherwise we're in an asynchronous game so...
113   Send the move to the asynchonous interface..
114   Update our current object pointer to the next object
115   BLOCK END - process all objects for movement
116   Iterate our move/tick counter
117   BLANK
118   BLOCK END - swmove
119   BLANK
120   BLANK
121   BLANK

MOVE PLAYER
122   Declare and define moveplyr with one argument
123   Argument one is a pointer to the player plane
124   BLOCK START - moveplyr, moves the player plane
125   Declares a local object pointer
126   Declare a return flag
127   Declare a temporary old x value
128   BLANK
129   Set the computer plane global to false (now processing player)
130   Set the player plane global to true (this matters for call to movepln)
131   BLANK
132   Point to the input plane
133   Get the input plane's index
134   BLANK
135   BLOCK START - check for player game over, if endstat is set..
136   ...and if the end game counter has reached zero..
137   Then we're not in network multiplayer
138   or not in asynchronous multipler
139   and haven't chosen to quit...
140   Then restart the game
141   Otherwise, the multiplayer game is over so end the game
142   BLOCK END - check for player game over
143   BLANK
144   BLOCK START - keyboard delay check, if the delay has ended..
145   If we're in multiplayer..
146   Get the multiplayer's key input
147   Or in asynch mode
148   Get the key from the asynch file
149   Otherwise, we're in single player so..
150   Read the keyboard buffer
151   Then flush the keyboard buffer
152   End case for play mode check
153   Apply the key read to the plane
154   Otherwise, the delay continues..
155   Change the plane flaps to neutral
156   Undo bombing actions (no carpet bombing)
157   Undo shooting actions (no automatic weapons)
158   BLOCK END - keyboard delay check
159   BLANK
160   If the player plane has crashed...
161   And the hitcount is zero..
162   Increment player's crash counter
163   If the player hasn't won...
164   and the life value is below -5000 (possible?? long multiplayer delay?)
165   Or the playmode isn't multiplayer
166   ...play mode isn't asynch
167   ...crashed too much..
168   And the end state hasn't been set
169   Then this guy obviously lost
170   Otherwise, the player did win
171   Reinitialize the player
172   and the bottom HUD
173   Double check the end state..
174   Unless player hit control break, in that case
175   End the game
176   Otherwise, show the win sequence
177   End case for player win 2
178   End case for player win 
179   End case for crashed plane
180   BLANK
181   Save the player's previous location
182   Move the plane and save the state (Alive or not)
183   If the plane is within the screen boundary
184   Then reset screen scrolling
185   Otherwise, the plane has moved too close to the ends
186   Update left screen boundary by the rate of movement of the plane
187   Update right screen boundary by the rate of movement of the plane
188   End case for crashed plane
189   BLANK
190   BLOCK START - update HUD, if the player isn't at home...
191   Set the active video segment
192   If the player is firing...
193   Update the ammo counter
194   If the player is bombing...
195   Update the bomb counter
196   If the player is firing missiles...
197   Update the missile counter
198   If the player is dropping flares...
199   Update the falre counter
200   BLOCK END - update HUD
201   BLANK
202   Return the player's state (still alive or not)
203   BLOCK END - moveplyr
204   BLANK
205   BLANK
206   BLANK
207   BLANK

HANDLE KEYBOARD COMMANDS
208   Declare and define interpret with two arguments
209   Argument 1 is a pointer to the input player plane
210   Argument 2 is the key pressed
211   BLOCK START - interpret, applies keyboard input to the player plane
212   Declares a local object pointer
213   Declares a local state variable
214   BLANK
215   Points to the input object, usually player's plane
216   Sets turning state to 0
217   Resets bombing state
218   Reset shooting state
219   If no valid state to receive input...not in flying move
220   ...nor stalled
221   ...nor falling
222   ...nor wounded
223   ...nor stalled and wounded
224   ...nor a ghost
225   ...nor a stalled ghost
226   Then return from interpret -- nothing to do
227   BLANK
228   BLOCK START - Non-falling plane input
229   If an ending has been reached
230   And the ending is loser and while play is still alive...
231   Then have the plane return to base
232   Return form interpret -- nothing to do
233   End case for ending
234   BLANK
235   BLOCK START - Break key pressed, if break was pressed
236   Set the player's life counter to quit
237   Set going home to false
238   If the player is already at home...
239   And the state is already finished...
240   Set state to crashed (or some form of it)
241   Reset the hit counter
242   End case for plane at home
243   If the player is still active..
244   Then set the global quit flag to true -- shutdown on next game loop
245   BLOCK END - Break key pressed
246   BLANK
247   If the player hit the key to fly home...
248   Then if the player is flying..
249   Or a ghost..
250   Or wounded...
251   Then set the home flag to true (plane autopilots home)
252   BLOCK END - Non-falling plane input
253   BLANK
254   On every odd count of the game counter...
255   Or if the player isn't wounded..(wounded slows reactions)
256   Then if the player moves the flaps up..
257   Move the flaps
258   Player is no longer at home (instant takeoff!)
259   End case for move flaps up
260   BLANK
261   If the player moves the flaps down..
262   Move the flaps
263   Set the player to not at home (instant death!)
264   End case for move flaps down
265   BLANK
266   If the player hit's the key to flip the plane...
267   Then flip it! (invert orientation variable)
268   Player is no longer at home (not instant death, but it should be)
269   End case for flip
270   BLANK
271   Player cuts the engines a bit
272   If the plane had some power...
273   Reduce it a bit
274   The player is no longer at home
275   End case for deceleration
276   BLANK
277   If the player opens the throttle
278   Then if the plane isn't already at max speed
279   Increase the plane's acceleration
280   Plane is no longer at home base
281   End case for speed up
282   End case for wounded plane behavior
283   BLANK
284   If the player pulls the trigger and the game hasn't ended...
285   Then set the variable to fire (processed later)
286   BLANK
287   If the player tries to fire a missile and the game hasn't ended..
288   Set the fire missile flag
289   BLANK
290   If the player pulls the bomb drop lever and the game is still on...
291   Then set the bomb drop flag for layer processing
292   BLANK
293   If the flare presses the flare key and the game is still in progress
294   Then set the flare drop flag
295   BLANK
296   If the player turns the sound off
297   Then if the player is still active..
298   And there is currently a sound playing...
299   Set the sound to null (no sound)
300   Swap null sound to current sound
301   End case for sound in progress
302   Toggle the sound flag
303   End case for player in progress
304   BLANK
305   If the object's home flag is now set then...
306   Execute return to base for the object
307   BLOCK END - interpret
308   BLANK
309   BLANK
310   BLANK

MOVE COMPUTER PLANES
311   Declares and defines movecomp with one argument
312   Argument 1 is a pointer to an input plane
313   BLOCK START - movecomp, moves a computer plane
314   Declares a local object pointer
315   BLANK
316   Set the global computer player flag to true
317   Set the global human player flag to false
318   BLANK
319   Point to the input object
320   Reset the flap (turning) state to neutral
321   Reset bomb drop states
322   Reset missile firing states
323   BLANK
324   Pull the current end state for the object
325   BLANK
326   If the delay counter has expired
327   Then disable bullet firing
328   BLANK
329   SWITCH on computer plane state
330   BLANK
331   CASE wounded (fall-through)
332   CASE wounded and stalled
333   Don't process input if we're on an odd turn count (slow reactions)
334   End switch
335   BLANK
336   CASE flying (fall-through)
337   CASE stalled (fall-through)
338   If the game is in an end state...
339   Then always return home
340   End switch
341   End check for end game
342   If the input counter has expired...
343   Pass the flying decision to the AI routine in SWAUTO.C
344   End switch
345   BLANK
346   CASE crashed
347   Plane should no longer be firing
348   If hitcounter is 0 or lower and the game hasn't ended
349   Reinitialize the computer plane at home base
350   End switch
351   BLANK
352   In all cases...
353   Disable plane firing
354   End switch
355   End switch
356   BLANK
357   Call general plane actions using flags that are set and return state
358   BLOCK END - movecomp
359   BLANK
360   BLANK
361   BLANK

MOVE PLANES (GENERIC)
362   Declares and defines movepln with one argument
363   Argument 1 is an input plane
364   BLOCK START - movepln, applies generic move actions to all planes
365   Declares a local object pointer
366   Declare local variables for plane movement properties
367   Declare local variables for plane positions
368   Declare a gravity effects indexed by the first 8 game angles...
369   ...and the second 8 game angles
370   BLANK
371   Point to the input plane
372   BLOCK START - SWITCH on plane state
373   CASE plane is finished (fall-through)
374   CASE plane is waiting
375   Nothing to display, return false
376   BLANK
377   CASE plane is crashed (fall-through)
378   CASE plane is a ghost and still crashed
379   Decrement the hit counter
380   End switch -- nothing else to do
381   BLANK
382   CASE plane is falling
383   Decrement the high counter by 2
384   If the plane is falling while moving foward...
385   And the plane is moving upside down...
386   Decrement the hit counter (positive flaps)
387   Otherwise it's right side up
388   Decrement the hit counter once more (negative flaps)
389   BLANK
390   If the his counter is 0 or negative
391   and the plane is moving downwards
392   And to the left
393   Decrease leftward movement
394   Otherwise if it's moving right
395   Decrease rightward movement
396   Otherwise it's falling straight down...
397   Just roll the plane
398   BLANK
399   If the plane is falling slower than 10 pixels per tick
400   Apply more gravity
401   Reset the hit counter
402   End case for end of hit counter cycle
403   Update the object's angle (double return for the games 16 base angles)
404   If the plane is moving downward
405   Start the plane's falling sound
406   End case plane falling
407   BLANK
408   CASE plane is staled
409   Set the return state to flying
410   Go to stall subproc on line 419
411   BLANK
412   CASE plane is a ghost and stalled
413   Set the return state to ghost
414   Go to stall subproc on line 419
415   BLANK
416   CASE plane is wounded and stalled
417   Set the return state to wounded
418   BLANK
419   Stall handler sub-procedure
420   If the plane s no longer falling...
421   And the plane is no long moving below minimum speed..
422   Then return plane to previous flight mode
423   Go to controlled flight procedure on line 438
424   BLANK
425   CASE plane is flying normally (fall-through)
426   CASE plane is wounded (fall-through)
427   CASE plane is a ghost
428   If the plane is stalled but the plane is off the top of the screen..
429   And the difficulty is novice..
430   Set the plane angle to downward
431   Unstall the plane
432   Otherwise we're in expert mode...
433   Stall the plane
434   Save the state
435   End check for expert
436   End check for stalled
437   BLANK
438   Controlled flight sub-procedure
439   If the player has already won...
440   Nothing to do, skip movement
441   BLANK
442   If the plane life is 0 and we're not at home..
443   and we're flying normally...
444   ...or stalled...
445   ...or wounded...
446   ...or both...
447   Then hit the plane
448   Add some score
449   Return a recusrive call to movement
450   End case for no life
451   BLANK
452   If the plane is firing
453   Create a shot
454   BLANK
455   If the plane is dropping a bomb
456   Then make a bomb
457   BLANK
458   If the plane is firing a missile
459   Create the missile
460   BLANK
461   If the plane is dropping a flare
462   Make the flare
463   BLANK
464   Store the current angle
465   Store the current speed
466   Set update to false
467   BLANK
468   If the flaps are engaged...
469   and the plane is inverted...
470   Decrease the stored angle (more falling)
471   Otherwise...
472   Increase the stored angle (more falling)
473   Wrap the angle if necessary
474   End case for updates
475   BLANK
476   Every 4 ticks, we'll update speed...
477   If the plane isn't stalled but the plane is travelling slow..
478   and we're in expert mode..
479   Decrease speed even more
480   Set update flag (triggers line 495)
481   Otherwise...
482   Save the current speed limit... (varies on game difficulty)
483   plus the speed of the plane...
484   plus the gravity/angle offset...(we go faster downwards)
485   If the speed is below the limit..
486   Boost speed
487   And set update
488   Otherwise, if the speed is too fast
489   decrease speed
490   and set update flag anyway
491   End check for speeding
492   End check for stalled
493   End check for every 4 tick check
494   BLANK
495   If the update flag was set above...
496   If we're parked at the air base
497   And if we're accelerating or trying to fly..
498   Save speed at minimum
499   Otherwise..
500   No speed
501   BLANK
502   Otherwise, we're not at home so if we're slow and not stalled...
503   But we're novice..
504   Just give the player free speed
505   But if we're on expert..
506   Stall the plane
507   Recursively update move
508   End check for expert stall
509   End check for not at home
510   BLANK
511   Set the plane speed to the speed we've calculated above
512   Set the plane angle to the calculated angle
513   BLANK
514   If the plane is stalled
515   Reset all tracking vectors
516   Negate the speed
517   Otherwise,
518   Update the object's motion...
519   With the x vector
520   and the y vector
521   End motion update
522   End update check
523   BLANK
524   If the plane is stalled...
525   If the decremented hit counter is 0
526   Spin the plane
527   Point the plane downward...
528   Less the actual angle..
529   Wrap if necessary
530   Set the hit counter to the stall counter
531   Ene check for hit counter update
532   End check for called
533   BLANK
534   If this isn't a computer plane...
535   And if the player is still around...
536   And the player's speed is greater than...
537   ...the life counter mod 900
538   Set the display segment to video memory
539   Update the fuel guage on the HUD
540   End case for player fuel update
541   Tick the life counter by the speed
542   End case for player plane
543   BLANK
544   If the plane is moving...
545   Then it can't be at home
546   End case for normal flight modes
547   BLOCK END - SWITCH on plane state
548   BLANK
549   If this is the player plane who won and is in the end sequence
550   Then set the end graphic indexed by the end game counter
551   Otherwise...
552   Set the plane's graphic to either...
553   NULL if it's dead...
554   Or if it's falling...
555   straight downwards...
556   set to the spinning plane
557   Otherwise just the sideview based on angle
558   BLANK
559   Update the plane's position
560   BLANK
561   If the plane is off the left side of the world...
562   Then keep it pegged to the left wall
563   But...
564   IF the plane is on the edge of the right side of the world...
565   Keep it stuck there
566   BLANK
567   If there is no computer plane currently...
568   And the current plane is flying...
569   or stalled..
570   or wounded..
571   or both..
572   and the game is still on..
573   Then set the nearest plane to itself
574   BLANK
575   Remove the plane from the object list
576   Put it back on the list
577   BLANK
578   If there is a bomb drop counter...
579   Decrement it
580   IF there is a missile counter...
581   Decrement it
582   If there is a flare counter...
583   Decrement it
584   BLANK
585   If there is no computer plane and the player is at home and alive...
586   Then refuel the plane
587   BLANK
588   If the plane is within the screen...
589   And is falling...
590   or wounded...
591   or wounded and stalled...
592   Create some smoke
593   Set the display segment to video
594   Update the world minimap
595   Return positive value if we're still playing
596   End case for plane being visible
597   BLANK
598   If we've made it this far, then this plane is toast. No need to draw
599   BLOCK END - movepln
600   BLANK
601   BLANK
602   BLANK

FIND NEAREST TARGET PLANE
603   Declares and defines nearpln with one argument
604   Argument 1 is an input plane object
605   BLOCK START - nearpln
606   Declares three local object pointers
607   Declare local object indicies, position, ranges, and colors
608   BLANK
609   Point to the input plane
610   Point to the top of the object list
611   BLANK
612   Set the local x to the input plane's x
613   Set the local color to the input plane's color/team
614   BLANK
615   BLOCK START - Loop through all the planes
616   If the plane matches the searcher's color/team...
617   Go to next plane, not a valid target
618   BLANK
619   If the target plane is a computer player..
620   BLANK
621   And the play mode is not against the computer...
622   and the searching object is not in left hostile territory..
623   ...or right hostile territory...
624   And there is no candidate plane already set...
625   or if there is...
626   this one is closer...
627   Set the target
628   BLOCK END - Loop through all planes
629   BLOCK END - nearpln
630   BLANK
631   BLANK
632   BLANK
633   BLANK
634   BLANK
635   BLANK

REFUEL/RELOAD PLANE
636   Declares and defines refuel with one argument
637   Argument 1 is the plane to refuel
638   BLOCK START - refuel
639   Declares a local object pointer
640   BLANK
641   Point to the input plane
642   Set display segment to main video memory
643   If the plane can update fuel then...
644   Redraw the fuel guage
645   If the plane can update ammo then...
646   Redraw the ammo counter
647   If the plane can update the bombs
648   Redraw the bomb counter
649   If the plane can update the missile capacity...
650   Redraw the missile counter
651   If the plane can update the flare count...
652   Redraw the flare guage
653   BLOCK END - refuel
654   BLANK
655   BLANK
656   BLANK
657   BLANK

REARM PLANE COUNTER
658   Declares and defines topup with two arguments
659   Arguments one and two are a counter and a limit variable
660   BLOCK START - topup, provides a counter to rearm a single plane resource
661   Declare a local flag for resource updates
662   BLANK
663   Default flag is flag - no resource update
664   If the resource is already full
665   Then return false, no reloading to do
666   If the max resource is less than 20 (bombs,missiles,flares)
667   Then with every 20 ticks...
668   Increment the resource
669   Set the resource to a positive value (the player flag)
670   End tick check
671   Otherwise, the resource has a lot of units (fuel)
672   Increment the counter in small chunks every tick
673   Set the update flag
674   End check for resource type
675   If any updates pushed us beyond capacity
676   Reset the capacity to max
677   Return true or false if resource was incremented
678   BLOCK END - topup
679   BLANK
680   BLANK
681   BLANK
682   BLANK
683   BLANK

MOVE BULLETS
684   Declares and defines move shot with one argument
685   Argument 1 is a pointer to an input object
686   BLOCK START - moveshot, moves bullets through the air
687   Declares a local object pointer
688   Declares local position variables
689   BLANK
690   Point to the input bullet
691   Remove the bullet from the object list while we update
692   If the decremented bullet has no life span left then...
693   Decallocate the object
694   Return its destruction 
695   End case for end of life
696   BLANK
697   Update the bullet's position
698   BLANK
699   If the bullet leaves the top of the screen or hits the ground...
700   Or leaves the sides of the world...
701   Deallocate the object
702   Return its destruction again
703   End case for boundary check
704   BLANK
705   Put the bullet back on the object list
706   Update the symbol (white with XOR flag set)
707   Return true - the bullet lives
708   BLOCK END - moveshot
709   BLANK
710   BLANK
711   BLANK

MOVE BOMBS
712   Declares and defines movebomb with one argument
713   Argument 1 is a pointer to a bomb object
714   BLOCK START - movebomb, moves an input bomb as it falls
715   Declares a local object pointer
716   Declare local position variables
717   BLANK
718   Point to the input bomb
719   BLANK
720   Remove the bomb from the object list while we update
721   BLANK
722   If the bombs life span has become negative
723   Deallocate the object
724   Set the state to finished
725   Set the display segment to primary video memory
726   Update the world map
727   Return false since the bomb is now gone
728   End case for end of life bomb
729   BLANK
730   Update the fall angle of the bomb
731   BLANK
732   If the bomb hasn't started falling yet
733   Start the bomb sound effect
734   BLANK
735   Update the bomb's position
736   BLANK
737   If the bomb has left the world (not the top though)
738   Decallocate the object from memory
739   Stop the sound playing
740   Set the state to finished
741   Set the current display segment to primary video
742   Update the world map
743   Return false for the bombs destruction
744   End case for bomb leaving the world
745   BLANK
746   Update the graphic to the current orientation, maybe have changed
747   Put the bomb back on the object list
748   BLANK
749   If the bomb has left the top of the screen...
750   Return false for now(nothing to display)
751   BLANK
752   Set the current display to the primary video segment
753   Update the world drawing
754   Return true to display the bomb
755   BLOCK END - movebomb
756   BLANK
757   BLANK
758   BLANK

UPDATE FALLING DIRECTION (BOMBS, SHRAPNEL)
759   Declares and defines adjustfall with one argument
760   Argument 1 is a pointer to a bomb
761   BLOCK START - adjustfall, changes bomb falling angle
762   Declares a local object pointer
763   BLANK
764   Point to the input bomb object
765   If the decremented bomb's life is zero
766   And it is falling...
767   And moving left...
768   Then slow it's left progress
769   Otherwise it might be moving right...
770   If there is right progress..
771   Slow the right progress
772   If the problem is not falling 10 pixels per second
773   Increase its fall speed
774   Reset the bomb life counter
775   End case for changing bomb fall
776   BLOCK END - adjustfall
777   BLANK
778   BLANK
779   BLANK

UPDATE OBJECT FALLING ANGLES
780   Declares a defines symangle with one argument
781   Argument 1 is an input object
782   BLOCK START - symangle, coverts movement vectors to one of eight angles
783   Declare local variables for movement speeds
784   BLANK
785   Get the speed along the x vector
786   Get the speed alogn the y vector
787   If the bomg isn't moving fowward...
788   And it is falling...
789   Then the bomb should face angle 6 (straight down)
790   Otherwise, it's not moving forward/backward but..
791   If it's going up...
792   Choose return angle 2 (straight up)
793   Otherwise, a completely motionless bomb...
794   So return angle 6 (straight down)
795   However, if the bomb does have forward movement...
796   To the right...
797   And it's falling..
798   Make it angle 7 - down and to the right
799   But if it's going right..
800   And upwards...
801   Then it's going up and to the right 
802   Finally..
803   If it's just going to the right, then face that way
804   The final case is moving left...
805   and downward...
806   Return angle 5 for left and down..
807   Otherwise...
808   it's moving upwards
809   So return angle 3 for up and left
810   If this stuff fails...
811   Then it must be angle 4, down and left... Q.E.D.
812   BLOCK END - symangle
813   BLANK
814   BLANK
815   BLANK

MOVE MISSILES
816   Declares and defines movemiss with one argument
817   Argument 1 is a pointer to a missil object
818   BLOCK START - movemiss
819   Declares a local object pointer
820   Declare temporary variables for 
821   Declares another local object pointer for the target
822   BLANK
823   Point to the input missile
824   BLANK
825   Remove the missile from the object list while we update it
826   BLANK
827   If the missile has reached the end of its life
828   Return the object from the memory pool
829   Set its state to finished
830   Set the display segment to the video memory
831   Update the world minimap
832   Return false since there is no display
833   End case for end of missile life
834   BLANK
835   If the missile is flying...
836   And the target is not the object owner...
837   And its on an odd tick..
838   And there is a valid target
839   Reaffirm the object target
840   Adjust the aim of the missile
841   Save the new angle...
842   ..with the updated flap position accounting for angle wrap
843   Update the missile's movement vectors in the x...
844   and y vector..
845   End case for odd tick, for all ticks...
846   Update the missile position
847   If the decemented life counter runs out, or the missile is too high...
848   Change the missile state to falling..
849   And give it some extra life
850   End of case for missile flying
851   Otherwise the missile is no longer flying
852   Adjust its fall angle..
853   Account for angle wrap
854   Update the missile's position
855   End case for missile movement
856   BLANK
857   If the missile has left the world...
858   Decallocate the object
859   Set its state to finished
860   Update the screen segment to the video ram
861   Update the world minimap
862   Return false since there's no display
863   End case for leaving the world
864   BLANK
865   Update the missile graphic every tick based on angle
866   Readd the object to the list
867   BLANK
868   If the missile has left the top of the screen
869   Return false, nothing to draw
870   BLANK
871   Update the screen segment to the video ram
872   Update the world minimap
873   Return true to draw the missile
874   BLOCK END - movemiss
875   BLANK
876   BLANK
877   BLANK

MOVE FLARES
878   Declares and defines moveburst with one argument
879   Argument 1 is a pointer to a flare
880   BLOCK START - moveburst, moves a flare (falls to the ground)
881   Declares a local object pointer
882   Declare local position variables
883   BLANK
884   Point to the input flare object
885   Remove it from the object list
886   If the flare has reached the end of its life span
887   Remove the owner flag
888   Return the object to the memory pool
889   Return false - nothing to display
890   End case for flare end of life
891   BLANK
892   Adjust the flare's fall direction
893   Update the flare's position and return the new position
894   BLANK
895   IF the flare hits the ground or leaves the edges of the world...
896   Remove the flare owner
897   Remove the flare from it's sad existence
898   Return false
899   End case for leaving the world
900   BLANK
901   Reset the object target
902   Update the flare graphic
903   Readd it to the list
904   Display the flare if it's still on the screen
905   BLOCK END - moveburst
906   BLANK
907   BLANK
908   BLANK
909   BLANK

MOVE TARGETS
910   Declare and define movetarg with one argument
911   Argument 1 is a pointer to a target object
912   BLOCK START - movetarg, moves a target (fires at player after game 1)
913   Declare a local range integer
914   Declares two local object pointers
915   BLANK
916   Point to the target
917   Point to the top of the object list (usually the player)
918   Reset the target's firing state
919   If this isn't the first game (difficulty) and the building isn't dead..
920   And the target plane is flying...
921   or stalled..
922   or wounded..
923   or wounded and stalled..
924   and is on the opposite team...
925   ...and the delay counter matches...
926   ...and is within positive x range...
927   ...and positive y range...
928   ...and isn't too far away...
929   Then take the shot already!!
930   BLANK
931   If the target building's hit counter is below zero..
932   Reset the hit counter
933   BLANK
934   Update the graphic based on if the building is still alive...
935   If so, use the orientation symbol
936   Otherwise, use the broken building symbol
937   Return true, buildings never vanish, dead or alive
938   BLOCK END - movetarg
939   BLANK
940   BLANK
941   BLANK

MOVE SHRAPNEL
942   Declares and defines moveexpl with one argument
943   Argument 1 is a pointer to a piece of an explosion
944   BLOCK START - moveexpl, moves shrapel after an explosion
945   Declares a local object pointer
946   Declare local position variables
947   Declare a local orientation variable
948   BLANK
949   Point to the input piece of shrapnel
950   Save the object's orientation
951   Remove the shrapnel from the list for processing
952   BLOCK START - shrapnel is dead, if the life counter has gone negative..
953   ..and the object has a graphic..
954   Stop playing its sound
955   Deallocate the object 
956   Return its destruction to the caller
957   BLOCK END - shrapnel is dead
958   BLANK
959   BLOCK START - shrapnel is at zero life, If object decrements to 0
960   If the object is falling...
961   and it is moving less..
962   then slow it's leftward movement
963   Otherwise...
964   Check if it's moving right..
965   And if so, slow it's rightward movement.
966   If the shrapnel isn't in fast freefall
967   ...or doesn't have a graphic while not moving
968   Make it fall faster
969   Reset the object life counter
970   BLOCK END - shrapnel is at zero life
971   BLANK
972   Update the object's position and store in our local variables
973   BLANK
974   If the shrapnel has fallen in to the ground...
975   ..or off either end of the world..
976   Then if it has a valid graphic..
977   Stop playing it's sound
978   and remove it from memory
979   Return the vanishing shrapnel
980   End case for dead shrapnel check
981   Increment the shrapnel's hit counter
982   BLANK
983   Ad it back to the object list
984   Update the graphic, if needed
985   Return true if the object is below the top of the screen
986   BLOCK END - moveexpl
987   BLANK
988   BLANK
989   BLANK

MOVE SMOKE
990   Declares and defines movesmok with one argument
991   Argument 1 is a pointer to an input smoke object
992   BLOCK START - movesmok, moves a smoke object (actually just decays it)
993   Declares a local object pointer
994   Declare a local variable to hold state
995   BLANK
996   Point to the smoke object
997   Decrement the smoke life, and if it's 0..
998   Grab the owner's state and if it isn't falling...
999   Or wounded..
1000  Or really rounded..
1001  Or dead...
1002  Then the plane is ok so decallocate the smoke
1003  and return its demise
1004  End case for zero life
1005  Reset the smoke graphic to XOR owner color
1006  BLANK
1007  Return that the smoke lives
1008  BLOCK START - movesmok
1009  BLANK
1010  BLANK
1011  BLANK

MOVE FLOCK OF BIRDS
1012  Declares and defines moveflck with one argument
1013  Argument 1 is a pointer to a flock of birds
1014  BLOCK START - moveflck
1015  Declares a local object pointer
1016  Declares local position integers
1017  BLANK
1018  Point to the input bird flock
1019  Remove the flock from the object list while we work on it
1020  BLANK
1021  If the bird flock's life has dropped to -1..
1022  Then swap to primary video display
1023  Update the world object display
1024  Deallocate the bird object
1025  Return false, no longer exists
1026  End change for dead bird flock
1027  BLANK
1028  Decrement flock life counter and if it's now zero...
1029  Change the bird flap graphic
1030  Reset the bird flock life to 5 ticks
1031  End case for graphic change
1032  BLANK
1033  If the flock has flown beyond it's cage at work positions 50 and 2950..
1034  Reverse the flock's travel direction
1035  BLANK
1036  Update the flock's position storing the new position in local variables
1037  Put the flock back in to the object list
1038  Update the flock graphic
1039  Reset to main video display
1040  Update the world minimap
1041  Return true, the flock lives on
1042  BLOCK END - moveflck
1043  BLANK
1044  BLANK
1045  BLANK

MOVE BIRDS
1046  Declares and defines movebird with 1 argument
1047  Argument 1 is a pointer to a single bird
1048  BLOCK START - movebird, moves a single bird
1049  Declares a local object pointer
1050  Declare local position integers
1051  BLANK
1052  Point to the bird
1053  BLANK
1054  Remove the bird from the object list while we process it
1055  BLANK
1056  If the bird's life counter falls negative...
1057  Deallocate the object slot
1058  Return false
1059  End of case for -1 life counter
1060  If the bird's life falls to -2 then...
1061  Change vertical direction
1062  Mask x movement to fall between 0 and 7 minus 4
1063  Reset the bird life counter to 4
1064  End case for -2 bird life counter
1065  Otherwise, decrement bird life and if the counter is at 0
1066  Change orientation (wing flap)
1067  Reset bird life to 4
1068  End change for bird lifecycle
1069  BLANK
1070  Update the bird location based on movement, store position in x and y
1071  BLANK
1072  Add the bird object back to the object list
1073  Update the bird graphic, the wing flag state may have changed
1074  If the bird flies too high, hits the ground...
1075  or flies off the left or right of the world...
1076  Then invert the bird's vertical direction
1077  Set it's life to -2
1078  Return faulse
1079  End case for world boundary check
1080  If we've made it this far, return true
1081  BLOCK END - movebird
1082  BLANK
1083  BLANK
1084  BLANK
1085  BLANK

MOVE OX (NOT LITERALLY, MOVE FROM ALIVE TO DEAD)
1086  Declares and defines moveox with one argument
1087  Argument 1 is a pointer to an ox
1088  BLOCK START - moveox, mooooooves the ox (not really used)
1089  BLANK
1090  Sets the ox graphic to dead
1091  Returns true always
1092  BLOCK END - moveox
1093  BLANK
1094  BLANK
1095  BLANK
1096  BLANK

HANDLE PLANE CRASH
1097  Declare and define crashpln with one argumen
1098  Argument 1 is a pointer to the crashing plane
1099  BLOCK START - crashpln, handles crashes with other planes
1100  Declares a local object pointer
1101  BLANK
1102  Point to the input plane object
1103  BLANK
1104  If the object is moving left...
1105  Tip the plane 32 degrees counter clockwise
1106  Otherwise, it's moving right so...
1107  Tip the plane 32 degrees clockwise
1108  BLANK
1109  Set the object's state to crashed with variations for ghosts or not
1110  A crashed plane isn't at home
1111  Set all motion to 0
1112  BLANK
1113  Point to the other plane
1114  Set the hit counter based on if the nearest opponent's x difference..
1115  ...and the nearest opponents y difference...
1116  If to close then hit count is 64 ticks, otherwise it's safe so 32 ticks
1117  BLANK
1118  BLOCK END - crashpln
1119  BLANK
1120  BLANK
1121  BLANK

HIT ANOTHER PLANE
1122  Declare and define hitpln with 1 argument
1123  Argument 1 is a pointer to the hit plane
1124  BLOCK START - hitpln, sets state for a plane that was hit
1125  Declare a local pointer to an object
1126  BLANK
1127  Point to the input plane
1128  Reset the last movement variables
1129  Set the plane's hit counter to the falling default (10)
1130  Set the plane to falling
1131  The plane can't be at home if it's falling
1132  BLOCK END - hitpln
1133  BLANK
1134  BLANK
1135  BLANK

PLANE STALL
1136  Declare and define stallpln with 1 Argument
1137  Argument 1 is a pointer to a plane object
1138  BLOCK START - stallpln, sets a plane to stall mode
1139  Declares a local object pointer
1140  BLANK
1141  Point to the input plane  
1142  Reset all of the movement vectors and orientations
1143  Set the plane's angle to 14 (down and to the right)
1144  Set the plane's speed to 0
1145  Set the plane's vertical motion to 0
1146  Set the hitcounter to stall (delay's player actions)
1147  Set plane's state to stall with variations on current ghost state...
1148  ...or based on current wounded state
1149  The plane can't be at base if it's stalled
1150  BLOCK END - stallpln
1151  BLANK
1152  BLANK
1153  BLANK
1154  BLANK

INSERT OBJECT IN TO LINKED LIST
1155  Declare and define insertx with 2 arguments
1156  Arguments 1 and 2 are pointers to objects
1157  BLOCK START - insertx, inserts object in to object linked list
1158  Declare a local pointer to an object
1159  Declares a local variable used for object x coordinate
1160  BLANK
1161  Point to the 2nd input object
1162  Store the 1st object's x coordinate
1163  If the first object is less than the second object...
1164  Loop while the first object continues to be left of the target
1165  Follow the linked list backward
1166  Recheck loop invarient and repeat
1167  Otherwise, we're to the right of the object so...
1168  Loop while the input object's x is greater than the target
1169  Follow the list until the invarient breaks
1170  Set the previous object
1171  End list traversal
1172  Set the input object's next to the target object's next
1173  Set the input object previous to the target
1174  Fix up the previous object
1175  Fix up the next object
1176  BLOCK END - insertx
1177  BLANK
1178  BLANK
1179  BLANK
1180  BLANK

DELETE OBJECT FROM LINKED LIST
1181  Declare and define deletex with one argument
1182  Argument 1 is a pointer to a game object
1183  BLOCK START - deletex, deletes an object from the linked list
1184  Declares a local object pointer
1185  BLANK
1186  Point to the input object
1187  Change the next object's parent to the previous (no check for NULL?)
1188  Change the previous object's child to the next object
1189  BLOCK END - deletex
1190  EOF