Re: [LONG] COMMAND_PROGS (was Help with an item special)

From: ;P (siv@CYBERENET.NET)
Date: 12/26/97


> Any ideas of how one would go about starting this?
there's code at the bottom..

1) i would make an intangible mob that sits in the room..
2) on the mob i would have a COMMAND_PHRASE_PROG that triggers on the
statement of "use chisel ceiling" (or an abreviation of this)
3) have the program (on the mob) use the mpoload command to load the
portal (though, i would prolly just have the mob dig an exit)

so..the only thing that you may need to know now is how to make a command
prog...well..

there are two types, the word prog and the phrase prog..the word prog
fires whenever a particular command is typed in (no matter what the
arguments)..for example..a command_word_prog with the argument of "west"
would trigger whenever someone typed "w", "we", "west poo", or
"west"..the phrase prog will trigger when someone types in the exact
phrase as a command..so, a pharse prog with the arguments "use chisel
ceiling" will fire off when someone types "u chis cei", "us c ceiling",
but NOT on "use chisel", "use chisel floor"

i use the command progs instead of writing a lot of special procedures..i
was able to take out the guildguard code, replaced with a
command_word_prog with a direction..this allowed for customization of the
insult that the guard gave rather than the generic "The guard humiliates
you.." they also do well in situations where you want something to happen
when a  character does a certain thing..like loading a guard mob when the
char types "get treasure"

the command progs act exactly like special procedures, in that they will
not go to the normal command function if there is a prog that matches..

here are the additions that you need:
-------------
mobprog.c
-------------
int mprog_command_phrase_check(char *arg, struct char_data *mob,
                        struct char_data *actor)
{
  char *args, *temp = '\0';
  MPROG_DATA *mprg;
  int ok;
  char first[256], first2[256];

  for (mprg = mob_index[mob->nr].mobprogs; mprg != NULL; mprg = mprg->next)
    if (mprg->type & COMMAND_PHRASE_PROG) {
      args = mprg->arglist;
      temp = str_dup(arg);
      ok = 1;
      temp = one_argument(temp, first);
      args = one_argument(args, first2);
      while (*first && *first2 && ok) {
        if (!is_abbrev(first, first2))
          ok = 0;
        temp = one_argument(temp, first);
        args = one_argument(args, first2);
      }

      if (ok && !*first2 && !*first) {
        mprog_driver(mprg->comlist, mob, actor, NULL, NULL);
        return 1;
      }
    }
  return 0;
}

int mprog_command_word_check(char *arg, struct char_data *mob,
                        struct char_data *actor)
{
  char *args, temp[MAX_STRING_LENGTH];
  MPROG_DATA *mprg;

  for (mprg = mob_index[mob->nr].mobprogs; mprg != NULL; mprg = mprg->next)
    if (mprg->type & COMMAND_WORD_PROG) {
      args = mprg->arglist;
      if (!isalpha(*args)) {
        temp[0] = args[0];
        temp[1] = '\0';
        args = args + 1;
        skip_spaces(&args);
      } else
        args = one_argument(args, temp);
      while (*temp) {
        if (is_abbrev(arg, temp)) {
          mprog_driver(mprg->comlist, mob, actor, NULL, NULL);
          return 1;
        }
        if (!isalpha(*args)) {
          temp[0] = args[0];
          temp[1] = '\0';
          args = args + 1;
          skip_spaces(&args);
        } else
          args = one_argument(args, temp);
      }
    }
  return 0;
}
-------------
structs.h
-------------
#define COMMAND_WORD_PROG       (1 << 12)
#define COMMAND_PHRASE_PROG     (1 << 13)
-------------
interpreter.c
-------------
(wasn't sure what was stock, so i included quite a bit for use as
context...the lines marked with the plusses are definite additions)

in command_interpreter(struct char_data *ch, char *argument)

+  int mprog_command_word_check(char *arg, struct char_data *mob,
+                         struct char_data *actor);
+  int mprog_command_phrase_check(char *arg, struct char_data *mob,
+                         struct char_data *actor);

  if (IS_AFFECTED(ch, AFF_HIDE))
      REMOVE_BIT(AFF_FLAGS(ch), AFF_HIDE);
.
.
  } else
    line = any_one_arg(argument, arg);

+  for (k = world[ch->in_room].people; k; k = k->next_in_room) {
+    if (!k) continue;
+    if (!IS_NPC(ch) && IS_NPC(k)) {
+      if (mob_index[k->nr].progtypes & COMMAND_WORD_PROG)
+        if (mprog_command_word_check(arg, k, ch))
+         return;
+      if (mob_index[k->nr].progtypes & COMMAND_PHRASE_PROG)
+        if (mprog_command_phrase_check(argument, k, ch))
+         return;
+    }
+  }

  /* otherwise, find the command */
  for (length = strlen(arg), cmd = 0; *complete_cmd_info[cmd].command != '\n'; cmd++)
-------------
db.c
-------------
int mprog_name_to_type(char *name) {
  if (!str_cmp(name, "act_prog"))
.
.
  if (!str_cmp(name, "bribe_prog"))
    return BRIBE_PROG;
+  if (!str_cmp(name, "command_word_prog"))
+    return COMMAND_WORD_PROG;
+  if (!str_cmp(name, "command_phrase_prog"))
+    return COMMAND_PHRASE_PROG;
  return (ERROR_PROG);
-------------
medit.c (for oasis support)
-------------
char *medit_get_mprog_type(struct mob_prog_data *mprog) {
  switch (mprog->type) {
  case ACT_PROG:
    return ">act_prog";
    break;
.
.
+  case COMMAND_WORD_PROG:
+    return ">command_word_prog";
+    break;
+  case COMMAND_PHRASE_PROG:
+    return ">command_phrase_prog";
+    break;
  }


     +------------------------------------------------------------+
     | 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/08/00 PST