unofficial version 0.7.1: ui improvements
[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 version_string          "0.7.819"
32
33 #define ExtFunc         /* Marks functions that need prototypes */
34
35 #ifdef NOEXT    //prevent re-declaration
36 # define EXT
37 #else
38 # define EXT extern
39 #endif
40
41 #ifdef HAS_SIGPROCMASK
42 typedef sigset_t MySigSet;
43 #else
44 typedef int MySigSet;
45 #endif
46
47 /*
48  * The following definitions are to ensure network compatibility even if
49  * the sizes of ints and shorts are different.  I'm not sure exactly how
50  * to deal with this problem, so I've added an abstraction layer.
51  */
52
53 typedef short netint2;
54 typedef long netint4;
55
56 #define hton2(x) htons(x)
57 #define hton4(x) htonl(x)
58 #define ntoh2(x) ntohs(x)
59 #define ntoh4(x) ntohl(x)
60
61 /* Protocol versions */
62 #define MAJOR_VERSION           1       
63 #define PROTOCOL_VERSION        4
64 #define ROBOT_VERSION           1
65
66 #define DEFAULT_PORT 9284       /* Very arbitrary */
67
68 #define CONFIG_FILE "netris.conf"
69
70 //#define DEFAULT_KEYS "hlkj mfp^lq"
71 //#define DEFAULT_KEYS "4685 2fp^lq"
72 #define DEFAULT_KEYS "dcaf b^fp^lq"
73
74 #define MAX_BOARD_WIDTH         32
75 #define MAX_BOARD_HEIGHT        64
76 #define MAX_SCREENS                     9 //8 players
77
78 /* Event masks */
79 #define EM_alarm                        000001
80 #define EM_key                          000002
81 #define EM_net                          000004
82 #define EM_robot                        000010
83 #define EM_connect                      000020
84 #define EM_any                          000777
85
86 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType;
87 typedef enum _BlockTypeA {
88         BT_shadow, BT_none,
89         BT_green, BT_cyan, BT_blue, BT_magenta, BT_red, BT_yellow, BT_white,
90         BT_wall, BT_len
91 } BlockTypeA;
92 typedef enum _Dir { D_down, D_right, D_up, D_left } Dir;
93 typedef enum _Cmd { C_end, C_forw, C_back, C_left, C_right, C_plot } Cmd;
94 typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType;
95 typedef enum _MyEventType {
96         E_none, E_alarm, E_key, E_connect, E_net, E_lostConn, E_robot, E_lostRobot
97 } MyEventType;
98 typedef enum _NetPacketType {
99         NP_endConn,             //client/server quits
100         NP_byeBye,              //unused atm
101         NP_error,               //handshake error
102         NP_hello,               //check versions
103         NP_gamedata,    //game options
104
105         NP_start,               //game ok to start
106         NP_pause,               //player (un)pauses
107         NP_stop,                //game ended
108         NP_newPlayer,   //add new player
109         NP_argghhh,             //player died
110
111         NP_newPiece,    //new piece info
112         NP_rotright,    //rotate piece clockwise
113         NP_rotleft,             //rotate piece counterclockwise
114         NP_left,                //move piece left
115         NP_right,               //move piece right
116         NP_down,                //move piece one down
117         NP_drop,                //drop piece to bottom
118         NP_clear,               //line cleared
119         NP_insertJunk,  //player added junk
120
121         NP_giveJunk             //player has to add junk
122 } NetPacketType;
123
124 typedef signed char BlockType;
125
126 typedef struct _MyEvent {
127         MyEventType type;
128         union {
129                 char key;
130                 struct {
131                         short sender, uid;
132                         NetPacketType type;
133                         int size;
134                         void *data;
135                 } 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         struct _Shape *rotateTo, *rotateFrom;
162         int initY, initX, mirrored;
163         Dir initDir;
164         BlockType type;
165         Cmd *cmds;
166 } Shape;
167
168 typedef struct _ShapeOption {
169         float weight;
170         Shape *shape;
171 } ShapeOption;
172
173 typedef int (*ShapeDrawFunc)(int scr, int y, int x,
174                                         BlockType type, void *data);
175
176 /* NP_startConn flags */
177 #define SCF_usingRobot          000001
178 #define SCF_fairRobot           000002
179 #define SCF_paused                      000004
180
181 typedef struct _Player {
182         int alive;
183         char name[16];
184         int flags;
185         int team;
186         int dropmode;
187         int boardHeight, boardWidth, boardVisible;
188         int curX, curY;
189         Shape *curShape, *nextShape;
190         struct _Score {
191                 short level;
192                 long score;
193                 int drops, lines, adds;
194         } score;
195         char host[256]; //last-1
196         int spy,small;  //last
197 } Player;
198 EXT Player Players[MAX_SCREENS];
199 EXT short me;
200 EXT short maxPlayer;
201 EXT int spied; //in player.flags
202
203 #define DEFAULT_INTERVAL        1000000 /* Step-down interval in microseconds */
204 #define SPEEDINC                        1.2
205 #define SPEEDMINIMUM            40000
206
207 typedef struct __Game {
208         int maxplayers; //1
209         int started;    //2
210         int continuous; //3
211         long seed;              //4
212         int initspeed;  //5
213         int speed;
214         int standout, color, ascii;
215 } _Game;
216 EXT _Game Game;
217
218 EXT GameType game;
219 EXT int robotEnable, robotVersion, fairRobot;
220 EXT int protocolVersion;
221
222 EXT int initConn;
223 EXT short port;
224
225 EXT char scratch[1024];
226
227 extern ShapeOption stdOptions[];
228
229 #include "proto.h"
230
231 #endif /* NETRIS_H */
232
233 /*
234  * vi: ts=4 ai
235  * vim: noai si
236  */