Core.Object | +--Engine.Actor | +--Engine.Controller | +--Engine.AIController | +--XIIIMP.XIIIMPDuckController
int
BeginJump
SlowMoveSpeed,
BoostMoveSpeed
rotator
InitialRotationRate
MaxChange,NbChange
Array
NavPointList
,
PathIndex
NavigationPoint
PointToDodge
vector
ReInitPoint
FullPath,
SuperBoost
GoPoint,
TeleportPoint
PathCache[16],
UpActor
UpPoint
void
Damaged(Pawn Other)
//__________________________________________________________________
ResetAllbSpecialCost()
TeleportTheDuck()
FindNearestNavPoint()
bool
CheckPath()
//--------------------------------------------------------------
NavPathStorage(NavigationPoint NavPoint)
GetRandomLocation()
GetAllNavPoint()
00001 //----------------------------------------------------------- 00002 // 00003 //----------------------------------------------------------- 00004 class XIIIMPDuckController extends AIController; 00005 00006 #exec OBJ LOAD FILE=XIIISound.uax PACKAGE=XIIISound 00007 00008 var float MoveSpeed,FastMoveSpeed, SlowMoveSpeed, BoostMoveSpeed; 00009 var Array<NavigationPoint> NavPointList; 00010 var NavigationPoint GoPoint, TeleportPoint; 00011 var Actor PathCache[16], UpActor; 00012 var int PathCacheSize , PathIndex; 00013 var bool FullPath, SuperBoost; 00014 var vector ReInitPoint; 00015 var int MaxChange,NbChange; 00016 var vector UpPoint; 00017 var rotator InitialRotationRate; 00018 var NavigationPoint PointToDodge; 00019 var int BeginJump; 00020 00021 00022 00023 //__________________________________________________________________ 00024 00025 event bool NotifyBump(Actor Other) 00026 { 00027 if( ( Pawn(Other) != none ) && ( ! Pawn(Other).bIsDead ) ) 00028 { 00029 // ----------- Lauch Sound for the Death --------------------- 00030 // 2:pawn.playsound(Sound'XIIIsound.Multi__SFXMulti.SFXMulti__hHuntKill'); 00031 TheDuck(Pawn).soundcounter2++; 00032 if( TheDuck(Pawn).soundcounter2 == 255 ) 00033 TheDuck(Pawn).soundcounter2 =0; 00034 TheDuck(Pawn).PlaySoundOfTheDeath(); 00035 // ------------------------------------------------------------ 00036 00037 Pawn(Other).Controller.PlayerReplicationInfo.Score -= 10; 00038 Other.TakeDamage(1000, pawn, Location, vect(0,0,0), class'DT_KKK'); 00039 } 00040 } 00041 00042 //__________________________________________________________________ 00043 00044 function ResetAllbSpecialCost() 00045 { 00046 local int Loop, Index , Test; 00047 local NavigationPoint NavPt, LastPoint; 00048 00049 for( Loop=0;Loop < NavPointList.Length ; Loop++ ) 00050 { 00051 NavPt = NavPointList[ Loop ]; 00052 NavPt.bSpecialCost=false; 00053 } 00054 } 00055 00056 //__________________________________________________________________ 00057 00058 function Damaged(Pawn Other) 00059 { 00060 if( IsInState('ReInitWithTeleport') ) 00061 return; 00062 00063 SuperBoost=true; 00064 SetTimer( 10.0 , false ); 00065 gotostate('GoRandom','FlagMove'); 00066 } 00067 00068 //__________________________________________________________________ 00069 00070 event Timer() 00071 { 00072 SuperBoost=false; 00073 gotostate('GoRandom','FlagMove'); 00074 } 00075 00076 //__________________________________________________________________ 00077 //__________________________________________________________________ 00078 // INIT 00079 //__________________________________________________________________ 00080 //__________________________________________________________________ 00081 00082 auto state init 00083 { 00084 event BeginState() 00085 { 00086 local TheDuck D; 00087 00088 if( Pawn == none ) 00089 { 00090 foreach DynamicActors(class'TheDuck', D) 00091 { 00092 Pawn = D; 00093 break; 00094 } 00095 } 00096 00097 GetAllNavPoint(); 00098 00099 Pawn.SetPhysics(Phys_Walking); 00100 Pawn.Velocity = vect(0,0,0); 00101 Pawn.Acceleration = vect(0,0,0); 00102 Pawn.LoopAnim('neutre'); 00103 } 00104 00105 //-------------------------------------------------------------- 00106 00107 function GetAllNavPoint() 00108 { 00109 local NavigationPoint Nav; 00110 00111 Nav = Level.NavigationPointList; 00112 00113 while( Nav != none) 00114 { 00115 if( ( CrouchPathNode(Nav) == none ) && ( InventorySpot(Nav) == none ) ) 00116 { 00117 if( JumpPathNode(Nav) == none ) 00118 { 00119 NavPointList.Length = NavPointList.Length+1; 00120 NavPointList[ NavPointList.Length-1 ] = Nav; 00121 } 00122 } 00123 00124 Nav.bSpecialCost=false; 00125 00126 Nav = Nav.NextNavigationPoint; 00127 } 00128 } 00129 //-------------------------------------------------------------- 00130 00131 begin: 00132 sleep(1.0); 00133 gotostate('ReInitWithTeleport'); 00134 } 00135 00136 //__________________________________________________________________ 00137 //__________________________________________________________________ 00138 // GoRandom 00139 //__________________________________________________________________ 00140 //__________________________________________________________________ 00141 00142 state GoRandom 00143 { 00144 event BeginState() 00145 { 00146 if( PointToDodge != none ) 00147 PointToDodge.bSpecialCost=false; 00148 00149 NbChange = 0; 00150 BeginJump = 0; 00151 SetTimer3(0.0,false); 00152 } 00153 00154 //-------------------------------------------------------------- 00155 00156 function GetRandomLocation() 00157 { 00158 local int Loop, Index , Test; 00159 local NavigationPoint NavPt, LastPoint; 00160 00161 LastPoint = GoPoint; 00162 GoPoint = none; 00163 Index = 0; 00164 00165 for( Loop=Rand(NavPointList.Length);Loop < NavPointList.Length ; Loop++ ) 00166 { 00167 NavPt = NavPointList[ Loop ]; 00168 00169 if( ( NavPt != LastPoint ) && ( NavPt != TeleportPoint ) ) 00170 { 00171 MoveTarget = FindPathToward( NavPt, True); 00172 00173 if( MoveTarget != none ) 00174 { 00175 GoPoint = NavPt; 00176 break; 00177 } 00178 else 00179 Test++; 00180 } 00181 00182 Index++; 00183 00184 if( Loop == NavPointList.Length-1 ) 00185 Loop =0; 00186 00187 if( Index > NavPointList.Length ) 00188 break; 00189 } 00190 } 00191 00192 //-------------------------------------------------------------- 00193 00194 function NavPathStorage( NavigationPoint NavPoint ) 00195 { 00196 local int Loop; 00197 00198 if (pawn==none || pawn.bIsDead) 00199 { 00200 FullPath=true; //FRD to exit loop in states 00201 return; 00202 } 00203 if( PointToDodge != none ) 00204 { 00205 PointToDodge = none; 00206 PointToDodge.bSpecialCost=false; 00207 } 00208 if (Vsize(NavPoint.location-pawn.location)<400 && ActorReachable(NavPoint)) 00209 {//FRD in order to test direct and near path 00210 log("actorreachable j'y vais direct au navpoint"); 00211 movetarget=NavPoint; 00212 PathCacheSize = 1; 00213 PathCache[ 0 ] = NavPoint; 00214 FullPath=true; 00215 return; 00216 } 00217 MoveTarget = FindPathToward( NavPoint, True); 00218 00219 PathCacheSize = 0; 00220 00221 for( Loop=0;Loop<16;Loop++) 00222 { 00223 if( RouteCache[ Loop ] == none ) 00224 break; 00225 00226 PathCache[ Loop ] = RouteCache[ Loop ]; 00227 PathCacheSize++; 00228 } 00229 00230 FullPath = ( NavigationPoint(PathCache[ PathCacheSize-1 ]) == NavPoint ); 00231 } 00232 00233 //-------------------------------------------------------------- 00234 00235 function bool CheckPath() 00236 { 00237 local vector HitLocation; 00238 local vector HitNormal; 00239 00240 UpActor=Trace( HitLocation,HitNormal,MoveTarget.Location,Pawn.Location, true); 00241 00242 if( UpActor == none ) 00243 return true; 00244 else 00245 return false; 00246 } 00247 00248 //-------------------------------------------------------------- 00249 00250 event Timer3() 00251 { 00252 if( ! CheckPath() ) 00253 { 00254 if( NbChange < 2 ) 00255 { 00256 if( PointToDodge != none ) 00257 PointToDodge.bSpecialCost=false; 00258 00259 PointToDodge = NavigationPoint( MoveTarget ); 00260 PointToDodge.bSpecialCost=true; 00261 NbChange++; 00262 Gotostate('GoRandom','Begin'); 00263 } 00264 else 00265 Gotostate('Fight','Begin'); 00266 } 00267 } 00268 00269 //-------------------------------------------------------------- 00270 00271 event SeePlayer( Pawn Seen ) 00272 { 00273 if( Enemy == none ) 00274 { 00275 Enemy = Seen; 00276 SetTimer2( 10.0,false ); 00277 gotostate('GoRandom','FlagMove'); 00278 } 00279 } 00280 00281 //-------------------------------------------------------------- 00282 00283 event Timer2() 00284 { 00285 Enemy = none; 00286 SetTimer2( 0.0,false ); 00287 gotostate('GoRandom','FlagMove'); 00288 } 00289 00290 //-------------------------------------------------------------- 00291 00292 begin: 00293 00294 while( Pawn.Physics == PHYS_Falling ) 00295 sleep( 0.1 ); 00296 00297 SetTimer3(0.5,true); 00298 00299 GetRandomLocation(); 00300 00301 if( GoPoint == none ) 00302 { 00303 GotoState('DoNothing'); 00304 } 00305 else 00306 { 00307 while( true ) 00308 { 00309 NavPathStorage(GoPoint); 00310 00311 for( PathIndex = 0; PathIndex < PathCacheSize ; PathIndex ++ ) 00312 { 00313 MoveTarget = PathCache[ PathIndex ]; 00314 Focus=MoveTarget; 00315 00316 FlagMove: 00317 if( SuperBoost ) 00318 { 00319 TheDuck(Pawn).ChangeLoopAnimation( 0 ); 00320 MoveSpeed = BoostMoveSpeed; 00321 } 00322 else 00323 { 00324 if( Enemy != none ) 00325 { 00326 TheDuck(Pawn).ChangeLoopAnimation( 1 ); 00327 MoveSpeed = FastMoveSpeed; 00328 } 00329 else 00330 { 00331 TheDuck(Pawn).ChangeLoopAnimation( 2 ); 00332 MoveSpeed = SlowMoveSpeed; 00333 } 00334 } 00335 00336 if( CrouchPathNode(MoveTarget) != none ) 00337 { 00338 BeginJump++; 00339 00340 if( BeginJump < 5 ) 00341 Goto('begin'); 00342 else 00343 { 00344 BeginJump = 0; 00345 gotostate('ReInitWithTeleport'); 00346 } 00347 } 00348 00349 if( JumpPathNode(MoveTarget) != none ) 00350 { 00351 if( PathIndex < PathCacheSize -1 ) 00352 if( MoveTarget.Location.Z < PathCache[ PathIndex +1 ].Location.Z ) 00353 { 00354 BeginJump++; 00355 00356 if( BeginJump < 5 ) 00357 Goto('begin'); 00358 else 00359 { 00360 BeginJump = 0; 00361 gotostate('ReInitWithTeleport'); 00362 } 00363 } 00364 } 00365 00366 MoveToward( MoveTarget, Focus , MoveSpeed ); 00367 00368 NbChange = 0; 00369 BeginJump = 0; 00370 } 00371 00372 if( FullPath ) 00373 break; 00374 } 00375 00376 Goto('begin'); 00377 } 00378 } 00379 00380 //__________________________________________________________________ 00381 //__________________________________________________________________ 00382 // DoNothing 00383 //__________________________________________________________________ 00384 //__________________________________________________________________ 00385 00386 state DoNothing 00387 { 00388 event BeginState() 00389 { 00390 TheDuck(Pawn).ChangeLoopAnimation(3); 00391 Pawn.Velocity = vect(0,0,0); 00392 Pawn.Acceleration = vect(0,0,0); 00393 } 00394 00395 begin: 00396 pawn.setphysics(Phys_falling); 00397 Waitforlanding(); 00398 Sleep(0.5); 00399 Spawn(class'SpawnEmitter',,, Location); 00400 GotoState('ReInitWithTeleport'); 00401 } 00402 00403 //__________________________________________________________________ 00404 //__________________________________________________________________ 00405 // Fight 00406 //__________________________________________________________________ 00407 //__________________________________________________________________ 00408 00409 state Fight 00410 { 00411 event BeginState() 00412 { 00413 TheDuck(Pawn).ChangeLoopAnimation(4); 00414 Pawn.Velocity = vect(0,0,0); 00415 Pawn.Acceleration = vect(0,0,0); 00416 } 00417 00418 begin: 00419 focus=UpActor; 00420 SetRotation( rotator(UpActor.GetBoneCoords('X Head').Origin-Pawn.Location ) ); 00421 Sleep( 5.0 ); 00422 gotostate('GoRandom'); 00423 } 00424 00425 //__________________________________________________________________ 00426 //__________________________________________________________________ 00427 // Catched 00428 //__________________________________________________________________ 00429 //__________________________________________________________________ 00430 00431 state Catched 00432 { 00433 event BeginState() 00434 { 00435 Pawn.LoopAnim('Sol'); 00436 Pawn.Velocity = vect(0,0,0); 00437 Pawn.Acceleration = vect(0,0,0); 00438 Pawn.SetDrawType(DT_None); 00439 Pawn.SetCollision(False,False,False); 00440 } 00441 } 00442 00443 //__________________________________________________________________ 00444 //__________________________________________________________________ 00445 // ReInit 00446 //__________________________________________________________________ 00447 //__________________________________________________________________ 00448 00449 state ReInit 00450 { 00451 event BeginState() 00452 { 00453 Pawn.SetDrawType(DT_Mesh); 00454 ResetAllbSpecialCost(); 00455 } 00456 00457 function FindNearestNavPoint() 00458 { 00459 local int Loop; 00460 local NavigationPoint NearestPoint,TmpPoint; 00461 local float BestDist,TmpDist; 00462 00463 NearestPoint = NavPointList[0]; 00464 BestDist = VSize( NearestPoint.Location - ReInitPoint ); 00465 00466 for( Loop=0;Loop < NavPointList.Length ; Loop++ ) 00467 { 00468 TmpPoint = NavPointList[Loop]; 00469 00470 TmpDist = VSize( TmpPoint.Location - ReInitPoint ); 00471 00472 if( TmpDist < BestDist ) 00473 { 00474 BestDist = TmpDist; 00475 NearestPoint = TmpPoint; 00476 } 00477 } 00478 00479 // log("ReInit --> Teleport at"@NearestPoint); 00480 // log(""); 00481 00482 Pawn.SetLocation( NearestPoint.Location ); 00483 Spawn(class'SpawnEmitter',,, NearestPoint.Location); 00484 } 00485 00486 begin: 00487 00488 FindNearestNavPoint(); 00489 Damaged(none); 00490 gotostate('GoRandom'); 00491 } 00492 00493 //__________________________________________________________________ 00494 //__________________________________________________________________ 00495 // ReInitWithTeleport 00496 //__________________________________________________________________ 00497 //__________________________________________________________________ 00498 00499 state ReInitWithTeleport 00500 { 00501 event BeginState() 00502 { 00503 TheDuck(Pawn).FullDamage = 0; 00504 Pawn.SetDrawType(DT_Mesh); 00505 Pawn.SetCollision(true,true,true); 00506 ResetAllbSpecialCost(); 00507 } 00508 00509 function TeleportTheDuck() 00510 { 00511 local int RandID; 00512 00513 RandID = Rand(NavPointList.Length); 00514 00515 TeleportPoint = NavPointList[ RandID ]; 00516 00517 // log("ReInitWithTeleport --> Teleport at"@TeleportPoint@RandID@"/"@NavPointList.Length); 00518 // log(""); 00519 00520 Pawn.SetLocation( TeleportPoint.Location ); 00521 Spawn(class'SpawnEmitter',,, TeleportPoint.Location); 00522 } 00523 00524 begin: 00525 // ----------- Lauch Sound for the Death --------------------- 00526 // 3: Pawn.PlaySound(Sound'XIIIsound.Multi__SFXMulti.SFXMulti__hHuntLoop'); 00527 TheDuck(Pawn).soundcounter3++; 00528 if( TheDuck(Pawn).soundcounter3 == 255 ) 00529 TheDuck(Pawn).soundcounter3 =0; 00530 TheDuck(Pawn).PlaySoundOfTheDeath(); 00531 // ------------------------------------------------------------ 00532 00533 TeleportTheDuck(); 00534 gotostate('GoRandom'); 00535 } 00536 00537 //__________________________________________________________________ 00538 //__________________________________________________________________ 00539 // GameEnded 00540 //__________________________________________________________________ 00541 //__________________________________________________________________ 00542 00543 state GameEnded 00544 { 00545 event BeginState() 00546 { 00547 Enemy = none; 00548 00549 Pawn.velocity=vect(0,0,0); 00550 Pawn.acceleration=vect(0,0,0); 00551 00552 SetTimer(0.0,false); 00553 SetTimer2(0.0,false); 00554 SetTimer3(0.0,false); 00555 00556 // ----------- Lauch Sound for the Death --------------------- 00557 // 4 :pawn.PlaySound(Sound'XIIIsound.Multi__SFXMulti.SFXMulti__hHuntStopLoop'); 00558 TheDuck(Pawn).soundcounter4++; 00559 if( TheDuck(Pawn).soundcounter4 == 255 ) 00560 TheDuck(Pawn).soundcounter4 =0; 00561 TheDuck(Pawn).PlaySoundOfTheDeath(); 00562 // ------------------------------------------------------------ 00563 00564 TheDuck(Pawn).ChangeLoopAnimation( 3 ); 00565 } 00566 00567 event SeePlayer( Pawn Seen ); 00568 00569 event Timer(); 00570 event Timer2(); 00571 event Timer3(); 00572 } 00573 00574 //__________________________________________________________________ 00575 00576 00577 00578 defaultproperties 00579 { 00580 FastMoveSpeed=0.350000 00581 SlowMoveSpeed=0.100000 00582 BoostMoveSpeed=0.680000 00583 MaxChange=3 00584 }