Re: do_rescue spaghetti

From: George (greerga@CIRCLEMUD.ORG)
Date: 03/18/98


On Sat, 7 Mar 1998, Daniel Koepke wrote:

>Little nit-pick from stock bpl12, line 351-352 of act.offensive.c, the
>do_rescue command,
[...]
>Of course, that's the least of do_rescue()'s problems.  It's one of
>the few remnants of spaghetti code in CircleMUD (albeit it's still

I'd rather not check the success first, there are useful messages before
that check.  Does this look any better?  (Criticism is fine.)

diff -uprN -X .exclude stk/act.offensive.c rescue/act.offensive.c
--- stk/act.offensive.c Wed Oct 29 00:16:21 1997
+++ rescue/act.offensive.c      Wed Mar 18 20:44:05 1998
@@ -329,52 +329,46 @@ ACMD(do_rescue)

   one_argument(argument, arg);

-  if (!(vict = get_char_room_vis(ch, arg))) {
+  if (!(vict = get_char_room_vis(ch, arg)))
     send_to_char("Whom do you want to rescue?\r\n", ch);
-    return;
-  }
-  if (vict == ch) {
+  else if (vict == ch)
     send_to_char("What about fleeing instead?\r\n", ch);
-    return;
-  }
-  if (FIGHTING(ch) == vict) {
+  else if (FIGHTING(ch) == vict)
     send_to_char("How can you rescue someone you are trying to kill?\r\n", ch);
-    return;
-  }
-  for (tmp_ch = world[ch->in_room].people; tmp_ch &&
-       (FIGHTING(tmp_ch) != vict); tmp_ch = tmp_ch->next_in_room);
-
-  if (!tmp_ch) {
-    act("But nobody is fighting $M!", FALSE, ch, 0, vict, TO_CHAR);
-    return;
-  }
-  if (GET_CLASS(ch) != CLASS_WARRIOR)
-    send_to_char("But only true warriors can do this!", ch);
   else {
-    percent = number(1, 101);  /* 101% is a complete failure */
-    prob = GET_SKILL(ch, SKILL_RESCUE);
+    for (tmp_ch = world[ch->in_room].people; tmp_ch; tmp_ch = tmp_ch->next_in_room)
+      if (FIGHTING(tmp_ch) == vict)
+       break;
+
+    if (!tmp_ch)
+      act("But nobody is fighting $M!", FALSE, ch, 0, vict, TO_CHAR);
+    else if (!IS_WARRIOR(ch))
+      send_to_char("But only true warriors can do this!\r\n", ch);
+    else {
+      percent = number(1, 101);        /* 101% is a complete failure */
+      prob = GET_SKILL(ch, SKILL_RESCUE);
+
+      if (percent > prob) {
+        send_to_char("You fail the rescue!\r\n", ch);
+        return;
+      }
+      send_to_char("Banzai!  To the rescue...\r\n", ch);
+      act("You are rescued by $N, you are confused!", FALSE, vict, 0, ch, TO_CHAR);
+      act("$n heroically rescues $N!", FALSE, ch, 0, vict, TO_NOTVICT);
+
+      if (FIGHTING(vict) == tmp_ch)
+        stop_fighting(vict);
+      if (FIGHTING(tmp_ch))
+        stop_fighting(tmp_ch);
+      if (FIGHTING(ch))
+        stop_fighting(ch);

-    if (percent > prob) {
-      send_to_char("You fail the rescue!\r\n", ch);
-      return;
-    }
-    send_to_char("Banzai!  To the rescue...\r\n", ch);
-    act("You are rescued by $N, you are confused!", FALSE, vict, 0, ch, TO_CHAR);
-    act("$n heroically rescues $N!", FALSE, ch, 0, vict, TO_NOTVICT);
-
-    if (FIGHTING(vict) == tmp_ch)
-      stop_fighting(vict);
-    if (FIGHTING(tmp_ch))
-      stop_fighting(tmp_ch);
-    if (FIGHTING(ch))
-      stop_fighting(ch);
-
-    set_fighting(ch, tmp_ch);
-    set_fighting(tmp_ch, ch);
+      set_fighting(ch, tmp_ch);
+      set_fighting(tmp_ch, ch);

-    WAIT_STATE(vict, 2 * PULSE_VIOLENCE);
+      WAIT_STATE(vict, 2 * PULSE_VIOLENCE);
+    }
   }
-
 }


--
George Greer  -  Me@Null.net   | Genius may have its limitations, but stupidity
http://www.van.ml.org/~greerga | is not thus handicapped. -- Elbert Hubbard


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST