OSDN Git Service

Merge pull request #2674 from sikabane-works/release/3.0.0Alpha68
[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/monster-race-definition.h"
32 #include "system/monster-type-definition.h"
33 #include "system/object-type-definition.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 who;
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         who = -1;
73     } else {
74         /* Prevent taming, allow unique monster */
75         mode |= PM_NO_PET;
76
77         /* Behave as if they appear by themselfs */
78         who = 0;
79     }
80
81     bool success = false;
82     for (int i = 0; i < num; i++) {
83         if (summon_specific(player_ptr, who, 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     concptr q = _("どの死体を捧げますか? ", "Sacrifice which corpse? ");
220     concptr s = _("捧げられる死体を持っていない。", "You have nothing to sacrifice.");
221     OBJECT_IDX item;
222     ObjectType *o_ptr;
223     o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), FuncItemTester(&ObjectType::is_offerable));
224     if (!o_ptr) {
225         return false;
226     }
227
228     PLAYER_LEVEL plev = player_ptr->lev;
229     auto corpse_r_idx = i2enum<MonsterRaceId>(o_ptr->pval);
230     int summon_lev = plev * 2 / 3 + r_info[corpse_r_idx].level;
231
232     if (summon_specific(player_ptr, -1, player_ptr->y, player_ptr->x, summon_lev, SUMMON_HI_DEMON, (PM_ALLOW_GROUP | PM_FORCE_PET))) {
233         msg_print(_("硫黄の悪臭が充満した。", "The area fills with a stench of sulphur and brimstone."));
234         msg_print(_("「ご用でございますか、ご主人様」", "'What is thy bidding... Master?'"));
235         vary_item(player_ptr, item, -1);
236     } else {
237         msg_print(_("悪魔は現れなかった。", "No Greater Demon arrives."));
238     }
239
240     return true;
241 }
242
243 /*!
244  * @brief 同族召喚(援軍)処理
245  * @param player_ptr プレイヤーへの参照ポインタ
246  * @param level 召喚基準レベル
247  * @param y 召喚先Y座標
248  * @param x 召喚先X座標
249  * @param mode 召喚オプション
250  * @return ターンを消費した場合TRUEを返す
251  */
252 bool summon_kin_player(PlayerType *player_ptr, DEPTH level, POSITION y, POSITION x, BIT_FLAGS mode)
253 {
254     bool pet = (bool)(mode & PM_FORCE_PET);
255     if (!pet) {
256         mode |= PM_NO_PET;
257     }
258     return summon_specific(player_ptr, (pet ? -1 : 0), y, x, level, SUMMON_KIN, mode);
259 }
260
261 /*!
262  * @brief サイバーデーモンの召喚
263  * @param player_ptr プレイヤーへの参照ポインタ
264  * @param who 召喚主のモンスターID(0ならばプレイヤー)
265  * @param y 召喚位置Y座標
266  * @param x 召喚位置X座標
267  * @return 作用が実際にあった場合TRUEを返す
268  */
269 int summon_cyber(PlayerType *player_ptr, MONSTER_IDX who, POSITION y, POSITION x)
270 {
271     /* Summoned by a monster */
272     BIT_FLAGS mode = PM_ALLOW_GROUP;
273     auto *floor_ptr = player_ptr->current_floor_ptr;
274     if (who > 0) {
275         auto *m_ptr = &floor_ptr->m_list[who];
276         if (m_ptr->is_pet()) {
277             mode |= PM_FORCE_PET;
278         }
279     }
280
281     int max_cyber = (floor_ptr->dun_level / 50) + randint1(2);
282     if (max_cyber > 4) {
283         max_cyber = 4;
284     }
285
286     int count = 0;
287     for (int i = 0; i < max_cyber; i++) {
288         count += summon_specific(player_ptr, who, y, x, 100, SUMMON_CYBER, mode);
289     }
290
291     return count;
292 }
293
294 void mitokohmon(PlayerType *player_ptr)
295 {
296     int count = 0;
297     concptr sukekakusan = "";
298     if (summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, MonsterRaceId::SUKE, PM_FORCE_PET)) {
299         msg_print(_("『助さん』が現れた。", "Suke-san apperars."));
300         sukekakusan = "Suke-san";
301         count++;
302     }
303
304     if (summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, MonsterRaceId::KAKU, PM_FORCE_PET)) {
305         msg_print(_("『格さん』が現れた。", "Kaku-san appears."));
306         sukekakusan = "Kaku-san";
307         count++;
308     }
309
310     if (!count) {
311         for (int i = player_ptr->current_floor_ptr->m_max - 1; i > 0; i--) {
312             monster_type *m_ptr;
313             m_ptr = &player_ptr->current_floor_ptr->m_list[i];
314             if (!m_ptr->is_valid()) {
315                 continue;
316             }
317             if (!((m_ptr->r_idx == MonsterRaceId::SUKE) || (m_ptr->r_idx == MonsterRaceId::KAKU))) {
318                 continue;
319             }
320             if (!los(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x)) {
321                 continue;
322             }
323             if (!projectable(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x)) {
324                 continue;
325             }
326             count++;
327             break;
328         }
329     }
330
331     if (count == 0) {
332         msg_print(_("しかし、何も起きなかった。", "Nothing happens."));
333         return;
334     }
335
336     msg_format(
337         _("「者ども、ひかえおろう!!!このお方をどなたとこころえる。」", "%^s says 'WHO do you think this person is! Bow your head, down to your knees!'"),
338         sukekakusan);
339     sukekaku = true;
340     stun_monsters(player_ptr, 120);
341     confuse_monsters(player_ptr, 120);
342     turn_monsters(player_ptr, 120);
343     stasis_monsters(player_ptr, 120);
344     sukekaku = false;
345 }
346
347 /*!
348  * @brief HI_SUMMON(上級召喚)処理発動
349  * @param player_ptr プレイヤーへの参照ポインタ
350  * @param y 召喚位置Y座標
351  * @param x 召喚位置X座標
352  * @param can_pet プレイヤーのペットとなる可能性があるならばTRUEにする
353  * @return 作用が実際にあった場合TRUEを返す
354  * @todo 引数にPOSITION x/yは必要か? 要調査
355  */
356 int activate_hi_summon(PlayerType *player_ptr, POSITION y, POSITION x, bool can_pet)
357 {
358     BIT_FLAGS mode = PM_ALLOW_GROUP;
359     bool pet = false;
360     if (can_pet) {
361         if (one_in_(4)) {
362             mode |= PM_FORCE_FRIENDLY;
363         } else {
364             mode |= PM_FORCE_PET;
365             pet = true;
366         }
367     }
368
369     if (!pet) {
370         mode |= PM_NO_PET;
371     }
372
373     DEPTH dungeon_level = player_ptr->current_floor_ptr->dun_level;
374     DEPTH summon_lev = (pet ? player_ptr->lev * 2 / 3 + randint1(player_ptr->lev / 2) : dungeon_level);
375     int count = 0;
376     for (int i = 0; i < (randint1(7) + (dungeon_level / 40)); i++) {
377         switch (randint1(25) + (dungeon_level / 20)) {
378         case 1:
379         case 2:
380             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_ANT, mode);
381             break;
382         case 3:
383         case 4:
384             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_SPIDER, mode);
385             break;
386         case 5:
387         case 6:
388             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_HOUND, mode);
389             break;
390         case 7:
391         case 8:
392             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_HYDRA, mode);
393             break;
394         case 9:
395         case 10:
396             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_ANGEL, mode);
397             break;
398         case 11:
399         case 12:
400             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_UNDEAD, mode);
401             break;
402         case 13:
403         case 14:
404             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_DRAGON, mode);
405             break;
406         case 15:
407         case 16:
408             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_DEMON, mode);
409             break;
410         case 17:
411             if (can_pet) {
412                 break;
413             }
414             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_AMBERITES, (mode | PM_ALLOW_UNIQUE));
415             break;
416         case 18:
417         case 19:
418             if (can_pet) {
419                 break;
420             }
421             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_UNIQUE, (mode | PM_ALLOW_UNIQUE));
422             break;
423         case 20:
424         case 21:
425             if (!can_pet) {
426                 mode |= PM_ALLOW_UNIQUE;
427             }
428             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_HI_UNDEAD, mode);
429             break;
430         case 22:
431         case 23:
432             if (!can_pet) {
433                 mode |= PM_ALLOW_UNIQUE;
434             }
435             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, summon_lev, SUMMON_HI_DRAGON, mode);
436             break;
437         case 24:
438             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, 100, SUMMON_CYBER, mode);
439             break;
440         default:
441             if (!can_pet) {
442                 mode |= PM_ALLOW_UNIQUE;
443             }
444             count += summon_specific(player_ptr, (pet ? -1 : 0), y, x, pet ? summon_lev : (((summon_lev * 3) / 2) + 5), SUMMON_NONE, mode);
445         }
446     }
447
448     return count;
449 }
450
451 /*!
452  * @brief 「悪霊召喚」のランダムな効果を決定して処理する。
453  * @param player_ptr プレイヤーへの参照ポインタ
454  * @param dir 方向ID
455  */
456 void cast_invoke_spirits(PlayerType *player_ptr, DIRECTION dir)
457 {
458     PLAYER_LEVEL plev = player_ptr->lev;
459     int die = randint1(100) + plev / 5;
460     int vir = virtue_number(player_ptr, V_CHANCE);
461
462     if (vir != 0) {
463         if (player_ptr->virtues[vir - 1] > 0) {
464             while (randint1(400) < player_ptr->virtues[vir - 1]) {
465                 die++;
466             }
467         } else {
468             while (randint1(400) < (0 - player_ptr->virtues[vir - 1])) {
469                 die--;
470             }
471         }
472     }
473
474     msg_print(_("あなたは死者たちの力を招集した...", "You call on the power of the dead..."));
475     if (die < 26) {
476         chg_virtue(player_ptr, V_CHANCE, 1);
477     }
478
479     if (die > 100) {
480         msg_print(_("あなたはおどろおどろしい力のうねりを感じた!", "You feel a surge of eldritch force!"));
481     }
482
483     BadStatusSetter bss(player_ptr);
484     if (die < 8) {
485         msg_print(_("なんてこった!あなたの周りの地面から朽ちた人影が立ち上がってきた!", "Oh no! Mouldering forms rise from the earth around you!"));
486
487         (void)summon_specific(player_ptr, 0, player_ptr->y, player_ptr->x, player_ptr->current_floor_ptr->dun_level, SUMMON_UNDEAD,
488             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
489         chg_virtue(player_ptr, V_UNLIFE, 1);
490     } else if (die < 14) {
491         msg_print(_("名状し難い邪悪な存在があなたの心を通り過ぎて行った...", "An unnamable evil brushes against your mind..."));
492         (void)bss.mod_fear(randint1(4) + 4);
493     } else if (die < 26) {
494         msg_print(_("あなたの頭に大量の幽霊たちの騒々しい声が押し寄せてきた...", "Your head is invaded by a horde of gibbering spectral voices..."));
495         (void)bss.mod_confusion(randint1(4) + 4);
496     } else if (die < 31) {
497         poly_monster(player_ptr, dir, plev);
498     } else if (die < 36) {
499         fire_bolt_or_beam(player_ptr, beam_chance(player_ptr) - 10, AttributeType::MISSILE, dir, damroll(3 + ((plev - 1) / 5), 4));
500     } else if (die < 41) {
501         confuse_monster(player_ptr, dir, plev);
502     } else if (die < 46) {
503         fire_ball(player_ptr, AttributeType::POIS, dir, 20 + (plev / 2), 3);
504     } else if (die < 51) {
505         (void)lite_line(player_ptr, dir, damroll(6, 8));
506     } else if (die < 56) {
507         fire_bolt_or_beam(player_ptr, beam_chance(player_ptr) - 10, AttributeType::ELEC, dir, damroll(3 + ((plev - 5) / 4), 8));
508     } else if (die < 61) {
509         fire_bolt_or_beam(player_ptr, beam_chance(player_ptr) - 10, AttributeType::COLD, dir, damroll(5 + ((plev - 5) / 4), 8));
510     } else if (die < 66) {
511         fire_bolt_or_beam(player_ptr, beam_chance(player_ptr), AttributeType::ACID, dir, damroll(6 + ((plev - 5) / 4), 8));
512     } else if (die < 71) {
513         fire_bolt_or_beam(player_ptr, beam_chance(player_ptr), AttributeType::FIRE, dir, damroll(8 + ((plev - 5) / 4), 8));
514     } else if (die < 76) {
515         hypodynamic_bolt(player_ptr, dir, 75);
516     } else if (die < 81) {
517         fire_ball(player_ptr, AttributeType::ELEC, dir, 30 + plev / 2, 2);
518     } else if (die < 86) {
519         fire_ball(player_ptr, AttributeType::ACID, dir, 40 + plev, 2);
520     } else if (die < 91) {
521         fire_ball(player_ptr, AttributeType::ICE, dir, 70 + plev, 3);
522     } else if (die < 96) {
523         fire_ball(player_ptr, AttributeType::FIRE, dir, 80 + plev, 3);
524     } else if (die < 101) {
525         hypodynamic_bolt(player_ptr, dir, 100 + plev);
526     } else if (die < 104) {
527         earthquake(player_ptr, player_ptr->y, player_ptr->x, 12, 0);
528     } else if (die < 106) {
529         (void)destroy_area(player_ptr, player_ptr->y, player_ptr->x, 13 + randint0(5), false);
530     } else if (die < 108) {
531         symbol_genocide(player_ptr, plev + 50, true);
532     } else if (die < 110) {
533         dispel_monsters(player_ptr, 120);
534     } else {
535         dispel_monsters(player_ptr, 150);
536         slow_monsters(player_ptr, plev);
537         sleep_monsters(player_ptr, plev);
538         hp_player(player_ptr, 300);
539     }
540
541     if (die < 31) {
542         msg_print(
543             _("陰欝な声がクスクス笑う。「もうすぐおまえは我々の仲間になるだろう。弱き者よ。」", "Sepulchral voices chuckle. 'Soon you will join us, mortal.'"));
544     }
545 }