Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

olc_mpcode.c

Go to the documentation of this file.
00001 /* The following code is based on ILAB OLC by Jason Dinkel */
00002 /* Mobprogram code by Lordrom for Nevermore Mud */
00003 
00004 #if defined(macintosh)
00005 #include <types.h>
00006 #else
00007 #include <sys/types.h>
00008 #endif
00009 #include <ctype.h>
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string.h>
00013 #include <time.h>
00014 #include "merc.h"
00015 #include "tables.h"
00016 #include "olc.h"
00017 #include "recycle.h"
00018 
00019 #define MPEDIT( fun )           bool fun(CHAR_DATA *ch, char*argument)
00020 
00021 
00022 const struct olc_cmd_type mpedit_table[] = {
00023 /*    {    command        function    }, */
00024 
00025     {"commands", show_commands},
00026     {"create", mpedit_create},
00027     {"code", mpedit_code},
00028     {"show", mpedit_show},
00029     {"list", mpedit_list},
00030     {"?", show_help},
00031 
00032     {NULL, 0}
00033 };
00034 
00035 void mpedit (CHAR_DATA * ch, char *argument)
00036 {
00037     MPROG_CODE *pMcode;
00038     char arg[MAX_INPUT_LENGTH];
00039     char command[MAX_INPUT_LENGTH];
00040     int cmd;
00041     AREA_DATA *ad;
00042 
00043     smash_tilde (argument);
00044     strcpy (arg, argument);
00045     argument = one_argument (argument, command);
00046 
00047     EDIT_MPCODE (ch, pMcode);
00048 
00049     if (pMcode)
00050     {
00051         ad = get_vnum_area (pMcode->vnum);
00052 
00053         if (ad == NULL)
00054         {                        /* ??? */
00055             edit_done (ch);
00056             return;
00057         }
00058 
00059         if (!IS_BUILDER (ch, ad))
00060         {
00061             send_to_char ("MPEdit: Insufficient security to modify code.\n\r",
00062                           ch);
00063             edit_done (ch);
00064             return;
00065         }
00066     }
00067 
00068     if (command[0] == '\0')
00069     {
00070         mpedit_show (ch, argument);
00071         return;
00072     }
00073 
00074     if (!str_cmp (command, "done"))
00075     {
00076         edit_done (ch);
00077         return;
00078     }
00079 
00080     for (cmd = 0; mpedit_table[cmd].name != NULL; cmd++)
00081     {
00082         if (!str_prefix (command, mpedit_table[cmd].name))
00083         {
00084             if ((*mpedit_table[cmd].olc_fun) (ch, argument) && pMcode)
00085                 if ((ad = get_vnum_area (pMcode->vnum)) != NULL)
00086                     SET_BIT (ad->area_flags, AREA_CHANGED);
00087             return;
00088         }
00089     }
00090 
00091     interpret (ch, arg);
00092 
00093     return;
00094 }
00095 
00096 void do_mpedit (CHAR_DATA * ch, char *argument)
00097 {
00098     MPROG_CODE *pMcode;
00099     char command[MAX_INPUT_LENGTH];
00100 
00101     argument = one_argument (argument, command);
00102 
00103     if (is_number (command))
00104     {
00105         int vnum = atoi (command);
00106         AREA_DATA *ad;
00107 
00108         if ((pMcode = get_mprog_index (vnum)) == NULL)
00109         {
00110             send_to_char ("MPEdit : That vnum does not exist.\n\r", ch);
00111             return;
00112         }
00113 
00114         ad = get_vnum_area (vnum);
00115 
00116         if (ad == NULL)
00117         {
00118             send_to_char ("MPEdit : VNUM no asignado a ningun area.\n\r", ch);
00119             return;
00120         }
00121 
00122         if (!IS_BUILDER (ch, ad))
00123         {
00124             send_to_char
00125                 ("MPEdit : Insuficiente seguridad para editar area.\n\r", ch);
00126             return;
00127         }
00128 
00129         ch->desc->pEdit = (void *) pMcode;
00130         ch->desc->editor = ED_MPCODE;
00131 
00132         return;
00133     }
00134 
00135     if (!str_cmp (command, "create"))
00136     {
00137         if (argument[0] == '\0')
00138         {
00139             send_to_char ("Sintaxis : mpedit create [vnum]\n\r", ch);
00140             return;
00141         }
00142 
00143         mpedit_create (ch, argument);
00144         return;
00145     }
00146 
00147     send_to_char ("Sintaxis : mpedit [vnum]\n\r", ch);
00148     send_to_char ("           mpedit create [vnum]\n\r", ch);
00149 
00150     return;
00151 }
00152 
00153 MPEDIT (mpedit_create)
00154 {
00155     MPROG_CODE *pMcode;
00156     int value = atoi (argument);
00157     AREA_DATA *ad;
00158 
00159     if (IS_NULLSTR (argument) || value < 1)
00160     {
00161         send_to_char ("Sintaxis : mpedit create [vnum]\n\r", ch);
00162         return FALSE;
00163     }
00164 
00165     ad = get_vnum_area (value);
00166 
00167     if (ad == NULL)
00168     {
00169         send_to_char ("MPEdit : VNUM no asignado a ningun area.\n\r", ch);
00170         return FALSE;
00171     }
00172 
00173     if (!IS_BUILDER (ch, ad))
00174     {
00175         send_to_char
00176             ("MPEdit : Insuficiente seguridad para crear MobProgs.\n\r", ch);
00177         return FALSE;
00178     }
00179 
00180     if (get_mprog_index (value))
00181     {
00182         send_to_char ("MPEdit: Code vnum already exists.\n\r", ch);
00183         return FALSE;
00184     }
00185 
00186     pMcode = new_mpcode ();
00187     pMcode->vnum = value;
00188     pMcode->next = mprog_list;
00189     mprog_list = pMcode;
00190     ch->desc->pEdit = (void *) pMcode;
00191     ch->desc->editor = ED_MPCODE;
00192 
00193     send_to_char ("MobProgram Code Created.\n\r", ch);
00194 
00195     return TRUE;
00196 }
00197 
00198 MPEDIT (mpedit_show)
00199 {
00200     MPROG_CODE *pMcode;
00201     char buf[MAX_STRING_LENGTH];
00202 
00203     EDIT_MPCODE (ch, pMcode);
00204 
00205     sprintf (buf,
00206              "Vnum:       [%d]\n\r"
00207              "Code:\n\r%s\n\r", pMcode->vnum, pMcode->code);
00208     send_to_char (buf, ch);
00209 
00210     return FALSE;
00211 }
00212 
00213 MPEDIT (mpedit_code)
00214 {
00215     MPROG_CODE *pMcode;
00216     EDIT_MPCODE (ch, pMcode);
00217 
00218     if (argument[0] == '\0')
00219     {
00220         string_append (ch, &pMcode->code);
00221         return TRUE;
00222     }
00223 
00224     send_to_char ("Syntax: code\n\r", ch);
00225     return FALSE;
00226 }
00227 
00228 MPEDIT (mpedit_list)
00229 {
00230     int count = 1;
00231     MPROG_CODE *mprg;
00232     char buf[MAX_STRING_LENGTH];
00233     BUFFER *buffer;
00234     bool fAll = !str_cmp (argument, "all");
00235     char blah;
00236     AREA_DATA *ad;
00237 
00238     buffer = new_buf ();
00239 
00240     for (mprg = mprog_list; mprg != NULL; mprg = mprg->next)
00241         if (fAll
00242             || ENTRE (ch->in_room->area->min_vnum, mprg->vnum,
00243                       ch->in_room->area->max_vnum))
00244         {
00245             ad = get_vnum_area (mprg->vnum);
00246 
00247             if (ad == NULL)
00248                 blah = '?';
00249             else if (IS_BUILDER (ch, ad))
00250                 blah = '*';
00251             else
00252                 blah = ' ';
00253 
00254             sprintf (buf, "[%3d] (%c) %5d\n\r", count, blah, mprg->vnum);
00255             add_buf (buffer, buf);
00256 
00257             count++;
00258         }
00259 
00260     if (count == 1)
00261     {
00262         if (fAll)
00263             add_buf (buffer, "MobPrograms do not exist!\n\r");
00264         else
00265             add_buf (buffer, "MobPrograms do not exist in this area.\n\r");
00266     }
00267 
00268     page_to_char (buf_string (buffer), ch);
00269     free_buf (buffer);
00270 
00271     return FALSE;
00272 }

Generated on Thu Jan 13 21:48:13 2005 for Beyond the Shadows by  doxygen 1.4.0