lima-1.0b5/
lima-1.0b5/driver/
lima-1.0b5/driver/ChangeLog.old/
lima-1.0b5/driver/Win32/
lima-1.0b5/driver/compat/
lima-1.0b5/driver/include/
lima-1.0b5/driver/testsuite/
lima-1.0b5/driver/testsuite/clone/
lima-1.0b5/driver/testsuite/command/
lima-1.0b5/driver/testsuite/data/
lima-1.0b5/driver/testsuite/etc/
lima-1.0b5/driver/testsuite/include/
lima-1.0b5/driver/testsuite/inherit/
lima-1.0b5/driver/testsuite/inherit/master/
lima-1.0b5/driver/testsuite/log/
lima-1.0b5/driver/testsuite/single/
lima-1.0b5/driver/testsuite/single/tests/compiler/
lima-1.0b5/driver/testsuite/single/tests/efuns/
lima-1.0b5/driver/testsuite/single/tests/operators/
lima-1.0b5/driver/testsuite/u/
lima-1.0b5/driver/tmp/
lima-1.0b5/etc/
lima-1.0b5/lib/WWW/help/
lima-1.0b5/lib/cmds/
lima-1.0b5/lib/cmds/create/
lima-1.0b5/lib/cmds/player/attic/
lima-1.0b5/lib/contrib/bboard/
lima-1.0b5/lib/contrib/boards/
lima-1.0b5/lib/contrib/marriage/
lima-1.0b5/lib/contrib/roommaker/
lima-1.0b5/lib/contrib/transient_effect/
lima-1.0b5/lib/daemons/channel/
lima-1.0b5/lib/daemons/imud/
lima-1.0b5/lib/data/
lima-1.0b5/lib/data/config/
lima-1.0b5/lib/data/links/
lima-1.0b5/lib/data/news/
lima-1.0b5/lib/data/players/
lima-1.0b5/lib/data/secure/
lima-1.0b5/lib/domains/
lima-1.0b5/lib/domains/std/2.4.5/maze1/
lima-1.0b5/lib/domains/std/2.4.5/npc/
lima-1.0b5/lib/domains/std/2.4.5/post_dir/
lima-1.0b5/lib/domains/std/2.4.5/sub/
lima-1.0b5/lib/domains/std/camera/
lima-1.0b5/lib/domains/std/config/
lima-1.0b5/lib/domains/std/cult/
lima-1.0b5/lib/domains/std/effects/
lima-1.0b5/lib/domains/std/misc/
lima-1.0b5/lib/domains/std/monsters/
lima-1.0b5/lib/domains/std/recorder/
lima-1.0b5/lib/domains/std/rooms/
lima-1.0b5/lib/domains/std/rooms/beach/
lima-1.0b5/lib/domains/std/rooms/labyrinth/
lima-1.0b5/lib/domains/std/school/
lima-1.0b5/lib/domains/std/school/O/
lima-1.0b5/lib/domains/std/spells/
lima-1.0b5/lib/domains/std/spells/stock-mage/
lima-1.0b5/lib/domains/std/spells/stock-priest/
lima-1.0b5/lib/help/
lima-1.0b5/lib/help/admin/
lima-1.0b5/lib/help/hints/General_Questions/
lima-1.0b5/lib/help/hints/Pirate_Quest/
lima-1.0b5/lib/help/player/
lima-1.0b5/lib/help/player/bin/
lima-1.0b5/lib/help/player/quests/
lima-1.0b5/lib/help/wizard/
lima-1.0b5/lib/help/wizard/coding/guilds/
lima-1.0b5/lib/help/wizard/coding/rooms/
lima-1.0b5/lib/help/wizard/lib/daemons/
lima-1.0b5/lib/help/wizard/lib/lfun/
lima-1.0b5/lib/help/wizard/lib/std/
lima-1.0b5/lib/help/wizard/mudos_doc/
lima-1.0b5/lib/help/wizard/mudos_doc/applies/
lima-1.0b5/lib/help/wizard/mudos_doc/applies/interactive/
lima-1.0b5/lib/help/wizard/mudos_doc/applies/parsing/
lima-1.0b5/lib/help/wizard/mudos_doc/concepts/
lima-1.0b5/lib/help/wizard/mudos_doc/driver/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/arrays/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/buffers/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/compile/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/filesystem/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/floats/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/functions/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/general/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/mappings/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/mixed/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/numbers/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/parsing/
lima-1.0b5/lib/help/wizard/mudos_doc/lpc/constructs/
lima-1.0b5/lib/help/wizard/mudos_doc/lpc/types/
lima-1.0b5/lib/include/driver/
lima-1.0b5/lib/log/
lima-1.0b5/lib/obj/admtool/
lima-1.0b5/lib/obj/admtool/internal/
lima-1.0b5/lib/obj/admtool/mudinfo/
lima-1.0b5/lib/obj/admtool/secure/
lima-1.0b5/lib/obj/secure/
lima-1.0b5/lib/obj/secure/cmd/
lima-1.0b5/lib/obj/secure/mailers/
lima-1.0b5/lib/obj/secure/shell/
lima-1.0b5/lib/obj/secure/shell/classes/
lima-1.0b5/lib/obj/tasktool/
lima-1.0b5/lib/obj/tasktool/internal/
lima-1.0b5/lib/open/
lima-1.0b5/lib/secure/
lima-1.0b5/lib/secure/cgi/
lima-1.0b5/lib/secure/modules/
lima-1.0b5/lib/secure/simul_efun/
lima-1.0b5/lib/std/adversary/
lima-1.0b5/lib/std/adversary/advancement/
lima-1.0b5/lib/std/adversary/armor/
lima-1.0b5/lib/std/adversary/blows/
lima-1.0b5/lib/std/adversary/death/
lima-1.0b5/lib/std/adversary/formula/
lima-1.0b5/lib/std/adversary/health/
lima-1.0b5/lib/std/adversary/pulse/
lima-1.0b5/lib/std/adversary/wield/
lima-1.0b5/lib/std/classes/event_info/
lima-1.0b5/lib/std/container/
lima-1.0b5/lib/std/living/
lima-1.0b5/lib/std/modules/contrib/
lima-1.0b5/lib/std/patterns/
lima-1.0b5/lib/std/race/
lima-1.0b5/lib/std/race/restricted/
lima-1.0b5/lib/std/room/
lima-1.0b5/lib/tmp/
lima-1.0b5/lib/trans/
lima-1.0b5/lib/trans/admincmds/
lima-1.0b5/lib/trans/obj/
lima-1.0b5/lib/wiz/
/* Do not remove the headers from this file! see /USAGE for more info. */

/*
** DESIGN
**
**   Skills are represented as slash-separated names, organized as a tree
**   of skills.  Learning a skill propagates improvement up the chain to
**   the parent skills.  The total, aggregate value of a skill at any point
**   is computed from a skill and all of its parent skills.  This implies
**   that use of one skill can benefit sibling skills; for example, using a
**   sword improves the general combat skill which can help when you are
**   forced to use a polearm (which you are otherwise unskilled at).
**
**   A secondary concept of "training points" exist for each skill.  These
**   represent potential, additional improvement through formal training.
**   Similar to skill values, the training points also propagate upwards.
**   The points can then be applied to the skill and/or back down the tree;
**   for example, using a sword earns training points in combat which can
**   then be applied towards formal training with polearms or archery.
**
** MECHANICS
**
**   Progression within a skill is based on a curve (specifically, a third-
**   order polynomial).  At the low- and top-end of the skill value range,
**   it is hard to advance.  This is to represent the initial difficulty
**   of learning a new skill and the difficulty of perfecting it.  In the
**   middle of the skill value range, growth is much faster (learned points
**   are applied at a near one-to-one ratio).
**
**   At the ends of the range, skills are gained in a proportion based on
**   the LEARNING_FACTOR symbol.
**
**   As learning a skill propogates up the tree of skills, the amount
**   applied decreases exponentially (set by PROPOGATION_FACTOR).
**
**   Training points are added proportionally to the increase in the main
**   skill (set by the TRAINING_FACTOR symbol).
**
**   Learning a skill is based on three symbols: SKILL_ON_FAILURE,
**   SKILL_MIN_ON_WIN, SKILL_MAX_ON_WIN.  When a test_skill() fails, the
**   SKILL_ON_FAILURE amount is learned.  When the test_skill() succeeds,
**   then you learn something in the range of MIN/MAX based on your ratio
**   against the opposing skill (MAX if you're totally outclassed or MIN
**   if you stomp all over your opponent).
**
**   All these parameters are set in the skills.h file.
**
** Note: policy decision says that we aren't protecting skills from
**       "unauthorized" tampering.  This is consistent with much of
**       lib -- wizards can help players in any numbers of ways and
**       we won't try to guard against all of them.
*/

#include <classes.h>
#include <skills.h>

inherit CLASS_SKILL;

private mapping skills = ([ ]);

int base_test_skill(string skill, int opposing_skill);

class skill set_skill(string skill, int skill_points, int training_points)
{
    class skill	cs = skills[skill];

    if ( member_array(skill, SKILL_D->query_skills()) == -1 )
	error("illegal skill; cannot set new skill values.\n");

    if ( !cs )
    {
	cs = skills[skill] = new(class skill,
				 skill_points : skill_points,
				 training_points : training_points);
    }
    else
    {
	cs->skill_points = skill_points;
	cs->training_points = training_points;
    }

    return cs;
}


mapping get_skills()
{
    return skills;
}


class skill get_skill(string skill)
{
    return skills[skill];
}

//:FUNCTION aggregate_skill
// Returns the aggregated skill value for the specified skill.  This value
// incorporates the value of the skill itself plus all values of the parent
// skills.
int aggregate_skill(string skill)
{
    int total_skill = 0;
    int coef = 1;

    while ( 1 )
    {
	class skill my_skill;
	int i;

	my_skill = skills[skill];
	if ( my_skill )
	{
	    total_skill += fuzzy_divide(my_skill->skill_points, coef);
	}

	coef = coef * AGGREGATION_FACTOR;

	i = strsrch(skill, '/', -1);
	if ( i == -1 )
	    break;
	skill = skill[0..i-1];
    }

    return total_skill;
}

//:FUNCTION learn_skill
// Add some number of skill points to the given skill, propogating skill
// values up through the parent skills.  Training points are also assigned
// as appropriate.
void learn_skill(string skill, int value)
{
    while ( 1 )
    {
	class skill my_skill;
	int divisor;
	int i;
	int s;

	my_skill = skills[skill];
	if ( !my_skill )
	{
	    /* use set_skill() for verification of the skill */
	    my_skill = set_skill(skill, 0, 0);
	}

	/* centered within skill range */
	s = my_skill->skill_points - (MAX_SKILL_VALUE / 2);

	/* as a person's skill increases, the amount they learn decreases */
	divisor = ((LEARNING_FACTOR - 1) * s * s) / (MAX_SKILL_VALUE * MAX_SKILL_VALUE / 4) + 1;
	my_skill->skill_points += fuzzy_divide(value, divisor);
	if ( my_skill->skill_points > MAX_SKILL_VALUE )
	    my_skill->skill_points = MAX_SKILL_VALUE;

	/* accum training points */
	my_skill->training_points += fuzzy_divide(value, divisor * TRAINING_FACTOR);

	/* as skill moves up tree, it decreases */
	value = fuzzy_divide(value, PROPAGATION_FACTOR);
	if ( !value )
	    break;

	i = strsrch(skill, '/', -1);
	if ( i == -1 )
	    break;
	skill = skill[0..i-1];
    }
}

//:FUNCTION test_skill
// This replaces the basic adversary test_skill function,
// adding an attempt to improve the skill
int test_skill(string skill, int opposing_skill)
{
  int total_skill;
  int amount;
  int combined_total;
  int res;

  total_skill = aggregate_skill(skill);
  combined_total = total_skill + opposing_skill;

  res = base_test_skill(skill, opposing_skill);

  if(res)
  {
/*
 ** Successful skill attempts win a number of skill points based on
 ** the ratio between the total_skill and opposing_skill.
 **
 ** The range is MIN to MAX, centered between the two for evenly matched
 ** skills.  As the opposing skill increases, so does the amount learned.
 */
    amount = ( ( (SKILL_MAX_ON_WIN - SKILL_MIN_ON_WIN) * opposing_skill
           + (combined_total / 2) )
           / combined_total
           + SKILL_MIN_ON_WIN
           );
    learn_skill(skill, amount);
  }
  else
    learn_skill(skill, SKILL_ON_FAILURE);
  return res;
}


//:FUNCTION query_evaluation
//Returns the player's overall evaluation (0 to 100 percent) of their skill
//level.  This evaluation corresponds to how they are doing with respect
//to the maximum possible skill level.
int query_evaluation()
{
    return implode(values(skills),
		   (: $1 + ((class skill)$2)->skill_points :),
		   0) * 100 / EVALUATION_SKILL_LEVEL;
}