Пример #1
0
void AFlarePlanetarium::BeginPlay()
{
	Super::BeginPlay();
	FLOG("AFlarePlanetarium::BeginPlay");

	TArray<UActorComponent*> Components = GetComponentsByClass(UStaticMeshComponent::StaticClass());
	for (int32 ComponentIndex = 0; ComponentIndex < Components.Num(); ComponentIndex++)
	{
		UStaticMeshComponent* PlanetCandidate = Cast<UStaticMeshComponent>(Components[ComponentIndex]);
		if (PlanetCandidate)
		{
			// Apply a new dynamic material to planets so that we can control shading parameters
			UMaterialInstanceConstant* BasePlanetMaterial = Cast<UMaterialInstanceConstant>(PlanetCandidate->GetMaterial(0));
			if (BasePlanetMaterial)
			{
				//FLOGV("AFlarePlanetarium::BeginPlay : found planet '%s'", *PlanetCandidate->GetName());

#if PLATFORM_LINUX
				int32 UseNormalAsLightingDirection = 1;
#else
				int32 UseNormalAsLightingDirection = 0;
#endif
				UMaterialInstanceDynamic* PlanetMaterial = UMaterialInstanceDynamic::Create(BasePlanetMaterial, GetWorld());
				PlanetCandidate->SetMaterial(0, PlanetMaterial);
				PlanetMaterial->SetScalarParameterValue("UseNormalAsLightingDirection", UseNormalAsLightingDirection);
			}
		}
	}
}
void APlayerCharacter::TertiaryRelease() {
    UInventoryComponent* inv = Cast<UInventoryComponent>(GetComponentsByClass(UInventoryComponent::StaticClass())[0]);
    
    if(selectedQuickSlot == Primary)    if(inv->PrimarySlot)    inv->PrimarySlot->TertiaryRelease(this);
    if(selectedQuickSlot == Secondary)  if(inv->SecondarySlot)  inv->SecondarySlot->TertiaryRelease(this);
    if(selectedQuickSlot == Tertiary)   if(inv->TertiarySlot)   inv->TertiarySlot->TertiaryRelease(this);
}
Пример #3
0
void AInteractableChar::BeginPlay(){
	Super::BeginPlay();

	for( UActorComponent* MeshComp : GetComponentsByClass(UMeshComponent::StaticClass()) ){
		UMeshComponent* thisMesh = Cast<UMeshComponent>(MeshComp);
		Meshes.Push(thisMesh);
	}

}
void APlayerCharacter::Select() {
    UInventoryComponent* inv = Cast<UInventoryComponent>(GetComponentsByClass(UInventoryComponent::StaticClass())[0]);
    bool swapped = false;
    if(isInventoryOpen() || isClothingInventoryOpen()) {
        if(!(SelectedItem <= -11) && !(HoveredIndex <= -11)) {
            inv->SwapIndexes(SelectedItem, HoveredIndex);
            swapped = true;
        }
    }
    
    if (SelectedItem == -11) SelectedItem = HoveredIndex;
    if (swapped) SelectedItem = -11;
}
Пример #5
0
// Called when the game starts or when spawned
void ATestTL::BeginPlay()
{
	Super::BeginPlay();
	
	if (TLComp && MoveInterpCurve)
	{
		UE_LOG(TestTL, Log, TEXT("Begin Play ********%d*****%ls***"), 
			GetComponentsByClass(UTimelineComponent::StaticClass()).Num(),
			MoveInterpDelegate.IsBound()?TEXT("True"):TEXT("False"));
		TLComp->Activate(true);
		//TLComp->AddInterpFloat
		TLComp->AddInterpFloat(MoveInterpCurve, MoveInterpDelegate, FName("MoveInterp"));
		TLComp->PlayFromStart();
	}
}
Пример #6
0
void AFlarePlanetarium::PrepareCelestialBody(FFlareCelestialBody* Body, FPreciseVector Offset, double AngleOffset)
{
	CelestialBodyPosition BodyPosition;

	BodyPosition.Body = Body;
	FPreciseVector Location = Offset + Body->AbsoluteLocation;
	BodyPosition.AlignedLocation = Location.RotateAngleAxis(AngleOffset, FPreciseVector(0,1,0));
	BodyPosition.Radius = Body->Radius;
	BodyPosition.Distance = BodyPosition.AlignedLocation.Size();
	BodyPosition.TotalRotation = Body->RotationAngle + AngleOffset;

	// Find the celestial body component
	UStaticMeshComponent* BodyComponent = NULL;
	TArray<UActorComponent*> Components = GetComponentsByClass(UStaticMeshComponent::StaticClass());
	for (int32 ComponentIndex = 0; ComponentIndex < Components.Num(); ComponentIndex++)
	{
		UStaticMeshComponent* ComponentCandidate = Cast<UStaticMeshComponent>(Components[ComponentIndex]);
		if (ComponentCandidate && ComponentCandidate->GetName() == Body->Identifier.ToString()	)
		{
			BodyComponent = ComponentCandidate;
			break;
		}
	}

	if (BodyComponent)
	{
		BodyPosition.BodyComponent = BodyComponent;
		BodyPositions.Add(BodyPosition);
	}
	else
	{
		FLOGV("AFlarePlanetarium::PrepareCelestialBody : no planetarium component for celestial body '%s'", *(Body->Identifier.ToString()));
	}


	if (Body == &Sun)
	{
		SunOcclusionAngle = FPreciseMath::Asin(BodyPosition.Radius / BodyPosition.Distance);
		SunPhase = FMath::UnwindRadians(FMath::Atan2(BodyPosition.AlignedLocation.Z, BodyPosition.AlignedLocation.X));
	}

	for (int SatteliteIndex = 0; SatteliteIndex < Body->Sattelites.Num(); SatteliteIndex++)
	{
		FFlareCelestialBody* CelestialBody = &Body->Sattelites[SatteliteIndex];
		PrepareCelestialBody(CelestialBody, Offset, AngleOffset);
	}
}
Пример #7
0
void ALD35Character::Tick(float deltaTime)
{
	Super::Tick(deltaTime);

	if (Health <= 0) return;

	ShotCooldown -= deltaTime;
	HealthRegenStoppedFor -= deltaTime;

	if (IsFiring && ShotCooldown <= 0)
	{
		ShotCooldown = IsInAlternateForm ? 0.5f : 1.5f;

		OnFire();
	}

	if (IsInAlternateForm)
	{
		Energy = FMath::Clamp(Energy - deltaTime / MaxTransformTime, 0.f, 1.f);

		if (Energy <= 0)
		{
			Transform();
		}

		if (HealthRegenStoppedFor <= 0) Health = FMath::Clamp(Health + deltaTime, 0.f, 4.f);
	}

	for (auto& a : GetComponentsByTag(UPrimitiveComponent::StaticClass(), TEXT("Human")))
	{
		Cast<UPrimitiveComponent>(a)->SetVisibility(!IsInAlternateForm);
	}

	for (auto& a : GetComponentsByTag(UPrimitiveComponent::StaticClass(), TEXT("Claw")))
	{
		Cast<UPrimitiveComponent>(a)->SetVisibility(IsInAlternateForm);
	}

	for (auto& a : GetComponentsByClass(UPointLightComponent::StaticClass()))
	{
		Cast<UPointLightComponent>(a)->SetVisibility(!IsSomeoneTransformed);
	}
}
void APlayerCharacter::UpdateSpeed() const {
    float maxSpeed = baseMovementSpeed;
    if(isScoping()) {
        maxSpeed *= scopingSpeedModifier;
    } if(isSprinting()) {
        maxSpeed *= sprintingSpeedModifier;
    } if(isInventoryOpen() || isClothingInventoryOpen()) {
        maxSpeed *= inventoryOpenSpeedModifier;
    }
    
    UInventoryComponent* inv =  Cast<UInventoryComponent>(GetComponentsByClass(UInventoryComponent::StaticClass())[0]);
    if(inv->GetWeight() >0) {
        //maxSpeed *= 1 / (inv->GetWeight() * 0.01); // NEED FORMULA
    }
    
    GetCharacterMovement()->MaxWalkSpeed = maxSpeed;
    GetCharacterMovement()->MaxWalkSpeedCrouched = 0.5 * maxSpeed;
    GetTransform().GetLocation();
}
Пример #9
0
/******************** StoreResource *************************/
bool APOTLStructure::StoreResource(UResource* Resource)
{
	if (Resource)
	{
		TArray<UActorComponent*> StorageComponents = GetComponentsByClass(UStorageComponent::StaticClass());
		for (auto& Component : StorageComponents)
		{
			UStorageComponent* StorageComponent = Cast<UStorageComponent>(Component);
			if (StorageComponent)
			{
				if (StorageComponent->StoreResource(Resource))
				{
					return true;
				}
			}
		}
	}
	if (AttachedTo)
	{
		return AttachedTo->StoreResource(Resource);
	}
	return false;
}
void APlayerCharacter::QuaternaryClothingRelease() {
    UInventoryComponent* inv = Cast<UInventoryComponent>(GetComponentsByClass(UInventoryComponent::StaticClass())[0]);
    
    if(inv->Bag)    inv->Bag->QuaternaryClothingRelease(this);
}
void APlayerCharacter::Drop() {
    UInventoryComponent* inv = Cast<UInventoryComponent>(GetComponentsByClass(UInventoryComponent::StaticClass())[0]);
    
    
}
Пример #12
0
/******************** AddResource *************************/
int APOTLStructure::AddResource(FString ResourceId, int32 Quantity)
{
	int Leftovers = Quantity;
	
	// Check Attachments for storage with AddResource
	if (AttachedTo)
	{
		Leftovers = AttachedTo->AddResource(ResourceId, Quantity);
	}
	else {
		// distribute to self and attachments?
		for (auto& Attachment : AttachedStructures)
		{
			if (IsValid(Attachment))
			{

			}
		}
	}

	// Check for storage component in self
	if (Leftovers > 0)
	{
		TArray<UActorComponent*> StorageComponents = GetComponentsByClass(UStorageComponent::StaticClass());
		for (auto& Component : StorageComponents)
		{
			UStorageComponent* StorageComponent = Cast<UStorageComponent>(Component);
			if (StorageComponent)
			{
				Leftovers = StorageComponent->AddResource(ResourceId, Leftovers);
				if (Leftovers > 0)
				{

				}
				else
				{
					//Added = true;
					break;
				}
			}
		}
	}


	/*
	switch (Type)
	{
	case EResourceList::Free:
		if (FreeResources.Contains(Id))
		{
			if (FreeResources[Id] + Quantity < 0) 
			{

			}
			else
			{
				FreeResources[Id] += Quantity;
			}
			Added = true;
		}
		else
		{
			FreeResources.Add(Id, Quantity);
			Added = true;
		}
		break;
	case EResourceList::Upkeep:
		if (ResourceUpkeep.Contains(Id))
		{
			if (ResourceUpkeep[Id] + Quantity < 0)
			{

			}
			else
			{
				ResourceUpkeep[Id] += Quantity;
			}
			Added = true;
		}
		else
		{
			ResourceUpkeep.Add(Id, Quantity);
			Added = true;
		}
		break;
	default:
		break;
	}
	*/
	return Leftovers;
}
Пример #13
0
void AFlarePlanetarium::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	SmoothTime += DeltaSeconds * TimeMultiplier;

	if (GetGame())
	{
		if (!GetGame()->GetActiveSector())
		{
			// No active sector, do nothing
			Ready = false;
			return;
		}

		bool LightWasAdjusted = false;
		UFlareWorld* World = GetGame()->GetGameWorld();

		if (World)
		{
			float LocalTime = GetGame()->GetActiveSector()->GetLocalTime();
			CurrentSector = GetGame()->GetActiveSector()->GetSimulatedSector()->GetIdentifier();

			if (CurrentSector != PreviousSector)
			{
				LightWasAdjusted = true;
				PreviousSector = CurrentSector;
			}

			if (Sky == NULL)
			{
				for (TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr)
				{
					if ((*ActorItr)->GetName().StartsWith("Skybox"))
					{
						FLOG("AFlarePlanetarium::Tick : found the sky");
						Sky = *ActorItr;
						break;
					}
				}
			}

			if (Light == NULL)
			{
				TArray<UActorComponent*> Components = GetComponentsByClass(UDirectionalLightComponent::StaticClass());
				for (int32 ComponentIndex = 0; ComponentIndex < Components.Num(); ComponentIndex++)
				{
					UDirectionalLightComponent* LightCandidate = Cast<UDirectionalLightComponent>(Components[ComponentIndex]);
					if (LightCandidate)
					{
						Light = LightCandidate;
						break;
					}
				}
			}

			Ready = true;

			do
			{

				Sun = World->GetPlanerarium()->GetSnapShot(LocalTime, SmoothTime);

				// Draw Player
				const FFlareSectorOrbitParameters* PlayerOrbit = GetGame()->GetActiveSector()->GetSimulatedSector()->GetOrbitParameters();
				
				FFlareCelestialBody* CurrentParent = World->GetPlanerarium()->FindCelestialBody(PlayerOrbit->CelestialBodyIdentifier);
				if (CurrentParent)
				{
					FPreciseVector ParentLocation = CurrentParent->AbsoluteLocation;

					double DistanceToParentCenter = CurrentParent->Radius + PlayerOrbit->Altitude;
					FPreciseVector PlayerLocation =  ParentLocation + World->GetPlanerarium()->GetRelativeLocation(CurrentParent, LocalTime, SmoothTime, DistanceToParentCenter, 0, PlayerOrbit->Phase);
					/*FLOGV("Parent location = %s", *CurrentParent->AbsoluteLocation.ToString());
					FLOGV("PlayerLocation = %s", *PlayerLocation.ToString());*/
#ifdef PLANETARIUM_DEBUG
					DrawDebugLine(GetWorld(), FVector(1000, 0 ,0), FVector(- 1000, 0 ,0), FColor::Red, false);
					DrawDebugLine(GetWorld(), FVector(0, 1000 ,0), FVector(0,- 1000 ,0), FColor::Green, false);
					DrawDebugLine(GetWorld(), FVector(0, 0, 900), FVector(0, 0, -1000), FColor::Blue, false);
					DrawDebugLine(GetWorld(), FVector(0, 0, 900), FVector(0, 0, 1000), FColor::Cyan, false);
#endif
					FPreciseVector DeltaLocation = ParentLocation - PlayerLocation;
					FPreciseVector SunDeltaLocation = Sun.AbsoluteLocation - PlayerLocation;

					float AngleOffset =  90 + FMath::RadiansToDegrees(FMath::Atan2(DeltaLocation.Z,DeltaLocation.X));
					/*FLOGV("DeltaLocation = %s", *DeltaLocation.ToString());
					FLOGV("FMath::Atan2(DeltaLocation.Y,DeltaLocation.X)  = %f", FMath::Atan2(DeltaLocation.Z,DeltaLocation.X));
					FLOGV("AngleOffset  = %f", AngleOffset);*/

					SunDirection = -(SunDeltaLocation.RotateAngleAxis(AngleOffset, FPreciseVector(0,1,0))).GetUnsafeNormal();
					// Reset sun occlusion;
					SunOcclusion = 0;
					MinDistance = DistanceToParentCenter;

					BodyPositions.Empty();
					PrepareCelestialBody(&Sun, -PlayerLocation, AngleOffset);
					SetupCelestialBodies();

					// Try to find night
					if (SkipNightTimeRange > 0 && SunOcclusion >= 1)
					{
						SmoothTime = FMath::FRand() * SkipNightTimeRange;
						//FLOGV("AFlarePlanetarium::Tick : night, try to find light at %f (max %f)",SmoothTime, SkipNightTimeRange);
					}
					else
					{
						SkipNightTimeRange = 0;
					}


					if (Sky)
					{
						Sky->SetActorRotation(FRotator(-AngleOffset, 0 , 0));
						//FLOGV("Sky %s rotation= %s",*Sky->GetName(),  *Sky->GetActorRotation().ToString());
					}
					else
					{
						FLOG("AFlarePlanetarium::Tick : no sky found");
					}

					//FLOGV("SunOcclusion %f", SunOcclusion);
					if (Light)
					{
						float CurrentIntensity = Light->Intensity;
						float Intensity = 5 * FMath::Pow((1.0 - SunOcclusion), 2);

						if (FMath::Abs(Intensity - CurrentIntensity) > 0.1f)
						{
							LightWasAdjusted = true;
							FLOG("AFlarePlanetarium::Tick : lighting was adjusted");
						}

						Light->SetIntensity(Intensity);
					}
					else
					{
						FLOG("AFlarePlanetarium::Tick : no sunlight found");
					}
				}
				else
				{
					FLOGV("AFlarePlanetarium::Tick : failed to find the current sector: '%s' in planetarium", *(PlayerOrbit->CelestialBodyIdentifier.ToString()));
				}


			} while(SkipNightTimeRange != 0);
			
			// Recapture skylight
			if (LightWasAdjusted)
			{
				FLOG("AFlarePlanetarium::Tick : recapturing skylight");
				TArray<AActor*> SkylightCandidates;
				UGameplayStatics::GetAllActorsOfClass(GetWorld(), ASkyLight::StaticClass(), SkylightCandidates);
				if (SkylightCandidates.Num())
				{
					Cast<ASkyLight>(SkylightCandidates[0])->GetLightComponent()->RecaptureSky();
				}
			}
		}
	}
}