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 |
// A ship mounted gun turret that shoots bloat bile at random players. class DeckGun extends Actor placeable; // is the deck gun actively looking for targets? var () protected bool bActive; // Number of seconds between shots var () const float FireInterval; // Number of seconds between bursts of projectiles. var () const float BurstInterval; // The time the burst last finished. var protected float LastBurstEndTime; // The number of projectiles fired in the current burst var protected int NumFired; // Amount of time the Projectiles stay up in the air for before hitting. var () const float ProjectileHangTime; // Number of projectiles to spawn in each burst before 'cooling down'. var() const int NumProjectilesPerBurst; // Type of projectile to fire var () const class<Projectile> ProjectileType; // The last time the gun was fired var protected float LastFireTime; // amount of spread / aim error when Firing var () const float AimError; // The player who we're currently aiming at. var protected Pawn TargetPlayer; // the guy we were last aiming at. var protected Pawn LastTarget; // Jack looks for a new enemy every this amount of seconds. var () const float FindNewEnemyInterval; // Time at which we last found a new enemy to throw stuff at. var protected float LastAcquiredTargetTime; // Rotation of the gun in the map. var protected Rotator InitialRotation; // Animation we want to play on the client. var protected name PendingClientAnim; // name of the firing animation for the deck gun. var () const name FireAnimName; // Rate to play the firing animation at. 1.f == Normal speed. var () const float FireAnimRate; // Maximum range at which the gun will acquire targets var () const float MaxAggroRange; // Sound the gun makes every time it fires. var() const Sound FiringSound; // The volume of the shoot sound. var() const float FiringSoundVolume; // The radius of the shoot sound. var() const float FiringSoundRadius; var protected bool PendingClientStopAnim; replication { unreliable if(Role == Role_Authority) PendingClientAnim,PendingClientStopAnim; } simulated function PostNetReceive() { if(PendingClientAnim != '') { LoopAnim(PendingClientAnim,FireAnimRate,0.1,0); PendingClientAnim = ''; } if(PendingClientStopAnim) { PendingClientStopAnim = false; StopAnimating(); } } simulated function PostBeginPlay() { InitialRotation = Rotation; DesiredRotation = InitialRotation; } /** * Randomly picks a living player to shoot at from the controller list. * * @network All. */ simulated function Tick(float DeltaTime) { if(bActive) { FindTarget(); TrackTarget(DeltaTime); CheckFire(); } } /** * Orients the gun so that it's facing what it's about to shoot at. * * @network All. */ simulated function TrackTarget(float DeltaTime) { local Rotator TargetDir; if(TargetPlayer != none) { TargetDir = Rotator(TargetPlayer.Location - Location) ; DesiredRotation = TargetDir; } } /** * Randomly picks a living player to shoot at from the controller list. * * @network Server. */ function FindTarget() { local Controller C; local array<Pawn> ValidTargets; if(level.TimeSeconds - LastAcquiredTargetTime > FindNewEnemyInterval || TargetPlayer == none || TargetPlayer.health <= 0) { for (C = Level.ControllerList; C != None; C = C.NextController) { if(C.bIsPlayer && C.Pawn != none && C.Pawn.health > 0 && C.Pawn != LastTarget && (MaxAggroRange == 0 || VSize(C.Pawn.Location - Location) <= MaxAggroRange)) { ValidTargets[ValidTargets.length] = C.Pawn; } } // Nothing to aim at. Check to see if maybe the only guy who's left is our previous target. if(ValidTargets.length == 0) { if(LastTarget != none && LastTarget.Health > 0) { SetTarget(LastTarget); } } else { // Randomly pick from the available players. SetTarget(ValidTargets[Rand(ValidTargets.length)]); } } } /** * Set the specified pawn to be our currently active target. * * @param NewTarget The guy we want to start shooting at. * @network Server. */ function SetTarget( Pawn NewTarget) { LastAcquiredTargetTime = Level.TimeSeconds; LastTarget = TargetPlayer; TargetPlayer = NewTarget; } /** * Decide if it's time to shoot again. * * @network All. */ simulated function CheckFire() { if(TargetPlayer != none && Level.TimeSeconds - LastFireTime > FireInterval) { if(BarrelsAreFacingTarget()) { if(NumFired < NumProjectilesPerBurst) { LastFireTime = Level.TimeSeconds; DoFire(); } else { if(Level.TimeSeconds - LastBurstEndTime > BurstInterval) { NumFired = 0; } } } } } simulated function bool BarrelsAreFacingTarget() { return true; } /** * Actually fire the gun. * * @network Server. */ function DoFire() { local Projectile NewProj; local vector SpawnLocation; local vector AimErrorVect; local float GravityZ; local vector TargetLocation; local float fTimeEnd; local vector NewVelocity; if(Role < Role_Authority || ProjectileType == none) { return; } SpawnLocation = Location; AimErrorVect = VRand() * AimError; TargetLocation = TargetPlayer.Location + AimErrorVect; NewProj = Spawn(ProjectileType ,,,SpawnLocation, Rotation); if(NewProj == none) { return; } fTimeEnd = ProjectileHangTime * ( 1.1/Level.TimeDilation ); GravityZ = PhysicsVolume.Gravity.Z; fTimeEnd = FMax( 0.0001f, fTimeEnd ); NewVelocity = ( TargetLocation - SpawnLocation ) / fTimeEnd; NewVelocity.z = ( ( TargetLocation.z - SpawnLocation.z ) - ( 0.5f * GravityZ * ( fTimeEnd*fTimeEnd ) ) ) / fTimeEnd; NewProj.Velocity = NewVelocity; NumFired ++ ; if(FiringSound != none) { PlaySound(FiringSound,SLOT_Misc,FiringSoundVolume,false,FiringSoundRadius,,false); } if(NumFired == NumProjectilesPerBurst) { LastBurstEndTime = Level.TimeSeconds; PendingClientStopAnim = true; PendingClientAnim = '' ; StopAnimating(); } else { // Play firing animation. PendingClientStopAnim = false; PendingClientAnim = FireAnimName; if(Level.NetMode != NM_DedicatedServer) { LoopAnim(PendingClientAnim,FireAnimRate,0.1,0); } } } // Triggering the Deck-gun actives it. function Trigger( Actor Other, Pawn EventInstigator ) { bActive = !bActive; if(!bActive) { DesiredRotation = InitialRotation; } } defaultproperties { BurstInterval=3.000000 ProjectileHangTime=3.000000 NumProjectilesPerBurst=9 ProjectileType=Class'FrightScript.DeckGunProjectile' FireAnimName="Fire" FireAnimRate=2.000000 MaxAggroRange=5000.000000 FiringSoundVolume=2.000000 FiringSoundRadius=1000.000000 DrawType=DT_Mesh bNoDelete=True bAlwaysRelevant=True Physics=PHYS_Rotating RemoteRole=ROLE_SimulatedProxy NetUpdateFrequency=8.000000 Mesh=SkeletalMesh'FrightYard_SKM.DeckGunSKM' bNetNotify=True bRotateToDesired=True RotationRate=(Yaw=15000) bDirectional=True } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |