AI operating reactors & railguns, misc AI improvements

This commit is contained in:
Regalis
2015-11-30 19:06:27 +02:00
parent 6f2db08be0
commit 11857f894b
40 changed files with 804 additions and 272 deletions
+4
View File
@@ -60,6 +60,7 @@
<Compile Include="Source\Characters\AICharacter.cs" /> <Compile Include="Source\Characters\AICharacter.cs" />
<Compile Include="Source\Characters\AI\AIController.cs" /> <Compile Include="Source\Characters\AI\AIController.cs" />
<Compile Include="Source\Characters\AI\AITarget.cs" /> <Compile Include="Source\Characters\AI\AITarget.cs" />
<Compile Include="Source\Characters\AI\Objectives\AIObjectiveContainItem.cs" />
<Compile Include="Source\Characters\AI\Order.cs" /> <Compile Include="Source\Characters\AI\Order.cs" />
<Compile Include="Source\Characters\AI\CrewCommander.cs" /> <Compile Include="Source\Characters\AI\CrewCommander.cs" />
<Compile Include="Source\Characters\AI\HumanAIController.cs" /> <Compile Include="Source\Characters\AI\HumanAIController.cs" />
@@ -598,6 +599,9 @@
<Content Include="Content\Map\militarySymbol.png"> <Content Include="Content\Map\militarySymbol.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Map\researchbackground.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Map\researchSymbol.png"> <Content Include="Content\Map\researchSymbol.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 536 KiB

After

Width:  |  Height:  |  Size: 410 KiB

+22 -4
View File
@@ -12,9 +12,15 @@
<City <City
commonness="3" commonness="3"
hireablecharacters="true"
symbol="Content/Map/citySymbol.png" symbol="Content/Map/citySymbol.png"
background="Content/Map/citybackground.jpg"> background="Content/Map/citybackground.jpg">
<Hireable name="Assistant" commonness="10"/>
<Hireable name="Engineer" commonness="3"/>
<Hireable name="Mechanic" commonness="3"/>
<Hireable name="Security Officer" commonness="1"/>
<Hireable name="Captain" commonness="1"/>
<nameformats <nameformats
f0="The City of [name]" f0="The City of [name]"
f1="[name] City" f1="[name] City"
@@ -24,9 +30,15 @@
<Military <Military
commonness="1" commonness="1"
hireablecharacters="true"
symbol="Content/Map/militarySymbol.png" symbol="Content/Map/militarySymbol.png"
background="Content/Map/militarybackground.jpg"> background="Content/Map/militarybackground.jpg">
<Hireable name="Security Officer" commonness="10"/>
<Hireable name="Captain" commonness="3"/>
<Hireable name="Assistant" commonness="2"/>
<Hireable name="Engineer" commonness="2"/>
<Hireable name="Mechanic" commonness="2"/>
<nameformats <nameformats
f0="[name] Outpost" f0="[name] Outpost"
f1="[name] Facility" f1="[name] Facility"
@@ -36,9 +48,15 @@
<Research <Research
commonness="1" commonness="1"
hireablecharacters="true"
symbol="Content/Map/researchSymbol.png" symbol="Content/Map/researchSymbol.png"
background="Content/Map/citybackground.jpg"> background="Content/Map/researchbackground.jpg">
<Hireable name="Engineer" commonness="5"/>
<Hireable name="Mechanic" commonness="5"/>
<Hireable name="Assistant" commonness="3"/>
<Hireable name="Security Officer" commonness="1"/>
<Hireable name="Captain" commonness="1"/>
<nameformats <nameformats
f0="[name] Research Facility" f0="[name] Research Facility"
f1="[name] Research Center" f1="[name] Research Center"
Binary file not shown.

After

Width:  |  Height:  |  Size: 221 KiB

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework; using Barotrauma.Items.Components;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -35,7 +36,11 @@ namespace Barotrauma
{ {
IsOpen = !IsOpen; IsOpen = !IsOpen;
if (IsOpen && frame == null) CreateGUIFrame(); if (IsOpen)
{
CreateGUIFrame();
UpdateCharacters();
}
} }
private void CreateGUIFrame() private void CreateGUIFrame()
@@ -43,14 +48,64 @@ namespace Barotrauma
frame = new GUIFrame(Rectangle.Empty, Color.Black * 0.3f); frame = new GUIFrame(Rectangle.Empty, Color.Black * 0.3f);
frame.Padding = new Vector4(200.0f, 100.0f, 200.0f, 100.0f); frame.Padding = new Vector4(200.0f, 100.0f, 200.0f, 100.0f);
UpdateCharacters();
int x = 0, y = 150;
foreach (Order order in Order.PrefabList)
{
if (order.ItemComponentType!=null)
{
var matchingItems = Item.ItemList.FindAll(i => i.components.Find(ic => ic.GetType() == order.ItemComponentType) != null);
int y2 = y;
foreach (Item it in matchingItems)
{
var newOrder = new Order(order, it.components.Find(ic => ic.GetType() == order.ItemComponentType));
var button = new GUIButton(new Rectangle(x, y2, 150, 20), order.Name, GUI.Style, frame);
button.UserData = newOrder;
button.OnClicked = SetOrder;
y2 += 25;
}
}
else
{
var button = new GUIButton(new Rectangle(x, y, 150, 20), order.Name, GUI.Style, frame);
button.UserData = order;
button.OnClicked = SetOrder;
}
x += 160;
}
}
public void UpdateCharacters()
{
if (frame == null) CreateGUIFrame();
List<GUIComponent> prevCharacterFrames = new List<GUIComponent>();
foreach (GUIComponent child in frame.children)
{
if (child.UserData as Character == null) continue;
prevCharacterFrames.Add(child);
}
foreach (GUIComponent child in prevCharacterFrames)
{
frame.RemoveChild(child);
}
int x = 0, y = 0; int x = 0, y = 0;
foreach (Character character in crewManager.characters) foreach (Character character in crewManager.characters)
{ {
GUIButton characterButton = new GUIButton(new Rectangle(x,y, 150, 40), "", Color.Transparent, null, frame); if (character.IsDead) continue;
GUIButton characterButton = new GUIButton(new Rectangle(x, y, 150, 40), "", Color.Transparent, null, frame);
characterButton.UserData = character; characterButton.UserData = character;
characterButton.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); characterButton.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
if (character == Character.Controlled) if (character == Character.Controlled)
{ {
characterButton.CanBeSelected = false; characterButton.CanBeSelected = false;
@@ -77,17 +132,6 @@ namespace Barotrauma
x += 160; x += 160;
} }
x = 0;
y = 150;
foreach (Order command in Order.List)
{
var button = new GUIButton(new Rectangle(x, y, 150, 20), command.Name, GUI.Style, frame);
button.UserData = command;
button.OnClicked = SetOrder;
x += button.Rect.Width + 10;
}
} }
private bool SetOrder(GUIButton button, object userData) private bool SetOrder(GUIButton button, object userData)
@@ -13,6 +13,8 @@ namespace Barotrauma
protected Character character; protected Character character;
protected string option;
public virtual bool IsCompleted() public virtual bool IsCompleted()
{ {
return false; return false;
@@ -23,11 +25,23 @@ namespace Barotrauma
get { return false; } get { return false; }
} }
public AIObjective(Character character) public string Option
{
get { return option; }
}
public AIObjective(Character character, string option)
{ {
subObjectives = new List<AIObjective>(); subObjectives = new List<AIObjective>();
this.character = character; this.character = character;
this.option = option;
#if DEBUG
IsDuplicate(null);
#endif
} }
/// <summary> /// <summary>
@@ -37,10 +51,10 @@ namespace Barotrauma
/// <param name="character">the character who's trying to achieve the objective</param> /// <param name="character">the character who's trying to achieve the objective</param>
public void TryComplete(float deltaTime) public void TryComplete(float deltaTime)
{ {
subObjectives.RemoveAll(s => s.IsCompleted());
foreach (AIObjective objective in subObjectives) foreach (AIObjective objective in subObjectives)
{ {
if (objective.IsCompleted()) continue;
objective.TryComplete(deltaTime); objective.TryComplete(deltaTime);
return; return;
} }
@@ -50,6 +64,13 @@ namespace Barotrauma
protected virtual void Act(float deltaTime) { } protected virtual void Act(float deltaTime) { }
public void AddSubObjective(AIObjective objective)
{
if (subObjectives.Find(o => o.IsDuplicate(objective)) != null) return;
subObjectives.Add(objective);
}
public virtual float GetPriority(Character character) public virtual float GetPriority(Character character)
{ {
return 0.0f; return 0.0f;
@@ -57,7 +78,12 @@ namespace Barotrauma
public virtual bool IsDuplicate(AIObjective otherObjective) public virtual bool IsDuplicate(AIObjective otherObjective)
{ {
#if DEBUG
throw new NotImplementedException(); throw new NotImplementedException();
#else
return (this.GetType() == otherObjective.GetType());
#endif
} }
} }
} }
@@ -0,0 +1,73 @@
using Barotrauma.Items.Components;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Barotrauma
{
class AIObjectiveContainItem: AIObjective
{
private string itemName;
private ItemContainer container;
bool canBeCompleted;
bool isCompleted;
public AIObjectiveContainItem(Character character, string itemName, ItemContainer container)
: base (character, "")
{
this.itemName = itemName;
this.container = container;
//check if the container has room for more items
canBeCompleted = false;
foreach (Item contained in container.inventory.Items)
{
if (contained != null) continue;
canBeCompleted = true;
break;
}
}
public override bool IsCompleted()
{
return isCompleted;
}
protected override void Act(float deltaTime)
{
if (isCompleted) return;
//get the item that should be contained
var itemToContain = character.Inventory.FindItem(itemName);
if (itemToContain == null)
{
AddSubObjective(new AIObjectiveGetItem(character, itemName));
return;
}
if (Vector2.Distance(character.SimPosition, container.Item.SimPosition) > container.Item.PickDistance
|| !container.Item.IsInsideTrigger(character.Position))
{
AddSubObjective(new AIObjectiveGoTo(container.Item.SimPosition, character));
return;
}
container.Combine(itemToContain);
isCompleted = true;
}
public override bool IsDuplicate(AIObjective otherObjective)
{
AIObjectiveContainItem objective = otherObjective as AIObjectiveContainItem;
return (objective != null);
}
}
}
@@ -8,21 +8,21 @@ namespace Barotrauma
{ {
class AIObjectiveFindSafety : AIObjective class AIObjectiveFindSafety : AIObjective
{ {
const float SearchHullInterval = 1.0f; const float SearchHullInterval = 3.0f;
const float MinSafety = 50.0f; const float MinSafety = 50.0f;
AIObjectiveGoTo gotoObjective; AIObjectiveGoTo gotoObjective;
private List<AITarget> unreachable; private List<Hull> unreachable;
float currenthullSafety; float currenthullSafety;
float searchHullTimer; float searchHullTimer;
public AIObjectiveFindSafety(Character character) public AIObjectiveFindSafety(Character character)
: base(character) : base(character, "")
{ {
unreachable = new List<AITarget>(); unreachable = new List<Hull>();
} }
protected override void Act(float deltaTime) protected override void Act(float deltaTime)
@@ -44,6 +44,7 @@ namespace Barotrauma
} }
else else
{ {
var pathSteering = character.AIController.SteeringManager as IndoorsSteeringManager;
Hull bestHull = null; Hull bestHull = null;
float bestValue = currenthullSafety; float bestValue = currenthullSafety;
@@ -51,7 +52,7 @@ namespace Barotrauma
foreach (Hull hull in Hull.hullList) foreach (Hull hull in Hull.hullList)
{ {
if (hull == character.AnimController.CurrentHull) continue; if (hull == character.AnimController.CurrentHull) continue;
if (unreachable.Contains(hull.AiTarget)) continue; if (unreachable.Contains(hull)) continue;
float hullValue = GetHullSafety(hull); float hullValue = GetHullSafety(hull);
hullValue -= (float)Math.Sqrt(Math.Abs(character.Position.X- hull.Position.X)); hullValue -= (float)Math.Sqrt(Math.Abs(character.Position.X- hull.Position.X));
@@ -66,7 +67,17 @@ namespace Barotrauma
if (bestHull != null) if (bestHull != null)
{ {
gotoObjective = new AIObjectiveGoTo(bestHull.AiTarget, character); var path = pathSteering.PathFinder.FindPath(character.SimPosition, bestHull.SimPosition);
if (pathSteering.CurrentPath != null && pathSteering.CurrentPath.Cost < path.Cost && !pathSteering.CurrentPath.Unreachable && gotoObjective!=null)
{
return;
}
else
{
pathSteering.SetPath(path);
}
gotoObjective = new AIObjectiveGoTo(bestHull, character);
//character.AIController.SelectTarget(bestHull.AiTarget); //character.AIController.SelectTarget(bestHull.AiTarget);
} }
@@ -80,7 +91,7 @@ namespace Barotrauma
if (pathSteering!=null && pathSteering.CurrentPath!= null && if (pathSteering!=null && pathSteering.CurrentPath!= null &&
pathSteering.CurrentPath.Unreachable && !unreachable.Contains(gotoObjective.Target)) pathSteering.CurrentPath.Unreachable && !unreachable.Contains(gotoObjective.Target))
{ {
unreachable.Add(gotoObjective.Target); unreachable.Add(gotoObjective.Target as Hull);
} }
} }
@@ -11,7 +11,7 @@ namespace Barotrauma
Gap leak; Gap leak;
public AIObjectiveFixLeak(Gap leak, Character character) public AIObjectiveFixLeak(Gap leak, Character character)
:base (character) :base (character, "")
{ {
this.leak = leak; this.leak = leak;
} }
@@ -22,7 +22,7 @@ namespace Barotrauma
} }
public AIObjectiveGetItem(Character character, string itemName) public AIObjectiveGetItem(Character character, string itemName)
: base (character) : base (character, "")
{ {
canBeCompleted = true; canBeCompleted = true;
@@ -72,7 +72,7 @@ namespace Barotrauma
public override bool IsCompleted() public override bool IsCompleted()
{ {
return character.Inventory.Items.FirstOrDefault(i => i != null && (i.HasTag(itemName) || i.Name == itemName)) != null; return character.Inventory.FindItem(itemName) != null;
} }
} }
} }
@@ -10,7 +10,7 @@ namespace Barotrauma
{ {
class AIObjectiveGoTo : AIObjective class AIObjectiveGoTo : AIObjective
{ {
AITarget target; Entity target;
Vector2 targetPos; Vector2 targetPos;
@@ -26,13 +26,13 @@ namespace Barotrauma
} }
} }
public AITarget Target public Entity Target
{ {
get { return target; } get { return target; }
} }
public AIObjectiveGoTo(AITarget target, Character character, bool repeat = false) public AIObjectiveGoTo(Entity target, Character character, bool repeat = false)
: base (character) : base (character, "")
{ {
this.target = target; this.target = target;
this.repeat = false; this.repeat = false;
@@ -40,14 +40,19 @@ namespace Barotrauma
public AIObjectiveGoTo(Vector2 targetPos, Character character) public AIObjectiveGoTo(Vector2 targetPos, Character character)
: base(character) : base(character, "")
{ {
this.targetPos = targetPos; this.targetPos = targetPos;
} }
protected override void Act(float deltaTime) protected override void Act(float deltaTime)
{ {
character.AIController.SelectTarget(target); if (character.SelectedConstruction!=null)
{
character.SelectedConstruction = null;
}
if (target!=null) character.AIController.SelectTarget(target.AiTarget);
character.AIController.SteeringManager.SteeringSeek( character.AIController.SteeringManager.SteeringSeek(
target != null ? target.SimPosition : targetPos); target != null ? target.SimPosition : targetPos);
@@ -56,7 +61,22 @@ namespace Barotrauma
public override bool IsCompleted() public override bool IsCompleted()
{ {
if (repeat) return false; if (repeat) return false;
return Vector2.Distance(target != null ? target.SimPosition : ConvertUnits.ToDisplayUnits(targetPos), character.SimPosition) < 0.5f;
float allowedDistance = 0.5f;
var item = target as Item;
if (item != null) allowedDistance = Math.Max(item.PickDistance,allowedDistance);
return Vector2.Distance(target != null ? target.SimPosition : targetPos, character.SimPosition) < allowedDistance;
}
public override bool IsDuplicate(AIObjective otherObjective)
{
AIObjectiveGoTo objective = otherObjective as AIObjectiveGoTo;
if (objective == null) return false;
if (objective.target == target) return true;
return (objective.targetPos == targetPos);
} }
} }
} }
@@ -13,7 +13,7 @@ namespace Barotrauma
public AIObjectiveIdle(Character character) : base(character) public AIObjectiveIdle(Character character) : base(character, "")
{ {
} }
@@ -26,10 +26,27 @@ namespace Barotrauma
protected override void Act(float deltaTime) protected override void Act(float deltaTime)
{ {
var pathSteering = character.AIController.SteeringManager as IndoorsSteeringManager;
if (newTargetTimer <= 0.0f) if (newTargetTimer <= 0.0f)
{ {
currentTarget = FindRandomTarget(); currentTarget = FindRandomTarget();
if (currentTarget!=null)
{
var path = pathSteering.PathFinder.FindPath(character.SimPosition, currentTarget.SimPosition);
if (path.Cost > 200.0f)
{
return;
}
else
{
pathSteering.SetPath(path);
}
}
newTargetTimer = currentTarget == null ? 5.0f : 10.0f; newTargetTimer = currentTarget == null ? 5.0f : 10.0f;
} }
else else
@@ -40,16 +57,26 @@ namespace Barotrauma
if (currentTarget == null) return; if (currentTarget == null) return;
//wander randomly if reached the end of the path or the target is unreachable
if (pathSteering!=null && pathSteering.CurrentPath != null &&
(pathSteering.CurrentPath.NextNode == null || pathSteering.CurrentPath.Unreachable))
{
if (character.Position.X < character.AnimController.CurrentHull.Rect.X + 200.0f)
{
pathSteering.SteeringManual(deltaTime, Vector2.UnitX);
}
else if (character.Position.X > character.AnimController.CurrentHull.Rect.Right - 200.0f)
{
pathSteering.SteeringManual(deltaTime, -Vector2.UnitX);
}
character.AIController.SteeringManager.SteeringWander(1.0f);
return;
}
character.AIController.SteeringManager.SteeringSeek(currentTarget.SimPosition); character.AIController.SteeringManager.SteeringSeek(currentTarget.SimPosition);
var pathSteering = character.AIController.SteeringManager as IndoorsSteeringManager;
if (pathSteering!=null && pathSteering.CurrentPath != null)
{
if (pathSteering.CurrentPath.NextNode==null || pathSteering.CurrentPath.Unreachable)
{
character.AIController.SteeringManager.SteeringWander(1.0f);
}
}
} }
private AITarget FindRandomTarget() private AITarget FindRandomTarget()
@@ -47,7 +47,7 @@ namespace Barotrauma
public void UpdateObjectives() public void UpdateObjectives()
{ {
if (currentOrder != null || !objectives.Any()) return; if (!objectives.Any()) return;
//remove completed objectives //remove completed objectives
objectives = objectives.FindAll(o => !o.IsCompleted()); objectives = objectives.FindAll(o => !o.IsCompleted());
@@ -69,7 +69,7 @@ namespace Barotrauma
public void DoCurrentObjective(float deltaTime) public void DoCurrentObjective(float deltaTime)
{ {
if (currentOrder != null) if (currentOrder != null && (!objectives.Any() || objectives[0].GetPriority(character)<OrderPriority))
{ {
currentOrder.TryComplete(deltaTime); currentOrder.TryComplete(deltaTime);
return; return;
@@ -81,19 +81,18 @@ namespace Barotrauma
public void SetOrder(Order order, string option) public void SetOrder(Order order, string option)
{ {
currentOrder = null;
switch (order.Name.ToLower()) switch (order.Name.ToLower())
{ {
case "follow": case "follow":
currentOrder = new AIObjectiveGoTo(Character.Controlled.AiTarget, character, true); currentOrder = new AIObjectiveGoTo(Character.Controlled, character, true);
break;
case "operate reactor":
var reactorItem = Item.ItemList.Find(i => i.GetComponent<Reactor>() != null);
if (reactorItem == null) return;
currentOrder = new AIObjectiveOperateItem(reactorItem.GetComponent<Reactor>(), character);
break; break;
default: default:
currentOrder = null; if (order.TargetItem == null) return;
currentOrder = new AIObjectiveOperateItem(order.TargetItem, character, option);
break; break;
} }
} }
@@ -10,22 +10,43 @@ namespace Barotrauma
class AIObjectiveOperateItem : AIObjective class AIObjectiveOperateItem : AIObjective
{ {
private ItemComponent targetItem; private ItemComponent targetItem;
private ItemComponent itemController;
public AIObjectiveOperateItem(ItemComponent item, Character character) private bool isCompleted;
:base (character)
public AIObjectiveOperateItem(ItemComponent item, Character character, string option)
:base (character, option)
{ {
targetItem = item; targetItem = item;
var controllers = item.Item.GetConnectedComponents<Controller>();
if (controllers.Any()) itemController = controllers[0];
} }
protected override void Act(float deltaTime) protected override void Act(float deltaTime)
{ {
if (Vector2.Distance(character.SimPosition, targetItem.Item.SimPosition) < targetItem.Item.PickDistance) ItemComponent target = itemController == null ? targetItem: itemController;
if (Vector2.Distance(character.SimPosition, target.Item.SimPosition) < target.Item.PickDistance
|| target.Item.IsInsideTrigger(character.Position))
{ {
//targetItem.Pick(character, false, true); if (character.SelectedConstruction != target.Item && target.CanBeSelected)
{
target.Item.Pick(character, false, true);
}
if (targetItem.AIOperate(deltaTime, character, this)) isCompleted = true;
return; return;
} }
subObjectives.Add(new AIObjectiveGoTo(targetItem.Item.SimPosition, character)); subObjectives.Add(new AIObjectiveGoTo(target.Item, character));
}
public override bool IsCompleted()
{
return isCompleted;
} }
public override bool IsDuplicate(AIObjective otherObjective) public override bool IsDuplicate(AIObjective otherObjective)
+34 -12
View File
@@ -1,4 +1,5 @@
using System; using Barotrauma.Items.Components;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -7,32 +8,53 @@ namespace Barotrauma
{ {
class Order class Order
{ {
public static List<Order> List; public static List<Order> PrefabList;
public readonly string Name; public readonly string Name;
public readonly string DoingText; public readonly string DoingText;
Sprite buttonSprite; //Sprite buttonSprite;
public readonly Type ItemComponentType;
public ItemComponent TargetItem;
public readonly string[] Options; public readonly string[] Options;
static Order() static Order()
{ {
List = new List<Order>(); PrefabList = new List<Order>();
new Order("Follow", "Following"); PrefabList.Add(new Order("Follow", "Following"));
new Order("Operate Reactor", "Operating reactor", new string[] {"Power Up", "Shutdown"});
new Order("Dismiss", "Dismissed"); PrefabList.Add(new Order("Operate Reactor", "Operating reactor", typeof(Reactor), new string[] {"Power up", "Shutdown"}));
PrefabList.Add(new Order("Operate Railgun", "Operating railgun", typeof(Turret), new string[] { "Fire at will", "Hold fire" }));
PrefabList.Add(new Order("Dismiss", "Dismissed"));
}
private Order(string name, string doingText, Type itemComponentType, string[] parameters = null)
{
Name = name;
DoingText = doingText;
ItemComponentType = itemComponentType;
Options = parameters == null ? new string[0] : parameters;
}
public Order(Order prefab, ItemComponent targetItem)
{
Name = prefab.Name;
DoingText = prefab.DoingText;
ItemComponentType = prefab.ItemComponentType;
Options = prefab.Options;
TargetItem = targetItem;
} }
private Order(string name, string doingText, string[] parameters = null) private Order(string name, string doingText, string[] parameters = null)
:this (name,doingText, null, parameters)
{ {
this.Name = name;
this.DoingText = doingText;
this.Options = parameters == null ? new string[0] : parameters;
List.Add(this);
} }
} }
@@ -266,6 +266,7 @@ namespace Barotrauma
{ {
finalPath.Add(pathNode.Waypoint); finalPath.Add(pathNode.Waypoint);
path.Cost += pathNode.F;
pathNode = pathNode.Parent; pathNode = pathNode.Parent;
} }
@@ -276,6 +277,7 @@ namespace Barotrauma
path.AddNode(wayPoint); path.AddNode(wayPoint);
} }
return path; return path;
} }
} }
@@ -49,6 +49,13 @@ namespace Barotrauma
findPathTimer -= 1.0f / 60.0f; findPathTimer -= 1.0f / 60.0f;
} }
public void SetPath(SteeringPath path)
{
currentPath = path;
if (path.Nodes.Any()) currentTarget = path.Nodes[path.Nodes.Count - 1].SimPosition;
findPathTimer = 1.0f;
}
protected override Vector2 DoSteeringSeek(Vector2 target, float speed = 1) protected override Vector2 DoSteeringSeek(Vector2 target, float speed = 1)
{ {
@@ -101,7 +108,7 @@ namespace Barotrauma
//toggle the door if it's the previous node and open, or if it's current node and closed //toggle the door if it's the previous node and open, or if it's current node and closed
if (door.IsOpen != open) if (door.IsOpen != open)
{ {
var buttons = door.GetButtons(); var buttons = door.Item.GetConnectedComponents<Controller>();
foreach (Controller controller in buttons) foreach (Controller controller in buttons)
{ {
if (Vector2.Distance(controller.Item.SimPosition, character.SimPosition) > controller.Item.PickDistance * 2.0f) continue; if (Vector2.Distance(controller.Item.SimPosition, character.SimPosition) > controller.Item.PickDistance * 2.0f) continue;
@@ -123,7 +130,7 @@ namespace Barotrauma
if (!canOpenDoors) return null; if (!canOpenDoors) return null;
var doorButtons = nextNode.Waypoint.ConnectedGap.ConnectedDoor.GetButtons(); var doorButtons = nextNode.Waypoint.ConnectedGap.ConnectedDoor.Item.GetConnectedComponents<Controller>();
foreach (Controller button in doorButtons) foreach (Controller button in doorButtons)
{ {
if (Math.Sign(button.Item.Position.X - nextNode.Waypoint.Position.X) != if (Math.Sign(button.Item.Position.X - nextNode.Waypoint.Position.X) !=
@@ -50,6 +50,11 @@ namespace Barotrauma
steering += DoSteeringAvoid(deltaTime, speed); steering += DoSteeringAvoid(deltaTime, speed);
} }
public void SteeringManual(float deltaTime, Vector2 velocity)
{
steering += velocity * deltaTime;
}
public virtual void Update(float speed = 1.0f) public virtual void Update(float speed = 1.0f)
{ {
float steeringSpeed = steering.Length(); float steeringSpeed = steering.Length();
@@ -111,7 +116,7 @@ namespace Barotrauma
float maxDistance = 2.0f; float maxDistance = 2.0f;
Vector2 ahead = host.SimPosition + Vector2.Normalize(host.Steering)*maxDistance; Vector2 ahead = host.SimPosition + Vector2.Normalize(host.Steering) * maxDistance;
if (rayCastTimer <= 0.0f) if (rayCastTimer <= 0.0f)
{ {
@@ -125,7 +130,7 @@ namespace Barotrauma
else else
{ {
Structure closestStructure = closestBody.UserData as Structure; Structure closestStructure = closestBody.UserData as Structure;
if (closestStructure!=null) if (closestStructure != null)
{ {
Vector2 obstaclePosition = Submarine.LastPickedPosition; Vector2 obstaclePosition = Submarine.LastPickedPosition;
if (closestStructure.IsHorizontal) if (closestStructure.IsHorizontal)
@@ -139,6 +144,12 @@ namespace Barotrauma
avoidSteering = Vector2.Normalize(Submarine.LastPickedPosition - obstaclePosition); avoidSteering = Vector2.Normalize(Submarine.LastPickedPosition - obstaclePosition);
} }
else
{
Item item = closestBody.UserData as Item;
if (item != null) avoidSteering = Vector2.Normalize(Submarine.LastPickedPosition - item.SimPosition);
}
} }
} }
@@ -148,7 +159,7 @@ namespace Barotrauma
} }
return avoidSteering * speed; return avoidSteering * speed;
} }
} }
} }
@@ -32,6 +32,12 @@ namespace Barotrauma
get { return currentIndex; } get { return currentIndex; }
} }
public float Cost
{
get;
set;
}
public WayPoint PrevNode public WayPoint PrevNode
{ {
get get
@@ -131,6 +131,11 @@ namespace Barotrauma
public Vector2 CursorPosition public Vector2 CursorPosition
{ {
get { return cursorPosition; } get { return cursorPosition; }
set
{
if (!MathUtils.IsValid(value)) return;
cursorPosition = value;
}
} }
public Character ClosestCharacter public Character ClosestCharacter
@@ -216,6 +216,30 @@ namespace Barotrauma
return frame; return frame;
} }
public GUIFrame CreateCharacterFrame(GUIComponent parent, string text, object userData)
{
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, parent);
frame.UserData = userData;
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
frame.HoverColor = Color.LightGray * 0.5f;
frame.SelectedColor = Color.Gold * 0.5f;
// string name = character.Info.Name.Replace(' ', '\n');
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(40, 0, 0, 25),
text,
Color.Transparent, Color.White,
Alignment.Left, Alignment.Left,
null, frame, false);
textBlock.Font = GUI.SmallFont;
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
new GUIImage(new Rectangle(-10, -5, 0, 0), HeadSprite, Alignment.Left, frame);
return frame;
}
public void UpdateCharacterItems() public void UpdateCharacterItems()
{ {
pickedItems.Clear(); pickedItems.Clear();
-5
View File
@@ -44,11 +44,6 @@ namespace Barotrauma
get { return skills.Values.ToList(); } get { return skills.Values.ToList(); }
} }
//public List<float> SkillLevels
//{
// get { return skills.Values.ToList(); }
//}
public Job(JobPrefab jobPrefab) public Job(JobPrefab jobPrefab)
{ {
prefab = jobPrefab; prefab = jobPrefab;
+28 -31
View File
@@ -10,25 +10,6 @@ namespace Barotrauma
{ {
public static List<JobPrefab> List; public static List<JobPrefab> List;
string name;
string description;
//how many crew members can have the job (only one captain etc)
private int maxNumber;
//how many crew members are REQUIRED to have a job
//(i.e. if one captain is required, one captain is chosen even if all the players have set captain to lowest preference)
private int minNumber;
private float commonness;
//if set to true, a client that has chosen this as their preferred job will get it no matter what
public bool AllowAlways
{
get;
private set;
}
//names of the items the Character spawns with //names of the items the Character spawns with
public List<string> ItemNames; public List<string> ItemNames;
public List<bool> EquipItem; public List<bool> EquipItem;
@@ -37,39 +18,55 @@ namespace Barotrauma
public string Name public string Name
{ {
get { return name; } get;
private set;
} }
public string Description public string Description
{ {
get { return description; } get;
private set;
} }
//if set to true, a client that has chosen this as their preferred job will get it no matter what
public bool AllowAlways
{
get;
private set;
}
//how many crew members can have the job (only one captain etc)
public int MaxNumber public int MaxNumber
{ {
get { return maxNumber; } get;
private set;
} }
//how many crew members are REQUIRED to have the job
//(i.e. if one captain is required, one captain is chosen even if all the players have set captain to lowest preference)
public int MinNumber public int MinNumber
{ {
get { return minNumber; } get;
private set;
} }
public float Commonness public float Commonness
{ {
get { return commonness; } get;
private set;
} }
public JobPrefab(XElement element) public JobPrefab(XElement element)
{ {
name = ToolBox.GetAttributeString(element, "name", "name not found"); Name = ToolBox.GetAttributeString(element, "name", "name not found");
description = ToolBox.GetAttributeString(element, "description", ""); Description = ToolBox.GetAttributeString(element, "description", "");
minNumber = ToolBox.GetAttributeInt(element, "minnumber", 0); MinNumber = ToolBox.GetAttributeInt(element, "minnumber", 0);
maxNumber = ToolBox.GetAttributeInt(element, "maxnumber", 10); MaxNumber = ToolBox.GetAttributeInt(element, "maxnumber", 10);
commonness = ToolBox.GetAttributeInt(element, "commonness", 10); Commonness = ToolBox.GetAttributeInt(element, "commonness", 10);
AllowAlways = ToolBox.GetAttributeBool(element, "allowalways", false); AllowAlways = ToolBox.GetAttributeBool(element, "allowalways", false);
@@ -117,9 +114,9 @@ namespace Barotrauma
GUIFrame frame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style, backFrame); GUIFrame frame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style, backFrame);
frame.Padding = new Vector4(30.0f, 30.0f, 30.0f, 30.0f); frame.Padding = new Vector4(30.0f, 30.0f, 30.0f, 30.0f);
new GUITextBlock(new Rectangle(0,0,100,20), name, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, frame, false, GUI.LargeFont); new GUITextBlock(new Rectangle(0,0,100,20), Name, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, frame, false, GUI.LargeFont);
var descriptionBlock = new GUITextBlock(new Rectangle(0, 40, 0, 0), description, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, frame, true, GUI.SmallFont); var descriptionBlock = new GUITextBlock(new Rectangle(0, 40, 0, 0), Description, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, frame, true, GUI.SmallFont);
new GUITextBlock(new Rectangle(0, 40 + descriptionBlock.Rect.Height + 20, 100, 20), "Skills: ", GUI.Style, Alignment.TopLeft, Alignment.TopLeft, frame, false, GUI.LargeFont); new GUITextBlock(new Rectangle(0, 40 + descriptionBlock.Rect.Height + 20, 100, 20), "Skills: ", GUI.Style, Alignment.TopLeft, Alignment.TopLeft, frame, false, GUI.LargeFont);
+5 -3
View File
@@ -41,7 +41,10 @@ namespace Barotrauma
public static bool IsOpen public static bool IsOpen
{ {
get { return isOpen; } get
{
return isOpen;
}
} }
public static void Init(GameWindow window) public static void Init(GameWindow window)
@@ -72,6 +75,7 @@ namespace Barotrauma
} }
else else
{ {
GUIComponent.MouseOn = null;
textBox.Deselect(); textBox.Deselect();
} }
@@ -80,10 +84,8 @@ namespace Barotrauma
if (isOpen) if (isOpen)
{ {
frame.Update(deltaTime); frame.Update(deltaTime);
Character.DisableControls = true; Character.DisableControls = true;
if (PlayerInput.KeyHit(Keys.Up)) if (PlayerInput.KeyHit(Keys.Up))
+22 -15
View File
@@ -85,24 +85,28 @@ namespace Barotrauma
characterInfos.Add(character.Info); characterInfos.Add(character.Info);
} }
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, listBox); commander.UpdateCharacters();
frame.UserData = character;
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
frame.HoverColor = Color.LightGray * 0.5f;
frame.SelectedColor = Color.Gold * 0.5f;
string name = character.Info.Name.Replace(' ', '\n'); character.Info.CreateCharacterFrame(listBox, character.Info.Name.Replace(' ', '\n'), character);
GUITextBlock textBlock = new GUITextBlock( //GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, listBox);
new Rectangle(40, 0, 0, 25), //frame.UserData = character;
name, //frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
Color.Transparent, Color.White, //frame.HoverColor = Color.LightGray * 0.5f;
Alignment.Left, Alignment.Left, //frame.SelectedColor = Color.Gold * 0.5f;
null, frame, false);
textBlock.Font = GUI.SmallFont;
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
new GUIImage(new Rectangle(-10, -5, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame); //string name = character.Info.Name.Replace(' ', '\n');
//GUITextBlock textBlock = new GUITextBlock(
// new Rectangle(40, 0, 0, 25),
// name,
// Color.Transparent, Color.White,
// Alignment.Left, Alignment.Left,
// null, frame, false);
//textBlock.Font = GUI.SmallFont;
//textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
//new GUIImage(new Rectangle(-10, -5, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame);
} }
public void Update(float deltaTime) public void Update(float deltaTime)
@@ -123,6 +127,9 @@ namespace Barotrauma
GUIComponent characterBlock = listBox.GetChild(killedCharacter) as GUIComponent; GUIComponent characterBlock = listBox.GetChild(killedCharacter) as GUIComponent;
if (characterBlock != null) characterBlock.Color = Color.DarkRed * 0.5f; if (characterBlock != null) characterBlock.Color = Color.DarkRed * 0.5f;
commander.UpdateCharacters();
//if (characters.Find(c => !c.IsDead)==null) //if (characters.Find(c => !c.IsDead)==null)
//{ //{
// Game1.GameSession.EndShift(null, null); // Game1.GameSession.EndShift(null, null);
+5 -3
View File
@@ -13,12 +13,14 @@ namespace Barotrauma
availableCharacters = new List<CharacterInfo>(); availableCharacters = new List<CharacterInfo>();
} }
public void GenerateCharacters(string file, int amount) public void GenerateCharacters(Location location, int amount)
{ {
for (int i = 0 ; i<amount ; i++) for (int i = 0 ; i<amount ; i++)
{ {
availableCharacters.Add(new CharacterInfo(file)); JobPrefab job = location.Type.GetRandomHireable();
if (job == null) return;
availableCharacters.Add(new CharacterInfo(Character.HumanConfigFile, "", Gender.None, job));
} }
} }
} }
@@ -256,30 +256,6 @@ namespace Barotrauma.Items.Components
linkedGap.Open = 1.0f; linkedGap.Open = 1.0f;
} }
public List<Controller> GetButtons()
{
ConnectionPanel connectionPanel = Item.GetComponent<ConnectionPanel>();
if (connectionPanel == null) return new List<Controller>();
List<Controller> buttons = new List<Controller>();
foreach (Connection c in connectionPanel.Connections)
{
foreach (Wire w in c.Wires)
{
if (w == null) continue;
var otherConnection = w.OtherConnection(c);
if (otherConnection.Item == Item || otherConnection == null) continue;
var controller = otherConnection.Item.GetComponent<Controller>();
if (controller != null) buttons.Add(controller);
}
}
return buttons;
}
public override void Draw(SpriteBatch spriteBatch, bool editing) public override void Draw(SpriteBatch spriteBatch, bool editing)
{ {
Color color = (item.IsSelected) ? Color.Green : Color.White; Color color = (item.IsSelected) ? Color.Green : Color.White;
@@ -38,8 +38,7 @@ namespace Barotrauma.Items.Components
/// <summary> /// <summary>
/// The base class for components holding the different functionalities of the item /// The base class for components holding the different functionalities of the item
/// </summary> /// </summary>
class class ItemComponent : IPropertyObject
ItemComponent : IPropertyObject
{ {
protected Item item; protected Item item;
@@ -400,6 +399,13 @@ namespace Barotrauma.Items.Components
/// <param name="modifier"> A vector that can be used to pass additional information to the components</param> /// <param name="modifier"> A vector that can be used to pass additional information to the components</param>
public virtual void ItemActivate(Item item, Vector2 modifier) { } public virtual void ItemActivate(Item item, Vector2 modifier) { }
/// <returns>true if the operation was completed</returns>
public virtual bool AIOperate(float deltaTime, Character character, AIObjective objective)
{
return false;
}
//called when isActive is true and condition > 0.0f //called when isActive is true and condition > 0.0f
public virtual void Update(float deltaTime, Camera cam) { } public virtual void Update(float deltaTime, Camera cam) { }
@@ -86,6 +86,11 @@ namespace Barotrauma.Items.Components
} }
private int slotsPerRow; private int slotsPerRow;
public List<RelatedItem> ContainableItems
{
get { return containableItems; }
}
public ItemContainer(Item item, XElement element) public ItemContainer(Item item, XElement element)
: base (item, element) : base (item, element)
{ {
@@ -311,12 +311,44 @@ namespace Barotrauma.Items.Components
new Vector2(10, 40 * (temperature / 10000.0f)), new Color(temperature / 10000.0f, 1.0f - (temperature / 10000.0f), 0.0f, 1.0f), true); new Vector2(10, 40 * (temperature / 10000.0f)), new Color(temperature / 10000.0f, 1.0f - (temperature / 10000.0f), 0.0f, 1.0f), true);
} }
public override bool AIOperate(float deltaTime, Character character, AIObjective objective)
{
switch (objective.Option.ToLower())
{
case "power up":
float tempDiff = load - temperature;
shutDownTemp = Math.Min(load + 1000.0f, 7500.0f);
//temperature too high/low
if (Math.Abs(tempDiff)>500.0f)
{
autoTemp = false;
FissionRate += deltaTime * 100.0f * Math.Sign(tempDiff);
CoolingRate -= deltaTime * 100.0f * Math.Sign(tempDiff);
}
//temperature OK
else
{
autoTemp = true;
}
break;
case "shutdown":
shutDownTemp = 0.0f;
break;
}
return false;
}
bool valueChanged = false;
public override void DrawHUD(SpriteBatch spriteBatch, Character character) public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{ {
IsActive = true; IsActive = true;
bool valueChanged = false;
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
int x = GuiFrame.Rect.X; int x = GuiFrame.Rect.X;
@@ -398,7 +430,6 @@ namespace Barotrauma.Items.Components
if (valueChanged) if (valueChanged)
{ {
item.NewComponentEvent(this, true, false); item.NewComponentEvent(this, true, false);
valueChanged = false;
} }
} }
@@ -156,6 +156,13 @@ namespace Barotrauma.Items.Components
voltage = 0.0f; voltage = 0.0f;
} }
public override bool AIOperate(float deltaTime, Character character, AIObjective objective)
{
RechargeSpeed = maxRechargeSpeed * 0.5f;
return true;
}
public override void Draw(SpriteBatch spriteBatch, bool editing) public override void Draw(SpriteBatch spriteBatch, bool editing)
{ {
base.Draw(spriteBatch); base.Draw(spriteBatch);
+136 -42
View File
@@ -127,67 +127,161 @@ namespace Barotrauma.Items.Components
{ {
if (reload > 0.0f) return false; if (reload > 0.0f) return false;
Projectile projectileComponent = null; var projectiles = GetLoadedProjectiles(true);
//search for a projectile from linked containers if (projectiles.Count == 0) return false;
Item projectile = null;
Item projectileContainer = null;
foreach (MapEntity e in item.linkedTo)
{
projectileContainer = e as Item;
if (projectileContainer == null) continue;
ItemContainer containerComponent = projectileContainer.GetComponent<ItemContainer>(); if (GetAvailablePower() < currPowerConsumption) return false;
if (containerComponent == null) continue;
for (int i = 0; i < containerComponent.inventory.Items.Length; i++)
{
if (containerComponent.inventory.Items[i] == null) continue;
if ((projectileComponent = containerComponent.inventory.Items[i].GetComponent<Projectile>()) != null)
{
projectile = containerComponent.inventory.Items[i];
break;
}
}
if (projectileComponent != null) break;
}
if (projectile == null || projectileComponent == null) return false;
var batteries = item.GetConnectedComponents<PowerContainer>();
float availablePower = 0.0f; float availablePower = 0.0f;
//List<PowerContainer> batteries = new List<PowerContainer>(); foreach (PowerContainer battery in batteries)
foreach (Connection c in item.Connections)
{ {
foreach (Connection c2 in c.Recipients) float batteryPower = Math.Min(battery.Charge, battery.MaxOutPut);
{ float takePower = Math.Min(currPowerConsumption - availablePower, batteryPower);
if (c2 == null || c2.Item == null) continue;
PowerContainer batteryComponent = c2.Item.GetComponent<PowerContainer>(); battery.Charge -= takePower;
if (batteryComponent == null) continue;
float batteryPower = Math.Min(batteryComponent.Charge, batteryComponent.MaxOutPut);
float takePower = Math.Min(currPowerConsumption - availablePower, batteryPower);
batteryComponent.Charge -= takePower;
availablePower += takePower;
}
} }
reload = reloadTime; reload = reloadTime;
if (availablePower < currPowerConsumption) return false; Item projectile = projectiles[0].Item;
projectile.body.ResetDynamics(); projectile.body.ResetDynamics();
projectile.body.Enabled = true; projectile.body.Enabled = true;
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation); projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation);
projectileComponent.Use(deltaTime); projectiles[0].Use(deltaTime);
projectileContainer.RemoveContained(projectile); if (projectile.container != null) projectile.container.RemoveContained(projectile);
return true; return true;
} }
public override bool AIOperate(float deltaTime, Character character, AIObjective objective)
{
var projectiles = GetLoadedProjectiles();
if (projectiles.Count==0 || (projectiles.Count==1 && objective.Option.ToLower()=="hold fire"))
{
ItemContainer container = null;
foreach (MapEntity e in item.linkedTo)
{
var containerItem = e as Item;
if (containerItem == null) continue;
container = containerItem.GetComponent<ItemContainer>();
if (container != null) break;
}
if (container == null || container.ContainableItems.Count==0) return true;
objective.AddSubObjective(new AIObjectiveContainItem(character, container.ContainableItems[0].Names[0], container));
return false;
}
else if (GetAvailablePower() < powerConsumption)
{
var batteries = item.GetConnectedComponents<PowerContainer>();
float lowestCharge = 0.0f;
PowerContainer batteryToLoad = null;
foreach (PowerContainer battery in batteries)
{
if (batteryToLoad==null || battery.Charge < lowestCharge)
{
batteryToLoad = battery;
lowestCharge = battery.Charge;
}
}
if (batteryToLoad == null) return true;
if (batteryToLoad.RechargeSpeed < batteryToLoad.MaxRechargeSpeed*0.4f)
{
objective.AddSubObjective(new AIObjectiveOperateItem(batteryToLoad, character, ""));
return false;
}
}
//enough shells and power
Character closestEnemy = null;
float closestDist = 3000.0f;
foreach (Character enemy in Character.CharacterList)
{
//ignore humans and characters that are inside the sub
if (enemy.IsDead || enemy.SpeciesName == "human" || enemy.AnimController.CurrentHull != null) continue;
float dist = Vector2.Distance(enemy.Position, item.Position);
if (dist < closestDist)
{
closestEnemy = enemy;
closestDist = dist;
}
}
if (closestEnemy == null) return false;
character.CursorPosition = closestEnemy.Position;
SecondaryUse(deltaTime, character);
float enemyAngle = MathUtils.VectorToAngle(closestEnemy.Position-item.Position);
float turretAngle = -(rotation - MathHelper.TwoPi);
if (Math.Abs(enemyAngle - turretAngle) > 0.01f) return false;
var pickedBody = Submarine.PickBody(item.SimPosition, closestEnemy.SimPosition, null);
if (pickedBody != null && pickedBody.UserData as Limb == null) return false;
Use(deltaTime, character);
return false;
}
private float GetAvailablePower()
{
var batteries = item.GetConnectedComponents<PowerContainer>();
float availablePower = 0.0f;
foreach (PowerContainer battery in batteries)
{
float batteryPower = Math.Min(battery.Charge, battery.MaxOutPut);
availablePower += batteryPower;
}
return availablePower;
}
private List<Projectile> GetLoadedProjectiles(bool returnFirst = false)
{
List<Projectile> projectiles = new List<Projectile>();
foreach (MapEntity e in item.linkedTo)
{
var projectileContainer = e as Item;
if (projectileContainer == null) continue;
var containedItems = projectileContainer.ContainedItems;
if (containedItems == null) continue;
for (int i = 0; i < containedItems.Length; i++)
{
var projectileComponent = containedItems[i].GetComponent<Projectile>();
if (projectileComponent != null)
{
projectiles.Add(projectileComponent);
if (returnFirst) return projectiles;
}
}
}
return projectiles;
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power) public override void ReceiveSignal(string signal, Connection connection, Item sender, float power)
{ {
switch (connection.Name) switch (connection.Name)
+33 -1
View File
@@ -681,7 +681,7 @@ namespace Barotrauma
private GUIComponent CreateEditingHUD(bool inGame=false) private GUIComponent CreateEditingHUD(bool inGame=false)
{ {
int width = 500; int width = 400;
int x = GameMain.GraphicsWidth/2-width/2, y = 10; int x = GameMain.GraphicsWidth/2-width/2, y = 10;
List<ObjectProperty> editableProperties = inGame ? GetProperties<InGameEditable>() : GetProperties<Editable>(); List<ObjectProperty> editableProperties = inGame ? GetProperties<InGameEditable>() : GetProperties<Editable>();
@@ -786,6 +786,26 @@ namespace Barotrauma
} }
} }
public List<T> GetConnectedComponents<T>()
{
ConnectionPanel connectionPanel = GetComponent<ConnectionPanel>();
if (connectionPanel == null) return new List<T>();
List<T> connectedComponents = new List<T>();
foreach (Connection c in connectionPanel.Connections)
{
var recipients = c.Recipients;
foreach (Connection recipient in recipients)
{
var component = recipient.Item.GetComponent<T>();
if (component != null) connectedComponents.Add(component);
}
}
return connectedComponents;
}
public void SendSignal(string signal, string connectionName, float power = 0.0f) public void SendSignal(string signal, string connectionName, float power = 0.0f)
{ {
ConnectionPanel panel = GetComponent<ConnectionPanel>(); ConnectionPanel panel = GetComponent<ConnectionPanel>();
@@ -862,6 +882,18 @@ namespace Barotrauma
return closest; return closest;
} }
public bool IsInsideTrigger(Vector2 position)
{
foreach (Rectangle trigger in prefab.Triggers)
{
Rectangle transformedTrigger = TransformTrigger(trigger);
if (Submarine.RectContains(transformedTrigger, position)) return true;
}
return false;
}
public bool Pick(Character picker, bool ignoreRequiredItems=false, bool forceSelectKey=false, bool forceActionKey=false) public bool Pick(Character picker, bool ignoreRequiredItems=false, bool forceSelectKey=false, bool forceActionKey=false)
{ {
+9 -5
View File
@@ -151,13 +151,17 @@ namespace Barotrauma
if (size.X < 100.0f) continue; if (size.X < 100.0f) continue;
var smokeParticle = GameMain.ParticleManager.CreateParticle("smoke", if (Rand.Int(5) == 1)
{
var smokeParticle = GameMain.ParticleManager.CreateParticle("smoke",
spawnPos, speed, 0.0f, hull); spawnPos, speed, 0.0f, hull);
if (smokeParticle != null) if (smokeParticle != null)
{ {
smokeParticle.Size *= MathHelper.Clamp(size.X / 100.0f * Math.Max(hull.Oxygen / hull.FullVolume, 0.4f), 0.5f, 4.0f); smokeParticle.Size *= MathHelper.Clamp(size.X / 100.0f * Math.Max(hull.Oxygen / hull.FullVolume, 0.4f), 0.5f, 4.0f);
}
} }
} }
DamageCharacters(deltaTime); DamageCharacters(deltaTime);
@@ -166,7 +170,7 @@ namespace Barotrauma
if (hull.Volume > 0.0f) HullWaterExtinquish(deltaTime); if (hull.Volume > 0.0f) HullWaterExtinquish(deltaTime);
lightSource.Range = Math.Max(size.X, size.Y) * Rand.Range(8.0f, 10.0f)/2.0f; lightSource.Range = Math.Max(size.X, size.Y) * Rand.Range(8.0f, 10.0f)/2.0f;
lightSource.Color = new Color(1.0f, 0.9f, 0.6f) * Rand.Range(0.8f, 1.0f); lightSource.Color = new Color(1.0f, 0.45f, 0.3f) * Rand.Range(0.8f, 1.0f);
hull.Oxygen -= size.X*deltaTime*OxygenConsumption; hull.Oxygen -= size.X*deltaTime*OxygenConsumption;
+1 -1
View File
@@ -52,7 +52,7 @@ namespace Barotrauma
if (type.HasHireableCharacters) if (type.HasHireableCharacters)
{ {
hireManager = new HireManager(); hireManager = new HireManager();
hireManager.GenerateCharacters(Character.HumanConfigFile, 10); hireManager.GenerateCharacters(this, 10);
} }
Connections = new List<LocationConnection>(); Connections = new List<LocationConnection>();
+41 -8
View File
@@ -24,11 +24,9 @@ namespace Barotrauma
private Sprite backGround; private Sprite backGround;
public bool HasHireableCharacters //<name, commonness>
{ private List<Tuple<JobPrefab, float>> hireableJobs;
get; private float totalHireableWeight;
private set;
}
public string Name public string Name
{ {
@@ -40,6 +38,11 @@ namespace Barotrauma
get { return nameFormats; } get { return nameFormats; }
} }
public bool HasHireableCharacters
{
get { return hireableJobs.Any(); }
}
public Sprite Sprite public Sprite Sprite
{ {
get { return symbolSprite; } get { return symbolSprite; }
@@ -57,21 +60,51 @@ namespace Barotrauma
commonness = ToolBox.GetAttributeInt(element, "commonness", 1); commonness = ToolBox.GetAttributeInt(element, "commonness", 1);
totalWeight += commonness; totalWeight += commonness;
HasHireableCharacters = ToolBox.GetAttributeBool(element, "hireablecharacters", false);
nameFormats = new List<string>(); nameFormats = new List<string>();
foreach (XAttribute nameFormat in element.Element("nameformats").Attributes()) foreach (XAttribute nameFormat in element.Element("nameformats").Attributes())
{ {
nameFormats.Add(nameFormat.Value); nameFormats.Add(nameFormat.Value);
} }
hireableJobs = new List<Tuple<JobPrefab, float>>();
foreach (XElement subElement in element.Elements())
{
if (subElement.Name.ToString().ToLower() != "hireable") continue;
string jobName = ToolBox.GetAttributeString(subElement, "name", "");
JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name.ToLower() == jobName.ToLower());
if (jobPrefab==null)
{
DebugConsole.ThrowError("Invalid job name ("+jobName+") in location type "+name);
}
float jobCommonness = ToolBox.GetAttributeFloat(subElement, "commonness", 1.0f);
totalHireableWeight += jobCommonness;
Tuple<JobPrefab, float> hireableJob = new Tuple<JobPrefab, float>(jobPrefab, jobCommonness);
hireableJobs.Add(hireableJob);
}
string spritePath = ToolBox.GetAttributeString(element, "symbol", "Content/Map/beaconSymbol.png"); string spritePath = ToolBox.GetAttributeString(element, "symbol", "Content/Map/beaconSymbol.png");
symbolSprite = new Sprite(spritePath, new Vector2(0.5f, 0.5f)); symbolSprite = new Sprite(spritePath, new Vector2(0.5f, 0.5f));
string backgroundPath = ToolBox.GetAttributeString(element, "background", ""); string backgroundPath = ToolBox.GetAttributeString(element, "background", "");
backGround = new Sprite(backgroundPath, Vector2.Zero); backGround = new Sprite(backgroundPath, Vector2.Zero);
//sprite.Origin = ; }
public JobPrefab GetRandomHireable()
{
float randFloat = Rand.Range(0.0f, totalHireableWeight);
foreach (Tuple<JobPrefab, float> hireable in hireableJobs)
{
if (randFloat < hireable.Item2) return hireable.Item1;
randFloat -= hireable.Item2;
}
return null;
} }
public static LocationType Random() public static LocationType Random()
@@ -85,7 +85,7 @@ namespace Barotrauma.Networking
var selectionFrame = new GUIFrame(new Rectangle(0, 60, 300, 20), null, innerFrame); var selectionFrame = new GUIFrame(new Rectangle(0, 60, 300, 20), null, innerFrame);
for (int i = 0; i<3; i++) for (int i = 0; i<3; i++)
{ {
var selectionTick = new GUITickBox(new Rectangle(i * 100, 00, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame); var selectionTick = new GUITickBox(new Rectangle(i * 100, 0, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame);
selectionTick.Selected = i == (int)subSelectionMode; selectionTick.Selected = i == (int)subSelectionMode;
selectionTick.OnSelected = SwitchSubSelection; selectionTick.OnSelected = SwitchSubSelection;
selectionTick.UserData = (SelectionMode)i; selectionTick.UserData = (SelectionMode)i;
@@ -101,13 +101,10 @@ namespace Barotrauma.Networking
selectionTick.UserData = (SelectionMode)i; selectionTick.UserData = (SelectionMode)i;
} }
var allowSpecBox = new GUITickBox(new Rectangle(0, 150, 20, 20), "Allow spectating", Alignment.Left, innerFrame);
var allowSpecBox = new GUITickBox(new Rectangle(0, 0, 20, 20), "Allow spectating", Alignment.Left, innerFrame);
allowSpecBox.Selected = true; allowSpecBox.Selected = true;
allowSpecBox.OnSelected = ToggleAllowSpectating; allowSpecBox.OnSelected = ToggleAllowSpectating;
var closeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Close", Alignment.BottomRight, GUI.Style, innerFrame); var closeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Close", Alignment.BottomRight, GUI.Style, innerFrame);
closeButton.OnClicked = ToggleSettingsFrame; closeButton.OnClicked = ToggleSettingsFrame;
} }
+50 -26
View File
@@ -144,12 +144,12 @@ namespace Barotrauma
itemList = new GUIListBox(new Rectangle(0, 0, sellColumnWidth, 400), Color.White * 0.7f, Alignment.TopRight, GUI.Style, bottomPanel[(int)PanelTab.Store]); itemList = new GUIListBox(new Rectangle(0, 0, sellColumnWidth, 400), Color.White * 0.7f, Alignment.TopRight, GUI.Style, bottomPanel[(int)PanelTab.Store]);
itemList.OnSelected = SelectItem; itemList.OnSelected = SelectItem;
foreach (MapEntityPrefab ep in MapEntityPrefab.list) foreach (MapEntityPrefab ep in MapEntityPrefab.list)
{ {
if (ep.Price == 0) continue; if (ep.Price == 0) continue;
CreateItemFrame(ep, itemList); CreateItemFrame(ep, itemList);
} }
} }
public override void Select() public override void Select()
@@ -158,7 +158,16 @@ namespace Barotrauma
gameMode = GameMain.GameSession.gameMode as SinglePlayerMode; gameMode = GameMain.GameSession.gameMode as SinglePlayerMode;
//Map.Unload(); foreach (GUIComponent component in topPanel.children)
{
var button = component as GUIButton;
if (button == null || button.Text != "Hire") continue;
button.Enabled = GameMain.GameSession.Map.CurrentLocation.Type.HasHireableCharacters;
break;
}
//hireButton.Enabled = location.Type.HasHireableCharacters;
UpdateCharacterLists(); UpdateCharacterLists();
} }
@@ -173,6 +182,7 @@ namespace Barotrauma
locationTitle.Font = GUI.LargeFont; locationTitle.Font = GUI.LargeFont;
bottomPanel[(int)PanelTab.CurrentLocation].ClearChildren(); bottomPanel[(int)PanelTab.CurrentLocation].ClearChildren();
bottomPanel[(int)PanelTab.CurrentLocation].UserData = location;
//rightPanel[(int)PanelTab.Hire].Padding = GUI.style.smallPadding; //rightPanel[(int)PanelTab.Hire].Padding = GUI.style.smallPadding;
//for (int i = 0; i < Enum.GetNames(typeof(PanelTab)).Length; i++ ) //for (int i = 0; i < Enum.GetNames(typeof(PanelTab)).Length; i++ )
@@ -208,16 +218,18 @@ namespace Barotrauma
hireList.ClearChildren(); hireList.ClearChildren();
foreach (CharacterInfo c in location.HireManager.availableCharacters) foreach (CharacterInfo c in location.HireManager.availableCharacters)
{ {
GUITextBlock textBlock = new GUITextBlock( var frame = c.CreateCharacterFrame(hireList, c.Name + " (" + c.Job.Name + ")", c);
new Rectangle(0, 0, 0, 25),
c.Name + " (" + c.Job.Name + ")", GUI.Style, hireList);
textBlock.UserData = c;
textBlock = new GUITextBlock( //GUITextBlock textBlock = new GUITextBlock(
// new Rectangle(0, 0, 0, 25),
// c.Name + " (" + c.Job.Name + ")", GUI.Style, hireList);
//textBlock.UserData = c;
var textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25), new Rectangle(0, 0, 0, 25),
c.Salary.ToString(), c.Salary.ToString(),
null, null, null, null,
Alignment.TopRight, GUI.Style, textBlock); Alignment.TopRight, GUI.Style, frame);
} }
} }
else else
@@ -240,22 +252,22 @@ namespace Barotrauma
if (locationPanel != null) bottomPanel[(int)PanelTab.Map].RemoveChild(locationPanel); if (locationPanel != null) bottomPanel[(int)PanelTab.Map].RemoveChild(locationPanel);
locationPanel = new GUIFrame(new Rectangle(0, 0, 200, 190), Color.Transparent, Alignment.TopRight, null, bottomPanel[(int)PanelTab.Map]); locationPanel = new GUIFrame(new Rectangle(0, 0, 250, 190), Color.Transparent, Alignment.TopRight, null, bottomPanel[(int)PanelTab.Map]);
locationPanel.UserData = "selectedlocation"; locationPanel.UserData = "selectedlocation";
if (location == null) return; if (location == null) return;
new GUITextBlock(new Rectangle(0,0,0,0), location.Name, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel); new GUITextBlock(new Rectangle(0, 0, 0, 0), location.Name, Color.Black * 0.8f, Color.White, Alignment.TopLeft, null, locationPanel).Font = GUI.LargeFont;
if (GameMain.GameSession.Map.SelectedConnection != null && GameMain.GameSession.Map.SelectedConnection.Quest != null) if (GameMain.GameSession.Map.SelectedConnection != null && GameMain.GameSession.Map.SelectedConnection.Quest != null)
{ {
var quest = GameMain.GameSession.Map.SelectedConnection.Quest; var quest = GameMain.GameSession.Map.SelectedConnection.Quest;
new GUITextBlock(new Rectangle(0, 40, 0, 20), "Quest: "+quest.Name, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel); new GUITextBlock(new Rectangle(0, 40, 0, 20), "Quest: "+quest.Name, Color.Black*0.8f, Color.White, Alignment.TopLeft, null, locationPanel);
new GUITextBlock(new Rectangle(0, 60, 0, 20), "Reward: " + quest.Reward, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel); new GUITextBlock(new Rectangle(0, 60, 0, 20), "Reward: " + quest.Reward, Color.Black * 0.8f, Color.White, Alignment.TopLeft, null, locationPanel);
new GUITextBlock(new Rectangle(0, 80, 0, 0), quest.Description, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel, true); new GUITextBlock(new Rectangle(0, 80, 0, 0), quest.Description, Color.Black * 0.8f, Color.White, Alignment.TopLeft, null, locationPanel, true);
} }
@@ -269,14 +281,16 @@ namespace Barotrauma
characterList.ClearChildren(); characterList.ClearChildren();
foreach (CharacterInfo c in CrewManager.characterInfos) foreach (CharacterInfo c in CrewManager.characterInfos)
{ {
GUITextBlock textBlock = new GUITextBlock( c.CreateCharacterFrame(characterList, c.Name + " ("+c.Job.Name+") ", c);
new Rectangle(0, 0, 0, 25),
c.Name + " (" + c.Job.Name + ")", GUI.Style, //GUITextBlock textBlock = new GUITextBlock(
Alignment.Left, // new Rectangle(0, 0, 0, 25),
Alignment.Left, // c.Name + " (" + c.Job.Name + ")", GUI.Style,
characterList, false, GameMain.GraphicsWidth<1000 ? GUI.SmallFont : GUI.Font); // Alignment.Left,
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f); // Alignment.Left,
textBlock.UserData = c; // characterList, false, GameMain.GraphicsWidth<1000 ? GUI.SmallFont : GUI.Font);
//textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
//textBlock.UserData = c;
} }
} }
@@ -403,7 +417,7 @@ namespace Barotrauma
GameMain.GameSession.Map.Draw(spriteBatch, new Rectangle( GameMain.GameSession.Map.Draw(spriteBatch, new Rectangle(
bottomPanel[selectedRightPanel].Rect.X + 20, bottomPanel[selectedRightPanel].Rect.X + 20,
bottomPanel[selectedRightPanel].Rect.Y + 20, bottomPanel[selectedRightPanel].Rect.Y + 20,
bottomPanel[selectedRightPanel].Rect.Width - 280, bottomPanel[selectedRightPanel].Rect.Width - 310,
bottomPanel[selectedRightPanel].Rect.Height - 40), mapZoom); bottomPanel[selectedRightPanel].Rect.Height - 40), mapZoom);
} }
@@ -449,6 +463,16 @@ namespace Barotrauma
private bool SelectCharacter(GUIComponent component, object selection) private bool SelectCharacter(GUIComponent component, object selection)
{ {
GUIComponent prevInfoFrame = null;
foreach (GUIComponent child in bottomPanel[selectedRightPanel].children)
{
if (child.UserData as CharacterInfo == null) continue;
prevInfoFrame = child;
}
if (prevInfoFrame != null) bottomPanel[selectedRightPanel].RemoveChild(prevInfoFrame);
CharacterInfo characterInfo = selection as CharacterInfo; CharacterInfo characterInfo = selection as CharacterInfo;
if (characterInfo == null) return false; if (characterInfo == null) return false;
Binary file not shown.