File: god-item.cc

package info (click to toggle)
crawl 2%3A0.33.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,264 kB
  • sloc: cpp: 358,145; ansic: 27,203; javascript: 9,491; python: 8,359; perl: 3,327; java: 2,667; xml: 2,191; makefile: 1,830; sh: 611; objc: 250; cs: 15; sed: 9; lisp: 3
file content (463 lines) | stat: -rw-r--r-- 11,747 bytes parent folder | download | duplicates (2)
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
/**
 * @file
 * @brief Gods' attitude towards items.
**/

#include "AppHdr.h"

#include "god-item.h"

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>

#include "artefact.h"
#include "art-enum.h"
#include "god-conduct.h"
#include "god-passive.h"
#include "item-name.h"
#include "item-prop.h"
#include "item-status-flag-type.h"
#include "items.h"
#include "libutil.h"
#include "potion-type.h"
#include "religion.h"
#include "skills.h"
#include "spl-book.h"
#include "spl-util.h"

static bool _is_book_type(const item_def& item,
                          bool (*matches)(spell_type spell))
{
    if (!item.defined())
        return false;

    // Return false for item_defs of unknown subtype
    // (== NUM_BOOKS in most cases, OBJ_RANDOM for acquirement)
    if (item.sub_type == get_max_subtype(item.base_type)
        || item.sub_type == OBJ_RANDOM)
    {
        return false;
    }

    if (!item_is_spellbook(item))
        return false;

    // Book matches only if all the spells match
    for (spell_type spell : spells_in_book(item))
    {
        if (!matches(spell))
            return false;
    }
    return true;
}

bool is_holy_item(const item_def& item, bool calc_unid)
{
    if (is_unrandom_artefact(item))
    {
        const unrandart_entry* entry = get_unrand_entry(item.unrand_idx);

        if (entry->flags & UNRAND_FLAG_HOLY)
            return true;
    }

    if (item.base_type == OBJ_WEAPONS)
    {
        if (is_blessed(item))
            return true;
        if (calc_unid || item.is_identified())
            return get_weapon_brand(item) == SPWPN_HOLY_WRATH;
    }

    return false;
}

bool is_potentially_evil_item(const item_def& item, bool calc_unid)
{
    if (item.base_type == OBJ_WEAPONS
        && item.is_identified()
        && get_weapon_brand(item) == SPWPN_CHAOS)
    {
        return true;
    }

    if (!calc_unid && !item.is_identified())
        return false;

    switch (item.base_type)
    {
    case OBJ_MISSILES:
        {
        const int item_brand = get_ammo_brand(item);
        if (item_brand == SPMSL_CHAOS)
            return true;
        }
        break;
    default:
        break;
    }

    return false;
}

bool is_evil_brand(int brand)
{
    switch (brand)
    {
    case SPWPN_DRAINING:
    case SPWPN_PAIN:
    case SPWPN_VAMPIRISM:
    case SPWPN_REAPING:
    case SPWPN_CHAOS:
    case SPWPN_DISTORTION:
    case SPWPN_FOUL_FLAME:
        return true;
    default:
        return false;
    }
}

bool is_chaotic_brand(int brand)
{
    return brand == SPWPN_CHAOS || brand == SPWPN_DISTORTION;
}

bool is_hasty_brand(int brand)
{
    return brand == SPWPN_CHAOS || brand == SPWPN_SPEED;
}

/**
 * Do good gods always hate use of this item?
 *
 * @param item      The item in question.
 * @param calc_unid Whether to take into account facts the player does not know.
 * @return          Whether the Good Gods will always frown on this item's use.
 */
bool is_evil_item(const item_def& item, bool calc_unid)
{
    if (is_unrandom_artefact(item))
    {
        const unrandart_entry* entry = get_unrand_entry(item.unrand_idx);

        if (entry->flags & UNRAND_FLAG_EVIL)
            return true;
    }

    if (item.base_type == OBJ_WEAPONS)
    {
        if (is_demonic(item) || testbits(item.flags, ISFLAG_CHAOTIC))
            return true;
        if (calc_unid || item.is_identified())
            return is_evil_brand(get_weapon_brand(item));
    }

    if (!calc_unid && !item.is_identified())
        return false;

    switch (item.base_type)
    {
    case OBJ_SCROLLS:
        return item.sub_type == SCR_TORMENT;
    case OBJ_STAVES:
        return item.sub_type == STAFF_DEATH;
    case OBJ_MISCELLANY:
        return item.sub_type == MISC_HORN_OF_GERYON;
    case OBJ_BOOKS:
        return _is_book_type(item, is_evil_spell);
    case OBJ_TALISMANS:
        return item.sub_type == TALISMAN_DEATH
                || item.sub_type == TALISMAN_VAMPIRE;
    default:
        return false;
    }
}

bool is_unclean_item(const item_def& item, bool calc_unid)
{
    if (is_unrandom_artefact(item))
    {
        const unrandart_entry* entry = get_unrand_entry(item.unrand_idx);

        if ((entry->flags & (UNRAND_FLAG_EVIL)
            || testbits(item.flags, ISFLAG_CHAOTIC)))
        {
            return true;
        }
    }

    if (item.has_spells() && (item.is_identified() || calc_unid))
        return _is_book_type(item, is_unclean_spell);

    return false;
}

bool is_chaotic_item(const item_def& item, bool calc_unid)
{
    if (is_unrandom_artefact(item))
    {
        const unrandart_entry* entry = get_unrand_entry(item.unrand_idx);

        if (entry->flags & UNRAND_FLAG_CHAOTIC ||
           (testbits(item.flags, ISFLAG_CHAOTIC)))
        {
            return true;
        }
    }

    if (item.base_type == OBJ_WEAPONS
        && (calc_unid || item.is_identified()))
    {
        return is_chaotic_brand(get_weapon_brand(item));
    }

    if (!calc_unid && !item.is_identified())
        return false;

    switch (item.base_type)
    {
    case OBJ_MISSILES:
        return get_ammo_brand(item) == SPMSL_CHAOS;
    case OBJ_WANDS:
        return item.sub_type == WAND_POLYMORPH;
    case OBJ_POTIONS:
        return (item.sub_type == POT_MUTATION
                            && !have_passive(passive_t::cleanse_mut_potions))
                 || item.sub_type == POT_LIGNIFY;
    case OBJ_BOOKS:
        return item.sub_type == BOOK_MANUAL && item.plus == SK_SHAPESHIFTING
               || _is_book_type(item, is_chaotic_spell);
    case OBJ_MISCELLANY:
        return item.sub_type == MISC_BOX_OF_BEASTS;
    case OBJ_TALISMANS:
    case OBJ_BAUBLES:
        return true;
    default:
        return false;
    }
}

static bool _is_potentially_hasty_item(const item_def& item)
{
    if (item.base_type == OBJ_WEAPONS
        && (item.is_identified() && get_weapon_brand(item) == SPWPN_CHAOS)
        || (testbits(item.flags, ISFLAG_CHAOTIC)))
    {
        return true;
    }

    if (!item.is_identified())
        return false;

    switch (item.base_type)
    {
    case OBJ_MISSILES:
        {
        const int item_brand = get_ammo_brand(item);
        if (item_brand == SPMSL_CHAOS || item_brand == SPMSL_FRENZY)
            return true;
        }
        break;
    default:
        break;
    }

    return false;
}

bool is_hasty_item(const item_def& item, bool calc_unid)
{

    if (is_artefact(item) && item.base_type != OBJ_BOOKS)
    {
        if ((calc_unid || item.is_identified()))
        {
            if (artefact_property(item, ARTP_RAMPAGING))
                return true;
            // intentionally continue to other hasty checks
        }
    }

    if (item.base_type == OBJ_WEAPONS)
    {
        if (calc_unid || item.is_identified())
            return get_weapon_brand(item) == SPWPN_SPEED;
    }

    if (!calc_unid && !item.is_identified())
        return false;

    switch (item.base_type)
    {
    case OBJ_ARMOUR:
        return get_armour_rampaging(item, true)
               || get_armour_ego_type(item) == SPARM_MAYHEM
               || is_unrandom_artefact(item, UNRAND_LIGHTNING_SCALES);
    case OBJ_POTIONS:
        return item.sub_type == POT_HASTE;
    case OBJ_BOOKS:
        return _is_book_type(item, is_hasty_spell);
    default:
        break;
    }

    return false;
}

bool is_wizardly_item(const item_def& item, bool calc_unid)
{
    if ((calc_unid || item.is_identified())
        && get_armour_ego_type(item) == SPARM_ENERGY)
    {
        return true;
    }

    if (is_unrandom_artefact(item, UNRAND_WUCAD_MU)
        || is_unrandom_artefact(item, UNRAND_MAGE)
        || is_unrandom_artefact(item, UNRAND_MAJIN)
        || is_unrandom_artefact(item, UNRAND_BATTLE)
        || is_unrandom_artefact(item, UNRAND_ELEMENTAL_STAFF)
        || is_unrandom_artefact(item, UNRAND_OLGREB))
    {
        return true;
    }

    return item.base_type == OBJ_STAVES;
}

/**
 * Do the good gods hate use of this spell?
 *
 * @param spell     The spell in question; e.g. SPELL_PUTREFACTION.
 * @return          Whether the Good Gods hate this spell.
 */
bool is_evil_spell(spell_type spell)
{
    const spschools_type disciplines = get_spell_disciplines(spell);
    spell_flags flags = get_spell_flags(spell);

    if (flags & spflag::unholy)
        return true;
    return bool(disciplines & spschool::necromancy)
           && !bool(flags & spflag::not_evil);
}

bool is_unclean_spell(spell_type spell)
{
    spell_flags flags = get_spell_flags(spell);

    return bool(flags & spflag::unclean);
}

bool is_chaotic_spell(spell_type spell)
{
    spell_flags flags = get_spell_flags(spell);

    return bool(flags & spflag::chaotic);
}

bool is_hasty_spell(spell_type spell)
{
    spell_flags flags = get_spell_flags(spell);

    return bool(flags & spflag::hasty);
}

/**
 * What conducts can one violate using this item?
 * This should only be based on the player's knowledge.
 *
 * @param item  The item in question.
 * @return      List of conducts that can be violated with this; empty if none.
 */
vector<conduct_type> item_conducts(const item_def &item)
{
    vector<conduct_type> conducts;

    if (is_evil_item(item, false))
        conducts.push_back(DID_EVIL);

    if (is_unclean_item(item, false))
        conducts.push_back(DID_UNCLEAN);

    if (is_chaotic_item(item, false))
        conducts.push_back(DID_CHAOS);

    if (is_holy_item(item, false))
        conducts.push_back(DID_HOLY);

    if (item_is_spellbook(item))
        conducts.push_back(DID_SPELL_MEMORISE);

    if ((item.sub_type == BOOK_MANUAL && is_magic_skill((skill_type)item.plus)))
        conducts.push_back(DID_SPELL_PRACTISE);

    if (is_wizardly_item(item, false))
        conducts.push_back(DID_WIZARDLY_ITEM);

    if (_is_potentially_hasty_item(item) || is_hasty_item(item, false))
        conducts.push_back(DID_HASTY);

    if (is_potentially_evil_item(item, false))
        conducts.push_back(DID_EVIL);

    return conducts;
}

bool god_hates_item(const item_def &item)
{
    return god_hates_item_handling(item) != DID_NOTHING;
}

bool god_despises_item(const item_def &item, god_type which_god)
{
    if (item.base_type != OBJ_TALISMANS)
        return false;
    return (item.sub_type == TALISMAN_DEATH || item.sub_type == TALISMAN_VAMPIRE)
                && is_good_god(which_god)
           || which_god == GOD_ZIN;
}

/**
 * Does the given god like items of the given kind enough to make artefacts
 * from them? (Thematically.)
 *
 * @param item          The item which may be the basis for an artefact.
 * @param which_god     The god in question.
 * @return              Whether it makes sense for the given god to make an
 *                      artefact out of the given item. Thematically.
 *                      (E.g., Ely shouldn't be forging swords.)
 */
bool god_likes_item_type(const item_def &item, god_type which_god)
{
    if (god_despises_item(item, which_god))
        return false;
    // XXX: also check god_hates_item()?
    // XXXX: if someone does this, make sure to generalize so that it doesn't
    // use `you.religion`; this code is potentially called in item generation
    // for artefact names
    switch (which_god)
    {
        case GOD_ELYVILON: // Peaceful healer god: no weapons.
        case GOD_SIF_MUNA: // The magic gods: no weapons.
        case GOD_VEHUMET:
            if (item.base_type == OBJ_WEAPONS)
                return false;
            break;

        case GOD_TROG:
            // Berserker god: weapons only.
            if (item.base_type != OBJ_WEAPONS)
                return false;
            break;

        default:
            break;
    }

    return true;
}