47 assert(pShip !=
nullptr);
52 std::map<uint8, GenericModule*>::iterator itr =
m_modules.begin();
71 m_modules.insert(std::pair<uint8, GenericModule*>(
flag,
nullptr));
72 m_fittings.insert(std::pair<uint8, GenericModule*>(
flag,
nullptr));
76 m_modules.insert(std::pair<uint8, GenericModule*>(
flag,
nullptr));
77 m_systems.insert(std::pair<uint8, GenericModule*>(
flag,
nullptr));
81 m_modules.insert(std::pair<uint8, GenericModule*>(
flag,
nullptr));
82 m_systems.insert(std::pair<uint8, GenericModule*>(
flag,
nullptr));
86 std::vector<InventoryItemRef> itemVec;
90 for (
auto cur : itemVec) {
93 _log(MODULE__ERROR,
"MM::Initialize() - %s(%u) has flagNone set in ship %s",\
99 switch (cur->categoryID()) {
101 _log(MODULE__TRACE,
"MM::Initialize() - loading %s(%u) to %s.",\
102 cur->name(), cur->itemID(),
sDataMgr.GetFlagName(cur->flag()));
123 _log(MODULE__TRACE,
"MM::Initialize() - loading %s(%u) to %s.",\
124 cur->name(), cur->itemID(),
sDataMgr.GetFlagName(cur->flag()));
130 if (pMod ==
nullptr) {
132 _log(MODULE__ERROR,
"MM::Initialize() - No module at %s to load charge %s(%u) into",\
133 sDataMgr.GetFlagName(cur->flag()), cur->name(), cur->itemID() );
138 _log(MODULE__TRACE,
"MM::Initialize() - %s at %s is already loaded. Moving %s to cargo.",\
144 _log(MODULE__TRACE,
"MM::Initialize() - loading %s(%u) at %s with %s(%u).",\
146 sDataMgr.GetFlagName(cur->flag()), cur->name(), cur->itemID());
149 cur->SetAttribute(
AttrQuantity, cur->quantity(),
false);
164 std::map<uint8, GenericModule*>::reverse_iterator ritr =
m_systems.rbegin(), rend =
m_systems.rend();
165 while (ritr != rend) {
166 if (ritr->second !=
nullptr)
167 ritr->second->Online();
173 if (itr->second !=
nullptr)
174 if (itr->second->GetAttribute(
AttrOnline).get_bool())
175 itr->second->Online();
188 if (itr->second !=
nullptr)
189 if (itr->second->GetAttribute(
AttrOnline).get_bool())
190 itr->second->Process();
194 if (
sConfig.debug.UseProfiling)
205 if (cur.second !=
nullptr)
206 cur.second->RemoveTarget(pSE);
295 std::map<uint8, GenericModule*>::iterator itr =
m_modules.find((
uint8)flag);
305 if (iRef.
get() !=
nullptr)
313 std::vector<GenericModule*> modVec;
318 if (modVec.empty () ==
true)
360 if (pMod ==
nullptr) {
361 _log(MODULE__ERROR,
"MM::UninstallRig() - Rig %u not found", itemID);
384 if (!
sConfig.debug.IsTestServer)
392 sLog.Warning(
"ModuleManager",
"%s tried to fit %s(%u) at %s, which is not a subsystem", \
455 if (pMod ==
nullptr) {
456 _log(MODULE__ERROR,
"MM::UnfitModule() - Module %u not found", itemID);
460 _log(MODULE__TRACE,
"%s(%u) calling MM::UnfitModule(itemID)", pMod->
GetSelf()->
name(), pMod->
itemID());
478 if (pMod ==
nullptr) {
479 _log(MODULE__ERROR,
"MM::UnfitModule() - Module not found at %s",
sDataMgr.GetFlagName(flag));
483 _log(MODULE__TRACE,
"%s(%u) calling MM::UnfitModule(flag)", pMod->
GetSelf()->
name(), pMod->
itemID());
503 sLog.Warning(
"MM::AddModule",
"%s is not a module slot.",
sDataMgr.GetFlagName(flag));
561 if (pMod ==
nullptr) {
562 _log(MODULE__ERROR,
"MM::Online(itemID) - Module %u not found", itemID);
566 _log(MODULE__WARNING,
"MM::Online(itemID) - %s already Online", pMod->
GetSelf()->
name());
575 _log(MODULE__MESSAGE,
"MM::Online(itemID) - %s going Online", pMod->
GetSelf()->
name());
582 if (pMod ==
nullptr) {
583 _log(MODULE__ERROR,
"MM::Online(flag) - Module not found in %s",
sDataMgr.GetFlagName(flag));
587 _log(MODULE__WARNING,
"MM::Online(flag) - %s already Online", pMod->
GetSelf()->
name());
591 _log(MODULE__MESSAGE,
"MM::Online(flag) - %s going Online", pMod->
GetSelf()->
name());
598 if (pMod ==
nullptr) {
599 _log(MODULE__ERROR,
"MM::Offline(itemID) - Module %u not found", itemID);
603 _log(MODULE__WARNING,
"MM::Offline(itemID) - %s not Online", pMod->
GetSelf()->
name());
608 _log(MODULE__MESSAGE,
"MM::Offline(itemID) - %s going Offline", pMod->
GetSelf()->
name());
615 if (pMod ==
nullptr) {
616 _log(MODULE__ERROR,
"MM::Offline(flag) - Module not found in %s",
sDataMgr.GetFlagName(flag));
620 _log(MODULE__WARNING,
"MM::Offline(flag) - %s not Online", pMod->
GetSelf()->
name());
624 _log(MODULE__MESSAGE,
"MM::Offline(flag) - %s going Offline", pMod->
GetSelf()->
name());
631 if (cur.second !=
nullptr)
632 cur.second->AbortCycle();
638 std::map<uint8, GenericModule*>::reverse_iterator itr =
m_modules.rbegin(), end =
m_modules.rend();
640 if (itr->second !=
nullptr)
641 itr->second->Online();
649 if (cur.second !=
nullptr)
650 cur.second->Offline();
656 if (cur.second !=
nullptr)
657 cur.second->Deactivate();
663 _log(MODULE__ERROR,
"MM::Activate() - Called from a ship with no pilot." );
668 if (pDestiny ==
nullptr) {
674 if (pMod ==
nullptr) {
675 _log(MODULE__ERROR,
"MM::Activate() - Called on module %u that is not loaded.", itemID );
679 _log(MODULE__TRACE,
"MM::Activate() - %s (%u - %s) targetID: %i, repeat: %i.", \
682 if (effectID == 16) {
691 if (effectID == 2255) {
694 throw UserError (
"DeniedActivateTargetNotPresent");
711 throw UserError (
"DeniedActivateInWarp");
713 throw UserError (
"DeniedActivateCloaked");
715 throw UserError (
"DeniedActivateInJump");
719 pMod->
Activate(effectID, targetID, repeat);
725 if (pMod ==
nullptr) {
726 _log(MODULE__ERROR,
"MM::Deactivate() - Called on module %u that is not loaded.", itemID );
731 if (effectName.compare(
"online") == 0) {
732 _log(MODULE__TRACE,
"MM::Deactivate() - %s Offlining - '%s'", pMod->
GetSelf()->
name(), effectName.c_str());
739 _log(MODULE__TRACE,
"MM::Deactivate() - %s Deactivating - '%s'", pMod->
GetSelf()->
name(), effectName.c_str());
746 if (pMod ==
nullptr) {
747 _log(MODULE__ERROR,
"MM::Overload() - Called on module %u that is not loaded.", itemID);
750 _log(MODULE__TRACE,
"MM::Overload() - %s Overloading...", pMod->
GetSelf()->
name());
757 if (pMod ==
nullptr) {
758 _log(MODULE__ERROR,
"MM::DeOverload() - Called on module %u that is not loaded.", itemID);
761 _log(MODULE__TRACE,
"MM::DeOverload() - %s DeOverload...", pMod->
GetSelf()->
name());
782 if (pMod ==
nullptr) {
783 _log(MODULE__ERROR,
"MM::DamageModule() - Module not found.");
788 _log(MODULE__DAMAGE,
"MM::DamageModule() - %s taking %.2f damage. current damage %.2f", \
810 if (pMod !=
nullptr){
811 _log(MODULE__ERROR,
"MM::RepairModule() - Called on module that is not loaded.");
820 if (cur.second !=
nullptr)
821 cur.second->Repair();
871 if (pMod ==
nullptr) {
872 _log(MODULE__ERROR,
"MM::ModuleRepair() - module %s not found.", modID);
885 if (pMod ==
nullptr) {
886 _log(MODULE__ERROR,
"MM::ModuleRepair() - module %s not found.", modID);
896 if (pMod ==
nullptr) {
897 _log(MODULE__ERROR,
"MM::LoadCharge() - module not found at %s",
sDataMgr.GetFlagName(flag));
901 float chargeVolume = chargeRef->GetAttribute(
AttrVolume).get_float();
908 _log(MODULE__TRACE,
"MM::LoadCharge() - %s reloading with same type. remaining capy:%.2f", pMod->
GetSelf()->
name(), modCapacity);
915 _log(MODULE__TRACE,
"MM::LoadCharge() - %s reloading with different type. empty capy:%.2f", pMod->
GetSelf()->
name(), modCapacity);
918 _log(MODULE__TRACE,
"MM::LoadCharge() - %s not loaded. capy:%.2f", pMod->
GetSelf()->
name(), modCapacity);
924 if (modCapacity < chargeVolume)
927 int32 loadQty = floor((modCapacity / chargeVolume));
931 if (loadQty < chargeRef->
quantity()) {
933 chargeRef = chargeRef->Split(loadQty,
false,
true);
934 if (chargeRef.
get() ==
nullptr) {
935 _log(MODULE__ERROR,
"");
942 loadQty = chargeRef->quantity();
997 Rsp_CommonGetInfo_Entry entry2;
998 if (chargeRef->Populate(entry2)) {
1004 result->
SetItem(0,
new PyInt(chargeRef->locationID()));
1008 sLog.Error(
"MM::LoadCharge",
"cannot Populate() %s", chargeRef->name());
1018 if (pMod ==
nullptr) {
1019 _log(MODULE__ERROR,
"MM::UnloadCharge() - module invalid");
1029 _log(MODULE__ERROR,
"MM::UnloadCharge() - %s at %s is not loaded", \
1035 if (chargeRef.get() ==
nullptr) {
1036 _log(MODULE__ERROR,
"MM::UnloadCharge() - charge not found on module %s at %s", \
1044 if (chargeRef->quantity() < 1)
1056 if (sRef.
get() !=
nullptr) {
1058 if (iRef.
get() !=
nullptr) {
1060 iRef->Merge(chargeRef);
1068 _log(MODULE__ERROR,
"MM::UnloadCharge() - Station %u not found for ship %u owned by %s",\
1085 if (iRef.
get() !=
nullptr) {
1088 int16 qty(chargeRef->quantity());
1089 chargeRef->Delete();
1090 iRef->AlterQuantity(qty,
true);
1101 chargeRef->Delete();
1108 if ((pMod !=
nullptr) and pMod->
IsLoaded() )
1119 if (pMod ==
nullptr) {
1120 _log(MODULE__ERROR,
"MM::UnloadModule() - module not found for %u", itemID);
1124 _log(MODULE__TRACE,
"%s(%u) calling MM::UnloadModule(item)", pMod->
GetSelf()->
name(), pMod->
itemID());
1131 if (pMod ==
nullptr) {
1132 _log(MODULE__ERROR,
"MM::UnloadModule() - module not found at %s",
sDataMgr.GetFlagName(flag));
1136 _log(MODULE__TRACE,
"%s(%u) calling MM::UnloadModule(flag)", pMod->
GetSelf()->
name(), pMod->
itemID());
1142 _log(MODULE__TRACE,
"%s(%u) calling MM::UnloadModule(mod)", pMod->
GetSelf()->
name(), pMod->
itemID());
1149 std::map<uint8, GenericModule*>::iterator mItr;
1152 if (mItr->second !=
nullptr)
1161 if (cur.second !=
nullptr)
1162 cur.second->UnloadCharge();
1174 sLog.Magenta(
"MM::UpdateModules()",
"testing");
1180 if (!modVec.empty()) {
1181 _log(MODULE__TRACE,
"MM::UpdateModules(modVec)");
1185 std::vector< GenericModule* > modList;
1188 for (
auto cur : modList) {
1200 sLog.Magenta(
"MM::UpdateModules(flag)",
"Needs to be implemented");
1204 std::vector< GenericModule* > modVec;
1207 for (
auto cur : modVec)
1214 sLog.Magenta(
"MM::CharacterBoardingShip()",
"Needs to be tested");
1217 std::vector<uint32> modVec;
1220 std::vector< GenericModule* > modList;
1223 for (
auto cur : modList)
1224 if (cur->GetAttribute(
AttrOnline).get_bool())
1252 sLog.Magenta(
"MM::ShipWarping()",
"Deactivating non-warpsafe modules.");
1255 if (cur.second !=
nullptr)
1256 if (!cur.second->isWarpSafe())
1257 cur.second->AbortCycle();
1263 sLog.Magenta(
"MM::ShipJumping()",
"Deactivating all modules.");
1273 if (cur.second !=
nullptr)
1274 switch (cur.second->groupID()) {
1281 cur.second->Deactivate();
1298 if (cur.second !=
nullptr)
1299 modVec.push_back(cur.second->GetSelf());
1304 std::map<uint8, GenericModule*>::reverse_iterator itr =
m_modules.rbegin(), end =
m_modules.rend();
1305 while (itr != end) {
1306 if (itr->second !=
nullptr)
1307 modVec.push_back( itr->second->GetSelf() );
1364 std::vector<InventoryItemRef> moduleList;
1366 for (
auto cur : moduleList)
1367 if (cur->HasReqSkill(skillID))
1368 modVec.push_back(cur);
1374 if (cur.second !=
nullptr)
1375 cur.second->GetSelf()->SaveItem();
1377 cur.second->SaveItem();
1386 if (pMod !=
nullptr)
1387 modVec.push_back(pMod->
itemID());
1398 if (pMod !=
nullptr)
1399 modVec.push_back(pMod->
itemID());
1409 std::map<uint8, GenericModule*> tmpList;
1410 for (
auto cur : modVec) {
1412 if (pMod !=
nullptr)
1413 tmpList.insert(std::pair<uint8, GenericModule*>((
uint8)pMod->
flag(), pMod));
1416 if (tmpList.empty())
1418 std::map<uint8, GenericModule*>::reverse_iterator itr = tmpList.rbegin();
1419 for (; itr != tmpList.rend(); ++itr)
1420 pModList.push_back(itr->second);
1425 std::vector< GenericModule* > modVecAll;
1438 for (
auto cur : modVecAll)
1439 if (cur->IsActive())
1440 if (!cur->IsOverloaded())
1441 modVec.push_back(cur);
1446 std::vector< GenericModule* > modVecAll;
1459 for (
auto cur : modVecAll)
1460 if (cur->IsActive()) {
1461 if (!cur->IsOverloaded())
1472 std::vector< GenericModule* > modVec;
1485 for (
auto cur : modVec)
1486 if (cur->IsActive())
1487 if (!cur->IsOverloaded())
1514 if (
sConfig.debug.IsTestServer)
1519 _log(MODULE__TRACE,
"MM::addModuleRef() - adding %s in %s to map.", pMod->
GetSelf()->
name(),
sDataMgr.GetFlagName(flag));
1549 }
else if (pMod->
isRig()) {
1570 if (
sConfig.debug.IsTestServer)
1575 _log(MODULE__TRACE,
"MM::deleteModuleRef() - removing %s from %s.", pMod->
GetSelf()->
name(),
sDataMgr.GetFlagName(flag));
1602 }
else if (pMod->
isRig()) {
1613 return (
GetModule(slot1)->GetModulePowerLevel() ==
GetModule(slot2)->GetModulePowerLevel());
1626 cur.second->AlterQuantity(+1,
false);
1627 cur.second->AlterQuantity(-1,
false);
#define sConfig
A macro for easier access to the singleton.
void addModuleRef(EVEItemFlags flag, GenericModule *pMod)
void GetInventoryVec(std::vector< InventoryItemRef > &itemVec)
void SendNotification(const PyAddress &dest, EVENotificationStream ¬i, bool seq=true)
SystemEntity * GetSE(uint32 entityID) const
void CheckSlotFitLimited(EVEItemFlags flag)
void deleteModuleRef(EVEItemFlags flag, GenericModule *pMod)
void DeOverload(uint32 itemID)
void SendErrorMsg(const char *fmt,...)
#define _log(type, fmt,...)
InventoryItemRef GetLoadedChargeOnModule(EVEItemFlags flag)
virtual void AbortCycle()
virtual bool Merge(InventoryItemRef to_merge, int32 qty=0, bool notify=true)
bool HasAttribute(uint32 attrID)
void UnfitModule(uint32 itemID)
bool HasAvailableSpace(EVEItemFlags flag, InventoryItemRef iRef) const
virtual void DeOverload()
UserError & AddTypeName(const char *name, uint32 typeID)
Shorthand method for adding a type's name.
void UnloadModule(uint32 itemID)
InventoryItemRef GetLoadedChargeRef()
void GetActiveModules(uint8 rack, std::vector< GenericModule * > &modVec)
void CheckGroupFitLimited(EVEItemFlags flag, InventoryItemRef iRef)
void GetShipRigs(std::vector< uint32 > &modVec)
this is a class that kinda mimics how python polymorph's numbers.
void SendNotifyMsg(const char *fmt,...)
void SetAttribute(uint32 attrID, EvilNumber val, bool update=true)
Advanced version of UserError that allows to send a full custom message.
void UninstallRig(uint32 itemID)
void GetModulesInBank(EVEItemFlags flag, std::vector< GenericModule * > &modVec)
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
void GetWeapons(std::list< GenericModule * > &weaponList)
std::map< uint8, GenericModule * > m_fittings
#define is_log_enabled(type)
#define sLog
Evaluates to a NewLog instance.
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type()() itemID() copy() materialLevel()()() itemID() itemID Fits selected item to active ship() skillID(level)-gives skillID to specified level." ) COMMAND( online
void GetModuleListOfRefsAsc(std::vector< InventoryItemRef > &modVec)
DestinyManager * DestinyMgr()
GenericModule * GetModule(EVEItemFlags flag)
PyRep * ModuleRepair(uint32 modID)
void UpdateModules(std::vector< uint32 > modVec)
bool VerifySlotExchange(EVEItemFlags slot1, EVEItemFlags slot2)
void GetModuleListOfRefsOrderedRev(std::vector< InventoryItemRef > &modVec)
virtual void Activate(uint16 effectID, uint32 targetID=0, int16 repeat=0)
bool InstallRig(ModuleItemRef mRef, EVEItemFlags flag)
void GetModuleListOfRefsOrdered(std::vector< InventoryItemRef > &modVec)
#define codelog(type, fmt,...)
void SetItem(size_t index, PyRep *object)
Stores Python object.
SystemManager * SystemMgr() const
bool InstallSubSystem(ModuleItemRef mRef, EVEItemFlags flag)
uint32 locationID() const
std::map< EVEItemFlags, InventoryItemRef > m_charges
void DeactivateAllModules()
void Activate(int32 itemID, uint16 effectID, int32 targetID, int32 repeat)
void SetAttribute(uint16 attrID, int num, bool notify=true)
#define IsFittingSlot(flag)
uint8 GetFittedModuleCountByGroup(uint16 groupID)
void GetShipSubSystems(std::vector< uint32 > &modVec)
const char * GetName() const
const char * GetName() const
static GenericModule * ModuleFactory(ModuleItemRef mRef, ShipItemRef sRef)
void StopModuleRepair(uint32 modID)
Python object "ccp_exceptions.UserError".
#define IsSubSystem(flag)
bool ChangeSingleton(bool singleton, bool notify=false)
static RefPtr StaticCast(const RefPtr< Y > &oth)
Acts as static_cast from one RefPtr to another.
void SortModulesBySlotDec(std::vector< uint32 > &modVec, std::vector< GenericModule * > &pModList)
GenericModule * GetRandModule()
void RemoveTarget(SystemEntity *pSE)
void MultiplyAttribute(uint16 attrID, EvilNumber num, bool notify=false)
EVEItemFlags flag() const
void UnloadCharge(GenericModule *pMod)
void GetModuleListByReqSkill(uint16 skillID, std::vector< InventoryItemRef > &modVec)
void Deactivate(uint32 itemID, std::string effectName)
std::map< uint16, uint8 > m_modByGroup
RefPtr< InventoryItem > InventoryItemRef
void CharacterLeavingShip()
RefPtr< ShipItem > ShipItemRef
uint16 GetAvailableSlotInBank(EVEEffectID slotBank)
#define IsModuleSlot(flag)
int64 MakeRandomInt(int64 low, int64 high)
Generates random integer from interval [low; high].
int64 max(int64 x, int64 y=0)
virtual Client * GetPilot()
void Offline(uint32 itemID)
virtual void UnloadCharge()
EvilNumber GetAttribute(const uint16 attrID) const
void LoadCharge(InventoryItemRef chargeRef, EVEItemFlags flag)
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type()() itemID() copy() materialLevel()() itemID(attributeID)-Retrieves attribute value." ) COMMAND( setattr
void RepairModule(uint32 itemID, EvilNumber amount)
virtual void LoadCharge(InventoryItemRef charge)
bool AddModule(ModuleItemRef mRef, EVEItemFlags flag)
std::map< uint8, GenericModule * > m_systems
void Online(uint32 itemID)
void GetActiveModulesHeat(uint8 rack, float &heat)
void CharacterBoardingShip()
void Overload(uint32 itemID)
std::map< uint8, GenericModule * > m_modules
bool IsSlotOccupied(EVEItemFlags flag)
ModuleManager(ShipItem *const pShip)
void DamageModule(uint32 itemID, float amount)
Inventory * GetMyInventory()
EvilNumber GetAttribute(uint32 attrID)
virtual void Deactivate(std::string effect="")
InventoryItemRef GetByTypeFlag(uint32 typeID, EVEItemFlags flag) const
void SetModuleState(int8 state)
uint8 GetActiveModulesCount(uint8 rack)
const char * itoa(int64 num)
Convers num to string.
void GetModuleListOfRefsDec(std::vector< InventoryItemRef > &modVec)
void UnlinkGroup(uint32 memberID, bool update=false)