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 06:36] 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>
 return return
Line 118: Line 179:
 } }
 </code> </code>
 +
 +===== Example old format (Remort 6) =====
 +
 +<code>
 +#VER 3
 +#CLONE 24451
 +#CLONE 16700
 +
 +#AREADATA
 +Name Lost Library~
 +Builders Xyzlvador Churel~
 +Notes ~
 +VNUMs 101 299
 +Credits Remort 6, Xzylvador~
 +Minlevel 0
 +Maxlevel 0
 +Miniquests 0
 +Security 9
 +Time 15
 +Remort
 +End
 +</code>
 +
 +===== Example new format (Remort 6) =====
  
 <code lua> <code lua>
Line 147: Line 232:
   },   },
 } }
 +</code>
 +
 +===== Example old loading code: =====
 +
 +<code C>
 +    for ( ; ; )
 +    {
 +        word   = feof( fp ) ? "End" : fread_word( fp );
 +        fMatch = FALSE;
 +
 +        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");
 +      int file_version = LLtbl_get_kv_int( LS, &area, "Version");
 +
 +      LLtbl clones;
 +      LLtbl_get_kv_tbl( LS, &area, "Clones", &clones);
 +      ind=0;
 +      while ( LLtbl_i_exists( LS, &clones, ++ind ) )
 +      {
 +          pArea->clones[ind-1] = LLtbl_get_iv_int( LS, &clones, ind);
 +      }
 +      LLtbl_release( LS, &clones);
 +
 +      pArea->name=LLtbl_get_kv_str( LS, &area, "Name");
 +      pArea->builders=LLtbl_get_kv_str( LS, &area, "Builders");
 +      pArea->comments=LLtbl_get_kv_str( LS, &area, "Comments");
 +      pArea->min_vnum=LLtbl_get_kv_int( LS, &area, "MinVnum");
 +      pArea->max_vnum=LLtbl_get_kv_int( LS, &area, "MaxVnum");
 +      pArea->credits=LLtbl_get_kv_str( LS, &area, "Credits");
 +      pArea->minlevel=LLtbl_get_kv_int( LS, &area, "MinLevel");
 +      pArea->maxlevel=LLtbl_get_kv_int( LS, &area, "MaxLevel");
 +      pArea->miniquests=LLtbl_get_kv_int( LS, &area, "Miniquests");
 +      pArea->security=LLtbl_get_kv_int( LS, &area, "Security");
 +      pArea->reset_time=LLtbl_get_kv_int( LS, &area, "Time" );
 +
 +      LLtbl aflag;
 +      LLtbl_get_kv_tbl( LS, &area, "Flags", &aflag);
 +      ind=0;      while ( LLtbl_i_exists( LS, &aflag, ++ind) )
 +      {
 +          const char *flag=LLtbl_get_iv_str( LS, &aflag, ind);
 +          int bit=flag_lookup( flag, area_flags);
 +          if ( bit == NO_FLAG )
 +          {
 +              bugf("No such area_flag: %s", flag);
 +              exit(1);
 +          }
 +          SET_BIT( pArea->area_flags, bit);
 +          free_string(flag);
 +      }
 +      LLtbl_release( LS, &aflag);
 +
 +      LLtbl atrigs;
 +      LLtbl_get_kv_tbl( LS, &area, "ATrigs", &atrigs);
 +      ind=0;
 +      while ( LLtbl_i_exists( LS, &atrigs, ++ind) )
 +      {
 +          LLtbl atrig;
 +          LLtbl_get_iv_tbl( LS, &atrigs, ind, &atrig);
 +
 +          PROG_LIST *pAprog = alloc_ATRIG();
 +          const char *trigtype=LLtbl_get_kv_str( LS, &atrig, "Type");
 +          int trigger;
 +          if ( (trigger = flag_lookup( trigtype, aprog_flags)) == NO_FLAG )
 +          {
 +              bugf("invalid aprog_flag: '%s'", trigtype);
 +              exit(1);
 +          }
 +          free_string(trigtype);
 +
 +          SET_BIT(pArea->aprog_flags, trigger);
 +          pAprog->trig_type = trigger;
 +          pAprog->vnum = LLtbl_get_kv_int( LS, &atrig, "Vnum");
 +          pAprog->trig_phrase=LLtbl_get_kv_str(LS, &atrig, "Phrase");
 +
 +          LLtbl_release(LS, &atrig);
 +      }
 +      LLtbl_release( LS, &atrigs);
 +
 +      LLtbl_release( LS, &area);
 </code> </code>
  
vodur/luaafile.1446359776.txt.gz · Last modified: 2015/11/01 06:36 by vodur