unit Script;

interface
uses
  SysUtils, Forms, GlScene, GLGeomObjects, Model, quod_C,
  GLVectorFileObjects, VectorGeometry, GlFileSMD, JPEG, GLObjects;

Type
 TScriptCube = record
   P, S : Tpoint;
   Sc : string;
   Ac : boolean;
  end;

Procedure CreatScrCube(PX,PY,SX,SY : real; S : string; B : boolean);
Procedure ScrRead(S1: integer; s2:string);
Procedure ScrV;
Procedure WorkScr;
  var

  ScriptCube : array[1..200] of TScriptCube;
  MoFSC, SD : integer;
  SO, SP1,SP2, Zvuk, Next : string;
  Worked : boolean;
  pickW: TGLCustomSceneObject;
implementation

Procedure CreatScrCube(PX,PY,SX,SY : real; S : string; B : boolean);
begin
  MoFSC:=MoFSC+1;
  ScriptCube[MoFSC].P.X:=PX;
  ScriptCube[MoFSC].P.Y:=PY;
  ScriptCube[MoFSC].S.X:=SX;
  ScriptCube[MoFSC].S.Y:=SY;
  ScriptCube[MoFSC].Sc:=S;
  ScriptCube[MoFSC].Ac:=B;
end;

Procedure ScrRead(S1: integer; s2:string);
var
Sfile: textfile;
Sb, Fn : string;
begin
  SD:=0;
  Fn:=ExtractFilePath(Application.ExeName)+ '\Map\'+quod_C.SCRIPTF;
if FileExists(FN) then
begin
assignfile(Sfile, FN);
reset(Sfile);
readln(Sfile,SB);
if SB='<SCRIPTS>' then
  begin
    while (SB<>'<<-'+s2){ or (SB<>'<END>')} do
    readln(Sfile,SB);

    readln(Sfile,SB);
    SD:=strtoint(SB);

    readln(Sfile,SO);
    readln(Sfile,SP1);
    readln(Sfile,SP2);
    readln(Sfile,zvuk);
    if (zvuk<>'') and (zvuk<>'no') then
//    Sound.PSoundO(zvuk);
    readln(Sfile,SB);
    if (SB<>'+') and (S1<>0) then ScriptCube[s1].Ac:=false;
    Next:='';
    if (SB<>'-') and (SB<>'') then next:=SB;
    worked:=false;
  end;
closefile(Sfile);
end;
end;

Procedure ScrV;
begin
if SO='sound' then
       begin
//         Sound.LMusic(SP1);
//         Sound.PSoundO(SP1);
         Worked:=true;
       end;
if SO='talk' then
       begin
//         Sound.PSound(SP2,strtoint(sp1));
//         Worked:=true;
//         AI.AiBOT[strtoint(SP1)].ActorR.SwitchToAnimation('');
       end;

if SO='music' then
       begin
//         Sound.LMusic(SP1);
//         Sound.PMusic(SP1);
//         Worked:=true;
       end;

if SO='movex' then
       begin
         Pickw.Position.X:=Pickw.Position.X+strtoint(SP1)/100;
         if (Pickw.Position.X<strtoint(SP2)/10+0.1)
         and (Pickw.Position.X>strtoint(SP2)/10-0.1)
         then Worked:=true;
       end;
if SO='movey' then
       begin
         Pickw.Position.y:=Pickw.Position.y+strtoint(SP1)/100;
         if (Pickw.Position.y<strtoint(SP2)/10+0.1)
         and (Pickw.Position.y>strtoint(SP2)/10-0.1)
         then Worked:=true;
       end;
if SO='movez' then
       begin
         Pickw.Position.z:=Pickw.Position.z+strtoint(SP1)/100;
         if (Pickw.Position.z<strtoint(SP2)/10+0.1)
         and (Pickw.Position.z>strtoint(SP2)/10-0.1)
         then Worked:=true;
       end;
if SO='lift' then
       begin
        // MForm.GLDCE.Gravity:=-strtoint(SP1)*1.5;
         Pickw.Position.z:=Pickw.Position.z+strtoint(SP1)/100;
         if (Pickw.Position.z<strtoint(SP2)/10+0.1)
         and (Pickw.Position.z>strtoint(SP2)/10-0.1)
         then
         begin
         Worked:=true;
         // MForm.GLDCE.Gravity:=9.5;
         end;
       end;
if SO='visible' then
       begin
         if SP1='true' then PickW.Visible:=true
         else PickW.Visible:=false;
         Worked:=true;
       end;
if SO='text' then
       begin
//         Gamer.Text.Text:=SP1;
//         Worked:=true;
       end;
if SO='krolik' then
       begin
//       Effects.KrolikTime:=strtoint(SP1);
//       Gamer.Krolik.Visible:=true;
//       Sound.PSoundY('aaa1');
//       Worked:=true;
       end;
if SO='krolik2' then
       begin
//       Gamer.Krolik.Material.MaterialLibrary:=Mform.MenuImage;
//       Gamer.Krolik.Material.LibMaterialName:='k';
//       Effects.KrolikTime:=strtoint(SP1);
//       Gamer.Krolik.Visible:=true;
//       Sound.PSoundY('aaa1');
//       Worked:=true;
       end;

if SO='material' then
       begin
//       Pickw.Material.MaterialLibrary:=mform.GLML;
//       Pickw.Material.LibMaterialName:=sp1;
//       Worked:=true;
      end;

if SO='manim' then
       begin
//       Mform.Caption:=SP1;
//       Effects.AnimS:=strtoint(SP1);
//       Worked:=true;
       end;

if SO='win' then
       begin
{        if Mform.MenuImage.Materials[25].Material.FrontProperties.Diffuse.Alpha>0.975
         then
         begin
         GameProc.MAP:=SP1;
         GameProc.SCRIPTF:=SP2;
         GameProc.LoadNewGame;
         Worked:=true;
         end
         else
         Mform.MenuImage.Materials[25].Material.FrontProperties.Diffuse.Alpha:=
         Mform.MenuImage.Materials[25].Material.FrontProperties.Diffuse.Alpha+0.0075;
         Gamer.MyBlood.Visible:=true;
         Gamer.MyBlood.Material.LibMaterialName:='t0';  }
       end;

if SO='titri' then
{       begin
        if Mform.MenuImage.Materials[25].Material.FrontProperties.Diffuse.Alpha>0.95
         then
         GameProc.CreatTitri
         else
         Mform.MenuImage.Materials[25].Material.FrontProperties.Diffuse.Alpha:=
         Mform.MenuImage.Materials[25].Material.FrontProperties.Diffuse.Alpha+0.005;
         Gamer.MyBlood.Visible:=true;
         Gamer.MyBlood.Material.LibMaterialName:='t0';   }
       end;

{if (Worked=true) and (Next<>'') then
ScrRead(0,Next);
end;}

Procedure WorkScr;
var
WI : integer;
begin
{  if Worked=true then
  for wi:=1 to KolSC do
      if  (ScriptCube[wi].Active=true)
      and (Gamer.Player.Position.x>ScriptCube[wi].PX-ScriptCube[wi].SX/2)
      and (Gamer.Player.Position.x<ScriptCube[wi].PX+ScriptCube[wi].SX/2)
      and (Gamer.Player.Position.Y<ScriptCube[wi].PY+ScriptCube[wi].SY/2)
      and (Gamer.Player.Position.Y>ScriptCube[wi].PY-ScriptCube[wi].SY/2)
      and (Gamer.Player.Position.Z-1<ScriptCube[wi].PZ+ScriptCube[wi].SZ)
      and (Gamer.Player.Position.Z-1>ScriptCube[wi].PZ-ScriptCube[wi].SZ)
      then ScrRead(wi,ScriptCube[wi].Script);
  if Worked=false then ScrV; }
end;

end.
