Ejemplo n.º 1
0
FText FFlareTransactionLogEntry::GetComment(AFlareGame* Game) const
{
	FText Comment;


//	FLOGV("--- Type %d", int(Type));
//	FLOGV("  Spacecraft %s", *Spacecraft.ToString());
//	FLOGV("  Sector %s", *Sector.ToString());
//	FLOGV("  ExtraIdentifier1 %s", *ExtraIdentifier1.ToString());
//	FLOGV("  ExtraIdentifier2 %s", *ExtraIdentifier2.ToString());


	UFlareSimulatedSpacecraft* SpacecraftCache = nullptr;
	FFlareResourceDescription* ResourceCache = nullptr;

	if(Spacecraft != NAME_None)
	{
		SpacecraftCache = Game->GetGameWorld()->FindSpacecraft(Spacecraft);
	}

	if(Resource != NAME_None)
	{
		ResourceCache = Game->GetResourceCatalog()->Get(Resource);
	}

	auto FindFactoryDescription = [](UFlareSimulatedSpacecraft* SpacecraftWithFactory, FName Identifier) -> FFlareFactoryDescription const*
	{
		for(UFlareFactory* Factory : SpacecraftWithFactory->GetFactories())
		{
			FFlareFactoryDescription const* FactoryDescription = Factory->GetDescription();
			if(FactoryDescription->Identifier == Identifier)
			{
				return FactoryDescription;
			}
		}
		return nullptr;
	};

	auto GetFactoryName = [this, &SpacecraftCache, &FindFactoryDescription]()
	{
		FFlareFactoryDescription const* FactoryDescription = FindFactoryDescription(SpacecraftCache, ExtraIdentifier1);

		if(FactoryDescription)
		{
			return FactoryDescription->Name;
		}

		return FText();
	};


	auto IsAITransaction = [](UFlareSimulatedSpacecraft* SpacecraftCache, UFlareSimulatedSpacecraft* OtherSpacecraftCache)
	{
		if(SpacecraftCache && OtherSpacecraftCache)
		{
			if((!SpacecraftCache->IsStation() && !SpacecraftCache->GetCompany()->IsPlayerCompany()) || (!OtherSpacecraftCache->IsStation() && !OtherSpacecraftCache->GetCompany()->IsPlayerCompany()))
			{
				return true;
			}
		}
		return false;
	};


	switch(Type)
	{
	case EFlareTransactionLogEntry::ManualResourcePurchase:
	{
		UFlareSimulatedSpacecraft* OtherSpacecraftCache = Game->GetGameWorld()->FindSpacecraft(ExtraIdentifier1);

		if(OtherSpacecraftCache && ResourceCache)
		{
			FText ResourceComment = FText::Format(LOCTEXT("ManualResourcePurchaseResources", "{0} {1}"), ResourceQuantity, ResourceCache->Name);

			if(IsAITransaction(SpacecraftCache, OtherSpacecraftCache))
			{
				Comment = FText::Format(LOCTEXT("AIManualResourcePurchase", "{0} sold {1} with {2}"), OtherSpacecraftCache->GetCompany()->GetCompanyName(), ResourceComment, UFlareGameTools::DisplaySpacecraftName(OtherSpacecraftCache));
			}
			else
			{
				Comment = FText::Format(LOCTEXT("ManualResourcePurchase", "Bought {0} from {1}"), ResourceComment, UFlareGameTools::DisplaySpacecraftName(OtherSpacecraftCache));
			}
		}
		break;
	}
	case EFlareTransactionLogEntry::ManualResourceSell:
	{
		UFlareSimulatedSpacecraft* OtherSpacecraftCache = Game->GetGameWorld()->FindSpacecraft(ExtraIdentifier1);

		if(OtherSpacecraftCache && ResourceCache)
		{
			FText ResourceComment = FText::Format(LOCTEXT("ManualResourceSellResources", "{0} {1}"), ResourceQuantity, ResourceCache->Name);

			if(IsAITransaction(SpacecraftCache, OtherSpacecraftCache))
			{
				Comment = FText::Format(LOCTEXT("AIManualResourceSell", "{0} bought {1} with {2}"), OtherSpacecraftCache->GetCompany()->GetCompanyName(), ResourceComment, UFlareGameTools::DisplaySpacecraftName(OtherSpacecraftCache));
			}
			else
			{
				Comment = FText::Format(LOCTEXT("ManualResourceSell", "Sold {0} to {1}"), ResourceComment, UFlareGameTools::DisplaySpacecraftName(OtherSpacecraftCache));
			}
		}
		break;
	}
	case EFlareTransactionLogEntry::TradeRouteResourcePurchase:
	{
		UFlareSimulatedSpacecraft* OtherSpacecraftCache = Game->GetGameWorld()->FindSpacecraft(ExtraIdentifier1);
		UFlareTradeRoute* TradeRouteCache = Game->GetGameWorld()->FindTradeRoute(ExtraIdentifier2);

		if(OtherSpacecraftCache && ResourceCache)
		{
			FText ResourceComment = FText::Format(LOCTEXT("TradeRouteResourcePurchaseComment", "{0} {1}"), ResourceQuantity, ResourceCache->Name);

			if(TradeRouteCache)
			{
				Comment = FText::Format(LOCTEXT("TradeRouteResourcePurchase", "Bought {0} from {1} on trade route {2}"), ResourceComment, UFlareGameTools::DisplaySpacecraftName(OtherSpacecraftCache), TradeRouteCache->GetTradeRouteName());
			}
			else
			{
				Comment = FText::Format(LOCTEXT("NotTradeRouteResourcePurchase", "Bought {0} from {1} on an old trade route"), ResourceComment, UFlareGameTools::DisplaySpacecraftName(OtherSpacecraftCache));
			}
		}
		break;
	}
	case EFlareTransactionLogEntry::TradeRouteResourceSell:
	{
		UFlareSimulatedSpacecraft* OtherSpacecraftCache = Game->GetGameWorld()->FindSpacecraft(ExtraIdentifier1);
		UFlareTradeRoute* TradeRouteCache = Game->GetGameWorld()->FindTradeRoute(ExtraIdentifier2);

		if(OtherSpacecraftCache && ResourceCache)
		{
			FText ResourceComment = FText::Format(LOCTEXT("TradeRouteResourceSellResources", "{0} {1}"), ResourceQuantity, ResourceCache->Name);

			if(TradeRouteCache)
			{
				Comment = FText::Format(LOCTEXT("TradeRouteResourceSell", "Sold {0} to {1} on trade route {2}"), ResourceComment, UFlareGameTools::DisplaySpacecraftName(OtherSpacecraftCache), TradeRouteCache->GetTradeRouteName());
			}
			else
			{
				Comment = FText::Format(LOCTEXT("NotTradeRouteResourceSell", "Sold {0} to {1} on an old trade route"), ResourceComment, UFlareGameTools::DisplaySpacecraftName(OtherSpacecraftCache));
			}
		}
		break;
	}
	case EFlareTransactionLogEntry::FactoryWages:
	{
		if(SpacecraftCache)
		{
			Comment = FText::Format(LOCTEXT("FactoryWages", "Factory wages for {0}"), GetFactoryName());
		}
		break;
	}
	case EFlareTransactionLogEntry::CancelFactoryWages:
	{
		if(SpacecraftCache)
		{
			Comment = FText::Format(LOCTEXT("CancelFactoryWages", "Cancelled factory wages for {0}"), GetFactoryName());
		}
		break;
	}
	case EFlareTransactionLogEntry::StationConstructionFees:
	{
		FFlareSpacecraftDescription* Description = Game->GetSpacecraftCatalog()->Get(ExtraIdentifier1);

		if(Description)
		{
			Comment = FText::Format(LOCTEXT("StationConstructionFees", "Contruction fees for {0}"), Description->Name);
		}
		break;
	}
	case EFlareTransactionLogEntry::StationUpgradeFees:
	{
		Comment = LOCTEXT("StationUpgradeFees", "Station upgrade fees");
		break;
	}
	case EFlareTransactionLogEntry::CancelStationUpgradeFees:
	{
		Comment = LOCTEXT("CancelStationUpgradeFees", "Cancelled station upgrade fees");
		break;
	}
	case EFlareTransactionLogEntry::UpgradeShipPart:
	{
		Comment = LOCTEXT("UpgradeShipFees", "Upgrade ship fees");
		break;
	}
	case EFlareTransactionLogEntry::OrderShip:
	{
		FFlareSpacecraftDescription* Description = Game->GetSpacecraftCatalog()->Get(ExtraIdentifier1);
		if(Description)
		{
			Comment = FText::Format(LOCTEXT("OrderShip", "Ordered ship ({0}})"), Description->Name);
		}
		break;
	}
	case EFlareTransactionLogEntry::CancelOrderShip:
	{
		FFlareSpacecraftDescription* Description = Game->GetSpacecraftCatalog()->Get(ExtraIdentifier1);
		if(Description)
		{
			Comment = FText::Format(LOCTEXT("CancelOrderShip", "Cancelled ship order ({0}})"), Description->Name);
		}
		break;
	}
	case EFlareTransactionLogEntry::OrderShipAdvance:
	{
		FFlareSpacecraftDescription* Description = Game->GetSpacecraftCatalog()->Get(ExtraIdentifier1);
		if(Description)
		{
			Comment = FText::Format(LOCTEXT("OrderShipAdvance", "Paid for ship order ({0}})"), Description->Name);
		}
		break;
	}
	case EFlareTransactionLogEntry::PeoplePurchase:
	{
		//UFlareSimulatedSpacecraft* OtherSpacecraftCache = Game->GetGameWorld()->FindSpacecraft(ExtraIdentifier1);

		if(ResourceCache)
		{
			FText ResourceComment = FText::Format(LOCTEXT("PeoplePurchaseResources", "{0} {1}"), ResourceQuantity, ResourceCache->Name);
			Comment = FText::Format(LOCTEXT("PeoplePurchase", "Population bought {0}"), ResourceComment);
		}
		break;
	}
	case EFlareTransactionLogEntry::InitialMoney:
	{
		Comment = LOCTEXT("InitialMoney", "Initial company capital");
		break;
	}
	case EFlareTransactionLogEntry::PayRepair:
	{
		Comment = FText::Format(LOCTEXT("PayRepair", "Spacecraft repairs ({0} fleet supply)"), ResourceQuantity);
		break;
	}
	case EFlareTransactionLogEntry::PayRefill:
	{
		Comment = FText::Format(LOCTEXT("PayRefill", "Weapons refilling ({0} fleet supply)"), ResourceQuantity);
		break;
	}
	case EFlareTransactionLogEntry::PaidForRepair:
	{
		Comment = FText::Format(LOCTEXT("PaidForRepair", "Paid for repairs ({0} fleet supply)"), ResourceQuantity);
		break;
	}
	case EFlareTransactionLogEntry::PaidForRefill:
	{
		Comment = FText::Format(LOCTEXT("PaidForRefill", "Paid for refilling ({0} fleet supply)"), ResourceQuantity);
		break;
	}
	case EFlareTransactionLogEntry::SendTribute:
	{
		Comment = LOCTEXT("SendTribute", "Paid tribute");
		break;
	}
	case EFlareTransactionLogEntry::ReceiveTribute:
	{
		Comment = LOCTEXT("ReceiveTribute", "Received tribute");
		break;
	}
	case EFlareTransactionLogEntry::RecoveryFees:
	{
		Comment = LOCTEXT("RecoveryFees", "Recovery fees");
		break;
	}
	case EFlareTransactionLogEntry::ScrapGain:
	{
		Comment = LOCTEXT("ScrapGain", "Scrap money");
		break;
	}
	case EFlareTransactionLogEntry::Cheat:
	{
		Comment = LOCTEXT("Cheat", "Unlawful transaction");
		break;
	}
	case EFlareTransactionLogEntry::QuestReward:
	{
		Comment = LOCTEXT("QuestReward", "Contract reward");
		break;
	}

	// AI only:
	// MutualAssistance,
	// ScrapCost

	default:

		Comment = FText::Format(LOCTEXT("Dummy", "Dummy comment {0}"), int(Type));
	}

	return Comment;
}