- CrewCommander key can be changed

- Improved logic for teleporting character in/out the sub
- changed Turret.AIOperate to use the new coordinate system
- neutralballastlevel option in steering
- crewmanager UI works properly with different numbers of crew members
- fixed obstructvision "twitching" when moving in/out the sub
- resetting steering velocity when AI is waiting
- GetItem AIObjective ignores items outside the sub
- crew has the "dismissed" order by default
-
This commit is contained in:
Regalis
2016-01-20 00:26:45 +02:00
parent 4dd48d7bf2
commit 6c57c1270c
24 changed files with 213 additions and 74 deletions
@@ -15,6 +15,8 @@ namespace Barotrauma
GUIFrame frame;
//GUIListBox characterList;
private int characterFrameBottom;
public GUIFrame Frame
{
get { return IsOpen ? frame : null; }
@@ -29,7 +31,6 @@ namespace Barotrauma
public CrewCommander(CrewManager crewManager)
{
this.crewManager = crewManager;
}
public void ToggleGUIFrame()
@@ -47,20 +48,19 @@ namespace Barotrauma
{
frame = new GUIFrame(Rectangle.Empty, Color.Black * 0.6f);
frame.Padding = new Vector4(200.0f, 100.0f, 200.0f, 100.0f);
//UpdateCharacters();
int buttonWidth = 130;
int spacing = 20;
int y = 250;
int y = 50;
for (int n = 0; n<2; n++)
{
{
List<Order> orders = (n==0) ?
Order.PrefabList.FindAll(o => o.ItemComponentType == null) :
Order.PrefabList.FindAll(o=> o.ItemComponentType!=null);
Order.PrefabList.FindAll(o=> o.ItemComponentType != null);
int startX = (int)-(buttonWidth * orders.Count + spacing * (orders.Count - 1)) / 2;
@@ -117,7 +117,7 @@ namespace Barotrauma
public void UpdateCharacters()
{
if (frame == null) CreateGUIFrame();
CreateGUIFrame();
List<GUIComponent> prevCharacterFrames = new List<GUIComponent>();
foreach (GUIComponent child in frame.children)
@@ -134,18 +134,19 @@ namespace Barotrauma
List<Character> aliveCharacters = crewManager.characters.FindAll(c => !c.IsDead);
characterFrameBottom = 0;
int charactersPerRow = 4;
int spacing = 5;
int rows = (int)Math.Ceiling((double)aliveCharacters.Count / charactersPerRow);
int i = 0;
foreach (Character character in aliveCharacters)
{
int rowCharacterCount = Math.Min(charactersPerRow, aliveCharacters.Count);
if (aliveCharacters.Count - i < charactersPerRow-1) rowCharacterCount = aliveCharacters.Count % charactersPerRow;
//if (i >= aliveCharacters.Count - charactersPerRow && aliveCharacters.Count % charactersPerRow > 0) rowCharacterCount = aliveCharacters.Count % charactersPerRow;
// rowCharacterCount = Math.Min(rowCharacterCount, aliveCharacters.Count - i);
int startX = (int)-(150 * rowCharacterCount + spacing * (rowCharacterCount - 1)) / 2;
@@ -159,12 +160,13 @@ namespace Barotrauma
characterButton.UserData = character;
characterButton.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
characterButton.Color = Character.Controlled == character ? Color.Gold * 0.3f : Color.Black * 0.5f;
characterButton.Color = Character.Controlled == character ? Color.Gold * 0.2f : Color.Black * 0.5f;
characterButton.HoverColor = Color.LightGray * 0.5f;
characterButton.SelectedColor = Color.Gold * 0.5f;
characterButton.SelectedColor = Color.Gold * 0.6f;
characterButton.OutlineColor = Color.LightGray * 0.8f;
characterFrameBottom = Math.Max(characterFrameBottom, characterButton.Rect.Bottom);
string name = character.Info.Name;
if (character.Info.Job != null) name += '\n' + "(" + character.Info.Job.Name + ")";
@@ -187,6 +189,16 @@ namespace Barotrauma
i++;
}
foreach (GUIComponent child in frame.children)
{
if (!(child.UserData is Order)) continue;
Rectangle rect = child.Rect;
rect.Y += characterFrameBottom;
child.Rect = rect;
}
}
private bool SetOrder(GUIButton button, object userData)
@@ -225,12 +237,22 @@ namespace Barotrauma
var existingOrder = characterFrame.children.Find(c => c.UserData as Order != null);
if (existingOrder != null) characterFrame.RemoveChild(existingOrder);
var orderFrame = new GUIFrame(new Rectangle(0, characterFrame.Rect.Height, 0, 30 + order.Options.Length * 15), null, characterFrame);
orderFrame.OutlineColor = Color.LightGray * 0.8f;
var orderFrame = new GUIFrame(new Rectangle(-5, characterFrame.Rect.Height, characterFrame.Rect.Width, 30 + order.Options.Length * 15), null, characterFrame);
orderFrame.OutlineColor = Color.LightGray * 0.5f;
orderFrame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
orderFrame.UserData = order;
var img = new GUIImage(new Rectangle(0, 0, 20, 20), order.SymbolSprite, Alignment.TopLeft, orderFrame);
img.Scale = 20.0f / img.SourceRect.Width;
img.Color = order.Color;
img.CanBeFocused = false;
new GUITextBlock(new Rectangle(0, 0, 0, 20), order.DoingText, GUI.Style, Alignment.TopLeft, Alignment.TopCenter, orderFrame);
var optionList = new GUIListBox(new Rectangle(0, 20, 0, 80), Color.Transparent, null, orderFrame);
optionList.UserData = order;
@@ -289,7 +289,7 @@ namespace Barotrauma
updateTargetsTimer = Math.Min(updateTargetsTimer, 0.1f);
coolDownTimer *= 0.1f;
if (amount > 1.0f && attackWhenProvoked)
if (amount > 0.1f && attackWhenProvoked)
{
attackHumans = 100.0f;
attackRooms = 100.0f;
@@ -38,6 +38,14 @@ namespace Barotrauma
objectiveManager.AddObjective(new AIObjectiveIdle(c));
updateObjectiveTimer = Rand.Range(0.0f, UpdateObjectiveInterval);
if (GameMain.GameSession!=null && GameMain.GameSession.CrewManager!=null)
{
CurrentOrder = Order.PrefabList.Find(o => o.Name.ToLower() == "dismissed");
objectiveManager.SetOrder(CurrentOrder, "");
GameMain.GameSession.CrewManager.SetCharacterOrder(Character, CurrentOrder);
}
}
public override void Update(float deltaTime)
@@ -87,6 +95,8 @@ namespace Barotrauma
if (Character.IsKeyDown(InputType.Aim))
{
Character.AnimController.TargetDir = Character.CursorPosition.X > Character.Position.X ? Direction.Right : Direction.Left;
if (Character.SelectedConstruction != null) Character.SelectedConstruction.SecondaryUse(deltaTime, Character);
}
else if (Math.Abs(Character.AnimController.TargetMovement.X) > 0.1f && !Character.AnimController.InWater)
{
@@ -110,6 +120,8 @@ namespace Barotrauma
CurrentOrderOption = option;
CurrentOrder = order;
objectiveManager.SetOrder(order, option);
GameMain.GameSession.CrewManager.SetCharacterOrder(Character, order);
}
public override void SelectTarget(AITarget target)
@@ -101,6 +101,9 @@ namespace Barotrauma
{
currSearchIndex++;
//don't try to get items from outside the sub
if (Item.ItemList[currSearchIndex].CurrentHull == null) continue;
if (!Item.ItemList[currSearchIndex].HasTag(itemName) && Item.ItemList[currSearchIndex].Name != itemName) continue;
if (IgnoreContainedItems && Item.ItemList[currSearchIndex].Container != null) continue;
if (Item.ItemList[currSearchIndex].Inventory is CharacterInventory) continue;
@@ -59,7 +59,12 @@ namespace Barotrauma
protected override void Act(float deltaTime)
{
if (target == character) return;
if (target == character)
{
character.AIController.SteeringManager.Reset();
return;
}
waitUntilPathUnreachable -= deltaTime;
@@ -116,7 +121,7 @@ namespace Barotrauma
completed = completed || Vector2.Distance(target != null ? target.SimPosition : targetPos, character.SimPosition) < allowedDistance;
if (completed) character.AIController.SteeringManager.SteeringManual(0.0f, -character.AIController.Steering);
if (completed) character.AIController.SteeringManager.Reset();
return completed;
}
@@ -70,6 +70,8 @@ namespace Barotrauma
public void SetOrder(Order order, string option)
{
if (order == null) return;
currentObjective = null;
switch (order.Name.ToLower())
@@ -9,7 +9,7 @@ namespace Barotrauma
{
class AIObjectiveOperateItem : AIObjective
{
private ItemComponent component;
private ItemComponent component, controller;
private Entity operateTarget;
@@ -33,14 +33,14 @@ namespace Barotrauma
public AIObjectiveOperateItem(ItemComponent item, Character character, string option, Entity operateTarget = null, bool useController = false)
:base (character, option)
{
component = item;
this.component = item;
this.operateTarget = operateTarget;
if (useController)
{
var controllers = item.Item.GetConnectedComponents<Controller>();
if (controllers.Any()) component = controllers[0];
if (controllers.Any()) controller = controllers[0];
}
@@ -49,21 +49,23 @@ namespace Barotrauma
protected override void Act(float deltaTime)
{
if (component.CanBeSelected)
ItemComponent target = controller == null ? component : controller;
if (target.CanBeSelected)
{
if (Vector2.Distance(character.Position, component.Item.Position) < component.Item.PickDistance
|| component.Item.IsInsideTrigger(character.WorldPosition))
if (Vector2.Distance(character.Position, target.Item.Position) < target.Item.PickDistance
|| target.Item.IsInsideTrigger(character.WorldPosition))
{
if (character.SelectedConstruction != component.Item && component.CanBeSelected)
if (character.SelectedConstruction != target.Item && target.CanBeSelected)
{
component.Item.Pick(character, false, true);
target.Item.Pick(character, false, true);
}
if (component.AIOperate(deltaTime, character, this)) isCompleted = true;
return;
}
AddSubObjective(new AIObjectiveGoTo(component.Item, character));
AddSubObjective(new AIObjectiveGoTo(target.Item, character));
}
else
{
@@ -55,6 +55,11 @@ namespace Barotrauma
steering += velocity;
}
public void Reset()
{
steering = Vector2.Zero;
}
public virtual void Update(float speed = 1.0f)
{
float steeringSpeed = steering.Length();
@@ -553,10 +553,12 @@ namespace Barotrauma
if (newHull == null && currentHull.Submarine != null)
{
SetPosition(refLimb.SimPosition + ConvertUnits.ToSimUnits(currentHull.Submarine.Position));
character.CursorPosition += currentHull.Submarine.Position;
}
else if (currentHull == null && newHull != null && newHull.Submarine != null)
{
SetPosition(refLimb.SimPosition - ConvertUnits.ToSimUnits(newHull.Submarine.Position));
character.CursorPosition -= newHull.Submarine.Position;
}
}