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

Pet.cpp 906B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "StdAfx.h"
  2. #include "PhysicsObj.h"
  3. #include "Monster.h"
  4. #include "World.h"
  5. #include "pet.h"
  6. CMonsterPet::CMonsterPet()
  7. {
  8. dwTargetID = 0;
  9. SetThink(&CMonsterPet::IdleThink);
  10. }
  11. void CMonsterPet::SetFollow(CPhysicsObj *pTarget)
  12. {
  13. if (!pTarget)
  14. return;
  15. if (pTarget->IsItem())
  16. return;
  17. dwTargetID = pTarget->m_dwGUID;
  18. SetThink(&CMonsterPet::FollowThink);
  19. }
  20. BOOL CMonsterPet::IdleThink()
  21. {
  22. CBaseMonster::MonsterThink();
  23. return TRUE;
  24. }
  25. BOOL CMonsterPet::FollowThink()
  26. {
  27. CPhysicsObj* pTarget;
  28. if (!dwTargetID || !(pTarget = g_pWorld->FindWithinPVS(this, dwTargetID)))
  29. {
  30. //We lost our target!
  31. dwTargetID = 0;
  32. SetThink(&CMonsterPet::IdleThink);
  33. return TRUE;
  34. }
  35. Vector origin(m_Origin);
  36. Vector goal(pTarget->m_Origin);
  37. Vector goal_angle;
  38. AngleVectors(goal - origin, &goal_angle);
  39. m_fNextThink = g_pGlobals->Time() + 0.1f;
  40. CBaseMonster::MonsterThink();
  41. return TRUE;
  42. }