Core.Object | +--Engine.Actor | +--Engine.Keypoint | +--XIDPawn.GenFRD | +--XIDPawn.Patrouille
float
AncienDelai
IAController
Cont1,Cont2
DistEntreChemins
XIIIGameInfo
GI
Actor
LastWP
int
NbRecul
name
PersoName1,PersoName2
i
BaseSoldier
perso1,perso2,perso
void
Timer()
00001 //============================================================================= 00002 // Patrouille. 00003 //============================================================================= 00004 class Patrouille extends GenFRD; 00005 00006 var basesoldier perso1,perso2,perso; 00007 var() name PersoName1,PersoName2; 00008 var int NbRecul; 00009 var float DistEntreChemins; 00010 var IAController Cont1,Cont2; //2 controllers 00011 var float AncienDelai; 00012 var actor LastWP; 00013 var int i; 00014 var Xiiigameinfo GI; 00015 00016 00017 00018 00019 //============================================================================= 00020 // Patrouille ||. 00021 //============================================================================= 00022 Auto state patrouille 00023 { 00024 function Timer() 00025 { 00026 local vector direct; 00027 local vector distance; 00028 local float delai; 00029 00030 00031 if ((perso1==none)||(perso2==none)||(Cont1.DestNavPoint==none)||(Cont2.DestNavPoint==none)||(perso1.health<=0)||(perso2.health<=0)) 00032 { 00033 gotostate('fin'); 00034 return; 00035 } 00036 Cont1=IAController(perso1.controller); 00037 Cont2=IAController(perso2.controller); 00038 //si repassse devant alors annule delais 00039 if ((perso==perso1)&&((vector(perso1.rotation) dot (perso2.location-perso1.location))>0)) 00040 { 00041 log("retabli ancien delai 1"); 00042 patrolpoint(Cont1.DestNavPoint).pausetime=Anciendelai; 00043 NbRecul=0; 00044 LAstWP=none; 00045 perso=none; 00046 if (Cont1.sleeptime!=0) 00047 Cont1.gotostate('patrouille','patrol'); 00048 } 00049 else if ((perso==perso2)&&((vector(perso2.rotation) dot (perso1.location-perso2.location))>0)) 00050 { 00051 log("retabli ancien delai 2"); 00052 patrolpoint(Cont2.DestNavPoint).pausetime=Anciendelai; 00053 NbRecul=0; 00054 LAstWP=none; 00055 perso=none; 00056 if (Cont2.sleeptime!=0) 00057 Cont2.gotostate('patrouille','patrol'); 00058 } 00059 if ((LastWP==none) || ((perso!=none)&&(LastWP!=IACOntroller (perso.controller).DestNavPoint))) 00060 { 00061 distance=perso1.location-perso2.location; 00062 if (sqrt(square(Vsize(distance))-DistEntreChemins)>396) 00063 { 00064 log(" **************** trop loin ***************"); 00065 // Qui est devant? 00066 if (Cont1.Isinstate('patrouille')&&(Cont1.LastPatrolPoint!=none)&&(Cont1.DestNavPoint!=none)) 00067 { 00068 direct=(Cont1.DestNavPoint.location - Cont1.LastPatrolPoint.location); 00069 } 00070 else if (Cont2.Isinstate('patrouille')&&(Cont2.LastPatrolPoint!=none)&&(Cont2.DestNavPoint!=none)) 00071 { 00072 direct=(Cont2.DestNavPoint.location - Cont2.LastPatrolPoint.location); 00073 } 00074 if (direct dot (distance)>0) 00075 { 00076 log("perso1 devant"); 00077 if (perso==perso2) 00078 NbRecul=0; 00079 perso=perso1; 00080 } 00081 else 00082 { 00083 if (direct dot (distance)==0) 00084 { 00085 log("pas de delai"); 00086 return; 00087 } 00088 else 00089 { 00090 log("perso2 devant"); 00091 if (perso==perso2) 00092 NbRecul=0; 00093 perso=perso2; 00094 } 00095 } 00096 00097 00098 if (perso==perso1) 00099 { 00100 delai=Vsize(distance)/(perso2.groundSpeed*perso2.walkingspeed); 00101 if ((Cont2.Isinstate('chasse')) || (Cont2.Isinstate('temporise'))|| (Cont2.Isinstate('Vavers'))) 00102 { 00103 log("1 rallonge le delai"); 00104 delai+=12+4*Frand(); 00105 } 00106 else if (!Cont2.Isinstate('patrouille')) 00107 delai+=6+4*Frand(); 00108 } 00109 else 00110 { 00111 delai=Vsize(distance)/(perso1.groundSpeed*perso1.walkingspeed); 00112 if ((Cont1.Isinstate('chasse')) || (Cont1.Isinstate('temporise'))|| (Cont1.Isinstate('Vavers'))) 00113 { 00114 log("2 rallonge le delai"); 00115 delai+=12+4*Frand(); 00116 } 00117 else if (!Cont1.Isinstate('patrouille')) 00118 delai+=6+4*Frand(); 00119 } 00120 log("effectue delai"$delai); 00121 Cont1=IAcontroller(perso.controller); //reutil de cont1 00122 Anciendelai=patrolpoint(Cont1.DestNavPoint).pausetime; 00123 patrolpoint(Cont1.DestNavPoint).pausetime += delai; 00124 LastWP=Cont1.DestNavPoint; 00125 NbRecul++; 00126 if (NbRecul>1) 00127 gotostate('fin'); 00128 } 00129 else 00130 NbRecul=0; 00131 } 00132 } 00133 00134 begin: 00135 00136 init: 00137 sleep(2); 00138 GI=XIIIGameInfo(level.game); 00139 For(i=0;i<GI.BaseSoldierList.Length;i++) 00140 { 00141 perso=basesoldier(GI.BaseSoldierList[i]); 00142 if (!perso.bisdead && !perso.controller.isinstate('faction')) 00143 { 00144 if (perso.name==PersoName1) 00145 perso1=perso; 00146 else if (perso.name==PersoName2) 00147 perso2=perso; 00148 } 00149 } 00150 if ((perso1==none) || (perso2==none)) 00151 { 00152 log(" *** pas trouve persos de patrouille **** "); 00153 gotostate('fin'); 00154 } 00155 Cont1=IAController(perso1.controller); 00156 Cont2=IAController(perso2.controller); 00157 if ((Cont1.DestNavPoint!=none) && (Cont2.DestNavPoint!=none)) 00158 DistEntreChemins= square(VSize(Cont1.DestNavPoint.location-Cont2.DestNavPoint.location)); 00159 else 00160 DistEntreChemins=square(236); 00161 NbRecul=0; 00162 perso=none; 00163 LAstWP=none; 00164 setTimer(2,true); 00165 retard: 00166 00167 } 00168 00169 00170 //============================================================================= 00171 // FIN 00172 //============================================================================= 00173 state Fin 00174 { 00175 00176 begin: 00177 log(self$"fin"); 00178 } 00179 00180 00181 00182 defaultproperties 00183 { 00184 bDirectional=True 00185 }