AI combat, misc AI improvements, characters can't get stuck inside doors

This commit is contained in:
Regalis
2015-12-03 18:34:35 +02:00
parent 11857f894b
commit 5bcdfa2b56
36 changed files with 461 additions and 292 deletions
+38 -26
View File
@@ -244,6 +244,43 @@ namespace Barotrauma.Items.Components
OpenState += deltaTime * ((isOpen) ? 2.0f : -2.0f);
LinkedGap.Open = openState;
}
if (openState > 0.0f && openState < 1.0f)
{
//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(doorSprite.size.X,
item.Rect.Height * (1.0f - openState)));
foreach (Character c in Character.CharacterList)
{
int dir = Math.Sign(c.SimPosition.X - item.SimPosition.X);
foreach (Limb l in c.AnimController.Limbs)
{
if (l.SimPosition.Y > simPos.Y || l.SimPosition.Y < simPos.Y - simSize.Y) continue;
if (Math.Sign(l.SimPosition.X - item.SimPosition.X) != dir)
{
l.body.SetTransform(new Vector2(item.SimPosition.X + dir * simSize.X*1.2f, item.SimPosition.Y), l.body.Rotation);
SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, 1.0f, l.body.FarseerBody);
//c.AddDamage(item.SimPosition, DamageType.Blunt, 1.0f, 0.0f, 0.0f, true);
l.body.ApplyLinearImpulse(new Vector2(dir * 0.5f, isOpen ? 0.0f : -1.0f));
}
if (Math.Abs(l.SimPosition.X - item.SimPosition.X) > simSize.X*0.5f) continue;
l.body.ApplyLinearImpulse(new Vector2(dir * 0.5f, isOpen ? 0.0f : -0.5f));
c.StartStun(0.2f);
}
}
}
else
{
body.Enabled = openState < 1.0f;
}
item.SendSignal((isOpen) ? "1" : "0", "state_out");
@@ -278,32 +315,7 @@ namespace Barotrauma.Items.Components
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
{
//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)
{
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));
}
}
}
color, 0.0f, doorSprite.Origin, 1.0f, SpriteEffects.None, doorSprite.Depth);
}
public override void OnMapLoaded()
@@ -90,26 +90,18 @@ namespace Barotrauma.Items.Components
+ Rand.Range(-degreeOfFailure, degreeOfFailure));
projectile.Use(deltaTime);
projectileComponent.User = character;
projectile.body.ApplyTorque(projectile.body.Mass * degreeOfFailure * Rand.Range(-10.0f, 10.0f));
//recoil
//recoil
item.body.ApplyLinearImpulse(
new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * item.body.Mass * -50.0f);
//else
//{
projectileComponent.ignoredBodies = limbBodies;
//recoil
//item.body.ApplyLinearImpulse(
// new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * -item.body.Mass);
//}
projectileComponent.ignoredBodies = limbBodies;
item.RemoveContained(projectile);
Rope rope = item.GetComponent<Rope>();
if (rope != null) rope.Attach(projectile);
@@ -117,9 +109,8 @@ namespace Barotrauma.Items.Components
}
return false;
return false;
}
}
}
@@ -22,6 +22,8 @@ namespace Barotrauma.Items.Components
public List<Body> ignoredBodies;
public Character User;
[HasDefaultValue(10.0f, false)]
public float LaunchImpulse
{
@@ -127,17 +129,15 @@ namespace Barotrauma.Items.Components
{
if (stickJoint != null && stickJoint.JointTranslation < 0.01f)
{
if (stickTarget!=null)
if (stickTarget != null)
{
try
{
item.body.FarseerBody.RestoreCollisionWith(stickTarget);
}
catch (Exception e)
catch
{
#if DEBUG
DebugConsole.ThrowError("Failed to restore collision with stickTarget", e);
#endif
//the body that the projectile was stuck to has been removed
}
stickTarget = null;
@@ -147,11 +147,9 @@ namespace Barotrauma.Items.Components
{
GameMain.World.RemoveJoint(stickJoint);
}
catch (Exception e)
catch
{
#if DEBUG
DebugConsole.ThrowError("Failed to remove stickJoint", e);
#endif
//the body that the projectile was stuck to has been removed
}
stickJoint = null;
@@ -165,17 +163,17 @@ namespace Barotrauma.Items.Components
if (ignoredBodies.Contains(f2.Body)) return false;
AttackResult attackResult = new AttackResult(0.0f, 0.0f);
if (attack!=null)
if (attack != null)
{
Limb limb;
Structure structure;
if ((limb = (f2.Body.UserData as Limb)) != null)
{
attackResult = attack.DoDamage(null, limb.character, item.SimPosition, 1.0f);
{
attackResult = attack.DoDamage(User, limb.character, item.SimPosition, 1.0f);
}
else if ((structure = (f2.Body.UserData as Structure)) != null)
{
attackResult = attack.DoDamage(null, structure, item.SimPosition, 1.0f);
attackResult = attack.DoDamage(User, structure, item.SimPosition, 1.0f);
}
}
+13 -5
View File
@@ -161,7 +161,7 @@ namespace Barotrauma.Items.Components
{
var projectiles = GetLoadedProjectiles();
if (projectiles.Count==0 || (projectiles.Count==1 && objective.Option.ToLower()=="hold fire"))
if (projectiles.Count==0 || (projectiles.Count==1 && objective.Option.ToLower()!="fire at will"))
{
ItemContainer container = null;
foreach (MapEntity e in item.linkedTo)
@@ -174,8 +174,10 @@ namespace Barotrauma.Items.Components
}
if (container == null || container.ContainableItems.Count==0) return true;
objective.AddSubObjective(new AIObjectiveContainItem(character, container.ContainableItems[0].Names[0], container));
var containShellObjective = new AIObjectiveContainItem(character, container.ContainableItems[0].Names[0], container);
containShellObjective.IgnoreAlreadyContainedItems = true;
objective.AddSubObjective(containShellObjective);
return false;
}
else if (GetAvailablePower() < powerConsumption)
@@ -186,7 +188,7 @@ namespace Barotrauma.Items.Components
PowerContainer batteryToLoad = null;
foreach (PowerContainer battery in batteries)
{
if (batteryToLoad==null || battery.Charge < lowestCharge)
if (batteryToLoad == null || battery.Charge < lowestCharge)
{
batteryToLoad = battery;
lowestCharge = battery.Charge;
@@ -205,7 +207,6 @@ namespace Barotrauma.Items.Components
}
//enough shells and power
Character closestEnemy = null;
float closestDist = 3000.0f;
foreach (Character enemy in Character.CharacterList)
@@ -256,6 +257,13 @@ namespace Barotrauma.Items.Components
return availablePower;
}
public override void Remove()
{
base.Remove();
barrelSprite.Remove();
}
private List<Projectile> GetLoadedProjectiles(bool returnFirst = false)
{
List<Projectile> projectiles = new List<Projectile>();