4 #include <lib/warpzone/util_server.qh>
5 #include <server/defs.qh>
8 REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC)
9 REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC_TRIGGER)
17 // 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
19 // set myself as current viewloc where possible
20 for(e = world; (e = findentity(e, viewloc, self)); )
23 for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain)
25 if(IS_PLAYER(e)) // should we support non-player entities with this?
26 //if(!IS_DEAD(e)) // death view is handled separately, we can't override this just yet
28 vector emin = e.absmin;
29 vector emax = e.absmax;
30 if(self.solid == SOLID_BSP)
35 if(boxesoverlap(emin, emax, self.absmin, self.absmax)) // quick
36 if(WarpZoneLib_BoxTouchesBrush(emin, emax, self, e)) // accurate
40 self.nextthink = time;
43 bool trigger_viewloc_send(entity this, entity to, int sf)
45 // CSQC doesn't need to know our origin (yet), as we're only available for referencing
46 WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC_TRIGGER);
48 WriteEntity(MSG_ENTITY, self.enemy);
49 WriteEntity(MSG_ENTITY, self.goalentity);
51 WriteCoord(MSG_ENTITY, self.origin_x);
52 WriteCoord(MSG_ENTITY, self.origin_y);
53 WriteCoord(MSG_ENTITY, self.origin_z);
58 void viewloc_init(entity this)
61 for(e = world; (e = find(e, targetname, self.target)); )
62 if(e.classname == "target_viewlocation_start")
67 for(e = world; (e = find(e, targetname, self.target2)); )
68 if(e.classname == "target_viewlocation_end")
74 if(!self.enemy) { LOG_INFO("^1FAIL!\n"); remove(self); return; }
77 self.goalentity = self.enemy; // make them match so CSQC knows what to do
79 Net_LinkEntity(self, false, 0, trigger_viewloc_send);
81 self.think = viewloc_think;
82 self.nextthink = time;
85 spawnfunc(trigger_viewlocation)
87 // we won't check target2 here yet, as it may not even need to exist
88 if(self.target == "") { LOG_INFO("^1FAIL!\n"); remove(self); return; }
91 InitializeEntity(self, viewloc_init, INITPRIO_FINDTARGET);
94 bool viewloc_send(entity this, entity to, int sf)
96 WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC);
98 WriteByte(MSG_ENTITY, self.cnt);
100 WriteCoord(MSG_ENTITY, self.origin_x);
101 WriteCoord(MSG_ENTITY, self.origin_y);
102 WriteCoord(MSG_ENTITY, self.origin_z);
104 WriteCoord(MSG_ENTITY, self.angles_x);
105 WriteCoord(MSG_ENTITY, self.angles_y);
106 WriteCoord(MSG_ENTITY, self.angles_z);
115 self.angles_y = self.angle;
116 Net_LinkEntity(self, false, 0, viewloc_send);
119 spawnfunc(target_viewlocation_start)
121 self.classname = "target_viewlocation_start";
125 spawnfunc(target_viewlocation_end)
127 self.classname = "target_viewlocation_end";
133 spawnfunc(target_viewlocation) { spawnfunc_target_viewlocation_start(this); }
137 void trigger_viewloc_updatelink()
139 self.enemy = findfloat(world, entnum, self.cnt);
140 self.goalentity = findfloat(world, entnum, self.count);
143 NET_HANDLE(ENT_CLIENT_VIEWLOC_TRIGGER, bool isnew)
145 float point1 = ReadShort();
146 float point2 = ReadShort();
148 self.enemy = findfloat(world, entnum, point1);
149 self.goalentity = findfloat(world, entnum, point2);
151 self.origin_x = ReadCoord();
152 self.origin_y = ReadCoord();
153 self.origin_z = ReadCoord();
157 setorigin(self, self.origin);
162 self.think = trigger_viewloc_updatelink;
163 self.nextthink = time + 1; // we need to delay this or else
165 self.classname = "trigger_viewlocation";
166 self.drawmask = MASK_NORMAL; // not so concerned, but better keep it alive
169 NET_HANDLE(ENT_CLIENT_VIEWLOC, bool isnew)
171 self.cnt = ReadByte();
173 self.origin_x = ReadCoord();
174 self.origin_y = ReadCoord();
175 self.origin_z = ReadCoord();
176 setorigin(self, self.origin);
178 self.movedir_x = ReadCoord();
179 self.movedir_y = ReadCoord();
180 self.movedir_z = ReadCoord();
184 self.classname = ((self.cnt == 2) ? "target_viewlocation_end" : "target_viewlocation_start");
185 self.drawmask = MASK_NORMAL; // don't cull it