1 float waypointsprite_initialized;
2 float waypointsprite_fadedistance;
3 float waypointsprite_normdistance;
4 float waypointsprite_minscale;
5 float waypointsprite_minalpha;
6 float waypointsprite_distancealphaexponent;
7 float waypointsprite_timealphaexponent;
8 float waypointsprite_scale;
11 .string netname; // primary picture
12 .string netname2; // secondary picture
13 .string netname3; // tertiary picture
14 .float team; // team that gets netname2
21 vector SPRITE_SIZE = '128 32 0';
22 vector SPRITE_HOTSPOT = '64 32 0';
24 void drawrotpic(vector org, float rot, string pic, vector sz, vector hotspot, vector rgb, float a, float f)
26 vector v1, v2, v3, v4;
28 hotspot = -1 * hotspot;
30 // hotspot-relative coordinates of the corners
32 v2 = hotspot + '1 0 0' * sz_x;
33 v3 = hotspot + '1 0 0' * sz_x + '0 1 0' * sz_y;
34 v4 = hotspot + '0 1 0' * sz_y;
36 // rotate them, and make them absolute
37 rot = -rot; // rotate by the opposite angle, as our coordinate system is reversed
38 v1 = rotate(v1, rot) + org;
39 v2 = rotate(v2, rot) + org;
40 v3 = rotate(v3, rot) + org;
41 v4 = rotate(v4, rot) + org;
44 R_BeginPolygon(pic, f);
45 R_PolygonVertex(v1, '0 0 0', rgb, a);
46 R_PolygonVertex(v2, '1 0 0', rgb, a);
47 R_PolygonVertex(v3, '1 1 0', rgb, a);
48 R_PolygonVertex(v4, '0 1 0', rgb, a);
52 void Draw_WaypointSprite()
58 self.alpha = pow(bound(0, (self.fadetime - time) / self.lifetime, 1), waypointsprite_timealphaexponent);
62 if(self.hideflags & 2)
65 if(cvar("cl_hidewaypoints") >= 2)
68 if(self.hideflags & 1)
69 if(cvar("cl_hidewaypoints"))
70 return; // fixed waypoint
72 InterpolateOrigin_Do();
74 t = GetPlayerColor(player_localentnum - 1) + 1;
81 case SPRITERULE_DEFAULT:
85 spriteimage = self.netname;
90 spriteimage = self.netname;
92 case SPRITERULE_TEAMPLAY:
93 if(t == COLOR_SPECTATOR + 1)
94 spriteimage = self.netname3;
95 else if(self.team == t)
96 spriteimage = self.netname2;
98 spriteimage = self.netname;
101 error("Invalid waypointsprite rule!");
105 if(spriteimage == "")
109 dist = vlen(self.origin - view_origin);
114 if(self.maxdistance > waypointsprite_normdistance)
115 a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
116 else if(self.maxdistance > 0)
117 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
122 // draw the sprite image
125 o = project_3d_to_2d(self.origin);
128 if(o_z < 0 || o_x < 0 || o_y < 0 || o_x > vid_conwidth || o_y > vid_conheight)
130 // scale it to be just in view
134 // get the waypoint angle vector
136 d_x = view_right * (self.origin - view_origin) * vid_conwidth / vid_width;
137 d_y = -view_up * (self.origin - view_origin) * vid_conheight / (vid_height * vid_pixelheight);
141 d = o - '0.5 0 0' * vid_conwidth - '0 0.5 0' * vid_conheight;
143 if(cvar("v_flipped"))
146 f1 = d_x / vid_conwidth;
147 f2 = d_y / vid_conheight;
149 if(max(f1, -f1) > max(f2, -f2))
180 o = d + '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
185 vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
187 t = stof(db_get(tempdb, strcat("/spriteframes/", spriteimage)));
189 spriteimage = strcat("models/sprites/", spriteimage);
191 spriteimage = strcat("models/sprites/", spriteimage, "_frame", ftos(mod(floor((max(0, time - self.spawntime)) * 2), t)));
193 drawrotpic(o, rot * 90 * DEG2RAD, spriteimage, SPRITE_SIZE * waypointsprite_scale * vidscale, SPRITE_HOTSPOT * waypointsprite_scale * vidscale, '1 1 1', a, DRAWFLAG_MIPMAP);
196 void Ent_RemoveWaypointSprite()
199 strunzone(self.netname);
201 strunzone(self.netname2);
203 strunzone(self.netname3);
206 void Ent_WaypointSprite()
209 sendflags = ReadByte();
212 self.spawntime = time;
214 self.draw2d = Draw_WaypointSprite;
216 InterpolateOrigin_Undo();
220 // unfortunately, this needs to be exact (for the 3D display)
221 self.origin_x = ReadCoord();
222 self.origin_y = ReadCoord();
223 self.origin_z = ReadCoord();
228 self.team = ReadByte();
229 self.rule = ReadByte();
235 strunzone(self.netname);
236 self.netname = strzone(ReadString());
242 strunzone(self.netname2);
243 self.netname2 = strzone(ReadString());
249 strunzone(self.netname3);
250 self.netname3 = strzone(ReadString());
255 self.lifetime = ReadCoord();
256 self.fadetime = ReadCoord();
257 self.maxdistance = ReadShort();
258 self.hideflags = ReadByte();
264 self.teamradar_icon = (f & 0x7F);
267 self.(teamradar_times[self.teamradar_time_index]) = time;
268 self.teamradar_time_index = mod(self.teamradar_time_index + 1, MAX_TEAMRADAR_TIMES);
270 self.teamradar_color_x = ReadByte() / 255.0;
271 self.teamradar_color_y = ReadByte() / 255.0;
272 self.teamradar_color_z = ReadByte() / 255.0;
275 InterpolateOrigin_Note();
277 self.entremove = Ent_RemoveWaypointSprite;
280 void WaypointSprite_Load()
282 waypointsprite_fadedistance = vlen(world.maxs - world.mins);
283 waypointsprite_normdistance = cvar("g_waypointsprite_normdistance");
284 waypointsprite_minscale = cvar("g_waypointsprite_minscale");
285 waypointsprite_minalpha = cvar("g_waypointsprite_minalpha");
286 waypointsprite_distancealphaexponent = cvar("g_waypointsprite_distancealphaexponent");
287 waypointsprite_timealphaexponent = cvar("g_waypointsprite_timealphaexponent");
288 waypointsprite_scale = cvar("g_waypointsprite_scale");
289 if(!waypointsprite_scale)
290 waypointsprite_scale = 1.0;
292 if(!waypointsprite_initialized)
294 float dh, n, i, o, f;
295 string s, sname, sframes;
296 dh = search_begin("models/sprites/*_frame*.tga", FALSE, FALSE);
297 n = search_getsize(dh);
298 for(i = 0; i < n; ++i)
300 s = search_getfilename(dh, i);
301 if(substring(s, 0, 15) != "models/sprites/")
303 if(substring(s, strlen(s) - 4, 4) != ".tga")
305 s = substring(s, 15, strlen(s) - 19);
307 o = strstrofs(s, "_frame", 0);
308 sname = strcat("/spriteframes/", substring(s, 0, o));
309 sframes = substring(s, o + 6, strlen(s) - o - 6);
310 f = stof(sframes) + 1;
311 db_put(tempdb, sname, ftos(max(f, stof(db_get(tempdb, sname)))));
315 waypointsprite_initialized = 1;