5 #include <lib/warpzone/util_server.qh>
6 #include <common/mapobjects/triggers.qh>
7 #include <common/weapons/_all.qh>
8 #include <common/stats.qh>
11 REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC)
12 REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC_TRIGGER)
16 void viewloc_think(entity this)
18 // 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
20 // set myself as current viewloc where possible
22 FOREACH_CLIENT(IS_PLAYER(it) && it.viewloc == this,
28 for(e = NULL; (e = findentity(e, viewloc, this)); )
33 FOREACH_CLIENT(!it.viewloc && IS_PLAYER(it),
35 vector emin = it.absmin;
36 vector emax = it.absmax;
37 if(this.solid == SOLID_BSP)
42 if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
44 if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, it)) // accurate
50 for(e = findradius((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1); e; e = e.chain)
52 if(IS_PLAYER(e)) // should we support non-player entities with this?
53 //if(!IS_DEAD(e)) // death view is handled separately, we can't override this just yet
55 vector emin = e.absmin;
56 vector emax = e.absmax;
57 if(this.solid == SOLID_BSP)
62 if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
63 if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, e)) // accurate
68 this.nextthink = time;
71 bool trigger_viewloc_send(entity this, entity to, int sf)
73 // CSQC doesn't need to know our origin (yet), as we're only available for referencing
74 WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC_TRIGGER);
76 WriteByte(MSG_ENTITY, this.spawnflags);
78 WriteEntity(MSG_ENTITY, this.enemy);
79 WriteEntity(MSG_ENTITY, this.goalentity);
81 WriteVector(MSG_ENTITY, this.origin);
86 void viewloc_init(entity this)
89 for(e = NULL; (e = find(e, targetname, this.target)); )
90 if(e.classname == "target_viewlocation_start")
95 for(e = NULL; (e = find(e, targetname, this.target2)); )
96 if(e.classname == "target_viewlocation_end")
102 if(!this.enemy) { LOG_INFO("^1FAIL!"); delete(this); return; }
105 this.goalentity = this.enemy; // make them match so CSQC knows what to do
107 Net_LinkEntity(this, false, 0, trigger_viewloc_send);
109 setthink(this, viewloc_think);
110 this.nextthink = time;
113 spawnfunc(trigger_viewlocation)
115 // we won't check target2 here yet, as it may not even need to exist
116 if(this.target == "") { LOG_INFO("^1FAIL!"); delete(this); return; }
119 InitializeEntity(this, viewloc_init, INITPRIO_FINDTARGET);
122 bool viewloc_send(entity this, entity to, int sf)
124 WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC);
126 WriteByte(MSG_ENTITY, this.cnt);
128 WriteVector(MSG_ENTITY, this.origin);
130 WriteAngleVector(MSG_ENTITY, this.angles);
136 void viewloc_link(entity this)
139 this.angles_y = this.angle;
140 Net_LinkEntity(this, false, 0, viewloc_send);
143 spawnfunc(target_viewlocation_start)
145 this.classname = "target_viewlocation_start";
149 spawnfunc(target_viewlocation_end)
151 this.classname = "target_viewlocation_end";
157 spawnfunc(target_viewlocation)
159 spawnfunc_target_viewlocation_start(this);
164 void trigger_viewloc_updatelink(entity this)
166 this.enemy = findfloat(NULL, entnum, this.cnt);
167 this.goalentity = findfloat(NULL, entnum, this.count);
170 NET_HANDLE(ENT_CLIENT_VIEWLOC_TRIGGER, bool isnew)
172 this.spawnflags = ReadByte();
174 float point1 = ReadShort();
175 float point2 = ReadShort();
177 this.enemy = findfloat(NULL, entnum, point1);
178 this.goalentity = findfloat(NULL, entnum, point2);
180 this.origin = ReadVector();
184 setorigin(this, this.origin);
189 setthink(this, trigger_viewloc_updatelink);
190 this.nextthink = time + 1; // we need to delay this or else
192 this.classname = "trigger_viewlocation";
193 this.drawmask = MASK_NORMAL; // not so concerned, but better keep it alive
196 NET_HANDLE(ENT_CLIENT_VIEWLOC, bool isnew)
198 this.cnt = ReadByte();
200 this.origin = ReadVector();
201 setorigin(this, this.origin);
203 this.movedir = ReadAngleVector();
207 this.classname = ((this.cnt == 2) ? "target_viewlocation_end" : "target_viewlocation_start");
208 this.drawmask = MASK_NORMAL; // don't cull it