X-Git-Url: http://git.shiar.net/netris.git/blobdiff_plain/a3b41d71c27b89c5f3e82226316e031e3f8eb253..e3d58186949bfcdb149cc2a545ce6c14a8689268:/netris.h diff --git a/netris.h b/netris.h index 45d61bf..b04e040 100644 --- a/netris.h +++ b/netris.h @@ -38,9 +38,9 @@ # define IN(a) #endif -#ifndef NULL -# define NULL ((void *)0) -#endif +/*#ifndef NULL + # define NULL ((void *)0) + #endif*/ #ifdef HAS_SIGPROCMASK typedef sigset_t MySigSet; @@ -59,29 +59,25 @@ typedef long netint4; #define hton2(x) htons(x) #define hton4(x) htonl(x) - #define ntoh2(x) ntohs(x) #define ntoh4(x) ntohl(x) -#define DEFAULT_PORT 9284 /* Very arbitrary */ - -#define DEFAULT_KEYS "jkl mspf^l" - /* Protocol versions */ #define MAJOR_VERSION 1 -#define PROTOCOL_VERSION 3 +#define PROTOCOL_VERSION 4 #define ROBOT_VERSION 1 -#define MAX_BOARD_WIDTH 32 -#define MAX_BOARD_HEIGHT 64 -#define MAX_SCREENS 2 +#define DEFAULT_PORT 9284 /* Very arbitrary */ -#define DEFAULT_INTERVAL 300000 /* Step-down interval in microseconds */ +#define CONFIG_FILE "netris.conf" -/* NP_startConn flags */ -#define SCF_usingRobot 000001 -#define SCF_fairRobot 000002 -#define SCF_setSeed 000004 +//#define DEFAULT_KEYS "hlkj mspf^l" +//#define DEFAULT_KEYS "4685 2spf^l" +#define DEFAULT_KEYS "dcaf b^sp^f^l" + +#define MAX_BOARD_WIDTH 32 +#define MAX_BOARD_HEIGHT 64 +#define MAX_SCREENS 5 /* Event masks */ #define EM_alarm 000001 @@ -91,20 +87,22 @@ typedef long netint4; #define EM_any 000777 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType; -typedef enum _BlockTypeA { BT_none, BT_white, BT_blue, BT_magenta, - BT_cyan, BT_yellow, BT_green, BT_red, - BT_wall, BT_len } BlockTypeA; +typedef enum _BlockTypeA { + BT_none, BT_white, BT_blue, BT_magenta, BT_cyan, BT_yellow, BT_green, + BT_red, BT_wall, BT_len +} BlockTypeA; typedef enum _Dir { D_down, D_right, D_up, D_left } Dir; typedef enum _Cmd { C_end, C_forw, C_back, C_left, C_right, C_plot } Cmd; typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType; -typedef enum _MyEventType { E_none, E_alarm, E_key, E_net, - E_lostConn, E_robot, E_lostRobot } MyEventType; -typedef enum _NetPacketType { NP_endConn, NP_giveJunk, NP_newPiece, - NP_down, NP_left, NP_right, - NP_rotate, NP_drop, NP_clear, - NP_insertJunk, NP_startConn, - NP_userName, NP_pause, NP_version, - NP_byeBye } NetPacketType; +typedef enum _MyEventType { + E_none, E_alarm, E_key, E_net, E_lostConn, E_robot, E_lostRobot +} MyEventType; +typedef enum _NetPacketType { + NP_endConn, NP_byeBye, + NP_error, NP_hello, NP_gamedata, NP_newPlayer, NP_goAhead, + NP_pause, NP_giveJunk, NP_newPiece, NP_down, NP_left, NP_right, + NP_rotright, NP_rotleft, NP_drop, NP_clear, NP_insertJunk +} NetPacketType; typedef signed char BlockType; @@ -113,6 +111,7 @@ typedef struct _MyEvent { union { char key; struct { + short sender, uid; NetPacketType type; int size; void *data; @@ -134,10 +133,16 @@ typedef struct _EventGenRec { int fd; EventGenFunc func; int mask; + short player; + char buf[512]; + int bufSize, bufGoal; } EventGenRec; +extern EventGenRec netGen[MAX_SCREENS]; + +MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event); typedef struct _Shape { - struct _Shape *rotateTo; + struct _Shape *rotateTo, *rotateFrom; int initY, initX, mirrored; Dir initDir; BlockType type; @@ -152,20 +157,48 @@ typedef struct _ShapeOption { typedef int (*ShapeDrawFunc)(int scr, int y, int x, BlockType type, void *data); +/* NP_startConn flags */ +#define SCF_usingRobot 000001 +#define SCF_fairRobot 000002 +#define SCF_setSeed 000004 + +EXT int totalPlayers; + +typedef struct _Player { + char name[16]; + int flags; + int dropmode; + int boardHeight, boardWidth, boardVisible; + int curX, curY; + Shape *curShape, *nextShape; + struct _Score { + short level; + long score; + int drops, lines, adds; + } score; + char host[256]; + int spy; +} Player; +EXT Player Players[MAX_SCREENS]; +EXT short me; + +#define DEFAULT_INTERVAL 1000000 /* Step-down interval in microseconds */ +#define SPEEDINC 1.2 +#define SPEEDMINIMUM 40000 + +typedef struct __Game { + long seed; + long initspeed, speed; + int standout, color, ascii; +} _Game; +EXT _Game Game; + EXT GameType game; -EXT int boardHeight[MAX_SCREENS]; -EXT int boardVisible[MAX_SCREENS], boardWidth[MAX_SCREENS]; -EXT Shape *curShape[MAX_SCREENS]; -EXT int curY[MAX_SCREENS], curX[MAX_SCREENS]; -EXT char opponentName[16], opponentHost[256]; -EXT int standoutEnable, colorEnable; EXT int robotEnable, robotVersion, fairRobot; EXT int protocolVersion; -EXT long initSeed; -EXT long stepDownInterval, speed; - -EXT int myFlags, opponentFlags; +EXT int initConn, waitConn; +EXT char *hostStr, *portStr; EXT char scratch[1024];