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'Waffen-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 beams[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));
    if destroy>max then max:=destroy;

    if (x=2)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,' Reichweite='+w2s(range,4,false,false)+#13#10);

   end;
   filledrectangle(10,25*16+10,100,25*16+50,0);
   i:=y div 2;
   with beams[i+1] do begin
    vline(20,25*16+47,25*16+50,$e,0);
    for j:=1 to 8 do begin
     vline(10+j*10,25*16+47,25*16+50,$e,0);
     line(10+((j-1)*longint(range)) div 1000,25*16+50-trunc((kill*(10-j)*(10-j)/2/max)),
	  10+((j)*longint(range)) div 1000,25*16+50-trunc((kill*(9-j)*(9-j)/2/max)),9,2);
     line(10+((j-1)*longint(range)) div 1000,25*16+50-trunc((destroy*(10-j)*(10-j)/2/max)),
	  10+((j)*longint(range)) div 1000,25*16+50-trunc((destroy*(9-j)*(9-j)/2/max)),$c,2);
    end;
    line(10+(8*longint(range)) div 1000,25*16+50-trunc((kill*(10-9)*(10-9)/2/max)),
	 10+(9*longint(range)) div 1000,25*16+50-0,9,2);
    line(10+(8*longint(range)) div 1000,25*16+50-trunc((destroy*(10-9)*(10-9)/2/max)),
	 10+(9*longint(range)) div 1000,25*16+50-0,$c,2);
   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>2) then x:=2;
     end;
     $50:begin
      if y<17 then inc(y);
      if (y and 1<>0)and(x>2) then x:=2;
     end;
     $4b:begin
      if x>0 then dec(x);
     end;
     $4d:if (x<2)or(x<5)and(y and 1=0) then inc(x);
     $44:begin
      racesave;
      redraw:=2;
     end;
    end;
    #27:redraw:=2;
    #13:with beams[y div 2+1] do begin
     if y and 1=0 then case x of
      0:eingabe(1,y+5,20,'Neuer Name Waffe '+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:');
      2:range:=eingabenr(12*x+3,y+5,9999,range,'Reichweite:');
     end;
     redraw:=1;
    end;
   end;
  until redraw>0;
 until redraw>1;
 setvideomode(co80);
end.