Nuclide
Software Development Kit for id Technology (BETA)
Trigger.h
1/*
2 * Copyright (c) 2016-2024 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17/* ncTrigger class is responsible for the legacy trigger architecture.
18 In the future, ncEntity can be configured so that legacy
19 triggers can be disabled. That's why this class is separate from ncIO.
20
21 This is a very low-level class. You're never meant to use this.
22 Use ncEntity as a basis for your classes.
23*/
24
25#define CENVGLOBAL_CVAR "env_global_data"
26
28typedef enum
29{
31 GLOBAL_OFF,
33 GLOBAL_ON,
35 GLOBAL_DEAD
36} globalstate_t;
37
39typedef enum
40{
42 TRIG_OFF,
44 TRIG_ON,
46 TRIG_TOGGLE
47} triggermode_t;
48
50{
51 TOUCHFILTER_CLIENTS,
52 TOUCHFILTER_NPCS,
53 TOUCHFILTER_PUSHABLE,
54 TOUCHFILTER_PHYSICS,
55 TOUCHFILTER_FRIENDLIES,
56 TOUCHFILTER_CLIENTSINVEHICLES,
57 TOUCHFILTER_EVERYTHING,
58 TOUCHFILTER_PADDING1,
59 TOUCHFILTER_PADDING2,
60 TOUCHFILTER_CLIENTSNOTINVEHICLES,
61 TOUCHFILTER_DEBRIS,
62 TOUCHFILTER_NPCSINVEHICLES,
63 TOUCHFILTER_NOBOTS
64};
65
66
77{
78public:
79 void ncTrigger(void);
80
81 /* touch/blocked */
84 virtual void Blocked(entity);
86 virtual void StartTouch(entity);
87
89 virtual void Touch(entity);
90
92 virtual void EndTouch(entity);
93
94 /* overrides */
95 virtual void SpawnKey(string,string);
96
97#ifdef SERVER
98 /* overrides */
99 virtual void Save(float);
100 virtual void Restore(string,string);
101 virtual void Spawned(void);
102 virtual void Input(entity,string,string);
103
105 nonvirtual void SetValue(int newValue);
106
107 /* Called to check if the target entity can touch trigger itself. */
108 virtual bool CanBeTriggeredBy(entity);
109
111 virtual void Trigger(entity, triggermode_t);
112
113 /* master feature */
115 /* multisource overrides this, so keep virtual */
116 virtual int GetValue(entity);
117
119 nonvirtual void UseTargets(entity,int,float);
120
122 nonvirtual void SetTriggerTarget(string);
123
125 nonvirtual int GetMaster(entity);
126
128 nonvirtual bool TriggerEnabled(void);
129
130 nonvirtual void EnableTrigger(void);
131 nonvirtual void DisableTrigger(void);
132 nonvirtual void ToggleTrigger(void);
133
135 nonvirtual globalstate_t GetGlobalValue(string);
136
138 nonvirtual string GetTriggerMessage(void);
139
141 nonvirtual string GetTriggerKillTarget(void);
142
144 nonvirtual string GetTriggerTarget(void);
145
147 nonvirtual float GetTriggerDelay(void);
148
150 nonvirtual entity GetTargetEntity(void);
151
153 nonvirtual bool HasTriggerTarget(void);
154
156 nonvirtual bool HasTargetname(void);
157
159 nonvirtual void SetTeam(float);
160
162 nonvirtual float GetTeam(void);
163#endif
165 nonvirtual vector GetTouchPosition(void);
167 nonvirtual vector GetTouchNormal(void);
168
169private:
170 /* not needed to be saved right now */
171 float m_timeSinceLastTouch;
172 bool m_beingTouched;
173 entity m_touchingEntity;
174 vector m_touchPosition;
175 vector m_touchNormal;
176
177 nonvirtual void _TouchHandler(void);
178 nonvirtual void _BlockedHandler(void);
179
180#ifdef SERVER
181 string m_globalName;
182 string m_globalState;
183 string m_triggerKillTarget;
184 string m_triggerMessage;
185 string m_masterName;
186 int m_triggerValue;
187
188 bool m_triggerEnabled;
189 bool m_triggerStartsDisabled;
190 bool m_triggerSpawnflagFilter;
191
192 float m_touchingOnlyTeam;
193
194 /* legacy trigger architecture */
195 float m_triggerDelay;
196#endif
197
198#ifdef CLIENT
199 float team;
200#endif
201};
This class is responsible for handling core entity functionality.
Definition: IO.h:78
ncTrigger handles all the non-input as well as Legacy (Quake, GoldSource) style trigger behaviour.
Definition: Trigger.h:77
nonvirtual bool TriggerEnabled(void)
Returns whether the trigger functionality of this entity is enabled.
Definition: Trigger.qc:292
virtual int GetValue(entity)
Returns what we will pass onto other's ncTrigger::GetMaster() calls if we're their master.
Definition: Trigger.qc:166
virtual void Blocked(entity)
Called whenever out movement is being blocked by an entity.
Definition: Trigger.qc:451
void ncTrigger(void)
Definition: Trigger.qc:18
nonvirtual void UseTargets(entity, int, float)
When called will trigger its legacy targets with a given delay.
Definition: Trigger.qc:98
nonvirtual entity GetTargetEntity(void)
Returns the first entity named after the target field.
Definition: Trigger.qc:250
nonvirtual float GetTeam(void)
Retrives the team value of a given entity.
Definition: Trigger.qc:407
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: Trigger.qc:368
nonvirtual void SetTriggerTarget(string)
Sets the legacy target for this entity.
Definition: Trigger.qc:154
nonvirtual void EnableTrigger(void)
Definition: Trigger.qc:274
nonvirtual float GetTriggerDelay(void)
Returns the time until this triggers is scheduled to fire its targets, relative time in seconds.
Definition: Trigger.qc:232
nonvirtual globalstate_t GetGlobalValue(string)
Returns the value of a given env_global property.
Definition: Trigger.qc:172
nonvirtual vector GetTouchNormal(void)
Returns the normal of the last valid surface the entity has touched.
Definition: Trigger.qc:487
virtual void StartTouch(entity)
Called when we started touching another entity.
Definition: Trigger.qc:469
nonvirtual void DisableTrigger(void)
Definition: Trigger.qc:280
nonvirtual void SetValue(int newValue)
Sets the internal value of the entity as queried by GetValue().
Definition: Trigger.qc:160
virtual bool CanBeTriggeredBy(entity)
Definition: Trigger.qc:43
nonvirtual bool HasTargetname(void)
Returns TRUE if the entity has a name that can be used for messaging.
Definition: Trigger.qc:265
virtual void EndTouch(entity)
Called when we stopped touching the last touched entity.
Definition: Trigger.qc:475
nonvirtual bool HasTriggerTarget(void)
Returns TRUE if the entity has a legacy trigger target.
Definition: Trigger.qc:259
virtual void Trigger(entity, triggermode_t)
Called whenever we're legacy triggered by another object or function.
Definition: Trigger.qc:92
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: Trigger.qc:414
nonvirtual vector GetTouchPosition(void)
Returns the last valid point the entity has touched.
Definition: Trigger.qc:481
nonvirtual string GetTriggerKillTarget(void)
Returns the name of the entity group it will remove from the game upon trigger.
Definition: Trigger.qc:244
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: Trigger.qc:35
nonvirtual string GetTriggerTarget(void)
Returns the name of the entity group it can trigger (legacy style).
Definition: Trigger.qc:226
nonvirtual string GetTriggerMessage(void)
Returns the message which will be displayed upon trigger.
Definition: Trigger.qc:238
virtual void Restore(string, string)
Similar to ncIO::SpawnKey() but for save-game fields.
Definition: Trigger.qc:317
virtual void Touch(entity)
Called whenever we're touching another entity.
Definition: Trigger.qc:463
nonvirtual void SetTeam(float)
Assigns the entity to a given team value.
Definition: Trigger.qc:395
nonvirtual void ToggleTrigger(void)
Definition: Trigger.qc:286
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: Trigger.qc:298
nonvirtual int GetMaster(entity)
Returns whether our master allows us to be triggered.
Definition: Trigger.qc:193
typedef enumflags
Defines the valid alignment flags for text fields.
Definition: font.h:37