Exemple #1
0
void fibre_schedule_to(struct fibre *f)
{
	FCHECK(tls_fibre.sstack);
	FCHECK(fibre_can_switch_explicit());
	FCHECK(!(f->flags & FIBRE_FLAGS_COMPLETED));
	tls_fibre.sstack->vtable->schedule(tls_fibre.sstack->vtable_data, f);
}
Exemple #2
0
void UFlareFactory::Simulate()
{
	FCHECK(Parent);
	FCHECK(Parent->GetCurrentSector());
	FCHECK(Parent->GetCurrentSector()->GetPeople());

	if (!FactoryData.Active)
	{
		goto post_prod;
	}


	// Check if production is running
	if (!IsNeedProduction())
	{
		// Don't produce if not needed
		goto post_prod;
	}

	if (HasCostReserved())
	{

		if (FactoryData.ProductedDuration < GetProductionTime(GetCycleData()))
		{
			FactoryData.ProductedDuration += 1;
		}

		if (FactoryData.ProductedDuration < GetProductionTime(GetCycleData()))
		{

			// Still In production
			goto post_prod;
		}

		if (!HasOutputFreeSpace())
		{
			// TODO display warning to user
			// No free space wait.
			goto post_prod;
		}

		DoProduction();

	}
	TryBeginProduction();

	if (GetProductionTime(GetCycleData()) == 0  && HasCostReserved())
	{
		DoProduction();
	}


post_prod:

	if (FactoryDescription->VisibleStates)
	{
		UpdateDynamicState();
	}
}
Exemple #3
0
void fibre_finish(void)
{
	FCHECK(tls_fibre.inited);
	FCHECK(!tls_fibre.sstack);
	FCHECK(!tls_fibre.async_atomic);
	fibre_arch_finish();
	tls_fibre.inited = 0;
}
Exemple #4
0
static void fibre_bootstrap(void)
{
	struct fibre *f = fibre_get_current();
	FCHECK(f);
	FCHECK(!(f->flags & FIBRE_FLAGS_STARTED));
	FCHECK(!(f->flags & FIBRE_FLAGS_COMPLETED));
	f->flags |= FIBRE_FLAGS_STARTED;
	f->fn(f->fn_arg);
	f->flags |= FIBRE_FLAGS_COMPLETED;
	fibre_schedule();
	FCHECK(NULL == "Should never reach here!");
}
Exemple #5
0
int fibre_async_suspend_poll(void)
{
	struct fibre *f;
	FCHECK(fibre_async_can_suspend(FIBRE_ASYNC_POLL));
	f = fibre_get_current();
	FCHECK(!f->async);
	f->async = FIBRE_ASYNC_POLL;
	f->async_abort = 0;
	fibre_schedule();
	f->async = 0;
	return f->async_abort ? -EINTR : 0;
}
Exemple #6
0
int fibre_async_suspend_fd_readable(int fd)
{
	struct fibre *f;
	FCHECK(fibre_async_can_suspend(FIBRE_ASYNC_FD_READABLE));
	f = fibre_get_current();
	FCHECK(!f->async);
	f->async = FIBRE_ASYNC_FD_READABLE;
	f->async_fd_readable.fd = fd;
	f->async_abort = 0;
	fibre_schedule();
	f->async = 0;
	return f->async_abort ? -EINTR : 0;
}
Exemple #7
0
int fibre_async_suspend_use_cb(void *arg, int (*cb)(void *))
{
	struct fibre *f;
	FCHECK(fibre_async_can_suspend(FIBRE_ASYNC_CHECK_CB));
	f = fibre_get_current();
	FCHECK(!f->async);
	f->async = FIBRE_ASYNC_CHECK_CB;
	f->async_check_cb.cb_arg = arg;
	f->async_check_cb.cb = cb;
	f->async_abort = 0;
	fibre_schedule();
	f->async = 0;
	return f->async_abort ? -EINTR : 0;
}
Exemple #8
0
FText UFlareFactory::GetFactoryCycleCost(const FFlareProductionData* Data)
{
	FText ProductionCostText;
	FText CommaTextReference = UFlareGameTools::AddLeadingSpace(LOCTEXT("Comma", "+"));

	// Cycle cost in credits
	uint32 CycleProductionCost = GetProductionCost(Data);
	if (CycleProductionCost > 0)
	{
		ProductionCostText = FText::Format(LOCTEXT("ProductionCostFormat", "{0} credits"), FText::AsNumber(UFlareGameTools::DisplayMoney(CycleProductionCost)));
	}

	// Cycle cost in resources
	for (int ResourceIndex = 0; ResourceIndex < Data->InputResources.Num(); ResourceIndex++)
	{
		FText CommaText = ProductionCostText.IsEmpty() ? FText() : CommaTextReference;
		const FFlareFactoryResource* FactoryResource = &Data->InputResources[ResourceIndex];
		FCHECK(FactoryResource);

		ProductionCostText = FText::Format(LOCTEXT("ProductionResourcesFormat", "{0}{1} {2} {3}"),
			ProductionCostText, CommaText, FText::AsNumber(FactoryResource->Quantity), FactoryResource->Resource->Data.Acronym);
	}

	return ProductionCostText;
}
Exemple #9
0
void fibre_destroy(struct fibre *f)
{
	FCHECK(!f->flags || (f->flags & FIBRE_FLAGS_COMPLETED));
	if (f->flags & FIBRE_FLAGS_COMPLETED)
		fibre_arch_destroy(f->arch);
	free(f);
}
UFlareSpacecraftCatalog::UFlareSpacecraftCatalog(const class FObjectInitializer& PCIP)
	: Super(PCIP)
{
	TArray<FAssetData> AssetList;
	IAssetRegistry& Registry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry").Get();

	Registry.SearchAllAssets(true);
	Registry.GetAssetsByClass(UFlareSpacecraftCatalogEntry::StaticClass()->GetFName(), AssetList);

	for (int32 Index = 0; Index < AssetList.Num(); Index++)
	{
		//FLOGV("UFlareSpacecraftCatalog::UFlareSpacecraftCatalog : Found '%s'", *AssetList[Index].GetFullName());
		UFlareSpacecraftCatalogEntry* Spacecraft = Cast<UFlareSpacecraftCatalogEntry>(AssetList[Index].GetAsset());
		FCHECK(Spacecraft);

		if (Spacecraft->Data.IsStation())
		{
			StationCatalog.Add(Spacecraft);
		}
		else
		{
			ShipCatalog.Add(Spacecraft);
		}
	}

	StationCatalog.Sort(FSortByEntrySize());
	ShipCatalog.Sort(FSortByEntrySize());
}
Exemple #11
0
/***********************************************************************
*                   LOCAL FUNCTION DEFINITIONS                         *
************************************************************************/
static int export_encoder_pair(const char *name,
			       const int inst_id,
			       encoder_pair_t *e)
{
#define FCHECK(rvalue) if (float_pin_null(rvalue)) return _halerrno;
#define BCHECK(rvalue) if (bit_pin_null(rvalue)) return _halerrno;
#define UCHECK(rvalue) if (u32_pin_null(rvalue)) return _halerrno;

    BCHECK(e->smpl.master_A  = halxd_pin_bit_newf(HAL_IN, inst_id, 0,   "%s.master-A", name));
    BCHECK(e->smpl.master_B  = halxd_pin_bit_newf(HAL_IN, inst_id, 0,   "%s.master-B", name));
    BCHECK(e->smpl.slave_A   = halxd_pin_bit_newf(HAL_IN, inst_id, 0,   "%s.slave-A", name));
    BCHECK(e->smpl.slave_B   = halxd_pin_bit_newf(HAL_IN, inst_id, 0,   "%s.slave-B", name));
    BCHECK(e->smpl.enable    = halxd_pin_bit_newf(HAL_IN, inst_id, 0,   "%s.enable", name));

    FCHECK(e->upd.error   = halxd_pin_float_newf(HAL_OUT, inst_id, 0.0, "%s.error", name));

    UCHECK(e->upd.master_ppr   = halxd_pin_u32_newf(HAL_IO, inst_id, 0.0, "%s.master-ppr", name));
    UCHECK(e->upd.slave_ppr    = halxd_pin_u32_newf(HAL_IO, inst_id, 0.0, "%s.slave-ppr", name));
    UCHECK(e->upd.master_teeth = halxd_pin_u32_newf(HAL_IO, inst_id, 0.0, "%s.master-teeth", name));
    UCHECK(e->upd.slave_teeth  = halxd_pin_u32_newf(HAL_IO, inst_id, 0.0, "%s.slave-teeth", name));

    // sample_state
    e->smpl.master_state = 0;
    e->smpl.slave_state = 0;

    // shared_state
    e->sample_reads.incr.i.master_increment = 0;
    e->sample_reads.incr.i.slave_increment = 0;
    e->update_reads.raw_error = 0;

    // update_state
    e->upd.output_scale = 1.0;

    return 0;
}
Exemple #12
0
uint32 UFlareFactory::GetProductionCost(const FFlareProductionData* Data)
{
	const FFlareProductionData* CycleData = Data ? Data : &GetCycleData();
	FCHECK(CycleData);

	ScaledProductionCost = CycleData->ProductionCost;
	
	return ScaledProductionCost;
}
Exemple #13
0
int fibre_push(struct fibre_selector *s)
{
	int ret;
	FCHECK(tls_fibre.inited);
	s->parent = tls_fibre.sstack;
	tls_fibre.sstack = s;
	ret = s->vtable->post_push(s->vtable_data);
	if (ret) {
		tls_fibre.sstack = s->parent;
		s->parent = NULL;
	}
	return ret;
}
Exemple #14
0
int fibre_recreate(struct fibre *f, void (*fn)(void *), void *d)
{
	int ret;
	FCHECK(f->flags & FIBRE_FLAGS_COMPLETED);
	fibre_arch_destroy(f->arch);
	f->flags = 0;
	ret = fibre_arch_create(&f->arch, fibre_bootstrap);
	if (ret)
		return ret;
	f->fn = fn;
	f->fn_arg = d;
	return 0;
}
Exemple #15
0
int fibre_pop(struct fibre_selector **foo)
{
	struct fibre_selector *s = tls_fibre.sstack;
	int ret;
	FCHECK(s);
	ret = s->vtable->pre_pop(s->vtable_data);
	if (ret)
		return ret;
	tls_fibre.sstack = s->parent;
	s->parent = NULL;
	if (foo)
		*foo = s;
	return 0;
}
void SFlareSkirmishScoreMenu::Enter()
{
	FLOG("SFlareSkirmishScoreMenu::Enter");

	// Setup
	SetEnabled(true);
	SetVisibility(EVisibility::Visible);
	PlayerResults->ClearChildren();
	EnemyResults->ClearChildren();

	// Get data
	UFlareSkirmishManager* SkirmishManager = MenuManager->GetGame()->GetSkirmishManager();
	FCHECK(SkirmishManager);
	FFlareSkirmishResultData Result = SkirmishManager->GetResult();

	// Set title
	if (Result.PlayerVictory)
	{
		SkirmishResultText->SetText(LOCTEXT("SkirmishVictory", "Skirmish won"));
	}
	else
	{
		SkirmishResultText->SetText(LOCTEXT("SkirmishLoss", "Skirmish lost"));
	}

	// Set time
	int32 Minutes = FMath::Max(FMath::RoundToInt(Result.GameTime / 60), 1);
	FText MinutesText = (Minutes > 1) ? LOCTEXT("Minutes", "minutes") : LOCTEXT("Minute", "minute");
	SkirmishTimeText->SetText(
		FText::Format(LOCTEXT("TimeFormat", "Skirmish completed in {0} {1}"),
		FText::AsNumber(Minutes), MinutesText));

	// Set results
	FillResults(PlayerResults, LOCTEXT("PlayerTitle", "Player results"), Result.Player);
	FillResults(EnemyResults,  LOCTEXT("EnemyTitle",  "Enemy results"),  Result.Enemy);
}
Exemple #17
0
struct fibre *fibre_get_current(void)
{
	struct fibre_selector *s = tls_fibre.sstack;
	FCHECK(s);
	return s->vtable->get_current(s->vtable_data);
}
Exemple #18
0
FText UFlareFactory::GetFactoryCycleInfo()
{
	FText CommaTextReference = UFlareGameTools::AddLeadingSpace(LOCTEXT("Comma", "+"));
	FText ProductionOutputText;

	// No ship class selected
	if (IsShipyard() && FactoryData.TargetShipClass == NAME_None)
	{
		return LOCTEXT("SelectShipClass", "No ship in construction.");
	}

	FText ProductionCostText = GetFactoryCycleCost(&GetCycleData());

	// Cycle output in factory actions
	for (int ActionIndex = 0; ActionIndex < GetDescription()->OutputActions.Num(); ActionIndex++)
	{
		FText CommaText = ProductionOutputText.IsEmpty() ? FText() : CommaTextReference;
		const FFlareFactoryAction* FactoryAction = &GetDescription()->OutputActions[ActionIndex];
		FCHECK(FactoryAction);

		switch (FactoryAction->Action)
		{
			// Ship production
			case EFlareFactoryAction::CreateShip:
				ProductionOutputText = FText::Format(LOCTEXT("CreateShipActionFormat", "{0}{1} {2} {3}"),
					ProductionOutputText, CommaText, FText::AsNumber(FactoryAction->Quantity),
					GetGame()->GetSpacecraftCatalog()->Get(FactoryData.TargetShipClass)->Name);
				break;

			// Sector discovery
			case EFlareFactoryAction::DiscoverSector:
				ProductionOutputText = FText::Format(LOCTEXT("DiscoverSectorActionFormat", "{0}{1} sector"),
					ProductionOutputText, CommaText);
				break;

			// Research gain
			case EFlareFactoryAction::GainResearch:
				ProductionOutputText = FText::Format(LOCTEXT("GainResearchActionFormat", "{0}{1}{2} research"),
					ProductionOutputText, CommaText, FText::AsNumber(FactoryAction->Quantity * Parent->GetLevel()));
				break;

			// Build station
			case EFlareFactoryAction::BuildStation:
				ProductionOutputText = LOCTEXT("BuildStationActionFormat", "finish station construction");
				break;

			default:
				FLOGV("SFlareShipMenu::UpdateFactoryLimitsList : Unimplemented factory action %d", (FactoryAction->Action + 0));
		}
	}

	// Cycle output in resources
	for (int ResourceIndex = 0; ResourceIndex < GetCycleData().OutputResources.Num(); ResourceIndex++)
	{
		FText CommaText = ProductionOutputText.IsEmpty() ? FText() : CommaTextReference;
		const FFlareFactoryResource* FactoryResource = &GetCycleData().OutputResources[ResourceIndex];
		FCHECK(FactoryResource);

		ProductionOutputText = FText::Format(LOCTEXT("ProductionOutputFormat", "{0}{1} {2} {3}"),
			ProductionOutputText, CommaText, FText::AsNumber(FactoryResource->Quantity), FactoryResource->Resource->Data.Acronym);
	}

	return FText::Format(LOCTEXT("FactoryCycleInfoFormat", "Production cycle : {0} \u2192 {1} in {2}"),
		ProductionCostText, ProductionOutputText,
		UFlareGameTools::FormatDate(GetProductionTime(GetCycleData()), 2));
}
int32 SectorHelper::Trade(UFlareSimulatedSpacecraft* SourceSpacecraft, UFlareSimulatedSpacecraft* DestinationSpacecraft, FFlareResourceDescription* Resource, int32 MaxQuantity, int64* TransactionPrice, UFlareTradeRoute* TradeRoute)
{
	FText Unused;

	//FLOGV("Trade for %s", *Resource->Acronym.ToString());


	if(TransactionPrice )
	{
		*TransactionPrice = 0;
	}

	if(!SourceSpacecraft->CanTradeWith(DestinationSpacecraft, Unused))
	{
		FLOGV("Both spacecraft cannot trade: %s -> %s", *SourceSpacecraft->GetImmatriculation().ToString(), *DestinationSpacecraft->GetImmatriculation().ToString());
		return 0;
	}

	int32 ResourcePrice = SourceSpacecraft->GetCurrentSector()->GetTransfertResourcePrice(SourceSpacecraft, DestinationSpacecraft, Resource);
	int32 QuantityToTake = MaxQuantity;
	bool AllowDepts = SourceSpacecraft->GetGame()->GetQuestManager()->IsTradeQuestUseStation(DestinationSpacecraft) && SourceSpacecraft->GetCompany()->IsPlayerCompany();

	if (SourceSpacecraft->GetCompany() != DestinationSpacecraft->GetCompany() && !AllowDepts)
	{
		// Limit transaction bay available money
		int32 MaxAffordableQuantity = FMath::Max(0, int32(DestinationSpacecraft->GetCompany()->GetMoney() / ResourcePrice));
		QuantityToTake = FMath::Min(QuantityToTake, MaxAffordableQuantity);
	}
	int32 ResourceCapacity = DestinationSpacecraft->GetActiveCargoBay()->GetFreeSpaceForResource(Resource, SourceSpacecraft->GetCompany());
	int32 AvailableQuantity = SourceSpacecraft->GetActiveCargoBay()->GetResourceQuantity(Resource, DestinationSpacecraft->GetCompany());

	QuantityToTake = FMath::Min(QuantityToTake, ResourceCapacity);
	QuantityToTake = FMath::Min(QuantityToTake, AvailableQuantity);
	
	int32 TakenResources = SourceSpacecraft->GetActiveCargoBay()->TakeResources(Resource, QuantityToTake, DestinationSpacecraft->GetCompany());
	int32 GivenResources = DestinationSpacecraft->GetActiveCargoBay()->GiveResources(Resource, TakenResources, SourceSpacecraft->GetCompany());

	// Pay
	if (GivenResources > 0 && SourceSpacecraft->GetCompany() != DestinationSpacecraft->GetCompany())
	{
		int64 Price = ResourcePrice * GivenResources;
		DestinationSpacecraft->GetCompany()->TakeMoney(Price, AllowDepts, FFlareTransactionLogEntry::LogBuyResource(SourceSpacecraft, DestinationSpacecraft, Resource, GivenResources, TradeRoute));
		SourceSpacecraft->GetCompany()->GiveMoney(Price, FFlareTransactionLogEntry::LogSellResource(SourceSpacecraft, DestinationSpacecraft, Resource, GivenResources, TradeRoute));

		if(TransactionPrice )
		{
			*TransactionPrice = Price;
		}

		UFlareCompany* PlayerCompany = SourceSpacecraft->GetGame()->GetPC()->GetCompany();

		if(SourceSpacecraft->GetCompany() == PlayerCompany && DestinationSpacecraft->GetCompany() != PlayerCompany)
		{
			DestinationSpacecraft->GetCompany()->GivePlayerReputation(GivenResources * 0.01f, 100);
		}

		if(DestinationSpacecraft->GetCompany() == PlayerCompany && SourceSpacecraft->GetCompany() != PlayerCompany)
		{
			SourceSpacecraft->GetCompany()->GivePlayerReputation(GivenResources * 0.01f, 100);
		}
	}
	
	// Set the trading state if not player fleet
	if (GivenResources > 0)
	{
		AFlarePlayerController* PC = SourceSpacecraft->GetGame()->GetPC();
		UFlareFleet* PlayerFleet = PC->GetPlayerFleet();
		FCHECK(PC);

		if (SourceSpacecraft->GetCurrentFleet() != PlayerFleet && !SourceSpacecraft->IsStation())
		{
			SourceSpacecraft->SetTrading(true);
		}

		if (DestinationSpacecraft->GetCurrentFleet() != PlayerFleet && !DestinationSpacecraft->IsStation())
		{
			DestinationSpacecraft->SetTrading(true);
		}

		if(PC->GetPlayerShip() == SourceSpacecraft || PC->GetPlayerShip() == DestinationSpacecraft)
		{
			PC->SetAchievementProgression("ACHIEVEMENT_TRADE", 1);
		}
	}

	SourceSpacecraft->GetGame()->GetQuestManager()->OnTradeDone(SourceSpacecraft, DestinationSpacecraft, Resource, GivenResources);

	//FLOGV("Trade GivenResources %d", GivenResources);

	return GivenResources;

}
Exemple #20
0
void fibre_selector_free(struct fibre_selector *s)
{
	FCHECK(!s->parent);
	s->vtable->destroy(s->vtable_data);
	free(s);
}
Exemple #21
0
void fibre_schedule(void)
{
	FCHECK(tls_fibre.sstack);
	FCHECK(fibre_can_switch_implicit());
	tls_fibre.sstack->vtable->schedule(tls_fibre.sstack->vtable_data, NULL);
}
Exemple #22
0
int fibre_can_switch_implicit(void)
{
	FCHECK(tls_fibre.sstack);
	return tls_fibre.sstack->vtable->can_switch_implicit(
				tls_fibre.sstack->vtable_data);
}
Exemple #23
0
void fibre_async_abort(struct fibre *f)
{
	FCHECK(f->async);
	f->async_abort = 1;
}
Exemple #24
0
void fibre_async_get_use_cb(struct fibre *f, void **arg, int (**cb)(void *))
{
	FCHECK(f->async == FIBRE_ASYNC_CHECK_CB);
	*arg = f->async_check_cb.cb_arg;
	*cb = f->async_check_cb.cb;
}
void SFlareSkirmishScoreMenu::OnRetry()
{
	UFlareSkirmishManager* SkirmishManager = MenuManager->GetGame()->GetSkirmishManager();
	FCHECK(SkirmishManager);
	SkirmishManager->RestartPlay();
}
Exemple #26
0
void fibre_async_set_mask(uint32_t mask)
{
	FCHECK(tls_fibre.sstack);
	tls_fibre.sstack->async_mask = mask;
}
Exemple #27
0
void fibre_async_atomicity_down(void)
{
	FCHECK(tls_fibre.async_atomic);
	tls_fibre.async_atomic--;
}
void UFlareAsteroidComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
	float CollisionSize = GetCollisionShape().GetExtent().Size();
	EffectsUpdateTimer += DeltaTime;

	// Get player ship
	AFlareGame* Game = Cast<AFlareGame>(GetWorld()->GetAuthGameMode());
	FCHECK(Game);
	AFlarePlayerController* PC = Game->GetPC();
	FCHECK(PC);
	AFlareSpacecraft* ShipPawn = PC->GetShipPawn();

	// Update if close to player and visible
	if (ShipPawn
	 && (ShipPawn->GetActorLocation() - GetComponentLocation()).Size() < 500000
	 && (GetWorld()->TimeSeconds - LastRenderTime) < 0.5)
	{
		if (EffectsUpdateTimer > EffectsUpdatePeriod)
		{
			// World data
			FVector AsteroidLocation = GetComponentLocation();
			FVector SunDirection = Game->GetPlanetarium()->GetSunDirection();
			SunDirection.Normalize();
	
			// Compute new FX locations
			for (int32 Index = 0; Index < Effects.Num(); Index++)
			{
				FVector RandomDirection = FVector::CrossProduct(SunDirection, EffectsKernels[Index]);
				RandomDirection.Normalize();
				FVector StartPoint = AsteroidLocation + RandomDirection * CollisionSize;

				// Trace params
				FHitResult HitResult(ForceInit);
				FCollisionQueryParams TraceParams(FName(TEXT("Asteroid Trace")), false, NULL);
				TraceParams.bTraceComplex = true;
				TraceParams.bReturnPhysicalMaterial = false;
				ECollisionChannel CollisionChannel = ECollisionChannel::ECC_WorldDynamic;

				// Trace
				bool FoundHit = GetWorld()->LineTraceSingleByChannel(HitResult, StartPoint, AsteroidLocation, CollisionChannel, TraceParams);
				if (FoundHit && HitResult.Component == this && Effects[Index])
				{
					FVector EffectLocation = HitResult.Location;

					if (!Effects[Index]->IsActive())
					{
						Effects[Index]->Activate();
					}
					Effects[Index]->SetWorldLocation(EffectLocation);
					Effects[Index]->SetWorldRotation(SunDirection.Rotation());
				}
				else
				{
					Effects[Index]->Deactivate();
				}
			}

			EffectsUpdateTimer = 0;
		}
	}

	// Disable all
	else
	{
		for (int32 Index = 0; Index < Effects.Num(); Index++)
		{
			Effects[Index]->Deactivate();
		}
	}
}
Exemple #29
0
void fibre_async_get_fd_readable(struct fibre *f, int *fd)
{
	FCHECK(f->async == FIBRE_ASYNC_FD_READABLE);
	*fd = f->async_fd_readable.fd;
}