void InventoryItem::Move(uint32 new_location, EVEItemFlags new_flag, bool notify) { uint32 old_location = locationID(); EVEItemFlags old_flag = flag(); if( new_location == old_location && new_flag == old_flag ) return; //nothing to do... //first, take myself out of my old inventory, if its loaded. Inventory *old_inventory = m_factory.GetInventory( old_location, false ); if(old_inventory != NULL) old_inventory->RemoveItem( InventoryItemRef( this ) ); //releases its ref m_locationID = new_location; m_flag = new_flag; //then make sure that my new inventory is updated, if its loaded. Inventory *new_inventory = m_factory.GetInventory( new_location, false ); if( new_inventory != NULL ) new_inventory->AddItem( InventoryItemRef( this ) ); //makes a new ref SaveItem(); //notify about the changes. if( notify ) { std::map<int32, PyRep *> changes; if( new_location != old_location ) changes[ixLocationID] = new PyInt(old_location); if( new_flag != old_flag ) changes[ixFlag] = new PyInt(old_flag); SendItemChange( ownerID(), changes ); //changes is consumed } }
InventoryItemRef Inventory::GetByID(uint32 id) const { std::map<uint32, InventoryItemRef>::const_iterator res = mContents.find( id ); if( res != mContents.end() ) return res->second; else return InventoryItemRef(); }
InventoryItemRef ItemFactory::SpawnItem(ItemData &data) { InventoryItemRef i = InventoryItem::Spawn(*this, data); if( !i ) return InventoryItemRef(); // spawn successful; store the ref m_items.insert( std::make_pair( i->itemID(), i ) ); return i; }
InventoryItemRef ModuleManager::GetLoadedChargeOnModule(EVEItemFlags flag) { GenericModule * mod = m_Modules->GetModule(flag); if( mod->isLoaded() ) { if( mod != NULL ) { if( mod->isLoaded() ) return mod->getLoadedChargeRef(); else return InventoryItemRef(); } } else GetLogger()->Warning( "ModuleManager::UnloadCharge()", "WARNING! Called UnloadCharge() on a module that is NOT loaded or not a charged module!" ); return InventoryItemRef(); }
InventoryItemRef InventoryItem::LoadEntity(ItemFactory &factory, uint32 itemID, const ItemData &data) { const ItemType *type = factory.GetType( data.typeID ); InventoryItemRef itemRef = InventoryItemRef( new InventoryItem(factory, itemID, *type, data) ); itemRef->_Load(); return itemRef; }
EnergyTurret::EnergyTurret( InventoryItemRef item, ShipRef ship ) { m_Item = item; m_Ship = ship; m_Effects = new ModuleEffects(m_Item->typeID()); m_ShipAttrComp = new ModifyShipAttributesComponent(this, ship); m_ActiveModuleProc = new ActiveModuleProcessingComponent(item, this, ship, m_ShipAttrComp); m_chargeRef = InventoryItemRef(); // Ensure ref is NULL m_chargeLoaded = false; }
bool InventoryItem::_Load() { // load attributes mAttributeMap.Load(); // update inventory Inventory *inventory = m_factory.GetInventory( locationID(), false ); if( inventory != NULL ) inventory->AddItem( InventoryItemRef( this ) ); return true; }
SuperWeapon::SuperWeapon( InventoryItemRef item, ShipRef ship ) : m_buildUpTimer(0), m_effectDurationTimer(0) { m_Item = item; m_Ship = ship; m_Effects = new ModuleEffects(m_Item->typeID()); m_ShipAttrComp = new ModifyShipAttributesComponent(this, ship); m_ActiveModuleProc = new ActiveModuleProcessingComponent(item, this, ship, m_ShipAttrComp); m_chargeRef = InventoryItemRef(); // Ensure ref is NULL m_chargeLoaded = false; m_effectID = 0; }
InventoryItemRef Inventory::FindFirstByFlag(EVEItemFlags _flag) const { std::map<uint32, InventoryItemRef>::const_iterator cur, end; cur = mContents.begin(); end = mContents.end(); for(; cur != end; cur++) { if( cur->second->flag() == _flag ) return cur->second; } sLog.Error("Inventory", "unable to find first by flag"); return InventoryItemRef(); }
ProjectileTurret::ProjectileTurret( InventoryItemRef item, ShipRef ship ) { m_Item = item; m_Ship = ship; m_Effects = new ModuleEffects(m_Item->typeID()); m_ShipAttrComp = new ModifyShipAttributesComponent(this, ship); m_ActiveModuleProc = new ActiveModuleProcessingComponent(item, this, ship, m_ShipAttrComp); m_chargeRef = InventoryItemRef(); // Ensure ref is NULL m_chargeLoaded = false; m_ModuleState = MOD_UNFITTED; m_ChargeState = MOD_UNLOADED; }
InventoryItemRef InventoryItem::Split(int32 qty_to_take, bool notify) { if(qty_to_take <= 0) { _log(ITEM__ERROR, "%s (%u): Asked to split into a chunk of %d", itemName().c_str(), itemID(), qty_to_take); return InventoryItemRef(); } if(!AlterQuantity(-qty_to_take, notify)) { _log(ITEM__ERROR, "%s (%u): Failed to remove quantity %d during split.", itemName().c_str(), itemID(), qty_to_take); return InventoryItemRef(); } ItemData idata( typeID(), ownerID(), (notify ? 1 : locationID()), //temp location to cause the spawn via update flag(), qty_to_take ); InventoryItemRef res = m_factory.SpawnItem(idata); if(notify) res->Move( locationID(), flag() ); return( res ); }
InventoryItemRef Inventory::GetByTypeFlag(uint32 typeID, EVEItemFlags flag) const { std::map<uint32, InventoryItemRef>::const_iterator cur, end; cur = mContents.begin(); end = mContents.end(); for(; cur != end; cur++) { if( cur->second->typeID() == typeID && cur->second->flag() == flag ) { return cur->second; } } return InventoryItemRef(); }
InventoryItemRef InventoryItem::Spawn(ItemFactory &factory, ItemData &data) { // obtain type of new item const ItemType *t = factory.GetType( data.typeID ); if( t == NULL ) return InventoryItemRef(); // See what to do next: switch( t->categoryID() ) { //! TODO not handled. case EVEDB::invCategories::_System: case EVEDB::invCategories::Station: case EVEDB::invCategories::Material: case EVEDB::invCategories::Accessories: case EVEDB::invCategories::Charge: case EVEDB::invCategories::Trading: case EVEDB::invCategories::Bonus: case EVEDB::invCategories::Commodity: case EVEDB::invCategories::Implant: case EVEDB::invCategories::Reaction: break; /////////////////////////////////////// // Entity: /////////////////////////////////////// case EVEDB::invCategories::Entity: { // Spawn generic item for Entities at this time: uint32 itemID = InventoryItem::_SpawnEntity( factory, data ); if( itemID == 0 ) return InventoryItemRef(); InventoryItemRef itemRef = InventoryItem::LoadEntity( factory, itemID, data ); return itemRef; } /////////////////////////////////////// // Blueprint: /////////////////////////////////////// case EVEDB::invCategories::Blueprint: { BlueprintData bdata; // use default blueprint attributes BlueprintRef blueRef = Blueprint::Spawn( factory, data, bdata ); blueRef.get()->SaveAttributes(); return blueRef; } /////////////////////////////////////// // Celestial: // (used for Cargo Containers, Rings, and Biomasses, Wrecks, Large Collidable Objects, Clouds, // Cosmic Signatures, Mobile Sentry Guns, Global Warp Disruptors, Agents in Space, Cosmic Anomaly, Beacons, Wormholes, // and other celestial static objects such as NPC stations, stars, moons, planets, and stargates) /////////////////////////////////////// case EVEDB::invCategories::Celestial: { if ( (t->groupID() == EVEDB::invGroups::Secure_Cargo_Container) || (t->groupID() == EVEDB::invGroups::Cargo_Container) || (t->groupID() == EVEDB::invGroups::Freight_Container) || (t->groupID() == EVEDB::invGroups::Audit_Log_Secure_Container) || (t->groupID() == EVEDB::invGroups::Spawn_Container) || (t->groupID() == EVEDB::invGroups::Wreck) ) { // Spawn new Cargo Container uint32 itemID = CargoContainer::_Spawn( factory, data ); if( itemID == 0 ) return CargoContainerRef(); CargoContainerRef cargoRef = CargoContainer::Load( factory, itemID ); // THESE SHOULD BE MOVED INTO A CargoContainer::Spawn() function that does not exist yet // Create default dynamic attributes in the AttributeMap: cargoRef.get()->SetAttribute(AttrIsOnline, 1); // Is Online cargoRef.get()->SetAttribute(AttrDamage, 0.0); // Structure Damage //cargoRef.get()->SetAttribute(AttrShieldCharge, cargoRef.get()->GetAttribute(AttrShieldCapacity)); // Shield Charge //cargoRef.get()->SetAttribute(AttrArmorDamage, 0.0); // Armor Damage cargoRef.get()->SetAttribute(AttrMass, cargoRef.get()->type().attributes.mass()); // Mass cargoRef.get()->SetAttribute(AttrRadius, cargoRef.get()->type().attributes.radius()); // Radius cargoRef.get()->SetAttribute(AttrVolume, cargoRef.get()->type().attributes.volume()); // Volume cargoRef.get()->SetAttribute(AttrCapacity, cargoRef.get()->type().attributes.capacity()); // Capacity cargoRef.get()->SaveAttributes(); return cargoRef; //uint32 itemID = InventoryItem::_Spawn( factory, data ); //if( itemID == 0 ) // return InventoryItemRef(); //return InventoryItem::Load( factory, itemID ); } else { // Spawn new Celestial Object uint32 itemID = CelestialObject::_Spawn( factory, data ); if( itemID == 0 ) return CelestialObjectRef(); CelestialObjectRef celestialRef = CelestialObject::Load( factory, itemID ); celestialRef.get()->SaveAttributes(); return celestialRef; } } /////////////////////////////////////// // Ship: /////////////////////////////////////// case EVEDB::invCategories::Ship: { ShipRef shipRef = Ship::Spawn( factory, data ); shipRef.get()->SaveAttributes(); return shipRef; } /////////////////////////////////////// // Skill: /////////////////////////////////////// case EVEDB::invCategories::Skill: { return Skill::Spawn( factory, data ); } /////////////////////////////////////// // Owner: /////////////////////////////////////// case EVEDB::invCategories::Owner: { return Owner::Spawn( factory, data ); } /////////////////////////////////////// // Module: /////////////////////////////////////// case EVEDB::invCategories::Module: { // Spawn generic item: uint32 itemID = InventoryItem::_Spawn( factory, data ); if( itemID == 0 ) return InventoryItemRef(); InventoryItemRef itemRef = InventoryItem::Load( factory, itemID ); // THESE SHOULD BE MOVED INTO A Module::Spawn() function that does not exist yet // Create default dynamic attributes in the AttributeMap: itemRef.get()->SetAttribute(AttrIsOnline, 1); // Is Online itemRef.get()->SetAttribute(AttrDamage, 0.0); // Structure Damage //itemRef.get()->SetAttribute(AttrShieldCharge, itemRef.get()->GetAttribute(AttrShieldCapacity)); // Shield Charge //itemRef.get()->SetAttribute(AttrArmorDamage, 0.0); // Armor Damage itemRef.get()->SetAttribute(AttrMass, itemRef.get()->type().attributes.mass()); // Mass itemRef.get()->SetAttribute(AttrRadius, itemRef.get()->type().attributes.radius()); // Radius itemRef.get()->SetAttribute(AttrVolume, itemRef.get()->type().attributes.volume()); // Volume itemRef.get()->SetAttribute(AttrCapacity, itemRef.get()->type().attributes.capacity()); // Capacity itemRef.get()->SaveAttributes(); return itemRef; } /////////////////////////////////////// // Drone: /////////////////////////////////////// case EVEDB::invCategories::Drone: { // Spawn generic item: uint32 itemID = InventoryItem::_Spawn( factory, data ); if( itemID == 0 ) return InventoryItemRef(); InventoryItemRef itemRef = InventoryItem::Load( factory, itemID ); // THESE SHOULD BE MOVED INTO A Drone::Spawn() function that does not exist yet // Create default dynamic attributes in the AttributeMap: itemRef.get()->SetAttribute(AttrIsOnline, 1); // Is Online itemRef.get()->SetAttribute(AttrDamage, 0.0); // Structure Damage itemRef.get()->SetAttribute(AttrShieldCharge, itemRef.get()->GetAttribute(AttrShieldCapacity)); // Shield Charge itemRef.get()->SetAttribute(AttrArmorDamage, 0.0); // Armor Damage itemRef.get()->SetAttribute(AttrMass, itemRef.get()->type().attributes.mass()); // Mass itemRef.get()->SetAttribute(AttrRadius, itemRef.get()->type().attributes.radius()); // Radius itemRef.get()->SetAttribute(AttrVolume, itemRef.get()->type().attributes.volume()); // Volume itemRef.get()->SetAttribute(AttrCapacity, itemRef.get()->type().attributes.capacity()); // Capacity itemRef.get()->SaveAttributes(); return itemRef; } /////////////////////////////////////// // Deployable: /////////////////////////////////////// case EVEDB::invCategories::Deployable: { // Spawn generic item: uint32 itemID = InventoryItem::_Spawn( factory, data ); if( itemID == 0 ) return InventoryItemRef(); InventoryItemRef itemRef = InventoryItem::Load( factory, itemID ); // THESE SHOULD BE MOVED INTO A Deployable::Spawn() function that does not exist yet // Create default dynamic attributes in the AttributeMap: itemRef.get()->SetAttribute(AttrIsOnline, 1); // Is Online itemRef.get()->SetAttribute(AttrDamage, 0.0); // Structure Damage //itemRef.get()->SetAttribute(AttrShieldCharge, itemRef.get()->GetAttribute(AttrShieldCapacity)); // Shield Charge //itemRef.get()->SetAttribute(AttrArmorDamage, 0.0); // Armor Damage itemRef.get()->SetAttribute(AttrMass, itemRef.get()->type().attributes.mass()); // Mass itemRef.get()->SetAttribute(AttrRadius, itemRef.get()->type().attributes.radius()); // Radius itemRef.get()->SetAttribute(AttrVolume, itemRef.get()->type().attributes.volume()); // Volume itemRef.get()->SetAttribute(AttrCapacity, itemRef.get()->type().attributes.capacity()); // Capacity itemRef.get()->SaveAttributes(); return itemRef; } /////////////////////////////////////// // Asteroid: /////////////////////////////////////// case EVEDB::invCategories::Asteroid: { // Spawn generic item: uint32 itemID = InventoryItem::_Spawn( factory, data ); if( itemID == 0 ) return InventoryItemRef(); InventoryItemRef itemRef = InventoryItem::Load( factory, itemID ); // THESE SHOULD BE MOVED INTO AN Asteroid::Spawn() function that does not exist yet // Create default dynamic attributes in the AttributeMap: itemRef.get()->SetAttribute(AttrRadius, 500.0); // Radius itemRef.get()->SetAttribute(AttrMass, 1000000.0); // Mass itemRef.get()->SetAttribute(AttrVolume, 8000.0); // Volume itemRef.get()->SetAttribute(AttrQuantity, 1000.0); // Quantity itemRef.get()->SaveAttributes(); return itemRef; } /////////////////////////////////////// // Structure: /////////////////////////////////////// case EVEDB::invCategories::Structure: { // Spawn generic item: uint32 itemID = InventoryItem::_Spawn( factory, data ); if( itemID == 0 ) return InventoryItemRef(); InventoryItemRef itemRef = InventoryItem::Load( factory, itemID ); // THESE SHOULD BE MOVED INTO A Structure::Spawn() function that does not exist yet // Create default dynamic attributes in the AttributeMap: itemRef.get()->SetAttribute(AttrIsOnline, 1); // Is Online itemRef.get()->SetAttribute(AttrDamage, 0.0); // Structure Damage itemRef.get()->SetAttribute(AttrShieldCharge, itemRef.get()->GetAttribute(AttrShieldCapacity)); // Shield Charge itemRef.get()->SetAttribute(AttrArmorDamage, 0.0); // Armor Damage itemRef.get()->SetAttribute(AttrMass, itemRef.get()->type().attributes.mass()); // Mass itemRef.get()->SetAttribute(AttrRadius, itemRef.get()->type().attributes.radius()); // Radius itemRef.get()->SetAttribute(AttrVolume, itemRef.get()->type().attributes.volume()); // Volume itemRef.get()->SetAttribute(AttrCapacity, itemRef.get()->type().attributes.capacity()); // Capacity itemRef.get()->SaveAttributes(); return itemRef; } } switch( t->groupID() ) { /////////////////////////////////////// // Station: /////////////////////////////////////// case EVEDB::invGroups::Station: { //_log( ITEM__ERROR, "Refusing to create station '%s'.", data.name.c_str() ); //return InventoryItemRef(); //return Station::Spawn( factory, data ); uint32 itemID = Station::_Spawn( factory, data ); if( itemID == 0 ) return StationRef(); StationRef stationRef = Station::Load( factory, itemID ); // THESE SHOULD BE MOVED INTO A Station::Spawn() function that does not exist yet // Create default dynamic attributes in the AttributeMap: stationRef.get()->SetAttribute(AttrIsOnline, 1); // Is Online stationRef.get()->SetAttribute(AttrDamage, 0.0); // Structure Damage stationRef.get()->SetAttribute(AttrShieldCharge,stationRef.get()->GetAttribute(AttrShieldCapacity)); // Shield Charge stationRef.get()->SetAttribute(AttrArmorDamage, 0.0); // Armor Damage stationRef.get()->SetAttribute(AttrMass, stationRef.get()->type().attributes.mass()); // Mass stationRef.get()->SetAttribute(AttrRadius, stationRef.get()->type().attributes.radius()); // Radius stationRef.get()->SetAttribute(AttrVolume, stationRef.get()->type().attributes.volume()); // Volume stationRef.get()->SetAttribute(AttrCapacity, stationRef.get()->type().attributes.capacity()); // Capacity stationRef.get()->SaveAttributes(); return stationRef; } } // Spawn generic item: uint32 itemID = InventoryItem::_Spawn( factory, data ); if( itemID == 0 ) return InventoryItemRef(); InventoryItemRef itemRef = InventoryItem::Load( factory, itemID ); itemRef.get()->SaveAttributes(); return itemRef; }
RefPtr<_Ty> InventoryItem::_LoadItem(ItemFactory &factory, uint32 itemID, // InventoryItem stuff: const ItemType &type, const ItemData &data) { // See what to do next: switch( type.categoryID() ) { //! TODO not handled. case EVEDB::invCategories::_System: case EVEDB::invCategories::Station: case EVEDB::invCategories::Material: case EVEDB::invCategories::Accessories: case EVEDB::invCategories::Module: case EVEDB::invCategories::Charge: case EVEDB::invCategories::Trading: case EVEDB::invCategories::Bonus: case EVEDB::invCategories::Commodity: case EVEDB::invCategories::Drone: case EVEDB::invCategories::Implant: case EVEDB::invCategories::Deployable: case EVEDB::invCategories::Structure: case EVEDB::invCategories::Reaction: case EVEDB::invCategories::Asteroid: break; /////////////////////////////////////// // Blueprint: /////////////////////////////////////// case EVEDB::invCategories::Blueprint: { return Blueprint::_LoadItem<Blueprint>( factory, itemID, type, data ); } /////////////////////////////////////// // Entity: /////////////////////////////////////// case EVEDB::invCategories::Entity: { if( (type.groupID() == EVEDB::invGroups::Spawn_Container) ) return CargoContainerRef( new CargoContainer( factory, itemID, type, data ) ); else if( (type.groupID() >= EVEDB::invGroups::Asteroid_Angel_Cartel_Frigate && type.groupID() <= EVEDB::invGroups::Deadspace_Serpentis_Frigate) || (type.groupID() >= 755 /* Asteroid Rogue Drone BattleCruiser */ && type.groupID() <= 761 /* Asteroid Rogue Drone Swarm */) || (type.groupID() >= 789 /* Asteroid Angel Cartel Commander Frigate */ && type.groupID() <= 814 /* Asteroid Serpentis Commander Frigate */) || (type.groupID() >= 843 /* Asteroid Rogue Drone Commander BattleCruiser */ && type.groupID() <= 852 /* Asteroid Serpentis Commander Battleship */) || (type.groupID() >= 959 /* Deadspace Sleeper Sleepless Sentinel */ && type.groupID() <= 987 /* Deadspace Sleeper Emergent Patroller */) ) return InventoryItemRef( new InventoryItem(factory, itemID, type, data) ); else return CelestialObjectRef( new CelestialObject( factory, itemID, type, data ) ); } /////////////////////////////////////// // Celestial: /////////////////////////////////////// case EVEDB::invCategories::Celestial: { if( (type.groupID() == EVEDB::invGroups::Secure_Cargo_Container) || (type.groupID() == EVEDB::invGroups::Audit_Log_Secure_Container) || (type.groupID() == EVEDB::invGroups::Freight_Container) || (type.groupID() == EVEDB::invGroups::Cargo_Container) || (type.groupID() == EVEDB::invGroups::Wreck) ) return CargoContainerRef( new CargoContainer( factory, itemID, type, data ) ); else return CelestialObjectRef( new CelestialObject( factory, itemID, type, data ) ); } /////////////////////////////////////// // Ship: /////////////////////////////////////// case EVEDB::invCategories::Ship: { return Ship::_LoadItem<Ship>( factory, itemID, type, data ); } /////////////////////////////////////// // Skill: /////////////////////////////////////// case EVEDB::invCategories::Skill: { return Skill::_LoadItem<Skill>( factory, itemID, type, data ); } /////////////////////////////////////// // Owner: /////////////////////////////////////// case EVEDB::invCategories::Owner: { return Owner::_LoadItem<Owner>( factory, itemID, type, data ); } } // ItemCategory didn't do it, try ItemGroup: switch( type.groupID() ) { /////////////////////////////////////// // Station: /////////////////////////////////////// case EVEDB::invGroups::Station: { return Station::_LoadItem<Station>( factory, itemID, type, data ); } } // Generic item, create one: return InventoryItemRef( new InventoryItem( factory, itemID, type, data ) ); }