00001 #include <string.h>
00002
00003 #include <gccore.h>
00004
00005 #include "globals.h"
00006 #include "prototypes.h"
00007 #include "PowerupUtils.h"
00008
00009 inline void IncreaseLevel(int player);
00010 inline void IncreaseLevelAllBut(int player);
00011
00012 int RemoveLines(int player)
00013 {
00014 int sil = 0;
00015 int width = g_players[player].playfieldWidth;
00016 int height = g_players[player].playfieldHeight;
00017
00018 for (int y = 0; y < height; ++y)
00019 {
00020 for (int x = 0; x < width; ++x)
00021 {
00022 if (map[player][x][y] != 9)
00023 ++sil;
00024 }
00025
00026 if (sil == width)
00027 {
00028 RemoveLine(y, player);
00029 return 1;
00030 }
00031
00032 sil = 0;
00033 }
00034
00035 return 0;
00036 }
00037
00038 void RemoveLine(int line, int player)
00039 {
00040 int width = g_players[player].playfieldWidth;
00041 TetrisPieceConnectivityInfo *connectivityInfo = NULL;
00042
00043 for (int x = 0; x < width; ++x)
00044 {
00045
00046 connectivityInfo = g_players[player].gameData.playfield[x][line].connectivityInfo;
00047 if (connectivityInfo)
00048 {
00049 connectivityInfo->counter--;
00050
00051 if (connectivityInfo->counter == 0)
00052 {
00053
00054 int slot = g_players[player].GetPowerupQueueSlot();
00055 if (slot >= 0)
00056 {
00057 Powerup *powerup = PowerupUtils::GetInstance(connectivityInfo->powerupId);
00058 g_players[player].QueuePowerup(powerup, slot);
00059 }
00060
00061 g_players[player].gameData.playfield[x][line].Free();
00062 }
00063 }
00064 }
00065
00066 for (int y = line; y > 0; --y)
00067 {
00068 for (int x = 0; x < width; ++x)
00069 {
00070 map[player][x][y] = map[player][x][y-1];
00071 g_players[player].gameData.playfield[x][y] = g_players[player].gameData.playfield[x][y-1];
00072 }
00073 }
00074
00075 for (int x = 0; x < width; ++x)
00076 {
00077 map[player][x][0] = 9;
00078 g_players[player].gameData.playfield[x][0].SetConnectivityInfo(NULL);
00079 }
00080
00081 g_players[player].gameData.lines++;
00082 g_players[player].gameData.score++;
00083
00084 if (options.players == 1)
00085 {
00086 if (g_players[0].gameData.lines % 10 == 0)
00087 IncreaseLevel(0);
00088
00089 return;
00090 }
00091
00092 int maxLines = g_players[player].isHandicapEnabled ?
00093 g_players[player].maxLines : options.maxLines;
00094
00095 if (maxLines && g_players[player].gameData.lines == maxLines)
00096 {
00097 winner(player);
00098 return;
00099 }
00100
00101 int attackRate = g_players[player].isHandicapEnabled ?
00102 g_players[player].attackRate : options.attackRate;
00103
00104
00105 if (attackRate && g_players[player].gameData.score % attackRate == 0)
00106 {
00107 IncreaseLevelAllBut(player);
00108 }
00109 }
00110
00111 void IncreaseLevel(int player)
00112 {
00113 if (g_players[player].gameData.level < 9)
00114 {
00115 g_players[player].gameData.level++;
00116 block[player].speed = timing[g_players[player].gameData.level];
00117 }
00118 }
00119
00120 void IncreaseLevelAllBut(int player)
00121 {
00122 for (int i = 0; i < options.players; ++i)
00123 {
00124 if (i != player)
00125 IncreaseLevel(i);
00126 }
00127 }