示例#1
0
void AIControl( int player )
{
	if( timeAI[player] > GameTickCount() )
		return;

	timeAI[player] += moveQuick[player]? character[player].speedRush:
	                                     character[player].speedNormal;

	switch( RandomBefore( 2 ) )
	{
		case 0:
			if( destinationR[player] != blobR[player] )
			{
				if( CanRotate(player) )
				{
					DoRotate( player );
				}
			}
			break;

		case 1:
			if( destinationX[player] != blobX[player] )
			{
				if( destinationX[player] > blobX[player] )
				{
					if( CanGoRight( player ) )
						GoRight( player );
				}
				else
				{
					if( CanGoLeft( player ) )
						GoLeft( player );
				}
			}
			break;
	}

	if( destinationX[player] == blobX[player] &&
		destinationR[player] == blobR[player] &&
		RandomBefore( 100 ) < character[player].intellect )
	{
		DoDrop( player );
	}
}
示例#2
0
int GetMagic( int player )
{
	int result;
	int realSeed;
	
	realSeed = internalRandomSeed;
	
	internalRandomSeed = randomSeed[player];
	result = (RandomBefore(19) == 0)? true: false;
	randomSeed[player] = internalRandomSeed;
	
	internalRandomSeed = realSeed;

	return result;
}
示例#3
0
int GetPiece( int player )
{
	int result;
	unsigned int  realSeed;
	
	realSeed = internalRandomSeed;
	
	internalRandomSeed = randomSeed[player];
	result = pieceMap[RandomBefore(numPieces)];
	randomSeed[player] = internalRandomSeed;
	
	internalRandomSeed = realSeed;

	return result;
}
示例#4
0
void InitRandom( int inNumPieces )
{
	int count, swap, swapWith;
	
	numPieces = inNumPieces;
	randomSeed[0] = randomSeed[1] = SDL_GetTicks();
	pieceCount[0] = pieceCount[1] = 0;
	grenadeTimer[0] = grenadeTimer[1] = 40;
	
	for( count=0; count<kBlobTypes; count++ )
	{
		pieceMap[count] = count+1;
	}

	for( count=0; count<kBlobTypes; count++ )
	{
		swapWith = RandomBefore( kBlobTypes );
		swap = pieceMap[swapWith];
		pieceMap[swapWith] = pieceMap[count];
		pieceMap[count] = swap;
	}
}
示例#5
0
void ChooseAIDestination( int player )
{
	int testX, testR, testX2, testR2, value, bestValue = -9999999;
	int x, y;
	int bestX[kGridAcross*4], bestR[kGridAcross*4], currentBest = -1;
	int rowDifference, totalTries, temp;
	bool shouldTry[kGridAcross][4];

	timeAI[player] = GameTickCount( ) + 1;
	moveQuick[player] = true;

	if( grenade[player] )
	{
		bestValue = 0;
		currentBest = 2;

		for( testX = 0; testX < kGridAcross; testX++ )
		{
			rowDifference = GetRowHeight( player, testX );

			if( (rowDifference < kGridDown) &&
					(grid[player][testX][rowDifference+1] >= kFirstBlob) &&
					(grid[player][testX][rowDifference+1] <= kLastBlob)     )
			{
				value = 0;

				for( x=0; x<kGridAcross; x++ )
				{
					for( y=0; y<kGridDown; y++ )
					{
						if( grid[player][x][y] == grid[player][testX][rowDifference+1] ) value++;
					}
				}

				if( value > bestValue )
				{
					bestValue = value;
					currentBest = testX;
				}
			}
		}

		destinationR[player] = upRotate;
		destinationX[player] = currentBest;
		return;
	}

	if( (GameTickCount() - startTime) <= 3600 )
	{
		for( testX = 0; testX < kGridAcross; testX++ )
		{
			rowDifference =  GetRowHeight( player, testX ) - character[player].autoSetup[testX];

			if( rowDifference >= 2 )
			{
				destinationR[player] = downRotate;
				destinationX[player] = testX;
				return;
			}

			if( rowDifference == 1 )
			{
				destinationX[player] = testX;

				if( testX > 0 )
				{
					if( GetRowHeight( player, testX-1 ) > character[player].autoSetup[testX-1] )
					{
						destinationR[player] = leftRotate;
						return;
					}
				}

				if( testX < (kGridAcross-1) )
				{
					if( GetRowHeight( player, testX+1 ) > character[player].autoSetup[testX+1] )
					{
						destinationR[player] = rightRotate;
						return;
					}
				}

				destinationR[player] = upRotate;
				return;
			}
		}
	}

	moveQuick[player] = (emotions[player] == kEmotionSad) || (emotions[player] == kEmotionPanic);

	totalTries = character[player].intellect;
	for( testX = 0; testX < kGridAcross; testX++ )
	{
		for( testR = 0; testR < 4; testR++ )
		{
			shouldTry[testX][testR] = --totalTries >= 0;
		}
	}

	for( testX = 0; testX < kGridAcross; testX++ )
	{
		for( testR = 0; testR < 4; testR++ )
		{
			testX2 = RandomBefore( kGridAcross );
			testR2 = RandomBefore( 4 );

			temp = shouldTry[testX][testR];
			shouldTry[testX][testR] = shouldTry[testX2][testR2];
			shouldTry[testX2][testR2] = temp;
		}
	}

	shouldTry[0][leftRotate]			  = false;
	shouldTry[kGridAcross-1][rightRotate] = false;

	for( testX = 0; testX < kGridAcross; testX++ )
	{
		for( testR = 0; testR<=3; testR++ )
		{
			if( shouldTry[testX][testR] )
			{
				value = TestAIDestination( player, testX, testR );

				if( value > bestValue )
				{
					bestValue = value;
					currentBest = -1;
				}

				if( value == bestValue )
				{
					currentBest++;
					bestX[currentBest] = testX;
					bestR[currentBest] = testR;
				}
			}
		}
	}

	currentBest = RandomBefore( currentBest + 1 );
	destinationX[player] = bestX[currentBest];
	destinationR[player] = bestR[currentBest];
}
示例#6
0
void UpdateOpponent( void )
{
	MRect    myRect = {0,0,64,64}, dstRect = {0,0,64,64}, maskRect;
	int      emotiMap[] = {0, 1, 2, 1}, draw = false, count;
	SDL_Rect srcSDLRect, dstSDLRect;
	
	if( GameTickCount( ) > opponentTime )
	{
		switch( opponentMood )
		{
			case 0: 				// Idle
				opponentTime += 60 + RandomBefore(180);
				opponentMood = RandomBefore(2) + 1;
				opponentFrame = (emotiMap[emotions[1]] * kOppFrames);
				break;
			
			case 1:					// Shifty Eyes
				opponentTime += 40 + RandomBefore(60);
				opponentMood = 0;
				opponentFrame = (emotiMap[emotions[1]] * kOppFrames) + RandomBefore(2) + 1;
				break;

			case 2:					// Blinks
				opponentTime += 3;
				opponentMood = 3;
				opponentFrame = (emotiMap[emotions[1]] * kOppFrames) + 3;
				break;
			
			case 3:					// Blinks (more)
				opponentTime += 3;
				opponentMood = 4;
				opponentFrame = (emotiMap[emotions[1]] * kOppFrames) + 4;
				break;
			
			case 4: 				// Blinks (more)
				opponentTime += 3;
				opponentMood = 0;
				opponentFrame = (emotiMap[emotions[1]] * kOppFrames) + 3;
				break;
			
			case 5:                 // Chatter (only good for tutorial)
				opponentTime += 8;
				opponentMood = 6;
				opponentFrame = 5;
				break;

			case 6:					// Chatter 2 (only good for tutorial)
				opponentTime += 8;
				opponentMood = 5;
				opponentFrame = 6;
				break;
			
			case 7:					// Pissed (when hit with punishments)
				opponentTime += 60;
				opponentFrame = 7;
				opponentMood = 0;
				break;
		}
		
		draw = true;
	}
	
	if( GameTickCount( ) > panicTime )
	{
		panicTime += 2;
		
		if( emotions[1] == kEmotionPanic )
		{
			if( ++panicFrame >= kGlowArraySize ) panicFrame = 0;
			draw = true;
		}
		else
		{
			panicFrame = 0;
		}
	}
	
	for( count=0; count<kGlows; count++ )
	{
		if( GameTickCount( ) > glowTime[count] )
		{
			glowTime[count] += character[1].glow[count].time;
			
			if( character[1].glow[count].color )
			{
				if( ++glowFrame[count] >= kGlowArraySize ) glowFrame[count] = 0;
				draw = true;
			}
			else
			{
				glowFrame[count] = 0;
			}
		}
	}
	
	if( draw )
	{
		OffsetMRect( &myRect, 64*opponentFrame, 0 );
		
		SDLU_AcquireSurface( opponentDrawSurface );
		
		SDLU_BlitSurface( opponentSurface,     SDLU_MRectToSDLRect( &myRect, &srcSDLRect ),
		                  opponentDrawSurface, SDLU_MRectToSDLRect( &dstRect, &dstSDLRect )  );
		
		maskRect = myRect;
		for( count=0; count<kGlows; count++ )
		{
			OffsetMRect( &maskRect, 0, 64 );

			if( glowFrame[count] )
			{
				if( character[1].glow[count].color & 0x8000 )
				{
					SurfaceBlitColor(  opponentMaskSurface,  opponentDrawSurface,
					                  &maskRect,            &dstRect, 
					                   (character[1].glow[count].color & 0x7C00) >> 10,
									   (character[1].glow[count].color & 0x03E0) >> 5,
									   (character[1].glow[count].color & 0x001F),
									   heavyGlowArray[glowFrame[count]] );
				}
				else
				{
					SurfaceBlitColor(  opponentMaskSurface,  opponentDrawSurface,
					                  &maskRect,            &dstRect, 
					                   (character[1].glow[count].color & 0x7C00) >> 10,
									   (character[1].glow[count].color & 0x03E0) >> 5,
									   (character[1].glow[count].color & 0x001F),
									   lightGlowArray[glowFrame[count]] );
				}
			}
		}