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
  engines[i].id_nr:=i;
  engines[i].bild:=159+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'Antriebs-Editor'#13#10#10#0'C'#$87' F10=Sichern ESC=Ende');
  repeat
   max:=1;
   writeg(o,#0'@'#0#5);
   for i:=1 to 9 do with engines[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);

    for j:=1 to 9 do begin
     if (x=j-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,w2s(j,2,false,false)+':'+l2s(fueluse[j],5,false,false,false));
     if fueluse[j]>max then max:=fueluse[j];
    end;
    writeg(o,#13#10);
   end;
   filledrectangle(10,25*16-6,110,25*16+50,0);
   i:=y div 2;
   with engines[i+1] do begin
    vline(20,25*16+47,25*16+50,$e,0);
    line(10,25*16+50,20,25*16+50-(fueluse[1]*50)div max,$c,0);
    for j:=2 to 9 do begin
     vline(10+j*10,25*16+47,25*16+50,$e,0);
     line(j*10   ,25*16+50-(fueluse[j-1]*50)div max,
	  j*10+10,25*16+50-(fueluse[j  ]*50)div max,$d xor (j and 1),0);
    end;
    line(100,25*16+50-(fueluse[9]*50)div max,110,25*16-6,$d,0);
    writeg(o,#0'@'#0#28#0'C'#$8f' 123 456 789');
   end;
   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>5) then x:=5;
     end;
     $50:begin
      if y<17 then inc(y);
      if (y and 1=0)and(x>5) then x:=5;
     end;
     $4b:begin
      if x>0 then dec(x);
     end;
     $4d:if (x<5)or(x<8)and(y and 1<>0) then inc(x);
     $44:begin
      racesave;
      redraw:=2;
     end;
    end;
    #27:redraw:=2;
    #13:with engines[y div 2+1] do begin
     if y and 1=0 then case x of
      0:eingabe(1,y+5,20,'Neuer Name Antrieb '+char(y div 2 + 49),engines[y div 2+1].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 begin
      fueluse[x+1]:=eingabenr(8*x+3,y+6,99999,fueluse[x+1],'Verbrauch:');
     end;
     redraw:=1;
    end;
   end;
  until redraw>0;
 until redraw>1;;
 setvideomode(co80);
end.