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

odelete.c File Reference

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "tables.h"
#include "olc.h"

Include dependency graph for odelete.c:

Go to the source code of this file.

Functions

 OEDIT (CHAR_DATA *ch, char *argument)


Function Documentation

OEDIT CHAR_DATA ch,
char *  argument
 

Definition at line 71 of file odelete.c.

References room_index_data::area, obj_index_data::area, AREA_CHANGED, area_data::area_flags, reset_data::arg1, reset_data::arg3, reset_data::command, FALSE, get_obj_index(), is_number(), MAX_KEY_HASH, MIL, MSL, reset_data::next, room_index_data::next, obj_index_data::next, obj_index_hash, one_argument(), room_index_data::reset_first, room_index_data::reset_last, room_index_hash, send_to_char(), SET_BIT, top_obj_index, top_vnum_obj, and TRUE.

00072 {
00073      OBJ_INDEX_DATA *pObj;
00074      OBJ_INDEX_DATA *iObj;
00075      OBJ_INDEX_DATA *sObj;
00076      RESET_DATA *pReset = NULL;
00077      RESET_DATA *prev = NULL;
00078      ROOM_INDEX_DATA *pRoom = NULL;
00079      char arg[MIL];
00080      char buf[MSL];
00081      int index, count, iHash, i;
00082 
00083      if ( argument[0] == '\0' )
00084      {
00085           send_to_char( "Syntax:  oedit delete [vnum]\n\r", ch );
00086           return FALSE;
00087      }
00088 
00089      one_argument( argument, arg );
00090 
00091      if( is_number( arg ) )
00092      {
00093           index = atoi( arg );
00094           pObj = get_obj_index( index );
00095      }
00096      else
00097      {
00098           send_to_char( "That is not a number.\n\r", ch );
00099           return FALSE;
00100      }
00101 
00102      SET_BIT( pObj->area->area_flags, AREA_CHANGED );
00103 
00104      /* Remove it from the object list */
00105 
00106      iHash = index % MAX_KEY_HASH;
00107 
00108      /* DEBUG CODE - uncomment this if you have doubts */
00109      /* printf("\nObject hash for location %d:\n", iHash);
00110      for ( tObj = obj_index_hash[iHash]; tObj != NULL; tObj = tObj->next )
00111           printf("name: %s vnum: %d\n", tObj->name, tObj->vnum ); */
00112 
00113      sObj = obj_index_hash[iHash];
00114 
00115      if( sObj->next == NULL ) /* only entry */
00116           obj_index_hash[iHash] = NULL;
00117      else if( sObj == pObj ) /* first entry */
00118           obj_index_hash[iHash] = pObj->next;
00119      else /* everything else */
00120      {
00121           for( iObj = sObj; iObj != NULL; iObj = iObj->next )
00122           {
00123                if( iObj ==  pObj )
00124                {
00125                     sObj->next = pObj->next;
00126                     break;
00127                }
00128                sObj = iObj;
00129           }
00130      }
00131 
00132      /* If you uncomment this you also need to
00133         find every instance of the object that exists in
00134         the mud and extract them otherwise each of thier
00135         pIndexData will be pointing at free memory.
00136         (Which may or may not contain the actual info)
00137         As it is all the objects will be removed the reboot/login
00138         automatically by fread_obj when it cant find the index */
00139 
00140      /* free_string( pObj->name );
00141      free_string( pObj->short_descr );
00142      free_string( pObj->description );
00143 
00144      for( pAf = pObj->affected; pAf; pAf = pAf->next )
00145           free_affect( pAf );
00146 
00147      for( pExtra = pObj->extra_descr; pExtra; pExtra = pExtra->next )
00148           free_extra_descr( pExtra );
00149 
00150      free( pObj ); */
00151 
00152      /* DEBUG CODE - uncomment this if you have doubts */
00153      /* printf("\nObject hash for location %d after removal:\n", iHash);
00154      for ( tObj = obj_index_hash[iHash]; tObj != NULL; tObj = tObj->next )
00155           printf("name: %s vnum: %d\n", tObj->name, tObj->vnum ); */
00156 
00157      /* DEBUG CODE */
00158      // printf( "\ntop_vnum_obj before: %d\n", top_vnum_obj );
00159 
00160      if( top_vnum_obj == index )
00161           for( i = 1; i < index; i++ )
00162                if( get_obj_index( i ) )
00163                     top_vnum_obj = i;
00164 
00165      /* DEBUG CODE */
00166      // printf( "top_vnum_obj after: %d\n", top_vnum_obj );
00167 
00168      top_obj_index--;
00169 
00170      /* Now crush all resets */
00171      count = 0;
00172      for( iHash = 0; iHash < MAX_KEY_HASH; iHash++ )
00173      {
00174           for( pRoom = room_index_hash[iHash]; pRoom; pRoom = pRoom->next )
00175           {
00176                prev = pRoom->reset_first;
00177                for( pReset = pRoom->reset_first; pReset; pReset = pReset->next )
00178                {
00179                     switch( pReset->command )
00180                     {
00181                          case 'O':
00182                          case 'E':
00183                          case 'P':
00184                          case 'G':
00185                               if( ( pReset->arg1 == index ) ||
00186                                   ( (  pReset->command == 'P' ) && (
00187 pReset->arg3 == index ) ) )
00188                               {
00189                                    // printf("\nprev: %d  prev->next: %d\n",
00190 //prev, prev->next );
00191 
00192                                    /* DEBUG CODE - uncomment this if you have
00193 doubts */
00194                                    /* printf("\nReset info for room %d:\n",
00195 pRoom->vnum );
00196                                    for( tReset = pRoom->reset_first; tReset;
00197 tReset = tReset->next )
00198                                         printf("command: %c  vnum: %d 
00199 memloc:%d\n", tReset->command, tReset->arg1, tReset ); */
00200 
00201                                    if( pRoom->reset_first == pReset )
00202                                    {
00203                                         pRoom->reset_first = pReset->next;
00204                                         if( !pRoom->reset_first )
00205                                              pRoom->reset_last = NULL;
00206                                    }
00207                                    else if( pRoom->reset_last == pReset )
00208                                    {
00209                                         pRoom->reset_last = prev;
00210                                         prev->next = NULL;
00211                                    }
00212                                    else
00213                                    {
00214                                         prev->next = prev->next->next;
00215                                    }
00216 
00217                                    count++;
00218                                    SET_BIT( pRoom->area->area_flags,
00219 AREA_CHANGED );
00220 
00221                                    /* DEBUG CODE - uncomment this if you have
00222 doubts */
00223                                    /* printf("\nReset info for room %d after
00224 removal:\n", pRoom->vnum );
00225                                    for( tReset = pRoom->reset_first; tReset;
00226 tReset = tReset->next )
00227                                         printf("command: %c  vnum: %d 
00228 memloc:%d\n", tReset->command, tReset->arg1, tReset ); */
00229 
00230                                    // printf("\nprev: %d  prev->next: %d\n",
00231 //prev, prev->next );
00232                               }
00233                     }
00234                     prev = pReset;
00235                }
00236           }
00237      }
00238 
00239      sprintf( buf, "Removed object vnum {R%d{x and {R%d{x resets.\n\r", index,
00240 count );
00241      send_to_char( buf, ch );
00242      return TRUE;
00243 }

Here is the call graph for this function:


Generated on Thu Jan 13 22:12:09 2005 for Beyond the Shadows by  doxygen 1.4.0