OSDN Git Service

[Refactor] #40634 Separated check_activation_conditions() from exe_activate()
authorHourier <hourier@users.sourceforge.jp>
Mon, 17 Aug 2020 10:05:38 +0000 (19:05 +0900)
committerHourier <hourier@users.sourceforge.jp>
Mon, 17 Aug 2020 10:05:38 +0000 (19:05 +0900)
src/action/activation-execution.c

index dc70745..1c08c22 100644 (file)
@@ -118,6 +118,25 @@ static bool check_activation_success(ae_type *ae_ptr)
     return FALSE;
 }
 
+static bool check_activation_conditions(player_type *user_ptr, ae_type *ae_ptr)
+{
+    if (!check_activation_success(ae_ptr))
+        return FALSE;
+
+    if (ae_ptr->o_ptr->timeout) {
+        msg_print(_("\82»\82ê\82Í\94÷\82©\82É\89¹\82ð\97§\82Ä\81A\8bP\82«\81A\8fÁ\82¦\82½...", "It whines, glows and fades..."));
+        return FALSE;
+    }
+
+    if (!ae_ptr->o_ptr->xtra4 && (ae_ptr->o_ptr->tval == TV_FLASK) && ((ae_ptr->o_ptr->sval == SV_LITE_TORCH) || (ae_ptr->o_ptr->sval == SV_LITE_LANTERN))) {
+        msg_print(_("\94R\97¿\82ª\82È\82¢\81B", "It has no fuel."));
+        free_turn(user_ptr);
+        return FALSE;
+    }
+    
+    return TRUE;
+}
+
 /*!
  * @brief \91\95\94õ\82ð\94­\93®\82·\82é\83R\83}\83\93\83h\82Ì\83T\83u\83\8b\81[\83`\83\93 /
  * Activate a wielded object.  Wielded objects never stack.
@@ -143,20 +162,9 @@ void exe_activate(player_type *user_ptr, INVENTORY_IDX item)
         return;
 
     decide_activation_success(user_ptr, ae_ptr);
-    if (!check_activation_success(ae_ptr))
+    if (!check_activation_conditions(user_ptr, ae_ptr))
         return;
 
-    if (ae_ptr->o_ptr->timeout) {
-        msg_print(_("\82»\82ê\82Í\94÷\82©\82É\89¹\82ð\97§\82Ä\81A\8bP\82«\81A\8fÁ\82¦\82½...", "It whines, glows and fades..."));
-        return;
-    }
-
-    if (!ae_ptr->o_ptr->xtra4 && (ae_ptr->o_ptr->tval == TV_FLASK) && ((ae_ptr->o_ptr->sval == SV_LITE_TORCH) || (ae_ptr->o_ptr->sval == SV_LITE_LANTERN))) {
-        msg_print(_("\94R\97¿\82ª\82È\82¢\81B", "It has no fuel."));
-        free_turn(user_ptr);
-        return;
-    }
-
     msg_print(_("\8en\93®\82³\82¹\82½...", "You activate it..."));
     sound(SOUND_ZAP);
     if (activation_index(user_ptr, ae_ptr->o_ptr)) {