wi_stuff.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2000 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. * DESCRIPTION:
  30. * Intermission screens.
  31. *
  32. *-----------------------------------------------------------------------------
  33. */
  34. #include "doomstat.h"
  35. #include "m_random.h"
  36. #include "w_wad.h"
  37. #include "g_game.h"
  38. #include "r_main.h"
  39. #include "v_video.h"
  40. #include "wi_stuff.h"
  41. #include "s_sound.h"
  42. #include "sounds.h"
  43. #include "lprintf.h" // jff 08/03/98 - declaration of lprintf
  44. #include "r_draw.h"
  45. // Ty 03/17/98: flag that new par times have been loaded in d_deh
  46. extern boolean deh_pars;
  47. //
  48. // Data needed to add patches to full screen intermission pics.
  49. // Patches are statistics messages, and animations.
  50. // Loads of by-pixel layout and placement, offsets etc.
  51. //
  52. //
  53. // Different vetween registered DOOM (1994) and
  54. // Ultimate DOOM - Final edition (retail, 1995?).
  55. // This is supposedly ignored for commercial
  56. // release (aka DOOM II), which had 34 maps
  57. // in one episode. So there.
  58. #define NUMEPISODES 4
  59. #define NUMMAPS 9
  60. // Not used
  61. // in tics
  62. //U #define PAUSELEN (TICRATE*2)
  63. //U #define SCORESTEP 100
  64. //U #define ANIMPERIOD 32
  65. // pixel distance from "(YOU)" to "PLAYER N"
  66. //U #define STARDIST 10
  67. //U #define WK 1
  68. // GLOBAL LOCATIONS
  69. #define WI_TITLEY 2
  70. #define WI_SPACINGY 33
  71. // SINGLE-PLAYER STUFF
  72. #define SP_STATSX 50
  73. #define SP_STATSY 50
  74. #define SP_TIMEX 8
  75. // proff/nicolas 09/20/98 -- changed for hi-res
  76. #define SP_TIMEY 160
  77. //#define SP_TIMEY (SCREENHEIGHT-32)
  78. // NET GAME STUFF
  79. #define NG_STATSY 50
  80. #define NG_STATSX (32 + V_NamePatchWidth(star)/2 + 32*!dofrags)
  81. #define NG_SPACINGX 64
  82. // Used to display the frags matrix at endgame
  83. // DEATHMATCH STUFF
  84. #define DM_MATRIXX 42
  85. #define DM_MATRIXY 68
  86. #define DM_SPACINGX 40
  87. #define DM_TOTALSX 269
  88. #define DM_KILLERSX 10
  89. #define DM_KILLERSY 100
  90. #define DM_VICTIMSX 5
  91. #define DM_VICTIMSY 50
  92. // These animation variables, structures, etc. are used for the
  93. // DOOM/Ultimate DOOM intermission screen animations. This is
  94. // totally different from any sprite or texture/flat animations
  95. typedef enum
  96. {
  97. ANIM_ALWAYS, // determined by patch entry
  98. ANIM_RANDOM, // occasional
  99. ANIM_LEVEL // continuous
  100. } animenum_t;
  101. typedef struct
  102. {
  103. int x; // x/y coordinate pair structure
  104. int y;
  105. } point_t;
  106. //
  107. // Animation.
  108. // There is another anim_t used in p_spec.
  109. //
  110. typedef struct
  111. {
  112. animenum_t type;
  113. // period in tics between animations
  114. int period;
  115. // number of animation frames
  116. int nanims;
  117. // location of animation
  118. point_t loc;
  119. // ALWAYS: n/a,
  120. // RANDOM: period deviation (<256),
  121. // LEVEL: level
  122. int data1;
  123. // ALWAYS: n/a,
  124. // RANDOM: random base period,
  125. // LEVEL: n/a
  126. int data2;
  127. /* actual graphics for frames of animations
  128. * cphipps - const
  129. */
  130. patchnum_t p[3];
  131. // following must be initialized to zero before use!
  132. // next value of bcnt (used in conjunction with period)
  133. int nexttic;
  134. // last drawn animation frame
  135. int lastdrawn;
  136. // next frame number to animate
  137. int ctr;
  138. // used by RANDOM and LEVEL when animating
  139. int state;
  140. } anim_t;
  141. static point_t lnodes[NUMEPISODES][NUMMAPS] =
  142. {
  143. // Episode 0 World Map
  144. {
  145. { 185, 164 }, // location of level 0 (CJ)
  146. { 148, 143 }, // location of level 1 (CJ)
  147. { 69, 122 }, // location of level 2 (CJ)
  148. { 209, 102 }, // location of level 3 (CJ)
  149. { 116, 89 }, // location of level 4 (CJ)
  150. { 166, 55 }, // location of level 5 (CJ)
  151. { 71, 56 }, // location of level 6 (CJ)
  152. { 135, 29 }, // location of level 7 (CJ)
  153. { 71, 24 } // location of level 8 (CJ)
  154. },
  155. // Episode 1 World Map should go here
  156. {
  157. { 254, 25 }, // location of level 0 (CJ)
  158. { 97, 50 }, // location of level 1 (CJ)
  159. { 188, 64 }, // location of level 2 (CJ)
  160. { 128, 78 }, // location of level 3 (CJ)
  161. { 214, 92 }, // location of level 4 (CJ)
  162. { 133, 130 }, // location of level 5 (CJ)
  163. { 208, 136 }, // location of level 6 (CJ)
  164. { 148, 140 }, // location of level 7 (CJ)
  165. { 235, 158 } // location of level 8 (CJ)
  166. },
  167. // Episode 2 World Map should go here
  168. {
  169. { 156, 168 }, // location of level 0 (CJ)
  170. { 48, 154 }, // location of level 1 (CJ)
  171. { 174, 95 }, // location of level 2 (CJ)
  172. { 265, 75 }, // location of level 3 (CJ)
  173. { 130, 48 }, // location of level 4 (CJ)
  174. { 279, 23 }, // location of level 5 (CJ)
  175. { 198, 48 }, // location of level 6 (CJ)
  176. { 140, 25 }, // location of level 7 (CJ)
  177. { 281, 136 } // location of level 8 (CJ)
  178. }
  179. };
  180. //
  181. // Animation locations for episode 0 (1).
  182. // Using patches saves a lot of space,
  183. // as they replace 320x200 full screen frames.
  184. //
  185. static anim_t epsd0animinfo[] =
  186. {
  187. { ANIM_ALWAYS, TICRATE/3, 3, { 224, 104 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  188. { ANIM_ALWAYS, TICRATE/3, 3, { 184, 160 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  189. { ANIM_ALWAYS, TICRATE/3, 3, { 112, 136 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  190. { ANIM_ALWAYS, TICRATE/3, 3, { 72, 112 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  191. { ANIM_ALWAYS, TICRATE/3, 3, { 88, 96 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  192. { ANIM_ALWAYS, TICRATE/3, 3, { 64, 48 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  193. { ANIM_ALWAYS, TICRATE/3, 3, { 192, 40 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  194. { ANIM_ALWAYS, TICRATE/3, 3, { 136, 16 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  195. { ANIM_ALWAYS, TICRATE/3, 3, { 80, 16 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  196. { ANIM_ALWAYS, TICRATE/3, 3, { 64, 24 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 }
  197. };
  198. static anim_t epsd1animinfo[] =
  199. {
  200. { ANIM_LEVEL, TICRATE/3, 1, { 128, 136 }, 1, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  201. { ANIM_LEVEL, TICRATE/3, 1, { 128, 136 }, 2, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  202. { ANIM_LEVEL, TICRATE/3, 1, { 128, 136 }, 3, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  203. { ANIM_LEVEL, TICRATE/3, 1, { 128, 136 }, 4, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  204. { ANIM_LEVEL, TICRATE/3, 1, { 128, 136 }, 5, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  205. { ANIM_LEVEL, TICRATE/3, 1, { 128, 136 }, 6, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  206. { ANIM_LEVEL, TICRATE/3, 1, { 128, 136 }, 7, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  207. { ANIM_LEVEL, TICRATE/3, 3, { 192, 144 }, 8, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  208. { ANIM_LEVEL, TICRATE/3, 1, { 128, 136 }, 8, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 }
  209. };
  210. static anim_t epsd2animinfo[] =
  211. {
  212. { ANIM_ALWAYS, TICRATE/3, 3, { 104, 168 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  213. { ANIM_ALWAYS, TICRATE/3, 3, { 40, 136 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  214. { ANIM_ALWAYS, TICRATE/3, 3, { 160, 96 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  215. { ANIM_ALWAYS, TICRATE/3, 3, { 104, 80 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  216. { ANIM_ALWAYS, TICRATE/3, 3, { 120, 32 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 },
  217. { ANIM_ALWAYS, TICRATE/4, 3, { 40, 0 }, 0, 0, { {0, 0, 0, 0, 0} }, 0, 0, 0, 0 }
  218. };
  219. static int NUMANIMS[NUMEPISODES] =
  220. {
  221. sizeof(epsd0animinfo)/sizeof(anim_t),
  222. sizeof(epsd1animinfo)/sizeof(anim_t),
  223. sizeof(epsd2animinfo)/sizeof(anim_t)
  224. };
  225. static anim_t *anims[NUMEPISODES] =
  226. {
  227. epsd0animinfo,
  228. epsd1animinfo,
  229. epsd2animinfo
  230. };
  231. //
  232. // GENERAL DATA
  233. //
  234. //
  235. // Locally used stuff.
  236. //
  237. #define FB 0
  238. // States for single-player
  239. #define SP_KILLS 0
  240. #define SP_ITEMS 2
  241. #define SP_SECRET 4
  242. #define SP_FRAGS 6
  243. #define SP_TIME 8
  244. #define SP_PAR ST_TIME
  245. #define SP_PAUSE 1
  246. // in seconds
  247. #define SHOWNEXTLOCDELAY 4
  248. //#define SHOWLASTLOCDELAY SHOWNEXTLOCDELAY
  249. // used to accelerate or skip a stage
  250. int acceleratestage; // killough 3/28/98: made global
  251. // wbs->pnum
  252. static int me;
  253. // specifies current state
  254. static stateenum_t state;
  255. // contains information passed into intermission
  256. static wbstartstruct_t* wbs;
  257. static wbplayerstruct_t* plrs; // wbs->plyr[]
  258. // used for general timing
  259. static int cnt;
  260. // used for timing of background animation
  261. static int bcnt;
  262. // signals to refresh everything for one frame
  263. static int firstrefresh;
  264. static int cnt_time;
  265. static int cnt_total_time;
  266. static int cnt_par;
  267. static int cnt_pause;
  268. //
  269. // GRAPHICS
  270. //
  271. // You Are Here graphic
  272. static const char* yah[2] = { "WIURH0", "WIURH1" };
  273. // splat
  274. static const char* splat = "WISPLAT";
  275. // %, : graphics
  276. static const char percent[] = {"WIPCNT"};
  277. static const char colon[] = {"WICOLON"};
  278. // 0-9 graphic
  279. static patchnum_t num[10];
  280. // minus sign
  281. static const char wiminus[] = {"WIMINUS"};
  282. // "Finished!" graphics
  283. static const char finished[] = {"WIF"};
  284. // "Entering" graphic
  285. static const char entering[] = {"WIENTER"};
  286. // "secret"
  287. static const char sp_secret[] = {"WISCRT2"};
  288. // "Kills", "Scrt", "Items", "Frags"
  289. static const char kills[] = {"WIOSTK"};
  290. static const char secret[] = {"WIOSTS"};
  291. static const char items[] = {"WIOSTI"};
  292. static const char frags[] = {"WIFRGS"};
  293. // Time sucks.
  294. static const char time1[] = {"WITIME"};
  295. static const char par[] = {"WIPAR"};
  296. static const char sucks[] = {"WISUCKS"};
  297. // "killers", "victims"
  298. static const char killers[] = {"WIKILRS"};
  299. static const char victims[] = {"WIVCTMS"};
  300. // "Total", your face, your dead face
  301. static const char total[] = {"WIMSTT"};
  302. static const char star[] = {"STFST01"};
  303. static const char bstar[] = {"STFDEAD0"};
  304. // "red P[1..MAXPLAYERS]"
  305. static const char facebackp[] = {"STPB0"};
  306. //
  307. // CODE
  308. //
  309. static void WI_endDeathmatchStats(void);
  310. static void WI_endNetgameStats(void);
  311. #define WI_endStats WI_endNetgameStats
  312. /* ====================================================================
  313. * WI_levelNameLump
  314. * Purpore: Returns the name of the graphic lump containing the name of
  315. * the given level.
  316. * Args: Episode and level, and buffer (must by 9 chars) to write to
  317. * Returns: void
  318. */
  319. void WI_levelNameLump(int epis, int map, char* buf)
  320. {
  321. if (gamemode == commercial) {
  322. sprintf(buf, "CWILV%2.2d", map);
  323. } else {
  324. sprintf(buf, "WILV%d%d", epis, map);
  325. }
  326. }
  327. // ====================================================================
  328. // WI_slamBackground
  329. // Purpose: Put the full-screen background up prior to patches
  330. // Args: none
  331. // Returns: void
  332. //
  333. static void WI_slamBackground(void)
  334. {
  335. char name[9]; // limited to 8 characters
  336. if (gamemode == commercial || (gamemode == retail && wbs->epsd == 3))
  337. strcpy(name, "INTERPIC");
  338. else
  339. sprintf(name, "WIMAP%d", wbs->epsd);
  340. // background
  341. V_DrawNamePatch(0, 0, FB, name, CR_DEFAULT, VPT_STRETCH);
  342. }
  343. // ====================================================================
  344. // WI_Responder
  345. // Purpose: Draw animations on intermission background screen
  346. // Args: ev -- event pointer, not actually used here.
  347. // Returns: False -- dummy routine
  348. //
  349. // The ticker is used to detect keys
  350. // because of timing issues in netgames.
  351. boolean WI_Responder(event_t* ev)
  352. {
  353. return false;
  354. }
  355. // ====================================================================
  356. // WI_drawLF
  357. // Purpose: Draw the "Finished" level name before showing stats
  358. // Args: none
  359. // Returns: void
  360. //
  361. void WI_drawLF(void)
  362. {
  363. int y = WI_TITLEY;
  364. char lname[9];
  365. // draw <LevelName>
  366. /* cph - get the graphic lump name and use it */
  367. WI_levelNameLump(wbs->epsd, wbs->last, lname);
  368. // CPhipps - patch drawing updated
  369. V_DrawNamePatch((320 - V_NamePatchWidth(lname))/2, y,
  370. FB, lname, CR_DEFAULT, VPT_STRETCH);
  371. // draw "Finished!"
  372. y += (5*V_NamePatchHeight(lname))/4;
  373. // CPhipps - patch drawing updated
  374. V_DrawNamePatch((320 - V_NamePatchWidth(finished))/2, y,
  375. FB, finished, CR_DEFAULT, VPT_STRETCH);
  376. }
  377. // ====================================================================
  378. // WI_drawEL
  379. // Purpose: Draw introductory "Entering" and level name
  380. // Args: none
  381. // Returns: void
  382. //
  383. void WI_drawEL(void)
  384. {
  385. int y = WI_TITLEY;
  386. char lname[9];
  387. /* cph - get the graphic lump name */
  388. WI_levelNameLump(wbs->epsd, wbs->next, lname);
  389. // draw "Entering"
  390. // CPhipps - patch drawing updated
  391. V_DrawNamePatch((320 - V_NamePatchWidth(entering))/2,
  392. y, FB, entering, CR_DEFAULT, VPT_STRETCH);
  393. // draw level
  394. y += (5*V_NamePatchHeight(lname))/4;
  395. // CPhipps - patch drawing updated
  396. V_DrawNamePatch((320 - V_NamePatchWidth(lname))/2, y, FB,
  397. lname, CR_DEFAULT, VPT_STRETCH);
  398. }
  399. /* ====================================================================
  400. * WI_drawOnLnode
  401. * Purpose: Draw patches at a location based on episode/map
  402. * Args: n -- index to map# within episode
  403. * c[] -- array of names of patches to be drawn
  404. * Returns: void
  405. */
  406. void
  407. WI_drawOnLnode // draw stuff at a location by episode/map#
  408. ( int n,
  409. const char* const c[] )
  410. {
  411. int i;
  412. boolean fits = false;
  413. i = 0;
  414. do
  415. {
  416. int left;
  417. int top;
  418. int right;
  419. int bottom;
  420. const rpatch_t* patch = R_CachePatchName(c[i]);
  421. left = lnodes[wbs->epsd][n].x - patch->leftoffset;
  422. top = lnodes[wbs->epsd][n].y - patch->topoffset;
  423. right = left + patch->width;
  424. bottom = top + patch->height;
  425. R_UnlockPatchName(c[i]);
  426. if (left >= 0
  427. && right < 320
  428. && top >= 0
  429. && bottom < 200)
  430. {
  431. fits = true;
  432. }
  433. else
  434. {
  435. i++;
  436. }
  437. } while (!fits && i!=2);
  438. if (fits && i<2)
  439. {
  440. // CPhipps - patch drawing updated
  441. V_DrawNamePatch(lnodes[wbs->epsd][n].x, lnodes[wbs->epsd][n].y,
  442. FB, c[i], CR_DEFAULT, VPT_STRETCH);
  443. }
  444. else
  445. {
  446. // DEBUG
  447. //jff 8/3/98 use logical output routine
  448. lprintf(LO_DEBUG,"Could not place patch on level %d", n+1);
  449. }
  450. }
  451. // ====================================================================
  452. // WI_initAnimatedBack
  453. // Purpose: Initialize pointers and styles for background animation
  454. // Args: none
  455. // Returns: void
  456. //
  457. void WI_initAnimatedBack(void)
  458. {
  459. int i;
  460. anim_t* a;
  461. if (gamemode == commercial) // no animation for DOOM2
  462. return;
  463. if (wbs->epsd > 2)
  464. return;
  465. for (i=0;i<NUMANIMS[wbs->epsd];i++)
  466. {
  467. a = &anims[wbs->epsd][i];
  468. // init variables
  469. a->ctr = -1;
  470. // specify the next time to draw it
  471. if (a->type == ANIM_ALWAYS)
  472. a->nexttic = bcnt + 1 + (M_Random()%a->period);
  473. else
  474. if (a->type == ANIM_RANDOM)
  475. a->nexttic = bcnt + 1 + a->data2+(M_Random()%a->data1);
  476. else
  477. if (a->type == ANIM_LEVEL)
  478. a->nexttic = bcnt + 1;
  479. }
  480. }
  481. // ====================================================================
  482. // WI_updateAnimatedBack
  483. // Purpose: Figure out what animation we do on this iteration
  484. // Args: none
  485. // Returns: void
  486. //
  487. void WI_updateAnimatedBack(void)
  488. {
  489. int i;
  490. anim_t* a;
  491. if (gamemode == commercial)
  492. return;
  493. if (wbs->epsd > 2)
  494. return;
  495. for (i=0;i<NUMANIMS[wbs->epsd];i++)
  496. {
  497. a = &anims[wbs->epsd][i];
  498. if (bcnt == a->nexttic)
  499. {
  500. switch (a->type)
  501. {
  502. case ANIM_ALWAYS:
  503. if (++a->ctr >= a->nanims) a->ctr = 0;
  504. a->nexttic = bcnt + a->period;
  505. break;
  506. case ANIM_RANDOM:
  507. a->ctr++;
  508. if (a->ctr == a->nanims)
  509. {
  510. a->ctr = -1;
  511. a->nexttic = bcnt+a->data2+(M_Random()%a->data1);
  512. }
  513. else
  514. a->nexttic = bcnt + a->period;
  515. break;
  516. case ANIM_LEVEL:
  517. // gawd-awful hack for level anims
  518. if (!(state == StatCount && i == 7)
  519. && wbs->next == a->data1)
  520. {
  521. a->ctr++;
  522. if (a->ctr == a->nanims) a->ctr--;
  523. a->nexttic = bcnt + a->period;
  524. }
  525. break;
  526. }
  527. }
  528. }
  529. }
  530. // ====================================================================
  531. // WI_drawAnimatedBack
  532. // Purpose: Actually do the animation (whew!)
  533. // Args: none
  534. // Returns: void
  535. //
  536. void WI_drawAnimatedBack(void)
  537. {
  538. int i;
  539. anim_t* a;
  540. if (gamemode==commercial) //jff 4/25/98 Someone forgot commercial an enum
  541. return;
  542. if (wbs->epsd > 2)
  543. return;
  544. for (i=0 ; i<NUMANIMS[wbs->epsd] ; i++)
  545. {
  546. a = &anims[wbs->epsd][i];
  547. if (a->ctr >= 0)
  548. // CPhipps - patch drawing updated
  549. V_DrawNumPatch(a->loc.x, a->loc.y, FB, a->p[a->ctr].lumpnum, CR_DEFAULT, VPT_STRETCH);
  550. }
  551. }
  552. // ====================================================================
  553. // WI_drawNum
  554. // Purpose: Draws a number. If digits > 0, then use that many digits
  555. // minimum, otherwise only use as many as necessary
  556. // Args: x, y -- location
  557. // n -- the number to be drawn
  558. // digits -- number of digits minimum or zero
  559. // Returns: new x position after drawing (note we are going to the left)
  560. // CPhipps - static
  561. static int WI_drawNum (int x, int y, int n, int digits)
  562. {
  563. int fontwidth = num[0].width;
  564. int neg;
  565. int temp;
  566. if (digits < 0)
  567. {
  568. if (!n)
  569. {
  570. // make variable-length zeros 1 digit long
  571. digits = 1;
  572. }
  573. else
  574. {
  575. // figure out # of digits in #
  576. digits = 0;
  577. temp = n;
  578. while (temp)
  579. {
  580. temp /= 10;
  581. digits++;
  582. }
  583. }
  584. }
  585. neg = n < 0;
  586. if (neg)
  587. n = -n;
  588. // if non-number, do not draw it
  589. if (n == 1994)
  590. return 0;
  591. // draw the new number
  592. while (digits--)
  593. {
  594. x -= fontwidth;
  595. // CPhipps - patch drawing updated
  596. V_DrawNumPatch(x, y, FB, num[ n % 10 ].lumpnum, CR_DEFAULT, VPT_STRETCH);
  597. n /= 10;
  598. }
  599. // draw a minus sign if necessary
  600. if (neg)
  601. // CPhipps - patch drawing updated
  602. V_DrawNamePatch(x-=8, y, FB, wiminus, CR_DEFAULT, VPT_STRETCH);
  603. return x;
  604. }
  605. // ====================================================================
  606. // WI_drawPercent
  607. // Purpose: Draws a percentage, really just a call to WI_drawNum
  608. // after putting a percent sign out there
  609. // Args: x, y -- location
  610. // p -- the percentage value to be drawn, no negatives
  611. // Returns: void
  612. // CPhipps - static
  613. static void WI_drawPercent(int x, int y, int p)
  614. {
  615. if (p < 0)
  616. return;
  617. // CPhipps - patch drawing updated
  618. V_DrawNamePatch(x, y, FB, percent, CR_DEFAULT, VPT_STRETCH);
  619. WI_drawNum(x, y, p, -1);
  620. }
  621. // ====================================================================
  622. // WI_drawTime
  623. // Purpose: Draws the level completion time or par time, or "Sucks"
  624. // if 1 hour or more
  625. // Args: x, y -- location
  626. // t -- the time value to be drawn
  627. // Returns: void
  628. //
  629. // CPhipps - static
  630. // - largely rewritten to display hours and use slightly better algorithm
  631. static void WI_drawTime(int x, int y, int t)
  632. {
  633. int n;
  634. if (t<0)
  635. return;
  636. if (t < 100*60*60)
  637. for(;;) {
  638. n = t % 60;
  639. t /= 60;
  640. x = WI_drawNum(x, y, n, (t || n>9) ? 2 : 1) - V_NamePatchWidth(colon);
  641. // draw
  642. if (t)
  643. // CPhipps - patch drawing updated
  644. V_DrawNamePatch(x, y, FB, colon, CR_DEFAULT, VPT_STRETCH);
  645. else break;
  646. }
  647. else // "sucks" (maybe should be "addicted", even I've never had a 100 hour game ;)
  648. V_DrawNamePatch(x - V_NamePatchWidth(sucks),
  649. y, FB, sucks, CR_DEFAULT, VPT_STRETCH);
  650. }
  651. // ====================================================================
  652. // WI_End
  653. // Purpose: Unloads data structures (inverse of WI_Start)
  654. // Args: none
  655. // Returns: void
  656. //
  657. void WI_End(void)
  658. {
  659. if (deathmatch)
  660. WI_endDeathmatchStats();
  661. else if (netgame)
  662. WI_endNetgameStats();
  663. else
  664. WI_endStats();
  665. }
  666. // ====================================================================
  667. // WI_initNoState
  668. // Purpose: Clear state, ready for end of level activity
  669. // Args: none
  670. // Returns: void
  671. //
  672. void WI_initNoState(void)
  673. {
  674. state = NoState;
  675. acceleratestage = 0;
  676. cnt = 10;
  677. }
  678. // ====================================================================
  679. // WI_drawTimeStats
  680. // Purpose: Put the times on the screen
  681. // Args: time, total time, par time, in seconds
  682. // Returns: void
  683. //
  684. // cph - pulled from WI_drawStats below
  685. static void WI_drawTimeStats(int cnt_time_sec, int cnt_total_time_sec, int cnt_par_time_sec)
  686. {
  687. V_DrawNamePatch(SP_TIMEX, SP_TIMEY, FB, time1, CR_DEFAULT, VPT_STRETCH);
  688. WI_drawTime(320/2 - SP_TIMEX, SP_TIMEY, cnt_time_sec);
  689. V_DrawNamePatch(SP_TIMEX, (SP_TIMEY+200)/2, FB, total, CR_DEFAULT, VPT_STRETCH);
  690. WI_drawTime(320/2 - SP_TIMEX, (SP_TIMEY+200)/2, cnt_total_time_sec);
  691. // Ty 04/11/98: redid logic: should skip only if with pwad but
  692. // without deh patch
  693. // killough 2/22/98: skip drawing par times on pwads
  694. // Ty 03/17/98: unless pars changed with deh patch
  695. if (!(modifiedgame && !deh_pars))
  696. {
  697. if (wbs->epsd < 3)
  698. {
  699. V_DrawNamePatch(320/2 + SP_TIMEX, SP_TIMEY, FB, par, CR_DEFAULT, VPT_STRETCH);
  700. WI_drawTime(320 - SP_TIMEX, SP_TIMEY, cnt_par_time_sec);
  701. }
  702. }
  703. }
  704. // ====================================================================
  705. // WI_updateNoState
  706. // Purpose: Cycle until end of level activity is done
  707. // Args: none
  708. // Returns: void
  709. //
  710. void WI_updateNoState(void)
  711. {
  712. WI_updateAnimatedBack();
  713. if (!--cnt)
  714. G_WorldDone();
  715. }
  716. static boolean snl_pointeron = false;
  717. // ====================================================================
  718. // WI_initShowNextLoc
  719. // Purpose: Prepare to show the next level's location
  720. // Args: none
  721. // Returns: void
  722. //
  723. void WI_initShowNextLoc(void)
  724. {
  725. if ((gamemode != commercial) && (gamemap == 8)) {
  726. G_WorldDone();
  727. return;
  728. }
  729. state = ShowNextLoc;
  730. acceleratestage = 0;
  731. // e6y: That was pretty easy - only a HEX editor and luck
  732. // There is no more desync on ddt-tas.zip\e4tux231.lmp
  733. // --------- tasdoom.idb ---------
  734. // .text:00031194 loc_31194: ; CODE XREF: WI_updateStats+3A9j
  735. // .text:00031194 mov ds:state, 1
  736. // .text:0003119E mov ds:acceleratestage, 0
  737. // .text:000311A8 mov ds:cnt, 3Ch
  738. // nowhere no hide
  739. if (compatibility_level == tasdoom_compatibility)
  740. cnt = 60;
  741. else
  742. cnt = SHOWNEXTLOCDELAY * TICRATE;
  743. WI_initAnimatedBack();
  744. }
  745. // ====================================================================
  746. // WI_updateShowNextLoc
  747. // Purpose: Prepare to show the next level's location
  748. // Args: none
  749. // Returns: void
  750. //
  751. void WI_updateShowNextLoc(void)
  752. {
  753. WI_updateAnimatedBack();
  754. if (!--cnt || acceleratestage)
  755. WI_initNoState();
  756. else
  757. snl_pointeron = (cnt & 31) < 20;
  758. }
  759. // ====================================================================
  760. // WI_drawShowNextLoc
  761. // Purpose: Show the next level's location on animated backgrounds
  762. // Args: none
  763. // Returns: void
  764. //
  765. void WI_drawShowNextLoc(void)
  766. {
  767. int i;
  768. int last;
  769. WI_slamBackground();
  770. // draw animated background
  771. WI_drawAnimatedBack();
  772. if ( gamemode != commercial)
  773. {
  774. if (wbs->epsd > 2)
  775. {
  776. WI_drawEL(); // "Entering..." if not E1 or E2
  777. return;
  778. }
  779. last = (wbs->last == 8) ? wbs->next - 1 : wbs->last;
  780. // draw a splat on taken cities.
  781. for (i=0 ; i<=last ; i++)
  782. WI_drawOnLnode(i, &splat);
  783. // splat the secret level?
  784. if (wbs->didsecret)
  785. WI_drawOnLnode(8, &splat);
  786. // draw flashing ptr
  787. if (snl_pointeron)
  788. WI_drawOnLnode(wbs->next, yah);
  789. }
  790. // draws which level you are entering..
  791. if ( (gamemode != commercial)
  792. || wbs->next != 30) // check for MAP30 end game
  793. WI_drawEL();
  794. }
  795. // ====================================================================
  796. // WI_drawNoState
  797. // Purpose: Draw the pointer and next location
  798. // Args: none
  799. // Returns: void
  800. //
  801. void WI_drawNoState(void)
  802. {
  803. snl_pointeron = true;
  804. WI_drawShowNextLoc();
  805. }
  806. // ====================================================================
  807. // WI_fragSum
  808. // Purpose: Calculate frags for this player based on the current totals
  809. // of all the other players. Subtract self-frags.
  810. // Args: playernum -- the player to be calculated
  811. // Returns: the total frags for this player
  812. //
  813. int WI_fragSum(int playernum)
  814. {
  815. int i;
  816. int numfrags = 0;
  817. for (i=0 ; i<MAXPLAYERS ; i++)
  818. {
  819. if (playeringame[i] // is this player playing?
  820. && i!=playernum) // and it's not the player we're calculating
  821. {
  822. numfrags += plrs[playernum].frags[i];
  823. }
  824. }
  825. // JDC hack - negative frags.
  826. numfrags -= plrs[playernum].frags[playernum];
  827. return numfrags;
  828. }
  829. static int dm_state;
  830. // CPhipps - short, dynamically allocated
  831. static short int **dm_frags; // frags matrix
  832. static short int *dm_totals; // totals by player
  833. // ====================================================================
  834. // WI_initDeathmatchStats
  835. // Purpose: Set up to display DM stats at end of level. Calculate
  836. // frags for all players.
  837. // Args: none
  838. // Returns: void
  839. //
  840. void WI_initDeathmatchStats(void)
  841. {
  842. int i; // looping variables
  843. // CPhipps - allocate data structures needed
  844. dm_frags = calloc(MAXPLAYERS, sizeof(*dm_frags));
  845. dm_totals = calloc(MAXPLAYERS, sizeof(*dm_totals));
  846. state = StatCount; // We're doing stats
  847. acceleratestage = 0;
  848. dm_state = 1; // count how many times we've done a complete stat
  849. cnt_pause = TICRATE;
  850. for (i=0 ; i<MAXPLAYERS ; i++)
  851. {
  852. if (playeringame[i])
  853. {
  854. // CPhipps - allocate frags line
  855. dm_frags[i] = calloc(MAXPLAYERS, sizeof(**dm_frags)); // set all counts to zero
  856. dm_totals[i] = 0;
  857. }
  858. }
  859. WI_initAnimatedBack();
  860. }
  861. // ====================================================================
  862. // CPhipps - WI_endDeathmatchStats
  863. // Purpose: Deallocate dynamically allocated DM stats data
  864. // Args: none
  865. // Returns: void
  866. //
  867. void WI_endDeathmatchStats(void)
  868. {
  869. int i;
  870. for (i=0; i<MAXPLAYERS; i++)
  871. free(dm_frags[i]);
  872. free(dm_frags); free(dm_totals);
  873. }
  874. // ====================================================================
  875. // WI_updateDeathmatchStats
  876. // Purpose: Advance Deathmatch stats screen animation. Calculate
  877. // frags for all players. Lots of noise and drama around
  878. // the presentation.
  879. // Args: none
  880. // Returns: void
  881. //
  882. void WI_updateDeathmatchStats(void)
  883. {
  884. int i;
  885. int j;
  886. boolean stillticking;
  887. WI_updateAnimatedBack();
  888. if (acceleratestage && dm_state != 4) // still ticking
  889. {
  890. acceleratestage = 0;
  891. for (i=0 ; i<MAXPLAYERS ; i++)
  892. {
  893. if (playeringame[i])
  894. {
  895. for (j=0 ; j<MAXPLAYERS ; j++)
  896. if (playeringame[j])
  897. dm_frags[i][j] = plrs[i].frags[j];
  898. dm_totals[i] = WI_fragSum(i);
  899. }
  900. }
  901. S_StartSound(0, sfx_barexp); // bang
  902. dm_state = 4; // we're done with all 4 (or all we have to do)
  903. }
  904. if (dm_state == 2)
  905. {
  906. if (!(bcnt&3))
  907. S_StartSound(0, sfx_pistol); // noise while counting
  908. stillticking = false;
  909. for (i=0 ; i<MAXPLAYERS ; i++)
  910. {
  911. if (playeringame[i])
  912. {
  913. for (j=0 ; j<MAXPLAYERS ; j++)
  914. {
  915. if (playeringame[j]
  916. && dm_frags[i][j] != plrs[i].frags[j])
  917. {
  918. if (plrs[i].frags[j] < 0)
  919. dm_frags[i][j]--;
  920. else
  921. dm_frags[i][j]++;
  922. if (dm_frags[i][j] > 999) // Ty 03/17/98 3-digit frag count
  923. dm_frags[i][j] = 999;
  924. if (dm_frags[i][j] < -999)
  925. dm_frags[i][j] = -999;
  926. stillticking = true;
  927. }
  928. }
  929. dm_totals[i] = WI_fragSum(i);
  930. if (dm_totals[i] > 999)
  931. dm_totals[i] = 999;
  932. if (dm_totals[i] < -999)
  933. dm_totals[i] = -999; // Ty 03/17/98 end 3-digit frag count
  934. }
  935. }
  936. if (!stillticking)
  937. {
  938. S_StartSound(0, sfx_barexp);
  939. dm_state++;
  940. }
  941. }
  942. else if (dm_state == 4)
  943. {
  944. if (acceleratestage)
  945. {
  946. S_StartSound(0, sfx_slop);
  947. if ( gamemode == commercial)
  948. WI_initNoState();
  949. else
  950. WI_initShowNextLoc();
  951. }
  952. }
  953. else if (dm_state & 1)
  954. {
  955. if (!--cnt_pause)
  956. {
  957. dm_state++;
  958. cnt_pause = TICRATE;
  959. }
  960. }
  961. }
  962. // ====================================================================
  963. // WI_drawDeathmatchStats
  964. // Purpose: Draw the stats on the screen in a matrix
  965. // Args: none
  966. // Returns: void
  967. //
  968. // proff/nicolas 09/20/98 -- changed for hi-res
  969. // CPhipps - patch drawing updated
  970. void WI_drawDeathmatchStats(void)
  971. {
  972. int i;
  973. int j;
  974. int x;
  975. int y;
  976. int w;
  977. int lh; // line height
  978. int halfface = V_NamePatchWidth(facebackp)/2;
  979. lh = WI_SPACINGY;
  980. WI_slamBackground();
  981. // draw animated background
  982. WI_drawAnimatedBack();
  983. WI_drawLF();
  984. // draw stat titles (top line)
  985. V_DrawNamePatch(DM_TOTALSX-V_NamePatchWidth(total)/2,
  986. DM_MATRIXY-WI_SPACINGY+10, FB, total, CR_DEFAULT, VPT_STRETCH);
  987. V_DrawNamePatch(DM_KILLERSX, DM_KILLERSY, FB, killers, CR_DEFAULT, VPT_STRETCH);
  988. V_DrawNamePatch(DM_VICTIMSX, DM_VICTIMSY, FB, victims, CR_DEFAULT, VPT_STRETCH);
  989. // draw P?
  990. x = DM_MATRIXX + DM_SPACINGX;
  991. y = DM_MATRIXY;
  992. for (i=0 ; i<MAXPLAYERS ; i++)
  993. {
  994. if (playeringame[i]) {
  995. //int trans = playernumtotrans[i];
  996. V_DrawNamePatch(x-halfface, DM_MATRIXY - WI_SPACINGY,
  997. FB, facebackp, i ? CR_LIMIT+i : CR_DEFAULT,
  998. VPT_STRETCH | (i ? VPT_TRANS : 0));
  999. V_DrawNamePatch(DM_MATRIXX-halfface, y,
  1000. FB, facebackp, i ? CR_LIMIT+i : CR_DEFAULT,
  1001. VPT_STRETCH | (i ? VPT_TRANS : 0));
  1002. if (i == me)
  1003. {
  1004. V_DrawNamePatch(x-halfface, DM_MATRIXY - WI_SPACINGY,
  1005. FB, bstar, CR_DEFAULT, VPT_STRETCH);
  1006. V_DrawNamePatch(DM_MATRIXX-halfface, y,
  1007. FB, star, CR_DEFAULT, VPT_STRETCH);
  1008. }
  1009. }
  1010. x += DM_SPACINGX;
  1011. y += WI_SPACINGY;
  1012. }
  1013. // draw stats
  1014. y = DM_MATRIXY+10;
  1015. w = num[0].width;
  1016. for (i=0 ; i<MAXPLAYERS ; i++)
  1017. {
  1018. x = DM_MATRIXX + DM_SPACINGX;
  1019. if (playeringame[i])
  1020. {
  1021. for (j=0 ; j<MAXPLAYERS ; j++)
  1022. {
  1023. if (playeringame[j])
  1024. WI_drawNum(x+w, y, dm_frags[i][j], 2);
  1025. x += DM_SPACINGX;
  1026. }
  1027. WI_drawNum(DM_TOTALSX+w, y, dm_totals[i], 2);
  1028. }
  1029. y += WI_SPACINGY;
  1030. }
  1031. }
  1032. //
  1033. // Note: The term "Netgame" means a coop game
  1034. //
  1035. // e6y
  1036. // 'short' => 'int' for cnt_kills, cnt_items and cnt_secret
  1037. //
  1038. // Original sources use 'int' type for cnt_kills instead of 'short'
  1039. // I don't know who have made change of type, but this change
  1040. // leads to desynch if 'kills' percentage is more than 32767.
  1041. // Actually PrBoom will be in an infinite cycle at calculation of
  1042. // percentage if the player will not press <Use> for acceleration, because
  1043. // the condition (cnt_kills[0] >= (plrs[me].skills * 100) / wbs->maxkills)
  1044. // will be always false in this case.
  1045. //
  1046. // If you will kill 800 monsters on MAP30 on Ultra-Violence skill and
  1047. // will not press <Use>, vanilla will count up to 80000%, but PrBoom
  1048. // will be in infinite cycle of counting:
  1049. // (0, 1, 2, ..., 32766, 32767, -32768, -32767, ..., -1, 0, 1, ...)
  1050. // Negative numbers will not be displayed.
  1051. static int *cnt_kills;
  1052. static int *cnt_items;
  1053. static int *cnt_secret;
  1054. static int *cnt_frags;
  1055. static int dofrags;
  1056. static int ng_state;
  1057. // ====================================================================
  1058. // CPhipps - WI_endNetgameStats
  1059. // Purpose: Clean up coop game stats
  1060. // Args: none
  1061. // Returns: void
  1062. //
  1063. static void WI_endNetgameStats(void)
  1064. {
  1065. free(cnt_frags); cnt_frags = NULL;
  1066. free(cnt_secret); cnt_secret = NULL;
  1067. free(cnt_items); cnt_items = NULL;
  1068. free(cnt_kills); cnt_kills = NULL;
  1069. }
  1070. // ====================================================================
  1071. // WI_initNetgameStats
  1072. // Purpose: Prepare for coop game stats
  1073. // Args: none
  1074. // Returns: void
  1075. //
  1076. void WI_initNetgameStats(void)
  1077. {
  1078. int i;
  1079. state = StatCount;
  1080. acceleratestage = 0;
  1081. ng_state = 1;
  1082. cnt_pause = TICRATE;
  1083. // CPhipps - allocate these dynamically, blank with calloc
  1084. cnt_kills = calloc(MAXPLAYERS, sizeof(*cnt_kills));
  1085. cnt_items = calloc(MAXPLAYERS, sizeof(*cnt_items));
  1086. cnt_secret= calloc(MAXPLAYERS, sizeof(*cnt_secret));
  1087. cnt_frags = calloc(MAXPLAYERS, sizeof(*cnt_frags));
  1088. for (i=0 ; i<MAXPLAYERS ; i++)
  1089. if (playeringame[i])
  1090. dofrags += WI_fragSum(i);
  1091. dofrags = !!dofrags; // set to true or false - did we have frags?
  1092. WI_initAnimatedBack();
  1093. }
  1094. // ====================================================================
  1095. // WI_updateNetgameStats
  1096. // Purpose: Calculate coop stats as we display them with noise and fury
  1097. // Args: none
  1098. // Returns: void
  1099. // Comment: This stuff sure is complicated for what it does
  1100. //
  1101. void WI_updateNetgameStats(void)
  1102. {
  1103. int i;
  1104. int fsum;
  1105. boolean stillticking;
  1106. WI_updateAnimatedBack();
  1107. if (acceleratestage && ng_state != 10)
  1108. {
  1109. acceleratestage = 0;
  1110. for (i=0 ; i<MAXPLAYERS ; i++)
  1111. {
  1112. if (!playeringame[i])
  1113. continue;
  1114. cnt_kills[i] = (plrs[i].skills * 100) / wbs->maxkills;
  1115. cnt_items[i] = (plrs[i].sitems * 100) / wbs->maxitems;
  1116. // killough 2/22/98: Make secrets = 100% if maxsecret = 0:
  1117. cnt_secret[i] = wbs->maxsecret ?
  1118. (plrs[i].ssecret * 100) / wbs->maxsecret : 100;
  1119. if (dofrags)
  1120. cnt_frags[i] = WI_fragSum(i); // we had frags
  1121. }
  1122. S_StartSound(0, sfx_barexp); // bang
  1123. ng_state = 10;
  1124. }
  1125. if (ng_state == 2)
  1126. {
  1127. if (!(bcnt&3))
  1128. S_StartSound(0, sfx_pistol); // pop
  1129. stillticking = false;
  1130. for (i=0 ; i<MAXPLAYERS ; i++)
  1131. {
  1132. if (!playeringame[i])
  1133. continue;
  1134. cnt_kills[i] += 2;
  1135. if (cnt_kills[i] >= (plrs[i].skills * 100) / wbs->maxkills)
  1136. cnt_kills[i] = (plrs[i].skills * 100) / wbs->maxkills;
  1137. else
  1138. stillticking = true; // still got stuff to tally
  1139. }
  1140. if (!stillticking)
  1141. {
  1142. S_StartSound(0, sfx_barexp);
  1143. ng_state++;
  1144. }
  1145. }
  1146. else if (ng_state == 4)
  1147. {
  1148. if (!(bcnt&3))
  1149. S_StartSound(0, sfx_pistol);
  1150. stillticking = false;
  1151. for (i=0 ; i<MAXPLAYERS ; i++)
  1152. {
  1153. if (!playeringame[i])
  1154. continue;
  1155. cnt_items[i] += 2;
  1156. if (cnt_items[i] >= (plrs[i].sitems * 100) / wbs->maxitems)
  1157. cnt_items[i] = (plrs[i].sitems * 100) / wbs->maxitems;
  1158. else
  1159. stillticking = true;
  1160. }
  1161. if (!stillticking)
  1162. {
  1163. S_StartSound(0, sfx_barexp);
  1164. ng_state++;
  1165. }
  1166. }
  1167. else if (ng_state == 6)
  1168. {
  1169. if (!(bcnt&3))
  1170. S_StartSound(0, sfx_pistol);
  1171. stillticking = false;
  1172. for (i=0 ; i<MAXPLAYERS ; i++)
  1173. {
  1174. if (!playeringame[i])
  1175. continue;
  1176. cnt_secret[i] += 2;
  1177. // killough 2/22/98: Make secrets = 100% if maxsecret = 0:
  1178. if (cnt_secret[i] >= (wbs->maxsecret ? (plrs[i].ssecret * 100) / wbs->maxsecret : compatibility_level < lxdoom_1_compatibility ? 0 : 100))
  1179. cnt_secret[i] = wbs->maxsecret ? (plrs[i].ssecret * 100) / wbs->maxsecret : 100;
  1180. else
  1181. stillticking = true;
  1182. }
  1183. if (!stillticking)
  1184. {
  1185. S_StartSound(0, sfx_barexp);
  1186. ng_state += 1 + 2*!dofrags;
  1187. }
  1188. }
  1189. else if (ng_state == 8)
  1190. {
  1191. if (!(bcnt&3))
  1192. S_StartSound(0, sfx_pistol);
  1193. stillticking = false;
  1194. for (i=0 ; i<MAXPLAYERS ; i++)
  1195. {
  1196. if (!playeringame[i])
  1197. continue;
  1198. cnt_frags[i] += 1;
  1199. if (cnt_frags[i] >= (fsum = WI_fragSum(i)))
  1200. cnt_frags[i] = fsum;
  1201. else
  1202. stillticking = true;
  1203. }
  1204. if (!stillticking)
  1205. {
  1206. S_StartSound(0, sfx_pldeth);
  1207. ng_state++;
  1208. }
  1209. }
  1210. else if (ng_state == 10)
  1211. {
  1212. if (acceleratestage)
  1213. {
  1214. S_StartSound(0, sfx_sgcock);
  1215. if ( gamemode == commercial )
  1216. WI_initNoState();
  1217. else
  1218. WI_initShowNextLoc();
  1219. }
  1220. }
  1221. else if (ng_state & 1)
  1222. {
  1223. if (!--cnt_pause)
  1224. {
  1225. ng_state++;
  1226. cnt_pause = TICRATE;
  1227. }
  1228. }
  1229. }
  1230. // ====================================================================
  1231. // WI_drawNetgameStats
  1232. // Purpose: Put the coop stats on the screen
  1233. // Args: none
  1234. // Returns: void
  1235. //
  1236. // proff/nicolas 09/20/98 -- changed for hi-res
  1237. // CPhipps - patch drawing updated
  1238. void WI_drawNetgameStats(void)
  1239. {
  1240. int i;
  1241. int x;
  1242. int y;
  1243. int pwidth = V_NamePatchWidth(percent);
  1244. int fwidth = V_NamePatchWidth(facebackp);
  1245. WI_slamBackground();
  1246. // draw animated background
  1247. WI_drawAnimatedBack();
  1248. WI_drawLF();
  1249. // draw stat titles (top line)
  1250. V_DrawNamePatch(NG_STATSX+NG_SPACINGX-V_NamePatchWidth(kills),
  1251. NG_STATSY, FB, kills, CR_DEFAULT, VPT_STRETCH);
  1252. V_DrawNamePatch(NG_STATSX+2*NG_SPACINGX-V_NamePatchWidth(items),
  1253. NG_STATSY, FB, items, CR_DEFAULT, VPT_STRETCH);
  1254. V_DrawNamePatch(NG_STATSX+3*NG_SPACINGX-V_NamePatchWidth(secret),
  1255. NG_STATSY, FB, secret, CR_DEFAULT, VPT_STRETCH);
  1256. if (dofrags)
  1257. V_DrawNamePatch(NG_STATSX+4*NG_SPACINGX-V_NamePatchWidth(frags),
  1258. NG_STATSY, FB, frags, CR_DEFAULT, VPT_STRETCH);
  1259. // draw stats
  1260. y = NG_STATSY + V_NamePatchHeight(kills);
  1261. for (i=0 ; i<MAXPLAYERS ; i++)
  1262. {
  1263. //int trans = playernumtotrans[i];
  1264. if (!playeringame[i])
  1265. continue;
  1266. x = NG_STATSX;
  1267. V_DrawNamePatch(x-fwidth, y, FB, facebackp,
  1268. i ? CR_LIMIT+i : CR_DEFAULT,
  1269. VPT_STRETCH | (i ? VPT_TRANS : 0));
  1270. if (i == me)
  1271. V_DrawNamePatch(x-fwidth, y, FB, star, CR_DEFAULT, VPT_STRETCH);
  1272. x += NG_SPACINGX;
  1273. if (cnt_kills)
  1274. WI_drawPercent(x-pwidth, y+10, cnt_kills[i]);
  1275. x += NG_SPACINGX;
  1276. if (cnt_items)
  1277. WI_drawPercent(x-pwidth, y+10, cnt_items[i]);
  1278. x += NG_SPACINGX;
  1279. if (cnt_secret)
  1280. WI_drawPercent(x-pwidth, y+10, cnt_secret[i]);
  1281. x += NG_SPACINGX;
  1282. if (dofrags && cnt_frags)
  1283. WI_drawNum(x, y+10, cnt_frags[i], -1);
  1284. y += WI_SPACINGY;
  1285. }
  1286. if (y <= SP_TIMEY)
  1287. // cph - show times in coop on the entering screen
  1288. WI_drawTimeStats(plrs[me].stime / TICRATE, wbs->totaltimes / TICRATE, wbs->partime / TICRATE);
  1289. }
  1290. static int sp_state;
  1291. // ====================================================================
  1292. // WI_initStats
  1293. // Purpose: Get ready for single player stats
  1294. // Args: none
  1295. // Returns: void
  1296. // Comment: Seems like we could do all these stats in a more generic
  1297. // set of routines that weren't duplicated for dm, coop, sp
  1298. //
  1299. void WI_initStats(void)
  1300. {
  1301. state = StatCount;
  1302. acceleratestage = 0;
  1303. sp_state = 1;
  1304. // CPhipps - allocate (awful code, I know, but saves changing it all) and initialise
  1305. *(cnt_kills = malloc(sizeof(*cnt_kills))) =
  1306. *(cnt_items = malloc(sizeof(*cnt_items))) =
  1307. *(cnt_secret= malloc(sizeof(*cnt_secret))) = -1;
  1308. cnt_time = cnt_par = cnt_total_time = -1;
  1309. cnt_pause = TICRATE;
  1310. WI_initAnimatedBack();
  1311. }
  1312. // ====================================================================
  1313. // WI_updateStats
  1314. // Purpose: Calculate solo stats
  1315. // Args: none
  1316. // Returns: void
  1317. //
  1318. void WI_updateStats(void)
  1319. {
  1320. WI_updateAnimatedBack();
  1321. if (acceleratestage && sp_state != 10)
  1322. {
  1323. acceleratestage = 0;
  1324. cnt_kills[0] = (plrs[me].skills * 100) / wbs->maxkills;
  1325. cnt_items[0] = (plrs[me].sitems * 100) / wbs->maxitems;
  1326. // killough 2/22/98: Make secrets = 100% if maxsecret = 0:
  1327. cnt_secret[0] = (wbs->maxsecret ?
  1328. (plrs[me].ssecret * 100) / wbs->maxsecret : 100);
  1329. cnt_total_time = wbs->totaltimes / TICRATE;
  1330. cnt_time = plrs[me].stime / TICRATE;
  1331. cnt_par = wbs->partime / TICRATE;
  1332. S_StartSound(0, sfx_barexp);
  1333. sp_state = 10;
  1334. }
  1335. if (sp_state == 2)
  1336. {
  1337. cnt_kills[0] += 2;
  1338. if (!(bcnt&3))
  1339. S_StartSound(0, sfx_pistol);
  1340. if (cnt_kills[0] >= (plrs[me].skills * 100) / wbs->maxkills)
  1341. {
  1342. cnt_kills[0] = (plrs[me].skills * 100) / wbs->maxkills;
  1343. S_StartSound(0, sfx_barexp);
  1344. sp_state++;
  1345. }
  1346. }
  1347. else if (sp_state == 4)
  1348. {
  1349. cnt_items[0] += 2;
  1350. if (!(bcnt&3))
  1351. S_StartSound(0, sfx_pistol);
  1352. if (cnt_items[0] >= (plrs[me].sitems * 100) / wbs->maxitems)
  1353. {
  1354. cnt_items[0] = (plrs[me].sitems * 100) / wbs->maxitems;
  1355. S_StartSound(0, sfx_barexp);
  1356. sp_state++;
  1357. }
  1358. }
  1359. else if (sp_state == 6)
  1360. {
  1361. cnt_secret[0] += 2;
  1362. if (!(bcnt&3))
  1363. S_StartSound(0, sfx_pistol);
  1364. // killough 2/22/98: Make secrets = 100% if maxsecret = 0:
  1365. if ((!wbs->maxsecret && compatibility_level < lxdoom_1_compatibility) ||
  1366. cnt_secret[0] >= (wbs->maxsecret ?
  1367. (plrs[me].ssecret * 100) / wbs->maxsecret : 100))
  1368. {
  1369. cnt_secret[0] = (wbs->maxsecret ?
  1370. (plrs[me].ssecret * 100) / wbs->maxsecret : 100);
  1371. S_StartSound(0, sfx_barexp);
  1372. sp_state++;
  1373. }
  1374. }
  1375. else if (sp_state == 8)
  1376. {
  1377. int time_done, total_done, par_done; // finished counting?
  1378. int time_just, total_just, par_just; // _just_ finished counting?
  1379. // Test if counter is below target, then increment, and test again
  1380. // If the first is false and the second true, we've just gone over
  1381. #define UPDATE_COUNT(count, inc, target, done, just) \
  1382. (just) = ((count) >= (target)); \
  1383. (count) += (inc); \
  1384. (done) = ((count) >= (target)); \
  1385. (just) = (!(just) && (done)); \
  1386. if ((done)) (count) = (target);
  1387. UPDATE_COUNT(cnt_time, 3, (plrs[me].stime / TICRATE),
  1388. time_done, time_just);
  1389. UPDATE_COUNT(cnt_total_time, 3, (wbs->totaltimes / TICRATE),
  1390. total_done, total_just);
  1391. UPDATE_COUNT(cnt_par, 3, (wbs->partime / TICRATE),
  1392. par_done, par_just);
  1393. #undef UPDATE_COUNT
  1394. // If all three timers are finished, play explosion and bump state
  1395. // Ignore total time or par time if not counted or displayed
  1396. if (time_done
  1397. && (total_done || compatibility_level < lxdoom_1_compatibility)
  1398. && (par_done || (modifiedgame && !deh_pars)))
  1399. {
  1400. // Only play explosion once when counter has just finished
  1401. if (time_just
  1402. || (total_just && compatibility_level >= lxdoom_1_compatibility)
  1403. || (par_just && (!modifiedgame || deh_pars)))
  1404. S_StartSound(0, sfx_barexp);
  1405. // Fast-forward total time in old complevels
  1406. if (compatibility_level < lxdoom_1_compatibility)
  1407. cnt_total_time = (wbs->totaltimes / TICRATE);
  1408. // Only bump state if par timer has actually finished (demosync)
  1409. if (par_done)
  1410. {
  1411. sp_state++;
  1412. // Make sure all the counters have reached their targets
  1413. cnt_time = (plrs[me].stime / TICRATE);
  1414. cnt_total_time = (wbs->totaltimes / TICRATE);
  1415. cnt_par = (wbs->partime / TICRATE);
  1416. }
  1417. }
  1418. // Otherwise, if any of the timers are still going, play gunshots
  1419. else
  1420. {
  1421. if (!(bcnt&3))
  1422. S_StartSound(0, sfx_pistol);
  1423. }
  1424. }
  1425. else if (sp_state == 10)
  1426. {
  1427. if (acceleratestage)
  1428. {
  1429. S_StartSound(0, sfx_sgcock);
  1430. if (gamemode == commercial)
  1431. WI_initNoState();
  1432. else
  1433. WI_initShowNextLoc();
  1434. }
  1435. }
  1436. else if (sp_state & 1)
  1437. {
  1438. if (!--cnt_pause)
  1439. {
  1440. sp_state++;
  1441. cnt_pause = TICRATE;
  1442. }
  1443. }
  1444. }
  1445. // ====================================================================
  1446. // WI_drawStats
  1447. // Purpose: Put the solo stats on the screen
  1448. // Args: none
  1449. // Returns: void
  1450. //
  1451. // proff/nicolas 09/20/98 -- changed for hi-res
  1452. // CPhipps - patch drawing updated
  1453. void WI_drawStats(void)
  1454. {
  1455. // line height
  1456. int lh;
  1457. lh = (3*num[0].height)/2;
  1458. WI_slamBackground();
  1459. // draw animated background
  1460. WI_drawAnimatedBack();
  1461. WI_drawLF();
  1462. V_DrawNamePatch(SP_STATSX, SP_STATSY, FB, kills, CR_DEFAULT, VPT_STRETCH);
  1463. if (cnt_kills)
  1464. WI_drawPercent(320 - SP_STATSX, SP_STATSY, cnt_kills[0]);
  1465. V_DrawNamePatch(SP_STATSX, SP_STATSY+lh, FB, items, CR_DEFAULT, VPT_STRETCH);
  1466. if (cnt_items)
  1467. WI_drawPercent(320 - SP_STATSX, SP_STATSY+lh, cnt_items[0]);
  1468. V_DrawNamePatch(SP_STATSX, SP_STATSY+2*lh, FB, sp_secret, CR_DEFAULT, VPT_STRETCH);
  1469. if (cnt_secret)
  1470. WI_drawPercent(320 - SP_STATSX, SP_STATSY+2*lh, cnt_secret[0]);
  1471. WI_drawTimeStats(cnt_time, cnt_total_time, cnt_par);
  1472. }
  1473. // ====================================================================
  1474. // WI_checkForAccelerate
  1475. // Purpose: See if the player has hit either the attack or use key
  1476. // or mouse button. If so we set acceleratestage to 1 and
  1477. // all those display routines above jump right to the end.
  1478. // Args: none
  1479. // Returns: void
  1480. //
  1481. void WI_checkForAccelerate(void)
  1482. {
  1483. int i;
  1484. player_t *player;
  1485. // check for button presses to skip delays
  1486. for (i=0, player = players ; i<MAXPLAYERS ; i++, player++)
  1487. {
  1488. if (playeringame[i])
  1489. {
  1490. if (player->cmd.buttons & BT_ATTACK)
  1491. {
  1492. if (!player->attackdown)
  1493. acceleratestage = 1;
  1494. player->attackdown = true;
  1495. }
  1496. else
  1497. player->attackdown = false;
  1498. if (player->cmd.buttons & BT_USE)
  1499. {
  1500. if (!player->usedown)
  1501. acceleratestage = 1;
  1502. player->usedown = true;
  1503. }
  1504. else
  1505. player->usedown = false;
  1506. }
  1507. }
  1508. }
  1509. // ====================================================================
  1510. // WI_Ticker
  1511. // Purpose: Do various updates every gametic, for stats, animation,
  1512. // checking that intermission music is running, etc.
  1513. // Args: none
  1514. // Returns: void
  1515. //
  1516. void WI_Ticker(void)
  1517. {
  1518. // counter for general background animation
  1519. bcnt++;
  1520. if (bcnt == 1)
  1521. {
  1522. // intermission music
  1523. if ( gamemode == commercial )
  1524. S_ChangeMusic(mus_dm2int, true);
  1525. else
  1526. S_ChangeMusic(mus_inter, true);
  1527. }
  1528. WI_checkForAccelerate();
  1529. switch (state)
  1530. {
  1531. case StatCount:
  1532. if (deathmatch) WI_updateDeathmatchStats();
  1533. else if (netgame) WI_updateNetgameStats();
  1534. else WI_updateStats();
  1535. break;
  1536. case ShowNextLoc:
  1537. WI_updateShowNextLoc();
  1538. break;
  1539. case NoState:
  1540. WI_updateNoState();
  1541. break;
  1542. }
  1543. }
  1544. /* ====================================================================
  1545. * WI_loadData
  1546. * Purpose: Initialize intermission data such as background graphics,
  1547. * patches, map names, etc.
  1548. * Args: none
  1549. * Returns: void
  1550. *
  1551. * CPhipps - modified for new wad lump handling.
  1552. * - no longer preload most graphics, other funcs can use
  1553. * them by name
  1554. */
  1555. void WI_loadData(void)
  1556. {
  1557. int i;
  1558. int j;
  1559. char name[9]; // limited to 8 characters
  1560. anim_t* a;
  1561. if (gamemode != commercial)
  1562. {
  1563. if (wbs->epsd < 3)
  1564. {
  1565. for (j=0;j<NUMANIMS[wbs->epsd];j++)
  1566. {
  1567. a = &anims[wbs->epsd][j];
  1568. for (i=0;i<a->nanims;i++)
  1569. {
  1570. // MONDO HACK!
  1571. if (wbs->epsd != 1 || j != 8)
  1572. {
  1573. // animations
  1574. sprintf(name, "WIA%d%.2d%.2d", wbs->epsd, j, i);
  1575. R_SetPatchNum(&a->p[i], name);
  1576. }
  1577. else
  1578. {
  1579. // HACK ALERT!
  1580. a->p[i] = anims[1][4].p[i];
  1581. }
  1582. }
  1583. }
  1584. }
  1585. }
  1586. for (i=0;i<10;i++)
  1587. {
  1588. // numbers 0-9
  1589. sprintf(name, "WINUM%d", i);
  1590. R_SetPatchNum(&num[i], name);
  1591. }
  1592. }
  1593. // ====================================================================
  1594. // WI_Drawer
  1595. // Purpose: Call the appropriate stats drawing routine depending on
  1596. // what kind of game is being played (DM, coop, solo)
  1597. // Args: none
  1598. // Returns: void
  1599. //
  1600. void WI_Drawer (void)
  1601. {
  1602. switch (state)
  1603. {
  1604. case StatCount:
  1605. if (deathmatch)
  1606. WI_drawDeathmatchStats();
  1607. else if (netgame)
  1608. WI_drawNetgameStats();
  1609. else
  1610. WI_drawStats();
  1611. break;
  1612. case ShowNextLoc:
  1613. WI_drawShowNextLoc();
  1614. break;
  1615. case NoState:
  1616. WI_drawNoState();
  1617. break;
  1618. }
  1619. }
  1620. // ====================================================================
  1621. // WI_initVariables
  1622. // Purpose: Initialize the intermission information structure
  1623. // Note: wbstartstruct_t is defined in d_player.h
  1624. // Args: wbstartstruct -- pointer to the structure with the data
  1625. // Returns: void
  1626. //
  1627. void WI_initVariables(wbstartstruct_t* wbstartstruct)
  1628. {
  1629. wbs = wbstartstruct;
  1630. #ifdef RANGECHECKING
  1631. if (gamemode != commercial)
  1632. {
  1633. if ( gamemode == retail )
  1634. RNGCHECK(wbs->epsd, 0, 3);
  1635. else
  1636. RNGCHECK(wbs->epsd, 0, 2);
  1637. }
  1638. else
  1639. {
  1640. RNGCHECK(wbs->last, 0, 8);
  1641. RNGCHECK(wbs->next, 0, 8);
  1642. }
  1643. RNGCHECK(wbs->pnum, 0, MAXPLAYERS);
  1644. RNGCHECK(wbs->pnum, 0, MAXPLAYERS);
  1645. #endif
  1646. acceleratestage = 0;
  1647. cnt = bcnt = 0;
  1648. firstrefresh = 1;
  1649. me = wbs->pnum;
  1650. plrs = wbs->plyr;
  1651. if (!wbs->maxkills)
  1652. wbs->maxkills = 1; // probably only useful in MAP30
  1653. if (!wbs->maxitems)
  1654. wbs->maxitems = 1;
  1655. if ( gamemode != retail )
  1656. if (wbs->epsd > 2)
  1657. wbs->epsd -= 3;
  1658. }
  1659. // ====================================================================
  1660. // WI_Start
  1661. // Purpose: Call the various init routines
  1662. // Note: wbstartstruct_t is defined in d_player.h
  1663. // Args: wbstartstruct -- pointer to the structure with the
  1664. // intermission data
  1665. // Returns: void
  1666. //
  1667. void WI_Start(wbstartstruct_t* wbstartstruct)
  1668. {
  1669. WI_initVariables(wbstartstruct);
  1670. WI_loadData();
  1671. if (deathmatch)
  1672. WI_initDeathmatchStats();
  1673. else if (netgame)
  1674. WI_initNetgameStats();
  1675. else
  1676. WI_initStats();
  1677. }