Better autopilot, guiframe tweaking, fixed ui scaling, aicontroller bugfixes, human walk/run anim uses HandIK
This commit is contained in:
@@ -207,11 +207,16 @@ namespace Subsurface.Items.Components
|
||||
statusEffects.Add(StatusEffect.Load(subElement));
|
||||
break;
|
||||
case "guiframe":
|
||||
string rectStr = ToolBox.GetAttributeString(subElement, "rect", "0.0,0.0,0.5,0.5");
|
||||
|
||||
string[] components = rectStr.Split(',');
|
||||
if (components.Length < 4) continue;
|
||||
|
||||
Vector4 rect = ToolBox.GetAttributeVector4(subElement, "rect", Vector4.One);
|
||||
rect.X *= GameMain.GraphicsWidth;
|
||||
rect.Y *= GameMain.GraphicsHeight;
|
||||
rect.Z *= GameMain.GraphicsWidth;
|
||||
rect.W *= GameMain.GraphicsHeight;
|
||||
if (components[0].Contains(".")) rect.X *= GameMain.GraphicsWidth;
|
||||
if (components[1].Contains(".")) rect.Y *= GameMain.GraphicsHeight;
|
||||
if (components[2].Contains(".")) rect.Z *= GameMain.GraphicsWidth;
|
||||
if (components[3].Contains(".")) rect.W *= GameMain.GraphicsHeight;
|
||||
|
||||
Vector4 color = ToolBox.GetAttributeVector4(subElement, "color", Vector4.One);
|
||||
|
||||
@@ -228,7 +233,7 @@ namespace Subsurface.Items.Components
|
||||
|
||||
guiFrame = new GUIFrame(
|
||||
new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Z, (int)rect.W),
|
||||
new Color(color.X, color.Y, color.Z, color.W), alignment, GUI.Style);
|
||||
new Color(color.X, color.Y, color.Z) * color.W, alignment, GUI.Style);
|
||||
//guiFrame.Alpha = color.W;
|
||||
|
||||
break;
|
||||
|
||||
@@ -172,6 +172,31 @@ namespace Subsurface.Items.Components
|
||||
quest.RadarPosition, displayScale, center, (rect.Width * 0.55f));
|
||||
}
|
||||
}
|
||||
|
||||
if (!GameMain.DebugDraw) return;
|
||||
|
||||
var steering = item.GetComponent<Steering>();
|
||||
if (steering == null || steering.SteeringPath == null) return;
|
||||
|
||||
Vector2 prevPos = Vector2.Zero;
|
||||
|
||||
foreach (WayPoint wp in steering.SteeringPath.Nodes)
|
||||
{
|
||||
Vector2 pos = (wp.Position - Submarine.Loaded.Position) * displayScale;
|
||||
if (pos.Length() > radius) continue;
|
||||
|
||||
pos.Y = -pos.Y;
|
||||
pos += center;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X -3 / 2, (int)pos.Y - 3, 6, 6), (steering.SteeringPath.CurrentNode==wp) ? Color.LightGreen : Color.Green, false);
|
||||
|
||||
if (prevPos!=Vector2.Zero)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch, pos, prevPos, Color.Green);
|
||||
}
|
||||
|
||||
prevPos = pos;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawMarker(SpriteBatch spriteBatch, string label, Vector2 position, float scale, Vector2 center, float radius)
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
class Steering : Powered
|
||||
{
|
||||
private const float AutopilotRayCastInterval = 5.0f;
|
||||
|
||||
private Vector2 currVelocity;
|
||||
private Vector2 targetVelocity;
|
||||
|
||||
@@ -24,6 +26,8 @@ namespace Subsurface.Items.Components
|
||||
private float networkUpdateTimer;
|
||||
private bool valueChanged;
|
||||
|
||||
private float autopilotRayCastTimer;
|
||||
|
||||
bool AutoPilot
|
||||
{
|
||||
get { return autoPilot; }
|
||||
@@ -37,7 +41,7 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false);
|
||||
steeringPath = pathFinder.FindPath(
|
||||
ConvertUnits.ToSimUnits(Level.Loaded.Position),
|
||||
ConvertUnits.ToSimUnits(Submarine.Loaded.Position),
|
||||
ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
|
||||
}
|
||||
}
|
||||
@@ -59,6 +63,11 @@ namespace Subsurface.Items.Components
|
||||
get { return targetVelocity; }
|
||||
}
|
||||
|
||||
public SteeringPath SteeringPath
|
||||
{
|
||||
get { return steeringPath; }
|
||||
}
|
||||
|
||||
public Steering(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
@@ -81,21 +90,7 @@ namespace Subsurface.Items.Components
|
||||
// ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
|
||||
//}
|
||||
|
||||
steeringPath.GetNode(Vector2.Zero, 20.0f);
|
||||
|
||||
if (steeringPath.CurrentNode!=null)
|
||||
{
|
||||
float prediction = 10.0f;
|
||||
|
||||
Vector2 futurePosition = Submarine.Loaded.Speed * prediction;
|
||||
|
||||
Vector2 targetSpeed = (steeringPath.CurrentNode.Position - futurePosition);
|
||||
|
||||
//float dist = targetSpeed.Length();
|
||||
targetSpeed = Vector2.Normalize(targetSpeed);
|
||||
|
||||
TargetVelocity = targetSpeed*100.0f;
|
||||
}
|
||||
UpdateAutoPilot(deltaTime);
|
||||
}
|
||||
else if (valueChanged)
|
||||
{
|
||||
@@ -160,6 +155,51 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAutoPilot(float deltaTime)
|
||||
{
|
||||
autopilotRayCastTimer -= deltaTime;
|
||||
|
||||
steeringPath.CheckProgress(ConvertUnits.ToSimUnits(Submarine.Loaded.Position), 10.0f);
|
||||
|
||||
if (autopilotRayCastTimer<=0.0f && steeringPath.NextNode != null)
|
||||
{
|
||||
Vector2 diff = steeringPath.NextNode.Position - Submarine.Loaded.Position;
|
||||
|
||||
bool nextVisible = true;
|
||||
for (int x = -1; x < 2; x += 2)
|
||||
{
|
||||
for (int y = -1; y < 2; y += 2)
|
||||
{
|
||||
Vector2 cornerPos =
|
||||
new Vector2(Submarine.Borders.Width * x, Submarine.Borders.Height * y) / 2.0f;
|
||||
|
||||
cornerPos = ConvertUnits.ToSimUnits(cornerPos*1.2f);
|
||||
|
||||
if (Submarine.PickBody(cornerPos, cornerPos + diff, null, Physics.CollisionLevel) == null) continue;
|
||||
|
||||
nextVisible = false;
|
||||
x = 2;
|
||||
y = 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (nextVisible) steeringPath.SkipToNextNode();
|
||||
|
||||
autopilotRayCastTimer = AutopilotRayCastInterval;
|
||||
}
|
||||
|
||||
if (steeringPath.CurrentNode != null)
|
||||
{
|
||||
float prediction = 5.0f;
|
||||
|
||||
Vector2 futurePosition = Submarine.Loaded.Speed * prediction;
|
||||
Vector2 targetSpeed = ((steeringPath.CurrentNode.Position - Submarine.Loaded.Position) - futurePosition);
|
||||
|
||||
targetSpeed = Vector2.Normalize(targetSpeed);
|
||||
TargetVelocity = targetSpeed * 100.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||
{
|
||||
if (connection.Name == "velocity_in")
|
||||
|
||||
@@ -184,24 +184,24 @@ namespace Subsurface.Items.Components
|
||||
|
||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||
{
|
||||
int width = 300, height = 200;
|
||||
int x = GameMain.GraphicsWidth / 2 - width / 2;
|
||||
int y = GameMain.GraphicsHeight / 2 - height / 2;
|
||||
GuiFrame.Draw(spriteBatch);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
|
||||
int x = GuiFrame.Rect.X;
|
||||
int y = GuiFrame.Rect.Y;
|
||||
//GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
|
||||
|
||||
spriteBatch.DrawString(GUI.Font,
|
||||
"Charge: " + (int)charge + "/" + (int)capacity + " (" + (int)((charge / capacity) * 100.0f) + " %)",
|
||||
new Vector2(x + 30, y + 30), Color.White);
|
||||
|
||||
spriteBatch.DrawString(GUI.Font, "Recharge rate: " + (rechargeSpeed / maxRechargeSpeed), new Vector2(x + 30, y + 100), Color.White);
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 50, y + 150, 40, 40), "+"))
|
||||
spriteBatch.DrawString(GUI.Font, "Recharge rate: " + (int)((rechargeSpeed / maxRechargeSpeed)*100.0f)+" %", new Vector2(x + 30, y + 100), Color.White);
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 90, 40, 40), "+"))
|
||||
{
|
||||
rechargeSpeed = Math.Min(rechargeSpeed + maxRechargeSpeed*0.1f, maxRechargeSpeed);
|
||||
item.NewComponentEvent(this, true);
|
||||
}
|
||||
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 150, 40, 40), "-"))
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 90, 40, 40), "-"))
|
||||
{
|
||||
rechargeSpeed = Math.Max(rechargeSpeed - maxRechargeSpeed * 0.1f, 0.0f);
|
||||
item.NewComponentEvent(this, true);
|
||||
|
||||
@@ -146,8 +146,6 @@ namespace Subsurface.Items.Components
|
||||
|
||||
GuiFrame.Draw(spriteBatch);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
|
||||
|
||||
spriteBatch.DrawString(GUI.Font, "Power: " + (int)(-currPowerConsumption), new Vector2(x + 30, y + 30), Color.White);
|
||||
spriteBatch.DrawString(GUI.Font, "Load: " + (int)powerLoad, new Vector2(x + 30, y + 100), Color.White);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace Subsurface.Items.Components
|
||||
Limb limb;
|
||||
Structure structure;
|
||||
if ((limb = (f2.Body.UserData as Limb)) != null)
|
||||
{
|
||||
{
|
||||
attackResult = attack.DoDamage(null, limb.character, item.SimPosition, 1.0f);
|
||||
}
|
||||
else if ((structure = (f2.Body.UserData as Structure)) != null)
|
||||
|
||||
Reference in New Issue
Block a user