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
20 vector SPRITE_SIZE = '128 32 0';
21 vector SPRITE_HOTSPOT = '64 32 0';
23 void drawrotpic(vector org, float rot, string pic, vector sz, vector hotspot, vector rgb, float a, float f)
25 vector v1, v2, v3, v4;
27 hotspot = -1 * hotspot;
29 // hotspot-relative coordinates of the corners
31 v2 = hotspot + '1 0 0' * sz_x;
32 v3 = hotspot + '1 0 0' * sz_x + '0 1 0' * sz_y;
33 v4 = hotspot + '0 1 0' * sz_y;
35 // rotate them, and make them absolute
36 rot = -rot; // rotate by the opposite angle, as our coordinate system is reversed
37 v1 = rotate(v1, rot) + org;
38 v2 = rotate(v2, rot) + org;
39 v3 = rotate(v3, rot) + org;
40 v4 = rotate(v4, rot) + org;
43 R_BeginPolygon(pic, f);
44 R_PolygonVertex(v1, '0 0 0', rgb, a);
45 R_PolygonVertex(v2, '1 0 0', rgb, a);
46 R_PolygonVertex(v3, '1 1 0', rgb, a);
47 R_PolygonVertex(v4, '0 1 0', rgb, a);
51 void Draw_WaypointSprite()
57 self.alpha = pow(bound(0, (self.fadetime - time) / self.lifetime, 1), waypointsprite_timealphaexponent);
61 if(self.hideflags & 2)
64 if(cvar("cl_hidewaypoints") >= 2)
67 if(self.hideflags & 1)
68 if(cvar("cl_hidewaypoints"))
69 return; // fixed waypoint
71 InterpolateOrigin_Do();
73 t = GetPlayerColor(player_localentnum - 1) + 1;
80 case SPRITERULE_DEFAULT:
84 spriteimage = self.netname;
89 spriteimage = self.netname;
91 case SPRITERULE_TEAMPLAY:
92 if(t == COLOR_SPECTATOR + 1)
93 spriteimage = self.netname3;
94 else if(self.team == t)
95 spriteimage = self.netname2;
97 spriteimage = self.netname;
100 error("Invalid waypointsprite rule!");
104 if(spriteimage == "")
108 dist = vlen(self.origin - view_origin);
113 if(self.maxdistance > waypointsprite_normdistance)
114 a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
115 else if(self.maxdistance > 0)
116 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
121 // draw the sprite image
124 o = project_3d_to_2d(self.origin);
127 if(o_z < 0 || o_x < 0 || o_y < 0 || o_x > vid_conwidth || o_y > vid_conheight)
129 // scale it to be just in view
133 // get the waypoint angle vector
134 d_x = view_right * (self.origin - view_origin) * vid_conwidth / vid_width;
135 d_y = -view_up * (self.origin - view_origin) * vid_conheight / (vid_height * vid_pixelheight);
138 //d = o - '0.5 0 0' * vid_conwidth - '0 0.5 0' * vid_conheight;
140 f1 = d_x / vid_conwidth;
141 f2 = d_y / vid_conheight;
143 if(max(f1, -f1) > max(f2, -f2))
174 o = d + '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
179 vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
181 t = stof(db_get(tempdb, strcat("/spriteframes/", spriteimage)));
183 spriteimage = strcat("models/sprites/", spriteimage);
185 spriteimage = strcat("models/sprites/", spriteimage, "_frame", ftos(mod(floor(time * 2), t)));
187 drawrotpic(o, rot * 90 * DEG2RAD, spriteimage, SPRITE_SIZE * waypointsprite_scale * vidscale, SPRITE_HOTSPOT * waypointsprite_scale * vidscale, '1 1 1', a, DRAWFLAG_MIPMAP);
190 void Ent_RemoveWaypointSprite()
193 strunzone(self.netname);
195 strunzone(self.netname2);
197 strunzone(self.netname3);
200 void Ent_WaypointSprite()
203 sendflags = ReadByte();
205 self.draw2d = Draw_WaypointSprite;
207 InterpolateOrigin_Undo();
211 // unfortunately, this needs to be exact (for the 3D display)
212 self.origin_x = ReadCoord();
213 self.origin_y = ReadCoord();
214 self.origin_z = ReadCoord();
219 self.team = ReadByte();
220 self.rule = ReadByte();
226 strunzone(self.netname);
227 self.netname = strzone(ReadString());
233 strunzone(self.netname2);
234 self.netname2 = strzone(ReadString());
240 strunzone(self.netname3);
241 self.netname3 = strzone(ReadString());
246 self.lifetime = ReadCoord();
247 self.fadetime = ReadCoord();
248 self.maxdistance = ReadShort();
249 self.hideflags = ReadByte();
255 self.teamradar_icon = (f & 0x7F);
258 self.(teamradar_times[self.teamradar_time_index]) = time;
259 self.teamradar_time_index = mod(self.teamradar_time_index + 1, MAX_TEAMRADAR_TIMES);
261 self.teamradar_color_x = ReadByte() / 255.0;
262 self.teamradar_color_y = ReadByte() / 255.0;
263 self.teamradar_color_z = ReadByte() / 255.0;
266 InterpolateOrigin_Note();
268 self.entremove = Ent_RemoveWaypointSprite;
271 void WaypointSprite_Load()
273 waypointsprite_fadedistance = vlen(world.maxs - world.mins);
274 waypointsprite_normdistance = cvar("g_waypointsprite_normdistance");
275 waypointsprite_minscale = cvar("g_waypointsprite_minscale");
276 waypointsprite_minalpha = cvar("g_waypointsprite_minalpha");
277 waypointsprite_distancealphaexponent = cvar("g_waypointsprite_distancealphaexponent");
278 waypointsprite_timealphaexponent = cvar("g_waypointsprite_timealphaexponent");
279 waypointsprite_scale = cvar("g_waypointsprite_scale");
280 if(!waypointsprite_scale)
281 waypointsprite_scale = 1.0;
283 if(!waypointsprite_initialized)
285 float dh, n, i, o, f;
286 string s, sname, sframes;
287 dh = search_begin("models/sprites/*_frame*.tga", FALSE, FALSE);
288 n = search_getsize(dh);
289 for(i = 0; i < n; ++i)
291 s = search_getfilename(dh, i);
292 if(substring(s, 0, 15) != "models/sprites/")
294 if(substring(s, strlen(s) - 4, 4) != ".tga")
296 s = substring(s, 15, strlen(s) - 19);
298 o = strstrofs(s, "_frame", 0);
299 sname = strcat("/spriteframes/", substring(s, 0, o));
300 sframes = substring(s, o + 6, strlen(s) - o - 6);
301 f = stof(sframes) + 1;
302 db_put(tempdb, sname, ftos(max(f, stof(db_get(tempdb, sname)))));
306 waypointsprite_initialized = 1;