summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2019-02-15 19:20:26 +0100
committerBardur Arantsson <bardur@scientician.net>2019-02-15 19:20:26 +0100
commitec341170b9728e9f33b8ee2da8bd5c16f03f8710 (patch)
treee4a908408ee2c7270a0187aea24ce3896797edd6
parent67eae27a831d804953ac02926cef4b4b3a43b420 (diff)
Remove duplicate code
-rw-r--r--src/cmd2.cc118
1 files changed, 28 insertions, 90 deletions
diff --git a/src/cmd2.cc b/src/cmd2.cc
index 8318e370..c57fcb2e 100644
--- a/src/cmd2.cc
+++ b/src/cmd2.cc
@@ -761,6 +761,26 @@ static bool do_cmd_open_aux(int y, int x)
}
+/*
+ * Change a command "argument" to a number of repitions
+ */
+static void allow_repeat_command()
+{
+ // If there's a command argument, we set the number
+ // of repetitions instead.
+ if (command_arg)
+ {
+ /* Set repeat count */
+ command_rep = command_arg - 1;
+
+ /* Redraw the state */
+ p_ptr->redraw |= (PR_FRAME);
+
+ /* Cancel the arg */
+ command_arg = 0;
+ }
+}
+
/*
* Open a closed/locked/jammed door or a closed/locked chest.
@@ -810,17 +830,7 @@ void do_cmd_open()
}
/* Allow repeated command */
- if (command_arg)
- {
- /* Set repeat count */
- command_rep = command_arg - 1;
-
- /* Redraw the state */
- p_ptr->redraw |= (PR_FRAME);
-
- /* Cancel the arg */
- command_arg = 0;
- }
+ allow_repeat_command();
/* Get a "repeated" direction */
if (get_rep_dir(&dir))
@@ -959,17 +969,7 @@ void do_cmd_close()
}
/* Allow repeated command */
- if (command_arg)
- {
- /* Set repeat count */
- command_rep = command_arg - 1;
-
- /* Redraw the state */
- p_ptr->redraw |= (PR_FRAME);
-
- /* Cancel the arg */
- command_arg = 0;
- }
+ allow_repeat_command();
/* Get a "repeated" direction */
if (get_rep_dir(&dir))
@@ -1388,17 +1388,7 @@ void do_cmd_tunnel()
if (p_ptr->wild_mode) return;
/* Allow repeated command */
- if (command_arg)
- {
- /* Set repeat count */
- command_rep = command_arg - 1;
-
- /* Redraw the state */
- p_ptr->redraw |= (PR_FRAME);
-
- /* Cancel the arg */
- command_arg = 0;
- }
+ allow_repeat_command();
/* Get a direction to tunnel, or Abort */
if (get_rep_dir(&dir))
@@ -1579,17 +1569,7 @@ void do_cmd_bash()
}
/* Allow repeated command */
- if (command_arg)
- {
- /* Set repeat count */
- command_rep = command_arg - 1;
-
- /* Redraw the state */
- p_ptr->redraw |= (PR_FRAME);
-
- /* Cancel the arg */
- command_arg = 0;
- }
+ allow_repeat_command();
/* Get a "repeated" direction */
if (get_rep_dir(&dir))
@@ -1669,17 +1649,7 @@ void do_cmd_alter()
/* Allow repeated command */
- if (command_arg)
- {
- /* Set repeat count */
- command_rep = command_arg - 1;
-
- /* Redraw the state */
- p_ptr->redraw |= (PR_FRAME);
-
- /* Cancel the arg */
- command_arg = 0;
- }
+ allow_repeat_command();
/* Get a direction */
if (get_rep_dir(&dir))
@@ -1848,17 +1818,7 @@ static void do_cmd_walk_jump(int pickup)
/* Allow repeated command */
- if (command_arg)
- {
- /* Set repeat count */
- command_rep = command_arg - 1;
-
- /* Redraw the state */
- p_ptr->redraw |= (PR_FRAME);
-
- /* Cancel the arg */
- command_arg = 0;
- }
+ allow_repeat_command();
/* Get a "repeated" direction */
if (get_rep_dir(&dir))
@@ -1930,18 +1890,7 @@ static void do_cmd_unwalk()
/* Allow repeated command */
- if (command_arg)
- {
- /* Set repeat count */
- command_rep = command_arg - 1;
-
- /* Redraw the state */
- p_ptr->redraw |= (PR_FRAME);
-
- /* Cancel the arg */
- command_arg = 0;
- }
-
+ allow_repeat_command();
/* Attack monsters */
if (c_ptr->m_idx > 0)
@@ -2143,18 +2092,7 @@ void do_cmd_stay(int pickup)
/* Allow repeated command */
- if (command_arg)
- {
- /* Set repeat count */
- command_rep = command_arg - 1;
-
- /* Redraw the state */
- p_ptr->redraw |= (PR_FRAME);
-
- /* Cancel the arg */
- command_arg = 0;
- }
-
+ allow_repeat_command();
/* Take a turn */
energy_use = 100;