//-------------------------------------------------------------------------------------------- mad_t * action_check_copy_vfs( mad_t * pmad, const char* loadname ) { /// @details ZZ@> This function copies a model's actions vfs_FILE *fileread; int actiona, actionb; char szOne[16] = EMPTY_CSTR; char szTwo[16] = EMPTY_CSTR; if ( NULL == pmad ) return pmad; fileread = vfs_openRead( loadname ); if ( NULL == fileread ) return pmad; while ( goto_colon( NULL, fileread, btrue ) ) { fget_string( fileread, szOne, SDL_arraysize( szOne ) ); actiona = action_which( szOne[0] ); fget_string( fileread, szTwo, SDL_arraysize( szTwo ) ); actionb = action_which( szTwo[0] ); action_copy_correct( pmad, actiona + 0, actionb + 0 ); action_copy_correct( pmad, actiona + 1, actionb + 1 ); action_copy_correct( pmad, actiona + 2, actionb + 2 ); action_copy_correct( pmad, actiona + 3, actionb + 3 ); } vfs_close( fileread ); return pmad; }
/** * @brief * Construct this text input file with the given file name. * @param fileName * the file name * @remark * The text input file is in its initial state w.r.t. the given file name. * That is, the current extended character is _Traits::startOfInput() and * advance() must be called to advance to the first extend character. See * advance() for more information. */ TextInputFile(const string& fileName) : TextFile<_Traits>(fileName, TextFile<_Traits>::Mode::Read), _file(nullptr), _current(Traits::startOfInput()) { _file = vfs_openRead(fileName); }
//-------------------------------------------------------------------------------------------- void load_action_names_vfs( const char* loadname ) { /// @details ZZ@> This function loads all of the 2 letter action names vfs_FILE* fileread; int cnt; char first = CSTR_END, second = CSTR_END; STRING comment; bool_t found; fileread = vfs_openRead( loadname ); if ( !fileread ) return; for ( cnt = 0; cnt < ACTION_COUNT; cnt++ ) { comment[0] = CSTR_END; found = bfalse; if ( goto_colon( NULL, fileread, bfalse ) ) { if ( vfs_scanf( fileread, " %c%c %s", &first, &second, &comment ) >= 2 ) { found = btrue; } } if ( found ) { cActionName[cnt][0] = first; cActionName[cnt][1] = second; cActionComent[cnt][0] = CSTR_END; if ( VALID_CSTR( comment ) ) { strncpy( cActionComent[cnt], comment, SDL_arraysize( cActionComent[cnt] ) ); cActionComent[cnt][255] = CSTR_END; } } else { cActionName[cnt][0] = CSTR_END; cActionComent[cnt][0] = CSTR_END; } } vfs_close( fileread ); }
//-------------------------------------------------------------------------------------------- egoboo_rv init_random_treasure_tables_vfs( const char* filepath ) { //ZF> This loads all the treasure tables from randomtreasure.txt vfs_FILE *fileread; int num_table; // try to open the file fileread = vfs_openRead( filepath ); if ( NULL == fileread ) { log_warning( "Could not load random treasure tables! (%s)\n", filepath ); return rv_error; } //Load each treasure table num_table = 0; while ( goto_colon( NULL, fileread, btrue ) ) { //Load the name of this table STRING szTemp; fget_string( fileread, szTemp, SDL_arraysize( szTemp ) ); //Stop here if we are already full if ( num_table >= MAX_TABLES ) { log_warning( "Cannot load random treasure table: %s (We only support up to %i tables, consider increasing MAX_TABLES) \n", szTemp, MAX_TABLES ); break; } snprintf( treasureTableList[num_table].table_name, SDL_arraysize( treasureTableList[num_table].table_name ), "%%%s", szTemp ); //Load all objects in this treasure table treasureTableList[num_table].size = 0; load_one_treasure_table_vfs( fileread, &treasureTableList[num_table] ); num_table++; } //Finished vfs_close( fileread ); return rv_success; }
//-------------------------------------------------------------------------------------------- pip_t * load_one_pip_file_vfs( const char *szLoadName, pip_t * ppip ) { /// @details ZZ@> This function loads a particle template, returning bfalse if the file wasn't /// found vfs_FILE* fileread; IDSZ idsz; char cTmp; fileread = vfs_openRead( szLoadName ); if ( NULL == fileread ) { return NULL; } pip_init( ppip ); // set up the EGO_PROFILE_STUFF strncpy( ppip->name, szLoadName, SDL_arraysize( ppip->name ) ); ppip->loaded = btrue; // read the 1 line comment at the top of the file vfs_gets( ppip->comment, SDL_arraysize( ppip->comment ) - 1, fileread ); // rewind the file vfs_seek( fileread, 0 ); // General data ppip->force = fget_next_bool( fileread ); cTmp = fget_next_char( fileread ); if ( 'L' == toupper( cTmp ) ) ppip->type = SPRITE_LIGHT; else if ( 'S' == toupper( cTmp ) ) ppip->type = SPRITE_SOLID; else if ( 'T' == toupper( cTmp ) ) ppip->type = SPRITE_ALPHA; ppip->image_base = fget_next_int( fileread ); ppip->numframes = fget_next_int( fileread ); ppip->image_add.base = fget_next_int( fileread ); ppip->image_add.rand = fget_next_int( fileread ); ppip->rotate_pair.base = fget_next_int( fileread ); ppip->rotate_pair.rand = fget_next_int( fileread ); ppip->rotate_add = fget_next_int( fileread ); ppip->size_base = fget_next_int( fileread ); ppip->size_add = fget_next_int( fileread ); ppip->spdlimit = fget_next_float( fileread ); ppip->facingadd = fget_next_int( fileread ); // override the base rotation if ( ppip->image_base < 256 && prt_u != prt_direction[ ppip->image_base ] ) { ppip->rotate_pair.base = prt_direction[ ppip->image_base ]; }; // Ending conditions ppip->end_water = fget_next_bool( fileread ); ppip->end_bump = fget_next_bool( fileread ); ppip->end_ground = fget_next_bool( fileread ); ppip->end_lastframe = fget_next_bool( fileread ); ppip->end_time = fget_next_int( fileread ); // Collision data ppip->dampen = fget_next_float( fileread ); ppip->bump_money = fget_next_int( fileread ); ppip->bump_size = fget_next_int( fileread ); ppip->bump_height = fget_next_int( fileread ); fget_next_range( fileread, &( ppip->damage ) ); ppip->damagetype = fget_next_damage_type( fileread ); // Lighting data cTmp = fget_next_char( fileread ); if ( 'T' == toupper( cTmp ) ) ppip->dynalight.mode = DYNA_MODE_ON; else if ( 'L' == toupper( cTmp ) ) ppip->dynalight.mode = DYNA_MODE_LOCAL; else ppip->dynalight.mode = DYNA_MODE_OFF; ppip->dynalight.level = fget_next_float( fileread ); ppip->dynalight.falloff = fget_next_int( fileread ); // Initial spawning of this particle ppip->facing_pair.base = fget_next_int( fileread ); ppip->facing_pair.rand = fget_next_int( fileread ); ppip->spacing_hrz_pair.base = fget_next_int( fileread ); ppip->spacing_hrz_pair.rand = fget_next_int( fileread ); ppip->spacing_vrt_pair.base = fget_next_int( fileread ); ppip->spacing_vrt_pair.rand = fget_next_int( fileread ); ppip->vel_hrz_pair.base = fget_next_int( fileread ); ppip->vel_hrz_pair.rand = fget_next_int( fileread ); ppip->vel_vrt_pair.base = fget_next_int( fileread ); ppip->vel_vrt_pair.rand = fget_next_int( fileread ); // Continuous spawning of other particles ppip->contspawn_delay = fget_next_int( fileread ); ppip->contspawn_amount = fget_next_int( fileread ); ppip->contspawn_facingadd = fget_next_int( fileread ); ppip->contspawn_lpip = fget_next_int( fileread ); // End spawning of other particles ppip->endspawn_amount = fget_next_int( fileread ); ppip->endspawn_facingadd = fget_next_int( fileread ); ppip->endspawn_lpip = fget_next_int( fileread ); // Bump spawning of attached particles ppip->bumpspawn_amount = fget_next_int( fileread ); ppip->bumpspawn_lpip = fget_next_int( fileread ); // Random stuff !!!BAD!!! Not complete ppip->daze_time = fget_next_int( fileread ); ppip->grog_time = fget_next_int( fileread ); ppip->spawnenchant = fget_next_bool( fileread ); ppip->cause_roll = fget_next_bool( fileread ); // !!Cause roll ppip->cause_pancake = fget_next_bool( fileread ); ppip->needtarget = fget_next_bool( fileread ); ppip->targetcaster = fget_next_bool( fileread ); ppip->startontarget = fget_next_bool( fileread ); ppip->onlydamagefriendly = fget_next_bool( fileread ); ppip->soundspawn = fget_next_int( fileread ); ppip->end_sound = fget_next_int( fileread ); ppip->friendlyfire = fget_next_bool( fileread ); ppip->hateonly = fget_next_bool( fileread ); ppip->newtargetonspawn = fget_next_bool( fileread ); ppip->targetangle = fget_next_int( fileread ) >> 1; ppip->homing = fget_next_bool( fileread ); ppip->homingfriction = fget_next_float( fileread ); ppip->homingaccel = fget_next_float( fileread ); ppip->rotatetoface = fget_next_bool( fileread ); goto_colon( NULL, fileread, bfalse ); // !!Respawn on hit is unused ppip->manadrain = fget_next_int( fileread ) * 256; ppip->lifedrain = fget_next_int( fileread ) * 256; // assume default end_wall ppip->end_wall = ppip->end_ground; // assume default damfx if ( ppip->homing ) ppip->damfx = DAMFX_NONE; // Read expansions while ( goto_colon( NULL, fileread, btrue ) ) { idsz = fget_idsz( fileread ); if ( idsz == MAKE_IDSZ( 'T', 'U', 'R', 'N' ) ) SET_BIT( ppip->damfx, DAMFX_NONE ); //ZF> This line doesnt do anything? else if ( idsz == MAKE_IDSZ( 'A', 'R', 'M', 'O' ) ) SET_BIT( ppip->damfx, DAMFX_ARMO ); else if ( idsz == MAKE_IDSZ( 'B', 'L', 'O', 'C' ) ) SET_BIT( ppip->damfx, DAMFX_NBLOC ); else if ( idsz == MAKE_IDSZ( 'A', 'R', 'R', 'O' ) ) SET_BIT( ppip->damfx, DAMFX_ARRO ); else if ( idsz == MAKE_IDSZ( 'T', 'I', 'M', 'E' ) ) SET_BIT( ppip->damfx, DAMFX_TIME ); else if ( idsz == MAKE_IDSZ( 'Z', 'S', 'P', 'D' ) ) ppip->zaimspd = fget_float( fileread ); else if ( idsz == MAKE_IDSZ( 'F', 'S', 'N', 'D' ) ) ppip->end_sound_floor = fget_int( fileread ); else if ( idsz == MAKE_IDSZ( 'W', 'S', 'N', 'D' ) ) ppip->end_sound_wall = fget_int( fileread ); else if ( idsz == MAKE_IDSZ( 'W', 'E', 'N', 'D' ) ) ppip->end_wall = ( 0 != fget_int( fileread ) ); else if ( idsz == MAKE_IDSZ( 'P', 'U', 'S', 'H' ) ) ppip->allowpush = ( 0 != fget_int( fileread ) ); else if ( idsz == MAKE_IDSZ( 'D', 'L', 'E', 'V' ) ) ppip->dynalight.level_add = fget_int( fileread ) / 1000.0f; else if ( idsz == MAKE_IDSZ( 'D', 'R', 'A', 'D' ) ) ppip->dynalight.falloff_add = fget_int( fileread ) / 1000.0f; else if ( idsz == MAKE_IDSZ( 'I', 'D', 'A', 'M' ) ) ppip->intdamagebonus = ( 0 != fget_int( fileread ) ); else if ( idsz == MAKE_IDSZ( 'W', 'D', 'A', 'M' ) ) ppip->wisdamagebonus = ( 0 != fget_int( fileread ) ); else if ( idsz == MAKE_IDSZ( 'O', 'R', 'N', 'T' ) ) { char cTmp = fget_first_letter( fileread ); switch ( toupper( cTmp ) ) { case 'X': ppip->orientation = ORIENTATION_X; break; // put particle up along the world or body-fixed x-axis case 'Y': ppip->orientation = ORIENTATION_Y; break; // put particle up along the world or body-fixed y-axis case 'Z': ppip->orientation = ORIENTATION_Z; break; // put particle up along the world or body-fixed z-axis case 'V': ppip->orientation = ORIENTATION_V; break; // vertical, like a candle case 'H': ppip->orientation = ORIENTATION_H; break; // horizontal, like a plate case 'B': ppip->orientation = ORIENTATION_B; break; // billboard } } } vfs_close( fileread ); return ppip; }
//-------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------- mod_file_t * module_load_info_vfs( const char * szLoadName, mod_file_t * pmod ) { /// @details BB@> this function actually reads in the module data vfs_FILE * fileread; int cnt; char cTmp; // clear all the module info if ( NULL == pmod ) return NULL; memset( pmod, 0, sizeof( *pmod ) ); // see if we can open the file fileread = vfs_openRead( szLoadName ); if ( NULL == fileread ) return NULL; // Read basic data fget_next_name( fileread, pmod->longname, sizeof( pmod->longname ) ); fget_next_string( fileread, pmod->reference, SDL_arraysize( pmod->reference ) ); pmod->unlockquest.id = fget_next_idsz( fileread ); pmod->unlockquest.level = fget_int( fileread ); pmod->importamount = fget_next_int( fileread ); pmod->allowexport = fget_next_bool( fileread ); pmod->minplayers = fget_next_int( fileread ); pmod->maxplayers = fget_next_int( fileread ); cTmp = fget_next_char( fileread ); if ( 'T' == toupper( cTmp ) ) pmod->respawnvalid = btrue; if ( 'A' == toupper( cTmp ) ) pmod->respawnvalid = RESPAWN_ANYTIME; fget_next_char( fileread ); pmod->rtscontrol = bfalse; //< depecrated, not in use fget_next_string( fileread, pmod->rank, SDL_arraysize( pmod->rank ) ); str_trim( pmod->rank ); // convert the special ranks of "unranked" or "-" ("rank 0") to an empty string if ( 0 == strncmp( pmod->rank, "-", RANKSIZE ) ) { pmod->rank[0] = CSTR_END; } else if ( 'U' == toupper( pmod->rank[0] ) ) { pmod->rank[0] = CSTR_END; } pmod->rank[RANKSIZE-1] = CSTR_END; // Read the summary for ( cnt = 0; cnt < SUMMARYLINES; cnt++ ) { // load the string fget_next_string( fileread, pmod->summary[cnt], SDL_arraysize( pmod->summary[cnt] ) ); pmod->summary[cnt][SUMMARYSIZE-1] = CSTR_END; // remove the '_' characters str_decode( pmod->summary[cnt], SDL_arraysize( pmod->summary[cnt] ), pmod->summary[cnt] ); } // Assume default module type as a sidequest pmod->moduletype = FILTER_SIDE; // Read expansions while ( goto_colon( NULL, fileread, btrue ) ) { IDSZ idsz = fget_idsz( fileread ); // Read module type if ( idsz == MAKE_IDSZ( 'T', 'Y', 'P', 'E' ) ) { // grab the expansion value cTmp = fget_first_letter( fileread ); // parse the expansion value if ( 'M' == toupper( cTmp ) ) pmod->moduletype = FILTER_MAIN; else if ( 'S' == toupper( cTmp ) ) pmod->moduletype = FILTER_SIDE; else if ( 'T' == toupper( cTmp ) ) pmod->moduletype = FILTER_TOWN; else if ( 'F' == toupper( cTmp ) ) pmod->moduletype = FILTER_FUN; else if ( 'S' == toupper( cTmp ) ) pmod->moduletype = FILTER_STARTER; } else if ( idsz == MAKE_IDSZ( 'B', 'E', 'A', 'T' ) ) { pmod->beaten = btrue; } } vfs_close( fileread ); return pmod; }
//-------------------------------------------------------------------------------------------- int module_has_idsz_vfs( const char *szModName, IDSZ idsz, size_t buffer_len, char * buffer ) { /// @details ZZ@> This function returns btrue if the named module has the required IDSZ vfs_FILE *fileread; STRING newloadname; Uint32 newidsz; int foundidsz; int cnt; if ( idsz == IDSZ_NONE ) return btrue; if ( 0 == strcmp( szModName, "NONE" ) ) return bfalse; snprintf( newloadname, SDL_arraysize( newloadname ), "mp_modules/%s/gamedat/menu.txt", szModName ); fileread = vfs_openRead( newloadname ); if ( NULL == fileread ) return bfalse; // Read basic data goto_colon( NULL, fileread, bfalse ); // Name of module... Doesn't matter goto_colon( NULL, fileread, bfalse ); // Reference directory... goto_colon( NULL, fileread, bfalse ); // Reference IDSZ... goto_colon( NULL, fileread, bfalse ); // Import... goto_colon( NULL, fileread, bfalse ); // Export... goto_colon( NULL, fileread, bfalse ); // Min players... goto_colon( NULL, fileread, bfalse ); // Max players... goto_colon( NULL, fileread, bfalse ); // Respawn... goto_colon( NULL, fileread, bfalse ); // BAD! NOT USED goto_colon( NULL, fileread, bfalse ); // Rank... // Summary... for ( cnt = 0; cnt < SUMMARYLINES; cnt++ ) { goto_colon( NULL, fileread, bfalse ); } // Now check expansions foundidsz = bfalse; while ( goto_colon( NULL, fileread, btrue ) ) { newidsz = fget_idsz( fileread ); if ( newidsz == idsz ) { foundidsz = btrue; break; } } if ( NULL != buffer ) { if ( buffer_len < 1 ) { /* nothing */ } else if ( 1 == buffer_len ) { buffer[0] = CSTR_END; } else { vfs_gets( buffer, buffer_len, fileread ); } } vfs_close( fileread ); return foundidsz; }