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 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 |
//===================================================================== // AI_Duel // Duels with the target. // // Notes: // Duel decides whether to be aggressive or defensive // 1. Aggressive ("Chase"): Fly towards opponent on a diagonal - try to land on high terrain if possible // 2. Defensive ("Lure"): Move around, hide behind cover - gain height if possible // // Option 1: Duel action runs concurrently and posts/unposts lure/chase goals // Option 2: Lure/Chase pre-conditions figure out their own activation // // I like Option 1 better because it's hard for lure to know when a chase is more appropriate. // It also enables Duel to interrupt GainHeight should the target be spotted // The only disadvantage is having parent and child actions running at the same time. Given the number of // Duel actions active at the same time (not a lot) that's probaby a minor thing. //===================================================================== class AI_Duel extends AI_CharacterAction implements IWeaponSelectionFunction editinlinenew; //===================================================================== // Constants const MAX_TAKECOVER_DIST = 3000.0f; // duelist doesn't try to take cover unless at least *this* close const JETPACK_BEHIND_DIST = 2000.0f; // don't jetpack behind unless at least *this* close //===================================================================== // Variables var(Parameters) int rank "Rank of the duelist (1, 2, or 3)"; var(Parameters) editinline Name targetName "Label of target (any Pawn)"; var(Parameters) class<Weapon> preferredWeaponClass "AI will use this weapon if at all possible"; var(InternalParameters) editconst Pawn target; var(InternalParameters) editconst IWeaponSelectionFunction weaponSelection; // not used var(InternalParameters) editconst IFollowFunction followFunction; var() float maxSpinfusorRange "maximum distance at which the Duelist uses the spinfusor"; var() float maxBucklerRange "maximum distance at which the Duelist uses the buckler"; var() float maxEnergyBladeRange "Maximum distance at which to use the energy blade"; var() float idealSpinfusorRange "preferred distance for using the spinfusor"; var() float idealGrenadeLauncherRange "preferred distance for using the grenade launcher"; var() float idealBucklerRange "preferred distance for using the buckler"; var BaseAICharacter ai; var AI_Goal takeCoverGoal; var AI_Goal gainHeightGoal; var AI_TargetMemorySensor targetMemorySensor; var Character targetCharacter; var vector destination; var float jetpackBehindDistance; // max distance at which to try to jetpack behind target //===================================================================== // Functions //--------------------------------------------------------------------- // Selection Heuristic // Returns a value in the range [0, 1], indicating how suitable this action is for achieving this goal static function float selectionHeuristic( AI_Goal goal ) { return 1.0; // most suitable attack for a duelist } //--------------------------------------------------------------------- // callbacks from subGoals function goalAchievedCB( AI_Goal goal, AI_Action child ) { super.goalAchievedCB( goal, child ); clearGoals( goal ); } function goalNotAchievedCB( AI_Goal goal, AI_Action child, ACT_ErrorCodes errorCode ) { super.goalNotAchievedCB( goal, child, errorCode ); clearGoals( goal ); } final function clearGoals( AI_Goal goal ) { if ( goal == takeCoverGoal && takeCoverGoal != None ) { takeCoverGoal.unPostGoal( self ); takeCoverGoal.Release(); takeCoverGoal = None; } if ( goal == gainHeightGoal && gainHeightGoal != None ) { gainHeightGoal.unPostGoal( self ); gainHeightGoal.Release(); gainHeightGoal = None; } } //--------------------------------------------------------------------- // function for determining what weapon to use function Weapon bestWeapon( Character ai, Pawn target, class<Weapon> preferredWeaponClass ) { local Weapon w; local Vector hitLocation; local float timeToHit; local Character targetCharacter; w = Weapon( ai.nextEquipment( None, class'Buckler' )); if ( w != None && w.hasAmmo() && ( preferredWeaponClass == class'Buckler' || VDistSquared( ai.Location, target.Location ) < maxBucklerRange * maxBucklerRange ) && w.aimClass.static.obstacleInPath( hitLocation, timeToHit, target, w, w.aimClass.static.getAimLocation( w, target )) == None ) return w; w = Weapon( ai.nextEquipment( None, class'EnergyBlade' )); if ( w != None && VDistSquared( ai.Location, target.Location ) <= maxEnergyBladeRange * maxEnergyBladeRange ) return w; targetCharacter = Character(target); w = Weapon( ai.nextEquipment( None, class'Spinfusor' )); if ( w != None && w.hasAmmo() && ( preferredWeaponClass == class'Spinfusor' || VDistSquared( ai.Location, target.Location ) < maxSpinfusorRange * maxSpinfusorRange || (targetCharacter != None && targetCharacter.isInAir() && target.Velocity.Z > 0)) && // target airborne and going up: use spinfusor w.aimClass.static.obstacleInPath( hitLocation, timeToHit, target, w, w.aimClass.static.getAimLocation( w, target )) == None && !w.aimClass.static.willHurt( w, ai, hitLocation, timeToHit )) return w; w = Weapon( ai.nextEquipment( None, class'GrenadeLauncher' )); if ( w != None && w.hasAmmo() ) return w; return ai.weapon; // no weapon found: keep holding what you got } //--------------------------------------------------------------------- // best range at which to shoot weapon function float firingRange( class<Weapon> weaponClass ) { // always try to back up to the ideal spinfusor range unless holding the energy blade if ( ClassIsChildOf( weaponClass, class'EnergyBlade' )) return 0.8f * (class'EnergyBlade'.default.range + target.CollisionRadius); // energy blade else return idealSpinfusorRange; } //--------------------------------------------------------------------- // are conditions met for firing this weapon? function bool bShouldFire( BaseAICharacter ai, Weapon weapon ) { return true; } //--------------------------------------------------------------------- function cleanup() { super.cleanup(); weaponSelection = None; followFunction = None; // when Duel deactivates, AI keeps on moving with his last direction // (maybe there should be a default low-pri action that lands the AI?) if ( class'Pawn'.static.checkAlive( pawn ) ) AI_Controller(pawn.controller).stopMove(); if ( targetMemorySensor != None ) { targetMemorySensor.deactivateSensor( self ); targetMemorySensor = None; } if ( takeCoverGoal != None ) { takeCoverGoal.Release(); takeCoverGoal = None; } if ( gainHeightGoal != None ) { gainHeightGoal.Release(); gainHeightGoal = None; } } //===================================================================== // State code state Running { Begin: if ( rank != 1 && rank != 2 && rank != 3 ) { log( "AI ERROR: invalid rank" @ rank @ "given to duelist" @ Pawn.name ); fail( ACT_INVALID_PARAMETERS, true ); } if ( target == None && targetName == '' ) { log( "AI WARNING:" @ name @ "has no target" ); fail( ACT_INVALID_PARAMETERS, true ); } if ( target == None ) target = Pawn(pawn.findByLabel( class'Pawn', targetName, true )); if ( pawn.logTyrion ) log( name @ "started." @ pawn.name @ "is dueling" @ target.name ); if ( target == None ) { log( "AI WARNING:" @ name @ "can't find specified rook" ); fail( ACT_INVALID_PARAMETERS ); } targetMemorySensor = AI_TargetMemorySensor( class'AI_Sensor'.static.activateSensor( self, class'AI_TargetMemorySensor', characterResource() ) ); targetMemorySensor.setParameters( target, rook().visionMemory ); ai = baseAICharacter(); targetCharacter = Character(target); jetpackBehindDistance = FMax( JETPACK_BEHIND_DIST, 1.2f * idealSpinfusorRange ); // so AI jetpacks even when backed up to spinfusor range (new class'AI_DirectAttackGoal'( characterResource(), achievingGoal.priority-1, target, self, preferredWeaponClass, followFunction )).postGoal( self ); while ( class'Pawn'.static.checkAlive( ai ) && class'Pawn'.static.checkAlive( target ) ) { // decide whether to be aggressive if ( ( targetCharacter == None || targetCharacter.energy > ai.energy || !targetCharacter.isInAir() ) && targetMemorySensor.queryObjectValue() != None && VSizeSquared2D( target.Location - ai.Location ) < jetpackBehindDistance * jetpackBehindDistance && class'AI_JetpackBehind'.static.getJetpackBehindPoint( destination, ai, target )) { if ( ai.logTyrion ) log( name @ "(" @ ai.name @ ") aggressively attacking (jetpacking behind)" ); if ( takeCoverGoal != None ) { takeCoverGoal.unPostGoal( self ); takeCoverGoal.Release(); takeCoverGoal = None; } if ( gainHeightGoal != None ) { gainHeightGoal.unPostGoal( self ); gainHeightGoal.Release(); gainHeightGoal = None; } WaitForGoal( (new class'AI_JetpackBehindGoal'( movementResource(), achievingGoal.priority, target, destination, 1.2f * jetpackBehindDistance, followFunction )).postGoal( self ), true ); } else { /*if ( takeCoverGoal == None && gainHeightGoal == None ) { if ( VDistSquared( target.Location, ai.Location ) < MAX_TAKECOVER_DIST * MAX_TAKECOVER_DIST ) { if ( true || ai.logTyrion ) log( name @ "(" @ ai.name @ ") taking cover" ); takeCoverGoal = (new class'AI_TakeCoverGoal'( movementResource(), achievingGoal.priority, target, 75 )).postGoal( self ).myAddRef(); } else { if ( true || ai.logTyrion ) log( name @ "(" @ ai.name @ ") gaining height" ); gainHeightGoal = (new class'AI_GainHeightGoal'( movementResource(), achievingGoal.priority, target, 75 )).postGoal( self ).myAddRef(); } }*/ } //log( takeCoverGoal @ gainHeightGoal ); yield(); } if ( class'Pawn'.static.checkDead( target ) ) { if ( ai.logTyrion ) log( name @ "(" @ ai.name @ ") stopped. TARGET DEAD!" ); succeed(); } else fail( ACT_GENERAL_FAILURE ); } //===================================================================== defaultproperties { satisfiesGoal = class'AI_AttackGoal' maxSpinfusorRange = 3000 maxBucklerRange = 1800 maxEnergyBladeRange = 750 idealSpinfusorRange = 2000 idealGrenadelauncherRange = 3000 idealBucklerRange = 1200 } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |