nightmare4_fluffos_v1/
nightmare4_fluffos_v1/bin/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/ChangeLog.old/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/Win32/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/compat/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/compat/simuls/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/include/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/clone/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/command/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/data/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/etc/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/include/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/inherit/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/inherit/master/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/log/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/tests/compiler/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/tests/efuns/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/tests/operators/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/u/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/tmp/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/windows/
nightmare4_fluffos_v1/lib/cfg/
nightmare4_fluffos_v1/lib/cmds/admins/
nightmare4_fluffos_v1/lib/cmds/common/
nightmare4_fluffos_v1/lib/cmds/creators/include/
nightmare4_fluffos_v1/lib/cmds/creators/include/SCCS/
nightmare4_fluffos_v1/lib/cmds/hm/
nightmare4_fluffos_v1/lib/daemon/services/
nightmare4_fluffos_v1/lib/doc/
nightmare4_fluffos_v1/lib/doc/faq/
nightmare4_fluffos_v1/lib/doc/help/classes/
nightmare4_fluffos_v1/lib/doc/help/creators/
nightmare4_fluffos_v1/lib/doc/help/hm/
nightmare4_fluffos_v1/lib/doc/help/players/
nightmare4_fluffos_v1/lib/doc/help/races/
nightmare4_fluffos_v1/lib/doc/help/religion/
nightmare4_fluffos_v1/lib/doc/mudlib/
nightmare4_fluffos_v1/lib/doc/mudlib/cfg/
nightmare4_fluffos_v1/lib/domains/Ylsrim/
nightmare4_fluffos_v1/lib/domains/Ylsrim/adm/
nightmare4_fluffos_v1/lib/domains/Ylsrim/armour/
nightmare4_fluffos_v1/lib/domains/Ylsrim/fish/
nightmare4_fluffos_v1/lib/domains/Ylsrim/meal/
nightmare4_fluffos_v1/lib/domains/Ylsrim/npc/
nightmare4_fluffos_v1/lib/domains/Ylsrim/virtual/
nightmare4_fluffos_v1/lib/domains/Ylsrim/weapon/
nightmare4_fluffos_v1/lib/domains/Ylsrim/xtra/
nightmare4_fluffos_v1/lib/lib/comp/
nightmare4_fluffos_v1/lib/lib/lvs/
nightmare4_fluffos_v1/lib/lib/std/
nightmare4_fluffos_v1/lib/lib/user/
nightmare4_fluffos_v1/lib/news/
nightmare4_fluffos_v1/lib/obj/
nightmare4_fluffos_v1/lib/obj/include/
nightmare4_fluffos_v1/lib/save/
nightmare4_fluffos_v1/lib/save/kills/a/
nightmare4_fluffos_v1/lib/save/kills/b/
nightmare4_fluffos_v1/lib/save/kills/f/
nightmare4_fluffos_v1/lib/save/kills/m/
nightmare4_fluffos_v1/lib/save/kills/q/
nightmare4_fluffos_v1/lib/save/kills/r/
nightmare4_fluffos_v1/lib/secure/cfg/
nightmare4_fluffos_v1/lib/secure/cfg/classes/
nightmare4_fluffos_v1/lib/secure/cfg/races/SCCS/
nightmare4_fluffos_v1/lib/secure/cmds/creators/include/
nightmare4_fluffos_v1/lib/secure/cmds/players/
nightmare4_fluffos_v1/lib/secure/cmds/players/include/
nightmare4_fluffos_v1/lib/secure/daemon/include/
nightmare4_fluffos_v1/lib/secure/lib/
nightmare4_fluffos_v1/lib/secure/lib/include/
nightmare4_fluffos_v1/lib/secure/lib/net/
nightmare4_fluffos_v1/lib/secure/lib/std/
nightmare4_fluffos_v1/lib/secure/obj/
nightmare4_fluffos_v1/lib/secure/obj/include/
nightmare4_fluffos_v1/lib/secure/save/
nightmare4_fluffos_v1/lib/secure/save/boards/
nightmare4_fluffos_v1/lib/secure/save/votes/
nightmare4_fluffos_v1/lib/spells/
nightmare4_fluffos_v1/lib/verbs/admins/include/
nightmare4_fluffos_v1/lib/verbs/common/
nightmare4_fluffos_v1/lib/verbs/common/include/
nightmare4_fluffos_v1/lib/verbs/creators/
nightmare4_fluffos_v1/lib/verbs/creators/include/
nightmare4_fluffos_v1/lib/verbs/players/include/SCCS/
nightmare4_fluffos_v1/lib/verbs/rooms/
nightmare4_fluffos_v1/lib/verbs/rooms/include/
nightmare4_fluffos_v1/lib/www/
nightmare4_fluffos_v1/old/
nightmare4_fluffos_v1/old/tools/
nightmare4_fluffos_v1/win32/
/*    /lib/abilities.c
 *    From the Nightmare V LPC Library
 *    Handles learned traits
 *    Created by Descartes of Borg 950122
 *    Version: @(#) abilities.c 1.22@(#)
 *    Last modified: 97/01/03
 */

private int            Level       = 1;
private mapping        Skills      = ([]);
private static mapping SkillsBonus = ([]);

// abstract methods
varargs void eventPrint(string str, mixed args...);
// end abstract methods

string array GetPrimarySkills();
varargs void SetSkill(string skill, int level, int cls);

/* ***************** abilities.c attributes ***************** */
/* GetBaseSkillLevel() returns the unmodified skill level */
int GetBaseSkillLevel(string skill) { 
    if( !Skills[skill] ) {
	return 0;
    }
    else {
	return Skills[skill]["level"];
    }
}

int GetLevel() {
    return Level;
}

/* static int ResetLevel()
 *
 * description
 * takes the average skill level of the primary skills and divided by 4
 * and sets the level to that number
 *
 * returns the new level
 */
int ResetLevel() {
    string array skills = GetPrimarySkills();
    int num = sizeof(skills);
    int points = 0;

    if( num < 1 ) {
	return (Level = 1);
    }
    foreach(string skill in skills) {
	points += Skills[skill]["level"];
    }
    Level = (points/num)/2;
    if( Level < 1 ) {
	Level = 1;
    }
    return Level;
}

int SetLevel(int x) {
    string array skills = GetPrimarySkills();
    int i;

    foreach(string skill in skills) {
	SetSkill(skill, 2*x);
    }
    return (Level = x);
}

int GetMaxSkillPoints(string skill, int level) {
    if( !Skills[skill] ) {
	return 0;
    }
    else if( level == 0 ) {
	return 200;
    }
    else {
	int cl, x;

	if( !(cl = Skills[skill]["class"]) ) {
	    return level * 600;
	}
	if( cl > 4 ) {
	    cl = 4;
	}
	if( cl < 1 ) {
	    cl = 4;
	}
	x = level;
	while( cl-- ) {
	    x *= level;
	}
	return (x * 400);
    }
}

string array GetPrimarySkills() { 
    return filter(keys(Skills), (: Skills[$1]["class"] == 1 :));
}

/* varargs int AddSkill(string skill, int classes)
 * string skill - the skill being added (required)
 * int classes - the class of the skill (optional)
 *
 * defaults
 * classes defaults to 1, primary class
 *
 * description
 * Used to add a new ability to the list of abilities.  "skill" is the name
 * of the skill being added, and "class" represents the ranking of that skill
 *
 * returns 1 on success, 0 on failure
 */
varargs int AddSkill(string skill, int cls) {
    if( !stringp(skill) ) {
	error("Bad argument 1 to AddSkill().\n\tExpected: string, Got: " +
	      typeof(skill) + "\n");
    }
    if( !nullp(Skills[skill]) ) {
	return 0;
    }
    if( !cls ) {
	cls = 1;
    }
    else if( cls < 0 || cls > 4) {
	return 0;
    }
    Skills[skill] = ([ "points" : 0, "level" : 0, "class" : cls ]);
    return 1;
}

mapping GetSkill(string skill) {
    return copy(Skills[skill]);
}

void RemoveSkill(string skill) {
    if( !Skills[skill] ) {
	return;
    }
    map_delete(Skills, skill);
    ResetLevel();
}

/* varargs void SetSkill(string skill, int level, int classes)
 * string skill - the name of the skill being set (required)
 * int level - the level to which that skill is being set (required)
 * int classes - the class to which the skill is being set (optional)
 *
 * defaults
 * classes will default to 1, primary class
 *
 * description
 * sets the skill "skill" to the level "level"
 * if a classes is given, its class is set to it, otherwise the class is
 * set to 1
 * usefule mostly for monster types, probably should have override
 * protections in the user object (should use AddSkill() for users)
 */
varargs void SetSkill(string skill, int level, int cls) {
    if( !stringp(skill) ) {
	error("Bad argument 1 to SetSkill().\n\tExpected: string, Got: " +
	      typeof(skill) + "\n");
    }
    if( !cls ) {
        if( Skills[skill] ) {
	    cls = Skills[skill]["class"];
	}
        else {
	    cls = 1;
	}
    }
    else if( cls < 1 || cls > 4) {
	return 0;
    }
    Skills[skill] = ([ "points" : 0, "level" : level, "class" : cls ]);
}

string array GetSkills() {
    return keys(Skills);
}

void AddSkillBonus(string skill, function f) {
    if( !SkillsBonus[skill] ) {
	SkillsBonus[skill] = ([]);
    }
    SkillsBonus[skill][previous_object()] = f;
}

varargs void RemoveSkillBonus(string skill, object ob) {
    if( !SkillsBonus[skill] ) {
	return;
    }
    if( !ob ) {
	ob = previous_object();
    }
    if( !ob || !SkillsBonus[skill][ob] ) {
	return;
    }
    map_delete(SkillsBonus[skill], ob);
}

int GetSkillBonus(string skill) {
    object ob;
    int x = 0;

    if( !SkillsBonus[skill] ) {
	return 0;
    }
    foreach(ob in keys(SkillsBonus[skill])) {
	if( !ob ) continue;
	else x += evaluate(SkillsBonus[skill][ob], skill);
    }
    return x;
}

int GetSkillClass(string skill) { 
    if( !Skills[skill] ) {
	return 0;
    }
    else {
	return Skills[skill]["class"];
    }
}

/* GetSkillLevel() returns the base skill level + any bonuses */
int GetSkillLevel(string skill) { 
    return (GetBaseSkillLevel(skill) + GetSkillBonus(skill));
}

/* int AddSkillPoints(string skill, int x)
 * string name - the skill to which points are being added
 * int x - the number of points being added
 *
 * description
 * adds "x" points to the total for skill "skill"
 * if the points go over the max for the current skill level,
 * then the level is raised 1
 * if the points go under 0, then the skill level is lowered
 *
 * returns the skill level after addition
 */
int AddSkillPoints(string name, int x) {
    int y;

    if( !Skills[name] ) {
	return 0;
    }
    Skills[name]["points"] += x;
    while( Skills[name]["points"] < 0 ) { /* lost skills! */
	if( Skills[name]["level"] == 1 ) {
	    Skills[name]["points"] = 0;
	}
	else {
	    int tmp;

	    tmp = --Skills[name]["level"];
	    Skills[name]["points"] += GetMaxSkillPoints(name, tmp);
	    if( Skills[name]["class"] == 1 ) {
		ResetLevel();
	    }
	}
    }
    y = GetMaxSkillPoints(name, Skills[name]["level"]);
    while( Skills[name]["points"] > y ) {
	int max;

	if( Skills[name]["class"] == 1 ) {
	    max = 2;
	}
	else {
	    max = 1;
	}
	if( Skills[name]["level"] >= ((GetLevel()+max) *2) ) {
	    Skills[name]["points"] = y;
	}
	else {
            eventPrint("%^YELLOW%^You are a bit more adept with your " +
		       name + ".");
	    Skills[name]["level"]++;
	    Skills[name]["points"] -= y;
	    if( Skills[name]["class"] == 1 ) {
		ResetLevel();
	    }
	}
	y = GetMaxSkillPoints(name, Skills[name]["level"]);
    }
    return Skills[name]["level"];
}

/* ******************* abilities.c events ********************* */
/**
 * Trains a skill based on a scale of 1-100 in favour of success and 1-100
 * against success.  Any particular thing (like calculating whether a player
 * hits an enemy) determins whether an operation succeeds or fails.  For
 * example, pro = melee attack, con = melee defense.  While the con may
 * be greater than the pro, combat may randomize that.  You still reward
 * based on the absolutes.  Success is flagged to this method.  The value of
 * training looks like this:
 * highest- pro: 0, con: 100, success: 1
 * moderate- pro: 100, con: 0, success: 1
 * moderate- pro: 0, con 100, success: 0
 * low- pro: 100, con: 0, success: 0
 * This means if you have everything going against you and you succeed, you
 * get the highest reward.  If you have everything going for you and you fail,
 * you get nothing.
 * Adjustments are made for your level and any multiplier bonuses.
 */
varargs void  eventTrainSkill(string skill, int pro, int con, int array a...) {
    int level = (GetLevel()/8 + 1);
    int val, success, bonus;

    if( sizeof(a) ) {
	success = a[0];
	if( sizeof(a) == 2 ) {
	    bonus = a[1];
	}
	else {
	    bonus = 1;
	}
    }
    else {
	success = 1;
	bonus = 1;
    }
    if( con > 100 ) {
	con = 100;
    }
    if( con < 0 ) {
	con = 0;
    }
    if( pro > 100 ) {
	pro = 100;
    }
    if( pro < 0 ) {
	pro = 0;
    }
    val = (con - pro + (200*success) + 100)/8;
    AddSkillPoints(skill, (bonus * val * level * level) + 1);
}
    
/* ****************** abilities.c driver applies **************** */
static void create() {
}