~gpcf/advtrains

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH] Make killing velocity configurable

Details
Message ID
<HK0PR01MB259407CDCCDA582D931B86E0DB3E9@HK0PR01MB2594.apcprd01.prod.exchangelabs.com>
DKIM signature
missing
Download raw message
Patch: +9 -2
At the same time, fix a longstanding issue where overrun mode was
actually defaulting to nil when unconfigured and behaving like 'none',
which is probably why 56independent wasn't seeing that behaviour.
---
 advtrains/settingtypes.txt | 4 ++++
 advtrains/trainlogic.lua   | 7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/advtrains/settingtypes.txt b/advtrains/settingtypes.txt
index 2b627cb..2f8df0d 100644
--- a/advtrains/settingtypes.txt
+++ b/advtrains/settingtypes.txt
@@ -40,6 +40,9 @@ advtrains_prot_range_down (Track protection range [down]) int 1 0 10
#    normal: Player is killed, game-defined behavior is applied as if the player died by other means.
advtrains_overrun_mode (Overrun mode) enum drop none,drop,normal

#    Kill the player when a train hits them going above this velocity.
advtrains_kill_velocity (Train velocity to kill players and entities) int 3 1 30

#    Wagon entity loading/unloading range, in nodes
#    When a wagon is within this range to a player, it is loaded
#    When a wagon leaves this range + 32 nodes, it is unloaded
@@ -61,3 +64,4 @@ advtrains_save_interval (Save Interval) int 60 20 3600
#    If enabled, trains only collide with nodes with "normal" drawtype.
advtrains_forgiving_collision (Forgiving Collision mode) bool false

#
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index 35c3726..4a9b998 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -1,7 +1,8 @@
--trainlogic.lua
--controls train entities stuff about connecting/disconnecting/colliding trains and other things

local setting_overrun_mode = minetest.settings:get("advtrains_overrun_mode")
local setting_overrun_mode = minetest.settings:get("advtrains_overrun_mode") or "normal"
local setting_kill_velocity = tonumber(minetest.settings:get("advtrains_kill_velocity")) or 3

local benchmark=false
local bm={}
@@ -771,7 +772,9 @@ function advtrains.train_step_c(id, train, dtime)
						end

						--- 8b damage players ---
						if is_loaded_area and train.velocity > 3 and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal") then
                        if is_loaded_area and train.velocity > setting_kill_velocity
                            and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal")
                        then
							local testpts = minetest.pos_to_string(testpos)
							local player=advtrains.playersbypts[testpts]
							if player and player:get_hp()>0 and advtrains.is_damage_enabled(player:get_player_name()) then
-- 
2.34.1
Jason Bigelow <jbis1337@hotmail.com>
Details
Message ID
<HK0PR01MB2594BB89BCAFFD747D5F624ADB3E9@HK0PR01MB2594.apcprd01.prod.exchangelabs.com>
In-Reply-To
<HK0PR01MB259407CDCCDA582D931B86E0DB3E9@HK0PR01MB2594.apcprd01.prod.exchangelabs.com> (view parent)
DKIM signature
missing
Download raw message
Sorry for starting a new thread, old one is here: 
https://lists.sr.ht/~gpcf/advtrains/patches/29780. Well, now I know 
another way not to reply correctly...


Anway the biggest issue with 56independent's code was that he didn't 
check for a nil, and didn't add the new setting to settingtypes.txt. But 
while addressing those issues, I did stumble upon what the underlying 
issue was: trains aren't (weren't) deadly unless configured to do so, 
despite the default given in settingtypes.txt. Yeah, the Minetest API 
sucks like that sometimes.
Details
Message ID
<87wnhhtdcp.fsf@forksworld.de>
In-Reply-To
<HK0PR01MB259407CDCCDA582D931B86E0DB3E9@HK0PR01MB2594.apcprd01.prod.exchangelabs.com> (view parent)
DKIM signature
missing
Download raw message
> +#    Kill the player when a train hits them going above this velocity.
> +advtrains_kill_velocity (Train velocity to kill players and entities) int 3 1 30

I would suggest changing the description to "minimum velocity at which
trains can kill players".

Maybe the lower minimum should be set to 0 to allow making the train kill
players regardless of the velocity of the train. The type could also be
"float" but I do not think that matters in particular.

[PATCH] Allow kill velocity to be set to zero

Details
Message ID
<20220303101316.28628-1-yw05@forksworld.de>
In-Reply-To
<87wnhhtdcp.fsf@forksworld.de> (view parent)
DKIM signature
missing
Download raw message
Patch: +5 -4
Here are the changes I proposed in my reply email.

---
 advtrains/settingtypes.txt | 3 ++-
 advtrains/trainlogic.lua   | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/advtrains/settingtypes.txt b/advtrains/settingtypes.txt
index 2f8df0d..7bfa298 100644
--- a/advtrains/settingtypes.txt
+++ b/advtrains/settingtypes.txt
@@ -41,7 +41,8 @@ advtrains_prot_range_down (Track protection range [down]) int 1 0 10
advtrains_overrun_mode (Overrun mode) enum drop none,drop,normal

#    Kill the player when a train hits them going above this velocity.
advtrains_kill_velocity (Train velocity to kill players and entities) int 3 1 30
#    This setting is only sensible if advtrains_overrun_mode is set to "drop" or "normal".
advtrains_kill_velocity (Train velocity to kill players and entities) int 3 0 30

#    Wagon entity loading/unloading range, in nodes
#    When a wagon is within this range to a player, it is loaded
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index 4a9b998..27c7cab 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -772,9 +772,9 @@ function advtrains.train_step_c(id, train, dtime)
						end

						--- 8b damage players ---
                        if is_loaded_area and train.velocity > setting_kill_velocity
                            and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal")
                        then
						if is_loaded_area and train.velocity > setting_kill_velocity
							and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal")
						then
							local testpts = minetest.pos_to_string(testpos)
							local player=advtrains.playersbypts[testpts]
							if player and player:get_hp()>0 and advtrains.is_damage_enabled(player:get_player_name()) then
-- 
2.35.1
Reply to thread Export thread (mbox)