Moar progress, fixed shadow/los/submarine misalignment issues
This commit is contained in:
@@ -27,6 +27,11 @@ namespace Barotrauma
|
||||
set { sightRange = value; }
|
||||
}
|
||||
|
||||
public Vector2 WorldPosition
|
||||
{
|
||||
get { return Entity.WorldPosition; }
|
||||
}
|
||||
|
||||
public Vector2 SimPosition
|
||||
{
|
||||
get { return Entity.SimPosition; }
|
||||
|
||||
@@ -167,12 +167,17 @@ namespace Barotrauma
|
||||
|
||||
selectedTargetMemory.Priority -= deltaTime;
|
||||
|
||||
Vector2 attackPosition = selectedAiTarget.SimPosition;
|
||||
if (wallAttackPos != Vector2.Zero) attackPosition = wallAttackPos;
|
||||
Vector2 attackSimPosition = Character.Submarine==null ? ConvertUnits.ToSimUnits(selectedAiTarget.WorldPosition) : selectedAiTarget.SimPosition;
|
||||
if (wallAttackPos != Vector2.Zero)
|
||||
{
|
||||
attackSimPosition = wallAttackPos;
|
||||
|
||||
if (selectedAiTarget.Entity != null && Character.Submarine==null && selectedAiTarget.Entity.Submarine != null) attackSimPosition += ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position);
|
||||
}
|
||||
|
||||
if (coolDownTimer>0.0f)
|
||||
{
|
||||
UpdateCoolDown(attackPosition, deltaTime);
|
||||
UpdateCoolDown(attackSimPosition, deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -187,7 +192,7 @@ namespace Barotrauma
|
||||
raycastTimer = RaycastInterval;
|
||||
}
|
||||
|
||||
steeringManager.SteeringSeek(attackPosition);
|
||||
steeringManager.SteeringSeek(attackSimPosition);
|
||||
|
||||
//check if any of the limbs is close enough to attack the target
|
||||
if (attackingLimb == null)
|
||||
@@ -195,7 +200,7 @@ namespace Barotrauma
|
||||
foreach (Limb limb in Character.AnimController.Limbs)
|
||||
{
|
||||
if (limb.attack==null || limb.attack.Type == AttackType.None) continue;
|
||||
if (Vector2.Distance(limb.SimPosition, attackPosition) > limb.attack.Range) continue;
|
||||
if (ConvertUnits.ToDisplayUnits(Vector2.Distance(limb.SimPosition, attackSimPosition)) > limb.attack.Range) continue;
|
||||
|
||||
attackingLimb = limb;
|
||||
break;
|
||||
@@ -203,7 +208,7 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateLimbAttack(deltaTime, attackingLimb, attackPosition);
|
||||
UpdateLimbAttack(deltaTime, attackingLimb, attackSimPosition);
|
||||
|
||||
}
|
||||
|
||||
@@ -230,9 +235,19 @@ namespace Barotrauma
|
||||
private void GetTargetEntity()
|
||||
{
|
||||
targetEntity = null;
|
||||
|
||||
|
||||
|
||||
|
||||
//check if there's a wall between the target and the Character
|
||||
Vector2 rayStart = Character.AnimController.Limbs[0].SimPosition;
|
||||
Vector2 rayStart = Character.SimPosition;
|
||||
Vector2 rayEnd = selectedAiTarget.SimPosition;
|
||||
|
||||
if (selectedAiTarget.Entity.Submarine!=null && Character.Submarine==null)
|
||||
{
|
||||
rayStart -= ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position);
|
||||
}
|
||||
|
||||
Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd);
|
||||
|
||||
if (Submarine.LastPickedFraction == 1.0f || closestBody == null)
|
||||
@@ -245,6 +260,8 @@ namespace Barotrauma
|
||||
if (wall == null)
|
||||
{
|
||||
wallAttackPos = Submarine.LastPickedPosition;
|
||||
if (selectedAiTarget.Entity.Submarine!=null) wallAttackPos -= ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -261,6 +278,7 @@ namespace Barotrauma
|
||||
if (wall.SectionDamage(i) > sectionDamage) sectionIndex = i;
|
||||
}
|
||||
wallAttackPos = wall.SectionPosition(sectionIndex);
|
||||
//if (wall.Submarine != null) wallAttackPos += wall.Submarine.Position;
|
||||
wallAttackPos = ConvertUnits.ToSimUnits(wallAttackPos);
|
||||
}
|
||||
|
||||
@@ -288,15 +306,8 @@ namespace Barotrauma
|
||||
|
||||
float dir = (limb.attack.Type == AttackType.PinchCW) ? 1.0f : -1.0f;
|
||||
|
||||
if (wallAttackPos != Vector2.Zero && targetEntity != null)
|
||||
{
|
||||
damageTarget = targetEntity as IDamageable;
|
||||
}
|
||||
else
|
||||
{
|
||||
damageTarget = selectedAiTarget.Entity as IDamageable;
|
||||
}
|
||||
|
||||
damageTarget = (wallAttackPos != Vector2.Zero && targetEntity != null) ? targetEntity : selectedAiTarget.Entity as IDamageable;
|
||||
|
||||
attackTimer += deltaTime*0.05f;
|
||||
|
||||
if (damageTarget == null)
|
||||
@@ -305,12 +316,12 @@ namespace Barotrauma
|
||||
break;
|
||||
}
|
||||
|
||||
float dist = Vector2.Distance(limb.SimPosition, damageTarget.SimPosition);
|
||||
float dist = ConvertUnits.ToDisplayUnits(Vector2.Distance(limb.SimPosition, attackPosition));
|
||||
if (dist < limb.attack.Range * 0.5f)
|
||||
{
|
||||
attackTimer += deltaTime;
|
||||
limb.body.ApplyTorque(limb.Mass * 50.0f * Character.AnimController.Dir * dir);
|
||||
|
||||
|
||||
limb.attack.DoDamage(Character, damageTarget, limb.SimPosition, deltaTime, (limb.soundTimer <= 0.0f));
|
||||
|
||||
limb.soundTimer = Limb.SoundInterval;
|
||||
@@ -392,9 +403,8 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
dist = Vector2.Distance(
|
||||
character.AnimController.Limbs[0].SimPosition,
|
||||
target.SimPosition);
|
||||
dist = ConvertUnits.ToDisplayUnits(dist);
|
||||
character.WorldPosition,
|
||||
target.WorldPosition);
|
||||
|
||||
AITargetMemory targetMemory = FindTargetMemory(target);
|
||||
|
||||
@@ -406,6 +416,11 @@ namespace Barotrauma
|
||||
Vector2 rayStart = character.AnimController.Limbs[0].SimPosition;
|
||||
Vector2 rayEnd = target.SimPosition;
|
||||
|
||||
if (target.Entity.Submarine != null && character.Submarine==null)
|
||||
{
|
||||
rayStart -= ConvertUnits.ToSimUnits(target.Entity.Submarine.Position);
|
||||
}
|
||||
|
||||
Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd);
|
||||
Structure closestStructure = (closestBody == null) ? null : closestBody.UserData as Structure;
|
||||
|
||||
@@ -490,12 +505,12 @@ namespace Barotrauma
|
||||
{
|
||||
if (Character.IsDead) return;
|
||||
|
||||
Vector2 pos = Character.Position;
|
||||
Vector2 pos = Character.WorldPosition;
|
||||
pos.Y = -pos.Y;
|
||||
|
||||
if (selectedAiTarget!=null)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch, pos, ConvertUnits.ToDisplayUnits(new Vector2(selectedAiTarget.SimPosition.X, -selectedAiTarget.SimPosition.Y)), Color.Red);
|
||||
GUI.DrawLine(spriteBatch, pos, new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red);
|
||||
|
||||
if (wallAttackPos!=Vector2.Zero)
|
||||
{
|
||||
|
||||
@@ -87,7 +87,9 @@ namespace Barotrauma
|
||||
{
|
||||
if (selectedAiTarget != null)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch, new Vector2(Character.Position.X, -Character.Position.Y), ConvertUnits.ToDisplayUnits(new Vector2(selectedAiTarget.SimPosition.X, -selectedAiTarget.SimPosition.Y)), Color.Red);
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(Character.WorldPosition.X, -Character.WorldPosition.Y),
|
||||
new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red);
|
||||
}
|
||||
|
||||
IndoorsSteeringManager pathSteering = steeringManager as IndoorsSteeringManager;
|
||||
|
||||
@@ -89,8 +89,8 @@ namespace Barotrauma
|
||||
|
||||
foreach (WayPoint wp in WayPoint.WayPointList)
|
||||
{
|
||||
if (wp.SpawnType != SpawnType.Human) continue;
|
||||
|
||||
if (wp.SpawnType != SpawnType.Human || wp.CurrentHull==null) continue;
|
||||
|
||||
foreach (string tag in wp.IdCardTags)
|
||||
{
|
||||
if (idCard.HasTag(tag)) return wp.CurrentHull.AiTarget;
|
||||
|
||||
@@ -536,11 +536,11 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public void FindHull(bool setSubmarine = true)
|
||||
public void FindHull(Vector2? worldPosition = null, bool setSubmarine = true)
|
||||
{
|
||||
Hull newHull = Hull.FindHull(
|
||||
ConvertUnits.ToDisplayUnits(refLimb.SimPosition),
|
||||
currentHull);
|
||||
Vector2 findPos = worldPosition==null ? refLimb.WorldPosition : (Vector2)worldPosition;
|
||||
|
||||
Hull newHull = Hull.FindHull(findPos, currentHull);
|
||||
|
||||
if (newHull == currentHull) return;
|
||||
|
||||
@@ -619,11 +619,9 @@ namespace Barotrauma
|
||||
|
||||
foreach (Limb limb in Limbs)
|
||||
{
|
||||
Vector2 limbPosition = ConvertUnits.ToDisplayUnits(limb.SimPosition);
|
||||
|
||||
//find the room which the limb is in
|
||||
//the room where the ragdoll is in is used as the "guess", meaning that it's checked first
|
||||
Hull limbHull = Hull.FindHull(limbPosition, currentHull);
|
||||
Hull limbHull = Hull.FindHull(limb.WorldPosition, currentHull);
|
||||
|
||||
bool prevInWater = limb.inWater;
|
||||
limb.inWater = false;
|
||||
@@ -633,9 +631,9 @@ namespace Barotrauma
|
||||
//limb isn't in any room -> it's in the water
|
||||
limb.inWater = true;
|
||||
}
|
||||
else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limbPosition))
|
||||
{
|
||||
if (limbPosition.Y < limbHull.Surface)
|
||||
else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limb.Position))
|
||||
{
|
||||
if (limb.Position.Y < limbHull.Surface)
|
||||
{
|
||||
limb.inWater = true;
|
||||
|
||||
@@ -659,12 +657,12 @@ namespace Barotrauma
|
||||
|
||||
//create a splash particle
|
||||
GameMain.ParticleManager.CreateParticle("watersplash",
|
||||
new Vector2(limb.Position.X, limbHull.Surface),
|
||||
new Vector2(limb.Position.X, limbHull.Surface) + limbHull.Submarine.Position,
|
||||
new Vector2(0.0f, Math.Abs(-limb.LinearVelocity.Y * 10.0f)),
|
||||
0.0f, limbHull);
|
||||
|
||||
|
||||
GameMain.ParticleManager.CreateParticle("bubbles",
|
||||
new Vector2(limb.Position.X, limbHull.Surface),
|
||||
new Vector2(limb.Position.X, limbHull.Surface) + limbHull.Submarine.Position,
|
||||
limb.LinearVelocity*0.001f,
|
||||
0.0f, limbHull);
|
||||
|
||||
@@ -678,7 +676,7 @@ namespace Barotrauma
|
||||
float parallel = (float)Math.Abs(Math.Sin(limb.Rotation));
|
||||
Vector2 impulse = Vector2.Multiply(limb.LinearVelocity, -parallel * limb.Mass);
|
||||
//limb.body.ApplyLinearImpulse(impulse);
|
||||
int n = (int)((limbPosition.X - limbHull.Rect.X) / Hull.WaveWidth);
|
||||
int n = (int)((limb.Position.X - limbHull.Rect.X) / Hull.WaveWidth);
|
||||
limbHull.WaveVel[n] = Math.Min(impulse.Y * 1.0f, 5.0f);
|
||||
StrongestImpact = ((impulse.Length() * 0.5f) - limb.impactTolerance);
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Barotrauma
|
||||
sound = Sound.Load(soundPath);
|
||||
}
|
||||
|
||||
Range = FarseerPhysics.ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "range", 0.0f));
|
||||
Range = ToolBox.GetAttributeFloat(element, "range", 0.0f);
|
||||
|
||||
Duration = ToolBox.GetAttributeFloat(element, "duration", 0.0f);
|
||||
|
||||
|
||||
@@ -153,15 +153,15 @@ namespace Barotrauma
|
||||
if (velocity.X < 0.0f) rotation -= MathHelper.Pi;
|
||||
}
|
||||
|
||||
if (Level.Loaded != null) drawPosition = position;// +Level.Loaded.Position;
|
||||
drawPosition = position;// +Level.Loaded.Position;
|
||||
|
||||
if (depth > 0.0f)
|
||||
{
|
||||
Vector2 camOffset = drawPosition - GameMain.GameScreen.Cam.WorldViewCenter;
|
||||
|
||||
drawPosition = drawPosition - camOffset * (depth / MaxDepth) * 0.05f;
|
||||
drawPosition -= camOffset * (depth / MaxDepth) * 0.05f;
|
||||
}
|
||||
|
||||
|
||||
prefab.Sprite.Draw(spriteBatch, new Vector2(drawPosition.X, -drawPosition.Y), Color.Lerp(Color.White, Color.DarkBlue, (depth/MaxDepth)*0.3f),
|
||||
rotation, 1.0f - (depth / MaxDepth) * 0.2f, velocity.X > 0.0f ? SpriteEffects.None : SpriteEffects.FlipHorizontally, (depth / MaxDepth));
|
||||
}
|
||||
|
||||
@@ -47,9 +47,10 @@ namespace Barotrauma
|
||||
|
||||
if (position == null)
|
||||
{
|
||||
if (WayPoint.WayPointList.Count>0)
|
||||
var wayPoints = WayPoint.WayPointList.FindAll(wp => wp.Submarine==null);
|
||||
if (wayPoints.Any())
|
||||
{
|
||||
WayPoint wp = WayPoint.WayPointList[Rand.Int(WayPoint.WayPointList.Count)];
|
||||
WayPoint wp = wayPoints[Rand.Int(wayPoints.Count)];
|
||||
|
||||
pos = new Vector2(wp.Rect.X, wp.Rect.Y);
|
||||
pos += Rand.Vector(200.0f);
|
||||
|
||||
@@ -138,6 +138,11 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 CursorWorldPosition
|
||||
{
|
||||
get { return Submarine == null ? cursorPosition : cursorPosition + Submarine.Position; }
|
||||
}
|
||||
|
||||
public Character ClosestCharacter
|
||||
{
|
||||
get { return closestCharacter; }
|
||||
@@ -295,7 +300,7 @@ namespace Barotrauma
|
||||
|
||||
public static Character Create(CharacterInfo characterInfo, WayPoint spawnPoint, bool isNetworkPlayer = false)
|
||||
{
|
||||
return Create(characterInfo.File, spawnPoint.SimPosition, characterInfo, isNetworkPlayer);
|
||||
return Create(characterInfo.File, spawnPoint.WorldPosition, characterInfo, isNetworkPlayer);
|
||||
}
|
||||
|
||||
|
||||
@@ -393,7 +398,7 @@ namespace Barotrauma
|
||||
|
||||
foreach (Limb limb in AnimController.Limbs)
|
||||
{
|
||||
limb.body.SetTransform(position+limb.SimPosition, 0.0f);
|
||||
limb.body.SetTransform(ConvertUnits.ToSimUnits(position)+limb.SimPosition, 0.0f);
|
||||
//limb.prevPosition = ConvertUnits.ToDisplayUnits(position);
|
||||
}
|
||||
|
||||
@@ -443,7 +448,8 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
AnimController.FindHull(false);
|
||||
AnimController.FindHull(null, false);
|
||||
if (AnimController.CurrentHull != null) Submarine = AnimController.CurrentHull.Submarine;
|
||||
|
||||
CharacterList.Add(this);
|
||||
|
||||
@@ -735,7 +741,7 @@ namespace Barotrauma
|
||||
{
|
||||
Limb head = AnimController.GetLimb(LimbType.Head);
|
||||
|
||||
Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(WorldPosition);
|
||||
Lights.LightManager.ViewPos = WorldPosition;
|
||||
|
||||
if (!DisableControls)
|
||||
{
|
||||
@@ -1004,7 +1010,7 @@ namespace Barotrauma
|
||||
AnimController.DebugDraw(spriteBatch);
|
||||
}
|
||||
|
||||
Vector2 healthBarPos = new Vector2(Position.X - 50, -Position.Y - 100.0f);
|
||||
Vector2 healthBarPos = new Vector2(WorldPosition.X - 50, -WorldPosition.Y - 100.0f);
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X - 2, (int)healthBarPos.Y - 2, 100 + 4, 15 + 4), Color.Black, false);
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X, (int)healthBarPos.Y, (int)(100.0f * (health / maxHealth)), 15), Color.Red, true);
|
||||
}
|
||||
@@ -1102,12 +1108,12 @@ namespace Barotrauma
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Particle p = GameMain.ParticleManager.CreateParticle("waterblood",
|
||||
centerOfMass + Rand.Vector(50.0f),
|
||||
ConvertUnits.ToDisplayUnits(centerOfMass) + Rand.Vector(50.0f),
|
||||
Vector2.Zero);
|
||||
if (p!=null) p.Size *= 2.0f;
|
||||
|
||||
GameMain.ParticleManager.CreateParticle("bubbles",
|
||||
centerOfMass + Rand.Vector(50.0f),
|
||||
ConvertUnits.ToDisplayUnits(centerOfMass) + Rand.Vector(50.0f),
|
||||
new Vector2(Rand.Range(-50f, 50f), Rand.Range(-100f,50f)));
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,11 @@ namespace Barotrauma
|
||||
get { return doesFlip; }
|
||||
}
|
||||
|
||||
public Vector2 WorldPosition
|
||||
{
|
||||
get { return character.Submarine == null ? Position : Position + character.Submarine.Position; }
|
||||
}
|
||||
|
||||
public Vector2 Position
|
||||
{
|
||||
get { return ConvertUnits.ToDisplayUnits(body.SimPosition); }
|
||||
@@ -352,13 +357,13 @@ namespace Barotrauma
|
||||
if (particleVel != Vector2.Zero) particleVel = Vector2.Normalize(particleVel);
|
||||
|
||||
GameMain.ParticleManager.CreateParticle("blood",
|
||||
Position,
|
||||
WorldPosition,
|
||||
particleVel * Rand.Range(100.0f, 300.0f), 0.0f, character.AnimController.CurrentHull);
|
||||
}
|
||||
|
||||
for (int i = 0; i < bloodAmount / 2; i++)
|
||||
{
|
||||
GameMain.ParticleManager.CreateParticle("waterblood", Position, Vector2.Zero, 0.0f, character.AnimController.CurrentHull);
|
||||
GameMain.ParticleManager.CreateParticle("waterblood", WorldPosition, Vector2.Zero, 0.0f, character.AnimController.CurrentHull);
|
||||
}
|
||||
|
||||
damage += Math.Max(amount,bleedingAmount) / character.MaxHealth * 100.0f;
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace Barotrauma
|
||||
|
||||
protected virtual void Apply(float deltaTime, Entity entity, List<IPropertyObject> targets)
|
||||
{
|
||||
if (explosion != null) explosion.Explode(entity.SimPosition);
|
||||
if (explosion != null) explosion.Explode(entity.WorldPosition);
|
||||
if (Fire) new FireSource(ConvertUnits.ToDisplayUnits(entity.SimPosition));
|
||||
|
||||
if (sound != null) sound.Play(1.0f, 1000.0f, ConvertUnits.ToDisplayUnits(entity.SimPosition));
|
||||
|
||||
Reference in New Issue
Block a user