From 96aa6d3c847192863507a282e38664cca693af07 Mon Sep 17 00:00:00 2001 From: Matthew Cline Date: Tue, 3 Nov 2009 02:54:13 -0800 Subject: Unit test for beams bouncing --- crawl-ref/source/l_debug.cc | 31 ++++++++++++++++++++++++ crawl-ref/source/test/bounce.lua | 47 ++++++++++++++++++++++++++++++++++++ crawl-ref/source/test/des/bounce.des | 23 ++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 crawl-ref/source/test/bounce.lua create mode 100644 crawl-ref/source/test/des/bounce.des (limited to 'crawl-ref') diff --git a/crawl-ref/source/l_debug.cc b/crawl-ref/source/l_debug.cc index 810970dddd..91ff1080b6 100644 --- a/crawl-ref/source/l_debug.cc +++ b/crawl-ref/source/l_debug.cc @@ -8,6 +8,7 @@ #include "cluautil.h" #include "l_libs.h" +#include "beam.h" #include "chardump.h" #include "dungeon.h" #include "message.h" @@ -70,6 +71,35 @@ LUAFN(_debug_test_explore) return (0); } +LUAFN(debug_bouncy_beam) +{ + coord_def source; + coord_def target; + + source.x = luaL_checkint(ls, 1); + source.y = luaL_checkint(ls, 2); + target.x = luaL_checkint(ls, 3); + target.y = luaL_checkint(ls, 4); + + bolt beam; + + beam.range = luaL_checkint(ls, 5); + beam.type = '*'; + beam.colour = LIGHTCYAN; + beam.flavour = BEAM_ELECTRICITY; + beam.source = source; + beam.target = target; + beam.is_beam = true; + beam.draw_delay = 0; + + beam.name = "debug lightning beam"; + beam.short_name = "DEBUG"; + + beam.fire(); + + return (0); +} + const struct luaL_reg debug_dlib[] = { { "goto_place", debug_goto_place }, @@ -77,6 +107,7 @@ const struct luaL_reg debug_dlib[] = { "generate_level", debug_generate_level }, { "dump_map", debug_dump_map }, { "test_explore", _debug_test_explore }, +{ "bouncy_beam", debug_bouncy_beam }, { NULL, NULL } }; diff --git a/crawl-ref/source/test/bounce.lua b/crawl-ref/source/test/bounce.lua new file mode 100644 index 0000000000..357f2072e3 --- /dev/null +++ b/crawl-ref/source/test/bounce.lua @@ -0,0 +1,47 @@ +-- Check bouncing of lightning bolts around in a box with ragged +-- edges. If there's anything wrong the C/C++ code will assert. + +local checks = 0 +local iters = 10 + +local function test_bounce_iter(map) + dgn.reset_level() + -- local width, height = dgn.mapsize(map) -- returns (0,0) + local function place_map() + return dgn.place_map(map, true, true, 30, 30) + end + dgn.with_map_anchors(30, 30, place_map) + + if dgn.grid(31, 31) ~= dgn.find_feature_number("floor") then + assert(false, "Map not placed properly") + end + + -- Move player out of the way + you.moveto(2, 2) + + -- Fire beams slightly off of compass directions, to get the + -- beam to bounce all over the place. + debug.bouncy_beam(30, 30, 30 - 8, 30 - 7, 1000) + debug.bouncy_beam(30, 30, 30 - 1, 30 - 8, 1000) + debug.bouncy_beam(30, 30, 30 + 8, 30 - 7, 1000) + debug.bouncy_beam(30, 30, 30 + 1, 30 - 8, 1000) + debug.bouncy_beam(30, 30, 30 - 8, 30 + 7, 1000) + debug.bouncy_beam(30, 30, 30 - 1, 30 + 8, 1000) + debug.bouncy_beam(30, 30, 30 + 8, 30 + 7, 1000) + debug.bouncy_beam(30, 30, 30 + 1, 30 + 8, 1000) +end + +local function test_bounces() + dgn.load_des_file("test/des/bounce.des") + local map = dgn.map_by_tag("bounce_test") + assert(map, "Could not find bounce_test map (tag 'bounce_test')") + -- The ragedness of the map edge is randomized on placement, + -- so place the same map multiple times. + for i = 1, iters do + test_bounce_iter(map) + end + + checks = 1 +end + +test_bounces() diff --git a/crawl-ref/source/test/des/bounce.des b/crawl-ref/source/test/des/bounce.des new file mode 100644 index 0000000000..8202da7af2 --- /dev/null +++ b/crawl-ref/source/test/des/bounce.des @@ -0,0 +1,23 @@ +# A random set of walls for unpredictable ray bouncing. +NAME: bounce_test +TAGS: bounce_test +KFEAT: x = w:70 floor / w:30 X +MAP +XXXXXXXXXXXXXXXXX +XxxxxxxxxxxxxxxxX +XxxxxxxxxxxxxxxxX +XxxxxxxxxxxxxxxxX +XxxxxxxxxxxxxxxxX +Xxxxx.......xxxxX +Xxxxx.......xxxxX +Xxxxx.......xxxxX +Xxxxx...@...xxxxX +Xxxxx.......xxxxX +Xxxxx.......xxxxX +Xxxxx.......xxxxX +XxxxxxxxxxxxxxxxX +XxxxxxxxxxxxxxxxX +XxxxxxxxxxxxxxxxX +XxxxxxxxxxxxxxxxX +XXXXXXXXXXXXXXXXX +ENDMAP -- cgit v1.2.3-54-g00ecf