Depthmod is completely broken in spring 85 - Page 2

Depthmod is completely broken in spring 85

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Depthmod is completely broken in spring 85

Post by jK »

Wow that change was ages ago totally forgot it :)

I favor the following depthModLimit solution:

Code: Select all

	// depth-mod
	if (height < 0.0f) {
		float depthMod = 1.0f / std::max(0.01f, 1.0f + (-height * moveData.depthMod));
		depthMod = std::max(depthMod, moveData.depthModLimit);

		speedMod *= depthMod;
		speedMod *= waterDamageCost;
	}
This way a `depthModLimit=0.3` would mean depthMod only reduces maxspeed _to_ 30%.

Remains the question of the default value of it.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Depthmod is completely broken in spring 85

Post by Pxtl »

0.5 if you want to be backwards-compatible - that's what every game that included depthmod was getting until this version.

Otherwise I'd say zero, for simplicity's sake.

So nobody using negative depthmods for underwater speedboost? I guess there's no point in supporting that case if nobody does it.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Depthmod is completely broken in spring 85

Post by jK »

Pxtl wrote:So nobody using negative depthmods for underwater speedboost? I guess there's no point in supporting that case if nobody does it.
When I made the change I only checked the code to that position and moveData.depthMod wasn't 0..1 clamped IIRC. Still I didn't checked if the subsequent code limits it somehow. So I kept the support for it.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Depthmod is completely broken in spring 85

Post by smoth »

Pxtl wrote:That said, do mods have access to the typemap that would allow them to create and apply their own types? Because that would be an alternative - Forb could apply a 50% slowdown type to everything below elevation zero.
typemaps don't work that way.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Depthmod is completely broken in spring 85

Post by knorke »

Pxtl wrote:edit: I'd absolutely support a simpler equation - a simple linear formula down to a fixed cap would be fine.
Well if you cap at one end, might as well limit the other end too ;)

Image
So it would need 3 tags but you can do anything you want. Anything at all.

And you can basicaly use jK's code but switch the 0.0f for noSlowWaterDepth:

Code: Select all

   // depth-mod
   if (height < noSlowWaterDepth) { // <- change to jK's code
      float depthMod = 1.0f / std::max(0.01f, 1.0f + (-height * moveData.depthMod));
      depthMod = std::max(depthMod, moveData.depthModLimit);

      speedMod *= depthMod;
      speedMod *= waterDamageCost;
   }
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Depthmod is completely broken in spring 85

Post by Forboding Angel »

jK wrote:Wow that change was ages ago totally forgot it :)

I favor the following depthModLimit solution:

Code: Select all

	// depth-mod
	if (height < 0.0f) {
		float depthMod = 1.0f / std::max(0.01f, 1.0f + (-height * moveData.depthMod));
		depthMod = std::max(depthMod, moveData.depthModLimit);

		speedMod *= depthMod;
		speedMod *= waterDamageCost;
	}
This way a `depthModLimit=0.3` would mean depthMod only reduces maxspeed _to_ 30%.

Remains the question of the default value of it.

I'm good with this method, however please allow for multiple decimal places (something that for some reason a lot of tags don't).

I.E. For my uses I would use 0.95 so that only 5% of max speed is lost. I just want a tiny slowdown to indicate that the unit is under increased resistance from the water, I do not want it to have a significant impact upon gameplay.

I'mo a default of 0.75 would be a lot better for everyone involved. Half speed is quite a bit.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Depthmod is completely broken in spring 85

Post by Pxtl »

smoth wrote:typemaps don't work that way.
Didn't think so. Was just a guess. If you could make up a terrain-type that says "bots and vehicles move at 70%" and then whenever the terrain is modified you apply that type to anything underwater you could brute-force a flat underwater slowdown that way... but yeah, that level of control over the typemap doesn't exist.
Pxtl wrote:0.5 if you want to be backwards-compatible - that's what every game that included depthmod was getting until this version.

Otherwise I'd say zero, for simplicity's sake.

So nobody using negative depthmods for underwater speedboost? I guess there's no point in supporting that case if nobody does it.
Well, there's that max(0.01f...) snippet that was added to avoid divide-by-zero. That's effectively defining the max speedup as 100x normal. But otherwise it looks like the code should allow for underwater speedups with negative slopemod bounded at a hard cap of 100x normal speed. I should give it a try and see what happens.

Either way, though... no point worrying about that behavior if nobody uses it. Undefined behavior is undefined.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Depthmod is completely broken in spring 85

Post by FLOZi »

https://github.com/spring/spring/commit ... e000359e2e
un-hardcode the DepthMod equation
new MoveDef parameters
"depthModMinHeight", defaults to 0.0
"depthModMaxHeight", defaults to +inf
"depthModQuadraticCoeff", defaults to 0.0
"depthModLinearCoeff", defaults to 0.1 (deprecates "depthMod")
"depthModConstantCoeff", defaults to 1.0

new formula is given by
if h < "depthModMinHeight": 1.0
if h > "depthModMaxHeight": 1.0
else:
depthScale = MAX(0.01, MIN("depthModMaxValue", (a * h * h) + (b * h) + c))
depthMod = 1 / depthScale
where
h = unit's absolute height below water surface
a = "depthModQuadraticCoeff"
b = "depthModLinearCoeff"
c = "depthModConstantCoeff"
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Depthmod is completely broken in spring 85

Post by Forboding Angel »

Thanks kloot!!! :-) Especially for the explicit instructions on how to get what I want with 0.86 :mrgreen:
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Depthmod is completely broken in spring 85

Post by Pxtl »

Yes indeed. Depthmod system will be usable again with that patch. The comment defines a "maxDepthModValue" though in its equations that does not appear in the list of new MoveDef parameters, I assume that was accidental.

The DepthModMaxHeight is surprising... since it goes back to 1.0 at this height, it couldn't be used for underwater functionality. What's that for then? Some incredibly perverse reverse-depthmod where you have an amphibious unit that slows down as it gets higher and higher up on the land, and moves faster under water?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Depthmod is completely broken in spring 85

Post by Forboding Angel »

Actually for the gundam universe, that would be useful.
Post Reply

Return to “Engine”