(deee8cd6d) Merge branch 'dev' into human-ai

This commit is contained in:
Joonas Rikkonen
2019-05-16 05:23:20 +03:00
parent abd19f614f
commit 053ef60fc4
14 changed files with 176 additions and 396 deletions
@@ -83,26 +83,44 @@ namespace Barotrauma
foreach (FireSource fs in targetHull.FireSources)
{
bool inRange = fs.IsInDamageRange(character, MathHelper.Clamp(fs.DamageRange * 1.5f, extinguisher.Range * 0.5f, extinguisher.Range));
if (targetHull == character.CurrentHull && (inRange || useExtinquisherTimer > 0.0f))
bool move = !inRange;
if (inRange || useExtinquisherTimer > 0.0f)
{
useExtinquisherTimer += deltaTime;
if (useExtinquisherTimer > 2.0f) useExtinquisherTimer = 0.0f;
if (useExtinquisherTimer > 2.0f)
{
useExtinquisherTimer = 0.0f;
}
character.AIController.SteeringManager.Reset();
character.CursorPosition = fs.Position;
if (extinguisher.Item.RequireAimToUse)
{
character.SetInput(InputType.Aim, false, true);
}
extinguisher.Use(deltaTime, character);
if (!targetHull.FireSources.Contains(fs))
Limb sightLimb = null;
if (character.Inventory.IsInLimbSlot(extinguisherItem, InvSlotType.RightHand))
{
character.Speak(TextManager.Get("DialogPutOutFire").Replace("[roomname]", targetHull.Name), null, 0, "putoutfire", 10.0f);
sightLimb = character.AnimController.GetLimb(LimbType.RightHand);
}
else if (character.Inventory.IsInLimbSlot(extinguisherItem, InvSlotType.LeftHand))
{
sightLimb = character.AnimController.GetLimb(LimbType.LeftHand);
}
if (!character.CanSeeTarget(fs, sightLimb))
{
move = true;
}
else
{
move = false;
extinguisher.Use(deltaTime, character);
if (!targetHull.FireSources.Contains(fs))
{
character.Speak(TextManager.Get("DialogPutOutFire").Replace("[roomname]", targetHull.Name), null, 0, "putoutfire", 10.0f);
}
}
return;
}
else
if (move)
{
//go to the first firesource
if (gotoObjective == null || !gotoObjective.CanBeCompleted || gotoObjective.IsCompleted())
@@ -113,8 +131,8 @@ namespace Barotrauma
{
gotoObjective.TryComplete(deltaTime);
}
break;
}
break;
}
}
}
@@ -102,10 +102,22 @@ namespace Barotrauma
HumanAIController.AnimController.Crouching = true;
}
//float reach = HumanAIController.AnimController.ArmLength + ConvertUnits.ToSimUnits(repairTool.Range);
float reach = ConvertUnits.ToSimUnits(repairTool.Range);
bool cannotReach = ConvertUnits.ToSimUnits(gapDiff.Length()) > reach;
if (cannotReach)
bool canReach = ConvertUnits.ToSimUnits(gapDiff.Length()) < reach;
if (canReach)
{
Limb sightLimb = null;
if (character.Inventory.IsInLimbSlot(repairTool.Item, InvSlotType.RightHand))
{
sightLimb = character.AnimController.GetLimb(LimbType.RightHand);
}
else if (character.Inventory.IsInLimbSlot(repairTool.Item, InvSlotType.LeftHand))
{
sightLimb = character.AnimController.GetLimb(LimbType.LeftHand);
}
canReach = character.CanSeeTarget(leak, sightLimb);
}
else
{
if (gotoObjective != null)
{
@@ -131,7 +143,6 @@ namespace Barotrauma
AddSubObjective(gotoObjective);
}
}
canReach = character.CanSeeTarget(leak, sightLimb);
}
if (gotoObjective == null || gotoObjective.IsCompleted())
{
@@ -92,7 +92,7 @@ namespace Barotrauma
{
if (character.CurrentHull == target.Item.CurrentHull)
{
if (character.SelectedConstruction != target.Item && target.CanBeSelected)
if (character.SelectedConstruction != target.Item)
{
target.Item.TryInteract(character, false, true);
}
@@ -102,12 +102,6 @@ namespace Barotrauma
}
return;
}
if (component.AIOperate(deltaTime, character, this))
{
isCompleted = true;
}
return;
}
AddSubObjective(gotoObjective = new AIObjectiveGoTo(target.Item, character, objectiveManager));
@@ -95,7 +95,7 @@ namespace Barotrauma
{
FindRepairTool();
}
if (character.CanInteractWith(Item))
if (character.CurrentHull == Item.CurrentHull && character.CanInteractWith(Item))
{
if (repairTool != null)
{
@@ -1379,25 +1379,35 @@ namespace Barotrauma
else
{
closestBody = Submarine.CheckVisibility(seeingLimb.SimPosition, seeingLimb.SimPosition + diff);
if (closestBody != null)
if (!IsBlocking(closestBody))
{
if (closestBody.UserData is Structure wall && wall.CastShadow)
closestBody = Submarine.CheckVisibility(target.SimPosition, target.SimPosition - diff);
}
}
return !IsBlocking(closestBody);
bool IsBlocking(Body body)
{
if (body == null) { return false; }
if (body.UserData is Structure wall && wall.CastShadow)
{
return wall != target;
}
else if (body.UserData is Item item && item != target)
{
var door = item.GetComponent<Door>();
if (door != null)
{
return false;
return !door.IsOpen;
}
}
closestBody = Submarine.CheckVisibility(target.SimPosition, target.SimPosition - diff);
return false;
}
if (closestBody != null)
{
if (closestBody.UserData is Structure wall && wall.CastShadow)
{
return false;
}
}
return true;
}
/// <summary>
/// TODO: ensure that works. CheckVisibility takes positions in sim space, but this method uses world positions
/// </summary>
public bool CanSeeCharacter(Character target, Vector2 sourceWorldPos)
{
Vector2 diff = ConvertUnits.ToSimUnits(target.WorldPosition - sourceWorldPos);
@@ -1413,7 +1423,9 @@ namespace Barotrauma
if (closestBody == null) return true;
}
Structure wall = closestBody.UserData as Structure;
return wall == null || !wall.CastShadow;
Item item = closestBody.UserData as Item;
Door door = item?.GetComponent<Door>();
return (wall == null || !wall.CastShadow) && (door == null || door.IsOpen);
}
public bool HasEquippedItem(Item item)