unit GroupGen;

interface

uses
  windows, messages, sysutils, loadz;

procedure GenerateGroup(x, y: integer; intensivity: integer; aType: string; chance: integer; IsGenerateEntrace: boolean = false);
procedure GenerateGroupInPrison(x, y, intensivity: integer; aType: string; chance: integer);
procedure GenerateGroupInWall(x, y, intensivity: integer; aType: string; chance: integer);

implementation

uses
  MyCRT;

procedure GenerateGroupInPrison(x, y, intensivity: integer; aType: string; chance: integer);
var
  n, s, e, w, i, j, k: integer;
begin
  i := x;
  j := y;
  for k := 1 to intensivity do
  begin
    n := random(chance);
    e := random(chance);
    s := random(chance);
    w := random(chance);
    if n = 1 then
    begin
      i := i - 1;
      if (not IsBold(i, j)) and (not IsType(i, j, 'PrisonUp')) and (not IsType(i, j, 'PrisonDown')) then
        SetElement(i, j, aType);
    end;
    if s = 1 then
    begin
      i := i + 1;
      if (not IsBold(i, j)) and (not IsType(i, j, 'PrisonUp')) and (not IsType(i, j, 'PrisonDown')) then
        SetElement(i, j, aType);
    end;
    if e = 1 then
    begin
      j := j + 1;
      if (not IsBold(i, j)) and (not IsType(i, j, 'PrisonUp')) and (not IsType(i, j, 'PrisonDown')) then
        SetElement(i, j, aType);
    end;
    if w = 1 then
    begin
      j := j - 1;
      if (not IsBold(i, j)) and (not IsType(i, j, 'PrisonUp')) and (not IsType(i, j, 'PrisonDown')) then
        SetElement(i, j, aType);
    end;
  end;
end;

procedure GenerateGroupInWall(x, y, intensivity: integer; aType: string; chance: integer);
var
  n, s, e, w, i, j, k: integer;
begin
  i := x;
  j := y;
  for k := 1 to intensivity do
  begin
    n := random(chance);
    e := random(chance);
    s := random(chance);
    w := random(chance);
    if n = 1 then
    begin
      i := i - 1;
      if (IsType(i, j, 'Wall') or IsType(i, j, 'WallGround') or IsType(i, j, 'Rock') or (IsType(i, j, 'Land'))) then
        SetElement(i, j, aType);
    end;
    if s = 1 then
    begin
      i := i + 1;
      if (IsType(i, j, 'Wall') or IsType(i, j, 'WallGround') or IsType(i, j, 'Rock') or (IsType(i, j, 'Land'))) then
        SetElement(i, j, aType);
    end;
    if e = 1 then
    begin
      j := j + 1;
      if (IsType(i, j, 'Wall') or IsType(i, j, 'WallGround') or IsType(i, j, 'Rock') or (IsType(i, j, 'Land'))) then
        SetElement(i, j, aType);
    end;
    if w = 1 then
    begin
      j := j - 1;
      if (IsType(i, j, 'Wall') or IsType(i, j, 'WallGround') or IsType(i, j, 'Rock') or (IsType(i, j, 'Land'))) then
        SetElement(i, j, aType);
    end;
  end;
end;

procedure GenerateGroup(x, y, intensivity: integer; aType: string; chance: integer; IsGenerateEntrace: boolean = false);
var
  n, s, e, w, i, j, k: integer;
  AlreadyGenerated: boolean;
  luck: integer;
begin
  i := x;
  j := y;
  luck := 10 - (data.luck div 3);
  if (luck < 1) then
    luck := 1;
  AlreadyGenerated := false;
  for k := 1 to intensivity do
  begin
    n := random(chance);
    e := random(chance);
    s := random(chance);
    w := random(chance);
    if (n = 1) and (i > 2) then
    begin
      i := i - 1;
      if ((not IsInHouse(i, j)) and not IsBold(i, j)) then
      begin
        SetElement(i, j, aType);
        if (IsGenerateEntrace) and (not AlreadyGenerated) then
          if (Random(10) + 1) mod luck = 0 then
          begin
            SetElement(i, j, 'PrisonDown');
            cur_lev.map[i, j].ObjAttrz := 3 + Random(12);
            AlreadyGenerated := true;
          end;
      end;
    end;
    if (s = 1) and (i < RESOLUTION_X - 1) then
    begin
      i := i + 1;
      if ((not IsInHouse(i, j)) and not IsBold(i, j)) then
      begin
        SetElement(i, j, aType);
        if (IsGenerateEntrace) and (not AlreadyGenerated) then
          if (Random(10) + 1) mod luck = 0 then
          begin
            SetElement(i, j, 'PrisonDown');
            cur_lev.map[i, j].ObjAttrz := 3 + Random(12);
            AlreadyGenerated := true;
          end;
      end;
    end;
    if (e = 1) and (j < RESOLUTION_Y - 1) then
    begin
      j := j + 1;
      if ((not IsInHouse(i, j)) and not IsBold(i, j)) then
      begin
        SetElement(i, j, aType);
        if (IsGenerateEntrace) and (not AlreadyGenerated) then
          if (Random(10) + 1) mod luck = 0 then
          begin
            SetElement(i, j, 'PrisonDown');
            cur_lev.map[i, j].ObjAttrz := 3 + Random(12);
            AlreadyGenerated := true;
          end;
      end;
    end;
    if (w = 1) and (j > 2) then
    begin
      j := j - 1;
      if ((not IsInHouse(i, j)) and not IsBold(i, j)) then
      begin
        SetElement(i, j, aType);
        if (IsGenerateEntrace) and (not AlreadyGenerated) then
          if (Random(10) + 1) mod luck = 0 then
          begin
            SetElement(i, j, 'PrisonDown');
            cur_lev.map[i, j].ObjAttrz := 3 + Random(12);
            AlreadyGenerated := true;
          end;
      end;
    end;
  end;
  if (not AlreadyGenerated) and (IsGenerateEntrace) then
    SetElement(x, y, 'PrisonDown');
end;

end.
