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 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
|
#include "AppHdr.h"
#include "ng-setup.h"
#include "adjust.h"
#include "dungeon.h"
#include "end.h"
#include "files.h"
#include "god-companions.h"
#include "hints.h"
#include "invent.h"
#include "item-name.h"
#include "item-prop.h"
#include "items.h"
#include "item-use.h"
#include "jobs.h"
#include "message.h"
#include "mutation.h"
#include "ng-init.h"
#include "ng-wanderer.h"
#include "options.h"
#include "prompt.h"
#include "religion.h"
#include "shopping.h"
#include "skills.h"
#include "spl-book.h"
#include "spl-damage.h"
#include "spl-summoning.h"
#include "spl-util.h"
#include "state.h"
#include "tag-version.h"
#include "throw.h"
#include "transform.h"
#define MIN_START_STAT 3
static void _init_player()
{
you = player();
dlua.callfn("dgn_clear_persistant_data", "");
}
// Make sure no stats are unacceptably low
// (currently possible only for GhBe - 1KB)
static void _unfocus_stats()
{
int needed;
for (int i = 0; i < NUM_STATS; ++i)
{
int j = (i + 1) % NUM_STATS;
int k = (i + 2) % NUM_STATS;
if ((needed = MIN_START_STAT - you.base_stats[i]) > 0)
{
if (you.base_stats[j] > you.base_stats[k])
you.base_stats[j] -= needed;
else
you.base_stats[k] -= needed;
you.base_stats[i] = MIN_START_STAT;
}
}
}
// Some consumables to make the starts of Sprint a little easier.
static void _give_bonus_items()
{
newgame_make_item(OBJ_POTIONS, POT_CURING);
newgame_make_item(OBJ_POTIONS, POT_HEAL_WOUNDS);
newgame_make_item(OBJ_POTIONS, POT_HASTE);
newgame_make_item(OBJ_POTIONS, POT_MAGIC, 2);
newgame_make_item(OBJ_POTIONS, POT_BERSERK_RAGE);
newgame_make_item(OBJ_SCROLLS, SCR_BLINKING);
}
static void _autopickup_ammo(missile_type missile)
{
if (Options.autopickup_starting_ammo)
you.force_autopickup[OBJ_MISSILES][missile] = AP_FORCE_ON;
}
/**
* Make an item during character creation.
*
* Puts the item in the first available slot in the inventory, equipping or
* memorising the first spell from it as appropriate. If the item would be
* useless, we try with a possibly more useful sub_type, then, if it's still
* useless, give up and don't create any item.
*
* @param base, sub_type what the item is
* @param qty what size stack to make
* @param plus what the value of item_def::plus should be
* @param force_ego what the value of item_def::special should be
* @param force_tutorial whether to create it even in the tutorial
* @returns a pointer to the item created, if any.
*/
item_def* newgame_make_item(object_class_type base,
int sub_type, int qty, int plus,
int force_ego, bool force_tutorial)
{
// Don't set normal equipment in the tutorial.
if (!force_tutorial && crawl_state.game_is_tutorial())
return nullptr;
// not an actual item
// the WPN_UNKNOWN case is used when generating a paper doll during
// character creation
if (sub_type == WPN_UNARMED || sub_type == WPN_UNKNOWN)
return nullptr;
inventory_category category = inventory_category_for(base);
int slot;
int start = category == INVENT_CONSUMABLE ? MAX_GEAR : 0;
int end = category == INVENT_GEAR ? MAX_GEAR : ENDOFPACK;
for (slot = start; slot < end; ++slot)
{
item_def& item = you.inv[slot];
if (!item.defined())
break;
if (item.is_type(base, sub_type) && item.brand == force_ego
&& is_stackable_item(item))
{
item.quantity += qty;
return &item;
}
}
item_def &item(you.inv[slot]);
item.base_type = base;
item.sub_type = sub_type;
item.quantity = qty;
item.plus = plus;
item.brand = force_ego;
item.pos = ITEM_IN_INVENTORY;
item.link = slot;
// To mitigate higher shield penalties for smaller races, give small
// races bucklers instead of shields.
if (item.is_type(OBJ_ARMOUR, ARM_KITE_SHIELD) && you.body_size() < SIZE_MEDIUM)
item.sub_type = ARM_BUCKLER;
// If the character is restricted in wearing the requested armour,
// hand out a replacement instead.
if (item.base_type == OBJ_ARMOUR && !can_equip_item(item))
{
if (item.sub_type == ARM_HELMET || item.sub_type == ARM_HAT)
item.sub_type = ARM_HAT;
else if (item.sub_type == ARM_BUCKLER)
item.sub_type = ARM_KITE_SHIELD;
else if (is_shield(item))
item.sub_type = ARM_BUCKLER;
else if (get_armour_slot(item) == SLOT_BODY_ARMOUR
&& you.has_mutation(MUT_FORMLESS))
{
item.sub_type = ARM_CLOAK;
item.plus = max(item.plus, (short)1);
}
else
item.sub_type = ARM_ROBE;
}
// Make sure we didn't get a stack of shields or such nonsense.
ASSERT(item.quantity == 1 || is_stackable_item(item));
// If that didn't help, nothing will.
if (is_useless_item(item, false, true))
{
item = item_def();
return nullptr;
}
// Make sure branded and/or enchanted items appear as such.
item_set_appearance(item);
if (item_type_is_equipment(item.base_type))
autoequip_item(item);
if (item.base_type == OBJ_MISSILES)
_autopickup_ammo(static_cast<missile_type>(item.sub_type));
origin_set_startequip(item);
if (item.base_type == OBJ_WEAPONS && you.species == SP_COGLIN)
name_weapon(item);
seen_item(item);
return &item;
}
void give_throwing_ammo(int n)
{
if (species::can_throw_large_rocks(you.species))
newgame_make_item(OBJ_MISSILES, MI_LARGE_ROCK, n);
else if (you.body_size(PSIZE_TORSO) <= SIZE_SMALL)
newgame_make_item(OBJ_MISSILES, MI_BOOMERANG, 2*n);
else
newgame_make_item(OBJ_MISSILES, MI_JAVELIN, n);
}
static void _give_job_spells(job_type job)
{
vector<spell_type> spells = get_job_spells(job);
if (spells.empty())
return;
if (you.has_mutation(MUT_INNATE_CASTER))
{
for (spell_type s : spells)
if (you.spell_no < MAX_DJINN_SPELLS && !spell_is_useless(s, false))
add_spell_to_memory(s);
return;
}
library_add_spells(spells, true);
const spell_type first_spell = spells[0];
if (!spell_is_useless(first_spell, false, true)
&& spell_difficulty(first_spell) <= 1)
{
add_spell_to_memory(first_spell);
}
}
static void _give_offhand_weapon()
{
const item_def *wpn = you.weapon();
if (!wpn || you.offhand_item() || you.hands_reqd(*wpn) != HANDS_ONE)
return;
if (is_range_weapon(*wpn))
{
const int plus = you.char_class == JOB_HUNTER ? 0 : -2;
newgame_make_item(OBJ_WEAPONS, WPN_SLING, 1, plus);
}
else
newgame_make_item(OBJ_WEAPONS, WPN_DAGGER);
}
void give_items_skills(const newgame_def& ng)
{
// Set available equipment slots for the player before trying to give them
// any items.
you.equipment.update();
create_wanderer();
switch (you.char_class)
{
case JOB_BERSERKER:
you.religion = GOD_TROG;
you.raw_piety = 35;
if (you_can_wear(SLOT_BODY_ARMOUR) != false)
you.skills[SK_ARMOUR] += 2;
else
{
you.skills[SK_DODGING]++;
if (!is_useless_skill(SK_ARMOUR))
you.skills[SK_ARMOUR]++; // converted later
}
break;
case JOB_ARTIFICER:
{
if (species_apt(SK_ARMOUR) < species_apt(SK_DODGING))
you.skills[SK_DODGING]++;
else
you.skills[SK_ARMOUR]++;
break;
}
case JOB_CHAOS_KNIGHT:
{
you.religion = GOD_XOM;
you.raw_piety = 100;
int timeout_rnd = random2(40);
timeout_rnd += random2(40); // force a sequence point between random2s
you.gift_timeout = max(5, timeout_rnd);
if (species_apt(SK_ARMOUR) < species_apt(SK_DODGING))
you.skills[SK_DODGING]++;
else
you.skills[SK_ARMOUR]++;
break;
}
case JOB_CINDER_ACOLYTE:
you.religion = GOD_IGNIS;
you.raw_piety = 150;
break;
default:
break;
}
if (you.char_class == JOB_CHAOS_KNIGHT)
newgame_make_item(OBJ_WEAPONS, ng.weapon, 1, 0, SPWPN_CHAOS);
else if (you.char_class == JOB_CINDER_ACOLYTE)
newgame_make_item(OBJ_WEAPONS, ng.weapon, 1, -1, SPWPN_FLAMING);
else if (job_has_weapon_choice(you.char_class))
newgame_make_item(OBJ_WEAPONS, ng.weapon);
give_job_equipment(you.char_class);
give_job_skills(you.char_class);
_give_job_spells(you.char_class);
if (you.char_class == JOB_GLADIATOR)
give_throwing_ammo(1);
if (you.has_mutation(MUT_NO_GRASPING)) // i.e. felids
you.skills[SK_THROWING] = 0;
if (you.has_mutation(MUT_NO_ARMOUR)) // i.e. felids
you.skills[SK_SHIELDS] = 0; // i.e. FeFi
if (you.has_mutation(MUT_WIELD_OFFHAND))
{
// Coglins would rather have two slings than one bow.
if (you.char_class == JOB_HUNTER)
{
item_def *wpn = you.weapon();
unequip_item(*wpn, false, true);
wpn->sub_type = WPN_SLING;
wpn->plus = 2;
autoequip_item(*wpn);
}
_give_offhand_weapon();
}
if (!you_worship(GOD_NO_GOD))
{
you.worshipped[you.religion] = 1;
set_god_ability_slots();
if (!you_worship(GOD_XOM))
you.piety_max[you.religion] = you.raw_piety;
}
if (crawl_state.game_is_descent())
you.attribute[ATTR_VOUCHER] = 1;
}
static void _setup_tutorial_miscs()
{
// Allow for a few specific hint mode messages.
// A few more will be initialised by the tutorial map.
tutorial_init_hints();
// No gold to begin with.
you.gold = 0;
// Give them some mana to play around with.
you.mp_max_adj += 2;
newgame_make_item(OBJ_ARMOUR, ARM_ROBE, 1, 0, 0, true);
// No need for Shields skill without shield.
you.skills[SK_SHIELDS] = 0;
// Some spellcasting for the magic tutorial.
if (crawl_state.map.find("tutorial_lesson4") != string::npos)
you.skills[SK_SPELLCASTING] = 1;
}
static void _give_basic_knowledge()
{
identify_inventory();
mark_inventory_sets_unknown();
// Removed item types are handled in _set_removed_types_as_identified.
}
static void _setup_generic(const newgame_def& ng,
bool normal_dungeon_setup /*for catch2-tests*/);
// Initialise a game based on the choice stored in ng.
void setup_game(const newgame_def& ng,
bool normal_dungeon_setup /*for catch2-tests */)
{
crawl_state.type = ng.type; // by default
if (Options.seed_from_rc && ng.type != GAME_TYPE_CUSTOM_SEED)
{
// rc seed overrides seed from other sources, and forces a normal game
// to be a custom seed game. There is currently no special designation
// for sprint etc. games that involve a custom seed.
// TODO: does this make any sense for hints mode?
Options.seed = Options.seed_from_rc;
if (ng.type == GAME_TYPE_NORMAL)
crawl_state.type = GAME_TYPE_CUSTOM_SEED;
}
else if (Options.seed && ng.type != GAME_TYPE_CUSTOM_SEED)
{
// there's a seed lingering in the options, but we shouldn't use it.
Options.seed = 0;
}
else if (!Options.seed && ng.type == GAME_TYPE_CUSTOM_SEED)
crawl_state.type = GAME_TYPE_NORMAL;
crawl_state.map = ng.map;
switch (crawl_state.type)
{
case GAME_TYPE_NORMAL:
case GAME_TYPE_DESCENT:
case GAME_TYPE_CUSTOM_SEED:
case GAME_TYPE_TUTORIAL:
case GAME_TYPE_SPRINT:
break;
case GAME_TYPE_HINTS:
init_hints();
break;
case GAME_TYPE_ARENA:
default:
die("Bad game type");
end(-1);
}
_setup_generic(ng, normal_dungeon_setup);
}
static bool _spell_triggered_by(spell_type to_trigger, spell_type trigger)
{
switch (to_trigger)
{
case SPELL_BATTLESPHERE:
return battlesphere_can_mirror(trigger);
case SPELL_SPELLSPARK_SERVITOR:
return spell_servitorable(trigger);
case SPELL_PERCUSSIVE_TEMPERING:
return trigger == SPELL_CLOCKWORK_BEE
|| trigger == SPELL_WALKING_ALEMBIC
|| trigger == SPELL_PHALANX_BEETLE
|| trigger == SPELL_MONARCH_BOMB
|| trigger == SPELL_FORGE_LIGHTNING_SPIRE
|| trigger == SPELL_FORGE_BLAZEHEART_GOLEM
|| trigger == SPELL_RENDING_BLADE
|| trigger == SPELL_BATTLESPHERE
|| trigger == SPELL_SPLINTERFROST_SHELL
|| trigger == SPELL_PLATINUM_PARAGON;
default:
return true;
}
}
static bool _spell_has_trigger(spell_type to_trigger,
const set<spell_type> &triggers)
{
for (spell_type trigger : triggers)
if (_spell_triggered_by(to_trigger, trigger))
return true;
return _spell_triggered_by(to_trigger, SPELL_NO_SPELL);
}
static void _setup_innate_spells()
{
set<spell_type> spellset;
// Start with all spells from your job.
for (spell_type sp : you.spells)
if (sp != SPELL_NO_SPELL)
spellset.insert(sp);
// Get spells at XL 3 and every odd level thereafter.
vector<spell_type> chosen_spells;
int const min_lev[] = {1,2, 2,3,4, 5,6,6, 6,7,7, 8,9};
int const max_lev[] = {1,2, 3,4,5, 5,6,7, 7,8,8, 9,9};
for (int i = 0; i < 27 / 2; i++)
{
spell_type next_spell = SPELL_NO_SPELL;
int seen = 0;
for (int s = 0; s < NUM_SPELLS; ++s)
{
const spell_type spell = static_cast<spell_type>(s);
if (!is_player_book_spell(spell)
|| spellset.find(spell) != spellset.end()
|| spell_is_useless(spell, false)
|| !_spell_has_trigger(spell, spellset))
{
continue;
}
const int lev = spell_difficulty(spell);
if (lev >= min_lev[i] && lev <= max_lev[i]
&& one_chance_in(++seen))
{
next_spell = spell;
}
}
ASSERT(next_spell != SPELL_NO_SPELL);
spellset.insert(next_spell);
chosen_spells.push_back(next_spell);
}
for (spell_type s : chosen_spells)
you.props[INNATE_SPELLS_KEY].get_vector().push_back(s);
}
void initial_dungeon_setup()
{
rng::generator levelgen_rng(BRANCH_DUNGEON);
initialise_branch_depths();
initialise_temples();
init_level_connectivity();
initialise_item_descriptions();
you.zot_orb_monster = random_choose(MONS_ORB_OF_FIRE,
MONS_ORB_OF_WINTER,
MONS_ORB_OF_ENTROPY);
}
static void _setup_generic(const newgame_def& ng,
bool normal_dungeon_setup /*for catch2-tests*/)
{
// this seems non-ideal, but messages are not being displayed at this point
// so if a force_more_message triggers, the more will just show on a blank
// screen. TODO: it's not clear to me why the more can show up without
// the message that triggered it.
unwind_bool no_more(crawl_state.show_more_prompt, false);
rng::reset(); // initialize rng from Options.seed
_init_player();
you.game_seed = crawl_state.seed;
you.deterministic_levelgen =
Options.pregen_dungeon != level_gen_type::classic;
#if TAG_MAJOR_VERSION == 34
// Avoid the remove_dead_shops() Gozag fixup in new games: see
// ShoppingList::item_type_identified().
you.props[REMOVED_DEAD_SHOPS_KEY] = true;
#endif
// Needs to happen before we give the player items, so that item specs
// in job descriptions can be parsed safely.
initialise_item_sets();
// Needs to happen before we give the player items, so that it's safe to
// check whether those items need to be removed from their shopping list.
shopping_list.refresh();
you.your_name = ng.name;
you.species = ng.species;
you.char_class = ng.job;
you.chr_class_name = get_job_name(you.char_class);
species_stat_init(you.species); // must be down here {dlb}
// Before we get into the inventory init, set light radius based
// on species vision.
update_vision_range();
job_stat_init(you.char_class);
_unfocus_stats();
give_basic_mutations(you.species);
// This function depends on stats and mutations being finalised.
give_items_skills(ng);
roll_demonspawn_mutations();
if (you.has_mutation(MUT_MULTILIVED))
you.lives = 1;
if (crawl_state.game_is_sprint())
_give_bonus_items();
// Give tutorial skills etc
if (crawl_state.game_is_tutorial())
_setup_tutorial_miscs();
_give_basic_knowledge();
// intentionally create the subgenerator either way, so that this has the
// same impact on the current main rng for all chars.
rng::subgenerator dj_rng;
if (you.has_mutation(MUT_INNATE_CASTER))
_setup_innate_spells();
// A first pass to link the items properly.
for (int i = 0; i < ENDOFPACK; ++i)
{
auto &item = you.inv[i];
if (!item.defined())
continue;
item.pos = ITEM_IN_INVENTORY;
item.link = i;
// If consumables end up on a non-letter, auto_assign_item_slot below will crash.
item.slot = index_to_letter(item.link >= MAX_GEAR
? item.link - MAX_GEAR
: item.link);
item_colour(item); // set correct special and colour
}
// Put our weapon in our first item slot, if we have one.
if (item_def* wpn = you.weapon())
swap_inv_slots(*wpn, 0, false);
// A second pass to apply the item_slot option.
for (auto &item : you.inv)
{
if (!item.defined())
continue;
if (!item.props.exists("adjusted"))
{
item.props["adjusted"] = true;
auto_assign_item_slot(item, true);
}
}
if (you.char_class == JOB_SHAPESHIFTER)
{
const item_def* talisman = nullptr;
for (auto& item : you.inv)
{
if (item.is_type(OBJ_TALISMANS, TALISMAN_QUILL))
{
talisman = &item;
break;
}
}
ASSERT(talisman);
set_default_form(transformation::quill, talisman);
set_form(transformation::quill, 1); // hacky...
}
reassess_starting_skills(false);
init_skill_order();
init_can_currently_train();
init_train();
if (you.religion == GOD_TROG)
join_trog_skills();
init_training();
if (you.has_mutation(MUT_INNATE_CASTER))
cleanup_innate_magic_skills();
// Apply autoinscribe rules to inventory.
request_autoinscribe();
autoinscribe();
// We calculate hp and mp here; all relevant factors should be
// finalised by now. (GDL)
calc_hp();
calc_mp();
// Make sure the starting player is fully charged up.
set_hp(you.hp_max);
set_mp(you.max_magic_points);
if (normal_dungeon_setup)
initial_dungeon_setup();
// Generate the second name of Jiyva
fix_up_jiyva_name();
// Get rid of god companions left from previous games
init_companions();
// Create the save file.
if (Options.no_save)
you.save = new package();
else
you.save = new package(get_savedir_filename(you.your_name).c_str(),
true, true);
// pregen temple -- it's quick and easy, and this prevents a popup from
// happening. This needs to happen after you.save is created.
if (normal_dungeon_setup && you.deterministic_levelgen &&
!crawl_state.game_is_descent() && // disables temple
!pregen_dungeon(level_id(BRANCH_TEMPLE, 1)))
{
die("Builder failure while trying to generate temple!");
}
}
|