A* pathfinding, autopilot, WIP radar rendering, proper location names, character skills shown in menus, got rid of PreviewCharacter, mantis

This commit is contained in:
Regalis
2015-07-14 21:09:00 +03:00
parent a2636133ca
commit 44b9a63c94
51 changed files with 1971 additions and 940 deletions
@@ -57,6 +57,8 @@ namespace Subsurface.Items.Components
isActive = true;
reload = 1.0f;
bool failed = UseFailed(character);
List<Body> limbBodies = new List<Body>();
foreach (Limb l in character.AnimController.limbs)
{
@@ -75,18 +77,44 @@ namespace Subsurface.Items.Components
Projectile projectileComponent= projectile.GetComponent<Projectile>();
if (projectileComponent == null) continue;
projectileComponent.ignoredBodies = limbBodies;
projectile.body.ResetDynamics();
projectile.SetTransform(TransformedBarrelPos,
(item.body.Dir == 1.0f) ? item.body.Rotation : item.body.Rotation - MathHelper.Pi);
projectile.Use(deltaTime);
if (failed)
{
Vector2 modifiedVelocity = projectile.body.LinearVelocity;
modifiedVelocity.X *= Rand.Range(0.0f, 0.5f);
modifiedVelocity.Y *= Rand.Range(0.0f, 0.5f);
projectile.body.LinearVelocity = modifiedVelocity;
projectile.body.ApplyTorque(projectile.body.Mass * Rand.Range(-10.0f, 10.0f));
//recoil
item.body.ApplyLinearImpulse(
new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * item.body.Mass * -10.0f);
if (Rand.Int(2) == 0)
{
item.Drop(character);
item.body.ApplyTorque(projectile.body.Mass * Rand.Range(-10.0f, 10.0f));
}
}
else
{
projectileComponent.ignoredBodies = limbBodies;
//recoil
item.body.ApplyLinearImpulse(
new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * -item.body.Mass);
}
item.RemoveContained(projectile);
//recoil
item.body.ApplyLinearImpulse(
new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * item.body.Mass);
Rope rope = item.GetComponent<Rope>();
if (rope != null) rope.Attach(projectile);
+36 -2
View File
@@ -52,6 +52,8 @@ namespace Subsurface
public List<RelatedItem> requiredItems;
public List<Skill> requiredSkills;
private List<ItemSound> sounds;
private GUIFrame guiFrame;
@@ -133,6 +135,8 @@ namespace Subsurface
requiredItems = new List<RelatedItem>();
requiredSkills = new List<Skill>();
sounds = new List<ItemSound>();
statusEffects = new List<StatusEffect>();
@@ -165,6 +169,12 @@ namespace Subsurface
RelatedItem ri = RelatedItem.Load(subElement);
if (ri != null) requiredItems.Add(ri);
break;
case "requiredskill":
case "requiredskills":
string skillName = ToolBox.GetAttributeString(subElement, "name", "");
requiredSkills.Add(new Skill(skillName, ToolBox.GetAttributeInt(subElement, "level", 0)));
break;
case "statuseffect":
statusEffects.Add(StatusEffect.Load(subElement));
break;
@@ -340,6 +350,30 @@ namespace Subsurface
}
}
public bool HasRequiredSkills(Character character)
{
foreach (Skill skill in requiredSkills)
{
int characterLevel = character.GetSkillLevel(skill.Name);
if (characterLevel < skill.Level) return false;
}
return true;
}
protected bool UseFailed(Character character)
{
foreach (Skill skill in requiredSkills)
{
int characterLevel = character.GetSkillLevel(skill.Name);
if (characterLevel > skill.Level) continue;
if (Rand.Int(characterLevel) - skill.Level < 0) return true;
}
return false;
}
public bool HasRequiredContainedItems(bool addMessage)
{
if (!requiredItems.Any()) return true;
@@ -367,7 +401,7 @@ namespace Subsurface
foreach (RelatedItem ri in requiredItems)
{
if (ri.Type == RelatedItem.RelationType.Equipped)
if (ri.Type.HasFlag(RelatedItem.RelationType.Equipped))
{
for (int i = 0; i < character.SelectedItems.Length; i++ )
{
@@ -381,7 +415,7 @@ namespace Subsurface
//if (addMessage && !String.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
return false;
}
else if (ri.Type == RelatedItem.RelationType.Picked)
else if (ri.Type.HasFlag(RelatedItem.RelationType.Picked))
{
Item pickedItem = character.Inventory.items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x));
if (pickedItem == null)
@@ -30,7 +30,7 @@ namespace Subsurface.Items.Components
}
}
[Editable, HasDefaultValue(500.0f, true)]
[Editable, HasDefaultValue(2000.0f, true)]
public float MaxForce
{
get { return maxForce; }
+2 -2
View File
@@ -163,7 +163,7 @@ namespace Subsurface.Items.Components
else if (connection.Name == "set_speed")
{
float tempSpeed;
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempSpeed))
if (float.TryParse(signal, NumberStyles.Any, CultureInfo.InvariantCulture, out tempSpeed))
{
flowPercentage = MathHelper.Clamp(tempSpeed, -100.0f, 100.0f);
}
@@ -171,7 +171,7 @@ namespace Subsurface.Items.Components
else if (connection.Name == "set_targetlevel")
{
float tempTarget;
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempTarget))
if (float.TryParse(signal, NumberStyles.Any, CultureInfo.InvariantCulture, out tempTarget))
{
targetLevel = MathHelper.Clamp(tempTarget, 0.0f, 100.0f);
}
+62 -13
View File
@@ -15,8 +15,12 @@ namespace Subsurface.Items.Components
float angle;
float pingState;
//RenderTarget2D renderTarget;
Sprite pingCircle, screenOverlay;
[HasDefaultValue(0.0f, false)]
public float Range
{
@@ -27,6 +31,19 @@ namespace Subsurface.Items.Components
public Radar(Item item, XElement element)
: base(item, element)
{
foreach (XElement subElement in element.Elements())
{
switch (subElement.Name.ToString().ToLower())
{
case "pingcircle":
pingCircle = new Sprite(subElement);
break;
case "screenoverlay":
screenOverlay = new Sprite(subElement);
break;
}
}
//renderTarget = new RenderTarget2D(Game1.CurrGraphicsDevice, GuiFrame.Rect.Width, GuiFrame.Rect.Height);
}
@@ -34,6 +51,9 @@ namespace Subsurface.Items.Components
{
base.Update(deltaTime, cam);
pingState = (pingState + deltaTime * 0.5f) % 1.0f;
angle = (angle + deltaTime) % MathHelper.TwoPi;
}
@@ -42,38 +62,67 @@ namespace Subsurface.Items.Components
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
int x = GuiFrame.Rect.X;
int y = GuiFrame.Rect.Y;
GuiFrame.Draw(spriteBatch);
if (GUI.DrawButton(spriteBatch, new Rectangle(x+20, y+20, 200, 30), "Activate Radar")) isActive = !isActive;
Vector2 lineEnd = GuiFrame.Center;
lineEnd += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))*Math.Min(width,height)/2.0f;
GUI.DrawLine(spriteBatch, GuiFrame.Center, lineEnd, Color.Green);
int radius = GuiFrame.Rect.Height / 2 - 10;
DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2));
}
if (!isActive) return;
private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect)
{
float scale = 0.01f;
Vector2 center = new Vector2(rect.Center.X, rect.Center.Y);
//lineEnd += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Math.Min(width, height) / 2.0f;
//GUI.DrawLine(spriteBatch, GuiFrame.Center, lineEnd, Color.Green);
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.Position, 5);
if (!isActive || Level.Loaded == null) return;
if (pingCircle!=null)
{
pingCircle.Draw(spriteBatch, center, Color.White * (1.0f-pingState), 0.0f, (rect.Width/pingCircle.size.X)*pingState);
}
float scale = 0.015f;
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.Position, 7);
Vector2 offset = Vector2.Zero;
for (int i = 0; i < edges.Count; i++)
{
GUI.DrawLine(spriteBatch,
GuiFrame.Center + (edges[i][0] - offset) * scale,
GuiFrame.Center + (edges[i][1] - offset) * scale, Color.Green);
center + (edges[i][0] - offset) * scale,
center + (edges[i][1] - offset) * scale, Color.White);
}
scale = ConvertUnits.ToDisplayUnits(scale);
for (int i = 0; i< Submarine.Loaded.HullVertices.Count; i++)
for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++)
{
Vector2 start =Submarine.Loaded.HullVertices[i] * scale;
Vector2 start = Submarine.Loaded.HullVertices[i] * scale;
start.Y = -start.Y;
Vector2 end = Submarine.Loaded.HullVertices[(i+1)%Submarine.Loaded.HullVertices.Count] * scale;
Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * scale;
end.Y = -end.Y;
GUI.DrawLine(spriteBatch, GuiFrame.Center + start,GuiFrame.Center + end, Color.Green);
GUI.DrawLine(spriteBatch, center + start, center + end, Color.White);
}
foreach (Character c in Character.CharacterList)
{
if (c.AnimController.CurrentHull != null) continue;
if (c.SimPosition!=Vector2.Zero && c.SimPosition.Length() < 7*Level.GridCellWidth)
{
int width = (int)c.Mass/5;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)c.Position.X - width / 2, (int)c.Position.Y - width / 2, width, width), Color.White);
}
}
if (screenOverlay!=null)
{
screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width/screenOverlay.size.X);
}
}
@@ -1,7 +1,9 @@
using Microsoft.Xna.Framework;
using FarseerPhysics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Xml.Linq;
@@ -13,18 +15,69 @@ namespace Subsurface.Items.Components
Vector2 currVelocity;
Vector2 targetVelocity;
bool autoPilot;
SteeringPath steeringPath;
private Vector2 TargetVelocity
{
get { return targetVelocity;}
set
{
targetVelocity.X = MathHelper.Clamp(value.X, -100.0f, 100.0f);
targetVelocity.Y = MathHelper.Clamp(value.Y, -100.0f, 100.0f);
}
}
public Steering(Item item, XElement element)
: base(item, element)
{
isActive = true;
}
public override void OnMapLoaded()
{
PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(Level.Loaded.StartPosition),
ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
}
public override void Update(float deltaTime, Camera cam)
{
base.Update(deltaTime, cam);
item.SendSignal(targetVelocity.X.ToString(), "velocity_x_out");
item.SendSignal((-targetVelocity.Y).ToString(), "velocity_y_out");
if (autoPilot || true)
{
steeringPath.GetNode(Vector2.Zero, 5.0f);
if (steeringPath.CurrentNode!=null)
{
Vector2 targetSpeed = steeringPath.CurrentNode.Position;
float dist = targetSpeed.Length();
targetSpeed = Vector2.Normalize(targetSpeed);
if (dist<2000.0f)
{
targetSpeed = targetSpeed * Math.Max(dist / 2000.0f, 0.5f);
}
Vector2 currSpeed = (Submarine.Loaded.Speed == Vector2.Zero) ? Vector2.Zero : Vector2.Normalize(Submarine.Loaded.Speed);
//targetSpeed.X = (targetSpeed.X - currSpeed.X);
//targetSpeed.Y = (targetSpeed.Y - currSpeed.Y);
//TargetVelocity += targetSpeed;
TargetVelocity += (targetSpeed-currSpeed);
}
}
item.SendSignal(targetVelocity.X.ToString(CultureInfo.InvariantCulture), "velocity_x_out");
item.SendSignal((-targetVelocity.Y).ToString(CultureInfo.InvariantCulture), "velocity_y_out");
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
@@ -52,7 +105,7 @@ namespace Subsurface.Items.Components
GUI.DrawRectangle(spriteBatch, new Rectangle((int)targetVelPos.X - 5, (int)targetVelPos.Y - 5, 10, 10), Color.White);
if (Vector2.Distance(PlayerInput.MousePosition, targetVelPos)<10.0f)
if (Vector2.Distance(PlayerInput.MousePosition, new Vector2(velRect.Center.X, velRect.Center.Y)) < 200.0f)
{
GUI.DrawRectangle(spriteBatch, new Rectangle((int)targetVelPos.X -10, (int)targetVelPos.Y - 10, 20, 20), Color.Red);
@@ -82,8 +135,18 @@ namespace Subsurface.Items.Components
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
{
targetVelocity.X = message.ReadFloat();
targetVelocity.Y = message.ReadFloat();
Vector2 newTargetVelocity = Vector2.Zero;
try
{
newTargetVelocity = new Vector2(message.ReadFloat(), message.ReadFloat());
}
catch
{
return;
}
TargetVelocity = newTargetVelocity;
}
}
}
+2 -2
View File
@@ -84,8 +84,8 @@ namespace Subsurface.Items.Components
Debug.WriteLine(item.body.Rotation);
Launch(new Vector2(
(float)Math.Cos(item.body.Rotation),
(float)Math.Sin(item.body.Rotation))*launchImpulse*item.body.Mass);
(float)Math.Cos(item.body.Rotation),
(float)Math.Sin(item.body.Rotation)) * launchImpulse * item.body.Mass);
return true;
}