X-Git-Url: http://git.shiar.net/netris.git/blobdiff_plain/96163e4af19e7eb66a97ae1d16c1e1e176477c55..392ee62ca6a0a64356e9a874100c981f70b8611a:/client.c diff --git a/client.c b/client.c index 1b48a8e..98b9542 100644 --- a/client.c +++ b/client.c @@ -21,6 +21,7 @@ #include "netris.h" #include +#include #include #include #include @@ -40,7 +41,6 @@ static struct option options[] = { { "level", 1, 0, 'l' }, { "nick", 1, 0, 'n' }, { "team", 1, 0, 't' }, - { "dropmode", 2, 0, 'd' }, { "color", 2, 0, 'C' }, { "slowterm", 2, 0, 'S' }, { "keys", 1, 0, 'k' }, @@ -51,12 +51,12 @@ static struct option options[] = { }; enum { - KT_left, KT_right, KT_rotright, KT_rotleft, KT_drop, KT_down, + KT_left, KT_right, KT_rotright, KT_rotleft, KT_drop, KT_dropsoft, KT_down, KT_faster, KT_pause, KT_redraw, KT_say, KT_quit, KT_numKeys }; static char *keyNames[KT_numKeys+1] = { - "Left", "Right", "RotRight", "RotLeft", "Drop", "Down", + "Left", "Right", "RotRight", "RotLeft", "Drop", "DropSoft", "Down", "Faster", "Pause", "Redraw", "Say", "Quit", NULL }; @@ -65,9 +65,11 @@ _Sets Sets = {7, 0, 1, 1, 1}; static char keyTable[KT_numKeys+1]; enum { + CT_quit, CT_pause, CT_MAX }; static char *cmds[] = { + "quit", "pause" }; static char *hostStr; @@ -131,8 +133,6 @@ void Usage(void) " -t, --team \tJoin a team (don't receive lines from your teammates)\n" " -l, --level \tBegin at a higher level (can be used as handicap)\n" " -k, --keys \tRemap keys (default is \"%s\" for cursors)\n" - " -d, --dropmode\tDrops go into drop mode\n" - " -D, --instadrop\tInstant drop\n" "\n" " -r, --robot \tExecute program to control the game instead of keyboard\n" " -F, --fair-robot\tUse fair robot interface\n" @@ -167,9 +167,6 @@ void HandleOption(char tag, char *value) case 't': //team Players[0].team = atoi(value); break; - case 'd': //dropmode - Sets.dropmode = value ? atoi(value) : 1; - break; case 'C': //color Sets.color = value && strcasecmp(value, "0") ? 1 : 0; break; @@ -328,15 +325,34 @@ void CheckClears(int scr) void OneGame(void) { - int changed = 0; + bool changed = 0; short gameStatus = 2; //2=loop; 1=new piece; 0=quit - int dropMode = 0; - int chatMode = 0; + bool chatMode = 0; char chatText[MSG_WIDTH] = "\0"; void handle_cmd(char cmd, char *arg) { switch (cmd) { + case CT_quit: + ShowPause(me); + refresh(); + gameStatus = 0; + return; + case CT_pause: + if (Players[me].alive <= 0) return; + Players[me].flags ^= SCF_paused; + if (Game.started > 1) + Message(Players[me].flags & SCF_paused + ? "You paused the game" : "You unpaused the game"); + else + Message(Players[me].flags & SCF_paused + ? "You are not ready" : "You are ready"); + checkPaused(); + if (game == GT_classicTwo) + SendPacket(me, NP_pause, 0, NULL); + ShowPause(me); + changed = 1; + return; } } @@ -362,8 +378,11 @@ void OneGame(void) void handle_str(char *str) { if (chatText[0] == '/') { + if (chatText[1] != '/') { handle_cmdstr(chatText + 1); return; + } + memmove(chatText, chatText + 1, strlen(chatText)); } Message("<\\%d%s\\7> %s", @@ -401,7 +420,8 @@ void OneGame(void) if (!(p = strchr(keyTable, tolower(key)))) return; key = p - keyTable; - // global actions (always possible, even if not playing) + void handle_keycmd(char key) + { switch (key) { case KT_redraw: clear(); @@ -414,32 +434,14 @@ void OneGame(void) Messagetype(key, strlen(chatText) - 1, chatText); return; case KT_quit: - ShowPause(me); - refresh(); - gameStatus = 0; + handle_cmd(CT_quit, NULL); return; - } - - if (Players[me].alive <= 0) return; - // actions available while in game - switch (key) { case KT_pause: - Players[me].flags ^= SCF_paused; - if (Game.started > 1) - Message(Players[me].flags & SCF_paused - ? "You paused the game" : "You unpaused the game"); - else - Message(Players[me].flags & SCF_paused - ? "You are not ready" : "You are ready"); - checkPaused(); - if (game == GT_classicTwo) - SendPacket(me, NP_pause, 0, NULL); - ShowPause(me); - changed = 1; + handle_cmd(CT_pause, NULL); return; } - if (paused) return; + if (Players[me].alive <= 0 || paused) return; // actions only available while actually playing switch (key) { case KT_left: @@ -462,14 +464,19 @@ void OneGame(void) else gameStatus = 1; //completely dropped break; - case KT_drop: + case KT_dropsoft: SetITimer(Game.speed, Game.speed); if (DropPiece(me)) { if (spied) SendPacket(me, NP_drop, 0, NULL); - if (!Sets.dropmode) gameStatus = 1; //instadrop } else gameStatus = 1; //dropped - dropMode = Sets.dropmode > 1; + break; + case KT_drop: + SetITimer(Game.speed, Game.speed); + if (DropPiece(me)) { + if (spied) SendPacket(me, NP_drop, 0, NULL); + } + gameStatus = 1; // drop break; case KT_faster: if (game != GT_onePlayer) break; @@ -481,12 +488,8 @@ void OneGame(void) changed = 1; break; } - - if (dropMode && DropPiece(me) > 0) { - SetITimer(Game.speed, Game.speed); - if (spied) SendPacket(me, NP_drop, 0, NULL); - } - return; + } + handle_keycmd(key); } //GameKey int oldPaused = 0; @@ -756,7 +759,6 @@ GameLoop: oldPaused = paused; } //(un)pause } //game loop - dropMode = 0; Players[me].score.score++; CheckClears(me); } //new piece loop @@ -793,7 +795,6 @@ int main(int argc, char **argv) strncpy(Players[0].name, userName, 16); //sizeof(Player.name) Players[0].name[16] = 0; Players[0].alive = 1; - Players[0].dropmode = 0; } //set defaults // if (getopt(argc, argv, "f:") == 'f') @@ -801,7 +802,7 @@ int main(int argc, char **argv) // else ReadConf(CONFIG_FILE); while ((ch = getopt_long( - argc, argv, "hHRk:c:n:odDSCap:i:l:t:", options, NULL + argc, argv, "hHRk:c:n:oSCap:i:l:t:", options, NULL )) != -1) HandleOption(ch, optarg); if (optind < argc) {