mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 13:23:56 -07:00
Add float depth support to cmpPosition.
This allows for amphibious units (swimming animals, tanks, etc). The specified depth is the distance from the water surface where the unit will start to float. Should most likely be a little less than the height of the actor. Reviewed By: fatherbushido Differential Revision: https://code.wildfiregames.com/D842 This was SVN commit r20196.
This commit is contained in:
parent
fd034c9bcd
commit
38cca12ec6
24 changed files with 39 additions and 5 deletions
|
|
@ -4,6 +4,7 @@
|
|||
<Altitude>0</Altitude>
|
||||
<Anchor>upright</Anchor>
|
||||
<Floating>false</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
<TurnRate>1.0</TurnRate>
|
||||
</Position>
|
||||
<UnitAI>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
<Position>
|
||||
<Altitude>-1</Altitude>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
<TurnRate>5.0</TurnRate>
|
||||
</Position>
|
||||
<Selectable>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
</Obstruction>
|
||||
<Position>
|
||||
<Floating>false</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ResourceSupply>
|
||||
<Amount>200</Amount>
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
<Position>
|
||||
<TurnRate>1.0</TurnRate>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<Repairable>
|
||||
<RepairTimeRatio>3.0</RepairTimeRatio>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
</Obstruction>
|
||||
<Position>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ResourceSupply>
|
||||
<Amount>500</Amount>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
<Position>
|
||||
<Altitude>-0.1</Altitude>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ResourceSupply>
|
||||
<Amount>200</Amount>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
</Obstruction>
|
||||
<Position>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ResourceSupply>
|
||||
<Amount>550</Amount>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
</Obstruction>
|
||||
<Position>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ResourceSupply>
|
||||
<Amount>400</Amount>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
</Obstruction>
|
||||
<Position>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ResourceSupply>
|
||||
<Amount>450</Amount>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
<Altitude>0</Altitude>
|
||||
<Anchor>upright</Anchor>
|
||||
<Floating>false</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
<TurnRate>6.0</TurnRate>
|
||||
</Position>
|
||||
<Selectable>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<Altitude>0</Altitude>
|
||||
<Anchor>upright</Anchor>
|
||||
<Floating>false</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
<TurnRate>6.0</TurnRate>
|
||||
</Position>
|
||||
<Visibility>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
</Obstruction>
|
||||
<Position>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ProductionQueue>
|
||||
<Entities datatype="tokens">
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@
|
|||
</Obstruction>
|
||||
<Position>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ProductionQueue>
|
||||
<BatchTimeModifier>0.7</BatchTimeModifier>
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
</Obstruction>
|
||||
<Position>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ProductionQueue disable=""/>
|
||||
<Sound>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
<Altitude>0</Altitude>
|
||||
<Anchor>upright</Anchor>
|
||||
<Floating>false</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
<TurnRate>6.0</TurnRate>
|
||||
</Position>
|
||||
<Selectable/>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
<Altitude>0</Altitude>
|
||||
<Anchor>upright</Anchor>
|
||||
<Floating>false</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
<TurnRate>6.0</TurnRate>
|
||||
</Position>
|
||||
<Selectable>
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
<Altitude>0</Altitude>
|
||||
<Anchor>upright</Anchor>
|
||||
<Floating>false</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
<TurnRate>3.0</TurnRate>
|
||||
</Position>
|
||||
<Trader>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
<Altitude>0</Altitude>
|
||||
<Anchor>upright</Anchor>
|
||||
<Floating>false</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
<TurnRate>6.0</TurnRate>
|
||||
</Position>
|
||||
<Visibility>
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
</Obstruction>
|
||||
<Position>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ProductionQueue>
|
||||
<BatchTimeModifier>0.8</BatchTimeModifier>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
<Altitude>0</Altitude>
|
||||
<Anchor>upright</Anchor>
|
||||
<Floating>false</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
<TurnRate>6.0</TurnRate>
|
||||
</Position>
|
||||
<Selectable>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
<Position>
|
||||
<Altitude>-2.0</Altitude>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>false</KillBeforeGather>
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
</Obstruction>
|
||||
<Position>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
</Position>
|
||||
<ResourceSupply>
|
||||
<KillBeforeGather>true</KillBeforeGather>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
</Identity>
|
||||
<Position>
|
||||
<Floating>true</Floating>
|
||||
<FloatDepth>0.0</FloatDepth>
|
||||
<TurnRate>3.0</TurnRate>
|
||||
</Position>
|
||||
<ResourceGatherer>
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ public:
|
|||
} m_AnchorType;
|
||||
|
||||
bool m_Floating;
|
||||
entity_pos_t m_FloatDepth;
|
||||
|
||||
float m_RotYSpeed; // maximum radians per second, used by InterpolatedRotY to follow RotY
|
||||
|
||||
// Dynamic state:
|
||||
|
|
@ -107,6 +109,7 @@ public:
|
|||
"<Anchor>upright</Anchor>"
|
||||
"<Altitude>0.0</Altitude>"
|
||||
"<Floating>false</Floating>"
|
||||
"<FloatDepth>0.0</FloatDepth>"
|
||||
"<TurnRate>6.0</TurnRate>"
|
||||
"</a:example>"
|
||||
"<element name='Anchor' a:help='Automatic rotation to follow the slope of terrain'>"
|
||||
|
|
@ -123,6 +126,9 @@ public:
|
|||
"<element name='Floating' a:help='Whether the entity floats on water'>"
|
||||
"<data type='boolean'/>"
|
||||
"</element>"
|
||||
"<element name='FloatDepth' a:help='The depth at which an entity floats on water (needs Floating to be true)'>"
|
||||
"<ref name='nonNegativeDecimal'/>"
|
||||
"</element>"
|
||||
"<element name='TurnRate' a:help='Maximum graphical rotation speed around Y axis, in radians per second'>"
|
||||
"<ref name='positiveDecimal'/>"
|
||||
"</element>";
|
||||
|
|
@ -146,6 +152,7 @@ public:
|
|||
m_Y = paramNode.GetChild("Altitude").ToFixed();
|
||||
m_RelativeToGround = true;
|
||||
m_Floating = paramNode.GetChild("Floating").ToBool();
|
||||
m_FloatDepth = paramNode.GetChild("FloatDepth").ToFixed();
|
||||
|
||||
m_RotYSpeed = paramNode.GetChild("TurnRate").ToFixed().ToFloat();
|
||||
|
||||
|
|
@ -185,6 +192,7 @@ public:
|
|||
serialize.NumberFixed_Unbounded("altitude", m_Y);
|
||||
serialize.Bool("relative", m_RelativeToGround);
|
||||
serialize.Bool("floating", m_Floating);
|
||||
serialize.NumberFixed_Unbounded("float depth", m_FloatDepth);
|
||||
serialize.NumberFixed_Unbounded("constructionprogress", m_ConstructionProgress);
|
||||
|
||||
if (serialize.IsDebug())
|
||||
|
|
@ -241,6 +249,7 @@ public:
|
|||
deserialize.NumberFixed_Unbounded("altitude", m_Y);
|
||||
deserialize.Bool("relative", m_RelativeToGround);
|
||||
deserialize.Bool("floating", m_Floating);
|
||||
deserialize.NumberFixed_Unbounded("float depth", m_FloatDepth);
|
||||
deserialize.NumberFixed_Unbounded("constructionprogress", m_ConstructionProgress);
|
||||
// TODO: should there be range checks on all these values?
|
||||
|
||||
|
|
@ -401,6 +410,7 @@ public:
|
|||
if (m_RelativeToGround)
|
||||
return m_Y;
|
||||
// not relative to the ground, so the height offset is m_Y - ground height
|
||||
// except when floating, when the height offset is m_Y - water level + float depth
|
||||
entity_pos_t baseY;
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(GetSystemEntity());
|
||||
if (cmpTerrain)
|
||||
|
|
@ -410,7 +420,7 @@ public:
|
|||
{
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(GetSystemEntity());
|
||||
if (cmpWaterManager)
|
||||
baseY = std::max(baseY, cmpWaterManager->GetWaterLevel(m_X, m_Z));
|
||||
baseY = std::max(baseY, cmpWaterManager->GetWaterLevel(m_X, m_Z) - m_FloatDepth);
|
||||
}
|
||||
return m_Y - baseY;
|
||||
}
|
||||
|
|
@ -428,6 +438,7 @@ public:
|
|||
if (!m_RelativeToGround)
|
||||
return m_Y;
|
||||
// relative to the ground, so the fixed height = ground height + m_Y
|
||||
// except when floating, when the fixed height = water level - float depth + m_Y
|
||||
entity_pos_t baseY;
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(GetSystemEntity());
|
||||
if (cmpTerrain)
|
||||
|
|
@ -437,7 +448,7 @@ public:
|
|||
{
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(GetSystemEntity());
|
||||
if (cmpWaterManager)
|
||||
baseY = std::max(baseY, cmpWaterManager->GetWaterLevel(m_X, m_Z));
|
||||
baseY = std::max(baseY, cmpWaterManager->GetWaterLevel(m_X, m_Z) - m_FloatDepth);
|
||||
}
|
||||
return m_Y + baseY;
|
||||
}
|
||||
|
|
@ -692,7 +703,7 @@ public:
|
|||
{
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(GetSystemEntity());
|
||||
if (cmpWaterManager)
|
||||
baseY = std::max(baseY, cmpWaterManager->GetExactWaterLevel(x, z));
|
||||
baseY = std::max(baseY, cmpWaterManager->GetExactWaterLevel(x, z) - m_FloatDepth.ToFloat());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -737,8 +748,8 @@ public:
|
|||
CmpPtr<ICmpWaterManager> cmpWaterManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpWaterManager)
|
||||
{
|
||||
baseY0 = std::max(baseY0, cmpWaterManager->GetExactWaterLevel(x0, z0));
|
||||
baseY1 = std::max(baseY1, cmpWaterManager->GetExactWaterLevel(x1, z1));
|
||||
baseY0 = std::max(baseY0, cmpWaterManager->GetExactWaterLevel(x0, z0) - m_FloatDepth.ToFloat());
|
||||
baseY1 = std::max(baseY1, cmpWaterManager->GetExactWaterLevel(x1, z1) - m_FloatDepth.ToFloat());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue