cleanup
- fix possible crash in conc (but it's still an ugly hack) - fix noob usage of strcmp - flag some memory leaks (it would be nice, if the author(s) would clean up the mess himself) - fix crash in substr - whitespace cleanup there are plenty more memory leaks in command.cpp - for example, every goto in cubescript does not clean up anything
This commit is contained in:
@@ -46,7 +46,7 @@ bool CACBot::ChoosePreferredWeapon()
|
||||
{
|
||||
sWeaponScore = 0; // Minimal score for a weapon
|
||||
sWeaponScore = i > 1 ? 5 : 0; // Primary are usually better
|
||||
|
||||
|
||||
if (!m_pMyEnt->mag[i] && WeaponInfoTable[i].eWeaponType != TYPE_MELEE)
|
||||
{
|
||||
continue;
|
||||
@@ -127,7 +127,7 @@ bool CACBot::ChoosePreferredWeapon()
|
||||
if (WeaponInfoTable[m_pMyEnt->gunselect].eWeaponType == TYPE_ROCKET)
|
||||
{
|
||||
m_bShootAtFeet = true;
|
||||
|
||||
|
||||
}
|
||||
if(lastmillis > m_iChangeWeaponDelay)
|
||||
{
|
||||
|
||||
@@ -127,7 +127,7 @@ bool CBot::FindEnemy(void)
|
||||
{
|
||||
m_pMyEnt->enemy = player1;
|
||||
}
|
||||
|
||||
|
||||
return m_pMyEnt->enemy != NULL;
|
||||
}
|
||||
|
||||
@@ -2035,7 +2035,7 @@ bool CBot::IsInFOV(const vec &o)
|
||||
dir = forward;
|
||||
dir.z = 0; // Make 2D
|
||||
|
||||
// ideal direction
|
||||
// ideal direction
|
||||
target = o;
|
||||
target.sub(m_pMyEnt->o);
|
||||
target.z = 0.0f; // Make 2D
|
||||
@@ -2045,5 +2045,5 @@ bool CBot::IsInFOV(const vec &o)
|
||||
flAngle = acos(flDot/(target.magnitude() * dir.magnitude()));
|
||||
|
||||
return m_pBotSkill->iFov/2.0f >= flAngle/RAD;
|
||||
}
|
||||
}
|
||||
// Code of CBot - End
|
||||
|
||||
+55
-55
@@ -6,7 +6,7 @@
|
||||
//
|
||||
// Author: <[email protected]>
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
@@ -34,7 +34,7 @@ long lrand (void)
|
||||
// credits go to Ray Gardner for his fast implementation of minimal random
|
||||
// number generators
|
||||
// http://c.snippets.org/snip_lister.php?fname=rg_rand.c
|
||||
|
||||
|
||||
// compose the two 16-bit parts of the long integer and assemble them
|
||||
static unsigned long lrand_lo, lrand_hi;
|
||||
lrand_lo = 16807 * (long) (lseed & 0xFFFF); // low part
|
||||
@@ -48,7 +48,7 @@ long lrand (void)
|
||||
lrand_lo &= LRAND_MAX; // then get rid of the disturbing bit
|
||||
lrand_lo++; // and increase it a bit (to avoid overflow problems, I suppose)
|
||||
}
|
||||
|
||||
|
||||
lrand_lo += lrand_hi >> 15;
|
||||
// now do twisted maths to generate the next seed
|
||||
// is the resulting number greater than LRAND_MAX (half the capacity) ?
|
||||
@@ -69,9 +69,9 @@ void lsrand (unsigned long initial_seed)
|
||||
// usually initialized with the time of day, and time is a value that
|
||||
// changes slowly, we bump the seed twice to have it in a more
|
||||
// random state for future calls of the random number generator.
|
||||
|
||||
|
||||
// fill in the initial seed of the random number generator
|
||||
lseed = (long) initial_seed;
|
||||
lseed = (long) initial_seed;
|
||||
lseed = lrand (); // bump it once
|
||||
lseed = lrand (); // bump it twice
|
||||
return; // that's all folks
|
||||
@@ -81,9 +81,9 @@ long RandomLong (long from, long to)
|
||||
{
|
||||
// this function returns a random integer number between (and including)
|
||||
// the starting and ending values passed by parameters from and to.
|
||||
if (to <= from)
|
||||
if (to <= from)
|
||||
return (from);
|
||||
|
||||
|
||||
return (from + lrand () / (LRAND_MAX / (to - from + 1)));
|
||||
}
|
||||
|
||||
@@ -91,10 +91,10 @@ float RandomFloat (float from, float to)
|
||||
{
|
||||
// this function returns a random floating-point number between (and including)
|
||||
// the starting and ending values passed by parameters from and to.
|
||||
|
||||
|
||||
if (to <= from)
|
||||
return (from);
|
||||
|
||||
|
||||
return (from + (float) lrand () / (LRAND_MAX / (to - from)));
|
||||
}
|
||||
|
||||
@@ -110,42 +110,42 @@ void AnglesToVectors(vec angles, vec &forward, vec &right, vec &up)
|
||||
float cos_pitch;
|
||||
float cos_yaw;
|
||||
float cos_roll;
|
||||
|
||||
|
||||
// For some reason this has to be done :)
|
||||
// Me = math n00b
|
||||
angles.x = -angles.x;
|
||||
angles.y -= 90;
|
||||
|
||||
|
||||
// compute the sin and cosine of the pitch component
|
||||
angle = angles.x * degrees_to_radians;
|
||||
sin_pitch = sinf (angle);
|
||||
cos_pitch = cosf (angle);
|
||||
|
||||
|
||||
// compute the sin and cosine of the yaw component
|
||||
angle = angles.y * degrees_to_radians;
|
||||
sin_yaw = sinf (angle);
|
||||
cos_yaw = cosf (angle);
|
||||
|
||||
|
||||
// compute the sin and cosine of the roll component
|
||||
angle = angles.z * degrees_to_radians;
|
||||
sin_roll = sinf (angle);
|
||||
cos_roll = cosf (angle);
|
||||
|
||||
|
||||
// build the FORWARD vector
|
||||
forward.x = cos_pitch * cos_yaw;
|
||||
forward.y = cos_pitch * sin_yaw;
|
||||
forward.z = -sin_pitch;
|
||||
|
||||
|
||||
// build the RIGHT vector
|
||||
right.x = -(-(sin_roll * sin_pitch * cos_yaw) - (cos_roll * -sin_yaw));
|
||||
right.y = -(-(sin_roll * sin_pitch * sin_yaw) - (cos_roll * cos_yaw));
|
||||
right.z = -(sin_roll * cos_pitch);
|
||||
|
||||
|
||||
// build the UPWARDS vector
|
||||
up.x = ((cos_roll * sin_pitch * cos_yaw) - (sin_roll * -sin_yaw));
|
||||
up.y = ((cos_roll * sin_pitch * sin_yaw) - (sin_roll * cos_yaw));
|
||||
up.z = cos_roll * cos_pitch;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -175,30 +175,30 @@ void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult
|
||||
{
|
||||
tr->end = from;
|
||||
tr->collided = false;
|
||||
|
||||
|
||||
static float flNearestDist, flDist;
|
||||
static vec v;
|
||||
static bool solid;
|
||||
|
||||
|
||||
flNearestDist = 9999.0f;
|
||||
|
||||
|
||||
if(OUTBORD((int)from.x, (int)from.y)) return;
|
||||
|
||||
|
||||
// Check if the 'line' collides with entities like mapmodels
|
||||
loopv(ents)
|
||||
{
|
||||
entity &e = ents[i];
|
||||
if(e.type!=MAPMODEL) continue; // Only check map models for now
|
||||
|
||||
|
||||
mapmodelinfo &mmi = getmminfo(e.attr2);
|
||||
if(!&mmi || !mmi.h) continue;
|
||||
|
||||
|
||||
float lo = (float)(S(e.x, e.y)->floor+mmi.zoff+e.attr3);
|
||||
float hi = lo+mmi.h;
|
||||
float z = (fabs(from.z-lo) < fabs(from.z-hi)) ? lo : hi;
|
||||
makevec(&v, e.x, e.y, z);
|
||||
flDist = GetDistance(from, v);
|
||||
|
||||
float z = (fabs(from.z-lo) < fabs(from.z-hi)) ? lo : hi;
|
||||
makevec(&v, e.x, e.y, z);
|
||||
flDist = GetDistance(from, v);
|
||||
|
||||
if ((flDist < flNearestDist) && (intersect(&e, from, to, &tr->end)))
|
||||
{
|
||||
flNearestDist = GetDistance(from, tr->end);
|
||||
@@ -213,9 +213,9 @@ void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult
|
||||
{
|
||||
playerent *d = players[i];
|
||||
if(!d || (d==pTracer) || (d->state != CS_ALIVE)) continue; // Only check valid players
|
||||
|
||||
flDist = GetDistance(from, d->o);
|
||||
|
||||
|
||||
flDist = GetDistance(from, d->o);
|
||||
|
||||
if ((flDist < flNearestDist) && (intersect(d, from, to, &tr->end)))
|
||||
{
|
||||
flNearestDist = flDist;
|
||||
@@ -227,23 +227,23 @@ void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult
|
||||
playerent *d = player1; // Shortcut
|
||||
if (d && (d!=pTracer) && !BotManager.m_pBotToView && (d->state == CS_ALIVE))
|
||||
{
|
||||
flDist = GetDistance(from, d->o);
|
||||
|
||||
flDist = GetDistance(from, d->o);
|
||||
|
||||
if ((flDist < flNearestDist) && (intersect(d, from, to, &tr->end)))
|
||||
{
|
||||
flNearestDist = flDist;
|
||||
tr->collided = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
float dx = to.x-from.x;
|
||||
float dy = to.y-from.y;
|
||||
float dy = to.y-from.y;
|
||||
int steps = (int)(sqrt(dx*dx+dy*dy)/0.9);
|
||||
if(!steps) // If from and to are on the same cube...
|
||||
{
|
||||
if (GetDistance(from, to) < flNearestDist)
|
||||
if (GetDistance(from, to) < flNearestDist)
|
||||
{
|
||||
tr->end = to;
|
||||
sqr *s = S(int(from.x), int(from.y));
|
||||
@@ -257,12 +257,12 @@ void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
float x = from.x;
|
||||
float y = from.y;
|
||||
int i = 0;
|
||||
vec endcube = from;
|
||||
|
||||
|
||||
// Now check if the 'line' is hit by a cube
|
||||
while(i<steps)
|
||||
{
|
||||
@@ -277,7 +277,7 @@ void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult
|
||||
if(s->type==CHF) ceil += s->vdelta/4.0f;
|
||||
float rz = from.z-((from.z-to.z)*(i/(float)steps));
|
||||
if(rz<floor || rz>ceil) break;
|
||||
|
||||
|
||||
endcube.x = x;
|
||||
endcube.y = y;
|
||||
endcube.z = rz;
|
||||
@@ -285,7 +285,7 @@ void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult
|
||||
y += dy/(float)steps;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
if ((i>=steps) && !tr->collided)
|
||||
{
|
||||
tr->end = to;
|
||||
@@ -305,7 +305,7 @@ float GetDistance(vec v1, vec v2)
|
||||
if ((v1.x == 0) && (v2.x == 0) && (v1.y == 0) && (v2.y == 0) && (v1.z == 0) &&
|
||||
(v2.z == 0))
|
||||
return 0.0f;
|
||||
|
||||
|
||||
return v1.dist(v2);
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ float Get2DDistance(vec v1, vec v2)
|
||||
{
|
||||
if ((v1.x == 0) && (v2.x == 0) && (v1.y == 0) && (v2.y == 0))
|
||||
return 0.0f;
|
||||
|
||||
|
||||
v1.z = v2.z = 0.0f;
|
||||
return v1.dist(v2);
|
||||
}
|
||||
@@ -333,7 +333,7 @@ bool IsVisible(vec v1, vec v2, dynent *tracer, bool SkipTags)
|
||||
vec PredictPos(vec pos, vec vel, float Time)
|
||||
{
|
||||
float flVelLength = vel.magnitude();
|
||||
|
||||
|
||||
if (flVelLength <= 1.0)
|
||||
return pos; // don't bother with low velocities...
|
||||
|
||||
@@ -378,7 +378,7 @@ vec Normalize(vec v)
|
||||
{
|
||||
float flLen = sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
|
||||
static vec v_norm = g_vecZero;
|
||||
if (flLen == 0)
|
||||
if (flLen == 0)
|
||||
{
|
||||
v_norm.x=0;v_norm.y=0;v_norm.z=1;
|
||||
}
|
||||
@@ -392,7 +392,7 @@ vec Normalize(vec v)
|
||||
|
||||
float GetYawDiff(float curyaw, vec v1, vec v2)
|
||||
{
|
||||
float yaw = -(float)atan2(v2.x - v1.x, v2.y - v1.y)/PI*180+180;
|
||||
float yaw = -(float)atan2(v2.x - v1.x, v2.y - v1.y)/PI*180+180;
|
||||
return yaw-curyaw;
|
||||
}
|
||||
|
||||
@@ -414,20 +414,20 @@ int GetDirection(const vec &angles, const vec &v1, const vec &v2)
|
||||
tmp.z = 0.0f; // Make 2D
|
||||
tmp = Normalize(tmp);
|
||||
forward.z = 0; // Make 2D
|
||||
|
||||
|
||||
flDot = tmp.dot(forward);
|
||||
cross = CrossProduct(tmp, forward);
|
||||
|
||||
|
||||
int Dir = DIR_NONE;
|
||||
|
||||
|
||||
if (cross.z > 0.1f) Dir |= LEFT;
|
||||
else if (cross.z < -0.1f) Dir |= RIGHT;
|
||||
if (flDot < -0.1f) Dir |= BACKWARD;
|
||||
else if (flDot > 0.1f) Dir |= FORWARD;
|
||||
|
||||
|
||||
if (v1.z > v2.z) Dir |= DOWN;
|
||||
if (v1.z < v2.z) Dir |= UP;
|
||||
|
||||
|
||||
return Dir;
|
||||
}
|
||||
|
||||
@@ -456,14 +456,14 @@ const char *SkillNrToSkillName(short skillnr)
|
||||
else if (skillnr == 2) return "medium";
|
||||
else if (skillnr == 3) return "worse";
|
||||
else if (skillnr == 4) return "bad";
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool IsInGame(dynent *d)
|
||||
{
|
||||
if (!d) return false;
|
||||
|
||||
|
||||
if (d->type==ENT_BOT)
|
||||
{
|
||||
loopv(bots)
|
||||
@@ -480,11 +480,11 @@ bool IsInGame(dynent *d)
|
||||
{
|
||||
loopv(players)
|
||||
{
|
||||
#ifdef VANILLA_CUBE
|
||||
#ifdef VANILLA_CUBE
|
||||
if (!players[i] || (players[i]->state == CS_DEDHOST)) continue;
|
||||
#elif defined(AC_CUBE)
|
||||
if (!players[i]) continue;
|
||||
#endif
|
||||
#endif
|
||||
if (players[i] == d)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -44,27 +44,27 @@ struct waypoint_version_1_s
|
||||
int iFlags;
|
||||
vec v_origin;
|
||||
TLinkedList<waypoint_version_1_s *> ConnectedWPs;
|
||||
|
||||
|
||||
// A* stuff
|
||||
float f, g;
|
||||
waypoint_version_1_s *pParent;
|
||||
|
||||
|
||||
// Construction
|
||||
waypoint_version_1_s(void) : iFlags(0), f(0.0f), g(0.0f), pParent(NULL) { };
|
||||
waypoint_version_1_s(void) : iFlags(0), f(0.0f), g(0.0f), pParent(NULL) { };
|
||||
};
|
||||
|
||||
struct node_s
|
||||
{
|
||||
vec v_origin;
|
||||
vec v_origin;
|
||||
int iFlags;
|
||||
short sTriggerNr;
|
||||
short sYaw;
|
||||
short sCost; // Base and static cost
|
||||
TLinkedList<node_s *> ConnectedWPs;
|
||||
TLinkedList<node_s *> ConnectedWPsWithMe;
|
||||
|
||||
|
||||
TLinkedList<node_s *> FailedGoalList;
|
||||
|
||||
|
||||
// Construction
|
||||
node_s(void) : iFlags(0), sTriggerNr(0), sYaw(-1), sCost(10) { };
|
||||
node_s(const vec &o, const int &f, const short t=0, const short y=-1) : v_origin(o),
|
||||
@@ -80,11 +80,11 @@ struct waypoint_s
|
||||
short g[2];
|
||||
waypoint_s *pParent[2];
|
||||
bool bIsOpen[2], bIsClosed[2];
|
||||
|
||||
|
||||
// Construction
|
||||
waypoint_s(void) : pNode(NULL) { bIsOpen[0] = bIsOpen[1] = bIsClosed[0] =
|
||||
bIsClosed[1] = false; pParent[0] = pParent[1] = NULL;
|
||||
g[0] = g[1] = 0; };
|
||||
g[0] = g[1] = 0; };
|
||||
};
|
||||
|
||||
class CWaypointClass
|
||||
@@ -98,7 +98,7 @@ protected:
|
||||
vec m_vLastCreatedWP;
|
||||
float m_fPathDrawTime;
|
||||
char m_szMapName[32];
|
||||
|
||||
|
||||
#ifdef WP_FLOOD
|
||||
bool m_bFlooding; // True if flooding map with waypoints
|
||||
bool m_bFilteringNodes;
|
||||
@@ -106,9 +106,9 @@ protected:
|
||||
int m_iCurFloodX, m_iCurFloodY;
|
||||
int m_iFloodSize;
|
||||
int m_iFilteredNodes;
|
||||
#endif
|
||||
#endif
|
||||
friend class CBot;
|
||||
|
||||
|
||||
public:
|
||||
TLinkedList<node_s *> m_Waypoints[MAX_MAP_GRIDS][MAX_MAP_GRIDS];
|
||||
int m_iWaypointCount; // number of waypoints currently in use
|
||||
@@ -153,7 +153,7 @@ public:
|
||||
void CalcCost(node_s *pNode);
|
||||
void ReCalcCosts(void);
|
||||
|
||||
|
||||
|
||||
#ifdef WP_FLOOD
|
||||
// Flood functions
|
||||
virtual void StartFlood(void);
|
||||
|
||||
@@ -1313,16 +1313,7 @@ COMMANDF(testvisible, "i", (int *dir) { testvisible(*dir); });
|
||||
|
||||
void mapsize(void)
|
||||
{
|
||||
switch(ssize)
|
||||
{
|
||||
case 128: intret(7); break;
|
||||
case 256: intret(8); break;
|
||||
case 512: intret(9); break;
|
||||
case 1024: intret(10); break;
|
||||
case 2048: intret(11); break;
|
||||
case 4096: intret(12); break;
|
||||
default: intret(6); break;
|
||||
}
|
||||
intret(sfactor);
|
||||
}
|
||||
|
||||
COMMAND(mapsize, "");
|
||||
|
||||
Reference in New Issue
Block a user