/*
 * BALANS SPECA
 *
 */
 
int MAX_PEN     =   10000;    // Maksymalna sila speca

int PEN_WEAPON  =   10;      // Ile procent sily speca ma zalezec od broni
int PEN_STATS   =   20;      // statystyki postaci, 
int PEN_SKILLS  =   10;      // umiejetnosci postaci,
int PEN_GUILD   =   60;      // poziomu gildiowego.

int PEN_BONUS   =   (200);  // Ewentualny bonusik do speca.

/*
 *  Funkcja oblicza jakiego pena zadamy dla osobnego czynnika.
 *
 *  act  - wartosc czynnika (np. broni, statow itp)
 *  max  - wartosc czynnika odniesienia (maksymalna)
 *  waga - waga czynnika (ile procent sily speca ma od niego zalezec)
 */
int
count(int act, int max, int waga)
{
        return (MAX_PEN * (waga) / 100 * (act) / (max));
}

int
query_pen(object user, object enemy)
{
    int PEN;
    
    int user_weapon = (user->query_weapon())->query_hit();
    int max_weapon  = 100;
    
    int user_stats  = user->query_stat(SS_STR) +
                      user->query_stat(SS_DEX) +
                      (user->query_stat(SS_WIS) / 4);
    int max_stats   = 450;

    int user_skills = user->query_skill(SS_WEP_SWORD);
    int max_skills  = 200;  
   
    int user_guild  = user->query_stat(SS_OCCUP);
    int max_guild   = 200;
    
    PEN = count(user_weapon, max_weapon, PEN_WEAPON) +
          count(user_stats , max_stats , PEN_STATS ) +
          count(user_skills, max_skills, PEN_SKILLS) +
          count(user_guild , max_guild , PEN_GUILD ) +
          PEN_BONUS;
        
    return MIN ( MAX_PEN, PEN );
}

int
query_hit(object user, object enemy)
{
    object combat;
    int tohit;
    mixed result;

    combat = enemy->query_combat_object();
    
    tohit =  (user->query_skill(SS_WEP_SWORD) +
             (user->query_weapon())->query_hit()) / 2;

    result = combat->cb_tohit(-1, tohit, 1000, enemy);

    if(intp(result)) return result;
    if(objectp(result)) return 0;
    if(result[0] > 0) return result[0];
    return 0;
}
