unit ObjectActionRegion;

interface

uses
  CustomObject, Vec2f, IniFiles, Collision, System.SysUtils;

type
  TObjectActionRegion = class(TCustomObject)
  private
    FPosition: TVec2i;
    FSize: TVec2i;
    FRect: T2DRect;
    function IsActive: Boolean; override;
  public

  published
    procedure Load(Aini: TIniFile); override;
  end;

implementation

uses
  Resources, Level.Map;

procedure TObjectActionRegion.Load(Aini: TIniFile);
var
  Str: String;
begin
  inherited;
  Str := 'Obj_' + IntToStr(ID);
  FPosition := TVec2i.Create(Aini.ReadInteger(Str, 'Left', -1), Aini.ReadInteger(Str, 'Top', -1));
  FSize := TVec2i.Create(Aini.ReadInteger(Str, 'Width', 3), Aini.ReadInteger(Str, 'Height', 3));

  FRect.Position := Position + FPosition * 24;
  FRect.Size := FSize * 24;
end;

function TObjectActionRegion.IsActive: Boolean;
var
  i: Integer;
begin
  for i := 0 to TGlobals.LevelHeroes.Count - 1 do
    if TCollision.PointRect(TGlobals.LevelHeroes[i].Position, FRect) then
      Exit(True);

  Result := False;
end;

end.
