unit Otshelm_B;

interface
uses
  Model, SysUtils, Forms;

var
DialN : string;
OpontDT, HeroDT : array[1..10] of string;
MofDTS, IofDTS, BWD : byte;

procedure PersDialogb(n : byte);
procedure getguimess(D, S, B : string);
procedure DialogN;
Procedure BotsWork;

implementation
uses
Otshelm_C, Lives, ghload;

procedure getguimess(D, S, B : string);
var
I, O : integer;
FS : string;
begin
  O:=0;
  FS:='';
  for I:=0 to length(S) do
  begin
    O:=O+1;
    FS:=FS+S[I];
    if (O>40) and (S[I]=' ') then
    begin
      O:=0;
      FS:=FS+#13;
    end;
  end;
  OTofG:=TofG;
  TofG:=0;
  ghload.Layer[2].Visible:=true;
  ghload.GLLabel[1].O.Caption:=FS;
  ghload.GLForm[2].O.Caption:=D;
  ghload.GLButton[4].O.Caption:=B;
  ghload.Layer[1].Visible:=false;
  ghload.Layer[3].Visible:=false;
end;

procedure loadSDialog(FN : string);
var
  F : textfile;
  i : integer;
  S : string;
begin
  FN:=ExtractFilePath(Application.ExeName)+FN;
  if FileExists(FN) then
    begin
      assign(F,FN);
      reset(F);
      readln(F,MofDTS);
      for I:=1 to MofDTS do
        begin
          readln(F,OpontDT[I]);
          readln(F,HeroDT[I]);
        end;
      Closefile(F);
    end;
end;

procedure DialogN;
begin
  if IofDTS<MofDTS then
    begin
      IofDTS:=IofDTS+1;
      getguimess(DialN, OpontDT[IofDTS], HeroDT[IofDTS]);
    end
  else
    begin
      ghload.Layer[2].Visible:=false;
      TofG:=1;
    end;
end;

procedure PersDialogb(n : byte);
begin
  if Model.EtLiveObj[Model.Pers[N].Et].NPC then
    begin
      BWD:=N;
      if TCWin>5 then Model.Pers[N].Talk:=3;
      loadSDialog(Model.EtLiveObj[Model.Pers[N].Et].D[Model.Pers[N].Talk]);
      TofG:=8;
      IofDTS:=0;
      DialN:='Диалог с '+Model.EtLiveObj[Model.Pers[N].Et].Name;
      Model.Pers[N].MA:=Lives.whatroll(Model.Pers[N].A.Position.X,
                                        Model.Pers[NHero].A.Position.X,
                                        Model.Pers[N].A.Position.Y,
                                        Model.Pers[NHero].A.Position.Y);
      Model.Pers[N].Talk:=2;
    end;
end;

Procedure BotsWork;
begin
  if  Lives.roll(BWD) then
    begin
      TofG:=7;
      DialogN;
    end;
end;


end.
