From 21e7daa183759411af282c7b7db7d25f1f20dde1 Mon Sep 17 00:00:00 2001 From: ANAND Date: Thu, 17 Oct 2019 10:48:06 +0530 Subject: [PATCH] Add support for optionally setting start time and time speed per-map (#478) --- mods/ctf/ctf_map/README.md | 2 ++ mods/ctf/ctf_map/init.lua | 1 + mods/ctf/ctf_map/schem_map.lua | 13 ++++++++++--- mods/ctf/ctf_map/time.lua | 13 +++++++++++++ mods/ctf/ctf_match/matches.lua | 2 -- 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 mods/ctf/ctf_map/time.lua diff --git a/mods/ctf/ctf_map/README.md b/mods/ctf/ctf_map/README.md index 31c8c10..3e5e15f 100644 --- a/mods/ctf/ctf_map/README.md +++ b/mods/ctf/ctf_map/README.md @@ -73,6 +73,8 @@ Each map's metadata is stored in an accompanying .conf file containing the follo on join and on respawn. * `treasures`: [Optional] List of treasures to be registered for the map, in a serialized format. Refer to the `treasures` sub-section for more details. +* `start_time`: [Optional] Time at start of match. Defaults to `0.4` [`0` - `1`]. +* `time_speed`: [Optional] Time speed multiplier. Accepts any valid number. Defaults to 1. * `r`: Radius of the map. * `h`: Height of the map. * `team.i`: Name of team `i`. diff --git a/mods/ctf/ctf_map/init.lua b/mods/ctf/ctf_map/init.lua index efd3468..db3953e 100644 --- a/mods/ctf/ctf_map/init.lua +++ b/mods/ctf/ctf_map/init.lua @@ -20,6 +20,7 @@ if minetest.get_modpath("ctf") then dofile(modpath .. "/base.lua") dofile(modpath .. "/chest.lua") dofile(modpath .. "/give_initial_stuff.lua") + dofile(modpath .. "/time.lua") dofile(modpath .. "/schem_map.lua") dofile(modpath .. "/maps_catalog.lua") diff --git a/mods/ctf/ctf_map/schem_map.lua b/mods/ctf/ctf_map/schem_map.lua index 275bcb4..5d065f3 100644 --- a/mods/ctf/ctf_map/schem_map.lua +++ b/mods/ctf/ctf_map/schem_map.lua @@ -91,7 +91,9 @@ local function load_map_meta(idx, path) local initial_stuff = meta:get("initial_stuff") local treasures = meta:get("treasures") - treasures = treasures and treasures:split(";") + local start_time = meta:get("start_time") + local time_speed = meta:get("time_speed") + local map = { name = meta:get("name"), author = meta:get("author"), @@ -103,7 +105,9 @@ local function load_map_meta(idx, path) base_node = meta:get("base_node"), schematic = path .. ".mts", initial_stuff = initial_stuff and initial_stuff:split(","), - treasures = treasures, + treasures = treasures and treasures:split(";"), + start_time = start_time and tonumber(start_time), + time_speed = time_speed and tonumber(time_speed), r = tonumber(meta:get("r")), h = tonumber(meta:get("h")), offset = offset, @@ -114,7 +118,7 @@ local function load_map_meta(idx, path) assert(map.r <= max_r) map.pos1 = vector.add(offset, { x = -map.r, y = -map.h / 2, z = -map.r }) - map.pos2 = vector.add(offset, { x = map.r, y = map.h / 2, z = map.r }) + map.pos2 = vector.add(offset, { x = map.r, y = map.h / 2, z = map.r }) -- Read teams from config local i = 1 @@ -344,6 +348,9 @@ ctf_match.register_on_new_match(function() end end + -- Update time speed + ctf_map.update_time() + -- Place map place_map(ctf_map.map) end) diff --git a/mods/ctf/ctf_map/time.lua b/mods/ctf/ctf_map/time.lua new file mode 100644 index 0000000..e36115e --- /dev/null +++ b/mods/ctf/ctf_map/time.lua @@ -0,0 +1,13 @@ +local BASE_TIME_SPEED = 72 + +function ctf_map.update_time() + local time = ctf_map.map.start_time + local mult = ctf_map.map.time_speed or 1 + if time then + minetest.set_timeofday(time) + else + minetest.set_timeofday(0.4) + end + + minetest.settings:set("time_speed", BASE_TIME_SPEED * mult) +end diff --git a/mods/ctf/ctf_match/matches.lua b/mods/ctf/ctf_match/matches.lua index 9bebc80..b81fcf1 100644 --- a/mods/ctf/ctf_match/matches.lua +++ b/mods/ctf/ctf_match/matches.lua @@ -41,8 +41,6 @@ function ctf_match.next() ctf_alloc.set_all() - minetest.set_timeofday(0.4) - minetest.chat_send_all("Next round!") if minetest.global_exists("chatplus") then chatplus.log("Next round!")