int i, j, result;
char type, rotation;
- type = s/4;
- rotation = s&3;
- for (i = 0; i<4; i++)
- for (j = 0; j<4; j++)
+ type = s / 4;
+ rotation = s & 3;
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++)
if (shapes[type][rotation][i][j])
if (result = func(scr, y-i, x+j, shapes[type][rotation][i][j]))
return result;
int i;
float total = 0, val;
- for (i = 0; i<7; i++) total += options[i];
- val = Random(0, 32767)/32768.0*total;
- for (i = 0; i<7; i++) if ((val -= options[i])<0) return i<<2;
+ for (i = 0; i < 7; i++) total += options[i];
+ val = Random(0, 32767) / 32768.0 * total;
+ for (i = 0; i < 7; i++) if ((val -= options[i]) < 0)
+ return i << 2;
return 0;
}
unsigned char z;
if (!Game.gravity) return 0;
- for (y = Players[scr].boardHeight-1; y > 0; y--)
+ for (y = Players[scr].boardHeight - 1; y > 0; y--)
for (x = 0; x < Players[scr].boardWidth; x++) {
if (((z = GetBlock(scr, y, x)) > BT_none) && ((z & 160) == 0)) {
//doesn't stick left/up => topleft block
from++; //skip
for (x = 0; x<Players[scr].boardWidth; x++) {
SetBlock(scr, from, x, GetBlock(scr, from, x)&239);
- if (from>1)
+ if (from > 1)
SetBlock(scr, from-2, x, GetBlock(scr, from-2, x)&223);
} //don't stick blocks to line which we'll remove
} //full lines
#endif
static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event);
-static EventGenRec keyGen =
-// { NULL, 0, FT_read, STDIN_FILENO, KeyGenFunc, EM_key };
- { NULL, 0, FT_read, STDIN_FILENO, KeyGenFunc, EM_key };
+static EventGenRec keyGen = {
+// NULL, 0, FT_read, STDIN_FILENO, KeyGenFunc, EM_key
+ NULL, 0, FT_read, STDIN_FILENO, KeyGenFunc, EM_key
+};
static int boardYPos[MAX_SCREENS], boardXPos[MAX_SCREENS];
static int boardSize[MAX_SCREENS];
static int haveColor;
int PlayerDisp[MAX_SCREENS];
-#define MSG_HEIGHT 64 //max history
+#define MSG_HEIGHT 64 //max history
char *message[MSG_HEIGHT];
char messages[MSG_HEIGHT][MSG_WIDTH];
-static char *term_vi; /* String to make cursor invisible */
-static char *term_ve; /* String to make cursor visible */
+static char *term_vi; /* String to make cursor invisible */
+static char *term_ve; /* String to make cursor visible */
void InitScreens(void)
{
"vt100", "vt101", "vt102",
"vt200", "vt220", "vt300",
"vt320", "vt400", "vt420",
- "screen", "xterm", NULL };
+ "screen", "xterm", NULL
+ };
int i;
for (i = 0; vts[i]; i++)
- if (!strcmp(term, vts[i]))
- {
+ if (!strcmp(term, vts[i])) {
term_vi = "\033[?25l";
term_ve = "\033[?25h";
break;
mvwaddch(msgwin, messageHeight-1, (x+1) % (messageWidth-1), ' ');
} //escape
else {
- if (c == 13 || c==127) //enter/backspace
+ if (c == 13 || c == 127) //enter/backspace
mvwaddch(msgwin, messageHeight - 1, (x+2) % (messageWidth-1),
- x>=messageWidth-3 ? s[x - messageWidth + 3] : ' ');
+ x >= messageWidth-3 ? s[x - messageWidth + 3] : ' ');
else //any character
mvwaddch(msgwin, messageHeight - 1, x % (messageWidth-1), c);
mvwaddch(msgwin, messageHeight - 1, (x+1) % (messageWidth-1), '_');
}
void PlotBlock(int scr, int y, int x, unsigned char type)
{
- if (y >= 0 && y < Players[scr].boardVisible &&
- x >= 0 && x < Players[scr].boardWidth) {
+ if (y >= 0 && y < Players[scr].boardVisible
+ && x >= 0 && x < Players[scr].boardWidth) {
if (boardSize[scr] > 1)
PlotBlock1(boardYPos[scr] - y, boardXPos[scr] + 2*x, type);
else
void CatchWinCh(int sig)
{ //handle window resize
- endwin(); //exit curses
- refresh(); //and reinit display (with different sizes)
+ endwin(); //exit curses
+ refresh(); //and reinit display (with different sizes)
InitFields(); //manually redraw everything
- refresh(); //refresh
+ refresh(); //refresh
}
static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event)
{ 0, 0, 0, 0 }
};
-enum { KT_left, KT_right, KT_rotright, KT_rotleft, KT_drop, KT_down,
- KT_faster, KT_pause, KT_redraw, KT_quit, KT_numKeys };
+enum {
+ KT_left, KT_right, KT_rotright, KT_rotleft, KT_drop, KT_down,
+ KT_faster, KT_pause, KT_redraw, KT_quit, KT_numKeys
+};
static char *keyNames[KT_numKeys+1] = {
"Left", "Right", "RotRight", "RotLeft", "Drop", "Down",
- "Faster", "Pause", "Redraw", "Quit", NULL };
+ "Faster", "Pause", "Redraw", "Quit", NULL
+};
-_Sets Sets = {7, 0, 1, 1, 1}; //Sets
+_Sets Sets = {7, 0, 1, 1, 1};
static char keyTable[KT_numKeys+1];
else Sets.standout = 0;
break;
case 'k': //keys
- MapKeys(value); break;
+ MapKeys(value);
+ break;
case 'H': //info
Header();
- DistInfo(); exit(0);
+ DistInfo();
+ exit(0);
case 'R': //rules
- Rules(); exit(0);
+ Rules();
+ exit(0);
case 'h': //help
- Usage(); exit(0);
+ Usage();
+ exit(0);
default:
- Usage(); exit(1);
+ Usage();
+ exit(1);
}
}
while (fgets(buf, 512, file_in) != NULL) {
if ((ch = strchr(buf, '#')))
*ch = '\0'; // truncate string from # char
- for (i = strlen(buf)-1; i >= 0; i--)
+ for (i = strlen(buf) - 1; i >= 0; i--)
if (buf[i] == ' ' || buf[i] == '\n' || buf[i] == '\t' || buf[i] == 13)
buf[i] = '\0';
else break;
if (!Sets.dropmode) gameStatus = 1; //instadrop
}
else gameStatus = 1; //dropped
- dropMode = Sets.dropmode>1;
+ dropMode = Sets.dropmode > 1;
break;
case KT_faster:
if (game != GT_onePlayer) break;
netint4 data[3];
short column;
- if (Players[me].alive<=0) break;
+ if (Players[me].alive <= 0) break;
memcpy(data, net.data, sizeof(data[0]));
column = Random(0, Players[me].boardWidth);
Message("\\%d%s sends %d lines",
- Players[net.uid].team>7 ? 7 : Players[net.uid].team,
+ Players[net.uid].team > 7 ? 7 : Players[net.uid].team,
Players[net.uid].name, data[0]);
lastadd = net.uid;
InsertJunk(me, Players[net.uid].team, data[0], column);
case NP_msg:
{
Message("<\\%d%s\\7> %s",
- Players[net.uid].team>7 ? 7 : Players[net.uid].team,
+ Players[net.uid].team > 7 ? 7 : Players[net.uid].team,
Players[net.uid].name, net.data, net.type);
break;
} //chat
Game.started = 2;
paused = 0;
Message("The game has started");
- for (i = 1; i<MAX_SCREENS; i++) if (Players[i].alive>0)
+ for (i = 1; i < MAX_SCREENS; i++) if (Players[i].alive > 0)
ShowPause(i);
break;
} //start game
case NP_stop:
{
- if (Game.started>1) {
+ if (Game.started > 1) {
int winner;
float timer;
int i;
Message("The game has ended");
- timer = CurTimeval()/1e6;
- if (timer>5) {
- for (i = MAX_SCREENS-1; i>0; i--) if (Players[i].alive>=0) {
+ timer = CurTimeval() / 1e6;
+ if (timer > 5) {
+ for (i = MAX_SCREENS-1; i > 0; i--) if (Players[i].alive >= 0) {
Message("\\%d%10s%6.1fp%5.1fa",
- Players[i].team>7 ? 7 : Players[i].team, Players[i].name,
- Players[i].score.pieces/timer*60,
- Players[i].score.adds/timer*60);
- if (Players[i].alive>0) winner = i;
+ Players[i].team > 7 ? 7 : Players[i].team, Players[i].name,
+ Players[i].score.pieces / timer * 60,
+ Players[i].score.adds / timer * 60);
+ if (Players[i].alive > 0) winner = i;
} //show player stats
if (winner)
Message("%s won after %0.0f'%02d\"",
- Players[winner].name, timer/60, (int)timer%60);
+ Players[winner].name, timer / 60, (int)timer % 60);
} //show game stats
Message(NULL);
} //game was playing
{
int i;
- for (i = 1; i<MAX_SCREENS; i++) if (Players[i].alive>=0) {
+ for (i = 1; i < MAX_SCREENS; i++) if (Players[i].alive >= 0) {
Players[i].alive = 1;
Players[i].flags |= SCF_paused;
} //reset players
memcpy(&Players[net.uid], net.data, net.size);
ClearField(net.uid);
InitFields();
- if (Players[net.uid].team>7)
+ if (Players[net.uid].team > 7)
Message("%s joined the game", Players[net.uid].name);
else
Message("%s joined %s team", Players[net.uid].name,
teams[Players[net.uid].team]);
- if (Players[net.uid].flags&SCF_paused) {
+ if (Players[net.uid].flags & SCF_paused) {
checkPaused();
} //player has paused
// DrawField(net.uid);
char s[20];
Players[net.uid].flags ^= SCF_paused;
- if (Game.started>1)
+ if (Game.started > 1)
strcpy(s, Players[net.uid].flags&SCF_paused
? "paused the game" : "unpaused the game");
else
memcpy(&i, net.data, sizeof(i));
Players[net.uid].alive = 0;
if (i == me) Message("\\%dYou fragged %s",
- Players[me].team>7 ? 7 : Players[me].team, Players[net.uid].name);
+ Players[me].team > 7 ? 7 : Players[me].team, Players[net.uid].name);
else if (i==net.uid)
Message("\\%d%s died",
- Players[i].team>7 ? 7 : Players[i].team, Players[i].name);
+ Players[i].team > 7 ? 7 : Players[i].team, Players[i].name);
else
Message("\\%d%s fragged %s",
- Players[i].team>7 ? 7 : Players[i].team, Players[i].name,
+ Players[i].team > 7 ? 7 : Players[i].team, Players[i].name,
Players[net.uid].name);
checkPaused();
ShowPause(net.uid);
#define HEADER_SIZE3 sizeof(netint4[3])
MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
-EventGenRec netGen =
- { NULL, 0, FT_read, -1, NetGenFunc, EM_net, 0, "\0", 0, HEADER_SIZE3 };
+EventGenRec netGen = {
+ NULL, 0, FT_read, -1, NetGenFunc, EM_net, 0, "\0", 0, HEADER_SIZE3
+};
static sigjmp_buf close_env;
MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
static EventGenRec netGen[MAX_SCREENS] = {
- { NULL, 0, FT_read, -1, NetGenFunc, EM_net, 0, "\0", 0, HEADER_SIZE } };
+ { NULL, 0, FT_read, -1, NetGenFunc, EM_net, 0, "\0", 0, HEADER_SIZE }
+};
static MyEventType AlarmGenFunc(EventGenRec *gen, MyEvent *event);
-static EventGenRec alarmGen =
- { &alarmGen, 0, FT_read, -1, AlarmGenFunc, EM_alarm };
+static EventGenRec alarmGen = {
+ &alarmGen, 0, FT_read, -1, AlarmGenFunc, EM_alarm
+};
static MyEventType ConnGenFunc(EventGenRec *gen, MyEvent *event);
-static EventGenRec connGen =
- { NULL, 0, FT_read, -1, ConnGenFunc, EM_connect };
+static EventGenRec connGen = {
+ NULL, 0, FT_read, -1, ConnGenFunc, EM_connect
+};
static EventGenRec *nextGen = &alarmGen;
int playersReady = 0;
int paused = 1;
int i;
- char teams[10][7] = { "", "Green", "Cyan", "Blue", "Purple",
- "Red", "Grey", "White", "*Orange" };
+ char teams[10][7] = {
+ "", "Green", "Cyan", "Blue", "Purple",
+ "Red", "Grey", "White", "*Orange"
+ };
do {
switch (WaitMyEvent(&event, EM_any)) {
#include "util.h"
static MyEventType AlarmGenFunc(EventGenRec *gen, MyEvent *event);
-static EventGenRec alarmGen =
- { &alarmGen, 0, FT_read, -1, AlarmGenFunc, EM_alarm };
+static EventGenRec alarmGen = {
+ &alarmGen, 0, FT_read, -1, AlarmGenFunc, EM_alarm
+};
static EventGenRec *nextGen = &alarmGen;
static int myRandSeed = 1;
fprintf(stderr,
"NETRIS %s\t(c) 1994-1996,1999 Mark H. Weaver <mhw@netris.org>\n"
" \t(c) 2002 Shiar <shiar@shiar.org>\n\n",
- version_string);
+ version_string
+ );
}
void Usage(void)
"\n"
" -r, --robot <cmd>\tExecute program to control the game instead of keyboard\n"
" -F, --fair-robot\tUse fair robot interface\n"
- "\n", DEFAULT_PORT, DEFAULT_KEYS);
+ "\n", DEFAULT_PORT, DEFAULT_KEYS
+ );
}
void DistInfo(void)
"You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the Free Software\n"
"Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
- "\n");
+ "\n"
+ );
}
void Rules(void)
"multiple rows.\n"
"\n"
"The longest surviving player wins the game.\n"
- "\n");
+ "\n"
+ );
}
///////////// RANDOM /////////////