forked from derandark/PhatAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPortal.cpp
99 lines (78 loc) · 2.08 KB
/
Portal.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "StdAfx.h"
#include "Portal.h"
#include "World.h"
#include "ChatMsgs.h"
#define PORTAL_TRIGGER_DISTANCE 2.0f
#define PORTAL_TRIGGER_FREQUENCY 1.0f
CPortal::CPortal()
{
m_strName = "Portal";
m_wTypeID = 0x82D;
m_wIcon = 0x106B;
m_dwModel = 0x20001B3;
m_PhysicsState = ETHEREAL_PS | REPORT_COLLISIONS_PS | LIGHTING_ON_PS | GRAVITY_PS;
m_ItemType = TYPE_PORTAL;
m_WeenieBitfield = BF_PORTAL | BF_STUCK | BF_ATTACKABLE;
m_Usability = USEABLE_REMOTE;
m_UseDistance = 20.0;
m_bHasDestination = false;
// Arwic, for testing if we want to
m_Destination.origin = loc_t(0xC6A90023, 102.4f, 70.1f, 44.0f);
m_Destination.angles = heading_t(0.70710677f, 0, 0, 0.70710677f);
}
CPortal::~CPortal()
{
}
void CPortal::Precache()
{
// Load entity settings (location, and dynamic properties.)
SetThink(&CPortal::ProximityThink);
m_fNextThink = g_pGlobals->Time() + 0.1f;
}
void CPortal::Teleport(CPhysicsObj *pTarget)
{
if (m_bHasDestination)
{
pTarget->Movement_Teleport(m_Destination.origin, m_Destination.angles);
}
else
{
pTarget->SendNetMessage(ServerText("This portal has no destination set.", 7), PRIVATE_MSG, FALSE, TRUE);
}
}
BOOL CPortal::ProximityThink()
{
// Clear old teleports cache
if ((m_fLastCacheClear + PORTAL_TRIGGER_FREQUENCY) < g_pGlobals->Time())
{
m_RecentlyTeleported.clear();
m_fLastCacheClear = g_pGlobals->Time();
}
std::list<CPhysicsObj *> nearbyObjects;
g_pWorld->EnumNearby(this, PORTAL_TRIGGER_DISTANCE, &nearbyObjects);
for (std::list<CPhysicsObj *>::iterator i = nearbyObjects.begin(); i != nearbyObjects.end(); i++)
{
CPhysicsObj *pOther = *i;
if (pOther->IsPlayer() && !(pOther->m_PhysicsState & PhysicsState::LIGHTING_ON_PS))
{
if (m_RecentlyTeleported.find(pOther->m_dwGUID) == m_RecentlyTeleported.end())
{
Teleport(pOther);
m_RecentlyTeleported.insert(pOther->m_dwGUID);
}
}
}
m_fNextThink = g_pGlobals->Time() + 0.1f;
return TRUE;
}
void CPortal::Use(CPhysicsObj *pOther)
{
if (!pOther->IsPlayer())
{
return;
}
if ((Vector(pOther->m_Origin) - Vector(m_Origin)).Length() < 2.0)
{
Teleport(pOther);
}
}