void init_socials() { // create the social table social_table = newHashtable(); // open up the storage set STORAGE_SET *set = storage_read(SOCIALS_FILE); STORAGE_SET_LIST *list = read_list(set, "socials"); STORAGE_SET *social = NULL; // parse all of the socials while( (social = storage_list_next(list)) != NULL) add_social(socialRead(social)); // close the storage set storage_close(set); // add all of the socials to the command table HASH_ITERATOR *hash_i = newHashIterator(social_table); const char *cmd = NULL; SOCIAL_DATA *data = NULL; ITERATE_HASH(cmd, data, hash_i) { add_cmd(cmd, NULL, cmd_social, "player", FALSE); if(data->min_pos == POS_SITTING) add_cmd_check(cmd, chk_conscious); else if(data->min_pos == POS_STANDING) add_cmd_check(cmd, chk_can_move); else if(data->max_pos == POS_STANDING) add_cmd_check(cmd, chk_grounded); } deleteHashIterator(hash_i);
void fread_social( FILE *fp ) { const char *word; SOC_INDEX_DATA *social; bool fMatch; int stat; social = new_social( ); for ( ; ; ) { GET_TOKEN( fp, word, "End" ); fMatch = FALSE; switch ( UPPER( word[0] ) ) { case '*': fMatch = TRUE; fread_to_eol( fp ); break; case 'C': SKEY( "CharNoArg", social->char_no_arg ); SKEY( "CharFound", social->char_found ); SKEY( "CharAuto", social->char_auto ); break; case 'E': if ( !str_cmp( word, "End" ) ) { if ( !social->name ) { bugf( "Fread_social: Name not found" ); free_social( social ); return; } if ( !social->char_no_arg ) { bugf( "Fread_social: CharNoArg not found" ); free_social( social ); return; } add_social( social ); return; } break; case 'N': SKEY( "Name", social->name ); break; case 'O': SKEY( "OthersNoArg", social->others_no_arg ); SKEY( "OthersFound", social->others_found ); SKEY( "OthersAuto", social->others_auto ); break; case 'V': SKEY( "VictFound", social->vict_found ); break; } if ( !fMatch ) { bugf( "Fread_social: no match: %s. Skipping to next line.", word ); fread_to_eol( fp ); } } return; }
void fread_social( FILE * fp ) { char buf[MAX_STRING_LENGTH]; const char *word; bool fMatch; SOCIALTYPE *social; CREATE( social, SOCIALTYPE, 1 ); for( ;; ) { word = feof( fp ) ? "End" : fread_word( fp ); fMatch = FALSE; switch ( UPPER( word[0] ) ) { case '*': fMatch = TRUE; fread_to_eol( fp ); break; case 'C': KEY( "CharNoArg", social->char_no_arg, fread_string_nohash( fp ) ); KEY( "CharFound", social->char_found, fread_string_nohash( fp ) ); KEY( "CharAuto", social->char_auto, fread_string_nohash( fp ) ); break; case 'E': if( !str_cmp( word, "End" ) ) { if( !social->name ) { bug( "Fread_social: Name not found", 0 ); free_social( social ); return; } if( !social->char_no_arg ) { bug( "Fread_social: CharNoArg not found", 0 ); free_social( social ); return; } add_social( social ); return; } break; case 'N': KEY( "Name", social->name, fread_string_nohash( fp ) ); break; case 'O': KEY( "OthersNoArg", social->others_no_arg, fread_string_nohash( fp ) ); KEY( "OthersFound", social->others_found, fread_string_nohash( fp ) ); KEY( "OthersAuto", social->others_auto, fread_string_nohash( fp ) ); break; case 'V': KEY( "VictFound", social->vict_found, fread_string_nohash( fp ) ); break; } if( !fMatch ) { sprintf( buf, "Fread_social: no match: %s", word ); bug( buf, 0 ); } } }