int32 UFlareCargoBay::GetTotalCapacityForResource(FFlareResourceDescription* Resource, UFlareCompany* Client, bool LockOnly) const { int32 Quantity = 0; for (int CargoIndex = 0; CargoIndex < CargoBay.Num() ; CargoIndex++) { const FFlareCargo& Cargo = CargoBay[CargoIndex]; if(!CheckRestriction(&Cargo, Client)) { continue; } if(LockOnly && Cargo.Lock == EFlareResourceLock::NoLock) { continue; } if(Cargo.Lock != EFlareResourceLock::NoLock) { } if (Cargo.Resource == NULL || Cargo.Resource == Resource) { Quantity += GetSlotCapacity(); } } return Quantity; }
void DynamicTypeHandler::SetSlot(DynamicObject* instance, int index, Var value) #endif { Assert(index < GetSlotCapacity()); Assert(propertyId == Constants::NoProperty || CanStorePropertyValueDirectly(instance, propertyId, allowLetConst)); SetSlotUnchecked(instance, index, value); }
void DynamicTypeHandler::SetAuxSlot(DynamicObject* instance, int index, Var value) #endif { // We should only assign a stack value only to a stack object (current mark temp number in mark temp object) Assert(ThreadContext::IsOnStack(instance) || !ThreadContext::IsOnStack(value) || TaggedNumber::Is(value)); Assert(index < GetSlotCapacity() - GetInlineSlotCapacity()); Assert(propertyId == Constants::NoProperty || CanStorePropertyValueDirectly(instance, propertyId, allowLetConst)); instance->auxSlots[index] = value; }
Var DynamicTypeHandler::GetAuxSlot(DynamicObject * instance, int index) { // We should only assign a stack value only to a stack object (current mark temp number in mark temp object) Assert(index < GetSlotCapacity() - GetInlineSlotCapacity()); Var value = instance->auxSlots[index]; Assert(ThreadContext::IsOnStack(instance) || !ThreadContext::IsOnStack(value) || TaggedNumber::Is(value)); return value; }
int32 UFlareCargoBay::GetFreeSpaceForResource(FFlareResourceDescription* Resource, UFlareCompany* Client, bool LockOnly) const { int32 Quantity = 0; for (int CargoIndex = 0; CargoIndex < CargoBay.Num() ; CargoIndex++) { const FFlareCargo& Cargo = CargoBay[CargoIndex]; if(!CheckRestriction(&Cargo, Client)) { continue; } if(LockOnly && Cargo.Lock == EFlareResourceLock::NoLock) { continue; } if (Cargo.Resource == NULL) { Quantity += GetSlotCapacity(); } else if (Cargo.Resource == Resource) { Quantity += GetSlotCapacity() - Cargo.Quantity; } } if((!Client || !Client->IsPlayerCompany()) && Parent->GetGame()->GetQuestManager() != nullptr) { int32 ReservedCapacity = Parent->GetGame()->GetQuestManager()->GetReservedCapacity(Parent, Resource); int32 CapacityAfterReservation = FMath::Max(0, Quantity - ReservedCapacity); return CapacityAfterReservation; } else { return Quantity; } }
BOOL DynamicTypeHandler::FindNextProperty(ScriptContext* scriptContext, BigPropertyIndex& index, JavascriptString** propertyString, PropertyId* propertyId, PropertyAttributes* attributes, Type* type, DynamicType *typeToEnumerate, bool requireEnumerable, bool enumSymbols) { // Type handlers that support big property indexes override this function, so if we're here then this type handler does // not support big property indexes. Forward the call to the small property index version. Assert(GetSlotCapacity() <= PropertyIndexRanges<PropertyIndex>::MaxValue); PropertyIndex smallIndex = static_cast<PropertyIndex>(index); Assert(static_cast<BigPropertyIndex>(smallIndex) == index); const BOOL found = FindNextProperty(scriptContext, smallIndex, propertyString, propertyId, attributes, type, typeToEnumerate, requireEnumerable, enumSymbols); index = smallIndex; return found; }
void DynamicTypeHandler::VerifyObjectHeaderInlinedTypeHandler() const { Assert(IsObjectHeaderInlined(GetOffsetOfInlineSlots())); Assert(GetInlineSlotCapacity() >= GetObjectHeaderInlinableSlotCapacity()); Assert(GetInlineSlotCapacity() == GetSlotCapacity()); }
int32 UFlareCargoBay::GetCapacity() const { return GetSlotCapacity() * CargoBayCount; }
int32 UFlareCargoBay::GiveResources(FFlareResourceDescription* Resource, int32 Quantity, UFlareCompany* Client) { int32 QuantityToGive = Quantity; if (QuantityToGive == 0) { return Quantity; } // First pass, fill already existing slots for (int CargoIndex = 0 ; CargoIndex < CargoBay.Num() ; CargoIndex++) { FFlareCargo& Cargo = CargoBay[CargoIndex]; if (Resource == Cargo.Resource) { if(!CheckRestriction(&Cargo, Client)) { continue; } // Same resource int32 AvailableCapacity = GetSlotCapacity() - Cargo.Quantity; int32 GivenQuantity = FMath::Min(AvailableCapacity, QuantityToGive); if (GivenQuantity > 0) { Cargo.Quantity += GivenQuantity; QuantityToGive -= GivenQuantity; if (QuantityToGive == 0) { return Quantity; } } } } // Fill free cargo slots for (int CargoIndex = 0 ; CargoIndex < CargoBay.Num() ; CargoIndex++) { FFlareCargo& Cargo = CargoBay[CargoIndex]; if (Cargo.Resource == NULL) { if(!CheckRestriction(&Cargo, Client)) { continue; } // Empty Cargo int32 GivenQuantity = FMath::Min(GetSlotCapacity(), QuantityToGive); if (GivenQuantity > 0) { Cargo.Quantity += GivenQuantity; Cargo.Resource = Resource; QuantityToGive -= GivenQuantity; if (QuantityToGive == 0) { return Quantity; } } else { FLOGV("Zero sized cargo bay for %s", *Parent->GetImmatriculation().ToString()) } } } return Quantity - QuantityToGive; }
void UFlareCargoBay::Load(UFlareSimulatedSpacecraft* ParentSpacecraft, TArray<FFlareCargoSave>& Data, int32 minCargoBayCount, int32 minCargoBaySlotCapacity) { Parent = ParentSpacecraft; Game = Parent->GetGame(); CargoBayCount = minCargoBayCount; CargoBaySlotCapacity = minCargoBaySlotCapacity; int32 UsedBay = 0; for(FFlareCargoSave const& Cargo: Data) { if(Cargo.Quantity > 0 || Cargo.Lock != EFlareResourceLock::NoLock) { ++UsedBay; } if(Cargo.Quantity > CargoBaySlotCapacity) { CargoBaySlotCapacity = Cargo.Quantity; } } if(UsedBay > CargoBayCount) { CargoBayCount = UsedBay; } TArray<int32> UsedIndexes; if(Data.Num() > CargoBayCount) { int32 Index = 0; for(FFlareCargoSave const& Cargo: Data) { if(Cargo.Quantity > 0 || Cargo.Lock != EFlareResourceLock::NoLock) { UsedIndexes.Push(Index); } ++Index; } } else { int32 Index = 0; for(FFlareCargoSave const& Cargo: Data) { UsedIndexes.Push(Index); ++Index; } } // Initialize cargo bay CargoBay.Empty(); for (int32 CargoIndex = 0; CargoIndex < CargoBayCount; CargoIndex++) { FFlareCargo Cargo; Cargo.Resource = NULL; Cargo.Quantity = 0; Cargo.Lock = EFlareResourceLock::NoLock; Cargo.Restriction = EFlareResourceRestriction::Everybody; Cargo.ManualLock= false; if (CargoIndex < UsedIndexes.Num()) { // Existing save FFlareCargoSave* CargoSave = &Data[UsedIndexes[CargoIndex]]; Cargo.Restriction = CargoSave->Restriction; if (CargoSave->Quantity > 0) { Cargo.Resource = Game->GetResourceCatalog()->Get(CargoSave->ResourceIdentifier); Cargo.Quantity = FMath::Min(CargoSave->Quantity, GetSlotCapacity()); } if(CargoSave->Lock != EFlareResourceLock::NoLock) { Cargo.Resource = Game->GetResourceCatalog()->Get(CargoSave->ResourceIdentifier); Cargo.Lock = CargoSave->Lock; Cargo.ManualLock = true; } } CargoBay.Add(Cargo); } }