-+-+-+-+-+-+-+-+ START OF PART 20 -+-+-+-+-+-+-+-+ X`09`09`09 msg_print('You have forgotten a discipline!'); X`09`09 end; X`09`09 end; X`09 end; X`09 if (chp > mhp) then chp := mhp; X`09 if (cmana > mana) then cmana := mana; X`09 title := player_title`5Bpclass,lev`5D; X`09 prt_experience; X`09 prt_hp; X`09 if (is_magii) then prt_mana; X`09 prt_level; X`09 prt_title; X`09end; X end; X X X`09`7B Tunneling through real wall: 10,11,12 `09`09-RAK-`09`7D X`09`7B Used by TUNNEL and WALL_TO_MUD `7D X `5Bglobal,psect(moria$code)`5D function twall(y,x,t1,t2 : integer) : b Voolean; X`09begin X`09 twall := false; X`09 with cave`5By,x`5D do X`09 if (t1 > t2) then X`09 begin X`09`09if (next_to4(y,x,`5B1,2`5D) > 0) then X`09`09 begin X`09`09 fval := corr_floor2.ftval; X`09`09 fopen := corr_floor2.ftopen; X`09`09 end X`09`09else X`09`09 begin X`09`09 fval := corr_floor1.ftval; X`09`09 fopen := corr_floor1.ftopen; X`09`09 end; X`09`09if (test_light(y,x)) then X`09`09 if (panel_contains(y,x)) then X`09`09 begin X`09`09 if (tptr > 0) then X`09`09`09msg_print('You have found something!'); X`09`09 lite_spot(y,x); X`09`09 end; X`09`09fm := false; X`09`09pl := false; X`09`09twall := true; X`09 end; X`09end; X X X`09`7B Moria game module`09`09`09`09`09-RAK-`09`7D X`09`7B The code in this section has gone through many revisions, and `7D X`09`7B some of it could stand some more hard work... -RAK- `7D X`5Bglobal,psect(moria$code)`5D procedure dungeon; X X function water_hear_range : integer; X begin X`09water_hear_range := 10; X end; X X function water_see_range : integer; X begin X`09water_see_range := 5; X end; X X X`09`7B I may have written the town level code, but I'm not exactly `7D X`09`7B proud of it. Adding the stores required some real slucky `7D X`09`7B hooks which I have not had time to re-think. -RAK- `7D X X X`09`7B Prompts for a direction`09`09`09`09-RAK-`09`7D X function get_dir(prompt : vtype; X`09`09 var dir,com_val,y,x : integer) : boolean; X var X`09`09temp_prompt : vtype; X`09`09flag : boolean; X`09`09command : char; X begin X`09flag := false; X`09temp_prompt := '(1 2 3 4 6 7 8 9) ' + prompt; X`09prompt := ''; X`09repeat X`09 if (get_com(prompt,command)) then X`09 begin X`09 com_val := ord(command); X`09 dir := com_val - 48; X`09`09`7B Note that '5' is not a valid direction `7D X`09 if (dir in `5B1,2,3,4,6,7,8,9`5D) then X`09`09begin X`09`09 move(dir,y,x); X`09`09 flag := true; X`09`09 get_dir := true; X`09`09end X`09 else X`09`09prompt := temp_prompt; X`09 end X`09 else X`09 begin X`09 reset_flag := true; X`09 get_dir := false; X`09 flag := true; X`09 end; X`09until (flag); X end; X X X`09`7B Returns random co-ordinates`09`09`09`09-RAK-`09`7D X procedure new_spot(var y,x : integer; swim : boolean); X begin X`09repeat X`09 y := randint(cur_height); X`09 x := randint(cur_width); X`09until ( (cave`5By,x`5D.fopen) and X`09`09(cave`5By,x`5D.cptr = 0) and X`09`09(cave`5By,x`5D.tptr = 0)`09and X`09`09(swim or (swim <> (cave`5By,x`5D.fval in water_set)))); X end; X X X`09`7B Search Mode enhancement`09`09`09`09-RAK-`09`7D X procedure search_on; X begin X`09search_flag := true; X`09change_speed(+1); X`09py.flags.status := uor(py.flags.status,%X'00000100'); X`09prt_search; X`09with py.flags do X`09 food_digested := food_digested + 1; X end; X X`09`7B Resting allows a player to safely restore his hp`09-RAK-`09`7D X procedure rest; X var X`09`09rest_num : integer; X`09`09rest_str : vtype; X begin X`09prt('Rest for how long? ',1,1); X`09get_string(rest_str,1,20,10); X`09rest_num := 0; X`09readv(rest_str,rest_num,error:=continue); X`09if (rest_num > 0) then X`09 begin X`09 if (search_flag) then X`09 search_off; X`09 py.flags.rest := rest_num; X`09 turn_counter := turn_counter + rest_num; X`09 py.flags.status := uor(py.flags.status,%X'00000200'); X`09 prt_rest; X`09 with py.flags do X`09 food_digested := food_digested - 1; X`09 msg_print('Press any key to wake up...'); X`09 put_qio; X`09 end X`09else X`09 erase_line(msg_line,msg_line); X end; X X X`09`7B Teleport the player to a new location `09`09-RAK-`09`7D X procedure teleport(dis : integer); X var X`09`09y,x : integer; X begin X`09repeat X`09 y := randint(cur_height); X`09 x := randint(cur_width); X`09 while (distance(y,x,char_row,char_col) > dis) do X`09 begin X`09 y := y + trunc((char_row-y)/2); X`09 x := x + trunc((char_col-x)/2); X`09 end; X`09until ((cave`5By,x`5D.fopen) and (cave`5By,x`5D.cptr < 2)); X`09move_rec(char_row,char_col,y,x); X`09for i1 := char_row-1 to char_row+1 do X`09 for i2 := char_col-1 to char_col+1 do X`09 with cave`5Bi1,i2`5D do X`09 begin X`09`09tl := false; X`09`09if (not(test_light(i1,i2))) then X`09`09 unlite_spot(i1,i2); X`09 end; X`09if (test_light(char_row,char_col)) then X`09 lite_spot(char_row,char_col); X`09char_row := y; X`09char_col := x; X`09move_char(5); X`09creatures(false); X`09teleport_flag := false; X end; X X X`09`7B Return spell number and failure chance`09`09-RAK-`09`7D X function cast_spell(prompt`09`09: vtype; X`09`09`09item_ptr`09: treas_ptr; X`09`09`09var sn,sc`09: integer; X`09`09`09var redraw`09: boolean) : boolean; X var X`09`09i2,i4 : unsigned; X`09`09i1,i3 : integer; X`09`09spell : spl_type; X begin X`09i1 := 0; X`09i2 := item_ptr`5E.data.flags; X`09i4 := item_ptr`5E.data.flags2; X`09repeat X`09 i3 := bit_pos64(i4,i2); X`7B Avoid the cursed bit like the plague`09`09`09`09-DMF-`09`7D X`09 if (i3 > 31) then i3 := i3 - 1; X`09 if (i3 > 0) then X`09 with magic_spell`5Bpy.misc.pclass,i3`5D do X`09 if (slevel <= py.misc.lev) then X`09`09if (learned) then X`09`09 begin X`09`09 i1 := i1 + 1; X`09`09 spell`5Bi1`5D.splnum := i3; X`09`09 end; X`09until((i2 = 0) and (i4 = 0)); X`09if (i1 > 0) then X`09 cast_spell := get_spell(spell,i1,sn,sc,prompt,redraw); X`09if (redraw) then X`09 draw_cave; X end; X X X`09`7B Examine a Book`09`09`09`09`09-RAK-`09`7D X procedure examine_book; X var X`09`09i2,i4 : unsigned; X`09`09i3,i5`09`09`09: integer; X`09`09i1,item_ptr`09`09: treas_ptr; X`09`09redraw,flag : boolean; X`09`09dummy : char; X`09`09out_val : vtype; X begin X`09redraw := false; X`09if (not(find_range(`5BMagic_book,Prayer_Book,Instrument,Song_book`5D,fals Ve,i1,i3))) then X`09 msg_print('You are not carrying any books.') X`09else if (get_item(item_ptr,'Which Book?',redraw,i3,trash_char,false)) the Vn X`09 begin X`09 flag := true; X`09 with item_ptr`5E.data do X`09 if (class`5Bpy.misc.pclass`5D.mspell) then X`09`09begin X`09`09 if (tval <> Magic_Book) then X`09`09 begin X`09`09 msg_print('You do not understand the language.'); X`09`09 flag := false; X`09`09 end; X`09`09end X`09 else if (class`5Bpy.misc.pclass`5D.pspell) then X`09`09begin X`09`09 if (tval <> Prayer_Book) then X`09`09 begin X`09`09 msg_print('You do not understand the language.'); X`09`09 flag := false; X`09`09 end; X`09`09end X`09 else if (class`5Bpy.misc.pclass`5D.dspell) then X`09`09begin X`09`09 if (tval <> Instrument) then X`09`09 begin X`09`09 msg_print('You do not posses the talent.'); X`09`09 flag := false; X`09`09 end; X`09`09end X`09 else if (class`5Bpy.misc.pclass`5D.bspell) then X`09`09begin X`09`09 if (tval <> Song_book) then X`09`09 begin X`09`09 msg_print('You can not read the music.'); X`09`09 flag := false; X`09`09 end; X`09`09end X`09 else X`09`09begin X`09`09 msg_print('You do not understand the language.'); X`09`09 flag := false; X`09`09end; X`09 if (flag) then X`09 begin X`09`09redraw := true; X`09`09i5 := 0; X`09`09i2 := item_ptr`5E.data.flags; X`09`09i4 := item_ptr`5E.data.flags2; X`09`09clear(1,1); X`09writev(out_val,' Name Level Mana Known'); X`09`09prt(out_val,1,1); X`09`09repeat X`09`09 i3 := bit_pos64(i4,i2); X`09`09 if (i3 > 31) then i3 := i3 - 1; X`09`09 if (i3 > 0) then X`09`09 with magic_spell`5Bpy.misc.pclass,i3`5D do X`09`09 begin X`09`09`09i5 := i5 + 1; X`09`09`09if (slevel < 99) then X`09`09`09 begin X`09`09`09 writev(out_val,chr(96+i5),') ',pad(sname,' ',30), X`09`09`09`09slevel:2,' ',smana:2,' ',learned); X`09`09`09 prt(out_val,i5+1,1); X`09`09`09 end X`09`09`09else X`09`09`09 prt('',i5+1,1); X`09`09 end; X`09`09until ((i2 = 0) and (i4 = 0)); X`09`09prt('`5BPress any key to continue`5D',24,20); X`09`09inkey(dummy); X`09 end; X`09 end; X`09if (redraw) then draw_cave; X end; X X X`09`7B Drop an object being carried`09`09`09`09-RAK-`09`7D X`09`7B Note: Only one object per floor spot... `7D X procedure drop; X var X`09`09i1,i2`09`09: integer; X`09`09com_ptr`09`09: treas_ptr; X`09`09redraw : boolean; X`09`09out_val : vtype; X`09`09temp`09`09: integer; X`09`09count`09`09: integer; X begin X`09reset_flag := true; X`09with py.misc do X`09 temp := money`5B6`5D+money`5B5`5D+money`5B4`5D+money`5B3`5D+money`5B2`5 VD+money`5B1`5D; X`09if (inven_ctr > 0) or (temp > 0) then X`09 begin X`09 count := change_all_ok_stats(true,false); X`09 com_ptr := inventory_list; X`09 while (com_ptr <> nil) do X`09 begin X`09`09if (com_ptr`5E.data.tval = bag_or_sack) and X`09`09 (com_ptr`5E.insides <> 0) then X`09`09 begin X`09`09 com_ptr`5E.ok := false; X`09`09 count := count - 1; X`09`09 end; X`09`09com_ptr := com_ptr`5E.next; X`09 end; X`09 redraw := false; `7BSomeone said that it always redraws when drop` V7D X`09 if (get_item(com_ptr,'Which one? ',redraw,count,trash_char,true)) t Vhen X`09 begin X`09`09if (redraw) then draw_cave; X`09`09with cave`5Bchar_row,char_col`5D do X`09`09 if (tptr > 0) then X`09`09 msg_print('There is something there already.') X`09`09 else X`09`09 begin X`09`09 if (trash_char = '$') then X`09`09 inven_drop(com_ptr,char_row,char_col,true) X`09`09 else X`09`09`09inven_drop(com_ptr,char_row,char_col,false); X`09`09 prt_weight; X`09`09 objdes(out_val,inven_temp,true); X`09`09 out_val := 'Dropped ' + out_val + '.'; X`09`09 msg_print(out_val); X`09`09 reset_flag := false; X`09`09 end X`09 end X`09 else if (redraw) then X`09 draw_cave; X`09 end X`09else X`09 msg_print('You are not carrying anything.'); X end; X X X`09`7B Deletes object from given location`09`09`09-RAK-`09`7D X `5Bglobal,psect(moria$code)`5D function delete_object(y,x : integer) : bo Volean; X begin X delete_object := false; X with cave`5By,x`5D do X`09begin X`09 if (t_list`5Btptr`5D.tval = Secret_door) then X`09 fval := corr_floor3.ftval; X`09 fopen := true; X`09 pusht(tptr); X`09 tptr := 0; X`09 fm := false; X`09 if (test_light(y,x)) then X`09 begin X`09 lite_spot(y,x); X`09 delete_object := true; X`09 end X`09 else X`09 unlite_spot(y,x); X`09end; X end; X X X`09`7B Chests have traps too...`09`09`09`09-RAK-`09`7D X`09`7B Note: Chest traps are based on the FLAGS value `7D X procedure chest_trap(y,x : integer); X var X`09i1,i2,i3 : integer; X`09ident`09`09`09: boolean; X begin X`09with t_list`5Bcave`5By,x`5D.tptr`5D do X`09 begin X`09 if (uand(%X'00000010',flags) <> 0) then X`09 begin X`09`09msg_print('A small needle has pricked you!'); X`09`09if lose_stat(sr,'','You are unaffected.') then X`09`09 begin X`09`09 take_hit(damroll('1d4'),'a poison needle.'); X`09`09 print_stat := uor(%X'0001',print_stat); X`09`09 msg_print('You feel weakened!'); X`09`09 end X`09 end; X`09 if (uand(%X'00000020',flags) <> 0) then X`09 begin X`09`09msg_print('A small needle has pricked you!'); X`09`09take_hit(damroll('1d6'),'a poison needle.'); X`09`09py.flags.poisoned := py.flags.poisoned + 10 + randint(20); X`09 end; X`09 if (uand(%X'00000040',flags) <> 0) then X`09 begin X`09`09msg_print('A puff of yellow gas surrounds you!'); X`09`09if (py.flags.free_act) then X`09`09 msg_print('You are unaffected.') X`09`09else X`09`09 begin X`09`09 msg_print('You choke and pass out.'); X`09`09 py.flags.paralysis := 10 + randint(20); X`09`09 end; X`09 end; X`09 if (uand(%X'00000080',flags) <> 0) then X`09 begin X`09`09msg_print('There is a sudden explosion!'); X`09`09delete_object(y,x); X`09`09take_hit(damroll('5d8'),'an exploding chest.'); X`09 end; X`09 if (uand(%X'00000100',flags) <> 0) then X`09 begin X`09`09for i1 := 1 to 3 do X`09`09 begin X`09`09 i2 := y; X`09`09 i3 := x; X`09`09 if (cave`5Bi2,i3`5D.fval in water_set) then X`09`09 summon_water_monster(i2,i3,false) X`09`09 else X`09`09 summon_land_monster(i2,i3,false); X`09`09 end; X`09 end; X`09 end; X end; X X X`09`7B Opens a closed door or closed chest...`09`09-RAK-`09`7D X procedure openobject; X var X`09`09y,x,tmp : integer; X`09`09flag : boolean; X begin X`09y := char_row; X`09x := char_col; X`09if (get_dir('Which direction?',tmp,tmp,y,x)) then X`09 begin X`09 with cave`5By,x`5D do X`09 if (tptr > 0) then X`09`09`09`7B Closed door `7D X`09`09if (t_list`5Btptr`5D.tval = Closed_door) then X`09`09 with t_list`5Btptr`5D do X`09`09 begin X`09`09 if (p1 > 0) then `7B It's locked... `7D X`09`09`09begin X`09`09`09 with py.misc do X`09`09`09 tmp := disarm + lev + 2*todis_adj + spell_adj(iq); X`09`09`09 if (py.flags.confused > 0) then X`09`09`09 msg_print('You are too confused to pick the lock.') X`09`09`09 else if ((tmp-p1) > randint(100)) then X`09`09`09 begin X`09`09`09 msg_print('You have picked the lock.'); X`09`09`09 py.misc.exp := py.misc.exp + 1; X`09`09`09 prt_experience; X`09`09`09 p1 := 0; X`09`09`09 end +-+-+-+-+-+-+-+- END OF PART 20 +-+-+-+-+-+-+-+-