1 Index: netris-0.52/curses.c
2 ===================================================================
3 --- netris-0.52.orig/curses.c
4 +++ netris-0.52/curses.c
5 @@ -201,6 +201,8 @@ ExtFunc void InitScreen(int scr)
6 for (y = boardVisible[scr] - 1; y >= 0; --y) {
7 move(boardYPos[scr] - y, boardXPos[scr] - 1);
9 + for (x = boardWidth[scr] - 1; x >= 0; --x)
11 move(boardYPos[scr] - y, boardXPos[scr] + 2 * boardWidth[scr]);
14 @@ -256,6 +258,23 @@ ExtFunc void PlotUnderline(int scr, int
16 ExtFunc void ShowDisplayInfo(void)
18 + move(statusYPos - 3, statusXPos);
19 + printw("Won: %3d", won);
20 + move(statusYPos - 2, statusXPos);
21 + printw("Lost: %3d", lost);
23 + move(statusYPos - 1, statusXPos);
25 + case STATE_WAIT_CONNECTION:
26 + addstr("Waiting for opponent... ");
28 + case STATE_WAIT_KEYPRESS:
29 + addstr("Press the key for a new game.");
35 move(statusYPos - 9, statusXPos);
36 printw("Seed: %d", initSeed);
38 Index: netris-0.52/netris.h
39 ===================================================================
40 --- netris-0.52.orig/netris.h
41 +++ netris-0.52/netris.h
42 @@ -65,7 +65,7 @@ typedef long netint4;
44 #define DEFAULT_PORT 9284 /* Very arbitrary */
46 -#define DEFAULT_KEYS "jkl mspf^l"
47 +#define DEFAULT_KEYS "jkl mspf^ln"
49 /* Protocol versions */
50 #define MAJOR_VERSION 1
51 @@ -152,6 +152,13 @@ typedef struct _ShapeOption {
52 typedef int (*ShapeDrawFunc)(int scr, int y, int x,
53 BlockType type, void *data);
58 + STATE_WAIT_CONNECTION,
63 EXT int boardHeight[MAX_SCREENS];
64 EXT int boardVisible[MAX_SCREENS], boardWidth[MAX_SCREENS];
65 @@ -167,6 +174,9 @@ EXT long stepDownInterval, speed;
67 EXT int myFlags, opponentFlags;
70 +EXT enum States gameState;
72 EXT char scratch[1024];
74 extern ShapeOption stdOptions[];
75 Index: netris-0.52/util.c
76 ===================================================================
77 --- netris-0.52.orig/util.c
78 +++ netris-0.52/util.c
79 @@ -74,7 +74,7 @@ ExtFunc void Usage(void)
80 " -p <port> Set port number (default is %d)\n"
81 " -k <keys> Remap keys. The argument is a prefix of the string\n"
82 " containing the keys in order: left, rotate, right, drop,\n"
83 - " down-faster, toggle-spying, pause, faster, redraw.\n"
84 + " down-faster, toggle-spying, pause, faster, redraw, new.\n"
85 " \"^\" prefixes controls. (default is \"%s\")\n"
86 " -i <sec> Set the step-down interval, in seconds\n"
87 " -r <robot> Execute <robot> (a command) as a robot controlling\n"
88 Index: netris-0.52/game.c
89 ===================================================================
90 --- netris-0.52.orig/game.c
91 +++ netris-0.52/game.c
93 #include <netinet/in.h>
95 enum { KT_left, KT_rotate, KT_right, KT_drop, KT_down,
96 - KT_toggleSpy, KT_pause, KT_faster, KT_redraw, KT_numKeys };
97 + KT_toggleSpy, KT_pause, KT_faster, KT_redraw, KT_new, KT_numKeys };
99 static char *keyNames[KT_numKeys+1] = {
100 "Left", "Rotate", "Right", "Drop", "Down", "ToggleSpy", "Pause",
101 - "Faster", "Redraw", NULL };
102 + "Faster", "Redraw", "New", NULL };
104 static char *gameNames[GT_len] = { "OnePlayer", "ClassicTwo" };
106 @@ -40,6 +40,10 @@ static char keyTable[KT_numKeys+1];
107 static int dropModeEnable = 0;
108 static char *robotProg;
110 +static int wonLast = 0;
111 +int lost = 0, won = 0;
112 +enum States gameState = STATE_STARTING;
114 ExtFunc void MapKeys(char *newKeys)
117 @@ -323,6 +327,7 @@ ExtFunc void OneGame(int scr, int scr2)
125 @@ -350,14 +355,17 @@ ExtFunc void OneGame(int scr, int scr2)
126 SendPacket(NP_giveJunk, sizeof(data), data);
135 ExtFunc int main(int argc, char **argv)
137 - int initConn = 0, waitConn = 0, ch;
138 + int initConn = 0, waitConn = 0, ch, done = 0;
139 char *hostStr = NULL, *portStr = NULL;
142 standoutEnable = colorEnable = 1;
143 stepDownInterval = DEFAULT_INTERVAL;
144 @@ -422,112 +430,139 @@ ExtFunc int main(int argc, char **argv)
145 if (fairRobot && !robotEnable)
146 fatal("You can't use the -F option without the -r option");
149 - InitRobot(robotProg);
152 - if (initConn || waitConn) {
155 - game = GT_classicTwo;
157 - InitiateConnection(hostStr, portStr);
159 - WaitForConnection(portStr);
164 - data[0] = hton4(MAJOR_VERSION);
165 - data[1] = hton4(PROTOCOL_VERSION);
166 - SendPacket(NP_version, sizeof(data), data);
167 - if (WaitMyEvent(&event, EM_net) != E_net)
168 - fatal("Network negotiation failed");
169 - memcpy(data, event.u.net.data, sizeof(data));
170 - major = ntoh4(data[0]);
171 - protocolVersion = ntoh4(data[1]);
172 - if (event.u.net.type != NP_version || major < MAJOR_VERSION)
173 - fatal("Your opponent is using an old, incompatible version\n"
174 - "of Netris. They should get the latest version.");
175 - if (major > MAJOR_VERSION)
176 - fatal("Your opponent is using an newer, incompatible version\n"
177 - "of Netris. Get the latest version.");
178 - if (protocolVersion > PROTOCOL_VERSION)
179 - protocolVersion = PROTOCOL_VERSION;
181 - if (protocolVersion < 3 && stepDownInterval != DEFAULT_INTERVAL)
182 - fatal("Your opponent's version of Netris predates the -i option.\n"
183 - "For fairness, you shouldn't use the -i option either.");
190 + InitRobot(robotProg);
194 + if (initConn || waitConn) {
195 + game = GT_classicTwo;
196 + if(gameState != STATE_STARTING) {
197 + gameState = STATE_WAIT_CONNECTION;
202 + InitiateConnection(hostStr, portStr);
204 + WaitForConnection(portStr);
205 + gameState = STATE_PLAYING;
212 + data[0] = hton4(MAJOR_VERSION);
213 + data[1] = hton4(PROTOCOL_VERSION);
214 + SendPacket(NP_version, sizeof(data), data);
215 + if (WaitMyEvent(&event, EM_net) != E_net)
216 + fatal("Network negotiation failed");
217 + memcpy(data, event.u.net.data, sizeof(data));
218 + major = ntoh4(data[0]);
219 + protocolVersion = ntoh4(data[1]);
220 + if (event.u.net.type != NP_version || major < MAJOR_VERSION)
221 + fatal("Your opponent is using an old, incompatible version\n"
222 + "of Netris. They should get the latest version.");
223 + if (major > MAJOR_VERSION)
224 + fatal("Your opponent is using an newer, incompatible version\n"
225 + "of Netris. Get the latest version.");
226 + if (protocolVersion > PROTOCOL_VERSION)
227 + protocolVersion = PROTOCOL_VERSION;
229 + if (protocolVersion < 3 && stepDownInterval != DEFAULT_INTERVAL)
230 + fatal("Your opponent's version of Netris predates the -i option.\n"
231 + "For fairness, you shouldn't use the -i option either.");
237 - if (protocolVersion >= 3)
238 - len = sizeof(data);
240 - len = sizeof(netint4[2]);
241 - if ((myFlags & SCF_setSeed))
247 - data[0] = hton4(myFlags);
248 - data[1] = hton4(seed);
249 - data[2] = hton4(stepDownInterval);
250 - SendPacket(NP_startConn, len, data);
251 - if (WaitMyEvent(&event, EM_net) != E_net ||
252 - event.u.net.type != NP_startConn)
253 - fatal("Network negotiation failed");
254 - memcpy(data, event.u.net.data, len);
255 - opponentFlags = ntoh4(data[0]);
256 - seed = ntoh4(data[1]);
258 - if ((opponentFlags & SCF_setSeed) != (myFlags & SCF_setSeed))
259 - fatal("If one player sets the random number seed, "
261 - if ((myFlags & SCF_setSeed) && seed != initSeed)
262 - fatal("Both players have set the random number seed, "
263 - "and they are unequal.");
264 - if (protocolVersion >= 3 && stepDownInterval != ntoh4(data[2]))
265 - fatal("Your opponent is using a different step-down "
266 - "interval (-i).\nYou must both use the same one.");
268 + if (protocolVersion >= 3)
269 + len = sizeof(data);
271 + len = sizeof(netint4[2]);
272 + if ((myFlags & SCF_setSeed))
278 + data[0] = hton4(myFlags);
279 + data[1] = hton4(seed);
280 + data[2] = hton4(stepDownInterval);
281 + SendPacket(NP_startConn, len, data);
282 + if (WaitMyEvent(&event, EM_net) != E_net ||
283 + event.u.net.type != NP_startConn)
284 + fatal("Network negotiation failed");
285 + memcpy(data, event.u.net.data, len);
286 + opponentFlags = ntoh4(data[0]);
287 + seed = ntoh4(data[1]);
289 + if ((opponentFlags & SCF_setSeed) != (myFlags & SCF_setSeed))
290 + fatal("If one player sets the random number seed, "
292 + if ((myFlags & SCF_setSeed) && seed != initSeed)
293 + fatal("Both players have set the random number seed, "
294 + "and they are unequal.");
295 + if (protocolVersion >= 3 && stepDownInterval != ntoh4(data[2]))
296 + fatal("Your opponent is using a different step-down "
297 + "interval (-i).\nYou must both use the same one.");
305 + userName = getenv("LOGNAME");
306 + if (!userName || !userName[0])
307 + userName = getenv("USER");
308 + if (!userName || !userName[0])
309 + strcpy(userName, "???");
310 + len = strlen(userName)+1;
311 + if (len > sizeof(opponentName))
312 + len = sizeof(opponentName);
313 + SendPacket(NP_userName, len, userName);
314 + if (WaitMyEvent(&event, EM_net) != E_net ||
315 + event.u.net.type != NP_userName)
316 + fatal("Network negotiation failed");
317 + strncpy(opponentName, event.u.net.data,
318 + sizeof(opponentName)-1);
319 + opponentName[sizeof(opponentName)-1] = 0;
320 + for (i = 0; opponentName[i]; ++i)
321 + if (!isprint(opponentName[i]))
322 + opponentName[i] = '?';
323 + for (i = 0; opponentHost[i]; ++i)
324 + if (!isprint(opponentHost[i]))
325 + opponentHost[i] = '?';
333 - userName = getenv("LOGNAME");
334 - if (!userName || !userName[0])
335 - userName = getenv("USER");
336 - if (!userName || !userName[0])
337 - strcpy(userName, "???");
338 - len = strlen(userName)+1;
339 - if (len > sizeof(opponentName))
340 - len = sizeof(opponentName);
341 - SendPacket(NP_userName, len, userName);
342 - if (WaitMyEvent(&event, EM_net) != E_net ||
343 - event.u.net.type != NP_userName)
344 - fatal("Network negotiation failed");
345 - strncpy(opponentName, event.u.net.data,
346 - sizeof(opponentName)-1);
347 - opponentName[sizeof(opponentName)-1] = 0;
348 - for (i = 0; opponentName[i]; ++i)
349 - if (!isprint(opponentName[i]))
350 - opponentName[i] = '?';
351 - for (i = 0; opponentHost[i]; ++i)
352 - if (!isprint(opponentHost[i]))
353 - opponentHost[i] = '?';
355 + game = GT_onePlayer;
362 + WaitMyEvent(&event, EM_net);
368 + gameState = STATE_WAIT_KEYPRESS;
371 + while(getchar() != keyTable[KT_new])
377 - game = GT_onePlayer;
384 Index: netris-0.52/board.c
385 ===================================================================
386 --- netris-0.52.orig/board.c
387 +++ netris-0.52/board.c
388 @@ -36,6 +36,18 @@ static int oldFalling[MAX_SCREENS][MAX_B
390 ExtFunc void InitBoard(int scr)
394 + for(s = 0 ; s < MAX_SCREENS ; s++)
395 + for(h = 0 ; h < MAX_BOARD_HEIGHT ; h++)
396 + for(w = 0 ; w < MAX_BOARD_WIDTH ; w++) {
397 + board[s][h][w] = 0;
398 + oldBoard[s][h][w] = 0;
401 + oldFalling[s][w] = 0;
404 boardHeight[scr] = MAX_BOARD_HEIGHT;
405 boardVisible[scr] = 20;
406 boardWidth[scr] = 10;