<commit_before>// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.

#include "SuperTimeCommando.h"
#include "SuperTimeCommandoPlayerController.h"
#include "AI/Navigation/NavigationSystem.h"
#include "Runtime/Engine/Classes/Components/DecalComponent.h"
#include "Kismet/HeadMountedDisplayFunctionLibrary.h"
#include "SuperTimeCommandoCharacter.h"
#include "SuperTimeCommandoGameState.h"
#include "ActorHistory.h"

ASuperTimeCommandoPlayerController::ASuperTimeCommandoPlayerController()
{
	ActorHistory = CreateDefaultSubobject<UActorHistory>(TEXT("ActorHistory"));
	ActorHistory->SetupAttachment(RootComponent);

	bShowMouseCursor = true;
	DefaultMouseCursor = EMouseCursor::Crosshairs;
}

void ASuperTimeCommandoPlayerController::BeginPlay()
{
	GameState = GetWorld()->GetGameState<ASuperTimeCommandoGameState>();
	ActorHistory->Checkpoints.Add(FCheckpoint(Spawn, GetWorld()->GetTimeSeconds(), GetPawn()->GetActorLocation()));
	bHasMoved = true;
}

void ASuperTimeCommandoPlayerController::PlayerTick(float DeltaTime)
{
	Super::PlayerTick(DeltaTime);

	if (GameState->bIsTimeBackward)
	{
		if (ActorHistory->Checkpoints.Num() > 0 && ActorHistory->Checkpoints.Top().CheckpointType == Checkpoint)
		{
			FCheckpoint Checkpoint = ActorHistory->Checkpoints.Pop();
			//GetPawn()->SetActorLocation(Checkpoint.Location);
			// This looks better
			GetPawn()->AddMovementInput(Checkpoint.Location - GetPawn()->GetActorLocation(), 1.f);
		}
	}
	else
	{
		if (bHasMoved)
		{
			ActorHistory->Checkpoints.Push(FCheckpoint(Checkpoint, GetWorld()->GetTimeSeconds(), GetPawn()->GetActorLocation()));
			bHasMoved = false;
		}
	}
}

void ASuperTimeCommandoPlayerController::SetupInputComponent()
{
	// set up gameplay key bindings
	Super::SetupInputComponent();

	// Movement
	InputComponent->BindAxis("MoveForward", this, &ASuperTimeCommandoPlayerController::MoveForward);
	InputComponent->BindAxis("MoveRight", this, &ASuperTimeCommandoPlayerController::MoveRight);

	// Time rewind<commit_msg>Player movement improved<commit_after>// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.

#include "SuperTimeCommando.h"
#include "SuperTimeCommandoPlayerController.h"
#include "AI/Navigation/NavigationSystem.h"
#include "Runtime/Engine/Classes/Components/DecalComponent.h"
#include "Kismet/HeadMountedDisplayFunctionLibrary.h"
#include "SuperTimeCommandoCharacter.h"
#include "SuperTimeCommandoGameState.h"
#include "ActorHistory.h"

ASuperTimeCommandoPlayerController::ASuperTimeCommandoPlayerController()
{
	ActorHistory = CreateDefaultSubobject<UActorHistory>(TEXT("ActorHistory"));
	ActorHistory->SetupAttachment(RootComponent);

	bShowMouseCursor = true;
	DefaultMouseCursor = EMouseCursor::Crosshairs;
}

void ASuperTimeCommandoPlayerController::BeginPlay()
{
	GameState = GetWorld()->GetGameState<ASuperTimeCommandoGameState>();
	ActorHistory->Checkpoints.Add(FCheckpoint(Spawn, GetWorld()->GetTimeSeconds(), GetPawn()->GetActorLocation()));
	bHasMoved = true;
}

void ASuperTimeCommandoPlayerController::PlayerTick(float DeltaTime)
{
	Super::PlayerTick(DeltaTime);

	if (GameState->bIsTimeBackward)
	{
		if (ActorHistory->Checkpoints.Num() > 0 && ActorHistory->Checkpoints.Top().CheckpointType == Checkpoint)
		{
			FCheckpoint Checkpoint = ActorHistory->Checkpoints.Pop();
			// This looks better than just SetActorLocation
			FVector Movement = Checkpoint.Location - GetPawn()->GetActorLocation();
			GetPawn()->AddMovementInput(Movement, 1.f);
			// If is so far thus teleport
			if (Movement.Size() > 100)
			{
				GetPawn()->SetActorLocation(Checkpoint.Location);
			}
		}
	}
	else
	{
		if (bHasMoved)
		{
			ActorHistory->Checkpoints.Push(FCheckpoint(Checkpoint, GetWorld()->GetTimeSeconds(), GetPawn()->GetActorLocation()));
			bHasMoved = false;
		}
	}
}

void ASuperTimeCommandoPlayerController::SetupInputComponent()
{
	// set up gameplay key bindings
	Super::SetupInputComponent();

	// Movement
	InputComponent->BindAxis("MoveForward", this, &ASuperTimeCommandoPlayerController::MoveForward);
	InputComponent->BindAxis("MoveRight", this, &ASuperTimeCommandoPlayerController::MoveRight);

	// Time rewind
{'fraction_non_alphanumeric': 0.12748424624333496, 'fraction_numerical': 0.005574406204556471, 'mean_word_length': 7.1561264822134385, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5935082', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1241, 'n_words': 192}