1 #include "waypointsprites.qh"
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 void WaypointSprite_UpdateSprites(entity e, string m1, string m2, string m3)
37 void WaypointSprite_UpdateHealth(entity e, float f)
39 f = bound(0, f, e.max_health);
40 if(f != e.health || e.pain_finished)
48 void WaypointSprite_UpdateMaxHealth(entity e, float f)
50 if(f != e.max_health || e.pain_finished)
58 void WaypointSprite_UpdateBuildFinished(entity e, float f)
60 if(f != e.pain_finished || e.max_health)
68 void WaypointSprite_UpdateOrigin(entity e, vector o)
77 void WaypointSprite_UpdateRule(entity e, float t, float r)
79 // no check, as this is never called without doing an actual change (usually only once)
85 void WaypointSprite_UpdateTeamRadar(entity e, float icon, vector col)
87 // no check, as this is never called without doing an actual change (usually only once)
88 e.cnt = (icon & 0x7F) | (e.cnt & 0x80);
93 void WaypointSprite_Ping(entity e)
96 if(time < e.waypointsprite_pingtime)
98 e.waypointsprite_pingtime = time + 0.3;
99 // ALWAYS sends (this causes a radar circle), thus no check
104 void WaypointSprite_HelpMePing(entity e)
106 WaypointSprite_Ping(e);
107 e.waypointsprite_helpmetime = time + waypointsprite_deployed_lifetime;
111 void WaypointSprite_FadeOutIn(entity e, float t)
116 e.teleport_time = time + t;
118 else if(t < (e.teleport_time - time))
120 // accelerate the waypoint's dying
122 // (e.teleport_time - time) / wp.fade_time stays
123 // e.teleport_time = time + fadetime
124 float current_fadetime;
125 current_fadetime = e.teleport_time - time;
126 e.teleport_time = time + t;
127 e.fade_time = e.fade_time * t / current_fadetime;
133 void WaypointSprite_Init()
135 waypointsprite_limitedrange = autocvar_sv_waypointsprite_limitedrange;
136 waypointsprite_deployed_lifetime = autocvar_sv_waypointsprite_deployed_lifetime;
137 waypointsprite_deadlifetime = autocvar_sv_waypointsprite_deadlifetime;
140 void WaypointSprite_InitClient(entity e)
144 void WaypointSprite_Kill(entity wp)
149 wp.owner.(wp.owned_by_field) = world;
153 void WaypointSprite_Disown(entity wp, float fadetime)
157 if(wp.classname != "sprite_waypoint")
159 backtrace("Trying to disown a non-waypointsprite");
164 if(wp.exteriormodeltoclient == wp.owner)
165 wp.exteriormodeltoclient = world;
166 wp.owner.(wp.owned_by_field) = world;
169 WaypointSprite_FadeOutIn(wp, fadetime);
173 void WaypointSprite_Think()
181 if(time >= self.teleport_time)
185 if(self.exteriormodeltoclient)
186 WaypointSprite_UpdateOrigin(self, self.exteriormodeltoclient.origin + self.view_ofs);
189 WaypointSprite_Kill(self);
191 self.nextthink = time; // WHY?!?
194 float WaypointSprite_visible_for_player(entity e)
196 // personal waypoints
202 if(self.rule == SPRITERULE_SPECTATOR)
204 if(!autocvar_sv_itemstime)
206 if(!warmup_stage && e.classname == "player")
209 else if(self.team && self.rule == SPRITERULE_DEFAULT)
211 if(self.team != e.team)
220 entity WaypointSprite_getviewentity(entity e)
224 /* TODO idea (check this breaks nothing)
225 else if(e.classname == "observer")
231 float WaypointSprite_isteammate(entity e, entity e2)
235 if(e2.team != e.team)
246 float WaypointSprite_Customize()
248 // this is not in SendEntity because it shall run every frame, not just every update
250 // make spectators see what the player would see
252 e = WaypointSprite_getviewentity(other);
254 if(MUTATOR_CALLHOOK(CustomizeWaypoint))
257 return self.waypointsprite_visible_for_player(e);
260 float WaypointSprite_SendEntity(entity to, float sendflags)
264 WriteByte(MSG_ENTITY, ENT_CLIENT_WAYPOINT);
266 sendflags = sendflags & 0x7F;
270 else if(self.max_health || (self.pain_finished && (time < self.pain_finished + 0.25)))
273 WriteByte(MSG_ENTITY, sendflags);
279 WriteByte(MSG_ENTITY, (self.health / self.max_health) * 191.0);
283 dt = self.pain_finished - time;
284 dt = bound(0, dt * 32, 16383);
285 WriteByte(MSG_ENTITY, (dt & 0xFF00) / 256 + 192);
286 WriteByte(MSG_ENTITY, (dt & 0x00FF));
292 WriteCoord(MSG_ENTITY, self.origin.x);
293 WriteCoord(MSG_ENTITY, self.origin.y);
294 WriteCoord(MSG_ENTITY, self.origin.z);
299 WriteByte(MSG_ENTITY, self.team);
300 WriteByte(MSG_ENTITY, self.rule);
304 WriteString(MSG_ENTITY, self.model1);
307 WriteString(MSG_ENTITY, self.model2);
310 WriteString(MSG_ENTITY, self.model3);
314 WriteCoord(MSG_ENTITY, self.fade_time);
315 WriteCoord(MSG_ENTITY, self.teleport_time);
316 WriteShort(MSG_ENTITY, self.fade_rate); // maxdist
320 if(self.exteriormodeltoclient == to)
324 if(self.owner.classname == "onslaught_controlpoint")
326 entity wp_owner = self.owner;
327 entity e = WaypointSprite_getviewentity(to);
328 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { f |= 2; }
329 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { f |= 2; }
331 if(self.owner.classname == "onslaught_generator")
333 entity wp_owner = self.owner;
334 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { f |= 2; }
335 if(wp_owner.health <= 0) { f |= 2; }
338 WriteByte(MSG_ENTITY, f);
343 WriteByte(MSG_ENTITY, self.cnt); // icon on radar
344 WriteByte(MSG_ENTITY, self.colormod.x * 255.0);
345 WriteByte(MSG_ENTITY, self.colormod.y * 255.0);
346 WriteByte(MSG_ENTITY, self.colormod.z * 255.0);
348 if(WaypointSprite_isteammate(self.owner, WaypointSprite_getviewentity(to)))
350 dt = (self.waypointsprite_helpmetime - time) / 0.1;
355 WriteByte(MSG_ENTITY, dt);
358 WriteByte(MSG_ENTITY, 0);
364 void WaypointSprite_Reset()
366 // if a WP wants to time out, let it time out immediately; other WPs ought to be reset/killed by their owners
368 if(self.fade_time) // there was there before: || g_keyhunt, do we really need this?
369 WaypointSprite_Kill(self);
372 entity WaypointSprite_Spawn(
373 string spr, // sprite
374 float _lifetime, float maxdistance, // lifetime, max distance
375 entity ref, vector ofs, // position
376 entity showto, float t, // show to whom? Use a flag to indicate a team
377 entity own, .entity ownfield, // remove when own gets killed
378 float hideable, // true when it should be controlled by cl_hidewaypoints
379 float icon, vector rgb // initial icon and color
384 wp.classname = "sprite_waypoint";
385 wp.teleport_time = time + _lifetime;
386 wp.fade_time = _lifetime;
387 wp.exteriormodeltoclient = ref;
391 setorigin(wp, ref.origin + ofs);
398 wp.currentammo = hideable;
402 remove(own.(ownfield));
404 wp.owned_by_field = ownfield;
406 wp.fade_rate = maxdistance;
407 wp.think = WaypointSprite_Think;
410 wp.customizeentityforclient = WaypointSprite_Customize;
411 wp.waypointsprite_visible_for_player = WaypointSprite_visible_for_player;
412 wp.reset2 = WaypointSprite_Reset;
415 Net_LinkEntity(wp, false, 0, WaypointSprite_SendEntity);
419 entity WaypointSprite_SpawnFixed(
424 float icon, vector rgb // initial icon and color
427 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, own, ownfield, true, icon, rgb);
430 entity WaypointSprite_DeployFixed(
434 float icon, vector rgb // initial icon and color
437 float t, maxdistance;
443 maxdistance = waypointsprite_limitedrange;
446 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, world, ofs, world, t, self, waypointsprite_deployed_fixed, false, icon, rgb);
449 entity WaypointSprite_DeployPersonal(
452 float icon, vector rgb // initial icon and color
455 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, self, waypointsprite_deployed_personal, false, icon, rgb);
458 entity WaypointSprite_Attach(
461 float icon, vector rgb // initial icon and color
464 float t, maxdistance;
465 if(self.waypointsprite_attachedforcarrier)
466 return world; // can't attach to FC
472 maxdistance = waypointsprite_limitedrange;
475 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, self, '0 0 64', world, t, self, waypointsprite_attached, false, icon, rgb);
478 entity WaypointSprite_AttachCarrier(
481 float icon, vector rgb // initial icon and color
485 WaypointSprite_Kill(carrier.waypointsprite_attached); // FC overrides attached
486 e = WaypointSprite_Spawn(spr, 0, 0, carrier, '0 0 64', world, carrier.team, carrier, waypointsprite_attachedforcarrier, false, icon, rgb);
489 WaypointSprite_UpdateMaxHealth(e, '1 0 0' * healtharmor_maxdamage(start_health, start_armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON) * 2);
490 WaypointSprite_UpdateHealth(e, '1 0 0' * healtharmor_maxdamage(carrier.health, carrier.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON));
495 void WaypointSprite_DetachCarrier(entity carrier)
497 WaypointSprite_Disown(carrier.waypointsprite_attachedforcarrier, waypointsprite_deadlifetime);
500 void WaypointSprite_ClearPersonal()
502 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
505 void WaypointSprite_ClearOwned()
507 WaypointSprite_Kill(self.waypointsprite_deployed_fixed);
508 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
509 WaypointSprite_Kill(self.waypointsprite_attached);
512 void WaypointSprite_PlayerDead()
514 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
515 WaypointSprite_DetachCarrier(self);
518 void WaypointSprite_PlayerGone()
520 WaypointSprite_Disown(self.waypointsprite_deployed_fixed, waypointsprite_deadlifetime);
521 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
522 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
523 WaypointSprite_DetachCarrier(self);