OSDN Git Service

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