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 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 |
class ONSTeamAI extends TeamAI; var ONSPowerCore FinalCore; //this team's main powercore var bool bAllNodesTaken; function Reset() { Super.Reset(); bAllNodesTaken = false; } function SetObjectiveLists() { local GameObjective O; local ONSPowerCore Core; Super.SetObjectiveLists(); for (O = Objectives; O != None; O = O.NextObjective) { Core = ONSPowerCore(O); if (Core != None && Core.bFinalCore && Core.CoreStage == 0 && Core.DefenderTeamIndex == Team.TeamIndex) { FinalCore = Core; break; } } if (FinalCore == None) warn("Couldn't find PowerCore!"); } function ReAssessStrategy() { local GameObjective O; if (FreelanceSquad == None) return; if (FinalCore == None || ONSTeamAI(EnemyTeam.AI).FinalCore == None) { Super.ReAssessStrategy(); return; } if ( FinalCore.PoweredBy(EnemyTeam.TeamIndex) || ONSTeamAI(EnemyTeam.AI).FinalCore.PoweredBy(Team.TeamIndex) || (Level.Game.bOverTime && FinalCore.Health < ONSTeamAI(EnemyTeam.AI).FinalCore.Health) ) { FreelanceSquad.bFreelanceAttack = true; FreelanceSquad.bFreelanceDefend = false; O = GetPriorityAttackObjectiveFor(FreelanceSquad); } else if (Level.Game.bOverTime && FinalCore.Health > ONSTeamAI(EnemyTeam.AI).FinalCore.Health) { FreelanceSquad.bFreelanceAttack = false; FreelanceSquad.bFreelanceDefend = true; O = GetLeastDefendedObjective(); } else { FreelanceSquad.bFreelanceAttack = false; FreelanceSquad.bFreelanceDefend = false; O = GetPriorityFreelanceObjective(); } if ( (O != None) && (O != FreelanceSquad.SquadObjective) ) FreelanceSquad.SetObjective(O,true); } function CriticalObjectiveWarning(GameObjective AttackedObjective, Pawn EventInstigator) { local SquadAI S; local Bot M; local bool bFoundDefense; for (S = Squads; S != None; S = S.NextSquad) if (S.SquadObjective == AttackedObjective) { bFoundDefense = true; if ( EventInstigator != None ) { S.CriticalObjectiveWarning(EventInstigator); for (M = S.SquadMembers; M != None; M = M.NextSquadMember) if ( (M.Enemy == None || M.Enemy == EventInstigator) && Vehicle(M.Pawn) != None && M.Pawn.bStationary && !FastTrace(EventInstigator.Location + EventInstigator.CollisionHeight * vect(0,0,1), M.Pawn.Location) ) { Vehicle(M.Pawn).KDriverLeave(false); M.WhatToDoNext(67); } } } if ( !bFoundDefense ) { for (S = Squads; S != None; S = S.NextSquad) if ( (S.GetOrders() == 'Defend' || S.bFreelanceDefend) && (ONSPowerCore(S.SquadObjective) == None || (!ONSPowerCore(S.SquadObjective).bUnderAttack && ONSPowerCore(S.SquadObjective).CoreStage != 4)) ) { S.SetObjective(AttackedObjective, true); if ( EventInstigator != None ) S.CriticalObjectiveWarning(EventInstigator); return; } } } function FindNewObjectives(GameObjective DisabledObjective) { local SquadAI S; local Bot M; local ONSPowerCore Core, DisabledCore; local GameObjective O; local int i; local bool bHasVulnerableNode; for (O = Team.AI.Objectives; O != None; O = O.NextObjective) { Core = ONSPowerCore(O); if (Core != None && Core.CoreStage == 0 && Core.DefenderTeamIndex == Team.TeamIndex && Core.PoweredBy(EnemyTeam.TeamIndex)) { bHasVulnerableNode = true; break; } } for (S = Squads; S != None; S = S.NextSquad) { S.GetOrders(); Core = ONSPowerCore(S.SquadObjective); if (S.CurrentOrders == 'Attack' || S.bFreelanceAttack || (!bHasVulnerableNode && (S.CurrentOrders == 'Defend' || S.bFreelanceDefend))) { if ( Core == None || Core.bDisabled || (Core.DefenderTeamIndex == Team.TeamIndex && Core.CoreStage == 0) || (!Core.PoweredBy(Team.TeamIndex) && (bHasVulnerableNode || !Core.LinkedToCoreConstructingFor(Team.TeamIndex))) ) FindNewObjectiveFor(S, false); else if (Core.CoreStage == 1) for (M = S.SquadMembers; M != None; M = M.NextSquadMember) if (M.IsInState('RangedAttack')) //just finished destroying node, now take it over M.WhatToDoNext(66); } else if (S.CurrentOrders == 'Defend' || S.bFreelanceDefend) { if ( Core == None || Core.bDisabled || (Core.CoreStage != 4 && Core.CoreStage != 1 && (Core.DefenderTeamIndex != Team.TeamIndex || !Core.PoweredBy(EnemyTeam.TeamIndex))) ) FindNewObjectiveFor(S, false); else { //check if objective with higher defensepriority is now vulnerable DisabledCore = ONSPowerCore(DisabledObjective); if (DisabledCore != None && DisabledCore.CoreStage == 0) for (i = 0; i < DisabledCore.PowerLinks.Length; i++) if ( DisabledCore.PowerLinks[i].DefensePriority > Core.DefensePriority && (DisabledCore.PowerLinks[i].DefenseSquad == None || DisabledCore.PowerLinks[i].DefenseSquad.Team != Team) ) { S.SetObjective(DisabledCore, true); break; } } } else FindNewObjectiveFor(S, false); } } //ObjectiveCovered() returns true if the given objective is a SquadObjective for a squad on this team function bool ObjectiveCovered(GameObjective O) { local SquadAI S; for (S = Squads; S != None; S = S.NextSquad) if (S.SquadObjective == O) return true; return false; } function GameObjective GetPriorityAttackObjectiveFor(SquadAI AttackSquad) { local GameObjective O, NextPickedObjective; local ONSPowerCore Core; local array<ONSPowerCore> NextCores; local int i, j; local bool bAlreadyInList, bPickedObjectiveCovered, bTestObjectiveCovered; PickedObjective = None; for (O = Objectives; O != None; O = O.NextObjective) { Core = ONSPowerCore(O); if ( Core != None && !Core.bDisabled && (Core.DefenderTeamIndex != Team.TeamIndex || Core.CoreStage != 0) && Core.PoweredBy(Team.TeamIndex) ) { //keep track of neutral nodes that will be obtainable when the currently obtainable ones have been built //but only if this one is neutral or owned by this team because don't want bots waiting on "future" nodes //while a single team futilely attacks the enemy controlled node! if (Core.DefenderTeamIndex == Team.TeamIndex || (Core.CoreStage != 0 && Core.CoreStage != 2)) for (i = 0; i < Core.PowerLinks.Length; i++) if (Core.PowerLinks[i].CoreStage == 4 || Core.PowerLinks[i].CoreStage == 2) { bAlreadyInList = false; for (j = 0; j < NextCores.length; j++) { if (NextCores[j] == Core.PowerLinks[i]) { bAlreadyInList = true; break; } } if (!bAlreadyInList) NextCores[NextCores.length] = Core.PowerLinks[i]; } bTestObjectiveCovered = ObjectiveCovered(Core); if ( PickedObjective == None || (!bTestObjectiveCovered && (bPickedObjectiveCovered || PickedObjective.DefensePriority < Core.DefensePriority)) || (PickedObjective.DefensePriority == Core.DefensePriority && (bPickedObjectiveCovered == bTestObjectiveCovered) && FRand() < 0.5) ) { PickedObjective = Core; bPickedObjectiveCovered = bTestObjectiveCovered; } } } if (PickedObjective != None && ObjectiveCovered(PickedObjective)) { for (i = 0; i < NextCores.length; i++) if ( !ObjectiveCovered(NextCores[i]) && ( NextPickedObjective == None || NextPickedObjective.DefensePriority < NextCores[i].DefensePriority || (NextPickedObjective.DefensePriority == NextCores[i].DefensePriority && FRand() < 0.5) ) ) NextPickedObjective = NextCores[i]; if (NextPickedObjective != None) PickedObjective = NextPickedObjective; } return PickedObjective; } function GameObjective GetLeastDefendedObjective() { local GameObjective O, Best; for ( O=Objectives; O!=None; O=O.NextObjective ) { if ( ONSPowerCore(O) != None && ONSPowerCore(O).CoreStage == 0 && (O.DefenderTeamIndex == Team.TeamIndex) && ONSPowerCore(O).PoweredBy(EnemyTeam.TeamIndex) && ((Best == None) || (Best.DefensePriority < O.DefensePriority) || ((Best.DefensePriority == O.DefensePriority) && (Best.GetNumDefenders() > O.GetNumDefenders()))) ) Best = O; } if (Best == None) Best = GetPriorityAttackObjectiveFor(None); //nothing needs defending, so head to neutral node return Best; } function GameObjective GetMostDefendedObjective() { local GameObjective O, Best; for ( O=Objectives; O!=None; O=O.NextObjective ) { if ( ONSPowerCore(O) != None && ONSPowerCore(O).CoreStage == 0 && (O.DefenderTeamIndex == Team.TeamIndex) && ONSPowerCore(O).PoweredBy(EnemyTeam.TeamIndex) && ((Best == None) || (Best.DefensePriority < O.DefensePriority) || ((Best.DefensePriority == O.DefensePriority) && (Best.GetNumDefenders() < O.GetNumDefenders()))) ) Best = O; } if (Best == None) Best = GetPriorityAttackObjectiveFor(None); //nothing needs defending, so head to neutral node return Best; } function bool PutOnDefense(Bot B) { local GameObjective O; O = GetLeastDefendedObjective(); if ( O != None ) { //we need this because in Onslaught, unlike other gametypes, two defending squads (possibly from different teams!) //could be headed to the same objective if ( O.DefenseSquad == None || O.DefenseSquad.Team != Team ) { O.DefenseSquad = AddSquadWithLeader(B, O); ONSSquadAI(O.DefenseSquad).bDefendingSquad = true; } else O.DefenseSquad.AddBot(B); return true; } return false; } function bool OverrideCheckSpecialVehicleObjectives(bot B) { if ( bAllNodesTaken ) return false; if ( B.Squad == FreelanceSquad ) return true; } function bool IsFastFreelanceObjective(ONSPowerCore Core) { return ( (Core != None) && (Core.CoreStage == 4) && (Core.PoweredBy(Team.TeamIndex) || Core.LinkedToCoreConstructingFor(Team.TeamIndex)) ); } function float CoreAvailabilityScore(ONSPowerCore Core) { if ( !IsFastFreelanceObjective(Core) ) return -1; // distinguish based on whether enemy can get this node as well if ( Core.PoweredBy(1-Team.TeamIndex) ) return 1; if ( Core.LinkedToCoreConstructingFor(1-Team.TeamIndex) ) return 2; // if only linked to power core, lower score if ( Core.LinkedNodes.length == 1 ) return 3; return 4; } function GameObjective FindFastFreelanceObjective() { local GameObjective O; local ONSPowerCore OPC, Best; local float BestRating, NewRating; local float BestScore, NewScore; if ( (FreelanceSquad != None) && IsFastFreelanceObjective(ONSPowerCore(FreelanceSquad.SquadObjective)) ) return FreelanceSquad.SquadObjective; //find a node that the enemy wants to get (regardless of whether this team can get it) for (O = Objectives; O != None; O = O.NextObjective) { OPC = ONSPowerCore(O); NewScore = CoreAvailabilityScore(OPC); //log("Team "$Team.TeamIndex$" score for node "$OPC.NodeNum$" ("$OPC$") is "$NewScore$" vs best "$BestScore); if ( NewScore >= BestScore ) { if ( BestScore < NewScore ) Best = None; NewRating = OPC.RateCore(); if ( (Best == None) || (NewRating > BestRating) ) { Best = OPC; BestRating = NewRating; BestScore = NewScore; } } } //log("Team "$Team.TeamIndex$" best node "$best.NodeNum$" ("$best$")"); if ( Best == None ) bAllNodesTaken = true; return Best; } function GameObjective GetPriorityFreelanceObjective() { local GameObjective O, Best; local ONSPowerCore Core; if ( !bAllNodesTaken ) { Best = FindFastFreelanceObjective(); if ( !bAllNodesTaken ) return Best; } //find a node that the enemy wants to get (regardless of whether this team can get it) for (O = Objectives; O != None; O = O.NextObjective) { Core = ONSPowerCore(O); if ( Core != None && (Core.CoreStage == 4 || Core.CoreStage == 2 || Core.CoreStage == 5) && Core.DefenderTeamIndex != Team.TeamIndex && Core.PoweredBy(EnemyTeam.TeamIndex) && (Best == None || Best.DefensePriority < Core.DefensePriority) ) Best = O; } if (Best == None) Best = GetPriorityAttackObjectiveFor(None); return Best; } defaultproperties { SquadType=Class'Onslaught.ONSSquadAI' OrderList(0)="Attack" OrderList(4)="Defend" OrderList(6)="Attack" OrderList(7)="Attack" } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |