unit cont;

interface

uses
  Windows, SysUtils, classes, Graphics, Controls,trigu,Baseclass,EnemyHeap;

const
  COUNT_WEAP = 12;

type
  TContener = class
     _List:array[0..COUNT_WEAP-1] of TWeapon;
    public
     procedure init;
     procedure addweap(ID,x,y:integer;TW:TWEAP);
     procedure draw(canvas,b_canvas:Tcanvas);
     procedure DrawWeap(x,y,_angle:integer;  TW:TWEAP; canvas:Tcanvas);
     function  targetinit(x,y,_num:integer; canvas,b_canvas:Tcanvas):TRPoint;
     function AI_mozgoed(var _mm:TContenerEnemy; canvas,b_canvas:Tcanvas):integer;
  end;

implementation

uses GI;


procedure TContener.init;
var i,Count2,Noise1,Noise2:integer;
begin
for i:=0 to COUNT_WEAP-1 do begin
  _list[i]:=TWeapon.Create;
  _list[i].XPos:=0;
  _list[i].YPos:=0;
  _list[i]._radius:=200;
  _list[i]._speed_rot:=3;
  _list[i]._visible:=false;

  _list[i].Angle:=0;
  _list[i]._sector:=2;
  _list[i]._Type:=twgun;
  _list[i]._wait:=true;
  _list[i]._target:=-1;
  _list[i]._OnTarget:=false;
  _list[i]._level:=0;
  _list[i]._killed:=0;
  _list[i].SB:=TsoundBlock.Create;
  _list[i].SB._on:=true;
  _list[i].SB._loop:=false;
  _list[i].SB._playing:=false;
  _list[i].SB.Channel:=i+1;
end;
end;

procedure TContener.DrawWeap(x,y,_angle:integer; TW:TWEAP; canvas:Tcanvas);
begin
try
case TW of
 twgun: begin
  canvas.Polygon([
  point(Round(((-14)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((-14)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y) ),
  point(Round(((-2)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y)),
  point(Round(((-2)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((-5)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((-5)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y) ),
  point(Round(((-5)*CosineArray^[_angle]-(-5)*SineArray^[_angle])+x),Round(((-5)*SineArray^[_angle]+(-5)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(-5)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(-5)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y)),
  point(Round(((2)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((2)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(5)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(5)*CosineArray^[_angle])+y)),
  point(Round(((-5)*CosineArray^[_angle]-(5)*SineArray^[_angle])+x),Round(((-5)*SineArray^[_angle]+(5)*CosineArray^[_angle])+y)),
  point(Round(((-5)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((-5)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((-2)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y)),
  point(Round(((-14)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((-14)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y)),
  point(Round(((-14)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((-14)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y))]);
 end;
 twliser: begin
  canvas.Polygon([
  point(Round(((-13)*CosineArray^[_angle]-(0)*SineArray^[_angle])+x),Round(((-13)*SineArray^[_angle]+(0)*CosineArray^[_angle])+y) ),
  point(Round(((-12)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((-12)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y)),
  point(Round(((-2)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y)),
  point(Round((-(3)*SineArray^[_angle])+x),Round(((3)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((7)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((7)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((7)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((7)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((0)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((0)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((-2)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y)),
  point(Round(((-12)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((-12)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y)),
  point(Round(((-13)*CosineArray^[_angle]-(0)*SineArray^[_angle])+x),Round(((-13)*SineArray^[_angle]+(0)*CosineArray^[_angle])+y)) ]);
 end;
 twbazooka: begin
  canvas.Polygon([
  point(Round(((-18)*CosineArray^[_angle]-(0)*SineArray^[_angle])+x),Round(((-18)*SineArray^[_angle]+(0)*CosineArray^[_angle])+y) ),
  point(Round(((-18)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((-18)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((-16)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((-16)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((-16)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((-16)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y)),
  point(Round(((-6)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((-6)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y)),
  point(Round(((-6)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((-6)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((-2)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(-4)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(-4)*CosineArray^[_angle])+y)),
  point(Round(((2)*CosineArray^[_angle]-(-6)*SineArray^[_angle])+x),Round(((2)*SineArray^[_angle]+(-6)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(-6)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(-6)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((8)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((8)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((8)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((8)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(6)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(6)*CosineArray^[_angle])+y)),
  point(Round(((2)*CosineArray^[_angle]-(6)*SineArray^[_angle])+x),Round(((2)*SineArray^[_angle]+(6)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(4)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(4)*CosineArray^[_angle])+y)),
  point(Round(((-2)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((-6)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((-6)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((-6)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((-6)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y)),
  point(Round(((-16)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((-16)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y)),
  point(Round(((-16)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((-16)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((-18)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((-18)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((-18)*CosineArray^[_angle]-(0)*SineArray^[_angle])+x),Round(((-18)*SineArray^[_angle]+(0)*CosineArray^[_angle])+y))
  ]);
 end;
 twdgun: begin
  canvas.Polygon([
  point(Round(((-3)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y) ),
  point(Round(((-1)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(-5)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(-5)*CosineArray^[_angle])+y)),
  point(Round(((-3)*CosineArray^[_angle]-(-5)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(-5)*CosineArray^[_angle])+y)),
  point(Round(((-3)*CosineArray^[_angle]-(-7)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(-7)*CosineArray^[_angle])+y)),
  point(Round(((-12)*CosineArray^[_angle]-(-7)*SineArray^[_angle])+x),Round(((-12)*SineArray^[_angle]+(-7)*CosineArray^[_angle])+y)),
  point(Round(((-12)*CosineArray^[_angle]-(-9)*SineArray^[_angle])+x),Round(((-12)*SineArray^[_angle]+(-9)*CosineArray^[_angle])+y)),
  point(Round(((-8)*CosineArray^[_angle]-(-9)*SineArray^[_angle])+x),Round(((-8)*SineArray^[_angle]+(-9)*CosineArray^[_angle])+y)),
  point(Round(((-8)*CosineArray^[_angle]-(-11)*SineArray^[_angle])+x),Round(((-8)*SineArray^[_angle]+(-11)*CosineArray^[_angle])+y)),
  point(Round(((-3)*CosineArray^[_angle]-(-11)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(-11)*CosineArray^[_angle])+y)),
  point(Round(((-3)*CosineArray^[_angle]-(-12)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(-12)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(-12)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(-12)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(-10)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(-10)*CosineArray^[_angle])+y)),
  point(Round(((8)*CosineArray^[_angle]-(-10)*SineArray^[_angle])+x),Round(((8)*SineArray^[_angle]+(-10)*CosineArray^[_angle])+y)),
  point(Round(((8)*CosineArray^[_angle]-(-6)*SineArray^[_angle])+x),Round(((8)*SineArray^[_angle]+(-6)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(-6)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(-6)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(-5)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(-5)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(-5)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(-5)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((4)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((4)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((4)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((4)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(5)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(5)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(5)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(5)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(6)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(6)*CosineArray^[_angle])+y)),
  point(Round(((8)*CosineArray^[_angle]-(6)*SineArray^[_angle])+x),Round(((8)*SineArray^[_angle]+(6)*CosineArray^[_angle])+y)),
  point(Round(((8)*CosineArray^[_angle]-(10)*SineArray^[_angle])+x),Round(((8)*SineArray^[_angle]+(10)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(10)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(10)*CosineArray^[_angle])+y)),
  point(Round(((5)*CosineArray^[_angle]-(12)*SineArray^[_angle])+x),Round(((5)*SineArray^[_angle]+(12)*CosineArray^[_angle])+y)),
  point(Round(((-3)*CosineArray^[_angle]-(12)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(12)*CosineArray^[_angle])+y)),
  point(Round(((-3)*CosineArray^[_angle]-(11)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(11)*CosineArray^[_angle])+y)),
  point(Round(((-8)*CosineArray^[_angle]-(11)*SineArray^[_angle])+x),Round(((-8)*SineArray^[_angle]+(11)*CosineArray^[_angle])+y)),
  point(Round(((-8)*CosineArray^[_angle]-(9)*SineArray^[_angle])+x),Round(((-8)*SineArray^[_angle]+(9)*CosineArray^[_angle])+y)),
  point(Round(((-12)*CosineArray^[_angle]-(9)*SineArray^[_angle])+x),Round(((-12)*SineArray^[_angle]+(9)*CosineArray^[_angle])+y)),
  point(Round(((-12)*CosineArray^[_angle]-(7)*SineArray^[_angle])+x),Round(((-12)*SineArray^[_angle]+(7)*CosineArray^[_angle])+y)),
  point(Round(((-3)*CosineArray^[_angle]-(7)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(7)*CosineArray^[_angle])+y)),
  point(Round(((-3)*CosineArray^[_angle]-(5)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(5)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(5)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(5)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((-3)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y) ) ]);
 end;
 twsnipergun: begin
  canvas.Polygon([
  point(Round(((-17)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((-17)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y) ),
  point(Round(((-17)*CosineArray^[_angle]-(-5)*SineArray^[_angle])+x),Round(((-17)*SineArray^[_angle]+(-5)*CosineArray^[_angle])+y)),
  point(Round(((-3)*CosineArray^[_angle]-(-5)*SineArray^[_angle])+x),Round(((-3)*SineArray^[_angle]+(-5)*CosineArray^[_angle])+y)),
  point(Round(((-2)*CosineArray^[_angle]-(-6)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(-6)*CosineArray^[_angle])+y)),
  point(Round(((4)*CosineArray^[_angle]-(-6)*SineArray^[_angle])+x),Round(((4)*SineArray^[_angle]+(-6)*CosineArray^[_angle])+y)),
  point(Round(((6)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((6)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((2)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((2)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y)),
  point(Round(((2)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((2)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((2)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((2)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((2)*CosineArray^[_angle]-(6)*SineArray^[_angle])+x),Round(((2)*SineArray^[_angle]+(6)*CosineArray^[_angle])+y)),
  point(Round(((-4)*CosineArray^[_angle]-(6)*SineArray^[_angle])+x),Round(((-4)*SineArray^[_angle]+(6)*CosineArray^[_angle])+y)),
  point(Round(((-4)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((-4)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((-2)*CosineArray^[_angle]-(1)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(1)*CosineArray^[_angle])+y)),
  point(Round(((-2)*CosineArray^[_angle]-(-1)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(-1)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((-17)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((-17)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)) ]);
 end;
 twdliser: begin
  canvas.Polygon([
  point(Round(((-1)*CosineArray^[_angle]-(0)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(0)*CosineArray^[_angle])+y) ),
  point(Round(((-2)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((-4)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((-4)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((-4)*CosineArray^[_angle]-(4)*SineArray^[_angle])+x),Round(((-4)*SineArray^[_angle]+(4)*CosineArray^[_angle])+y)),
  point(Round(((-14)*CosineArray^[_angle]-(4)*SineArray^[_angle])+x),Round(((-14)*SineArray^[_angle]+(4)*CosineArray^[_angle])+y)),
  point(Round(((-15)*CosineArray^[_angle]-(5)*SineArray^[_angle])+x),Round(((-15)*SineArray^[_angle]+(5)*CosineArray^[_angle])+y)),
  point(Round(((-14)*CosineArray^[_angle]-(6)*SineArray^[_angle])+x),Round(((-14)*SineArray^[_angle]+(6)*CosineArray^[_angle])+y)),
  point(Round(((-4)*CosineArray^[_angle]-(6)*SineArray^[_angle])+x),Round(((-4)*SineArray^[_angle]+(6)*CosineArray^[_angle])+y)),
  point(Round(((-4)*CosineArray^[_angle]-(7)*SineArray^[_angle])+x),Round(((-4)*SineArray^[_angle]+(7)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(8)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(8)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(7)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(7)*CosineArray^[_angle])+y)),
  point(Round(((6)*CosineArray^[_angle]-(7)*SineArray^[_angle])+x),Round(((6)*SineArray^[_angle]+(7)*CosineArray^[_angle])+y)),
  point(Round(((6)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((6)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((8)*CosineArray^[_angle]-(3)*SineArray^[_angle])+x),Round(((8)*SineArray^[_angle]+(3)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(2)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(2)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(0)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(0)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((8)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((8)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((6)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((6)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((6)*CosineArray^[_angle]-(-7)*SineArray^[_angle])+x),Round(((6)*SineArray^[_angle]+(-7)*CosineArray^[_angle])+y)),
  point(Round(((3)*CosineArray^[_angle]-(-7)*SineArray^[_angle])+x),Round(((3)*SineArray^[_angle]+(-7)*CosineArray^[_angle])+y)),
  point(Round(((1)*CosineArray^[_angle]-(-8)*SineArray^[_angle])+x),Round(((1)*SineArray^[_angle]+(-8)*CosineArray^[_angle])+y)),
  point(Round(((-4)*CosineArray^[_angle]-(-7)*SineArray^[_angle])+x),Round(((-4)*SineArray^[_angle]+(-7)*CosineArray^[_angle])+y)),
  point(Round(((-4)*CosineArray^[_angle]-(-6)*SineArray^[_angle])+x),Round(((-4)*SineArray^[_angle]+(-6)*CosineArray^[_angle])+y)),
  point(Round(((-14)*CosineArray^[_angle]-(-6)*SineArray^[_angle])+x),Round(((-14)*SineArray^[_angle]+(-6)*CosineArray^[_angle])+y)),
  point(Round(((-15)*CosineArray^[_angle]-(-5)*SineArray^[_angle])+x),Round(((-15)*SineArray^[_angle]+(-5)*CosineArray^[_angle])+y)),
  point(Round(((-14)*CosineArray^[_angle]-(-4)*SineArray^[_angle])+x),Round(((-14)*SineArray^[_angle]+(-4)*CosineArray^[_angle])+y)),
  point(Round(((-4)*CosineArray^[_angle]-(-4)*SineArray^[_angle])+x),Round(((-4)*SineArray^[_angle]+(-4)*CosineArray^[_angle])+y)),
  point(Round(((-4)*CosineArray^[_angle]-(-3)*SineArray^[_angle])+x),Round(((-4)*SineArray^[_angle]+(-3)*CosineArray^[_angle])+y)),
  point(Round(((-2)*CosineArray^[_angle]-(-2)*SineArray^[_angle])+x),Round(((-2)*SineArray^[_angle]+(-2)*CosineArray^[_angle])+y)),
  point(Round(((-1)*CosineArray^[_angle]-(0)*SineArray^[_angle])+x),Round(((-1)*SineArray^[_angle]+(0)*CosineArray^[_angle])+y) ) ]);
 end;
end;
except
end;
end;



procedure TContener.addweap(ID,x,y:integer;TW:TWEAP);
begin
if (ID<0)or(ID>COUNT_WEAP-1) then exit;
  _list[ID].XPos:=x;
  _list[ID].YPos:=y;
  _list[ID]._visible:=true;
  _list[ID]._Type:=TW;
  case _list[ID]._Type of
    twgun: begin
     _list[ID]._radius:=250;
     _list[ID]._speed_rot:=4;
     _list[ID].SB._loop:=true;
    end;
    twliser: begin
     _list[ID]._radius:=270;
     _list[ID]._speed_rot:=5;
    end;
    twbazooka: begin
     _list[ID]._radius:=310;
     _list[ID]._speed_rot:=2;
     _list[ID]._sector:=2;
    end;
    twdgun: begin
      _list[ID]._radius:=190;
      _list[ID]._speed_rot:=2;
      _list[ID]._sector:=2;
    end;
    twsnipergun: begin
      _list[ID]._radius:=320;
      _list[ID]._speed_rot:=5;
      _list[ID]._sector:=2;
    end;
    twdliser: begin
     _list[ID]._radius:=210;
     _list[ID]._speed_rot:=3;
     end;
  end;
end;

procedure TContener.draw(canvas,b_canvas:Tcanvas);
var
	TempPoly: Array[0..46] of TPoint;
  Count,i: Integer;
begin
 try
 for i:=0 to COUNT_WEAP-1 do
 if _list[i]._visible then  begin

  Canvas.Pen.Color:=$664534;
  Canvas.Brush.Color:=$664534;
  Canvas.Font.Color:=clred;
 case _list[i]._Type of
  twgun: Canvas.Ellipse(_list[i].xpos-8,_list[i].ypos-8,_list[i].xpos+9,_list[i].ypos+9);
  twliser: Canvas.Ellipse(_list[i].xpos-5,_list[i].ypos-5,_list[i].xpos+6,_list[i].ypos+6);
  twdgun: Canvas.Ellipse(_list[i].xpos-5,_list[i].ypos-5,_list[i].xpos+5,_list[i].ypos+5);
  twdliser: Canvas.Ellipse(_list[i].xpos-5,_list[i].ypos-5,_list[i].xpos+5,_list[i].ypos+5);
  twbazooka: Canvas.Ellipse(_list[i].xpos-8,_list[i].ypos-8,_list[i].xpos+9,_list[i].ypos+9);
  twsnipergun: Canvas.Ellipse(_list[i].xpos-4,_list[i].ypos-4,_list[i].xpos+5,_list[i].ypos+5);
 end;    

  Canvas.Brush.Style:=bsClear;


// отладочная хрень, типа радиус действия пытается рисовать
//  Canvas.Ellipse(_list[i].xpos-_list[i]._radius,_list[i].ypos-_list[i]._radius,_list[i].xpos+_list[i]._radius,_list[i].ypos+_list[i]._radius);


  Canvas.Font.Name:='lusida console';
  Canvas.Font.Size:=6;
  Canvas.Brush.Color:=clBlack;
  Canvas.Font.Color:=clyellow;
  Canvas.TextOut(_list[i].XPos+8,_list[i].YPos+8,'Kill: '+inttostr(_list[i]._killed));
  Canvas.TextOut(_list[i].XPos+8,_list[i].YPos+18,'Ammo: '+inttostr(_list[i].Ammo));
  Canvas.TextOut(_list[i].XPos+8,_list[i].YPos+28,'Level: '+inttostr(trunc(_list[i]._level)));

  Canvas.Pen.Color:=clblack;
  Canvas.Brush.Color:=clBlack;
  DrawWeap(_list[i].XPos,_list[i].YPos,_list[i].Angle,_list[i]._Type,canvas);
  {case _list[i]._Type of
    twgun: mainForm.FOffscreenBuffer.Canvas.TextOut(_list[i].XPos+8,_list[i].YPos+8,'Gun');
    twliser: mainForm.FOffscreenBuffer.Canvas.TextOut(_list[i].XPos+8,_list[i].YPos+8,'Liser');
  end; }
  end;
  except
  end;
end;

function getplace(angle,a2:integer):boolean;
var iangle:integer;
begin
 iangle:=Angle-a2;
 result:=false;
 if ((iangle>2)and(iangle>0))or((iangle<-2)and(iangle<0)) then result:=true;
end;

function gettimefire(angle,a2,_sector:integer):boolean;
var iangle:integer;
begin
 iangle:=Angle-a2;
 result:=true;
 if ((iangle>_sector)and(iangle>0))or((iangle<-_sector)and(iangle<0)) then result:=false;
end;

function TContener.targetinit(x,y,_num:integer; canvas,b_canvas:Tcanvas):TRPoint;
var ang:integer;
begin
 result.Y:=0;
 if _list[_num]._visible then  begin

     if (_list[_num].XPos>x)and(_list[_num].YPos>y) then begin
     ang := (-1)*Round(ArcTan(((_list[_num].YPos)-Y)/(X-(_list[_num].xPos)))*180/pi);
     end else
       if (_list[_num].XPos<x)and(_list[_num].YPos>y) then begin
       ang :=180+(-1)*Round(ArcTan(((_list[_num].YPos)-Y)/(X-(_list[_num].xPos)))*180/pi);
       end else
         if (_list[_num].XPos>x)and(_list[_num].YPos<y) then begin
         ang :=360+(-1)*Round(ArcTan(((_list[_num].YPos)-Y)/(X-(_list[_num].xPos)))*180/pi);
         end else
           if (_list[_num].XPos<x)and(_list[_num].YPos<y) then begin
           ang :=180+(-1)*Round(ArcTan(((_list[_num].YPos)-Y)/(X-(_list[_num].xPos)))*180/pi);
           end else begin
             if (_list[_num].XPos=x)and(_list[_num].YPos<y) then ang :=270;
             if (_list[_num].XPos=x)and(_list[_num].YPos>y) then ang :=90;
             if (_list[_num].XPos>x)and(_list[_num].YPos=y) then ang :=0;
             if (_list[_num].XPos<x)and(_list[_num].YPos=y) then ang :=180;
           end;

//  mainForm.FOffscreenBuffer.Canvas.TextOut(40,0,inttostr(Ang));

  if getplace(_list[_num].Angle,ang) then
   _list[_num].Rotate(ang);
     result.X:=0;
  if gettimefire(_list[_num].Angle,ang,_list[_num]._sector) then begin
     result.X:=_list[_num].Fire(x,y,canvas,b_canvas);
     case _list[_num]._Type of
       twgun: _list[_num].SB.play(3);
       twdgun: _list[_num].SB.play(7);
       twbazooka: _list[_num].SB.play(2);
       twdliser:  _list[_num].SB.play(4);
       twliser:   _list[_num].SB.play(5);
       twsnipergun: _list[_num].SB.play(6);
     end;
    if (_list[_num]._Type=twliser) then result.Y:=2;
    if (_list[_num]._Type=twdliser) then result.Y:=5;
  end;

   end;
end;

function GetTrace(x1,y1,x2,y2,rad:integer):integer;
var ix,iy:integer;
begin
//  ix:=x1-x2; iy:=y1-y2;
  result:=trunc(sqrt(sqr(x1-x2)+sqr(y1-y2)));
end;

function GetOnTarget(TE:TEnemy; TW:TWEAP; _level:integer):boolean;
begin
result:=false;
case TW of         // teMeloch , teBugay , teharder_
  twsnipergun: begin
    case TE._tip of
     teMeloch: result:=true;
     teBugay:  if (_level>2)and(te.helth<50) then result:=true;
     //teharder: if (_level>4)and(te.helth<80) then result:=true;
    end;
  end;
  twgun,twliser,twbazooka,twsun: result:=true;
  twdgun,twdliser: begin
    if te._tip<>teMeloch then result:=true;
  end;
end;
end;

function TContener.AI_mozgoed(var _mm:TContenerEnemy; canvas,b_canvas:Tcanvas):integer;
var i,ii:integer; ang,iii:integer; TE,TE_target:TEnemy;  use:boolean; TR:TRPoint;
begin
 result:=0;
if _mm.List.Size=0 then exit;
 for ii:=0 to COUNT_WEAP-1 do
 if (_list[ii]._visible)and not(_list[ii]._wait) then  begin

 if  _list[ii]._OnTarget then begin
    use:=true;
    for i:=0 to (_mm.List.Size div sizeof(TEnemy))-1 do begin
  _mm.List.Position:=sizeof(TEnemy)*i;
  _mm.List.ReadBuffer(te,sizeof(TEnemy));
  if (te._use)and(use)and(te.ID=_list[ii]._target) then  begin
    use:=false;
    iii:=GetTrace(_list[ii].XPos,_list[ii].YPos,trunc(te.XPos),trunc(te.yPos),_list[ii]._radius);
    if (iii<ang)and(iii<=_list[ii]._radius)and(ang>0) then begin
     TE_target:=TE;
     ang:=iii;
     _list[ii]._OnTarget:=true;
     _list[ii]._target:=TE_target.ID;
     end else begin
     _list[ii]._OnTarget:=false;
     _list[ii]._target:=-1;
     end;
    end; end;
    if use then begin
     _list[ii]._OnTarget:=false;
     _list[ii]._target:=-1;
    end;
 end else begin
  ang:=_list[ii]._radius+1;
 for i:=0 to (_mm.List.Size div sizeof(TEnemy))-1 do begin
  _mm.List.Position:=sizeof(TEnemy)*i;
  _mm.List.ReadBuffer(te,sizeof(TEnemy));
  if (te._use)and(GetOnTarget(te,_list[ii]._Type, trunc(_list[ii]._level))) then  begin
  // if =,twdliser
    iii:=GetTrace(_list[ii].XPos,_list[ii].YPos,trunc(te.XPos),trunc(te.yPos),_list[ii]._radius);
    if (iii<ang)and(iii<=_list[ii]._radius)and(ang>0) then begin
     TE_target:=TE;
     ang:=iii;
     _list[ii]._OnTarget:=true;
     _list[ii]._target:=TE_target.ID;

     end;
  end;
 end;
  end;

  if _list[ii]._OnTarget then
   if (ang<=_list[ii]._radius) then begin
   TR:=targetinit(trunc(TE_target.XPos),trunc(TE_target.yPos),ii, canvas,b_canvas);
   TE_target.helth:=TE_target.helth-tr.X;
  // if tr.X>0 then
   // GI._Shadow.Draw_shadow(canvas,canvas,_list[ii].XPos,_list[ii].YPos);
   result:=result+tr.Y;
   end;

  if _list[ii]._OnTarget then
   if (ang<=_list[ii]._radius) then
   if TE_target.helth<0 then begin
   _mm.delen(TE_target.ID);
   
  // Paint_dead_small(trunc(TE_target.XPos),trunc(TE_target.yPos),random(2),b_canvas);
   _list[ii]._target:=-1;
   _list[ii]._OnTarget:=false;
   _list[ii]._level:=_list[ii]._level+0.25;
   _list[ii]._killed:=_list[ii]._killed+1;
 // if _list[ii]._Type=twbazooka then
 //  _list[ii].Ba_Bax(TE_target.XPos,TE_target.yPos,8);
   _mm._more:=_mm._more+1;
    end else begin
     
     _mm.List.Position:=sizeof(TEnemy)*TE_target.ID;
     _mm.List.Write(TE_target,sizeof(TEnemy));
     end;

 end;
end;

end.

