4 #include "../../../lib/warpzone/util_server.qh"
5 #include "../../../server/defs.qh"
14 // 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
16 // set myself as current viewloc where possible
17 for(e = world; (e = findentity(e, viewloc, self)); )
20 for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain)
22 if(IS_PLAYER(e)) // should we support non-player entities with this?
23 //if(e.deadflag == DEAD_NO) // death view is handled separately, we can't override this just yet
25 vector emin = e.absmin;
26 vector emax = e.absmax;
27 if(self.solid == SOLID_BSP)
32 if(boxesoverlap(emin, emax, self.absmin, self.absmax)) // quick
33 if(WarpZoneLib_BoxTouchesBrush(emin, emax, self, e)) // accurate
37 self.nextthink = time;
40 bool trigger_viewloc_send(entity this, entity to, int sf)
42 // CSQC doesn't need to know our origin (yet), as we're only available for referencing
43 WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC_TRIGGER);
45 WriteEntity(MSG_ENTITY, self.enemy);
46 WriteEntity(MSG_ENTITY, self.goalentity);
48 WriteCoord(MSG_ENTITY, self.origin_x);
49 WriteCoord(MSG_ENTITY, self.origin_y);
50 WriteCoord(MSG_ENTITY, self.origin_z);
58 for(e = world; (e = find(e, targetname, self.target)); )
59 if(e.classname == "target_viewlocation_start")
64 for(e = world; (e = find(e, targetname, self.target2)); )
65 if(e.classname == "target_viewlocation_end")
71 if(!self.enemy) { LOG_INFO("^1FAIL!\n"); remove(self); return; }
74 self.goalentity = self.enemy; // make them match so CSQC knows what to do
76 Net_LinkEntity(self, false, 0, trigger_viewloc_send);
78 self.think = viewloc_think;
79 self.nextthink = time;
82 spawnfunc(trigger_viewlocation)
84 // we won't check target2 here yet, as it may not even need to exist
85 if(self.target == "") { LOG_INFO("^1FAIL!\n"); remove(self); return; }
88 InitializeEntity(self, viewloc_init, INITPRIO_FINDTARGET);
91 bool viewloc_send(entity this, entity to, int sf)
93 WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC);
95 WriteByte(MSG_ENTITY, self.cnt);
97 WriteCoord(MSG_ENTITY, self.origin_x);
98 WriteCoord(MSG_ENTITY, self.origin_y);
99 WriteCoord(MSG_ENTITY, self.origin_z);
101 WriteCoord(MSG_ENTITY, self.angles_x);
102 WriteCoord(MSG_ENTITY, self.angles_y);
103 WriteCoord(MSG_ENTITY, self.angles_z);
112 self.angles_y = self.angle;
113 Net_LinkEntity(self, false, 0, viewloc_send);
116 spawnfunc(target_viewlocation_start)
118 self.classname = "target_viewlocation_start";
122 spawnfunc(target_viewlocation_end)
124 self.classname = "target_viewlocation_end";
130 spawnfunc(target_viewlocation) { spawnfunc_target_viewlocation_start(this); }
134 void trigger_viewloc_updatelink()
136 self.enemy = findfloat(world, entnum, self.cnt);
137 self.goalentity = findfloat(world, entnum, self.count);
140 NET_HANDLE(ENT_CLIENT_VIEWLOC_TRIGGER, bool isnew)
142 float point1 = ReadShort();
143 float point2 = ReadShort();
145 self.enemy = findfloat(world, entnum, point1);
146 self.goalentity = findfloat(world, entnum, point2);
148 self.origin_x = ReadCoord();
149 self.origin_y = ReadCoord();
150 self.origin_z = ReadCoord();
154 setorigin(self, self.origin);
159 self.think = trigger_viewloc_updatelink;
160 self.nextthink = time + 1; // we need to delay this or else
162 self.classname = "trigger_viewlocation";
163 self.drawmask = MASK_NORMAL; // not so concerned, but better keep it alive
166 NET_HANDLE(ENT_CLIENT_VIEWLOC, bool isnew)
168 self.cnt = ReadByte();
170 self.origin_x = ReadCoord();
171 self.origin_y = ReadCoord();
172 self.origin_z = ReadCoord();
173 setorigin(self, self.origin);
175 self.movedir_x = ReadCoord();
176 self.movedir_y = ReadCoord();
177 self.movedir_z = ReadCoord();
181 self.classname = ((self.cnt == 2) ? "target_viewlocation_end" : "target_viewlocation_start");
182 self.drawmask = MASK_NORMAL; // don't cull it