F_FINALE.C 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. //**************************************************************************
  2. //**
  3. //** f_finale.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: f_finale.c,v $
  6. //** $Revision: 1.7 $
  7. //** $Date: 96/01/05 23:33:26 $
  8. //** $Author: bgokey $
  9. //**
  10. //**************************************************************************
  11. // HEADER FILES ------------------------------------------------------------
  12. #include "h2def.h"
  13. #include "soundst.h"
  14. #include "p_local.h"
  15. #include <ctype.h>
  16. // MACROS ------------------------------------------------------------------
  17. #define TEXTSPEED 3
  18. #define TEXTWAIT 250
  19. // TYPES -------------------------------------------------------------------
  20. // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
  21. // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
  22. // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
  23. static void TextWrite(void);
  24. static void DrawPic(void);
  25. static void InitializeFade(boolean fadeIn);
  26. static void DeInitializeFade(void);
  27. static void FadePic(void);
  28. static char *GetFinaleText(int sequence);
  29. // EXTERNAL DATA DECLARATIONS ----------------------------------------------
  30. extern boolean automapactive;
  31. extern boolean viewactive;
  32. // PUBLIC DATA DECLARATIONS ------------------------------------------------
  33. // PRIVATE DATA DEFINITIONS ------------------------------------------------
  34. static int FinaleStage;
  35. static int FinaleCount;
  36. static int FinaleEndCount;
  37. static int FinaleLumpNum;
  38. static int FontABaseLump;
  39. static char *FinaleText;
  40. static fixed_t *Palette;
  41. static fixed_t *PaletteDelta;
  42. static byte *RealPalette;
  43. // CODE --------------------------------------------------------------------
  44. //===========================================================================
  45. //
  46. // F_StartFinale
  47. //
  48. //===========================================================================
  49. void F_StartFinale (void)
  50. {
  51. gameaction = ga_nothing;
  52. gamestate = GS_FINALE;
  53. viewactive = false;
  54. automapactive = false;
  55. P_ClearMessage(&players[consoleplayer]);
  56. FinaleStage = 0;
  57. FinaleCount = 0;
  58. FinaleText = GetFinaleText(0);
  59. FinaleEndCount = 70;
  60. FinaleLumpNum = W_GetNumForName("FINALE1");
  61. FontABaseLump = W_GetNumForName("FONTA_S")+1;
  62. InitializeFade(1);
  63. // S_ChangeMusic(mus_victor, true);
  64. S_StartSongName("hall", false); // don't loop the song
  65. }
  66. //===========================================================================
  67. //
  68. // F_Responder
  69. //
  70. //===========================================================================
  71. boolean F_Responder(event_t *event)
  72. {
  73. return false;
  74. }
  75. //===========================================================================
  76. //
  77. // F_Ticker
  78. //
  79. //===========================================================================
  80. void F_Ticker (void)
  81. {
  82. FinaleCount++;
  83. if(FinaleStage < 5 && FinaleCount >= FinaleEndCount)
  84. {
  85. FinaleCount = 0;
  86. FinaleStage++;
  87. switch(FinaleStage)
  88. {
  89. case 1: // Text 1
  90. FinaleEndCount = strlen(FinaleText)*TEXTSPEED+TEXTWAIT;
  91. break;
  92. case 2: // Pic 2, Text 2
  93. FinaleText = GetFinaleText(1);
  94. FinaleEndCount = strlen(FinaleText)*TEXTSPEED+TEXTWAIT;
  95. FinaleLumpNum = W_GetNumForName("FINALE2");
  96. S_StartSongName("orb", false);
  97. break;
  98. case 3: // Pic 2 -- Fade out
  99. FinaleEndCount = 70;
  100. DeInitializeFade();
  101. InitializeFade(0);
  102. break;
  103. case 4: // Pic 3 -- Fade in
  104. FinaleLumpNum = W_GetNumForName("FINALE3");
  105. FinaleEndCount = 71;
  106. DeInitializeFade();
  107. InitializeFade(1);
  108. S_StartSongName("chess", true);
  109. break;
  110. case 5: // Pic 3 , Text 3
  111. FinaleText = GetFinaleText(2);
  112. DeInitializeFade();
  113. break;
  114. default:
  115. break;
  116. }
  117. return;
  118. }
  119. if(FinaleStage == 0 || FinaleStage == 3 || FinaleStage == 4)
  120. {
  121. FadePic();
  122. }
  123. }
  124. //===========================================================================
  125. //
  126. // TextWrite
  127. //
  128. //===========================================================================
  129. static void TextWrite (void)
  130. {
  131. int count;
  132. char *ch;
  133. int c;
  134. int cx, cy;
  135. patch_t *w;
  136. memcpy(screen, W_CacheLumpNum(FinaleLumpNum, PU_CACHE),
  137. SCREENWIDTH*SCREENHEIGHT);
  138. if(FinaleStage == 5)
  139. { // Chess pic, draw the correct character graphic
  140. if(netgame)
  141. {
  142. V_DrawPatch(20, 0, W_CacheLumpName("chessall", PU_CACHE));
  143. }
  144. else if(PlayerClass[consoleplayer])
  145. {
  146. V_DrawPatch(60, 0, W_CacheLumpNum(W_GetNumForName("chessc")
  147. +PlayerClass[consoleplayer]-1, PU_CACHE));
  148. }
  149. }
  150. // Draw the actual text
  151. if(FinaleStage == 5)
  152. {
  153. cy = 135;
  154. }
  155. else
  156. {
  157. cy = 5;
  158. }
  159. cx = 20;
  160. ch = FinaleText;
  161. count = (FinaleCount-10)/TEXTSPEED;
  162. if (count < 0)
  163. {
  164. count = 0;
  165. }
  166. for(; count; count--)
  167. {
  168. c = *ch++;
  169. if(!c)
  170. {
  171. break;
  172. }
  173. if(c == '\n')
  174. {
  175. cx = 20;
  176. cy += 9;
  177. continue;
  178. }
  179. if(c < 32)
  180. {
  181. continue;
  182. }
  183. c = toupper(c);
  184. if(c == 32)
  185. {
  186. cx += 5;
  187. continue;
  188. }
  189. w = W_CacheLumpNum(FontABaseLump+c-33, PU_CACHE);
  190. if(cx+w->width > SCREENWIDTH)
  191. {
  192. break;
  193. }
  194. V_DrawPatch(cx, cy, w);
  195. cx += w->width;
  196. }
  197. }
  198. //===========================================================================
  199. //
  200. // InitializeFade
  201. //
  202. //===========================================================================
  203. static void InitializeFade(boolean fadeIn)
  204. {
  205. unsigned i;
  206. Palette = Z_Malloc(768*sizeof(fixed_t), PU_STATIC, 0);
  207. PaletteDelta = Z_Malloc(768*sizeof(fixed_t), PU_STATIC, 0);
  208. RealPalette = Z_Malloc(768*sizeof(byte), PU_STATIC, 0);
  209. if(fadeIn)
  210. {
  211. memset(RealPalette, 0, 768*sizeof(byte));
  212. for(i = 0; i < 768; i++)
  213. {
  214. Palette[i] = 0;
  215. PaletteDelta[i] = FixedDiv((*((byte *)W_CacheLumpName("playpal",
  216. PU_CACHE)+i))<<FRACBITS, 70*FRACUNIT);
  217. }
  218. }
  219. else
  220. {
  221. for(i = 0; i < 768; i++)
  222. {
  223. RealPalette[i] = *((byte *)W_CacheLumpName("playpal", PU_CACHE)+i);
  224. Palette[i] = RealPalette[i]<<FRACBITS;
  225. PaletteDelta[i] = FixedDiv(Palette[i], -70*FRACUNIT);
  226. }
  227. }
  228. I_SetPalette(RealPalette);
  229. }
  230. //===========================================================================
  231. //
  232. // DeInitializeFade
  233. //
  234. //===========================================================================
  235. static void DeInitializeFade(void)
  236. {
  237. Z_Free(Palette);
  238. Z_Free(PaletteDelta);
  239. Z_Free(RealPalette);
  240. }
  241. //===========================================================================
  242. //
  243. // FadePic
  244. //
  245. //===========================================================================
  246. static void FadePic(void)
  247. {
  248. unsigned i;
  249. for(i = 0; i < 768; i++)
  250. {
  251. Palette[i] += PaletteDelta[i];
  252. RealPalette[i] = Palette[i]>>FRACBITS;
  253. }
  254. I_SetPalette(RealPalette);
  255. }
  256. //===========================================================================
  257. //
  258. // DrawPic
  259. //
  260. //===========================================================================
  261. static void DrawPic(void)
  262. {
  263. memcpy(screen, W_CacheLumpNum(FinaleLumpNum, PU_CACHE),
  264. SCREENWIDTH*SCREENHEIGHT);
  265. if(FinaleStage == 4 || FinaleStage == 5)
  266. { // Chess pic, draw the correct character graphic
  267. if(netgame)
  268. {
  269. V_DrawPatch(20, 0, W_CacheLumpName("chessall", PU_CACHE));
  270. }
  271. else if(PlayerClass[consoleplayer])
  272. {
  273. V_DrawPatch(60, 0, W_CacheLumpNum(W_GetNumForName("chessc")
  274. +PlayerClass[consoleplayer]-1, PU_CACHE));
  275. }
  276. }
  277. }
  278. //===========================================================================
  279. //
  280. // F_Drawer
  281. //
  282. //===========================================================================
  283. void F_Drawer(void)
  284. {
  285. switch(FinaleStage)
  286. {
  287. case 0: // Fade in initial finale screen
  288. DrawPic();
  289. break;
  290. case 1:
  291. case 2:
  292. TextWrite();
  293. break;
  294. case 3: // Fade screen out
  295. DrawPic();
  296. break;
  297. case 4: // Fade in chess screen
  298. DrawPic();
  299. break;
  300. case 5:
  301. TextWrite();
  302. break;
  303. }
  304. UpdateState |= I_FULLSCRN;
  305. }
  306. //==========================================================================
  307. //
  308. // GetFinaleText
  309. //
  310. //==========================================================================
  311. static char *GetFinaleText(int sequence)
  312. {
  313. char *msgLumpName;
  314. int msgSize;
  315. int msgLump;
  316. static char *winMsgLumpNames[] =
  317. {
  318. "win1msg",
  319. "win2msg",
  320. "win3msg"
  321. };
  322. msgLumpName = winMsgLumpNames[sequence];
  323. msgLump = W_GetNumForName(msgLumpName);
  324. msgSize = W_LumpLength(msgLump);
  325. if(msgSize >= MAX_INTRMSN_MESSAGE_SIZE)
  326. {
  327. I_Error("Finale message too long (%s)", msgLumpName);
  328. }
  329. W_ReadLump(msgLump, ClusterMessage);
  330. ClusterMessage[msgSize] = 0; // Append terminator
  331. return ClusterMessage;
  332. }