Debian Codegraph @

prboom2/src/hexen/in_lude.c

raw
1 //
2 // Copyright(C) 1993-1996 Id Software, Inc.
3 // Copyright(C) 1993-2008 Raven Software
4 // Copyright(C) 2005-2014 Simon Howard
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16
17 #include "am_map.h"
18 #include "doomstat.h"
19 #include "d_event.h"
20 #include "s_sound.h"
21 #include "sounds.h"
22 #include "i_system.h"
23 #include "i_video.h"
24 #include "v_video.h"
25 #include "lprintf.h"
26 #include "w_wad.h"
27 #include "g_game.h"
28 #include "p_setup.h"
29
30 #include "dsda/exhud.h"
31 #include "dsda/mapinfo.h"
32
33 #include "heretic/mn_menu.h"
34 #include "heretic/sb_bar.h"
35
36 #include "hexen/sn_sonix.h"
37
38 #include "in_lude.h"
39
40 #define TEXTSPEED 3
41 #define TEXTWAIT 140
42
43 typedef enum
44 {
45 SINGLE,
46 COOPERATIVE,
47 DEATHMATCH
48 } gametype_t;
49
50 static void WaitStop(void);
51 static void Stop(void);
52 static void LoadPics(void);
53 static void CheckForSkip(void);
54 static void InitStats(void);
55 static void DrDeathTally(void);
56 static void DrNumber(int val, int x, int y, int wrapThresh);
57 static void DrNumberBold(int val, int x, int y, int wrapThresh);
58 static void DrawHubText(void);
59
60 static dboolean intermission;
61 char ClusterMessage[MAX_INTRMSN_MESSAGE_SIZE];
62
63 static dboolean skipintermission;
64 static int interstate = 0;
65 static int intertime = -1;
66 static gametype_t gametype;
67 static int cnt;
68 static int slaughterboy; // in DM, the player with the most kills
69 static int FontABaseLump;
70
71 static signed int totalFrags[MAX_MAXPLAYERS];
72
73 static int HubCount;
74 static char *HubText;
75
76 extern dboolean BorderNeedRefresh;
77
78 void Hexen_IN_Start(wbstartstruct_t* wbstartstruct)
79 {
80 V_SetPalette(0);
81 InitStats();
82 LoadPics();
83 intermission = true;
84 interstate = 0;
85 skipintermission = false;
86 intertime = 0;
87 AM_Stop(false);
88 SN_StopAllSequences();
89 }
90
91 static void WaitStop(void)
92 {
93 if (!--cnt)
94 {
95 Stop();
96 gameaction = ga_leavemap;
97 }
98 }
99
100 static void Stop(void)
101 {
102 intermission = false;
103 SB_Start();
104 BorderNeedRefresh = true;
105 }
106
107 static const char *ClusMsgLumpNames[] = {
108 "clus1msg",
109 "clus2msg",
110 "clus3msg",
111 "clus4msg",
112 "clus5msg"
113 };
114
115 static void InitStats(void)
116 {
117 int i;
118 int j;
119 int oldCluster;
120 signed int slaughterfrags;
121 int slaughtercount;
122 int playercount;
123 const char *msgLumpName;
124 int msgSize;
125 int msgLump;
126
127 if (!deathmatch)
128 {
129 gametype = SINGLE;
130 HubCount = 0;
131 oldCluster = dsda_MapCluster(gamemap);
132 if (oldCluster != dsda_MapCluster(leave_data.map))
133 {
134 if (oldCluster >= 1 && oldCluster <= 5)
135 {
136 msgLumpName = ClusMsgLumpNames[oldCluster - 1];
137 msgLump = W_GetNumForName(msgLumpName);
138 msgSize = W_LumpLength(msgLump);
139 if (msgSize >= MAX_INTRMSN_MESSAGE_SIZE)
140 {
141 I_Error("Cluster message too long (%s)", msgLumpName);
142 }
143 memcpy(ClusterMessage, W_LumpByNum(msgLump), msgSize);
144 ClusterMessage[msgSize] = '\0'; // Append terminator
145 HubText = ClusterMessage;
146 HubCount = strlen(HubText) * TEXTSPEED + TEXTWAIT;
147 S_StartSongName("hub", true);
148 }
149 }
150 }
151 else
152 {
153 gametype = DEATHMATCH;
154 slaughterboy = 0;
155 slaughterfrags = -9999;
156 playercount = 0;
157 slaughtercount = 0;
158 for (i = 0; i < g_maxplayers; i++)
159 {
160 totalFrags[i] = 0;
161 if (playeringame[i])
162 {
163 playercount++;
164 for (j = 0; j < g_maxplayers; j++)
165 {
166 if (playeringame[j])
167 {
168 totalFrags[i] += players[i].frags[j];
169 }
170 }
171 }
172 if (totalFrags[i] > slaughterfrags)
173 {
174 slaughterboy = 1 << i;
175 slaughterfrags = totalFrags[i];
176 slaughtercount = 1;
177 }
178 else if (totalFrags[i] == slaughterfrags)
179 {
180 slaughterboy |= 1 << i;
181 slaughtercount++;
182 }
183 }
184 if (playercount == slaughtercount)
185 { // don't do the slaughter stuff if everyone is equal
186 slaughterboy = 0;
187 }
188 S_StartSongName("hub", true);
189 }
190 }
191
192 static void LoadPics(void)
193 {
194 if (HubCount || gametype == DEATHMATCH)
195 {
196 FontABaseLump = W_GetNumForName("FONTA_S") + 1;
197 }
198 }
199
200 void Hexen_IN_Ticker(void)
201 {
202 if (!intermission)
203 {
204 return;
205 }
206 if (interstate)
207 {
208 WaitStop();
209 return;
210 }
211 skipintermission = false;
212 CheckForSkip();
213 intertime++;
214 if (skipintermission || (gametype == SINGLE && !HubCount))
215 {
216 interstate = 1;
217 cnt = 10;
218 skipintermission = false;
219 }
220 }
221
222 static void CheckForSkip(void)
223 {
224 int i;
225 player_t *player;
226 static dboolean triedToSkip;
227
228 for (i = 0, player = players; i < g_maxplayers; i++, player++)
229 {
230 if (playeringame[i])
231 {
232 if (player->cmd.buttons & BT_ATTACK)
233 {
234 if (!player->attackdown)
235 {
236 skipintermission = 1;
237 }
238 player->attackdown = true;
239 }
240 else
241 {
242 player->attackdown = false;
243 }
244 if (player->cmd.buttons & BT_USE)
245 {
246 if (!player->usedown)
247 {
248 skipintermission = 1;
249 }
250 player->usedown = true;
251 }
252 else
253 {
254 player->usedown = false;
255 }
256 }
257 }
258 if (deathmatch && intertime < 140)
259 { // wait for 4 seconds before allowing a skip
260 if (skipintermission == 1)
261 {
262 triedToSkip = true;
263 skipintermission = 0;
264 }
265 }
266 else
267 {
268 if (triedToSkip)
269 {
270 skipintermission = 1;
271 triedToSkip = false;
272 }
273 }
274 }
275
276 void Hexen_IN_Drawer(void)
277 {
278 if (!intermission)
279 {
280 return;
281 }
282 if (interstate)
283 {
284 return;
285 }
286
287 V_DrawRawScreen("INTERPIC");
288
289 if (gametype == SINGLE)
290 {
291 if (HubCount)
292 {
293 DrawHubText();
294 }
295 dsda_DrawExIntermission();
296 }
297 else
298 {
299 DrDeathTally();
300 }
301 }
302
303 #define TALLY_EFFECT_TICKS 20
304 #define TALLY_FINAL_X_DELTA (23*FRACUNIT)
305 #define TALLY_FINAL_Y_DELTA (13*FRACUNIT)
306 #define TALLY_START_XPOS (178*FRACUNIT)
307 #define TALLY_STOP_XPOS (90*FRACUNIT)
308 #define TALLY_START_YPOS (132*FRACUNIT)
309 #define TALLY_STOP_YPOS (83*FRACUNIT)
310 #define TALLY_TOP_X 85
311 #define TALLY_TOP_Y 9
312 #define TALLY_LEFT_X 7
313 #define TALLY_LEFT_Y 71
314 #define TALLY_TOTALS_X 291
315
316 static void DrDeathTally(void)
317 {
318 int i, j;
319 fixed_t xPos, yPos;
320 fixed_t xDelta, yDelta;
321 fixed_t xStart, scale;
322 int x, y;
323 dboolean bold;
324 static dboolean showTotals;
325 int temp;
326
327 V_DrawNamePatch(TALLY_TOP_X, TALLY_TOP_Y, 0, "tallytop", CR_DEFAULT, VPT_STRETCH);
328 V_DrawNamePatch(TALLY_LEFT_X, TALLY_LEFT_Y, 0, "tallylft", CR_DEFAULT, VPT_STRETCH);
329 if (intertime < TALLY_EFFECT_TICKS)
330 {
331 showTotals = false;
332 scale = (intertime * FRACUNIT) / TALLY_EFFECT_TICKS;
333 xDelta = FixedMul(scale, TALLY_FINAL_X_DELTA);
334 yDelta = FixedMul(scale, TALLY_FINAL_Y_DELTA);
335 xStart = TALLY_START_XPOS - FixedMul(scale,
336 TALLY_START_XPOS -
337 TALLY_STOP_XPOS);
338 yPos =
339 TALLY_START_YPOS - FixedMul(scale,
340 TALLY_START_YPOS - TALLY_STOP_YPOS);
341 }
342 else
343 {
344 xDelta = TALLY_FINAL_X_DELTA;
345 yDelta = TALLY_FINAL_Y_DELTA;
346 xStart = TALLY_STOP_XPOS;
347 yPos = TALLY_STOP_YPOS;
348 }
349 if (intertime >= TALLY_EFFECT_TICKS && showTotals == false)
350 {
351 showTotals = true;
352 S_StartVoidSound(hexen_sfx_platform_stop);
353 }
354 y = yPos >> FRACBITS;
355 for (i = 0; i < g_maxplayers; i++)
356 {
357 xPos = xStart;
358 for (j = 0; j < g_maxplayers; j++, xPos += xDelta)
359 {
360 x = xPos >> FRACBITS;
361 bold = (i == consoleplayer || j == consoleplayer);
362 if (playeringame[i] && playeringame[j])
363 {
364 if (bold)
365 {
366 DrNumberBold(players[i].frags[j], x, y, 100);
367 }
368 else
369 {
370 DrNumber(players[i].frags[j], x, y, 100);
371 }
372 }
373 else
374 {
375 temp = MN_TextAWidth("--") / 2;
376 if (bold)
377 {
378 MN_DrTextAYellow("--", x - temp, y);
379 }
380 else
381 {
382 MN_DrTextA("--", x - temp, y);
383 }
384 }
385 }
386 if (showTotals && playeringame[i]
387 && !((slaughterboy & (1 << i)) && !(intertime & 16)))
388 {
389 DrNumber(totalFrags[i], TALLY_TOTALS_X, y, 1000);
390 }
391 yPos += yDelta;
392 y = yPos >> FRACBITS;
393 }
394 }
395
396 static void DrNumber(int val, int x, int y, int wrapThresh)
397 {
398 char buff[8] = "XX";
399
400 if (!(val < -9 && wrapThresh < 1000))
401 {
402 snprintf(buff, sizeof(buff), "%d", val >= wrapThresh ? val % wrapThresh : val);
403 }
404 MN_DrTextA(buff, x - MN_TextAWidth(buff) / 2, y);
405 }
406
407 static void DrNumberBold(int val, int x, int y, int wrapThresh)
408 {
409 char buff[8] = "XX";
410
411 if (!(val < -9 && wrapThresh < 1000))
412 {
413 snprintf(buff, sizeof(buff), "%d", val >= wrapThresh ? val % wrapThresh : val);
414 }
415 MN_DrTextAYellow(buff, x - MN_TextAWidth(buff) / 2, y);
416 }
417
418 static void DrawHubText(void)
419 {
420 int count;
421 char *ch;
422 int c;
423 int cx, cy;
424 int lump;
425 int width;
426
427 cy = 5;
428 cx = 10;
429 ch = HubText;
430 count = (intertime - 10) / TEXTSPEED;
431 if (count < 0)
432 {
433 count = 0;
434 }
435 for (; count; count--)
436 {
437 c = *ch++;
438 if (!c)
439 {
440 break;
441 }
442 if (c == '\n')
443 {
444 cx = 10;
445 cy += 9;
446 continue;
447 }
448 if (c < 32)
449 {
450 continue;
451 }
452 c = toupper(c);
453 if (c == 32)
454 {
455 cx += 5;
456 continue;
457 }
458 lump = FontABaseLump + c - 33;
459 width = R_NumPatchWidth(lump);
460 if (cx + width > SCREENWIDTH)
461 {
462 break;
463 }
464 V_DrawNumPatch(cx, cy, 0, lump, CR_DEFAULT, VPT_STRETCH);
465 cx += width;
466 }
467 }