Changeset 1431 for trunk

Show
Ignore:
Timestamp:
06/07/09 18:22:43 (9 months ago)
Author:
ajps
Message:

Move the aiming of aimable spells to be passed as an argument with the cast command rather than asked for at time of effect. Move the warning about using too much mana into the UI 'layer'.

Location:
trunk/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/cmd-obj.c

    r1429 r1431  
    402402{ 
    403403        int spell; 
     404        const magic_type *s_ptr; 
     405 
    404406        cptr verb = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "cast" : "recite"); 
     407    cptr noun = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "spell" : "prayer"); 
    405408 
    406409        /* Track the object kind */ 
     
    412415        if (spell < 0) 
    413416        { 
    414                 cptr p = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "spell" : "prayer"); 
    415  
    416                 if (spell == -2) msg_format("You don't know any %ss in that book.", p); 
    417                 return; 
    418         } 
    419  
    420         cmd_insert(CMD_CAST, spell); 
     417                if (spell == -2) msg_format("You don't know any %ss in that book.", noun); 
     418                return; 
     419        } 
     420 
     421        /* Get the spell */ 
     422        s_ptr = &mp_ptr->info[spell]; 
     423         
     424        /* Verify "dangerous" spells */ 
     425        if (s_ptr->smana > p_ptr->csp) 
     426        { 
     427                /* Warning */ 
     428                msg_format("You do not have enough mana to %s this %s.", verb, noun); 
     429                 
     430                /* Flush input */ 
     431                flush(); 
     432                 
     433                /* Verify */ 
     434                if (!get_check("Attempt it anyway? ")) return; 
     435        } 
     436 
     437        cmd_insert(CMD_CAST, spell, DIR_UNKNOWN); 
    421438} 
    422439 
  • trunk/src/cmd5.c

    r1426 r1431  
    583583{ 
    584584        int spell = args[0].choice; 
     585        int dir = args[1].direction; 
    585586 
    586587        int item_list[INVEN_TOTAL + MAX_FLOOR_STACK]; 
     
    606607                        { 
    607608                                /* Cast a spell */ 
    608                                 if (spell_cast(spell)) 
     609                                if (spell_cast(spell, dir)) 
    609610                                        p_ptr->energy_use = 100; 
    610611                        } 
     
    714715 
    715716/* Cas the specified spell */ 
    716 bool spell_cast(int spell) 
     717bool spell_cast(int spell, int dir) 
    717718{ 
    718719        int chance; 
    719720        const magic_type *s_ptr; 
    720721 
    721     cptr p = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? 
    722                   "cast this spell" : 
    723                   "recite this prayer"); 
    724  
    725  
    726         /* Get the spell */ 
    727         s_ptr = &mp_ptr->info[spell]; 
    728  
    729  
    730         /* Verify "dangerous" spells */ 
    731         if (s_ptr->smana > p_ptr->csp) 
    732         { 
    733                 /* Warning */ 
    734                 msg_format("You do not have enough mana to %s.", p); 
    735  
    736                 /* Flush input */ 
    737                 flush(); 
    738  
    739                 /* Verify */ 
    740                 if (!get_check("Attempt it anyway? ")) return FALSE; 
    741         } 
    742  
    743  
    744722        /* Spell failure chance */ 
    745723        chance = spell_chance(spell); 
     
    756734        { 
    757735                /* Cast the spell */ 
    758                 if (!cast_spell(cp_ptr->spell_book, spell)) return FALSE; 
     736                if (!cast_spell(cp_ptr->spell_book, spell, dir)) return FALSE; 
    759737 
    760738                /* A spell was cast */ 
  • trunk/src/externs.h

    r1417 r1431  
    303303s16b spell_chance(int spell); 
    304304bool spell_okay(int spell, bool known, bool browse); 
    305 bool spell_cast(int spell); 
     305bool spell_cast(int spell, int dir); 
    306306void spell_learn(int spell); 
    307307 
     
    647647extern cptr get_spell_name(int tval, int index); 
    648648extern void get_spell_info(int tval, int index, char *buf, size_t len); 
    649 extern bool cast_spell(int tval, int index); 
     649extern bool cast_spell(int tval, int index, int dir); 
     650extern bool spell_needs_aim(int tval, int spell); 
    650651 
    651652/* xtra2.c */ 
  • trunk/src/game-cmd.c

    r1428 r1431  
    9999                case CMD_REST: 
    100100                case CMD_STUDY_SPELL: 
    101                 case CMD_CAST: 
    102101                { 
    103102                        cmd.args[0].choice = va_arg(vp, int); 
     
    187186                        if (cmd.args[1].direction == DIR_UNKNOWN &&  
    188187                                obj_needs_aim(object_from_item_idx(cmd.args[0].choice))) 
     188                        { 
     189                                if (!get_aim_dir(&cmd.args[1].direction)) 
     190                                        return 1; 
     191                        } 
     192 
     193                        break; 
     194                } 
     195 
     196                /* This takes a choice and a direction. */ 
     197                case CMD_CAST: 
     198                { 
     199                        cmd.args[0].choice = va_arg(vp, int); 
     200                        cmd.args[1].direction = va_arg(vp, int); 
     201 
     202                        if (cmd.args[1].direction == DIR_UNKNOWN &&  
     203                                spell_needs_aim(cp_ptr->spell_book, cmd.args[0].choice)) 
    189204                        { 
    190205                                if (!get_aim_dir(&cmd.args[1].direction)) 
  • trunk/src/x-spell.c

    r1392 r1431  
    421421 
    422422 
    423  
    424 static bool cast_mage_spell(int spell) 
     423bool spell_needs_aim(int tval, int spell) 
     424{ 
     425        if (tval == TV_MAGIC_BOOK) 
     426        { 
     427                switch (spell) 
     428                { 
     429                        case SPELL_MAGIC_MISSILE: 
     430                        case SPELL_STINKING_CLOUD: 
     431                        case SPELL_CONFUSE_MONSTER: 
     432                        case SPELL_LIGHTNING_BOLT: 
     433                        case SPELL_SLEEP_MONSTER: 
     434                        case SPELL_SPEAR_OF_LIGHT: 
     435                        case SPELL_FROST_BOLT: 
     436                        case SPELL_TURN_STONE_TO_MUD: 
     437                        case SPELL_WONDER: 
     438                        case SPELL_POLYMORPH_OTHER: 
     439                        case SPELL_FIRE_BOLT: 
     440                        case SPELL_SLOW_MONSTER: 
     441                        case SPELL_FROST_BALL: 
     442                        case SPELL_TELEPORT_OTHER: 
     443                        case SPELL_BEDLAM: 
     444                        case SPELL_FIRE_BALL: 
     445                        case SPELL_ACID_BOLT: 
     446                        case SPELL_CLOUD_KILL: 
     447                        case SPELL_ACID_BALL: 
     448                        case SPELL_ICE_STORM: 
     449                        case SPELL_METEOR_SWARM: 
     450                        case SPELL_MANA_STORM: 
     451                        case SPELL_SHOCK_WAVE: 
     452                        case SPELL_EXPLOSION: 
     453                        case SPELL_RIFT: 
     454                        case SPELL_REND_SOUL:  
     455                        case SPELL_CHAOS_STRIKE:  
     456                                return TRUE; 
     457                                 
     458                        default: 
     459                                return FALSE; 
     460                } 
     461        } 
     462        else 
     463        { 
     464                switch (spell) 
     465                { 
     466                        case PRAYER_SCARE_MONSTER: 
     467                        case PRAYER_ORB_OF_DRAINING: 
     468                        case PRAYER_ANNIHILATION: 
     469                        case PRAYER_TELEPORT_OTHER: 
     470                                return TRUE; 
     471 
     472                        default: 
     473                                return FALSE; 
     474                } 
     475        } 
     476} 
     477 
     478 
     479static bool cast_mage_spell(int spell, int dir) 
    425480{ 
    426481        int py = p_ptr->py; 
    427482        int px = p_ptr->px; 
    428  
    429         int dir; 
    430483 
    431484        int plev = p_ptr->lev; 
     
    439492                case SPELL_MAGIC_MISSILE: 
    440493                { 
    441                         if (!get_aim_dir(&dir)) return (FALSE); 
    442494                        fire_bolt_or_beam(beam-10, GF_MISSILE, dir, 
    443495                                          damroll(3 + ((plev - 1) / 5), 4)); 
     
    488540                case SPELL_STINKING_CLOUD: 
    489541                { 
    490                         if (!get_aim_dir(&dir)) return (FALSE); 
    491542                        fire_ball(GF_POIS, dir, 10 + (plev / 2), 2); 
    492543                        break; 
     
    495546                case SPELL_CONFUSE_MONSTER: 
    496547                { 
    497                         if (!get_aim_dir(&dir)) return (FALSE); 
    498548                        (void)confuse_monster(dir, plev); 
    499549                        break; 
     
    502552                case SPELL_LIGHTNING_BOLT: 
    503553                { 
    504                         if (!get_aim_dir(&dir)) return (FALSE); 
    505                         fire_beam(GF_ELEC, dir, 
    506                                   damroll(3+((plev-5)/6), 6)); 
     554                        fire_beam(GF_ELEC, dir, damroll(3+((plev-5)/6), 6)); 
    507555                        break; 
    508556                } 
     
    516564                case SPELL_SLEEP_MONSTER: 
    517565                { 
    518                         if (!get_aim_dir(&dir)) return (FALSE); 
    519566                        (void)sleep_monster(dir); 
    520567                        break; 
     
    533580                } 
    534581 
    535                 case SPELL_SPEAR_OF_LIGHT: /* spear of light */ 
    536                 { 
    537                         if (!get_aim_dir(&dir)) return (FALSE); 
     582                case SPELL_SPEAR_OF_LIGHT: 
     583                { 
    538584                        msg_print("A line of blue shimmering light appears."); 
    539585                        lite_line(dir); 
     
    543589                case SPELL_FROST_BOLT: 
    544590                { 
    545                         if (!get_aim_dir(&dir)) return (FALSE); 
    546591                        fire_bolt_or_beam(beam-10, GF_COLD, dir, 
    547592                                          damroll(5+((plev-5)/4), 8)); 
     
    551596                case SPELL_TURN_STONE_TO_MUD: 
    552597                { 
    553                         if (!get_aim_dir(&dir)) return (FALSE); 
    554598                        (void)wall_to_mud(dir); 
    555599                        break; 
     
    567611                } 
    568612 
    569                 case SPELL_WONDER: /* wonder */ 
    570                 { 
    571                         if (!get_aim_dir(&dir)) return (FALSE); 
     613                case SPELL_WONDER: 
     614                { 
    572615                        (void)spell_wonder(dir); 
    573616                        break; 
     
    576619                case SPELL_POLYMORPH_OTHER: 
    577620                { 
    578                         if (!get_aim_dir(&dir)) return (FALSE); 
    579621                        (void)poly_monster(dir); 
    580622                        break; 
     
    594636                case SPELL_FIRE_BOLT: 
    595637                { 
    596                         if (!get_aim_dir(&dir)) return (FALSE); 
    597638                        fire_bolt_or_beam(beam, GF_FIRE, dir, 
    598639                                          damroll(6+((plev-5)/4), 8)); 
     
    602643                case SPELL_SLOW_MONSTER: 
    603644                { 
    604                         if (!get_aim_dir(&dir)) return (FALSE); 
    605645                        (void)slow_monster(dir); 
    606646                        break; 
     
    609649                case SPELL_FROST_BALL: 
    610650                { 
    611                         if (!get_aim_dir(&dir)) return (FALSE); 
    612651                        fire_ball(GF_COLD, dir, 30 + (plev), 2); 
    613652                        break; 
     
    621660                case SPELL_TELEPORT_OTHER: 
    622661                { 
    623                         if (!get_aim_dir(&dir)) return (FALSE); 
    624662                        (void)teleport_monster(dir); 
    625663                        break; 
     
    628666                case SPELL_BEDLAM: 
    629667                { 
    630                         if (!get_aim_dir(&dir)) return (FALSE); 
    631668                        fire_ball(GF_OLD_CONF, dir, plev, 4); 
    632669                        break; 
     
    635672                case SPELL_FIRE_BALL: 
    636673                { 
    637                         if (!get_aim_dir(&dir)) return (FALSE); 
    638674                        fire_ball(GF_FIRE, dir, 55 + (plev), 2); 
    639675                        break; 
     
    684720                case SPELL_ACID_BOLT: 
    685721                { 
    686                         if (!get_aim_dir(&dir)) return (FALSE); 
    687722                        fire_bolt_or_beam(beam, GF_ACID, dir, damroll(8+((plev-5)/4), 8)); 
    688723                        break; 
     
    691726                case SPELL_CLOUD_KILL: 
    692727                { 
    693                         if (!get_aim_dir(&dir)) return (FALSE); 
    694728                        fire_ball(GF_POIS, dir, 40 + (plev / 2), 3); 
    695729                        break; 
     
    698732                case SPELL_ACID_BALL: 
    699733                { 
    700                         if (!get_aim_dir(&dir)) return (FALSE); 
    701734                        fire_ball(GF_ACID, dir, 40 + (plev), 2); 
    702735                        break; 
     
    705738                case SPELL_ICE_STORM: 
    706739                { 
    707                         if (!get_aim_dir(&dir)) return (FALSE); 
    708740                        fire_ball(GF_ICE, dir, 50 + (plev * 2), 3); 
    709741                        break; 
     
    712744                case SPELL_METEOR_SWARM: 
    713745                { 
    714                         if (!get_aim_dir(&dir)) return (FALSE); 
    715746                        fire_swarm(2 + plev / 20, GF_METEOR, dir, 30 + plev / 2, 1); 
    716747                        break; 
     
    719750                case SPELL_MANA_STORM: 
    720751                { 
    721                         if (!get_aim_dir(&dir)) return (FALSE); 
    722752                        fire_ball(GF_MANA, dir, 300 + (plev * 2), 3); 
    723753                        break; 
     
    737767                case SPELL_SHOCK_WAVE: 
    738768                { 
    739                         if (!get_aim_dir(&dir)) return (FALSE); 
    740769                        fire_ball(GF_SOUND, dir, 10 + plev, 2); 
    741770                        break; 
     
    744773                case SPELL_EXPLOSION: 
    745774                { 
    746                         if (!get_aim_dir(&dir)) return (FALSE); 
    747775                        fire_ball(GF_SHARD, dir, 20 + (plev * 2), 2); 
    748776                        break; 
     
    826854                case SPELL_RIFT: 
    827855                { 
    828                         if (!get_aim_dir(&dir)) return (FALSE); 
    829856                        fire_beam(GF_GRAVITY, dir,      40 + damroll(plev, 7)); 
    830857                        break; 
     
    833860                case SPELL_REND_SOUL: /* rend soul */ 
    834861                { 
    835                         if (!get_aim_dir(&dir)) return (FALSE); 
    836862                        fire_bolt_or_beam(beam / 4, GF_NETHER, dir, damroll(11, plev)); 
    837863                        break; 
     
    840866                case SPELL_CHAOS_STRIKE: /* chaos strike */ 
    841867                { 
    842                         if (!get_aim_dir(&dir)) return (FALSE); 
    843868                        fire_bolt_or_beam(beam, GF_CHAOS, dir, damroll(13, plev)); 
    844869                        break; 
     
    868893 
    869894 
    870 static bool cast_priest_spell(int spell) 
     895static bool cast_priest_spell(int spell, int dir) 
    871896{ 
    872897        int py = p_ptr->py; 
    873898        int px = p_ptr->px; 
    874  
    875         int dir; 
    876899 
    877900        int plev = p_ptr->lev; 
     
    934957                case PRAYER_SCARE_MONSTER: 
    935958                { 
    936                         if (!get_aim_dir(&dir)) return (FALSE); 
    937959                        (void)fear_monster(dir, plev); 
    938960                        break; 
     
    9931015                case PRAYER_ORB_OF_DRAINING: 
    9941016                { 
    995                         if (!get_aim_dir(&dir)) return (FALSE); 
    9961017                        fire_ball(GF_HOLY_ORB, dir, 
    9971018                                  (damroll(3, 6) + plev + 
     
    12091230                case PRAYER_ANNIHILATION: 
    12101231                { 
    1211                         if (!get_aim_dir(&dir)) return (FALSE); 
    12121232                        drain_life(dir, 200); 
    12131233                        break; 
     
    12611281                case PRAYER_TELEPORT_OTHER: 
    12621282                { 
    1263                         if (!get_aim_dir(&dir)) return (FALSE); 
    12641283                        (void)teleport_monster(dir); 
    12651284                        break; 
     
    12941313 
    12951314 
    1296 bool cast_spell(int tval, int index) 
     1315bool cast_spell(int tval, int index, int dir) 
    12971316{ 
    12981317        if (tval == TV_MAGIC_BOOK) 
    12991318        { 
    1300                 return cast_mage_spell(index); 
     1319                return cast_mage_spell(index, dir); 
    13011320        } 
    13021321        else 
    13031322        { 
    1304                 return cast_priest_spell(index); 
     1323                return cast_priest_spell(index, dir); 
    13051324        } 
    13061325}