3 void SUB_DontUseTargets(entity this, entity actor, entity trigger) { }
5 void SUB_UseTargets(entity this, entity actor, entity trigger);
7 void DelayThink(entity this)
9 SUB_UseTargets (this, this.enemy, NULL);
14 void generic_setactive(entity this, int act)
16 if(act == ACTIVE_TOGGLE)
18 if(this.active == ACTIVE_ACTIVE)
20 this.active = ACTIVE_NOT;
24 this.active = ACTIVE_ACTIVE;
33 void generic_netlinked_setactive(entity this, int act)
35 int old_status = this.active;
36 generic_setactive(this, act);
38 if (this.active != old_status)
40 this.SendFlags |= SF_TRIGGER_UPDATE;
44 void generic_netlinked_reset(entity this)
48 if(this.spawnflags & START_ENABLED)
50 this.active = ACTIVE_ACTIVE;
54 this.active = ACTIVE_NOT;
59 this.active = ACTIVE_ACTIVE;
62 this.SendFlags |= SF_TRIGGER_UPDATE;
65 // Compatibility with old maps
66 void generic_netlinked_legacy_use(entity this, entity actor, entity trigger)
68 //LOG_WARNF("Entity %s was (de)activated by a trigger, please update map to use relays", this.targetname);
69 this.setactive(this, ACTIVE_TOGGLE);
72 bool autocvar_g_triggers_debug = true;
74 void trigger_init(entity this)
76 string m = this.model;
78 if(autocvar_g_triggers_debug)
83 _setmodel(this, m); // no precision needed
85 setorigin(this, this.origin);
87 setsize(this, this.mins * this.scale, this.maxs * this.scale);
89 setsize(this, this.mins, this.maxs);
92 if(autocvar_g_triggers_debug)
93 BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
96 void trigger_link(entity this, bool(entity this, entity to, int sendflags) sendfunc)
98 setSendEntity(this, sendfunc);
99 this.SendFlags = 0xFFFFFF;
102 void trigger_common_write(entity this, bool withtarget)
105 if(this.warpzone_isboxy)
107 if(this.origin != '0 0 0')
109 if(this.movedir != '0 0 0')
111 if(this.angles != '0 0 0')
112 BITSET_ASSIGN(f, 16);
113 WriteByte(MSG_ENTITY, f);
117 // probably some way to clean this up...
119 if(this.target && this.target != "") targbits |= BIT(0);
120 if(this.target2 && this.target2 != "") targbits |= BIT(1);
121 if(this.target3 && this.target3 != "") targbits |= BIT(2);
122 if(this.target4 && this.target4 != "") targbits |= BIT(3);
123 if(this.targetname && this.targetname != "") targbits |= BIT(4);
124 if(this.killtarget && this.killtarget != "") targbits |= BIT(5);
126 WriteByte(MSG_ENTITY, targbits);
128 if(targbits & BIT(0))
129 WriteString(MSG_ENTITY, this.target);
130 if(targbits & BIT(1))
131 WriteString(MSG_ENTITY, this.target2);
132 if(targbits & BIT(2))
133 WriteString(MSG_ENTITY, this.target3);
134 if(targbits & BIT(3))
135 WriteString(MSG_ENTITY, this.target4);
136 if(targbits & BIT(4))
137 WriteString(MSG_ENTITY, this.targetname);
138 if(targbits & BIT(5))
139 WriteString(MSG_ENTITY, this.killtarget);
143 WriteVector(MSG_ENTITY, this.origin);
146 WriteVector(MSG_ENTITY, this.movedir);
149 WriteVector(MSG_ENTITY, this.angles);
151 WriteShort(MSG_ENTITY, this.modelindex);
152 WriteVector(MSG_ENTITY, this.mins);
153 WriteVector(MSG_ENTITY, this.maxs);
154 WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255));
159 void trigger_common_read(entity this, bool withtarget)
162 this.warpzone_isboxy = (f & 1);
166 strfree(this.target);
167 strfree(this.target2);
168 strfree(this.target3);
169 strfree(this.target4);
170 strfree(this.targetname);
171 strfree(this.killtarget);
173 int targbits = ReadByte();
175 this.target = ((targbits & BIT(0)) ? strzone(ReadString()) : string_null);
176 this.target2 = ((targbits & BIT(1)) ? strzone(ReadString()) : string_null);
177 this.target3 = ((targbits & BIT(2)) ? strzone(ReadString()) : string_null);
178 this.target4 = ((targbits & BIT(3)) ? strzone(ReadString()) : string_null);
179 this.targetname = ((targbits & BIT(4)) ? strzone(ReadString()) : string_null);
180 this.killtarget = ((targbits & BIT(5)) ? strzone(ReadString()) : string_null);
184 this.origin = ReadVector();
186 this.origin = '0 0 0';
187 setorigin(this, this.origin);
190 this.movedir = ReadVector();
192 this.movedir = '0 0 0';
195 this.angles = ReadVector();
197 this.angles = '0 0 0';
199 this.modelindex = ReadShort();
200 this.mins = ReadVector();
201 this.maxs = ReadVector();
202 this.scale = ReadByte() / 16;
203 setsize(this, this.mins, this.maxs);
206 void trigger_remove_generic(entity this)
208 strfree(this.target);
209 strfree(this.target2);
210 strfree(this.target3);
211 strfree(this.target4);
212 strfree(this.targetname);
213 strfree(this.killtarget);
219 ==============================
222 the global "activator" should be set to the entity that initiated the firing.
224 If this.delay is set, a DelayedUse entity will be created that will actually
225 do the SUB_UseTargets after that many seconds have passed.
227 Centerprints any this.message to the activator.
229 Removes all entities with a targetname that match this.killtarget,
230 and removes them, so some events can remove other triggers.
232 Search for (string)targetname in all entities that
233 match (string)this.target and call their .use function
235 ==============================
238 void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventReuse)
245 // create a temp object to fire at a later time
246 entity t = new(DelayedUse);
247 t.nextthink = time + this.delay;
248 setthink(t, DelayThink);
250 t.message = this.message;
251 t.killtarget = this.killtarget;
252 t.target = this.target;
253 t.target2 = this.target2;
254 t.target3 = this.target3;
255 t.target4 = this.target4;
256 t.antiwall_flag = this.antiwall_flag;
267 if(IS_PLAYER(actor) && this.message != "")
268 if(IS_REAL_CLIENT(actor))
270 centerprint(actor, this.message);
271 if (this.noise == "")
272 play2(actor, SND(TALK));
276 // kill the killtagets
281 for(entity t = NULL; (t = find(t, targetname, s)); )
290 if(this.target_random)
291 RandomSelection_Init();
293 for(int i = 0; i < 4; ++i)
298 case 0: s = this.target; break;
299 case 1: s = this.target2; break;
300 case 2: s = this.target3; break;
301 case 3: s = this.target4; break;
305 for(entity t = NULL; (t = find(t, targetname, s)); )
307 if(t != this && t.use && (t.sub_target_used != time || !preventReuse))
309 if(this.target_random)
311 RandomSelection_AddEnt(t, 1, 0);
315 t.use(t, actor, this);
317 t.sub_target_used = time;
324 if(this.target_random && RandomSelection_chosen_ent)
326 RandomSelection_chosen_ent.use(RandomSelection_chosen_ent, actor, this);
328 RandomSelection_chosen_ent.sub_target_used = time;
332 void SUB_UseTargets(entity this, entity actor, entity trigger) { SUB_UseTargets_Ex(this, actor, trigger, false); }
333 void SUB_UseTargets_PreventReuse(entity this, entity actor, entity trigger) { SUB_UseTargets_Ex(this, actor, trigger, true); }