X-Git-Url: http://git.shiar.nl/netris.git/blobdiff_plain/1e54ff896419cfb2a3e5e576e75713c4fbeeed5b..7098b3a509b56f28e31d67fe4344e900521b1914:/game.c diff --git a/game.c b/game.c index fcc2379..32c85db 100644 --- a/game.c +++ b/game.c @@ -52,12 +52,12 @@ static struct option options[] = { enum { KT_left, KT_right, KT_rotright, KT_rotleft, KT_drop, KT_down, - KT_faster, KT_pause, KT_redraw, KT_quit, KT_numKeys + KT_faster, KT_pause, KT_redraw, KT_say, KT_quit, KT_numKeys }; static char *keyNames[KT_numKeys+1] = { "Left", "Right", "RotRight", "RotLeft", "Drop", "Down", - "Faster", "Pause", "Redraw", "Quit", NULL + "Faster", "Pause", "Redraw", "Say", "Quit", NULL }; _Sets Sets = {7, 0, 1, 1, 1}; @@ -138,10 +138,7 @@ void HandleOption(char tag, char *value) Game.initspeed = atof(value) * 1e6; break; case 'l': //level - if ((Players[0].score.level = atof(value)) < 1) - Players[0].score.level = 1; - if (Players[0].score.level > 15) - Players[0].score.level = 15; + Players[0].score.level = MIN(MAX(atof(value), 1), 15); break; case 'n': //nick memcpy(Players[0].name, value, strlen(value) + 1); @@ -295,8 +292,7 @@ void CheckClears(int scr) short junkLines; netint4 data[1]; - if (Game.gravity) junkLines = linesCleared - 1; - else junkLines = linesCleared - (linesCleared < 4); + junkLines = linesCleared - (Game.gravity ? 1 : linesCleared < 4); data[0] = junkLines; SendPacket(me, NP_giveJunk, sizeof(data), data); Message("\\%dYou send %d lines", @@ -323,32 +319,42 @@ void OneGame(void) { char *p; - if (key == 13) { - if (!(chatMode = !chatMode)) { + if (chatMode) { + if (key == 13) { + // enter text + chatMode = 0; if (chatText[0]) { Message("<\\%d%s\\7> %s", Players[me].team > 7 ? 7 : Players[me].team, Players[me].name, chatText); - if (game==GT_classicTwo) + if (game == GT_classicTwo) SendPacket(me, NP_msg, strlen(chatText) + 1, chatText); memset(chatText, 0, sizeof(chatText)); } //say it else Messagetype(27, -1, NULL); //escape return; - } //leave chat mode - } //enter pressed (start/stop chat mode) - if (chatMode) { - if (key == 27) //escape + } + else if (key == 27) //escape chatMode = 0; else if (key == 127 && chatText) //backspace chatText[strlen(chatText) - 1] = 0; - else if (key != 13 && strlen(chatText) < MSG_WIDTH-1) //text + else if (strlen(chatText) < MSG_WIDTH-1) //text chatText[strlen(chatText)] = key; Messagetype(key, strlen(chatText) - 1, chatText); return; } //key in chat mode + if (!(p = strchr(keyTable, tolower(key)))) return; key = p - keyTable; + + // global actions (always possible, even if not playing) + switch (key) { + case KT_say: + chatMode = 1; + Messagetype(key, strlen(chatText) - 1, chatText); + break; + } + if (Players[me].alive <= 0 && key != KT_quit) return; if (paused && key < KT_pause) return; switch (key) { @@ -430,7 +436,6 @@ void OneGame(void) switch(net.type) { case NP_newPiece: { - FreezePiece(net.uid); memcpy(&Players[net.uid].nextShape, net.data, sizeof(Players[0].nextShape)); StartNewPiece(net.uid, Players[net.uid].curShape); @@ -584,24 +589,24 @@ void OneGame(void) break; } //(un)pause case NP_part: + // player left checkPaused(); oldPaused = 0; - { Players[net.uid].alive = -1; Message("%s left", Players[net.uid].name); checkPaused(); ShowPause(net.uid); changed = 1; break; - } //player left case NP_argghhh: { char i; memcpy(&i, net.data, sizeof(i)); Players[net.uid].alive = 0; - if (i == me) Message("\\%dYou fragged %s", + if (i == me) + Message("\\%dYou fragged %s", Players[me].team > 7 ? 7 : Players[me].team, Players[net.uid].name); - else if (i==net.uid) + else if (i == net.uid) Message("\\%d%s died", Players[i].team > 7 ? 7 : Players[i].team, Players[i].name); else