document shapes array
[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_S, BT_L, BT_I, BT_O, BT_Z, BT_J, BT_T,
85         BT_wall, BT_len
86 } BlockTypeA;
87 typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType;
88 typedef enum _MyEventType {
89         E_none, E_alarm, E_key, E_connect, E_net, E_lostConn
90 } MyEventType;
91 typedef enum _NetPacketType {
92         NP_endConn,     //client/server quits
93         NP_byeBye,      //unused atm
94         NP_error,       //handshake error
95         NP_hello,       //check versions
96         NP_gamedata,    //game options
97
98         NP_start,       //game ok to start
99         NP_pause,       //player (un)pauses
100         NP_stop,        //game ended
101         NP_newPlayer,   //add new player
102         NP_team,        //player switched teams
103         NP_argghhh,     //player died
104         NP_part,        //player left
105
106         NP_msg,         //chat message
107
108         NP_newPiece,    //new piece info
109         NP_rotright,    //rotate piece clockwise
110         NP_rotleft,     //rotate piece counterclockwise
111         NP_left,        //move piece left
112         NP_right,       //move piece right
113         NP_down,        //move piece one down
114         NP_drop,        //drop piece to bottom
115         NP_clear,       //line cleared
116         NP_insertJunk,  //player added junk
117
118         NP_giveJunk     //player has to add junk
119 } NetPacketType;
120
121 typedef struct {
122         short sender, uid;
123         NetPacketType type;
124         int size;
125         void *data;
126 } _netEvent;
127 typedef struct _MyEvent {
128         MyEventType type;
129         union {
130                 char key;
131                 _netEvent net;
132                 struct {
133                         int size;
134                         char *data;
135                 } robot;
136         } u;
137 } MyEvent;
138
139 struct _EventGenRec;
140 typedef MyEventType (*EventGenFunc)(struct _EventGenRec *gen, MyEvent *event);
141
142 typedef struct _EventGenRec {
143         struct _EventGenRec *next;
144         int ready;
145         FDType fdType;
146         int fd;
147         EventGenFunc func;
148         int mask;
149         short player;
150         char buf[512];
151         int bufSize, bufGoal;
152 } EventGenRec;
153
154 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
155
156 /* NP_startConn flags */
157 #define SCF_paused  1
158
159 typedef struct {
160         int alive;
161         char name[16];
162         int flags;
163         int team;
164         int dropmode;
165         int boardHeight, boardWidth, boardVisible;
166         int curX, curY;
167         char curShape, nextShape;
168         struct _Score {
169                 short level;
170                 long score;
171                 int pieces, lines, adds;
172         } score;
173         char host[256];  //last
174 } _Player;
175 EXT _Player Players[MAX_SCREENS];
176 EXT short me;
177 EXT short maxPlayer;
178 EXT int spied; //in player.flags
179
180 #define DEFAULT_INTERVAL  1000000  /* Step-down interval in microseconds */
181 #define SPEEDINC          1.2
182 #define SPEEDMINIMUM      40000
183
184 typedef struct {
185         int gravity;     //1
186         int started;     //2
187         int continuous;  //3
188         long seed;       //4
189         int initspeed;   //5
190         int speed;
191 } _Game;
192 EXT _Game Game;
193
194 #define MSG_WIDTH 128
195
196 EXT GameType game; // => Game.type
197
198 EXT short port; // => just in game.c, parameter to inet connect
199
200 #endif //__NETRIS_H
201