Lowering unit elevation below ground/water level

Post Reply
User avatar
SpinoInWonderland
Posts: 1
Joined: Mon Nov 29, 2021 20:55 pm
Location: Earth
Contact:

Lowering unit elevation below ground/water level

Post by SpinoInWonderland »

How feasible is it to "sink" a unit into the ground/water level?

Asking because I want to make Spinosaurus semiaquatic (I can take the dated long-legged model, it is a 2006 game after all, but the palaeoenthusiast that I am just wants to make it a little bit more scientifically accurate there) but it lacks the swimming animations, so I set it to use the same ones it uses normally.

Below is the custom class I made for it:

Code: Select all

class CSpinosaurus inherit CAnimal

	const real SWIM_DEPTH=5.5f;
	
	var string m_sIdleAnim;
	var string m_sHump;

	var vec3 m_vHeight;
	var vec3 m_vPosition;
	
	export constructor()
		if(CMirageSrvMgr.Get().NoHumpWalking())then
			m_sHump="def";
		else
			m_sHump="hump";
		endif;
	endconstructor;

	export proc void OnInit(bool p_bLoad)
		super.OnInit(p_bLoad);
		SetCanSwim(true);
		SetIdleAnim();
		if(!p_bLoad)then
			ReBuildWeapon();
			CheckWaterLand();
		endif;
	endproc;

	export proc void OnPostLoad()
		super.OnPostLoad();
		CheckWaterLand();
	endproc;
	
	export proc void OnActionEnd(bool p_bBroken)
		super.OnActionEnd(p_bBroken);
		CheckWaterLand();	//fallback
	endproc;
	
	export proc void SetPos(vec3 p_vPos)
		//somebody beams me around -> I must check my pos for land/water
		super.SetPos(p_vPos);
		CheckWaterLand();
	endproc;

	export proc void CheckWaterLand()
		OnAmphibianWaterLandTransition(!IsInWater(),true);
	endproc;

	//this function will be called from inside the walk action
	proc void OnAmphibianWaterLandTransition(bool p_bWaterToLand, bool p_bInto)
		if(p_bWaterToLand)then
			m_sIdleAnim="standanim";
			m_xWalkSet="def";
			m_xHumpWalkSet=m_sHump;
			WaterToLand();
		else
			m_sIdleAnim="standanim";
			m_xWalkSet="def";
			m_xHumpWalkSet="m_sHump";
			LandToWater();
		endif;
		SetDefaultWalkSet(m_xWalkSet);
	endproc;
	
	export proc void LandToWater()
		m_vHeight.SetZ(Math.Max(CSrvWrap.GetScapeMgr().GetHeight(m_vHeight.GetX(),m_vHeight.GetY()),m_fWaterLevel)-SWIM_DEPTH);
	endproc;

	export proc void WaterToLand()
		m_vHeight.SetZ(Math.Max(CSrvWrap.GetScapeMgr().GetHeight(m_vHeight.GetX(),m_vHeight.GetY()),m_fWaterLevel));
	endproc;	
	
	export proc ref CFourCC GetWalkSet()
		return m_xWalkSet;
	endproc;
		
	export proc string EatAnim()
		if(IsInWater())then
			return "attack_front";
		else
			return "feeding";
		endif;
	endproc;
	
	export proc bool IsBugged()
		if(IsInWater())then
			return true;
		endif;
		return m_bBugged;
	endproc;
	
	export proc string GetVictoryAnim()
		var string sAnim="menace";
		var int iR=Random.GetInt()%3;
		if(iR==1)then
			sAnim="shake";
		elseif(iR==2)then
			sAnim="scratch";
		endif;
		return sAnim;
	endproc;
	
endclass;
I tried to use some modified lines from the flying unit classes in the MIRAGE mod, but set to reduce rather than raise the Z position. Unfortunately the Spinosaurus still walk on the water like they were Jesus rather than being thigh-deep in it as intended.

I'm trying to figure out what I did wrong or if I missed something. Any assistance would be appreciated.
User avatar
Scrat
- Mod -
Posts: 14223
Joined: Sat Jul 14, 2007 14:44 pm
Location: Bamberg / Budapest
Contact:

Re: Lowering unit elevation below ground/water level

Post by Scrat »

good question. Did you base your custom code on the code of Baryonyx?

Maybe as another experiment, change the wild Baryonyx' code so that the Baryonyx model is replaced with that of Spinosaurus, and see how the game deals with the modified 'Baryonyx'. If the game doesn't crash, changing the spinos code in the appropriate way should work too.
Post Reply

Return to “English”