Apply the new ground_level method.
[crawl.git] / crawl-ref / source / test / monster-plant-pathfind.lua
blob273cc307ab1b709ba03cc24283831c4bd253880d
1 -- [Mantis 591] Test to check that monsters don't vacillate between two
2 -- squares when trying to reach the player but blocked by plants.
4 local map = "monster_plant_pathfind"
5 local FAILMAP = map .. ".map"
7 debug.flush_map_memory()
8 debug.goto_place("D:2")
9 dgn.load_des_file("test/des/monster-plant-pathfind.des")
10 dgn.reset_level()
11 assert(dgn.place_map(dgn.map_by_name(map), true, true),
12 "Could not place " .. map)
14 local stair = test.find_feature('stone_stairs_up_i')
15 assert(stair, "Could not find stairs up")
17 you.moveto(stair.x, stair.y)
18 local you_x, you_y = you.pos()
19 assert(you_x == stair.x and you_y == stair.y,
20 "Could not move player " .. dgn.point(you_x, you_y) ..
21 " to stair " .. stair)
23 local monster = test.find_monsters("hippogriff")[1]
25 local function monster_pos()
26 local p = dgn.point(monster.x, monster.y)
27 -- Monster position is relative to the player position:
28 p = p + stair
29 return p
30 end
32 debug.los_changed()
34 assert(you.see_cell(monster_pos().x, monster_pos().y),
35 "Player at " .. stair .. " cannot see monster at "
36 .. monster_pos())
37 assert(you.see_cell(you_x + 1, you_y),
38 "Player at " .. stair .. " cannot see cell at "
39 .. (stair + dgn.point(1, 0)))
42 -- Assert if the monster moves back and forth between positions
43 local function check_monster_moves_repeat(monster, nmoves)
44 local visited_points = { }
46 local function note_position(p)
47 local key = p.y * dgn.GXM + p.x
48 local visits = visited_points[key] or 0
49 visits = visits + 1
50 visited_points[key] = visits
51 debug.dump_map(FAILMAP)
52 assert(visits < 2,
53 "Monster revisited " .. p .. "; dumped map to " .. FAILMAP)
54 end
56 local oldpos = nil
57 for i = 1, nmoves do
58 local p = monster_pos()
59 crawl.message("Monster " .. monster.name .. " at " .. p)
60 if p ~= oldpos then
61 note_position(p)
62 end
63 oldpos = p
65 -- Wake up the monster and kick it into seek (hopefully).
66 debug.seen_monsters_react()
67 -- Draw the view to give the user something to look at.
68 debug.viewwindow(true)
69 monster.add_energy(10)
70 assert(monster.beh == "seek",
71 "Monster " .. monster.name .. " is not in seek mode")
72 monster.run_ai()
73 end
74 end
76 check_monster_moves_repeat(monster, 6)