1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
|
/*
* File: skills.cc
* Summary: Skill exercising functions.
* Written by: Linley Henzell
*/
#include "AppHdr.h"
#include "skills.h"
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include "externs.h"
#include "itemprop.h"
#include "notes.h"
#include "output.h"
#include "player.h"
#include "random.h"
#include "skills2.h"
#include "spl-cast.h"
#include "sprint.h"
#include "state.h"
#include "hints.h"
// MAX_COST_LIMIT is the maximum XP amount it will cost to raise a skill
// by 10 skill points (ie one standard practice).
//
// MAX_SPENDING_LIMIT is the maximum XP amount we allow the player to
// spend on a skill in a single raise.
//
// Note that they don't have to be equal, but it is important to make
// sure that they're set so that the spending limit will always allow
// for 1 skill point to be earned.
#define MAX_COST_LIMIT 250
#define MAX_SPENDING_LIMIT 250
static int _exercise2( int exsk );
// These values were calculated by running a simulation of gaining skills.
// The goal is to try and match the old cost system which used the player's
// experience level (which has a number of problems) so things shouldn't
// seem too different to the player... but we still try to err on the
// high side for the lower levels. -- bwr
int skill_cost_needed( int level )
{
// The average starting skill total is actually lower, but
// some classes get about 2200, and they would probably be
// start around skill cost level 3 if we used the average. -- bwr
int ret = 2200;
switch (level)
{
case 1: ret = 0; break;
case 2: ret += 250; break; // 250 -- big because of initial 25 pool
case 3: ret += 350; break; // 100
case 4: ret += 550; break; // 200
case 5: ret += 900; break; // 350
case 6: ret += 1300; break; // 400
case 7: ret += 1900; break; // 600
case 8: ret += 2800; break; // 900
case 9: ret += 4200; break; // 1400
case 10: ret += 5900; break; // 1700
case 11: ret += 9000; break; // 3100
default:
ret += 9000 + (4000 * (level - 11));
break;
}
return (ret);
}
void calc_total_skill_points( void )
{
int i;
you.total_skill_points = 0;
for (i = 0; i < NUM_SKILLS; i++)
you.total_skill_points += you.skill_points[i];
for (i = 1; i <= 27; i++)
if (you.total_skill_points < skill_cost_needed(i))
break;
you.skill_cost_level = i - 1;
#ifdef DEBUG_DIAGNOSTICS
you.redraw_experience = true;
#endif
}
// skill_cost_level makes skills more expensive for more experienced characters
// skill_level makes higher skills more expensive
static int _calc_skill_cost( int skill_cost_level, int skill_level )
{
int ret = 1 + skill_level;
// does not yet allow for loss of skill levels.
if (skill_level > 9)
{
ret *= (skill_level - 7);
ret /= 3;
}
if (skill_cost_level > 4)
ret += skill_cost_level - 4;
if (skill_cost_level > 7)
ret += skill_cost_level - 7;
if (skill_cost_level > 10)
ret += skill_cost_level - 10;
if (skill_cost_level > 13)
ret += skill_cost_level - 13;
if (skill_cost_level > 16)
ret += skill_cost_level - 16;
if (skill_cost_level > 10)
{
ret *= (skill_cost_level - 5);
ret /= 5;
}
if (skill_level > 7)
ret += 1;
if (skill_level > 9)
ret += 2;
if (skill_level > 11)
ret += 3;
if (skill_level > 13)
ret += 4;
if (skill_level > 15)
ret += 5;
if (ret > MAX_COST_LIMIT)
ret = MAX_COST_LIMIT;
return (ret);
}
// returns total number of skill points gained
int exercise(int exsk, int deg)
{
int ret = 0;
if (crawl_state.game_is_sprint())
{
deg = sprint_modify_skills(deg);
}
while (deg > 0)
{
if (you.exp_available <= 0 || you.skills[exsk] >= 27)
break;
if (you.practise_skill[exsk] || one_chance_in(4))
ret += _exercise2(exsk);
deg--;
}
if (ret)
dprf("Exercised %s (deg: %d) by %d", skill_name(exsk), deg, ret);
return (ret);
}
static bool _check_crosstrain(skill_type exsk, skill_type sk1, skill_type sk2)
{
return ((exsk == sk1 || exsk == sk2)
&& (you.skills[sk1] > you.skills[exsk]
|| you.skills[sk2] > you.skills[exsk]));
}
static int _weap_crosstrain_bonus(skill_type exsk)
{
int bonus = 0;
if (_check_crosstrain(exsk, SK_SHORT_BLADES, SK_LONG_BLADES))
bonus += random2(3);
if (_check_crosstrain(exsk, SK_AXES, SK_POLEARMS))
bonus += random2(3);
if (_check_crosstrain(exsk, SK_POLEARMS, SK_STAVES))
bonus += random2(3);
if (_check_crosstrain(exsk, SK_AXES, SK_MACES_FLAILS))
bonus += random2(3);
if (_check_crosstrain(exsk, SK_MACES_FLAILS, SK_STAVES))
bonus += random2(3);
if (_check_crosstrain(exsk, SK_SLINGS, SK_THROWING))
bonus += random2(3);
return (10*bonus);
}
static bool _skip_exercise(skill_type exsk)
{
if (exsk < SK_SPELLCASTING || exsk > SK_EVOCATIONS)
return (false);
// Being good at elemental magic makes other elements harder to
// learn.
if (exsk >= SK_FIRE_MAGIC && exsk <= SK_EARTH_MAGIC
&& (you.skills[SK_FIRE_MAGIC] > you.skills[exsk]
|| you.skills[SK_ICE_MAGIC] > you.skills[exsk]
|| you.skills[SK_AIR_MAGIC] > you.skills[exsk]
|| you.skills[SK_EARTH_MAGIC] > you.skills[exsk]))
{
if (one_chance_in(3))
return (true);
}
// Some are direct opposites.
if ((exsk == SK_FIRE_MAGIC || exsk == SK_ICE_MAGIC)
&& (you.skills[SK_FIRE_MAGIC] > you.skills[exsk]
|| you.skills[SK_ICE_MAGIC] > you.skills[exsk]))
{
// Of course, this is cumulative with the one above.
if (!one_chance_in(3))
return (true);
}
if ((exsk == SK_AIR_MAGIC || exsk == SK_EARTH_MAGIC)
&& (you.skills[SK_AIR_MAGIC] > you.skills[exsk]
|| you.skills[SK_EARTH_MAGIC] > you.skills[exsk]))
{
if (!one_chance_in(3))
return (true);
}
// Experimental restriction (too many spell schools). -- bwr
// XXX: This also hinders Spellcasting and Inv/Evo.
// Count better non-elemental spell skills (up to 6)
int skill_rank = 1;
for (int i = SK_CONJURATIONS; i < SK_FIRE_MAGIC; ++i)
{
if (you.skills[exsk] < you.skills[i])
skill_rank++;
}
// Things get progressively harder, but not harder than
// the Fire-Air or Ice-Earth level.
// Note: 1 <= skill_rank <= 7, so (1 in 6) to (1 in 3).
if (skill_rank > 3 && one_chance_in(10 - skill_rank))
return (true);
return (false);
}
// These get a discount in the late game -- still required?
static bool _discounted_throwing_skill(skill_type exsk)
{
return (exsk == SK_THROWING || exsk == SK_BOWS || exsk == SK_CROSSBOWS);
}
static int _stat_mult(skill_type exsk, int skill_inc)
{
int stat = 10;
if ((exsk >= SK_FIGHTING && exsk <= SK_STAVES) || exsk == SK_ARMOUR)
{
// These skills are Easier for the strong.
stat = you.strength();
}
else if (exsk >= SK_SLINGS && exsk <= SK_UNARMED_COMBAT)
{
// These skills are easier for the dexterous.
// Note: Armour is handled above.
stat = you.dex();
}
else if (exsk >= SK_SPELLCASTING && exsk <= SK_POISON_MAGIC)
{
// These skills are easier for the smart.
stat = you.intel();
}
return (skill_inc * std::max<int>(5, stat) / 10);
}
static void _gain_skill_level(skill_type exsk)
{
skill_type old_best_skill = best_skill(SK_FIGHTING, (NUM_SKILLS - 1), 99);
you.skills[exsk]++;
take_note(Note(NOTE_GAIN_SKILL, exsk, you.skills[exsk]));
if (you.skills[exsk] == 27)
{
mprf(MSGCH_INTRINSIC_GAIN, "You have mastered %s!", skill_name(exsk));
}
else if (you.skills[exsk] == 1)
{
mprf(MSGCH_INTRINSIC_GAIN, "You have gained %s skill!", skill_name(exsk));
hints_gained_new_skill(exsk);
}
else
{
mprf(MSGCH_INTRINSIC_GAIN, "Your %s skill increases to level %d!",
skill_name(exsk), you.skills[exsk]);
}
learned_something_new(HINT_SKILL_RAISE);
// Recalculate this skill's order for tie breaking skills
// at its new level. See skills2.cc::init_skill_order()
// for more details. -- bwr
you.skill_order[exsk] = 0;
for (int i = SK_FIGHTING; i < NUM_SKILLS; ++i)
if (i != exsk && you.skills[i] >= you.skills[exsk])
you.skill_order[exsk]++;
if (exsk == SK_FIGHTING)
calc_hp();
if (exsk == SK_INVOCATIONS || exsk == SK_SPELLCASTING)
calc_mp();
if (exsk == SK_DODGING || exsk == SK_ARMOUR)
you.redraw_evasion = true;
if (exsk == SK_ARMOUR || exsk == SK_SHIELDS
|| exsk == SK_ICE_MAGIC || exsk == SK_EARTH_MAGIC
|| you.duration[DUR_TRANSFORMATION] > 0)
{
you.redraw_armour_class = true;
}
const skill_type best_spell = best_skill(SK_SPELLCASTING,
SK_POISON_MAGIC, 99);
if (exsk == SK_SPELLCASTING
&& you.skills[exsk] == 1 && best_spell == SK_SPELLCASTING)
{
mpr("You're starting to get the hang of this magic thing.");
}
const skill_type best = best_skill(SK_FIGHTING, (NUM_SKILLS - 1), 99);
if (best != old_best_skill || old_best_skill == exsk)
redraw_skill(you.your_name, player_title());
if (you.weapon() && item_is_staff(*you.weapon()))
maybe_identify_staff(*you.weapon());
}
static int _exercise2(int exski)
{
skill_type exsk = static_cast<skill_type>(exski);
// Being better at some magic skills makes others less likely to train.
// Note: applies to Invocations and Evocations, too! [rob]
if (_skip_exercise(exsk))
return (0);
// This will be added to you.skill_points[exsk];
int skill_inc = 10;
// This will be deducted from you.exp_available.
int cost = _calc_skill_cost(you.skill_cost_level, you.skills[exsk]);
// Being good at some weapons makes others easier to learn.
if (exsk < SK_ARMOUR)
skill_inc += _weap_crosstrain_bonus(exsk);
// Quick fix for the fact that stealth can't be gained fast enough
// to keep up with the monster levels. This should speed its
// advancement.
if (exsk == SK_STEALTH)
skill_inc += 10*random2(3);
// Starting to learn skills is easier if the appropriate stat is high.
if (you.skills[exsk] == 0)
skill_inc = _stat_mult(exsk, skill_inc);
// Spellcasting and Inv/Evo is cheaper early on.
if (exsk >= SK_SPELLCASTING && exsk <= SK_EVOCATIONS)
{
if (you.skill_cost_level < 5)
cost /= 2;
else if (you.skill_cost_level < 15)
{
cost *= (10 + (you.skill_cost_level - 5));
cost /= 20;
}
}
// Scale cost and skill_inc to available experience.
const int spending_limit = std::min(MAX_SPENDING_LIMIT, you.exp_available);
if (cost > spending_limit)
{
int frac = (spending_limit * 10) / cost;
// This system is a bit hard on missile weapons in the late
// game, since they require expendable ammo in order to
// practise. Increasing skill_inc would make
// missile weapons too easy earlier on, so, instead, we're
// giving them a special case here.
if (_discounted_throwing_skill(exsk)
&& cost <= you.exp_available)
{
// MAX_SPENDING_LIMIT < cost <= you.exp_available
frac = ((cost / 2) > MAX_SPENDING_LIMIT) ? 5 : 10;
}
cost = spending_limit;
skill_inc = (skill_inc * frac) / 10;
}
if (skill_inc <= 0)
return (0);
cost -= random2(5); // XXX: what's this for?
cost = std::max<int>(cost, 1); // No free lunch.
you.skill_points[exsk] += skill_inc;
you.exp_available -= cost;
you.total_skill_points += skill_inc;
if (you.skill_cost_level < 27
&& you.total_skill_points
>= skill_cost_needed(you.skill_cost_level + 1))
{
you.skill_cost_level++;
}
you.exp_available = std::max(0, you.exp_available);
you.redraw_experience = true;
const unsigned int next = skill_exp_needed(you.skills[exsk] + 1)
* species_skills(exsk, you.species) / 100;
if (you.skill_points[exsk] > next)
_gain_skill_level(exsk);
return (skill_inc);
}
|