Changeset 466

Show
Ignore:
Timestamp:
08/07/07 20:04:02 (1 year ago)
Author:
takkaria
Message:

Move trap code out into trap.c as part of #65, in anticipation of having a better trap system.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/Makefile.src

    r463 r466  
    5454        store.o \ 
    5555        tables.o \ 
     56        trap.o \ 
    5657        ui.o \ 
    5758        util.o  \ 
  • trunk/src/cmd1.c

    r465 r466  
    9999} 
    100100 
     101 
     102/*** Pickup ***/ 
    101103 
    102104/* 
     
    563565 
    564566/* 
    565  * Determine if a trap affects the player. 
    566  * Always miss 5% of the time, Always hit 5% of the time. 
    567  * Otherwise, match trap power against player armor. 
    568  */ 
    569 static bool check_hit(int power) 
    570 { 
    571         return test_hit(power, p_ptr->ac + p_ptr->to_a, TRUE); 
    572 } 
    573  
    574  
    575 /* 
    576  * Handle player hitting a real trap 
    577  */ 
    578 void hit_trap(int y, int x) 
    579 { 
    580         int i, num, dam; 
    581  
    582         cptr name = "a trap"; 
    583  
    584  
    585         /* Disturb the player */ 
    586         disturb(0, 0); 
    587  
    588         /* Analyze XXX XXX XXX */ 
    589         switch (cave_feat[y][x]) 
    590         { 
    591                 case FEAT_TRAP_HEAD + 0x00: 
    592                 { 
    593                         msg_print("You fall through a trap door!"); 
    594                         if (p_ptr->ffall) 
    595                         { 
    596                                 msg_print("You float gently down to the next level."); 
    597                         } 
    598                         else 
    599                         { 
    600                                 dam = damroll(2, 8); 
    601                                 take_hit(dam, name); 
    602                         } 
    603  
    604                         /* New depth */ 
    605                         p_ptr->depth++; 
    606  
    607                         /* Leaving */ 
    608                         p_ptr->leaving = TRUE; 
    609  
    610                         break; 
    611                 } 
    612  
    613                 case FEAT_TRAP_HEAD + 0x01: 
    614                 { 
    615                         msg_print("You fall into a pit!"); 
    616                         if (p_ptr->ffall) 
    617                         { 
    618                                 msg_print("You float gently to the bottom of the pit."); 
    619                         } 
    620                         else 
    621                         { 
    622                                 dam = damroll(2, 6); 
    623                                 take_hit(dam, name); 
    624                         } 
    625                         break; 
    626                 } 
    627  
    628                 case FEAT_TRAP_HEAD + 0x02: 
    629                 { 
    630                         msg_print("You fall into a spiked pit!"); 
    631  
    632                         if (p_ptr->ffall) 
    633                         { 
    634                                 msg_print("You float gently to the floor of the pit."); 
    635                                 msg_print("You carefully avoid touching the spikes."); 
    636                         } 
    637  
    638                         else 
    639                         { 
    640                                 /* Base damage */ 
    641                                 dam = damroll(2, 6); 
    642  
    643                                 /* Extra spike damage */ 
    644                                 if (rand_int(100) < 50) 
    645                                 { 
    646                                         msg_print("You are impaled!"); 
    647  
    648                                         dam = dam * 2; 
    649                                         (void)inc_timed(TMD_CUT, randint(dam)); 
    650                                 } 
    651  
    652                                 /* Take the damage */ 
    653                                 take_hit(dam, name); 
    654                         } 
    655                         break; 
    656                 } 
    657  
    658                 case FEAT_TRAP_HEAD + 0x03: 
    659                 { 
    660                         msg_print("You fall into a spiked pit!"); 
    661  
    662                         if (p_ptr->ffall) 
    663                         { 
    664                                 msg_print("You float gently to the floor of the pit."); 
    665                                 msg_print("You carefully avoid touching the spikes."); 
    666                         } 
    667  
    668                         else 
    669                         { 
    670                                 /* Base damage */ 
    671                                 dam = damroll(2, 6); 
    672  
    673                                 /* Extra spike damage */ 
    674                                 if (rand_int(100) < 50) 
    675                                 { 
    676                                         msg_print("You are impaled on poisonous spikes!"); 
    677  
    678                                         dam = dam * 2; 
    679                                         (void)inc_timed(TMD_CUT, randint(dam)); 
    680  
    681                                         if (p_ptr->resist_pois || p_ptr->timed[TMD_OPP_POIS]) 
    682                                         { 
    683                                                 msg_print("The poison does not affect you!"); 
    684                                         } 
    685                                         else 
    686                                         { 
    687                                                 dam = dam * 2; 
    688                                                 (void)inc_timed(TMD_POISONED, randint(dam)); 
    689                                         } 
    690                                 } 
    691  
    692                                 /* Take the damage */ 
    693                                 take_hit(dam, name); 
    694                         } 
    695  
    696                         break; 
    697                 } 
    698  
    699                 case FEAT_TRAP_HEAD + 0x04: 
    700                 { 
    701                         sound(MSG_SUM_MONSTER); 
    702                         msg_print("You are enveloped in a cloud of smoke!"); 
    703                         cave_info[y][x] &= ~(CAVE_MARK); 
    704                         cave_set_feat(y, x, FEAT_FLOOR); 
    705                         num = 2 + randint(3); 
    706                         for (i = 0; i < num; i++) 
    707                         { 
    708                                 (void)summon_specific(y, x, p_ptr->depth, 0); 
    709                         } 
    710                         break; 
    711                 } 
    712  
    713                 case FEAT_TRAP_HEAD + 0x05: 
    714                 { 
    715                         msg_print("You hit a teleport trap!"); 
    716                         teleport_player(100); 
    717                         break; 
    718                 } 
    719  
    720                 case FEAT_TRAP_HEAD + 0x06: 
    721                 { 
    722                         msg_print("You are enveloped in flames!"); 
    723                         dam = damroll(4, 6); 
    724                         fire_dam(dam, "a fire trap"); 
    725                         break; 
    726                 } 
    727  
    728                 case FEAT_TRAP_HEAD + 0x07: 
    729                 { 
    730                         msg_print("You are splashed with acid!"); 
    731                         dam = damroll(4, 6); 
    732                         acid_dam(dam, "an acid trap"); 
    733                         break; 
    734                 } 
    735  
    736                 case FEAT_TRAP_HEAD + 0x08: 
    737                 { 
    738                         if (check_hit(125)) 
    739                         { 
    740                                 msg_print("A small dart hits you!"); 
    741                                 dam = damroll(1, 4); 
    742                                 take_hit(dam, name); 
    743                                 (void)inc_timed(TMD_SLOW, rand_int(20) + 20); 
    744                         } 
    745                         else 
    746                         { 
    747                                 msg_print("A small dart barely misses you."); 
    748                         } 
    749                         break; 
    750                 } 
    751  
    752                 case FEAT_TRAP_HEAD + 0x09: 
    753                 { 
    754                         if (check_hit(125)) 
    755                         { 
    756                                 msg_print("A small dart hits you!"); 
    757                                 dam = damroll(1, 4); 
    758                                 take_hit(dam, name); 
    759                                 (void)do_dec_stat(A_STR, FALSE); 
    760                         } 
    761                         else 
    762                         { 
    763                                 msg_print("A small dart barely misses you."); 
    764                         } 
    765                         break; 
    766                 } 
    767  
    768                 case FEAT_TRAP_HEAD + 0x0A: 
    769                 { 
    770                         if (check_hit(125)) 
    771                         { 
    772                                 msg_print("A small dart hits you!"); 
    773                                 dam = damroll(1, 4); 
    774                                 take_hit(dam, name); 
    775                                 (void)do_dec_stat(A_DEX, FALSE); 
    776                         } 
    777                         else 
    778                         { 
    779                                 msg_print("A small dart barely misses you."); 
    780                         } 
    781                         break; 
    782                 } 
    783  
    784                 case FEAT_TRAP_HEAD + 0x0B: 
    785                 { 
    786                         if (check_hit(125)) 
    787                         { 
    788                                 msg_print("A small dart hits you!"); 
    789                                 dam = damroll(1, 4); 
    790                                 take_hit(dam, name); 
    791                                 (void)do_dec_stat(A_CON, FALSE); 
    792                         } 
    793                         else 
    794                         { 
    795                                 msg_print("A small dart barely misses you."); 
    796                         } 
    797                         break; 
    798                 } 
    799  
    800                 case FEAT_TRAP_HEAD + 0x0C: 
    801                 { 
    802                         msg_print("You are surrounded by a black gas!"); 
    803                         if (!p_ptr->resist_blind) 
    804                         { 
    805                                 (void)inc_timed(TMD_BLIND, rand_int(50) + 25); 
    806                         } 
    807                         break; 
    808                 } 
    809  
    810                 case FEAT_TRAP_HEAD + 0x0D: 
    811                 { 
    812                         msg_print("You are surrounded by a gas of scintillating colors!"); 
    813                         if (!p_ptr->resist_confu) 
    814                         { 
    815                                 (void)inc_timed(TMD_CONFUSED, rand_int(20) + 10); 
    816                         } 
    817                         break; 
    818                 } 
    819  
    820                 case FEAT_TRAP_HEAD + 0x0E: 
    821                 { 
    822                         msg_print("You are surrounded by a pungent green gas!"); 
    823                         if (!p_ptr->resist_pois && !p_ptr->timed[TMD_OPP_POIS]) 
    824                         { 
    825                                 (void)inc_timed(TMD_POISONED, rand_int(20) + 10); 
    826                         } 
    827                         break; 
    828                 } 
    829  
    830                 case FEAT_TRAP_HEAD + 0x0F: 
    831                 { 
    832                         msg_print("You are surrounded by a strange white mist!"); 
    833                         if (!p_ptr->free_act) 
    834                         { 
    835                                 (void)inc_timed(TMD_PARALYZED, rand_int(10) + 5); 
    836                         } 
    837                         break; 
    838                 } 
    839         } 
    840 } 
    841  
    842  
    843  
    844  
    845 /* 
    846567 * Move player in the given direction, with the given "pickup" flag. 
    847568 * 
  • trunk/src/externs.h

    r465 r466  
    303303extern void search(void); 
    304304extern byte py_pickup(int pickup); 
    305 extern void hit_trap(int y, int x); 
    306305extern void move_player(int dir); 
    307306 
     
    446445extern void place_object(int y, int x, int level, bool good, bool great); 
    447446extern void place_gold(int y, int x, int level); 
    448 extern void pick_trap(int y, int x); 
    449 extern void place_trap(int y, int x); 
    450447extern void place_secret_door(int y, int x); 
    451448extern void place_closed_door(int y, int x); 
     
    612609extern void store_init(void); 
    613610 
     611/* trap.c */ 
     612extern void hit_trap(int y, int x); 
     613extern void pick_trap(int y, int x); 
     614extern void place_trap(int y, int x); 
     615 
    614616/* typeutils.c */ 
    615617void display_panel(const data_panel *panel, int count, 
  • trunk/src/object2.c

    r452 r466  
    34023402 
    34033403 
    3404 /* 
    3405  * Hack -- instantiate a trap 
    3406  * 
    3407  * XXX XXX XXX This routine should be redone to reflect trap "level". 
    3408  * That is, it does not make sense to have spiked pits at 50 feet. 
    3409  * Actually, it is not this routine, but the "trap instantiation" 
    3410  * code, which should also check for "trap doors" on quest levels. 
    3411  */ 
    3412 void pick_trap(int y, int x) 
    3413 { 
    3414         int feat; 
    3415  
    3416         /* Paranoia */ 
    3417         if (cave_feat[y][x] != FEAT_INVIS) return; 
    3418  
    3419         /* Pick a trap */ 
    3420         while (1) 
    3421         { 
    3422                 /* Hack -- pick a trap */ 
    3423                 feat = FEAT_TRAP_HEAD + rand_int(16); 
    3424  
    3425                 /* Hack -- no trap doors on quest levels */ 
    3426                 if ((feat == FEAT_TRAP_HEAD + 0x00) && is_quest(p_ptr->depth)) continue; 
    3427  
    3428                 /* Hack -- no trap doors on the deepest level */ 
    3429                 if ((feat == FEAT_TRAP_HEAD + 0x00) && (p_ptr->depth >= MAX_DEPTH-1)) continue; 
    3430  
    3431                 /* Done */ 
    3432                 break; 
    3433         } 
    3434  
    3435         /* Activate the trap */ 
    3436         cave_set_feat(y, x, feat); 
    3437 } 
    3438  
    3439  
    3440  
    3441 /* 
    3442  * Places a random trap at the given location. 
    3443  * 
    3444  * The location must be a legal, naked, floor grid. 
    3445  * 
    3446  * Note that all traps start out as "invisible" and "untyped", and then 
    3447  * when they are "discovered" (by detecting them or setting them off), 
    3448  * the trap is "instantiated" as a visible, "typed", trap. 
    3449  */ 
    3450 void place_trap(int y, int x) 
    3451 { 
    3452         /* Paranoia */ 
    3453         if (!in_bounds(y, x)) return; 
    3454  
    3455         /* Require empty, clean, floor grid */ 
    3456         if (!cave_naked_bold(y, x)) return; 
    3457  
    3458         /* Place an invisible trap */ 
    3459         cave_set_feat(y, x, FEAT_INVIS); 
    3460 } 
    3461  
    34623404 
    34633405/*