Human AI improvements, minor UI tweaking

This commit is contained in:
Regalis
2015-11-25 16:04:51 +02:00
parent c456fa3c90
commit 4b5126675c
42 changed files with 687 additions and 321 deletions
+53 -24
View File
@@ -7,6 +7,7 @@ using FarseerPhysics.Factories;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Lights;
using System.Collections.Generic;
namespace Barotrauma.Items.Components
{
@@ -41,8 +42,7 @@ namespace Barotrauma.Items.Components
if (linkedGap != null) return linkedGap;
foreach (MapEntity e in item.linkedTo)
{
linkedGap = e as Gap;
linkedGap.ConnectedDoor = this;
linkedGap = e as Gap;
if (linkedGap != null) return linkedGap;
}
linkedGap = new Gap(item.Rect);
@@ -256,6 +256,30 @@ namespace Barotrauma.Items.Components
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)
{
Color color = (item.IsSelected) ? Color.Green : Color.White;
@@ -272,38 +296,43 @@ namespace Barotrauma.Items.Components
if (openState == 1.0f)
{
body.Enabled = false;
return;
}
spriteBatch.Draw(doorSprite.Texture, new Vector2(item.Rect.Center.X, -item.Rect.Y),
new Rectangle(doorSprite.SourceRect.X, (int)(doorSprite.size.Y * openState),
(int)doorSprite.size.X, (int)(doorSprite.size.Y * (1.0f - openState))),
color, 0.0f, doorSprite.Origin, 1.0f, SpriteEffects.None, doorSprite.Depth);
if (openState == 0.0f)
{
body.Enabled = true;
}
else
{
spriteBatch.Draw(doorSprite.Texture, new Vector2(item.Rect.Center.X, -item.Rect.Y),
new Rectangle(doorSprite.SourceRect.X, (int)(doorSprite.size.Y * openState),
(int)doorSprite.size.X, (int)(doorSprite.size.Y * (1.0f - openState))),
color, 0.0f, doorSprite.Origin, 1.0f, SpriteEffects.None, doorSprite.Depth);
//push characters out of the doorway when the door is closing/opening
Vector2 simPos = ConvertUnits.ToSimUnits(new Vector2(item.Rect.X, item.Rect.Y));
Vector2 simSize = ConvertUnits.ToSimUnits(new Vector2(item.Rect.Width,
item.Rect.Height * (1.0f - openState)));
if (openState == 0.0f)
foreach (Character c in Character.CharacterList)
{
body.Enabled = true;
}
else
{
//push characters out of the doorway when the door is closing/opening
Vector2 simPos = ConvertUnits.ToSimUnits(new Vector2(item.Rect.X, item.Rect.Y));
Vector2 simSize = ConvertUnits.ToSimUnits(new Vector2(item.Rect.Width,
item.Rect.Height * (1.0f - openState)));
foreach (Character c in Character.CharacterList)
int dir = Math.Sign(c.AnimController.Limbs[0].SimPosition.X - simPos.X);
foreach (Limb l in c.AnimController.Limbs)
{
int dir = Math.Sign(c.AnimController.Limbs[0].SimPosition.X - simPos.X);
foreach (Limb l in c.AnimController.Limbs)
{
if (l.SimPosition.Y < simPos.Y || l.SimPosition.Y > simPos.Y - simSize.Y) continue;
if (Math.Abs(l.SimPosition.X - simPos.X) > simSize.X * 2.0f) continue;
if (l.SimPosition.Y < simPos.Y || l.SimPosition.Y > simPos.Y - simSize.Y) continue;
if (Math.Abs(l.SimPosition.X - simPos.X) > simSize.X * 2.0f) continue;
l.body.ApplyForce(new Vector2(dir * 10.0f, 0.0f));
}
l.body.ApplyForce(new Vector2(dir * 10.0f, 0.0f));
}
}
}
}
public override void OnMapLoaded()
{
LinkedGap.ConnectedDoor = this;
}
public override void Remove()
@@ -551,7 +551,7 @@ namespace Barotrauma.Items.Components
}
if (!hasItem && ri.Type.HasFlag(RelatedItem.RelationType.Picked))
{
if (character.Inventory.items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x))!=null) hasItem = true;
if (character.Inventory.Items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x))!=null) hasItem = true;
}
if (!hasItem)
{
@@ -127,7 +127,7 @@ namespace Barotrauma.Items.Components
{
if (!hasStatusEffects) return;
foreach (Item contained in inventory.items)
foreach (Item contained in inventory.Items)
{
if (contained == null || contained.Condition <= 0.0f) continue;
//if (contained.body != null) contained.body.Enabled = false;
@@ -179,7 +179,7 @@ namespace Barotrauma.Items.Components
currentRotation += item.body.Rotation;
}
foreach (Item containedItem in inventory.items)
foreach (Item containedItem in inventory.Items)
{
if (containedItem == null) continue;
@@ -243,7 +243,7 @@ namespace Barotrauma.Items.Components
{
base.Remove();
foreach (Item item in inventory.items)
foreach (Item item in inventory.Items)
{
if (item == null) continue;
item.Remove();
@@ -274,10 +274,10 @@ namespace Barotrauma.Items.Components
{
XElement componentElement = base.Save(parentElement);
string[] itemIdStrings = new string[inventory.items.Length];
for (int i = 0; i < inventory.items.Length; i++)
string[] itemIdStrings = new string[inventory.Items.Length];
for (int i = 0; i < inventory.Items.Length; i++)
{
itemIdStrings[i] = (inventory.items[i]==null) ? "0" : inventory.items[i].ID.ToString();
itemIdStrings[i] = (inventory.Items[i]==null) ? "0" : inventory.Items[i].ID.ToString();
}
componentElement.Add(new XAttribute("contained", string.Join(",",itemIdStrings)));
@@ -162,7 +162,7 @@ namespace Barotrauma.Items.Components
ItemContainer container = item.GetComponent<ItemContainer>();
foreach (ItemPrefab ip in fabricatedItem.RequiredItems)
{
var requiredItem = Array.Find(container.inventory.items, it => it != null && it.Prefab == ip);
var requiredItem = container.inventory.Items.FirstOrDefault(it => it != null && it.Prefab == ip);
container.inventory.RemoveItem(requiredItem);
}
@@ -182,7 +182,7 @@ namespace Barotrauma.Items.Components
ItemContainer container = item.GetComponent<ItemContainer>();
foreach (ItemPrefab ip in targetItem.RequiredItems)
{
if (Array.Find(container.inventory.items, it => it != null && it.Prefab == ip) != null) continue;
if (Array.Find(container.inventory.Items, it => it != null && it.Prefab == ip) != null) continue;
selectedItemFrame.GetChild<GUIButton>().Enabled = false;
break;
}
+4 -4
View File
@@ -139,12 +139,12 @@ namespace Barotrauma.Items.Components
ItemContainer containerComponent = projectileContainer.GetComponent<ItemContainer>();
if (containerComponent == null) continue;
for (int i = 0; i < containerComponent.inventory.items.Length; i++)
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)
if (containerComponent.inventory.Items[i] == null) continue;
if ((projectileComponent = containerComponent.inventory.Items[i].GetComponent<Projectile>()) != null)
{
projectile = containerComponent.inventory.items[i];
projectile = containerComponent.inventory.Items[i];
break;
}
}