/****************************************************************************
* [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame | *
* -----------------------------------------------------------| \\._.// *
* SmaugWiz (C) 1998 by Russ Pillsbury (Windows NT version) | (0...0) *
* -----------------------------------------------------------| ).:.( *
* SMAUG (C) 1994, 1995, 1996 by Derek Snider | {o o} *
* -----------------------------------------------------------| / ' ' \ *
* SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus, |~'~.VxvxV.~'~*
* Scryn, Swordbearer, Rennard, Tricops, and Gorog. | *
* ------------------------------------------------------------------------ *
* Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik Staerfeldt, Tom Madsen, and Katja Nyboe. *
* ------------------------------------------------------------------------ *
* Table load/save Module *
****************************************************************************/
#include "stdafx.h"
#include "smaug.h"
#include "Smaugx.h"
#include "skill.h"
#include "social.h"
#include "objects.h"
#include "rooms.h"
#include "SmaugFiles.h"
#include "character.h"
#include "class.h"
#if defined (KEY)
#undef KEY
#endif
#define KEY(literal,field,value) \
if (!str_cmp (word, literal)) { \
field = value; \
fMatch = TRUE; \
break; \
}
/* global variables */
int top_sn;
char *const skill_tname [] =
{ "unknown", "Spell", "Skill", "Weapon",
"Tongue", "Herb", "Racial", "Disease" };
class CSpellFnData {
public:
char *name;
SPELL_FUN *fn;
};
static CSpellFnData SpNdata [] = {
"spell_smaug", spell_smaug,
"spell_acid_blast", spell_acid_blast,
"spell_animate_dead", spell_animate_dead,
"spell_astral_walk", spell_astral_walk,
"spell_blindness", spell_blindness,
"spell_burning_hands", spell_burning_hands,
"spell_call_lightning", spell_call_lightning,
"spell_cause_critical", spell_cause_critical,
"spell_cause_light", spell_cause_light,
"spell_cause_serious", spell_cause_serious,
"spell_change_sex", spell_change_sex,
"spell_charm_person", spell_charm_person,
"spell_chill_touch", spell_chill_touch,
"spell_colour_spray", spell_colour_spray,
"spell_control_weather", spell_control_weather,
"spell_create_food", spell_create_food,
"spell_create_water", spell_create_water,
"spell_cure_blindness", spell_cure_blindness,
"spell_cure_poison", spell_cure_poison,
"spell_curse", spell_curse,
"spell_detect_poison", spell_detect_poison,
"spell_dispel_evil", spell_dispel_evil,
"spell_dispel_magic", spell_dispel_magic,
"spell_dream", spell_dream,
"spell_earthquake", spell_earthquake,
"spell_enchant_weapon", spell_enchant_weapon,
"spell_energy_drain", spell_energy_drain,
"spell_faerie_fire", spell_faerie_fire,
"spell_faerie_fog", spell_faerie_fog,
"spell_farsight", spell_farsight,
"spell_fireball", spell_fireball,
"spell_flamestrike", spell_flamestrike,
"spell_gate", spell_gate,
"spell_knock", spell_knock,
"spell_harm", spell_harm,
"spell_identify", spell_identify,
"spell_invis", spell_invis,
"spell_know_alignment", spell_know_alignment,
"spell_lightning_bolt", spell_lightning_bolt,
"spell_locate_object", spell_locate_object,
"spell_magic_missile", spell_magic_missile,
"spell_mist_walk", spell_mist_walk,
"spell_pass_door", spell_pass_door,
"spell_plant_pass", spell_plant_pass,
"spell_poison", spell_poison,
"spell_polymorph", spell_polymorph,
"spell_possess", spell_possess,
"spell_recharge", spell_recharge,
"spell_remove_curse", spell_remove_curse,
"spell_remove_invis", spell_remove_invis,
"spell_remove_trap", spell_remove_trap,
"spell_shocking_grasp", spell_shocking_grasp,
"spell_sleep", spell_sleep,
"spell_solar_flight", spell_solar_flight,
"spell_summon", spell_summon,
"spell_teleport", spell_teleport,
"spell_ventriloquate", spell_ventriloquate,
"spell_weaken", spell_weaken,
"spell_word_of_recall", spell_word_of_recall,
"spell_acid_breath", spell_acid_breath,
"spell_fire_breath", spell_fire_breath,
"spell_frost_breath", spell_frost_breath,
"spell_gas_breath", spell_gas_breath,
"spell_lightning_breath", spell_lightning_breath,
"spell_spiral_blast", spell_spiral_blast,
"spell_scorching_surge", spell_scorching_surge,
"spell_helical_flow", spell_helical_flow,
"spell_transport", spell_transport,
"spell_portal", spell_portal,
"spell_ethereal_fist", spell_ethereal_fist,
"spell_spectral_furor", spell_spectral_furor,
"spell_hand_of_chaos", spell_hand_of_chaos,
"spell_disruption", spell_disruption,
"spell_sonic_resonance", spell_sonic_resonance,
"spell_mind_wrack", spell_mind_wrack,
"spell_mind_wrench", spell_mind_wrench,
"spell_revive", spell_revive,
"spell_sulfurous_spray", spell_sulfurous_spray,
"spell_caustic_fount", spell_caustic_fount,
"spell_acetum_primus", spell_acetum_primus,
"spell_galvanic_whip", spell_galvanic_whip,
"spell_magnetic_thrust", spell_magnetic_thrust,
"spell_quantum_spike", spell_quantum_spike,
"spell_black_hand", spell_black_hand,
"spell_black_fist", spell_black_fist,
"spell_black_lightning", spell_black_lightning,
"spell_midas_touch", spell_midas_touch,
"spell_bethsaidean_touch", spell_bethsaidean_touch,
"spell_expurgation", spell_expurgation,
"spell_sacral_divinity", spell_sacral_divinity,
"reserved", NULL,
"spell_null", spell_null
};
SPELL_FUN *spell_function (char *name)
{
for (int i=0; i < DIM (SpNdata); ++i)
if (! stricmp (SpNdata [i].name, name))
return SpNdata [i].fn;
return spell_notfound;
}
char *spell_name (SPELL_FUN *spell)
{
for (int i=0; i < DIM (SpNdata); ++i)
if (SpNdata [i].fn == spell)
return SpNdata [i].name;
return "reserved";
}
// Save the skill table to disk
void save_skill_table ()
{
FILE *fp;
if ((fp = fopen (FileTable.GetName (SM_SKILL_FILE), "w")) == NULL) {
bug ("Cannot open skills.dat for writting");
return;
}
fprintf (fp, "#Version %s SmaugWiz V2\n\n",
NCCP SkillTable.GetCurrentVersion ());
for (int x = 0; x < SkillTable.GetCount (); ++x) {
if (! SkillTable.HasName (x))
break;
fprintf (fp, "#SKILL\n");
SkillTable.Write (fp, x);
}
fprintf (fp, "#END\n");
fclose (fp);
}
// Save the herb table to disk
void save_herb_table ()
{
FILE *fp;
if ((fp = fopen (FileTable.GetName (SM_HERB_FILE), "w")) == NULL) {
bug ("Cannot open herbs.dat for writting");
return;
}
fprintf (fp, "#Version %s SmaugWiz V2\n\n",
NCCP SkillTable.GetCurrentVersion ());
for (int x = 0; x < HerbTable.GetCount (); ++x) {
if (! HerbTable.GetName (x) || HerbTable.GetName (x)[0] == '\0')
break;
fprintf (fp, "#HERB\n");
HerbTable.Write (fp, x);
}
fprintf (fp, "#END\n");
fclose (fp);
}
int get_skill (char *skill)
{
if (!str_cmp (skill, "Spell"))
return SKILL_SPELL;
if (!str_cmp (skill, "Skill"))
return SKILL_SKILL;
if (!str_cmp (skill, "Weapon"))
return SKILL_WEAPON;
if (!str_cmp (skill, "Tongue"))
return SKILL_TONGUE;
if (!str_cmp (skill, "Herb"))
return SKILL_HERB;
return SKILL_UNKNOWN;
}
void load_skill_table ()
{
FILE *fp;
char *pLine;
bool bVersionFound = FALSE;
if ((fp = fopen (FileTable.GetName (SM_SKILL_FILE), "r"))) {
for (;;) {
char letter;
char *word;
pLine = fread_line (fp);
letter = *pLine++;
if (letter == '*')
continue;
if (letter != '#') {
bug ("Load_skill_table: # not found.");
break;
}
word = ParseWord (pLine);
if (! strcmp (word, "SKILL")) {
if (! SkillTable.Read (fp)) then break;
}
else if (! strcmp (word, "END")) then break;
else if (! strcmp (word, "Version")) {
CString Version = ParseWord (pLine);
if (Version != SkillTable.GetCurrentVersion ()) {
bug ("Load_skill_table: Cannot load Version %s.",
NCCP Version);
break;
}
bVersionFound = TRUE;
continue;
} else {
bug ("Load_skill_table: bad section.");
continue;
}
}
fclose (fp);
if (! bVersionFound) {
bug ("Load_skill_table: No Version.");
ThrowSmaugException (SE_HERB);
}
} else {
bug ("Cannot open skills.dat");
ThrowSmaugException (SE_SKILL);
}
if (SkillTable.GetCount () <= 0) {
bug ("No Skills found in skills.dat");
ThrowSmaugException (SE_SKILL);
}
}
void load_herb_table ()
{
FILE *fp;
char *pLine;
bool bVersionFound = FALSE;
if ((fp = fopen (FileTable.GetName (SM_HERB_FILE), "r"))) {
for (;;) {
char letter;
char *word;
pLine = fread_line (fp);
letter = *pLine++;
if (letter == '*')
continue;
if (letter != '#') {
bug ("Load_herb_table: # not found.");
break;
}
word = ParseWord (pLine);
if (! str_cmp (word, "HERB")) {
if (! bVersionFound) then break;
if (! HerbTable.Read (fp)) then break;
}
else if (!str_cmp (word, "END")) then break;
else if (! str_cmp (word, "Version")) {
CString Version = ParseWord (pLine);
if (Version != SkillTable.GetCurrentVersion ()) {
bug ("Load_herb_table: Cannot load Version %s.",
NCCP Version);
break;
}
bVersionFound = TRUE;
continue;
} else {
bug ("Load_herb_table: bad section.");
continue;
}
}
fclose (fp);
if (! bVersionFound) {
bug ("Load_herb_table: No Version.");
ThrowSmaugException (SE_HERB);
}
} else {
bug ("Cannot open herbs.dat");
ThrowSmaugException (SE_HERB);
}
if (HerbTable.GetCount () <= 0) {
bug ("No Skills found in herbs.dat");
ThrowSmaugException (SE_HERB);
}
}