FixLeaks-command (still needs a sprite for the UI)
This commit is contained in:
@@ -19,5 +19,9 @@
|
||||
|
||||
<Order name="Operate Railgun" doingtext="Operating Railgun" targetitemtype="Turret" options="Fire at will, Hold fire" color="1.0,0.0,0.0,1.0">
|
||||
<Sprite texture="Content/UI/orderSymbols.png" sourcerect="0,64,64,64"/>
|
||||
</Order>
|
||||
</Order>
|
||||
|
||||
<Order name="Fix Leaks" doingtext="Fixing Leaks" color="0.2,0.2,1.0,1.0">
|
||||
<Sprite texture="Content/UI/orderSymbols.png" sourcerect="0,64,64,64"/>
|
||||
</Order>
|
||||
</Orders>
|
||||
@@ -0,0 +1,68 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class AIObjectiveFixLeaks : AIObjective
|
||||
{
|
||||
const float UpdateGapListInterval = 5.0f;
|
||||
|
||||
private float updateGapListTimer;
|
||||
|
||||
private List<AIObjectiveFixLeak> objectiveList;
|
||||
|
||||
public AIObjectiveFixLeaks(Character character)
|
||||
: base (character, "")
|
||||
{
|
||||
objectiveList = new List<AIObjectiveFixLeak>();
|
||||
}
|
||||
|
||||
public override bool IsCompleted()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void Act(float deltaTime)
|
||||
{
|
||||
updateGapListTimer -= deltaTime;
|
||||
|
||||
if (updateGapListTimer<=0.0f)
|
||||
{
|
||||
UpdateGapList();
|
||||
|
||||
updateGapListTimer = UpdateGapListInterval;
|
||||
}
|
||||
|
||||
if (objectiveList.Any()) objectiveList[0].TryComplete(deltaTime);
|
||||
}
|
||||
|
||||
private void UpdateGapList()
|
||||
{
|
||||
objectiveList.Clear();
|
||||
|
||||
foreach (Gap gap in Gap.GapList)
|
||||
{
|
||||
if (gap.IsRoomToRoom || gap.ConnectedDoor != null || gap.Open < 0.1f) continue;
|
||||
|
||||
float dist = Vector2.DistanceSquared(character.WorldPosition, gap.WorldPosition);
|
||||
|
||||
int index = 0;
|
||||
while (index<objectiveList.Count &&
|
||||
Vector2.DistanceSquared(objectiveList[index].Leak.WorldPosition, character.WorldPosition)<dist)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
|
||||
objectiveList.Insert(index, new AIObjectiveFixLeak(gap, character));
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsDuplicate(AIObjective otherObjective)
|
||||
{
|
||||
return otherObjective is AIObjectiveFixLeaks;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,13 +54,6 @@ namespace Barotrauma
|
||||
|
||||
//sort objectives according to priority
|
||||
objectives.Sort((x, y) => y.GetPriority(character).CompareTo(x.GetPriority(character)));
|
||||
|
||||
foreach (Gap gap in Gap.GapList)
|
||||
{
|
||||
if (gap.IsRoomToRoom || gap.ConnectedDoor != null || gap.Open<0.1f) continue;
|
||||
|
||||
AddObjective(new AIObjectiveFixLeak(gap, character));
|
||||
}
|
||||
}
|
||||
|
||||
public void DoCurrentObjective(float deltaTime)
|
||||
@@ -87,6 +80,10 @@ namespace Barotrauma
|
||||
case "wait":
|
||||
currentObjective = new AIObjectiveGoTo(character.SimPosition, character, true);
|
||||
break;
|
||||
case "fixleaks":
|
||||
case "fix leaks":
|
||||
currentObjective = new AIObjectiveFixLeaks(character);
|
||||
break;
|
||||
default:
|
||||
if (order.TargetItem == null) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user