Sees how far it can come from 'from' to 'to' and puts the end vector in 'end' (1337 description :-) UNDONE: Optimize this as much as possible
| 170 | // (1337 description :-) |
| 171 | // UNDONE: Optimize this as much as possible |
| 172 | void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult_s *tr, |
| 173 | bool SkipTags) |
| 174 | { |
| 175 | tr->end = from; |
| 176 | tr->collided = false; |
| 177 | |
| 178 | static float flNearestDist, flDist; |
| 179 | static vec v; |
| 180 | static bool solid; |
| 181 | |
| 182 | flNearestDist = 9999.0f; |
| 183 | |
| 184 | if(OUTBORD((int)from.x, (int)from.y)) return; |
| 185 | |
| 186 | // Check if the 'line' collides with entities like mapmodels |
| 187 | loopv(ents) |
| 188 | { |
| 189 | entity &e = ents[i]; |
| 190 | if(e.type!=MAPMODEL) continue; // Only check map models for now |
| 191 | |
| 192 | mapmodelinfo *mmi = getmminfo(e.attr2); |
| 193 | if(!mmi || !mmi->h) continue; |
| 194 | |
| 195 | float lo = (float)(S(e.x, e.y)->floor + mmi->zoff + e.attr3); |
| 196 | float hi = lo + mmi->h; |
| 197 | float z = (fabs(from.z-lo) < fabs(from.z-hi)) ? lo : hi; |
| 198 | makevec(&v, e.x, e.y, z); |
| 199 | flDist = GetDistance(from, v); |
| 200 | |
| 201 | if ((flDist < flNearestDist) && (intersect(&e, from, to, &tr->end))) |
| 202 | { |
| 203 | flNearestDist = GetDistance(from, tr->end); |
| 204 | tr->collided = true; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if (CheckPlayers) |
| 209 | { |
| 210 | // Check if the 'line' collides with bots |
| 211 | loopv(bots) |
| 212 | { |
| 213 | playerent *d = bots[i]; |
| 214 | if(!d || (d==pTracer) || (d->state != CS_ALIVE)) continue; // Only check valid bots |
| 215 | |
| 216 | flDist = GetDistance(from, d->o); |
| 217 | |
| 218 | if ((flDist < flNearestDist) && (intersect(d, from, to, &tr->end))) |
| 219 | { |
| 220 | flNearestDist = flDist; |
| 221 | tr->collided = true; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | // Check if the 'line' collides with the local player(player1) |
| 226 | playerent *d = player1; // Shortcut |
| 227 | if (d && (d!=pTracer) && !BotManager.m_pBotToView && (d->state == CS_ALIVE)) |
| 228 | { |
| 229 | flDist = GetDistance(from, d->o); |
no test coverage detected