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