Skip to content

Commit

Permalink
#209 Fixed code bugs to add simple bots (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
xthebat authored Feb 23, 2024
1 parent f77f5d6 commit 91ad7bd
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 7 deletions.
Binary file modified Content/Characters/Blueprints/BP_Cloud9Character.uasset
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/Cloud9/Character/Cloud9Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void ACloud9Character::Tick(float DeltaSeconds)
Super::Tick(DeltaSeconds);

// Auto select any available weapon if nothing selected
if (not Inventory->GetSelectedWeapon())
if (not Inventory->GetSelectedWeapon() and not Inventory->IsEmpty())
{
Inventory->SelectOtherAvailableWeapon(false);
}
Expand Down
5 changes: 5 additions & 0 deletions Source/Cloud9/Character/Components/Cloud9Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
UCloud9Inventory::UCloud9Inventory()
{
SelectedWeaponSlot = EWeaponSlot::NotSelected;
WeaponsCount = 0;

let SlotsNumber = StaticEnum<EWeaponSlot>()->NumEnums();
WeaponSlots.SetNum(SlotsNumber);
Expand Down Expand Up @@ -264,6 +265,7 @@ bool UCloud9Inventory::AddWeapon(const FWeaponConfig& Config, bool Select, bool

log(Display, "[Inventory='%s'] Added configured weapon = '%s'", *GetName(), *Config.ToString());

WeaponsCount++;
OnWeaponAddDelegate.Broadcast(Weapon);
return true;
}
Expand Down Expand Up @@ -296,10 +298,13 @@ bool UCloud9Inventory::RemoveWeapon(EWeaponSlot Slot)
WeaponAt(Slot)->Destroy();
WeaponAt(Slot) = nullptr;

WeaponsCount--;
OnWeaponRemoveDelegate.Broadcast();
return true;
}

bool UCloud9Inventory::IsEmpty() const { return WeaponsCount == 0; }

bool UCloud9Inventory::SelectOtherAvailableWeapon(bool Instant, bool Force)
{
EWeaponSlot NewSlot = EWeaponSlot::NotSelected;
Expand Down
8 changes: 7 additions & 1 deletion Source/Cloud9/Character/Components/Cloud9Inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class CLOUD9_API UCloud9Inventory
UFUNCTION(BlueprintCallable)
bool RemoveWeapon(EWeaponSlot Slot);

UFUNCTION(BlueprintCallable)
bool IsEmpty() const;

UFUNCTION(BlueprintCallable)
ACloud9WeaponBase* GetSelectedWeapon() const;

Expand All @@ -127,12 +130,15 @@ class CLOUD9_API UCloud9Inventory
UPROPERTY(BlueprintAssignable, meta=(AllowPrivateAccess), Category=Events)
FOnWeaponSwitchDelegate OnWeaponSwitchDelegate;

UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess), Category=State)
int WeaponsCount;

template <typename WeaponType = ACloud9WeaponBase>
WeaponType* WeaponAt(EWeaponSlot Slot) const { return WeaponSlots[Slot | EUEnum::To<int>{}]; }

template <typename WeaponType = ACloud9WeaponBase>
WeaponType*& WeaponAt(EWeaponSlot Slot) { return WeaponSlots[Slot | EUEnum::To<int>{}]; }

private:
bool SelectWeaponImpl(EWeaponSlot Slot, bool Instant, bool Force);

Expand Down
3 changes: 3 additions & 0 deletions Source/Cloud9/Cloud9.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@

#include "CoreMinimal.h"

// TODO: should be reworked somehow ... TRACE_CHANNEL
#define TRACE_CHANNEL ECC_PhysicsBody

DECLARE_LOG_CATEGORY_EXTERN(LogCloud9, Log, All);
2 changes: 1 addition & 1 deletion Source/Cloud9/Contollers/Cloud9MouseController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void UCloud9MouseController::ProcessCharacterView() const
{
FHitResult TraceHitResult;
let bIsHitValid = Controller->GetHitResultUnderCursor(
ECC_Visibility,
TRACE_CHANNEL,
true,
TraceHitResult);
Pawn->SetViewDirection(TraceHitResult, bIsHitValid);
Expand Down
5 changes: 5 additions & 0 deletions Source/Cloud9/Environment/Cloud9ShootingRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ FName ACloud9ShootingRange::WidgetComponentName = "WidgetComponentName";

ACloud9ShootingRange::ACloud9ShootingRange()
{
// Disable collision to remove firearms hit screen
SetActorEnableCollision(false);
PrimaryActorTick.bCanEverTick = true;
ZoneComponent = CreateDefaultSubobject<UBoxComponent>(ZoneComponentName);
WidgetComponent = CreateDefaultSubobject<UWidgetComponent>(WidgetComponentName);
Expand Down Expand Up @@ -44,6 +46,9 @@ void ACloud9ShootingRange::OnConstruction(const FTransform& Transform)
WidgetComponent->SetWidgetClass(WidgetClass);
WidgetComponent->SetRelativeRotation({0.0f, 90.0f, 0.0f});
WidgetComponent->SetDrawSize({ZoneSize.X * 2.0f, ZoneSize.Z * 2.0f});
// Not work's quit well (currently disable all collision in constructor)
// But required for future to make possible for shooting range configuration
WidgetComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}

void ACloud9ShootingRange::BeginPlay()
Expand Down
4 changes: 2 additions & 2 deletions Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ EFirearmFireStatus ACloud9WeaponFirearm::Fire(
EjectCase();

FHitResult CursorHit;
if (not Controller->GetHitResultUnderCursor(ECC_Visibility, true, CursorHit))
if (not Controller->GetHitResultUnderCursor(TRACE_CHANNEL, true, CursorHit))
{
log(Error, "Cursor not hit anything")
return EFirearmFireStatus::Success;
Expand All @@ -333,7 +333,7 @@ EFirearmFireStatus ACloud9WeaponFirearm::Fire(
LineHit,
StartLocation,
EndLocation,
ECC_Visibility,
TRACE_CHANNEL,
CollisionParams);

if (Settings->bIsPrintHitScanInfo)
Expand Down
4 changes: 2 additions & 2 deletions Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ bool ACloud9WeaponGrenade::OnGrenadeActionLoop()
this,
InstigatorController,
false,
ECC_Visibility);
TRACE_CHANNEL);
Explosion->FireImpulse();

if (let ExplodeSounds = GetWeaponInfo()->Sounds.ExplodeSounds; ExplodeSounds.Num() > 0)
Expand Down Expand Up @@ -387,7 +387,7 @@ bool ACloud9WeaponGrenade::Throw() const
}

FHitResult CursorHit;
if (not Controller->GetHitResultUnderCursor(ECC_Visibility, true, CursorHit))
if (not Controller->GetHitResultUnderCursor(TRACE_CHANNEL, true, CursorHit))
{
log(Error, "[Weapon='%s'] Cursor not hit anything", *GetName());
return false;
Expand Down

0 comments on commit 91ad7bd

Please sign in to comment.