2020-08-13 16:14 CEST

View Issue Details Jump to Notes ] Related Changesets ]
IDProjectCategoryView StatusLast Update
0006357Spring engineLuapublic2020-07-03 16:51
ReporterFLOZi 
Assigned ToKloot 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusresolvedResolutionfixed 
Product Version104.0 +git 
Target VersionFixed in Version 
Summary0006357: MoveCtrlNotify for SetLimits
DescriptionIt'd be really useful if MoveCtrlNotify was called when a unit hit the limits set in MoveCtrl.SetLimits.

This could be via a new scriptNotify code (i.e. 2) and might be enabled/disabled through a MoveCtrl.SetTrackLimits callout.

I'll happily do the work if you indicate the preferred implementation.
TagsNo tags attached.
Checked infolog.txt for ErrorsIrrelevant
Attached Files
  • diff file icon patch.diff (4,335 bytes) 2020-01-02 09:57 -
    From 4a43b8d6f47302a0ee77b09098c6a9f1e1c64fde Mon Sep 17 00:00:00 2001
    From: Craig Lawrence <flozi@blueyonder.co.uk>
    Date: Wed, 1 Jan 2020 22:43:41 +0000
    Subject: [PATCH] Resolve 6357 * Add 'Spring.MoveCtrl.TrackLimits' callout *
     When enabled, MoveCtrlNotify is called (data = 2) when a unit reaches limits
     set via Spring.MoveCtrl.SetLimits
    
    ---
     rts/Lua/LuaSyncedMoveCtrl.cpp        | 13 +++++++++++++
     rts/Lua/LuaSyncedMoveCtrl.h          |  1 +
     rts/Sim/MoveTypes/ScriptMoveType.cpp | 21 ++++++++++++++-------
     rts/Sim/MoveTypes/ScriptMoveType.h   |  1 +
     4 files changed, 29 insertions(+), 7 deletions(-)
    
    diff --git a/rts/Lua/LuaSyncedMoveCtrl.cpp b/rts/Lua/LuaSyncedMoveCtrl.cpp
    index f647f1bfab..1160757a2c 100644
    --- a/rts/Lua/LuaSyncedMoveCtrl.cpp
    +++ b/rts/Lua/LuaSyncedMoveCtrl.cpp
    @@ -55,6 +55,7 @@ bool LuaSyncedMoveCtrl::PushMoveCtrl(lua_State* L)
     
     	REGISTER_LUA_CFUNC(SetTrackSlope);
     	REGISTER_LUA_CFUNC(SetTrackGround);
    +	REGISTER_LUA_CFUNC(SetTrackLimits);
     	REGISTER_LUA_CFUNC(SetGroundOffset);
     	REGISTER_LUA_CFUNC(SetGravity);
     	REGISTER_LUA_CFUNC(SetDrag);
    @@ -389,6 +390,18 @@ int LuaSyncedMoveCtrl::SetTrackGround(lua_State* L)
     }
     
     
    +int LuaSyncedMoveCtrl::SetTrackLimits(lua_State* L)
    +{
    +	CScriptMoveType* moveType = ParseScriptMoveType(L, __func__, 1);
    +
    +	if (moveType == nullptr)
    +		return 0;
    +
    +	moveType->trackLimits = luaL_checkboolean(L, 2);
    +	return 0;
    +}
    +
    +
     int LuaSyncedMoveCtrl::SetGroundOffset(lua_State* L)
     {
     	CScriptMoveType* moveType = ParseScriptMoveType(L, __func__, 1);
    diff --git a/rts/Lua/LuaSyncedMoveCtrl.h b/rts/Lua/LuaSyncedMoveCtrl.h
    index 9b5b1baf34..f582ae4785 100644
    --- a/rts/Lua/LuaSyncedMoveCtrl.h
    +++ b/rts/Lua/LuaSyncedMoveCtrl.h
    @@ -39,6 +39,7 @@ class LuaSyncedMoveCtrl {
     
     		static int SetTrackSlope(lua_State* L);
     		static int SetTrackGround(lua_State* L);
    +		static int SetTrackLimits(lua_State* L);
     		static int SetGroundOffset(lua_State* L);
     		static int SetGravity(lua_State* L);
     		static int SetDrag(lua_State* L);
    diff --git a/rts/Sim/MoveTypes/ScriptMoveType.cpp b/rts/Sim/MoveTypes/ScriptMoveType.cpp
    index 4c2893808a..325fecb531 100644
    --- a/rts/Sim/MoveTypes/ScriptMoveType.cpp
    +++ b/rts/Sim/MoveTypes/ScriptMoveType.cpp
    @@ -28,6 +28,7 @@ CR_REG_METADATA(CScriptMoveType, (
     
     	CR_MEMBER(trackSlope),
     	CR_MEMBER(trackGround),
    +	CR_MEMBER(trackLimits),
     	CR_MEMBER(groundOffset),
     	CR_MEMBER(gravityFactor),
     	CR_MEMBER(windFactor),
    @@ -55,6 +56,7 @@ CScriptMoveType::CScriptMoveType(CUnit* owner):
     	maxs(+1.0e9f, +1.0e9f, +1.0e9f),
     	trackSlope(false),
     	trackGround(false),
    +	trackLimits(false),
     	groundOffset(0.0f),
     	gravityFactor(0.0f),
     	windFactor(0.0f),
    @@ -162,13 +164,18 @@ bool CScriptMoveType::Update()
     
     void CScriptMoveType::CheckLimits()
     {
    -	if (owner->pos.x < mins.x) { owner->pos.x = mins.x; owner->speed.x = 0.0f; }
    -	if (owner->pos.x > maxs.x) { owner->pos.x = maxs.x; owner->speed.x = 0.0f; }
    -	if (owner->pos.y < mins.y) { owner->pos.y = mins.y; owner->speed.y = 0.0f; }
    -	if (owner->pos.y > maxs.y) { owner->pos.y = maxs.y; owner->speed.y = 0.0f; }
    -	if (owner->pos.z < mins.z) { owner->pos.z = mins.z; owner->speed.z = 0.0f; }
    -	if (owner->pos.z > maxs.z) { owner->pos.z = maxs.z; owner->speed.z = 0.0f; }
    -
    +	bool hitLimit = false;
    +	if (owner->pos.x < mins.x) { owner->pos.x = mins.x; owner->speed.x = 0.0f; hitLimit = true; }
    +	if (owner->pos.x > maxs.x) { owner->pos.x = maxs.x; owner->speed.x = 0.0f; hitLimit = true; }
    +	if (owner->pos.y < mins.y) { owner->pos.y = mins.y; owner->speed.y = 0.0f; hitLimit = true; }
    +	if (owner->pos.y > maxs.y) { owner->pos.y = maxs.y; owner->speed.y = 0.0f; hitLimit = true; }
    +	if (owner->pos.z < mins.z) { owner->pos.z = mins.z; owner->speed.z = 0.0f; hitLimit = true; }
    +	if (owner->pos.z > maxs.z) { owner->pos.z = maxs.z; owner->speed.z = 0.0f; hitLimit = true; }
    +
    +	if (trackLimits && hitLimit) {
    +		scriptNotify = 2;
    +		CheckNotify();
    +	}
     	owner->UpdateMidAndAimPos();
     }
     
    diff --git a/rts/Sim/MoveTypes/ScriptMoveType.h b/rts/Sim/MoveTypes/ScriptMoveType.h
    index 072d3ca2ca..44371e5b6d 100644
    --- a/rts/Sim/MoveTypes/ScriptMoveType.h
    +++ b/rts/Sim/MoveTypes/ScriptMoveType.h
    @@ -66,6 +66,7 @@ class CScriptMoveType : public AMoveType
     
     		bool trackSlope;
     		bool trackGround;
    +		bool trackLimits;
     		float groundOffset;
     
     		float gravityFactor;
    -- 
    2.15.1.windows.2
    
    
    diff file icon patch.diff (4,335 bytes) 2020-01-02 09:57 +
  • diff file icon patch2.diff (7,070 bytes) 2020-01-09 22:40 -
    diff --git a/rts/Lua/LuaConstGame.cpp b/rts/Lua/LuaConstGame.cpp
    index aed7893a68..b4ae1dc9c8 100644
    --- a/rts/Lua/LuaConstGame.cpp
    +++ b/rts/Lua/LuaConstGame.cpp
    @@ -15,6 +15,7 @@
     #include "Sim/Misc/DamageArrayHandler.h"
     #include "Sim/Misc/Wind.h"
     #include "Sim/MoveTypes/MoveDefHandler.h"
    +#include "Sim/MoveTypes/ScriptMoveType.h"
     #include "Sim/Units/UnitHandler.h"
     #include "System/FileSystem/ArchiveScanner.h"
     #include "System/StringUtil.h"
    @@ -199,6 +200,15 @@ bool LuaConstGame::PushEntries(lua_State* L)
     			LuaPushNamedNumber(L, "Ship" , MoveDef::SpeedModClass::Ship );
     		lua_rawset(L, -3);
     	}
    +	{
    +		// MoveCtrl script notify types
    +		lua_pushliteral(L, "scriptNotifyTypes");
    +		lua_createtable(L, 0, 3);
    +			LuaPushNamedNumber(L, "hitNothing" , CScriptMoveType::hitNothing );
    +			LuaPushNamedNumber(L, "hitGround" , CScriptMoveType::hitGround );
    +			LuaPushNamedNumber(L, "hitLimit", CScriptMoveType::hitLimit);
    +		lua_rawset(L, -3);
    +	}
     
     	return true;
     }
    diff --git a/rts/Lua/LuaSyncedMoveCtrl.cpp b/rts/Lua/LuaSyncedMoveCtrl.cpp
    index f647f1bfab..097873bb1f 100644
    --- a/rts/Lua/LuaSyncedMoveCtrl.cpp
    +++ b/rts/Lua/LuaSyncedMoveCtrl.cpp
    @@ -55,6 +55,7 @@ bool LuaSyncedMoveCtrl::PushMoveCtrl(lua_State* L)
     
     	REGISTER_LUA_CFUNC(SetTrackSlope);
     	REGISTER_LUA_CFUNC(SetTrackGround);
    +	REGISTER_LUA_CFUNC(SetTrackLimits);
     	REGISTER_LUA_CFUNC(SetGroundOffset);
     	REGISTER_LUA_CFUNC(SetGravity);
     	REGISTER_LUA_CFUNC(SetDrag);
    @@ -68,6 +69,7 @@ bool LuaSyncedMoveCtrl::PushMoveCtrl(lua_State* L)
     	REGISTER_LUA_CFUNC(SetShotStop);
     	REGISTER_LUA_CFUNC(SetSlopeStop);
     	REGISTER_LUA_CFUNC(SetCollideStop);
    +	REGISTER_LUA_CFUNC(SetLimitsStop);
     
     	REGISTER_LUA_CFUNC(SetAirMoveTypeData);
     	REGISTER_LUA_CFUNC(SetGroundMoveTypeData);
    @@ -389,6 +391,18 @@ int LuaSyncedMoveCtrl::SetTrackGround(lua_State* L)
     }
     
     
    +int LuaSyncedMoveCtrl::SetTrackLimits(lua_State* L)
    +{
    +	CScriptMoveType* moveType = ParseScriptMoveType(L, __func__, 1);
    +
    +	if (moveType == nullptr)
    +		return 0;
    +
    +	moveType->trackLimits = luaL_checkboolean(L, 2);
    +	return 0;
    +}
    +
    +
     int LuaSyncedMoveCtrl::SetGroundOffset(lua_State* L)
     {
     	CScriptMoveType* moveType = ParseScriptMoveType(L, __func__, 1);
    @@ -509,6 +523,18 @@ int LuaSyncedMoveCtrl::SetCollideStop(lua_State* L)
     }
     
     
    +int LuaSyncedMoveCtrl::SetLimitsStop(lua_State* L)
    +{
    +	CScriptMoveType* moveType = ParseScriptMoveType(L, __func__, 1);
    +
    +	if (moveType == nullptr)
    +		return 0;
    +
    +	moveType->limitsStop = lua_toboolean(L, 2);
    +	return 0;
    +}
    +
    +
     
     /******************************************************************************/
     /* MoveType member-value handling */
    diff --git a/rts/Lua/LuaSyncedMoveCtrl.h b/rts/Lua/LuaSyncedMoveCtrl.h
    index 9b5b1baf34..f05df19d9f 100644
    --- a/rts/Lua/LuaSyncedMoveCtrl.h
    +++ b/rts/Lua/LuaSyncedMoveCtrl.h
    @@ -39,6 +39,7 @@ class LuaSyncedMoveCtrl {
     
     		static int SetTrackSlope(lua_State* L);
     		static int SetTrackGround(lua_State* L);
    +		static int SetTrackLimits(lua_State* L);
     		static int SetGroundOffset(lua_State* L);
     		static int SetGravity(lua_State* L);
     		static int SetDrag(lua_State* L);
    @@ -52,6 +53,7 @@ class LuaSyncedMoveCtrl {
     		static int SetShotStop(lua_State* L);
     		static int SetSlopeStop(lua_State* L);
     		static int SetCollideStop(lua_State* L);
    +		static int SetLimitsStop(lua_State* L);
     
     		// *MoveType-specific setters
     		static int SetGroundMoveTypeData(lua_State* L);
    diff --git a/rts/Sim/MoveTypes/ScriptMoveType.cpp b/rts/Sim/MoveTypes/ScriptMoveType.cpp
    index 4c2893808a..34b4dbbab5 100644
    --- a/rts/Sim/MoveTypes/ScriptMoveType.cpp
    +++ b/rts/Sim/MoveTypes/ScriptMoveType.cpp
    @@ -28,6 +28,7 @@ CR_REG_METADATA(CScriptMoveType, (
     
     	CR_MEMBER(trackSlope),
     	CR_MEMBER(trackGround),
    +	CR_MEMBER(trackLimits),
     	CR_MEMBER(groundOffset),
     	CR_MEMBER(gravityFactor),
     	CR_MEMBER(windFactor),
    @@ -55,6 +56,7 @@ CScriptMoveType::CScriptMoveType(CUnit* owner):
     	maxs(+1.0e9f, +1.0e9f, +1.0e9f),
     	trackSlope(false),
     	trackGround(false),
    +	trackLimits(false),
     	groundOffset(0.0f),
     	gravityFactor(0.0f),
     	windFactor(0.0f),
    @@ -63,7 +65,8 @@ CScriptMoveType::CScriptMoveType(CUnit* owner):
     	shotStop(false),
     	slopeStop(false),
     	collideStop(false),
    -	scriptNotify(0)
    +	limitsStop(false),
    +	scriptNotify(hitNothing)
     {
     	// use the transformation matrix instead of heading
     	UseHeading(false);
    @@ -88,7 +91,7 @@ void CScriptMoveType::CheckNotify()
     		// NOTE: deletes \<this\>
     		owner->DisableScriptMoveType();
     	} else {
    -		scriptNotify = 0;
    +		scriptNotify = hitNothing;
     	}
     }
     
    @@ -131,7 +134,7 @@ bool CScriptMoveType::Update()
     				velVec = ZeroVector;
     				relVel = ZeroVector;
     				rotVel = ZeroVector;
    -				scriptNotify = 1;
    +				scriptNotify = hitGround;
     			}
     		}
     	}
    @@ -162,13 +165,32 @@ bool CScriptMoveType::Update()
     
     void CScriptMoveType::CheckLimits()
     {
    -	if (owner->pos.x < mins.x) { owner->pos.x = mins.x; owner->speed.x = 0.0f; }
    -	if (owner->pos.x > maxs.x) { owner->pos.x = maxs.x; owner->speed.x = 0.0f; }
    -	if (owner->pos.y < mins.y) { owner->pos.y = mins.y; owner->speed.y = 0.0f; }
    -	if (owner->pos.y > maxs.y) { owner->pos.y = maxs.y; owner->speed.y = 0.0f; }
    -	if (owner->pos.z < mins.z) { owner->pos.z = mins.z; owner->speed.z = 0.0f; }
    -	if (owner->pos.z > maxs.z) { owner->pos.z = maxs.z; owner->speed.z = 0.0f; }
    +	bool exceedLimit = false;
    +	if (owner->pos.x < mins.x) { 
    +		exceedLimit = true;
    +		if (limitsStop) { owner->pos.x = mins.x; owner->speed.x = 0.0f; }
    +	}
    +	if (owner->pos.x > maxs.x) { 
    +		exceedLimit = true;
    +		if (limitsStop) { owner->pos.x = maxs.x; owner->speed.x = 0.0f; }
    +	}
    +	if (owner->pos.y < mins.y) { 
    +		exceedLimit = true;
    +		if (limitsStop) { owner->pos.y = mins.y; owner->speed.y = 0.0f; }
    +	}
    +	if (owner->pos.z > maxs.z) { 
    +		exceedLimit = true;
    +		if (limitsStop) { owner->pos.z = maxs.z; owner->speed.z = 0.0f; }
    +	}
    +	if (owner->pos.z < mins.z) { 
    +		exceedLimit = true;
    +		if (limitsStop) { owner->pos.z = mins.z; owner->speed.z = 0.0f; }
    +	}
     
    +	if (trackLimits && exceedLimit) {
    +		scriptNotify = hitLimit;
    +		CheckNotify();
    +	}
     	owner->UpdateMidAndAimPos();
     }
     
    diff --git a/rts/Sim/MoveTypes/ScriptMoveType.h b/rts/Sim/MoveTypes/ScriptMoveType.h
    index 072d3ca2ca..7c015c689f 100644
    --- a/rts/Sim/MoveTypes/ScriptMoveType.h
    +++ b/rts/Sim/MoveTypes/ScriptMoveType.h
    @@ -25,6 +25,12 @@ class CScriptMoveType : public AMoveType
     		void SetRotationVelocity(const float3& rvel);
     		void SetHeading(short heading);
     		void SetNoBlocking(bool state);
    +		
    +		enum ScriptNotifyState {
    +			hitNothing = 0,
    +			hitGround = 1,
    +			hitLimit = 2,
    +		};
     
     	public: // null'ed virtuals
     		void StartMoving(float3, float goalRadius) override {}
    @@ -66,6 +72,7 @@ class CScriptMoveType : public AMoveType
     
     		bool trackSlope;
     		bool trackGround;
    +		bool trackLimits;
     		float groundOffset;
     
     		float gravityFactor;
    @@ -77,9 +84,10 @@ class CScriptMoveType : public AMoveType
     		bool shotStop;
     		bool slopeStop;
     		bool collideStop;
    +		bool limitsStop;
     
     	protected:
    -		int scriptNotify;
    +		ScriptNotifyState scriptNotify = hitNothing;
     };
     
     #endif // SCRIPT_MOVE_TYPE_H
    
    diff file icon patch2.diff (7,070 bytes) 2020-01-09 22:40 +

-Relationships
+Relationships

-Notes

~0020299

FLOZi (reporter)

path2.diff replaces patch.diff, disabled existing default behaviour of SetLimits (forcing position and setting velocity to 0) and adds 'SetLimitsStop' callout to enable that. Allows Game control via MoveCtrlNotify to do whatever you want when the limits are reached, or to enable current behaviour.

~0020434

Anonymous (viewer)

Fix f4563f2fd2091da4fc7cbd408d555674e8641773 committed to develop branch: fix 0006357, repo: spring changeset id: 37876
+Notes

+Related Changesets

-Issue History
Date Modified Username Field Change
2019-12-31 22:43 FLOZi New Issue
2020-01-02 09:57 FLOZi File Added: patch.diff
2020-01-09 22:40 FLOZi File Added: patch2.diff
2020-01-09 22:41 FLOZi Note Added: 0020299
2020-07-02 23:30 Changeset attached => spring develop f4563f2f
2020-07-02 23:30 Anonymous Note Added: 0020434
2020-07-02 23:30 Changeset attached => spring maintenance adb8b6a2
2020-07-03 16:51 abma Assigned To => Kloot
2020-07-03 16:51 abma Status new => resolved
2020-07-03 16:51 abma Resolution open => fixed
+Issue History