modernize configure
[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
20 #ifndef __NETRIS_H
21 #define __NETRIS_H
22
23 #include "config.h"
24
25 #include <sys/time.h>
26 #include <assert.h>
27 #include <stdio.h>
28 #include <signal.h>
29
30 #define version_string "0.8"
31
32 #ifdef NOEXT  //prevent re-declaration
33 # define EXT
34 #else
35 # define EXT extern
36 #endif
37
38 #ifdef HAS_SIGPROCMASK
39 typedef sigset_t MySigSet;
40 #else
41 typedef int MySigSet;
42 #endif
43
44 /*
45  * The following definitions are to ensure network compatibility even if
46  * the sizes of ints and shorts are different.  I'm not sure exactly how
47  * to deal with this problem, so I've added an abstraction layer.
48  */
49
50 typedef short netint2;
51 typedef long netint4;
52
53 #define hton2(x) htons(x)
54 #define hton4(x) htonl(x)
55 #define ntoh2(x) ntohs(x)
56 #define ntoh4(x) ntohl(x)
57
58 /* Protocol versions */
59 #define MAJOR_VERSION     1
60 #define PROTOCOL_VERSION  4
61
62 #define DEFAULT_PORT 9284  /* Very arbitrary */
63
64 #define CONFIG_FILE "netris.conf"
65
66 //#define DEFAULT_KEYS "hlkj mfp^lq"
67 //#define DEFAULT_KEYS "4685 2fp^lq"
68 #define DEFAULT_KEYS "dcaf b^fp^lq"
69
70 #define MAX_BOARD_WIDTH    32
71 #define MAX_BOARD_HEIGHT   64
72 #define MAX_SCREENS         9 //8 players
73
74 /* Event masks */
75 #define EM_alarm       000001
76 #define EM_key         000002
77 #define EM_net         000004
78 #define EM_connect     000020
79 #define EM_any         000777
80
81 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType;
82 typedef enum _BlockTypeA {
83         BT_shadow, BT_none,
84         BT_green, BT_cyan, BT_blue, BT_magenta, BT_red, BT_yellow, BT_white,
85         BT_wall, BT_len
86 } BlockTypeA;
87 typedef enum _Dir { D_down, D_right, D_up, D_left } Dir;
88 typedef enum _Cmd { C_end, C_forw, C_back, C_left, C_right, C_plot } Cmd;
89 typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType;
90 typedef enum _MyEventType {
91         E_none, E_alarm, E_key, E_connect, E_net, E_lostConn
92 } MyEventType;
93 typedef enum _NetPacketType {
94         NP_endConn,     //client/server quits
95         NP_byeBye,      //unused atm
96         NP_error,       //handshake error
97         NP_hello,       //check versions
98         NP_gamedata,    //game options
99
100         NP_start,       //game ok to start
101         NP_pause,       //player (un)pauses
102         NP_stop,        //game ended
103         NP_newPlayer,   //add new player
104         NP_team,        //player switched teams
105         NP_argghhh,     //player died
106         NP_part,        //player left
107
108         NP_msg,         //chat message
109
110         NP_newPiece,    //new piece info
111         NP_rotright,    //rotate piece clockwise
112         NP_rotleft,     //rotate piece counterclockwise
113         NP_left,        //move piece left
114         NP_right,       //move piece right
115         NP_down,        //move piece one down
116         NP_drop,        //drop piece to bottom
117         NP_clear,       //line cleared
118         NP_insertJunk,  //player added junk
119
120         NP_giveJunk     //player has to add junk
121 } NetPacketType;
122
123 typedef struct {
124         short sender, uid;
125         NetPacketType type;
126         int size;
127         void *data;
128 } _netEvent;
129 typedef struct _MyEvent {
130         MyEventType type;
131         union {
132                 char key;
133                 _netEvent net;
134                 struct {
135                         int size;
136                         char *data;
137                 } robot;
138         } u;
139 } MyEvent;
140
141 struct _EventGenRec;
142 typedef MyEventType (*EventGenFunc)(struct _EventGenRec *gen, MyEvent *event);
143
144 typedef struct _EventGenRec {
145         struct _EventGenRec *next;
146         int ready;
147         FDType fdType;
148         int fd;
149         EventGenFunc func;
150         int mask;
151         short player;
152         char buf[512];
153         int bufSize, bufGoal;
154 } EventGenRec;
155
156 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
157
158 typedef struct _Shape {
159         char shape, rotate;
160 } Shape;
161
162 /* NP_startConn flags */
163 #define SCF_paused  1
164
165 typedef struct {
166         int alive;
167         char name[16];
168         int flags;
169         int team;
170         int dropmode;
171         int boardHeight, boardWidth, boardVisible;
172         int curX, curY;
173         char curShape, nextShape;
174         struct _Score {
175                 short level;
176                 long score;
177                 int pieces, lines, adds;
178         } score;
179         char host[256];  //last
180 } _Player;
181 EXT _Player Players[MAX_SCREENS];
182 EXT short me;
183 EXT short maxPlayer;
184 EXT int spied; //in player.flags
185
186 #define DEFAULT_INTERVAL  1000000  /* Step-down interval in microseconds */
187 #define SPEEDINC          1.2
188 #define SPEEDMINIMUM      40000
189
190 typedef struct {
191         int gravity;     //1
192         int started;     //2
193         int continuous;  //3
194         long seed;       //4
195         int initspeed;   //5
196         int speed;
197 } _Game;
198 EXT _Game Game;
199
200 #define MSG_WIDTH 128
201
202 EXT GameType game; // => Game.type
203
204 EXT short port; // => just in game.c, parameter to inet connect
205
206 #endif //__NETRIS_H
207