OSDN Git Service

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