#include "MovementArrow.h" #include "AdventureMap.h" // Sets default values AMovementArrow::AMovementArrow() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; SceneComponent = CreateDefaultSubobject(TEXT("Scene")); RootComponent = SceneComponent; MeshStraight = CreateDefaultSubobject(TEXT("Straight")); MeshRight = CreateDefaultSubobject(TEXT("Right")); MeshRightSharp = CreateDefaultSubobject(TEXT("RightSharp")); MeshLeftSharp = CreateDefaultSubobject(TEXT("LeftSharp")); MeshLeft = CreateDefaultSubobject(TEXT("Left")); MeshVariants.Add(MeshStraight); MeshVariants.Add(MeshRight); MeshVariants.Add(MeshRightSharp); MeshVariants.Add(MeshLeftSharp); MeshVariants.Add(MeshLeft); for (UStaticMeshComponent* Mesh : MeshVariants) { Mesh->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform); Mesh->ToggleVisibility(); } } void AMovementArrow::SetVariant(FHexVector InVec, FHexVector OutVec) { int32 InVecIndex = MapRef->UnitVectors.Find(InVec); SceneComponent->SetRelativeRotation(FRotator(0, InVecIndex * 60.f, 0)); int32 OutVecIndex = MapRef->UnitVectors.Find(OutVec); int32 BackMotion = (InVecIndex + 3) % 6; if (BackMotion < 0) { BackMotion = (((InVecIndex + 3) % 6) + 6) % 6; } // c++ modulus weirdness if (InVecIndex < BackMotion && OutVecIndex > BackMotion) { OutVecIndex--; } if (InVecIndex > BackMotion && OutVecIndex < BackMotion) { InVecIndex--; } int32 VariantIndex = (OutVecIndex - InVecIndex) % 5; if (VariantIndex < 0) { VariantIndex = ((OutVecIndex - InVecIndex) % 5 + 5) % 5; } // c++ modulus weirdness MeshVariants[VariantIndex]->ToggleVisibility(); } // Called when the game starts or when spawned void AMovementArrow::BeginPlay() { Super::BeginPlay(); } // Called every frame void AMovementArrow::Tick(float DeltaTime) { Super::Tick(DeltaTime); }