uses
 tstring,
 types,
 utils,
 kb,
 evgraph,
 vbios,
{$ifndef unix}
 crt,
{$else}
 xcrt,
{$endif}
 grafik,
 data;

var
 x,
 y,
 redraw:byte;
 o:t_bdata;
 i,j:word;
 c:char;
 cs:byte;
 max:longint;

begin
 for i:=1 to 9 do begin
  torps[i].id_nr:=i;
  torps[i].bild:=169+i;
 end;
 x:=0;
 y:=0;
 initb(o,8,8,78,29,$8,$f);
 repeat
  window(6,6,79*8+1,29*16+9);
  writeg(o,#0'C'#$8f#12'Minen-Editor'#13#10#10#0'C'#$87' F10=Sichern ESC=Ende');
  filledrectangle(10,25*16,99,25*16+50,0);
  repeat
   max:=1;
   writeg(o,#0'@'#0#5);
   for i:=1 to 9 do with mines[i] do begin
    if (x=0)and(y=(i-1)*2)
    then writeg(o,#0'C'#$1f)
    else writeg(o,#0'C'+char($f or (i and 1) shl 7));
    writeg(o,nstring(name,20)+':');

    if (x=1)and(y=(i-1)*2)
    then writeg(o,#0'C'#$1f)
    else writeg(o,#0'C'+char($f or (i and 1) shl 7));
    writeg(o,'TechLvl='+w2s(techlvl,2,false,false));

    if (x=2)and(y=(i-1)*2)
    then writeg(o,#0'C'#$1f)
    else writeg(o,#0'C'+char($f or (i and 1) shl 7));
    writeg(o,' Creds='+w2s(costcred,4,false,false));

    if (x=3)and(y=(i-1)*2)
    then writeg(o,#0'C'#$1f)
    else writeg(o,#0'C'+char($f or (i and 1) shl 7));
    writeg(o,' Molyb='+w2s(costmolyb,4,false,false));

    if (x=4)and(y=(i-1)*2)
    then writeg(o,#0'C'#$1f)
    else writeg(o,#0'C'+char($f or (i and 1) shl 7));
    writeg(o,' Dura='+w2s(costdura,4,false,false));

    if (x=5)and(y=(i-1)*2)
    then writeg(o,#0'C'#$1f)
    else writeg(o,#0'C'+char($f or (i and 1) shl 7));
    writeg(o,' Trit='+w2s(costtrit,4,false,false)+#13#10);

    if (x=0)and(y=i*2-1)
    then writeg(o,#0'C'#$1f)
    else writeg(o,#0'C'+char($f or (i and 1) shl 7));
    writeg(o,' T”ten='+w2s(kill,4,false,false));
    if kill>max then max:=kill;

    if (x=1)and(y=i*2-1)
    then writeg(o,#0'C'#$1f)
    else writeg(o,#0'C'+char($f or (i and 1) shl 7));
    writeg(o,' Zerst”ren='+w2s(destroy,4,false,false)+#13#10);
    if destroy>max then max:=destroy;

   end;

   for i:=1 to 9 do with mines[i] do begin
    filledrectangle (i*10,25*16+50-(longint(kill)*50) div max,6+i*10,25*16+50,9);
    filledrectangle2(i*10+3,25*16+50-(longint(destroy)*50) div max,9+i*10,25*16+50,$c,2);
    if i<>9 then vline(9+i*10,25*16,25*16+50,$e,0);
   end;
   writeg(o,#0'@'#0#28#0'C'#$8f'12 345 678 9');
   c:=kbreadkey;
   if c=#0 then cs:=byte(kbreadkey) else cs:=kbscancode;
   case c of
    #0:case cs of
     $48:begin
      if y>0 then dec(y);
      if (y and 1<>0)and(x>1) then x:=1;
     end;
     $50:begin
      if y<17 then inc(y);
      if (y and 1<>0)and(x>1) then x:=1;
     end;
     $4b:begin
      if x>0 then dec(x);
     end;
     $4d:if (x<1)or(x<5)and(y and 1=0) then inc(x);
     $44:begin
      racesave;
      redraw:=2;
     end;
    end;
    #27:redraw:=2;
    #13:with mines[y div 2+1] do begin
     if y and 1=0 then case x of
      0:eingabe(1,y+5,20,'Neuer Name Mine '+char(y div 2 + 49),name);
      1:TechLvl:=eingabenr(20+7*x+3,y+5,12,techlvl,'TechLevel:');
      2:costCred:=eingabenr(20+7*x+3,y+5,9999,costCred,'Preis:');
      3:CostMolyb:=eingabenr(20+7*x+3,y+5,9999,CostMolyb,'Molybdenium:');
      4:CostDura:=eingabenr(20+7*x+3,y+5,9999,CostDura,'Duranium:');
      5:CostTrit:=eingabenr(20+7*x+3,y+5,9999,CostTrit,'Tritanium:');
     end else case x of
      0:kill:=eingabenr(12*x+3,y+5,9999,kill,'gegen Besatzung:');
      1:destroy:=eingabenr(12*x+3,y+5,9999,destroy,'gegen Schiffe:');
     end;
     redraw:=1;
    end;
   end;
  until redraw>0;
 until redraw>1;
 setvideomode(co80);
end.