in level generation.
Clouds now have a "spread rate" field, which by default uses the same per-cloud-type rate as before (normal spread rate for steam, grey smoke and black smoke, no spreading for other cloud types). Might want to make the spread rate decrease as the cloud spreads (currently it remains unchanged).
Added new dungeon event type "entered level", to complement "entering level".
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2489 c06c8d41-db1a-0410-9941-cceddc491573
ZLQAAP55CJ77XIJN3DZVPT4GTTVLIBFJLIJJKI6L5UBSHX7VUK6AC
WFED7ME7LXUZCZY3TWX7PCPW4EAA55W626CM2OOYVJTLI2BWFTVAC
5BJPWUPLJFS34FUTFJVKA4A52YMIGV6EWDXLNSDCWBJWBGVSQFGQC
TLA5UN6LZPXGKERI27EFY4HKIIU3VU5Y7ZU54WXL6ANBUV2VOTMQC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
B62ICMDTN5V7R7RBL4JALFVKEMVOOVLRSJASRNYS6CGFWBEEF5JQC
QKGDOYIYKE6B36ION5O2DRW65DWWPZMYNWJVH7LJJ7FPGGM2MYAQC
PR2XIEELO6UJWT3EXDHWCJZGIZCCF3D6KF6LC67R6RWWAVNWEHWAC
DDU4A3JGN5IUIPP5IASOODKPR2WBHSDSV4FITZ6HNXNSXXQACWAQC
AUXHSGS4EFOPZ6TVZYWNVOUDO7NYKUKE3HBKGQQWTALSVFOE3HAAC
7Y5HSDFKA5TPLS2TWTRFMQVX6UXUDHXU5MUMXQSDFAIY4THQ3BIQC
UBQTNLYGD3SNWMUNGWUPX7EXEGQXOXCFCPWIVWBFE7ID7DJLPFWAC
RGHXFBNIULRVRYLBGG5JZDMYVM2E2JJ2Y5KQPMU6PUS3V26G6ZXQC
ED62QWGKBPORWVKDFOQRKJXEIWZVNGR3O4KWQBDSRNPT36AYOQYAC
GQL5SIGBHLU3FMCE54XVGLRY5AZHRM6DUEB722REA2DPLGJSN6EQC
HNXKX6ZDQJV33E7UKZOLBYWJMRZ4QLEMXVXJZNRCTOIG2KVRTIEAC
ZP2KE7A2LE7Z2S7AC45WE4CXDSEVDTWIMV2EM4IBUKXYJIDU6R7QC
static bool cloud_helper(int (*func)(int, int, int, cloud_type, kill_category),
int x, int y,
int pow, cloud_type ctype, kill_category );
static bool cloud_helper(int (*func)(int, int, int, int, cloud_type,
kill_category),
int x, int y, int pow, int spread_rate,
cloud_type ctype, kill_category );
static bool cloud_helper(int (*func)(int, int, int, cloud_type, kill_category),
int x, int y,
int pow, cloud_type ctype, kill_category whose )
static bool cloud_helper(int (*func)(int, int, int, int, cloud_type,
kill_category),
int x, int y, int pow, int spread_rate,
cloud_type ctype, kill_category whose )
"none", "turn", "mons_move", "player_move", "leave_level", "enter_level",
"player_los", "player_climb", "monster_dies", "item_pickup",
"feat_change"
"none", "turn", "mons_move", "player_move", "leave_level",
"entering_level", "entered_level", "player_los", "player_climb",
"monster_dies", "item_pickup", "feat_change"
}
#define SQRT_2 1.41421356237309504880
static int dgn_random_walk(lua_State *ls)
{
const int x = luaL_checkint(ls, 1);
const int y = luaL_checkint(ls, 2);
const int dist = luaL_checkint(ls, 3);
// Fourth param being true means that we can move past
// statues.
const dungeon_feature_type minmove =
lua_isnil(ls, 4) ? DNGN_MINMOVE : DNGN_ORCISH_IDOL;
if (!in_bounds(x, y))
{
char buf[80];
sprintf(buf, "Point (%d,%d) isn't in bounds.", x, y);
luaL_argerror(ls, 1, buf);
return (0);
}
if (dist < 1)
{
luaL_argerror(ls, 3, "Distance must be positive.");
return (0);
}
float dist_left = dist;
// Allow movement to all 8 adjacent squares if distance is 1
// (needed since diagonal moves are distance sqrt(2))
if (dist == 1)
dist_left = SQRT_2;
int moves_left = dist;
coord_def pos(x, y);
while (dist_left >= 1.0 && moves_left-- > 0)
{
int okay_dirs = 0;
int dir = -1;
for (int j = 0; j < 8; j++)
{
const coord_def new_pos = pos + Compass[j];
const float move_dist = (j % 2 == 0) ? 1.0 : SQRT_2;
if (in_bounds(new_pos) && grd(new_pos) >= minmove
&& move_dist <= dist_left)
{
if (one_chance_in(++okay_dirs))
dir = j;
}
}
if (okay_dirs == 0)
break;
if (one_chance_in(++okay_dirs))
continue;
pos += Compass[dir];
dist_left -= (dir % 2 == 0) ? 1.0 : SQRT_2;
}
dlua_push_coord(ls, pos);
return (2);
}
static cloud_type dgn_cloud_name_to_type(std::string name)
{
lowercase(name);
if (name == "random")
return (CLOUD_RANDOM);
else if (name == "debugging")
return (CLOUD_DEBUGGING);
for (int i = CLOUD_NONE; i < CLOUD_RANDOM; i++)
if (cloud_name(static_cast<cloud_type>(i)) == name)
return static_cast<cloud_type>(i);
return (CLOUD_NONE);
}
static kill_category dgn_kill_name_to_category(std::string name)
{
if (name == "")
return KC_OTHER;
lowercase(name);
if (name == "you")
return KC_YOU;
else if (name == "friendly")
return KC_FRIENDLY;
else if (name == "other")
return KC_OTHER;
else
return KC_NCATEGORIES;
static int make_a_lua_cloud(int x, int y, int garbage, int spread_rate,
cloud_type ctype, kill_category whose)
{
UNUSED( garbage );
const int pow = random_range(lua_cloud_pow_min,
lua_cloud_pow_max,
lua_cloud_pow_rolls);
place_cloud( ctype, x, y, pow, whose, spread_rate );
return 1;
}
static int dgn_apply_area_cloud(lua_State *ls)
{
const int x = luaL_checkint(ls, 1);
const int y = luaL_checkint(ls, 2);
lua_cloud_pow_min = luaL_checkint(ls, 3);
lua_cloud_pow_max = luaL_checkint(ls, 4);
lua_cloud_pow_rolls = luaL_checkint(ls, 5);
const int size = luaL_checkint(ls, 6);
const cloud_type ctype = dgn_cloud_name_to_type(luaL_checkstring(ls, 7));
const char* kname = lua_isstring(ls, 8) ? luaL_checkstring(ls, 8)
: "";
const kill_category kc = dgn_kill_name_to_category(kname);
const int spread_rate = lua_isnumber(ls, 9) ? luaL_checkint(ls, 9) : -1;
if (!in_bounds(x, y))
{
char buf[80];
sprintf(buf, "Point (%d,%d) isn't in bounds.", x, y);
luaL_argerror(ls, 1, buf);
return (0);
}
if (lua_cloud_pow_min < 0)
{
luaL_argerror(ls, 4, "pow_min must be non-negative");
return (0);
}
if (lua_cloud_pow_max < lua_cloud_pow_min)
{
luaL_argerror(ls, 5, "pow_max must not be less than pow_min");
return (0);
}
if (lua_cloud_pow_max == 0)
{
luaL_argerror(ls, 5, "pow_max must be positive");
return (0);
}
if (lua_cloud_pow_rolls <= 0)
{
luaL_argerror(ls, 6, "pow_rolls must be positive");
return (0);
}
if (size < 1)
{
luaL_argerror(ls, 4, "size must be positive.");
return (0);
}
if (ctype == CLOUD_NONE)
{
std::string error = "Invalid cloud type '";
error += luaL_checkstring(ls, 7);
error += "'";
luaL_argerror(ls, 7, error.c_str());
return (0);
}
if (kc == KC_NCATEGORIES)
{
std::string error = "Invalid kill category '";
error += kname;
error += "'";
luaL_argerror(ls, 8, error.c_str());
return (0);
}
if (spread_rate < -1 || spread_rate > 100)
{
luaL_argerror(ls, 9, "spread_rate must be between -1 and 100,"
"inclusive");
return (0);
}
apply_area_cloud(make_a_lua_cloud, x, y, 0, size,
ctype, kc, spread_rate);
return (0);
}
DET_PLAYER_IN_LOS = 0x0020, // Player just entered LOS.
DET_PLAYER_CLIMBS = 0x0040, // Player climbing stairs.
DET_MONSTER_DIED = 0x0080,
DET_ITEM_PICKUP = 0x0100,
DET_FEAT_CHANGE = 0x0200
DET_ENTERED_LEVEL = 0x0020,
DET_PLAYER_IN_LOS = 0x0040, // Player just entered LOS.
DET_PLAYER_CLIMBS = 0x0080, // Player climbing stairs.
DET_MONSTER_DIED = 0x0100,
DET_ITEM_PICKUP = 0x0200,
DET_FEAT_CHANGE = 0x0400
------------------------------------------------------------------------------
-- lm_tmsg.lua:
-- Fog machines.
--
-- There are three different "pure" ways to use a fog machine marker:
--
-- 1) Repeatedly lay down medium to large clouds on top of the marker
-- and let them pile up on one another. (One of the cloud grids in
-- the gfirst laid cloud has to decay away before this is this really
-- starts working.
--
-- 2) Perform random walks from the marker and place a single-grid cloud
-- at the destination of each walk.
--
-- 3) Place a single-grid cloud on the marker and let it spread out.
--
-- Comibining these different methods, along with varying the differrent
-- parameters, can be used to achieve different effects.
--
-- Marker parameters:
--
-- cloud_type: The name of the cloud type to use. Defaults to "thin mist".
-- walk_dist: The distance to move over the course of one random walk.
-- defaults to 0.
-- pow_min: The minimum "power" (lifetime) of each cloud; defaults to 1.
-- pow_max: The maximum power of each cloud; must be provided.
-- pow_rolls: The number of rolls of [pow_min, pow_max], with the average
-- value uses; increasing the values makes the average value more likely
-- and exterme values less likely. Defaults to 1.
-- delay, delay_min and delay_max: The delay between laying down one cloud
-- and the next. 10 is equal to normal-speed player turn. Either
-- delay or delay_max and delay_min must be provided. Providing just
-- "delay" is equivalent to delay_min and delay_max being equal.
-- size, size_min and size_max: The number of grids each cloud will cover.
-- Either size or size_max and size_min must be provided. Providing
-- just "size" is equivalent to size_min and size_max being equal.
-- spread_rate: The rate at which a cloud spreads. Must either be
-- -1 (default spread rate that varies by cloud type) or between
-- 0 and 100 inclusive.
-- start_clouds: The number of clouds to lay when the level containing
-- the cloud machine is entered. This is necessary since clouds
-- are cleared when the player leaves a level.
------------------------------------------------------------------------------
FogMachine = { }
FogMachine.__index = FogMachine
function FogMachine:_new()
local m = { }
setmetatable(m, self)
self.__index = self
return m
end
function FogMachine:new(pars)
if not pars then
error("No parameters provided")
end
if not pars.pow_max then
error("No pow_max provided.")
end
if not (pars.delay or (pars.delay_min and pars.delay_max)) then
error("Delay parameters not provided.")
end
if not (pars.size or (pars.size_min and pars.size_max)) then
error("Size parameters not provided.")
end
local m = FogMachine:_new()
m.cloud_type = pars.cloud_type or "thin mist"
m.walk_dist = pars.walk_dist or 0
m.pow_min = pars.pow_min or 1
m.pow_max = pars.pow_max
m.pow_rolls = pars.pow_rolls or 3
m.delay_min = pars.delay_min or pars.delay or 1
m.delay_max = pars.delay_max or pars.delay
m.kill_cat = pars.kill_cat or "other"
m.size_min = pars.size_min or pars.size or 1
m.size_max = pars.size_max or pars.size
m.spread_rate = pars.spread_rate or -1
m.start_clouds = pars.start_clouds or 1
m.countdown = 0
return m
end
function FogMachine:do_fog(marker)
local x, y = marker:pos()
if self.walk_dist > 0 then
x, y = dgn.random_walk(x, y, self.walk_dist)
end
dgn.apply_area_cloud(x, y, self.pow_min, self.pow_max, self.pow_rolls,
crawl.random_range(self.size_min, self.size_max, 1),
self.cloud_type, self.kill_cat, self.spread_rate)
end
function FogMachine:activate(marker, verbose)
local _x, _y = marker:pos()
dgn.register_listener(dgn.dgn_event_type('turn'), marker)
dgn.register_listener(dgn.dgn_event_type('entered_level'), marker)
end
function FogMachine:event(marker, ev)
local _x, _y = marker:pos()
if ev:type() == dgn.dgn_event_type('turn') then
self.countdown = self.countdown - ev:ticks()
while self.countdown <= 0 do
self:do_fog(marker)
self.countdown = self.countdown +
crawl.random_range(self.delay_min, self.delay_max, 1)
end
elseif ev:type() == dgn.dgn_event_type('entered_level') then
for i = 1, self.start_clouds do
self:do_fog(marker)
self.countdown = crawl.random_range(self.delay_min, self.delay_max, 1)
end
end
end
function FogMachine:write(marker, th)
file.marshall(th, self.cloud_type)
file.marshall(th, self.walk_dist)
file.marshall(th, self.pow_min)
file.marshall(th, self.pow_max)
file.marshall(th, self.pow_rolls)
file.marshall(th, self.delay_min)
file.marshall(th, self.delay_max)
file.marshall(th, self.kill_cat)
file.marshall(th, self.size_min)
file.marshall(th, self.size_max)
file.marshall(th, self.spread_rate)
file.marshall(th, self.start_clouds)
file.marshall(th, self.countdown)
end
function FogMachine:read(marker, th)
self.cloud_type = file.unmarshall_string(th)
self.walk_dist = file.unmarshall_number(th)
self.pow_min = file.unmarshall_number(th)
self.pow_max = file.unmarshall_number(th)
self.pow_rolls = file.unmarshall_number(th)
self.delay_min = file.unmarshall_number(th)
self.delay_max = file.unmarshall_number(th)
self.kill_cat = file.unmarshall_string(th)
self.size_min = file.unmarshall_number(th)
self.size_max = file.unmarshall_number(th)
self.spread_rate = file.unmarshall_number(th)
self.start_clouds = file.unmarshall_number(th)
self.countdown = file.unmarshall_number(th)
setmetatable(self, FogMachine)
return self
end
function fog_machine(pars)
return FogMachine:new(pars)
end