home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / uswar.zip / FLEET.PAS < prev    next >
Pascal/Delphi Source File  |  1980-01-01  |  26KB  |  865 lines

  1. Program FLEET;
  2.  
  3. {This module will allow the player to select the fleets from his
  4. navy. Fleets will be posted in the theaters given in the game
  5. data file.  Up to four theaters may be used.
  6. Repeat
  7. .  Read map and display
  8. .  Clear all fleet assignments
  9. .  Do until all fleets OK
  10. .  .  Display navy to right of map
  11. .  .  Initialize all fleets
  12. .  .  Set to first fleet
  13. .  .  Do until all fleets selected
  14. .  .  .  Show selected ship status on demend
  15. .  .  .  Clear map fleet area
  16. .  .  .  If cursor at ships in port
  17. .  .  .  .   Move cursor to select ship
  18. .  .  .  .   Select ship on CR
  19. .  .  .  .   Move ship from port to fleet
  20. .  .  .  Else
  21. .  .  .  .   Restore fleet ships to ships in port
  22. .  .  .  End
  23. .  .  End
  24. .  End
  25. .
  26. .  Decrement damage of all Allied ships in port
  27. .  Randomly select Axis fleets
  28. .  Decrement damage of all Axis ships in port (if any)
  29. .
  30. .  Engage in combat
  31. .  Clear all Work1 (shots taken)
  32. .  Set round to 0
  33. .  For each theater
  34. .  .   Increment the round
  35. .  .   Repeat until all surface ships on one side eliminated
  36. .  .   .   Randomly select Axis Combat followed by Allied Combat or vice versa
  37. .  .   End
  38. .  End
  39. .
  40. .  Calculate victory points
  41. .
  42. until victory point delta is five or as selected from input data set
  43. Display winner}
  44.  
  45. {$ICOMMON.PAS}
  46. {$IPUTPIC.PAS}
  47. {$ICURSOR.PAS}
  48. {$IBORDER.PAS}
  49. {$IWIND.PAS}
  50. {$IBEEP.PAS}
  51.  
  52. VAR list:array[1..20] of integer;
  53.     Allied_Total,Axis_Total,
  54.     Allied_Ship_Cnt,Axis_Ship_Cnt,
  55.     Allied_Sub_Cnt,Axis_Sub_Cnt,
  56.     Allied_Ship_No,Axis_Ship_No:integer;
  57.     Round:integer;
  58.     Sub_Shots,key,scnt,acnt,xcnt:integer;
  59.     Temp_Name:string[10];
  60.     Theamax:array[1..8] of integer;
  61.     init_no:real;
  62.     Cur_Ctl,Max_Ships,Assg_Ships,Turn:integer;
  63.  
  64. Procedure Ships_in_Port;                           {Display ships not assigned}
  65. Begin                                              {to a theater}
  66.   Gotoxy(66,1);
  67.   FastWrite('Ships in Port',7,0,1);
  68.   For i:=1 to Ships do
  69.     Begin
  70.       Gotoxy(67,i+2);
  71.       With Allied_Navy[i] do
  72.         If (Status<>9) and (Fleet=0) then
  73.            begin
  74.              If Theater=0 then FastWrite(' ',7,0,1)
  75.              else Fastwrite('*',7,0,1);
  76.              FastWrite(ID,7,0,1);
  77.            end
  78.         Else
  79.            FastWrite('           ',7,0,1);
  80.     end;
  81. end;
  82.  
  83. Procedure Pick_Fleets;
  84.  
  85. begin
  86.  
  87. gotoxy(24,24);
  88. Fastwrite('Enter ? for help',7,0,1);
  89. theano:=1;                                              {Display first theater}
  90. cmax:=Theater[1].max;
  91. ixloc:='p';                                      {Set location pointer to port}
  92. portix:=1;                                       {Set to first ship}
  93. theaix:=1;
  94. For i:=1 to theacnt do                           {Clear fleet assignments}
  95.   begin
  96.     For j:=1 to 20 do
  97.        begin
  98.           Allied_Fleet[i,j]:=0;
  99.           Axis_Fleet[i,j]:=0;
  100.        end;
  101.   end;
  102.  
  103. for i:= 1 to 20 do
  104.  begin
  105.    Allied_Navy[i].Fleet:=0;
  106.    Axis_Navy[i].Fleet:=0;
  107.  end;
  108.  
  109. Ships_in_Port;
  110.  
  111. TheaWind(theano);
  112. repeat
  113.  
  114.   begin
  115.     cx:=66;                                        {Set cursor select position}
  116.     cy:=portix+2;
  117.     if ixloc='t' then
  118.       with Theater[theano] do
  119.         begin
  120.            cx:=x+1;
  121.            cy:=theaix+1+y;
  122.            cmax:=max;
  123.         end;
  124.     gotoxy(cx,cy);
  125.     Fastwrite(chr(26),15,0,3);
  126.     Uncursor;
  127.  
  128.     l:=cursor;                                     {Read character}
  129.     case l of
  130.      32: begin                                              {Advance theater}
  131.             Restore;
  132.             theano:=theano+1;
  133.             if theano>theacnt then theano:=1;
  134.             TheaWind(theano);
  135.             theaix:=1;
  136.             cmax:=theater[theano].max;
  137.           end;
  138.      4:  begin                                              {Advance cursor}
  139.            if ixloc='p' then
  140.              begin
  141.                Cur_Ctl:=portix;
  142.                repeat
  143.                  portix:=portix+1;
  144.                  if portix>Ships then portix:=1;
  145.                until ((Allied_Navy[portix].fleet=0) and
  146.                      (Allied_Navy[portix].status<>9)) or (portix=Cur_Ctl);
  147.              end
  148.            else
  149.              with theater[theano] do
  150.                begin
  151.                   Cur_Ctl:=theaix;
  152.                   repeat
  153.                      theaix:=theaix+1;
  154.                      if theaix>max then theaix:=1;
  155.                   until (Allied_Fleet[theano,theaix]>0) or (theaix=Cur_Ctl);
  156.                end;
  157.            end;
  158.      3:  begin                                              {Decrement cursor}
  159.            if ixloc='p' then
  160.              begin
  161.                Cur_Ctl:=portix;
  162.                repeat
  163.                  portix:=portix-1;
  164.                  if portix<1 then portix:=Ships;
  165.                until ((Allied_Navy[portix].fleet=0) and
  166.                       (Allied_Navy[portix].status<>9)) or
  167.                      (portix=Cur_Ctl);
  168.              end
  169.            else
  170.              with theater[theano] do
  171.                begin
  172.                  Cur_Ctl:=theaix;
  173.                  repeat
  174.                    theaix:=theaix-1;
  175.                    if theaix<1 then theaix:=max;
  176.                  until (Allied_Fleet[theano,theaix]<>0) or
  177.                        (theaix=Cur_Ctl);
  178.                end;
  179.  
  180.          end;
  181.      1:  ixloc:='t';                            {switch to theater}
  182.      2:  ixloc:='p';                            {switch to port}
  183.      13: begin
  184.            if (ixloc='p') then                  {switch ship from port to}
  185.              begin                              {theater}
  186.                 with Allied_Navy[portix] do
  187.                 if (Fleet=0) and (Status<>9) and
  188.                    ((Theater=0) or (Theater=theano)) then
  189.                   begin
  190.                     theaix:=0;
  191.                     repeat
  192.                       theaix:=theaix+1;
  193.                     until (theaix>cmax) or (Allied_Fleet[theano,theaix]=0);
  194.                     if theaix<=cmax then
  195.                        begin
  196.                          Fleet:=theano;
  197.                          Allied_Fleet[theano,theaix]:=portix;
  198.                        end
  199.                     else
  200.                        theaix:=cmax;
  201.                     end;
  202.                   end
  203.                 else
  204.                   begin
  205.                     i:=Allied_Fleet[theano,theaix];  {switch ship from theater}
  206.                     if i>0 then                      {to port}
  207.                        begin
  208.                          Allied_Navy[i].Fleet:=0;
  209.                          Allied_Fleet[theano,theaix]:=0;
  210.                        end;
  211.                   end;
  212.                   TheaWind(theano);
  213.                   Ships_in_Port;
  214.          end;
  215.      115,
  216.      83: begin                                       {Display status}
  217.            if (ixloc='p') and (Allied_Navy[portix].Fleet=0) and
  218.               (Allied_Navy[portix].Status<>9) then
  219.            DispStatus(portix);
  220.            if ixloc='t' then
  221.              begin
  222.                i:=Allied_Fleet[theano,theaix];
  223.                if i<>0 then
  224.                  DispStatus(i);
  225.              end;
  226.           end;
  227.      63:  begin
  228.            Restore;
  229.            Windx:=16;                                  {Setup window}
  230.            Windy:=8;
  231.            Winddx:=33;
  232.            Winddy:=11;
  233.            Border(Windx,windy,winddx,winddy,1,15,0);
  234.            Window(Windx+1,Windy+1,Windx+Winddx-2,Windy+winddy-2);
  235.            ClrScr;
  236.            Gotoxy(5,9);                                {Display static data}
  237.            FastWrite('PRESS ANY KEY TO CONTINUE',7,0,1);
  238.            Gotoxy(1,1);
  239.            FastWrite(' Up/Down cursors select ship',7,0,1);
  240.            Gotoxy(1,2);
  241.            FastWrite(' Left/Right switch theater/port',7,0,1);
  242.            Gotoxy(1,3);
  243.            FastWrite(' ENTER moves ship',7,0,1);
  244.            Gotoxy(1,4);
  245.            FastWrite(' END completes selection',7,0,1);
  246.            Gotoxy(1,5);
  247.            FastWrite(' S or s displays ship status',7,0,1);
  248.            Gotoxy(1,6);
  249.            FastWrite(' Space advances theater',7,0,1);
  250.            Gotoxy(1,7);
  251.            FastWrite(' Q or q terminates game ',7,0,1);
  252.            Window(1,1,80,25);
  253.            uncursor;
  254.            Kbdrd;
  255.            Restore;
  256.            TheaWind(theano);
  257.          end;
  258.  
  259.     end; {case}
  260.     if l<>32 then                                 {Clear cursor unless theater}
  261.       begin                                       {changed}
  262.          Gotoxy(cx,cy);                           {Clear cursor}
  263.          Fastwrite(' ',7,0,3);
  264.       end;
  265.   end;
  266. until (l=5) or (quitsw=1);                                        {End inputted}
  267.  
  268. For i:=1 to ships do
  269.   begin
  270.     with Allied_Navy[i] do
  271.       if (Fleet=0) and (Status<>9) and (Damage>0) then
  272.       Damage:=Damage-1;
  273.   end;
  274.  
  275. For i:=1 to 20 do                                      {Shuffle list index}
  276.   list[i]:=i;
  277.  
  278. For i:=1 to 50 do
  279.   begin
  280.     j:=random(20)+1;
  281.     k:=random(20)+1;
  282.     l:=list[j];
  283.     list[j]:=list[k];
  284.     list[k]:=l;
  285.   end;
  286.  
  287. Max_Ships:=0;
  288. For i:=1 to theacnt do                                {Clear fleet counts}
  289.   begin                                               {and set max fleet cnt}
  290.     Axis_Fleet_Count[i]:=1;                           {allowed}
  291.     Theamax[i]:=Theater[i].max;
  292.     Max_Ships:=Max_Ships+Theamax[i];
  293.   end;
  294.  
  295. Assg_Ships:=0;
  296. For n:=1 to 20 do                                     {Move fixed theater ships}
  297.   with Axis_navy[n] do                                {to theater}
  298.    begin
  299.     if Max_Ships>Assg_Ships then
  300.     begin
  301.       if (Theater<>0) and (status<>9) and
  302.          (Axis_Fleet_Count[Theater]<=Theamax[Theater]) then
  303.         begin
  304.           Fleet:=Theater;
  305.           Axis_Fleet[theater,Axis_Fleet_Count[Theater]]:=n;
  306.           Axis_Fleet_Count[Theater]:=Axis_Fleet_Count[Theater]+1;
  307.           Assg_Ships:=Assg_Ships+1;
  308.         end;
  309.     end;
  310.    end;
  311.  
  312. n:=0;                                                 {Randomly select rest of}
  313. For i:=1 to 20 do                                     {axis fleets}
  314.   begin
  315.      with Axis_Navy[list[i]] do                       {pick ship}
  316.        begin
  317.          if Max_Ships>Assg_Ships then
  318.            begin
  319.              if (fleet=0) and (status<>9) and (damage<(defense/2)) then
  320.                 begin
  321.                   repeat
  322.                     n:=n+1;                             {select theater}
  323.                     if n>theacnt then n:=1;
  324.                    {gotoxy(1,1);write(max_Ships,' ',assg_Ships);read(kbd,c);}
  325.                   until Axis_Fleet_Count[n]<=Theamax[n];
  326.                   Fleet:=n;
  327.                   Axis_Fleet[n,Axis_Fleet_Count[n]]:=list[i];
  328.                   Axis_Fleet_Count[n]:=Axis_Fleet_Count[n]+1;
  329.                   Assg_Ships:=Assg_Ships+1;
  330.                 end;
  331.            end;
  332.        end;
  333.   end;
  334.  
  335. For i:=1 to 20 do
  336.   begin
  337.     with Axis_Navy[i] do
  338.       if (Fleet=0) and (Status<>9) and (Damage>0) then
  339.       Damage:=Damage-1;
  340.   end;
  341.  
  342. if quitsw<>1 then
  343.  begin
  344.     For m:=1 to theacnt do
  345.       TheaWind(m);
  346.  
  347.     gotoxy(20,24);
  348.     Fastwrite('PRESS ANY KEY TO CONTINUE',15,0,1);
  349.     uncursor;
  350.     Kbdrd;
  351.     gotoxy(1,1);
  352.  end;
  353. end;
  354.  
  355.  
  356. Procedure Up_Axis_Cnt(n:integer);   {Increment Axis ship/sub counters}
  357. begin
  358.   If Axis_Navy[n].Model='S' then Axis_Sub_Cnt:=Axis_Sub_Cnt+1
  359.   else Axis_Ship_Cnt:=Axis_Ship_Cnt+1;
  360. end;
  361.  
  362. Procedure Up_Allied_Cnt(n:integer);   {Increment Allied ship/sub counters}
  363. begin
  364.   If Allied_Navy[n].Model='S' then Allied_Sub_Cnt:=Allied_Sub_Cnt+1
  365.   else Allied_Ship_Cnt:=Allied_Ship_Cnt+1;
  366. end;
  367.  
  368. Procedure ReCalc(tn:integer);                       {Rearrange and reorder}
  369. begin                                               {ships in theater to}
  370.                                                     {eliminate blank spots}
  371. Allied_Ship_Cnt:=0;
  372. Allied_Sub_Cnt:=0;
  373. For i:=1 to Theater[tn].max do
  374.   begin
  375.     if Allied_Fleet[tn,i]=0 then
  376.       begin
  377.         for j:=(i+1) to Theater[tn].max do
  378.           begin
  379.             if Allied_Fleet[tn,j]<>0 then
  380.               begin
  381.                 Allied_Fleet[tn,i]:=Allied_Fleet[tn,j];
  382.                 Allied_Fleet[tn,j]:=0;
  383.                 Up_Allied_Cnt(Allied_Fleet[tn,i]);
  384.                 j:=Theater[tn].max;
  385.               end;
  386.           end;
  387.       end
  388.     else
  389.       Up_Allied_Cnt(Allied_Fleet[tn,i]);
  390.   end;
  391. Allied_Total:=Allied_Ship_Cnt+Allied_Sub_Cnt;
  392. Axis_Ship_Cnt:=0;
  393. Axis_Sub_Cnt:=0;
  394. For i:=1 to Theater[tn].max do
  395.   begin
  396.     if Axis_Fleet[tn,i]=0 then
  397.       begin
  398.         for j:=(i+1) to Theater[tn].max do
  399.           begin
  400.             if Axis_Fleet[tn,j]<>0 then
  401.               begin
  402.                 Axis_Fleet[tn,i]:=Axis_Fleet[tn,j];
  403.                 Axis_Fleet[tn,j]:=0;
  404.                 Up_Axis_Cnt(Axis_Fleet[tn,i]);
  405.                 j:=Theater[tn].max;
  406.               end;
  407.           end;
  408.       end
  409.     else
  410.       Up_Axis_Cnt(Axis_Fleet[tn,i]);
  411.   end;
  412. Axis_Total:=Axis_Ship_Cnt+Axis_Sub_Cnt;
  413. TheaWind(tn);
  414. Window(66,3,80,24);
  415. gotoxy(1,21);
  416. end;
  417.  
  418. Procedure HiLite(as,xs:integer);
  419.  
  420. begin
  421. Allied_Ship_No:=Allied_Fleet[Theano,as];
  422. Axis_Ship_No:=Axis_Fleet[Theano,xs];
  423. with theater[theano] do
  424.   begin
  425.     Window(x+1,y+1,x+23,y+max+2);
  426.     if as <> 0 then
  427.       begin
  428.         gotoxy(2,as+1);
  429.         with Allied_Navy[Allied_Ship_No] do
  430.           Fastwrite(ID,0,15,1);
  431.       end;
  432.     if xs <> 0 then
  433.       begin
  434.         gotoxy(13,xs+1);
  435.         with Axis_Navy[Axis_ship_No] do
  436.           Fastwrite(ID,0,15,1);
  437.       end;
  438.   end;
  439. end;
  440.  
  441.  
  442. Procedure Do_Return;
  443. begin
  444. if quitsw<>1 then
  445.   begin
  446.     Writeln;
  447.     Writeln('PRESS ANY KEY');
  448.     Writeln('TO CONTINUE.');
  449.     Window(1,24,80,25);
  450.     ClrScr;
  451.     Gotoxy(15,1);
  452.     FastWrite(Temp_Name+' Battle Phase',15,0,1);
  453.     uncursor;
  454.     Kbdrd;
  455.     Window(66,1,80,25);
  456.     ClrScr;
  457.     Recalc(Theano);
  458.     Theawind(Theano);
  459.   end;
  460. end;
  461.  
  462. Procedure Battle_Results;                {Calculate and display battle results}
  463.  
  464. begin
  465. ReCalc(theano);
  466. TheaWind(theano);
  467. Window(66,3,80,24);
  468. ClrScr;
  469. Gotoxy(2,2);
  470. Writeln('BATTLE RESULTS');
  471. Writeln;
  472. if ((Axis_Ship_Cnt>0) and (Allied_Sub_Cnt>0)) or
  473.    ((Allied_Ship_Cnt>0) and (Axis_Sub_Cnt>0)) or
  474.    (Allied_Ship_Cnt=Axis_Ship_Cnt) then             {I.E. Are both=0}
  475.    begin
  476.      writeln('  Battle is');
  477.      writeln('   a draw');
  478.    end
  479. else
  480.    begin
  481.      if Allied_Ship_Cnt>0 then
  482.         begin
  483.           Victory_Points:=Victory_Points+1;
  484.           for n:= 1 to Allied_Total do
  485.             begin                                {See if Convoy survived}
  486.               with Allied_Navy[Allied_Fleet[theano,n]] do
  487.               begin
  488.                 if model='V' then
  489.                   begin
  490.                     Victory_Points:=Victory_Points+1; {increment VP}
  491.                     Fleet:=0;                         {remove convoy}
  492.                     Status:=9;
  493.                     Allied_Fleet[theano,n]:=0;
  494.                     Writeln('  Convoy VP');
  495.                   end;
  496.               end;
  497.             end;
  498.           Temp_name:=Allied_Name;
  499.         end
  500.      else
  501.         begin
  502.           Victory_Points:=Victory_Points-1;
  503.           for n:= 1 to Axis_Total do
  504.             begin                                {See if Convoy survived}
  505.               with Axis_Navy[Axis_Fleet[theano,n]] do
  506.               begin
  507.                 if model='V' then
  508.                   begin
  509.                     Victory_Points:=Victory_Points-1; {increment VP}
  510.                     Fleet:=0;                         {remove convoy}
  511.                     Status:=9;
  512.                     Axis_Fleet[theano,n]:=0;
  513.                     Writeln('  Convoy VP');
  514.                   end;
  515.               end;
  516.             end;
  517.           Temp_name:=Axis_Name;
  518.         end;
  519.      Writeln('   '+Temp_name);
  520.      Writeln(' wins battle');
  521.    end;
  522. Writeln;
  523. Writeln('   Turn  ',Turn);
  524. Writeln('   VPs = ',abs(Victory_Points));
  525. Writeln('     of ',Victory_Points_to_win);
  526. Writeln(' needed to win');
  527. Writeln;
  528. Temp_Name:=Axis_Name;
  529. if Victory_Points>0 then Temp_Name:=Allied_Name;
  530. Writeln('   '+Temp_Name);
  531. Writeln('   advantage');
  532. Do_Return;
  533. end;
  534.  
  535. Procedure Do_Attack(as,ts:integer);
  536.  
  537. var Target_Total,Attacker_Total,
  538.     Target_Ship_Cnt,Attacker_Ship_Cnt,
  539.     Target_Sub_Cnt,Attacker_Sub_Cnt:integer;
  540.     Target_Fleet,Attacker_Fleet:Fleet_Kind;
  541.     Target:Ship;
  542.     Attacker:Ship;
  543.  
  544. begin
  545. If Temp_Name=Axis_Name then
  546.   begin
  547.     Target_Total:=Allied_Total;
  548.     Target_Ship_Cnt:=Allied_Ship_Cnt;
  549.     Target_Sub_Cnt:=Allied_Sub_Cnt;
  550.     Target:=Allied_Navy[Allied_Fleet[theano,ts]];
  551.     Target_Fleet:=Allied_Fleet[theano];
  552.     Attacker_Fleet:=Axis_Fleet[theano];
  553.     Attacker:=Axis_Navy[Axis_Fleet[theano,as]];
  554.     i:=as;
  555.     j:=ts;
  556.   end
  557. else
  558.   begin
  559.     Target_Total:=Axis_Total;
  560.     Target_Ship_Cnt:=Axis_Ship_Cnt;
  561.     Target_Sub_Cnt:=Axis_Sub_Cnt;
  562.     Target:=Axis_Navy[Axis_Fleet[theano,ts]];
  563.     Target_Fleet:=Axis_Fleet[theano];
  564.     Attacker_Fleet:=Allied_Fleet[theano];
  565.     Attacker:=Allied_Navy[Allied_Fleet[theano,as]];
  566.     i:=ts;
  567.     j:=as;
  568.   end;
  569.  
  570. if (Target_Total>0) and ((Attacker.Model<>'S') or
  571.                         ((Attacker.Model='S') and (Round=1) and
  572.                         ((Target.Model<>'S') and
  573.                          (Target.Model<>'K') and
  574.                          (Target.Model<>'P')))) then
  575.   begin
  576.     HiLite(j,i);
  577.     Window(66,3,80,24);
  578.     ClrScr;
  579.  
  580.     gotoxy(1,1);
  581.     writeln(Temp_Name);
  582.     writeln('ATTACK RESULTS');
  583.     writeln;
  584.     Writeln(Attacker.ID);
  585.     Writeln('attacking');
  586.     Writeln(Target.ID);
  587.     Writeln;
  588.     Writeln('Turn ',Turn);
  589.     Writeln('Round ',Round);
  590.     Writeln('Shot ',scnt,' of ',Attacker.attack);
  591.     Writeln;
  592.     j:=5;
  593.     k:=Random(6)+1;
  594.     if (Attacker.Model='D') and (Target.Model='S') then k:=6;
  595.     if (Attacker.Model<>'D') and (Target.Model='S')then j:=6;
  596.     if Attacker.Model='A' then j:=4;
  597.     if attacker.Model='K' then j:=3;
  598.     if k<j then
  599.       begin
  600.         Writeln('MISS');
  601.         Writeln;
  602.       end
  603.     else
  604.       begin
  605.         if Attacker.Model='K' then
  606.            begin                                           {remove kamikazi}
  607.               Attacker.Fleet:=0;
  608.               Attacker.Status:=9;
  609.               Attacker_Fleet[as]:=0;
  610.               If Temp_Name=Axis_Name then xcnt:=xcnt-1
  611.               else acnt:=acnt-1;
  612.               scnt:=Attacker.attack;
  613.            end;
  614.         if k=j then
  615.           begin
  616.             Writeln('DISABLED');
  617.             Target.Fleet:=0;                               {move target yo port}
  618.             Target_Fleet[ts]:=0;
  619.             Writeln;
  620.           end
  621.         else
  622.          begin
  623.             Writeln('HIT!!!!');
  624.             l:=random(3)+1;
  625.             if attacker.model='K' then l:=random(8)+1;     {set heavy hit from kamikazi}
  626.             if random(15)>=14 then l:=10;                  {randomly sink ship}
  627.             writeln('Damage = ',l,' Pts');
  628.             writeln;
  629.             with Target do
  630.               begin
  631.                 Damage:=Damage+l;
  632.                 If damage >= Defense then
  633.                   begin
  634.                     Status:=9;
  635.                     Writeln(ID);
  636.                     Writeln('has been sunk.');
  637.                     writeln;
  638.                     Fleet:=0;
  639.                     Target_Fleet[ts]:=0;
  640.                   end;
  641.               end;
  642.           end;
  643.       end;
  644.     If Temp_Name=Axis_Name then
  645.       begin
  646.         Allied_Navy[Allied_Fleet[theano,ts]]:=Target;
  647.         Allied_Fleet[theano]:=Target_Fleet;
  648.         Axis_Navy[Axis_Fleet[theano,as]]:=Attacker;
  649.         Axis_Fleet[theano]:=Attacker_Fleet;
  650.       end
  651.     else
  652.       begin
  653.         Axis_Navy[Axis_Fleet[theano,ts]]:=Target;
  654.         Axis_Fleet[theano]:=Target_Fleet;
  655.         Allied_Navy[Allied_Fleet[theano,as]]:=Attacker;
  656.         Allied_Fleet[theano]:=Attacker_Fleet;
  657.       end;
  658.     Do_Return;
  659.   end;
  660. end;
  661.  
  662.  
  663. Procedure Axis_Combat;
  664. begin
  665. if (Axis_Total>0) and (Allied_Total>0) then
  666.   begin
  667.     Temp_Name:=Axis_Name;
  668.     Sub_Shots:=Allied_Ship_Cnt;
  669.     for xcnt:= 1 to Axis_Total do
  670.       begin
  671.         with Axis_Navy[Axis_Fleet[TheaNo,xcnt]] do
  672.           begin
  673.             if model = 'S' then attack:=Sub_Shots;
  674.             scnt:=1;
  675.             while (scnt<=attack) and (Allied_Total>0) and (quitsw<>1) do
  676.                begin
  677.                   acnt:=random(Allied_Total)+1;
  678.                   Do_Attack(xcnt,acnt);
  679.                   scnt:=scnt+1;
  680.                end;
  681.           end;
  682.       end;
  683.   end;
  684. end;
  685.  
  686. Procedure Do_Battle;
  687.  
  688. begin
  689.   with Allied_Navy[Allied_Fleet[theano,acnt]] do
  690.     begin
  691.       Window(1,24,80,25);
  692.       ClrScr;
  693.       Gotoxy(12,1);
  694.       FastWrite('Attacker and target are highlighted. Enter ? for help.',15,0,1);
  695.       HiLite(acnt,xcnt);
  696.       uncursor;
  697.       key:=cursor;
  698.       case key of
  699.          5 : scnt:=attack;                          {complete firing}
  700.          4 : begin                                  {cursor down}
  701.                xcnt:=xcnt+1;
  702.                if xcnt>Axis_Total then xcnt:=1;
  703.              end;
  704.          3 : begin                                  {cursor up}
  705.                xcnt:=xcnt-1;
  706.                if xcnt<1 then xcnt:=Axis_Total;
  707.              end;
  708.     115,83 : DispStatus(Allied_Fleet[theano,acnt]);     {status}
  709.         13 : begin
  710.                 Do_Attack(acnt,xcnt);                   {do attack}
  711.                 scnt:=scnt+1;                           {incr shot counter}
  712.              end;
  713.     119,87 : begin                                      {withdraw}
  714.                 scnt:=-1;                               {signal to get out}
  715.                 Fleet:=0;                               {of loop}
  716.                 Allied_Fleet[theano,acnt]:=0;
  717.                 acnt:=acnt-1;
  718.                 ReCalc(theano);
  719.              end;
  720.         63 : begin
  721.                Window(1,1,80,25);
  722.                Restore;
  723.                Windx:=16;                         {help window}
  724.                Windy:=8;
  725.                Winddx:=33;
  726.                Winddy:=11;
  727.                Border(Windx,windy,winddx,winddy,1,15,0);
  728.                Window(Windx+1,Windy+1,Windx+Winddx-2,Windy+winddy-2);
  729.                ClrScr;
  730.                Gotoxy(5,9);                  {Display static data}
  731.                FastWrite('PRESS ANY KEY TO CONTINUE',7,0,1);
  732.                Gotoxy(1,1);
  733.                FastWrite(' Up/Down cursors select target',7,0,1);
  734.                Gotoxy(1,2);
  735.                FastWrite(' ENTER fires on target',7,0,1);
  736.                Gotoxy(1,3);
  737.                FastWrite(' W or w withdraws attacker',7,0,1);
  738.                Gotoxy(1,4);
  739.                FastWrite(' END completes firing',7,0,1);
  740.                Gotoxy(1,5);
  741.                FastWrite(' S or s displays ship status',7,0,1);
  742.                Gotoxy(1,6);
  743.                FastWrite(' Q or q terminates game',7,0,1);
  744.                Window(1,1,80,25);
  745.                uncursor;
  746.                kbdrd;
  747.                Restore;
  748.                TheaWind(theano);
  749.                HiLite(acnt,xcnt);
  750.              end;
  751.       end; {case}
  752.       ReCalc(theano);
  753.       TheaWind(theano);
  754.       if xcnt>Axis_Total then xcnt:=Axis_Total;
  755.     end;
  756. end;
  757.  
  758. Procedure Allied_Combat;
  759. begin
  760. if (Allied_Total>0) and (Axis_Total>0) then
  761.   begin
  762.     ReCalc(theano);
  763.     Sub_Shots:=Axis_Ship_Cnt;
  764.     acnt:=1;
  765.     xcnt:=1;
  766.     repeat
  767.       begin
  768.         Temp_Name:=Allied_Name;
  769.         with Allied_Navy[Allied_Fleet[TheaNo,acnt]] do
  770.           begin
  771.             if model = 'S' then attack := Sub_Shots;
  772.             if (model<>'S') or ((model = 'S') and (Round < 2)) then
  773.               begin
  774.                 scnt:=1;
  775.                   begin
  776.                     repeat
  777.                       if Axis_Total>0 then Do_Battle;
  778.                       {Note:scnt is incremented in Do_Battle when
  779.                        key is 13. It is set to -1 when ship withdrawn}
  780.                     until (key=5) or (key=119) or (key=87) or
  781.                           (scnt>attack) or (scnt<1) or (Axis_Total=0) or
  782.                           (Allied_Total=0) or (quitsw=1);
  783.                   end;
  784.               end;
  785.           end;
  786.       end;
  787.       acnt:=acnt+1;
  788.     until (acnt>Allied_Total) or (Allied_Total=0) or (Axis_Total=0) or
  789.           (quitsw=1);
  790.   end;
  791. end;
  792.  
  793. Procedure Do_Combats;
  794. begin
  795.  
  796. For TheaNo:=1 to TheaCnt do
  797.   begin
  798.     ReCalc(Theano);                                 {Recalculate and position}
  799.     Round:=1;
  800.     init_no:=Random;
  801.     repeat
  802.        begin
  803.          TheaWind(TheaNo);                       {Display Theater}
  804.          If (init_no < init_factor) then         {Randomly determine the}
  805.            begin                                 {initative}
  806.              if quitsw <> 1 then Axis_Combat;
  807.              if quitsw <> 1 then Allied_Combat;
  808.            end
  809.          else
  810.            begin
  811.              if quitsw <> 1 then Allied_Combat;
  812.              if quitsw <> 1 then Axis_Combat;
  813.            end;
  814.       end;
  815.     Round:=Round+1;
  816.     until (Allied_Ship_Cnt=0) or (Axis_Ship_Cnt=0) or (quitsw=1);
  817.     if quitsw<>1 then
  818.       begin
  819.         Battle_Results;
  820.         Window(1,1,80,25);
  821.         Restore;
  822.       end;
  823.   end;
  824. end;
  825.  
  826. begin
  827.  
  828. Randomize;
  829. GetPic(PicName);                      {Load map}
  830. Victory_Points:=0;                    {Initialize victory point count}
  831. Turn:=1;
  832. repeat
  833.   Snapshot(3);
  834.   if quitsw <> 1 then Pick_Fleets;    {Pick Allied and Axis fleets}
  835.   if quitsw <> 1 then Snapshot(3);
  836.  
  837.   if quitsw <> 1 then Do_Combats;     {Do combat in each theater}
  838.   turn:=turn+1;
  839. until (abs(Victory_Points)>=Victory_Points_to_win) or (quitsw=1) or
  840.       (turn>10);
  841. if quitsw<>1 then
  842. begin
  843.   Window(1,1,80,25);
  844.   ClrScr;
  845.   for m:=2 to 9 do
  846.     Border(m+10,m,59-(2*m),25-(2*m),1,7,0);
  847.   Temp_Name:=Allied_Name;
  848.   If Victory_Points<0 then Temp_Name:=Axis_Name;
  849.   if turn<11 then
  850.   begin
  851.     Gotoxy(33,11);
  852.     LowVideo;
  853.     Writeln('WINNER OF THE');
  854.   end;
  855.   Gotoxy(34,12);
  856.   Writeln('CAMPAIGN IS');
  857.   NormVideo;
  858.   Gotoxy(35,13);
  859.   If (abs(Victory_Points)>=Victory_Points_to_win) then Writeln(Temp_Name)
  860.   else Writeln(' A DRAW');
  861.   Uncursor;
  862.   Kbdrd;
  863. end;
  864. Clrscr;
  865. end.