OSDN Git Service

[Refactor] 発生源に使用されているwhoをリネーム
[hengbandforosx/hengbandosx.git] / src / spell / spells-summon.cpp
1 #include "spell/spells-summon.h"
2 #include "avatar/avatar.h"
3 #include "effect/spells-effect-util.h"
4 #include "floor/floor-object.h"
5 #include "floor/line-of-sight.h"
6 #include "game-option/birth-options.h"
7 #include "hpmp/hp-mp-processor.h"
8 #include "inventory/inventory-object.h"
9 #include "monster-floor/monster-summon.h"
10 #include "monster-floor/place-monster-types.h"
11 #include "monster-race/monster-race.h"
12 #include "monster-race/race-indice-types.h"
13 #include "monster/monster-info.h"
14 #include "monster/monster-status.h"
15 #include "monster/smart-learn-types.h"
16 #include "object/item-tester-hooker.h"
17 #include "object/item-use-flags.h"
18 #include "spell-kind/earthquake.h"
19 #include "spell-kind/spells-floor.h"
20 #include "spell-kind/spells-genocide.h"
21 #include "spell-kind/spells-launcher.h"
22 #include "spell-kind/spells-lite.h"
23 #include "spell-kind/spells-sight.h"
24 #include "spell-kind/spells-specific-bolt.h"
25 #include "spell/spells-diceroll.h"
26 #include "spell/spells-status.h"
27 #include "spell/summon-types.h"
28 #include "status/bad-status-setter.h"
29 #include "sv-definition/sv-other-types.h"
30 #include "system/floor-type-definition.h"
31 #include "system/item-entity.h"
32 #include "system/monster-entity.h"
33 #include "system/monster-race-info.h"
34 #include "system/player-type-definition.h"
35 #include "target/projection-path-calculator.h"
36 #include "util/string-processor.h"
37 #include "view/display-messages.h"
38
39 /*!
40  * @brief トランプ魔法独自の召喚処理を行う / Handle summoning and failure of trump spells
41  * @param num summon_specific()関数を呼び出す回数
42  * @param pet ペット化として召喚されるか否か
43  * @param y 召喚位置のy座標
44  * @param x 召喚位置のx座標
45  * @param lev 召喚レベル
46  * @param type 召喚条件ID
47  * @param mode モンスター生成条件フラグ
48  * @return モンスターが(敵対も含めて)召還されたならばTRUEを返す。
49  */
50 bool trump_summoning(PlayerType *player_ptr, int num, bool pet, POSITION y, POSITION x, DEPTH lev, summon_type type, BIT_FLAGS mode)
51 {
52     /* Default level */
53     PLAYER_LEVEL plev = player_ptr->lev;
54     if (!lev) {
55         lev = plev * 2 / 3 + randint1(plev / 2);
56     }
57
58     MONSTER_IDX src_idx;
59     if (pet) {
60         /* Become pet */
61         mode |= PM_FORCE_PET;
62
63         /* Only sometimes allow unique monster */
64         if (mode & PM_ALLOW_UNIQUE) {
65             /* Forbid often */
66             if (randint1(50 + plev) >= plev / 10) {
67                 mode &= ~PM_ALLOW_UNIQUE;
68             }
69         }
70
71         /* Player is who summons */
72         src_idx = -1;
73     } else {
74         /* Prevent taming, allow unique monster */
75         mode |= PM_NO_PET;
76
77         /* Behave as if they appear by themselfs */
78         src_idx = 0;
79     }
80
81     bool success = false;
82     for (int i = 0; i < num; i++) {
83         if (summon_specific(player_ptr, src_idx, y, x, lev, type, mode)) {
84             success = true;
85         }
86     }
87
88     if (!success) {
89         msg_print(_("誰もあなたのカードの呼び声に答えない。", "Nobody answers to your Trump call."));
90     }
91
92     return success;
93 }
94
95 bool cast_summon_demon(PlayerType *player_ptr, int power)
96 {
97     uint32_t flg = 0L;
98     bool pet = !one_in_(3);
99     if (pet) {
100         flg |= PM_FORCE_PET;
101     } else {
102         flg |= PM_NO_PET;
103     }
104     if (!(pet && (player_ptr->lev < 50))) {
105         flg |= PM_ALLOW_GROUP;
106     }
107
108     if (!summon_specific(player_ptr, (pet ? -1 : 0), player_ptr->y, player_ptr->x, power, SUMMON_DEMON, flg)) {
109         return true;
110     }
111
112     msg_print(_("硫黄の悪臭が充満した。", "The area fills with a stench of sulphur and brimstone."));
113     if (pet) {
114         msg_print(_("「ご用でございますか、ご主人様」", "'What is thy bidding... Master?'"));
115     } else {
116         msg_print(_("「卑しき者よ、我は汝の下僕にあらず! お前の魂を頂くぞ!」", "'NON SERVIAM! Wretch! I shall feast on thy mortal soul!'"));
117     }
118
119     return true;
120 }
121
122 bool cast_summon_undead(PlayerType *player_ptr, int power)
123 {
124     bool pet = one_in_(3);
125     summon_type type = (player_ptr->lev > 47 ? SUMMON_HI_UNDEAD : SUMMON_UNDEAD);
126
127     BIT_FLAGS mode = 0L;
128     if (!pet || ((player_ptr->lev > 24) && one_in_(3))) {
129         mode |= PM_ALLOW_GROUP;
130     }
131     if (pet) {
132         mode |= PM_FORCE_PET;
133     } else {
134         mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
135     }
136
137     if (summon_specific(player_ptr, (pet ? -1 : 0), player_ptr->y, player_ptr->x, power, type, mode)) {
138         msg_print(_("冷たい風があなたの周りに吹き始めた。それは腐敗臭を運んでいる...",
139             "Cold winds begin to blow around you, carrying with them the stench of decay..."));
140         if (pet) {
141             msg_print(_("古えの死せる者共があなたに仕えるため土から甦った!", "Ancient, long-dead forms arise from the ground to serve you!"));
142         } else {
143             msg_print(_("死者が甦った。眠りを妨げるあなたを罰するために!", "'The dead arise... to punish you for disturbing them!'"));
144         }
145     }
146     return true;
147 }
148
149 bool cast_summon_hound(PlayerType *player_ptr, int power)
150 {
151     BIT_FLAGS mode = PM_ALLOW_GROUP;
152     bool pet = !one_in_(5);
153     if (pet) {
154         mode |= PM_FORCE_PET;
155     } else {
156         mode |= PM_NO_PET;
157     }
158
159     if (summon_specific(player_ptr, (pet ? -1 : 0), player_ptr->y, player_ptr->x, power, SUMMON_HOUND, mode)) {
160         if (pet) {
161             msg_print(_("ハウンドがあなたの下僕として出現した。", "A group of hounds appear as your servants."));
162         } else {
163             msg_print(_("ハウンドはあなたに牙を向けている!", "A group of hounds appear as your enemies!"));
164         }
165     }
166
167     return true;
168 }
169
170 bool cast_summon_elemental(PlayerType *player_ptr, int power)
171 {
172     bool pet = one_in_(3);
173     BIT_FLAGS mode = 0L;
174     if (!(pet && (player_ptr->lev < 50))) {
175         mode |= PM_ALLOW_GROUP;
176     }
177     if (pet) {
178         mode |= PM_FORCE_PET;
179     } else {
180         mode |= PM_NO_PET;
181     }
182
183     if (summon_specific(player_ptr, (pet ? -1 : 0), player_ptr->y, player_ptr->x, power, SUMMON_ELEMENTAL, mode)) {
184         msg_print(_("エレメンタルが現れた...", "An elemental materializes..."));
185         if (pet) {
186             msg_print(_("あなたに服従しているようだ。", "It seems obedient to you."));
187         } else {
188             msg_print(_("それをコントロールできなかった!", "You fail to control it!"));
189         }
190     }
191
192     return true;
193 }
194
195 bool cast_summon_octopus(PlayerType *player_ptr)
196 {
197     BIT_FLAGS mode = PM_ALLOW_GROUP;
198     bool pet = !one_in_(5);
199     if (pet) {
200         mode |= PM_FORCE_PET;
201     }
202     if (summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, MonsterRaceId::JIZOTAKO, mode)) {
203         if (pet) {
204             msg_print(_("蛸があなたの下僕として出現した。", "A group of octopuses appear as your servants."));
205         } else {
206             msg_print(_("蛸はあなたを睨んでいる!", "A group of octopuses appear as your enemies!"));
207         }
208     }
209
210     return true;
211 }
212
213 /*!
214  * @brief 悪魔領域のグレーターデーモン召喚を処理する / Daemon spell Summon Greater Demon
215  * @return 処理を実行したならばTRUEを返す。
216  */
217 bool cast_summon_greater_demon(PlayerType *player_ptr)
218 {
219     constexpr auto q = _("どの死体を捧げますか? ", "Sacrifice which corpse? ");
220     constexpr auto s = _("捧げられる死体を持っていない。", "You have nothing to sacrifice.");
221     short i_idx;
222     const auto *o_ptr = choose_object(player_ptr, &i_idx, q, s, (USE_INVEN | USE_FLOOR), FuncItemTester(&ItemEntity::is_offerable));
223     if (!o_ptr) {
224         return false;
225     }
226
227     PLAYER_LEVEL plev = player_ptr->lev;
228     auto corpse_r_idx = i2enum<MonsterRaceId>(o_ptr->pval);
229     int summon_lev = plev * 2 / 3 + monraces_info[corpse_r_idx].level;
230
231     if (summon_specific(player_ptr, -1, player_ptr->y, player_ptr->x, summon_lev, SUMMON_HI_DEMON, (PM_ALLOW_GROUP | PM_FORCE_PET))) {
232         msg_print(_("硫黄の悪臭が充満した。", "The area fills with a stench of sulphur and brimstone."));
233         msg_print(_("「ご用でございますか、ご主人様」", "'What is thy bidding... Master?'"));
234         vary_item(player_ptr, i_idx, -1);
235     } else {
236         msg_print(_("悪魔は現れなかった。", "No Greater Demon arrives."));
237     }
238
239     return true;
240 }
241
242 /*!
243  * @brief 同族召喚(援軍)処理
244  * @param player_ptr プレイヤーへの参照ポインタ
245  * @param level 召喚基準レベル
246  * @param y 召喚先Y座標
247  * @param x 召喚先X座標
248  * @param mode 召喚オプション
249  * @return ターンを消費した場合TRUEを返す
250  */
251 bool summon_kin_player(PlayerType *player_ptr, DEPTH level, POSITION y, POSITION x, BIT_FLAGS mode)
252 {
253     bool pet = (bool)(mode & PM_FORCE_PET);
254     if (!pet) {
255         mode |= PM_NO_PET;
256     }
257     return summon_specific(player_ptr, (pet ? -1 : 0), y, x, level, SUMMON_KIN, mode);
258 }
259
260 /*!
261  * @brief サイバーデーモンの召喚
262  * @param player_ptr プレイヤーへの参照ポインタ
263  * @param src_idx 召喚主のモンスターID(0ならばプレイヤー)
264  * @param y 召喚位置Y座標
265  * @param x 召喚位置X座標
266  * @return 作用が実際にあった場合TRUEを返す
267  */
268 int summon_cyber(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION y, POSITION x)
269 {
270     /* Summoned by a monster */
271     BIT_FLAGS mode = PM_ALLOW_GROUP;
272     auto *floor_ptr = player_ptr->current_floor_ptr;
273     if (src_idx > 0) {
274         auto *m_ptr = &floor_ptr->m_list[src_idx];
275         if (m_ptr->is_pet()) {
276             mode |= PM_FORCE_PET;
277         }
278     }
279
280     int max_cyber = (floor_ptr->dun_level / 50) + randint1(2);
281     if (max_cyber > 4) {
282         max_cyber = 4;
283     }
284
285     int count = 0;
286     for (int i = 0; i < max_cyber; i++) {
287         count += summon_specific(player_ptr, src_idx, y, x, 100, SUMMON_CYBER, mode);
288     }
289
290     return count;
291 }
292
293 void mitokohmon(PlayerType *player_ptr)
294 {
295     int count = 0;
296     [[maybe_unused]] concptr sukekakusan = "";
297     if (summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, MonsterRaceId::SUKE, PM_FORCE_PET)) {
298         msg_print(_("『助さん』が現れた。", "Suke-san apperars."));
299         sukekakusan = "Suke-san";
300         count++;
301     }
302
303     if (summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, MonsterRaceId::KAKU, PM_FORCE_PET)) {
304         msg_print(_("『格さん』が現れた。", "Kaku-san appears."));
305         sukekakusan = "Kaku-san";
306         count++;
307     }
308
309     if (!count) {
310         for (int i = player_ptr->current_floor_ptr->m_max - 1; i > 0; i--) {
311             MonsterEntity *m_ptr;
312             m_ptr = &player_ptr->current_floor_ptr->m_list[i];
313             if (!m_ptr->is_valid()) {
314                 continue;
315             }
316             if (!((m_ptr->r_idx == MonsterRaceId::SUKE) || (m_ptr->r_idx == MonsterRaceId::KAKU))) {
317                 continue;
318             }
319             if (!los(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x)) {
320                 continue;
321             }
322             if (!projectable(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x)) {
323                 continue;
324             }
325             count++;
326             break;
327         }
328     }
329
330     if (count == 0) {
331         msg_print(_("しかし、何も起きなかった。", "Nothing happens."));
332         return;
333     }
334
335     msg_print(_(
336         "「者ども、ひかえおろう!!!このお方をどなたとこころえる。」",
337         format("%s^ says 'WHO do you think this person is! Bow your head, down to your knees!'", sukekakusan)));
338     sukekaku = true;
339     stun_monsters(player_ptr, 120);
340     confuse_monsters(player_ptr, 120);
341     turn_monsters(player_ptr, 120);
342     stasis_monsters(player_ptr, 120);
343     sukekaku = false;
344 }
345
346 /*!
347  * @brief HI_SUMMON(上級召喚)処理発動
348  * @param player_ptr プレイヤーへの参照ポインタ
349  * @param y 召喚位置Y座標
350  * @param x 召喚位置X座標
351  * @param can_pet プレイヤーのペットとなる可能性があるならばTRUEにする
352  * @return 作用が実際にあった場合TRUEを返す
353  * @todo 引数にPOSITION x/yは必要か? 要調査
354  */
355 int activate_hi_summon(PlayerType *player_ptr, POSITION y, POSITION x, bool can_pet)
356 {
357     BIT_FLAGS mode = PM_ALLOW_GROUP;
358     bool pet = false;
359     if (can_pet) {
360         if (one_in_(4)) {
361             mode |= PM_FORCE_FRIENDLY;
362         } else {
363             mode |= PM_FORCE_PET;
364             pet = true;
365         }
366     }
367
368     if (!pet) {
369         mode |= PM_NO_PET;
370     }
371
372     DEPTH dungeon_level = player_ptr->current_floor_ptr->dun_level;
373     DEPTH summon_lev = (pet ? player_ptr->lev * 2 / 3 + randint1(player_ptr->lev / 2) : dungeon_level);
374     int count = 0;
375     for (int i = 0; i < (randint1(7) + (dungeon_level / 40)); i++) {
376         switch (randint1(25) + (dungeon_level / 20)) {
377         case 1:
378         case 2:
379             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_ANT, mode);
380             break;
381         case 3:
382         case 4:
383             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_SPIDER, mode);
384             break;
385         case 5:
386         case 6:
387             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_HOUND, mode);
388             break;
389         case 7:
390         case 8:
391             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_HYDRA, mode);
392             break;
393         case 9:
394         case 10:
395             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_ANGEL, mode);
396             break;
397         case 11:
398         case 12:
399             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_UNDEAD, mode);
400             break;
401         case 13:
402         case 14:
403             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_DRAGON, mode);
404             break;
405         case 15:
406         case 16:
407             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_DEMON, mode);
408             break;
409         case 17:
410             if (can_pet) {
411                 break;
412             }
413             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_AMBERITES, (mode | PM_ALLOW_UNIQUE));
414             break;
415         case 18:
416         case 19:
417             if (can_pet) {
418                 break;
419             }
420             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_UNIQUE, (mode | PM_ALLOW_UNIQUE));
421             break;
422         case 20:
423         case 21:
424             if (!can_pet) {
425                 mode |= PM_ALLOW_UNIQUE;
426             }
427             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_HI_UNDEAD, mode);
428             break;
429         case 22:
430         case 23:
431             if (!can_pet) {
432                 mode |= PM_ALLOW_UNIQUE;
433             }
434             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_HI_DRAGON, mode);
435             break;
436         case 24:
437             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, 100, SUMMON_CYBER, mode);
438             break;
439         default:
440             if (!can_pet) {
441                 mode |= PM_ALLOW_UNIQUE;
442             }
443             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, pet ? summon_lev : (((summon_lev * 3) / 2) + 5), SUMMON_NONE, mode);
444         }
445     }
446
447     return count;
448 }
449
450 /*!
451  * @brief 「悪霊召喚」のランダムな効果を決定して処理する。
452  * @param player_ptr プレイヤーへの参照ポインタ
453  * @param dir 方向ID
454  */
455 void cast_invoke_spirits(PlayerType *player_ptr, DIRECTION dir)
456 {
457     PLAYER_LEVEL plev = player_ptr->lev;
458     int die = randint1(100) + plev / 5;
459     int vir = virtue_number(player_ptr, Virtue::CHANCE);
460
461     if (vir != 0) {
462         if (player_ptr->virtues[vir - 1] > 0) {
463             while (randint1(400) < player_ptr->virtues[vir - 1]) {
464                 die++;
465             }
466         } else {
467             while (randint1(400) < (0 - player_ptr->virtues[vir - 1])) {
468                 die--;
469             }
470         }
471     }
472
473     msg_print(_("あなたは死者たちの力を招集した...", "You call on the power of the dead..."));
474     if (die < 26) {
475         chg_virtue(player_ptr, Virtue::CHANCE, 1);
476     }
477
478     if (die > 100) {
479         msg_print(_("あなたはおどろおどろしい力のうねりを感じた!", "You feel a surge of eldritch force!"));
480     }
481
482     BadStatusSetter bss(player_ptr);
483     if (die < 8) {
484         msg_print(_("なんてこった!あなたの周りの地面から朽ちた人影が立ち上がってきた!", "Oh no! Mouldering forms rise from the earth around you!"));
485
486         (void)summon_specific(player_ptr, 0, player_ptr->y, player_ptr->x, player_ptr->current_floor_ptr->dun_level, SUMMON_UNDEAD,
487             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
488         chg_virtue(player_ptr, Virtue::UNLIFE, 1);
489     } else if (die < 14) {
490         msg_print(_("名状し難い邪悪な存在があなたの心を通り過ぎて行った...", "An unnamable evil brushes against your mind..."));
491         (void)bss.mod_fear(randint1(4) + 4);
492     } else if (die < 26) {
493         msg_print(_("あなたの頭に大量の幽霊たちの騒々しい声が押し寄せてきた...", "Your head is invaded by a horde of gibbering spectral voices..."));
494         (void)bss.mod_confusion(randint1(4) + 4);
495     } else if (die < 31) {
496         poly_monster(player_ptr, dir, plev);
497     } else if (die < 36) {
498         fire_bolt_or_beam(player_ptr, beam_chance(player_ptr) - 10, AttributeType::MISSILE, dir, damroll(3 + ((plev - 1) / 5), 4));
499     } else if (die < 41) {
500         confuse_monster(player_ptr, dir, plev);
501     } else if (die < 46) {
502         fire_ball(player_ptr, AttributeType::POIS, dir, 20 + (plev / 2), 3);
503     } else if (die < 51) {
504         (void)lite_line(player_ptr, dir, damroll(6, 8));
505     } else if (die < 56) {
506         fire_bolt_or_beam(player_ptr, beam_chance(player_ptr) - 10, AttributeType::ELEC, dir, damroll(3 + ((plev - 5) / 4), 8));
507     } else if (die < 61) {
508         fire_bolt_or_beam(player_ptr, beam_chance(player_ptr) - 10, AttributeType::COLD, dir, damroll(5 + ((plev - 5) / 4), 8));
509     } else if (die < 66) {
510         fire_bolt_or_beam(player_ptr, beam_chance(player_ptr), AttributeType::ACID, dir, damroll(6 + ((plev - 5) / 4), 8));
511     } else if (die < 71) {
512         fire_bolt_or_beam(player_ptr, beam_chance(player_ptr), AttributeType::FIRE, dir, damroll(8 + ((plev - 5) / 4), 8));
513     } else if (die < 76) {
514         hypodynamic_bolt(player_ptr, dir, 75);
515     } else if (die < 81) {
516         fire_ball(player_ptr, AttributeType::ELEC, dir, 30 + plev / 2, 2);
517     } else if (die < 86) {
518         fire_ball(player_ptr, AttributeType::ACID, dir, 40 + plev, 2);
519     } else if (die < 91) {
520         fire_ball(player_ptr, AttributeType::ICE, dir, 70 + plev, 3);
521     } else if (die < 96) {
522         fire_ball(player_ptr, AttributeType::FIRE, dir, 80 + plev, 3);
523     } else if (die < 101) {
524         hypodynamic_bolt(player_ptr, dir, 100 + plev);
525     } else if (die < 104) {
526         earthquake(player_ptr, player_ptr->y, player_ptr->x, 12, 0);
527     } else if (die < 106) {
528         (void)destroy_area(player_ptr, player_ptr->y, player_ptr->x, 13 + randint0(5), false);
529     } else if (die < 108) {
530         symbol_genocide(player_ptr, plev + 50, true);
531     } else if (die < 110) {
532         dispel_monsters(player_ptr, 120);
533     } else {
534         dispel_monsters(player_ptr, 150);
535         slow_monsters(player_ptr, plev);
536         sleep_monsters(player_ptr, plev);
537         hp_player(player_ptr, 300);
538     }
539
540     if (die < 31) {
541         msg_print(
542             _("陰欝な声がクスクス笑う。「もうすぐおまえは我々の仲間になるだろう。弱き者よ。」", "Sepulchral voices chuckle. 'Soon you will join us, mortal.'"));
543     }
544 }