4 #include "../dpdefs/progsdefs.qc"
5 #include "../dpdefs/dpextensions.qc"
6 #include "../common/constants.qh"
7 #include "../common/util.qh"
8 #include "../common/buffs.qh"
9 #include "autocvars.qh"
10 #include "constants.qh"
12 #include "../common/deathtypes.qh"
13 #include "mutators/mutators_include.qh"
14 #include "../common/mapinfo.qh"
15 #include "miscfunctions.qh"
18 ..entity owned_by_field;
24 .float(entity) waypointsprite_visible_for_player;
26 void WaypointSprite_UpdateSprites(entity e, string m1, string m2, string m3)
45 void WaypointSprite_UpdateHealth(entity e, float f)
47 f = bound(0, f, e.max_health);
48 if(f != e.health || e.pain_finished)
56 void WaypointSprite_UpdateMaxHealth(entity e, float f)
58 if(f != e.max_health || e.pain_finished)
66 void WaypointSprite_UpdateBuildFinished(entity e, float f)
68 if(f != e.pain_finished || e.max_health)
76 void WaypointSprite_UpdateOrigin(entity e, vector o)
85 void WaypointSprite_UpdateRule(entity e, float t, float r)
87 // no check, as this is never called without doing an actual change (usually only once)
93 void WaypointSprite_UpdateTeamRadar(entity e, float icon, vector col)
95 // no check, as this is never called without doing an actual change (usually only once)
96 e.cnt = (icon & 0x7F) | (e.cnt & 0x80);
101 .float waypointsprite_pingtime;
102 .float waypointsprite_helpmetime;
103 void WaypointSprite_Ping(entity e)
106 if(time < e.waypointsprite_pingtime)
108 e.waypointsprite_pingtime = time + 0.3;
109 // ALWAYS sends (this causes a radar circle), thus no check
114 float waypointsprite_limitedrange, waypointsprite_deployed_lifetime, waypointsprite_deadlifetime;
116 void WaypointSprite_HelpMePing(entity e)
118 WaypointSprite_Ping(e);
119 e.waypointsprite_helpmetime = time + waypointsprite_deployed_lifetime;
123 void WaypointSprite_FadeOutIn(entity e, float t)
128 e.teleport_time = time + t;
130 else if(t < (e.teleport_time - time))
132 // accelerate the waypoint's dying
134 // (e.teleport_time - time) / wp.fade_time stays
135 // e.teleport_time = time + fadetime
136 float current_fadetime;
137 current_fadetime = e.teleport_time - time;
138 e.teleport_time = time + t;
139 e.fade_time = e.fade_time * t / current_fadetime;
145 void WaypointSprite_Init()
147 waypointsprite_limitedrange = autocvar_sv_waypointsprite_limitedrange;
148 waypointsprite_deployed_lifetime = autocvar_sv_waypointsprite_deployed_lifetime;
149 waypointsprite_deadlifetime = autocvar_sv_waypointsprite_deadlifetime;
151 void WaypointSprite_InitClient(entity e)
155 void WaypointSprite_Kill(entity wp)
160 wp.owner.(wp.owned_by_field) = world;
164 void WaypointSprite_Disown(entity wp, float fadetime)
168 if(wp.classname != "sprite_waypoint")
170 backtrace("Trying to disown a non-waypointsprite");
175 if(wp.exteriormodeltoclient == wp.owner)
176 wp.exteriormodeltoclient = world;
177 wp.owner.(wp.owned_by_field) = world;
180 WaypointSprite_FadeOutIn(wp, fadetime);
184 void WaypointSprite_Think()
192 if(time >= self.teleport_time)
196 if(self.exteriormodeltoclient)
197 WaypointSprite_UpdateOrigin(self, self.exteriormodeltoclient.origin + self.view_ofs);
200 WaypointSprite_Kill(self);
202 self.nextthink = time; // WHY?!?
205 float WaypointSprite_visible_for_player(entity e)
207 // personal waypoints
213 if(self.team && self.rule == SPRITERULE_DEFAULT)
215 if(self.team != e.team)
224 entity WaypointSprite_getviewentity(entity e)
228 /* TODO idea (check this breaks nothing)
229 else if(e.classname == "observer")
235 float WaypointSprite_isteammate(entity e, entity e2)
239 if(e2.team != e.team)
250 float WaypointSprite_Customize()
252 // this is not in SendEntity because it shall run every frame, not just every update
254 // make spectators see what the player would see
256 e = WaypointSprite_getviewentity(other);
258 if(MUTATOR_CALLHOOK(CustomizeWaypoint))
261 return self.waypointsprite_visible_for_player(e);
264 float WaypointSprite_SendEntity(entity to, float sendflags)
268 WriteByte(MSG_ENTITY, ENT_CLIENT_WAYPOINT);
270 sendflags = sendflags & 0x7F;
274 else if(self.max_health || (self.pain_finished && (time < self.pain_finished + 0.25)))
277 WriteByte(MSG_ENTITY, sendflags);
283 WriteByte(MSG_ENTITY, (self.health / self.max_health) * 191.0);
287 dt = self.pain_finished - time;
288 dt = bound(0, dt * 32, 16383);
289 WriteByte(MSG_ENTITY, (dt & 0xFF00) / 256 + 192);
290 WriteByte(MSG_ENTITY, (dt & 0x00FF));
296 WriteCoord(MSG_ENTITY, self.origin.x);
297 WriteCoord(MSG_ENTITY, self.origin.y);
298 WriteCoord(MSG_ENTITY, self.origin.z);
303 WriteByte(MSG_ENTITY, self.team);
304 WriteByte(MSG_ENTITY, self.rule);
308 WriteString(MSG_ENTITY, self.model1);
311 WriteString(MSG_ENTITY, self.model2);
314 WriteString(MSG_ENTITY, self.model3);
318 WriteCoord(MSG_ENTITY, self.fade_time);
319 WriteCoord(MSG_ENTITY, self.teleport_time);
320 WriteShort(MSG_ENTITY, self.fade_rate); // maxdist
325 if(self.exteriormodeltoclient == to)
327 WriteByte(MSG_ENTITY, f);
332 WriteByte(MSG_ENTITY, self.cnt); // icon on radar
333 WriteByte(MSG_ENTITY, self.colormod.x * 255.0);
334 WriteByte(MSG_ENTITY, self.colormod.y * 255.0);
335 WriteByte(MSG_ENTITY, self.colormod.z * 255.0);
337 if(WaypointSprite_isteammate(self.owner, WaypointSprite_getviewentity(to)))
339 dt = (self.waypointsprite_helpmetime - time) / 0.1;
344 WriteByte(MSG_ENTITY, dt);
347 WriteByte(MSG_ENTITY, 0);
353 void WaypointSprite_Reset()
355 // if a WP wants to time out, let it time out immediately; other WPs ought to be reset/killed by their owners
357 if(self.fade_time) // there was there before: || g_keyhunt, do we really need this?
358 WaypointSprite_Kill(self);
361 entity WaypointSprite_Spawn(
362 string spr, // sprite
363 float lifetime, float maxdistance, // lifetime, max distance
364 entity ref, vector ofs, // position
365 entity showto, float t, // show to whom? Use a flag to indicate a team
366 entity own, .entity ownfield, // remove when own gets killed
367 float hideable, // true when it should be controlled by cl_hidewaypoints
368 float icon, vector rgb // initial icon and color
373 wp.classname = "sprite_waypoint";
374 wp.teleport_time = time + lifetime;
375 wp.fade_time = lifetime;
376 wp.exteriormodeltoclient = ref;
380 setorigin(wp, ref.origin + ofs);
387 wp.currentammo = hideable;
391 remove(own.ownfield);
393 wp.owned_by_field = ownfield;
395 wp.fade_rate = maxdistance;
396 wp.think = WaypointSprite_Think;
399 wp.customizeentityforclient = WaypointSprite_Customize;
400 wp.waypointsprite_visible_for_player = WaypointSprite_visible_for_player;
401 wp.reset2 = WaypointSprite_Reset;
404 Net_LinkEntity(wp, false, 0, WaypointSprite_SendEntity);
408 entity WaypointSprite_SpawnFixed(
413 float icon, vector rgb // initial icon and color
416 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, own, ownfield, true, icon, rgb);
419 .entity waypointsprite_deployed_fixed;
420 entity WaypointSprite_DeployFixed(
424 float icon, vector rgb // initial icon and color
427 float t, maxdistance;
433 maxdistance = waypointsprite_limitedrange;
436 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, world, ofs, world, t, self, waypointsprite_deployed_fixed, false, icon, rgb);
439 .entity waypointsprite_deployed_personal;
440 entity WaypointSprite_DeployPersonal(
443 float icon, vector rgb // initial icon and color
446 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, self, waypointsprite_deployed_personal, false, icon, rgb);
449 .entity waypointsprite_attached;
450 .entity waypointsprite_attachedforcarrier;
451 entity WaypointSprite_Attach(
454 float icon, vector rgb // initial icon and color
457 float t, maxdistance;
458 if(self.waypointsprite_attachedforcarrier)
459 return world; // can't attach to FC
465 maxdistance = waypointsprite_limitedrange;
468 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, self, '0 0 64', world, t, self, waypointsprite_attached, false, icon, rgb);
471 entity WaypointSprite_AttachCarrier(
474 float icon, vector rgb // initial icon and color
478 WaypointSprite_Kill(carrier.waypointsprite_attached); // FC overrides attached
479 e = WaypointSprite_Spawn(spr, 0, 0, carrier, '0 0 64', world, carrier.team, carrier, waypointsprite_attachedforcarrier, false, icon, rgb);
482 WaypointSprite_UpdateMaxHealth(e, '1 0 0' * healtharmor_maxdamage(start_health, start_armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON) * 2);
483 WaypointSprite_UpdateHealth(e, '1 0 0' * healtharmor_maxdamage(carrier.health, carrier.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON));
488 void WaypointSprite_DetachCarrier(entity carrier)
490 WaypointSprite_Disown(carrier.waypointsprite_attachedforcarrier, waypointsprite_deadlifetime);
493 void WaypointSprite_ClearPersonal()
495 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
498 void WaypointSprite_ClearOwned()
500 WaypointSprite_Kill(self.waypointsprite_deployed_fixed);
501 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
502 WaypointSprite_Kill(self.waypointsprite_attached);
505 void WaypointSprite_PlayerDead()
507 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
508 WaypointSprite_DetachCarrier(self);
511 void WaypointSprite_PlayerGone()
513 WaypointSprite_Disown(self.waypointsprite_deployed_fixed, waypointsprite_deadlifetime);
514 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
515 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
516 WaypointSprite_DetachCarrier(self);