From: kainazzzo Date: Tue, 14 Jun 2005 03:14:35 +0000 (+0000) Subject: Added everything necessary to save overtop of the old dragon when someone beats the... X-Git-Url: https://jfr.im/git/irc/gameservirc.git/commitdiff_plain/8e8005496ea89dc8d8c7ffb12c76836a4de701a4?hp=451df086ac3cadf256173808e1ee8861bdf7611f Added everything necessary to save overtop of the old dragon when someone beats the original git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@327 bc333340-6410-0410-a689-9d09f3c113fa --- diff --git a/gameserv/config.cpp b/gameserv/config.cpp index ec3605e..c9f7230 100644 --- a/gameserv/config.cpp +++ b/gameserv/config.cpp @@ -45,6 +45,8 @@ char *remoteport; // Port to connect to on remoteserver char *remotepass; // Password for the server link char *playerdata; // File to store player data in +char *dragondata; // File to store current dragon data in +char *masterdata; // File to store the master data in char *newsdata; // File to store news data in char *pidfile; // Process ID file @@ -74,6 +76,10 @@ void unload_config_file() delete [] remotepass; if (playerdata) delete [] playerdata; + if (dragondata) + delete [] dragondata; + if (masterdata) + delete [] masterdata; if (adminpass) delete [] adminpass; if (welcomemsg) @@ -96,7 +102,7 @@ int load_config_file(char *config) { char *buf, *directive, *value; - #define numdirectives 28 + #define numdirectives 30 unload_config_file(); @@ -149,6 +155,9 @@ int load_config_file(char *config) "GameServ should identify with NickServ"; directives[26].desc = "NSNAME - Your network's NickServ nickname"; directives[27].desc = "NSPASS - GameServ's NickServ Password"; + directives[28].desc = "DRAGONDATA - File to store the current "\ + "dragon's stats in"; + directives[29].desc = "MASTERDATA - File to store the level master stats in"; configflags = 0; @@ -378,6 +387,20 @@ int load_config_file(char *config) strcpy(nspass, value); directives[27].done = true; } + else if (stricmp(directive, "DRAGONDATA") == 0) + { + value = strtok(NULL, ""); + dragondata = new char[strlen(value) + 1]; + strcpy(dragondata, value); + directives[28].done = true; + } + else if (stricmp(directive, "MASTERDATA") == 0) + { + value = strtok(NULL, ""); + masterdata = new char[strlen(value) + 1]; + strcpy(masterdata, value); + directives[29].done = true; + } else if (stricmp(directive, "WELCOMEMSG") == 0) { // This directive is optional diff --git a/gameserv/do_attack.cpp b/gameserv/do_attack.cpp index 1f53b24..4f1ce64 100644 --- a/gameserv/do_attack.cpp +++ b/gameserv/do_attack.cpp @@ -52,7 +52,8 @@ void do_attack(char *u) { // Player's Hit hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) + - (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2)); + (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2)) - + fight->defense; // Opponent's Hit mhit = (fight->strength / 2) + @@ -95,13 +96,22 @@ void do_attack(char *u) notice(s_GameServ, u, "You recieve %d experience and %d gold!", fight->exp, fight->gold); - if (dragon_fight(ni)) - { - addNews(todaysnews, "%s is a true warrior! %s has beaten %s!!", - ni->stats->name.c_str(), ni->stats->name.c_str(), - ni->stats->master->name.c_str()); - ni->stats->master = NULL; // Don't progress in levels - } + if (dragon_fight(ni)) + { + addNews(todaysnews, "%s is a true warrior! %s has beaten %s!!"\ + " %s is now watching over the Dragon's lair!", + ni->stats->name.c_str(), ni->stats->name.c_str(), + ni->stats->fight->name.c_str(), ni->stats->name.c_str()); + dragon.name = "DRAGON-" + ni->stats->name; + dragon.weapon = weapons[ni->stats->weapon]; + dragon.strength = ni->stats->strength + webonus[ni->stats->weapon]; + dragon.defense = ni->stats->defense + arbonus[ni->stats->armor]; + dragon.hp = ni->stats->maxhp; + dragon.maxhp = ni->stats->maxhp; + save_dragon(); + clearDragonFight(ni->stats); + reset(ni->stats); + } // If your new experience (or gold) will be greater than 2 billion, // then set your exp to 2bil. (2 billion max)... otherwise add them. diff --git a/gameserv/extern.h b/gameserv/extern.h index 576be89..00d1d78 100644 --- a/gameserv/extern.h +++ b/gameserv/extern.h @@ -52,6 +52,7 @@ E char *pidfile; E char *newsdata; E char *nsname; E char *nspass; +E Monster dragon; #if defined(P10) E char *gsnum; @@ -62,6 +63,8 @@ E char *remoteserver; E char *remoteport; E char *remotepass; E char *playerdata; +E char *dragondata; +E char *masterdata; E char *logfile; E char *adminpass; E char *VERSION; @@ -207,6 +210,8 @@ E void showinventory(aClient *from, aClient *to = NULL); E int save_gs_dbase(); E int load_gs_dbase(); +E int load_dragon(); +E int save_dragon(); // Log File Stuff E void log(const char *fmt, ...); diff --git a/gameserv/flags.h b/gameserv/flags.h index 833fbd6..42d4217 100644 --- a/gameserv/flags.h +++ b/gameserv/flags.h @@ -38,6 +38,7 @@ #define FLAG_ALIVE 0x00000002 #define FLAG_YOURTURN 0x00000004 #define FLAG_WONGAME 0x00000008 +#define FLAG_DRAGONFIGHT 0x00000010 // Config File flags #define CFLAG_LISTENONCF 0x00000001 @@ -106,4 +107,8 @@ #define setWonGame(x) ((x)->addFlag(FLAG_WONGAME)) #define clearWonGame(x) ((x)->remFlag(FLAG_WONGAME)) +#define isDragonFight(x) ((x)->getFlags() & FLAG_DRAGONFIGHT) +#define setDragonFight(x) ((x)->addFlag(FLAG_DRAGONFIGHT)) +#define clearDragonFight(x) ((x)->remFlag(FLAG_DRAGONFIGHT)) + #endif diff --git a/gameserv/gameserv.cpp b/gameserv/gameserv.cpp index 523431f..8375922 100644 --- a/gameserv/gameserv.cpp +++ b/gameserv/gameserv.cpp @@ -24,12 +24,14 @@ using std::ios; #endif - +Monster dragon; // The current dragon Level levels[LEVELS]; // The newest way to store monsters // Database functions int save_gs_dbase(); int load_gs_dbase(); +int load_dragon(); +int save_dragon(); // String functions #ifndef HAVE_STRTOK @@ -1383,22 +1385,22 @@ void do_stats(char *u) bool load_masters() { - ifstream infile("data/masters.dat"); + ifstream infile(masterdata); char *buf; int l = 0; buf = new char[1024]; if (infile.fail()) { - log("Error opening data/masters.dat"); + log("Error opening %s", masterdata); return false; } #ifdef DEBUGMODE - log("Loading masters from data/masters.dat"); + log("Loading masters from %s", masterdata); #endif - for (l = 0; l < LEVELS; l++) + for (l = 0; l < LEVELS - 1; l++) { infile.getline(buf, 1024, '\n'); @@ -1436,7 +1438,7 @@ bool load_masters() delete []buf; - if (l < LEVELS) // We didn't load a master for every level - check data/masters.dat + if (l < LEVELS - 1) // We didn't load a master for every level - check data/masters.dat return false; else return true; @@ -1589,7 +1591,7 @@ bool dragon_fight(aClient *user) if (!is_playing(user)) return false; else - return (user->stats->level == LEVELS && master_fight(user)); + return (isDragonFight(user->stats)); } void do_fight(char *u) { @@ -2164,13 +2166,75 @@ outfile.close(); return 1; } +int load_dragon() +{ + ifstream infile; + char *buf; + + infile.open(dragondata); + + if (infile.fail()) + { + infile.clear(); + log ("Error opening %s. Trying initialdragon.dat", dragondata); + infile.open("data/initialdragon.dat"); + if (infile.fail()) + { + log ("Error opening data/initialdragon.dat"); + return 0; + } + } + + buf = new char[1024]; + + infile.getline(buf, 1024, '\n'); + infile.close(); // Done with the file... we have what we want + + dragon.name = strtok(buf, "~"); + dragon.weapon = strtok(NULL, "~"); + dragon.gold = 0; + dragon.exp = 0; + dragon.strength = stringtoint(strtok(NULL, "~")); + dragon.hp = stringtoint(strtok(NULL, "~")); + dragon.defense = stringtoint(strtok(NULL, "~")); + dragon.death = strtok(NULL, ""); + + log ("loaded dragon: %s", dragon.name.c_str()); + + delete []buf; + +return save_dragon(); // Save the dragon file and return the status code :) +} + +int save_dragon() +{ + ofstream outfile; + + outfile.open(dragondata); + + if (outfile.fail()) + { + log ("Error opening %s. Exiting.", dragondata); + return 0; + } + + outfile << dragon.name.c_str() << '~' << dragon.weapon.c_str() << '~' + << dragon.strength << '~' << dragon.hp << '~' + << dragon.defense << '~' << dragon.death.c_str() << "\n^" + << endl; + +outfile.close(); + +return 1; +} + int load_gs_dbase() { ifstream infile; aClient *temp; Player *p; char *tempname, *buf, *password; - buf = new char[1023]; + buf = new char[1024]; infile.open(playerdata); @@ -2910,7 +2974,9 @@ void do_dragon(char *u) notice(s_GameServ, u, "Just then you notice the eye begin to "\ "glare orange! The tooth is moving... but it is still too "\ "dark for you to make out.... THE DRAGON! You see it!"); - see_master(u); + p->fight = new Monster(dragon); + setDragonFight(p); + display_monster(u); } void do_master(char *u) diff --git a/gameserv/player.cpp b/gameserv/player.cpp index df3aaed..372ebe1 100644 --- a/gameserv/player.cpp +++ b/gameserv/player.cpp @@ -153,6 +153,7 @@ monster_::monster_() weapon.erase(); death.erase(); strength = 0; + defense = 0; exp = 0; gold = 0; maxhp = hp = 0; @@ -164,6 +165,7 @@ monster_::monster_(monster_ *m) weapon = m->weapon; death = m->death; strength = m->strength; + defense = m->defense; maxhp = m->maxhp; hp = m->hp; gold = m->gold; @@ -176,6 +178,7 @@ monster_::monster_(monster_ &m) weapon = m.weapon; death = m.death; strength = m.strength; + defense = m.defense; maxhp = m.maxhp; hp = m.hp; gold = m.gold; diff --git a/gameserv/player.h b/gameserv/player.h index 0425406..48fb67e 100644 --- a/gameserv/player.h +++ b/gameserv/player.h @@ -61,14 +61,15 @@ struct monster_ { monster_(monster_ *); monster_(monster_ &); ~monster_(); - string name; // The monster's name - string weapon; // A name for their weapon. Doesn't have to be in weapons[] - int strength; // Their strength - int gold; // The gold you get when you kill them - int exp; // The experience you get when you kill them - int hp; // Their remaining hitpoints - int maxhp; // Their max hitpoints - string death; // What is said when they die + string name; // The monster's name + string weapon; // A name for their weapon. Doesn't have to be in weapons[] + int strength; // Their strength + int gold; // The gold you get when you kill them + int exp; // The experience you get when you kill them + int hp; // Their remaining hitpoints + int maxhp; // Their max hitpoints + int defense; // Only used seldomly + string death; // What is said when they die }; #endif diff --git a/gameserv/tcpclient.cpp b/gameserv/tcpclient.cpp index fa73761..dccf1c9 100644 --- a/gameserv/tcpclient.cpp +++ b/gameserv/tcpclient.cpp @@ -117,6 +117,12 @@ int main(int argc, char *argv[]) goto end; } + if (!load_dragon()) + { + log("Error loading dragon"); + goto end; + } + if (load_levels() == false) { log("Error loading levels"); @@ -584,6 +590,7 @@ int main(int argc, char *argv[]) end: save_gs_dbase(); + save_dragon(); saveNews(newsdata, todaysnews); delete_monsters();