![]() |
Mortar Pro Plugin
Version 2
Modular Turret Plugin
|
#include <MortarProAimingComponent.h>
Public Member Functions | |
void | FireAt (const FVector &AimLocation, AActor *TargetActor, TArray< AActor * > SecondaryTargetsRef) |
void | GetAllFiringSocketsName (TArray< FName > &SocketsName) const |
EMortarProFiringState | GetCurrentState () const |
float | GetDirectionThresholdComparision () const |
void | GetFiringCountForAllSockets (TMap< FName, int32 > &PerSocketFireCount) const |
int32 | GetFiringCountForSocket (const FName &SocketName) const |
float | GetInitialIdleEventDelay () const |
void | GetProjectile (TMap< FName, FMortarProGunSocketProperties > &OutProjectiles) const |
float | GetShotsSpreadDegree () const |
bool | HasAmmo () const |
bool | HasUnlimitedAmmo () const |
void | InitializeAiming (class UMortarProTurretMeshComponent *TurretToSet, class UMortarProBarrelMeshComponent *BarrelToSet, AActor *Owner) |
bool | IsGunGravityEnabled () const |
bool | IsPredictTargetPositionEnabled () const |
virtual void | ResetAimingRunTimeParameters () |
void | SetDirectionThresholdComparision (const float &Threshold) |
void | SetFiringLeftForAllSockets (const TMap< FName, int32 > &PerSocketFireCount) |
void | SetFiringLeftForSocket (const FName &SocketName, const int32 &InFiringLeft) |
void | SetGunGravity (const bool &bGunGravity) |
void | SetIdle () |
void | SetInitialIdleEventDelay (const float &Delay) |
void | SetPredictTargetPosition (const bool &bEnable) |
void | SetProjectile (const TMap< FName, FMortarProGunSocketProperties > &ProjectileToSet) |
void | SetShotsSpreadDegree (const float &ShotsSpread) |
void | SetUnlimitedAmmo (const bool &bUnlimited) |
virtual void | StopComponent () |
UMortarProAimingComponent () | |
Public Attributes | |
FMortarProBeginAimingMovement | BeginAimingMovementTowardsTarget |
FMortarProBeginFire | BeginFire |
FMortarProBeginIdleState | BeginIdleState |
FMortarProEndAimingMovement | EndAimingMovementTowardsTarget |
FMortarProEndFiring | EndFiring |
FMortarProEndIdleState | EndIdleState |
Protected Member Functions | |
virtual void | BeginPlay () override |
virtual void | Fire () |
virtual void | FireProjectile () |
class UMortarProPoolSubsystem * | GetValidSubSystem () |
bool | IsMoving (const FVector &HitLocation) |
virtual void | SetBarrelState () |
virtual void | StopFiring () |
virtual void | TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override |
Protected Attributes | |
uint32 | bAmmoLeft: 1 |
class UMortarProBarrelMeshComponent * | Barrel = nullptr |
uint32 | bEnableGunGravity: 1 |
uint32 | bEnablePredictTargetPosition: 1 |
uint32 | bUnlimitedAmmo: 1 |
FVector | CurrentAimDirection |
EMortarProFiringState | CurrentFiringState |
FVector | CurrentHitTargetLocation |
FVector | DefaultAimLocation |
FName | DefaultSocketName |
class USoundBase * | FireSound |
float | InitialIdleEventDelay = 4.f |
float | LastFireTime = 0 |
class AActor * | OwnerActor |
FString | OwnerName |
TMap< FName, FMortarProGunSocketProperties > | ProjectileSpawnSockets |
float | ShotsSpreadDegree = 2.f |
TWeakObjectPtr< AActor > | TargetActor |
class UMortarProTurretMeshComponent * | Turret = nullptr |
Private Member Functions | |
void | CalculateAimDirection (FVector &AimDirection) |
void | CalculateTossVelocity (const float &OverrideGravityZ, const FName &SocketName) |
bool | CheckHasAmmoForAnySocket () const |
void | EmitEndMovementEvent () |
void | ExitFromIdleState () |
void | InitialIdleEventDelayTimer () |
bool | MoveTowards (const FVector &HitLocation) |
void | PredictTargetPosition (FVector &OriginalTargetLocation) |
Private Attributes | |
uint32 | bDrawDebugTargetSphere: 1 |
uint32 | bHasComponentInitialized: 1 |
uint32 | bInitialIdleEventWaitApplied: 1 |
uint32 | bOnEndMovementEventEmitted: 1 |
uint32 | bOnStartMovementEventEmitted: 1 |
TMap< FName, FMortarProGunSocketProperties > | DefaultProjectileSpawnSockets |
float | DirectionThresholdComparision = 0.05f |
float | DistanceThreshold = 5.f |
float | DrawTargetDebugSphereDuration = 1.f |
FTimerHandle | InitialIdleEventDelayTimerHandle |
float | MinSpeedThreshold = 0.5f |
FVector | OutLaunchVelocity |
class UMortarProPoolSubsystem * | PoolingSubSystem { nullptr } |
TWeakObjectPtr< AActor > | PreviousTargetActor |
FVector | PreviousTargetLocation = FVector::ZeroVector |
float | ProjectileSpeed = 0.f |
TArray< TWeakObjectPtr< AActor > > | SecondaryTargets |
FVector | TargetActorVelocity = FVector::ZeroVector |
float | TossVelocityArc = 0.75f |
float | VelocityThreshold = 5.f |
This component is responible for Aiming ,barrel and turret movement , And Firing .It is the base class of burst aiming and semi auto aiming component.
UMortarProAimingComponent::UMortarProAimingComponent | ( | ) |
|
overrideprotectedvirtual |
Function Called when game is starting
Reimplemented in UMortarProBurstAimingComponent, and UMortarProSemiAutoAimingComponent.
|
private |
Calculates Aim Direction. If Gravity is enabled it will give direction for arc else it will just return the current Aim Direction if gravity is not enabled
[out] | AimDirection | FVector type |
|
private |
Calculates Toss Velocity for gravity enabled projectiles.In case gravity is not enabled it is returned without any calculation
[in] | OverrideGravityZ | Gravity to consider while suggesting toss velocity. |
[in] | SocketName | Name of SOcket from which we consider firing |
|
private |
Check If there is ammo for any socket left
|
private |
Emits End Barrel/Turret Movement event
|
private |
Exits From Idle State by calling OnEndIdleStateEvent.if we have spawned projectile on idle event then here we want to deactivate it
|
protectedvirtual |
Function Called on each fire request. This should be defined in child classes to have custom fire behavior
Reimplemented in UMortarProBeamAimingComponent, UMortarProBurstAimingComponent, and UMortarProSemiAutoAimingComponent.
void UMortarProAimingComponent::FireAt | ( | const FVector & | AimLocation, |
AActor * | TargetActor, | ||
TArray< AActor * > | SecondaryTargetsRef | ||
) |
Checks if Mortar is able to aim and then moves mortar at the Desired Location And then Fires
[in] | AimLocation | Desired Aiming Location in FVector |
[in] | TargetActor | to hit |
[in] | SecondaryTargetsRef | Reference to secondary Targets |
|
protectedvirtual |
Function Called to spawn a projectile actor for each socket with each projectile have it's own speed. Defined as Virtual function to override the functionality in child classes
Reimplemented in UMortarProBurstAimingComponent.
void UMortarProAimingComponent::GetAllFiringSocketsName | ( | TArray< FName > & | SocketsName | ) | const |
Gets Barrel Firing Sockets Name param[out] Array of Sockets Name from which firing has tobe don
EMortarProFiringState UMortarProAimingComponent::GetCurrentState | ( | ) | const |
Gets The Current State of Gun
float UMortarProAimingComponent::GetDirectionThresholdComparision | ( | ) | const |
Gets comparision Threshold which is used to for comparing Aim Direction and Forward Vector of Gun
void UMortarProAimingComponent::GetFiringCountForAllSockets | ( | TMap< FName, int32 > & | PerSocketFireCount | ) | const |
Gets Total Firing Left for all sockets param[out] Map of Firing Count Which contains socket name for key and value as firing count for that socket
int32 UMortarProAimingComponent::GetFiringCountForSocket | ( | const FName & | SocketName | ) | const |
Gets Total Firing Left for a particular socket param[in] SocketName Name of socket for which we want firing count return FiringCount for the particular socket
float UMortarProAimingComponent::GetInitialIdleEventDelay | ( | ) | const |
Gets Initial Delay time(seconds) To Apply Before Going in Idle State.Idle State is when Mortar Pawn Can't find any target i.e when Fire Task Fail in Behavior Tree
void UMortarProAimingComponent::GetProjectile | ( | TMap< FName, FMortarProGunSocketProperties > & | OutProjectiles | ) | const |
Gets Projectile class for each socket param[out] Map of SocketName to actor
float UMortarProAimingComponent::GetShotsSpreadDegree | ( | ) | const |
Gets Shots Spread Range which is used while Firing.
|
protected |
Returns A Valid Subsystem For Pooling This also ensures that the subsystem is the blueprint one and not the cpp one return Pointer To SubSystem if valid nullptr otherwise
bool UMortarProAimingComponent::HasAmmo | ( | ) | const |
Checks whether there is ammo left to fire
bool UMortarProAimingComponent::HasUnlimitedAmmo | ( | ) | const |
Provides information whether there is limit on ammo
|
private |
Timer Function Called after we have applied Initial Delay. Only called once.
void UMortarProAimingComponent::InitializeAiming | ( | class UMortarProTurretMeshComponent * | TurretToSet, |
class UMortarProBarrelMeshComponent * | BarrelToSet, | ||
AActor * | Owner | ||
) |
Set Barrel reference
[in] | TurretToSet | Reference to Turret |
[in] | BarrelToSet | Reference to Barrel |
[in] | Owner | Reference to Owner who is having barrel and turret. |
bool UMortarProAimingComponent::IsGunGravityEnabled | ( | ) | const |
Gets if Gravity is enabled while firing
|
protected |
returns true if the barrel and Turret component is moving compares the barrel/Gun forward vector with Hitlocation
[in] | HitLocation | Target which we want to aim for |
bool UMortarProAimingComponent::IsPredictTargetPositionEnabled | ( | ) | const |
Gets if Target Position is enabled while firing
|
private |
Moves Barrel and Turret Towards HitLocation.
[in] | HitLocation | Location at which turret has to hit the target returns true if mortar pro pawn is locked on target. False otherwise |
|
private |
Predict Target Position if the target is moving
[in] | OriginalTargetLocation | Actual location of target |
|
virtual |
Resets Firing Parameters
Reimplemented in UMortarProBeamAimingComponent, UMortarProBurstAimingComponent, and UMortarProSemiAutoAimingComponent.
|
protectedvirtual |
Sets Barrel State based on Gun State whether ther is ammo left/or gun is moving or is locked on target Virtual Function that needs to be defined in child class
Reimplemented in UMortarProBeamAimingComponent, UMortarProBurstAimingComponent, and UMortarProSemiAutoAimingComponent.
void UMortarProAimingComponent::SetDirectionThresholdComparision | ( | const float & | Threshold | ) |
Sets comparision Threshold which is used to for comparing Aim Direction and Forward Vector of Gun
[in] | Threshold | limit for comparing Aim Direction and Forward Vector of Gun in float |
void UMortarProAimingComponent::SetFiringLeftForAllSockets | ( | const TMap< FName, int32 > & | PerSocketFireCount | ) |
Sets Firing Count for all the sockets
[in] | PerSocketFireCount | Count Map Containing fire count for each socket. Key = SocketName Value = Firing Count |
void UMortarProAimingComponent::SetFiringLeftForSocket | ( | const FName & | SocketName, |
const int32 & | InFiringLeft | ||
) |
Sets Firing Count for a particular socket
[in] | SocketName | Name of the socket for which we want to set the count |
[in] | InFiringLeft | Total Fire Count for the socket |
void UMortarProAimingComponent::SetGunGravity | ( | const bool & | bGunGravity | ) |
Sets Gravity for Gun . This only helps in taking Gravity in account while firing and doesn't enable/disable actual gravity of gun
[in] | bGunGravity | Gravity for GUn |
void UMortarProAimingComponent::SetIdle | ( | ) |
Sets Position of barrel to default aim location
void UMortarProAimingComponent::SetInitialIdleEventDelay | ( | const float & | Delay | ) |
Sets Initial Delay time(seconds) To Apply Before Going in Idle State.Idle State is when Mortar Pawn Can't find any target i.e when Fire Task Fail in Behavior Tree.
[in] | Delay | float Variable containing delay time |
void UMortarProAimingComponent::SetPredictTargetPosition | ( | const bool & | bEnable | ) |
Sets whether to predict target position based on movement
[in] | bEnable | true to enable prediction false otherwise |
void UMortarProAimingComponent::SetProjectile | ( | const TMap< FName, FMortarProGunSocketProperties > & | ProjectileToSet | ) |
Sets Projectile Class that needs to be spawned.On special event Mortar Can have different projectile
[in] | ProjectileToSet | Projectile to spawn of Class Projectile |
void UMortarProAimingComponent::SetShotsSpreadDegree | ( | const float & | ShotsSpread | ) |
Sets Shots Spread Range
[in] | ShotsSpread | Shots Spread In Degree |
void UMortarProAimingComponent::SetUnlimitedAmmo | ( | const bool & | bUnlimited | ) |
Sets whether mortar is having unlimited ammo
[in] | bUnlimited | boolean flag true if unlimited ammo false otherwise |
|
virtual |
Function called to stop Component.Stops Firing and other timers. Emits any pending events
Reimplemented in UMortarProBurstAimingComponent.
|
protectedvirtual |
Function called to stop Firing. Broadcasts EndFiring Event as well
Reimplemented in UMortarProBeamAimingComponent, and UMortarProBurstAimingComponent.
|
overrideprotectedvirtual |
Function Called on Every Tick
Reimplemented in UMortarProBurstAimingComponent.
|
protected |
Stores boolean value telling if event for start barrel movement towards target has been called once
|
protected |
Barrel/Gun Class to Use Moves Vertically(Pitch)
|
private |
Flag to Enable Debug Drawing of Sphere which is drawn at position where mortar pawn will shoot
FMortarProBeginAimingMovement UMortarProAimingComponent::BeginAimingMovementTowardsTarget |
Event Called on barrel and Turret movement starting when it is moving towards target
FMortarProBeginFire UMortarProAimingComponent::BeginFire |
Event Called Just After Spawning a Projectile actor
FMortarProBeginIdleState UMortarProAimingComponent::BeginIdleState |
Event Called when mortar gun is not moving and not locked on target is in idle state
|
protected |
Whether to take Gravity in Account This will be used while aiming
|
protected |
Whether to predict target poisition when it is moving
|
private |
Flag to track whether shooting type and other parameters have been set properly
|
private |
Flag denoting whether we have applied Initial Delay for Idle event. This flag gets reset when we exit from idle state By default it is set to false
|
private |
Stores boolean value telling if event for barrel movement towards target completed has been called once
|
private |
Stores boolean value telling if event for start barrel movement towards target has been called once
|
protected |
Allow Unlimited Firing
|
protected |
Current Aim Direction of barrel
|
protected |
Tracks the state of gun like whether it is reloading,firing,burst firing etc
|
protected |
Current Location of Target
|
protected |
Default Aim Location of Barrel
|
private |
Stores Default Projectile Spawn Sockets Details. It comes in handy while resetting
|
protected |
Name of 1st Socket
|
private |
This is used to for comparing Aim Direction and Forward Vector of Gun To check if they are in same direction
|
private |
Threshold for Distance by which we can be sure that two position are distant apart
|
private |
Duration of Draw sphere at target
FMortarProEndAimingMovement UMortarProAimingComponent::EndAimingMovementTowardsTarget |
Event Called when Barrel and Turret has completed its movement towards target
FMortarProEndFiring UMortarProAimingComponent::EndFiring |
FMortarProEndIdleState UMortarProAimingComponent::EndIdleState |
Event Called when mortar gun is ready to move/engage and ending its idle state
|
protected |
Sound Played on Each Mortar Firing
|
protected |
Initial Delay time (seconds) To Apply Before Going in Idle State. Idle State is when Mortar Pawn Can't find any target i.e when Fire Task Fail in Behavior Tree.Minimum clamped to 0
|
private |
Timer handle for Initial Delay for Idle Event
|
protected |
Stores Last Firing Time
|
private |
Min Threshold of speed for target below which target is considered stationary.
|
private |
Toss Velocity for projectile. Used in case of gravity
|
protected |
Reference to Owner Actor
|
protected |
Name of Owner
|
private |
Pooling Subsystem. It stores the reference to the pooling subsystem Whenever a projectile is initilzied we add it into pool and on destroy we remove it from pool
|
private |
Reference for Previous target Actor
|
private |
Previous Target Actor Location
|
protected |
This is a map of Socket Name To Projectile Telling Which socket has to Fire which projectile
|
private |
Speed of projectile.
|
private |
Contains Reference to Secondary Targets
|
protected |
How much shots can Be Spread in Degrees Shots Spread Range between 0 to ShotsSpreadDegree inclusive. Lies Between 0 and 180
|
protected |
Reference for target Actor
|
private |
Target Velocity of current Target Actor
|
private |
Arc to choose while calculating toss velocity
|
protected |
Turret to use which moves Horizontally(Yaw)
|
private |
Threshold for velocity by which we can be sure that actor is moving