initial interface requests
[netris.git] / netris.h
1 /*
2  * Netris -- A free networked version of T*tris
3  * Copyright (C) 1994-1996,1999  Mark H. Weaver <mhw@netris.org>
4  * 
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.
9  * 
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.
14  * 
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.
18  *
19  * $Id: netris.h,v 1.28 1999/05/16 06:56:29 mhw Exp $
20  */
21
22 #ifndef NETRIS_H
23 #define NETRIS_H
24
25 #include "config.h"
26 #include <sys/time.h>
27 #include <assert.h>
28 #include <stdio.h>
29 #include <signal.h>
30
31 #define ExtFunc         /* Marks functions that need prototypes */
32
33 #ifdef NOEXT
34 # define EXT
35 # define IN(a) a
36 #else
37 # define EXT extern
38 # define IN(a)
39 #endif
40
41 #ifndef NULL
42 # define NULL ((void *)0)
43 #endif
44
45 #ifdef HAS_SIGPROCMASK
46 typedef sigset_t MySigSet;
47 #else
48 typedef int MySigSet;
49 #endif
50
51 /*
52  * The following definitions are to ensure network compatibility even if
53  * the sizes of ints and shorts are different.  I'm not sure exactly how
54  * to deal with this problem, so I've added an abstraction layer.
55  */
56
57 typedef short netint2;
58 typedef long netint4;
59
60 #define hton2(x) htons(x)
61 #define hton4(x) htonl(x)
62
63 #define ntoh2(x) ntohs(x)
64 #define ntoh4(x) ntohl(x)
65
66 #define DEFAULT_PORT 9284       /* Very arbitrary */
67
68 //#define DEFAULT_KEYS "hlkj mspf^l"
69 //#define DEFAULT_KEYS "4685 2spf^l"
70 #define DEFAULT_KEYS "dcaf b^sp^f^l"
71
72 /* Protocol versions */
73 #define MAJOR_VERSION           1       
74 #define PROTOCOL_VERSION        4
75 #define ROBOT_VERSION           1
76
77 #define MAX_BOARD_WIDTH         32
78 #define MAX_BOARD_HEIGHT        64
79 #define MAX_SCREENS                     2
80
81 #define DEFAULT_INTERVAL        300000  /* Step-down interval in microseconds */
82
83 /* NP_startConn flags */
84 #define SCF_usingRobot          000001
85 #define SCF_fairRobot           000002
86 #define SCF_setSeed                     000004
87
88 /* Event masks */
89 #define EM_alarm                        000001
90 #define EM_key                          000002
91 #define EM_net                          000004
92 #define EM_robot                        000010
93 #define EM_any                          000777
94
95 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType;
96 typedef enum _BlockTypeA { BT_none, BT_white, BT_blue, BT_magenta,
97                                                         BT_cyan, BT_yellow, BT_green, BT_red,
98                                                         BT_wall, BT_len } BlockTypeA;
99 typedef enum _Dir { D_down, D_right, D_up, D_left } Dir;
100 typedef enum _Cmd { C_end, C_forw, C_back, C_left, C_right, C_plot } Cmd;
101 typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType;
102 typedef enum _MyEventType { E_none, E_alarm, E_key, E_net,
103                                                         E_lostConn, E_robot, E_lostRobot } MyEventType;
104 typedef enum _NetPacketType { NP_endConn, NP_giveJunk, NP_newPiece,
105                                                         NP_down, NP_left, NP_right,
106                                                         NP_rotright, NP_rotleft, NP_drop, NP_clear,
107                                                         NP_insertJunk, NP_startConn,
108                                                         NP_userName, NP_pause, NP_version,
109                                                         NP_byeBye } NetPacketType;
110
111 typedef signed char BlockType;
112
113 typedef struct _MyEvent {
114         MyEventType type;
115         union {
116                 char key;
117                 struct {
118                         NetPacketType type;
119                         int size;
120                         void *data;
121                 } net;
122                 struct {
123                         int size;
124                         char *data;
125                 } robot;
126         } u;
127 } MyEvent;
128
129 struct _EventGenRec;
130 typedef MyEventType (*EventGenFunc)(struct _EventGenRec *gen, MyEvent *event);
131
132 typedef struct _EventGenRec {
133         struct _EventGenRec *next;
134         int ready;
135         FDType fdType;
136         int fd;
137         EventGenFunc func;
138         int mask;
139 } EventGenRec;
140
141 typedef struct _Shape {
142         struct _Shape *rotateTo, *rotateFrom;
143         int initY, initX, mirrored;
144         Dir initDir;
145         BlockType type;
146         Cmd *cmds;
147 } Shape;
148
149 typedef struct _ShapeOption {
150         float weight;
151         Shape *shape;
152 } ShapeOption;
153
154 typedef int (*ShapeDrawFunc)(int scr, int y, int x,
155                                         BlockType type, void *data);
156
157 EXT GameType game;
158 EXT int boardHeight[MAX_SCREENS];
159 EXT int boardVisible[MAX_SCREENS], boardWidth[MAX_SCREENS];
160 EXT Shape *curShape[MAX_SCREENS], *nextShape[MAX_SCREENS];
161 EXT int curY[MAX_SCREENS], curX[MAX_SCREENS];
162 EXT char opponentName[16], opponentHost[256];
163 EXT int standoutEnable, colorEnable;
164 EXT int robotEnable, robotVersion, fairRobot;
165 EXT int protocolVersion;
166
167 EXT long initSeed;
168 EXT long stepDownInterval, speed;
169
170 EXT int myFlags, opponentFlags;
171
172 EXT char scratch[1024];
173
174 extern ShapeOption stdOptions[];
175 extern char *version_string;
176
177 #include "proto.h"
178
179 #endif /* NETRIS_H */
180
181 /*
182  * vi: ts=4 ai
183  * vim: noai si
184  */