{$M 22048,0,155520}
{Best of the two worlds, enough memory reserved for music}
{and enough left for the rest                            }

Program Super_fighter_of_fighters_2_turbo_special_edition;

{SFOF2TSE v4.26 by Crush,D UNT}

uses mse_tp,sound,crt,crush13h;
{mse_tp and sound for sound}
{crt for keypressed and reakey}
{crush13h for vga}
{dos for disk accessing}

Const nfighters=120;     {due to league promotions, nfighters must be 120}

Type  fighterrec= Record
                      name:string[14];
                      imagefile:string[12];
                      x1:integer;
                      y1:integer;
                      x2:integer;
                      y2:integer;
                      askill:integer;
                      dskill:integer;
                      strength:integer;
                      luck:integer;
                      moral:integer;
                      speed:integer;
                      experience:integer;
                      win:integer;
                      lose:integer;
                      control:integer; { 0 for cpu ; 1 to 9 humam }
                 End;

     schedule= Record
                     status:integer;
                     homefighter:integer;
                     awayfighter:integer;
               End;

var  a,b,k,l:integer;
     league1:array [1..nfighters div 4] of integer;
     league2:array [1..nfighters div 4] of integer;
     league3:array [1..nfighters div 4] of integer;
     league4:array [1..nfighters div 4] of integer;
     l1,l2,l3,l4:boolean;
     schedule1:array [1..nfighters div 4,1..nfighters div 4] of schedule;
     schedule2:array [1..nfighters div 4,1..nfighters div 4] of schedule;
     schedule3:array [1..nfighters div 4,1..nfighters div 4] of schedule;
     schedule4:array [1..nfighters div 4,1..nfighters div 4] of schedule;
     fighter: array [1..nfighters] of fighterrec;
     fighterimg: array [1..nfighters] of pointer;
     flag:boolean;
     new1,new2:boolean;
     c:char;
     winner:integer;
     season:integer;

{-------------------------------intro---------------------------------}

procedure getfighters;
var f:text;
begin
     assign (f,'fighter.dat');
     reset (f);

     for a:=1 to nfighters do
         begin
         readln (f,fighter[a].name);              {place intro }
         readln (f,fighter[a].imagefile);         {in between  }
         readln (f,fighter[a].x1);
         readln (f,fighter[a].y1);
         readln (f,fighter[a].x2);
         readln (f,fighter[a].y2);
         readln (f,fighter[a].askill);
         readln (f,fighter[a].dskill);
         readln (f,fighter[a].strength);
         readln (f,fighter[a].luck);
         readln (f,fighter[a].moral);
         readln (f,fighter[a].speed);

         fighter[a].experience:=0;
         fighter[a].control:=0;
         end;


     close (f);
     for a:=1 to nfighters do
         begin

         loadpcx (fighter[a].imagefile,vp[1]);
         getimage (fighter[a].x1,fighter[a].y1,fighter[a].x2,fighter[a].y2,fighterimg[a],vp[1]);

         end;
end;

{------------------------------credits--------------------------------}

procedure credits;
begin
end;

{-------------------------------game----------------------------------}

procedure newfighters;
var s:char;
    ss:integer;
    d:char;
    character:boolean;
    r:integer;
    done:boolean;
    c:char;
    blank:pointer;
begin
     for r:=1 to 120 do fighter[r].control:=0;
     s:='0';
     cls (0,vga);
     cls (0,vp[1]);
     putstring (0,0,15,15,0,'Sign up here!',1,vga);
     character:=false;

     repeat
      putstring (0,16,15,15,0,'How many',1,vga);
      putstring (0,32,15,15,0,'players(1-9)?',1,vga);
      s:= readkey;
      for d:='1' to '9' do if d=s then character:=true;
     until character=true;

     cls (0,vga);
     getimage (96,16,319,32,blank,vga);
     for d:= '1' to s do
     begin
          r:=1;
          if d='1' then ss:=1;
          if d='2' then ss:=2;
          if d='3' then ss:=3;
          if d='4' then ss:=4;
          if d='5' then ss:=5;
          if d='6' then ss:=6;
          if d='7' then ss:=7;
          if d='8' then ss:=8;
          if d='9' then ss:=9;
          putstring (32,20*ss-20,15,15,0, d+'.' ,1,vga);
          done:=false;
          repeat
           if fighter[r].control=0
           then begin
                    putimage (64,20*ss-20,1,fighterimg[r],vga);
                    putimage (96,20*ss-20,1,blank,vga);
                    putstring(96,20*ss-20,15,15,0, fighter[r].name,1,vga);
                    c:=readkey;
                    if c='k' then
                                  begin
                                       repeat
                                       r:=r-1;
                                       if r<=0 then r:=nfighters;
                                       if r>=nfighters+1 then r:=1;
                                       until fighter[r].control=0;
                                  end;
                    if c='l' then
                                  begin
                                       repeat
                                       r:=r+1;
                                       if r<=0 then r:=nfighters;
                                       if r>=nfighters+1 then r:=1;
                                       until fighter[r].control=0;
                                  end;
                    if c=' ' then done:=true;
               end
           else r:=r+1;
          until done=true;

          fighter[r].control:=ss;

     end;
     killimage (blank);
end;

procedure livefight (c1,c2:integer);
var r1,r2:integer;
    s1,s2:real;
    eb1,eb2:integer;
    hp:real;
    raskill,rluck,rmoral,rspeed:integer;
    dead:boolean;
    exp:integer;
    blank:pointer;
begin

     dead:=false;

     cls (0,vga);
     putimage (72,42,1,fighterimg[c1],vga);
     if new1=true then square (72,42,92,62,155,vga);
     putimage (72,142,1,fighterimg[c2],vga);
     if new2=true then square (72,142,92,162,155,vga);
     putstring (90,42,15,15,0,fighter[c1].name,1,vga);
     putstring (90,142,15,15,0,fighter[c2].name,1,vga);
     putstring (144,92,15,15,0,'Vs',1,vga);

     eb1:=0;
     if fighter[c1].experience>50 then eb1:=1;
     if fighter[c1].experience>100 then eb1:=2;
     if fighter[c1].experience>200 then eb1:=3;
     if fighter[c1].experience>400 then eb1:=4;       {experience influence}
     if fighter[c1].experience>600 then eb1:=5;
     if fighter[c1].experience>800 then eb1:=6;
     if fighter[c1].experience>1100 then eb1:=7;
     if fighter[c1].experience>1400 then eb1:=8;
     if fighter[c1].experience>1700 then eb1:=9;
     if fighter[c1].experience>2000 then eb1:=10;

     eb2:=0;
     if fighter[c2].experience>50 then eb2:=1;
     if fighter[c2].experience>100 then eb2:=2;
     if fighter[c2].experience>200 then eb2:=3;
     if fighter[c2].experience>400 then eb2:=4;
     if fighter[c2].experience>600 then eb2:=5;
     if fighter[c2].experience>800 then eb2:=6;
     if fighter[c2].experience>1100 then eb2:=7;
     if fighter[c2].experience>1400 then eb2:=8;
     if fighter[c2].experience>1700 then eb2:=9;
     if fighter[c2].experience>2000 then eb2:=10;

     if fighter[c1].askill + eb1 > fighter[c2].askill + eb2
        then raskill:=fighter[c1].askill
        else raskill:=fighter[c2].askill;
     if fighter[c1].luck + eb1 > fighter[c2].luck + eb2
        then rluck:=fighter[c1].luck
        else rluck:=fighter[c2].luck;
     if fighter[c1].speed + eb1 > fighter[c2].speed + eb2
        then rspeed:=fighter[c1].speed
        else rspeed:=fighter[c2].speed;
     if fighter[c1].moral + eb1 > fighter[c2].moral + eb2
        then rmoral:=fighter[c1].moral
        else rmoral:=fighter[c2].moral;

     s1:=fighter[c1].strength+eb1;
     s2:=fighter[c2].strength+eb2;
     readkey;
     cls (0,vga);
     getimage (0,0,319,48,blank,vga);
     winner:=0;
     repeat

      r1:=random(raskill)+1;
      r2:=random(raskill)+1;
      if fighter[c1].askill*2+r1+fighter[c1].luck+eb1 > fighter[c2].dskill*2+r2+fighter[c2].moral+eb2
      then
          begin
               cls (0,vga);
               hp:=0.5;
               if fighter[c1].luck=rluck then hp:=hp+0.5;
               if fighter[c1].speed=rspeed then hp:=hp+0.5;
               if fighter[c2].moral=rmoral then hp:=hp-0.5;
               s2:= s2-hp;
               putstring (0,0,15,15,0,fighter[c1].name+' attacks...',1,vga);
               putstring (0,16,15,15,0,fighter[c1].name+' hits '+fighter[c2].name,1,vga);
               if s2 <= 0 then winner:=1;
               if s2 <= 0 then putstring (0,32,15,15,0,fighter[c1].name+' is victorious',1,vga);
          end
      else
          begin
               cls (0,vga);
               putstring (0,0,15,15,0,fighter[c1].name+' attacks...',1,vga);
               putstring (0,16,15,15,0,'but '+fighter[c2].name+' defends well',1,vga);
          end;
      readkey;
      if winner=0 then
      if fighter[c2].askill*2+r2+fighter[c2].luck+eb2 > fighter[c1].dskill*2+r1+fighter[c1].moral+eb1
      then
          begin
               cls (0,vga);
               hp:=0.5;
               if fighter[c2].luck=rluck then hp:=hp+0.5;
               if fighter[c2].speed=rspeed then hp:=hp+0.5;
               if fighter[c1].moral=rmoral then hp:=hp-0.5;
               s1:= s1-hp;
               putstring (0,0,15,15,0,fighter[c2].name+' attacks...',1,vga);
               putstring (0,16,15,15,0,fighter[c2].name+' hits '+fighter[c1].name,1,vga);
               if s1 <= 0 then winner:=2;
               if s1 <= 0 then putstring (0,32,15,15,0,fighter[c2].name+' is victorious',1,vga);
          end
      else
          begin
               cls (0,vga);
               putstring (0,0,15,15,0,fighter[c2].name+' attacks...',1,vga);
               putstring (0,16,15,15,0,'but '+fighter[c1].name+' defends well',1,vga);
          end;
      readkey;
     until winner<>0;

     if winner=1
     then begin
               fighter[c1].moral:=fighter[c1].moral+1;
               fighter[c2].moral:=fighter[c2].moral-1;
               if fighter[c2].moral<0 then fighter[c2].moral:=5;
               exp:=fighter[c2].askill+fighter[c2].dskill+fighter[c2].strength+fighter[c2].speed;
               fighter[c1].experience:=fighter[c1].experience+exp;
               fighter[c1].win:=fighter[c1].win+1;
               fighter[c2].lose:=fighter[c2].lose+1;
          end;
     if winner=2
     then begin
               fighter[c2].moral:=fighter[c2].moral+1;
               fighter[c1].moral:=fighter[c1].moral-1;
               if fighter[c1].moral<0 then fighter[c2].moral:=5;
               exp:=fighter[c1].askill+fighter[c1].dskill+fighter[c1].strength+fighter[c1].speed;
               fighter[c2].experience:=fighter[c2].experience+exp;
               fighter[c2].win:=fighter[c2].win+1;
               fighter[c1].lose:=fighter[c1].lose+1;
          end;
     killimage (blank);
end;

procedure fight (c1,c2:integer);
var r1,r2:integer;
    s1,s2:real;
    eb1,eb2:integer;
    hp:real;
    raskill,rluck,rmoral,rspeed:integer;
    exp:integer;
begin

     cls (0,vga);
     putimage (72,42,1,fighterimg[c1],vga);
     putimage (72,142,1,fighterimg[c2],vga);
     putstring (90,42,15,15,0,fighter[c1].name,1,vga);
     putstring (90,142,15,15,0,fighter[c2].name,1,vga);
     putstring (144,92,15,15,0,'Vs',1,vga);

     eb1:=0;
     if fighter[c1].experience>50 then eb1:=1;
     if fighter[c1].experience>100 then eb1:=2;
     if fighter[c1].experience>200 then eb1:=3;
     if fighter[c1].experience>400 then eb1:=4;       {experience influence}
     if fighter[c1].experience>600 then eb1:=5;
     if fighter[c1].experience>800 then eb1:=6;
     if fighter[c1].experience>1100 then eb1:=7;
     if fighter[c1].experience>1400 then eb1:=8;
     if fighter[c1].experience>1700 then eb1:=9;
     if fighter[c1].experience>2000 then eb1:=10;

     eb2:=0;
     if fighter[c2].experience>50 then eb2:=1;
     if fighter[c2].experience>100 then eb2:=2;
     if fighter[c2].experience>200 then eb2:=3;
     if fighter[c2].experience>400 then eb2:=4;
     if fighter[c2].experience>600 then eb2:=5;
     if fighter[c2].experience>800 then eb2:=6;
     if fighter[c2].experience>1100 then eb2:=7;
     if fighter[c2].experience>1400 then eb2:=8;
     if fighter[c2].experience>1700 then eb2:=9;
     if fighter[c2].experience>2000 then eb2:=10;

     if fighter[c1].askill + eb1 > fighter[c2].askill + eb2
        then raskill:=fighter[c1].askill
        else raskill:=fighter[c2].askill;
     if fighter[c1].luck + eb1 > fighter[c2].luck + eb2
        then rluck:=fighter[c1].luck
        else rluck:=fighter[c2].luck;
     if fighter[c1].speed + eb1 > fighter[c2].speed + eb2
        then rspeed:=fighter[c1].speed
        else rspeed:=fighter[c2].speed;
     if fighter[c1].moral + eb1 > fighter[c2].moral + eb2
        then rmoral:=fighter[c1].moral
        else rmoral:=fighter[c2].moral;

     s1:=fighter[c1].strength+eb1;
     s2:=fighter[c2].strength+eb2;
     readkey;
     cls (0,vga);

     winner:=0;
     repeat
      r1:=random(raskill)+1;
      r2:=random(raskill)+1;
      if fighter[c1].askill*2+r1+fighter[c1].luck+eb1 > fighter[c2].dskill*2+r2+fighter[c2].moral+eb2
      then begin
               hp:=0.5;
               if fighter[c1].luck=rluck then hp:=hp+0.5;
               if fighter[c1].speed=rspeed then hp:=hp+0.5;
               if fighter[c2].moral=rmoral then hp:=hp-0.5;
               s2:= s2-hp;
               if s2 <= 0 then winner:=1;
               if s2 <= 0 then putstring (0,32,15,15,0,fighter[c1].name+' is victorious',1,vga);
          end;
      if winner=0 then
      if fighter[c2].askill*2+r2+fighter[c2].luck+eb2 > fighter[c1].dskill*2+r1+fighter[c1].moral+eb1
      then begin
               hp:=0.5;
               if fighter[c2].luck=rluck then hp:=hp+0.5;
               if fighter[c2].speed=rspeed then hp:=hp+0.5;
               if fighter[c1].moral=rmoral then hp:=hp-0.5;
               s1:= s1-hp;
               if s1 <= 0 then winner:=2;
               if s1 <= 0 then putstring (0,32,15,15,0,fighter[c2].name+' is victorious',1,vga);
          end;
     until winner<>0;
     readkey;

     if winner=1
     then begin
               fighter[c1].moral:=fighter[c1].moral+1;
               fighter[c2].moral:=fighter[c2].moral-1;
               if fighter[c2].moral<0 then fighter[c2].moral:=5;
               exp:=fighter[c2].askill+fighter[c2].dskill+fighter[c2].strength+fighter[c2].speed;
               fighter[c1].experience:=fighter[c1].experience+exp;
               fighter[c1].win:=fighter[c1].win+1;
               fighter[c2].lose:=fighter[c2].lose+1;
          end;
     if winner=2
     then begin
               fighter[c2].moral:=fighter[c2].moral+1;
               fighter[c1].moral:=fighter[c1].moral-1;
               if fighter[c1].moral<0 then fighter[c2].moral:=5;
               exp:=fighter[c1].askill+fighter[c1].dskill+fighter[c1].strength+fighter[c1].speed;
               fighter[c2].experience:=fighter[c2].experience+exp;
               fighter[c2].win:=fighter[c2].win+1;
               fighter[c1].lose:=fighter[c1].lose+1;
          end;
end;

procedure simfight (c1,c2:integer);
var r1,r2:integer;
    s1,s2:real;
    eb1,eb2:integer;
    hp:real;
    raskill,rluck,rmoral,rspeed:integer;
    exp:integer;
begin

     cls (0,vga);
     putstring (85,92,15,15,0,'Fighting...',1,vga);

     eb1:=0;
     if fighter[c1].experience>50 then eb1:=1;
     if fighter[c1].experience>100 then eb1:=2;
     if fighter[c1].experience>200 then eb1:=3;
     if fighter[c1].experience>400 then eb1:=4;       {experience influence}
     if fighter[c1].experience>600 then eb1:=5;
     if fighter[c1].experience>800 then eb1:=6;
     if fighter[c1].experience>1100 then eb1:=7;
     if fighter[c1].experience>1400 then eb1:=8;
     if fighter[c1].experience>1700 then eb1:=9;
     if fighter[c1].experience>2000 then eb1:=10;

     eb2:=0;
     if fighter[c2].experience>50 then eb2:=1;
     if fighter[c2].experience>100 then eb2:=2;
     if fighter[c2].experience>200 then eb2:=3;
     if fighter[c2].experience>400 then eb2:=4;
     if fighter[c2].experience>600 then eb2:=5;
     if fighter[c2].experience>800 then eb2:=6;
     if fighter[c2].experience>1100 then eb2:=7;
     if fighter[c2].experience>1400 then eb2:=8;
     if fighter[c2].experience>1700 then eb2:=9;
     if fighter[c2].experience>2000 then eb2:=10;

     if fighter[c1].askill + eb1 > fighter[c2].askill + eb2
        then raskill:=fighter[c1].askill
        else raskill:=fighter[c2].askill;
     if fighter[c1].luck + eb1 > fighter[c2].luck + eb2
        then rluck:=fighter[c1].luck
        else rluck:=fighter[c2].luck;
     if fighter[c1].speed + eb1 > fighter[c2].speed + eb2
        then rspeed:=fighter[c1].speed
        else rspeed:=fighter[c2].speed;
     if fighter[c1].moral + eb1 > fighter[c2].moral + eb2
        then rmoral:=fighter[c1].moral
        else rmoral:=fighter[c2].moral;

     s1:=fighter[c1].strength+eb1;
     s2:=fighter[c2].strength+eb2;
     winner:=0;
     repeat
      r1:=random(raskill)+1;
      r2:=random(raskill)+1;
      if fighter[c1].askill*2+r1+fighter[c1].luck+eb1 > fighter[c2].dskill*2+r2+fighter[c2].moral+eb2
      then begin
               hp:=0.5;
               if fighter[c1].luck=rluck then hp:=hp+0.5;
               if fighter[c1].speed=rspeed then hp:=hp+0.5;
               if fighter[c2].moral=rmoral then hp:=hp-0.5;
               s2:= s2-hp;
               if s2 <= 0 then winner:=1;
          end;
      if winner=0 then
      if fighter[c2].askill*2+r2+fighter[c2].luck+eb2 > fighter[c1].dskill*2+r1+fighter[c1].moral+eb1
      then begin
               hp:=0.5;
               if fighter[c2].luck=rluck then hp:=hp+0.5;
               if fighter[c2].speed=rspeed then hp:=hp+0.5;
               if fighter[c1].moral=rmoral then hp:=hp-0.5;
               s1:= s1-hp;
               if s1 <= 0 then winner:=2;
          end;
     until winner<>0;

     if winner=1
     then begin
               fighter[c1].moral:=fighter[c1].moral+1;
               fighter[c2].moral:=fighter[c2].moral-1;
               if fighter[c2].moral<0 then fighter[c2].moral:=5;
               exp:=fighter[c2].askill+fighter[c2].dskill+fighter[c2].strength+fighter[c2].speed;
               fighter[c1].experience:=fighter[c1].experience+exp;
               fighter[c1].win:=fighter[c1].win+1;
               fighter[c2].lose:=fighter[c2].lose+1;
          end;
     if winner=2
     then begin
               fighter[c2].moral:=fighter[c2].moral+1;
               fighter[c1].moral:=fighter[c1].moral-1;
               if fighter[c1].moral<0 then fighter[c2].moral:=5;
               exp:=fighter[c1].askill+fighter[c1].dskill+fighter[c1].strength+fighter[c1].speed;
               fighter[c2].experience:=fighter[c2].experience+exp;
               fighter[c2].win:=fighter[c2].win+1;
               fighter[c1].lose:=fighter[c1].lose+1;
          end;
end;

procedure set_fight_mode (c1,c2:integer);
begin
     new1:=false;
     new2:=false;

     for a:=1 to 9 do if fighter[c1].control=a then new1:=true;

     for a:=1 to 9 do if fighter[c2].control=a then new2:=true;

     if new1=true then if new2=false then livefight (c1,c2);
     if new1=false then if new2=true then livefight (c1,c2);
     if new1=true then if new2=true then livefight(c1,c2);
     if new1=false then if new2=false then fight (c1,c2);
end;

procedure setschedule;
var c,d:integer;
begin
     for a:=1 to 30 do
         begin
              for b:=1 to 30 do
                  begin
                       schedule1[a,b].homefighter:=league1[a];
                       schedule2[a,b].homefighter:=league2[a];
                       schedule3[a,b].homefighter:=league3[a];
                       schedule4[a,b].homefighter:=league4[a];
                       schedule1[a,b].awayfighter:=league1[b];
                       schedule2[a,b].awayfighter:=league2[b];
                       schedule3[a,b].awayfighter:=league3[b];
                       schedule4[a,b].awayfighter:=league4[b];
                       schedule1[a,b].status:=0;
                       schedule2[a,b].status:=0;
                       schedule3[a,b].status:=0;
                       schedule4[a,b].status:=0;
                  end;
         end;
end;

procedure savegame;
var f:text;
    answer:string[8];
    c:integer;
begin
     repeat
      cls (0,vga);
      putstring (0,0,15,15,0,'What''s the file name?',1,vga);
      getstring(0,16,15,15,0,1,answer);
     until length(answer)<=8;

     assign (f,answer+'.sg');
     reset (f);

     for a:=1 to nfighters do
         begin
              readln (f,fighter[a].experience);
              readln (f,fighter[a].moral);
              readln (f,fighter[a].win);
              readln (f,fighter[a].lose);
              readln (f,fighter[a].control);
         end;
     for a:=1 to 30 do
         begin
              readln (f,league1[a]);
              readln (f,league2[a]);
              readln (f,league3[a]);
              readln (f,league4[a]);
              for b:=1 to 30 do
                  begin
                       for c:=1 to 15 do
                           begin
                                readln (f,schedule1[a,b].homefighter);
                                readln (f,schedule2[a,b].homefighter);
                                readln (f,schedule3[a,b].homefighter);
                                readln (f,schedule4[a,b].homefighter);
                                readln (f,schedule1[a,b].awayfighter);
                                readln (f,schedule2[a,b].awayfighter);
                                readln (f,schedule3[a,b].awayfighter);
                                readln (f,schedule4[a,b].awayfighter);
                           end;
                  end;
         end;
     readln (f,season);
     close (f);

     putstring (0,32,15,15,0,'Your game has been saved!',1,vga);
end;

procedure setleagues;
var c,d:integer;
begin
     for a:=1 to (nfighters div 4) do
         begin
              league1[a]:=a+30;
              league2[a]:=a;
              league3[a]:=a+90;
              league4[a]:=a+60;
         end;
     for a:=1 to (nfighters div 4) do
         begin
              for b:=1 to 9 do
                  begin
                       c:=league1[a];
                       if fighter[c].control=b then         { every human }
                          begin                             { player stays}
                               d:=league4[b+20];            { in 21-29    }
                               league4[b+20]:=c;            { of 4th league}
                               league1[a]:=d;
                          end;
                       c:=league2[a];
                       if fighter[c].control=b then
                          begin
                               d:=league4[b+20];
                               league4[b+20]:=c;
                               league2[a]:=d;
                          end;
                       c:=league3[a];
                       if fighter[c].control=b then
                          begin
                               d:=league4[b+20];
                               league4[b+20]:=c;
                               league3[a]:=d;
                          end;
                       c:=league4[a];
                       if fighter[c].control=b then
                          begin
                               d:=league4[b+20];
                               league4[b+20]:=c;
                               league4[a]:=d;
                          end;
                  end;
         end;
     setschedule;
     season:=1;
     {savegame;   }
end;

procedure nextseason;
var prom1,prom2,prom3,prom4,prom5:integer;
    unpr1,unpr2,unpr3,unpr4,unpr5:integer;
    first,second,third:integer;
    a,b:integer;
begin
     for a:=1 to (nfighters div 4) do
         begin
              fighter[league1[a]].experience:=fighter[league1[a]].experience-60;
              fighter[league2[a]].experience:=fighter[league2[a]].experience-50;
              fighter[league3[a]].experience:=fighter[league3[a]].experience-40;
              fighter[league4[a]].experience:=fighter[league4[a]].experience-30;
         end;
     for a:=1 to nfighters do
         begin
              for b:=1 to 9 do
                  begin
                       if fighter[a].control=b then fighter[a].experience:=fighter[a].experience+20;
                       if fighter[a].control=b then fighter[a].moral:=fighter[a].moral+2;
                  end;
         end;
     for a:=1 to nfighters do
         begin
              if fighter[a].moral >10 then fighter[a].moral:=4;
              if fighter[a].moral <0 then fighter[a].moral:=5;
         end;

                                {the above is for humans better then machines}
     prom1:=league2[1];         {the above above is because the best players}
     prom2:=league2[2];         {are always on the top so their opponents}
     prom3:=league2[3];         {win more experience per combat}
     prom4:=league2[4];         {give sum more, take sum more :) }
     prom5:=league2[5];
     unpr1:=league1[26];             {promotions and unpromotions}
     unpr2:=league1[27];             {between leagues 1 and 2}
     unpr3:=league1[28];
     unpr4:=league1[29];
     unpr5:=league1[30];
     league1[26]:=prom1;
     league1[27]:=prom2;
     league1[28]:=prom3;
     league1[29]:=prom4;
     league1[30]:=prom5;
     league2[1]:=unpr1;
     league2[2]:=unpr2;
     league2[3]:=unpr3;
     league2[4]:=unpr4;
     league2[5]:=unpr5;

     prom1:=league3[1];
     prom2:=league3[2];
     prom3:=league3[3];
     prom4:=league3[4];
     prom5:=league3[5];
     unpr1:=league2[26];              {between leagues 2 and 3}
     unpr2:=league2[27];
     unpr3:=league2[28];
     unpr4:=league2[29];
     unpr5:=league2[30];
     league2[26]:=prom1;
     league2[27]:=prom2;
     league2[28]:=prom3;
     league2[29]:=prom4;
     league2[30]:=prom5;
     league3[1]:=unpr1;
     league3[2]:=unpr2;
     league3[3]:=unpr3;
     league3[4]:=unpr4;
     league3[5]:=unpr5;

     prom1:=league4[1];
     prom2:=league4[2];
     prom3:=league4[3];
     prom4:=league4[4];
     prom5:=league4[5];
     unpr1:=league3[26];              {between leagues 3 and 4}
     unpr2:=league3[27];
     unpr3:=league3[28];
     unpr4:=league3[29];
     unpr5:=league3[30];
     league3[26]:=prom1;
     league3[27]:=prom2;
     league3[28]:=prom3;
     league3[29]:=prom4;
     league3[30]:=prom5;
     league4[1]:=unpr1;
     league4[2]:=unpr2;
     league4[3]:=unpr3;
     league4[4]:=unpr4;
     league4[5]:=unpr5;

     first:=league1[1];
     second:=league1[2];           {champions}
     third:=league1[3];

     setschedule;
     season:=season+1;
     savegame;
end;

procedure fighting;
var stat:boolean;
begin
     l1:=false;
     l2:=false;
     l3:=false;
     l4:=false;
     for a:=1 to 30 do
         begin
              for b:=1 to 9 do
                  begin
                       if fighter[league1[a]].control=b then l1:=true;
                       if fighter[league2[a]].control=b then l2:=true;
                       if fighter[league3[a]].control=b then l3:=true;
                       if fighter[league4[a]].control=b then l4:=true;
                  end;
         end;
     k:=random(30)+1;             {only watch fight in players leagues}
     l:=random(30)+1;
     if k=l then
        begin
             schedule1[k,l].status:=3;
             schedule2[k,l].status:=3;    {no fighting clonage}
             schedule3[k,l].status:=3;
             schedule4[k,l].status:=3;
        end;
     if schedule1[k,l].status=0 then
        begin
             if l1=true then set_fight_mode(schedule1[k,l].homefighter,schedule1[k,l].awayfighter)
             else simfight(schedule1[k,l].homefighter,schedule1[k,l].awayfighter);
             if winner=1 then schedule1[k,l].status:=1;
             if winner=2 then schedule1[k,l].status:=2;
        end;
     if schedule2[k,l].status=0 then
        begin
             if l2=true then set_fight_mode(schedule2[k,l].homefighter,schedule2[k,l].awayfighter)
             else simfight(schedule2[k,l].homefighter,schedule2[k,l].awayfighter);
             if winner=1 then schedule2[k,l].status:=1;
             if winner=2 then schedule2[k,l].status:=2;
        end;
     if schedule3[k,l].status=0 then
        begin
             if l3=true then set_fight_mode(schedule3[k,l].homefighter,schedule3[k,l].awayfighter)
             else simfight(schedule3[k,l].homefighter,schedule3[k,l].awayfighter);
             if winner=1 then schedule3[k,l].status:=1;
             if winner=2 then schedule3[k,l].status:=2;
        end;
     if schedule4[k,l].status=0 then
        begin
             if l4=true then set_fight_mode(schedule4[k,l].homefighter,schedule4[k,l].awayfighter)
             else simfight(schedule4[k,l].homefighter,schedule4[k,l].awayfighter);
             if winner=1 then schedule4[k,l].status:=1;
             if winner=2 then schedule4[k,l].status:=2;
        end;
     stat:=false;
     for k:=1 to 30 do
         begin
              for l:=1 to 30 do
                  begin
                       if schedule1[k,l].status=0 then stat:=true;
                       if schedule2[k,l].status=0 then stat:=true;
                       if schedule3[k,l].status=0 then stat:=true;
                       if schedule4[k,l].status=0 then stat:=true;
                  end;
         end;
     if stat=false then nextseason;
end;

procedure seeboard;
begin
end;

procedure seeschedule;
begin
end;

procedure competition;
var exit:boolean;
    h:char;
begin
     exit:=false;
     repeat
      {loadpcx ('screen.pcx',vp[1]);
      copypage (vp[1],vga);}
      cls(0,vga);
      putstring (0,0,15,15,0,'1,2,3 ou 4?',1,vga);
      h:=readkey;
      if h='1' then fighting;
      if h='2' then seeboard;
      if h='3' then seeschedule;
      if h='4' then exit:=true;
     until exit=true;
end;

procedure newgame;
begin
     newfighters;
     setleagues;
     competition;
end;

procedure loadgame;
var f:text;
    answer:string[8];
    c:integer;
begin
     repeat
      cls (0,vga);
      putstring (0,0,15,15,0,'What''s the file name?',1,vga);
      getstring(0,16,15,15,0,1,answer);
     until length(answer)<=8;

     assign (f,answer+'.sg');
     reset (f);
     rewrite (f);
     for a:=1 to nfighters do
         begin
              writeln (f,fighter[a].experience);
              writeln (f,fighter[a].moral);
              writeln (f,fighter[a].win);
              writeln (f,fighter[a].lose);
              writeln (f,fighter[a].control);
         end;
     for a:=1 to 30 do
         begin
              writeln (f,league1[a]);
              writeln (f,league2[a]);
              writeln (f,league3[a]);
              writeln (f,league4[a]);
              for b:=1 to 30 do
                  begin
                       for c:=1 to 15 do
                           begin
                                writeln (f,schedule1[a,b].homefighter);
                                writeln (f,schedule2[a,b].homefighter);
                                writeln (f,schedule3[a,b].homefighter);
                                writeln (f,schedule4[a,b].homefighter);
                                writeln (f,schedule1[a,b].awayfighter);
                                writeln (f,schedule2[a,b].awayfighter);
                                writeln (f,schedule3[a,b].awayfighter);
                                writeln (f,schedule4[a,b].awayfighter);
                           end;
                  end;
         end;
     readln (f,season);
     close (f);

     putstring (0,32,15,15,0,'Your game has been loaded!',1,vga);

     competition;
end;

procedure display_hof;
begin
end;

begin

     getcardinfo;
     loadmodule ('4morn.gdm');
     startmusic;

     video_mode ( $13);
     initvirt;

     loadfont ('abc.fnt',1);    {load the font}

     flag:=false;
     getfighters;             {intro in between... 120 records is a lot}
     setcolor (104,63,9,0);   {font color}

     repeat
      {loadpcx ('title.pcx',vp[1]);
      copypage (vp[1],vga);}
      cls(0,vga);
      putstring (0,0,15,15,0,'1,2,3,4 ou 5?',1,vga);
      c:=readkey;
      if c='1' then newgame;
      if c='2' then loadgame;
      if c='3' then credits;
      if c='4' then display_hof;
      if c='5' then flag:=true;
     until flag=true;

     for a:=1 to nfighters do killimage(fighterimg[a]);

     closevirt;
     video_mode ( 03);

     stopmusic;
     stopoutput;
     unloadmodule;
     freemse;
end.