(c14dcd3d6) Support for multi-target monster missions

This commit is contained in:
Joonas Rikkonen
2019-04-18 12:03:07 +03:00
parent 786c37811f
commit fdacc4534b
5 changed files with 55 additions and 25 deletions
@@ -439,11 +439,14 @@ namespace Barotrauma.Items.Components
{ {
var mission = GameMain.GameSession.Mission; var mission = GameMain.GameSession.Mission;
if (!string.IsNullOrWhiteSpace(mission.SonarLabel) && mission.SonarPosition != Vector2.Zero) if (!string.IsNullOrWhiteSpace(mission.SonarLabel))
{ {
DrawMarker(spriteBatch, foreach (Vector2 sonarPosition in mission.SonarPositions)
mission.SonarLabel, {
mission.SonarPosition - transducerCenter, displayScale, center, (rect.Width * 0.47f)); DrawMarker(spriteBatch,
mission.SonarLabel,
sonarPosition - transducerCenter, displayScale, center, (rect.Width * 0.47f));
}
} }
} }
@@ -76,7 +76,7 @@ namespace Barotrauma
else if (Vector2.DistanceSquared(center, ai.SimPosition) > maxDistFromCenter * maxDistFromCenter) else if (Vector2.DistanceSquared(center, ai.SimPosition) > maxDistFromCenter * maxDistFromCenter)
{ {
float distFromCenter = Vector2.Distance(center, ai.SimPosition); float distFromCenter = Vector2.Distance(center, ai.SimPosition);
ai.SteeringManager.SteeringSeek(center, distFromCenter - maxDistFromCenter); ai.SteeringManager.SteeringSeek(center, (distFromCenter - maxDistFromCenter) / 10.0f);
} }
//keep the characters moving in roughly the same direction //keep the characters moving in roughly the same direction
@@ -55,9 +55,9 @@ namespace Barotrauma
get { return true; } get { return true; }
} }
public virtual Vector2 SonarPosition public virtual IEnumerable<Vector2> SonarPositions
{ {
get { return Vector2.Zero; } get { return Enumerable.Empty<Vector2>(); }
} }
public string SonarLabel public string SonarLabel
@@ -1,4 +1,6 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma namespace Barotrauma
{ {
@@ -8,32 +10,38 @@ namespace Barotrauma
private int state; private int state;
private Character monster; private int monsterCount;
private Vector2 sonarPosition; private readonly List<Character> monsters = new List<Character>();
private readonly List<Vector2> sonarPositions = new List<Vector2>();
public override Vector2 SonarPosition public override IEnumerable<Vector2> SonarPositions
{ {
get { return monster != null && !monster.IsDead ? sonarPosition : Vector2.Zero; } get
{
return sonarPositions;
}
} }
public MonsterMission(MissionPrefab prefab, Location[] locations) public MonsterMission(MissionPrefab prefab, Location[] locations)
: base(prefab, locations) : base(prefab, locations)
{ {
monsterFile = prefab.ConfigElement.GetAttributeString("monsterfile", ""); monsterFile = prefab.ConfigElement.GetAttributeString("monsterfile", "");
monsterCount = prefab.ConfigElement.GetAttributeInt("monstercount", 1);
} }
public override void Start(Level level) public override void Start(Level level)
{ {
Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out Vector2 spawnPos); Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out Vector2 spawnPos);
bool isClient = false; bool isClient = GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient;
#if CLIENT for (int i = 0; i < monsterCount; i++)
isClient = GameMain.Client != null; {
#endif monsters.Add(Character.Create(monsterFile, spawnPos, ToolBox.RandomSeed(8), null, isClient, true, false));
monster = Character.Create(monsterFile, spawnPos, ToolBox.RandomSeed(8), null, isClient, true, false); }
monster.Enabled = false; monsters.ForEach(m => m.Enabled = false);
sonarPosition = spawnPos; SwarmBehavior.CreateSwarm(monsters.Cast<AICharacter>());
sonarPositions.Add(spawnPos);
} }
public override void Update(float deltaTime) public override void Update(float deltaTime)
@@ -41,12 +49,23 @@ namespace Barotrauma
switch (state) switch (state)
{ {
case 0: case 0:
if (monster.Enabled) sonarPositions.Clear();
var activeMonsters = monsters.Where(m => m != null && !m.Removed && !m.IsDead);
if (activeMonsters.Any())
{ {
sonarPosition = monster.Position; Vector2 centerOfMass = Vector2.Zero;
foreach (var monster in activeMonsters)
{
//don't add another label if there's another monster roughly at the same spot
if (sonarPositions.All(p => Vector2.DistanceSquared(p, monster.Position) > 1000.0f * 1000.0f))
{
sonarPositions.Add(monster.Position);
}
}
} }
if (!monster.IsDead) return;
if (activeMonsters.Any()) { return; }
#if CLIENT #if CLIENT
ShowMessage(state); ShowMessage(state);
#endif #endif
@@ -57,10 +76,9 @@ namespace Barotrauma
public override void End() public override void End()
{ {
if (!monster.IsDead) return; if (!monsters.All(m => m.Removed || m.IsDead)) { return; }
GiveReward(); GiveReward();
completed = true; completed = true;
} }
} }
@@ -1,6 +1,8 @@
using FarseerPhysics; using FarseerPhysics;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using System; using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma namespace Barotrauma
{ {
@@ -14,11 +16,18 @@ namespace Barotrauma
private int state; private int state;
public override Vector2 SonarPosition public override IEnumerable<Vector2> SonarPositions
{ {
get get
{ {
return state > 0 ? Vector2.Zero : ConvertUnits.ToDisplayUnits(item.SimPosition); if (state > 0 )
{
Enumerable.Empty<Vector2>();
}
else
{
yield return ConvertUnits.ToDisplayUnits(item.SimPosition);
}
} }
} }