aim: look at last enemy origin when just loosed focus

fix: saving bot practice took enormous amount of time when changing level on large practice database
refactor: changed random number generator usage
This commit is contained in:
jeefo 2024-04-25 15:03:39 +03:00
commit 3358168fad
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
27 changed files with 588 additions and 581 deletions

View file

@ -193,25 +193,25 @@ public:
m_printQueueFlushTimestamp = 0.0f;
}
int intValue (size_t arg) const {
if (!hasArg (arg)) {
return 0;
template <typename U> constexpr U arg (const size_t index) const {
if constexpr (cr::is_same <U, float>::value) {
if (!hasArg (index)) {
return 0.0f;
}
return m_args[index].as <float> ();
}
return m_args[arg].int_ ();
}
float floatValue (size_t arg) const {
if (!hasArg (arg)) {
return 0.0f;
else if constexpr (cr::is_same <U, int>::value) {
if (!hasArg (index)) {
return 0;
}
return m_args[index].as <int> ();
}
return m_args[arg].float_ ();
}
StringRef strValue (size_t arg) {
if (!hasArg (arg)) {
return "";
else if constexpr (cr::is_same <U, StringRef>::value) {
if (!hasArg (index)) {
return "";
}
return m_args[index];
}
return m_args[arg];
}
bool hasArg (size_t arg) const {

View file

@ -188,7 +188,7 @@ public:
void prepareBotArgs (edict_t *ent, String str);
// adds cvar to registration stack
void addNewCvar (const char *name, const char *value, const char *info, bool bounded, float min, float max, int32_t varType, bool missingAction, const char *regval, class ConVar *self);
void pushConVar (StringRef name, StringRef value, StringRef info, bool bounded, float min, float max, int32_t varType, bool missingAction, StringRef regval, class ConVar *self);
// check the cvar bounds
void checkCvarsBounds ();
@ -470,18 +470,18 @@ public:
~ConVar () = default;
public:
ConVar (const char *name, const char *initval, int32_t type = Var::NoServer, bool regMissing = false, const char *regVal = nullptr) : ptr (nullptr) {
ConVar (StringRef name, StringRef initval, int32_t type = Var::NoServer, bool regMissing = false, StringRef regVal = nullptr) : ptr (nullptr) {
setPrefix (name, type);
Game::instance ().addNewCvar (name_.chars (), initval, "", false, 0.0f, 0.0f, type, regMissing, regVal, this);
Game::instance ().pushConVar (name_.chars (), initval, "", false, 0.0f, 0.0f, type, regMissing, regVal, this);
}
ConVar (const char *name, const char *initval, const char *info, bool bounded = true, float min = 0.0f, float max = 1.0f, int32_t type = Var::NoServer, bool regMissing = false, const char *regVal = nullptr) : ptr (nullptr) {
ConVar (StringRef name, StringRef initval, StringRef info, bool bounded = true, float min = 0.0f, float max = 1.0f, int32_t type = Var::NoServer, bool regMissing = false, const char *regVal = nullptr) : ptr (nullptr) {
setPrefix (name, type);
Game::instance ().addNewCvar (name_.chars (), initval, info, bounded, min, max, type, regMissing, regVal, this);
Game::instance ().pushConVar (name_.chars (), initval, info, bounded, min, max, type, regMissing, regVal, this);
}
public:
template <typename U> constexpr U get () const {
template <typename U> constexpr U as () const {
if constexpr (cr::is_same <U, float>::value) {
return ptr->value;
}
@ -498,34 +498,22 @@ public:
public:
operator bool () const {
return bool_ ();
return as <bool> ();
}
operator float () const {
return float_ ();
return as <float> ();
}
operator int () const {
return as <int> ();
}
operator StringRef () {
return str ();
return as <StringRef> ();
}
public:
bool bool_ () const {
return get <bool> ();
}
int int_ () const {
return get <int> ();
}
float float_ () const {
return get <float> ();
}
StringRef str () const {
return get <StringRef> ();
}
StringRef name () const {
return ptr->name;
}
@ -546,7 +534,7 @@ public:
void revert ();
// set the cvar prefix if needed
void setPrefix (const char *name, int32_t type);
void setPrefix (StringRef name, int32_t type);
};
class MessageWriter final {

View file

@ -317,7 +317,7 @@ public:
// get the random node on map
int32_t random () const {
return rg.get (0, length () - 1);
return rg (0, length () - 1);
}
// check if has editor

View file

@ -309,7 +309,7 @@ private:
bool m_jumpSequence {}; // next path link will be jump link
PathWalk m_pathWalk {}; // pointer to current node from path
Dodge m_combatStrafeDir {}; // direction to strafe
Dodge m_dodgeStrafeDir {}; // direction to strafe
Fight m_fightStyle {}; // combat style to use
CollisionState m_collisionState {}; // collision State
FindPath m_pathType {}; // which pathfinder to use
@ -354,6 +354,7 @@ private:
CountdownTimer m_forgetLastVictimTimer {}; // time to forget last victim position ?
CountdownTimer m_approachingLadderTimer {}; // bot is approaching ladder
CountdownTimer m_lostReachableNodeTimer {}; // bot's issuing next node, probably he's lost
private:
int pickBestWeapon (Array <int> &vec, int moneySave);