home *** CD-ROM | disk | FTP | other *** search
- class VanAi
- {
- var nom = new String();
- var etat = new String();
- var oldEtat = new String();
- var goTo = new String();
- var van = new Object();
- var nbSecBefRespawn = new Number();
- var secPassedBefRespawn = new Number();
- var paused = new Boolean();
- var nbFrPlayerSeen = new Number();
- var frMaxPlayerSeen = new Number();
- function VanAi(l_nom, l_van)
- {
- this.nom = l_nom;
- this.etat = "PasLa";
- this.oldEtat = this.etat;
- this.van = l_van;
- this.paused = false;
- this.nbSecBefRespawn = 30;
- this.secPassedBefRespawn = 0;
- this.nbFrPlayerSeen = 0;
- }
- function PasLa()
- {
- }
- function CheckAiGoTo()
- {
- var _loc4_ = this.van.GetStageCoord();
- var _loc3_ = _global.C[this.goTo].GetStageCoord();
- var _loc6_ = Math.abs(_loc3_.x - _loc4_.x);
- var _loc5_ = Math.abs(_loc3_.y - _loc4_.y);
- if(_loc6_ < 60 && _loc5_ < 60)
- {
- this.goTo = _global.C[this.goTo].GetNextGoTo();
- this.UpdateTrajectory();
- }
- }
- function EnterFrame()
- {
- if(!this.paused)
- {
- this[this.etat]();
- }
- }
- function Explode()
- {
- this.van.SetState("Exploding");
- this.van.SetStateLocked();
- this.SetState("WaitingVanReborn");
- }
- function FindRespawnSpot()
- {
- var _loc7_ = _global.C.G_respawnSpot.length;
- var _loc6_ = _global.C[_global.C.G_vehPers].GetStageCoord();
- var _loc4_ = new Number();
- var _loc5_ = new Object();
- _loc5_.dist = 999999;
- var _loc3_ = 0;
- while(_loc3_ < _loc7_)
- {
- _loc4_ = _global.C[_global.C.G_respawnSpot[_loc3_]].GetAbsDistWithObj(_loc6_);
- if(_loc4_ < _loc5_.dist && _loc4_ > 500)
- {
- _loc5_.dist = _loc4_;
- _loc5_.nom = _global.C[_global.C.G_respawnSpot[_loc3_]].GetName();
- }
- _loc3_ = _loc3_ + 1;
- }
- _loc6_ = _global.C[_loc5_.nom].GetStageCoord();
- this.van.TeleportTo(_loc6_);
- this.goTo = _global.C[_loc5_.nom].GetNextGoTo();
- this.SetState("Moving");
- }
- function GetName()
- {
- return this.nom;
- }
- function GetState()
- {
- return this.etat;
- }
- function Moving()
- {
- this.CheckAiGoTo();
- this.UpdateTrajectory();
- this.van.SetState("MoveForw");
- this.nbFrPlayerSeen = this.nbFrPlayerSeen + 1;
- if(_global.C.utils.GetAbsDistBetweenObj(this.van,_global.C[_global.C.G_vehPers]) < 600)
- {
- this.nbFrPlayerSeen = 0;
- }
- else if(this.nbFrPlayerSeen >= this.frMaxPlayerSeen)
- {
- if(_global.C[_global.C.G_package].GetAttachedTo() == this.van.GetName())
- {
- this.nbFrPlayerSeen = 0;
- }
- else
- {
- this.nbFrPlayerSeen = 0;
- this.SetState("WaitForRespawn");
- }
- }
- }
- function Pause()
- {
- this.paused = true;
- }
- function SetMaxFrPlayerSeen(l_newVal)
- {
- if(l_newVal > 0)
- {
- this.frMaxPlayerSeen = l_newVal;
- }
- }
- function SetState(l_newState)
- {
- if(l_newState != undefined && l_newState != this.etat)
- {
- this.oldEtat = this.etat;
- this.etat = l_newState;
- }
- }
- function UnPause()
- {
- this.paused = false;
- }
- function UpdateTrajectory()
- {
- var _loc4_ = _global.C[this.goTo].GetStageCoord();
- var _loc7_ = this.van.GetOrientationRefStageCoord();
- var _loc8_ = this.van.GetStageCoord();
- var _loc3_ = Math.atan2(_loc4_.y - _loc8_.y,_loc4_.x - _loc8_.x);
- var _loc6_ = Math.atan2(_loc4_.y - _loc7_.y,_loc4_.x - _loc7_.x);
- _loc6_ = Math.round(_loc6_ * 180 / 3.141592653589793);
- _loc3_ = Math.round(_loc3_ * 180 / 3.141592653589793);
- var _loc5_ = _loc3_ - _loc6_;
- _loc3_ += 90;
- if(_loc3_ >= 180 && _loc5_ < 0)
- {
- if(this.van.GetPropRotation() <= 0)
- {
- _loc3_ = - (360 - _loc3_);
- }
- }
- else if(_loc3_ >= 180 && _loc5_ > 0)
- {
- if(this.van.GetPropRotation() <= 0)
- {
- _loc3_ -= 360;
- }
- }
- if(_loc5_ > 0)
- {
- this.van.SetTrajectory("Left");
- this.van.SetTargetRotation(_loc3_);
- }
- else if(_loc5_ < 0)
- {
- this.van.SetTrajectory("Right");
- this.van.SetTargetRotation(_loc3_);
- }
- else
- {
- this.van.SetTrajectory(null);
- }
- }
- function WaitForRespawn()
- {
- this.nbSecBefRespawn = this.nbSecBefRespawn + 1;
- if(this.nbSecBefRespawn >= this.nbSecBefRespawn)
- {
- this.nbSecBefRespawn = 0;
- this.FindRespawnSpot();
- }
- }
- function WaitingVanReborn()
- {
- if(this.van.GetState() == "PasLa")
- {
- this.SetState("WaitForRespawn");
- }
- }
- }
-