summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/art-func.h
blob: d0bbfd815103fd8aa8f9451029c0c2be183c548b (plain) (blame)
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
/*
 * File:       art-func.h
 * Summary:    Functions non-standard unrandarts uses.
 * Written by: Matthew Cline
 */

/*
 * util/art-data.pl scans through this file to grab the functions
 * non-standard unrandarts use and put them into the unranddata structs
 * in art-data.h, so the function names must have the form of
 * _UNRAND_ENUM_func_name() in order to be recognised.
 */

#ifdef ART_FUNC_H
#error "art-func.h included twice!"
#endif

#ifdef ART_DATA_H
#error "art-func.h must be included before art-data.h"
#endif

#define ART_FUNC_H

#include "cloud.h"    // For storm's bow rain
#include "effects.h"  // For Sceptre of Torment tormenting
#include "env.h"      // For storm bow env.cgrid
#include "food.h"     // For evokes
#include "mgen_data.h" // For Sceptre of Asmodeus evoke
#include "mon-place.h" // For Sceptre of Asmodeus evoke
#include "mon-stuff.h" // For Scythe of Curses cursing items
#include "spells3.h"  // For Zonguldrok animating dead
#include "spl-cast.h" // For evokes
#include "spl-mis.h"  // For Staff of Wucad Mu miscasts
#include "terrain.h"  // For storm bow.

/*******************
 * Helper functions.
 *******************/

static void _equip_mpr(bool* show_msgs, const char* msg,
                       msg_channel_type chan = MSGCH_PLAIN)
{
    bool def_show = true;

    if (show_msgs == NULL)
        show_msgs = &def_show;

    if (*show_msgs)
        mpr(msg, chan);

    // Caller shouldn't give any more messages.
    *show_msgs = false;
}

/*******************
 * Unrand functions.
 *******************/

static void _ASMODEUS_melee_effect(item_def* weapon, actor* attacker,
                                   actor* defender, bool mondied)
{
    if (attacker->atype() == ACT_PLAYER)
    {
        did_god_conduct(DID_UNHOLY, 3);
    }
}

static bool _evoke_sceptre_of_asmodeus()
{
    bool rc = true;
    if (one_chance_in(21))
        rc = false;
    else if (one_chance_in(20))
    {
        // Summon devils, maybe a Fiend.
        const monster_type mon = (one_chance_in(4) ? MONS_FIEND :
                                     summon_any_demon(DEMON_COMMON));
        const bool good_summon = create_monster(
                                     mgen_data::hostile_at(mon,
                                         "the Sceptre of Asmodeus",
                                         true, 6, 0, you.pos())) != -1;

        if (good_summon)
        {
            if (mon == MONS_FIEND)
                mpr("\"Your arrogance condemns you, mortal!\"");
            else
                mpr("The Sceptre summons one of its servants.");
        }
        else
            mpr("The air shimmers briefly.");
    }
    else
    {
        // Cast a destructive spell.
        const spell_type spl = static_cast<spell_type>(
            random_choose_weighted(114, SPELL_BOLT_OF_FIRE,
                                   57,  SPELL_LIGHTNING_BOLT,
                                   57,  SPELL_BOLT_OF_DRAINING,
                                   12,  SPELL_HELLFIRE,
                                   0));
        your_spells(spl, you.skills[SK_EVOCATIONS] * 8, false);
    }

    return (rc);
}


static bool _ASMODEUS_evoke(item_def *item, int* pract, bool* did_work,
                            bool* unevokable)
{
    if (_evoke_sceptre_of_asmodeus())
    {
        make_hungry(200, false, true);
        *did_work = true;
        *pract    = 1;
    }

    return (false);
}

////////////////////////////////////////////////////

// XXX: Defender's resistance to fire being temporarily downgraded is
// hardcoded in melee_attack::fire_res_apply_cerebov_downgrade()

static void _CEREBOV_melee_effect(item_def* weapon, actor* attacker,
                                  actor* defender, bool mondied)
{
    if (attacker->atype() == ACT_PLAYER)
    {
        did_god_conduct(DID_UNHOLY, 3);
    }
}

////////////////////////////////////////////////////

static void _CURSES_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    _equip_mpr(show_msgs, "A shiver runs down your spine.");
}

static void _CURSES_world_reacts(item_def *item)
{
    if (one_chance_in(30))
        curse_an_item(false);
}

static void _CURSES_melee_effect(item_def* weapon, actor* attacker,
                                 actor* defender, bool mondied)
{
    if (attacker->atype() == ACT_PLAYER)
    {
        did_god_conduct(DID_NECROMANCY, 3);
    }
}

/////////////////////////////////////////////////////

static void _DISPATER_melee_effect(item_def* weapon, actor* attacker,
                                   actor* defender, bool mondied)
{
    if (attacker->atype() == ACT_PLAYER)
    {
        did_god_conduct(DID_UNHOLY, 3);
    }
}

static bool _DISPATER_evoke(item_def *item, int* pract, bool* did_work,
                            bool* unevokable)
{
    if (you.duration[DUR_DEATHS_DOOR] || !enough_hp(11, true)
        || !enough_mp(5, true))
    {
        return (false);
    }

    mpr("You feel the staff feeding on your energy!");

    dec_hp( 5 + random2avg(19, 2), false, "Staff of Dispater" );
    dec_mp( 2 + random2avg(5, 2) );
    make_hungry(100, false, true);

    int power = you.skills[SK_EVOCATIONS] * 8;
    your_spells( SPELL_HELLFIRE, power, false );

    *pract    = (coinflip() ? 2 : 1);
    *did_work = true;

    return (false);
}

////////////////////////////////////////////////////

// XXX: Staff giving a boost to poison spells is hardcoded in
// player_spec_poison()

static void _olgreb_pluses(item_def *item)
{
    // Giving Olgreb's staff a little lift since staves of poison have
    // been made better. -- bwr
    item->plus  = you.skills[SK_POISON_MAGIC] / 3;
    item->plus2 = item->plus;
}

static void _OLGREB_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    if (you.can_smell())
        _equip_mpr(show_msgs, "You smell chlorine.");
    else
        _equip_mpr(show_msgs, "The staff glows a sickly green.");

    _olgreb_pluses(item);
}

static void _OLGREB_unequip(const item_def *item, bool *show_msgs)
{
    if (you.can_smell())
        _equip_mpr(show_msgs, "The smell of chlorine vanishes.");
    else
        _equip_mpr(show_msgs, "The staff's sickly green glow vanishes.");
}

static void _OLGREB_world_reacts(item_def *item)
{
    _olgreb_pluses(item);
}

static bool _OLGREB_evoke(item_def *item, int* pract, bool* did_work,
                          bool* unevokable)
{
    if (!enough_mp( 4, true ) || you.skills[SK_EVOCATIONS] < random2(6))
        return (false);

    dec_mp(4);
    make_hungry(50, false, true);
    *pract    = 1;
    *did_work = true;

    int power = 10 + you.skills[SK_EVOCATIONS] * 8;

    your_spells( SPELL_OLGREBS_TOXIC_RADIANCE, power, false );

    if (x_chance_in_y(you.skills[SK_EVOCATIONS] + 1, 10))
        your_spells( SPELL_VENOM_BOLT, power, false );

    return (false);
}

////////////////////////////////////////////////////

static void _power_pluses(item_def *item)
{
    item->plus  = stepdown_value( -4 + (you.hp / 5), 4, 4, 4, 20 );
    item->plus2 = item->plus;
}

static void _POWER_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    _equip_mpr(show_msgs, "You sense an aura of extreme power.");
    _power_pluses(item);
}

static void _POWER_world_reacts(item_def *item)
{
    _power_pluses(item);
}

////////////////////////////////////////////////////

static void _SINGING_SWORD_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    bool def_show = true;

    if (show_msgs == NULL)
        show_msgs = &def_show;

    if (!*show_msgs)
        return;

    if (item_type_known(*item))
    {
        mprf(MSGCH_TALK, "%s says, \"Hi!  I'm the Singing Sword!\"",
             item->name(DESC_CAP_THE).c_str());
    }
    else
        mpr("The Singing Sword hums in delight!", MSGCH_TALK);

    *show_msgs = false;
}

static void _SINGING_SWORD_unequip(const item_def *item, bool *show_msgs)
{
    _equip_mpr(show_msgs, "The Singing Sword sighs.", MSGCH_TALK);
}

////////////////////////////////////////////////////

static void _PRUNE_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    _equip_mpr(show_msgs, "You feel pruney.");
}

////////////////////////////////////////////////////

static void _TORMENT_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    _equip_mpr(show_msgs, "A terribly searing pain shoots up your arm!");
}

static void _TORMENT_world_reacts(item_def *item)
{
    if (one_chance_in(200))
    {
        torment(TORMENT_SPWLD, you.pos());
        did_god_conduct(DID_UNHOLY, 1);
    }
}

static void _TORMENT_melee_effect(item_def* weapon, actor* attacker,
                                  actor* defender, bool mondied)
{
    if (attacker->atype() == ACT_PLAYER && coinflip())
    {
        torment(TORMENT_SPWLD, you.pos());
        did_god_conduct(DID_UNHOLY, 5);
    }
}

/////////////////////////////////////////////////////

static void _TROG_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    _equip_mpr(show_msgs, "You feel bloodthirsty!");
}

static void _TROG_unequip(const item_def *item, bool *show_msgs)
{
    _equip_mpr(show_msgs, "You feel less violent.");
}

static void _TROG_melee_effect(item_def* weapon, actor* attacker,
                               actor* defender, bool mondied)
{
    if (coinflip())
        attacker->go_berserk(false);
}

////////////////////////////////////////////////////

static void _wucad_miscast(actor* victim, int power,int fail)
{
    MiscastEffect(victim, WIELD_MISCAST, SPTYP_DIVINATION, power, fail,
                  "the Staff of Wucad Mu", NH_NEVER);
}

static void _wucad_pluses(item_def *item)
{
    item->plus  = std::min(you.intel - 3, 22);
    item->plus2 = std::min(you.intel / 2, 13);
}

static void _WUCAD_MU_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    _wucad_miscast(&you, 9, 90);
    _wucad_pluses(item);
}

static void _WUCAD_MU_unequip(const item_def *item, bool *show_msgs)
{
    _wucad_miscast(&you, 9, 90);
}

static void _WUCAD_MU_world_reacts(item_def *item)
{
    _wucad_pluses(item);
}

static void _WUCAD_MU_melee_effect(item_def* weapon, actor* attacker,
                                   actor* defender, bool mondied)
{
    if (one_chance_in(9))
        _wucad_miscast(attacker, random2(9), random2(70));
}

static bool _WUCAD_MU_evoke(item_def *item, int* pract, bool* did_work,
                            bool* unevokable)
{
    if (you.magic_points == you.max_magic_points
        || you.skills[SK_EVOCATIONS] < random2(25))
    {
        return (false);
    }

    mpr("Magical energy flows into your mind!");

    inc_mp( 3 + random2(5) + you.skills[SK_EVOCATIONS] / 3, false );
    make_hungry(50, false, true);

    *pract    = 1;
    *did_work = true;

    if (one_chance_in(3))
        _wucad_miscast(&you, random2(9), random2(70));

    return (false);
}

///////////////////////////////////////////////////

// XXX: Always getting maximal vampiric drain is hardcoded in
// melee_attack::apply_damage_brand()

static void _VAMPIRES_TOOTH_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    if (you.is_undead != US_UNDEAD)
    {
        _equip_mpr(show_msgs,
                   "You feel a strange hunger, and smell blood in the air...");
    }
    else
        _equip_mpr(show_msgs, "You feel strangely empty.");

    // Vampire's Tooth imposes more hunger than a normal vampiric
    // weapon.  Like other vampiric weapons, the hunger is less for
    // vampires than for other species.
    if (you.species != SP_VAMPIRE)
        artefact_set_property(*item, ARTP_METABOLISM, 3);
    else
        artefact_set_property(*item, ARTP_METABOLISM, 1);
}

///////////////////////////////////////////////////

// XXX: Pluses at creation time are hardcoded in make_item_unrandart()

static void _VARIABILITY_world_reacts(item_def *item)
{
    do_uncurse_item(*item);

    if (x_chance_in_y(2, 5))
        item->plus  += (coinflip() ? +1 : -1);

    if (x_chance_in_y(2, 5))
        item->plus2 += (coinflip() ? +1 : -1);

    if (item->plus < -4)
        item->plus = -4;
    else if (item->plus > 16)
        item->plus = 16;

    if (item->plus2 < -4)
        item->plus2 = -4;
    else if (item->plus2 > 16)
        item->plus2 = 16;
}

///////////////////////////////////////////////////

static void _ZONGULDROK_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    _equip_mpr(show_msgs, "You sense an extremely unholy aura.");
}

static void _ZONGULDROK_world_reacts(item_def *item)
{
    if (one_chance_in(5))
    {
        animate_dead(&you, 1 + random2(3), BEH_HOSTILE, MHITYOU, 0,
                     "the Sword of Zonguldrok");
        did_god_conduct(DID_NECROMANCY, 1);
    }
}

static void _ZONGULDROK_melee_effect(item_def* weapon, actor* attacker,
                                     actor* defender, bool mondied)
{
    if (attacker->atype() == ACT_PLAYER)
    {
        did_god_conduct(DID_NECROMANCY, 3);
    }
}

///////////////////////////////////////////////////

static void _STORM_BOW_world_reacts(item_def *item)
{
    if (!one_chance_in(300))
        return;

    for (radius_iterator ri(you.pos(), 2); ri; ++ri)
        if (!cell_is_solid(*ri) && env.cgrid(*ri) == EMPTY_CLOUD && one_chance_in(5))
            place_cloud( CLOUD_RAIN, *ri, random2(20), KC_OTHER, 3);
}

///////////////////////////////////////////////////

static void _GONG_melee_effect(item_def* item, actor* wearer,
                               actor* attacker, bool dummy)
{
    if (silenced(wearer->pos()))
        return;

    std::string msg = getSpeakString("shield of the gong");
    if (msg.empty())
        msg = "You hear a strange loud sound.";
    mpr(msg.c_str(), MSGCH_SOUND);

    noisy(40, wearer->pos());
}

///////////////////////////////////////////////////

static void _RCLOUDS_world_reacts(item_def *item)
{
    cloud_type cloud;
    if (one_chance_in(4))
        cloud = CLOUD_RAIN;
    else
        cloud = CLOUD_MIST;

    for (radius_iterator ri(you.pos(), 2); ri; ++ri)
        if (!cell_is_solid(*ri) && env.cgrid(*ri) == EMPTY_CLOUD 
                && one_chance_in(20))
        {
            place_cloud( cloud, *ri, random2(10), KC_OTHER, 1);
        }
}

static void _RCLOUDS_equip(item_def *item, bool *show_msgs, bool unmeld)
{
    _equip_mpr(show_msgs, "A thin mist springs up around you!");
}