Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 |
//===================================================================== // AI_Search //===================================================================== class AI_Search extends AI_MovementAction editinlinenew; //===================================================================== // Constants const SEARCH_DISTANCE1 = 1.0f; // what percentage of searchDistance you run in the direction of target when searching on first search const SEARCH_DISTANCE2 = 0.75f; const SEARCH_ROTATION1 = +1.1780972f; // 3/8 * PI: how far to turn for first search const SEARCH_ROTATION2 = -1.1780972f; //===================================================================== // Variables var(Parameters) float searchDistance "how far the AI moves when searching for something"; var(InternalParameters) editconst Pawn target; var(InternalParameters) editconst Character.GroundMovementLevels searchSpeed "how fast the AI moves while searching"; var BaseAICharacter ai; var ACT_ErrorCodes errorCode; // errorcode from child action var Actor node; // destination node var Vector orgLocation; // location of pawn when search started var Rotator orgRotation; // rotation of pawn when search started //===================================================================== // Functions //--------------------------------------------------------------------- // Callbacks from Navigation System actions function actionSucceededCB( NS_Action child ) { super.actionSucceededCB( child ); errorCode = ACT_SUCCESS; } function actionFailedCB( NS_Action child, ACT_ErrorCodes anErrorCode ) { super.actionFailedCB( child, anErrorCode ); errorCode = anErrorCode; } //--------------------------------------------------------------------- // get search destination private final function Vector getDestination( float searchDistance, float searchRotation ) { local Vector targetVector; local Vector dest; local Vector lastValidLocation; local array<Actor> ignore; if ( target != None ) targetVector = target.Location - ai.Location; else targetVector = ai.Location; targetVector *= searchDistance / VSize(targetVector); dest = rotateZ( targetVector, PI/4 * FRand() - PI/8 + searchRotation ) + ai.Location; AI_Controller(ai.controller).canPointBeReached( ai.Location, dest, ai, ignore, lastValidLocation ); return lastValidLocation; } //--------------------------------------------------------------------- function cleanup() { super.cleanup(); if ( class'Pawn'.static.checkAlive( resource.pawn() ) ) AI_Controller(resource.pawn().controller).stopMove(); } //===================================================================== // State code state Running { Begin: ai = baseAICharacter(); if ( ai.logTyrion ) log( name @ "started." @ ai.name @ "is searching for" @ target.name @ "( searchDistance:" @ searchDistance @ ")" ); orgLocation = ai.Location; orgRotation = ai.Rotation; // run to place in the approximate direction of the enemy, look around a bit waitForAction( class'NS_MoveToLocation'.static.startAction( AI_Controller(ai.controller), self, getDestination( SEARCH_DISTANCE1 * searchDistance, SEARCH_ROTATION1 ), None,,, searchSpeed, )); if ( errorCode != ACT_SUCCESS ) fail( errorCode ); // wait till movement has stopped while ( !isZero( ai.Velocity )) yield(); ai.PlayAnimation( "AI_Searching" ); Sleep(2.0); //ai.FinishAnim(); if ( class'Pawn'.static.checkDead( ai ) ) fail( ACT_ALL_RESOURCES_DIED ); // run to another place waitForAction( class'NS_MoveToLocation'.static.startAction( AI_Controller(ai.controller), self, getDestination( SEARCH_DISTANCE2 * searchDistance, SEARCH_ROTATION2 ), None,,, searchSpeed, )); // wait till movement has stopped while ( !isZero( ai.Velocity )) yield(); ai.PlayAnimation( "AI_Searching" ); Sleep(2.0); //ai.FinishAnim(); if ( class'Pawn'.static.checkDead( ai ) ) fail( ACT_ALL_RESOURCES_DIED ); // return back to where you started waitForAction( class'NS_MoveToLocation'.static.startAction( AI_Controller(ai.controller), self, orgLocation, None,,, searchSpeed, )); // face the way you were originally facing waitForAction( class'NS_Turn'.static.startAction( AI_Controller(ai.controller), self, orgRotation )); if ( ai.logTyrion ) log( name @ "stopped." ); succeed(); } //===================================================================== defaultproperties { satisfiesGoal = class'AI_SearchGoal' searchDistance = 600 } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |