-+-+-+-+-+-+-+-+ START OF PART 46 -+-+-+-+-+-+-+-+ Xstatic int summon_object(int, int, int, int); X#endif X X X/* Player hit a trap.`09(Chuckle)`09`09`09-RAK-`09*/ Xstatic void hit_trap(y, x) Xint y, x; X`7B X int i, ty, tx, num, dam; X register cave_type *c_ptr; X register struct misc *p_ptr; X register inven_type *t_ptr; X bigvtype tmp; X X end_find(); X change_trap(y, x); X c_ptr = &cave`5By`5D`5Bx`5D; X p_ptr = &py.misc; X t_ptr = &t_list`5Bc_ptr->tptr`5D; X dam = pdamroll(t_ptr->damage); X switch(t_ptr->subval) X `7B X case 1: /* Open pit*/ X msg_print("You fell into a pit!"); X if (py.flags.ffall) X`09msg_print("You gently float down."); X else X `7B X`09objdes(tmp, t_ptr, TRUE); X`09take_hit(dam, tmp); X `7D X break; X case 2: /* Arrow trap*/ X if (test_hit(125, 0, 0, p_ptr->pac+p_ptr->ptoac, CLA_MISC_HIT)) X`09`7B X`09 objdes(tmp, t_ptr, TRUE); X`09 take_hit(dam, tmp); X`09 msg_print("An arrow hits you."); X`09`7D X else X`09msg_print("An arrow barely misses you."); X break; X case 3: /* Covered pit*/ X msg_print("You fell into a covered pit."); X if (py.flags.ffall) X`09msg_print("You gently float down."); X else X `7B X`09objdes(tmp, t_ptr, TRUE); X`09take_hit(dam, tmp); X `7D X place_trap(y, x, 0); X break; X case 4: /* Trap door*/ X msg_print("You fell through a trap door!"); X new_level_flag = TRUE; X dun_level++; X if (py.flags.ffall) X`09msg_print("You gently float down."); X else X`09`7B X`09 objdes(tmp, t_ptr, TRUE); X`09 take_hit(dam, tmp); X`09`7D X /* Force the messages to display before starting to generate the X`09 next level. */ X msg_print (CNIL); X break; X case 5: /* Sleep gas*/ X if (py.flags.paralysis == 0) X`09`7B X`09 msg_print("A strange white mist surrounds you!"); X`09 if (py.flags.free_act) X`09 msg_print("You are unaffected."); X`09 else X`09 `7B X`09 msg_print("You fall asleep."); X`09 py.flags.paralysis += randint(10) + 4; X`09 `7D X`09`7D X break; X case 6: /* Hid Obj*/ X (void) delete_object(y, x); X place_object(y, x); X msg_print("Hmmm, there was something under this rock."); X break; X case 7: /* STR Dart*/ X if (test_hit(125, 0, 0, p_ptr->pac+p_ptr->ptoac, CLA_MISC_HIT)) X`09`7B X`09 if (!py.flags.sustain_str) X`09 `7B X`09 (void) dec_stat(A_STR); X`09 objdes(tmp, t_ptr, TRUE); X`09 take_hit(dam, tmp); X`09 msg_print("A small dart weakens you!"); X`09 `7D X`09 else X`09 msg_print("A small dart hits you."); X`09`7D X else X`09msg_print("A small dart barely misses you."); X break; X case 8: /* Teleport*/ X teleport_flag = TRUE; X msg_print("You hit a teleport trap!"); X /* Light up the teleport trap, before we teleport away. */ X move_light (y, x, y, x); X break; X case 9: /* Rockfall*/ X take_hit(dam, "a falling rock"); X (void) delete_object(y, x); X place_rubble(y, x); X msg_print("You are hit by falling rock."); X break; X case 10: /* Corrode gas*/ X /* Makes more sense to print the message first, then damage an X`09 object. */ X msg_print("A strange red gas surrounds you."); X corrode_gas("corrosion gas"); X break; X case 11: /* Summon mon*/ X (void) delete_object(y, x);`09/* Rune disappears. */ X num = 2 + randint (3); X for (i = 0; i < num; i++) X`09`7B X`09 ty = y; X`09 tx = x; X`09 (void) summon_monster(&ty, &tx, FALSE); X`09`7D X break; X case 12: /* Fire trap*/ X msg_print("You are enveloped in flames!"); X fire_dam(dam, "a fire trap"); X break; X case 13: /* Acid trap*/ X msg_print("You are splashed with acid!"); X acid_dam(dam, "an acid trap"); X break; X case 14: /* Poison gas*/ X msg_print("A pungent green gas surrounds you!"); X poison_gas(dam, "a poison gas trap"); X break; X case 15: /* Blind Gas */ X msg_print("A black gas surrounds you!"); X py.flags.blind += randint(50) + 50; X break; X case 16: /* Confuse Gas*/ X msg_print("A gas of scintillating colors surrounds you!"); X py.flags.confused += randint(15) + 15; X break; X case 17: /* Slow Dart*/ X if (test_hit(125, 0, 0, p_ptr->pac+p_ptr->ptoac, CLA_MISC_HIT)) X`09`7B X`09 objdes(tmp, t_ptr, TRUE); X`09 take_hit(dam, tmp); X`09 msg_print("A small dart hits you!"); X`09 if (py.flags.free_act) X`09 msg_print("You are unaffected."); X`09 else X`09 py.flags.slow += randint(20) + 10; X`09`7D X else X`09msg_print("A small dart barely misses you."); X break; X case 18: /* CON Dart*/ X if (test_hit(125, 0, 0, p_ptr->pac+p_ptr->ptoac, CLA_MISC_HIT)) X`09`7B X`09 if (!py.flags.sustain_con) X`09 `7B X`09 (void) dec_stat(A_CON); X`09 objdes(tmp, t_ptr, TRUE); X`09 take_hit(dam, tmp); X`09 msg_print("A small dart saps your health!"); X`09 `7D X`09 else X`09 msg_print("A small dart hits you."); X`09`7D X else X`09msg_print("A small dart barely misses you."); X break; X case 19: /*Secret Door*/ X break; X case 99: /* Scare Mon*/ X break; X X /* Town level traps are special,`09the stores.`09*/ X case 101: /* General */ X enter_store(0); X break; X case 102: /* Armory`09 */ X enter_store(1); X break; X case 103: /* Weaponsmith*/ X enter_store(2); X break; X case 104: /* Temple`09 */ X enter_store(3); X break; X case 105: /* Alchemy */ X enter_store(4); X break; X case 106: /* Magic-User */ X enter_store(5); X break; X X default: X msg_print("Unknown trap value."); X break; X `7D X`7D X X X/* Return spell number and failure chance`09`09-RAK-`09*/ X/* returns -1 if no spells in book X returns 1 if choose a spell in book to cast X returns 0 if don't choose a spell, i.e. exit with an escape */ Xint cast_spell(prompt, item_val, sn, sc) Xchar *prompt; Xint item_val; Xint *sn, *sc; X`7B X int32u j; X register int i, k; X int spell`5B31`5D, result, first_spell; X register spell_type *s_ptr; X X result = -1; X i = 0; X j = inventory`5Bitem_val`5D.flags; X first_spell = bit_pos(&j); X /* set j again, since bit_pos modified it */ X j = inventory`5Bitem_val`5D.flags & spell_learned; X s_ptr = magic_spell`5Bpy.misc.pclass-1`5D; X while (j) X `7B X k = bit_pos(&j); X if (s_ptr`5Bk`5D.slevel <= py.misc.lev) X`09`7B X`09 spell`5Bi`5D = k; X`09 i++; X`09`7D X `7D X if (i > 0) X `7B X result = get_spell(spell, i, sn, sc, prompt, first_spell); X if (result && magic_spell`5Bpy.misc.pclass-1`5D`5B*sn`5D.smana > py.mi Vsc.cmana) X`09`7B X`09 if (class`5Bpy.misc.pclass`5D.spell == MAGE) X`09 result = get_check("You summon your limited strength to cast \ Xthis one! Confirm?"); X`09 else X`09 result = get_check("The gods may think you presumptuous for \ Xthis! Confirm?"); X`09`7D X `7D X return(result); X`7D X X X/* Player is on an object. Many things can happen based -RAK-`09*/ X/* on the TVAL of the object. Traps are set off, money and most */ X/* objects are picked up. Some objects, such as open doors, just*/ X/* sit there.`09`09`09`09`09`09 */ Xstatic void carry(y, x, pickup) Xint y, x; Xint pickup; X`7B X register int locn, i; X bigvtype out_val, tmp_str; X register cave_type *c_ptr; X register inven_type *i_ptr; X X c_ptr = &cave`5By`5D`5Bx`5D; X i_ptr = &t_list`5Bc_ptr->tptr`5D; X i = t_list`5Bc_ptr->tptr`5D.tval; X if (i <= TV_MAX_PICK_UP) X `7B X end_find(); X /* There's GOLD in them thar hills! */ X if (i == TV_GOLD) X`09`7B X`09 py.misc.au += i_ptr->cost; X`09 objdes(tmp_str, i_ptr, TRUE); X`09 (void) sprintf(out_val, X`09`09`09 "You have found %ld gold pieces worth of %s", X`09`09`09 i_ptr->cost, tmp_str); X`09 prt_gold(); X`09 (void) delete_object(y, x); X`09 msg_print(out_val); X`09`7D X else X`09`7B X`09 if (inven_check_num(i_ptr))`09 /* Too many objects?`09 */ X`09 `7B`09`09`09 /* Okay, pick it up */ X`09 if (pickup && prompt_carry_flag) X`09`09`7B X`09`09 objdes(tmp_str, i_ptr, TRUE); X`09`09 /* change the period to a question mark */ X`09`09 tmp_str`5Bstrlen(tmp_str)-1`5D = '?'; X`09`09 (void) sprintf(out_val, "Pick up %s", tmp_str); X`09`09 pickup = get_check(out_val); X`09`09`7D X`09 /* Check to see if it will change the players speed. */ X`09 if (pickup && !inven_check_weight(i_ptr)) X`09`09`7B X`09`09 objdes(tmp_str, i_ptr, TRUE); X`09`09 /* change the period to a question mark */ X`09`09 tmp_str`5Bstrlen(tmp_str)-1`5D = '?'; X`09`09 (void) sprintf(out_val, X`09`09`09`09 "Exceed your weight limit to pick up %s", X`09`09`09`09 tmp_str); X`09`09 pickup = get_check(out_val); X`09`09`7D X`09 /* Attempt to pick up an object.`09 */ X`09 if (pickup) X`09`09`7B X`09`09 locn = inven_carry(i_ptr); X`09`09 objdes(tmp_str, &inventory`5Blocn`5D, TRUE); X`09`09 (void) sprintf(out_val, "You have %s (%c)",tmp_str,locn+'a'); X`09`09 msg_print(out_val); X`09`09 (void) delete_object(y, x); X`09`09`7D X`09 `7D X`09 else X`09 `7B X`09 objdes(tmp_str, i_ptr, TRUE); X`09 (void) sprintf(out_val, "You can't carry %s", tmp_str); X`09 msg_print(out_val); X`09 `7D X`09`7D X `7D X /* OPPS!`09`09`09`09 */ X else if (i == TV_INVIS_TRAP `7C`7C i == TV_VIS_TRAP `7C`7C i == TV_STORE_D VOOR) X hit_trap(y, x); X`7D X X X/* Deletes a monster entry from the level`09`09-RAK-`09*/ Xvoid delete_monster(j) Xint j; X`7B X register monster_type *m_ptr; X X m_ptr = &m_list`5Bj`5D; X cave`5Bm_ptr->fy`5D`5Bm_ptr->fx`5D.cptr = 0; X if (m_ptr->ml) X lite_spot((int)m_ptr->fy, (int)m_ptr->fx); X if (j != mfptr - 1) X `7B X m_ptr = &m_list`5Bmfptr - 1`5D; X cave`5Bm_ptr->fy`5D`5Bm_ptr->fx`5D.cptr = j; X m_list`5Bj`5D = m_list`5Bmfptr - 1`5D; X `7D X mfptr--; X m_list`5Bmfptr`5D = blank_monster; X if (mon_tot_mult > 0) X mon_tot_mult--; X`7D X X/* The following two procedures implement the same function as delete monste Vr. X However, they are used within creatures(), because deleting a monster X while scanning the m_list causes two problems, monsters might get two X turns, and m_ptr/monptr might be invalid after the delete_monster. X Hence the delete is done in two steps. */ X/* fix1_delete_monster does everything delete_monster does except delete X the monster record and reduce mfptr, this is called in breathe, and X a couple of places in creatures.c */ Xvoid fix1_delete_monster(j) Xint j; X`7B X register monster_type *m_ptr; X X m_ptr = &m_list`5Bj`5D; X /* force the hp negative to ensure that the monster is dead, for example, X if the monster was just eaten by another, it will still have positive X hit points */ X m_ptr->hp = -1; X cave`5Bm_ptr->fy`5D`5Bm_ptr->fx`5D.cptr = 0; X if (m_ptr->ml) X lite_spot((int)m_ptr->fy, (int)m_ptr->fx); X if (mon_tot_mult > 0) X mon_tot_mult--; X`7D X X/* fix2_delete_monster does everything in delete_monster that wasn't done X by fix1_monster_delete above, this is only called in creatures() */ Xvoid fix2_delete_monster(j) Xint j; X`7B X register monster_type *m_ptr; X X if (j != mfptr - 1) X `7B X m_ptr = &m_list`5Bmfptr - 1`5D; X cave`5Bm_ptr->fy`5D`5Bm_ptr->fx`5D.cptr = j; X m_list`5Bj`5D = m_list`5Bmfptr - 1`5D; X `7D X m_list`5Bmfptr - 1`5D = blank_monster; X mfptr--; X`7D X X X/* Creates objects nearby the coordinates given`09`09-RAK-`09 */ Xstatic int summon_object(y, x, num, typ) Xint y, x, num, typ; X`7B X register int i, j, k; X register cave_type *c_ptr; X int real_typ, res; X X if (typ == 1) X real_typ = 1; /* typ == 1 -> objects */ X else X real_typ = 256; /* typ == 2 -> gold */ X res = 0; X do X `7B X i = 0; X do X`09`7B X`09 j = y - 3 + randint(5); X`09 k = x - 3 + randint(5); X`09 if (in_bounds(j, k) && los(y, x, j, k)) X`09 `7B X`09 c_ptr = &cave`5Bj`5D`5Bk`5D; X`09 if (c_ptr->fval <= MAX_OPEN_SPACE && (c_ptr->tptr == 0)) X`09`09`7B X`09`09 if (typ == 3) /* typ == 3 -> 50% objects, 50% gold */ X`09`09 `7B X`09`09 if (randint(100) < 50) X`09`09`09real_typ = 1; X`09`09 else X`09`09`09real_typ = 256; X`09`09 `7D X`09`09 if (real_typ == 1) X`09`09 place_object(j, k); X`09`09 else X`09`09 place_gold(j, k); X`09`09 lite_spot(j, k); X`09`09 if (test_light(j, k)) X`09`09 res += real_typ; X`09`09 i = 20; X`09`09`7D X`09 `7D X`09 i++; X`09`7D X while (i <= 20); X num--; X `7D X while (num != 0); X return res; X`7D X X X/* Deletes object from given location`09`09`09-RAK-`09*/ Xint delete_object(y, x) Xint y, x; X`7B X register int delete; X register cave_type *c_ptr; X X c_ptr = &cave`5By`5D`5Bx`5D; X if (c_ptr->fval == BLOCKED_FLOOR) X c_ptr->fval = CORR_FLOOR; X pusht(c_ptr->tptr); X c_ptr->tptr = 0; X c_ptr->fm = FALSE; X lite_spot(y, x); X if (test_light(y, x)) X delete = TRUE; X else X delete = FALSE; X return(delete); X`7D X X X/* Allocates objects upon a creatures death`09`09-RAK-`09*/ X/* Oh well, another creature bites the dust. Reward the victor*/ X/* based on flags set in the main creature record`09`09 */ X/* Returns a mask of bits from the given flags which indicates what the X monster is seen to have dropped. This may be added to monster memory. */ Xint32u monster_death(y, x, flags) Xint y, x; Xregister int32u flags; X`7B X register int i, number; X int32u dump, res; X#if defined(ATARIST_MWC) X int32u holder;`09/* avoid a compiler bug */ X#endif X X#if !defined(ATARIST_MWC) X if (flags & CM_CARRY_OBJ) X i = 1; X else X i = 0; X if (flags & CM_CARRY_GOLD) X i += 2; X X number = 0; X if ((flags & CM_60_RANDOM) && (randint(100) < 60)) X number++; X if ((flags & CM_90_RANDOM) && (randint(100) < 90)) X number++; X if (flags & CM_1D2_OBJ) X number += randint(2); X if (flags & CM_2D2_OBJ) X number += damroll(2, 2); X if (flags & CM_4D2_OBJ) +-+-+-+-+-+-+-+- END OF PART 46 +-+-+-+-+-+-+-+-