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

#include "TurretFormulas.h"

Public Member Functions

TurretFormulas.cpp

formulas for turret tracking, to hit, and other specific things : Allan

Date
: 10 June 2015
float GetToHit (ShipItemRef shipRef, TurretModule *pMod, SystemEntity *pTarget)
 
float GetNPCToHit (NPC *pNPC, SystemEntity *pTarget)
 
float GetDroneToHit (DroneSE *pDrone, SystemEntity *pTarget)
 
float GetSentryToHit (Sentry *pSentry, SystemEntity *pTarget)
 

Detailed Description

Definition at line 17 of file TurretFormulas.h.

Member Function Documentation

float TurretFormulas::GetDroneToHit ( DroneSE pDrone,
SystemEntity pTarget 
)

Definition at line 136 of file TurretFormulas.cpp.

References AttrEntityAttackRange, AttrFalloff, AttrOptimalSigRadius, AttrSignatureRadius, AttrTrackingSpeed, SystemEntity::DestinyMgr(), Ga::GaVec3::distance(), EvilNumber::get_float(), InventoryItem::GetAttribute(), DestinyManager::GetPosition(), SystemEntity::GetSelf(), SystemEntity::GetVelocity(), Ga::GaVec3::length(), MakeRandomFloat(), EvE::max(), and sConfig.

Referenced by DroneAIMgr::AttackTarget().

137 {
138  if (pTarget == nullptr)
139  return 0;
140  float falloff = pDrone->GetSelf()->GetAttribute(AttrFalloff).get_float();
141  float distance = pDrone->DestinyMgr()->GetPosition().distance(pTarget->DestinyMgr()->GetPosition());
142  GVector vector = pTarget->GetVelocity() - pDrone->GetVelocity();
143  float transversalV = vector.length();
144  float a = (transversalV / (distance * pDrone->GetSelf()->GetAttribute(AttrTrackingSpeed).get_float()));
146  float c = pow((a * b), 2);
147  float d = EvE::max(distance - pDrone->GetSelf()->GetAttribute(AttrEntityAttackRange).get_float());
148  float e = pow((d / falloff), 2);
149  float ChanceToHit = pow(0.5, c + e);
150  float rNum = MakeRandomFloat(0.0, 1.0);
151  if (rNum <= sConfig.rates.DroneCritChance)
152  return 3.0f;
153  if (rNum < ChanceToHit)
154  return (rNum + 0.49);
155  // drones will have a minimum damage instead of zero
156  return 0.1;
157 }
#define sConfig
A macro for easier access to the singleton.
GaExpInl GaFloat length() const
Definition: GaTypes.h:156
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
const GVector & GetVelocity()
Definition: SystemEntity.h:240
DestinyManager * DestinyMgr()
Definition: SystemEntity.h:198
InventoryItemRef GetSelf()
Definition: SystemEntity.h:202
int64 max(int64 x, int64 y=0)
Definition: misc.h:103
EvilNumber GetAttribute(const uint16 attrID) const
const GPoint & GetPosition() const
float get_float()
Definition: EvilNumber.cpp:184
Definition: gpoint.h:70
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:

float TurretFormulas::GetNPCToHit ( NPC pNPC,
SystemEntity pTarget 
)

Definition at line 91 of file TurretFormulas.cpp.

References _log, AttrSignatureRadius, SystemEntity::DestinyMgr(), Ga::GaVec3::distance(), EvilNumber::get_float(), NPC::GetAIMgr(), InventoryItem::GetAttribute(), NPCAIMgr::GetFalloff(), NPCAIMgr::GetOptimalRange(), DestinyManager::GetPosition(), SystemEntity::GetSelf(), NPCAIMgr::GetSigRes(), NPCAIMgr::GetTrackingSpeed(), SystemEntity::GetVelocity(), Ga::GaVec3::length(), MakeRandomFloat(), EvE::max(), sConfig, and y().

Referenced by NPCAIMgr::AttackTarget(), and ConcordAI::AttackTarget().

92 {
93  if (pTarget == nullptr)
94  return 0;
95  uint16 sigRes = pNPC->GetAIMgr()->GetSigRes();
96  uint16 range = pNPC->GetAIMgr()->GetOptimalRange();
97  uint32 falloff = pNPC->GetAIMgr()->GetFalloff();
98  float distance = pNPC->DestinyMgr()->GetPosition().distance(pTarget->DestinyMgr()->GetPosition());
99  float trackSpeed = pNPC->GetAIMgr()->GetTrackingSpeed();
100  float targSig = pTarget->GetSelf()->GetAttribute(AttrSignatureRadius).get_float();
101  _log(DAMAGE__TRACE_NPC, "NPC::GetToHit - distance:%.2f, range:%u, falloff:%u", distance, range, falloff);
102 
103  GVector vector = pTarget->GetVelocity() - pNPC->GetVelocity();
104  float transversalV = vector.length();
105  float angularVel = transversalV / distance;
106  _log(DAMAGE__TRACE_NPC, "NPC::GetToHit - transversalV:%.3f, angularVel:%.3f tracking:%.3f, targetSig:%.1f, sigRes:%u", \
107  transversalV, angularVel, trackSpeed, targSig, sigRes);
108 
109  float a = (angularVel / trackSpeed);
110  float b = (sigRes / targSig);
111  float modifier(0.0f);
112  if ((a < 1) and (b > 1)) {
113  b = 1;
114  modifier = (targSig / sigRes);
115  }
116  float c = pow((a * b), 2);
117  float d = EvE::max(distance - range);
118  float e = pow((d / falloff), 2);
119  float x = pow(0.5, c);
120  float y = pow(0.5, e);
121  float ChanceToHit = x * y;
122  _log(DAMAGE__TRACE_NPC, "NPC::GetToHit - (%.3f * %.3f)^2 = c:%.5f : (%.3f / %u)^2 = e:%.5f", a, b, c, d, falloff, e);
123  _log(DAMAGE__TRACE_NPC, "NPC::GetToHit - %f * %f = %.5f", x, y, ChanceToHit);
124  float rNum = MakeRandomFloat(0.0, 1.0);
125  _log(DAMAGE__TRACE_NPC, "NPC::GetToHit - ChanceToHit:%f, Rand:%.3f - %s", ChanceToHit, rNum, ((rNum <= sConfig.rates.NpcCritChance) ? "Crit" : (rNum < ChanceToHit ? "Hit" : "Miss")));
126  if (rNum <= sConfig.rates.NpcCritChance)
127  return 3.0f;
128  if (rNum < ChanceToHit) {
129  if (modifier)
130  return modifier;
131  return (rNum + 0.49);
132  }
133  return 0;
134 }
#define sConfig
A macro for easier access to the singleton.
GaExpInl GaFloat length() const
Definition: GaTypes.h:156
itemID[count] Create count or of the specified() x() y(z)-Jump to the specified position in space.Stopped." ) COMMAND( translocate
#define _log(type, fmt,...)
Definition: logsys.h:124
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
uint16 GetSigRes()
Definition: NPCAI.h:73
const GVector & GetVelocity()
Definition: SystemEntity.h:240
NPCAIMgr * GetAIMgr()
Definition: NPC.h:81
DestinyManager * DestinyMgr()
Definition: SystemEntity.h:198
InventoryItemRef GetSelf()
Definition: SystemEntity.h:202
unsigned __int32 uint32
Definition: eve-compat.h:50
uint16 GetOptimalRange()
Definition: NPCAI.h:72
int64 max(int64 x, int64 y=0)
Definition: misc.h:103
uint32 GetFalloff()
Definition: NPCAI.h:74
EvilNumber GetAttribute(const uint16 attrID) const
const GPoint & GetPosition() const
float get_float()
Definition: EvilNumber.cpp:184
Definition: gpoint.h:70
GaExpInl GaFloat distance(const GaVec3 &oth) const
Definition: GaTypes.h:158
unsigned __int16 uint16
Definition: eve-compat.h:48
double GetTrackingSpeed()
Definition: NPCAI.h:76

Here is the call graph for this function:

Here is the caller graph for this function:

float TurretFormulas::GetSentryToHit ( Sentry pSentry,
SystemEntity pTarget 
)

Definition at line 159 of file TurretFormulas.cpp.

References AttrEntityAttackRange, AttrFalloff, AttrOptimalSigRadius, AttrSignatureRadius, AttrTrackingSpeed, SystemEntity::DestinyMgr(), Ga::GaVec3::distance(), EvilNumber::get_float(), InventoryItem::GetAttribute(), DestinyManager::GetPosition(), SystemEntity::GetPosition(), SystemEntity::GetSelf(), SystemEntity::GetVelocity(), Ga::GaVec3::length(), MakeRandomFloat(), EvE::max(), and sConfig.

Referenced by SentryAI::AttackTarget().

160 {
161  if (pTarget == nullptr)
162  return 0;
163  float sigRes = pSentry->GetSelf()->GetAttribute(AttrOptimalSigRadius).get_float();
164  float falloff = pSentry->GetSelf()->GetAttribute(AttrFalloff).get_float();
165  float distance = pSentry->GetPosition().distance(pTarget->DestinyMgr()->GetPosition());
166  float targSig = pTarget->GetSelf()->GetAttribute(AttrSignatureRadius).get_float();
167  float a = (pTarget->GetVelocity().length() / (distance * pSentry->GetSelf()->GetAttribute(AttrTrackingSpeed).get_float()));
168  float b = (sigRes / targSig);
169  float modifier = 0.0f;
170  if ((a < 1) and (b > 1)) {
171  b = 1;
172  modifier = (targSig / sigRes);
173  }
174  float c = pow((a * b), 2);
175  float d = EvE::max(distance - pSentry->GetSelf()->GetAttribute(AttrEntityAttackRange).get_float());
176  float e = pow((d / falloff), 2);
177  float ChanceToHit = pow(0.5, c + e);
178  float rNum = MakeRandomFloat(0.0, 1.0);
179  if (rNum <= sConfig.rates.SentryCritChance)
180  return 3.0f;
181  if (rNum < ChanceToHit) {
182  if (modifier)
183  return modifier;
184  return (rNum + 0.49);
185  }
186  return 0;
187 }
#define sConfig
A macro for easier access to the singleton.
GaExpInl GaFloat length() const
Definition: GaTypes.h:156
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
const GPoint & GetPosition() const
Definition: SystemEntity.h:211
const GVector & GetVelocity()
Definition: SystemEntity.h:240
DestinyManager * DestinyMgr()
Definition: SystemEntity.h:198
InventoryItemRef GetSelf()
Definition: SystemEntity.h:202
int64 max(int64 x, int64 y=0)
Definition: misc.h:103
EvilNumber GetAttribute(const uint16 attrID) const
const GPoint & GetPosition() const
float get_float()
Definition: EvilNumber.cpp:184
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:

float TurretFormulas::GetToHit ( ShipItemRef  shipRef,
TurretModule pMod,
SystemEntity pTarget 
)

Definition at line 26 of file TurretFormulas.cpp.

References _log, AttrFalloff, AttrMaxRange, AttrOptimalSigRadius, AttrSignatureRadius, AttrTrackingSpeed, SystemEntity::DestinyMgr(), Ga::GaVec3::distance(), EvilNumber::get_float(), EvilNumber::get_uint32(), GenericModule::GetAttribute(), InventoryItem::GetAttribute(), ShipItem::GetPilot(), DestinyManager::GetPosition(), SystemEntity::GetSelf(), Client::GetShipSE(), SystemEntity::GetVelocity(), Ga::GaVec3::length(), MakeRandomFloat(), EvE::max(), InventoryItem::position(), sConfig, and y().

Referenced by TurretModule::ApplyDamage().

27 {
28  if (pTarget == nullptr)
29  return 0;
30  uint32 falloff = pMod->GetAttribute(AttrFalloff).get_uint32();
31  uint32 range = pMod->GetAttribute(AttrMaxRange).get_uint32();
32  float distance = shipRef->position().distance(pTarget->DestinyMgr()->GetPosition());
33  _log(DAMAGE__TRACE, "Turret::GetToHit - distance:%.2f, range:%u, falloff:%u", distance, range, falloff);
34 
35  // calculate transversal from other data
36  /* i have had problems finding exact data for transversal velocity
37  * ideas/data taken from https://wiki.eveuniversity.org/Velocity
38  * The transversal velocity is computed by subtracting the two velocity vectors from one another, and then finding the length of the vector.
39  * angular velocity = transversal velocity / distance
40  */
41  GVector vector = pTarget->GetVelocity() - shipRef->GetPilot()->GetShipSE()->GetVelocity();
42  float transversalV = vector.length();
43  float angularVel = transversalV / distance;
44  float targSig = pTarget->GetSelf()->GetAttribute(AttrSignatureRadius).get_float();
45  float sigRes = pMod->GetAttribute(AttrOptimalSigRadius).get_float();
46  float trackSpeed = pMod->GetAttribute(AttrTrackingSpeed).get_float();
47  _log(DAMAGE__TRACE, "Turret::GetToHit - transversalV:%.3f, angularV:%.3f, tracking:%.3f, targetSig:%.1f, sigRes:%.1f", \
48  transversalV, angularVel, trackSpeed, targSig, sigRes);
49  // calculations for chance to hit --UD 29May17
50  /*ChanceToHit = 0.5 ^ ((((Transversal speed/(Range to target * Turret Tracking))*(Turret Signature Resolution / Target Signature Radius))^2)
51  * + ((max(0, Range To Target - Turret Optimal Range))/Turret Falloff)^2)
52  *
53  * a = Transversal speed/(Range to target * Turret Tracking)
54  * b = Turret Signature Resolution / Target Signature Radius
55  * c = (a * b) ^ 2
56  * d = max(0, distance - optimal range)
57  * e = (d / falloff) ^ 2
58  * tohit = 0.5 ^ (c + e)
59  */
60  float a = (angularVel / trackSpeed);
61  float b = (sigRes / targSig);
62  float modifier(0.0f);
63  if ((a < 1) and (b > 1)) {
64  /* in cases where weapon can track target, but sigRes > targSig, the weapon would not hit on live but *should* hit with reduced damage
65  * modify formula to remove Signature variable from equation, test toHit against tracking,
66  * then use Signature variables to determine amount of damage reduction (i.e. large gun vs. small ship)
67  */
68  b = 1;
69  modifier = (targSig / sigRes);
70  }
71  float c = pow((a * b), 2);
72  float d = EvE::max(distance - range);
73  float e = pow((d / falloff), 2);
74  float x = pow(0.5, c);
75  float y = pow(0.5, e);
76  float ChanceToHit = x * y;
77  _log(DAMAGE__TRACE, "Turret::GetToHit - (%.3f * %.3f)^2 = c:%.5f : (%.3f / %u)^2 = e:%.5f", a, b, c, d, falloff, e);
78  float rNum = MakeRandomFloat();
79  _log(DAMAGE__TRACE, "Turret::GetToHit - %f * %f = %.5f - Rand:%.3f - %s", \
80  x, y, ChanceToHit, rNum, ((rNum <= sConfig.rates.PlayerCritChance) ? "Crit" : (rNum < ChanceToHit ? "Hit" : "Miss")));
81  if (rNum <= sConfig.rates.PlayerCritChance)
82  return 3.0f;
83  if (rNum < ChanceToHit) {
84  if (modifier)
85  return modifier;
86  return (rNum + 0.49);
87  }
88  return 0;
89 }
#define sConfig
A macro for easier access to the singleton.
GaExpInl GaFloat length() const
Definition: GaTypes.h:156
itemID[count] Create count or of the specified() x() y(z)-Jump to the specified position in space.Stopped." ) COMMAND( translocate
#define _log(type, fmt,...)
Definition: logsys.h:124
const GPoint & position() const
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
const GVector & GetVelocity()
Definition: SystemEntity.h:240
DestinyManager * DestinyMgr()
Definition: SystemEntity.h:198
InventoryItemRef GetSelf()
Definition: SystemEntity.h:202
uint32 get_uint32()
Definition: EvilNumber.cpp:173
unsigned __int32 uint32
Definition: eve-compat.h:50
ShipSE * GetShipSE()
Definition: Client.h:168
int64 max(int64 x, int64 y=0)
Definition: misc.h:103
virtual Client * GetPilot()
Definition: Ship.h:72
EvilNumber GetAttribute(const uint16 attrID) const
const GPoint & GetPosition() const
float get_float()
Definition: EvilNumber.cpp:184
Definition: gpoint.h:70
GaExpInl GaFloat distance(const GaVec3 &oth) const
Definition: GaTypes.h:158
EvilNumber GetAttribute(uint32 attrID)
Definition: GenericModule.h:53

Here is the call graph for this function:

Here is the caller graph for this function:


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