vodur:luaafile
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| vodur:luaafile [2015/11/01 06:32] – vodur | vodur:luaafile [2015/11/11 04:40] (current) – vodur | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | <code C > | + | ===== Pros/Cons for new method: ===== |
| + | |||
| + | Pros:\\ | ||
| + | Less messy/ | ||
| + | Can easily parse area files with outside scripts for analysis. | ||
| + | |||
| + | Cons:\\ | ||
| + | Less performant (bigger filesize, slower save/ | ||
| + | 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 < | ||
| + | if ( pArea-> | ||
| + | fprintf( fp, "# | ||
| + | |||
| + | fprintf( fp, " | ||
| + | rfprintf( fp, "Name %s~\n", | ||
| + | rfprintf( fp, " | ||
| + | rfprintf( fp, " | ||
| + | fprintf( fp, "VNUMs %d %d\n", | ||
| + | rfprintf( fp, " | ||
| + | /* Added minlevel, maxlevel, and miniquests for new areas command | ||
| + | | ||
| + | fprintf( fp, " | ||
| + | fprintf( fp, " | ||
| + | fprintf( fp, " | ||
| + | fprintf( fp, " | ||
| + | fprintf( fp, "Time %d\n", | ||
| + | if (IS_SET(pArea-> | ||
| + | fprintf( fp, " | ||
| + | if (IS_SET(pArea-> | ||
| + | fprintf( fp, " | ||
| + | if (IS_SET(pArea-> | ||
| + | fprintf( fp, " | ||
| + | if ( IS_SET(pArea-> | ||
| + | fprintf(fp, " | ||
| + | |||
| + | /* save aprogs if any */ | ||
| + | if (pArea-> | ||
| + | { | ||
| + | PROG_LIST *pAprog; | ||
| + | reverse_aprog_order(pArea); | ||
| + | for (pAprog = pArea-> | ||
| + | { | ||
| + | rfprintf(fp, | ||
| + | } | ||
| + | reverse_aprog_order(pArea); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Example new saving code: ===== | ||
| + | |||
| + | <code C> | ||
| LStbl area; | LStbl area; | ||
| LStbl_create( LS, &area ); | LStbl_create( LS, &area ); | ||
| Line 42: | Line 98: | ||
| flag_bit_name(area_flags, | flag_bit_name(area_flags, | ||
| LSarr_release( LS, & | LSarr_release( LS, & | ||
| + | |||
| + | LSarr atrigs; | ||
| + | LSarr_create( LS, &atrigs ); | ||
| + | LStbl_kv_arr( LS, &area, " | ||
| + | |||
| + | if (pArea-> | ||
| + | { | ||
| + | PROG_LIST *pAprog; | ||
| + | reverse_aprog_order(pArea); | ||
| + | for (pAprog = pArea-> | ||
| + | { | ||
| + | LStbl atrig; | ||
| + | LStbl_create( LS, & | ||
| + | LSarr_add_tbl( LS, & | ||
| + | LStbl_kv_str( LS, &atrig, " | ||
| + | LStbl_kv_int( LS, &atrig, " | ||
| + | LStbl_kv_str( LS, &atrig, " | ||
| + | LStbl_release( LS, & | ||
| + | } | ||
| + | reverse_aprog_order(pArea); | ||
| + | } | ||
| + | LSarr_release( LS, & | ||
| + | |||
| + | LStbl_save( LS, &area, " | ||
| + | LStbl_release( LS, &area ); | ||
| </ | </ | ||
| + | |||
| + | ===== Example old format (Bastion) ===== | ||
| + | |||
| + | < | ||
| + | #VER 3 | ||
| + | |||
| + | #AREADATA | ||
| + | Name Bastion~ | ||
| + | Builders Parademia Rynor~ | ||
| + | Notes ~ | ||
| + | VNUMs 10200 10599 | ||
| + | Credits Siva~ | ||
| + | Minlevel 1 | ||
| + | Maxlevel 100 | ||
| + | Miniquests 9 | ||
| + | Security 8 | ||
| + | Time 15 | ||
| + | AProg enter 10200 100~ | ||
| + | End | ||
| + | </ | ||
| + | |||
| + | ===== Example new format (Bastion) ===== | ||
| <code lua> | <code lua> | ||
| Line 75: | Line 178: | ||
| }, | }, | ||
| } | } | ||
| + | </ | ||
| + | |||
| + | ===== Example old format (Remort 6) ===== | ||
| + | |||
| + | < | ||
| + | #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 | ||
| + | </ | ||
| + | |||
| + | ===== Example new format (Remort 6) ===== | ||
| + | |||
| + | <code lua> | ||
| + | return | ||
| + | { | ||
| + | Version = 6, | ||
| + | Clones = | ||
| + | { | ||
| + | 24451, | ||
| + | 16700, | ||
| + | }, | ||
| + | Name = "Lost Library", | ||
| + | Builders = " | ||
| + | Comments = "", | ||
| + | MinVnum = 101, | ||
| + | MaxVnum = 299, | ||
| + | Credits = " | ||
| + | MinLevel = 0, | ||
| + | MaxLevel = 0, | ||
| + | Miniquests = 0, | ||
| + | Security = 9, | ||
| + | Time = 15, | ||
| + | Flags = | ||
| + | { | ||
| + | " | ||
| + | }, | ||
| + | ATrigs = | ||
| + | { | ||
| + | }, | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Example old loading code: ===== | ||
| + | |||
| + | <code C> | ||
| + | for ( ; ; ) | ||
| + | { | ||
| + | word = feof( fp ) ? " | ||
| + | fMatch = FALSE; | ||
| + | |||
| + | switch ( UPPER(word[0]) ) | ||
| + | { | ||
| + | /* Added for the new areas command - Astark Dec 2012 */ | ||
| + | case ' | ||
| + | if (!str_cmp(word, | ||
| + | { | ||
| + | PROG_LIST *pAprog; | ||
| + | const char *word; | ||
| + | int trigger = 0; | ||
| + | |||
| + | pAprog | ||
| + | word = fread_word( fp ); | ||
| + | if ( (trigger = flag_lookup( word, aprog_flags )) == NO_FLAG ) | ||
| + | { | ||
| + | bugf(" | ||
| + | exit(1); | ||
| + | } | ||
| + | SET_BIT(pArea-> | ||
| + | pAprog-> | ||
| + | pAprog-> | ||
| + | pAprog-> | ||
| + | pAprog-> | ||
| + | pArea-> | ||
| + | } | ||
| + | break; | ||
| + | case ' | ||
| + | KEY(" | ||
| + | KEY(" | ||
| + | KEY(" | ||
| + | case ' | ||
| + | SKEY( " | ||
| + | if ( !str_cmp(word, | ||
| + | { | ||
| + | SET_BIT(pArea-> | ||
| + | break; | ||
| + | } | ||
| + | if ( !str_cmp(word, | ||
| + | { | ||
| + | SET_BIT(pArea-> | ||
| + | break; | ||
| + | } | ||
| + | SKEY( " | ||
| + | break; | ||
| + | case ' | ||
| + | if ( !str_cmp(word, | ||
| + | SET_BIT(pArea-> | ||
| + | break; | ||
| + | case ' | ||
| + | KEY( " | ||
| + | if ( !str_cmp(word, | ||
| + | { | ||
| + | SET_BIT(pArea-> | ||
| + | break; | ||
| + | } | ||
| + | break; | ||
| + | case ' | ||
| + | KEY(" | ||
| + | case ' | ||
| + | if ( !str_cmp( word, " | ||
| + | { | ||
| + | pArea-> | ||
| + | pArea-> | ||
| + | } | ||
| + | break; | ||
| + | case ' | ||
| + | if ( !str_cmp( word, " | ||
| + | { | ||
| + | fMatch = TRUE; | ||
| + | if ( area_first == NULL ) | ||
| + | area_first = pArea; | ||
| + | if ( area_last | ||
| + | area_last-> | ||
| + | |||
| + | area_last | ||
| + | pArea-> | ||
| + | current_area = pArea; | ||
| + | top_area++; | ||
| + | |||
| + | return; | ||
| + | } | ||
| + | break; | ||
| + | case ' | ||
| + | SKEY( " | ||
| + | break; | ||
| + | case ' | ||
| + | SKEY( " | ||
| + | break; | ||
| + | } | ||
| + | |||
| + | if ( !fMatch ) | ||
| + | { | ||
| + | // no nothing but avoid warning | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Example new loading code: ===== | ||
| + | |||
| + | <code C> | ||
| + | LLtbl area; | ||
| + | LLtbl_load( LS, &area, " | ||
| + | int file_version = LLtbl_get_kv_int( LS, &area, " | ||
| + | |||
| + | LLtbl clones; | ||
| + | LLtbl_get_kv_tbl( LS, &area, " | ||
| + | ind=0; | ||
| + | while ( LLtbl_i_exists( LS, & | ||
| + | { | ||
| + | pArea-> | ||
| + | } | ||
| + | LLtbl_release( LS, & | ||
| + | |||
| + | pArea-> | ||
| + | pArea-> | ||
| + | pArea-> | ||
| + | pArea-> | ||
| + | pArea-> | ||
| + | pArea-> | ||
| + | pArea-> | ||
| + | pArea-> | ||
| + | pArea-> | ||
| + | pArea-> | ||
| + | pArea-> | ||
| + | |||
| + | LLtbl aflag; | ||
| + | LLtbl_get_kv_tbl( LS, &area, " | ||
| + | ind=0; | ||
| + | { | ||
| + | const char *flag=LLtbl_get_iv_str( LS, &aflag, ind); | ||
| + | int bit=flag_lookup( flag, area_flags); | ||
| + | if ( bit == NO_FLAG ) | ||
| + | { | ||
| + | bugf(" | ||
| + | exit(1); | ||
| + | } | ||
| + | SET_BIT( pArea-> | ||
| + | free_string(flag); | ||
| + | } | ||
| + | LLtbl_release( LS, & | ||
| + | |||
| + | LLtbl atrigs; | ||
| + | LLtbl_get_kv_tbl( LS, &area, " | ||
| + | ind=0; | ||
| + | while ( LLtbl_i_exists( LS, & | ||
| + | { | ||
| + | LLtbl atrig; | ||
| + | LLtbl_get_iv_tbl( LS, & | ||
| + | |||
| + | PROG_LIST *pAprog = alloc_ATRIG(); | ||
| + | const char *trigtype=LLtbl_get_kv_str( LS, &atrig, " | ||
| + | int trigger; | ||
| + | if ( (trigger = flag_lookup( trigtype, aprog_flags)) == NO_FLAG ) | ||
| + | { | ||
| + | bugf(" | ||
| + | exit(1); | ||
| + | } | ||
| + | free_string(trigtype); | ||
| + | |||
| + | SET_BIT(pArea-> | ||
| + | pAprog-> | ||
| + | pAprog-> | ||
| + | pAprog-> | ||
| + | |||
| + | LLtbl_release(LS, | ||
| + | } | ||
| + | LLtbl_release( LS, & | ||
| + | |||
| + | LLtbl_release( LS, &area); | ||
| </ | </ | ||
vodur/luaafile.1446359564.txt.gz · Last modified: 2015/11/01 06:32 by vodur