home *** CD-ROM | disk | FTP | other *** search
/ One Click 21 (Special) / OC021.iso / Juegos / 05-11-10-1.swf / scripts / __Packages / VanAi.as < prev    next >
Encoding:
Text File  |  2005-11-18  |  4.9 KB  |  186 lines

  1. class VanAi
  2. {
  3.    var nom = new String();
  4.    var etat = new String();
  5.    var oldEtat = new String();
  6.    var goTo = new String();
  7.    var van = new Object();
  8.    var nbSecBefRespawn = new Number();
  9.    var secPassedBefRespawn = new Number();
  10.    var paused = new Boolean();
  11.    var nbFrPlayerSeen = new Number();
  12.    var frMaxPlayerSeen = new Number();
  13.    function VanAi(l_nom, l_van)
  14.    {
  15.       this.nom = l_nom;
  16.       this.etat = "PasLa";
  17.       this.oldEtat = this.etat;
  18.       this.van = l_van;
  19.       this.paused = false;
  20.       this.nbSecBefRespawn = 30;
  21.       this.secPassedBefRespawn = 0;
  22.       this.nbFrPlayerSeen = 0;
  23.    }
  24.    function PasLa()
  25.    {
  26.    }
  27.    function CheckAiGoTo()
  28.    {
  29.       var _loc4_ = this.van.GetStageCoord();
  30.       var _loc3_ = _global.C[this.goTo].GetStageCoord();
  31.       var _loc6_ = Math.abs(_loc3_.x - _loc4_.x);
  32.       var _loc5_ = Math.abs(_loc3_.y - _loc4_.y);
  33.       if(_loc6_ < 60 && _loc5_ < 60)
  34.       {
  35.          this.goTo = _global.C[this.goTo].GetNextGoTo();
  36.          this.UpdateTrajectory();
  37.       }
  38.    }
  39.    function EnterFrame()
  40.    {
  41.       if(!this.paused)
  42.       {
  43.          this[this.etat]();
  44.       }
  45.    }
  46.    function Explode()
  47.    {
  48.       this.van.SetState("Exploding");
  49.       this.van.SetStateLocked();
  50.       this.SetState("WaitingVanReborn");
  51.    }
  52.    function FindRespawnSpot()
  53.    {
  54.       var _loc7_ = _global.C.G_respawnSpot.length;
  55.       var _loc6_ = _global.C[_global.C.G_vehPers].GetStageCoord();
  56.       var _loc4_ = new Number();
  57.       var _loc5_ = new Object();
  58.       _loc5_.dist = 999999;
  59.       var _loc3_ = 0;
  60.       while(_loc3_ < _loc7_)
  61.       {
  62.          _loc4_ = _global.C[_global.C.G_respawnSpot[_loc3_]].GetAbsDistWithObj(_loc6_);
  63.          if(_loc4_ < _loc5_.dist && _loc4_ > 500)
  64.          {
  65.             _loc5_.dist = _loc4_;
  66.             _loc5_.nom = _global.C[_global.C.G_respawnSpot[_loc3_]].GetName();
  67.          }
  68.          _loc3_ = _loc3_ + 1;
  69.       }
  70.       _loc6_ = _global.C[_loc5_.nom].GetStageCoord();
  71.       this.van.TeleportTo(_loc6_);
  72.       this.goTo = _global.C[_loc5_.nom].GetNextGoTo();
  73.       this.SetState("Moving");
  74.    }
  75.    function GetName()
  76.    {
  77.       return this.nom;
  78.    }
  79.    function GetState()
  80.    {
  81.       return this.etat;
  82.    }
  83.    function Moving()
  84.    {
  85.       this.CheckAiGoTo();
  86.       this.UpdateTrajectory();
  87.       this.van.SetState("MoveForw");
  88.       this.nbFrPlayerSeen = this.nbFrPlayerSeen + 1;
  89.       if(_global.C.utils.GetAbsDistBetweenObj(this.van,_global.C[_global.C.G_vehPers]) < 600)
  90.       {
  91.          this.nbFrPlayerSeen = 0;
  92.       }
  93.       else if(this.nbFrPlayerSeen >= this.frMaxPlayerSeen)
  94.       {
  95.          if(_global.C[_global.C.G_package].GetAttachedTo() == this.van.GetName())
  96.          {
  97.             this.nbFrPlayerSeen = 0;
  98.          }
  99.          else
  100.          {
  101.             this.nbFrPlayerSeen = 0;
  102.             this.SetState("WaitForRespawn");
  103.          }
  104.       }
  105.    }
  106.    function Pause()
  107.    {
  108.       this.paused = true;
  109.    }
  110.    function SetMaxFrPlayerSeen(l_newVal)
  111.    {
  112.       if(l_newVal > 0)
  113.       {
  114.          this.frMaxPlayerSeen = l_newVal;
  115.       }
  116.    }
  117.    function SetState(l_newState)
  118.    {
  119.       if(l_newState != undefined && l_newState != this.etat)
  120.       {
  121.          this.oldEtat = this.etat;
  122.          this.etat = l_newState;
  123.       }
  124.    }
  125.    function UnPause()
  126.    {
  127.       this.paused = false;
  128.    }
  129.    function UpdateTrajectory()
  130.    {
  131.       var _loc4_ = _global.C[this.goTo].GetStageCoord();
  132.       var _loc7_ = this.van.GetOrientationRefStageCoord();
  133.       var _loc8_ = this.van.GetStageCoord();
  134.       var _loc3_ = Math.atan2(_loc4_.y - _loc8_.y,_loc4_.x - _loc8_.x);
  135.       var _loc6_ = Math.atan2(_loc4_.y - _loc7_.y,_loc4_.x - _loc7_.x);
  136.       _loc6_ = Math.round(_loc6_ * 180 / 3.141592653589793);
  137.       _loc3_ = Math.round(_loc3_ * 180 / 3.141592653589793);
  138.       var _loc5_ = _loc3_ - _loc6_;
  139.       _loc3_ += 90;
  140.       if(_loc3_ >= 180 && _loc5_ < 0)
  141.       {
  142.          if(this.van.GetPropRotation() <= 0)
  143.          {
  144.             _loc3_ = - (360 - _loc3_);
  145.          }
  146.       }
  147.       else if(_loc3_ >= 180 && _loc5_ > 0)
  148.       {
  149.          if(this.van.GetPropRotation() <= 0)
  150.          {
  151.             _loc3_ -= 360;
  152.          }
  153.       }
  154.       if(_loc5_ > 0)
  155.       {
  156.          this.van.SetTrajectory("Left");
  157.          this.van.SetTargetRotation(_loc3_);
  158.       }
  159.       else if(_loc5_ < 0)
  160.       {
  161.          this.van.SetTrajectory("Right");
  162.          this.van.SetTargetRotation(_loc3_);
  163.       }
  164.       else
  165.       {
  166.          this.van.SetTrajectory(null);
  167.       }
  168.    }
  169.    function WaitForRespawn()
  170.    {
  171.       this.nbSecBefRespawn = this.nbSecBefRespawn + 1;
  172.       if(this.nbSecBefRespawn >= this.nbSecBefRespawn)
  173.       {
  174.          this.nbSecBefRespawn = 0;
  175.          this.FindRespawnSpot();
  176.       }
  177.    }
  178.    function WaitingVanReborn()
  179.    {
  180.       if(this.van.GetState() == "PasLa")
  181.       {
  182.          this.SetState("WaitForRespawn");
  183.       }
  184.    }
  185. }
  186.