Ejemplo n.º 1
0
void PlayLoop (void)
{
	id0_char_t shot_color[3] = {4,9,14};

	id0_int_t allgems[5]={GEM_DELAY_TIME,		// used for Q & D comparison
						 GEM_DELAY_TIME,		// for having all gems...
						 GEM_DELAY_TIME,		// the "allgems" declaration MUST
						 GEM_DELAY_TIME,		// match the "gems" declaration in
						 GEM_DELAY_TIME		// the gametype structure!
						};

//	id0_int_t originx=0;
//	id0_int_t i=100;
	id0_signed_long_t dx,dy/*,radius*/,psin,pcos,newx,newy;
	//id0_int_t		give;
	id0_short_t objnum;
	id0_signed_long_t ox,oy,xl,xh,yl,yh,px,py,norm_dx,norm_dy;
	id0_short_t o_radius;

	void (*think)(struct objstruct *); // REFKEEN: C++ patch

	ingame = true;
	SD_SetTimeCount(0);
	playstate = (exittype)0;
	//playstate = TimeCount = 0;
	gamestate.shotpower = handheight = 0;
	pointcount = pointsleft = 0;

	status_flag = S_NONE;

#if 0
	// setup sky/ground colors and effects (based on level)
	//
	switch (gamestate.mapon)
	{
		case 255:
			if (!(BGFLAGS & BGF_NIGHT))
			{
				InitBgChange(3*60,sky_daytonight,-1,NULL,BGF_NIGHT);
				groundcolor = &gnd_colors[0];
			}
			else
			{
				skycolor = &sky_colors[0];
				groundcolor = &gnd_colors[0];
			}
		break;

		default:
			skycolor = &sky_colors[gamestate.mapon];
			groundcolor = &gnd_colors[gamestate.mapon];
			skytimer = groundtimer = -1;
		break;
	}
#endif

	BGFLAGS |= BGF_NOT_LIGHTNING;
	skytimer = groundtimer = -1;

	debug_gnd = *groundcolor;
	debug_sky = *skycolor;
	RedrawStatusWindow();
	ThreeDRefresh();
	if (screenfaded)
		VW_FadeIn();

#ifndef PROFILE
	fizzlein = true;				// fizzle fade in the first refresh
#endif
	/*TimeCount = */lasttimecount = lastnuke = 0;
	SD_SetTimeCount(0);

	PollControls ();				// center mouse
//	StartMusic ();
	do
	{
#ifndef PROFILE
		PollControls();
#else
		control.xaxis = 1;
		//if (++TimeCount == 300)
		//	return;
		SD_AddToTimeCount(1);
		if (SD_GetTimeCount() == 300)
			return;
#endif
		DisplayStatus(&status_flag);

		objnum=0;
		for (obj = player;obj;obj = obj->next)
		{
			if ((obj->active >= yes) && (!(FreezeTime && (obj!=player))))
			{
				if (obj->ticcount)
				{
					obj->ticcount-=realtics;
					while ( obj->ticcount <= 0)
					{
						think = obj->state->thinkptr;
						if (think)
						{
							statetype *oldstate=obj->state;

							think (obj);
							if (!obj->state)
							{
								RemoveObj (obj);
								goto nextactor;
							}
							if (obj->state != oldstate)
								break;
						}

						obj->state = obj->state->next;
						if (!obj->state)
						{
							RemoveObj (obj);
							goto nextactor;
						}
						if (!obj->state->tictime)
						{
							obj->ticcount = 0;
							goto nextactor;
						}
						if (obj->state->tictime>0)
							obj->ticcount += obj->state->tictime;
					}
				}

				think =	obj->state->thinkptr;
				if (think)
				{
					think (obj);
					if (!obj->state)
						RemoveObj (obj);
				}
nextactor:;
			}

			// keep a list of objects around the player for radar updates
			//
				if (obj == player)
				{
					px = player->x;
					py = player->y;
					psin = sintable[player->angle];
					pcos = costable[player->angle];
					xl = px-((id0_long_t)RADAR_WIDTH<<TILESHIFT)/2;
					xh = px+((id0_long_t)RADAR_WIDTH<<TILESHIFT)/2-1;
					yl = py-((id0_long_t)RADAR_HEIGHT<<TILESHIFT)/2;
					yh = py+((id0_long_t)RADAR_HEIGHT<<TILESHIFT)/2;
				}

				if (objnum > MAX_RADAR_BLIPS-2)
					objnum = MAX_RADAR_BLIPS-2;

				ox = obj->x;
				oy = obj->y;


				if ((ox >= xl) && (ox <= xh) && (oy >= yl) && (oy <= yh))
				{
					norm_dx = (dx = px-ox)>>TILESHIFT;
					norm_dy = (dy = oy-py)>>TILESHIFT;

					id0_int_t IntSqrt(id0_long_t va);

					o_radius = IntSqrt((norm_dx * norm_dx) + (norm_dy * norm_dy));

					if (o_radius < RADAR_RADIUS)
					{
						newx = FixedByFrac(dy,pcos)-FixedByFrac(dx,psin);
						newy = FixedByFrac(dy,psin)+FixedByFrac(dx,pcos);

						RadarXY[objnum][0]=newx>>TILESHIFT;
						RadarXY[objnum][1]=newy>>TILESHIFT;

						// Define color to use for this object...
						//

						switch (obj->obclass)
						{
			// NO GEM NEEDED
			//
					// THE WIZARD! (YOU)
					//
							case playerobj:
								RadarXY[objnum++][2]=15;
							break;

					// WIZARD'S SHOTS
					//
							case pshotobj:
							case bigpshotobj:
								RadarXY[objnum++][2]=shot_color[screenpage];
							break;

					// BATS	    							(DK GRAY)
					//
							case batobj:
								if (obj->active == always)
									RadarXY[objnum++][2]=8;
							break;

					// RABBITS	    						(LT GRAY)
					//
							case bunnyobj:
								if (obj->active == always)
									RadarXY[objnum++][2]=7;
							break;

			// RED GEM
			//
					// EYE, RED DEMON        					(DK RED)
					//
							case eyeobj:
							case reddemonobj:
								if (gamestate.gems[B_RGEM-B_RGEM])
									if (obj->active == always)
										RadarXY[objnum++][2]=4;
							break;

					// RED MAGE							(LT RED)
					//
							case mageobj:
								if (gamestate.gems[B_RGEM-B_RGEM])
									if (obj->active == always)
										RadarXY[objnum++][2]=12;
							break;

			// BLUE GEM
			//
					// SUCCUBUS							(LT BLUE)
					//
							case succubusobj:
								if (gamestate.gems[B_BGEM-B_RGEM])
									if (obj->active == always)
										RadarXY[objnum++][2]=9;
							break;

					// WATER DRAGON							(DK BLUE)
					//
							case wetobj:
								if (gamestate.gems[B_GGEM-B_RGEM])
									if (obj->active == always)
										RadarXY[objnum++][2]=1;
							break;



			// GREEN GEM
			//
					// GREEN TROLL							(LT GREEN)
					//
							case fatdemonobj:
								if (gamestate.gems[B_GGEM-B_RGEM])
									if (obj->active == always)
										RadarXY[objnum++][2]=10;
							break;

					// GODESS							(DK GREEN)
					//
							case godessobj:
								if (gamestate.gems[B_GGEM-B_RGEM])
									if (obj->active == always)
										RadarXY[objnum++][2]=2;
							break;

			// YELLOW GEM
			//
					// ANT								(BROWN)
					//
							case antobj:
							case treeobj:
								if (gamestate.gems[B_YGEM-B_RGEM])
									if (obj->active == always)
										RadarXY[objnum++][2]=6;
							break;

					// SKELETON							(YELLOW)
					//
							case skeletonobj:
								if (gamestate.gems[B_YGEM-B_RGEM])
									if (obj->active == always)
										RadarXY[objnum++][2]=14;
							break;

			// PURPLE GEM
			//
					// ZOMBIE
					//
							case zombieobj:
								if (gamestate.gems[B_PGEM-B_RGEM])
									if (obj->active == always)
										RadarXY[objnum++][2]=13;
							break;

			// ALL GEMS NEEDED
			//
					// NEMESIS
					//
							case grelmobj:
								if (!memcmp(gamestate.gems,allgems,sizeof(gamestate.gems)))
									if (obj->active == always)
										RadarXY[objnum++][2]=15;
							break;
						}
					}
				}
		}
Ejemplo n.º 2
0
void PlayLoop (void)
{
	id0_int_t		give;

	void (*think)(struct objstruct *); // REFKEEN: C++ patch

	ingame = true;
	SD_SetTimeCount(0);
	playstate = (exittype)0;
	//playstate = TimeCount = 0;
	gamestate.shotpower = handheight = 0;
	pointcount = pointsleft = 0;

	DrawLevelNumber (gamestate.mapon);
	DrawBars ();

#ifndef PROFILE
	fizzlein = true;				// fizzle fade in the first refresh
#endif
	/*TimeCount = */lasttimecount = lastnuke = 0;

	PollControls ();				// center mouse
	StartMusic ();
	do
	{
#ifndef PROFILE
		PollControls();
#else
		c.xaxis = 1;
//		if (++TimeCount == 300)
//			return;
		SD_SetTimeCount(SD_GetTimeCount()+1);
		if (SD_GetTimeCount() == 300)
			return;
#endif

		for (obj = player;obj;obj = obj->next)
			if (obj->active)
			{
				if (obj->ticcount)
				{
					obj->ticcount-=tics;
					while ( obj->ticcount <= 0)
					{
						think = obj->state->thinkptr;
						if (think)
						{
							think (obj);
							if (!obj->state)
							{
								RemoveObj (obj);
								goto nextactor;
							}
						}

						obj->state = obj->state->next;
						if (!obj->state)
						{
							RemoveObj (obj);
							goto nextactor;
						}
						if (!obj->state->tictime)
						{
							obj->ticcount = 0;
							goto nextactor;
						}
						if (obj->state->tictime>0)
							obj->ticcount += obj->state->tictime;
					}
				}
				think =	obj->state->thinkptr;
				if (think)
				{
					think (obj);
					if (!obj->state)
						RemoveObj (obj);
				}
nextactor:;
			}


		if (bordertime)
		{
			bordertime -= tics;
			if (bordertime<=0)
			{
				bordertime = 0;
				VW_ColorBorder (3);
			}
		}

		if (pointcount)
		{
			pointcount -= tics;
			if (pointcount <= 0)
			{
				pointcount += POINTTICS;
				give = (pointsleft > 1000)? 1000 :
						(
							(pointsleft > 100)? 100 :
								((pointsleft < 20)? pointsleft : 20)
						);
				SD_PlaySound (GETPOINTSSND);
				AddPoints (give);
				pointsleft -= give;
				if (!pointsleft)
					pointcount = 0;
			}
		}

		ThreeDRefresh ();

		CheckKeys();
		// (REFKEEN) SPECIAL - Without this the game
		// can run very fast, even if it's not noticeable
		// (a lot of PlayLoop iterations and consumed CPU power)
		//
		// Notes:
		// 1. Should NOT be called from ThreeDRefresh/CalcTics,
		// because we don't always want that to be done
		// (e.g., FizzleFade effect right after loading C4 saved game).
		// 2. SHOULD be called AFTER CheckKeys. That function resets
		// lasttimecount (just like CalcTics) if the debug key modifier
		// (F10 in Cat. 3-D/Abyss, Backspace in Armageddon/Apocalypse)
		// is held. As a consequence, if the wait is done before the
		// call to CheckKeys then the game may seem to get stuck while
		// the debug key modifier is held.
		BE_ST_TimeCountWaitFromSrc(SD_GetTimeCount(), 1);
		//
		if (singlestep)
		{
			VW_WaitVBL(14);
			lasttimecount = SD_GetTimeCount();
		}
		if (extravbls)
			VW_WaitVBL(extravbls);

	}while (!playstate);
	StopMusic ();

	ingame = false;
	if (bordertime)
	{
		bordertime = 0;
		VW_ColorBorder (3);
	}

	if (!abortgame)
		AddPoints (pointsleft);
	else
		abortgame = false;
}