5 #include <lib/warpzone/util_server.qh>
6 #include <server/defs.qh>
9 REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC)
10 REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC_TRIGGER)
14 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
21 for(e = NULL; (e = findentity(e, viewloc, this)); )
24 for(e = findradius((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1); e; e = e.chain)
26 if(IS_PLAYER(e)) // should we support non-player entities with this?
27 //if(!IS_DEAD(e)) // death view is handled separately, we can't override this just yet
29 vector emin = e.absmin;
30 vector emax = e.absmax;
31 if(this.solid == SOLID_BSP)
36 if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
37 if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, e)) // accurate
41 this.nextthink = time;
44 bool trigger_viewloc_send(entity this, entity to, int sf)
46 // CSQC doesn't need to know our origin (yet), as we're only available for referencing
47 WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC_TRIGGER);
49 WriteEntity(MSG_ENTITY, this.enemy);
50 WriteEntity(MSG_ENTITY, this.goalentity);
52 WriteCoord(MSG_ENTITY, this.origin_x);
53 WriteCoord(MSG_ENTITY, this.origin_y);
54 WriteCoord(MSG_ENTITY, this.origin_z);
59 void viewloc_init(entity this)
62 for(e = NULL; (e = find(e, targetname, this.target)); )
63 if(e.classname == "target_viewlocation_start")
68 for(e = NULL; (e = find(e, targetname, this.target2)); )
69 if(e.classname == "target_viewlocation_end")
75 if(!this.enemy) { LOG_INFO("^1FAIL!"); delete(this); return; }
78 this.goalentity = this.enemy; // make them match so CSQC knows what to do
80 Net_LinkEntity(this, false, 0, trigger_viewloc_send);
82 setthink(this, viewloc_think);
83 this.nextthink = time;
86 spawnfunc(trigger_viewlocation)
88 // we won't check target2 here yet, as it may not even need to exist
89 if(this.target == "") { LOG_INFO("^1FAIL!"); delete(this); return; }
92 InitializeEntity(this, viewloc_init, INITPRIO_FINDTARGET);
95 bool viewloc_send(entity this, entity to, int sf)
97 WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC);
99 WriteByte(MSG_ENTITY, this.cnt);
101 WriteCoord(MSG_ENTITY, this.origin_x);
102 WriteCoord(MSG_ENTITY, this.origin_y);
103 WriteCoord(MSG_ENTITY, this.origin_z);
105 WriteAngle(MSG_ENTITY, this.angles_x);
106 WriteAngle(MSG_ENTITY, this.angles_y);
107 WriteAngle(MSG_ENTITY, this.angles_z);
113 void viewloc_link(entity this)
116 this.angles_y = this.angle;
117 Net_LinkEntity(this, false, 0, viewloc_send);
120 spawnfunc(target_viewlocation_start)
122 this.classname = "target_viewlocation_start";
126 spawnfunc(target_viewlocation_end)
128 this.classname = "target_viewlocation_end";
134 spawnfunc(target_viewlocation) { spawnfunc_target_viewlocation_start(this); }
138 void trigger_viewloc_updatelink(entity this)
140 this.enemy = findfloat(NULL, entnum, this.cnt);
141 this.goalentity = findfloat(NULL, entnum, this.count);
144 NET_HANDLE(ENT_CLIENT_VIEWLOC_TRIGGER, bool isnew)
146 float point1 = ReadShort();
147 float point2 = ReadShort();
149 this.enemy = findfloat(NULL, entnum, point1);
150 this.goalentity = findfloat(NULL, entnum, point2);
152 this.origin_x = ReadCoord();
153 this.origin_y = ReadCoord();
154 this.origin_z = ReadCoord();
158 setorigin(this, this.origin);
163 setthink(this, trigger_viewloc_updatelink);
164 this.nextthink = time + 1; // we need to delay this or else
166 this.classname = "trigger_viewlocation";
167 this.drawmask = MASK_NORMAL; // not so concerned, but better keep it alive
170 NET_HANDLE(ENT_CLIENT_VIEWLOC, bool isnew)
172 this.cnt = ReadByte();
174 this.origin_x = ReadCoord();
175 this.origin_y = ReadCoord();
176 this.origin_z = ReadCoord();
177 setorigin(this, this.origin);
179 this.movedir_x = ReadAngle();
180 this.movedir_y = ReadAngle();
181 this.movedir_z = ReadAngle();
185 this.classname = ((this.cnt == 2) ? "target_viewlocation_end" : "target_viewlocation_start");
186 this.drawmask = MASK_NORMAL; // don't cull it