2025-07-18 09:12 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000951Spring engineGeneralpublic2008-10-14 21:21
ReporterEvil4Zerggin 
Assigned ToKloot 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000951: Make Floating Structures Obey Maxslope on Land?
DescriptionPatch to make floating structures check maxslope on land. I'm not the most familiar with C++ and the engine so please check the code.
Additional InformationAs far as I can tell, giving a structure a waterline and removing minwaterdepth allows it to be built on land and water, and the structure floats when on the latter. However, it also appears to ignore the structure's slope tolerance, even on land. Would it be possible to make it not ignore slope tolerance on land (but still ignore it on water)? This would allow us to use the same structure on both land and water, saving space on buildlists.

See also:

http://spring.clan-sy.com/phpbb/viewtopic.php?f=21&t=15152
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon FloatingSlopeTolerance.patch (716 bytes) 2008-06-11 22:25 -
    Index: UnitHandler.cpp
    ===================================================================
    --- UnitHandler.cpp	(revision 6023)
    +++ UnitHandler.cpp	(working copy)
    @@ -381,8 +381,10 @@
     			}
     		}
     	}
    -
    -	if(!unitdef->floater)
    +	
    +	float groundheight = ground->GetHeight2(pos.x,pos.z);
    +	
    +	if(!unitdef->floater || groundheight > 0)
     	{
     		float* heightmap=readmap->GetHeightmap();
     		int x=(int) (pos.x/SQUARE_SIZE);
    @@ -395,12 +397,12 @@
     		if(pos.y<orgh-hdif && pos.y<h-hdif)
     			return 0;
     	}
    -	float groundheight = ground->GetHeight2(pos.x,pos.z);
    +	
     	if(!unitdef->floater && groundheight<-unitdef->maxWaterDepth)
     		return 0;
     	if(groundheight>-unitdef->minWaterDepth)
     		return 0;
    -
    +	
     	return ret;
     }
     
    
    patch file icon FloatingSlopeTolerance.patch (716 bytes) 2008-06-11 22:25 +
  • patch file icon FloatingSlopeTolerance_01.patch (2,423 bytes) 2008-06-11 23:08 -
    Index: UnitDefHandler.cpp
    ===================================================================
    --- UnitDefHandler.cpp	(revision 5917)
    +++ UnitDefHandler.cpp	(working copy)
    @@ -743,7 +743,7 @@
     	ud.smoothAnim = udTable.GetBool("smoothAnim", false);
     	ud.canLoopbackAttack = udTable.GetBool("canLoopbackAttack", false);
     	ud.canCrash = udTable.GetBool("canCrash", true);
    -	ud.levelGround = udTable.GetBool("levelGround", true);
    +	ud.levelGround = udTable.GetBool("levelGround", !ud.floater);
     	ud.strafeToAttack = udTable.GetBool("strafeToAttack", false);
     
     
    Index: UnitHandler.cpp
    ===================================================================
    --- UnitHandler.cpp	(revision 6023)
    +++ UnitHandler.cpp	(working copy)
    @@ -381,8 +381,10 @@
     			}
     		}
     	}
    -
    -	if(!unitdef->floater)
    +	
    +	float groundheight = ground->GetHeight2(pos.x,pos.z);
    +	
    +	if(!unitdef->floater || groundheight > 0)
     	{
     		float* heightmap=readmap->GetHeightmap();
     		int x=(int) (pos.x/SQUARE_SIZE);
    @@ -395,12 +397,12 @@
     		if(pos.y<orgh-hdif && pos.y<h-hdif)
     			return 0;
     	}
    -	float groundheight = ground->GetHeight2(pos.x,pos.z);
    +	
     	if(!unitdef->floater && groundheight<-unitdef->maxWaterDepth)
     		return 0;
     	if(groundheight>-unitdef->minWaterDepth)
     		return 0;
    -
    +	
     	return ret;
     }
     
    Index: UnitLoader.cpp
    ===================================================================
    --- UnitLoader.cpp	(revision 5917)
    +++ UnitLoader.cpp	(working copy)
    @@ -497,7 +497,7 @@
     void CUnitLoader::FlattenGround(const CUnit* unit)
     {
     	const UnitDef* unitDef = unit->unitDef;
    -	if (!mapDamage->disabled && unitDef->levelGround && !unitDef->floater &&
    +	if (!mapDamage->disabled && unitDef->levelGround &&
     	    !(unitDef->canmove && (unitDef->speed > 0.0f))) {
     		BuildInfo bi(unitDef, unit->pos, unit->buildFacing);
     		bi.pos = helper->Pos2BuildPos(bi);
    Index: UnitTypes/Builder.cpp
    ===================================================================
    --- UnitTypes/Builder.cpp	(revision 6024)
    +++ UnitTypes/Builder.cpp	(working copy)
    @@ -515,7 +515,7 @@
     	CUnit* b = unitLoader.LoadUnit(nextBuildType, nextBuildPos, team,
     	                               true, buildInfo.buildFacing, this);
     
    -	if (mapDamage->disabled || !unitDef->levelGround || unitDef->floater ||
    +	if (mapDamage->disabled || !unitDef->levelGround ||
     	    (unitDef->canmove && (unitDef->speed > 0.0f))) {
     		// skip the terraforming job.
     		b->terraformLeft = 0;
    
    patch file icon FloatingSlopeTolerance_01.patch (2,423 bytes) 2008-06-11 23:08 +
  • patch file icon FloatingSlopeTolerance_02.patch (2,552 bytes) 2008-06-11 23:30 -
    Index: UnitHandler.cpp
    ===================================================================
    --- UnitHandler.cpp	(revision 6023)
    +++ UnitHandler.cpp	(working copy)
    @@ -381,8 +381,10 @@
     			}
     		}
     	}
    -
    -	if(!unitdef->floater)
    +	
    +	const float groundheight = ground->GetHeight2(pos.x,pos.z);
    +	
    +	if(!unitdef->floater || groundheight > 0)
     	{
     		float* heightmap=readmap->GetHeightmap();
     		int x=(int) (pos.x/SQUARE_SIZE);
    @@ -395,12 +397,12 @@
     		if(pos.y<orgh-hdif && pos.y<h-hdif)
     			return 0;
     	}
    -	float groundheight = ground->GetHeight2(pos.x,pos.z);
    +	
     	if(!unitdef->floater && groundheight<-unitdef->maxWaterDepth)
     		return 0;
     	if(groundheight>-unitdef->minWaterDepth)
     		return 0;
    -
    +	
     	return ret;
     }
     
    Index: UnitLoader.cpp
    ===================================================================
    --- UnitLoader.cpp	(revision 5917)
    +++ UnitLoader.cpp	(working copy)
    @@ -497,7 +497,8 @@
     void CUnitLoader::FlattenGround(const CUnit* unit)
     {
     	const UnitDef* unitDef = unit->unitDef;
    -	if (!mapDamage->disabled && unitDef->levelGround && !unitDef->floater &&
    +	const float groundheight = ground->GetHeight2(unit->pos.x,unit->pos.z);
    +	if (!mapDamage->disabled && unitDef->levelGround && !(unitDef->floater && groundheight <= 0) &&
     	    !(unitDef->canmove && (unitDef->speed > 0.0f))) {
     		BuildInfo bi(unitDef, unit->pos, unit->buildFacing);
     		bi.pos = helper->Pos2BuildPos(bi);
    Index: UnitTypes/Builder.cpp
    ===================================================================
    --- UnitTypes/Builder.cpp	(revision 6024)
    +++ UnitTypes/Builder.cpp	(working copy)
    @@ -514,8 +514,10 @@
     
     	CUnit* b = unitLoader.LoadUnit(nextBuildType, nextBuildPos, team,
     	                               true, buildInfo.buildFacing, this);
    +	                               
    +	const float groundheight = ground->GetHeight2(b->pos.x,b->pos.z);
     
    -	if (mapDamage->disabled || !unitDef->levelGround || unitDef->floater ||
    +	if (mapDamage->disabled || !unitDef->levelGround || (unitDef->floater && groundheight <= 0) ||
     	    (unitDef->canmove && (unitDef->speed > 0.0f))) {
     		// skip the terraforming job.
     		b->terraformLeft = 0;
    @@ -555,8 +557,8 @@
     		 * Duplicated from CMoveType::SlowUpdate(), which
     		 * is why we use the regular code for floating things.
     		 */
    -		curBuild->pos.y=ground->GetHeight2(curBuild->pos.x,curBuild->pos.z);
    -		curBuild->midPos.y=curBuild->pos.y+curBuild->relMidPos.y;
    +		curBuild->pos.y=groundheight;
    +		curBuild->midPos.y=groundheight+curBuild->relMidPos.y;
     	}
     	else {
     		float d=nextBuildPos.y-curBuild->pos.y;
    
    patch file icon FloatingSlopeTolerance_02.patch (2,552 bytes) 2008-06-11 23:30 +

-Relationships
+Relationships

-Notes

~0002330

Evil4Zerggin (reporter)

Added patch for ground flattening, although I think I did it wrong (should flatten ground under floating structures only on land, even if levelGround is true). New patch to come as soon as I figure out how to do that.

~0002331

Evil4Zerggin (reporter)

Hopefully corrected patch.

~0002834

lurker (reporter)

bump

~0002894

Kloot (developer)

committed, thanks for your contribution :)
+Notes

-Issue History
Date Modified Username Field Change
2008-06-11 22:25 Evil4Zerggin New Issue
2008-06-11 22:25 Evil4Zerggin File Added: FloatingSlopeTolerance.patch
2008-06-11 23:08 Evil4Zerggin File Added: FloatingSlopeTolerance_01.patch
2008-06-11 23:12 Evil4Zerggin Note Added: 0002330
2008-06-11 23:30 Evil4Zerggin File Added: FloatingSlopeTolerance_02.patch
2008-06-11 23:31 Evil4Zerggin Note Added: 0002331
2008-10-13 10:06 lurker Note Added: 0002834
2008-10-13 13:00 Kloot Status new => assigned
2008-10-13 13:00 Kloot Assigned To => Kloot
2008-10-14 21:21 Kloot Status assigned => resolved
2008-10-14 21:21 Kloot Resolution open => fixed
2008-10-14 21:21 Kloot Note Added: 0002894
+Issue History