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_UpdateOrigin(entity e, vector o)
37 void WaypointSprite_UpdateRule(entity e, float t, float r)
39 // no check, as this is never called without doing an actual change (usually only once)
45 void WaypointSprite_UpdateTeamRadar(entity e, float icon, vector col)
47 // no check, as this is never called without doing an actual change (usually only once)
48 e.cnt = (icon & 0x7F) | (e.cnt & 0x80);
53 void WaypointSprite_Ping(entity e)
55 // ALWAYS sends (this causes a radar circle), thus no check
60 void WaypointSprite_FadeOutIn(entity e, float t)
65 e.teleport_time = time + t;
67 else if(t < (e.teleport_time - time))
69 // accelerate the waypoint's dying
71 // (e.teleport_time - time) / wp.health stays
72 // e.teleport_time = time + fadetime
73 float current_fadetime;
74 current_fadetime = e.teleport_time - time;
75 e.teleport_time = time + t;
76 e.health = e.health * t / current_fadetime;
82 float waypointsprite_limitedrange, waypointsprite_deployed_lifetime, waypointsprite_deadlifetime;
83 void WaypointSprite_Init()
85 waypointsprite_limitedrange = cvar("g_waypointsprite_limitedrange");
86 waypointsprite_deployed_lifetime = cvar("g_waypointsprite_deployed_lifetime");
87 waypointsprite_deadlifetime = cvar("g_waypointsprite_deadlifetime");
89 void WaypointSprite_InitClient(entity e)
93 void WaypointSprite_Kill(entity wp)
98 wp.owner.(wp.owned_by_field) = world;
102 void WaypointSprite_Disown(entity wp, float fadetime)
106 if(wp.classname != "sprite_waypoint")
108 backtrace("Trying to disown a non-waypointsprite");
113 if(wp.exteriormodeltoclient == wp.owner)
114 wp.exteriormodeltoclient = world;
115 wp.owner.(wp.owned_by_field) = world;
118 WaypointSprite_FadeOutIn(wp, fadetime);
122 void WaypointSprite_Think()
130 if(time >= self.teleport_time)
134 if(self.exteriormodeltoclient)
135 WaypointSprite_UpdateOrigin(self, self.exteriormodeltoclient.origin + self.view_ofs);
138 WaypointSprite_Kill(self);
140 self.nextthink = time; // WHY?!?
143 float WaypointSprite_visible_for_player(entity e)
145 // personal waypoints
147 if(self.enemy != other)
151 if(self.team && self.rule == SPRITERULE_DEFAULT)
153 if(self.team != other.team)
155 if(other.classname != "player")
162 float WaypointSprite_Customize()
164 // this is not in SendEntity because it shall run every frame, not just every update
166 // make spectators see what the player would see
169 if(e.classname == "spectator")
172 return self.waypointsprite_visible_for_player(e);
175 float WaypointSprite_SendEntity(entity to, float sendflags)
177 WriteByte(MSG_ENTITY, ENT_CLIENT_WAYPOINT);
178 WriteByte(MSG_ENTITY, sendflags);
182 WriteCoord(MSG_ENTITY, self.origin_x);
183 WriteCoord(MSG_ENTITY, self.origin_y);
184 WriteCoord(MSG_ENTITY, self.origin_z);
189 WriteByte(MSG_ENTITY, self.team);
190 WriteByte(MSG_ENTITY, self.rule);
194 WriteString(MSG_ENTITY, self.model1);
197 WriteString(MSG_ENTITY, self.model2);
200 WriteString(MSG_ENTITY, self.model3);
204 WriteCoord(MSG_ENTITY, self.health);
205 WriteCoord(MSG_ENTITY, self.teleport_time);
206 WriteShort(MSG_ENTITY, self.max_health); // maxdist
211 if(self.exteriormodeltoclient == to)
213 WriteByte(MSG_ENTITY, f);
218 WriteByte(MSG_ENTITY, self.cnt); // icon on radar
219 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
220 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
221 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
227 void WaypointSprite_Reset()
229 // if a WP wants to time out, let it time out immediately; other WPs ought to be reset/killed by their owners
231 if(self.health) // there was there before: || g_keyhunt, do we really need this?
232 WaypointSprite_Kill(self);
235 entity WaypointSprite_Spawn(
236 string spr, // sprite
237 float lifetime, float maxdistance, // lifetime, max distance
238 entity ref, vector ofs, // position
239 entity showto, float t, // show to whom? Use a flag to indicate a team
240 entity own, .entity ownfield, // remove when own gets killed
241 float hideable // true when it should be controlled by cl_hidewaypoints
246 wp.classname = "sprite_waypoint";
247 wp.teleport_time = time + lifetime;
248 wp.health = lifetime;
249 wp.exteriormodeltoclient = ref;
253 setorigin(wp, ref.origin + ofs);
260 wp.currentammo = hideable;
264 remove(own.ownfield);
266 wp.owned_by_field = ownfield;
268 wp.max_health = maxdistance;
269 wp.think = WaypointSprite_Think;
272 wp.customizeentityforclient = WaypointSprite_Customize;
273 wp.waypointsprite_visible_for_player = WaypointSprite_visible_for_player;
274 wp.reset2 = WaypointSprite_Reset;
275 Net_LinkEntity(wp, FALSE, 0, WaypointSprite_SendEntity);
279 entity WaypointSprite_SpawnFixed(
286 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, own, ownfield, TRUE);
289 .entity waypointsprite_deployed_fixed;
290 entity WaypointSprite_DeployFixed(
296 float t, maxdistance;
302 maxdistance = waypointsprite_limitedrange;
305 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, world, ofs, world, t, self, waypointsprite_deployed_fixed, FALSE);
308 .entity waypointsprite_deployed_personal;
309 entity WaypointSprite_DeployPersonal(
314 return WaypointSprite_Spawn(spr, 0, 0, world, ofs, world, 0, self, waypointsprite_deployed_personal, FALSE);
317 .entity waypointsprite_attached;
318 .entity waypointsprite_attachedforcarrier;
319 entity WaypointSprite_Attach(
324 float t, maxdistance;
325 if(self.waypointsprite_attachedforcarrier)
326 return world; // can't attach to FC
332 maxdistance = waypointsprite_limitedrange;
335 return WaypointSprite_Spawn(spr, waypointsprite_deployed_lifetime, maxdistance, self, '0 0 64', world, t, self, waypointsprite_attached, FALSE);
338 entity WaypointSprite_AttachCarrier(
343 WaypointSprite_Kill(carrier.waypointsprite_attached); // FC overrides attached
344 return WaypointSprite_Spawn(spr, 0, 0, carrier, '0 0 64', world, carrier.team, carrier, waypointsprite_attachedforcarrier, FALSE);
347 void WaypointSprite_DetachCarrier(entity carrier)
349 WaypointSprite_Disown(carrier.waypointsprite_attachedforcarrier, waypointsprite_deadlifetime);
352 void WaypointSprite_ClearPersonal()
354 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
357 void WaypointSprite_ClearOwned()
359 WaypointSprite_Kill(self.waypointsprite_deployed_fixed);
360 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
361 WaypointSprite_Kill(self.waypointsprite_attached);
364 void WaypointSprite_PlayerDead()
366 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
367 WaypointSprite_DetachCarrier(self);
370 void WaypointSprite_PlayerGone()
372 WaypointSprite_Disown(self.waypointsprite_deployed_fixed, waypointsprite_deadlifetime);
373 WaypointSprite_Kill(self.waypointsprite_deployed_personal);
374 WaypointSprite_Disown(self.waypointsprite_attached, waypointsprite_deadlifetime);
375 WaypointSprite_DetachCarrier(self);