unit c_mobs;

interface

uses
  c_map, defs;

type
  Tmob = object
    X, Y : Single;
    speed : single;
    dx, dy : Single;
    GoToWP : Word;
    nextX, nextY : Single;
    angle, oldangle, dxangle : Single;
    health, maxhealth : Integer;
    dead : Boolean;
    Procedure Init(w : Word);
    procedure Process(delta : Double);
  end;

var
  test : array of Tmob;
  mobcount : integer;  

implementation

uses Math;

procedure Tmob.Init(w : Word);
begin
  X:= map.wp[map.FindWPwithID(w)].X;
  Y:= map.wp[map.FindWPwithID(w)].Y;
  GoToWP:= w;

  NextX:= X;
  NextY:= Y;
  speed:= random(5000)/1000+1.0 + game_round/10;

  maxhealth:= 250 + game_round*10;
  health:= maxhealth;
end;

procedure Tmob.Process(delta : Double);
var
  alpha : Single;
begin
  if health <= 0 then
  begin
    dead:= true;
    money:= money + 5;
    exit;
  end;

  if (abs(X - NextX) < 16) and (abs(Y - NextY) < 16) then
  begin
    if (GoToWp = WPEnd) then
    begin
      dead:= true;
      corrupted:= corrupted + game_round;
      exit;
    end;

    GoToWP:= map.wp[map.FindWPwithID(GoToWP)].NextID;
    nextX:= map.wp[map.FindWPwithID(GoToWP)].X;
    nextY:= map.wp[map.FindWPwithID(GoToWP)].Y;

    alpha:= ArcTan2((NextY-Y),(NextX-X));
    dx:= cos((alpha))*speed;
    dy:= sin((alpha))*speed;

    angle:= RadToDeg(alpha)*256/360+64;

  end;

  X:= X + dx*delta;
  Y:= Y + dy*delta;
end;

end.
