예제 #1
0
파일: dropweapon.cpp 프로젝트: paud/d2x-xl
//this function is for when the CPlayerData intentionally drops a powerup
//this function is based on DropPowerup()
int SpitPowerup (CObject *spitterP, ubyte id, int seed)
{
	short			nObject;
	CObject		*objP;
	CFixVector	newVelocity, newPos;
	tObjTransformation	*posP = OBJPOS (spitterP);

#if 0
if ((gameData.app.nGameMode & GM_NETWORK) &&
	 (gameData.multiplayer.powerupsInMine [(int)id] + PowerupsOnShips (id) >=
	  gameData.multiplayer.maxPowerupsAllowed [id]))
	return -1;
#endif
newVelocity = spitterP->mType.physInfo.velocity + spitterP->info.position.mOrient.FVec() * I2X (SPIT_SPEED);
newVelocity[X] += (d_rand() - 16384) * SPIT_SPEED * 2;
newVelocity[Y] += (d_rand() - 16384) * SPIT_SPEED * 2;
newVelocity[Z] += (d_rand() - 16384) * SPIT_SPEED * 2;
// Give keys zero velocity so they can be tracked better in multi
if (IsMultiGame && (id >= POW_KEY_BLUE) && (id <= POW_KEY_GOLD))
	newVelocity.SetZero ();
//there's a piece of code which lets the CPlayerData pick up a powerup if
//the distance between him and the powerup is less than 2 time their
//combined radii.  So we need to create powerups pretty far out from
//the player.
newPos = posP->vPos + posP->mOrient.FVec () * spitterP->info.xSize;
if (IsMultiGame && (gameData.multigame.create.nLoc >= MAX_NET_CREATE_OBJECTS))
	return (-1);
nObject = CreatePowerup (id, (short) (GetTeam (gameData.multiplayer.nLocalPlayer) + 1), (short) OBJSEG (spitterP), newPos,  1);
if (nObject < 0) {
	Int3();
	return nObject;
	}
objP = OBJECTS + nObject;
objP->mType.physInfo.velocity = newVelocity;
objP->mType.physInfo.drag = 512;	//1024;
objP->mType.physInfo.mass = I2X (1);
objP->mType.physInfo.flags = PF_BOUNCE;
objP->rType.vClipInfo.nClipIndex = gameData.objs.pwrUp.info [objP->info.nId].nClipIndex;
objP->rType.vClipInfo.xFrameTime = gameData.eff.vClipP [objP->rType.vClipInfo.nClipIndex].xFrameTime;
objP->rType.vClipInfo.nCurFrame = 0;
if (spitterP == gameData.objs.consoleP)
	objP->cType.powerupInfo.nFlags |= PF_SPAT_BY_PLAYER;
switch (objP->info.nId) {
	case POW_CONCUSSION_1:
	case POW_CONCUSSION_4:
	case POW_SHIELD_BOOST:
	case POW_ENERGY:
		objP->info.xLifeLeft = (d_rand() + I2X (3)) * 64;		//	Lives for 3 to 3.5 binary minutes (a binary minute is 64 seconds)
		if (gameData.app.nGameMode & GM_MULTI)
			objP->info.xLifeLeft /= 2;
		break;
	default:
		//if (gameData.app.nGameMode & GM_MULTI)
		//	objP->info.xLifeLeft = (d_rand() + I2X (3)) * 64;		//	Lives for 5 to 5.5 binary minutes (a binary minute is 64 seconds)
		break;
	}
MultiSendWeapons (1);
return nObject;
}
예제 #2
0
/*
=============================
idGameBustOutWindow::UpdateBall
=============================
*/
void idGameBustOutWindow::UpdateBall( void ) {
	int ballnum,i,j;
	bool playSoundBounce = false;
	bool playSoundBrick = false;
	static int bounceChannel = 1;

	if ( ballsInPlay == 0 ) {
		return;
	}

	for ( ballnum = 0; ballnum < balls.Num(); ballnum++ ) {
		BOEntity *ball = balls[ballnum];

		// Check for ball going below screen, lost ball
		if ( ball->position.y > 480.f ) {
			ball->removed = true;
			continue;
		}

		// Check world collision
		if ( ball->position.y < 20 && ball->velocity.y < 0 ) {
			ball->velocity.y = -ball->velocity.y;

			// Increase ball speed when it hits ceiling
			if ( !ballHitCeiling ) {
				ballSpeed *= 1.25f;
				ballHitCeiling = true;
			}
			playSoundBounce = true;
		}

		if ( ball->position.x > 608 && ball->velocity.x > 0 ) {
			ball->velocity.x = -ball->velocity.x;
			playSoundBounce = true;
		} else if ( ball->position.x < 8 && ball->velocity.x < 0 ) {
			ball->velocity.x = -ball->velocity.x;
			playSoundBounce = true;
		}

		// Check for Paddle collision
		idVec2 ballCenter = ball->position + idVec2( BALL_RADIUS, BALL_RADIUS );
		collideDir_t collision = paddle->checkCollision( ballCenter, ball->velocity );

		if ( collision == COLLIDE_UP ) {
			if ( ball->velocity.y > 0 ) {
				idVec2	paddleVec( paddleVelocity*2, 0 );
				float	centerX;

				if ( bigPaddleTime > gui->GetTime() ) {
					centerX = paddle->x + 80.f;
				} else {
					centerX = paddle->x + 48.f;
				}

				ball->velocity.y = -ball->velocity.y;

				paddleVec.x += (ball->position.x - centerX) * 2;

				ball->velocity += paddleVec;
				ball->velocity.NormalizeFast();
				ball->velocity *= ballSpeed;

				playSoundBounce = true;
			}
		} else if ( collision == COLLIDE_LEFT || collision == COLLIDE_RIGHT ) {
			if ( ball->velocity.y > 0 ) {
				ball->velocity.x = -ball->velocity.x;
				playSoundBounce = true;
			}
		}

		collision = COLLIDE_NONE;

		// Check for collision with bricks
		for ( i=0; i<BOARD_ROWS; i++ ) {
			int num = board[i].Num();

			for ( j=0; j<num; j++ ) {
				BOBrick *brick = (board[i])[j];

				collision = brick->checkCollision( ballCenter, ball->velocity );
				if ( collision ) {
					// Now break the brick if there was a collision
					brick->isBroken = true;
					brick->ent->fadeOut = true;

					if ( brick->powerup > POWERUP_NONE ) {
						CreatePowerup( brick );
					}

					numBricks--;
					gameScore += 100;
					updateScore = true;

					// Go ahead an forcibly remove the last brick, no fade
					if ( numBricks == 0 ) {
						brick->ent->removed = true;
					}
					board[i].Remove( brick );
					break;
				}
			}

			if ( collision ) {
				playSoundBrick = true;
				break;
			}
		}

		if ( collision == COLLIDE_DOWN || collision == COLLIDE_UP ) {
			ball->velocity.y *= -1;
		} else if ( collision == COLLIDE_LEFT || collision == COLLIDE_RIGHT ) {
			ball->velocity.x *= -1;
		}

		if ( playSoundBounce ) {
			session->sw->PlayShaderDirectly( "arcade_ballbounce", bounceChannel );
		} else if ( playSoundBrick ) {
			session->sw->PlayShaderDirectly( "arcade_brickhit", bounceChannel );
		}

		if ( playSoundBounce || playSoundBrick ) {
			bounceChannel++;
			if ( bounceChannel == 4 ) {
				bounceChannel = 1;
			}
		}
	}

	// Check to see if any balls were removed from play
	for ( ballnum=0; ballnum<balls.Num(); ballnum++ ) {
		if ( balls[ballnum]->removed ) {
			ballsInPlay--;
			balls.RemoveIndex( ballnum );
		}
	}

	// If all the balls were removed, update the game accordingly
	if ( ballsInPlay == 0 ) {
		if ( ballsRemaining == 0 ) {
			gameOver = true;

			// Game Over sound
			session->sw->PlayShaderDirectly( "arcade_sadsound", S_UNIQUE_CHANNEL );
		} else {
			ballsRemaining--;

			// Ball was lost, but game is not over
			session->sw->PlayShaderDirectly( "arcade_missedball", S_UNIQUE_CHANNEL );
		}

		ClearPowerups();
		updateScore = true;
	}
}
예제 #3
0
string osl_ExecuteSystemFunction(vector<OSL_LEXEM>* list)
{
	string _result;
	_result.resize(0);

	#ifdef _DEBUG_OSL
	WriteToLog(DEFAULT_OSL_LOG_NAME, "Executing system function...");
	#endif

	unsigned int param_count = 1;

	for(vector<OSL_LEXEM>::iterator it = list->begin();
		it != list->end();
		it++)
	{
		OSL_LEXEM lx = *it;

		if(osl_IsComma(lx.token))
			param_count++;
	}

	vector<OSL_LEXEM>::iterator i_first = list->begin();
	OSL_LEXEM first = *i_first;

	if(first.token == "echo")
	{
		vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
		OSL_LEXEM second = *i_second;

		char* message = new char[second.token.length()+1];
		strcpy(message, (char*)second.token.data());

		message = osl_RemoveQuotesChr(message);
		DoEcho(message);
	}
	else if(first.token == "load")
	{
		vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
		OSL_LEXEM second = *i_second;

		bool ok = DoLoad(osl_RemoveQuotesStr(second.token));

		ok == true ? _result = OSL_EXEC_OK : _result = OSL_EXEC_FAIL;
	}
	else if(first.token == "exit")
	{
		DoExit();
	}
	else if(first.token == "init")
	{
					vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
					OSL_LEXEM second = *i_second;

					if(second.token == "gui")
					{
						if(!gui)
						{
							gui = new GUI();
							_result = OSL_EXEC_OK;
						}
						else
						{
							osl_Error("GUI already initialized");
							_result = OSL_EXEC_FAIL;
						}
					}
					else
					{
						osl_Error("init(): unknown parameter");
						_result = OSL_EXEC_FAIL;
					}
	}
	else if(first.token == "loadconfig")
	{
		vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
		OSL_LEXEM second = *i_second;

		if(osl_IsStrConstant(second.token))
		{
			char* file = new char[second.token.length()+1];
			strcpy(file, (char*)second.token.data());
			file = osl_RemoveQuotesChr(file);

			bool ok = LoadConfig(file, &cfg);

			if(ok)
			{
				ApplyConfig(&cfg);
				_result = OSL_EXEC_OK;
			}
			else
				_result = OSL_EXEC_FAIL;
		}
		else
			osl_Error("LoadConfig(): Invalid argument");
	}
	else if(first.token == "loadfontfromfile")
	{
		WriteToLog(DEFAULT_OSL_LOG_NAME, "Trying to load font from file...");

		if(param_count == 3)
		{
			vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
			OSL_LEXEM second = *i_second;
			vector<OSL_LEXEM>::iterator i_third = list->begin()+4;
			OSL_LEXEM third = *i_third;
			vector<OSL_LEXEM>::iterator i_fourth = list->begin()+6;
			OSL_LEXEM fourth = *i_fourth;

			if(osl_IsIntConstant(third.token) &&
				osl_IsIntConstant(fourth.token))
			{
				try
				{
					if(LoadFontFromFile((char*)osl_RemoveQuotesStr(second.token).c_str(),
						osl_StrToInt(third.token),
						osl_StrToInt(fourth.token)))
					{
						WriteToLog(DEFAULT_OSL_LOG_NAME, "LoadFontFromFile OK");
						_result = OSL_EXEC_OK;
					}
					else
					{
						WriteToLog(DEFAULT_OSL_LOG_NAME, "LoadFontFromFile FAILED");
						_result = OSL_EXEC_FAIL;
					}
				}
				catch(...)
				{
					osl_Error("Exception in try block: LoadFontFromFile");
					_result = OSL_EXEC_FAIL;
				}			
			}
			else
			{
				osl_Error("LoadFontFromFile() error: incompatible types");
				_result = OSL_EXEC_FAIL;
			}
		}
		else
		{
			osl_Error("LoadFontFromFile() error: function require one parameter");
			_result = OSL_EXEC_FAIL;
		}
	}
	else if(first.token == "loadfont")
	{
		WriteToLog(DEFAULT_OSL_LOG_NAME, "Trying to load font...");
		if(param_count == 4)
		{
			vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
			OSL_LEXEM second = *i_second;
			vector<OSL_LEXEM>::iterator i_third = list->begin()+4;
			OSL_LEXEM third = *i_third;
			vector<OSL_LEXEM>::iterator i_fourth = list->begin()+6;
			OSL_LEXEM fourth = *i_fourth;
			vector<OSL_LEXEM>::iterator i_fifth = list->begin()+8;
			OSL_LEXEM fifth = *i_fifth;

			try
			{
				bool ok =
					LoadFont((char*)osl_RemoveQuotesStr(second.token).c_str(),
						osl_StrToInt(third.token),
						osl_StrToInt(fourth.token),
						(char*)osl_RemoveQuotesStr(fifth.token).c_str());

				ok == true ? _result = OSL_EXEC_OK : _result = OSL_EXEC_FAIL;
			}
			catch(...)
			{
				osl_Error("Exception in try block: LoadFont");
				_result = OSL_EXEC_FAIL;
			}
			WriteToLog(DEFAULT_OSL_LOG_NAME, "LoadFont OK");

		}
		else
		{
			osl_Error("LoadFont() error: function requires two parametres");
			_result = OSL_EXEC_FAIL;
		}
	}
	else if(first.token == "loadtexture")
	{
		WriteToLog(DEFAULT_OSL_LOG_NAME, "Trying to load texture...");
		if(param_count == 1)
		{
			vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
			OSL_LEXEM second = *i_second;

			try
			{
				string s = osl_RemoveQuotesStr(second.token);
				char* n = new char[strlen(s.data())+1];
				sprintf(n, "%s\0", s.data());

				if(!LoadTexture(n))
				{
					osl_Error("LoadTexture() failed");
					_result = OSL_EXEC_FAIL;
				}
				else
					_result = OSL_EXEC_OK;
				delete[] n;
			}
			catch(...)
			{
				osl_Error("Exception in try block: LoadTexture");
				_result = OSL_EXEC_FAIL;
			}
			WriteToLog(DEFAULT_OSL_LOG_NAME, "LoadTexture OK");
		}
		else
		{
			osl_Error("LoadTexture() error: function requires one parameter");
			_result = OSL_EXEC_FAIL;
		}
	}
	else if(first.token == "newguielem")
	{
		if(param_count == 2)
		{
			vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
			OSL_LEXEM second = *i_second;
			vector<OSL_LEXEM>::iterator i_third = list->begin()+4;
			OSL_LEXEM third = *i_third;

			NewGUIElem(osl_RemoveQuotesStr(second.token),
				osl_RemoveQuotesStr(third.token));
		}
		else
			osl_Error("NewGUIElem() error: function requires two parametres");
	}
	else if(first.token == "setguielem")
	{
		if(param_count == 3)
		{
			vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
			OSL_LEXEM second = *i_second;
			vector<OSL_LEXEM>::iterator i_third = list->begin()+4;
			OSL_LEXEM third = *i_third;
			vector<OSL_LEXEM>::iterator i_fourth = list->begin()+6;
			OSL_LEXEM fourth = *i_fourth;

			SetGUIElem(osl_RemoveQuotesStr(second.token),
				osl_RemoveQuotesStr(third.token),
				osl_RemoveQuotesStr(fourth.token));
		}
		else if(param_count == 5)
		{
			vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
			OSL_LEXEM second = *i_second;
			vector<OSL_LEXEM>::iterator i_third = list->begin()+4;
			OSL_LEXEM third = *i_third;
			vector<OSL_LEXEM>::iterator i_fourth = list->begin()+6;
			OSL_LEXEM fourth = *i_fourth;
			vector<OSL_LEXEM>::iterator i_fifth = list->begin()+8;
			OSL_LEXEM fifth = *i_fifth;
			vector<OSL_LEXEM>::iterator i_sixth = list->begin()+10;
			OSL_LEXEM sixth = *i_sixth;

			SetGUIElem(osl_RemoveQuotesStr(second.token),
				osl_RemoveQuotesStr(third.token),
				osl_RemoveQuotesStr(fourth.token),
				osl_RemoveQuotesStr(fifth.token),
				osl_RemoveQuotesStr(sixth.token));
		}
		else if(param_count == 6)
		{
			vector<OSL_LEXEM>::iterator i_second = list->begin()+2;
			OSL_LEXEM second = *i_second;
			vector<OSL_LEXEM>::iterator i_third = list->begin()+4;
			OSL_LEXEM third = *i_third;
			vector<OSL_LEXEM>::iterator i_fourth = list->begin()+6;
			OSL_LEXEM fourth = *i_fourth;
			vector<OSL_LEXEM>::iterator i_fifth = list->begin()+8;
			OSL_LEXEM fifth = *i_fifth;
			vector<OSL_LEXEM>::iterator i_sixth = list->begin()+10;
			OSL_LEXEM sixth = *i_sixth;
			vector<OSL_LEXEM>::iterator i_seventh = list->begin()+12;
			OSL_LEXEM seventh = *i_seventh;

			SetGUIElem(osl_RemoveQuotesStr(second.token),
				osl_RemoveQuotesStr(third.token),
				osl_RemoveQuotesStr(fourth.token),
				osl_RemoveQuotesStr(fifth.token),
				osl_RemoveQuotesStr(sixth.token),
				osl_RemoveQuotesStr(seventh.token));
		}
		else
			osl_Error("NewGUIElem() error: incorrect number of parametres");
	}
	else if(first.token == "createplayer")
	{
		if(param_count == 28)
		{
			vector<OSL_LEXEM>::iterator p1 = list->begin()+2;
			vector<OSL_LEXEM>::iterator p2 = list->begin()+4;
			vector<OSL_LEXEM>::iterator p3 = list->begin()+6;
			vector<OSL_LEXEM>::iterator p4 = list->begin()+8;
			vector<OSL_LEXEM>::iterator p5 = list->begin()+10;
			vector<OSL_LEXEM>::iterator p6 = list->begin()+12;
			vector<OSL_LEXEM>::iterator p7 = list->begin()+14;
			vector<OSL_LEXEM>::iterator p8 = list->begin()+16;
			vector<OSL_LEXEM>::iterator p9 = list->begin()+18;
			vector<OSL_LEXEM>::iterator p10 = list->begin()+20;
			vector<OSL_LEXEM>::iterator p11 = list->begin()+22;
			vector<OSL_LEXEM>::iterator p12 = list->begin()+24;
			vector<OSL_LEXEM>::iterator p13 = list->begin()+26;
			vector<OSL_LEXEM>::iterator p14 = list->begin()+28;
			vector<OSL_LEXEM>::iterator p15 = list->begin()+30;
			vector<OSL_LEXEM>::iterator p16 = list->begin()+32;
			vector<OSL_LEXEM>::iterator p17 = list->begin()+34;
			vector<OSL_LEXEM>::iterator p18 = list->begin()+36;
			vector<OSL_LEXEM>::iterator p19 = list->begin()+38;
			vector<OSL_LEXEM>::iterator p20 = list->begin()+40;
			vector<OSL_LEXEM>::iterator p21 = list->begin()+42;
			vector<OSL_LEXEM>::iterator p22 = list->begin()+44;
			vector<OSL_LEXEM>::iterator p23 = list->begin()+46;
			vector<OSL_LEXEM>::iterator p24 = list->begin()+48;
			vector<OSL_LEXEM>::iterator p25 = list->begin()+50;
			vector<OSL_LEXEM>::iterator p26 = list->begin()+52;
			vector<OSL_LEXEM>::iterator p27 = list->begin()+54;
			vector<OSL_LEXEM>::iterator p28 = list->begin()+56;

			CreatePlayer((*p1).token, (*p2).token, (*p3).token, (*p4).token,
				(*p5).token, (*p6).token, (*p7).token, (*p8).token, (*p9).token,
				(*p10).token, (*p11).token, (*p12).token, (*p13).token, (*p14).token,
				(*p15).token, (*p16).token, (*p17).token, (*p18).token, (*p19).token,
				(*p20).token, (*p21).token, (*p22).token, (*p23).token, (*p24).token,
				(*p25).token, (*p26).token, (*p27).token, (*p28).token);


		}
		else
			osl_Error("CreatePlayer() error: incorrect number of parametres");
	}
	else if(first.token == "createpowerup")
	{
		if(param_count == 4)
		{
			vector<OSL_LEXEM>::iterator p1 = list->begin()+2;
			vector<OSL_LEXEM>::iterator p2 = list->begin()+4;
			vector<OSL_LEXEM>::iterator p3 = list->begin()+6;
			vector<OSL_LEXEM>::iterator p4 = list->begin()+8;

			CreatePowerup((*p1).token, (*p2).token, (*p3).token, (*p4).token);

		}
		else
			osl_Error("CreatePowerup() error: incorrect number of parametres");
	}
	else if(first.token == "createenemy")
	{
		if(param_count == 3)
		{
			vector<OSL_LEXEM>::iterator p1 = list->begin()+2;
			vector<OSL_LEXEM>::iterator p2 = list->begin()+4;
			vector<OSL_LEXEM>::iterator p3 = list->begin()+6;

			CreateEnemy((*p1).token, (*p2).token, (*p3).token);
		}
		else
			osl_Error("CreateEnemy() error: incorrect number of parametres");
	}
	else
		osl_Error("Command is not implemented yet");

	return _result;

}