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:37] – vodur | vodur:luaafile [2015/11/11 04:40] (current) – vodur | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== 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> | <code C> | ||
LStbl area; | LStbl area; | ||
Line 68: | Line 124: | ||
LStbl_release( LS, &area ); | LStbl_release( LS, &area ); | ||
</ | </ | ||
+ | |||
+ | ===== Example old format (Bastion) ===== | ||
< | < | ||
Line 86: | Line 144: | ||
End | End | ||
</ | </ | ||
+ | |||
+ | ===== Example new format (Bastion) ===== | ||
<code lua> | <code lua> | ||
Line 119: | Line 179: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ===== Example old format (Remort 6) ===== | ||
< | < | ||
Line 139: | Line 201: | ||
End | End | ||
</ | </ | ||
+ | |||
+ | ===== Example new format (Remort 6) ===== | ||
<code lua> | <code lua> | ||
Line 168: | Line 232: | ||
}, | }, | ||
} | } | ||
+ | </ | ||
+ | |||
+ | ===== 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.1446359826.txt.gz · Last modified: 2015/11/01 06:37 by vodur