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 virtual void OnRemoveEntity(void);
98
99#ifdef SERVER
100 /* overrides */
101 virtual void Save(float);
102 virtual void Restore(string,string);
103 virtual void Spawned(void);
104 virtual void Input(entity,string,string);
105
107 nonvirtual void SetValue(int newValue);
108
109 /* Called to check if the target entity can touch trigger itself. */
110 virtual bool CanBeTriggeredBy(entity);
111
113 virtual void Trigger(entity, triggermode_t);
114
115 /* master feature */
117 /* multisource overrides this, so keep virtual */
118 virtual int GetValue(entity);
119
121 nonvirtual void UseTargets(entity,int,float);
122
124 nonvirtual void SetTriggerTarget(string);
125
127 nonvirtual int GetMaster(entity);
128
130 nonvirtual bool TriggerEnabled(void);
131
132 nonvirtual void EnableTrigger(void);
133 nonvirtual void DisableTrigger(void);
134 nonvirtual void ToggleTrigger(void);
135
137 nonvirtual globalstate_t GetGlobalValue(string);
138
140 nonvirtual string GetTriggerMessage(void);
141
143 nonvirtual string GetTriggerKillTarget(void);
144
146 nonvirtual string GetTriggerTarget(void);
147
149 nonvirtual float GetTriggerDelay(void);
150
152 nonvirtual entity GetTargetEntity(void);
153
155 nonvirtual string Name(void);
156
158 nonvirtual bool HasTriggerTarget(void);
159
161 nonvirtual bool HasTargetname(void);
162
164 nonvirtual void SetTeam(float);
165
167 nonvirtual float GetTeam(void);
168#endif
170 nonvirtual vector GetTouchPosition(void);
172 nonvirtual vector GetTouchNormal(void);
173
174private:
175 /* not needed to be saved right now */
176 float m_timeSinceLastTouch;
177 bool m_beingTouched;
178 entity m_touchingEntity;
179 vector m_touchPosition;
180 vector m_touchNormal;
181
182 nonvirtual void _TouchHandler(void);
183 nonvirtual void _BlockedHandler(void);
184
185#ifdef SERVER
186 nonvirtual void _TouchEnded(void);
187
188 string m_globalName;
189 string m_globalState;
190 string m_triggerKillTarget;
191 string m_triggerMessage;
192 string m_masterName;
193 int m_triggerValue;
194
195 bool m_triggerEnabled;
196 bool m_triggerStartsDisabled;
197 bool m_triggerSpawnflagFilter;
198
199 float m_touchingOnlyTeam;
200
201 string m_outputOnPlayerTouch;
202 string m_outputOnStartTouch;
203 string m_outputOnEndTouch;
204 string m_outputOnEnable;
205 string m_outputOnDisable;
206
207 /* legacy trigger architecture */
208 float m_triggerDelay;
209#endif
210
211#ifdef CLIENT
212 float team;
213#endif
214};
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:321
virtual int GetValue(entity)
Returns what we will pass onto other's ncTrigger::GetMaster() calls if we're their master.
Definition: Trigger.qc:189
virtual void Blocked(entity)
Called whenever out movement is being blocked by an entity.
Definition: Trigger.qc:506
void ncTrigger(void)
Definition: Trigger.qc:22
nonvirtual void UseTargets(entity, int, float)
When called will trigger its legacy targets with a given delay.
Definition: Trigger.qc:121
nonvirtual entity GetTargetEntity(void)
Returns the first entity named after the target field.
Definition: Trigger.qc:273
nonvirtual float GetTeam(void)
Retrives the team value of a given entity.
Definition: Trigger.qc:444
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: Trigger.qc:397
nonvirtual void SetTriggerTarget(string)
Sets the legacy target for this entity.
Definition: Trigger.qc:177
nonvirtual string Name(void)
Returns the name of the entity.
Definition: Trigger.qc:297
nonvirtual void EnableTrigger(void)
Definition: Trigger.qc:303
nonvirtual float GetTriggerDelay(void)
Returns the time until this triggers is scheduled to fire its targets, relative time in seconds.
Definition: Trigger.qc:255
nonvirtual globalstate_t GetGlobalValue(string)
Returns the value of a given env_global property.
Definition: Trigger.qc:195
nonvirtual vector GetTouchNormal(void)
Returns the normal of the last valid surface the entity has touched.
Definition: Trigger.qc:542
virtual void StartTouch(entity)
Called when we started touching another entity.
Definition: Trigger.qc:524
nonvirtual void DisableTrigger(void)
Definition: Trigger.qc:309
nonvirtual void SetValue(int newValue)
Sets the internal value of the entity as queried by GetValue().
Definition: Trigger.qc:183
virtual bool CanBeTriggeredBy(entity)
Definition: Trigger.qc:66
nonvirtual bool HasTargetname(void)
Returns TRUE if the entity has a name that can be used for messaging.
Definition: Trigger.qc:288
virtual void EndTouch(entity)
Called when we stopped touching the last touched entity.
Definition: Trigger.qc:530
nonvirtual bool HasTriggerTarget(void)
Returns TRUE if the entity has a legacy trigger target.
Definition: Trigger.qc:282
virtual void Trigger(entity, triggermode_t)
Called whenever we're legacy triggered by another object or function.
Definition: Trigger.qc:115
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: Trigger.qc:451
nonvirtual vector GetTouchPosition(void)
Returns the last valid point the entity has touched.
Definition: Trigger.qc:536
nonvirtual string GetTriggerKillTarget(void)
Returns the name of the entity group it will remove from the game upon trigger.
Definition: Trigger.qc:267
virtual void Spawned(void)
Called when the entity is fully initialized.
Definition: Trigger.qc:43
nonvirtual string GetTriggerTarget(void)
Returns the name of the entity group it can trigger (legacy style).
Definition: Trigger.qc:249
nonvirtual string GetTriggerMessage(void)
Returns the message which will be displayed upon trigger.
Definition: Trigger.qc:261
virtual void Restore(string, string)
Similar to ncIO::SpawnKey() but for save-game fields.
Definition: Trigger.qc:346
virtual void OnRemoveEntity(void)
Handles what happens before the entity gets removed from the client game.
Definition: Trigger.qc:616
virtual void Touch(entity)
Called whenever we're touching another entity.
Definition: Trigger.qc:518
nonvirtual void SetTeam(float)
Assigns the entity to a given team value.
Definition: Trigger.qc:426
nonvirtual void ToggleTrigger(void)
Definition: Trigger.qc:315
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: Trigger.qc:327
nonvirtual int GetMaster(entity)
Returns whether our master allows us to be triggered.
Definition: Trigger.qc:216
typedef enumflags
Defines the valid alignment flags for text fields.
Definition: font.h:37