EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TargetManager Class Reference

#include "TargetManager.h"

Collaboration diagram for TargetManager:

Classes

class  TargetedByEntry
 
class  TargetEntry
 

Public Member Functions

 TargetManager (SystemEntity *self)
 
 ~TargetManager ()
 
bool Process ()
 
void Unload ()
 
void ClearModules ()
 
void TargetsCleared ()
 
void ClearFromTargets ()
 
void TargetLost (SystemEntity *tSE)
 
void ClearTarget (SystemEntity *tSE)
 
void TargetAdded (SystemEntity *tSE)
 
void TargetedAdd (SystemEntity *tSE)
 
void TargetedLost (SystemEntity *tSE)
 
void ClearTargets (bool notify=true)
 
void ClearAllTargets (bool notify=true)
 
void RemoveTarget (SystemEntity *tSE)
 
bool StartTargeting (SystemEntity *tSE, ShipItemRef sRef)
 
bool IsTargetedBy (SystemEntity *pSE)
 
SystemEntityGetFirstTarget (bool need_locked=false)
 
SystemEntityGetTarget (uint32 targetID, bool need_locked=true) const
 
bool StartTargeting (SystemEntity *who, float lockTime, uint8 maxLockedTargets, double maxTargetLockRange, bool &chase)
 
bool CanAttack ()
 
bool HasNoTargets () const
 
void Destroyed ()
 
void Depleted (MiningLaser *pMod)
 
void AddTargetModule (ActiveModule *pMod)
 
void RemoveTargetModule (ActiveModule *pMod)
 
PyListGetTargets () const
 
PyListGetTargeters () const
 
void QueueEvent (PyTuple **up) const
 
void QueueUpdate (PyTuple **up) const
 
void Dump () const
 
std::string TargetList (uint16 &length, uint16 &count)
 

Protected Member Functions

float TimeToLock (ShipItemRef sRef, SystemEntity *tSE) const
 
void TargetedByLocked (SystemEntity *tSE)
 
void TargetedByLost (SystemEntity *tSE)
 

Static Protected Member Functions

static const char * GetModeName (uint8 mode)
 
static const char * GetStateName (uint8 state)
 

Private Attributes

SystemEntitymySE
 
std::map< uint32, ActiveModule * > m_modules
 
std::map< SystemEntity
*, TargetEntry * > 
m_targets
 
std::map< SystemEntity
*, TargetedByEntry * > 
m_targetedBy
 
bool m_canAttack
 

Detailed Description

Definition at line 79 of file TargetManager.h.

Constructor & Destructor Documentation

TargetManager::TargetManager ( SystemEntity self)
Todo:
(Allan) add target lost and target fail reasons. maybe make common function, and pass "add", "clear", "otheradd", reason, etc ??

NOTE: the above suggestions have been completed and are in TargetManager.new still have bugs to work out.

Definition at line 53 of file TargetManager.cpp.

References m_canAttack, m_modules, m_targetedBy, and m_targets.

54 : mySE(self)
55 {
56  m_canAttack = false;
57 
58  m_modules.clear();
59  m_targets.clear();
60  m_targetedBy.clear();
61 }
std::map< SystemEntity *, TargetEntry * > m_targets
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy
SystemEntity * mySE
std::map< uint32, ActiveModule * > m_modules
TargetManager::~TargetManager ( )
inline

Definition at line 82 of file TargetManager.h.

82 { /* do nothing here */ }

Member Function Documentation

void TargetManager::AddTargetModule ( ActiveModule pMod)

Definition at line 543 of file TargetManager.cpp.

References _log, SystemEntity::GetName(), GenericModule::GetSelf(), GenericModule::GetShipRef(), SystemEntity::IsAsteroidSE(), GenericModule::IsMiningLaser(), GenericModule::itemID(), m_modules, mySE, and InventoryItem::name().

Referenced by ActiveModule::Activate().

544 {
545  _log(TARGET__INFO, "Adding %s:%s to %s's activeModule list.", \
546  pMod->GetShipRef()->name(), pMod->GetSelf()->name(), mySE->GetName() );
547  // i think this check is redundant...shouldnt be able to activate non-miner on roid.
548  if (mySE->IsAsteroidSE())
549  if (!pMod->IsMiningLaser())
550  return;
551 
552  m_modules.emplace(pMod->itemID(), pMod);
553 }
#define _log(type, fmt,...)
Definition: logsys.h:124
const char * name()
uint32 itemID()
Definition: GenericModule.h:97
ModuleItemRef GetSelf()
Definition: GenericModule.h:42
virtual bool IsMiningLaser() const
Definition: GenericModule.h:73
const char * GetName() const
Definition: SystemEntity.h:210
ShipItemRef GetShipRef()
Definition: GenericModule.h:43
SystemEntity * mySE
std::map< uint32, ActiveModule * > m_modules
virtual bool IsAsteroidSE()
Definition: SystemEntity.h:176

Here is the call graph for this function:

Here is the caller graph for this function:

bool TargetManager::CanAttack ( )
inline

Definition at line 134 of file TargetManager.h.

References m_canAttack.

Referenced by SentryAI::Attack(), DroneAIMgr::Attack(), NPCAIMgr::Attack(), and ConcordAI::Attack().

134 { return m_canAttack; }

Here is the caller graph for this function:

void TargetManager::ClearAllTargets ( bool  notify = true)

Definition at line 284 of file TargetManager.cpp.

References _log, ClearFromTargets(), ClearTargets(), SystemEntity::GetID(), SystemEntity::GetName(), mySE, and TargetsCleared().

Referenced by SentryAI::ClearAllTargets(), DroneAIMgr::ClearAllTargets(), Destroyed(), ShipSE::Dock(), DestinyManager::InitWarp(), ShipSE::Jump(), ContainerSE::~ContainerSE(), DynamicSystemEntity::~DynamicSystemEntity(), and ObjectSystemEntity::~ObjectSystemEntity().

284  {
285  ClearTargets(notify);
287  if (notify)
288  TargetsCleared();
289  _log(TARGET__TRACE, "ClearAllTargets: %s(%u) has cleared all targeting information.", mySE->GetName(), mySE->GetID());
290 }
#define _log(type, fmt,...)
Definition: logsys.h:124
void ClearTargets(bool notify=true)
void ClearFromTargets()
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::ClearFromTargets ( )

Definition at line 310 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), m_targetedBy, mySE, and SafeDelete().

Referenced by ClearAllTargets(), and SystemEntity::Delete().

310  {
311  if (m_targetedBy.empty())
312  return;
313 
314  std::vector<SystemEntity *> ToNotify;
315  for (auto cur : m_targetedBy) {
316  SafeDelete(cur.second);
317  //do not notify until we clear our target list! otherwise Bad Things happen. (invalidate iterator here)
318  ToNotify.push_back(cur.first);
319  _log(TARGET__TRACE, "ClearFrom() - %s(%u) has added %s(%u) to delete list.", \
320  mySE->GetName(), mySE->GetID(), cur.first->GetName(), cur.first->GetID());
321  }
322 
323  m_targetedBy.clear();
324 
325  for (auto cur : ToNotify)
326  if (cur->TargetMgr() != nullptr)
327  cur->TargetMgr()->TargetLost(mySE);
328 }
#define _log(type, fmt,...)
Definition: logsys.h:124
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
uint32 GetID()
Definition: SystemEntity.h:207
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::ClearModules ( )

Definition at line 269 of file TargetManager.cpp.

References ActiveModule::AbortCycle(), and m_modules.

Referenced by ShipSE::Dock(), ShipSE::Jump(), ShipSE::Warp(), ContainerSE::~ContainerSE(), DynamicSystemEntity::~DynamicSystemEntity(), and ObjectSystemEntity::~ObjectSystemEntity().

269  {
270  auto cur = m_modules.begin ();
271  auto end = m_modules.end ();
272 
273  ActiveModule* module (nullptr);
274 
275  while (cur != end) {
276  module = cur->second;
277 
278  cur = m_modules.erase (cur);
279 
280  module->AbortCycle ();
281  }
282 }
std::map< uint32, ActiveModule * > m_modules

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::ClearTarget ( SystemEntity tSE)

Definition at line 255 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), m_canAttack, m_targets, mySE, sEntityList, TargetedByLost(), TargetLost(), and SystemEntity::TargetMgr().

Referenced by ConcordAI::Attack(), ConcordAI::CheckDistance(), SentryAI::ClearTarget(), DroneAIMgr::ClearTarget(), NPCAIMgr::ClearTarget(), DroneAIMgr::Process(), ConcordAI::Process(), and ShipSE::RemoveTarget().

255  {
256  //let the other entity know they are no longer targeted.
257  tSE->TargetMgr()->TargetedByLost(mySE);
258  //clear it from our own state
259  TargetLost(tSE);
260  if (m_targets.empty()) {
261  m_canAttack = false;
262  // no targets to process. remove from proc map
263  sEntityList.DeleteTargMgr(mySE);
264  }
265  _log(TARGET__TRACE, "ClearTarget: %s(%u) has cleared target %s(%u).", \
266  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
267 }
#define _log(type, fmt,...)
Definition: logsys.h:124
#define sEntityList
Definition: EntityList.h:208
TargetManager * TargetMgr()
Definition: SystemEntity.h:197
void TargetLost(SystemEntity *tSE)
std::map< SystemEntity *, TargetEntry * > m_targets
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE
void TargetedByLost(SystemEntity *tSE)

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::ClearTargets ( bool  notify = true)

Definition at line 292 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), m_canAttack, m_targets, mySE, SafeDelete(), and sEntityList.

Referenced by ClearAllTargets(), DroneAIMgr::ClearTargets(), and ConcordAI::ClearTargets().

292  {
293  m_canAttack = false;
294 
295  for (auto cur : m_targets) {
296  // failsafe still chance this code is incomplete
297  if (cur.first->TargetMgr() != nullptr)
298  cur.first->TargetMgr()->TargetedByLost(mySE);
299  SafeDelete(cur.second);
300  _log(TARGET__TRACE, "ClearTargets() - %s(%u) has cleared target %s(%u).",
301  mySE->GetName(), mySE->GetID(), cur.first->GetName(), cur.first->GetID());
302  }
303 
304  m_targets.clear();
305 
306  // no targets to process. remove from proc map
307  sEntityList.DeleteTargMgr(mySE);
308 }
#define _log(type, fmt,...)
Definition: logsys.h:124
#define sEntityList
Definition: EntityList.h:208
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
std::map< SystemEntity *, TargetEntry * > m_targets
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::Depleted ( MiningLaser pMod)

Definition at line 618 of file TargetManager.cpp.

References codelog, MiningLaser::Depleted(), SystemEntity::GetName(), SystemEntity::IsAsteroidSE(), GenericModule::itemID(), m_modules, and mySE.

Referenced by MiningLaser::ProcessCycle().

619 {
620  if (!mySE->IsAsteroidSE()) {
621  codelog(MODULE__ERROR, "Depleted() called by Non Astroid %s", mySE->GetName());
622  return;
623  }
624  // remove master module here to avoid placement in map
625  m_modules.erase(pMod->itemID());
626 
627  std::multimap<float, MiningLaser*> mMap;
628  // iterate thru the map of modules and add to map as MiningLasers with their mining volume
629  std::map<uint32, ActiveModule*>::iterator itr = m_modules.begin();
630  while (itr != m_modules.end()) {
631  mMap.emplace(itr->second->GetMiningModule()->GetMiningVolume(), itr->second->GetMiningModule());
632  itr = m_modules.erase(itr); //remove module from map here to avoid segfault on rock delete
633  }
634 
635  // call Depleted() on master module with map of active modules
636  pMod->Depleted(mMap);
637 }
uint32 itemID()
Definition: GenericModule.h:97
#define codelog(type, fmt,...)
Definition: logsys.h:128
const char * GetName() const
Definition: SystemEntity.h:210
void Depleted(std::multimap< float, MiningLaser * > &mMap)
SystemEntity * mySE
std::map< uint32, ActiveModule * > m_modules
virtual bool IsAsteroidSE()
Definition: SystemEntity.h:176

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::Destroyed ( )

Definition at line 562 of file TargetManager.cpp.

References _log, ActiveModule::AbortCycle(), EVEDB::invGroups::Armor_Repair_Projector, EVEDB::invGroups::Cargo_Scanner, ClearAllTargets(), ActiveModule::Deactivate(), Dump(), EVEDB::invGroups::Energy_Destabilizer, EVEDB::invGroups::Energy_Transfer_Array, EVEDB::invGroups::Energy_Vampire, SystemEntity::GetID(), SystemEntity::GetName(), GenericModule::GetProspectModule(), GenericModule::groupID(), m_modules, m_targetedBy, m_targets, mySE, EVEDB::invGroups::Projected_ECCM, EVEDB::invGroups::Remote_Sensor_Booster, EVEDB::invGroups::Remote_Sensor_Damper, EVEDB::invGroups::Salvager, EVEDB::invGroups::Shield_Transporter, EVEDB::invGroups::Ship_Scanner, EVEDB::invGroups::Target_Painter, Prospector::TargetDestroyed(), EVEDB::invGroups::Tracking_Disruptor, and EVEDB::invGroups::Tractor_Beam.

Referenced by ActiveModule::DeactivateCycle(), and SystemEntity::Killed().

563 {
564  _log(TARGET__INFO, "%s(%u) has been destroyed. %u modules, %u targets, and %u targeters in maps.", \
565  mySE->GetName(), mySE->GetID(), m_modules.size(), m_targets.size(), m_targetedBy.size());
566 
567  std::string effect = "TargetDestroyed";
568 
569  ClearAllTargets();
570 
571  // iterate thru the map of modules targeting this object, and call Deactivate on each.
572  auto cur = m_modules.begin ();
573  auto end = m_modules.end ();
574 
575  ActiveModule* module (nullptr);
576 
577  while (cur != end) {
578  // TODO: THIS IS A HACK TO FIX A PROBLEM ON THE TARGET MANAGER
579  // TODO: WHEN A MODULE'S CYCLE IS ABORTED BY THIS FUNCTION, IT ENDS UP CALLING
580  // TODO: ActiveModule::Clear DOWN THE ROAD, WHICH IN TURN REMOVES ITEMS FROM THE m_modules
581  // TODO: MAP WHILE WE'RE ITERATING IT, AND THAT'S A NO-NO UNLESS YOU CAN GET THE NEW
582  // TODO: ITERATOR FROM THE ERASE FUNCTION, THAT'S WHY IT'S HANDLED HERE INSTEAD OF LETTING
583  // TODO: THE ActiveModule::Clear TAKE CARE OF IT
584  module = cur->second;
585 
586  // this should advance the iterator without needing to do any cur++ or anything
587  cur = m_modules.erase (cur);
588  // some modules should immediately cease cycle when target destroyed. miners are NOT in this call
589  switch (module->groupID()) {
603  module->AbortCycle();
604  } break;
606  // set success=false and fall thru
607  module->GetProspectModule()->TargetDestroyed();
608  default: {
609  module->Deactivate(effect);
610  } break;
611  }
612  }
613 
614  Dump();
615 }
#define _log(type, fmt,...)
Definition: logsys.h:124
void ClearAllTargets(bool notify=true)
void Dump() const
std::map< SystemEntity *, TargetEntry * > m_targets
uint32 GetID()
Definition: SystemEntity.h:207
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE
std::map< uint32, ActiveModule * > m_modules

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::Dump ( ) const

Definition at line 751 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), is_log_enabled, m_modules, m_targetedBy, m_targets, and mySE.

Referenced by Destroyed(), and StartTargeting().

751  {
752  if (!is_log_enabled(TARGET__DUMP))
753  return;
754 
755  _log(TARGET__DUMP, "Target Dump for %s(%u):", mySE->GetName(), mySE->GetID());
756  if (m_targets.empty()) {
757  _log(TARGET__DUMP, " No Targets");
758  } else {
759  for (auto cur : m_targets)
760  cur.second->Dump(cur.first);
761  }
762  if (m_targetedBy.empty()) {
763  _log(TARGET__DUMP, " No Targeters");
764  } else {
765  for (auto cur : m_targetedBy)
766  cur.second->Dump(cur.first);
767  }
768 
769  _log(TARGET__DUMP, " Active Modules: (ship:module(moduleID))");
770  if (m_modules.empty()) {
771  _log(TARGET__DUMP, " *NONE*");
772  } else {
773  for (auto cur : m_modules)
774  _log(TARGET__DUMP, "\t\t %s: %s(%u)", cur.second->GetShipRef()->name(), cur.second->GetSelf()->name(), cur.second->itemID());
775  }
776 }
#define _log(type, fmt,...)
Definition: logsys.h:124
#define is_log_enabled(type)
Definition: logsys.h:78
std::map< SystemEntity *, TargetEntry * > m_targets
uint32 GetID()
Definition: SystemEntity.h:207
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE
std::map< uint32, ActiveModule * > m_modules

Here is the call graph for this function:

Here is the caller graph for this function:

SystemEntity * TargetManager::GetFirstTarget ( bool  need_locked = false)

Definition at line 482 of file TargetManager.cpp.

References TargMgr::State::Locked, and m_targets.

Referenced by SentryAI::Process(), DroneAIMgr::Process(), NPCAIMgr::Process(), ConcordAI::Process(), and NPCAIMgr::TargetLost().

482  {
483  if (m_targets.empty())
484  return nullptr;
485 
486  if (!need_locked)
487  return m_targets.begin()->first;
488 
489  std::map<SystemEntity *, TargetEntry *>::iterator itr = m_targets.begin();
490  for (; itr != m_targets.end(); ++itr)
491  if (itr->second->state == TargMgr::State::Locked)
492  return itr->first;
493 
494  return nullptr;
495 }
std::map< SystemEntity *, TargetEntry * > m_targets

Here is the caller graph for this function:

const char * TargetManager::GetModeName ( uint8  mode)
staticprotected

Definition at line 801 of file TargetManager.cpp.

References TargMgr::Mode::Add, TargMgr::Mode::Clear, TargMgr::Mode::LockedBy, TargMgr::Mode::Lost, TargMgr::Mode::None, TargMgr::Mode::OtherAdd, and TargMgr::Mode::OtherLost.

801  {
802 
803  switch(mode) {
804  case TargMgr::Mode::None: return "None";
805  case TargMgr::Mode::Add: return "Add";
806  case TargMgr::Mode::Lost: return "Lost";
807  case TargMgr::Mode::Clear: return "Clear";
808  case TargMgr::Mode::OtherAdd: return "OtherAdd";
809  case TargMgr::Mode::OtherLost: return "OtherLost";
810  case TargMgr::Mode::LockedBy: return "LockedBy";
811  default: return "Invalid";
812  }
813 }
const char * TargetManager::GetStateName ( uint8  state)
staticprotected

Definition at line 791 of file TargetManager.cpp.

References TargMgr::State::Idle, TargMgr::State::Locked, TargMgr::State::Locking, and TargMgr::State::Passive.

Referenced by TargetManager::TargetEntry::Dump(), and TargetManager::TargetedByEntry::Dump().

791  {
792  switch(state) {
793  case TargMgr::State::Idle: return "Idle";
794  case TargMgr::State::Locking: return "Locking";
795  case TargMgr::State::Passive: return "Passive";
796  case TargMgr::State::Locked: return "Locked";
797  default: return "Invalid";
798  }
799 }
entityID heal the character with the entityID note giving you detailed ship status information gives a list of all dynamic entities and players and their destinyState in this bubble shows some current destiny variables save all kick all and halt server immediate command list all items in current location s gives list of cargo contents and volumes in all holds list current session values show current ship DNA show current objects in their destiny state

Here is the caller graph for this function:

SystemEntity * TargetManager::GetTarget ( uint32  targetID,
bool  need_locked = true 
) const

Definition at line 523 of file TargetManager.cpp.

References _log, TargMgr::State::Locked, and m_targets.

523  {
524  if (m_targets.empty())
525  return nullptr;
526 
527  std::map<SystemEntity*, TargetEntry*>::const_iterator itr = m_targets.begin();
528  for (; itr != m_targets.end(); ++itr) {
529  if (itr->first->GetID() != targetID)
530  continue;
531  //found it...
532  if (need_locked and (itr->second->state != TargMgr::State::Locked)) {
533  _log(TARGET__INFO, "Found target %u, but it is not locked.", targetID);
534  continue;
535  }
536  _log(TARGET__INFO, "Found target %u: %s (nl? %s)", targetID, itr->first->GetName(), need_locked?"yes":"no");
537  return itr->first;
538  }
539  _log(TARGET__INFO, "Unable to find target %u (nl? %s)", targetID, need_locked?"yes":"no");
540  return nullptr; //not found.
541 }
#define _log(type, fmt,...)
Definition: logsys.h:124
std::map< SystemEntity *, TargetEntry * > m_targets
PyList * TargetManager::GetTargeters ( ) const

Definition at line 509 of file TargetManager.cpp.

References PyList::AddItemInt(), and m_targetedBy.

509  {
510  PyList* result = new PyList();
511  if (m_targetedBy.empty())
512  return result;
513 
514  std::map<SystemEntity*, TargetedByEntry*>::const_iterator itr = m_targetedBy.begin();
515  for(; itr != m_targetedBy.end(); ++itr)
516  result->AddItemInt( itr->first->GetID() );
517 
518  return result;
519 }
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy
void AddItemInt(int32 intval)
Definition: PyRep.h:702
Python list.
Definition: PyRep.h:639

Here is the call graph for this function:

PyList * TargetManager::GetTargets ( ) const

Definition at line 497 of file TargetManager.cpp.

References PyList::AddItemInt(), and m_targets.

497  {
498  PyList* result = new PyList();
499  if (m_targets.empty())
500  return result;
501 
502  std::map<SystemEntity *, TargetEntry *>::const_iterator itr = m_targets.begin();
503  for (; itr != m_targets.end(); ++itr)
504  result->AddItemInt( itr->first->GetID() );
505 
506  return result;
507 }
std::map< SystemEntity *, TargetEntry * > m_targets
void AddItemInt(int32 intval)
Definition: PyRep.h:702
Python list.
Definition: PyRep.h:639

Here is the call graph for this function:

bool TargetManager::HasNoTargets ( ) const
inline
bool TargetManager::IsTargetedBy ( SystemEntity pSE)

Definition at line 477 of file TargetManager.cpp.

References m_targetedBy.

Referenced by SentryAI::CheckDistance(), and NPCAIMgr::CheckDistance().

478 {
479  return (m_targetedBy.find(pSE) != m_targetedBy.end());
480 }
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy

Here is the caller graph for this function:

bool TargetManager::Process ( )

Definition at line 63 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), GetTimeUSeconds(), TargMgr::State::Idle, TargMgr::State::Locked, TargMgr::State::Locking, m_canAttack, m_targets, mySE, TargMgr::State::Passive, sConfig, sProfiler, TargetAdded(), and Profile::targets.

63  {
64  double profileStartTime = GetTimeUSeconds();
65 
66  if (m_targets.empty())
67  return false;
68 
69  //process outgoing targeting (outgoing will call incoming as needed)
70  std::map<SystemEntity*, TargetEntry*>::iterator itr = m_targets.begin();
71  while (itr != m_targets.end()) {
72  if ((itr->first == nullptr) or (itr->second == nullptr)) {
73  itr = m_targets.erase(itr);
74  continue;
75  }
76  switch (itr->second->state) {
78  case TargMgr::State::Locked:{ //do nothing
79  } break;
80  case TargMgr::State::Passive: // this will be used with stealth modules (which, ofc, are not written yet)
82  if (itr->second->timer.Check(false)) {
83  itr->second->timer.Disable();
84  itr->second->state = TargMgr::State::Locked;
85  _log(TARGET__TRACE, "%s(%u) has finished locking %s(%u)", \
86  mySE->GetName(), mySE->GetID(), itr->first->GetName(), itr->first->GetID());
87  TargetAdded(itr->first);
88  itr->first->TargetMgr()->TargetedByLocked(mySE);
89  m_canAttack = true;
90  }
91  } break;
92  }
93  ++itr;
94  }
95 
96  if (sConfig.debug.UseProfiling)
97  sProfiler.AddTime(Profile::targets, GetTimeUSeconds() - profileStartTime);
98 
99  return true;
100 }
#define sConfig
A macro for easier access to the singleton.
#define _log(type, fmt,...)
Definition: logsys.h:124
#define sProfiler
Definition: dbcore.cpp:39
void TargetAdded(SystemEntity *tSE)
std::map< SystemEntity *, TargetEntry * > m_targets
double GetTimeUSeconds()
Definition: utils_time.cpp:116
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE

Here is the call graph for this function:

void TargetManager::QueueEvent ( PyTuple **  up) const

Definition at line 685 of file TargetManager.cpp.

References m_targetedBy, and PyIncRef.

686 {
687  for (auto cur : m_targetedBy)
688  if (cur.first->HasPilot()) {
689  PyIncRef(*event);
690  cur.first->GetPilot()->QueueDestinyEvent(event);
691  }
692 }
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy
#define PyIncRef(op)
Definition: PyRep.h:56
void TargetManager::QueueUpdate ( PyTuple **  up) const

Definition at line 694 of file TargetManager.cpp.

References m_targetedBy, and PyIncRef.

Referenced by SystemEntity::SendDamageStateChanged().

695 {
696  for (auto cur : m_targetedBy)
697  if (cur.first->HasPilot()) {
698  PyIncRef(*update);
699  cur.first->GetPilot()->QueueDestinyUpdate(update);
700  }
701 }
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy
#define PyIncRef(op)
Definition: PyRep.h:56

Here is the caller graph for this function:

void TargetManager::RemoveTarget ( SystemEntity tSE)

Definition at line 240 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), m_canAttack, m_targets, mySE, SafeDelete(), and sEntityList.

Referenced by ActiveModule::DeactivateCycle().

240  {
241  std::map<SystemEntity*, TargetEntry*>::iterator itr = m_targets.find(tSE);
242  if (itr != m_targets.end()) {
243  SafeDelete(itr->second);
244  m_targets.erase(itr);
245  }
246  if (m_targets.empty()) {
247  m_canAttack = false;
248  // no targets to process. remove from proc map
249  sEntityList.DeleteTargMgr(mySE);
250  }
251  _log(TARGET__TRACE, "RemoveTarget: %s(%u) has removed target %s(%u).", \
252  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
253 }
#define _log(type, fmt,...)
Definition: logsys.h:124
#define sEntityList
Definition: EntityList.h:208
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
std::map< SystemEntity *, TargetEntry * > m_targets
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::RemoveTargetModule ( ActiveModule pMod)

Definition at line 555 of file TargetManager.cpp.

References _log, SystemEntity::GetName(), GenericModule::GetSelf(), GenericModule::GetShipRef(), GenericModule::itemID(), m_modules, mySE, and InventoryItem::name().

Referenced by ActiveModule::Clear(), and ActiveModule::DeactivateCycle().

556 {
557  _log(TARGET__INFO, "Removing the %s on %s from %s's activeModule list.", \
558  pMod->GetSelf()->name(), pMod->GetShipRef()->name(), mySE->GetName() );
559  m_modules.erase(pMod->itemID());
560 }
#define _log(type, fmt,...)
Definition: logsys.h:124
const char * name()
uint32 itemID()
Definition: GenericModule.h:97
ModuleItemRef GetSelf()
Definition: GenericModule.h:42
const char * GetName() const
Definition: SystemEntity.h:210
ShipItemRef GetShipRef()
Definition: GenericModule.h:43
SystemEntity * mySE
std::map< uint32, ActiveModule * > m_modules

Here is the call graph for this function:

Here is the caller graph for this function:

bool TargetManager::StartTargeting ( SystemEntity tSE,
ShipItemRef  sRef 
)

Definition at line 111 of file TargetManager.cpp.

References _log, EVEPOS::StructureState::ArmorReinforced, AttrMaxLockedTargets, AttrMaxTargetRange, codelog, Dump(), EvilNumber::get_double(), EvilNumber::get_uint32(), InventoryItem::GetAttribute(), Client::GetChar(), SystemEntity::GetID(), SystemEntity::GetIHubSE(), Client::GetName(), SystemEntity::GetName(), SystemEntity::GetOutpostSE(), SystemEntity::GetPilot(), SystemEntity::GetPosition(), SystemEntity::GetRadius(), Character::GetSkillLevel(), StructureSE::GetState(), SystemEntity::GetTCUSE(), SystemEntity::GetTowerSE(), SystemEntity::HasPilot(), SystemEntity::IsAsteroidSE(), SystemEntity::IsIHubSE(), SystemEntity::IsOutpostSE(), SystemEntity::IsTCUSE(), SystemEntity::IsTowerSE(), Ga::GaVec3::length(), TargMgr::State::Locking, m_targets, EvESkill::Multitasking, mySE, EVEPOS::StructureState::Online, EVEPOS::StructureState::Reinforced, Client::SendNotifyMsg(), sEntityList, EVEPOS::StructureState::SheildReinforced, Timer::Start(), TargetManager::TargetEntry::state, TargetedAdd(), EvESkill::Targeting, SystemEntity::TargetMgr(), TargetManager::TargetEntry::timer, and TimeToLock().

Referenced by SentryAI::Target(), DroneAIMgr::Target(), NPCAIMgr::Target(), ConcordAI::Target(), SentryAI::Targeted(), NPCAIMgr::Targeted(), and ConcordAI::Targeted().

112 { // NOTE this is for players and CAN throw (client calls this inside try/catch block)
113  if (!mySE->HasPilot()) {
114  codelog(TARGET__ERROR, "StartTargeting() called by pilot-less ship %s(%u) to target %s(%u)", \
115  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
116  return false;
117  }
118 
119  //first make sure they are not already in the list
120  if (m_targets.find(tSE) != m_targets.end()) {
121  _log(TARGET__DEBUG, " %s(%u): Told to target %s(%u), but we are already targeting them. Ignoring request.", \
122  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
123  return false;
124  }
125  // get lower of ship and char target skills, with minimum of 1
126  uint8 maxLockedTargets = 1;
127  uint8 maxCharTargets = mySE->GetPilot()->GetChar()->GetSkillLevel(EvESkill::Targeting);
128  maxCharTargets += mySE->GetPilot()->GetChar()->GetSkillLevel(EvESkill::Multitasking);
129  if (maxCharTargets > 0)
130  if (maxLockedTargets < maxCharTargets)
131  maxLockedTargets = maxCharTargets;
132 
133  uint8 maxShipTargets = (uint8)sRef->GetAttribute(AttrMaxLockedTargets).get_uint32();
134  if (maxShipTargets > 0)
135  if (maxLockedTargets > maxShipTargets)
136  maxLockedTargets = maxShipTargets;
137 
138  if (m_targets.size() >= maxLockedTargets) {
139  mySE->GetPilot()->SendNotifyMsg("Your ship and skills combination can only handle %u targets at a time.", maxLockedTargets);
140  _log(TARGET__DEBUG, " %s(%u): Told to target %s(%u), but we already have max targets of %u. Ignoring request.", \
141  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID(), maxLockedTargets);
142  return false;
143  }
144 
145  // Check if target is an invulnerable structure
146  if (tSE->IsTCUSE()) {
148  mySE->GetPilot()->SendNotifyMsg("You cannot target an invulnerable structure.");
149  return false;
150  }
151  } else if (tSE->IsTowerSE()) {
153  mySE->GetPilot()->SendNotifyMsg("You cannot target an invulnerable structure.");
154  return false;
155  }
156  } else if (tSE->IsIHubSE()) {
158  mySE->GetPilot()->SendNotifyMsg("You cannot target an invulnerable structure.");
159  return false;
160  }
161  } else if (tSE->IsOutpostSE()) {
162  if (tSE->GetOutpostSE()->GetState() == EVEPOS::StructureState::Online) { //TODO: This structure state likely will be different for outposts, will change later.
163  mySE->GetPilot()->SendNotifyMsg("You cannot target an invulnerable structure.");
164  return false;
165  }
166  }
167 
168  // Check against max target range
169  double maxTargetRange = sRef->GetAttribute(AttrMaxTargetRange).get_double();
170  GVector rangeToTarget( mySE->GetPosition(), tSE->GetPosition() );
171  // adjust for target radius, in case of ice or other large objects..
172  double targetDistance = rangeToTarget.length();
173  if (tSE->IsAsteroidSE())
174  targetDistance -= tSE->GetRadius();
175  if (targetDistance > maxTargetRange) {
176  mySE->GetPilot()->SendNotifyMsg("Your ship and skills combination can only target to %.0f meters. %s is %.0f meters away.", \
177  maxTargetRange, tSE->GetName(), targetDistance);
178  _log(TARGET__DEBUG, " %s(%u): Told to target %s(%u), but they are too far away. Ignoring request.", \
179  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
180  return false;
181  }
182 
183  // Calculate Time to Lock target:
184  float lockTime = TimeToLock( sRef, tSE );
185 
186  TargetEntry *te = new TargetEntry();
187  te->state = TargMgr::State::Locking;
188  te->timer.Start(lockTime *1000); //timer has ms resolution
189  m_targets[tSE] = te;
190  tSE->TargetMgr()->TargetedAdd(mySE);
191 
192  _log(TARGET__INFO, "Pilot %s in %s(%u) started targeting %s(%u) (%.2fs lock time)", \
193  mySE->GetPilot()->GetName(), mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID(), lockTime);
194 
195  sEntityList.AddTargMgr(mySE, this);
196 
197  Dump();
198 
199  return true;
200 }
unsigned __int8 uint8
Definition: eve-compat.h:46
void TargetedAdd(SystemEntity *tSE)
GaExpInl GaFloat length() const
Definition: GaTypes.h:156
#define _log(type, fmt,...)
Definition: logsys.h:124
double GetRadius()
Definition: SystemEntity.h:208
uint8 GetState() const
Definition: Structure.h:170
virtual bool HasPilot()
Definition: SystemEntity.h:258
void Dump() const
virtual Client * GetPilot()
Definition: SystemEntity.h:259
virtual StructureSE * GetOutpostSE()
Definition: SystemEntity.h:119
#define sEntityList
Definition: EntityList.h:208
void SendNotifyMsg(const char *fmt,...)
Definition: Client.cpp:2776
TargetManager * TargetMgr()
Definition: SystemEntity.h:197
CharacterRef GetChar() const
Definition: Client.h:164
virtual bool IsIHubSE()
Definition: SystemEntity.h:167
const GPoint & GetPosition() const
Definition: SystemEntity.h:211
virtual bool IsTowerSE()
Definition: SystemEntity.h:168
std::map< SystemEntity *, TargetEntry * > m_targets
#define codelog(type, fmt,...)
Definition: logsys.h:128
uint32 get_uint32()
Definition: EvilNumber.cpp:173
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: Client.h:94
const char * GetName() const
Definition: SystemEntity.h:210
float TimeToLock(ShipItemRef sRef, SystemEntity *tSE) const
SystemEntity * mySE
virtual bool IsAsteroidSE()
Definition: SystemEntity.h:176
virtual TowerSE * GetTowerSE()
Definition: SystemEntity.h:120
virtual bool IsTCUSE()
Definition: SystemEntity.h:165
EvilNumber GetAttribute(const uint16 attrID) const
double get_double()
Definition: EvilNumber.cpp:191
int8 GetSkillLevel(uint16 skillTypeID, bool zeroForNotInjected=true) const
Definition: Character.cpp:575
Definition: gpoint.h:70
virtual TCUSE * GetTCUSE()
Definition: SystemEntity.h:129
virtual IHubSE * GetIHubSE()
Definition: SystemEntity.h:131
virtual bool IsOutpostSE()
Definition: SystemEntity.h:175

Here is the call graph for this function:

Here is the caller graph for this function:

bool TargetManager::StartTargeting ( SystemEntity who,
float  lockTime,
uint8  maxLockedTargets,
double  maxTargetLockRange,
bool &  chase 
)

Definition at line 202 of file TargetManager.cpp.

References _log, Ga::GaVec3::distance(), Dump(), SystemEntity::GetID(), SystemEntity::GetName(), SystemEntity::GetPosition(), TargMgr::State::Locking, m_targets, mySE, sEntityList, Timer::Start(), TargetManager::TargetEntry::state, TargetedAdd(), SystemEntity::TargetMgr(), and TargetManager::TargetEntry::timer.

203 { // NOTE this is for npcs
204  //first make sure they are not already in the list
205  if (m_targets.find(tSE) != m_targets.end()) {
206  _log(TARGET__DEBUG, " %s(%u): Told to target %s(%u), but we are already targeting them. Ignoring request.", \
207  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
208  return true;
209  }
210  // Check against max locked target count
211  if (m_targets.size() >= maxLockedTargets){
212  _log(TARGET__DEBUG, " %s(%u): Told to target %s(%u), but we already have max targets. Ignoring request.", \
213  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
214  return false;
215  }
216  // Check against max target range
217  if (mySE->GetPosition().distance(tSE->GetPosition()) > maxTargetLockRange){
218  _log(TARGET__TRACE, " %s(%u): Told to target %s(%u), but they are too far away. Begin Approaching.", \
219  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
220  chase = true;
221  return false;
222  }
223 
224  TargetEntry *te = new TargetEntry();
225  te->state = TargMgr::State::Locking;
226  te->timer.Start(lockTime);
227  m_targets[tSE] = te;
228  tSE->TargetMgr()->TargetedAdd(mySE);
229 
230  _log(TARGET__INFO, "NPC %s(%u) started targeting %s(%u) (%.2fs lock time)", \
231  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID(), (lockTime /1000));
232 
233  sEntityList.AddTargMgr(mySE, this);
234 
235  Dump();
236 
237  return true;
238 }
#define _log(type, fmt,...)
Definition: logsys.h:124
void Dump() const
#define sEntityList
Definition: EntityList.h:208
const GPoint & GetPosition() const
Definition: SystemEntity.h:211
std::map< SystemEntity *, TargetEntry * > m_targets
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE
GaExpInl GaFloat distance(const GaVec3 &oth) const
Definition: GaTypes.h:158

Here is the call graph for this function:

void TargetManager::TargetAdded ( SystemEntity tSE)

Definition at line 400 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), SystemEntity::GetPilot(), SystemEntity::HasPilot(), SystemEntity::MakeDamageState(), mySE, Client::QueueDestinyEvent(), and Client::QueueDestinyUpdate().

Referenced by Process().

400  {
401  _log(TARGET__TRACE, "%s(%u) - adding target %s(%u).", \
402  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
403  if (!mySE->HasPilot())
404  return;
405  PyTuple* up(nullptr);
406  Notify_OnTarget te;
407  te.mode = "add";
408  te.targetID = tSE->GetID();
409  up = te.Encode();
411  OnDamageStateChange odsc;
412  odsc.entityID = tSE->GetID();
413  odsc.state = tSE->MakeDamageState();
414  up = odsc.Encode();
416 }
#define _log(type, fmt,...)
Definition: logsys.h:124
virtual bool HasPilot()
Definition: SystemEntity.h:258
void QueueDestinyEvent(PyTuple **multiEvent)
Definition: Client.cpp:2124
virtual Client * GetPilot()
Definition: SystemEntity.h:259
Python tuple.
Definition: PyRep.h:567
PyTuple * MakeDamageState()
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
void QueueDestinyUpdate(PyTuple **update, bool DoPackage=false, bool IsSetState=false)
Definition: Client.cpp:2131
SystemEntity * mySE

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::TargetedAdd ( SystemEntity tSE)

Definition at line 418 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), SystemEntity::GetNPCSE(), SystemEntity::GetPilot(), SystemEntity::HasPilot(), SystemEntity::IsNPCSE(), TargMgr::State::Locking, m_targetedBy, mySE, Client::SendNotification(), and NPC::TargetedAdd().

Referenced by StartTargeting().

418  {
419  //first make sure they are not already in the list
420  if (m_targetedBy.find(tSE) != m_targetedBy.end()) {
421  _log(TARGET__INFO, "Cannot add %s(%u) to %s(%u)'s locked list: they're already in there.", \
422  tSE->GetName(), tSE->GetID(), mySE->GetName(), mySE->GetID());
423  return;
424  } else {
425  //new entry.
426  _log(TARGET__TRACE, "%s(%u) - %s(%u) has started target lock on me.", \
427  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
428  TargetedByEntry *te = new TargetedByEntry();
429  te->state = TargMgr::State::Locking;
430  m_targetedBy[tSE] = te;
431  }
432  if (mySE->IsNPCSE())
433  mySE->GetNPCSE()->TargetedAdd(tSE);
434  if (!mySE->HasPilot())
435  return;
436  Notify_OnTarget te;
437  te.mode = "otheradd";
438  te.targetID = tSE->GetID();
439  Notify_OnMultiEvent multi;
440  multi.events = new PyList();
441  multi.events->AddItem(te.Encode());
442  PyTuple* tmp = multi.Encode();
443  mySE->GetPilot()->SendNotification("OnMultiEvent", "clientID", &tmp);
444 }
void SendNotification(const PyAddress &dest, EVENotificationStream &noti, bool seq=true)
Definition: Client.cpp:2245
#define _log(type, fmt,...)
Definition: logsys.h:124
virtual bool IsNPCSE()
Definition: SystemEntity.h:186
virtual NPC * GetNPCSE()
Definition: SystemEntity.h:134
virtual bool HasPilot()
Definition: SystemEntity.h:258
virtual Client * GetPilot()
Definition: SystemEntity.h:259
Python tuple.
Definition: PyRep.h:567
uint32 GetID()
Definition: SystemEntity.h:207
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE
virtual void TargetedAdd(SystemEntity *who)
Definition: NPC.cpp:123
Python list.
Definition: PyRep.h:639

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::TargetedByLocked ( SystemEntity tSE)
protected

Definition at line 364 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), and mySE.

364  {
365  _log(TARGET__TRACE, "%s(%u) has been locked by %s(%u)", \
366  mySE->GetName(), mySE->GetID(), pSE->GetName(), pSE->GetID());
367  // i think this is redundant....check
368  //mySE->TargetMgr()->TargetedAdd(pSE);
369 }
#define _log(type, fmt,...)
Definition: logsys.h:124
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE

Here is the call graph for this function:

void TargetManager::TargetedByLost ( SystemEntity tSE)
protected

Definition at line 371 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), m_targetedBy, mySE, SafeDelete(), and TargetedLost().

Referenced by ClearTarget().

371  {
372  std::map<SystemEntity *, TargetedByEntry *>::iterator itr = m_targetedBy.find(pSE);
373  if (itr == m_targetedBy.end()) {
374  _log(TARGET__DEBUG, "%s(%u) TargetByLost() - Tried to notify %s(%u) of target lost, but they did not have us targeted.", \
375  mySE->GetName(), mySE->GetID(), pSE->GetName(), pSE->GetID());
376  return;
377  }
378 
379  _log(TARGET__TRACE, "%s(%u) is no longer locked by %s(%u)", \
380  mySE->GetName(), mySE->GetID(), pSE->GetName(), pSE->GetID());
381 
382  SafeDelete(itr->second);
383  m_targetedBy.erase(itr);
384  TargetedLost(pSE);
385 }
#define _log(type, fmt,...)
Definition: logsys.h:124
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
void TargetedLost(SystemEntity *tSE)
uint32 GetID()
Definition: SystemEntity.h:207
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::TargetedLost ( SystemEntity tSE)

Definition at line 446 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), SystemEntity::GetPilot(), SystemEntity::HasPilot(), mySE, and Client::SendNotification().

Referenced by TargetedByLost().

446  {
447  _log(TARGET__TRACE, "%s(%u) - %s(%u) has lost target lock on me.", \
448  mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
449  if (!mySE->HasPilot())
450  return;
451  Notify_OnTarget te;
452  te.mode = "otherlost";
453  te.targetID = tSE->GetID();
454  // te.reason = "WarpingOut";
455  // te.reason = "StoppedTargeting";
456  Notify_OnMultiEvent multi;
457  multi.events = new PyList();
458  multi.events->AddItem(te.Encode());
459  PyTuple* tmp = multi.Encode();
460  mySE->GetPilot()->SendNotification("OnMultiEvent", "clientID", &tmp);
461 }
void SendNotification(const PyAddress &dest, EVENotificationStream &noti, bool seq=true)
Definition: Client.cpp:2245
#define _log(type, fmt,...)
Definition: logsys.h:124
virtual bool HasPilot()
Definition: SystemEntity.h:258
virtual Client * GetPilot()
Definition: SystemEntity.h:259
Python tuple.
Definition: PyRep.h:567
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE
Python list.
Definition: PyRep.h:639

Here is the call graph for this function:

Here is the caller graph for this function:

std::string TargetManager::TargetList ( uint16 length,
uint16 count 
)

Definition at line 704 of file TargetManager.cpp.

References m_modules, m_targetedBy, and m_targets.

Referenced by Command_targlist().

704  {
705  std::ostringstream str;
706  if (m_targets.empty()) {
707  str << "Targets: <br>";
708  str << " *NONE*<br>";
709  length += 23;
710  } else {
711  str << "Targets: <br>";
712  length += 11;
713  for (auto cur : m_targets) {
714  str << " " << cur.first->GetName();
715  str << " (" << cur.first->GetID() << ") <br>";
716  length += 35;
717  ++count;
718  }
719  }
720  if (m_targetedBy.empty()) {
721  str << "Targeted by: <br>";
722  str << " *NONE*<br>";
723  length += 28;
724  } else {
725  str << "Targeted by: <br>";
726  length += 15;
727  for (auto cur : m_targetedBy) {
728  str << " " << cur.first->GetName();
729  str << " (" << cur.first->GetID() << ") <br>";
730  length += 35;
731  ++count;
732  }
733  }
734  str << "Active Modules: (ship:module)<br>";
735  length += 30;
736  if (m_modules.empty()) {
737  str << " *NONE*";
738  length += 10;
739  } else {
740  for (auto cur : m_modules) {
741  str << " " << cur.second->GetShipRef()->itemName();
742  str << ":" << cur.second->GetSelf()->itemName() << "<br>";
743  length += 55;
744  ++count;
745  }
746  }
747 
748  return str.str();
749 }
std::map< SystemEntity *, TargetEntry * > m_targets
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy
std::map< uint32, ActiveModule * > m_modules

Here is the caller graph for this function:

void TargetManager::TargetLost ( SystemEntity tSE)

Definition at line 330 of file TargetManager.cpp.

References _log, SystemEntity::DestinyMgr(), DestinyManager::EntityRemoved(), SystemEntity::GetID(), SystemEntity::GetName(), SystemEntity::GetNPCSE(), SystemEntity::GetPilot(), SystemEntity::HasPilot(), SystemEntity::IsNPCSE(), SystemEntity::IsSentrySE(), m_canAttack, m_targets, mySE, SafeDelete(), Client::SendNotification(), sEntityList, and NPC::TargetLost().

Referenced by ClearTarget().

330  {
331  std::map<SystemEntity *, TargetEntry *>::iterator itr = m_targets.find(tSE);
332  if (itr == m_targets.end())
333  return;
334 
335  SafeDelete(itr->second);
336  m_targets.erase(itr);
337 
338  if (m_targets.empty()) {
339  m_canAttack = false;
340  // no targets to process. remove from proc map
341  sEntityList.DeleteTargMgr(mySE);
342  }
343  _log(TARGET__INFO, "%s(%u) has lost lock on %s(%u)", mySE->GetName(), mySE->GetID(), tSE->GetName(), tSE->GetID());
344 
345  if (mySE->IsSentrySE())
346  return;
347 
348  mySE->DestinyMgr()->EntityRemoved(tSE);
349  if (mySE->IsNPCSE())
350  mySE->GetNPCSE()->TargetLost(tSE);
351  if (!mySE->HasPilot())
352  return;
353  Notify_OnTarget te;
354  te.mode = "lost";
355  te.targetID = tSE->GetID();
356  //te.reason = "Docking";
357  Notify_OnMultiEvent multi;
358  multi.events = new PyList();
359  multi.events->AddItem(te.Encode());
360  PyTuple* tmp = multi.Encode(); //this is consumed below
361  mySE->GetPilot()->SendNotification("OnMultiEvent", "clientID", &tmp);
362 }
void SendNotification(const PyAddress &dest, EVENotificationStream &noti, bool seq=true)
Definition: Client.cpp:2245
#define _log(type, fmt,...)
Definition: logsys.h:124
virtual bool IsNPCSE()
Definition: SystemEntity.h:186
virtual void TargetLost(SystemEntity *who)
Definition: NPC.cpp:119
virtual NPC * GetNPCSE()
Definition: SystemEntity.h:134
virtual bool HasPilot()
Definition: SystemEntity.h:258
virtual Client * GetPilot()
Definition: SystemEntity.h:259
#define sEntityList
Definition: EntityList.h:208
Python tuple.
Definition: PyRep.h:567
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
std::map< SystemEntity *, TargetEntry * > m_targets
DestinyManager * DestinyMgr()
Definition: SystemEntity.h:198
uint32 GetID()
Definition: SystemEntity.h:207
void EntityRemoved(SystemEntity *pSE)
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE
virtual bool IsSentrySE()
Definition: SystemEntity.h:162
Python list.
Definition: PyRep.h:639

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::TargetsCleared ( )

Definition at line 463 of file TargetManager.cpp.

References _log, SystemEntity::GetID(), SystemEntity::GetName(), SystemEntity::GetPilot(), SystemEntity::HasPilot(), mySE, and Client::SendNotification().

Referenced by ClearAllTargets().

463  {
464  _log(TARGET__TRACE, "%s(%u) - i am clearing all target data.", mySE->GetName(), mySE->GetID());
465  if (!mySE->HasPilot())
466  return;
467  Notify_OnTarget te;
468  te.mode = "clear";
469  te.targetID = 0;
470  Notify_OnMultiEvent multi;
471  multi.events = new PyList();
472  multi.events->AddItem(te.Encode());
473  PyTuple* tmp = multi.Encode();
474  mySE->GetPilot()->SendNotification("OnMultiEvent", "clientID", &tmp);
475 }
void SendNotification(const PyAddress &dest, EVENotificationStream &noti, bool seq=true)
Definition: Client.cpp:2245
#define _log(type, fmt,...)
Definition: logsys.h:124
virtual bool HasPilot()
Definition: SystemEntity.h:258
virtual Client * GetPilot()
Definition: SystemEntity.h:259
Python tuple.
Definition: PyRep.h:567
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
SystemEntity * mySE
Python list.
Definition: PyRep.h:639

Here is the call graph for this function:

Here is the caller graph for this function:

float TargetManager::TimeToLock ( ShipItemRef  sRef,
SystemEntity tSE 
) const
protected

Definition at line 639 of file TargetManager.cpp.

References asinh, AttrScanResolution, AttrSignatureRadius, Ga::GaVec3::distance(), RefPtr< X >::get(), EvilNumber::get_uint32(), InventoryItem::GetAttribute(), SystemEntity::GetPosition(), SystemEntity::GetSelf(), InventoryItem::HasAttribute(), SystemEntity::IsAsteroidSE(), SystemEntity::IsContainerSE(), SystemEntity::IsDeployableSE(), SystemEntity::IsInanimateSE(), SystemEntity::IsWreckSE(), and InventoryItem::position().

Referenced by StartTargeting().

639  {
640  if ((tSE->IsAsteroidSE()) or (tSE->IsDeployableSE()) or (tSE->IsWreckSE())
641  or (tSE->IsContainerSE()) or (tSE->IsInanimateSE()))
642  return 2.0f;
643 
644  // fixed lock time -allan 24Dec14 -updated 26May15 -revisited after new effects system implementation 25Mar17
646  uint32 sigRad = 25; // set base as capsule with 25m signature radius
647 
648  if ( tSE->GetSelf().get() != nullptr )
651 
652  //https://wiki.eveonline.com/en/wiki/Targeting_speed
653  //locktime = 40000/(scanres * asinh(sigrad)^2)
654  float time = ( 40000 /(scanRes * std::pow(asinh(sigRad), 2))); // higher scan res means faster lock time.
655 
656  /* distance-based modifier to targeting speed? sure, why the hell not? -allan 27.6.15
657  * +0.1s for each 10k distance
658  * distance = pos - targ.pos
659  * disMod = distance /10k (for 10k increments)
660  * time += disMod * 0.1
661  */
662  double distance = sRef->position().distance( tSE->GetPosition());
663  // check for snipers... >85k distance do NOT need additional 7.5+s to targettime
664  // should we check LRT skill for pilots to modify this? yes....not sure how to modify time using this yet...
665  /*
666  * uint8 sLevel = 1;
667  * if (ship->HasPilot()) {
668  * sLevel += ship->GetPilot()->GetChar()->GetSkillLevel(EvESkill::LongRangeTargeting); // bonus to target range
669  * sLevel += ship->GetPilot()->GetChar()->GetSkillLevel(EvESkill::SignatureAnalysis); // skill at operating target systems
670  * sLevel += ship->GetPilot()->GetChar()->GetSkillLevel(EvESkill::Electronics); // basic ship sensor and computer systems
671 }
672 */
673  //if (mySE->IsNPCSE()) // not all snipers are npc
674  if (distance > 85000)
675  distance -= 75000;
676 
677  float disMod = distance /10000;
678  if (disMod < 1)
679  disMod = 0.0f;
680  time += (disMod * 0.1f);
681 
682  return time;
683 }
bool HasAttribute(const uint16 attrID) const
const GPoint & position() const
#define asinh
Definition: eve-compat.h:145
const GPoint & GetPosition() const
Definition: SystemEntity.h:211
InventoryItemRef GetSelf()
Definition: SystemEntity.h:202
virtual bool IsContainerSE()
Definition: SystemEntity.h:157
uint32 get_uint32()
Definition: EvilNumber.cpp:173
X * get() const
Definition: RefPtr.h:213
unsigned __int32 uint32
Definition: eve-compat.h:50
virtual bool IsAsteroidSE()
Definition: SystemEntity.h:176
virtual bool IsWreckSE()
Definition: SystemEntity.h:188
virtual bool IsDeployableSE()
Definition: SystemEntity.h:177
EvilNumber GetAttribute(const uint16 attrID) const
virtual bool IsInanimateSE()
Definition: SystemEntity.h:144
GaExpInl GaFloat distance(const GaVec3 &oth) const
Definition: GaTypes.h:158

Here is the call graph for this function:

Here is the caller graph for this function:

void TargetManager::Unload ( )

Definition at line 102 of file TargetManager.cpp.

References m_targetedBy, m_targets, and SafeDelete().

Referenced by SystemManager::UnloadSystem().

102  {
103  for (auto cur : m_targets)
104  SafeDelete(cur.second);
105  m_targets.clear();
106  for (auto cur : m_targetedBy)
107  SafeDelete(cur.second);
108  m_targetedBy.clear();
109 }
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
std::map< SystemEntity *, TargetEntry * > m_targets
std::map< SystemEntity *, TargetedByEntry * > m_targetedBy

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool TargetManager::m_canAttack
private
std::map<uint32, ActiveModule*> TargetManager::m_modules
private

The documentation for this class was generated from the following files: