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 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 |
//===================================================================== // AI_SquadMoveTo // Moves a squad to an arbitrary location on the map using walking/jetting/skiing //===================================================================== class AI_SquadMoveTo extends AI_SquadAction implements IBooleanGoalCondition editinlinenew; //===================================================================== // Constants //===================================================================== // Variables var(Parameters) editinline Name destinationName "A path node label"; var(Parameters) float formationDiameter "What's the approximate diameter of the formation?"; var(Parameters) Character.SkiCompetencyLevels skiCompetency; var(Parameters) Character.JetCompetencyLevels jetCompetency; var(Parameters) Character.GroundMovementLevels groundMovement; var(Parameters) float terminalDistanceXY; var(Parameters) float terminalDistanceZ; var(Parameters) float energyUsage; var(Parameters) float terminalVelocity; var(Parameters) float terminalHeight; var(InternalParameters) editconst Vector destination; var Actor node; var Pawn pawn; var int i; var Pawn leader; // leader pawn var int leaderIndex; // index of leader in pawn array (always last living pawn) var int nFollowers; // number of living followers var AI_Goal moveGoal; // leader's goal var AI_Goal squadFollowGoal; // squad goal for all the rest //===================================================================== // Functions //--------------------------------------------------------------------- // callback from child action function goalNotAchievedCB( AI_Goal goal, AI_Action child, ACT_ErrorCodes errorCode ) { super.goalNotAchievedCB( goal, child, errorCode ); if ( (errorCode == ACT_ALL_RESOURCES_DIED || errorCode == ACT_RESOURCE_INACTIVE) && goal.isA('AI_SquadFollowGoal') ) { goal.unpostGoal( self ); if ( squad().logTyrion ) log( name @ "unposting" @ goal.name @ "(all resources died)" ); } if ( goal.isA( 'AI_MoveToGoal' )) { goal.unpostGoal( self ); if ( squad().logTyrion ) log( name @ "unposting" @ goal.name @ "(goal failed)" ); } } //--------------------------------------------------------------------- // function to interrupt (slow down) leader if need be static function bool goalTest( AI_Goal goal ) { return followersTooFarAway( AI_SquadMoveTo(goal.parentAction) ); } //--------------------------------------------------------------------- static function bool followersTooFarAway( AI_SquadMoveTo action ) { local int i; local Pawn pawn; for ( i = 0; i < action.leaderIndex; i++ ) { pawn = action.squad().pawns[i]; if ( class'Pawn'.static.checkAlive( pawn ) && VDistSquared( action.leader.Location, pawn.Location ) > 4 * action.formationDiameter * action.formationDiameter ) { // log( action.name $ ": followers too far away!" ); return true; } } return false; } //--------------------------------------------------------------------- function cleanup() { super.cleanup(); if ( moveGoal != None ) { moveGoal.Release(); moveGoal = None; } if ( squadFollowGoal != None ) { squadFollowGoal.Release(); squadFollowGoal = None; } } //===================================================================== // State code // // Idea: have the leader execute the move, have the others follow him with a special version of follow that contains a desired position offset // The offset will be updated (here or in local actions?) to take account of varying terain, doors, etc. // In addition, AI's should have an action that coordinates them getting through doors (probably part of LOA?) whcih works even when they are not part of a squad // This action assign a new leader if the old one dies state Running { Begin: if ( destinationName != '' ) { //log( name @ "moving to" @ destinationName ); node = squad().findStaticByLabel( class'Pathfinding.PlacedNode', destinationName ); if ( node == None ) { log( "AI WARNING:" @ name @ "(" @ squad().name @ ") can't find specified path node" @ destinationName ); fail( ACT_INVALID_PARAMETERS, true ); } destination = node.Location; } if ( squad().logTyrion ) log( name @ "started." @ squad().name @ "is moving to" @ destination ); while ( leader == None ) { // compute number of followers and assign leader nFollowers = 0; for ( i = squad().pawns.length-1; i >= 0; i-- ) { pawn = squad().pawns[i]; //log( name @ "checking" @ pawn.name ); if ( class'Pawn'.static.checkAlive( pawn ) ) if ( leader == None ) { leader = pawn; // leader is last pawn who is alive leaderIndex = i; } else nFollowers++; } if ( squad().logTyrion ) log( name @ "picked leader" @ leader.name ); if ( leader == None ) fail( ACT_ALL_RESOURCES_DIED ); if ( squadFollowGoal != None ) { squadFollowGoal.unPostGoal( self ); squadFollowGoal.Release(); // must be done here as well as cleanup because squadFollowGoal could be overwritten squadFollowGoal = None; } if ( nFollowers > 0 ) squadFollowGoal = (new class'AI_SquadFollowGoal'( AI_SquadResource(resource), achievingGoal.priority, leader, 100, formationDiameter, ,terminalVelocity, terminalHeight, groundMovement )).postGoal( self ).myAddRef(); do { if ( followersTooFarAway( self ) ) { //log( name @ "leader waiting for followers to catch up" ); leader.level.speechManager.PlayDynamicSpeech( leader, 'FollowLeader' ); yield(); } else { if ( moveGoal != None ) { moveGoal.unPostGoal( self ); moveGoal.Release(); // must be done here as well as cleanup because moveGoal could be overwritten moveGoal = None; } moveGoal = (new class'AI_MoveToGoal'( AI_MovementResource(leader.movementAI), achievingGoal.priority, destination, skiCompetency, jetCompetency, groundMovement, energyUsage, terminalVelocity, terminalHeight, terminalDistanceXY, terminalDistanceZ )).postGoal( self ).myAddRef(); interruptGoalIf( moveGoal, class'AI_SquadMoveTo' ); // unposts goals after interruption (but not on failure) //log( name $ ":" @ moveGoal.resource.pawn().name $ "'s action interrupted" ); if ( class'Pawn'.static.checkAlive( leader ) ) AI_Controller(leader.controller).stopMove(); } } until( (moveGoal != None && moveGoal.hasCompleted()) || class'Pawn'.static.checkDead( leader ) ) //log( "moveGoal.Completion:" @ moveGoal.hasCompleted() ); if ( class'Pawn'.static.checkDead( leader ) ) { leader = None; moveGoal.unPostGoal( self ); squadFollowGoal.unpostGoal( self ); // unposted explicitly so resources get freed up on this tick if ( squad().logTyrion ) log( name @ "leader died!" ); } } if ( squad().logTyrion ) log( name @ "stopped." ); if ( !moveGoal.wasAchieved() ) fail( ACT_CANT_REACH_DESTINATION ); else succeed(); } //===================================================================== function classConstruct() { resourceUsage = class'AI_Resource'.const.RU_LEGS; } defaultproperties { satisfiesGoal = class'AI_SquadMoveToGoal' } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |