- option to select which location autopilot navigates towards

- generating "dummy locations" for the MP gamesessions (visible in sonar and mission descriptions)
- EndGame network message tells the clients if the mission was successful (because the message may arrive before the sub has reached the exit or before some character has died at the client's end)
This commit is contained in:
Regalis
2016-10-26 19:22:40 +03:00
parent 182cfb3451
commit 980f8e0d33
10 changed files with 184 additions and 61 deletions
@@ -20,10 +20,7 @@ namespace Barotrauma.Items.Components
private List<RadarBlip> radarBlips;
private float prevPingRadius;
public static string StartMarker = "Start";
public static string EndMarker = "End";
[HasDefaultValue(10000.0f, false)]
public float Range
{
@@ -266,11 +263,11 @@ namespace Barotrauma.Items.Components
DrawMarker(spriteBatch,
(GameMain.GameSession.Map == null) ? StartMarker : GameMain.GameSession.Map.CurrentLocation.Name,
GameMain.GameSession.StartLocation.Name,
(Level.Loaded.StartPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.5f));
DrawMarker(spriteBatch,
(GameMain.GameSession.Map == null) ? EndMarker : GameMain.GameSession.Map.SelectedLocation.Name,
GameMain.GameSession.EndLocation.Name,
(Level.Loaded.EndPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.5f));
if (GameMain.GameSession.Mission != null)
@@ -19,7 +19,8 @@ namespace Barotrauma.Items.Components
private Vector2 targetVelocity;
private GUITickBox autopilotTickBox, maintainPosTickBox;
private GUITickBox levelEndTickBox, levelStartTickBox;
private bool autoPilot;
private Vector2? posToMaintain;
@@ -47,21 +48,23 @@ namespace Barotrauma.Items.Components
if (value == autoPilot) return;
autoPilot = value;
autopilotTickBox.Selected = value;
maintainPosTickBox.Enabled = autoPilot;
levelEndTickBox.Enabled = autoPilot;
levelStartTickBox.Enabled = autoPilot;
if (autoPilot)
{
if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(item.WorldPosition),
TargetPosition == null ? ConvertUnits.ToSimUnits(Level.Loaded.EndPosition) : (Vector2)TargetPosition);
if (pathFinder == null) pathFinder = new PathFinder(WayPoint.WayPointList, false);
ToggleMaintainPosition(maintainPosTickBox);
}
else
{
maintainPosTickBox.Selected = false;
levelEndTickBox.Selected = false;
levelStartTickBox.Selected = false;
posToMaintain = null;
}
}
@@ -114,9 +117,24 @@ namespace Barotrauma.Items.Components
return true;
};
maintainPosTickBox = new GUITickBox(new Rectangle(0, 50, 20, 20), "Maintain position", Alignment.TopLeft, GuiFrame);
maintainPosTickBox = new GUITickBox(new Rectangle(5, 50, 15, 15), "Maintain position", Alignment.TopLeft, GUI.SmallFont, GuiFrame);
maintainPosTickBox.Enabled = false;
maintainPosTickBox.OnSelected = ToggleMaintainPosition;
levelStartTickBox = new GUITickBox(
new Rectangle(5, 70, 15, 15),
GameMain.GameSession.StartLocation.Name,
Alignment.TopLeft, GUI.SmallFont, GuiFrame);
levelStartTickBox.Enabled = false;
levelStartTickBox.OnSelected = SelectDestination;
levelEndTickBox = new GUITickBox(
new Rectangle(5, 90, 15, 15),
GameMain.GameSession.EndLocation.Name,
Alignment.TopLeft, GUI.SmallFont, GuiFrame);
levelEndTickBox.Enabled = false;
levelEndTickBox.OnSelected = SelectDestination;
}
public override void Update(float deltaTime, Camera cam)
@@ -332,6 +350,28 @@ namespace Barotrauma.Items.Components
}
private void UpdatePath()
{
Vector2 target;
if (TargetPosition != null)
{
target = (Vector2)TargetPosition;
}
else
{
if (levelEndTickBox.Selected)
{
target = ConvertUnits.ToSimUnits(Level.Loaded.EndPosition);
}
else
{
target = ConvertUnits.ToSimUnits(Level.Loaded.StartPosition);
}
}
steeringPath = pathFinder.FindPath(ConvertUnits.ToSimUnits(item.WorldPosition), target);
}
private void SteerTowardsPosition(Vector2 worldPosition)
{
float prediction = 10.0f;
@@ -346,7 +386,7 @@ namespace Barotrauma.Items.Components
}
else
{
TargetVelocity = targetSpeed/5.0f;
TargetVelocity = targetSpeed / 5.0f;
}
}
@@ -354,21 +394,42 @@ namespace Barotrauma.Items.Components
{
valueChanged = true;
if (tickBox.Selected)
{
if (item.Submarine == null)
{
posToMaintain = null;
}
else
{
posToMaintain = item.Submarine.WorldPosition;
}
}
else
levelStartTickBox.Selected = false;
levelEndTickBox.Selected = false;
if (item.Submarine == null)
{
posToMaintain = null;
}
else
{
posToMaintain = item.Submarine.WorldPosition;
}
tickBox.Selected = true;
return true;
}
private bool SelectDestination(GUITickBox tickBox)
{
valueChanged = true;
if (tickBox == levelStartTickBox)
{
levelEndTickBox.Selected = false;
}
else
{
levelStartTickBox.Selected = false;
}
maintainPosTickBox.Selected = false;
posToMaintain = null;
UpdatePath();
tickBox.Selected = true;
return true;
}
@@ -399,6 +460,10 @@ namespace Barotrauma.Items.Components
message.Write(((Vector2)posToMaintain).X);
message.Write(((Vector2)posToMaintain).Y);
}
else
{
message.Write(levelStartTickBox.Selected);
}
}
return true;
@@ -411,6 +476,8 @@ namespace Barotrauma.Items.Components
Vector2? newPosToMaintain = null;
bool headingToStart = false;
try
{
newTargetVelocity = new Vector2(message.ReadFloat(), message.ReadFloat());
@@ -424,6 +491,10 @@ namespace Barotrauma.Items.Components
message.ReadFloat(),
message.ReadFloat());
}
else
{
headingToStart = message.ReadBoolean();
}
}
}
@@ -437,6 +508,20 @@ namespace Barotrauma.Items.Components
maintainPosTickBox.Selected = newPosToMaintain != null;
posToMaintain = newPosToMaintain;
if (posToMaintain == null && autoPilot)
{
levelStartTickBox.Selected = headingToStart;
levelEndTickBox.Selected = !headingToStart;
UpdatePath();
}
else
{
levelStartTickBox.Selected = false;
levelEndTickBox.Selected = false;
}
}
}
}