y_inter.c 57.8 KB
Newer Older
Alam Ed Arias committed
1 2
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
James R. committed
3
// Copyright (C) 2004-2020 by Sonic Team Junior.
Alam Ed Arias committed
4 5 6 7 8 9
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file  y_inter.c
10
/// \brief Tally screens, or "Intermissions" as they were formally called in Doom
Alam Ed Arias committed
11 12 13 14 15 16 17 18 19 20 21

#include "doomdef.h"
#include "doomstat.h"
#include "d_main.h"
#include "f_finale.h"
#include "g_game.h"
#include "hu_stuff.h"
#include "i_net.h"
#include "i_video.h"
#include "p_tick.h"
#include "r_defs.h"
22
#include "r_skins.h"
Alam Ed Arias committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include "s_sound.h"
#include "st_stuff.h"
#include "v_video.h"
#include "w_wad.h"
#include "y_inter.h"
#include "z_zone.h"
#include "m_menu.h"
#include "m_misc.h"
#include "i_system.h"
#include "p_setup.h"

#include "r_local.h"
#include "p_local.h"

#include "m_cond.h" // condition sets
SteelT committed
38
#include "lua_hook.h" // IntermissionThinker hook
Alam Ed Arias committed
39

40 41
#include "lua_hud.h"

Alam Ed Arias committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#ifdef HWRENDER
#include "hardware/hw_main.h"
#endif

typedef struct
{
	char patch[9];
	 INT32 points;
	UINT8 display;
} y_bonus_t;

typedef union
{
	struct
	{
57
		char passed1[21]; // KNUCKLES GOT    / CRAWLA HONCHO
Alam Ed Arias committed
58
		char passed2[16]; // THROUGH THE ACT / PASSED THE ACT
Alam Ed Arias committed
59 60 61 62 63 64 65 66 67 68 69
		INT32 passedx1;
		INT32 passedx2;

		y_bonus_t bonuses[4];
		patch_t *bonuspatches[4];

		SINT8 gotperfbonus; // Used for visitation flags.

		UINT32 score, total; // fake score, total
		UINT32 tics; // time

70
		UINT8 actnum; // act number being displayed
Alam Ed Arias committed
71 72 73 74 75 76
		patch_t *ptotal; // TOTAL
		UINT8 gotlife; // Number of extra lives obtained
	} coop;

	struct
	{
77
		char passed1[29];             // KNUCKLES GOT     / CRAWLA HONCHO
toaster committed
78
		char passed2[17];             // A CHAOS EMERALD? / GOT THEM ALL!
79 80
		char passed3[15];             //                   CAN NOW BECOME
		char passed4[SKINNAMESIZE+7]; //                   SUPER CRAWLA HONCHO
Alam Ed Arias committed
81 82
		INT32 passedx1;
		INT32 passedx2;
83 84
		INT32 passedx3;
		INT32 passedx4;
Alam Ed Arias committed
85

86 87
		y_bonus_t bonuses[2];
		patch_t *bonuspatches[2];
Alam Ed Arias committed
88 89 90 91 92 93 94 95

		patch_t *pscore; // SCORE
		UINT32 score; // fake score

		// Continues
		UINT8 continues;
		patch_t *pcontinues;
		INT32 *playerchar; // Continue HUD
96
		UINT16 *playercolor;
Alam Ed Arias committed
97 98 99 100 101 102 103

		UINT8 gotlife; // Number of extra lives obtained
	} spec;

	struct
	{
		UINT32 scores[MAXPLAYERS]; // Winner's score
104
		UINT16 *color[MAXPLAYERS]; // Winner's color #
Alam Ed Arias committed
105 106 107 108 109 110 111 112 113 114 115 116 117
		boolean spectator[MAXPLAYERS]; // Spectator list
		INT32 *character[MAXPLAYERS]; // Winner's character #
		INT32 num[MAXPLAYERS]; // Winner's player #
		char *name[MAXPLAYERS]; // Winner's name
		patch_t *result; // RESULT
		patch_t *blueflag;
		patch_t *redflag; // int_ctf uses this struct too.
		INT32 numplayers; // Number of players being displayed
		char levelstring[40]; // holds levelnames up to 32 characters
	} match;

	struct
	{
118
		UINT16 *color[MAXPLAYERS]; // Winner's color #
Alam Ed Arias committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
		INT32 *character[MAXPLAYERS]; // Winner's character #
		INT32 num[MAXPLAYERS]; // Winner's player #
		char name[MAXPLAYERS][9]; // Winner's name
		UINT32 times[MAXPLAYERS];
		UINT32 rings[MAXPLAYERS];
		UINT32 maxrings[MAXPLAYERS];
		UINT32 monitors[MAXPLAYERS];
		UINT32 scores[MAXPLAYERS];
		UINT32 points[MAXPLAYERS];
		INT32 numplayers; // Number of players being displayed
		char levelstring[40]; // holds levelnames up to 32 characters
	} competition;

} y_data;

static y_data data;

// graphics
static patch_t *bgpatch = NULL;     // INTERSCR
static patch_t *bgtile = NULL;      // SPECTILE/SRB2BACK
static patch_t *interpic = NULL;    // custom picture defined in map header
static boolean usetile;
141 142 143 144 145 146 147 148 149 150 151 152
static INT32 timer;

typedef struct
{
	INT32 source_width, source_height;
	INT32 source_bpp, source_rowbytes;
	UINT8 *source_picture;
	INT32 target_width, target_height;
	INT32 target_bpp, target_rowbytes;
	UINT8 *target_picture;
} y_buffer_t;

Alam Ed Arias committed
153
boolean usebuffer = false;
Alam Ed Arias committed
154
static boolean useinterpic;
155
static y_buffer_t *y_buffer;
Alam Ed Arias committed
156 157

static INT32 intertic;
158
static INT32 tallydonetic = -1;
Alam Ed Arias committed
159 160 161
static INT32 endtic = -1;

intertype_t intertype = int_none;
162
intertype_t intermissiontypes[NUMGAMETYPES];
Alam Ed Arias committed
163

164
static void Y_RescaleScreenBuffer(void);
Alam Ed Arias committed
165 166 167 168 169 170 171
static void Y_AwardCoopBonuses(void);
static void Y_AwardSpecialStageBonus(void);
static void Y_CalculateCompetitionWinners(void);
static void Y_CalculateTimeRaceWinners(void);
static void Y_CalculateMatchWinners(void);
static void Y_UnloadData(void);

172
// Stuff copy+pasted from st_stuff.c
173 174 175
#define ST_DrawNumFromHud(h,n)        V_DrawTallNum(hudinfo[h].x, hudinfo[h].y, hudinfo[h].f, n)
#define ST_DrawPadNumFromHud(h,n,q)   V_DrawPaddedTallNum(hudinfo[h].x, hudinfo[h].y, hudinfo[h].f, n, q)
#define ST_DrawPatchFromHud(h,p)      V_DrawScaledPatch(hudinfo[h].x, hudinfo[h].y, hudinfo[h].f, p)
176

177 178
static void Y_IntermissionTokenDrawer(void)
{
179
	INT32 y, offs, lowy, calc;
180
	UINT32 tokencount;
181 182 183 184 185
	INT16 temp;
	UINT8 em;

	offs = 0;
	lowy = BASEVIDHEIGHT - 32 - 8;
186
	temp = tokenicon->height / 2;
187

188 189 190 191
	em = 0;
	while (emeralds & (1 << em))
		if (++em == 7)
			return;
192 193 194 195 196 197 198 199

	if (tallydonetic != -1)
	{
		offs = (intertic - tallydonetic)*2;
		if (offs > 10)
			offs = 8;
	}

200
	V_DrawSmallScaledPatch(32, lowy-1, 0, emeraldpics[2][em]); // coinbox
201 202 203 204 205 206 207 208 209 210 211 212 213 214

	y = (lowy + offs + 1) - (temp + (token + 1)*8);

	for (tokencount = token; tokencount; tokencount--)
	{
		if (y >= -temp)
			V_DrawSmallScaledPatch(32, y, 0, tokenicon);
		y += 8;
	}

	y += (offs*(temp - 1)/8);
	calc = (lowy - y)*2;

	if (calc > 0)
215
		V_DrawCroppedPatch(32<<FRACBITS, y<<FRACBITS, FRACUNIT/2, 0, tokenicon, 0, 0, tokenicon->width, calc);
216 217
}

218 219 220
//
// Y_ConsiderScreenBuffer
//
221
// Can we copy the current screen to a buffer?
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
//
void Y_ConsiderScreenBuffer(void)
{
	if (gameaction != ga_completed)
		return;

	if (y_buffer == NULL)
		y_buffer = Z_Calloc(sizeof(y_buffer_t), PU_STATIC, NULL);
	else
		return;

	y_buffer->source_width = vid.width;
	y_buffer->source_height = vid.height;
	y_buffer->source_bpp = vid.bpp;
	y_buffer->source_rowbytes = vid.rowbytes;
	y_buffer->source_picture = ZZ_Alloc(y_buffer->source_width*vid.bpp * y_buffer->source_height);
	VID_BlitLinearScreen(screens[1], y_buffer->source_picture, vid.width*vid.bpp, vid.height, vid.width*vid.bpp, vid.rowbytes);

	// Make the rescaled screen buffer
	Y_RescaleScreenBuffer();
}

//
// Y_RescaleScreenBuffer
//
247
// Write the rescaled source picture, to the destination picture that has the current screen's resolutions.
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
//
static void Y_RescaleScreenBuffer(void)
{
	INT32 sx, sy; // source
	INT32 dx, dy; // dest
	fixed_t scalefac, yscalefac;
	fixed_t rowfrac, colfrac;
	UINT8 *dest;

	// Who knows?
	if (y_buffer == NULL)
		return;

	if (y_buffer->target_picture)
		Z_Free(y_buffer->target_picture);

	y_buffer->target_width = vid.width;
	y_buffer->target_height = vid.height;
	y_buffer->target_rowbytes = vid.rowbytes;
	y_buffer->target_bpp = vid.bpp;
	y_buffer->target_picture = ZZ_Alloc(y_buffer->target_width*vid.bpp * y_buffer->target_height);
	dest = y_buffer->target_picture;

	scalefac = FixedDiv(y_buffer->target_width*FRACUNIT, y_buffer->source_width*FRACUNIT);
	yscalefac = FixedDiv(y_buffer->target_height*FRACUNIT, y_buffer->source_height*FRACUNIT);

	rowfrac = FixedDiv(FRACUNIT, yscalefac);
	colfrac = FixedDiv(FRACUNIT, scalefac);

	for (sy = 0, dy = 0; sy < (y_buffer->source_height << FRACBITS) && dy < y_buffer->target_height; sy += rowfrac, dy++)
		for (sx = 0, dx = 0; sx < (y_buffer->source_width << FRACBITS) && dx < y_buffer->target_width; sx += colfrac, dx += y_buffer->target_bpp)
			dest[(dy * y_buffer->target_rowbytes) + dx] = y_buffer->source_picture[((sy>>FRACBITS) * y_buffer->source_width) + (sx>>FRACBITS)];
}

//
// Y_CleanupScreenBuffer
//
// Free all related memory.
//
287
void Y_CleanupScreenBuffer(void)
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
{
	// Who knows?
	if (y_buffer == NULL)
		return;

	if (y_buffer->target_picture)
		Z_Free(y_buffer->target_picture);

	if (y_buffer->source_picture)
		Z_Free(y_buffer->source_picture);

	Z_Free(y_buffer);
	y_buffer = NULL;
}

Alam Ed Arias committed
303 304 305 306 307 308 309 310 311 312 313
//
// Y_IntermissionDrawer
//
// Called by D_Display. Nothing is modified here; all it does is draw.
// Neat concept, huh?
//
void Y_IntermissionDrawer(void)
{
	// Bonus loops
	INT32 i;

James R. committed
314
	if (intertype == int_none || rendermode == render_none)
315 316
		return;

Alam Ed Arias committed
317 318 319 320 321 322
	if (useinterpic)
		V_DrawScaledPatch(0, 0, 0, interpic);
	else if (!usetile)
	{
		if (rendermode == render_soft && usebuffer)
		{
323 324 325 326 327 328 329 330 331 332 333 334
			// no y_buffer
			if (y_buffer == NULL)
				VID_BlitLinearScreen(screens[1], screens[0], vid.width*vid.bpp, vid.height, vid.width*vid.bpp, vid.rowbytes);
			else
			{
				// Maybe the resolution changed?
				if ((y_buffer->target_width != vid.width) || (y_buffer->target_height != vid.height))
					Y_RescaleScreenBuffer();

				// Blit the already-scaled screen buffer to the current screen
				VID_BlitLinearScreen(y_buffer->target_picture, screens[0], vid.width*vid.bpp, vid.height, vid.width*vid.bpp, vid.rowbytes);
			}
Alam Ed Arias committed
335 336
		}
#ifdef HWRENDER
337
		else if (rendermode != render_soft && usebuffer)
Alam Ed Arias committed
338 339
			HWR_DrawIntermissionBG();
#endif
340
		else if (bgpatch)
Alam Ed Arias committed
341
		{
342 343 344
			fixed_t hs = vid.width  * FRACUNIT / BASEVIDWIDTH;
			fixed_t vs = vid.height * FRACUNIT / BASEVIDHEIGHT;
			V_DrawStretchyFixedPatch(0, 0, hs, vs, V_NOSCALEPATCH, bgpatch, NULL);
Alam Ed Arias committed
345 346
		}
	}
Jaime Ita Passos committed
347
	else if (bgtile)
Alam Ed Arias committed
348 349
		V_DrawPatchFill(bgtile);

350 351 352 353
	LUAh_IntermissionHUD();
	if (!LUA_HudEnabled(hud_intermissiontally))
		goto skiptallydrawer;

Alam Ed Arias committed
354 355 356 357
	if (intertype == int_coop)
	{
		INT32 bonusy;

358 359 360
		if (gottoken) // first to be behind everything else
			Y_IntermissionTokenDrawer();

361
		if (!splitscreen)  // there's not enough room in splitscreen, don't even bother trying!
Alam Ed Arias committed
362
		{
toaster committed
363 364 365 366 367 368
			// draw score
			ST_DrawPatchFromHud(HUD_SCORE, sboscore);
			ST_DrawNumFromHud(HUD_SCORENUM, data.coop.score);

			// draw time
			ST_DrawPatchFromHud(HUD_TIME, sbotime);
369
			if (cv_timetic.value == 3)
toaster committed
370 371
				ST_DrawNumFromHud(HUD_SECONDS, data.coop.tics);
			else
Alam Ed Arias committed
372
			{
toaster committed
373
				INT32 seconds, minutes, tictrn;
374

toaster committed
375 376 377
				seconds = G_TicsToSeconds(data.coop.tics);
				minutes = G_TicsToMinutes(data.coop.tics, true);
				tictrn  = G_TicsToCentiseconds(data.coop.tics);
378

toaster committed
379 380 381
				ST_DrawNumFromHud(HUD_MINUTES, minutes); // Minutes
				ST_DrawPatchFromHud(HUD_TIMECOLON, sbocolon); // Colon
				ST_DrawPadNumFromHud(HUD_SECONDS, seconds, 2); // Seconds
382

383
				if (cv_timetic.value == 1 || cv_timetic.value == 2 || modeattacking || marathonmode)
toaster committed
384 385 386 387
				{
					ST_DrawPatchFromHud(HUD_TIMETICCOLON, sboperiod); // Period
					ST_DrawPadNumFromHud(HUD_TICS, tictrn, 2); // Tics
				}
Alam Ed Arias committed
388 389 390 391 392
			}
		}

		// draw the "got through act" lines and act number
		V_DrawLevelTitle(data.coop.passedx1, 49, 0, data.coop.passed1);
toaster committed
393 394 395
		{
			INT32 h = V_LevelNameHeight(data.coop.passed2);
			V_DrawLevelTitle(data.coop.passedx2, 49+h+2, 0, data.coop.passed2);
Alam Ed Arias committed
396

toaster committed
397 398 399
			if (data.coop.actnum)
				V_DrawLevelActNum(244, 42+h, 0, data.coop.actnum);
		}
Alam Ed Arias committed
400 401 402

		bonusy = 150;
		// Total
403 404
		V_DrawScaledPatch(152, bonusy, 0, data.coop.ptotal);
		V_DrawTallNum(BASEVIDWIDTH - 68, bonusy + 1, 0, data.coop.total);
405
		bonusy -= (3*(tallnum[0]->height)/2) + 1;
Alam Ed Arias committed
406 407 408 409

		// Draw bonuses
		for (i = 3; i >= 0; --i)
		{
410
			if (data.coop.bonuses[i].display)
Alam Ed Arias committed
411 412 413 414
			{
				V_DrawScaledPatch(152, bonusy, 0, data.coop.bonuspatches[i]);
				V_DrawTallNum(BASEVIDWIDTH - 68, bonusy + 1, 0, data.coop.bonuses[i].points);
			}
415
			bonusy -= (3*(tallnum[0]->height)/2) + 1;
Alam Ed Arias committed
416 417 418 419
		}
	}
	else if (intertype == int_spec)
	{
420 421 422 423 424
		static tic_t animatetic = 0;
		INT32 ttheight = 16;
		INT32 xoffset1 = 0; // Line 1 x offset
		INT32 xoffset2 = 0; // Line 2 x offset
		INT32 xoffset3 = 0; // Line 3 x offset
425 426 427
		INT32 xoffset4 = 0; // Line 4 x offset
		INT32 xoffset5 = 0; // Line 5 x offset
		INT32 xoffset6 = 0; // Line 6 x offset
428 429
		UINT8 drawsection = 0;

430 431 432
		if (gottoken) // first to be behind everything else
			Y_IntermissionTokenDrawer();

Alam Ed Arias committed
433
		// draw the header
434
		if (intertic <= 2*TICRATE)
435
			animatetic = 0;
436
		else if (!animatetic && data.spec.bonuses[0].points == 0 && data.spec.bonuses[1].points == 0 && data.spec.passed3[0] != '\0')
toaster committed
437
			animatetic = intertic + TICRATE;
438

439
		if (animatetic && (tic_t)intertic >= animatetic)
440
		{
441
			const INT32 scradjust = (vid.width/vid.dupx)>>3; // 40 for BASEVIDWIDTH
442
			INT32 animatetimer = (intertic - animatetic);
443
			if (animatetimer <= 16)
444
			{
445 446 447 448 449 450
				xoffset1 = -(animatetimer      * scradjust);
				xoffset2 = -((animatetimer- 2) * scradjust);
				xoffset3 = -((animatetimer- 4) * scradjust);
				xoffset4 = -((animatetimer- 6) * scradjust);
				xoffset5 = -((animatetimer- 8) * scradjust);
				xoffset6 = -((animatetimer-10) * scradjust);
451
				if (xoffset2 > 0) xoffset2 = 0;
452
				if (xoffset3 > 0) xoffset3 = 0;
toaster committed
453 454
				if (xoffset4 > 0) xoffset4 = 0;
				if (xoffset5 > 0) xoffset5 = 0;
455
				if (xoffset6 > 0) xoffset6 = 0;
456
			}
457
			else if (animatetimer < 34)
458 459
			{
				drawsection = 1;
460 461 462 463 464 465
				xoffset1 = (24-animatetimer) * scradjust;
				xoffset2 = (26-animatetimer) * scradjust;
				xoffset3 = (28-animatetimer) * scradjust;
				xoffset4 = (30-animatetimer) * scradjust;
				xoffset5 = (32-animatetimer) * scradjust;
				xoffset6 = (34-animatetimer) * scradjust;
466 467
				if (xoffset1 < 0) xoffset1 = 0;
				if (xoffset2 < 0) xoffset2 = 0;
toaster committed
468 469
				if (xoffset3 < 0) xoffset3 = 0;
				if (xoffset4 < 0) xoffset4 = 0;
470
				if (xoffset5 < 0) xoffset5 = 0;
471 472
			}
			else
toaster committed
473
			{
474
				drawsection = 1;
475
				if (animatetimer == 32)
toaster committed
476 477
					S_StartSound(NULL, sfx_s3k68);
			}
478
		}
Alam Ed Arias committed
479

480
		if (drawsection == 1)
Alam Ed Arias committed
481
		{
482 483 484 485
			const char *ringtext = "\x82" "50 rings, no shield";
			const char *tut1text = "\x82" "press " "\x80" "spin";
			const char *tut2text = "\x82" "mid-" "\x80" "jump";
			ttheight = 8;
486
			V_DrawLevelTitle(data.spec.passedx1 + xoffset1, ttheight, 0, data.spec.passed1);
487
			ttheight += V_LevelNameHeight(data.spec.passed3) + 2;
toaster committed
488 489
			V_DrawLevelTitle(data.spec.passedx3 + xoffset2, ttheight, 0, data.spec.passed3);
			ttheight += V_LevelNameHeight(data.spec.passed4) + 2;
490
			V_DrawLevelTitle(data.spec.passedx4 + xoffset3, ttheight, 0, data.spec.passed4);
toaster committed
491

492 493 494
			ttheight = 108;
			V_DrawLevelTitle(BASEVIDWIDTH/2 + xoffset4 - (V_LevelNameWidth(ringtext)/2), ttheight, 0, ringtext);
			ttheight += V_LevelNameHeight(tut1text) + 2;
toaster committed
495 496
			V_DrawLevelTitle(BASEVIDWIDTH/2 + xoffset5 - (V_LevelNameWidth(tut1text)/2), ttheight, 0, tut1text);
			ttheight += V_LevelNameHeight(tut2text) + 2;
497
			V_DrawLevelTitle(BASEVIDWIDTH/2 + xoffset6 - (V_LevelNameWidth(tut2text)/2), ttheight, 0, tut2text);
Alam Ed Arias committed
498 499
		}
		else
500
		{
501
			INT32 yoffset = 0;
toaster committed
502 503 504 505
			if (data.spec.passed1[0] != '\0')
			{
				ttheight = 24;
				V_DrawLevelTitle(data.spec.passedx1 + xoffset1, ttheight, 0, data.spec.passed1);
toaster committed
506
				ttheight += V_LevelNameHeight(data.spec.passed2) + 2;
toaster committed
507 508 509 510 511 512 513 514
				V_DrawLevelTitle(data.spec.passedx2 + xoffset2, ttheight, 0, data.spec.passed2);
			}
			else
			{
				ttheight = 24 + (V_LevelNameHeight(data.spec.passed2)/2) + 2;
				V_DrawLevelTitle(data.spec.passedx2 + xoffset1, ttheight, 0, data.spec.passed2);
			}

515 516 517 518 519 520 521 522 523 524 525 526 527
			V_DrawScaledPatch(152 + xoffset3, 108, 0, data.spec.bonuspatches[0]);
			V_DrawTallNum(BASEVIDWIDTH + xoffset3 - 68, 109, 0, data.spec.bonuses[0].points);
			if (data.spec.bonuses[1].display)
			{
				V_DrawScaledPatch(152 + xoffset4, 124, 0, data.spec.bonuspatches[1]);
				V_DrawTallNum(BASEVIDWIDTH + xoffset4 - 68, 125, 0, data.spec.bonuses[1].points);
				yoffset = 16;
				// hack; pass the buck along...
				xoffset4 = xoffset5;
				xoffset5 = xoffset6;
			}
			V_DrawScaledPatch(152 + xoffset4, 124+yoffset, 0, data.spec.pscore);
			V_DrawTallNum(BASEVIDWIDTH + xoffset4 - 68, 125+yoffset, 0, data.spec.score);
528 529

			// Draw continues!
530
			if (continuesInSession /* && (data.spec.continues & 0x80) */) // Always draw when continues are a thing
531 532 533
			{
				UINT8 continues = data.spec.continues & 0x7F;

534
				V_DrawScaledPatch(152 + xoffset5, 150+yoffset, 0, data.spec.pcontinues);
535
				if (continues > 5)
536
				{
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
					INT32 leftx = (continues >= 10) ? 216 : 224;
					V_DrawContinueIcon(leftx + xoffset5, 162+yoffset, 0, *data.spec.playerchar, *data.spec.playercolor);
					V_DrawScaledPatch(leftx + xoffset5 + 12, 160+yoffset, 0, stlivex);
					if (!((data.spec.continues & 0x80) && !(endtic < 0 || intertic%20 < 10)))
						V_DrawRightAlignedString(252 + xoffset5, 158+yoffset, 0,
							va("%d",(((data.spec.continues & 0x80) && (endtic < 0)) ? continues-1 : continues)));
				}
				else
				{
					for (i = 0; i < continues; ++i)
					{
						if ((data.spec.continues & 0x80) && i == continues-1 && (endtic < 0 || intertic%20 < 10))
							break;
						V_DrawContinueIcon(246 + xoffset5 - (i*20), 162+yoffset, 0, *data.spec.playerchar, *data.spec.playercolor);
					}
552 553
				}
			}
554
		}
Alam Ed Arias committed
555 556

		// draw the emeralds
557
		//if (intertic & 1)
Alam Ed Arias committed
558
		{
toaster committed
559
			boolean drawthistic = !(ALL7EMERALDS(emeralds) && (intertic & 1));
560
			INT32 emeraldx = 152 - 3*28;
561
			INT32 em = P_GetNextEmerald();
562

toaster committed
563
			if (em == 7)
Alam Ed Arias committed
564
			{
toaster committed
565 566 567 568 569
				if (!stagefailed)
				{
					fixed_t adjust = 2*(FINESINE(FixedAngle((intertic + 1)<<(FRACBITS-4)) & FINEMASK));
					V_DrawFixedPatch(152<<FRACBITS, (74<<FRACBITS) - adjust, FRACUNIT, 0, emeraldpics[0][em], NULL);
				}
Alam Ed Arias committed
570
			}
toaster committed
571
			else if (em < 7)
572 573 574 575 576
			{
				static UINT8 emeraldbounces = 0;
				static INT32 emeraldmomy = 20;
				static INT32 emeraldy = -40;

toaster committed
577 578 579 580 581 582 583 584
				if (drawthistic)
					for (i = 0; i < 7; ++i)
					{
						if ((i != em) && (emeralds & (1 << i)))
							V_DrawScaledPatch(emeraldx, 74, 0, emeraldpics[0][i]);
						emeraldx += 28;
					}

585 586 587 588 589 590 591 592 593 594
				emeraldx = 152 + (em-3)*28;

				if (intertic <= 1)
				{
					emeraldbounces = 0;
					emeraldmomy = 20;
					emeraldy = -40;
				}
				else
				{
toaster committed
595
					if (!stagefailed)
596 597 598
					{
						if (emeraldbounces < 3)
						{
599
							emeraldy += (++emeraldmomy);
600 601 602 603 604 605 606 607 608 609
							if (emeraldy > 74)
							{
								S_StartSound(NULL, sfx_tink); // tink
								emeraldbounces++;
								emeraldmomy = -(emeraldmomy/2);
								emeraldy = 74;
							}
						}
					}
					else
610
					{
611 612 613 614 615
						if (emeraldy < (vid.height/vid.dupy)+16)
						{
							emeraldy += (++emeraldmomy);
							emeraldx += intertic - 6;
						}
616
						if (emeraldbounces < 1 && emeraldy > 74)
617
						{
618
							S_StartSound(NULL, sfx_shldls); // nope
619 620 621 622 623
							emeraldbounces++;
							emeraldmomy = -(emeraldmomy/2);
							emeraldy = 74;
						}
					}
toaster committed
624 625
					if (drawthistic)
						V_DrawScaledPatch(emeraldx, emeraldy, 0, emeraldpics[0][em]);
626
				}
Alam Ed Arias committed
627 628 629 630 631 632 633 634 635 636 637 638
			}
		}
	}
	else if (intertype == int_match || intertype == int_race)
	{
		INT32 j = 0;
		INT32 x = 4;
		INT32 y = 48;
		char name[MAXPLAYERNAME+1];
		char strtime[10];

		// draw the header
639
		V_DrawScaledPatch(112, 2, 0, data.match.result);
Alam Ed Arias committed
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704

		// draw the level name
		V_DrawCenteredString(BASEVIDWIDTH/2, 20, 0, data.match.levelstring);
		V_DrawFill(4, 42, 312, 1, 0);

		if (data.match.numplayers > 9)
		{
			V_DrawFill(160, 32, 1, 152, 0);

			if (intertype == int_race)
				V_DrawRightAlignedString(x+152, 32, V_YELLOWMAP, "TIME");
			else
				V_DrawRightAlignedString(x+152, 32, V_YELLOWMAP, "SCORE");

			V_DrawCenteredString(x+(BASEVIDWIDTH/2)+6, 32, V_YELLOWMAP, "#");
			V_DrawString(x+(BASEVIDWIDTH/2)+36, 32, V_YELLOWMAP, "NAME");
		}

		V_DrawCenteredString(x+6, 32, V_YELLOWMAP, "#");
		V_DrawString(x+36, 32, V_YELLOWMAP, "NAME");

		if (intertype == int_race)
			V_DrawRightAlignedString(x+(BASEVIDWIDTH/2)+152, 32, V_YELLOWMAP, "TIME");
		else
			V_DrawRightAlignedString(x+(BASEVIDWIDTH/2)+152, 32, V_YELLOWMAP, "SCORE");

		for (i = 0; i < data.match.numplayers; i++)
		{
			if (data.match.spectator[i])
				continue; //Ignore spectators.

			V_DrawCenteredString(x+6, y, 0, va("%d", j+1));
			j++; //We skip spectators, but not their number.

			if (playeringame[data.match.num[i]])
			{
				// Draw the back sprite, it looks ugly if we don't
				V_DrawSmallScaledPatch(x+16, y-4, 0, livesback);

				if (data.match.color[i] == 0)
					V_DrawSmallScaledPatch(x+16, y-4, 0,faceprefix[*data.match.character[i]]);
				else
				{
					UINT8 *colormap = R_GetTranslationColormap(*data.match.character[i], *data.match.color[i], GTC_CACHE);
					V_DrawSmallMappedPatch(x+16, y-4, 0,faceprefix[*data.match.character[i]], colormap);
				}

				if (data.match.numplayers > 9)
				{
					if (intertype == int_race)
						strlcpy(name, data.match.name[i], 8);
					else
						strlcpy(name, data.match.name[i], 9);
				}
				else
					STRBUFCPY(name, data.match.name[i]);

				V_DrawString(x+36, y, V_ALLOWLOWERCASE, name);

				if (data.match.numplayers > 9)
				{
					if (intertype == int_match)
						V_DrawRightAlignedString(x+152, y, 0, va("%i", data.match.scores[i]));
					else if (intertype == int_race)
					{
705
						if (players[data.match.num[i]].pflags & PF_GAMETYPEOVER)
Alam Ed Arias committed
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
							snprintf(strtime, sizeof strtime, "DNF");
						else
							snprintf(strtime, sizeof strtime,
								"%i:%02i.%02i",
								G_TicsToMinutes(data.match.scores[i], true),
								G_TicsToSeconds(data.match.scores[i]), G_TicsToCentiseconds(data.match.scores[i]));

						strtime[sizeof strtime - 1] = '\0';
						V_DrawRightAlignedString(x+152, y, 0, strtime);
					}
				}
				else
				{
					if (intertype == int_match)
						V_DrawRightAlignedString(x+152+BASEVIDWIDTH/2, y, 0, va("%u", data.match.scores[i]));
					else if (intertype == int_race)
					{
723
						if (players[data.match.num[i]].pflags & PF_GAMETYPEOVER)
Alam Ed Arias committed
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
							snprintf(strtime, sizeof strtime, "DNF");
						else
							snprintf(strtime, sizeof strtime, "%i:%02i.%02i", G_TicsToMinutes(data.match.scores[i], true),
									G_TicsToSeconds(data.match.scores[i]), G_TicsToCentiseconds(data.match.scores[i]));

						strtime[sizeof strtime - 1] = '\0';

						V_DrawRightAlignedString(x+152+BASEVIDWIDTH/2, y, 0, strtime);
					}
				}
			}

			y += 16;

			if (y > 176)
			{
				y = 48;
				x += BASEVIDWIDTH/2;
			}
		}
	}
	else if (intertype == int_ctf || intertype == int_teammatch)
	{
		INT32 x = 4, y = 0;
		INT32 redplayers = 0, blueplayers = 0;
		char name[MAXPLAYERNAME+1];

		// Show the team flags and the team score at the top instead of "RESULTS"
752
		V_DrawSmallScaledPatch(128 - (data.match.blueflag->width / 4), 2, 0, data.match.blueflag);
Alam Ed Arias committed
753 754
		V_DrawCenteredString(128, 16, 0, va("%u", bluescore));

755
		V_DrawSmallScaledPatch(192 - (data.match.redflag->width / 4), 2, 0, data.match.redflag);
Alam Ed Arias committed
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
		V_DrawCenteredString(192, 16, 0, va("%u", redscore));

		// draw the level name
		V_DrawCenteredString(BASEVIDWIDTH/2, 24, 0, data.match.levelstring);
		V_DrawFill(4, 42, 312, 1, 0);

		//vert. line
		V_DrawFill(160, 32, 1, 152, 0);

		//strings at the top of the list
		V_DrawCenteredString(x+6, 32, V_YELLOWMAP, "#");
		V_DrawCenteredString(x+(BASEVIDWIDTH/2)+6, 32, V_YELLOWMAP, "#");

		V_DrawString(x+36, 32, V_YELLOWMAP, "NAME");
		V_DrawString(x+(BASEVIDWIDTH/2)+36, 32, V_YELLOWMAP, "NAME");

		V_DrawRightAlignedString(x+152, 32, V_YELLOWMAP, "SCORE");
		V_DrawRightAlignedString(x+(BASEVIDWIDTH/2)+152, 32, V_YELLOWMAP, "SCORE");

		for (i = 0; i < data.match.numplayers; i++)
		{
			if (playeringame[data.match.num[i]] && !(data.match.spectator[i]))
			{
				UINT8 *colormap = R_GetTranslationColormap(*data.match.character[i], *data.match.color[i], GTC_CACHE);

				if (*data.match.color[i] == SKINCOLOR_RED) //red
				{
					if (redplayers++ > 9)
						continue;
					x = 4 + (BASEVIDWIDTH/2);
					y = (redplayers * 16) + 32;
					V_DrawCenteredString(x+6, y, 0, va("%d", redplayers));
				}
				else if (*data.match.color[i] == SKINCOLOR_BLUE) //blue
				{
					if (blueplayers++ > 9)
						continue;
					x = 4;
					y = (blueplayers * 16) + 32;
					V_DrawCenteredString(x+6, y, 0, va("%d", blueplayers));
				}
				else
					continue;

				// Draw the back sprite, it looks ugly if we don't
				V_DrawSmallScaledPatch(x+16, y-4, 0, livesback);

				//color is ALWAYS going to be 6/7 here, no need to check if it's nonzero.
				V_DrawSmallMappedPatch(x+16, y-4, 0,faceprefix[*data.match.character[i]], colormap);

				strlcpy(name, data.match.name[i], 9);

				V_DrawString(x+36, y, V_ALLOWLOWERCASE, name);

				V_DrawRightAlignedString(x+152, y, 0, va("%u", data.match.scores[i]));
			}
		}
	}
814
	else if (intertype == int_comp)
Alam Ed Arias committed
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
	{
		INT32 x = 4;
		INT32 y = 48;
		UINT32 ptime, pring, pmaxring, pmonitor, pscore;
		char sstrtime[10];

		// draw the level name
		V_DrawCenteredString(BASEVIDWIDTH/2, 8, 0, data.competition.levelstring);
		V_DrawFill(4, 42, 312, 1, 0);

		V_DrawCenteredString(x+6, 32, V_YELLOWMAP, "#");
		V_DrawString(x+36, 32, V_YELLOWMAP, "NAME");
		// Time
		V_DrawRightAlignedString(x+160, 32, V_YELLOWMAP, "TIME");

		// Rings
		V_DrawThinString(x+168, 32, V_YELLOWMAP, "RING");

		// Total rings
		V_DrawThinString(x+191, 24, V_YELLOWMAP, "TOTAL");
		V_DrawThinString(x+196, 32, V_YELLOWMAP, "RING");

		// Monitors
		V_DrawThinString(x+223, 24, V_YELLOWMAP, "ITEM");
		V_DrawThinString(x+229, 32, V_YELLOWMAP, "BOX");

		// Score
		V_DrawRightAlignedString(x+288, 32, V_YELLOWMAP, "SCORE");

		// Points
		V_DrawRightAlignedString(x+312, 32, V_YELLOWMAP, "PT");

		for (i = 0; i < data.competition.numplayers; i++)
		{
			ptime = (data.competition.times[i] & ~0x80000000);
			pring = (data.competition.rings[i] & ~0x80000000);
			pmaxring = (data.competition.maxrings[i] & ~0x80000000);
			pmonitor = (data.competition.monitors[i] & ~0x80000000);
			pscore = (data.competition.scores[i] & ~0x80000000);

			V_DrawCenteredString(x+6, y, 0, va("%d", i+1));

			if (playeringame[data.competition.num[i]])
			{
				// Draw the back sprite, it looks ugly if we don't
				V_DrawSmallScaledPatch(x+16, y-4, 0, livesback);

				if (data.competition.color[i] == 0)
					V_DrawSmallScaledPatch(x+16, y-4, 0,faceprefix[*data.competition.character[i]]);
				else
				{
					UINT8 *colormap = R_GetTranslationColormap(*data.competition.character[i], *data.competition.color[i], GTC_CACHE);
					V_DrawSmallMappedPatch(x+16, y-4, 0,faceprefix[*data.competition.character[i]], colormap);
				}

				// already constrained to 8 characters
				V_DrawString(x+36, y, V_ALLOWLOWERCASE, data.competition.name[i]);

873
				if (players[data.competition.num[i]].pflags & PF_GAMETYPEOVER)
Alam Ed Arias committed
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
					snprintf(sstrtime, sizeof sstrtime, "Time Over");
				else if (players[data.competition.num[i]].lives <= 0)
					snprintf(sstrtime, sizeof sstrtime, "Game Over");
				else
					snprintf(sstrtime, sizeof sstrtime, "%i:%02i.%02i", G_TicsToMinutes(ptime, true),
							G_TicsToSeconds(ptime), G_TicsToCentiseconds(ptime));

				sstrtime[sizeof sstrtime - 1] = '\0';
				// Time
				V_DrawRightAlignedThinString(x+160, y, ((data.competition.times[i] & 0x80000000) ? V_YELLOWMAP : 0), sstrtime);
				// Rings
				V_DrawRightAlignedThinString(x+188, y, V_MONOSPACE|((data.competition.rings[i] & 0x80000000) ? V_YELLOWMAP : 0), va("%u", pring));
				// Total rings
				V_DrawRightAlignedThinString(x+216, y, V_MONOSPACE|((data.competition.maxrings[i] & 0x80000000) ? V_YELLOWMAP : 0), va("%u", pmaxring));
				// Monitors
				V_DrawRightAlignedThinString(x+244, y, V_MONOSPACE|((data.competition.monitors[i] & 0x80000000) ? V_YELLOWMAP : 0), va("%u", pmonitor));
				// Score
				V_DrawRightAlignedThinString(x+288, y, V_MONOSPACE|((data.competition.scores[i] & 0x80000000) ? V_YELLOWMAP : 0), va("%u", pscore));
				// Final Points
				V_DrawRightAlignedString(x+312, y, V_YELLOWMAP, va("%d", data.competition.points[i]));
			}

			y += 16;

			if (y > 176)
				break;
		}
	}

903 904 905 906
skiptallydrawer:
	if (!LUA_HudEnabled(hud_intermissionmessages))
		return;

Alam Ed Arias committed
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926
	if (timer)
		V_DrawCenteredString(BASEVIDWIDTH/2, 188, V_YELLOWMAP,
			va("start in %d seconds", timer/TICRATE));

	// Make it obvious that scrambling is happening next round.
	if (cv_scrambleonchange.value && cv_teamscramble.value && (intertic/TICRATE % 2 == 0))
		V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, V_YELLOWMAP, M_GetText("Teams will be scrambled next round!"));
}

//
// Y_Ticker
//
// Manages fake score tally for single player end of act, and decides when intermission is over.
//
void Y_Ticker(void)
{
	if (intertype == int_none)
		return;

	// Check for pause or menu up in single player
Alam Ed Arias committed
927
	if (paused || P_AutoPause())
Alam Ed Arias committed
928 929
		return;

SteelT committed
930 931
	LUAh_IntermissionThinker();

Alam Ed Arias committed
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
	intertic++;

	// Team scramble code for team match and CTF.
	// Don't do this if we're going to automatically scramble teams next round.
	if (G_GametypeHasTeams() && cv_teamscramble.value && !cv_scrambleonchange.value && server)
	{
		// If we run out of time in intermission, the beauty is that
		// the P_Ticker() team scramble code will pick it up.
		if ((intertic % (TICRATE/7)) == 0)
			P_DoTeamscrambling();
	}

	// multiplayer uses timer (based on cv_inttime)
	if (timer)
	{
		if (!--timer)
		{
			Y_EndIntermission();
950
			G_AfterIntermission();
Alam Ed Arias committed
951 952 953 954 955 956 957
			return;
		}
	}
	// single player is hardcoded to go away after awhile
	else if (intertic == endtic)
	{
		Y_EndIntermission();
958
		G_AfterIntermission();
Alam Ed Arias committed
959 960 961 962 963 964 965 966 967 968
		return;
	}

	if (endtic != -1)
		return; // tally is done

	if (intertype == int_coop) // coop or single player, normal level
	{
		INT32 i;
		UINT32 oldscore = data.coop.score;
969
		boolean skip = (marathonmode) ? true : false;
Alam Ed Arias committed
970 971 972
		boolean anybonuses = false;

		if (!intertic) // first time only
973
		{
974 975 976 977 978 979
			if (mapheaderinfo[gamemap-1]->musinterfadeout
#ifdef _WIN32
				// can't fade midi due to win32 volume hack
				&& S_MusicType() != MU_MID
#endif
			)
980 981
				S_FadeOutStopMusic(mapheaderinfo[gamemap-1]->musinterfadeout);
			else if (mapheaderinfo[gamemap-1]->musintername[0] && S_MusicExists(mapheaderinfo[gamemap-1]->musintername, !midi_disabled, !digital_disabled))
982 983
				S_ChangeMusicInternal(mapheaderinfo[gamemap-1]->musintername, false); // don't loop it
			else
Marco Z committed
984
				S_ChangeMusicInternal("_clear", false); // don't loop it
985 986
			tallydonetic = -1;
		}
Alam Ed Arias committed
987 988 989 990 991

		if (intertic < TICRATE) // one second pause before tally begins
			return;

		for (i = 0; i < MAXPLAYERS; i++)
992
			if (playeringame[i] && (players[i].cmd.buttons & BT_SPIN))
Alam Ed Arias committed
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
				skip = true;

		// bonuses count down by 222 each tic
		for (i = 0; i < 4; ++i)
		{
			if (!data.coop.bonuses[i].points)
				continue;

			data.coop.bonuses[i].points -= 222;
			data.coop.total += 222;
			data.coop.score += 222;
			if (data.coop.bonuses[i].points < 0 || skip == true) // too far?
			{
				data.coop.score += data.coop.bonuses[i].points;
				data.coop.total += data.coop.bonuses[i].points;
				data.coop.bonuses[i].points = 0;
			}
1010 1011
			if (data.coop.score > MAXSCORE)
				data.coop.score = MAXSCORE;
Alam Ed Arias committed
1012 1013 1014 1015 1016 1017
			if (data.coop.bonuses[i].points > 0)
				anybonuses = true;
		}

		if (!anybonuses)
		{
1018
			tallydonetic = intertic;
Alam Ed Arias committed
1019
			endtic = intertic + 3*TICRATE; // 3 second pause after end of tally
1020
			S_StartSound(NULL, (gottoken ? sfx_token : sfx_chchng)); // cha-ching!
Alam Ed Arias committed
1021 1022 1023 1024 1025

			// Update when done with tally
			if ((!modifiedgame || savemoddata) && !(netgame || multiplayer) && !demoplayback)
			{
				if (M_UpdateUnlockablesAndExtraEmblems())
toaster committed
1026
					S_StartSound(NULL, sfx_s3k68);
Alam Ed Arias committed
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044

				G_SaveGameData();
			}
		}
		else if (!(intertic & 1))
			S_StartSound(NULL, sfx_ptally); // tally sound effect

		if (data.coop.gotlife > 0 && (skip == true || data.coop.score % 50000 < oldscore % 50000)) // just passed a 50000 point mark
		{
			// lives are already added since tally is fake, but play the music
			P_PlayLivesJingle(NULL);
			--data.coop.gotlife;
		}
	}
	else if (intertype == int_spec) // coop or single player, special stage
	{
		INT32 i;
		UINT32 oldscore = data.spec.score;
1045
		boolean skip = (marathonmode) ? true : false, super = false, anybonuses = false;
Alam Ed Arias committed
1046 1047 1048

		if (!intertic) // first time only
		{
1049 1050 1051 1052 1053 1054
			if (mapheaderinfo[gamemap-1]->musinterfadeout
#ifdef _WIN32
				// can't fade midi due to win32 volume hack
				&& S_MusicType() != MU_MID
#endif
			)
1055 1056
				S_FadeOutStopMusic(mapheaderinfo[gamemap-1]->musinterfadeout);
			else if (mapheaderinfo[gamemap-1]->musintername[0] && S_MusicExists(mapheaderinfo[gamemap-1]->musintername, !midi_disabled, !digital_disabled))
1057 1058
				S_ChangeMusicInternal(mapheaderinfo[gamemap-1]->musintername, false); // don't loop it
			else
Marco Z committed
1059
				S_ChangeMusicInternal("_clear", false); // don't loop it
1060
			tallydonetic = -1;
Alam Ed Arias committed
1061 1062
		}

1063
		if (intertic < 2*TICRATE) // TWO second pause before tally begins, thank you mazmazz
Alam Ed Arias committed
1064 1065 1066
			return;

		for (i = 0; i < MAXPLAYERS; i++)
1067 1068
			if (playeringame[i])
			{
1069
				if (players[i].cmd.buttons & BT_SPIN)
1070 1071 1072 1073
					skip = true;
				if (players[i].charflags & SF_SUPER)
					super = true;
			}
Alam Ed Arias committed
1074

1075
		if (tallydonetic != -1 && ((data.spec.continues & 0x80) || (super && ALL7EMERALDS(emeralds))))
Alam Ed Arias committed
1076
		{
1077
			if ((intertic - tallydonetic) > (3*TICRATE)/2)
Alam Ed Arias committed
1078
			{
1079
				endtic = intertic + 4*TICRATE; // 4 second pause after end of tally
1080 1081 1082
				if (data.spec.continues & 0x80)
					S_StartSound(NULL, sfx_s3kac); // bingly-bingly-bing!

Alam Ed Arias committed
1083 1084 1085 1086
			}
			return;
		}

1087 1088
		// bonuses count down by 222 each tic
		for (i = 0; i < 2; ++i)
Alam Ed Arias committed
1089
		{
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
			if (!data.spec.bonuses[i].points)
				continue;

			data.spec.bonuses[i].points -= 222;
			data.spec.score += 222;
			if (data.spec.bonuses[i].points < 0 || skip == true) // too far?
			{
				data.spec.score += data.spec.bonuses[i].points;
				data.spec.bonuses[i].points = 0;
			}
			if (data.spec.score > MAXSCORE)
				data.spec.score = MAXSCORE;
			if (data.spec.bonuses[i].points > 0)
				anybonuses = true;
Alam Ed Arias committed
1104 1105
		}

1106
		if (!anybonuses)
Alam Ed Arias committed
1107
		{
1108
			tallydonetic = intertic;
1109
			if (!((data.spec.continues & 0x80) || (super && ALL7EMERALDS(emeralds)))) // don't set endtic yet!
1110
				endtic = intertic + 4*TICRATE; // 4 second pause after end of tally
Alam Ed Arias committed
1111

1112
			S_StartSound(NULL, (gottoken ? sfx_token : sfx_chchng)); // cha-ching!
Alam Ed Arias committed
1113 1114 1115 1116 1117

			// Update when done with tally
			if ((!modifiedgame || savemoddata) && !(netgame || multiplayer) && !demoplayback)
			{
				if (M_UpdateUnlockablesAndExtraEmblems())
toaster committed
1118
					S_StartSound(NULL, sfx_s3k68);
Alam Ed Arias committed
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135

				G_SaveGameData();
			}
		}
		else if (!(intertic & 1))
			S_StartSound(NULL, sfx_ptally); // tally sound effect

		if (data.spec.gotlife > 0 && (skip == true || data.spec.score % 50000 < oldscore % 50000)) // just passed a 50000 point mark
		{
			// lives are already added since tally is fake, but play the music
			P_PlayLivesJingle(NULL);
			--data.spec.gotlife;
		}
	}
	else if (intertype == int_match || intertype == int_ctf || intertype == int_teammatch) // match
	{
		if (!intertic) // first time only
1136
			S_ChangeMusicInternal("_inter", true); // loop it
Alam Ed Arias committed
1137 1138 1139 1140 1141

		// If a player has left or joined, recalculate scores.
		if (data.match.numplayers != D_NumPlayers())
			Y_CalculateMatchWinners();
	}
1142
	else if (intertype == int_race || intertype == int_comp) // race
Alam Ed Arias committed
1143 1144
	{
		if (!intertic) // first time only
1145
			S_ChangeMusicInternal("_inter", true); // loop it
Alam Ed Arias committed
1146 1147 1148 1149 1150

		// Don't bother recalcing for race. It doesn't make as much sense.
	}
}

1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
//
// Y_DetermineIntermissionType
//
// Determines the intermission type from the current gametype.
//
void Y_DetermineIntermissionType(void)
{
	// set to int_none initially
	intertype = int_none;

	if (intermissiontypes[gametype] != int_none)
		intertype = intermissiontypes[gametype];
	else if (gametype == GT_COOP)
		intertype = (G_IsSpecialStage(gamemap)) ? int_spec : int_coop;
	else if (gametype == GT_TEAMMATCH)
		intertype = int_teammatch;
	else if (gametype == GT_MATCH
	 || gametype == GT_TAG
	 || gametype == GT_HIDEANDSEEK)
		intertype = int_match;
	else if (gametype == GT_RACE)
		intertype = int_race;
	else if (gametype == GT_COMPETITION)
		intertype = int_comp;
	else if (gametype == GT_CTF)
		intertype = int_ctf;
}

Alam Ed Arias committed
1179 1180 1181 1182 1183 1184 1185 1186
//
// Y_StartIntermission
//
// Called by G_DoCompleted. Sets up data for intermission drawer/ticker.
//
void Y_StartIntermission(void)
{
	INT32 i;
Alam Ed Arias committed
1187

Alam Ed Arias committed
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
	intertic = -1;

#ifdef PARANOIA
	if (endtic != -1)
		I_Error("endtic is dirty");
#endif

	if (!multiplayer)
	{
		timer = 0;
1198
		intertype = (G_IsSpecialStage(gamemap)) ? int_spec : int_coop;
Alam Ed Arias committed
1199 1200 1201
	}
	else
	{
1202
		if (cv_inttime.value == 0 && ((intertype == int_coop) || (intertype == int_spec)))
Alam Ed Arias committed
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
			timer = 0;
		else
		{
			timer = cv_inttime.value*TICRATE;

			if (!timer)
				timer = 1;
		}
	}

	// We couldn't display the intermission even if we wanted to.
1214 1215
	// But we still need to give the players their score bonuses, dummy.
	//if (dedicated) return;
Alam Ed Arias committed
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231

	// This should always exist, but just in case...
	if(!mapheaderinfo[prevmap])
		P_AllocMapHeader(prevmap);

	switch (intertype)
	{
		case int_coop: // coop or single player, normal level
		{
			// award time and ring bonuses
			Y_AwardCoopBonuses();

			// setup time data
			data.coop.tics = players[consoleplayer].realtime;

			for (i = 0; i < 4; ++i)
1232 1233 1234 1235
			{
				if (strlen(data.coop.bonuses[i].patch))
					data.coop.bonuspatches[i] = W_CachePatchName(data.coop.bonuses[i].patch, PU_PATCH);
			}
Jaime Ita Passos committed
1236
			data.coop.ptotal = W_CachePatchName("YB_TOTAL", PU_PATCH);
Alam Ed Arias committed
1237 1238

			// get act number
1239
			data.coop.actnum = mapheaderinfo[gamemap-1]->actnum;
Alam Ed Arias committed
1240 1241

			// get background patches
Jaime Ita Passos committed
1242
			bgpatch = W_CachePatchName("INTERSCR", PU_PATCH);
Alam Ed Arias committed
1243 1244 1245 1246

			// grab an interscreen if appropriate
			if (mapheaderinfo[gamemap-1]->interscreen[0] != '#')
			{
Jaime Ita Passos committed
1247
				interpic = W_CachePatchName(mapheaderinfo[gamemap-1]->interscreen, PU_PATCH);
Alam Ed Arias committed
1248 1249 1250 1251 1252 1253
				useinterpic = true;
				usebuffer = false;
			}
			else
			{
				useinterpic = false;
Sryder committed
1254 1255 1256 1257
#ifdef HWRENDER
				if (rendermode == render_opengl)
					usebuffer = true; // This needs to be here for OpenGL, otherwise usebuffer is never set to true for it, and thus there's no screenshot in the intermission
#endif
Alam Ed Arias committed
1258 1259 1260 1261
			}
			usetile = false;

			// set up the "got through act" message according to skin name
Alam Ed Arias committed
1262 1263
			// too long so just show "YOU GOT THROUGH THE ACT"
			if (strlen(skins[players[consoleplayer].skin].realname) > 13)
Alam Ed Arias committed
1264
			{
1265 1266
				strcpy(data.coop.passed1, "you got");
				strcpy(data.coop.passed2, (mapheaderinfo[gamemap-1]->actnum) ? "through act" : "through the act");
Alam Ed Arias committed
1267
			}
Alam Ed Arias committed
1268 1269
			// long enough that "X GOT" won't fit so use "X PASSED THE ACT"
			else if (strlen(skins[players[consoleplayer].skin].realname) > 8)
Alam Ed Arias committed
1270 1271
			{
				strcpy(data.coop.passed1, skins[players[consoleplayer].skin].realname);
1272
				strcpy(data.coop.passed2, (mapheaderinfo[gamemap-1]->actnum) ? "passed act" : "passed the act");
Alam Ed Arias committed
1273 1274 1275 1276
			}
			// length is okay for normal use
			else
			{
1277
				snprintf(data.coop.passed1, sizeof data.coop.passed1, "%s got",
Alam Ed Arias committed
1278
					skins[players[consoleplayer].skin].realname);
1279
				strcpy(data.coop.passed2, (mapheaderinfo[gamemap-1]->actnum) ? "through act" : "through the act");
Alam Ed Arias committed
1280 1281 1282 1283 1284
			}

			// set X positions
			if (mapheaderinfo[gamemap-1]->actnum)
			{
Alam Ed Arias committed
1285
				data.coop.passedx1 = 62 + (176 - V_LevelNameWidth(data.coop.passed1))/2;
Alam Ed Arias committed
1286 1287 1288 1289 1290 1291
				data.coop.passedx2 = 62 + (176 - V_LevelNameWidth(data.coop.passed2))/2;
			}
			else
			{
				data.coop.passedx1 = (BASEVIDWIDTH - V_LevelNameWidth(data.coop.passed1))/2;
				data.coop.passedx2 = (BASEVIDWIDTH - V_LevelNameWidth(data.coop.passed2))/2;
Alam Ed Arias committed
1292
			}
Alam Ed Arias committed
1293 1294 1295
			// The above value is not precalculated because it needs only be computed once
			// at the start of intermission, and precalculating it would preclude mods
			// changing the font to one of a slightly different width.
Alam Ed Arias committed
1296 1297 1298 1299 1300 1301 1302 1303
			break;
		}

		case int_spec: // coop or single player, special stage
		{
			// give out ring bonuses
			Y_AwardSpecialStageBonus();

1304
			for (i = 0; i < 2; ++i)
Jaime Ita Passos committed
1305
				data.spec.bonuspatches[i] = W_CachePatchName(data.spec.bonuses[i].patch, PU_PATCH);
1306

Jaime Ita Passos committed
1307 1308
			data.spec.pscore = W_CachePatchName("YB_SCORE", PU_PATCH);
			data.spec.pcontinues = W_CachePatchName("YB_CONTI", PU_PATCH);
Alam Ed Arias committed
1309 1310

			// get background tile
Jaime Ita Passos committed
1311
			bgtile = W_CachePatchName("SPECTILE", PU_PATCH);
Alam Ed Arias committed
1312 1313 1314 1315

			// grab an interscreen if appropriate
			if (mapheaderinfo[gamemap-1]->interscreen[0] != '#')
			{
Jaime Ita Passos committed
1316
				interpic = W_CachePatchName(mapheaderinfo[gamemap-1]->interscreen, PU_PATCH);
Alam Ed Arias committed
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
				useinterpic = true;
			}
			else
				useinterpic = false;

			// tile if using the default background
			usetile = !useinterpic;

			// get special stage specific patches
/*			if (!stagefailed && ALL7EMERALDS(emeralds))
			{
Jaime Ita Passos committed
1328
				data.spec.cemerald = W_CachePatchName("GOTEMALL", PU_PATCH);
Alam Ed Arias committed
1329 1330
				data.spec.headx = 70;
				data.spec.nowsuper = players[consoleplayer].skin
1331
					? NULL : W_CachePatchName("NOWSUPER", PU_PATCH);
Alam Ed Arias committed
1332 1333 1334
			}
			else
			{
Jaime Ita Passos committed
1335
				data.spec.cemerald = W_CachePatchName("CEMERALD", PU_PATCH);
Alam Ed Arias committed
1336 1337 1338 1339
				data.spec.headx = 48;
				data.spec.nowsuper = NULL;
			} */

1340 1341 1342 1343
			// Super form stuff (normally blank)
			data.spec.passed3[0] = '\0';
			data.spec.passed4[0] = '\0';

Alam Ed Arias committed
1344 1345 1346
			// set up the "got through act" message according to skin name
			if (stagefailed)
			{
1347
				strcpy(data.spec.passed2, "Special Stage");
Alam Ed Arias committed
1348 1349 1350 1351 1352 1353 1354 1355
				data.spec.passed1[0] = '\0';
			}
			else if (ALL7EMERALDS(emeralds))
			{
				snprintf(data.spec.passed1,
					sizeof data.spec.passed1, "%s",
					skins[players[consoleplayer].skin].realname);
				data.spec.passed1[sizeof data.spec.passed1 - 1] = '\0';
1356
				strcpy(data.spec.passed2, "got them all!");
1357

1358
				if (players[consoleplayer].charflags & SF_SUPER)
1359
				{
1360
					strcpy(data.spec.passed3, "can now become");
1361
					snprintf(data.spec.passed4,
1362
						sizeof data.spec.passed4, "Super %s",
1363 1364 1365
						skins[players[consoleplayer].skin].realname);
					data.spec.passed4[sizeof data.spec.passed4 - 1] = '\0';
				}
Alam Ed Arias committed
1366 1367 1368
			}
			else
			{
1369
				if (strlen(skins[players[consoleplayer].skin].realname) <= SKINNAMESIZE-5)
Alam Ed Arias committed
1370 1371
				{
					snprintf(data.spec.passed1,
1372
						sizeof data.spec.passed1, "%s got",
Alam Ed Arias committed
1373 1374 1375 1376
						skins[players[consoleplayer].skin].realname);
					data.spec.passed1[sizeof data.spec.passed1 - 1] = '\0';
				}
				else
1377 1378
					strcpy(data.spec.passed1, "You got");
				strcpy(data.spec.passed2, "a Chaos Emerald");
1379
				if (P_GetNextEmerald() > 6)
toaster committed
1380 1381 1382 1383
				{
					data.spec.passed2[15] = '?';
					data.spec.passed2[16] = '\0';
				}
Alam Ed Arias committed
1384 1385 1386
			}
			data.spec.passedx1 = (BASEVIDWIDTH - V_LevelNameWidth(data.spec.passed1))/2;
			data.spec.passedx2 = (BASEVIDWIDTH - V_LevelNameWidth(data.spec.passed2))/2;
1387 1388
			data.spec.passedx3 = (BASEVIDWIDTH - V_LevelNameWidth(data.spec.passed3))/2;
			data.spec.passedx4 = (BASEVIDWIDTH - V_LevelNameWidth(data.spec.passed4))/2;
Alam Ed Arias committed
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
			break;
		}

		case int_match:
		{
			// Calculate who won
			Y_CalculateMatchWinners();

			// set up the levelstring
			if (mapheaderinfo[prevmap]->actnum)
				snprintf(data.match.levelstring,
					sizeof data.match.levelstring,
					"%.32s * %d *",
					mapheaderinfo[prevmap]->lvlttl, mapheaderinfo[prevmap]->actnum);
			else
				snprintf(data.match.levelstring,
					sizeof data.match.levelstring,
					"* %.32s *",
					mapheaderinfo[prevmap]->lvlttl);

			data.match.levelstring[sizeof data.match.levelstring - 1] = '\0';

			// get RESULT header
			data.match.result =
Jaime Ita Passos committed
1413
				W_CachePatchName("RESULT", PU_PATCH);
Alam Ed Arias committed
1414

Jaime Ita Passos committed
1415
			bgtile = W_CachePatchName("SRB2BACK", PU_PATCH);
Alam Ed Arias committed
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
			usetile = true;
			useinterpic = false;
			break;
		}

		case int_race: // (time-only race)
		{
			// Calculate who won
			Y_CalculateTimeRaceWinners();

			// set up the levelstring
			if (mapheaderinfo[prevmap]->actnum)
				snprintf(data.match.levelstring,
					sizeof data.match.levelstring,
					"%.32s * %d *",
					mapheaderinfo[prevmap]->lvlttl, mapheaderinfo[prevmap]->actnum);
			else
				snprintf(data.match.levelstring,
					sizeof data.match.levelstring,
					"* %.32s *",
					mapheaderinfo[prevmap]->lvlttl);

			data.match.levelstring[sizeof data.match.levelstring - 1] = '\0';

			// get RESULT header
Jaime Ita Passos committed
1441
			data.match.result = W_CachePatchName("RESULT", PU_PATCH);
Alam Ed Arias committed
1442

Jaime Ita Passos committed
1443
			bgtile = W_CachePatchName("SRB2BACK", PU_PATCH);
Alam Ed Arias committed
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479
			usetile = true;
			useinterpic = false;
			break;
		}

		case int_teammatch:
		case int_ctf:
		{
			// Calculate who won
			Y_CalculateMatchWinners();

			// set up the levelstring
			if (mapheaderinfo[prevmap]->actnum)
				snprintf(data.match.levelstring,
					sizeof data.match.levelstring,
					"%.32s * %d *",
					mapheaderinfo[prevmap]->lvlttl, mapheaderinfo[prevmap]->actnum);
			else
				snprintf(data.match.levelstring,
					sizeof data.match.levelstring,
					"* %.32s *",
					mapheaderinfo[prevmap]->lvlttl);

			data.match.levelstring[sizeof data.match.levelstring - 1] = '\0';

			if (intertype == int_ctf)
			{
				data.match.redflag = rflagico;
				data.match.blueflag = bflagico;
			}
			else // team match
			{
				data.match.redflag = rmatcico;
				data.match.blueflag = bmatcico;
			}

Jaime Ita Passos committed
1480
			bgtile = W_CachePatchName("SRB2BACK", PU_PATCH);
Alam Ed Arias committed
1481 1482 1483 1484 1485
			usetile = true;
			useinterpic = false;
			break;
		}

1486
		case int_comp: // classic (full race)
Alam Ed Arias committed
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505
		{
			// find out who won
			Y_CalculateCompetitionWinners();

			// set up the levelstring
			if (mapheaderinfo[prevmap]->actnum)
				snprintf(data.competition.levelstring,
					sizeof data.competition.levelstring,
					"%.32s * %d *",
					mapheaderinfo[prevmap]->lvlttl, mapheaderinfo[prevmap]->actnum);
			else
				snprintf(data.competition.levelstring,
					sizeof data.competition.levelstring,
					"* %.32s *",
					mapheaderinfo[prevmap]->lvlttl);

			data.competition.levelstring[sizeof data.competition.levelstring - 1] = '\0';

			// get background tile
Jaime Ita Passos committed
1506
			bgtile = W_CachePatchName("SRB2BACK", PU_PATCH);
Alam Ed Arias committed
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
			usetile = true;
			useinterpic = false;
			break;
		}

		case int_none:
		default:
			break;
	}
}

//
// Y_CalculateMatchWinners
//
static void Y_CalculateMatchWinners(void)
{
	INT32 i, j;
	boolean completed[MAXPLAYERS];

	// Initialize variables
	memset(data.match.scores, 0, sizeof (data.match.scores));
	memset(data.match.color, 0, sizeof (data.match.color));
	memset(data.match.character, 0, sizeof (data.match.character));
	memset(data.match.spectator, 0, sizeof (data.match.spectator));
	memset(completed, 0, sizeof (completed));
	data.match.numplayers = 0;
	i = j = 0;

	for (j = 0; j < MAXPLAYERS; j++)
	{
		if (!playeringame[j])
			continue;

		for (i = 0; i < MAXPLAYERS; i++)
		{
			if (!playeringame[i])
				continue;

			if (players[i].score >= data.match.scores[data.match.numplayers] && completed[i] == false)
			{
				data.match.scores[data.match.numplayers] = players[i].score;
				data.match.color[data.match.numplayers] = &players[i].skincolor;
				data.match.character[data.match.numplayers] = &players[i].skin;
				data.match.name[data.match.numplayers] = player_names[i];
				data.match.spectator[data.match.numplayers] = players[i].spectator;
				data.match.num[data.match.numplayers] = i;
			}
		}
		completed[data.match.num[data.match.numplayers]] = true;
		data.match.numplayers++;
	}
}

//
// Y_CalculateTimeRaceWinners
//
static void Y_CalculateTimeRaceWinners(void)
{
	INT32 i, j;
	boolean completed[MAXPLAYERS];

	// Initialize variables

	for (i = 0; i < MAXPLAYERS; i++)
		data.match.scores[i] = INT32_MAX;

	memset(data.match.color, 0, sizeof (data.match.color));
	memset(data.match.character, 0, sizeof (data.match.character));
	memset(data.match.spectator, 0, sizeof (data.match.spectator));
	memset(completed, 0, sizeof (completed));
	data.match.numplayers = 0;
	i = j = 0;

	for (j = 0; j < MAXPLAYERS; j++)
	{
		if (!playeringame[j])
			continue;

		for (i = 0; i < MAXPLAYERS; i++)
		{
			if (!playeringame[i])
				continue;

			if (players[i].realtime <= data.match.scores[data.match.numplayers] && completed[i] == false)
			{
				data.match.scores[data.match.numplayers] = players[i].realtime;
				data.match.color[data.match.numplayers] = &players[i].skincolor;
				data.match.character[data.match.numplayers] = &players[i].skin;
				data.match.name[data.match.numplayers] = player_names[i];
				data.match.num[data.match.numplayers] = i;
			}
		}
		completed[data.match.num[data.match.numplayers]] = true;
		data.match.numplayers++;
	}
}

//
// Y_CalculateCompetitionWinners
//
static void Y_CalculateCompetitionWinners(void)
{
	INT32 i, j;
	boolean bestat[5];
	boolean completed[MAXPLAYERS];
	INT32 winner; // shortcut

	UINT32 points[MAXPLAYERS];
	UINT32 times[MAXPLAYERS];
	UINT32 rings[MAXPLAYERS];
	UINT32 maxrings[MAXPLAYERS];
	UINT32 monitors[MAXPLAYERS];
	UINT32 scores[MAXPLAYERS];
1620
	char tempname[9];
Alam Ed Arias committed
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634

	memset(data.competition.points, 0, sizeof (data.competition.points));
	memset(points, 0, sizeof (points));
	memset(completed, 0, sizeof (completed));

	// Award points.
	for (i = 0; i < MAXPLAYERS; i++)
	{
		if (!playeringame[i])
			continue;

		for (j = 0; j < 5; j++)
			bestat[j] = true;

1635 1636 1637
		if ((players[i].pflags & PF_GAMETYPEOVER) || players[i].lives <= 0)
			players[i].rings = 0;

Alam Ed Arias committed
1638
		times[i]    = players[i].realtime;
1639
		rings[i]    = (UINT32)max(players[i].rings, 0);
Alam Ed Arias committed
1640 1641
		maxrings[i] = (UINT32)players[i].totalring;
		monitors[i] = (UINT32)players[i].numboxes;
1642
		scores[i]   = (UINT32)min(players[i].score, MAXSCORE);
Alam Ed Arias committed
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653

		for (j = 0; j < MAXPLAYERS; j++)
		{
			if (!playeringame[j] || j == i)
				continue;

			if (players[i].realtime <= players[j].realtime)
				points[i]++;
			else
				bestat[0] = false;

1654
			if (max(players[i].rings, 0) >= max(players[j].rings, 0))
Alam Ed Arias committed
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714
				points[i]++;
			else
				bestat[1] = false;