Exemple #1
0
static bool load_area_mobiles( lua_State *L, D_AREA *area )
{
   int numMob = 0, i = 0;
   D_MOBILE *mob;
   
   if( !L || !area )
      return FALSE;
      
   lua_getglobal( L, "mobiles" );
   if( !lua_istable( L, -1 ) )
   {
      bug( "Error: 'mobiles' is not a valid table.\n" );
      return FALSE;
   }
   //numMob = lua_len( L, -1 );
   lua_len( L, -1 );
   numMob = luaL_checknumber( L, -1 );
   lua_pop( L, 1 );
   for( i = 1; i <= numMob; i++ )
   {
      lua_rawgeti( L, -1, i );
      if( ( mob = load_mobile( L ) ) == NULL )
      {
         bug( "Error: Unable to allocate memory for new mobile." );
         return FALSE;
      }
      AttachToList( mob, npc_list );
      AttachToList( mob, area->mobiles );
      lua_pop( L, 1 );
   }
   
   return TRUE;
}
Exemple #2
0
void load_world( CHAR_DATA * ch )
{
   FILE *mobfp;
   FILE *shipfp;
   char file1[256];
   char file2[256];
   const char *word;
   int done = 0;
   bool mobfile = FALSE;
   bool shipfile = FALSE;

   snprintf( file1, 256, "%s%s", SYSTEM_DIR, MOB_FILE );
   if( ( mobfp = fopen( file1, "r" ) ) == NULL )
   {
      bug( "%s", "load_world: fopen mob file" );
      perror( file1 );
   }
   else
      mobfile = TRUE;

   snprintf( file2, 256, "%s%s", SYSTEM_DIR, SHIP_FILE );
   if( ( shipfp = fopen( file2, "r" ) ) == NULL )
   {
      bug( "%s", "load_world: fopen ship file" );
      perror( file1 );
   }
   else
      shipfile = TRUE;

   if( mobfile )
   {
      log_string( "World state: loading mobs" );
      while( done == 0 )
      {
         if( feof( mobfp ) )
            done++;
         else
         {
            word = fread_word( mobfp );
            if( str_cmp( word, "#END" ) )
               load_mobile( mobfp );
            else
               done++;
         }
      }
      FCLOSE( mobfp );
   }

   load_obj_files(  );

   if( shipfile )
   {
      done = 0;
      log_string( "World state: loading ships" );
      while( done == 0 )
      {
         if( feof( shipfp ) )
            done++;
         else
         {
            word = fread_word( shipfp );
            if( str_cmp( word, "#END" ) )
               load_ship( shipfp );
            else
               done++;
         }
      }
      FCLOSE( shipfp );
   }

   /*
    * Once loaded, the data needs to be purged in the event it causes a crash so that it won't try to reload 
    */
   unlink( file1 );
   unlink( file2 );
   return;
}