1 ..entity owned_by_field;
7 .float(entity) waypointsprite_visible_for_player;
9 void WaypointSprite_UpdateSprites(entity e, string m1, string m2, string m3)
28 void WaypointSprite_UpdateHealth(entity e, float f)
37 void WaypointSprite_UpdateMaxHealth(entity e, float f)
46 void WaypointSprite_UpdateOrigin(entity e, vector o)
55 void WaypointSprite_UpdateRule(entity e, float t, float r)
57 // no check, as this is never called without doing an actual change (usually only once)
63 void WaypointSprite_UpdateTeamRadar(entity e, float icon, vector col)
65 // no check, as this is never called without doing an actual change (usually only once)
66 e.cnt = (icon & 0x7F) | (e.cnt & 0x80);
71 void WaypointSprite_Ping(entity e)
73 // ALWAYS sends (this causes a radar circle), thus no check
78 void WaypointSprite_FadeOutIn(entity e, float t)
83 e.teleport_time = time + t;
85 else if(t < (e.teleport_time - time))
87 // accelerate the waypoint's dying
89 // (e.teleport_time - time) / wp.fade_time stays
90 // e.teleport_time = time + fadetime
91 float current_fadetime;
92 current_fadetime = e.teleport_time - time;
93 e.teleport_time = time + t;
94 e.fade_time = e.fade_time * t / current_fadetime;
100 float waypointsprite_limitedrange, waypointsprite_deployed_lifetime, waypointsprite_deadlifetime;
101 void WaypointSprite_Init()
103 waypointsprite_limitedrange = cvar("g_waypointsprite_limitedrange");
104 waypointsprite_deployed_lifetime = cvar("g_waypointsprite_deployed_lifetime");
105 waypointsprite_deadlifetime = cvar("g_waypointsprite_deadlifetime");
107 void WaypointSprite_InitClient(entity e)
111 void WaypointSprite_Kill(entity wp)
116 wp.owner.(wp.owned_by_field) = world;
120 void WaypointSprite_Disown(entity wp, float fadetime)
124 if(wp.classname != "sprite_waypoint")
126 backtrace("Trying to disown a non-waypointsprite");
131 if(wp.exteriormodeltoclient == wp.owner)
132 wp.exteriormodeltoclient = world;
133 wp.owner.(wp.owned_by_field) = world;
136 WaypointSprite_FadeOutIn(wp, fadetime);
140 void WaypointSprite_Think()
148 if(time >= self.teleport_time)
152 if(self.exteriormodeltoclient)
153 WaypointSprite_UpdateOrigin(self, self.exteriormodeltoclient.origin + self.view_ofs);
156 WaypointSprite_Kill(self);
158 self.nextthink = time; // WHY?!?
161 float WaypointSprite_visible_for_player(entity e)
163 // personal waypoints
165 if(self.enemy != other)
169 if(self.team && self.rule == SPRITERULE_DEFAULT)
171 if(self.team != other.team)
173 if(other.classname != "player")
180 float WaypointSprite_Customize()
182 // this is not in SendEntity because it shall run every frame, not just every update
184 // make spectators see what the player would see
187 if(e.classname == "spectator")
190 return self.waypointsprite_visible_for_player(e);
193 float WaypointSprite_SendEntity(entity to, float sendflags)
195 WriteByte(MSG_ENTITY, ENT_CLIENT_WAYPOINT);
197 sendflags = sendflags & 0x7F;
202 WriteByte(MSG_ENTITY, sendflags);
205 WriteByte(MSG_ENTITY, (self.health / self.max_health) * 255.0);
209 WriteCoord(MSG_ENTITY, self.origin_x);
210 WriteCoord(MSG_ENTITY, self.origin_y);
211 WriteCoord(MSG_ENTITY, self.origin_z);
216 WriteByte(MSG_ENTITY, self.team);
217 WriteByte(MSG_ENTITY, self.rule);
221 WriteString(MSG_ENTITY, self.model1);
224 WriteString(MSG_ENTITY, self.model2);
227 WriteString(MSG_ENTITY, self.model3);
231 WriteCoord(MSG_ENTITY, self.fade_time);
232 WriteCoord(MSG_ENTITY, self.teleport_time);
233 WriteShort(MSG_ENTITY, self.fade_rate); // maxdist
238 if(self.exteriormodeltoclient == to)
240 WriteByte(MSG_ENTITY, f);
245 WriteByte(MSG_ENTITY, self.cnt); // icon on radar
246 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
247 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
248 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
254 void WaypointSprite_Reset()
256 // if a WP wants to time out, let it time out immediately; other WPs ought to be reset/killed by their owners
258 if(self.fade_time) // there was there before: || g_keyhunt, do we really need this?
259 WaypointSprite_Kill(self);
262 entity WaypointSprite_Spawn(
263 string spr, // sprite
264 float lifetime, float maxdistance, // lifetime, max distance
265 entity ref, vector ofs, // position
266 entity showto, float t, // show to whom? Use a flag to indicate a team
267 entity own, .entity ownfield, // remove when own gets killed
268 float hideable // true when it should be controlled by cl_hidewaypoints
273 wp.classname = "sprite_waypoint";
274 wp.teleport_time = time + lifetime;
275 wp.fade_time = lifetime;
276 wp.exteriormodeltoclient = ref;
280 setorigin(wp, ref.origin + ofs);
287 wp.currentammo = hideable;
291 remove(own.ownfield);
293 wp.owned_by_field = ownfield;
295 wp.fade_rate = maxdistance;
296 wp.think = WaypointSprite_Think;
299 wp.customizeentityforclient = WaypointSprite_Customize;
300 wp.waypointsprite_visible_for_player = WaypointSprite_visible_for_player;
301 wp.reset2 = WaypointSprite_Reset;
302 Net_LinkEntity(wp, FALSE, 0, WaypointSprite_SendEntity);
306 entity WaypointSprite_SpawnFixed(
313 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, own, ownfield, TRUE);
316 .entity waypointsprite_deployed_fixed;
317 entity WaypointSprite_DeployFixed(
323 float t, maxdistance;
329 maxdistance = waypointsprite_limitedrange;
332 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, world, ofs, world, t, self, waypointsprite_deployed_fixed, FALSE);
335 .entity waypointsprite_deployed_personal;
336 entity WaypointSprite_DeployPersonal(
341 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, self, waypointsprite_deployed_personal, FALSE);
344 .entity waypointsprite_attached;
345 .entity waypointsprite_attachedforcarrier;
346 entity WaypointSprite_Attach(
351 float t, maxdistance;
352 if(self.waypointsprite_attachedforcarrier)
353 return world; // can't attach to FC
359 maxdistance = waypointsprite_limitedrange;
362 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, self, '0 0 64', world, t, self, waypointsprite_attached, FALSE);
365 entity WaypointSprite_AttachCarrier(
370 WaypointSprite_Kill(carrier.waypointsprite_attached); // FC overrides attached
371 return WaypointSprite_Spawn(spr, 0, 0, carrier, '0 0 64', world, carrier.team, carrier, waypointsprite_attachedforcarrier, FALSE);
374 void WaypointSprite_DetachCarrier(entity carrier)
376 WaypointSprite_Disown(carrier.waypointsprite_attachedforcarrier, waypointsprite_deadlifetime);
379 void WaypointSprite_ClearPersonal()
381 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
384 void WaypointSprite_ClearOwned()
386 WaypointSprite_Kill(self.waypointsprite_deployed_fixed);
387 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
388 WaypointSprite_Kill(self.waypointsprite_attached);
391 void WaypointSprite_PlayerDead()
393 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
394 WaypointSprite_DetachCarrier(self);
397 void WaypointSprite_PlayerGone()
399 WaypointSprite_Disown(self.waypointsprite_deployed_fixed, waypointsprite_deadlifetime);
400 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
401 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
402 WaypointSprite_DetachCarrier(self);