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 |
//============================================================================= // ObjectivesTrigger.uc // Created By: Mike Fox // Created On: 8/01/00 // $Author: Mfox $ // $Date: 12/17/02 8:30p $ // $Revision: 4 $ //============================================================================= class ObjectivesTrigger extends Triggers; /*----------------------------------------------------------------------------- Used to give one or more scripts to NPCs which touch it. The first N NPCs are given primary scripts (usually there is just one of these), subsequent NPCs are given secondary scripts. If an NPC with a primary script dies, the nearest secondary NPC is considered for getting a primary script. Generally, this candidate NPC will be ordered to the location of the objectives trigger and will receive a primary script when it touches it but if the candidate NPC is already inside the trigger or if the trigger has bIgnoreDistance=true the NPC will get the script immediately. When ordering the candidate NPC to the location of the the objectives trigger, if a different valid NPC touches the objectives trigger first that NPC will be given the primary script (and the candidate NPC will get a secondary script unless a primary script becomes available). Note that NPCs begin to execute their script immediately when they are given one. -----------------------------------------------------------------------------*/ #exec Texture Import File=Textures\ObjectivesTrigger.bmp Mips=Off MASKED=1 //----------------------------------------------------------------------------- struct TScriptInfo { var() string CommandFileName; var() string CommandStartLabel; var Pawn AssignedPawn; }; var() array<TScriptInfo> PrimaryScripts; // primary scripts var() array<TScriptInfo> SecondaryScripts; // secondary scripts var() array< class<Actor> > ClassProximityTypes; // affected classes var() bool bIgnoreDistance; // if true, NPCs are given primary scripts immediately var int NumAssignedPrimaryScripts; var int NumAssignedSecondaryScripts; //----------------------------------------------------------------------------- /* event PreBeginPlay() { local int ii; Super.PreBeginPlay(); DMTN( "Scripts:" ); for( ii=0; ii<PrimaryScripts.Length; ii++ ) DMTN( "Primary #" $ ii+1 $ ": " $ PrimaryScripts[ ii ].CommandFileName ); for( ii=0; ii<SecondaryScripts.Length; ii++ ) DMTN( "Secondary #" $ ii+1 $ ": " $ SecondaryScripts[ ii ].CommandFileName ); } */ //----------------------------------------------------------------------------- function bool IsRelevant( Pawn P ) { local int ii; local bool bResult; if( P != None && P.Health > 0 && U2NPCController(P.Controller) != None && !P.HasDeathObserver( Self ) ) { for( ii=0; ii<ClassProximityTypes.Length; ii++ ) if( ClassIsChildOf( P.Class, ClassProximityTypes[ ii ] ) ) bResult = true; } return bResult; } //----------------------------------------------------------------------------- function AssignScript( U2NPCController NPC ) { local int ii; local string CommandFileName, StartLabel; if( NumAssignedPrimaryScripts < PrimaryScripts.Length ) { for( ii=0; ii<PrimaryScripts.Length; ii++ ) { if( PrimaryScripts[ ii ].AssignedPawn == None ) { //DMTN( "assigning primary script #" $ ii $ " to " $ NPC.Pawn ); CommandFileName = PrimaryScripts[ ii ].CommandFileName; StartLabel = PrimaryScripts[ ii ].CommandStartLabel; NumAssignedPrimaryScripts++; PrimaryScripts[ ii ].AssignedPawn = NPC.Pawn; break; } } } else if( NumAssignedSecondaryScripts < SecondaryScripts.Length ) { for( ii=0; ii<SecondaryScripts.Length; ii++ ) { if( SecondaryScripts[ ii ].AssignedPawn == None ) { //DMTN( "assigning secondary script #" $ ii $ " to " $ NPC.Pawn ); CommandFileName = SecondaryScripts[ ii ].CommandFileName; StartLabel = SecondaryScripts[ ii ].CommandStartLabel; NumAssignedSecondaryScripts++; SecondaryScripts[ ii ].AssignedPawn = NPC.Pawn; break; } } } if( CommandFileName == "" ) { DMTN( "Warning: no scripts available for " $ NPC $ " (" $ NPC.Pawn $ ")" ); } else { NPC.SetScript( CommandFileName, StartLabel ); // track NPC until it dies NPC.Pawn.AddDeathObserver( Self ); } } //----------------------------------------------------------------------------- event Touch( Actor Other ) { if( IsRelevant( Pawn(Other) ) ) { //DMTN( "Touched by relevant actor: " $ Other ); AssignScript( U2NPCController(Pawn(Other).Controller) ); } } //----------------------------------------------------------------------------- function bool HasPrimaryScript( Pawn P ) { local int ii; for( ii=0; ii<PrimaryScripts.Length; ii++ ) if( PrimaryScripts[ ii ].AssignedPawn == P ) return true; return false; } //----------------------------------------------------------------------------- function ClearSecondaryScript( Pawn P ) { local int ii; for( ii=0; ii<SecondaryScripts.Length; ii++ ) if( SecondaryScripts[ ii ].AssignedPawn == P ) { NumAssignedSecondaryScripts--; SecondaryScripts[ ii ].AssignedPawn = None; } } //----------------------------------------------------------------------------- function HandleControlledPawnDeath( Pawn P ) { local int ii; local int AssignedScript; local Controller C; local float DistanceToTrigger, MinDistanceToTrigger; local U2NPCController U2NPC, ClosestU2NPC; local bool bIsPrimary; // find the script that it had AssignedScript = -1; for( ii=0; ii<PrimaryScripts.Length; ii++ ) if( PrimaryScripts[ ii ].AssignedPawn == P ) { AssignedScript = ii; NumAssignedPrimaryScripts--; PrimaryScripts[ ii ].AssignedPawn = None; bIsPrimary = true; break; } if( AssignedScript == -1 ) { for( ii=0; ii<SecondaryScripts.Length; ii++ ) if( SecondaryScripts[ ii ].AssignedPawn == P ) { AssignedScript = ii; NumAssignedSecondaryScripts--; SecondaryScripts[ ii ].AssignedPawn = None; break; } } if( bIsPrimary ) { // give primary script to controlled NPC with a secondary script that is nearest to the objectives trigger? MinDistanceToTrigger = 999999.9; for( C=Level.ControllerList; C!=None; C=C.NextController ) { //DMTN( "considering " $ C $ " Pawn: " $ C.Pawn $ " HPS: " $ HasPrimaryScript( C.Pawn ) $ " HDO: " $ C.Pawn.HasDeathObserver( Self ) ); U2NPC = U2NPCController(C); if( C.Pawn != None && C.Pawn.Health > 0 && U2NPC != None && !HasPrimaryScript( C.Pawn ) && C.Pawn.HasDeathObserver( Self ) ) { DistanceToTrigger = VSize( Location - C.Pawn.Location ); //DMTN( " DistanceToTrigger:" $ DistanceToTrigger ); if( DistanceToTrigger < MinDistanceToTrigger ) { MinDistanceToTrigger = DistanceToTrigger; ClosestU2NPC = U2NPC; } } } //DMTN( "ClosestU2NPC: " $ ClosestU2NPC ); if( ClosestU2NPC != None ) { //DMTN( " Pawn: " $ ClosestU2NPC.Pawn $ " MinDistanceToTrigger: " $ MinDistanceToTrigger ); //AddArrow( Location, ClosestU2NPC.Pawn.Location, ColorPink() ); ClearSecondaryScript( ClosestU2NPC.Pawn ); if( bIgnoreDistance || MinDistanceToTrigger < (CollisionRadius + ClosestU2NPC.Pawn.CollisionRadius ) ) { //DMTN( "re-assigning primary script #" $ ii $ " to " $ ClosestU2NPC.Pawn ); // immediately give NPC script ClosestU2NPC.SetScript( PrimaryScripts[ AssignedScript ].CommandFileName, PrimaryScripts[ AssignedScript ].CommandStartLabel ); NumAssignedPrimaryScripts++; PrimaryScripts[ AssignedScript ].AssignedPawn = ClosestU2NPC.Pawn; } else { //DMTN( "ordering " $ ClosestU2NPC.Pawn $ " to my location" ); // order NPC to area of trigger (if/when it gets there it will get a script) ClosestU2NPC.SetScript( "" ); ClosestU2NPC.SetOrders( ClosestU2NPC.OrdersGoto, Self ); ClosestU2NPC.SetExecuteOrders( true ); // make sure NPC follows orders? } } } } //----------------------------------------------------------------------------- // Currently triggers should only ever come in when one of the controlled NPCs // is killed. function Trigger( Actor Other, Pawn EventInstigator, optional name EventName ) { if( Pawn(Other) != None && EventName == Pawn.ObservedDeathEvent ) { //DMTN( Other $ " died" ); HandleControlledPawnDeath( Pawn(Other) ); } else { Super.Trigger( Other, EventInstigator, EventName ); } } //----------------------------------------------------------------------------- defaultproperties { Texture=Texture'U2.ObjectivesTrigger' UseReticleOnEvents(0)="UseReticleText" UseReticleOnEvents(1)="UseReticleCorners" UseReticleOnEvents(2)="UseReticleTopBars" ProximityReticleOnEvents(0)="ProximityReticleCorners" ProximityReticleOnEvents(1)="ProximityReticleTopBars" } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |