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 void WaypointSprite_Ping(entity e)
88 if(time < e.waypointsprite_pingtime)
90 e.waypointsprite_pingtime = time + 0.3;
91 // ALWAYS sends (this causes a radar circle), thus no check
96 void WaypointSprite_FadeOutIn(entity e, float t)
101 e.teleport_time = time + t;
103 else if(t < (e.teleport_time - time))
105 // accelerate the waypoint's dying
107 // (e.teleport_time - time) / wp.fade_time stays
108 // e.teleport_time = time + fadetime
109 float current_fadetime;
110 current_fadetime = e.teleport_time - time;
111 e.teleport_time = time + t;
112 e.fade_time = e.fade_time * t / current_fadetime;
118 float waypointsprite_limitedrange, waypointsprite_deployed_lifetime, waypointsprite_deadlifetime;
119 void WaypointSprite_Init()
121 waypointsprite_limitedrange = autocvar_g_waypointsprite_limitedrange;
122 waypointsprite_deployed_lifetime = autocvar_g_waypointsprite_deployed_lifetime;
123 waypointsprite_deadlifetime = autocvar_g_waypointsprite_deadlifetime;
125 void WaypointSprite_InitClient(entity e)
129 void WaypointSprite_Kill(entity wp)
134 wp.owner.(wp.owned_by_field) = world;
138 void WaypointSprite_Disown(entity wp, float fadetime)
142 if(wp.classname != "sprite_waypoint")
144 backtrace("Trying to disown a non-waypointsprite");
149 if(wp.exteriormodeltoclient == wp.owner)
150 wp.exteriormodeltoclient = world;
151 wp.owner.(wp.owned_by_field) = world;
154 WaypointSprite_FadeOutIn(wp, fadetime);
158 void WaypointSprite_Think()
166 if(time >= self.teleport_time)
170 if(self.exteriormodeltoclient)
171 WaypointSprite_UpdateOrigin(self, self.exteriormodeltoclient.origin + self.view_ofs);
174 WaypointSprite_Kill(self);
176 self.nextthink = time; // WHY?!?
179 float WaypointSprite_visible_for_player(entity e)
181 // personal waypoints
183 if(self.enemy != other)
187 if(self.team && self.rule == SPRITERULE_DEFAULT)
189 if(self.team != other.team)
191 if(other.classname != "player")
198 float WaypointSprite_Customize()
200 // this is not in SendEntity because it shall run every frame, not just every update
202 // make spectators see what the player would see
205 if(e.classname == "spectator")
208 return self.waypointsprite_visible_for_player(e);
211 float WaypointSprite_SendEntity(entity to, float sendflags)
215 WriteByte(MSG_ENTITY, ENT_CLIENT_WAYPOINT);
217 sendflags = sendflags & 0x7F;
221 else if(self.max_health || (self.pain_finished && (time < self.pain_finished + 0.25)))
224 WriteByte(MSG_ENTITY, sendflags);
230 WriteByte(MSG_ENTITY, (self.health / self.max_health) * 191.0);
234 dt = self.pain_finished - time;
235 dt = bound(0, dt * 32, 16383);
236 WriteByte(MSG_ENTITY, (dt & 0xFF00) / 256 + 192);
237 WriteByte(MSG_ENTITY, (dt & 0x00FF));
243 WriteCoord(MSG_ENTITY, self.origin_x);
244 WriteCoord(MSG_ENTITY, self.origin_y);
245 WriteCoord(MSG_ENTITY, self.origin_z);
250 WriteByte(MSG_ENTITY, self.team);
251 WriteByte(MSG_ENTITY, self.rule);
255 WriteString(MSG_ENTITY, self.model1);
258 WriteString(MSG_ENTITY, self.model2);
261 WriteString(MSG_ENTITY, self.model3);
265 WriteCoord(MSG_ENTITY, self.fade_time);
266 WriteCoord(MSG_ENTITY, self.teleport_time);
267 WriteShort(MSG_ENTITY, self.fade_rate); // maxdist
272 if(self.exteriormodeltoclient == to)
274 WriteByte(MSG_ENTITY, f);
279 WriteByte(MSG_ENTITY, self.cnt); // icon on radar
280 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
281 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
282 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
288 void WaypointSprite_Reset()
290 // if a WP wants to time out, let it time out immediately; other WPs ought to be reset/killed by their owners
292 if(self.fade_time) // there was there before: || g_keyhunt, do we really need this?
293 WaypointSprite_Kill(self);
296 entity WaypointSprite_Spawn(
297 string spr, // sprite
298 float lifetime, float maxdistance, // lifetime, max distance
299 entity ref, vector ofs, // position
300 entity showto, float t, // show to whom? Use a flag to indicate a team
301 entity own, .entity ownfield, // remove when own gets killed
302 float hideable // true when it should be controlled by cl_hidewaypoints
307 wp.classname = "sprite_waypoint";
308 wp.teleport_time = time + lifetime;
309 wp.fade_time = lifetime;
310 wp.exteriormodeltoclient = ref;
314 setorigin(wp, ref.origin + ofs);
321 wp.currentammo = hideable;
325 remove(own.ownfield);
327 wp.owned_by_field = ownfield;
329 wp.fade_rate = maxdistance;
330 wp.think = WaypointSprite_Think;
333 wp.customizeentityforclient = WaypointSprite_Customize;
334 wp.waypointsprite_visible_for_player = WaypointSprite_visible_for_player;
335 wp.reset2 = WaypointSprite_Reset;
336 Net_LinkEntity(wp, FALSE, 0, WaypointSprite_SendEntity);
340 entity WaypointSprite_SpawnFixed(
347 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, own, ownfield, TRUE);
350 .entity waypointsprite_deployed_fixed;
351 entity WaypointSprite_DeployFixed(
357 float t, maxdistance;
363 maxdistance = waypointsprite_limitedrange;
366 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, world, ofs, world, t, self, waypointsprite_deployed_fixed, FALSE);
369 .entity waypointsprite_deployed_personal;
370 entity WaypointSprite_DeployPersonal(
375 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, self, waypointsprite_deployed_personal, FALSE);
378 .entity waypointsprite_attached;
379 .entity waypointsprite_attachedforcarrier;
380 entity WaypointSprite_Attach(
385 float t, maxdistance;
386 if(self.waypointsprite_attachedforcarrier)
387 return world; // can't attach to FC
393 maxdistance = waypointsprite_limitedrange;
396 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, self, '0 0 64', world, t, self, waypointsprite_attached, FALSE);
399 entity WaypointSprite_AttachCarrier(
405 WaypointSprite_Kill(carrier.waypointsprite_attached); // FC overrides attached
406 e = WaypointSprite_Spawn(spr, 0, 0, carrier, '0 0 64', world, carrier.team, carrier, waypointsprite_attachedforcarrier, FALSE);
409 WaypointSprite_UpdateMaxHealth(e, '1 0 0' * healtharmor_maxdamage(start_health, start_armorvalue, autocvar_g_balance_armor_blockpercent) * 2);
410 WaypointSprite_UpdateHealth(e, '1 0 0' * healtharmor_maxdamage(carrier.health, carrier.armorvalue, autocvar_g_balance_armor_blockpercent));
415 void WaypointSprite_DetachCarrier(entity carrier)
417 WaypointSprite_Disown(carrier.waypointsprite_attachedforcarrier, waypointsprite_deadlifetime);
420 void WaypointSprite_ClearPersonal()
422 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
425 void WaypointSprite_ClearOwned()
427 WaypointSprite_Kill(self.waypointsprite_deployed_fixed);
428 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
429 WaypointSprite_Kill(self.waypointsprite_attached);
432 void WaypointSprite_PlayerDead()
434 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
435 WaypointSprite_DetachCarrier(self);
438 void WaypointSprite_PlayerGone()
440 WaypointSprite_Disown(self.waypointsprite_deployed_fixed, waypointsprite_deadlifetime);
441 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
442 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
443 WaypointSprite_DetachCarrier(self);