Debian Codegraph @

source/test/monster-plant-pathfind.lua.disabled

raw
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.
3
4 local map = "monster_plant_pathfind"
5 local FAILMAP = map .. ".map"
6
7 debug.reset_player_data()
8 debug.goto_place("D:2")
9 dgn.reset_level()
10 assert(dgn.place_map(dgn.map_by_name(map), true, true),
11 "Could not place " .. map)
12
13 local stair = test.find_feature('stone_stairs_up_i')
14 assert(stair, "Could not find stairs up")
15
16 you.moveto(stair.x, stair.y)
17 local you_x, you_y = you.pos()
18 assert(you_x == stair.x and you_y == stair.y,
19 "Could not move player " .. dgn.point(you_x, you_y) ..
20 " to stair " .. stair)
21
22 local monster = test.find_monsters("wyvern")[1]
23
24 local function monster_pos()
25 local p = dgn.point(monster.x, monster.y)
26 -- Monster position is relative to the player position:
27 p = p + stair
28 return p
29 end
30
31 debug.los_changed()
32
33 assert(you.see_cell(monster_pos().x, monster_pos().y),
34 "Player at " .. stair .. " cannot see monster at "
35 .. monster_pos())
36 assert(you.see_cell(you_x + 1, you_y),
37 "Player at " .. stair .. " cannot see cell at "
38 .. (stair + dgn.point(1, 0)))
39
40
41 -- Assert if the monster moves back and forth between positions
42 local function check_monster_moves_repeat(monster, nmoves)
43 local visited_points = { }
44
45 local function note_position(p)
46 local key = p.y * dgn.GXM + p.x
47 local visits = visited_points[key] or 0
48 visits = visits + 1
49 visited_points[key] = visits
50 debug.dump_map(FAILMAP)
51 assert(visits < 2,
52 "Monster revisited " .. p .. "; dumped map to " .. FAILMAP)
53 end
54
55 local oldpos = nil
56 for i = 1, nmoves do
57 local p = monster_pos()
58 crawl.message("Monster " .. monster.name .. " at " .. p)
59 if p ~= oldpos then
60 note_position(p)
61 end
62 oldpos = p
63
64 -- Wake up the monster and kick it into seek (hopefully).
65 debug.seen_monsters_react()
66 -- Draw the view to give the user something to look at.
67 debug.viewwindow(true)
68 monster.add_energy(10)
69 assert(monster.beh == "seek",
70 "Monster " .. monster.name .. " is not in seek mode")
71 monster.run_ai()
72 end
73 end
74
75 check_monster_moves_repeat(monster, 6)