// Descent.Player.Intent: the debug override of the intent latch (DESIGN_UE.md sections 5.7 and 9.2). // It lives here, with the sim core that owns the latch, and not in the player track's commands file, so the // player track can add Descent.Player.Place / MoveTo / Look / ... in DescentCommands_Player.cpp without a clash. #include "Core/DescentIntent.h" #include "Core/DescentSimSubsystem.h" #include "Debug/DescentCommandUtil.h" #include "TheDescent.h" #include "HAL/IConsoleManager.h" namespace { void CmdPlayerIntent(const TArray& Args, UWorld* World) { static const TCHAR* Usage = TEXT("usage: Descent.Player.Intent fwd right up lookYawDps lookPitchDps seconds [primary] [secondary] [sprint] (fwd/right/up -1..1, look in degrees per second, seconds of SIM time; flags 0 or 1)"); UDescentSimSubsystem* Sim = UDescentSimSubsystem::Get(World); TArray N; if (!Sim || !Descent::Cmd::ParseNumbers(Args, 0, 6, N) || N[5] < 0.0) { Descent::Cmd::Fail(World, TEXT("Descent.Player.Intent"), Usage); return; } auto Flag = [&Args](int32 Index, bool& bOut) -> bool { bOut = false; if (Args.Num() <= Index) { return true; } bool bValid = false; bOut = Descent::Cmd::ParseBool(Args[Index], bValid); return bValid; }; FDescentIntent Intent; Intent.Move = FVector(N[0], N[1], N[2]); Intent.Look = FVector2D(N[3], N[4]); if (!Flag(6, Intent.bPrimary) || !Flag(7, Intent.bSecondary) || !Flag(8, Intent.bSprint)) { Descent::Cmd::Fail(World, TEXT("Descent.Player.Intent"), Usage); return; } // The vertical axis is also the jump / crouch key pair, so a held "up" drives both the swim axis and a jump. Intent.bJump = N[2] > 0.5; Intent.bDown = N[2] < -0.5; Sim->SetDebugIntent(Intent, N[5]); UE_LOG(LogDescent, Display, TEXT("Player.Intent: holding move (%.2f, %.2f, %.2f) look (%.1f, %.1f) deg/s for %.2f s of sim time"), N[0], N[1], N[2], N[3], N[4], N[5]); } FAutoConsoleCommandWithWorldAndArgs GIntentCmdPlayerIntent( TEXT("Descent.Player.Intent"), TEXT("Descent.Player.Intent fwd right up lookYawDps lookPitchDps seconds [primary] [secondary] [sprint] - hold an intent for a sim duration; it wins over the live input"), FConsoleCommandWithWorldAndArgsDelegate::CreateStatic(&CmdPlayerIntent)); }