User Tools

Site Tools


vodur:luaafile

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
vodur:luaafile [2015/11/01 07:24] vodurvodur:luaafile [2015/11/11 04:40] (current) vodur
Line 1: Line 1:
 +===== Pros/Cons for new method: =====
 +
 +Pros:\\
 +Less messy/problematic to add/remove/change stuff in area files now.\\
 +Can easily parse area files with outside scripts for analysis.
 +
 +Cons:\\
 +Less performant (bigger filesize, slower save/load)\\
 +Confusing to use new save/load code?
 +
 +===== Example old saving code: =====
 +
 +<code C>
 +      fprintf( fp, "#VER %d\n", CURR_AREA_VERSION );
 +
 +      for ( i = 0; i <MAX_AREA_CLONE; i++ )
 +      if ( pArea->clones[i]> 0 )
 +          fprintf( fp, "#CLONE %d\n", pArea->clones[i] );
 +
 +      fprintf( fp, "\n#AREADATA\n" );
 +      rfprintf( fp, "Name %s~\n",        pArea->name );
 +      rfprintf( fp, "Builders %s~\n",    fix_string( pArea->builders ) );
 +      rfprintf( fp, "Comments %s~\n",       fix_string( pArea->comments ) );
 +      fprintf( fp, "VNUMs %d %d\n",     pArea->min_vnum, pArea->max_vnum );
 +      rfprintf( fp, "Credits %s~\n",     pArea->credits );
 +    /* Added minlevel, maxlevel, and miniquests for new areas command
 +       -Astark Dec 2012 */
 +      fprintf( fp, "Minlevel %d\n",     pArea->minlevel );
 +      fprintf( fp, "Maxlevel %d\n",     pArea->maxlevel );
 +      fprintf( fp, "Miniquests %d\n",   pArea->miniquests );
 +      fprintf( fp, "Security %d\n",     pArea->security );
 +      fprintf( fp, "Time %d\n",         pArea->reset_time );
 +      if (IS_SET(pArea->area_flags,AREA_REMORT))
 +          fprintf( fp, "Remort\n");
 +      if (IS_SET(pArea->area_flags,AREA_NOQUEST))
 +          fprintf( fp, "NoQuest\n");
 +      if (IS_SET(pArea->area_flags,AREA_NOHIDE))
 +          fprintf( fp, "NoHide\n");
 +      if ( IS_SET(pArea->area_flags, AREA_SOLO) )
 +          fprintf(fp, "Solo\n");
 +
 +      /* save aprogs if any */
 +      if (pArea->aprogs != NULL)
 +      {
 +          PROG_LIST *pAprog;
 +          reverse_aprog_order(pArea);
 +          for (pAprog = pArea->aprogs; pAprog; pAprog = pAprog->next)
 +          {
 +              rfprintf(fp, "AProg %s %d %s~\n", name_lookup(pAprog->trig_type, a  prog_flags), pAprog->vnum, pAprog->trig_phrase);
 +          }
 +          reverse_aprog_order(pArea);
 +      }
 +</code>
 +
 +===== Example new saving code: =====
 +
 <code C> <code C>
       LStbl area;       LStbl area;
Line 68: Line 124:
       LStbl_release( LS, &area );       LStbl_release( LS, &area );
 </code> </code>
 +
 +===== Example old format (Bastion) =====
  
 <code> <code>
Line 86: Line 144:
 End End
 </code> </code>
 +
 +===== Example new format (Bastion) =====
  
 <code lua> <code lua>
Line 119: Line 179:
 } }
 </code> </code>
 +
 +===== Example old format (Remort 6) =====
  
 <code> <code>
Line 139: Line 201:
 End End
 </code> </code>
 +
 +===== Example new format (Remort 6) =====
  
 <code lua> <code lua>
Line 169: Line 233:
 } }
 </code> </code>
 +
 +===== Example old loading code: =====
  
 <code C> <code C>
 +    for ( ; ; )
 +    {
 +        word   = feof( fp ) ? "End" : fread_word( fp );
 +        fMatch = FALSE;
  
-LLtbl area;+        switch ( UPPER(word[0]) ) 
 +        { 
 +      /* Added for the new areas command - Astark Dec 2012 */ 
 +        case 'A': 
 +            if (!str_cmp(word, "AProg") ) 
 +            { 
 +                PROG_LIST *pAprog; 
 +                const char *word; 
 +                int trigger = 0; 
 + 
 +                pAprog              = alloc_ATRIG(); 
 +                word                = fread_word( fp ); 
 +                if ( (trigger = flag_lookup( word, aprog_flags )) == NO_FLAG ) 
 +                { 
 +                    bugf("load_area.AProg: invalid trigger '%s' for area %s.", word, pArea->name); 
 +                    exit(1); 
 +                } 
 +                SET_BIT(pArea->aprog_flags, trigger ); 
 +                pAprog->trig_type   = trigger; 
 +                pAprog->vnum        = fread_number( fp ); 
 +                pAprog->trig_phrase = fread_string( fp ); 
 +                pAprog->next        = pArea->aprogs; 
 +                pArea->aprogs   = pAprog; 
 +            } 
 +            break; 
 +        case 'M': 
 +            KEY("Minlevel", pArea->minlevel, fread_number( fp )); 
 +            KEY("Maxlevel", pArea->maxlevel, fread_number( fp )); 
 +            KEY("Miniquests", pArea->miniquests, fread_number( fp )); 
 +        case 'N': 
 +            SKEY( "Name", pArea->name ); 
 +            if ( !str_cmp(word, "NoQuest")) 
 +            { 
 +                SET_BIT(pArea->area_flags,AREA_NOQUEST); 
 +                break; 
 +            } 
 +            if ( !str_cmp(word, "NoHide")) 
 +            { 
 +                SET_BIT(pArea->area_flags,AREA_NOHIDE); 
 +                break; 
 +            } 
 +            SKEY( "Comments", pArea->comments ); 
 +            break; 
 +        case 'R': 
 +            if ( !str_cmp(word, "Remort")) 
 +                SET_BIT(pArea->area_flags,AREA_REMORT); 
 +            break; 
 +        case 'S': 
 +            KEY( "Security", pArea->security, fread_number( fp ) ); 
 +            if ( !str_cmp(word, "Solo") ) 
 +            { 
 +                SET_BIT(pArea->area_flags, AREA_SOLO); 
 +                break; 
 +            } 
 +            break; 
 +        case 'T': 
 +            KEY("Time", pArea->reset_time, fread_number( fp )); 
 +        case 'V': 
 +            if ( !str_cmp( word, "VNUMs" ) ) 
 +            { 
 +                pArea->min_vnum = fread_number( fp ); 
 +                pArea->max_vnum = fread_number( fp ); 
 +            } 
 +            break; 
 +        case 'E': 
 +            if ( !str_cmp( word, "End" ) ) 
 +            { 
 +                fMatch = TRUE; 
 +                if ( area_first == NULL ) 
 +                    area_first = pArea; 
 +                if ( area_last  != NULL ) 
 +                    area_last->next = pArea; 
 + 
 +                area_last    = pArea; 
 +                pArea->next  = NULL; 
 +                current_area = pArea; 
 +                top_area++; 
 + 
 +                return; 
 +            } 
 +            break; 
 +        case 'B': 
 +            SKEY( "Builders", pArea->builders ); 
 +            break; 
 +        case 'C': 
 +            SKEY( "Credits", pArea->credits ); 
 +            break; 
 +        } 
 + 
 +        if ( !fMatch ) 
 +        { 
 +            // no nothing but avoid warning 
 +        } 
 +    } 
 +</code> 
 + 
 +===== Example new loading code: ===== 
 + 
 +<code C> 
 +      LLtbl area;
       LLtbl_load( LS, &area, "Test1.lua");       LLtbl_load( LS, &area, "Test1.lua");
->>    int file_version = LLtbl_get_kv_int( LS, &area, "Version");+      int file_version = LLtbl_get_kv_int( LS, &area, "Version");
  
       LLtbl clones;       LLtbl clones;
vodur/luaafile.1446362656.txt.gz · Last modified: 2015/11/01 07:24 by vodur