2 * Netris -- A free networked version of T*tris
3 * Copyright (C) 1994-1996,1999 Mark H. Weaver <mhw@netris.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * $Id: netris.h,v 1.28 1999/05/16 06:56:29 mhw Exp $
31 #define version_string "0.7.821"
33 #define ExtFunc /* Marks functions that need prototypes */
35 #ifdef NOEXT //prevent re-declaration
41 #ifdef HAS_SIGPROCMASK
42 typedef sigset_t MySigSet;
48 * The following definitions are to ensure network compatibility even if
49 * the sizes of ints and shorts are different. I'm not sure exactly how
50 * to deal with this problem, so I've added an abstraction layer.
53 typedef short netint2;
56 #define hton2(x) htons(x)
57 #define hton4(x) htonl(x)
58 #define ntoh2(x) ntohs(x)
59 #define ntoh4(x) ntohl(x)
61 /* Protocol versions */
62 #define MAJOR_VERSION 1
63 #define PROTOCOL_VERSION 4
64 #define ROBOT_VERSION 1
66 #define DEFAULT_PORT 9284 /* Very arbitrary */
68 #define CONFIG_FILE "netris.conf"
70 //#define DEFAULT_KEYS "hlkj mfp^lq"
71 //#define DEFAULT_KEYS "4685 2fp^lq"
72 #define DEFAULT_KEYS "dcaf b^fp^lq"
74 #define MAX_BOARD_WIDTH 32
75 #define MAX_BOARD_HEIGHT 64
76 #define MAX_SCREENS 9 //8 players
79 #define EM_alarm 000001
82 #define EM_robot 000010
83 #define EM_connect 000020
86 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType;
87 typedef enum _BlockTypeA {
89 BT_green, BT_cyan, BT_blue, BT_magenta, BT_red, BT_yellow, BT_white,
92 typedef enum _Dir { D_down, D_right, D_up, D_left } Dir;
93 typedef enum _Cmd { C_end, C_forw, C_back, C_left, C_right, C_plot } Cmd;
94 typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType;
95 typedef enum _MyEventType {
96 E_none, E_alarm, E_key, E_connect, E_net, E_lostConn, E_robot, E_lostRobot
98 typedef enum _NetPacketType {
99 NP_endConn, //client/server quits
100 NP_byeBye, //unused atm
101 NP_error, //handshake error
102 NP_hello, //check versions
103 NP_gamedata, //game options
105 NP_start, //game ok to start
106 NP_pause, //player (un)pauses
107 NP_stop, //game ended
108 NP_newPlayer, //add new player
109 NP_team, //player switched teams
110 NP_argghhh, //player died
111 NP_part, //player left
113 NP_newPiece, //new piece info
114 NP_rotright, //rotate piece clockwise
115 NP_rotleft, //rotate piece counterclockwise
116 NP_left, //move piece left
117 NP_right, //move piece right
118 NP_down, //move piece one down
119 NP_drop, //drop piece to bottom
120 NP_clear, //line cleared
121 NP_insertJunk, //player added junk
123 NP_giveJunk //player has to add junk
126 typedef signed char BlockType;
128 typedef struct _MyEvent {
146 typedef MyEventType (*EventGenFunc)(struct _EventGenRec *gen, MyEvent *event);
148 typedef struct _EventGenRec {
149 struct _EventGenRec *next;
157 int bufSize, bufGoal;
160 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
162 typedef struct _Shape {
163 struct _Shape *rotateTo, *rotateFrom;
164 int initY, initX, mirrored;
170 typedef struct _ShapeOption {
175 typedef int (*ShapeDrawFunc)(int scr, int y, int x,
176 BlockType type, void *data);
178 /* NP_startConn flags */
179 #define SCF_usingRobot 000001
180 #define SCF_fairRobot 000002
181 #define SCF_paused 000004
183 typedef struct _Player {
189 int boardHeight, boardWidth, boardVisible;
191 Shape *curShape, *nextShape;
195 int drops, lines, adds;
197 char host[256]; //last-1
198 int spy,small; //last
200 EXT Player Players[MAX_SCREENS];
203 EXT int spied; //in player.flags
205 #define DEFAULT_INTERVAL 1000000 /* Step-down interval in microseconds */
207 #define SPEEDMINIMUM 40000
209 typedef struct __Game {
216 int standout, color, ascii;
221 EXT int robotEnable, robotVersion, fairRobot;
222 EXT int protocolVersion;
227 EXT char scratch[1024];
229 extern ShapeOption stdOptions[];
233 #endif /* NETRIS_H */