From 73320c3896f002f5a611d3e8b471e0cd01ca75b4 Mon Sep 17 00:00:00 2001 From: Ryan Flegel Date: Fri, 16 May 2008 15:42:02 +0000 Subject: [PATCH] #318: Automatically run default.nut for each level/sector and worldmap. We may want to consider moving world.nut functionality into default.nut. SVN-Revision: 5484 --- data/levels/test/intro.stl | 1 - data/levels/test/intro2.stl | 1 - data/levels/test/keydoors.stl | 8 ++++---- data/levels/test/snowslope.stl | 4 +++- data/levels/test/transition.stl | 1 - data/levels/world2/Crumbling_Path.stl | 1 - data/levels/world2/airkey.stl | 1 - data/levels/world2/builder.stl | 1 - data/levels/world2/christophB.stl | 1 - data/levels/world2/detour.stl | 1 - data/levels/world2/fish.stl | 2 -- data/levels/world2/key1.stl | 3 --- data/levels/world2/key2.stl | 3 --- data/levels/world2/key3.stl | 3 --- data/levels/world2/key4.stl | 3 --- data/levels/world2/key5.stl | 3 --- data/levels/world2/leaves.stl | 1 - data/levels/world2/level1.stl | 1 - data/levels/world2/level2.stl | 3 --- data/levels/world2/trees.stl | 2 -- data/levels/world2/underconstruction.stl | 8 ++++---- data/levels/world2/updown.stl | 1 - data/levels/world2/village.stl | 1 - data/levels/world2/worldmap.stwm | 1 - src/level.cpp | 1 + src/level.hpp | 1 + src/sector.cpp | 14 ++++++++++++++ src/worldmap/worldmap.cpp | 10 ++++++++++ 28 files changed, 37 insertions(+), 44 deletions(-) diff --git a/data/levels/test/intro.stl b/data/levels/test/intro.stl index 4c97b5d80..b87eea63e 100644 --- a/data/levels/test/intro.stl +++ b/data/levels/test/intro.stl @@ -109,7 +109,6 @@ (sprite "images/creatures/dummyguy/dummyguy.sprite") ) (init-script " - import(\"levels/test/default.nut\"); intro(); ") ) diff --git a/data/levels/test/intro2.stl b/data/levels/test/intro2.stl index df4e5e81c..a07879071 100644 --- a/data/levels/test/intro2.stl +++ b/data/levels/test/intro2.stl @@ -6,7 +6,6 @@ (sector (name "main") (init-script " - import(\"levels/test/default.nut\"); intro(); ") (gravity 10.000000) diff --git a/data/levels/test/keydoors.stl b/data/levels/test/keydoors.stl index c2e245c0d..00dfff814 100644 --- a/data/levels/test/keydoors.stl +++ b/data/levels/test/keydoors.stl @@ -4,10 +4,10 @@ (author "slacker") (sector (name "main") - (init-script "import(\"levels/world2/default.nut\"); -AIRHINT.set_action(\"outline\"); -EARTHHINT.set_action(\"outline\"); -WOODHINT.set_action(\"outline\");") + (init-script " + AIRHINT.set_action(\"outline\"); + EARTHHINT.set_action(\"outline\"); + WOODHINT.set_action(\"outline\");") (ambient-light 1 1 1) (spawnpoint (name "main") diff --git a/data/levels/test/snowslope.stl b/data/levels/test/snowslope.stl index 78c0fccc4..4f70c75c2 100644 --- a/data/levels/test/snowslope.stl +++ b/data/levels/test/snowslope.stl @@ -26,9 +26,11 @@ (image "images/tiles/doodads/iceshrub.png") ) (dispenser - (cycle 1) + (cycle 2) (x 3843) (y 709) + (random #t) + (type "cannon") (badguy "kamikazesnowball") ) (fish diff --git a/data/levels/test/transition.stl b/data/levels/test/transition.stl index ed39c0f53..7b1a0cac0 100644 --- a/data/levels/test/transition.stl +++ b/data/levels/test/transition.stl @@ -5,7 +5,6 @@ (license "GPL 2+ / CC-by-sa 3.0") (sector (name "main") - (init-script "import(\"levels/test/transition.nut\");") (ambient-light 0.7022965 0.8745861 1) (ambient_sound (sample "sounds/rain.wav") diff --git a/data/levels/world2/Crumbling_Path.stl b/data/levels/world2/Crumbling_Path.stl index 77514294b..683878c80 100644 --- a/data/levels/world2/Crumbling_Path.stl +++ b/data/levels/world2/Crumbling_Path.stl @@ -6,7 +6,6 @@ (sector (name "main") (music "music/forest2.ogg") - (init-script "import(\"levels/world2/default.nut\" );") (ambient-light 1 1 1) (background (x 4000) diff --git a/data/levels/world2/airkey.stl b/data/levels/world2/airkey.stl index ab0130d7e..4eac32c72 100644 --- a/data/levels/world2/airkey.stl +++ b/data/levels/world2/airkey.stl @@ -7,7 +7,6 @@ (sector (name "main") (music "music/forest.music") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (background (y 1500) diff --git a/data/levels/world2/builder.stl b/data/levels/world2/builder.stl index abc394e2a..045222647 100644 --- a/data/levels/world2/builder.stl +++ b/data/levels/world2/builder.stl @@ -6,7 +6,6 @@ (sector (name "main") (music "music/forest2.ogg") - (init-script "import(\"levels/world2/default.nut\")") (ambient-light 1 1 1) (background (x 4000) diff --git a/data/levels/world2/christophB.stl b/data/levels/world2/christophB.stl index ad73daee6..557702d4c 100644 --- a/data/levels/world2/christophB.stl +++ b/data/levels/world2/christophB.stl @@ -6,7 +6,6 @@ (sector (name "main") (music "music/forest.music") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (background (y 420) diff --git a/data/levels/world2/detour.stl b/data/levels/world2/detour.stl index 4c7d745bf..9451079e8 100644 --- a/data/levels/world2/detour.stl +++ b/data/levels/world2/detour.stl @@ -6,7 +6,6 @@ (sector (name "main") (music "music/forest2.ogg") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (background (x 3300) diff --git a/data/levels/world2/fish.stl b/data/levels/world2/fish.stl index e8965355e..9d93568c7 100644 --- a/data/levels/world2/fish.stl +++ b/data/levels/world2/fish.stl @@ -6,7 +6,6 @@ (sector (name "main") (music "music/forest.music") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (background (x 4000) @@ -410,7 +409,6 @@ (sector (name "secret") (music "music/cave.ogg") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (background (speed 0.5) diff --git a/data/levels/world2/key1.stl b/data/levels/world2/key1.stl index 7463ed413..d55339ca2 100644 --- a/data/levels/world2/key1.stl +++ b/data/levels/world2/key1.stl @@ -5,9 +5,6 @@ (license "GPL 2+ / CC-by-sa 3.0") (sector (name "main") - (init-script " - import(\"levels/world2/default.nut\"); - ") (ambient-light 1 1 1) (background (x 500) diff --git a/data/levels/world2/key2.stl b/data/levels/world2/key2.stl index 33ba6b4ea..93f75f287 100644 --- a/data/levels/world2/key2.stl +++ b/data/levels/world2/key2.stl @@ -5,9 +5,6 @@ (license "GPL 2+ / CC-by-sa 3.0") (sector (name "main") - (init-script " - import(\"levels/world2/default.nut\"); - ") (ambient-light 1 1 1) (background (speed 0.5) diff --git a/data/levels/world2/key3.stl b/data/levels/world2/key3.stl index 334251570..4b8931fb0 100644 --- a/data/levels/world2/key3.stl +++ b/data/levels/world2/key3.stl @@ -5,9 +5,6 @@ (license "GPL 2+ / CC-by-sa 3.0") (sector (name "main") - (init-script " - import(\"levels/world2/default.nut\"); - ") (ambient-light 1 1 1) (background (speed 0.5) diff --git a/data/levels/world2/key4.stl b/data/levels/world2/key4.stl index 2fade1ade..0909cd037 100644 --- a/data/levels/world2/key4.stl +++ b/data/levels/world2/key4.stl @@ -5,9 +5,6 @@ (license "GPL 2+ / CC-by-sa 3.0") (sector (name "main") - (init-script " - import(\"levels/world2/default.nut\"); - ") (ambient-light 1 1 1) (background (speed 0.5) diff --git a/data/levels/world2/key5.stl b/data/levels/world2/key5.stl index ccfbf4c50..58fe66749 100644 --- a/data/levels/world2/key5.stl +++ b/data/levels/world2/key5.stl @@ -5,9 +5,6 @@ (license "GPL 2+ / CC-by-sa 3.0") (sector (name "main") - (init-script " - import(\"levels/world2/default.nut\"); - ") (ambient-light 1 1 1) (background (speed 0.5) diff --git a/data/levels/world2/leaves.stl b/data/levels/world2/leaves.stl index 8f44d0910..c890b94f0 100644 --- a/data/levels/world2/leaves.stl +++ b/data/levels/world2/leaves.stl @@ -6,7 +6,6 @@ (sector (name "main") (music "music/forest.music") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (background (x 4000) diff --git a/data/levels/world2/level1.stl b/data/levels/world2/level1.stl index 9d38e2fbe..21e2b7dcd 100644 --- a/data/levels/world2/level1.stl +++ b/data/levels/world2/level1.stl @@ -6,7 +6,6 @@ (sector (name "main") (music "music/forest2.ogg") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (ambient_sound (sample "sounds/rain.wav") diff --git a/data/levels/world2/level2.stl b/data/levels/world2/level2.stl index 1e8a307e5..d1143575e 100644 --- a/data/levels/world2/level2.stl +++ b/data/levels/world2/level2.stl @@ -6,9 +6,6 @@ (sector (name "main") (music "music/forest.music") - (init-script " - import(\"levels/world2/default.nut\"); - ") (ambient-light 1 1 1) (background (y 500) diff --git a/data/levels/world2/trees.stl b/data/levels/world2/trees.stl index caeff7368..9238ab265 100644 --- a/data/levels/world2/trees.stl +++ b/data/levels/world2/trees.stl @@ -6,7 +6,6 @@ (sector (name "main") (music "music/forest2.ogg") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (background (y 650) @@ -261,7 +260,6 @@ (sector (name "tree house") (music "music/forest.music") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (background (speed 0.5) diff --git a/data/levels/world2/underconstruction.stl b/data/levels/world2/underconstruction.stl index bbffb0d09..d953ef12c 100644 --- a/data/levels/world2/underconstruction.stl +++ b/data/levels/world2/underconstruction.stl @@ -6,10 +6,10 @@ (sector (name "main") (music "music/forest3.ogg") - (init-script "import(\"levels/world2/default.nut\"); -AIRHINT.set_action(\"outline\"); -EARTHHINT.set_action(\"outline\"); -WOODHINT.set_action(\"outline\");") + (init-script " + AIRHINT.set_action(\"outline\"); + EARTHHINT.set_action(\"outline\"); + WOODHINT.set_action(\"outline\");") (ambient-light 1 1 1) (camera (mode "normal") diff --git a/data/levels/world2/updown.stl b/data/levels/world2/updown.stl index 158541fd0..f2718b257 100644 --- a/data/levels/world2/updown.stl +++ b/data/levels/world2/updown.stl @@ -6,7 +6,6 @@ (sector (name "main") (music "music/forest.music") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (background (x 200) diff --git a/data/levels/world2/village.stl b/data/levels/world2/village.stl index 2cc72bba2..8a6301ce2 100644 --- a/data/levels/world2/village.stl +++ b/data/levels/world2/village.stl @@ -6,7 +6,6 @@ (sector (name "main") (music "music/forest.music") - (init-script "import( \"levels/world2/default.nut\" );") (ambient-light 1 1 1) (ambient_sound (sample "sounds/saw.wav") diff --git a/data/levels/world2/worldmap.stwm b/data/levels/world2/worldmap.stwm index 8e3c7b049..78af95fd6 100644 --- a/data/levels/world2/worldmap.stwm +++ b/data/levels/world2/worldmap.stwm @@ -7,7 +7,6 @@ (sector (name "main") (music "music/forestmap.ogg") - (init-script "import(\"levels/world2/default.nut\");") (ambient-light 1 1 1) (special-tile (invisible-tile #t) diff --git a/src/level.cpp b/src/level.cpp index e1d26c654..78d4a1a6c 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -67,6 +67,7 @@ void Level::load(const std::string& filepath) { try { + filename = filepath; lisp::Parser parser; const lisp::Lisp* root = parser.parse(filepath); diff --git a/src/level.hpp b/src/level.hpp index 61bc5d612..889f8f343 100644 --- a/src/level.hpp +++ b/src/level.hpp @@ -46,6 +46,7 @@ public: std::string author; std::string contact; std::string license; + std::string filename; std::string on_menukey_script; Sectors sectors; Statistics stats; diff --git a/src/sector.cpp b/src/sector.cpp index 625a00b42..35f472eb8 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -44,6 +44,8 @@ #include "lisp/writer.hpp" #include "lisp/list_iterator.hpp" #include "tile.hpp" +#include "file_system.hpp" +#include "physfs/physfs_stream.hpp" #include "audio/sound_manager.hpp" #include "game_session.hpp" #include "resources.hpp" @@ -611,6 +613,18 @@ Sector::activate(const Vector& player_pos) camera->reset(player->get_pos()); update_game_objects(); + //Run default.nut just before init script + //Check to see if it's in a levelset (info file) + std::string basedir = FileSystem::dirname(get_level()->filename); + if(PHYSFS_exists((basedir + "/info").c_str())) { + try { + IFileStream in(basedir + "/default.nut"); + run_script(in, std::string("Sector(") + name + ") - default.nut"); + } catch(std::exception& ) { + // doesn't exist or erroneous; do nothing + } + } + // Run init script if(init_script != "") { std::istringstream in(init_script); diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index c491470c2..cf48384e5 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -54,6 +54,7 @@ #include "main.hpp" #include "spawn_point.hpp" #include "file_system.hpp" +#include "physfs/physfs_stream.hpp" #include "tile_manager.hpp" #include "tile_set.hpp" #include "gui/menu.hpp" @@ -939,6 +940,15 @@ WorldMap::setup() throw SquirrelError(global_vm, "Couldn't set worldmap in roottable"); sq_pop(global_vm, 1); + //Run default.nut just before init script + try { + IFileStream in(levels_path + "/default.nut"); + run_script(in, "WorldMap::default.nut"); + } catch(std::exception& ) { + // doesn't exist or erroneous; do nothing + } + + if(init_script != "") { std::istringstream in(init_script); run_script(in, "WorldMap::init"); -- 2.11.0