summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-11-12 06:09:15 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-11-12 06:09:15 +0000
commit3a38986e4358d3a989cef881386ecc654b36fa1c (patch)
treec0590eb69702ab13c945dfc9444a83117cb72ad6 /crawl-ref/source
parent53ad48697e85f87bb7686d2e030fc3716994406d (diff)
downloadcrawl-ref-3a38986e4358d3a989cef881386ecc654b36fa1c.tar.gz
crawl-ref-3a38986e4358d3a989cef881386ecc654b36fa1c.zip
Lua map markers can now be generated in C code from
map_lua_marker::parse_marker() by prefixing the Lua string with "lua_mapless:" rather than "lua:". Fog machines can be created and placed from within C code via place_fog_machine(). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2843 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/cloud.cc38
-rw-r--r--crawl-ref/source/cloud.h11
-rw-r--r--crawl-ref/source/dat/clua/lm_fog.lua21
-rw-r--r--crawl-ref/source/mapmark.cc37
-rw-r--r--crawl-ref/source/mapmark.h3
5 files changed, 100 insertions, 10 deletions
diff --git a/crawl-ref/source/cloud.cc b/crawl-ref/source/cloud.cc
index 8306c95766..ae7b614045 100644
--- a/crawl-ref/source/cloud.cc
+++ b/crawl-ref/source/cloud.cc
@@ -16,6 +16,8 @@
#include "externs.h"
#include "cloud.h"
+#include "mapmark.h"
+#include "misc.h"
#include "stuff.h"
#include "terrain.h"
@@ -305,6 +307,42 @@ cloud_type random_smoke_type()
return CLOUD_DEBUGGING;
}
+void place_fog_machine(fog_machine_type fm_type, cloud_type cl_type,
+ int x, int y, int size, int power)
+{
+ const char* fog_types[] = {
+ "geyser",
+ "spread",
+ "brownian"
+ };
+
+ try
+ {
+ char buf [160];
+ sprintf(buf, "lua_mapless:fog_machine_%s(\"%s\", %d, %d)",
+ fog_types[fm_type], cloud_name(cl_type).c_str(),
+ size, power);
+
+ map_marker *mark = map_lua_marker::parse_marker(buf, "");
+
+ if (mark == NULL)
+ {
+ mprf(MSGCH_DIAGNOSTICS, "Unable to parse fog machine from '%s'",
+ buf);
+ return;
+ }
+
+ mark->pos = coord_def(x, y);
+ env.markers.add(mark);
+ }
+ catch (const std::string &err)
+ {
+ mprf(MSGCH_DIAGNOSTICS, "Error while making fog machine: %s",
+ err.c_str());
+ }
+}
+
+
////////////////////////////////////////////////////////////////////////
// cloud_struct
diff --git a/crawl-ref/source/cloud.h b/crawl-ref/source/cloud.h
index e0d02d27ed..157aa1932c 100644
--- a/crawl-ref/source/cloud.h
+++ b/crawl-ref/source/cloud.h
@@ -14,6 +14,14 @@
#include "externs.h"
+enum fog_machine_type
+{
+ FM_GEYSER,
+ FM_SPREAD,
+ FM_BROWNIAN,
+ NUM_FOG_MACHINE_TYPES
+};
+
cloud_type random_smoke_type();
void delete_cloud( int cloud );
@@ -29,4 +37,7 @@ void manage_clouds(void);
bool is_opaque_cloud(unsigned char cloud_idx);
int steam_cloud_damage(const cloud_struct &cloud);
+void place_fog_machine(fog_machine_type fm_type, cloud_type cl_type,
+ int x, int y, int size, int power);
+
#endif
diff --git a/crawl-ref/source/dat/clua/lm_fog.lua b/crawl-ref/source/dat/clua/lm_fog.lua
index 62853cb9b7..d1106101fa 100644
--- a/crawl-ref/source/dat/clua/lm_fog.lua
+++ b/crawl-ref/source/dat/clua/lm_fog.lua
@@ -161,3 +161,24 @@ end
function fog_machine(pars)
return FogMachine:new(pars)
end
+
+function fog_machine_geyser(cloud_type, size, power)
+ return FogMachine:new {
+ cloud_type = cloud_type, pow_max = power, size = size,
+ delay_min = power , delay_max = power * 2
+ }
+end
+
+function fog_machine_spread(cloud_type, size, power)
+ return FogMachine:new {
+ cloud_type = cloud_type, pow_max = power, spread_rate = size,
+ size = 1, delay_min = 5, delay_max = 15
+ }
+end
+
+function fog_machine_brownian(cloud_type, size, power)
+ return FogMachine:new {
+ cloud_type = cloud_type, size = 1, pow_max = power,
+ walk_dist = size, delay_min = 1, delay_max = power / size
+ }
+end
diff --git a/crawl-ref/source/mapmark.cc b/crawl-ref/source/mapmark.cc
index a427749e9b..77a3db7aa1 100644
--- a/crawl-ref/source/mapmark.cc
+++ b/crawl-ref/source/mapmark.cc
@@ -161,14 +161,24 @@ map_lua_marker::map_lua_marker()
{
}
-map_lua_marker::map_lua_marker(const std::string &s, const std::string &)
+map_lua_marker::map_lua_marker(const std::string &s, const std::string &,
+ bool mapdef_marker)
: map_marker(MAT_LUA_MARKER, coord_def()), initialised(false)
{
lua_stack_cleaner clean(dlua);
- if (dlua.loadstring(("return " + s).c_str(), "lua_marker"))
- mprf(MSGCH_WARN, "lua_marker load error: %s", dlua.error.c_str());
- if (!dlua.callfn("dgn_run_map", 1, 1))
- mprf(MSGCH_WARN, "lua_marker exec error: %s", dlua.error.c_str());
+ if (mapdef_marker)
+ {
+ if (dlua.loadstring(("return " + s).c_str(), "lua_marker"))
+ mprf(MSGCH_WARN, "lua_marker load error: %s", dlua.error.c_str());
+ if (!dlua.callfn("dgn_run_map", 1, 1))
+ mprf(MSGCH_WARN, "lua_marker exec error: %s", dlua.error.c_str());
+ }
+ else
+ {
+ if (dlua.execstring(("return " + s).c_str(), "lua_marker_mapless", 1))
+ mprf(MSGCH_WARN, "lua_marker_mapless exec error: %s",
+ dlua.error.c_str());
+ }
check_register_table();
}
@@ -369,11 +379,20 @@ std::string map_lua_marker::property(const std::string &pname) const
map_marker *map_lua_marker::parse(
const std::string &s, const std::string &ctx) throw (std::string)
{
- if (s.find("lua:") != 0)
+ std::string raw = s;
+ bool mapdef_marker = true;
+
+ if (s.find("lua:") == 0)
+ strip_tag(raw, "lua:", true);
+ else if (s.find("lua_mapless:") == 0)
+ {
+ strip_tag(raw, "lua_mapless:", true);
+ mapdef_marker = false;
+ }
+ else
return (NULL);
- std::string raw = s;
- strip_tag(raw, "lua:", true);
- map_lua_marker *mark = new map_lua_marker(raw, ctx);
+
+ map_lua_marker *mark = new map_lua_marker(raw, ctx, mapdef_marker);
if (!mark->initialised)
{
delete mark;
diff --git a/crawl-ref/source/mapmark.h b/crawl-ref/source/mapmark.h
index f277295db7..a2d71e9567 100644
--- a/crawl-ref/source/mapmark.h
+++ b/crawl-ref/source/mapmark.h
@@ -87,7 +87,8 @@ class map_lua_marker : public map_marker, public dgn_event_listener
{
public:
map_lua_marker();
- map_lua_marker(const std::string &s, const std::string &ctx);
+ map_lua_marker(const std::string &s, const std::string &ctx,
+ bool mapdef_marker = true);
~map_lua_marker();
void activate(bool verbose);