unit start;

interface

uses
  windows, sysutils, loadz, turn, beginz, svet, reading, LevGen;

procedure startgame;

var
  APoint: TCoord;

implementation
uses
  MyCrt, NewUnit1;

procedure GenerateTables;
var
  i: byte;
begin
  for i := 1 to SINCOSCOUNT do
  begin
    Sinus[i] := sin(i * 2 / SINCOSCOUNT * Pi);
    Cosinus[i] := cos(i * 2 / SINCOSCOUNT * Pi);
  end;
end;

procedure GenerateTechnoColors;
const
  TECHNOZ_COUNT = 31;
var
  arr: array [1..TECHNOZ_COUNT] of byte;
  i, j: integer;
  len: byte;
  curr: byte;
begin
  for i := 1 to TECHNOZ_COUNT do
    arr[i] := i;
  len := TECHNOZ_COUNT;
  for i := 1 to TECHNOZ_COUNT do
  begin
    curr := Random(len) + 1;
    data.TechnoZ[i].num := arr[curr];
    data.TechnoZ[i].examined := false;
    for j := curr to len - 1 do
      arr[j] := arr[j + 1];
    dec(len);
  end;
end;

procedure GenerateNanoNames;
const
  TECHNOZ_COUNT = 25;
var
  arr: array [1..TECHNOZ_COUNT] of byte;
  i, j: integer;
  len: byte;
  curr: byte;
begin
  for i := 1 to TECHNOZ_COUNT do
    arr[i] := i;
  len := TECHNOZ_COUNT;
  for i := 1 to TECHNOZ_COUNT do
  begin
    curr := Random(len) + 1;
    data.NanoZ[i].num := arr[curr];
    data.NanoZ[i].examined := false;
    for j := curr to len - 1 do
      arr[j] := arr[j + 1];
    dec(len);
  end;
end;

procedure GenerateDrinkNames;
const
  DRINK_COUNT = 45;
var
  arr: array [1..DRINK_COUNT] of byte;
  i, j: integer;
  len: byte;
  curr: byte;
begin
  for i := 1 to DRINK_COUNT do
    arr[i] := i;
  len := DRINK_COUNT;
  for i := 1 to DRINK_COUNT do
  begin
    curr := Random(len) + 1;
    data.DrinkZ[i].num := arr[curr];
    data.DrinkZ[i].examined := false;
    for j := curr to len - 1 do
      arr[j] := arr[j + 1];
    dec(len);
  end;
end;

procedure osvall;
var
  x, y: integer;
begin
  for y := 1 to RESOLUTION_Y do
    for x := 1 to RESOLUTION_X do
      WriteChrXY(x, y, cur_lev.map[x, y].lev);
  readkey;
end;

procedure startgame;
var
  bool: boolean;
  i: integer;
begin
  randomize;
  DontDeleteSaves := false;
  data.hardly := false;
//  InitializeFont(DATAFOLDER + FONTFILENAME);
  for i := 1 to ParamCount do
    if Paramstr(i) = '/keepsaves' then
      DontDeleteSaves := true
    else if Paramstr(i) = '/dark' then
      data.hardly := true
    else if Paramstr(i) = '/nolab' then
      DoNotLabyrints := true;
  GenerateTables;
  data.trade := false;
  data.prizrak := false;
  textbackground(black);
  deleteSaz;
  data.year := 2286;
  data.month := 2;
  data.day := 1;
  data.hours := 1;
  data.minutes := 13;
  data.seconds := 59;
  data.PrisonLevel := 0;
  data.LastSavedLevel := 0;
  data.MaxLevel := 0;
  data.Light_color := white;
  data.cur_osv := 8;
  data.IsInInv := false;
  data.anAnnigil := false;
  for i := 1 to IMPLANTS_MAX - IMPLANTS_MIN + 1 do
    data.UsedImplants[i] := false;

  if not menu then
  begin
    data.maxweight := 300;
    data.max_health := 50;
    FstScreen(40);
    data.health := data.max_health div 5;
    data.hero := '@';
    data.herocolor := LightGreen;
    fstdialog;
    clrscr;
    for i := 1 to MAXITEMS do
    begin
      data.inventory[i].number := 0;
      data.inventory[i].count := 0;
    end;
    data.r_hand := 0;
    data.l_hand := 0;
    data.shapka := 0;
    data.sapogi := 0;
    data.toPortal := 0;
    data.ustal := 65535;
    data.hunger := 65535;
    data.gloves := 0;
    data.trousers := 0;
    data.amulet := 0;
    data.level := 1;
    data.expa_2_next := ((data.level * (1000 + (data.level * 10))) + Random(1000) + Random(100) + Random(10));
    data.money := 200;
    data.age := 24;
    data.bYear := data.year - data.age - 1;
    data.bMonth := Random(10) + 3;
    data.bDay := Random(30) + 1;
    data.DeathAge := 65 + Random(20);
    data.TradeImplants := false;

    GenerateTechnoColors;
    GenerateNanoNames;
    GenerateDrinkNames;
    delete;
    deletesaves;
    data.location := MAP_MAIN;//'city';//MAP_MAIN;
    level_load;
    gotoxy(3, 3);//(15, 42);
    osv;
    data.posx := 3;//15;
    data.posy := 3;//42;
    data.global_x := wherex;
    data.global_y := wherey;
  end
  else
  begin
    loadgame(true);
    clrscr;
{    data.health := 1000;
    data.inventory[2].number := 75;
    data.inventory[2].count := 1;
    data.money := 10000;
    data.ustal := 10005;
    data.hunger := 10050;}
    if data.location = MAP_MAIN then
    begin
      clean_map_all;
      gotoxy(data.global_x, data.global_y);
      osv_map;
    end
    else
    begin
      gotoxy(data.posx, data.posy);
      clean_all;
      gotoxy(data.posx, data.posy);
      osv;
    end;
  end;
  hud;
  read_nazv;
  repeat
    bool := maketurn;
  until (not bool);
  DeleteBeforeExit;
end;

begin
end.