- 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:
ac-stef
2014-05-14 22:54:37 +02:00
parent 5058172a06
commit eb60302e67
57 changed files with 246 additions and 254 deletions
+55 -55
View File
@@ -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;
}