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)
30 f = bound(0, f, e.max_health);
31 if(f != e.health || e.pain_finished)
39 void WaypointSprite_UpdateMaxHealth(entity e, float f)
41 if(f != e.max_health || e.pain_finished)
49 void WaypointSprite_UpdateBuildFinished(entity e, float f)
51 if(f != e.pain_finished || e.max_health)
59 void WaypointSprite_UpdateOrigin(entity e, vector o)
68 void WaypointSprite_UpdateRule(entity e, float t, float r)
70 // no check, as this is never called without doing an actual change (usually only once)
76 void WaypointSprite_UpdateTeamRadar(entity e, float icon, vector col)
78 // no check, as this is never called without doing an actual change (usually only once)
79 e.cnt = (icon & 0x7F) | (e.cnt & 0x80);
84 .float waypointsprite_pingtime;
85 .float waypointsprite_helpmetime;
86 void WaypointSprite_Ping(entity e)
89 if(time < e.waypointsprite_pingtime)
91 e.waypointsprite_pingtime = time + 0.3;
92 // ALWAYS sends (this causes a radar circle), thus no check
97 float waypointsprite_limitedrange, waypointsprite_deployed_lifetime, waypointsprite_deadlifetime;
99 void WaypointSprite_HelpMePing(entity e)
101 WaypointSprite_Ping(e);
102 e.waypointsprite_helpmetime = time + waypointsprite_deployed_lifetime;
106 void WaypointSprite_FadeOutIn(entity e, float t)
111 e.teleport_time = time + t;
113 else if(t < (e.teleport_time - time))
115 // accelerate the waypoint's dying
117 // (e.teleport_time - time) / wp.fade_time stays
118 // e.teleport_time = time + fadetime
119 float current_fadetime;
120 current_fadetime = e.teleport_time - time;
121 e.teleport_time = time + t;
122 e.fade_time = e.fade_time * t / current_fadetime;
128 void WaypointSprite_Init()
130 waypointsprite_limitedrange = autocvar_sv_waypointsprite_limitedrange;
131 waypointsprite_deployed_lifetime = autocvar_sv_waypointsprite_deployed_lifetime;
132 waypointsprite_deadlifetime = autocvar_sv_waypointsprite_deadlifetime;
134 void WaypointSprite_InitClient(entity e)
138 void WaypointSprite_Kill(entity wp)
143 wp.owner.(wp.owned_by_field) = world;
147 void WaypointSprite_Disown(entity wp, float fadetime)
151 if(wp.classname != "sprite_waypoint")
153 backtrace("Trying to disown a non-waypointsprite");
158 if(wp.exteriormodeltoclient == wp.owner)
159 wp.exteriormodeltoclient = world;
160 wp.owner.(wp.owned_by_field) = world;
163 WaypointSprite_FadeOutIn(wp, fadetime);
167 void WaypointSprite_Think()
175 if(time >= self.teleport_time)
179 if(self.exteriormodeltoclient)
180 WaypointSprite_UpdateOrigin(self, self.exteriormodeltoclient.origin + self.view_ofs);
183 WaypointSprite_Kill(self);
185 self.nextthink = time; // WHY?!?
188 float WaypointSprite_visible_for_player(entity e)
190 // personal waypoints
196 if(self.rule == SPRITERULE_SPECTATOR)
198 if(e.classname == "player")
201 else if(self.team && self.rule == SPRITERULE_DEFAULT)
203 if(self.team != e.team)
205 if(e.classname != "player")
212 entity WaypointSprite_getviewentity(entity e)
214 if(e.classname == "spectator")
216 /* TODO idea (check this breaks nothing)
217 else if(e.classname == "observer")
223 float WaypointSprite_isteammate(entity e, entity e2)
227 if(e2.team != e.team)
238 float WaypointSprite_Customize()
240 // this is not in SendEntity because it shall run every frame, not just every update
242 // make spectators see what the player would see
244 e = WaypointSprite_getviewentity(other);
246 // as a GENERAL rule:
247 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
248 // but only apply this to real players, not to spectators
249 if(g_minstagib && (self.owner.flags & FL_CLIENT) && (self.owner.items & IT_STRENGTH) && (e == other))
251 if(!WaypointSprite_isteammate(self.owner, e))
255 return self.waypointsprite_visible_for_player(e);
258 float WaypointSprite_SendEntity(entity to, float sendflags)
262 WriteByte(MSG_ENTITY, ENT_CLIENT_WAYPOINT);
264 sendflags = sendflags & 0x7F;
268 else if(self.max_health || (self.pain_finished && (time < self.pain_finished + 0.25)))
271 WriteByte(MSG_ENTITY, sendflags);
277 WriteByte(MSG_ENTITY, (self.health / self.max_health) * 191.0);
281 dt = self.pain_finished - time;
282 dt = bound(0, dt * 32, 16383);
283 WriteByte(MSG_ENTITY, (dt & 0xFF00) / 256 + 192);
284 WriteByte(MSG_ENTITY, (dt & 0x00FF));
290 WriteCoord(MSG_ENTITY, self.origin_x);
291 WriteCoord(MSG_ENTITY, self.origin_y);
292 WriteCoord(MSG_ENTITY, self.origin_z);
297 WriteByte(MSG_ENTITY, self.team);
298 WriteByte(MSG_ENTITY, self.rule);
302 WriteString(MSG_ENTITY, self.model1);
305 WriteString(MSG_ENTITY, self.model2);
308 WriteString(MSG_ENTITY, self.model3);
312 WriteCoord(MSG_ENTITY, self.fade_time);
313 WriteCoord(MSG_ENTITY, self.teleport_time);
314 WriteShort(MSG_ENTITY, self.fade_rate); // maxdist
319 if(self.exteriormodeltoclient == to)
321 WriteByte(MSG_ENTITY, f);
326 WriteByte(MSG_ENTITY, self.cnt); // icon on radar
327 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
328 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
329 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
331 if(WaypointSprite_isteammate(self.owner, WaypointSprite_getviewentity(to)))
333 dt = (self.waypointsprite_helpmetime - time) / 0.1;
338 WriteByte(MSG_ENTITY, dt);
341 WriteByte(MSG_ENTITY, 0);
347 void WaypointSprite_Reset()
349 // if a WP wants to time out, let it time out immediately; other WPs ought to be reset/killed by their owners
351 if(self.fade_time) // there was there before: || g_keyhunt, do we really need this?
352 WaypointSprite_Kill(self);
355 entity WaypointSprite_Spawn(
356 string spr, // sprite
357 float lifetime, float maxdistance, // lifetime, max distance
358 entity ref, vector ofs, // position
359 entity showto, float t, // show to whom? Use a flag to indicate a team
360 entity own, .entity ownfield, // remove when own gets killed
361 float hideable, // true when it should be controlled by cl_hidewaypoints
362 float icon, vector rgb // initial icon and color
367 wp.classname = "sprite_waypoint";
368 wp.teleport_time = time + lifetime;
369 wp.fade_time = lifetime;
370 wp.exteriormodeltoclient = ref;
374 setorigin(wp, ref.origin + ofs);
381 wp.currentammo = hideable;
385 remove(own.ownfield);
387 wp.owned_by_field = ownfield;
389 wp.fade_rate = maxdistance;
390 wp.think = WaypointSprite_Think;
393 wp.customizeentityforclient = WaypointSprite_Customize;
394 wp.waypointsprite_visible_for_player = WaypointSprite_visible_for_player;
395 wp.reset2 = WaypointSprite_Reset;
398 Net_LinkEntity(wp, FALSE, 0, WaypointSprite_SendEntity);
402 entity WaypointSprite_SpawnFixed(
407 float icon, vector rgb // initial icon and color
410 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, own, ownfield, TRUE, icon, rgb);
413 .entity waypointsprite_deployed_fixed;
414 entity WaypointSprite_DeployFixed(
418 float icon, vector rgb // initial icon and color
421 float t, maxdistance;
427 maxdistance = waypointsprite_limitedrange;
430 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, world, ofs, world, t, self, waypointsprite_deployed_fixed, FALSE, icon, rgb);
433 .entity waypointsprite_deployed_personal;
434 entity WaypointSprite_DeployPersonal(
437 float icon, vector rgb // initial icon and color
440 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, self, waypointsprite_deployed_personal, FALSE, icon, rgb);
443 .entity waypointsprite_attached;
444 .entity waypointsprite_attachedforcarrier;
445 entity WaypointSprite_Attach(
448 float icon, vector rgb // initial icon and color
451 float t, maxdistance;
452 if(self.waypointsprite_attachedforcarrier)
453 return world; // can't attach to FC
459 maxdistance = waypointsprite_limitedrange;
462 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, self, '0 0 64', world, t, self, waypointsprite_attached, FALSE, icon, rgb);
465 entity WaypointSprite_AttachCarrier(
468 float icon, vector rgb // initial icon and color
472 WaypointSprite_Kill(carrier.waypointsprite_attached); // FC overrides attached
473 e = WaypointSprite_Spawn(spr, 0, 0, carrier, '0 0 64', world, carrier.team, carrier, waypointsprite_attachedforcarrier, FALSE, icon, rgb);
476 WaypointSprite_UpdateMaxHealth(e, '1 0 0' * healtharmor_maxdamage(start_health, start_armorvalue, autocvar_g_balance_armor_blockpercent) * 2);
477 WaypointSprite_UpdateHealth(e, '1 0 0' * healtharmor_maxdamage(carrier.health, carrier.armorvalue, autocvar_g_balance_armor_blockpercent));
482 void WaypointSprite_DetachCarrier(entity carrier)
484 WaypointSprite_Disown(carrier.waypointsprite_attachedforcarrier, waypointsprite_deadlifetime);
487 void WaypointSprite_ClearPersonal()
489 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
492 void WaypointSprite_ClearOwned()
494 WaypointSprite_Kill(self.waypointsprite_deployed_fixed);
495 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
496 WaypointSprite_Kill(self.waypointsprite_attached);
499 void WaypointSprite_PlayerDead()
501 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
502 WaypointSprite_DetachCarrier(self);
505 void WaypointSprite_PlayerGone()
507 WaypointSprite_Disown(self.waypointsprite_deployed_fixed, waypointsprite_deadlifetime);
508 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
509 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
510 WaypointSprite_DetachCarrier(self);