// Console commands of the cargo loop (DESIGN_UE.md section 9.3, M5): Descent.Cargo.SpawnBox, .Eject, Descent.Store.Give, Descent.Sell. #include "Debug/DescentCommandUtil.h" #include "Systems/DescentCargo.h" #include "TheDescent.h" #include "Engine/World.h" #include "HAL/IConsoleManager.h" namespace { void CmdCargoSpawnBox(const TArray& Args, UWorld* World) { UDescentCargoSubsystem* S = UDescentCargoSubsystem::Get(World); TArray N; const int32 Type = Args.Num() > 0 ? Descent::Cargo::OreTypeOf(FName(*Args[0].ToLower())) : -1; if (!S || Type < 0 || !Descent::Cmd::ParseNumbers(Args, 1, 1, N)) { Descent::Cmd::Fail(World, TEXT("Descent.Cargo.SpawnBox"), TEXT("usage: Descent.Cargo.SpawnBox [slot 0..3 | floor] (no slot: the lowest free outfeed slot)")); return; } int32 Slot = -1; if (Args.Num() > 2) { Slot = Args[2].Equals(TEXT("floor"), ESearchCase::IgnoreCase) ? -2 : FCString::Atoi(*Args[2]); } if (!S->SpawnBox(static_cast(Type), FMath::RoundToInt32(N[0]), Slot)) { Descent::Cmd::Fail(World, TEXT("Descent.Cargo.SpawnBox"), TEXT("no free place for the box")); } } void CmdCargoEject(const TArray&, UWorld* World) { UDescentCargoSubsystem* S = UDescentCargoSubsystem::Get(World); if (!S || !S->EjectPartials()) { Descent::Cmd::Fail(World, TEXT("Descent.Cargo.Eject"), TEXT("nothing to eject, or no free outfeed slot")); } } void CmdStoreGive(const TArray& Args, UWorld* World) { UDescentCargoSubsystem* S = UDescentCargoSubsystem::Get(World); TArray N; const int32 Type = Args.Num() > 0 ? Descent::Cargo::RefinedTypeOf(FName(*Args[0].ToLower())) : -1; if (!S || Type < 0 || !Descent::Cmd::ParseNumbers(Args, 1, 1, N)) { Descent::Cmd::Fail(World, TEXT("Descent.Store.Give"), TEXT("usage: Descent.Store.Give n")); return; } S->Refined[Type] = FMath::Max(0, S->Refined[Type] + FMath::RoundToInt32(N[0])); } void CmdSell(const TArray& Args, UWorld* World) { UDescentCargoSubsystem* S = UDescentCargoSubsystem::Get(World); bool bOk = false; if (S && Args.Num() > 0 && Args[0].StartsWith(TEXT("box:"))) { bOk = S->SellBox(FCString::Atoi(*Args[0].Mid(4))); } else if (S && Args.Num() > 1) { const int32 Type = Descent::Cargo::RefinedTypeOf(FName(*Args[0].ToLower())); bOk = Type >= 0 && S->SellRefined(static_cast(Type), FCString::Atoi(*Args[1])); } if (!bOk) { Descent::Cmd::Fail(World, TEXT("Descent.Sell"), TEXT("usage: Descent.Sell n or Descent.Sell box: (not enough in storage, or no such box)")); } } FAutoConsoleCommandWithWorldAndArgs GCargoCmdSpawnBox(TEXT("Descent.Cargo.SpawnBox"), TEXT("Descent.Cargo.SpawnBox [slot|floor]"), FConsoleCommandWithWorldAndArgsDelegate::CreateStatic(&CmdCargoSpawnBox)); FAutoConsoleCommandWithWorldAndArgs GCargoCmdEject(TEXT("Descent.Cargo.Eject"), TEXT("Descent.Cargo.Eject - push the partial boxes out of the packer"), FConsoleCommandWithWorldAndArgsDelegate::CreateStatic(&CmdCargoEject)); FAutoConsoleCommandWithWorldAndArgs GCargoCmdStoreGive(TEXT("Descent.Store.Give"), TEXT("Descent.Store.Give n - add refined goods to the storage"), FConsoleCommandWithWorldAndArgsDelegate::CreateStatic(&CmdStoreGive)); FAutoConsoleCommandWithWorldAndArgs GCargoCmdSell(TEXT("Descent.Sell"), TEXT("Descent.Sell n | box: - sell at the Tethys terminal"), FConsoleCommandWithWorldAndArgsDelegate::CreateStatic(&CmdSell)); }