Re: [Long][Code][newbie?] need help on mob func.

From: George Greer (greerga@circlemud.org)
Date: 10/31/02


On Thu, 31 Oct 2002, DJMC wrote:

>SPECIAL(goto_mayor)
>{
[...]
>   int cmd_emote = find_command("emote");
>   int cmd_mutter = find_command("mutter");
>   int cmd_puke = find_command("puke");
>   int cmd_say = find_command("say");
>   int cmd_shudder = find_command("shudder");
>   int cmd_sigh = find_command("sigh");
>   int cmd_sway = find_command("sway");
>   int cmd_whine = find_command("whine");
>   int cmd_yell = find_command("yell");

Ewww.  This does 9 linear searches of the command table every time you call
this function.  Try at least making them 'static', and remember to check
the return code, 'kay?

>   ACMD(do_action);
>   ACMD(do_emote);
>   ACMD(do_gen_com);
>   ACMD(do_say);

These shouldn't be in the function body, though it's only an issue with
-Wnested-externs.

>   // Random Dice Roll to see if moving
>   if (number(1, 1000) < 900) {

So 1-899 and 900-1000? Why not just 1-9 and 10? Or 'number(0, 9)' ?

>     // Random Dice Roll to pick location
>     i = number(0, 5);
>
>     location = real_room(goto_rooms[i]);
>     if (location < 0||location > top_of_world) {

The start of something vünderful, ...

>      char_from_room(mob);
>      char_to_room(mob, location);

... and here we have the Crème de la Crème.

Though this should only elicit a warning by itself, the net effect will be
to leave a mobile hanging around in NOWHERE, which is very likely to cause
issues elsewhere.

--
George Greer
greerga@circlemud.org

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT