unit reading;

interface

uses
  sysutils, loadz, svet, aData;

procedure read_nazv;
procedure readz;
procedure think;
function rread(yx, yy: byte): string;
function read_loc(yx, yy: byte; var newx, newy: byte): string;


implementation

uses
  MyCRT;

function rread(yx, yy: byte): string;
var
  i: integer;
begin
  for i := 1 to CoordsCount do
    if (CoordsArr[i].locname = data.location) and (CoordsArr[i].oldCoordX = yx)
      and (CoordsArr[i].oldCoordY = yy) then
    begin
      rread := CoordsArr[i].text;
      exit;
    end;
  rread := '';
  exit;
end;

function read_loc(yx, yy: byte; var newx, newy: byte): string;
var
  i: integer;
begin
   for i := 1 to CoordsCount do
   begin
     if (CoordsArr[i].locname = data.location) and (CoordsArr[i].oldCoordX = yx)
       and (CoordsArr[i].oldCoordY = yy) then
     begin
       read_loc := CoordsArr[i].locnext;
       newx := CoordsArr[i].coordx;
       newy := CoordsArr[i].coordy;
       exit;
     end;
   end;
   read_loc := '';
   exit;
end;



procedure read_nazv;
var
  ff: string;
  xtz, ytz: byte;
begin
  xtz := wherex;
  ytz := wherey;
  ff:='';
  ff := rread(xtz, ytz);
  if (ff <> '') then
  begin
    textcolor(white);
    gotoxy(1, RESOLUTION_Y + 3);
    write(ff);
    gotoxy(xtz, ytz);
  end
{  else if data.location = MAP_MAIN then
  begin
    gotoxy(1, RESOLUTION_Y + 1);
    textcolor(white);
    write(IntToStr(data.day) + ' ');
    case data.month of
      1: write(STR_JANUARY);
      2: write(STR_FEBRUARY);
      3: write(STR_MARCH);
      4: write(STR_APRIL);
      5: write(STR_MAY);
      6: write(STR_JUNE);
      7: write(STR_JULE);
      8: write(STR_AUGUST);
      9: write(STR_SEPTEMBER);
      10: write(STR_OCTOBER);
      11: write(STR_NOVEMBER);
      12: write(STR_DECEMBER);
    end;
    write(IntToStr(data.year) + '  ' + IntToStr(data.hours div 10) + IntToStr(data.hours mod 10) + ':' +
          IntToStr(data.minutes div 10) + IntToStr(data.minutes mod 10));
    gotoxy(xtz, ytz);
  end }
  else
    gotoxy(xtz, ytz);
end;

procedure readz;
var
  i: integer;
  got: boolean;
  s, fname: string;
  f: TextFile;
begin
  got := false;
  if (data.Contusioned > 0) then
  begin
    hudmessage(STR_YOU_CONTUSIONED, MT_TEXT);
    exit;
  end;
  clrscr;
  fname := READFOLDER + IntToStr(cur_lev.map[data.posx, data.posy].ObjAttrz) + '.txt';
  AssignFile(f, fname);
  Reset(f);
  while (not Eof(f)) do
  begin
    System.Readln(f, s);
    WriteLn(s);
  end;
  CloseFile(f);
  readkey;
  clrscr;
  clean_all;
  GoToXY(data.posx, data.posy);
  osv;
{  for i := 1 to CoordsCount do
  begin
    if (CoordsArr[i].locname = data.location) and (CoordsArr[i].oldCoordX = data.posx)
      and (CoordsArr[i].oldCoordY = data.posy) then
    begin
      got := true;
      break;
    end;
  end;
  if got then
  begin
    textcolor(white);
    clrscr;
    write(CoordsArr[i].text);
    while wherex < 41 do
      write(' ');
    readkey;
    clrscr;
    clean_all;
    gotoxy(data.posx, data.posy);
//    osv;
  end;}
end;


procedure think;
begin
  clrscr;
  textcolor(white);
  write(cur_lev.feeling);
  readkey;
  clrscr;
  clean_all;
  gotoxy(data.posx, data.posy);
  osv;
end;


begin
end.