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.819"
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_argghhh, //player died
111 NP_newPiece, //new piece info
112 NP_rotright, //rotate piece clockwise
113 NP_rotleft, //rotate piece counterclockwise
114 NP_left, //move piece left
115 NP_right, //move piece right
116 NP_down, //move piece one down
117 NP_drop, //drop piece to bottom
118 NP_clear, //line cleared
119 NP_insertJunk, //player added junk
121 NP_giveJunk //player has to add junk
124 typedef signed char BlockType;
126 typedef struct _MyEvent {
144 typedef MyEventType (*EventGenFunc)(struct _EventGenRec *gen, MyEvent *event);
146 typedef struct _EventGenRec {
147 struct _EventGenRec *next;
155 int bufSize, bufGoal;
158 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
160 typedef struct _Shape {
161 struct _Shape *rotateTo, *rotateFrom;
162 int initY, initX, mirrored;
168 typedef struct _ShapeOption {
173 typedef int (*ShapeDrawFunc)(int scr, int y, int x,
174 BlockType type, void *data);
176 /* NP_startConn flags */
177 #define SCF_usingRobot 000001
178 #define SCF_fairRobot 000002
179 #define SCF_paused 000004
181 typedef struct _Player {
187 int boardHeight, boardWidth, boardVisible;
189 Shape *curShape, *nextShape;
193 int drops, lines, adds;
195 char host[256]; //last-1
196 int spy,small; //last
198 EXT Player Players[MAX_SCREENS];
201 EXT int spied; //in player.flags
203 #define DEFAULT_INTERVAL 1000000 /* Step-down interval in microseconds */
205 #define SPEEDMINIMUM 40000
207 typedef struct __Game {
214 int standout, color, ascii;
219 EXT int robotEnable, robotVersion, fairRobot;
220 EXT int protocolVersion;
225 EXT char scratch[1024];
227 extern ShapeOption stdOptions[];
231 #endif /* NETRIS_H */