List of previously used mapentities in editor, waypoint sprites, properly generating waypoints for hatches, waypoint paths are saved in editor instead of generating them on loading, gap particle bugfix, separate waypoint and spawnpoint prefabs, turret rotation limits visible in editor, hatch convexhull fix, new railgunloader sprite

This commit is contained in:
Regalis
2016-01-17 15:45:16 +02:00
parent 8e491ae855
commit 5f1cb194ab
20 changed files with 316 additions and 106 deletions

View File

@@ -67,7 +67,7 @@ namespace Barotrauma
}
}
public Gap(Rectangle rectangle)
public Gap(MapEntityPrefab prefab, Rectangle rectangle)
: this (rectangle, Submarine.Loaded)
{ }
@@ -225,7 +225,6 @@ namespace Barotrauma
soundIndex = SoundPlayer.flowSounds[index].Loop(soundIndex, soundVolume, WorldPosition, 2000.0f);
flowForce = Vector2.Zero;
lerpedFlowForce = Vector2.Lerp(lerpedFlowForce, flowForce, 0.05f);
if (open == 0.0f) return;
@@ -242,7 +241,9 @@ namespace Barotrauma
UpdateRoomToRoom(deltaTime);
}
if (LerpedFlowForce.Length() > 150.0f && flowTargetHull != null && flowTargetHull.Volume < flowTargetHull.FullVolume)
lerpedFlowForce = Vector2.Lerp(lerpedFlowForce, flowForce, deltaTime*2.0f);
if (LerpedFlowForce.Length() > 100.0f && flowTargetHull != null && flowTargetHull.Volume < flowTargetHull.FullVolume)
{
//UpdateFlowForce();
@@ -256,8 +257,10 @@ namespace Barotrauma
MathHelper.Clamp(flowForce.X, -5000.0f, 5000.0f) * Rand.Range(0.5f, 0.7f),
flowForce.Y * Rand.Range(0.5f, 0.7f));
var particle = GameMain.ParticleManager.CreateParticle("watersplash",
new Vector2(pos.X, pos.Y - Rand.Range(0.0f, 10.0f)), velocity);
var particle = GameMain.ParticleManager.CreateParticle(
"watersplash",
(Submarine.Loaded==null ? pos : pos + Submarine.Loaded.Position) - Vector2.UnitY * Rand.Range(0.0f, 10.0f),
velocity);
if (particle != null)
{
@@ -266,7 +269,10 @@ namespace Barotrauma
pos.Y = Rand.Range(lowerSurface, rect.Y - rect.Height);
GameMain.ParticleManager.CreateParticle("bubbles", pos, flowForce / 200.0f);
GameMain.ParticleManager.CreateParticle(
"bubbles",
Submarine.Loaded==null ? pos : pos + Submarine.Loaded.Position,
flowForce / 200.0f);
}
else
{
@@ -278,13 +284,18 @@ namespace Barotrauma
Vector2 velocity = new Vector2(
flowForce.X * Rand.Range(0.5f, 0.7f),
Math.Max(flowForce.Y,-100.0f) * Rand.Range(0.5f, 0.7f));
var splash = GameMain.ParticleManager.CreateParticle("watersplash", pos,
var splash = GameMain.ParticleManager.CreateParticle(
"watersplash",
Submarine.Loaded == null ? pos : pos + Submarine.Loaded.Position,
velocity);
if (splash != null) splash.Size = splash.Size * MathHelper.Clamp(rect.Width / 50.0f, 0.8f, 4.0f);
GameMain.ParticleManager.CreateParticle("bubbles", pos, flowForce / 2.0f);
GameMain.ParticleManager.CreateParticle(
"bubbles",
Submarine.Loaded == null ? pos : pos + Submarine.Loaded.Position,
flowForce / 2.0f);
}
}

View File

@@ -136,7 +136,7 @@ namespace Barotrauma
get { return fireSources; }
}
public Hull(Rectangle rectangle)
public Hull(MapEntityPrefab prefab, Rectangle rectangle)
: this (rectangle, Submarine.Loaded)
{

View File

@@ -89,25 +89,31 @@ namespace Barotrauma
public static void Init()
{
MapEntityPrefab ep = new MapEntityPrefab();
ep.name = "hull";
ep.name = "Hull";
ep.Description = "Hulls determine which parts are considered to be ''inside the sub''. Generally every room should be enclosed by a hull.";
ep.constructor = typeof(Hull).GetConstructor(new Type[] { typeof(Rectangle) });
ep.constructor = typeof(Hull).GetConstructor(new Type[] { typeof(MapEntityPrefab), typeof(Rectangle) });
ep.resizeHorizontal = true;
ep.resizeVertical = true;
list.Add(ep);
ep = new MapEntityPrefab();
ep.name = "gap";
ep.name = "Gap";
ep.Description = "Gaps allow water and air to flow between two hulls. ";
ep.constructor = typeof(Gap).GetConstructor(new Type[] { typeof(Rectangle) });
ep.constructor = typeof(Gap).GetConstructor(new Type[] { typeof(MapEntityPrefab), typeof(Rectangle) });
ep.resizeHorizontal = true;
ep.resizeVertical = true;
list.Add(ep);
ep = new MapEntityPrefab();
ep.name = "waypoint";
ep.constructor = typeof(WayPoint).GetConstructor(new Type[] { typeof(Rectangle) });
ep.name = "Waypoint";
ep.constructor = typeof(WayPoint).GetConstructor(new Type[] { typeof(MapEntityPrefab), typeof(Rectangle) });
list.Add(ep);
ep = new MapEntityPrefab();
ep.name = "Spawnpoint";
ep.constructor = typeof(WayPoint).GetConstructor(new Type[] { typeof(MapEntityPrefab), typeof(Rectangle) });
list.Add(ep);
}
@@ -121,7 +127,7 @@ namespace Barotrauma
GUI.DrawLine(spriteBatch, new Vector2(position.X-GameMain.GraphicsWidth, -position.Y), new Vector2(position.X+GameMain.GraphicsWidth, -position.Y), Color.White);
GUI.DrawLine(spriteBatch, new Vector2(position.X, position.Y - GameMain.GraphicsHeight), new Vector2(position.X, position.Y+GameMain.GraphicsHeight), Color.White);
GUI.DrawLine(spriteBatch, new Vector2(position.X, -(position.Y - GameMain.GraphicsHeight)), new Vector2(position.X, -(position.Y + GameMain.GraphicsHeight)), Color.White);
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) placePosition = position;
}
@@ -138,7 +144,7 @@ namespace Barotrauma
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released)
{
object[] lobject = new object[] { newRect };
object[] lobject = new object[] { this, newRect };
constructor.Invoke(lobject);
placePosition = Vector2.Zero;
selected = null;

View File

@@ -673,7 +673,7 @@ namespace Barotrauma
MapEntity.MapLoaded();
WayPoint.GenerateSubWaypoints();
//WayPoint.GenerateSubWaypoints();
GameMain.LightManager.OnMapLoaded();

View File

@@ -8,17 +8,22 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.ObjectModel;
using Barotrauma.Items.Components;
using FarseerPhysics.Dynamics;
namespace Barotrauma
{
public enum SpawnType { None, Human, Enemy, Cargo, Path };
public enum SpawnType { Path, Human, Enemy, Cargo };
class WayPoint : MapEntity
{
public static List<WayPoint> WayPointList = new List<WayPoint>();
public static bool ShowWayPoints = true, ShowSpawnPoints = true;
private SpawnType spawnType;
private static Texture2D iconTexture;
private const int IconSize = 32;
private static int[] iconIndices = { 3, 0, 1, 2 };
protected SpawnType spawnType;
//characters spawning at the waypoint will be given an ID card with these tags
private string[] idCardTags;
@@ -47,13 +52,13 @@ namespace Barotrauma
set { spawnType = value; }
}
public override string Name
{
get
{
return "WayPoint";
}
}
//public override string Name
//{
// get
// {
// return spawnType == SpawnType.Path ? "WayPoint" : "SpawnPoint";
// }
//}
public string[] IdCardTags
{
@@ -75,9 +80,18 @@ namespace Barotrauma
ConnectedGap = gap;
}
public WayPoint(Rectangle rectangle)
public WayPoint(MapEntityPrefab prefab, Rectangle rectangle)
: this (rectangle, Submarine.Loaded)
{ }
{
if (prefab.Name.Contains("Spawn"))
{
spawnType = SpawnType.Human;
}
else
{
SpawnType = SpawnType.Path;
}
}
public WayPoint(Rectangle newRect, Submarine submarine)
: base (submarine)
@@ -86,6 +100,11 @@ namespace Barotrauma
linkedTo = new ObservableCollection<MapEntity>();
idCardTags = new string[0];
if (iconTexture==null)
{
iconTexture = Sprite.LoadTexture("Content/Map/waypointIcons.png");
}
InsertToList();
WayPointList.Add(this);
@@ -105,19 +124,31 @@ namespace Barotrauma
if (IsHidden()) return;
Rectangle drawRect =
Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height);
//Rectangle drawRect =
// Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height);
Vector2 drawPos = Position;
if (Submarine!=null) drawPos += Submarine.DrawPosition;
drawPos.Y = -drawPos.Y;
Color clr = (isSelected) ? Color.Red : Color.LightGreen;
GUI.DrawRectangle(spriteBatch, new Rectangle(drawRect.X, -drawRect.Y, rect.Width, rect.Height), clr, true);
Color clr = (isSelected) ? Color.Red : Color.White;
if (isHighlighted) clr = Color.DarkRed;
int iconX = iconIndices[(int)spawnType]*IconSize % iconTexture.Width;
int iconY = (int)(Math.Floor(iconIndices[(int)spawnType]*IconSize / (float)iconTexture.Width))*IconSize;
spriteBatch.Draw(iconTexture,
new Rectangle((int)(drawPos.X - IconSize/2), (int)(drawPos.Y - IconSize/2), IconSize, IconSize),
new Rectangle(iconX, iconY, IconSize,IconSize), clr);
//GUI.DrawRectangle(spriteBatch, new Rectangle(drawRect.X, -drawRect.Y, rect.Width, rect.Height), clr, true);
//spriteBatch.DrawString(GUI.SmallFont, Position.ToString(), new Vector2(Position.X, -Position.Y), Color.White);
foreach (MapEntity e in linkedTo)
{
GUI.DrawLine(spriteBatch,
new Vector2(drawRect.X+rect.Width/2.0f, -drawRect.Y+rect.Height/2.0f),
drawPos,
new Vector2(e.DrawPosition.X, -e.DrawPosition.Y),
Color.Green);
}
@@ -167,8 +198,8 @@ namespace Barotrauma
spawnType += (int)button.UserData;
if (spawnType > SpawnType.Cargo) spawnType = SpawnType.None;
if (spawnType < SpawnType.None) spawnType = SpawnType.Enemy;
if (spawnType > SpawnType.Path) spawnType = SpawnType.Human;
if (spawnType < SpawnType.Human) spawnType = SpawnType.Path;
spawnTypeText.Text = spawnType.ToString();
@@ -179,7 +210,7 @@ namespace Barotrauma
{
IdCardTags = text.Split(',');
textBox.Text = text;
textBox.Color = Color.White;
textBox.Color = Color.Green;
return true;
}
@@ -191,7 +222,7 @@ namespace Barotrauma
if (assignedJob !=null && trimmedName!="none")
{
textBox.Color = Color.White;
textBox.Color = Color.Green;
textBox.Text = (assignedJob == null) ? "None" : assignedJob.Name;
}
@@ -378,16 +409,59 @@ namespace Barotrauma
ladderPoints[1] = new WayPoint(new Vector2(item.Rect.Center.X, item.Rect.Y-1.0f), SpawnType.Path, Submarine.Loaded);
WayPoint prevPoint = ladderPoints[0];
for (float y = ladderPoints[0].Position.Y+100.0f; y < ladderPoints[1].Position.Y; y+=100.0f )
{
var midPoint = new WayPoint(new Vector2(item.Rect.Center.X, y), SpawnType.Path, Submarine.Loaded);
midPoint.Ladders = ladders;
midPoint.ConnectTo(prevPoint);
prevPoint = midPoint;
WayPoint prevPoint = ladderPoints[0];
Vector2 prevPos = prevPoint.SimPosition;
List<Body> ignoredBodies = new List<Body>();
while (prevPoint != ladderPoints[1])
{
var pickedBody = Submarine.PickBody(prevPos, ladderPoints[1].SimPosition, ignoredBodies);
if (pickedBody == null) break;
ignoredBodies.Add(pickedBody);
if (pickedBody.UserData is Item)
{
var door = (pickedBody.UserData as Item).GetComponent<Door>();
if (door != null)
{
WayPoint newPoint = new WayPoint(door.Item.Position, SpawnType.Path, Submarine.Loaded);
newPoint.ConnectedGap = door.LinkedGap;
newPoint.ConnectTo(prevPoint);
prevPoint = newPoint;
prevPos = ConvertUnits.ToSimUnits(door.Item.Position - Vector2.UnitY * door.Item.Rect.Height);
}
else
{
prevPos = Submarine.LastPickedPosition;
}
}
else
{
prevPos = Submarine.LastPickedPosition;
}
}
ladderPoints[1].ConnectTo(prevPoint);
prevPoint.ConnectTo(ladderPoints[1]);
//for (float y = ladderPoints[0].Position.Y+100.0f; y < ladderPoints[1].Position.Y; y+=100.0f )
//{
// var midPoint = new WayPoint(new Vector2(item.Rect.Center.X, y), SpawnType.Path, Submarine.Loaded);
// midPoint.Ladders = ladders;
// midPoint.ConnectTo(prevPoint);
// prevPoint = midPoint;
//}
//ladderPoints[1].ConnectTo(prevPoint);
for (int i = 0; i < 2; i++)
{
@@ -395,13 +469,13 @@ namespace Barotrauma
for (int dir = -1; dir <= 1; dir += 2)
{
WayPoint closest = ladderPoints[i].FindClosest(dir, true, new Vector2(-100.0f, 0f));
WayPoint closest = ladderPoints[i].FindClosest(dir, true, new Vector2(-150.0f, 10f));
if (closest == null) continue;
ladderPoints[i].ConnectTo(closest);
}
}
ladderPoints[0].ConnectTo(ladderPoints[1]);
//ladderPoints[0].ConnectTo(ladderPoints[1]);
}
foreach (Gap gap in Gap.GapList)
@@ -423,6 +497,24 @@ namespace Barotrauma
}
}
foreach (Gap gap in Gap.GapList)
{
if (gap.isHorizontal || gap.IsRoomToRoom) continue;
//too small to walk through
if (gap.Rect.Width < 100.0f) continue;
var wayPoint = new WayPoint(
new Vector2(gap.Rect.Center.X, gap.Rect.Y - gap.Rect.Height/2), SpawnType.Path, Submarine.Loaded, gap);
for (int dir = -1; dir <= 1; dir += 2)
{
WayPoint closest = wayPoint.FindClosest(dir, false, new Vector2(-outSideWaypointInterval, outSideWaypointInterval) / 2.0f);
if (closest == null) continue;
wayPoint.ConnectTo(closest);
}
}
var orphans = WayPointList.FindAll(w => w.spawnType == SpawnType.Path && !w.linkedTo.Any());
foreach (WayPoint wp in orphans)
@@ -438,27 +530,37 @@ namespace Barotrauma
float closestDist = 0.0f;
WayPoint closest = null;
if (horizontalSearch)
{
foreach (WayPoint wp in WayPointList)
{
if (wp.SpawnType != SpawnType.Path || wp == this) continue;
if ((wp.Position.Y - Position.Y) < tolerance.X || (wp.Position.Y - Position.Y) > tolerance.Y) continue;
float diff = 0.0f;
if (horizontalSearch)
{
if ((wp.Position.Y - Position.Y) < tolerance.X || (wp.Position.Y - Position.Y) > tolerance.Y) continue;
diff = wp.Position.X - Position.X;
}
else
{
if ((wp.Position.X - Position.X) < tolerance.X || (wp.Position.X - Position.X) > tolerance.Y) continue;
diff = wp.Position.Y - Position.Y;
}
float diff = wp.Position.X - Position.X;
if (Math.Sign(diff) != dir) continue;
diff = Math.Abs(diff);
if (closest == null || diff < closestDist)
float dist = Vector2.Distance(wp.Position, Position);
if (closest == null || dist < closestDist)
{
if (Submarine.CheckVisibility(SimPosition, wp.SimPosition) != null) continue;
closestDist = diff;
closestDist = dist;
closest = wp;
}
}
}
return closest;
}
@@ -469,13 +571,13 @@ namespace Barotrauma
if (!wayPoint2.linkedTo.Contains(this)) wayPoint2.linkedTo.Add(this);
}
public static WayPoint GetRandom(SpawnType spawnType = SpawnType.None, Job assignedJob = null)
public static WayPoint GetRandom(SpawnType spawnType = SpawnType.Human, Job assignedJob = null)
{
List<WayPoint> wayPoints = new List<WayPoint>();
foreach (WayPoint wp in WayPointList)
{
if (spawnType != SpawnType.None && wp.spawnType != spawnType) continue;
if (wp.spawnType != spawnType) continue;
if (assignedJob != null && wp.assignedJob != assignedJob.Prefab) continue;
wayPoints.Add(wp);
@@ -525,6 +627,16 @@ namespace Barotrauma
if (assignedWayPoints[i] != null) continue;
//try to assign a spawnpoint that isn't meant for any specific job
var nonJobSpecificPoints = WayPointList.FindAll(wp => wp.spawnType == SpawnType.Human && wp.assignedJob == null);
if (nonJobSpecificPoints.Any())
{
assignedWayPoints[i] = nonJobSpecificPoints[Rand.Int(nonJobSpecificPoints.Count, false)];
}
if (assignedWayPoints[i] != null) continue;
//everything else failed -> just give a random spawnpoint
assignedWayPoints[i] = GetRandom(SpawnType.Human);
}
@@ -548,7 +660,7 @@ namespace Barotrauma
public override XElement Save(XDocument doc)
{
if (MoveWithLevel || spawnType == SpawnType.Path) return null;
if (MoveWithLevel) return null;
XElement element = new XElement("WayPoint");
element.Add(new XAttribute("ID", ID),
@@ -591,8 +703,8 @@ namespace Barotrauma
WayPoint w = new WayPoint(rect, submarine);
w.ID = (ushort)int.Parse(element.Attribute("ID").Value);
w.spawnType = (SpawnType)Enum.Parse(typeof(SpawnType),
ToolBox.GetAttributeString(element, "spawn", "None"));
Enum.TryParse<SpawnType>(ToolBox.GetAttributeString(element, "spawn", "Path"), out w.spawnType);
string idCardTagString = ToolBox.GetAttributeString(element, "idcardtags", "");
if (!string.IsNullOrWhiteSpace(idCardTagString))