code cleanup: use terniaries
[netris.git] / game.c
diff --git a/game.c b/game.c
index 5779d84c2ca89f71e7d9f72a04c91ac5a59ff218..64acecc6928b6afae51fd8bdd642570a6d013216 100644 (file)
--- 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};
@@ -123,8 +123,7 @@ void HandleOption(char tag, char *value)
 {
        switch (tag) {
        case 'a':       //ascii
-               if (value && !strcasecmp(value, "0")) Sets.ascii = 0;
-               else Sets.ascii = 1;
+               Sets.ascii = value && !strcasecmp(value, "0") ? 0 : 1;
                Sets.drawstyle &= ~Sets.ascii;
                break;
        case 'c':       //connect
@@ -147,15 +146,13 @@ void HandleOption(char tag, char *value)
                Players[0].team = atoi(value);
                break;
        case 'd':       //dropmode
-               Sets.dropmode = atoi(value);
+               Sets.dropmode = value ? atoi(value) : 1;
                break;
        case 'C':       //color
-               if (value && !strcasecmp(value, "1")) Sets.color = 1;
-               else Sets.color = 0;
+               Sets.color = value && strcasecmp(value, "0") ? 1 : 0;
                break;
        case 'S':       //slowterm
-               if (value && !strcasecmp(value, "1")) Sets.standout = 1;
-               else Sets.standout = 0;
+               Sets.standout = value && !strcasecmp(value, "0") ? 1 : 0;
                break;
        case 'k':       //keys
                MapKeys(value);
@@ -344,15 +341,49 @@ void OneGame(void)
                        return;
                } //key in chat mode
 
-               if (key == 13) {
+               if (!(p = strchr(keyTable, tolower(key)))) return;
+               key = p - keyTable;
+
+               // global actions (always possible, even if not playing)
+               switch (key) {
+               case KT_redraw:
+                       clear();
+                       InitFields();
+//                     ScheduleFullRedraw();
+                       refresh();
+                       return;
+               case KT_say:
                        chatMode = 1;
                        Messagetype(key, strlen(chatText) - 1, chatText);
+                       return;
+               case KT_quit:
+                       ShowPause(me);
+                       refresh();
+                       gameStatus = 0;
+                       return;
                }
 
-               if (!(p = strchr(keyTable, tolower(key)))) return;
-               key = p - keyTable;
-               if (Players[me].alive <= 0 && key != KT_quit) return;
-               if (paused && key < KT_pause) 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;
+                       return;
+               }
+
+               if (paused) return;
+               // actions only available while actually playing
                switch (key) {
                case KT_left:
                        if (MovePiece(me, 0, -1) && spied) SendPacket(me, NP_left, 0, NULL);
@@ -392,32 +423,8 @@ void OneGame(void)
                        ShowScore(me, Players[me].score);
                        changed = 1;
                        break;
-               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;
-                       break;
-               case KT_redraw:
-                       clear();
-                       InitFields();
-//                     ScheduleFullRedraw();
-                       refresh();
-                       break;
-               case KT_quit:
-                       ShowPause(me);
-                       refresh();
-                       gameStatus = 0;
-                       break;
-               } //E_key
+               }
+
                if (dropMode && DropPiece(me) > 0) {
                        SetITimer(Game.speed, Game.speed);
                        if (spied) SendPacket(me, NP_drop, 0, NULL);