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
135 d_x = view_right * (self.origin - view_origin) * vid_conwidth / vid_width;
136 d_y = -view_up * (self.origin - view_origin) * vid_conheight / (vid_height * vid_pixelheight);
139 //d = o - '0.5 0 0' * vid_conwidth - '0 0.5 0' * vid_conheight;
141 if(cvar("v_flipped"))
144 f1 = d_x / vid_conwidth;
145 f2 = d_y / vid_conheight;
147 if(max(f1, -f1) > max(f2, -f2))
178 o = d + '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
183 vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
185 t = stof(db_get(tempdb, strcat("/spriteframes/", spriteimage)));
187 spriteimage = strcat("models/sprites/", spriteimage);
189 spriteimage = strcat("models/sprites/", spriteimage, "_frame", ftos(mod(floor((max(0, time - self.spawntime)) * 2), t)));
191 drawrotpic(o, rot * 90 * DEG2RAD, spriteimage, SPRITE_SIZE * waypointsprite_scale * vidscale, SPRITE_HOTSPOT * waypointsprite_scale * vidscale, '1 1 1', a, DRAWFLAG_MIPMAP);
194 void Ent_RemoveWaypointSprite()
197 strunzone(self.netname);
199 strunzone(self.netname2);
201 strunzone(self.netname3);
204 void Ent_WaypointSprite()
207 sendflags = ReadByte();
210 self.spawntime = time;
212 self.draw2d = Draw_WaypointSprite;
214 InterpolateOrigin_Undo();
218 // unfortunately, this needs to be exact (for the 3D display)
219 self.origin_x = ReadCoord();
220 self.origin_y = ReadCoord();
221 self.origin_z = ReadCoord();
226 self.team = ReadByte();
227 self.rule = ReadByte();
233 strunzone(self.netname);
234 self.netname = strzone(ReadString());
240 strunzone(self.netname2);
241 self.netname2 = strzone(ReadString());
247 strunzone(self.netname3);
248 self.netname3 = strzone(ReadString());
253 self.lifetime = ReadCoord();
254 self.fadetime = ReadCoord();
255 self.maxdistance = ReadShort();
256 self.hideflags = ReadByte();
262 self.teamradar_icon = (f & 0x7F);
265 self.(teamradar_times[self.teamradar_time_index]) = time;
266 self.teamradar_time_index = mod(self.teamradar_time_index + 1, MAX_TEAMRADAR_TIMES);
268 self.teamradar_color_x = ReadByte() / 255.0;
269 self.teamradar_color_y = ReadByte() / 255.0;
270 self.teamradar_color_z = ReadByte() / 255.0;
273 InterpolateOrigin_Note();
275 self.entremove = Ent_RemoveWaypointSprite;
278 void WaypointSprite_Load()
280 waypointsprite_fadedistance = vlen(world.maxs - world.mins);
281 waypointsprite_normdistance = cvar("g_waypointsprite_normdistance");
282 waypointsprite_minscale = cvar("g_waypointsprite_minscale");
283 waypointsprite_minalpha = cvar("g_waypointsprite_minalpha");
284 waypointsprite_distancealphaexponent = cvar("g_waypointsprite_distancealphaexponent");
285 waypointsprite_timealphaexponent = cvar("g_waypointsprite_timealphaexponent");
286 waypointsprite_scale = cvar("g_waypointsprite_scale");
287 if(!waypointsprite_scale)
288 waypointsprite_scale = 1.0;
290 if(!waypointsprite_initialized)
292 float dh, n, i, o, f;
293 string s, sname, sframes;
294 dh = search_begin("models/sprites/*_frame*.tga", FALSE, FALSE);
295 n = search_getsize(dh);
296 for(i = 0; i < n; ++i)
298 s = search_getfilename(dh, i);
299 if(substring(s, 0, 15) != "models/sprites/")
301 if(substring(s, strlen(s) - 4, 4) != ".tga")
303 s = substring(s, 15, strlen(s) - 19);
305 o = strstrofs(s, "_frame", 0);
306 sname = strcat("/spriteframes/", substring(s, 0, o));
307 sframes = substring(s, o + 6, strlen(s) - o - 6);
308 f = stof(sframes) + 1;
309 db_put(tempdb, sname, ftos(max(f, stof(db_get(tempdb, sname)))));
313 waypointsprite_initialized = 1;