Example #1
0
bool ModuleManager::_fitModule(InventoryItemRef item, EVEItemFlags flag)
{
    bool verifyFailed = false;
    GenericModule * mod = ModuleFactory(item, ShipRef(m_Ship));

    // Check for max turret modules allowed:
    if( mod->isTurretFitted() && (m_Modules->GetFittedTurretCount() == m_Ship->GetMaxTurrentHardpoints().get_int()) )
    {
        //std::map<std::string, PyRep *> args;
        //args["typename"] = new PyString(item->itemName().c_str());
        //args["portion"] = new PyInt(item->type().portionSize());

        throw PyException( MakeUserError( "NotEnoughTurretSlots" ) );
        verifyFailed = true;
    }
    // Check for max launcher modules allowed:
    if( mod->isLauncherFitted() && (m_Modules->GetFittedLauncherCount() == m_Ship->GetMaxLauncherHardpoints().get_int()) )
    {
        //std::map<std::string, PyRep *> args;
        //args["typename"] = new PyString(item->itemName().c_str());
        //args["portion"] = new PyInt(item->type().portionSize());

        throw PyException( MakeUserError( "NotEnoughLauncherSlots" ) );
        verifyFailed = true;
    }
    // Check for max modules of group allowed:
    else if( mod->isMaxGroupFitLimited() && (m_Modules->GetFittedModuleCountByGroup(item->groupID()) == mod->getItem()->GetAttribute(AttrMaxGroupFitted).get_int()) )
    {
        //std::map<std::string, PyRep *> args;
        //args["typename"] = new PyString(item->itemName().c_str());
        //args["portion"] = new PyInt(item->type().portionSize());

        throw PyException( MakeUserError( "CantFitTooManyByGroup" ) );
        verifyFailed = true;
    }
    else
    {
        // Fit Module now that all checks have passed:
        //m_Modules->AddModule(mod->flag(), mod);
        m_Modules->AddModule(flag, mod);
    }

    if( verifyFailed )
    {
        delete mod;
        return false;
    }
    else
        return true;
}
Example #2
0
bool ModuleManager::_fitModule(InventoryItemRef item, EVEItemFlags flag)
{
    bool verifyFailed = false;
	GenericModule * mod;

	// First, check to see if this module item is already fitted, and if so, let's instruct ModuleContainer to move the module
	GenericModule * existingMod = m_Modules->GetModule(item->itemID());

	if( existingMod != NULL )
	{
		if( m_Modules->isSlotOccupied(flag) )
		{
			throw PyException( MakeUserError( "SlotAlreadyOccupied" ) );
			verifyFailed = true;
		}

		m_Modules->RemoveModule( existingMod->flag() );		// Remove this module from existing slot
		existingMod->getItem()->SetFlag( flag );			// Change item's flag to the NEW slot flag
		m_Modules->AddModule( flag, existingMod );			// Add this module back to the container at the NEW slot location
	}
	else
	{
		mod = ModuleFactory(item, ShipRef(m_Ship));

		// Set module's pointer to its owner ModuleManager's log object:
		mod->setLog(m_pLog);

		// Check for max turret modules allowed:
		if( mod->isTurretFitted() && (m_Modules->GetFittedTurretCount() == m_Ship->GetMaxTurrentHardpoints().get_int()) )
		{
			//std::map<std::string, PyRep *> args;
			//args["typename"] = new PyString(item->itemName().c_str());
			//args["portion"] = new PyInt(item->type().portionSize());

			throw PyException( MakeUserError( "NotEnoughTurretSlots" ) );
			verifyFailed = true;
		}
		// Check for max launcher modules allowed:
		if( mod->isLauncherFitted() && (m_Modules->GetFittedLauncherCount() == m_Ship->GetMaxLauncherHardpoints().get_int()) )
		{
			//std::map<std::string, PyRep *> args;
			//args["typename"] = new PyString(item->itemName().c_str());
			//args["portion"] = new PyInt(item->type().portionSize());

			throw PyException( MakeUserError( "NotEnoughLauncherSlots" ) );
			verifyFailed = true;
		}
		// Check for max modules of group allowed:
		else if( mod->isMaxGroupFitLimited() && (m_Modules->GetFittedModuleCountByGroup(item->groupID()) == mod->getItem()->GetAttribute(AttrMaxGroupFitted).get_int()) )
		{
			//std::map<std::string, PyRep *> args;
			//args["typename"] = new PyString(item->itemName().c_str());
			//args["portion"] = new PyInt(item->type().portionSize());

			throw PyException( MakeUserError( "CantFitTooManyByGroup" ) );
			verifyFailed = true;
		}
		else
		{
			// Fit Module now that all checks have passed:
			m_Modules->AddModule(flag, mod);
		}
	}

    if( verifyFailed )
    {
        if( mod != NULL )
			delete mod;
        return false;
    }
    else
        return true;
}