4 #include "../../../dpdefs/progsdefs.qh"
5 #include "../../../warpzonelib/util_server.qh"
6 #include "../../../server/defs.qh"
15 // set myself as current viewloc where possible
16 for(e = world; (e = findentity(e, viewloc, self)); )
19 for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain)
21 if(IS_PLAYER(e)) // should we support non-player entities with this?
22 //if(e.deadflag == DEAD_NO) // death view is handled separately, we can't override this just yet
24 vector emin = e.absmin;
25 vector emax = e.absmax;
26 if(self.solid == SOLID_BSP)
31 if(boxesoverlap(emin, emax, self.absmin, self.absmax)) // quick
32 if(WarpZoneLib_BoxTouchesBrush(emin, emax, self, e)) // accurate
36 self.nextthink = time;
39 bool trigger_viewloc_send(entity to, int sf)
41 // CSQC doesn't need to know our origin (yet), as we're only available for referencing
42 WriteByte(MSG_ENTITY, ENT_CLIENT_VIEWLOC_TRIGGER);
44 WriteEntity(MSG_ENTITY, self.enemy);
45 WriteEntity(MSG_ENTITY, self.goalentity);
47 WriteCoord(MSG_ENTITY, self.origin_x);
48 WriteCoord(MSG_ENTITY, self.origin_y);
49 WriteCoord(MSG_ENTITY, self.origin_z);
57 for(e = world; (e = find(e, targetname, self.target)); )
58 if(e.classname == "target_viewlocation_start")
63 for(e = world; (e = find(e, targetname, self.target2)); )
64 if(e.classname == "target_viewlocation_end")
70 if(!self.enemy) { print("^1FAIL!\n"); remove(self); return; }
73 self.goalentity = self.enemy; // make them match so CSQC knows what to do
75 Net_LinkEntity(self, false, 0, trigger_viewloc_send);
77 self.think = viewloc_think;
78 self.nextthink = time;
81 void spawnfunc_trigger_viewlocation()
83 // we won't check target2 here yet, as it may not even need to exist
84 if(self.target == "") { print("^1FAIL!\n"); remove(self); return; }
87 InitializeEntity(self, viewloc_init, INITPRIO_FINDTARGET);
90 bool viewloc_send(entity to, int sf)
92 WriteByte(MSG_ENTITY, ENT_CLIENT_VIEWLOC);
94 WriteByte(MSG_ENTITY, self.cnt);
96 WriteCoord(MSG_ENTITY, self.origin_x);
97 WriteCoord(MSG_ENTITY, self.origin_y);
98 WriteCoord(MSG_ENTITY, self.origin_z);
100 WriteCoord(MSG_ENTITY, self.angles_x);
101 WriteCoord(MSG_ENTITY, self.angles_y);
102 WriteCoord(MSG_ENTITY, self.angles_z);
111 self.angles_y = self.angle;
112 Net_LinkEntity(self, false, 0, viewloc_send);
115 void spawnfunc_target_viewlocation_start()
117 self.classname = "target_viewlocation_start";
121 void spawnfunc_target_viewlocation_end()
123 self.classname = "target_viewlocation_end";
129 void spawnfunc_target_viewlocation() { spawnfunc_target_viewlocation_start(); }
133 void trigger_viewloc_updatelink()
135 self.enemy = findfloat(world, entnum, self.cnt);
136 self.goalentity = findfloat(world, entnum, self.count);
139 void ent_viewloc_trigger()
141 float point1 = ReadShort();
142 float point2 = ReadShort();
144 self.enemy = findfloat(world, entnum, point1);
145 self.goalentity = findfloat(world, entnum, point2);
147 self.origin_x = ReadCoord();
148 self.origin_y = ReadCoord();
149 self.origin_z = ReadCoord();
150 setorigin(self, self.origin);
155 self.think = trigger_viewloc_updatelink;
156 self.nextthink = time + 1; // we need to delay this or else
158 self.classname = "trigger_viewlocation";
159 self.drawmask = MASK_NORMAL; // not so concerned, but better keep it alive
164 self.cnt = ReadByte();
166 self.origin_x = ReadCoord();
167 self.origin_y = ReadCoord();
168 self.origin_z = ReadCoord();
169 setorigin(self, self.origin);
171 self.movedir_x = ReadCoord();
172 self.movedir_y = ReadCoord();
173 self.movedir_z = ReadCoord();
175 self.classname = ((self.cnt == 2) ? "target_viewlocation_end" : "target_viewlocation_start");
176 self.drawmask = MASK_NORMAL; // don't cull it