unofficial version 0.6: first major updates
[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 #define ntoh2(x) ntohs(x)
63 #define ntoh4(x) ntohl(x)
64
65 /* Protocol versions */
66 #define MAJOR_VERSION           1       
67 #define PROTOCOL_VERSION        4
68 #define ROBOT_VERSION           1
69
70 #define DEFAULT_PORT 9284       /* Very arbitrary */
71
72 #define CONFIG_FILE "netris.conf"
73
74 //#define DEFAULT_KEYS "hlkj mspf^l"
75 //#define DEFAULT_KEYS "4685 2spf^l"
76 #define DEFAULT_KEYS "dcaf b^sp^f^l"
77
78 #define MAX_BOARD_WIDTH         32
79 #define MAX_BOARD_HEIGHT        64
80 #define MAX_SCREENS                     5
81
82 /* Event masks */
83 #define EM_alarm                        000001
84 #define EM_key                          000002
85 #define EM_net                          000004
86 #define EM_robot                        000010
87 #define EM_any                          000777
88
89 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType;
90 typedef enum _BlockTypeA {
91         BT_none, BT_white, BT_blue, BT_magenta, BT_cyan, BT_yellow, BT_green,
92         BT_red, BT_wall, BT_len
93 } BlockTypeA;
94 typedef enum _Dir { D_down, D_right, D_up, D_left } Dir;
95 typedef enum _Cmd { C_end, C_forw, C_back, C_left, C_right, C_plot } Cmd;
96 typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType;
97 typedef enum _MyEventType {
98         E_none, E_alarm, E_key, E_net, E_lostConn, E_robot, E_lostRobot
99 } MyEventType;
100 typedef enum _NetPacketType {
101         NP_endConn, NP_byeBye,
102         NP_error, NP_hello, NP_gamedata, NP_newPlayer, NP_goAhead,
103         NP_pause, NP_giveJunk, NP_newPiece, NP_down, NP_left, NP_right,
104         NP_rotright, NP_rotleft, NP_drop, NP_clear, NP_insertJunk
105 } NetPacketType;
106
107 typedef signed char BlockType;
108
109 typedef struct _MyEvent {
110         MyEventType type;
111         union {
112                 char key;
113                 struct {
114                         short sender, uid;
115                         NetPacketType type;
116                         int size;
117                         void *data;
118                 } net;
119                 struct {
120                         int size;
121                         char *data;
122                 } robot;
123         } u;
124 } MyEvent;
125
126 struct _EventGenRec;
127 typedef MyEventType (*EventGenFunc)(struct _EventGenRec *gen, MyEvent *event);
128
129 typedef struct _EventGenRec {
130         struct _EventGenRec *next;
131         int ready;
132         FDType fdType;
133         int fd;
134         EventGenFunc func;
135         int mask;
136         short player;
137         char buf[512];
138         int bufSize, bufGoal;
139 } EventGenRec;
140 extern EventGenRec netGen[MAX_SCREENS];
141
142 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
143
144 typedef struct _Shape {
145         struct _Shape *rotateTo, *rotateFrom;
146         int initY, initX, mirrored;
147         Dir initDir;
148         BlockType type;
149         Cmd *cmds;
150 } Shape;
151
152 typedef struct _ShapeOption {
153         float weight;
154         Shape *shape;
155 } ShapeOption;
156
157 typedef int (*ShapeDrawFunc)(int scr, int y, int x,
158                                         BlockType type, void *data);
159
160 /* NP_startConn flags */
161 #define SCF_usingRobot          000001
162 #define SCF_fairRobot           000002
163 #define SCF_setSeed                     000004
164
165 EXT int totalPlayers;
166
167 typedef struct _Player {
168         char name[16];
169         int flags;
170         int dropmode;
171         int boardHeight, boardWidth, boardVisible;
172         int curX, curY;
173         Shape *curShape, *nextShape;
174         struct _Score {
175                 short level;
176                 long score;
177                 int drops, lines, adds;
178         } score;
179         char host[256];
180         int spy;
181 } Player;
182 EXT Player Players[MAX_SCREENS];
183 EXT short me;
184
185 #define DEFAULT_INTERVAL        1000000 /* Step-down interval in microseconds */
186 #define SPEEDINC                        1.2
187 #define SPEEDMINIMUM            40000
188
189 typedef struct __Game {
190         long seed;
191         long initspeed, speed;
192         int standout, color, ascii;
193 } _Game;
194 EXT _Game Game;
195
196 EXT GameType game;
197 EXT int robotEnable, robotVersion, fairRobot;
198 EXT int protocolVersion;
199
200 EXT int initConn, waitConn;
201 EXT char *hostStr, *portStr;
202
203 EXT char scratch[1024];
204
205 extern ShapeOption stdOptions[];
206 extern char *version_string;
207
208 #include "proto.h"
209
210 #endif /* NETRIS_H */
211
212 /*
213  * vi: ts=4 ai
214  * vim: noai si
215  */