Clone of PhatAC @ https://github.com/floaterxk/PhatAC

Moves.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "StdAfx.h"
  2. #include "PhysicsObj.h"
  3. #include "World.h"
  4. #include "ObjectMsgs.h"
  5. void CPhysicsObj::Movement_Init()
  6. {
  7. m_fMoveThink = g_pGlobals->Time();
  8. }
  9. void CPhysicsObj::Movement_Shutdown()
  10. {
  11. }
  12. void CPhysicsObj::Movement_Think()
  13. {
  14. if (HasOwner())
  15. return;
  16. if ((m_fMoveThink + 0.05f) < g_pGlobals->Time())
  17. {
  18. if (m_lastMoveOrigin.landcell != m_Origin.landcell ||
  19. m_lastMoveOrigin.x != m_Origin.x ||
  20. m_lastMoveOrigin.y != m_Origin.y ||
  21. m_lastMoveOrigin.z != m_Origin.z)
  22. {
  23. Movement_UpdatePos();
  24. }
  25. else if (m_lastMoveAngles.w != m_Angles.w ||
  26. m_lastMoveAngles.x != m_Angles.x ||
  27. m_lastMoveAngles.y != m_Angles.y ||
  28. m_lastMoveAngles.z != m_Angles.z)
  29. {
  30. Movement_UpdatePos();
  31. }
  32. m_fMoveThink = g_pGlobals->Time();
  33. }
  34. }
  35. void CPhysicsObj::Movement_Teleport(loc_t origin, heading_t angles)
  36. {
  37. m_wNumPortals++;
  38. m_Origin = origin;
  39. m_Angles = angles;
  40. if (IsPlayer())
  41. ((CBasePlayer *)this)->EnterPortal();
  42. Movement_UpdatePos();
  43. }
  44. void CPhysicsObj::Movement_SendUpdate(DWORD dwCell)
  45. {
  46. //According to my reading of the ASM
  47. //The flags (which are only processed as 1 BYTE) work as follows:
  48. //0x08 0x10 0x20 and 0x40 are X Y Z W for angles, respectively
  49. //if flagged it means to default to zero, otherwise the message contains the value
  50. //0x01
  51. //reads in 3 floats for unknown purpose, these come if you jump.. i know that much
  52. //0x02
  53. //reads in float for unknown purpose
  54. //0x04
  55. //sets some sort of boolean relating to the update
  56. //----
  57. BinaryWriter* poo = MoveUpdate(this);
  58. g_pWorld->BroadcastPVS(dwCell, poo->GetData(), poo->GetSize());
  59. delete poo;
  60. }
  61. void CPhysicsObj::Movement_UpdatePos()
  62. {
  63. if (HasOwner())
  64. return;
  65. //QUICKFIX: Broadcast to the old landblock that we've moved from.
  66. //This sends duplicates if the block is near the other.
  67. m_wNumMovements++;
  68. DWORD dwNewCell = GetLandcell();
  69. DWORD dwOldCell = m_lastMoveOrigin.landcell;
  70. if (BLOCK_WORD(dwOldCell) != BLOCK_WORD(dwNewCell))
  71. {
  72. Movement_SendUpdate(dwOldCell);
  73. }
  74. Movement_SendUpdate(dwNewCell);
  75. m_lastMoveOrigin = m_Origin;
  76. m_lastMoveAngles = m_Angles;
  77. }