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
  beams[i].id_nr:=i;
  beams[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'TorpedoRohr-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 torprohre[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 (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,' Nachladezeit='+w2s(recharge,4,false,false)+#13#10);

   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);
     end;
     $50:begin
      if y<17 then inc(y);
     end;
     $4b:begin
      if x>0 then dec(x);
     end;
     $4d:if (x<5)and(y and 1=0) then inc(x);
     $44:begin
      racesave;
      redraw:=2;
     end;
    end;
    #27:redraw:=2;
    #13:with torprohre[y div 2+1] do begin
     if y and 1=0 then case x of
      0:eingabe(1,y+5,20,'Neuer Name Rohrtyp '+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 begin
      recharge:=eingabenr(12*x+3,y+5,9999,recharge,'Nachladezeit:');
      if recharge<25 then recharge:=25;
     end;
     redraw:=1;
    end;
   end;
  until redraw>0;
 until redraw>1;
 setvideomode(co80);
end.