OSDN Git Service

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