unit creation;

interface

uses units, constants, records, variables,
     respawns, global, pathfinding, buildings;

procedure CreateEnemys;

var
  current_params : integer;

implementation

var
  number : integer;
  par_big : REnemyParams;

function GenerateParams : REnemyParams;
begin
current_params := current_params + 1;

number := 20 + round(sqr(current_params) * 2);

result.scale := 0.4 + current_params / 12;
if result.scale > 2 then result.scale := 2;
result.health := 10 + current_params*6;
result.default_health := result.health;
result.damage := 0.4 + sqrt(current_params) / 4;
result.default_damage := result.damage;
result.speed := 0.00008 + sqrt(current_params) / 15000;
result.default_speed := result.speed;
result.get_credits := 5 + round(sqrt(current_params * 2) + current_params);
result.get_score := round(sqrt(current_params));

par_big.scale := result.scale + 0.3;
par_big.health := result.health * 1.5;
par_big.default_health := par_big.health;
par_big.damage := result.damage + result.damage * sqrt(current_params);
par_big.default_damage := par_big.damage;
par_big.speed := result.speed + result.speed * sqrt(current_params) / 2.2;
par_big.default_speed := par_big.speed;
par_big.get_credits := result.get_credits * 4;
par_big.get_score := result.get_score * 2;
end;

procedure CreateEnemys;
var
i, c, e, ne : integer;
par : REnemyParams;
begin
play_new_wave := play_new_wave + 1;

next_wave_hour := hours + random(2) + 2;
if next_wave_hour > 23 then
  begin
    next_wave_hour := next_wave_hour - 24;
    next_wave_day := next_wave_day + 1;
  end;
next_wave_minute := random(60);

par := GenerateParams;
if number > total_respawns then number := total_respawns;
if total_enemys + number > max_enemys then number := max_enemys - total_enemys;
if number <= 0 then exit;

c := 0;
repeat
i := random(total_respawns) + 1;
with gRespawns[i] do
  begin
    total_enemys := total_enemys + 1;
    ne := total_enemys;
    if total_enemys >= max_enemys then
      for e := 1 to max_enemys do
        if not iEnemys[e] then ne := e;  
    if ne >= max_enemys then exit;

    iEnemys[ne] := true;
    if c = 0 then
      gEnemys[ne] := TUnit.Create(map_x, map_y, par_big, true)
    else
      gEnemys[ne] := TUnit.Create(map_x, map_y, par, false);
    with gEnemys[ne] do
      begin
        num := ne;
        pathmap.map[map_x, map_y].child_enemy_id := ne;

        body1.id := id_enemys + total_enemys;
        body2.id := body1.id; wings1.id := body1.id; wings2.id := body1.id;
        respawn_number := i;
        path_pos := path.length;
        path_pos_f := path.length;
      end;

    c := c + 1;
  end;
until c = number;
end;

end.
