Skip to content

Commit

Permalink
const correct waypointai methods
Browse files Browse the repository at this point in the history
  • Loading branch information
no-lex committed Oct 7, 2023
1 parent 3b954ff commit 871b2a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
30 changes: 15 additions & 15 deletions game/ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,18 @@ namespace ai
aistate &getstate(int idx = -1);
aistate &switchstate(aistate &b, int t, int r = -1, int v = -1);

float viewdist(int skill);
float viewfieldx(int skill);
float viewfieldy(int skill);
bool canmove();
float attackmindist(int atk);
float attackmaxdist(int atk);
bool attackrange(int atk, float dist);
bool targetable(gameent *e);
bool getsight(vec &o, float yaw, float pitch, vec &q, vec &v, float mdist, float fovx, float fovy);
float viewdist(int skill) const;
float viewfieldx(int skill) const;
float viewfieldy(int skill) const;
bool canmove() const;
float attackmindist(int atk) const;
float attackmaxdist(int atk) const;
bool attackrange(int atk, float dist) const;
bool targetable(gameent *e) const;
bool getsight(vec &o, float yaw, float pitch, vec &q, vec &v, float mdist, float fovx, float fovy) const;
bool cansee(vec &x, vec &y, vec &targ = aitarget);
bool canshoot(int atk, gameent *e);
bool canshoot(int atk);
bool canshoot(int atk, gameent *e) const;
bool canshoot(int atk) const;
bool hastarget(int atk, aistate &b, gameent *e, float yaw, float pitch, float dist);
vec getaimpos(int atk, gameent *e);
bool randomnode(aistate &b, const vec &pos, float guard, float wander);
Expand All @@ -335,8 +335,8 @@ namespace ai
bool defend(aistate &b, const vec &pos, float guard = sightmin, float wander = sightmax, int walk = 1);
bool violence(aistate &b, gameent *e, int pursue = 0);
bool istarget(aistate &b, int pursue = 0, bool force = false, float mindist = 0.f);
int isgoodammo(int gun);
bool hasgoodammo();
int isgoodammo(int gun) const;
bool hasgoodammo() const;
void assist(aistate &b, std::vector<interest> &interests, bool all = false, bool force = false);
bool parseinterests(aistate &b, std::vector<interest> &interests, bool override = false, bool ignore = false);
bool find(aistate &b, bool override = false);
Expand All @@ -352,8 +352,8 @@ namespace ai
bool anynode(aistate &b, int len = numprevnodes);
bool hunt(aistate &b);
void jumpto(aistate &b, const vec &pos);
void fixfullrange(float &yaw, float &pitch, float &roll, bool full);
void fixrange(float &yaw, float &pitch);
void fixfullrange(float &yaw, float &pitch, float &roll, bool full) const;
void fixrange(float &yaw, float &pitch) const;
void getyawpitch(const vec &from, const vec &pos, float &yaw, float &pitch);
void scaleyawpitch(float &yaw, float &pitch, float targyaw, float targpitch, float frame, float scale);
int process(aistate &b);
Expand Down
34 changes: 17 additions & 17 deletions game/waypointai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace ai
return addstate(t, r, v);
}

float waypointai::viewdist(int skill)
float waypointai::viewdist(int skill) const
{
if(skill <= 100)
{
Expand All @@ -96,7 +96,7 @@ namespace ai
}
}

float waypointai::viewfieldx(int skill)
float waypointai::viewfieldx(int skill) const
{
if(skill <= 100)
{
Expand All @@ -108,37 +108,37 @@ namespace ai
}
}

float waypointai::viewfieldy(int skill)
float waypointai::viewfieldy(int skill) const
{
return viewfieldx(skill)*3.f/4.f;
}

bool waypointai::canmove()
bool waypointai::canmove() const
{
return aiplayer->state != ClientState_Dead && !intermission;
conoutf(ConsoleMsg_GameInfo, "%d", aiplayer->state);
return true;
}

float waypointai::attackmindist(int atk)
float waypointai::attackmindist(int atk) const
{
return max(int(attacks[atk].exprad), 2);
}

float waypointai::attackmaxdist(int atk)
float waypointai::attackmaxdist(int atk) const
{
return attacks[atk].time + 4;
}

bool waypointai::attackrange(int atk, float dist)
bool waypointai::attackrange(int atk, float dist) const
{
float mindist = attackmindist(atk),
maxdist = attackmaxdist(atk);
return dist >= mindist*mindist && dist <= maxdist*maxdist;
}

//check if a player is alive and can be a valid target for another player (don't shoot up teammates)
bool waypointai::targetable(gameent *e)
bool waypointai::targetable(gameent *e) const
{
if(aiplayer == e || !canmove())
{
Expand All @@ -164,7 +164,7 @@ namespace ai
return istarget;
}

bool waypointai::getsight(vec &o, float yaw, float pitch, vec &q, vec &v, float mdist, float fovx, float fovy)
bool waypointai::getsight(vec &o, float yaw, float pitch, vec &q, vec &v, float mdist, float fovx, float fovy) const
{
float dist = o.dist(q);

Expand All @@ -182,15 +182,15 @@ namespace ai

bool waypointai::cansee(vec &x, vec &y, vec &targ)
{
aistate &b = getstate();
const aistate &b = getstate();
if(canmove() && b.type != AIState_Wait)
{
return getsight(x, aiplayer->yaw, aiplayer->pitch, y, targ, views[2], views[0], views[1]);
}
return false;
}

bool waypointai::canshoot(int atk, gameent *e)
bool waypointai::canshoot(int atk, gameent *e) const
{
if(attackrange(atk, e->o.squaredist(aiplayer->o)) && targetable(e))
{
Expand All @@ -199,7 +199,7 @@ namespace ai
return false;
}

bool waypointai::canshoot(int atk)
bool waypointai::canshoot(int atk) const
{
return !becareful && aiplayer->ammo[attacks[atk].gun] > 0 && lastmillis - aiplayer->lastaction >= aiplayer->gunwait;
}
Expand Down Expand Up @@ -889,12 +889,12 @@ namespace ai
return false;
}

int waypointai::isgoodammo(int gun)
int waypointai::isgoodammo(int gun) const
{
return gun == Gun_Pulse || gun == Gun_Rail;
}

bool waypointai::hasgoodammo()
bool waypointai::hasgoodammo() const
{
static const int goodguns[] = { Gun_Pulse, Gun_Rail, Gun_Eng, Gun_Carbine };
for(int i = 0; i < static_cast<int>(sizeof(goodguns)/sizeof(goodguns[0])); ++i)
Expand Down Expand Up @@ -945,8 +945,8 @@ namespace ai
case 2:
{
clear(false);
break;
}
[[fallthrough]];
case 1:
{
return true; // not close enough to pop it yet
Expand Down Expand Up @@ -1003,7 +1003,7 @@ namespace ai
}
}

void waypointai::fixfullrange(float &yaw, float &pitch, float &roll, bool full)
void waypointai::fixfullrange(float &yaw, float &pitch, float &roll, bool full) const
{
if(full) //modulus check if full range allowed
{
Expand Down Expand Up @@ -1053,7 +1053,7 @@ namespace ai
}
}

void waypointai::fixrange(float &yaw, float &pitch)
void waypointai::fixrange(float &yaw, float &pitch) const
{
float r = 0.f;
fixfullrange(yaw, pitch, r, false);
Expand Down

0 comments on commit 871b2a4

Please sign in to comment.