OSDN Git Service

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