本文整理汇总了C++中InventoryItemRef::Merge方法的典型用法代码示例。如果您正苦于以下问题:C++ InventoryItemRef::Merge方法的具体用法?C++ InventoryItemRef::Merge怎么用?C++ InventoryItemRef::Merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InventoryItemRef
的用法示例。
在下文中一共展示了InventoryItemRef::Merge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadCharge
void ModuleManager::LoadCharge(InventoryItemRef chargeRef, EVEItemFlags flag)
{
ActiveModule * mod = (ActiveModule *)(m_Modules->GetModule(flag)); // Should not be dangrous to assume ALL modules where charges are loaded are ACTIVE modules
if( mod != NULL )
{
// Scenarios to handle:
// + no charge loaded: check capacity >= volume of charge to add, if true, LOAD
// - ELSE: if charge to load is qty > 1, calculate smallest integer qty that will EQUAL capacity, SPLIT remainder off, then LOAD!
// + some charge loaded: check capacity >= volume of charge to add, if true, MERGE new charge to existing
// - ELSE: if charge to load is qty > 1, calculate smallest integer qty that added to existing charge qty will EQUAL capacity, SPLIT remainder off, then LOAD!
// Key facts to get:
// * existing charge ref -> qty and volume/unit
// * module ref -> capacity of module
// * charge to add ref -> qty and volume/unit
EvilNumber modCapacity = mod->getItem()->GetAttribute(AttrCapacity);
EvilNumber chargeToLoadVolume = chargeRef->GetAttribute(AttrVolume);
EvilNumber chargeToLoadQty = EvilNumber(chargeRef->quantity());
/////////////////////////////////////////
// chargeRef->Split();
// chargeRef->Merge();
// mod->Load(chargeRef);
// chargeRef->Move(m_Ship->itemID(), flag); // used to be (m_pOperator->GetLocationID(), flag)
/////////////////////////////////////////
//m_Ship->GetOperator()->Client()->MoveItem(chargeRef->itemID(), m_Ship->itemID(), flag);
if( mod->isLoaded() )
{
// Module is loaded, let's check available capacity:
InventoryItemRef loadedChargeRef = mod->getLoadedChargeRef();
EvilNumber loadedChargeVolume = loadedChargeRef->GetAttribute(AttrVolume);
EvilNumber loadedChargeQty = EvilNumber(loadedChargeRef->quantity());
modCapacity -= (loadedChargeVolume * loadedChargeQty); // Calculate remaining capacity
if( chargeRef->typeID() != loadedChargeRef->typeID() )
{
// Different charge type is being swapped into this module, so unload what's loaded
if( IsStation(m_Ship->GetOperator()->GetLocationID()) )
loadedChargeRef->Move(m_Ship->locationID(), flagHangar);
else
{
m_Ship->ValidateAddItem(flagCargoHold,loadedChargeRef);
loadedChargeRef->Move(m_Ship->itemID(), flagCargoHold);
}
mod->unload();
// Loading of charge will be performed below
}
else
{
if( modCapacity > chargeToLoadVolume )
{
// Great! We can load at least one, let's top off the loaded charges:
uint32 quantityWeCanLoad = floor((modCapacity / chargeToLoadVolume).get_float());
if( quantityWeCanLoad > 0 )
{
if( quantityWeCanLoad < chargeToLoadQty.get_int() )
{
// Split chargeRef to qty 'quantityWeCanLoad'
// Merge new smaller qty 'quantityWeCanLoad' with loadedChargeRef
// Load this merged charge Ref into module
InventoryItemRef loadableChargeQtyRef = chargeRef->Split( quantityWeCanLoad );
loadableChargeQtyRef->ChangeOwner( chargeRef->ownerID() );
loadedChargeRef->Merge( loadableChargeQtyRef );
mod->load( loadedChargeRef );
loadedChargeRef->Move(m_Ship->itemID(), flag); // used to be (m_pOperator->GetLocationID(), flag)
}
else
{
// Merge chargeRef with loadedChargeRef
// Load this merged charge Ref into module
loadedChargeRef->Merge( chargeRef );
mod->load( loadedChargeRef );
loadedChargeRef->Move(m_Ship->itemID(), flag); // used to be (m_pOperator->GetLocationID(), flag)
}
}
else
throw PyException( MakeCustomError( "Cannot load even one unit of this charge!" ) );
}
else
{
throw PyException( MakeCustomError( "Charge is full!" ) );
}
}
}
// Refresh ammo capacity of module in case it was modified in previous code block ahead of a load action:
modCapacity = mod->getItem()->GetAttribute(AttrCapacity);
// Load charge supplied if this module was either never loaded, or just unloaded from a different type right above:
if( !(mod->isLoaded()) )
{
// Module is not loaded at all, let's check total volume of charge to load against available capacity:
if( modCapacity >= (chargeToLoadVolume * chargeToLoadQty) )
{
// We can insert entire stack of chargeRef into module
// Load chargeRef as-is into module
mod->load( chargeRef );
//.........这里部分代码省略.........