| 358 | } |
| 359 | |
| 360 | int CCollision::IntersectLineTeleHook(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr) const |
| 361 | { |
| 362 | float Distance = distance(Pos0, Pos1); |
| 363 | int End(Distance + 1); |
| 364 | vec2 Last = Pos0; |
| 365 | int dx = 0, dy = 0; // Offset for checking the "through" tile |
| 366 | ThroughOffset(Pos0, Pos1, &dx, &dy); |
| 367 | for(int i = 0; i <= End; i++) |
| 368 | { |
| 369 | float a = i / (float)End; |
| 370 | vec2 Pos = mix(Pos0, Pos1, a); |
| 371 | // Temporary position for checking collision |
| 372 | int ix = round_to_int(Pos.x); |
| 373 | int iy = round_to_int(Pos.y); |
| 374 | |
| 375 | int Index = GetPureMapIndex(Pos); |
| 376 | if(pTeleNr) |
| 377 | { |
| 378 | if(g_Config.m_SvOldTeleportHook) |
| 379 | *pTeleNr = IsTeleport(Index); |
| 380 | else |
| 381 | *pTeleNr = IsTeleportHook(Index); |
| 382 | } |
| 383 | if(pTeleNr && *pTeleNr) |
| 384 | { |
| 385 | if(pOutCollision) |
| 386 | *pOutCollision = Pos; |
| 387 | if(pOutBeforeCollision) |
| 388 | *pOutBeforeCollision = Last; |
| 389 | return TILE_TELEINHOOK; |
| 390 | } |
| 391 | |
| 392 | int Hit = 0; |
| 393 | if(CheckPoint(ix, iy)) |
| 394 | { |
| 395 | if(!IsThrough(ix, iy, dx, dy, Pos0, Pos1)) |
| 396 | Hit = GetCollisionAt(ix, iy); |
| 397 | } |
| 398 | else if(IsHookBlocker(ix, iy, Pos0, Pos1)) |
| 399 | { |
| 400 | Hit = TILE_NOHOOK; |
| 401 | } |
| 402 | if(Hit) |
| 403 | { |
| 404 | if(pOutCollision) |
| 405 | *pOutCollision = Pos; |
| 406 | if(pOutBeforeCollision) |
| 407 | *pOutBeforeCollision = Last; |
| 408 | return Hit; |
| 409 | } |
| 410 | |
| 411 | Last = Pos; |
| 412 | } |
| 413 | if(pOutCollision) |
| 414 | *pOutCollision = Pos1; |
| 415 | if(pOutBeforeCollision) |
| 416 | *pOutBeforeCollision = Pos1; |
| 417 | return 0; |
no test coverage detected