4 #include "../../../dpdefs/progsdefs.qh"
5 #include "../../../warpzonelib/util_server.qh"
6 #include "../../../server/defs.qh"
15 // we abuse this method, rather than using normal .touch, because touch isn't reliable with multiple clients inside the same trigger, and can't "untouch" entities
17 // set myself as current viewloc where possible
18 for(e = world; (e = findentity(e, viewloc, self)); )
21 for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain)
23 if(IS_PLAYER(e)) // should we support non-player entities with this?
24 //if(e.deadflag == DEAD_NO) // death view is handled separately, we can't override this just yet
26 vector emin = e.absmin;
27 vector emax = e.absmax;
28 if(self.solid == SOLID_BSP)
33 if(boxesoverlap(emin, emax, self.absmin, self.absmax)) // quick
34 if(WarpZoneLib_BoxTouchesBrush(emin, emax, self, e)) // accurate
38 self.nextthink = time;
41 bool trigger_viewloc_send(entity this, entity to, int sf)
43 // CSQC doesn't need to know our origin (yet), as we're only available for referencing
44 WriteByte(MSG_ENTITY, ENT_CLIENT_VIEWLOC_TRIGGER);
46 WriteEntity(MSG_ENTITY, self.enemy);
47 WriteEntity(MSG_ENTITY, self.goalentity);
49 WriteCoord(MSG_ENTITY, self.origin_x);
50 WriteCoord(MSG_ENTITY, self.origin_y);
51 WriteCoord(MSG_ENTITY, self.origin_z);
59 for(e = world; (e = find(e, targetname, self.target)); )
60 if(e.classname == "target_viewlocation_start")
65 for(e = world; (e = find(e, targetname, self.target2)); )
66 if(e.classname == "target_viewlocation_end")
72 if(!self.enemy) { LOG_INFO("^1FAIL!\n"); remove(self); return; }
75 self.goalentity = self.enemy; // make them match so CSQC knows what to do
77 Net_LinkEntity(self, false, 0, trigger_viewloc_send);
79 self.think = viewloc_think;
80 self.nextthink = time;
83 spawnfunc(trigger_viewlocation)
85 // we won't check target2 here yet, as it may not even need to exist
86 if(self.target == "") { LOG_INFO("^1FAIL!\n"); remove(self); return; }
89 InitializeEntity(self, viewloc_init, INITPRIO_FINDTARGET);
92 bool viewloc_send(entity this, entity to, int sf)
94 WriteByte(MSG_ENTITY, ENT_CLIENT_VIEWLOC);
96 WriteByte(MSG_ENTITY, self.cnt);
98 WriteCoord(MSG_ENTITY, self.origin_x);
99 WriteCoord(MSG_ENTITY, self.origin_y);
100 WriteCoord(MSG_ENTITY, self.origin_z);
102 WriteCoord(MSG_ENTITY, self.angles_x);
103 WriteCoord(MSG_ENTITY, self.angles_y);
104 WriteCoord(MSG_ENTITY, self.angles_z);
113 self.angles_y = self.angle;
114 Net_LinkEntity(self, false, 0, viewloc_send);
117 spawnfunc(target_viewlocation_start)
119 self.classname = "target_viewlocation_start";
123 spawnfunc(target_viewlocation_end)
125 self.classname = "target_viewlocation_end";
131 spawnfunc(target_viewlocation) { spawnfunc_target_viewlocation_start(this); }
135 void trigger_viewloc_updatelink()
137 self.enemy = findfloat(world, entnum, self.cnt);
138 self.goalentity = findfloat(world, entnum, self.count);
141 void ent_viewloc_trigger()
143 float point1 = ReadShort();
144 float point2 = ReadShort();
146 self.enemy = findfloat(world, entnum, point1);
147 self.goalentity = findfloat(world, entnum, point2);
149 self.origin_x = ReadCoord();
150 self.origin_y = ReadCoord();
151 self.origin_z = ReadCoord();
152 setorigin(self, self.origin);
157 self.think = trigger_viewloc_updatelink;
158 self.nextthink = time + 1; // we need to delay this or else
160 self.classname = "trigger_viewlocation";
161 self.drawmask = MASK_NORMAL; // not so concerned, but better keep it alive
166 self.cnt = ReadByte();
168 self.origin_x = ReadCoord();
169 self.origin_y = ReadCoord();
170 self.origin_z = ReadCoord();
171 setorigin(self, self.origin);
173 self.movedir_x = ReadCoord();
174 self.movedir_y = ReadCoord();
175 self.movedir_z = ReadCoord();
177 self.classname = ((self.cnt == 2) ? "target_viewlocation_end" : "target_viewlocation_start");
178 self.drawmask = MASK_NORMAL; // don't cull it