-
Notifications
You must be signed in to change notification settings - Fork 22
/
Pet.cpp
55 lines (42 loc) · 906 Bytes
/
Pet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "StdAfx.h"
#include "PhysicsObj.h"
#include "Monster.h"
#include "World.h"
#include "pet.h"
CMonsterPet::CMonsterPet()
{
dwTargetID = 0;
SetThink(&CMonsterPet::IdleThink);
}
void CMonsterPet::SetFollow(CPhysicsObj *pTarget)
{
if (!pTarget)
return;
if (pTarget->IsItem())
return;
dwTargetID = pTarget->m_dwGUID;
SetThink(&CMonsterPet::FollowThink);
}
BOOL CMonsterPet::IdleThink()
{
CBaseMonster::MonsterThink();
return TRUE;
}
BOOL CMonsterPet::FollowThink()
{
CPhysicsObj* pTarget;
if (!dwTargetID || !(pTarget = g_pWorld->FindWithinPVS(this, dwTargetID)))
{
//We lost our target!
dwTargetID = 0;
SetThink(&CMonsterPet::IdleThink);
return TRUE;
}
Vector origin(m_Origin);
Vector goal(pTarget->m_Origin);
Vector goal_angle;
AngleVectors(goal - origin, &goal_angle);
m_fNextThink = g_pGlobals->Time() + 0.1f;
CBaseMonster::MonsterThink();
return TRUE;
}