Beispiel #1
0
void ModuleManager::UnfitModule(uint32 itemID)
{
    GenericModule * mod = m_Modules->GetModule(itemID);
    if( mod != NULL )
    {
		if( mod->isLoaded() )
		{
			InventoryItemRef loadedChargeRef = mod->getLoadedChargeRef();
			if( IsStation(m_Ship->locationID()) )
				loadedChargeRef->Move(m_Ship->locationID(), flagHangar);		// used to be (m_pOperator->GetLocationID(), flag)
			else
			{
				m_Ship->ValidateAddItem(flagCargoHold,loadedChargeRef);
				//if( m_Ship->ValidateAddItem(flagCargoHold,loadedChargeRef) )
				//{
					loadedChargeRef->Move(m_Ship->itemID(), flagCargoHold);		// used to be (m_pOperator->GetLocationID(), flag)
					mod->unload();
				//}
				//else
				//	throw PyException( MakeCustomError( "Not enough cargo space!") );
			}
		}

		mod->offline();
		m_Modules->RemoveModule(itemID);
    }
}
Beispiel #2
0
PyResult Command_tr( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args )
{
	if( args.argCount() < 3 ) {
		throw PyException( MakeCustomError("Correct Usage: /tr [entityID]") );
	}

	const std::string& name = args.arg( 1 );
	if( "me" != name )
		throw PyException( MakeCustomError( "Translocate (/TR) to non-me who '%s' is not supported yet.", name.c_str() ) );
	
	if( !args.isNumber( 2 ) )
		throw PyException( MakeCustomError( "Argument 1 should be an entity ID" ) );
    uint32 loc = atoi( args.arg( 2 ).c_str() );

    sLog.Log( "Command", "Translocate to %u.", loc );

	GPoint p( 0.0f, 1000000.0f, 0.0f ); //when going to a system, who knows where to stick them... could find a stargate and stick them near it I guess...

		
	if( !IsStation( loc ) && !IsSolarSystem( loc ) )
    {
		Client* target = services->entity_list.FindCharacter( loc );
		if( NULL == target )
			target = services->entity_list.FindByShip( loc );
		if( NULL == target )
			throw PyException( MakeCustomError( "Unable to find location %u.", loc ) );

		loc = target->GetLocationID();
		p = target->GetPosition();
	}

	who->MoveToLocation( loc , p );
	return new PyString( "Translocation successful." );
}
bool AttributeMap::SendAttributeChanges( PyTuple* attrChange )
{
    if (attrChange == NULL)
    {
        sLog.Error("AttributeMap", "unable to send NULL packet");
        return false;
    }

    // Oh hell, this character finding needs to be optimized ( redesigned so its not needed.. ).
    if( (mItem.ownerID() == 1) || (IsStation(mItem.itemID())) )
    {
        // This item is owned by the EVE System either directly, as in the case of a character object,
        // or indirectly, as in the case of a Station, which is owned by the corporation that runs it.
        // So, we don't need to queue up Destiny events in these cases.
        return true;
    }
    else
    {
        Client *client = sEntityList.FindCharacter(mItem.ownerID());
        //Client *client = this->mItem.GetItemFactory()->GetUsingClient();

        if (client == NULL)
        {
            //sLog.Error("AttributeMap::SendAttributeChanges()", "unable to find client:%u", mItem.ownerID());
            //return false;
            return true;
        }
        else
        {
            if( client->Destiny() == NULL )
            {
                //sLog.Warning( "AttributeMap::SendAttributeChanges()", "client->Destiny() returned NULL" );
                //return false;
            }
            else
                client->QueueDestinyEvent(&attrChange);

            return true;
        }
    }
}
Beispiel #4
0
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 );
				chargeRef->Move(m_Ship->itemID(), flag);		// used to be (m_pOperator->GetLocationID(), flag)
			}
			else
			{
				// We need to split off only as many charge units as can fit into this module
				// Split chargeRef
				uint32 quantityWeCanLoad = floor((modCapacity / chargeToLoadVolume).get_float());
				if( quantityWeCanLoad > 0 )
				{
					// 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() );
					mod->load( loadableChargeQtyRef );
					loadableChargeQtyRef->Move(m_Ship->itemID(), flag);		// used to be (m_pOperator->GetLocationID(), flag)
				}
				else
		            throw PyException( MakeCustomError( "Cannot load even one unit of this charge!" ) );
			}
		}
    }
}
Beispiel #5
0
void RamProxyService::_VerifyInstallJob_Call(const Call_InstallJob &args, InventoryItemRef installedItem, const PathElement &bomLocation, Client *const c) {
    // ACTIVITY CHECK
    // ***************

    const ItemType *productType;
    switch(args.activityID) {
        /*
         * Manufacturing
         */
        case ramActivityManufacturing: {
            if(installedItem->categoryID() != EVEDB::invCategories::Blueprint)
                throw(PyException(MakeUserError("RamActivityRequiresABlueprint")));

            BlueprintRef bp = BlueprintRef::StaticCast( installedItem );

            if(!bp->infinite() && (bp->licensedProductionRunsRemaining() - args.runs) < 0)
                throw(PyException(MakeUserError("RamTooManyProductionRuns")));

            productType = &bp->productType();
            break;
        }
        /*
         * Time/Material Research
         */
        case ramActivityResearchingMaterialProductivity:
        case ramActivityResearchingTimeProductivity: {
            if(installedItem->categoryID() != EVEDB::invCategories::Blueprint)
                throw(PyException(MakeUserError("RamActivityRequiresABlueprint")));

            BlueprintRef bp = BlueprintRef::StaticCast( installedItem );

            if(bp->copy())
                throw(PyException(MakeUserError("RamCannotResearchABlueprintCopy")));

            productType = &bp->type();
            break;
        }
        /*
         * Copying
         */
        case ramActivityCopying: {
            if(installedItem->categoryID() != EVEDB::invCategories::Blueprint)
                throw(PyException(MakeUserError("RamActivityRequiresABlueprint")));

            BlueprintRef bp = BlueprintRef::StaticCast( installedItem );

            if(bp->copy())
                throw(PyException(MakeUserError("RamCannotCopyABlueprintCopy")));

            productType = &bp->type();
            break;
        }
        /*
         * The rest
         */
        case ramActivityResearchingTechnology:
        case ramActivityDuplicating:
        case ramActivityReverseEngineering:
        case ramActivityInvention: /* {
            if(installedItem->categoryID() != EVEDB::invCategories::Blueprint)
                throw(PyException(MakeUserError("RamActivityRequiresABlueprint")));

            Blueprint *bp = (Blueprint *)installedItem;

            if(!bp->copy())
                throw(PyException(MakeUserError("RamCannotInventABlueprintOriginal")));

            uint32 productTypeID = m_db.GetTech2Blueprint(installedItem->typeID());
            if(productTypeID == NULL)
                throw(PyException(MakeUserError("RamInventionNoOutput")));

            productType = m_manager->item_factory.type(productTypeID);
            break;
        } */
        default: {
            // not supported
            throw(PyException(MakeUserError("RamActivityInvalid")));
            //throw(PyException(MakeUserError("RamNoKnownOutputType")));
        }
    }

    if(!m_db.IsProducableBy(args.installationAssemblyLineID, productType->groupID()))
        throw(PyException(MakeUserError("RamBadEndProductForActivity")));

    // JOBS CHECK
    // ***********
    if(args.activityID == ramActivityManufacturing) {
        uint32 jobCount = m_db.CountManufacturingJobs(c->GetCharacterID());
        if(c->GetChar()->GetAttribute(AttrManufactureSlotLimit).get_int() <= jobCount) {
            std::map<std::string, PyRep *> exceptArgs;
            exceptArgs["current"] = new PyInt(jobCount);
            exceptArgs["max"] = c->GetChar()->GetAttribute(AttrManufactureSlotLimit).GetPyObject();
            throw(PyException(MakeUserError("MaxFactorySlotUsageReached", exceptArgs)));
        }
    } else {
        uint32 jobCount = m_db.CountResearchJobs(c->GetCharacterID());
        if(c->GetChar()->GetAttribute(AttrMaxLaborotorySlots).get_int() <= jobCount) {
            std::map<std::string, PyRep *> exceptArgs;
            exceptArgs["current"] = new PyInt(jobCount);
            exceptArgs["max"] = c->GetChar()->GetAttribute(AttrMaxLaborotorySlots).GetPyObject();
            throw(PyException(MakeUserError("MaxResearchFacilitySlotUsageReached", exceptArgs)));
        }
    }

    // INSTALLATION CHECK
    // *******************

    uint32 regionID = m_db.GetRegionOfContainer(args.installationContainerID);
    if(regionID == 0)
        throw(PyException(MakeUserError("RamIsNotAnInstallation")));

    if(c->GetRegionID() != regionID)
        throw(PyException(MakeUserError("RamRangeLimitationRegion")));

    // RamStructureNotInSpace
    // RamStructureNotIsSolarsystem
    // RamRangeLimitation
    // RamRangeLimitationJumps
    // RamRangeLimitationJumpsNoSkill

    // ASSEMBLY LINE CHECK
    // *********************

    uint32 ownerID;
    double minCharSec, maxCharSec;
    EVERamRestrictionMask restrictionMask;
    EVERamActivity activity;

    // get properties
    if(!m_db.GetAssemblyLineVerifyProperties(args.installationAssemblyLineID, ownerID, minCharSec, maxCharSec, restrictionMask, activity))
        throw(PyException(MakeUserError("RamInstallationHasNoDefaultContent")));

    // check validity of activity
    if(activity < ramActivityManufacturing || activity > ramActivityInvention)
        throw(PyException(MakeUserError("RamAssemblyLineHasNoActivity")));

    // check security rating if required
    if((restrictionMask & ramRestrictBySecurity) == ramRestrictBySecurity) {
        if(minCharSec > c->GetSecurityRating())
            throw(PyException(MakeUserError("RamAccessDeniedSecStatusTooLow")));

        if(maxCharSec < c->GetSecurityRating())
            throw(PyException(MakeUserError("RamAccessDeniedSecStatusTooHigh")));

        // RamAccessDeniedCorpSecStatusTooHigh
        // RamAccessDeniedCorpSecStatusTooLow
    }

    // check standing if required
    if((restrictionMask & ramRestrictByStanding) == ramRestrictByStanding) {
        // RamAccessDeniedCorpStandingTooLow
        // RamAccessDeniedStandingTooLow
    }

    if((restrictionMask & ramRestrictByAlliance) == ramRestrictByAlliance) {
//      if(...)
            throw(PyException(MakeUserError("RamAccessDeniedWrongAlliance")));
    } else if((restrictionMask & ramRestrictByCorp) == ramRestrictByCorp) {
        if(ownerID != c->GetCorporationID())
            throw(PyException(MakeUserError("RamAccessDeniedWrongCorp")));
    }

    if(args.isCorpJob) {
        if((c->GetCorpRole() & corpRoleFactoryManager) != corpRoleFactoryManager)
            throw(PyException(MakeUserError("RamCannotInstallForCorpByRoleFactoryManager")));

        if(args.activityID == ramActivityManufacturing) {
            if((c->GetCorpRole() & corpRoleCanRentFactorySlot) != corpRoleCanRentFactorySlot)
                throw(PyException(MakeUserError("RamCannotInstallForCorpByRole")));
        } else {
            if((c->GetCorpRole() & corpRoleCanRentResearchSlot) != corpRoleCanRentResearchSlot)
                throw(PyException(MakeUserError("RamCannotInstallForCorpByRole")));
        }
    }

    // INSTALLED ITEM CHECK
    // *********************

    // ownership
    if(args.isCorpJob) {
        if(installedItem->ownerID() != c->GetCorporationID())
            throw(PyException(MakeUserError("RamCannotInstallItemForAnotherCorp")));
    } else {
        if(installedItem->ownerID() != c->GetCharacterID())
            throw(PyException(MakeUserError("RamCannotInstallItemForAnother")));
    }

    // corp hangar permission
    if(    (installedItem->flag() == flagCorpSecurityAccessGroup2 && (c->GetCorpRole() & corpRoleHangarCanTake2) != corpRoleHangarCanTake2)
        || (installedItem->flag() == flagCorpSecurityAccessGroup3 && (c->GetCorpRole() & corpRoleHangarCanTake3) != corpRoleHangarCanTake3)
        || (installedItem->flag() == flagCorpSecurityAccessGroup4 && (c->GetCorpRole() & corpRoleHangarCanTake4) != corpRoleHangarCanTake4)
        || (installedItem->flag() == flagCorpSecurityAccessGroup5 && (c->GetCorpRole() & corpRoleHangarCanTake5) != corpRoleHangarCanTake5)
        || (installedItem->flag() == flagCorpSecurityAccessGroup6 && (c->GetCorpRole() & corpRoleHangarCanTake6) != corpRoleHangarCanTake6)
        || (installedItem->flag() == flagCorpSecurityAccessGroup7 && (c->GetCorpRole() & corpRoleHangarCanTake7) != corpRoleHangarCanTake7)
    )
            throw(PyException(MakeUserError("RamAccessDeniedToBOMHangar")));

    // large location check
    if(IsStation(args.installationContainerID)) {
        if(/*args.isCorpJob && */installedItem->flag() == flagCargoHold)
            throw(PyException(MakeUserError("RamCorpInstalledItemNotInCargo")));

        if(installedItem->locationID() != (uint32)args.installationContainerID) {
            if((uint32)args.installationContainerID == c->GetLocationID()) {
                std::map<std::string, PyRep *> exceptArgs;
                exceptArgs["location"] = new PyString(m_db.GetStationName(args.installationContainerID));

                if(args.isCorpJob)
                    throw(PyException(MakeUserError("RamCorpInstalledItemWrongLocation", exceptArgs)));
                else
                    throw(PyException(MakeUserError("RamInstalledItemWrongLocation", exceptArgs)));
            } else
                throw(PyException(MakeUserError("RamRemoteInstalledItemNotInStation")));
        } else {
            if(args.isCorpJob) {
                if(installedItem->flag() < flagCorpSecurityAccessGroup2 || installedItem->flag() > flagCorpSecurityAccessGroup7) {
                    if((uint32)args.installationContainerID == c->GetLocationID()) {
                        std::map<std::string, PyRep *> exceptArgs;
                        exceptArgs["location"] = new PyString(m_db.GetStationName(args.installationContainerID));

                        throw(PyException(MakeUserError("RamCorpInstalledItemWrongLocation", exceptArgs)));
                    } else
                        throw(PyException(MakeUserError("RamRemoteInstalledItemNotInOffice")));
                }
            } else {
                if(installedItem->flag() != flagHangar) {
                    if((uint32)args.installationInvLocationID == c->GetLocationID()) {
                        std::map<std::string, PyRep *> exceptArgs;
                        exceptArgs["location"] = new PyString(m_db.GetStationName(args.installationContainerID));

                        throw(PyException(MakeUserError("RamInstalledItemWrongLocation", exceptArgs)));
                    } else {
                        throw(PyException(MakeUserError("RamRemoteInstalledItemInStationNotHangar")));
                    }
                }
            }
        }
    } else if((uint32)args.installationContainerID == c->GetShipID()) {
        if(c->GetChar()->flag() != flagPilot)
            throw(PyException(MakeUserError("RamAccessDeniedNotPilot")));

        if(installedItem->locationID() != (uint32)args.installationContainerID)
            throw(PyException(MakeUserError("RamInstalledItemMustBeInShip")));
    } else {
        // here should be stuff around POS, but I dont certainly know how it should work, so ...
        // RamInstalledItemBadLocationStructure
        // RamInstalledItemInStructureNotInContainer
        // RamInstalledItemInStructureUnknownLocation
    }

    // BOM LOCATION CHECK
    // *******************

    // corp hangar permission
    if(    (bomLocation.flag == flagCorpSecurityAccessGroup2 && (c->GetCorpRole() & corpRoleHangarCanTake2) != corpRoleHangarCanTake2)
        || (bomLocation.flag == flagCorpSecurityAccessGroup3 && (c->GetCorpRole() & corpRoleHangarCanTake3) != corpRoleHangarCanTake3)
        || (bomLocation.flag == flagCorpSecurityAccessGroup4 && (c->GetCorpRole() & corpRoleHangarCanTake4) != corpRoleHangarCanTake4)
        || (bomLocation.flag == flagCorpSecurityAccessGroup5 && (c->GetCorpRole() & corpRoleHangarCanTake5) != corpRoleHangarCanTake5)
        || (bomLocation.flag == flagCorpSecurityAccessGroup6 && (c->GetCorpRole() & corpRoleHangarCanTake6) != corpRoleHangarCanTake6)
        || (bomLocation.flag == flagCorpSecurityAccessGroup7 && (c->GetCorpRole() & corpRoleHangarCanTake7) != corpRoleHangarCanTake7)
    )
            throw(PyException(MakeUserError("RamAccessDeniedToBOMHangar")));
}
Beispiel #6
0
bool Inventory::LoadContents(ItemFactory &factory)
{
    // check if the contents has already been loaded...
    if( !IsStation(this->inventoryID()) )
	{
		if( ContentsLoaded() )
		{
			return true;
		}
	}

    sLog.Debug("Inventory", "Recursively loading contents of inventory %u", inventoryID() );

    //load the list of items we need
    std::vector<uint32> items;
    if( !GetItems( factory, items ) )
    {
        sLog.Error("Inventory", "Failed  to get items of %u", inventoryID() );
        return false;
    }

    //Now get each one from the factory (possibly recursing)
    ItemData into;
    uint32 characterID = 0;
    uint32 corporationID = 0;
    uint32 locationID = 0;
    std::vector<uint32>::iterator cur, end;
    cur = items.begin();
    end = items.end();
    for(; cur != end; cur++)
    {
        // Each "cur" item should be checked to see if they are "owned" by the character connected to this client,
        // and if not, then do not "get" the entire contents of this for() loop for that item, except in the case that
        // this item is located in space or belongs to this character's corporation:
        factory.db().GetItem( *cur, into );
        if( factory.GetUsingClient() != NULL )
        {
            characterID = factory.GetUsingClient()->GetCharacterID();
            corporationID = factory.GetUsingClient()->GetCorporationID();
            locationID = factory.GetUsingClient()->GetLocationID();
        }
        else
            sLog.Error( "Inventory::LoadContents()", "Failed to resolve pointer to Client object currently using the ItemFactory." );
        if( (into.ownerID == characterID) || (characterID == 0) || (into.ownerID == corporationID) )// || (into.locationID == locationID) )
        //    || (factory.GetUsingClient() == NULL) )
        {
            // Continue to GetItem() if the client calling this is owned by the character that owns this item
            // --OR--
            // The characterID == 0, which means this is attempting to load the character of this client for the first time.
            // --OR--
            // The pointer to the client object currently "using" the ItemFactory is NULL, meaning no client is using it at the moment.
            if( factory.GetUsingClient() == NULL )
                sLog.Error( "Inventory::LoadContents()", "WARNING! Loading Contents while ItemFactory::GetUsingClient() returned NULL!" );

            InventoryItemRef i = factory.GetItem( *cur );
            if( !i )
            {
                sLog.Error("Inventory::LoadContents()", "Failed to load item %u contained in %u. Skipping.", *cur, inventoryID() );
                continue;
            }

            AddItem( i );
        }
    }

    mContentsLoaded = true;
    return true;
}