sbar.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // sbar.c -- status bar code
  16. #include "quakedef.h"
  17. int sb_updates; // if >= vid.numpages, no update needed
  18. #define STAT_MINUS 10 // num frame for '-' stats digit
  19. qpic_t *sb_nums[2][11];
  20. qpic_t *sb_colon, *sb_slash;
  21. qpic_t *sb_ibar;
  22. qpic_t *sb_sbar;
  23. qpic_t *sb_scorebar;
  24. qpic_t *sb_weapons[7][8]; // 0 is active, 1 is owned, 2-5 are flashes
  25. qpic_t *sb_ammo[4];
  26. qpic_t *sb_sigil[4];
  27. qpic_t *sb_armor[3];
  28. qpic_t *sb_items[32];
  29. qpic_t *sb_faces[7][2]; // 0 is gibbed, 1 is dead, 2-6 are alive
  30. // 0 is static, 1 is temporary animation
  31. qpic_t *sb_face_invis;
  32. qpic_t *sb_face_quad;
  33. qpic_t *sb_face_invuln;
  34. qpic_t *sb_face_invis_invuln;
  35. qboolean sb_showscores;
  36. qboolean sb_showteamscores;
  37. int sb_lines; // scan lines to draw
  38. void Sbar_DeathmatchOverlay (int start);
  39. void Sbar_TeamOverlay (void);
  40. void Sbar_MiniDeathmatchOverlay (void);
  41. static qboolean largegame = false;
  42. /*
  43. ===============
  44. Sbar_ShowTeamScores
  45. Tab key down
  46. ===============
  47. */
  48. void Sbar_ShowTeamScores (void)
  49. {
  50. if (sb_showteamscores)
  51. return;
  52. sb_showteamscores = true;
  53. sb_updates = 0;
  54. }
  55. /*
  56. ===============
  57. Sbar_DontShowTeamScores
  58. Tab key up
  59. ===============
  60. */
  61. void Sbar_DontShowTeamScores (void)
  62. {
  63. sb_showteamscores = false;
  64. sb_updates = 0;
  65. }
  66. /*
  67. ===============
  68. Sbar_ShowScores
  69. Tab key down
  70. ===============
  71. */
  72. void Sbar_ShowScores (void)
  73. {
  74. if (sb_showscores)
  75. return;
  76. sb_showscores = true;
  77. sb_updates = 0;
  78. }
  79. /*
  80. ===============
  81. Sbar_DontShowScores
  82. Tab key up
  83. ===============
  84. */
  85. void Sbar_DontShowScores (void)
  86. {
  87. sb_showscores = false;
  88. sb_updates = 0;
  89. }
  90. /*
  91. ===============
  92. Sbar_Changed
  93. ===============
  94. */
  95. void Sbar_Changed (void)
  96. {
  97. sb_updates = 0; // update next frame
  98. }
  99. /*
  100. ===============
  101. Sbar_Init
  102. ===============
  103. */
  104. void Sbar_Init (void)
  105. {
  106. int i;
  107. for (i=0 ; i<10 ; i++)
  108. {
  109. sb_nums[0][i] = Draw_PicFromWad (va("num_%i",i));
  110. sb_nums[1][i] = Draw_PicFromWad (va("anum_%i",i));
  111. }
  112. sb_nums[0][10] = Draw_PicFromWad ("num_minus");
  113. sb_nums[1][10] = Draw_PicFromWad ("anum_minus");
  114. sb_colon = Draw_PicFromWad ("num_colon");
  115. sb_slash = Draw_PicFromWad ("num_slash");
  116. sb_weapons[0][0] = Draw_PicFromWad ("inv_shotgun");
  117. sb_weapons[0][1] = Draw_PicFromWad ("inv_sshotgun");
  118. sb_weapons[0][2] = Draw_PicFromWad ("inv_nailgun");
  119. sb_weapons[0][3] = Draw_PicFromWad ("inv_snailgun");
  120. sb_weapons[0][4] = Draw_PicFromWad ("inv_rlaunch");
  121. sb_weapons[0][5] = Draw_PicFromWad ("inv_srlaunch");
  122. sb_weapons[0][6] = Draw_PicFromWad ("inv_lightng");
  123. sb_weapons[1][0] = Draw_PicFromWad ("inv2_shotgun");
  124. sb_weapons[1][1] = Draw_PicFromWad ("inv2_sshotgun");
  125. sb_weapons[1][2] = Draw_PicFromWad ("inv2_nailgun");
  126. sb_weapons[1][3] = Draw_PicFromWad ("inv2_snailgun");
  127. sb_weapons[1][4] = Draw_PicFromWad ("inv2_rlaunch");
  128. sb_weapons[1][5] = Draw_PicFromWad ("inv2_srlaunch");
  129. sb_weapons[1][6] = Draw_PicFromWad ("inv2_lightng");
  130. for (i=0 ; i<5 ; i++)
  131. {
  132. sb_weapons[2+i][0] = Draw_PicFromWad (va("inva%i_shotgun",i+1));
  133. sb_weapons[2+i][1] = Draw_PicFromWad (va("inva%i_sshotgun",i+1));
  134. sb_weapons[2+i][2] = Draw_PicFromWad (va("inva%i_nailgun",i+1));
  135. sb_weapons[2+i][3] = Draw_PicFromWad (va("inva%i_snailgun",i+1));
  136. sb_weapons[2+i][4] = Draw_PicFromWad (va("inva%i_rlaunch",i+1));
  137. sb_weapons[2+i][5] = Draw_PicFromWad (va("inva%i_srlaunch",i+1));
  138. sb_weapons[2+i][6] = Draw_PicFromWad (va("inva%i_lightng",i+1));
  139. }
  140. sb_ammo[0] = Draw_PicFromWad ("sb_shells");
  141. sb_ammo[1] = Draw_PicFromWad ("sb_nails");
  142. sb_ammo[2] = Draw_PicFromWad ("sb_rocket");
  143. sb_ammo[3] = Draw_PicFromWad ("sb_cells");
  144. sb_armor[0] = Draw_PicFromWad ("sb_armor1");
  145. sb_armor[1] = Draw_PicFromWad ("sb_armor2");
  146. sb_armor[2] = Draw_PicFromWad ("sb_armor3");
  147. sb_items[0] = Draw_PicFromWad ("sb_key1");
  148. sb_items[1] = Draw_PicFromWad ("sb_key2");
  149. sb_items[2] = Draw_PicFromWad ("sb_invis");
  150. sb_items[3] = Draw_PicFromWad ("sb_invuln");
  151. sb_items[4] = Draw_PicFromWad ("sb_suit");
  152. sb_items[5] = Draw_PicFromWad ("sb_quad");
  153. sb_sigil[0] = Draw_PicFromWad ("sb_sigil1");
  154. sb_sigil[1] = Draw_PicFromWad ("sb_sigil2");
  155. sb_sigil[2] = Draw_PicFromWad ("sb_sigil3");
  156. sb_sigil[3] = Draw_PicFromWad ("sb_sigil4");
  157. sb_faces[4][0] = Draw_PicFromWad ("face1");
  158. sb_faces[4][1] = Draw_PicFromWad ("face_p1");
  159. sb_faces[3][0] = Draw_PicFromWad ("face2");
  160. sb_faces[3][1] = Draw_PicFromWad ("face_p2");
  161. sb_faces[2][0] = Draw_PicFromWad ("face3");
  162. sb_faces[2][1] = Draw_PicFromWad ("face_p3");
  163. sb_faces[1][0] = Draw_PicFromWad ("face4");
  164. sb_faces[1][1] = Draw_PicFromWad ("face_p4");
  165. sb_faces[0][0] = Draw_PicFromWad ("face5");
  166. sb_faces[0][1] = Draw_PicFromWad ("face_p5");
  167. sb_face_invis = Draw_PicFromWad ("face_invis");
  168. sb_face_invuln = Draw_PicFromWad ("face_invul2");
  169. sb_face_invis_invuln = Draw_PicFromWad ("face_inv2");
  170. sb_face_quad = Draw_PicFromWad ("face_quad");
  171. Cmd_AddCommand ("+showscores", Sbar_ShowScores);
  172. Cmd_AddCommand ("-showscores", Sbar_DontShowScores);
  173. Cmd_AddCommand ("+showteamscores", Sbar_ShowTeamScores);
  174. Cmd_AddCommand ("-showteamscores", Sbar_DontShowTeamScores);
  175. sb_sbar = Draw_PicFromWad ("sbar");
  176. sb_ibar = Draw_PicFromWad ("ibar");
  177. sb_scorebar = Draw_PicFromWad ("scorebar");
  178. }
  179. //=============================================================================
  180. // drawing routines are reletive to the status bar location
  181. /*
  182. =============
  183. Sbar_DrawPic
  184. =============
  185. */
  186. void Sbar_DrawPic (int x, int y, qpic_t *pic)
  187. {
  188. Draw_Pic (x /* + ((vid.width - 320)>>1) */, y + (vid.height-SBAR_HEIGHT), pic);
  189. }
  190. /*
  191. =============
  192. Sbar_DrawSubPic
  193. =============
  194. JACK: Draws a portion of the picture in the status bar.
  195. */
  196. void Sbar_DrawSubPic(int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height)
  197. {
  198. Draw_SubPic (x, y+(vid.height-SBAR_HEIGHT), pic, srcx, srcy, width, height);
  199. }
  200. /*
  201. =============
  202. Sbar_DrawTransPic
  203. =============
  204. */
  205. void Sbar_DrawTransPic (int x, int y, qpic_t *pic)
  206. {
  207. Draw_TransPic (x /*+ ((vid.width - 320)>>1) */, y + (vid.height-SBAR_HEIGHT), pic);
  208. }
  209. /*
  210. ================
  211. Sbar_DrawCharacter
  212. Draws one solid graphics character
  213. ================
  214. */
  215. void Sbar_DrawCharacter (int x, int y, int num)
  216. {
  217. Draw_Character ( x /*+ ((vid.width - 320)>>1) */ + 4, y + vid.height-SBAR_HEIGHT, num);
  218. }
  219. /*
  220. ================
  221. Sbar_DrawString
  222. ================
  223. */
  224. void Sbar_DrawString (int x, int y, char *str)
  225. {
  226. Draw_String (x /*+ ((vid.width - 320)>>1) */, y+ vid.height-SBAR_HEIGHT, str);
  227. }
  228. /*
  229. =============
  230. Sbar_itoa
  231. =============
  232. */
  233. int Sbar_itoa (int num, char *buf)
  234. {
  235. char *str;
  236. int pow10;
  237. int dig;
  238. str = buf;
  239. if (num < 0)
  240. {
  241. *str++ = '-';
  242. num = -num;
  243. }
  244. for (pow10 = 10 ; num >= pow10 ; pow10 *= 10)
  245. ;
  246. do
  247. {
  248. pow10 /= 10;
  249. dig = num/pow10;
  250. *str++ = '0'+dig;
  251. num -= dig*pow10;
  252. } while (pow10 != 1);
  253. *str = 0;
  254. return str-buf;
  255. }
  256. /*
  257. =============
  258. Sbar_DrawNum
  259. =============
  260. */
  261. void Sbar_DrawNum (int x, int y, int num, int digits, int color)
  262. {
  263. char str[12];
  264. char *ptr;
  265. int l, frame;
  266. l = Sbar_itoa (num, str);
  267. ptr = str;
  268. if (l > digits)
  269. ptr += (l-digits);
  270. if (l < digits)
  271. x += (digits-l)*24;
  272. while (*ptr)
  273. {
  274. if (*ptr == '-')
  275. frame = STAT_MINUS;
  276. else
  277. frame = *ptr -'0';
  278. Sbar_DrawTransPic (x,y,sb_nums[color][frame]);
  279. x += 24;
  280. ptr++;
  281. }
  282. }
  283. //=============================================================================
  284. //ZOID: this should be MAX_CLIENTS, not MAX_SCOREBOARD!!
  285. //int fragsort[MAX_SCOREBOARD];
  286. int fragsort[MAX_CLIENTS];
  287. int scoreboardlines;
  288. typedef struct {
  289. char team[16+1];
  290. int frags;
  291. int players;
  292. int plow, phigh, ptotal;
  293. } team_t;
  294. team_t teams[MAX_CLIENTS];
  295. int teamsort[MAX_CLIENTS];
  296. int scoreboardteams;
  297. /*
  298. ===============
  299. Sbar_SortFrags
  300. ===============
  301. */
  302. void Sbar_SortFrags (qboolean includespec)
  303. {
  304. int i, j, k;
  305. // sort by frags
  306. scoreboardlines = 0;
  307. for (i=0 ; i<MAX_CLIENTS ; i++)
  308. {
  309. if (cl.players[i].name[0] &&
  310. (!cl.players[i].spectator || includespec))
  311. {
  312. fragsort[scoreboardlines] = i;
  313. scoreboardlines++;
  314. if (cl.players[i].spectator)
  315. cl.players[i].frags = -999;
  316. }
  317. }
  318. for (i=0 ; i<scoreboardlines ; i++)
  319. for (j=0 ; j<scoreboardlines-1-i ; j++)
  320. if (cl.players[fragsort[j]].frags < cl.players[fragsort[j+1]].frags)
  321. {
  322. k = fragsort[j];
  323. fragsort[j] = fragsort[j+1];
  324. fragsort[j+1] = k;
  325. }
  326. }
  327. void Sbar_SortTeams (void)
  328. {
  329. int i, j, k;
  330. player_info_t *s;
  331. int teamplay;
  332. char t[16+1];
  333. // request new ping times every two second
  334. scoreboardteams = 0;
  335. teamplay = atoi(Info_ValueForKey(cl.serverinfo, "teamplay"));
  336. if (!teamplay)
  337. return;
  338. // sort the teams
  339. memset(teams, 0, sizeof(teams));
  340. for (i = 0; i < MAX_CLIENTS; i++)
  341. teams[i].plow = 999;
  342. for (i = 0; i < MAX_CLIENTS; i++) {
  343. s = &cl.players[i];
  344. if (!s->name[0])
  345. continue;
  346. if (s->spectator)
  347. continue;
  348. // find his team in the list
  349. t[16] = 0;
  350. strncpy(t, Info_ValueForKey(s->userinfo, "team"), 16);
  351. if (!t || !t[0])
  352. continue; // not on team
  353. for (j = 0; j < scoreboardteams; j++)
  354. if (!strcmp(teams[j].team, t)) {
  355. teams[j].frags += s->frags;
  356. teams[j].players++;
  357. goto addpinginfo;
  358. }
  359. if (j == scoreboardteams) { // must add him
  360. j = scoreboardteams++;
  361. strcpy(teams[j].team, t);
  362. teams[j].frags = s->frags;
  363. teams[j].players = 1;
  364. addpinginfo:
  365. if (teams[j].plow > s->ping)
  366. teams[j].plow = s->ping;
  367. if (teams[j].phigh < s->ping)
  368. teams[j].phigh = s->ping;
  369. teams[j].ptotal += s->ping;
  370. }
  371. }
  372. // sort
  373. for (i = 0; i < scoreboardteams; i++)
  374. teamsort[i] = i;
  375. // good 'ol bubble sort
  376. for (i = 0; i < scoreboardteams - 1; i++)
  377. for (j = i + 1; j < scoreboardteams; j++)
  378. if (teams[teamsort[i]].frags < teams[teamsort[j]].frags) {
  379. k = teamsort[i];
  380. teamsort[i] = teamsort[j];
  381. teamsort[j] = k;
  382. }
  383. }
  384. int Sbar_ColorForMap (int m)
  385. {
  386. m = (m < 0) ? 0 : ((m > 13) ? 13 : m);
  387. m *= 16;
  388. return m < 128 ? m + 8 : m + 8;
  389. }
  390. /*
  391. ===============
  392. Sbar_SoloScoreboard
  393. ===============
  394. */
  395. void Sbar_SoloScoreboard (void)
  396. {
  397. char str[80];
  398. int minutes, seconds, tens, units;
  399. Sbar_DrawPic (0, 0, sb_scorebar);
  400. // time
  401. minutes = cl.time / 60;
  402. seconds = cl.time - 60*minutes;
  403. tens = seconds / 10;
  404. units = seconds - 10*tens;
  405. sprintf (str,"Time :%3i:%i%i", minutes, tens, units);
  406. Sbar_DrawString (184, 4, str);
  407. }
  408. //=============================================================================
  409. /*
  410. ===============
  411. Sbar_DrawInventory
  412. ===============
  413. */
  414. void Sbar_DrawInventory (void)
  415. {
  416. int i;
  417. char num[6];
  418. float time;
  419. int flashon;
  420. qboolean headsup;
  421. qboolean hudswap;
  422. headsup = !(cl_sbar.value || scr_viewsize.value<100);
  423. hudswap = cl_hudswap.value; // Get that nasty float out :)
  424. if (!headsup)
  425. Sbar_DrawPic (0, -24, sb_ibar);
  426. // weapons
  427. for (i=0 ; i<7 ; i++)
  428. {
  429. if (cl.stats[STAT_ITEMS] & (IT_SHOTGUN<<i) )
  430. {
  431. time = cl.item_gettime[i];
  432. flashon = (int)((cl.time - time)*10);
  433. if (flashon < 0)
  434. flashon = 0;
  435. if (flashon >= 10)
  436. {
  437. if ( cl.stats[STAT_ACTIVEWEAPON] == (IT_SHOTGUN<<i) )
  438. flashon = 1;
  439. else
  440. flashon = 0;
  441. }
  442. else
  443. flashon = (flashon%5) + 2;
  444. if (headsup) {
  445. if (i || vid.height>200)
  446. Sbar_DrawSubPic ((hudswap) ? 0 : (vid.width-24),-68-(7-i)*16 , sb_weapons[flashon][i],0,0,24,16);
  447. } else
  448. Sbar_DrawPic (i*24, -16, sb_weapons[flashon][i]);
  449. // Sbar_DrawSubPic (0,0,20,20,i*24, -16, sb_weapons[flashon][i]);
  450. if (flashon > 1)
  451. sb_updates = 0; // force update to remove flash
  452. }
  453. }
  454. // ammo counts
  455. for (i=0 ; i<4 ; i++)
  456. {
  457. sprintf (num, "%3i",cl.stats[STAT_SHELLS+i] );
  458. if (headsup) {
  459. // Sbar_DrawSubPic(3, -24, sb_ibar, 3, 0, 42,11);
  460. Sbar_DrawSubPic((hudswap) ? 0 : (vid.width-42), -24 - (4-i)*11, sb_ibar, 3+(i*48), 0, 42, 11);
  461. if (num[0] != ' ')
  462. Sbar_DrawCharacter ( (hudswap) ? 3 : (vid.width-39), -24 - (4-i)*11, 18 + num[0] - '0');
  463. if (num[1] != ' ')
  464. Sbar_DrawCharacter ( (hudswap) ? 11 : (vid.width-31), -24 - (4-i)*11, 18 + num[1] - '0');
  465. if (num[2] != ' ')
  466. Sbar_DrawCharacter ( (hudswap) ? 19 : (vid.width-23), -24 - (4-i)*11, 18 + num[2] - '0');
  467. } else {
  468. if (num[0] != ' ')
  469. Sbar_DrawCharacter ( (6*i+1)*8 - 2, -24, 18 + num[0] - '0');
  470. if (num[1] != ' ')
  471. Sbar_DrawCharacter ( (6*i+2)*8 - 2, -24, 18 + num[1] - '0');
  472. if (num[2] != ' ')
  473. Sbar_DrawCharacter ( (6*i+3)*8 - 2, -24, 18 + num[2] - '0');
  474. }
  475. }
  476. flashon = 0;
  477. // items
  478. for (i=0 ; i<6 ; i++)
  479. if (cl.stats[STAT_ITEMS] & (1<<(17+i)))
  480. {
  481. time = cl.item_gettime[17+i];
  482. if (time && time > cl.time - 2 && flashon )
  483. { // flash frame
  484. sb_updates = 0;
  485. }
  486. else
  487. Sbar_DrawPic (192 + i*16, -16, sb_items[i]);
  488. if (time && time > cl.time - 2)
  489. sb_updates = 0;
  490. }
  491. // sigils
  492. for (i=0 ; i<4 ; i++)
  493. if (cl.stats[STAT_ITEMS] & (1<<(28+i)))
  494. {
  495. time = cl.item_gettime[28+i];
  496. if (time && time > cl.time - 2 && flashon )
  497. { // flash frame
  498. sb_updates = 0;
  499. }
  500. else
  501. Sbar_DrawPic (320-32 + i*8, -16, sb_sigil[i]);
  502. if (time && time > cl.time - 2)
  503. sb_updates = 0;
  504. }
  505. }
  506. //=============================================================================
  507. /*
  508. ===============
  509. Sbar_DrawFrags
  510. ===============
  511. */
  512. void Sbar_DrawFrags (void)
  513. {
  514. int i, k, l;
  515. int top, bottom;
  516. int x, y, f;
  517. char num[12];
  518. player_info_t *s;
  519. Sbar_SortFrags (false);
  520. // draw the text
  521. l = scoreboardlines <= 4 ? scoreboardlines : 4;
  522. x = 23;
  523. // xofs = (vid.width - 320)>>1;
  524. y = vid.height - SBAR_HEIGHT - 23;
  525. for (i=0 ; i<l ; i++)
  526. {
  527. k = fragsort[i];
  528. s = &cl.players[k];
  529. if (!s->name[0])
  530. continue;
  531. if (s->spectator)
  532. continue;
  533. // draw background
  534. top = s->topcolor;
  535. bottom = s->bottomcolor;
  536. top = (top < 0) ? 0 : ((top > 13) ? 13 : top);
  537. bottom = (bottom < 0) ? 0 : ((bottom > 13) ? 13 : bottom);
  538. top = Sbar_ColorForMap (top);
  539. bottom = Sbar_ColorForMap (bottom);
  540. // Draw_Fill (xofs + x*8 + 10, y, 28, 4, top);
  541. // Draw_Fill (xofs + x*8 + 10, y+4, 28, 3, bottom);
  542. Draw_Fill (x*8 + 10, y, 28, 4, top);
  543. Draw_Fill (x*8 + 10, y+4, 28, 3, bottom);
  544. // draw number
  545. f = s->frags;
  546. sprintf (num, "%3i",f);
  547. Sbar_DrawCharacter ( (x+1)*8 , -24, num[0]);
  548. Sbar_DrawCharacter ( (x+2)*8 , -24, num[1]);
  549. Sbar_DrawCharacter ( (x+3)*8 , -24, num[2]);
  550. if (k == cl.playernum)
  551. {
  552. Sbar_DrawCharacter (x*8+2, -24, 16);
  553. Sbar_DrawCharacter ( (x+4)*8-4, -24, 17);
  554. }
  555. x+=4;
  556. }
  557. }
  558. //=============================================================================
  559. /*
  560. ===============
  561. Sbar_DrawFace
  562. ===============
  563. */
  564. void Sbar_DrawFace (void)
  565. {
  566. int f, anim;
  567. if ( (cl.stats[STAT_ITEMS] & (IT_INVISIBILITY | IT_INVULNERABILITY) )
  568. == (IT_INVISIBILITY | IT_INVULNERABILITY) )
  569. {
  570. Sbar_DrawPic (112, 0, sb_face_invis_invuln);
  571. return;
  572. }
  573. if (cl.stats[STAT_ITEMS] & IT_QUAD)
  574. {
  575. Sbar_DrawPic (112, 0, sb_face_quad );
  576. return;
  577. }
  578. if (cl.stats[STAT_ITEMS] & IT_INVISIBILITY)
  579. {
  580. Sbar_DrawPic (112, 0, sb_face_invis );
  581. return;
  582. }
  583. if (cl.stats[STAT_ITEMS] & IT_INVULNERABILITY)
  584. {
  585. Sbar_DrawPic (112, 0, sb_face_invuln);
  586. return;
  587. }
  588. if (cl.stats[STAT_HEALTH] >= 100)
  589. f = 4;
  590. else
  591. f = cl.stats[STAT_HEALTH] / 20;
  592. if (cl.time <= cl.faceanimtime)
  593. {
  594. anim = 1;
  595. sb_updates = 0; // make sure the anim gets drawn over
  596. }
  597. else
  598. anim = 0;
  599. Sbar_DrawPic (112, 0, sb_faces[f][anim]);
  600. }
  601. /*
  602. =============
  603. Sbar_DrawNormal
  604. =============
  605. */
  606. void Sbar_DrawNormal (void)
  607. {
  608. if (cl_sbar.value || scr_viewsize.value<100)
  609. Sbar_DrawPic (0, 0, sb_sbar);
  610. // armor
  611. if (cl.stats[STAT_ITEMS] & IT_INVULNERABILITY)
  612. {
  613. Sbar_DrawNum (24, 0, 666, 3, 1);
  614. Sbar_DrawPic (0, 0, draw_disc);
  615. }
  616. else
  617. {
  618. Sbar_DrawNum (24, 0, cl.stats[STAT_ARMOR], 3
  619. , cl.stats[STAT_ARMOR] <= 25);
  620. if (cl.stats[STAT_ITEMS] & IT_ARMOR3)
  621. Sbar_DrawPic (0, 0, sb_armor[2]);
  622. else if (cl.stats[STAT_ITEMS] & IT_ARMOR2)
  623. Sbar_DrawPic (0, 0, sb_armor[1]);
  624. else if (cl.stats[STAT_ITEMS] & IT_ARMOR1)
  625. Sbar_DrawPic (0, 0, sb_armor[0]);
  626. }
  627. // face
  628. Sbar_DrawFace ();
  629. // health
  630. Sbar_DrawNum (136, 0, cl.stats[STAT_HEALTH], 3
  631. , cl.stats[STAT_HEALTH] <= 25);
  632. // ammo icon
  633. if (cl.stats[STAT_ITEMS] & IT_SHELLS)
  634. Sbar_DrawPic (224, 0, sb_ammo[0]);
  635. else if (cl.stats[STAT_ITEMS] & IT_NAILS)
  636. Sbar_DrawPic (224, 0, sb_ammo[1]);
  637. else if (cl.stats[STAT_ITEMS] & IT_ROCKETS)
  638. Sbar_DrawPic (224, 0, sb_ammo[2]);
  639. else if (cl.stats[STAT_ITEMS] & IT_CELLS)
  640. Sbar_DrawPic (224, 0, sb_ammo[3]);
  641. Sbar_DrawNum (248, 0, cl.stats[STAT_AMMO], 3
  642. , cl.stats[STAT_AMMO] <= 10);
  643. }
  644. /*
  645. ===============
  646. Sbar_Draw
  647. ===============
  648. */
  649. void Sbar_Draw (void)
  650. {
  651. qboolean headsup;
  652. char st[512];
  653. headsup = !(cl_sbar.value || scr_viewsize.value<100);
  654. if ((sb_updates >= vid.numpages) && !headsup)
  655. return;
  656. if (scr_con_current == vid.height)
  657. return; // console is full screen
  658. scr_copyeverything = 1;
  659. // scr_fullupdate = 0;
  660. sb_updates++;
  661. // top line
  662. if (sb_lines > 24)
  663. {
  664. if (!cl.spectator || autocam == CAM_TRACK)
  665. Sbar_DrawInventory ();
  666. if (!headsup || vid.width<512)
  667. Sbar_DrawFrags ();
  668. }
  669. // main area
  670. if (sb_lines > 0)
  671. {
  672. if (cl.spectator) {
  673. if (autocam != CAM_TRACK) {
  674. Sbar_DrawPic (0, 0, sb_scorebar);
  675. Sbar_DrawString (160-7*8,4, "SPECTATOR MODE");
  676. Sbar_DrawString(160-14*8+4, 12, "Press [ATTACK] for AutoCamera");
  677. } else {
  678. if (sb_showscores || cl.stats[STAT_HEALTH] <= 0)
  679. Sbar_SoloScoreboard ();
  680. else
  681. Sbar_DrawNormal ();
  682. // Sbar_DrawString (160-14*8+4,4, "SPECTATOR MODE - TRACK CAMERA");
  683. sprintf(st, "Tracking %-.13s, [JUMP] for next",
  684. cl.players[spec_track].name);
  685. Sbar_DrawString(0, -8, st);
  686. }
  687. } else if (sb_showscores || cl.stats[STAT_HEALTH] <= 0)
  688. Sbar_SoloScoreboard ();
  689. else
  690. Sbar_DrawNormal ();
  691. }
  692. // main screen deathmatch rankings
  693. // if we're dead show team scores in team games
  694. if (cl.stats[STAT_HEALTH] <= 0 && !cl.spectator)
  695. if (atoi(Info_ValueForKey(cl.serverinfo, "teamplay")) > 0 &&
  696. !sb_showscores)
  697. Sbar_TeamOverlay();
  698. else
  699. Sbar_DeathmatchOverlay (0);
  700. else if (sb_showscores)
  701. Sbar_DeathmatchOverlay (0);
  702. else if (sb_showteamscores)
  703. Sbar_TeamOverlay();
  704. #ifdef GLQUAKE
  705. if (sb_showscores || sb_showteamscores ||
  706. cl.stats[STAT_HEALTH] <= 0)
  707. sb_updates = 0;
  708. // clear unused areas in gl
  709. #if 0
  710. {
  711. int x = (vid.width - 320)>>1;
  712. // left
  713. if (x > 0) {
  714. Draw_TileClear (0, vid.height - sb_lines, x, sb_lines);
  715. Draw_TileClear (x+320, vid.height - sb_lines, vid.width - x+320, sb_lines);
  716. }
  717. }
  718. #endif
  719. if (vid.width > 320 && !headsup)
  720. Draw_TileClear (320, vid.height - sb_lines, vid.width - 320, sb_lines);
  721. #endif
  722. if (sb_lines > 0)
  723. Sbar_MiniDeathmatchOverlay ();
  724. }
  725. //=============================================================================
  726. /*
  727. ==================
  728. Sbar_IntermissionNumber
  729. ==================
  730. */
  731. void Sbar_IntermissionNumber (int x, int y, int num, int digits, int color)
  732. {
  733. char str[12];
  734. char *ptr;
  735. int l, frame;
  736. l = Sbar_itoa (num, str);
  737. ptr = str;
  738. if (l > digits)
  739. ptr += (l-digits);
  740. if (l < digits)
  741. x += (digits-l)*24;
  742. while (*ptr)
  743. {
  744. if (*ptr == '-')
  745. frame = STAT_MINUS;
  746. else
  747. frame = *ptr -'0';
  748. Draw_TransPic (x,y,sb_nums[color][frame]);
  749. x += 24;
  750. ptr++;
  751. }
  752. }
  753. /*
  754. ==================
  755. Sbar_TeamOverlay
  756. team frags
  757. added by Zoid
  758. ==================
  759. */
  760. void Sbar_TeamOverlay (void)
  761. {
  762. qpic_t *pic;
  763. int i, k, l;
  764. int x, y;
  765. char num[12];
  766. int teamplay;
  767. char team[5];
  768. team_t *tm;
  769. int plow, phigh, pavg;
  770. // request new ping times every two second
  771. teamplay = atoi(Info_ValueForKey(cl.serverinfo, "teamplay"));
  772. if (!teamplay) {
  773. Sbar_DeathmatchOverlay(0);
  774. return;
  775. }
  776. scr_copyeverything = 1;
  777. scr_fullupdate = 0;
  778. pic = Draw_CachePic ("gfx/ranking.lmp");
  779. Draw_Pic (160-pic->width/2, 0, pic);
  780. y = 24;
  781. x = 36;
  782. Draw_String(x, y, "low/avg/high team total players");
  783. y += 8;
  784. // Draw_String(x, y, "------------ ---- ----- -------");
  785. Draw_String(x, y, "\x1d\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1f \x1d\x1e\x1e\x1f \x1d\x1e\x1e\x1e\x1f \x1d\x1e\x1e\x1e\x1e\x1e\x1f");
  786. y += 8;
  787. // sort the teams
  788. Sbar_SortTeams();
  789. // draw the text
  790. l = scoreboardlines;
  791. for (i=0 ; i < scoreboardteams && y <= vid.height-10 ; i++)
  792. {
  793. k = teamsort[i];
  794. tm = teams + k;
  795. // draw pings
  796. plow = tm->plow;
  797. if (plow < 0 || plow > 999)
  798. plow = 999;
  799. phigh = tm->phigh;
  800. if (phigh < 0 || phigh > 999)
  801. phigh = 999;
  802. if (!tm->players)
  803. pavg = 999;
  804. else
  805. pavg = tm->ptotal / tm->players;
  806. if (pavg < 0 || pavg > 999)
  807. pavg = 999;
  808. sprintf (num, "%3i/%3i/%3i", plow, pavg, phigh);
  809. Draw_String ( x, y, num);
  810. // draw team
  811. team[4] = 0;
  812. strncpy (team, tm->team, 4);
  813. Draw_String (x + 104, y, team);
  814. // draw total
  815. sprintf (num, "%5i", tm->frags);
  816. Draw_String (x + 104 + 40, y, num);
  817. // draw players
  818. sprintf (num, "%5i", tm->players);
  819. Draw_String (x + 104 + 88, y, num);
  820. if (!strncmp(Info_ValueForKey(cl.players[cl.playernum].userinfo,
  821. "team"), tm->team, 16)) {
  822. Draw_Character ( x + 104 - 8, y, 16);
  823. Draw_Character ( x + 104 + 32, y, 17);
  824. }
  825. y += 8;
  826. }
  827. y += 8;
  828. Sbar_DeathmatchOverlay(y);
  829. }
  830. /*
  831. ==================
  832. Sbar_DeathmatchOverlay
  833. ping time frags name
  834. ==================
  835. */
  836. void Sbar_DeathmatchOverlay (int start)
  837. {
  838. qpic_t *pic;
  839. int i, k, l;
  840. int top, bottom;
  841. int x, y, f;
  842. char num[12];
  843. player_info_t *s;
  844. int total;
  845. int minutes;
  846. int p;
  847. int teamplay;
  848. char team[5];
  849. int skip = 10;
  850. if (largegame)
  851. skip = 8;
  852. // request new ping times every two second
  853. if (realtime - cl.last_ping_request > 2)
  854. {
  855. cl.last_ping_request = realtime;
  856. MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
  857. SZ_Print (&cls.netchan.message, "pings");
  858. }
  859. teamplay = atoi(Info_ValueForKey(cl.serverinfo, "teamplay"));
  860. scr_copyeverything = 1;
  861. scr_fullupdate = 0;
  862. if (!start) {
  863. pic = Draw_CachePic ("gfx/ranking.lmp");
  864. Draw_Pic (160-pic->width/2, 0, pic);
  865. }
  866. // scores
  867. Sbar_SortFrags (true);
  868. // draw the text
  869. l = scoreboardlines;
  870. if (start)
  871. y = start;
  872. else
  873. y = 24;
  874. if (teamplay)
  875. {
  876. x = 4;
  877. // 0 40 64 104 152 192
  878. Draw_String ( x , y, "ping pl time frags team name");
  879. y += 8;
  880. // Draw_String ( x , y, "---- -- ---- ----- ---- ----------------");
  881. Draw_String ( x , y, "\x1d\x1e\x1e\x1f \x1d\x1f \x1d\x1e\x1e\x1f \x1d\x1e\x1e\x1e\x1f \x1d\x1e\x1e\x1f \x1d\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1f");
  882. y += 8;
  883. }
  884. else
  885. {
  886. x = 16;
  887. // 0 40 64 104 152
  888. Draw_String ( x , y, "ping pl time frags name");
  889. y += 8;
  890. // Draw_String ( x , y, "---- -- ---- ----- ----------------");
  891. Draw_String ( x , y, "\x1d\x1e\x1e\x1f \x1d\x1f \x1d\x1e\x1e\x1f \x1d\x1e\x1e\x1e\x1f \x1d\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1f");
  892. y += 8;
  893. }
  894. for (i=0 ; i<l && y <= vid.height-10 ; i++)
  895. {
  896. k = fragsort[i];
  897. s = &cl.players[k];
  898. if (!s->name[0])
  899. continue;
  900. // draw ping
  901. p = s->ping;
  902. if (p < 0 || p > 999)
  903. p = 999;
  904. sprintf (num, "%4i", p);
  905. Draw_String ( x, y, num);
  906. // draw pl
  907. p = s->pl;
  908. sprintf (num, "%3i", p);
  909. if (p > 25)
  910. Draw_Alt_String ( x+32, y, num);
  911. else
  912. Draw_String ( x+32, y, num);
  913. if (s->spectator)
  914. {
  915. Draw_String (x+40, y, "(spectator)");
  916. // draw name
  917. if (teamplay)
  918. Draw_String (x+152+40, y, s->name);
  919. else
  920. Draw_String (x+152, y, s->name);
  921. y += skip;
  922. continue;
  923. }
  924. // draw time
  925. if (cl.intermission)
  926. total = cl.completed_time - s->entertime;
  927. else
  928. total = realtime - s->entertime;
  929. minutes = (int)total/60;
  930. sprintf (num, "%4i", minutes);
  931. Draw_String ( x+64 , y, num);
  932. // draw background
  933. top = s->topcolor;
  934. bottom = s->bottomcolor;
  935. top = Sbar_ColorForMap (top);
  936. bottom = Sbar_ColorForMap (bottom);
  937. if (largegame)
  938. Draw_Fill ( x+104, y+1, 40, 3, top);
  939. else
  940. Draw_Fill ( x+104, y, 40, 4, top);
  941. Draw_Fill ( x+104, y+4, 40, 4, bottom);
  942. // draw number
  943. f = s->frags;
  944. sprintf (num, "%3i",f);
  945. Draw_Character ( x+112 , y, num[0]);
  946. Draw_Character ( x+120 , y, num[1]);
  947. Draw_Character ( x+128 , y, num[2]);
  948. if (k == cl.playernum)
  949. {
  950. Draw_Character ( x + 104, y, 16);
  951. Draw_Character ( x + 136, y, 17);
  952. }
  953. // team
  954. if (teamplay)
  955. {
  956. team[4] = 0;
  957. strncpy (team, Info_ValueForKey(s->userinfo, "team"), 4);
  958. Draw_String (x+152, y, team);
  959. }
  960. // draw name
  961. if (teamplay)
  962. Draw_String (x+152+40, y, s->name);
  963. else
  964. Draw_String (x+152, y, s->name);
  965. y += skip;
  966. }
  967. if (y >= vid.height-10) // we ran over the screen size, squish
  968. largegame = true;
  969. }
  970. /*
  971. ==================
  972. Sbar_MiniDeathmatchOverlay
  973. frags name
  974. frags team name
  975. displayed to right of status bar if there's room
  976. ==================
  977. */
  978. void Sbar_MiniDeathmatchOverlay (void)
  979. {
  980. int i, k;
  981. int top, bottom;
  982. int x, y, f;
  983. char num[12];
  984. player_info_t *s;
  985. int teamplay;
  986. char team[5];
  987. int numlines;
  988. char name[16+1];
  989. team_t *tm;
  990. if (vid.width < 512 || !sb_lines)
  991. return; // not enuff room
  992. teamplay = atoi(Info_ValueForKey(cl.serverinfo, "teamplay"));
  993. scr_copyeverything = 1;
  994. scr_fullupdate = 0;
  995. // scores
  996. Sbar_SortFrags (false);
  997. if (vid.width >= 640)
  998. Sbar_SortTeams();
  999. if (!scoreboardlines)
  1000. return; // no one there?
  1001. // draw the text
  1002. y = vid.height - sb_lines - 1;
  1003. numlines = sb_lines/8;
  1004. if (numlines < 3)
  1005. return; // not enough room
  1006. // find us
  1007. for (i=0 ; i < scoreboardlines; i++)
  1008. if (fragsort[i] == cl.playernum)
  1009. break;
  1010. if (i == scoreboardlines) // we're not there, we are probably a spectator, just display top
  1011. i = 0;
  1012. else // figure out start
  1013. i = i - numlines/2;
  1014. if (i > scoreboardlines - numlines)
  1015. i = scoreboardlines - numlines;
  1016. if (i < 0)
  1017. i = 0;
  1018. x = 324;
  1019. for (/* */ ; i < scoreboardlines && y < vid.height - 8 + 1; i++)
  1020. {
  1021. k = fragsort[i];
  1022. s = &cl.players[k];
  1023. if (!s->name[0])
  1024. continue;
  1025. // draw ping
  1026. top = s->topcolor;
  1027. bottom = s->bottomcolor;
  1028. top = Sbar_ColorForMap (top);
  1029. bottom = Sbar_ColorForMap (bottom);
  1030. Draw_Fill ( x, y+1, 40, 3, top);
  1031. Draw_Fill ( x, y+4, 40, 4, bottom);
  1032. // draw number
  1033. f = s->frags;
  1034. sprintf (num, "%3i",f);
  1035. Draw_Character ( x+8 , y, num[0]);
  1036. Draw_Character ( x+16, y, num[1]);
  1037. Draw_Character ( x+24, y, num[2]);
  1038. if (k == cl.playernum)
  1039. {
  1040. Draw_Character ( x, y, 16);
  1041. Draw_Character ( x + 32, y, 17);
  1042. }
  1043. // team
  1044. if (teamplay)
  1045. {
  1046. team[4] = 0;
  1047. strncpy (team, Info_ValueForKey(s->userinfo, "team"), 4);
  1048. Draw_String (x+48, y, team);
  1049. }
  1050. // draw name
  1051. name[16] = 0;
  1052. strncpy(name, s->name, 16);
  1053. if (teamplay)
  1054. Draw_String (x+48+40, y, name);
  1055. else
  1056. Draw_String (x+48, y, name);
  1057. y += 8;
  1058. }
  1059. // draw teams if room
  1060. if (vid.width < 640 || !teamplay)
  1061. return;
  1062. // draw seperator
  1063. x += 208;
  1064. for (y = vid.height - sb_lines; y < vid.height - 6; y += 2)
  1065. Draw_Character(x, y, 14);
  1066. x += 16;
  1067. y = vid.height - sb_lines;
  1068. for (i=0 ; i < scoreboardteams && y <= vid.height; i++)
  1069. {
  1070. k = teamsort[i];
  1071. tm = teams + k;
  1072. // draw pings
  1073. team[4] = 0;
  1074. strncpy (team, tm->team, 4);
  1075. Draw_String (x, y, team);
  1076. // draw total
  1077. sprintf (num, "%5i", tm->frags);
  1078. Draw_String (x + 40, y, num);
  1079. if (!strncmp(Info_ValueForKey(cl.players[cl.playernum].userinfo,
  1080. "team"), tm->team, 16)) {
  1081. Draw_Character ( x - 8, y, 16);
  1082. Draw_Character ( x + 32, y, 17);
  1083. }
  1084. y += 8;
  1085. }
  1086. }
  1087. /*
  1088. ==================
  1089. Sbar_IntermissionOverlay
  1090. ==================
  1091. */
  1092. void Sbar_IntermissionOverlay (void)
  1093. {
  1094. scr_copyeverything = 1;
  1095. scr_fullupdate = 0;
  1096. if (atoi(Info_ValueForKey(cl.serverinfo, "teamplay")) > 0 && !sb_showscores)
  1097. Sbar_TeamOverlay ();
  1098. else
  1099. Sbar_DeathmatchOverlay (0);
  1100. }
  1101. /*
  1102. ==================
  1103. Sbar_FinaleOverlay
  1104. ==================
  1105. */
  1106. void Sbar_FinaleOverlay (void)
  1107. {
  1108. qpic_t *pic;
  1109. scr_copyeverything = 1;
  1110. pic = Draw_CachePic ("gfx/finale.lmp");
  1111. Draw_TransPic ( (vid.width-pic->width)/2, 16, pic);
  1112. }