Skip to content
This repository has been archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
Added Animation and sound hooks for chaning firemode
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyAwesome committed Nov 4, 2014
1 parent f4264c3 commit fdc613d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
51 changes: 32 additions & 19 deletions Source/Empires2/Private/BaseEmpiresWeapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
UBaseEmpiresWeapon::UBaseEmpiresWeapon(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{

GunOffset = FVector(100.0f, 30.0f, 10.0f);
ActiveFiremode = 0;

Expand All @@ -31,7 +31,7 @@ void UBaseEmpiresWeapon::PostInitProperties()
continue;
}
UBaseFiremode* firemode = ConstructObject<UBaseFiremode>(FiremodeClasses[i]);

firemode->SetWeapon(this);
Firemodes.Add(firemode);
}
Expand All @@ -48,14 +48,37 @@ void UBaseEmpiresWeapon::SetOwner(class AEmpires2Character* Owner)
OwningCharacter = Owner;
}

void UBaseEmpiresWeapon::PlaySound(USoundBase* Sound)
{
// try and play the sound if specified
if (Sound != nullptr)
{
UGameplayStatics::PlaySoundAtLocation(OwningCharacter, Sound, OwningCharacter->GetActorLocation());
}
}

void UBaseEmpiresWeapon::PlayAnimation(UAnimMontage* Animation)
{
// try and play a animation
if (Animation != nullptr)
{
// Get the animation object for the arms mesh
UAnimInstance* AnimInstance = OwningCharacter->Mesh1P->GetAnimInstance();
if (AnimInstance != nullptr)
{
AnimInstance->Montage_Play(Animation, 1.f);
}
}
}

/////////////////////FIRE CONTROL

bool UBaseEmpiresWeapon::CanFire()
{
UBaseFiremode* firemode = GetActiveFiremode();
if (firemode == nullptr) return false; //No active firemode
//TODO: Check if the firemode is capable of firing

return true;
}

Expand All @@ -81,7 +104,7 @@ void UBaseEmpiresWeapon::FireShot()

//Get the current firemode's projectile
FAmmoPool ammoPool = GetCurrentAmmoPool();

if (ammoPool.ProjectileClass == nullptr)
{
SCREENLOG(TEXT("Unable to fire Weapon %s, firemode %d because projectile is null!"), GetName(), ActiveFiremode);
Expand All @@ -102,23 +125,10 @@ void UBaseEmpiresWeapon::FireShot()
//And look at it go!
}

// try and play the sound if specified
if (FireSound != nullptr)
{
UGameplayStatics::PlaySoundAtLocation(OwningCharacter, FireSound, OwningCharacter->GetActorLocation());
}
PlaySound(FireSound);

// try and play a firing animation if specified
if (FireAnimation != nullptr)
{
PlayAnimation(FireAnimation);

// Get the animation object for the arms mesh
UAnimInstance* AnimInstance = OwningCharacter->Mesh1P->GetAnimInstance();
if (AnimInstance != nullptr)
{
AnimInstance->Montage_Play(FireAnimation, 1.f);
}
}
}

///////////////////////////////////// FIREMODES
Expand All @@ -128,6 +138,9 @@ void UBaseEmpiresWeapon::NextFiremode()
if (GetActiveFiremode()->IsFiring()) return; //Don't change modes if we are shooting
if (Firemodes.Num() == 1) return; //Don't change firemode if we only have one firemode

//Play the animation and sound for changing the firemode.
PlaySound(ChangeFiremodeSound);
PlayAnimation(ChangeFiremodeAnimation);

ActiveFiremode++;
if (ActiveFiremode >= Firemodes.Num())
Expand Down
12 changes: 12 additions & 0 deletions Source/Empires2/Public/BaseEmpiresWeapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ class EMPIRES2_API UBaseEmpiresWeapon : public UObject
UPROPERTY(EditDefaultsOnly, Category = Display)
USkeletalMesh* ViewModel;

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Display)
USoundBase* ChangeFiremodeSound;

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Display)
class UAnimMontage* ChangeFiremodeAnimation;

///////////////// HELPERS
public:
void PlaySound(USoundBase* Sound);

void PlayAnimation(UAnimMontage* Animation);


public:
class AEmpires2Character* OwningCharacter;
Expand Down

0 comments on commit fdc613d

Please sign in to comment.