/* ....[@@@..[@@@..............[@.................. MUD++ is a written from ....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and ....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++. ....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing ....[@......[@..[@@@@@..[@@@@@.................. development project. All ................................................ contributions are welcome. ....Copyright(C).1995.Melvin.Smith.............. Enjoy. ------------------------------------------------------------------------------ Melvin Smith (aka Fusion) msmith@hom.net MUD++ development mailing list mudpp@van.ml.org ------------------------------------------------------------------------------ guild.cc */ #include "config.h" #include "string.h" #include "io.h" #include "guild.h" #include "array.h" #include "llist.h" #include "skill.h" #include "spell.h" int Guild::load() { String str; int size; char buf[BUF]; struct GuildSkill sk; struct GuildSpell sp; skills.clr(); spells.clr(); // general data str << GUILD_DIR << name; InputFile inf1( str ); if ( !inf1 ) return -1; readFrom(inf1); inf1.close(); // skill data str.clr(); str << GUILD_DIR << name << ".skill"; InputFile inf2(str); // this file is optional if ( inf2 ) { size = inf2.getnum(); skills.grow(size); while ( *(inf2.getword(buf)) != '#') { sk.skill = lookupSkill( buf ); sk.level = inf2.getnum(); sk.cost = inf2.getnum(); skills.add(sk); } inf2.close(); } // spell data str.clr(); str << GUILD_DIR << name << ".spell"; InputFile inf3(str); // this file is optional if ( inf3 ) { size = inf3.getnum(); spells.grow(size); while ( *(inf3.getword(buf)) != '#') { sp.spell = lookupSpell( buf ); sp.level = inf3.getnum(); sp.cost = inf3.getnum(); spells.add(sp); } inf3.close(); } return 0; } int Guild::readFrom( StaticInput & in ) { char buf[BUF]; in.getstring(buf); description = buf; min_level = in.getnum(); xp_penalty = in.getnum(); return 0; } int Guild::save() { String str; int size; int i; // general data str << GUILD_DIR << name; OutputFile outf1(str.chars()); if ( !outf1 ) return -1; writeTo(outf1); outf1.close(); // skill data str.clr(); str << GUILD_DIR << name << ".skill"; OutputFile outf2( str.chars() ); if ( !outf2 ) return -1; size = skills.length(); outf2 << size << endl; for ( i=0; i < size; i++ ) { outf2 << skills[i].skill->getName() << " " << skills[i].level << " " << skills[i].cost << endl; } outf2 << "#"; outf2.close(); // spell data str.clr(); str << GUILD_DIR << name << ".spell"; OutputFile outf3( str.chars() ); if ( !outf3 ) return -1; size = spells.length(); outf3 << size << endl; for ( i=0; i < size; i++ ) { outf3 << spells[i].spell->getName() << " " << spells[i].level << " " << spells[i].cost << endl; } outf3 << "#"; outf3.close(); return 0; } int Guild::writeTo( Output & out ) const { out << description << "~"<<endl; out << min_level << " " << xp_penalty << " "; return 0; } LList< Guild > guilds; void loadGuilds() { Guild * guild; String str; char buf[BUF]; guilds.destroyList(); str << GUILD_DIR << GUILD_FILE; InputFile inf( str ); if ( !inf ) { Cout << "ERROR: No guild.lst file.\n\r"; exit(1); } while ( *(inf.getword(buf)) != '#' ) { str = buf; guild = new Guild(str); if ( guild->load() == -1) { Cout << "ERROR during loading guild " << str <<endl; exit(1); } guilds.add(guild); } inf.close(); } void saveGuilds() { Guild * guild; String str; str << GUILD_DIR << GUILD_FILE; OutputFile outf( str.chars() ); if ( !outf ) { Cout << "ERROR: Cannot create guild.lst file.\n\r"; exit(1); } for_each( guilds, guild ) { outf << guild->getName() << endl; guild->save(); } outf << '#'; outf.close(); }