From de8d0d1584e9269d6cff0ccc2256359e0051e335 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Tue, 7 Nov 2006 18:38:15 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@526 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/bot/ac_bot.cpp | 4 +- source/src/bot/bot.cpp | 13 +-- source/src/bot/bot_ai.cpp | 157 ++++++++++++++++---------------- source/src/bot/bot_util.cpp | 28 ++---- source/src/bot/bot_waypoint.cpp | 23 ++--- source/src/bot/botmanager.cpp | 8 +- source/src/clientgame.cpp | 2 +- source/src/cube.h | 45 +++++---- source/src/entities.cpp | 19 ++-- source/src/physics.cpp | 15 +-- source/src/renderextras.cpp | 20 ++-- source/src/rendermd3.cpp | 5 +- source/src/renderparticles.cpp | 12 +-- source/src/savegamedemo.cpp | 18 +--- source/src/sound.cpp | 7 +- source/src/weapon.cpp | 75 +++++++-------- source/src/world.cpp | 2 +- 17 files changed, 218 insertions(+), 235 deletions(-) diff --git a/source/src/bot/ac_bot.cpp b/source/src/bot/ac_bot.cpp index f80aad13..c60c1051 100644 --- a/source/src/bot/ac_bot.cpp +++ b/source/src/bot/ac_bot.cpp @@ -229,8 +229,8 @@ void CACBot::CheckItemPickup() if(OUTBORD(e.x, e.y)) continue; vec v = { e.x, e.y, S(e.x, e.y)->floor+m_pMyEnt->eyeheight }; - vdist(dist, t, m_pMyEnt->o, v); - if(dist<2.5) + + if(v.dist(m_pMyEnt->o)<2.5) { PickUp(i); } diff --git a/source/src/bot/bot.cpp b/source/src/bot/bot.cpp index d5b819bc..e308e166 100644 --- a/source/src/bot/bot.cpp +++ b/source/src/bot/bot.cpp @@ -352,21 +352,18 @@ void CBot::SendBotInfo() float CBot::GetDistance(const vec &o) { - vdist(flDist, vecto, m_pMyEnt->o, o); - return flDist; + return o.dist(m_pMyEnt->o); } float CBot::GetDistance(const vec &v1, const vec &v2) { - vdist(flDist, vecto, v1, v2); - return flDist; + return v2.dist(v1); } float CBot::GetDistance(entity *e) { vec v = { e->x, e->y, e->z }; - vdist(flDist, vecto, m_pMyEnt->o, v); - return flDist; + return v.dist(m_pMyEnt->o); } bool CBot::SelectGun(int Gun) @@ -428,8 +425,8 @@ bool CBot::IsVisible(vec o, int Dir, float flDist, bool CheckPlayers, float *pEn AnglesToVectors(angles, forward, right, up); - vmul(forward, flDist); - vadd(end, forward); + forward.mul(flDist); + end.add(forward); TraceLine(o, end, m_pMyEnt, CheckPlayers, &tr); diff --git a/source/src/bot/bot_ai.cpp b/source/src/bot/bot_ai.cpp index 1ac9f464..95ab2c2d 100644 --- a/source/src/bot/bot_ai.cpp +++ b/source/src/bot/bot_ai.cpp @@ -103,7 +103,7 @@ vec CBot::GetEnemyPos(dynent *d) break; } - vadd(o, offset); + o.add(offset); return o; } @@ -302,7 +302,7 @@ bool CBot::CheckHunt(void) if (m_iHuntDelay > lastmillis) return (m_pHuntTarget!=NULL); - if (!vis(m_vHuntLocation, g_vecZero)) + if (m_vHuntLocation!=g_vecZero) m_vPrevHuntLocation = m_vHuntLocation; m_pHuntTarget = NULL; @@ -351,8 +351,8 @@ bool CBot::CheckHunt(void) // Check previous locations of enemy for (int j=0;jPrevLocations.prevloc[j], m_vPrevHuntLocation)) continue; - if (vis(d->PrevLocations.prevloc[j], g_vecZero)) continue; + if (d->PrevLocations.prevloc[j]==m_vPrevHuntLocation) continue; + if (d->PrevLocations.prevloc[j]==g_vecZero) continue; vec v = d->PrevLocations.prevloc[j]; @@ -368,8 +368,8 @@ bool CBot::CheckHunt(void) // Check previous locations of bot hisself for (int j=0;jPrevLocations.prevloc[j], m_vPrevHuntLocation)) continue; - if (vis(m_pMyEnt->PrevLocations.prevloc[j], g_vecZero)) continue; + if (m_pMyEnt->PrevLocations.prevloc[j]==m_vPrevHuntLocation) continue; + if (m_pMyEnt->PrevLocations.prevloc[j]==g_vecZero) continue; vec v = m_pMyEnt->PrevLocations.prevloc[j]; @@ -383,13 +383,13 @@ bool CBot::CheckHunt(void) } } - if (!vis(bestfromenemy, g_vecZero)) + if (bestfromenemy!=g_vecZero) { pNewEnemy = d; BestEnemyVal = EnemyVal; BestOldPos = bestfromenemy; } - else if (!vis(bestfrombot, g_vecZero)) + else if (bestfrombot!=g_vecZero) { pNewEnemy = d; BestEnemyVal = EnemyVal; @@ -430,8 +430,8 @@ bool CBot::CheckHunt(void) // Check previous locations of enemy for (int j=0;jPrevLocations.prevloc[j], m_vPrevHuntLocation)) continue; - if (vis(d->PrevLocations.prevloc[j], g_vecZero)) continue; + if (d->PrevLocations.prevloc[j]==m_vPrevHuntLocation) continue; + if (d->PrevLocations.prevloc[j]==g_vecZero) continue; vec v = d->PrevLocations.prevloc[j]; @@ -447,8 +447,8 @@ bool CBot::CheckHunt(void) // Check previous locations of bot hisself for (int j=0;jPrevLocations.prevloc[j], m_vPrevHuntLocation)) continue; - if (vis(m_pMyEnt->PrevLocations.prevloc[j], g_vecZero)) continue; + if (m_pMyEnt->PrevLocations.prevloc[j]==m_vPrevHuntLocation) continue; + if (m_pMyEnt->PrevLocations.prevloc[j]==g_vecZero) continue; vec v = m_pMyEnt->PrevLocations.prevloc[j]; @@ -462,13 +462,13 @@ bool CBot::CheckHunt(void) } } - if (!vis(bestfromenemy, g_vecZero)) + if (bestfromenemy!=g_vecZero) { pNewEnemy = d; BestEnemyVal = EnemyVal; BestOldPos = bestfromenemy; } - else if (!vis(bestfrombot, g_vecZero)) + else if (bestfrombot!=g_vecZero) { pNewEnemy = d; BestEnemyVal = EnemyVal; @@ -510,8 +510,8 @@ bool CBot::CheckHunt(void) // Check previous locations of enemy for (int j=0;jPrevLocations.prevloc[j], m_vPrevHuntLocation)) continue; - if (vis(d->PrevLocations.prevloc[j], g_vecZero)) continue; + if (d->PrevLocations.prevloc[j]==m_vPrevHuntLocation) continue; + if (d->PrevLocations.prevloc[j]==g_vecZero) continue; vec v = d->PrevLocations.prevloc[j]; @@ -527,8 +527,8 @@ bool CBot::CheckHunt(void) // Check previous locations of bot hisself for (int j=0;jPrevLocations.prevloc[j], m_vPrevHuntLocation)) continue; - if (vis(m_pMyEnt->PrevLocations.prevloc[j], g_vecZero)) continue; + if (m_pMyEnt->PrevLocations.prevloc[j]==m_vPrevHuntLocation) continue; + if (m_pMyEnt->PrevLocations.prevloc[j]==g_vecZero) continue; vec v = m_pMyEnt->PrevLocations.prevloc[j]; @@ -542,13 +542,13 @@ bool CBot::CheckHunt(void) } } - if (!vis(bestfromenemy, g_vecZero)) + if (bestfromenemy!=g_vecZero) { pNewEnemy = d; BestEnemyVal = EnemyVal; BestOldPos = bestfromenemy; } - else if (!vis(bestfrombot, g_vecZero)) + else if (bestfrombot!=g_vecZero) { pNewEnemy = d; BestEnemyVal = EnemyVal; @@ -581,8 +581,8 @@ bool CBot::CheckHunt(void) // Check previous locations of enemy for (int j=0;jPrevLocations.prevloc[j], m_vPrevHuntLocation)) continue; - if (vis(d->PrevLocations.prevloc[j], g_vecZero)) continue; + if (d->PrevLocations.prevloc[j]==m_vPrevHuntLocation) continue; + if (d->PrevLocations.prevloc[j]==g_vecZero) continue; vec v = d->PrevLocations.prevloc[j]; @@ -598,8 +598,8 @@ bool CBot::CheckHunt(void) // Check previous locations of bot hisself for (int j=0;jPrevLocations.prevloc[j], m_vPrevHuntLocation)) continue; - if (vis(m_pMyEnt->PrevLocations.prevloc[j], g_vecZero)) continue; + if (m_pMyEnt->PrevLocations.prevloc[j]==m_vPrevHuntLocation) continue; + if (m_pMyEnt->PrevLocations.prevloc[j]==g_vecZero) continue; vec v = m_pMyEnt->PrevLocations.prevloc[j]; @@ -613,13 +613,13 @@ bool CBot::CheckHunt(void) } } - if (!vis(bestfromenemy, g_vecZero)) + if (bestfromenemy!=g_vecZero) { pNewEnemy = d; BestEnemyVal = EnemyVal; BestOldPos = bestfromenemy; } - else if (!vis(bestfrombot, g_vecZero)) + else if (bestfrombot!=g_vecZero) { pNewEnemy = d; BestEnemyVal = EnemyVal; @@ -640,7 +640,7 @@ bool CBot::CheckHunt(void) flMaxShootDelay) * 1000.0f); } - if (!vis(m_vHuntLocation, g_vecZero)) + if (m_vHuntLocation!=g_vecZero) m_vPrevHuntLocation = m_vHuntLocation; m_pHuntTarget = pNewEnemy; @@ -685,10 +685,10 @@ bool CBot::HuntEnemy(void) { vec OldPos = m_pHuntTarget->PrevLocations.prevloc[j]; - if (bDone && vis(m_vHuntLocation, OldPos)) + if (bDone && m_vHuntLocation==OldPos) continue; - if (vis(OldPos, g_vecZero)) + if (OldPos==g_vecZero) continue; if (GetDistance(OldPos) > 250.0f) @@ -709,10 +709,10 @@ bool CBot::HuntEnemy(void) { vec OldPos = m_pMyEnt->PrevLocations.prevloc[j]; - if (bDone && vis(m_vHuntLocation, OldPos)) + if (bDone && m_vHuntLocation==OldPos) continue; - if (vis(OldPos, g_vecZero)) + if (OldPos==g_vecZero) continue; if (GetDistance(OldPos) > 25.0f) @@ -904,8 +904,8 @@ void CBot::ShootEnemy() AnglesToVectors(GetViewAngles(), forward, right, up); dest = m_pMyEnt->o; - vmul(forward, 1000); - vadd(dest, forward); + forward.mul(1000); + dest.add(forward); TraceLine(m_pMyEnt->o, dest, m_pMyEnt, false, &tr); debugbeam(m_pMyEnt->o, tr.end); @@ -1141,7 +1141,7 @@ void CBot::MainAI() // Time to check the environment? else if (m_iCheckEnvDelay < lastmillis) { - if (!vis(m_vWaterGoal, g_vecZero)) m_vWaterGoal = g_vecZero; + if (m_vWaterGoal!=g_vecZero) m_vWaterGoal = g_vecZero; // Check for stuck and strafe if (UnderWater(m_pMyEnt->o) || !CheckStuck()) @@ -1405,8 +1405,8 @@ void CBot::DoCombatNav() AnglesToVectors(src, forward, right, up); dest = o; - vmul(forward, 40); - vadd(dest, forward); + forward.mul(40); + dest.add(forward); TraceLine(o, dest, m_pMyEnt, false, &tr); @@ -1457,8 +1457,8 @@ void CBot::DoCombatNav() AnglesToVectors(angles, forward, right, up); end = m_pMyEnt->o; - vmul(forward, 15.0f); - vadd(end, forward); + forward.mul(15.0f); + end.add(forward); TraceLine(m_pMyEnt->o, end, m_pMyEnt, true, &tr); StrafeDirChoices.Insert(LEFT, (int)GetDistance(m_pMyEnt->o, tr.end)); @@ -1471,8 +1471,8 @@ void CBot::DoCombatNav() AnglesToVectors(angles, forward, right, up); end = m_pMyEnt->o; - vmul(forward, 15.0f); - vadd(end, forward); + forward.mul(15.0f); + end.add(forward); TraceLine(m_pMyEnt->o, end, m_pMyEnt, true, &tr); StrafeDirChoices.Insert(RIGHT, (int)GetDistance(m_pMyEnt->o, tr.end)); @@ -1494,7 +1494,7 @@ bool CBot::CheckStuck() if (m_iStuckCheckDelay >= lastmillis) return false; - if ((!vis(m_vGoal, g_vecZero)) && (GetDistance(m_vGoal) < 2.0f)) + if ((m_vGoal!=g_vecZero) && (GetDistance(m_vGoal) < 2.0f)) return false; bool IsStuck = false; @@ -1545,8 +1545,8 @@ bool CBot::CheckStuck() // Check the left side... dir = right; dest = m_pMyEnt->o; - vmul(dir, 3); - vsub(dest, dir); + dir.mul(3); + dest.sub(dir); TraceLine(m_pMyEnt->o, dest, m_pMyEnt, false, &tr); //debugbeam(m_pMyEnt->o, end); @@ -1562,8 +1562,8 @@ bool CBot::CheckStuck() // Check the right side... dir = right; dest = m_pMyEnt->o; - vmul(dir, 3); - vadd(dest, dir); + dir.mul(3); + dest.add(dir); TraceLine(m_pMyEnt->o, dest, m_pMyEnt, true, &tr); //debugbeam(m_pMyEnt->o, end); @@ -1579,8 +1579,8 @@ bool CBot::CheckStuck() // Check if bot can turn 180 degrees dir = forward; dest = m_pMyEnt->o; - vmul(dir, 3); - vsub(dest, dir); + dir.mul(3); + dest.add(dir); TraceLine(m_pMyEnt->o, dest, m_pMyEnt, true, &tr); //debugbeam(m_pMyEnt->o, end); @@ -1609,7 +1609,7 @@ bool CBot::CheckStuck() // Check if a near wall is blocking and we can jump over it bool CBot::CheckJump() { - bool bHasGoal = (!vis(m_vGoal, g_vecZero)); + bool bHasGoal = m_vGoal!=g_vecZero; float flGoalDist = (bHasGoal) ? GetDistance(m_vGoal) : 0.0f; // if ((bHasGoal) && (flGoalDist < 2.0f)) @@ -1677,8 +1677,8 @@ bool CBot::CheckStrafe() // Check for a near left wall to = from; dir = right; - vmul(dir, 3.0f); - vsub(to, dir); + dir.mul(3.0f); + to.sub(dir); TraceLine(from, to, m_pMyEnt, false, &tr); if (tr.collided) flLeftDist = GetDistance(from, tr.end); @@ -1687,8 +1687,8 @@ bool CBot::CheckStrafe() // Check for a near right wall to = from; dir = right; - vmul(dir, 3.0f); - vadd(to, dir); + dir.mul(3.0f); + to.add(dir); TraceLine(from, to, m_pMyEnt, false, &tr); if (tr.collided) flRightDist = GetDistance(from, tr.end); @@ -1697,17 +1697,17 @@ bool CBot::CheckStrafe() if ((flLeftDist == -1.0f) && (flRightDist == -1.0f)) { dir = right; - vmul(dir, m_pMyEnt->radius); + dir.mul(m_pMyEnt->radius); // Check left from = m_pMyEnt->o; - vsub(from, dir); + from.sub(dir); if (IsVisible(from, FORWARD, 3.0f, false, &flLeftDist)) flLeftDist = -1.0f; // Check right from = m_pMyEnt->o; - vadd(from, dir); + from.add(dir); if (IsVisible(from, FORWARD, 3.0f, false, &flRightDist)) flRightDist = -1.0f; } @@ -1780,8 +1780,8 @@ void CBot::CheckFOV() AnglesToVectors(src, forward, right, up); dest = origin; - vmul(forward, 40); - vadd(dest, forward); + forward.mul(40); + dest.add(forward); TraceLine(origin, dest, m_pMyEnt, false, &tr); @@ -1819,8 +1819,8 @@ void CBot::CheckFOV() vec start = origin; start.z += 2.0f; dest = start; - vmul(forward, 6); - vadd(dest, forward); + forward.mul(6); + dest.add(forward); TraceLine(start, dest, m_pMyEnt, false, &tr); //debugbeam(start, end); @@ -1845,8 +1845,8 @@ void CBot::CheckFOV() vec start = origin; start.z -= 1.7f; dest = start; - vmul(forward, 4); - vadd(dest, forward); + forward.mul(4); + dest.add(forward); TraceLine(start, dest, m_pMyEnt, false, &tr); @@ -1869,8 +1869,8 @@ void CBot::CheckFOV() AnglesToVectors(src, forward, right, up); dest = origin; - vmul(forward, 3.0f); - vadd(dest, forward); + forward.mul(3.0f); + dest.add(forward); TraceLine(origin, dest, m_pMyEnt, false, &tr); @@ -1914,8 +1914,8 @@ void CBot::CheckFOV() AnglesToVectors(src, forward, right, up); dest = origin; - vmul(forward, 4.0f); - vadd(dest, forward); + forward.mul(4.0f); + dest.add(forward); TraceLine(origin, dest, m_pMyEnt, false, &tr); @@ -1926,8 +1926,8 @@ void CBot::CheckFOV() AnglesToVectors(src, forward, right, up); dest = origin; - vmul(forward, 4.0f); - vadd(dest, forward); + forward.mul(4.0f); + dest.add(forward); TraceLine(origin, dest, m_pMyEnt, false, &tr); @@ -1947,7 +1947,7 @@ bool CBot::WaterNav() { const int iSearchRange = 4; - if (vis(m_vWaterGoal, g_vecZero)) + if (m_vWaterGoal==g_vecZero) { AddDebugText("WaterNav"); // Find the nearest and reachable cube which isn't underwater @@ -2025,7 +2025,7 @@ bool CBot::WaterNav() } } - if (!vis(m_vWaterGoal, g_vecZero)) + if (m_vWaterGoal!=g_vecZero) { AddDebugText("WaterNav"); //debugbeam(m_pMyEnt->o, m_vWaterGoal); @@ -2049,7 +2049,7 @@ bool CBot::CheckItems() return false; } - if (vis(m_vGoal, g_vecZero)) + if (m_vGoal==g_vecZero) m_pTargetEnt = NULL; if (!m_pTargetEnt) @@ -2109,12 +2109,12 @@ bool CBot::IsReachable(vec to, float flMaxHeight) // Trace from 1 cube to the left vec temp = right; - vmul(temp, 1.0f); - vsub(src, temp); + temp.mul(1.0f); + src.sub(temp); if (!::IsVisible(src, to)) return false; // Trace from 1 cube to the right - vadd(src, temp); + src.add(temp); if (!::IsVisible(src, to)) return false; if (UnderWater(from) && UnderWater(to)) @@ -2143,7 +2143,8 @@ bool CBot::IsReachable(vec to, float flMaxHeight) // check if distance to ground increases more than jump height // at points between from and to... - vec v_temp = to; vsub(v_temp, from); + vec v_temp = to; + v_temp.sub(from); vec v_direction = Normalize(v_temp); // 1 unit long vec v_check = from; vec v_down = from; @@ -2161,8 +2162,8 @@ bool CBot::IsReachable(vec to, float flMaxHeight) { // move 2 units closer to the goal v_temp = v_direction; - vmul(v_temp, 2.0f); - vadd(v_check, v_temp); + v_temp.mul(2.0f); + v_check.add(v_temp); v_down = v_check; v_down.z = v_down.z - 100.0f; @@ -2291,12 +2292,12 @@ bool CBot::IsInFOV(const vec &o) AnglesToVectors(GetViewAngles(), forward, right, up); v2 = o; - vsub(v2, m_pMyEnt->o); + v2.sub(m_pMyEnt->o); v2.z = 0.0f; // Make 2D v2 = Normalize(v2); forward.z = 0; // Make 2D - flDot = dotprod(v2 , forward); + flDot = v2.dot(forward); return(flDot >= 0.5f); // sin2(0.5) == 60 degrees FOV } diff --git a/source/src/bot/bot_util.cpp b/source/src/bot/bot_util.cpp index ea53a0ae..383eabb9 100644 --- a/source/src/bot/bot_util.cpp +++ b/source/src/bot/bot_util.cpp @@ -353,8 +353,7 @@ float GetDistance(vec v1, vec v2) (v2.z == 0)) return 0.0f; - vdist(flDist, vecto, v1, v2); - return flDist; + return v1.dist(v2); } // As GetDistance(), but doesn take height in account. @@ -364,8 +363,7 @@ float Get2DDistance(vec v1, vec v2) return 0.0f; v1.z = v2.z = 0.0f; - vdist(flDist, vecto, v1, v2); - return flDist; + return v1.dist(v2); } bool IsVisible(vec v1, vec v2, dynent *tracer, bool SkipTags) @@ -381,24 +379,14 @@ bool IsVisible(vec v1, vec v2, dynent *tracer, bool SkipTags) // - Time: In seconds, predict how far it is in Time seconds vec PredictPos(vec pos, vec vel, float Time) { - float flVelLength = sqrt(vel.x*vel.x + vel.y*vel.y + vel.z*vel.z); + float flVelLength = vel.magnitude(); if (flVelLength <= 1.0) return pos; // don't bother with low velocities... - float speed = flVelLength * Time; - float flTemp = 1/flVelLength; - vec vecNormalize; - - vecNormalize.x = vel.x * flTemp; - vecNormalize.y = vel.y * flTemp; - vecNormalize.z = vel.z * flTemp; - - vec v_src = pos; - vmul(vecNormalize, speed); - vec v_end = v_src; - vadd(v_end, vecNormalize); - + vec v_end = vel; + v_end.mul(Time); + v_end.add(pos); return v_end; } @@ -469,12 +457,12 @@ int GetDirection(const vec &angles, const vec &v1, const vec &v2) AnglesToVectors(angles, forward, right, up); tmp = v2; - vsub(tmp, v1); + tmp.sub(v1); tmp.z = 0.0f; // Make 2D tmp = Normalize(tmp); forward.z = 0; // Make 2D - flDot = dotprod(tmp , forward); + flDot = tmp.dot(forward); cross = CrossProduct(tmp, forward); int Dir = DIR_NONE; diff --git a/source/src/bot/bot_waypoint.cpp b/source/src/bot/bot_waypoint.cpp index c71235d7..672a67c6 100644 --- a/source/src/bot/bot_waypoint.cpp +++ b/source/src/bot/bot_waypoint.cpp @@ -711,8 +711,8 @@ void CWaypointClass::DrawNearWaypoints() from.z = end.z = (pNearest->v_origin.z-1.0f); AnglesToVectors(angles, forward, right, up); - vmul(forward, 5.0f); - vadd(end, forward); + forward.mul(5.0f); + end.add(forward); linestyle(2.0f, 0xFF, 0x40, 0x40); line(int(from.x), int(from.y), int(from.z), int(end.x), int(end.y), int(end.z)); @@ -760,7 +760,7 @@ void CWaypointClass::DrawNearWaypoints() for(int i=0;iPrevLocations.prevloc[i], g_vecZero)) continue; + if (player1->PrevLocations.prevloc[i]==g_vecZero) continue; vec v1 = player1->PrevLocations.prevloc[i]; v1.z -= 1.0f; vec v2 = v1; @@ -1003,7 +1003,8 @@ bool CWaypointClass::WPIsReachable(vec from, vec to) // check if distance to ground increases more than jump height // at points between from and to... - vec v_temp = to; vsub(v_temp, from); + vec v_temp = to; + v_temp.sub(from); vec v_direction = Normalize(v_temp); // 1 unit long vec v_check = from; vec v_down = from; @@ -1021,8 +1022,8 @@ bool CWaypointClass::WPIsReachable(vec from, vec to) { // move 2 units closer to the goal v_temp = v_direction; - vmul(v_temp, 2.0f); - vadd(v_check, v_temp); + v_temp.mul(2.0f); + v_check.add(v_temp); v_down = v_check; v_down.z = v_down.z - 100.0f; @@ -1163,7 +1164,7 @@ node_s *CWaypointClass::GetWaypointFromVec(const vec &v_src) while(pNode) { - if (vis(pNode->Entry->v_origin, v_src)) + if (pNode->Entry->v_origin==v_src) return pNode->Entry; pNode = pNode->next; @@ -2235,7 +2236,7 @@ bool CBot::HeadToWaypoint() float WPDist = GetDistance(m_pCurrentWaypoint->pNode->v_origin); #ifndef RELEASE_BUILD - if (m_pCurrentGoalWaypoint && vis(m_vGoal, g_vecZero)) + if (m_pCurrentGoalWaypoint && m_vGoal==g_vecZero) condebug("Warning: m_vGoal unset"); #endif @@ -2406,17 +2407,17 @@ bool CBot::HeadToWaypoint() bool bStrafe = false; int iStrafeDir = 0; - vmul(dir, m_pMyEnt->radius); + dir.mul(m_pMyEnt->radius); // Check left from = m_pMyEnt->o; - vsub(from, dir); + from.sub(dir); if (IsVisible(from, FORWARD, 3.0f, false, &flLeftDist)) flLeftDist = -1.0f; // Check right from = m_pMyEnt->o; - vadd(from, dir); + from.add(dir); if (IsVisible(from, FORWARD, 3.0f, false, &flRightDist)) flRightDist = -1.0f; diff --git a/source/src/bot/botmanager.cpp b/source/src/bot/botmanager.cpp index 67ddbbd6..153deb02 100644 --- a/source/src/bot/botmanager.cpp +++ b/source/src/bot/botmanager.cpp @@ -1340,8 +1340,8 @@ void telebot(void) traceresult_s tr; AnglesToVectors(angles, forward, right, up); - vmul(forward, 4.0f); - vadd(dest, forward); + forward.mul(4.0f); + dest.add(forward); TraceLine(player1->o, dest, player1, true, &tr); @@ -1418,8 +1418,8 @@ void testvisible(int iDir) AnglesToVectors(angles, forward, right, up); - vmul(forward, 20.0f); - vadd(end, forward); + forward.mul(20.0f); + end.add(forward); TraceLine(from, end, player1, false, &tr); diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index d2cbf8dc..be90ac27 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -346,7 +346,7 @@ int nearestenemy(vec *v, string team) if(!other) continue; if(isteam(team,other->team))continue; // its a teammate vec place = {v->x, v->y, v->z}; - vdistsquared(distsquared, t, place, other->o); + float distsquared = vec(other->o).sub(place).squaredlen(); if(nearestPlayerDistSquared == -1) nearestPlayerDistSquared = distsquared; // first run else if(distsquared < nearestPlayerDistSquared) nearestPlayerDistSquared = distsquared; // if a player is closer }; diff --git a/source/src/cube.h b/source/src/cube.h index 5bc766eb..eb8c31b3 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -139,7 +139,33 @@ struct header // map file format header #define MINBORD 2 // 2 cubes from the edge of the world are always solid #define OUTBORD(x,y) ((x)=ssize-MINBORD || (y)>=ssize-MINBORD) -struct vec { float x, y, z; }; +struct vec +{ + float x, y, z; + + bool operator==(const vec &o) const { return x == o.x && y == o.y && z == o.z; } + bool operator!=(const vec &o) const { return x != o.x || y != o.y || z != o.z; } + + vec &mul(float f) { x *= f; y *= f; z *= f; return *this; }; + vec &div(float f) { x /= f; y /= f; z /= f; return *this; }; + vec &add(float f) { x += f; y += f; z += f; return *this; }; + vec &sub(float f) { x -= f; y -= f; z -= f; return *this; }; + + vec &add(const vec &o) { x += o.x; y += o.y; z += o.z; return *this; }; + vec &sub(const vec &o) { x -= o.x; y -= o.y; z -= o.z; return *this; }; + + float squaredlen() const { return x*x + y*y + z*z; }; + float dot(const vec &o) const { return x*o.x + y*o.y + z*o.z; }; + + float magnitude() const { return sqrtf(squaredlen()); }; + vec &normalize() { div(magnitude()); return *this; }; + + float dist(const vec &e) const { vec t; return dist(e, t); }; + float dist(const vec &e, vec &t) const { t = *this; t.sub(e); return t.magnitude(); }; + + bool reject(const vec &o, float max) { return x>o.x+max || xo.y+max || y(u).x+(max) || (v).x<(u).x-(max) || (v).y>(u).y+(max) || (v).y<(u).y-(max)) -#define vlinterp(v,f,u,g) { (v).x = (v).x*f+(u).x*g; (v).y = (v).y*f+(u).y*g; (v).z = (v).z*f+(u).z*g; } -// Added by Rick (compares 2 vectors) -#define vis(v1,v2) ((v1.x==v2.x) && (v1.y==v2.y) && (v1.z==v2.z)) -// End add by Rick - /* Gamemodes 0 - tdm 1 - coop edit diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 22c4b0b3..b7893759 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -227,17 +227,16 @@ void checkitems() { if(OUTBORD(e.x, e.y)) continue; vec v = { e.x, e.y, player1->o.z }; - vdist(dist1, t, player1->o, v); + float dist1 = player1->o.dist(v); float dist2 = player1->o.z - (S(e.x, e.y)->floor+player1->eyeheight); - if(dist1<1.5 && dist2floor+player1->eyeheight }; - vdist(dist, t, player1->o, v); - if(dist<2.5) pickup(i, player1); + if(player1->o.dist(v)<2.5f) pickup(i, player1); }; }; @@ -318,20 +317,20 @@ bool intersect(entity *e, vec &from, vec &to, vec *end) // if lineseg hits entit float lo = (float)(S(e->x, e->y)->floor+mmi.zoff+e->attr3); float hi = lo+mmi.h; vec v = to, w = { e->x, e->y, lo + (fabs(hi-lo)/2.0f) }, *p; - vsub(v, from); - vsub(w, from); - float c1 = dotprod(w, v); + v.sub(from); + w.sub(from); + float c1 = w.dot(v); if(c1<=0) p = &from; else { - float c2 = dotprod(v, v); + float c2 = v.squaredlen(); if(c2<=c1) p = &to; else { float f = c1/c2; - vmul(v, f); - vadd(v, from); + v.mul(f); + v.add(from); p = &v; }; }; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index aedecec0..0296bb70 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -234,17 +234,18 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime) const float fpsfric = friction/curtime*20.0f; - vmul(pl->vel, fpsfric-1); // slowly apply friction and direction to velocity, gives a smooth movement - vadd(pl->vel, d); - vdiv(pl->vel, fpsfric); + pl->vel.mul(fpsfric-1); // slowly apply friction and direction to velocity, gives a smooth movement + pl->vel.add(d); + pl->vel.div(fpsfric); d = pl->vel; - vmul(d, speed); // d is now frametime based velocity vector + d.mul(speed); // d is now frametime based velocity vector if(pl->isphysent) { - pl->pitch += ((float) sqrt(dotprod(pl->vel, pl->vel)))*speed*pl->rotspeed*5.0f; + float dist = d.magnitude(); + pl->pitch += dist*pl->rotspeed*5.0f; if(pl->pitch>360.0f) pl->pitch = 0.0f; - pl->yaw += ((float) sqrt(dotprod(pl->vel, pl->vel)))*speed*pl->rotspeed*5.0f; + pl->yaw += dist*pl->rotspeed*5.0f; if(pl->yaw>360.0f) pl->yaw = 0.0f; } @@ -253,7 +254,7 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime) if(floating) // just apply velocity { - vadd(pl->o, d); + pl->o.add(d); if(pl->jumpnext) { pl->jumpnext = false; pl->vel.z = 2; } } else // apply velocity with collision diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index 912fefe2..76572b0a 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -535,19 +535,17 @@ void addshotline(dynent *d, vec &from, vec &to) shotline *s = &shotlines[i]; if(s->inuse) continue; int start = 10; - vdist(_dist, _unitv, player1->o, to); - if(_dist <= 10.0f) start = 8; + if(player1->o.dist(to) <= 10.0f) start = 8; else start = 5; - vdist(dist, unitv, from, to); - vdiv(unitv, dist); + vec unitv; + float dist = to.dist(from, unitv); + unitv.div(dist); s->inuse = true; s->from = unitv; - vmul(s->from, dist/10*start); - vadd(s->from, from); + s->from.mul(dist/10*start).add(from); s->to = unitv; - vmul(s->to, dist/10*-(10-start-2)); - vadd(s->to, to); + s->to.mul(dist/10*-(10-start-2)).add(to); s->millis = lastmillis; return; }; @@ -656,10 +654,10 @@ void addgib(dynent *d) float gibvelangle = (float) rnd(360); float speed = (float) gibspeed; - p->vel.x = sin(gibvelangle)*speed*rnd(1000)/1000.0f; - p->vel.y = cos(gibvelangle)*speed*rnd(1000)/1000.0f; + p->vel.x = sinf(gibvelangle)*speed*rnd(1000)/1000.0f; + p->vel.y = cosf(gibvelangle)*speed*rnd(1000)/1000.0f; p->vel.z = speed*rnd(1000)/1000.0f; - vdiv(p->vel, 10.0f); + p->vel.div(10.0f); p->yaw = (float)rnd(360); p->pitch = (float)rnd(360); diff --git a/source/src/rendermd3.cpp b/source/src/rendermd3.cpp index 317f2d80..1c9fd0c2 100644 --- a/source/src/rendermd3.cpp +++ b/source/src/rendermd3.cpp @@ -502,8 +502,9 @@ void rendergun(md3model *weapon, int lastaction) light.z = s->b/ll+of; }; - vdist(dist, unitv, player1->o, worldpos); - vdiv(unitv, dist); + vec unitv; + float dist = worldpos.dist(player1->o, unitv); + unitv.div(dist); weaponmove wm; if(!intermission) wm.calcmove(unitv, lastaction); diff --git a/source/src/renderparticles.cpp b/source/src/renderparticles.cpp index 98848629..7260f6c6 100644 --- a/source/src/renderparticles.cpp +++ b/source/src/renderparticles.cpp @@ -115,9 +115,8 @@ void render_particles(int time) { if(pt.gr) p->o.z -= ((lastmillis-p->millis)/3.0f)*curtime/(pt.gr*10000); vec a = p->d; - vmul(a, time); - vdiv(a, 20000.0f); - vadd(p->o, a); + a.mul(time/20000.0f); + p->o.add(a); pp = &p->next; }; }; @@ -149,12 +148,13 @@ void particle_splash(int type, int num, int fade, vec &p) void particle_trail(int type, int fade, vec &s, vec &e) { - vdist(d, v, s, e); - vdiv(v, d*2+0.1f); + vec v; + float d = e.dist(s, v); + v.div(d*2+0.1f); vec p = s; loopi((int)d*2) { - vadd(p, v); + p.add(v); vec d = { float(rnd(11)-5), float(rnd(11)-5), float(rnd(11)-5) }; newparticle(p, d, rnd(fade)+fade, type); }; diff --git a/source/src/savegamedemo.cpp b/source/src/savegamedemo.cpp index 2f4d601e..ed0c7504 100644 --- a/source/src/savegamedemo.cpp +++ b/source/src/savegamedemo.cpp @@ -231,21 +231,14 @@ VAR(demodelaymsec, 0, 120, 500); void catmulrom(vec &z, vec &a, vec &b, vec &c, float s, vec &dest) // spline interpolation { - vec t1 = b, t2 = c; - - vsub(t1, z); vmul(t1, 0.5f) - vsub(t2, a); vmul(t2, 0.5f); - float s2 = s*s; float s3 = s*s2; dest = a; - vec t = b; - - vmul(dest, 2*s3 - 3*s2 + 1); - vmul(t, -2*s3 + 3*s2); vadd(dest, t); - vmul(t1, s3 - 2*s2 + s); vadd(dest, t1); - vmul(t2, s3 - s2); vadd(dest, t2); + dest.mul(2*s3 - 3*s2 + 1); + dest.add(vec(b).mul(-2*s3 + 3*s2)); + dest.add(vec(b).sub(z).mul(0.5f).mul(s3 - 2*s2 + s)); + dest.add(vec(c).sub(a).mul(0.5f).mul(s3 - s2)); }; void fixwrap(dynent *a, dynent *b) @@ -328,8 +321,7 @@ void demoplaybackstep() fixwrap(a, player1); fixwrap(c, player1); fixwrap(z, player1); - vdist(dist, v, z->o, c->o); - if(dist<16) // if teleport or spawn, dont't interpolate + if(z->o.dist(c->o)<16) // if teleport or spawn, dont't interpolate { catmulrom(z->o, a->o, b->o, c->o, bf, player1->o); catmulrom(*(vec *)&z->yaw, *(vec *)&a->yaw, *(vec *)&b->yaw, *(vec *)&c->yaw, bf, *(vec *)&player1->yaw); diff --git a/source/src/sound.cpp b/source/src/sound.cpp index c9ee6248..4849f758 100644 --- a/source/src/sound.cpp +++ b/source/src/sound.cpp @@ -161,13 +161,14 @@ void updatechanvol(int chan, vec *loc) int vol = soundvol, pan = 255/2; if(loc) { - vdist(dist, v, *loc, player1->o); + vec v; + float dist = player1->o.dist(*loc, v); vol -= (int)(dist*3*soundvol/255); // simple mono distance attenuation if(vol<0) vol = 0; if(stereo && (v.x != 0 || v.y != 0)) { - float yaw = -atan2(v.x, v.y) - player1->yaw*RAD; // relative angle of sound along X-Y axis - pan = int(255.9f*(0.5f*sin(yaw)+0.5f)); // range is from 0 (left) to 255 (right) + float yaw = -atan2f(v.x, v.y) - player1->yaw*RAD; // relative angle of sound along X-Y axis + pan = int(255.9f*(0.5f*sinf(yaw)+0.5f)); // range is from 0 (left) to 255 (right) }; }; vol = (vol*MAXVOL)/255; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index f5cfa3d6..3b28d861 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -160,14 +160,13 @@ int kick_back(int gun) { return guns[gun].mdl_kick_back; }; void createrays(vec &from, vec &to) // create random spread of rays for the shotgun { - vdist(dist, dvec, from, to); - float f = dist*SGSPREAD/1000; + float f = to.dist(from)*SGSPREAD/1000; loopi(SGRAYS) { #define RNDD (rnd(101)-50)*f vec r = { RNDD, RNDD, RNDD }; sg[i] = to; - vadd(sg[i], r); + sg[i].add(r); #undef RNDD }; }; @@ -176,20 +175,19 @@ void createrays(vec &from, vec &to) // create random spread of rays bool intersect(dynent *d, vec &from, vec &to, vec *end) // if lineseg hits entity bounding box { vec v = to, w = d->o, *p; - vsub(v, from); - vsub(w, from); - float c1 = dotprod(w, v); + v.sub(from); + w.sub(from); + float c1 = w.dot(v); if(c1<=0) p = &from; else { - float c2 = dotprod(v, v); + float c2 = v.squaredlen(); if(c2<=c1) p = &to; else { float f = c1/c2; - vmul(v, f); - vadd(v, from); + v.mul(f).add(from); p = &v; }; }; @@ -315,15 +313,15 @@ const float RL_DAMRAD = 10; // hack void radialeffect(dynent *o, vec &v, int cn, int qdam, dynent *at) { if(o->state!=CS_ALIVE) return; - vdist(dist, temp, v, o->o); + vec temp; + float dist = o->o.dist(v, temp); dist -= 2; // account for eye distance imprecision if(distvel, temp); + o->vel.add(temp.mul((RL_DAMRAD-dist)*damage/800)); }; }; @@ -386,11 +384,11 @@ void moveprojectiles(float time) if(!p->inuse) continue; //int qdam = guns[p->gun].damage*(p->owner->quadmillis ? 4 : 1); int qdam = guns[p->gun].damage; - vdist(dist, v, p->o, p->to); + vec v; + float dist = p->to.dist(p->o, v); float dtime = dist*1000/p->speed; if(time>dtime) dtime = time; - vmul(v, time/dtime); - vadd(v, p->o) + v.mul(time/dtime).add(p->o); if(p->local) { loopv(players) @@ -446,25 +444,23 @@ void throw_nade(dynent *d, vec &to, physent *p) p->onfloor = false; p->o = d->o; - p->vel.z = sin(RAD*d->pitch); - float speed = cos(RAD*d->pitch); - p->vel.x = sin(RAD*d->yaw)*speed; - p->vel.y = -cos(RAD*d->yaw)*speed; + p->vel.z = sinf(RAD*d->pitch); + float speed = cosf(RAD*d->pitch); + p->vel.x = sinf(RAD*d->yaw)*speed; + p->vel.y = -cosf(RAD*d->yaw)*speed; - vmul(p->vel, 1.7f); + p->vel.mul(1.7f); vec throwdir = p->vel; - vmul(throwdir, d->radius); - vadd(p->o, throwdir); - vadd(p->o, throwdir); + throwdir.mul(2*d->radius); + p->o.add(throwdir); - vec &from = d->o; - d->thrownademillis = lastmillis; d->inhandnade = NULL; if(d==player1) { + vec &from = d->o; player1->lastaction = lastmillis; addmsg(SV_SHOT, "ri8", d->gunselect, (int)(from.x*DMF), (int)(from.y*DMF), (int)(from.z*DMF), (int)(to.x*DMF), (int)(to.y*DMF), (int)(to.z*DMF), lastmillis-p->millis); }; @@ -491,8 +487,7 @@ void explode_nade(physent *i) if(i->state != NADE_THROWED) { vec o = i->owner->o; - vec dist = { 0.1f, 0.1f, 0.1f }; - vadd(o, dist); + o.add(0.1f); throw_nade(i->owner, o, i); }; playsound(S_FEXPLODE, &i->o); @@ -544,9 +539,10 @@ void shootv(int gun, vec &from, vec &to, dynent *d, bool local, int nademillis) void hitpush(int target, int damage, dynent *d, dynent *at, vec &from, vec &to) { hit(target, damage, d, at, at->gunselect==GUN_KNIFE ? true : false); - vdist(dist, v, from, to); - vmul(v, damage/dist/50); - vadd(d->vel, v); + vec v; + float dist = to.dist(from, v); + v.mul(damage/dist/50); + d->vel.add(v); }; void raydamage(dynent *o, vec &from, vec &to, dynent *d, int i) @@ -569,7 +565,8 @@ void spreadandrecoil(vec &from, vec &to, dynent *d) if (d->gunselect==GUN_KNIFE || d->gunselect==GUN_GRENADE) return; //spread - vdist(dist, unitv, from, to); + vec unitv; + float dist = to.dist(from, unitv); float f = dist/1000; int spd = guns[d->gunselect].spread; @@ -593,15 +590,12 @@ void spreadandrecoil(vec &from, vec &to, dynent *d) { #define RNDD (rnd(spd)-spd/2)*f vec r = { RNDD, RNDD, RNDD }; - vadd(to, r); + to.add(r); #undef RNDD }; //increase pitch for recoil - vdiv(unitv, dist); - vec recoil = unitv; - vmul(recoil, rcl); - vadd(d->vel, recoil); + d->vel.add(vec(unitv).mul(rcl/dist)); if(d->pitch<80.0f) d->pitch += guns[d->gunselect].recoil*0.05f; }; @@ -686,14 +680,15 @@ void shoot(dynent *d, vec &targ) }; spreadandrecoil(from,to,d); - vdist(dist, unitv, from, to); - vdiv(unitv, dist); + vec unitv; + float dist = to.dist(from, unitv); + unitv.div(dist); if(d->gunselect==GUN_KNIFE) { - vmul(unitv, 3); // punch range + unitv.mul(3); // punch range to = from; - vadd(to, unitv); + to.add(unitv); }; if(d->gunselect==GUN_SHOTGUN) createrays(from, to); diff --git a/source/src/world.cpp b/source/src/world.cpp index 6853f606..76b06f78 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -176,7 +176,7 @@ int closestent() // used for delent and edit mode ent display entity &e = ents[i]; if(e.type==NOTUSED) continue; vec v = { e.x, e.y, e.z }; - vdist(dist, t, player1->o, v); + float dist = v.dist(player1->o); if(dist