dsIIr4/bin/
dsIIr4/extra/creremote/
dsIIr4/extra/wolfpaw/
dsIIr4/lib/cmds/admins/
dsIIr4/lib/cmds/common/
dsIIr4/lib/cmds/creators/include/
dsIIr4/lib/cmds/creators/include/SCCS/
dsIIr4/lib/daemon/services/
dsIIr4/lib/doc/
dsIIr4/lib/domains/Ylsrim/
dsIIr4/lib/domains/Ylsrim/adm/
dsIIr4/lib/domains/Ylsrim/armor/
dsIIr4/lib/domains/Ylsrim/broken/
dsIIr4/lib/domains/Ylsrim/fish/
dsIIr4/lib/domains/Ylsrim/meal/
dsIIr4/lib/domains/Ylsrim/npc/
dsIIr4/lib/domains/Ylsrim/virtual/
dsIIr4/lib/domains/Ylsrim/weapon/
dsIIr4/lib/domains/campus/adm/
dsIIr4/lib/domains/campus/etc/
dsIIr4/lib/domains/campus/meals/
dsIIr4/lib/domains/campus/npc/
dsIIr4/lib/domains/campus/save/
dsIIr4/lib/domains/campus/txt/
dsIIr4/lib/domains/campus/txt/ai/charles/
dsIIr4/lib/domains/campus/txt/ai/charles/bak2/
dsIIr4/lib/domains/campus/txt/ai/charles/bak2/bak1/
dsIIr4/lib/domains/campus/txt/ai/charly/
dsIIr4/lib/domains/campus/txt/ai/charly/bak/
dsIIr4/lib/domains/campus/txt/jenny/
dsIIr4/lib/domains/default/creator/
dsIIr4/lib/domains/default/doors/
dsIIr4/lib/domains/default/etc/
dsIIr4/lib/domains/default/virtual/
dsIIr4/lib/domains/default/weap/
dsIIr4/lib/domains/town/virtual/
dsIIr4/lib/lib/comp/
dsIIr4/lib/lib/lvs/
dsIIr4/lib/lib/user/
dsIIr4/lib/lib/virtual/
dsIIr4/lib/log/
dsIIr4/lib/obj/book_source/
dsIIr4/lib/obj/include/
dsIIr4/lib/realms/template/
dsIIr4/lib/realms/template/adm/
dsIIr4/lib/realms/template/area/armor/
dsIIr4/lib/realms/template/area/npc/
dsIIr4/lib/realms/template/area/obj/
dsIIr4/lib/realms/template/area/room/
dsIIr4/lib/realms/template/area/weap/
dsIIr4/lib/realms/template/bak/
dsIIr4/lib/realms/template/cmds/
dsIIr4/lib/save/
dsIIr4/lib/save/kills/o/
dsIIr4/lib/secure/cfg/classes/
dsIIr4/lib/secure/cmds/creators/include/
dsIIr4/lib/secure/cmds/players/
dsIIr4/lib/secure/cmds/players/include/
dsIIr4/lib/secure/daemon/include/
dsIIr4/lib/secure/lib/
dsIIr4/lib/secure/lib/include/
dsIIr4/lib/secure/lib/net/include/
dsIIr4/lib/secure/lib/std/
dsIIr4/lib/secure/modules/
dsIIr4/lib/secure/npc/
dsIIr4/lib/secure/obj/include/
dsIIr4/lib/secure/room/
dsIIr4/lib/secure/save/
dsIIr4/lib/secure/save/boards/
dsIIr4/lib/secure/save/players/g/
dsIIr4/lib/secure/tmp/
dsIIr4/lib/secure/verbs/creators/
dsIIr4/lib/shadows/
dsIIr4/lib/spells/
dsIIr4/lib/std/board/
dsIIr4/lib/std/lib/
dsIIr4/lib/tmp/
dsIIr4/lib/verbs/admins/include/
dsIIr4/lib/verbs/common/
dsIIr4/lib/verbs/common/include/
dsIIr4/lib/verbs/creators/include/
dsIIr4/lib/verbs/players/include/SCCS/
dsIIr4/lib/verbs/rooms/
dsIIr4/lib/verbs/rooms/include/
dsIIr4/lib/www/
dsIIr4/v22.2b14-dsouls2/
dsIIr4/v22.2b14-dsouls2/ChangeLog.old/
dsIIr4/v22.2b14-dsouls2/Win32/
dsIIr4/v22.2b14-dsouls2/compat/
dsIIr4/v22.2b14-dsouls2/compat/simuls/
dsIIr4/v22.2b14-dsouls2/include/
dsIIr4/v22.2b14-dsouls2/mudlib/
dsIIr4/v22.2b14-dsouls2/testsuite/
dsIIr4/v22.2b14-dsouls2/testsuite/clone/
dsIIr4/v22.2b14-dsouls2/testsuite/command/
dsIIr4/v22.2b14-dsouls2/testsuite/data/
dsIIr4/v22.2b14-dsouls2/testsuite/etc/
dsIIr4/v22.2b14-dsouls2/testsuite/include/
dsIIr4/v22.2b14-dsouls2/testsuite/inherit/
dsIIr4/v22.2b14-dsouls2/testsuite/inherit/master/
dsIIr4/v22.2b14-dsouls2/testsuite/log/
dsIIr4/v22.2b14-dsouls2/testsuite/single/
dsIIr4/v22.2b14-dsouls2/testsuite/single/tests/compiler/
dsIIr4/v22.2b14-dsouls2/testsuite/single/tests/efuns/
dsIIr4/v22.2b14-dsouls2/testsuite/single/tests/operators/
dsIIr4/v22.2b14-dsouls2/testsuite/u/
dsIIr4/v22.2b14-dsouls2/tmp/
dsIIr4/win32/
/*    /lib/abilities.c
 *    From the Dead Souls 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, mixed 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();

    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, int level) {
    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;
    }
    if(!level){
	level = 1;
    }
    else if( cls < 0 || cls > 4) {
	return 0;
    }
    Skills[skill] = ([ "points" : 0, "level" : level, "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
 * useful 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, mixed cls) {
    int tmp;
    if(cls && !intp(cls)) {
	tmp = 1;
	cls = tmp;
    }
    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);
}

mapping GetSkillsMap(){
    return copy(Skills);
}

void AddSkillBonus(string skill, mixed 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;
    }

    if(intp(SkillsBonus[skill]))
	return SkillsBonus[skill];

    foreach(ob in keys(SkillsBonus[skill])) {
	if( !ob ) continue;
	else if(intp(SkillsBonus[skill][ob])) x += SkillsBonus[skill][ob];
	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() {
}