5 #include <lib/warpzone/util_server.qh>
6 #include <common/mapobjects/triggers.qh>
7 #include <server/defs.qh>
10 REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC)
11 REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC_TRIGGER)
15 void viewloc_think(entity this)
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
21 FOREACH_CLIENT(IS_PLAYER(it) && it.viewloc == this,
27 for(e = NULL; (e = findentity(e, viewloc, this)); )
32 FOREACH_CLIENT(!it.viewloc && IS_PLAYER(it),
34 vector emin = it.absmin;
35 vector emax = it.absmax;
36 if(this.solid == SOLID_BSP)
41 if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
43 if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, it)) // accurate
49 for(e = findradius((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1); e; e = e.chain)
51 if(IS_PLAYER(e)) // should we support non-player entities with this?
52 //if(!IS_DEAD(e)) // death view is handled separately, we can't override this just yet
54 vector emin = e.absmin;
55 vector emax = e.absmax;
56 if(this.solid == SOLID_BSP)
61 if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
62 if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, e)) // accurate
67 this.nextthink = time;
70 bool trigger_viewloc_send(entity this, entity to, int sf)
72 // CSQC doesn't need to know our origin (yet), as we're only available for referencing
73 WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC_TRIGGER);
75 WriteByte(MSG_ENTITY, this.spawnflags);
77 WriteEntity(MSG_ENTITY, this.enemy);
78 WriteEntity(MSG_ENTITY, this.goalentity);
80 WriteVector(MSG_ENTITY, this.origin);
85 void viewloc_init(entity this)
88 for(e = NULL; (e = find(e, targetname, this.target)); )
89 if(e.classname == "target_viewlocation_start")
94 for(e = NULL; (e = find(e, targetname, this.target2)); )
95 if(e.classname == "target_viewlocation_end")
101 if(!this.enemy) { LOG_INFO("^1FAIL!"); delete(this); return; }
104 this.goalentity = this.enemy; // make them match so CSQC knows what to do
106 Net_LinkEntity(this, false, 0, trigger_viewloc_send);
108 setthink(this, viewloc_think);
109 this.nextthink = time;
112 spawnfunc(trigger_viewlocation)
114 // we won't check target2 here yet, as it may not even need to exist
115 if(this.target == "") { LOG_INFO("^1FAIL!"); delete(this); return; }
118 InitializeEntity(this, viewloc_init, INITPRIO_FINDTARGET);
121 bool viewloc_send(entity this, entity to, int sf)
123 WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC);
125 WriteByte(MSG_ENTITY, this.cnt);
127 WriteVector(MSG_ENTITY, this.origin);
129 WriteAngleVector(MSG_ENTITY, this.angles);
135 void viewloc_link(entity this)
138 this.angles_y = this.angle;
139 Net_LinkEntity(this, false, 0, viewloc_send);
142 spawnfunc(target_viewlocation_start)
144 this.classname = "target_viewlocation_start";
148 spawnfunc(target_viewlocation_end)
150 this.classname = "target_viewlocation_end";
156 spawnfunc(target_viewlocation)
158 spawnfunc_target_viewlocation_start(this);
163 void trigger_viewloc_updatelink(entity this)
165 this.enemy = findfloat(NULL, entnum, this.cnt);
166 this.goalentity = findfloat(NULL, entnum, this.count);
169 NET_HANDLE(ENT_CLIENT_VIEWLOC_TRIGGER, bool isnew)
171 this.spawnflags = ReadByte();
173 float point1 = ReadShort();
174 float point2 = ReadShort();
176 this.enemy = findfloat(NULL, entnum, point1);
177 this.goalentity = findfloat(NULL, entnum, point2);
179 this.origin = ReadVector();
183 setorigin(this, this.origin);
188 setthink(this, trigger_viewloc_updatelink);
189 this.nextthink = time + 1; // we need to delay this or else
191 this.classname = "trigger_viewlocation";
192 this.drawmask = MASK_NORMAL; // not so concerned, but better keep it alive
195 NET_HANDLE(ENT_CLIENT_VIEWLOC, bool isnew)
197 this.cnt = ReadByte();
199 this.origin = ReadVector();
200 setorigin(this, this.origin);
202 this.movedir = ReadAngleVector();
206 this.classname = ((this.cnt == 2) ? "target_viewlocation_end" : "target_viewlocation_start");
207 this.drawmask = MASK_NORMAL; // don't cull it