WIP CrashReporter, misc refactoring

This commit is contained in:
Regalis
2015-09-19 15:14:47 +03:00
parent 16bf562837
commit f6966f06c3
86 changed files with 1616 additions and 631 deletions
@@ -23,12 +23,12 @@ namespace Subsurface
public Vector2 Position
{
get { return Character.AnimController.limbs[0].SimPosition; }
get { return Character.AnimController.Limbs[0].SimPosition; }
}
public Vector2 Velocity
{
get { return Character.AnimController.limbs[0].LinearVelocity; }
get { return Character.AnimController.Limbs[0].LinearVelocity; }
}
public AiState State
@@ -145,7 +145,7 @@ namespace Subsurface
private void UpdateDistanceAccumulator()
{
Limb limb = Character.AnimController.limbs[0];
Limb limb = Character.AnimController.Limbs[0];
distanceAccumulator += (limb.SimPosition - prevPosition).Length();
prevPosition = limb.body.SimPosition;
@@ -187,7 +187,7 @@ namespace Subsurface
//check if any of the limbs is close enough to attack the target
if (attackingLimb == null)
{
foreach (Limb limb in Character.AnimController.limbs)
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;
@@ -210,7 +210,7 @@ namespace Subsurface
//System.Diagnostics.Debug.WriteLine("cooldown");
if (selectedAiTarget.Entity is Hull ||
Vector2.Distance(attackPosition, Character.AnimController.limbs[0].SimPosition) < ConvertUnits.ToSimUnits(500.0f))
Vector2.Distance(attackPosition, Character.AnimController.Limbs[0].SimPosition) < ConvertUnits.ToSimUnits(500.0f))
{
steeringManager.SteeringSeek(attackPosition, -0.8f);
steeringManager.SteeringAvoid(deltaTime, 1.0f);
@@ -226,7 +226,7 @@ namespace Subsurface
{
targetEntity = null;
//check if there's a wall between the target and the character
Vector2 rayStart = Character.AnimController.limbs[0].SimPosition;
Vector2 rayStart = Character.AnimController.Limbs[0].SimPosition;
Vector2 rayEnd = selectedAiTarget.Position;
Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd);
@@ -372,7 +372,7 @@ namespace Subsurface
}
dist = Vector2.Distance(
character.AnimController.limbs[0].SimPosition,
character.AnimController.Limbs[0].SimPosition,
target.Position);
dist = ConvertUnits.ToDisplayUnits(dist);
@@ -383,7 +383,7 @@ namespace Subsurface
if (Math.Abs(valueModifier) > Math.Abs(targetValue) && (dist < target.SightRange * sight || dist < target.SoundRange * hearing))
{
Vector2 rayStart = character.AnimController.limbs[0].SimPosition;
Vector2 rayStart = character.AnimController.Limbs[0].SimPosition;
Vector2 rayEnd = target.Position;
Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd);
+216
View File
@@ -0,0 +1,216 @@
using Lidgren.Network;
using Microsoft.Xna.Framework;
using Subsurface.Networking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Subsurface
{
class AICharacter : Character
{
private AIController aiController;
public AICharacter(string file) : this(file, Vector2.Zero, null)
{
}
public AICharacter(string file, Vector2 position)
: this(file, position, null)
{
}
public AICharacter(CharacterInfo characterInfo, WayPoint spawnPoint, bool isNetworkPlayer = false)
: this(characterInfo.File, spawnPoint.SimPosition, characterInfo, isNetworkPlayer)
{
}
public AICharacter(CharacterInfo characterInfo, Vector2 position, bool isNetworkPlayer = false)
: this(characterInfo.File, position, characterInfo, isNetworkPlayer)
{
}
public AICharacter(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false)
: base(file, position, characterInfo, isNetworkPlayer)
{
aiController = new EnemyAIController(this, file);
}
public override void Update(Camera cam, float deltaTime)
{
base.Update(cam, deltaTime);
if (isDead) return;
if (soundTimer > 0)
{
soundTimer -= deltaTime;
}
else
{
PlaySound((aiController == null) ? AIController.AiState.None : aiController.State);
soundTimer = soundInterval;
}
aiController.Update(deltaTime);
}
public override void FillNetworkData(NetworkEventType type, NetOutgoingMessage message, object data)
{
if (type == NetworkEventType.KillCharacter)
{
return;
}
message.Write((float)NetTime.Now);
message.Write(LargeUpdateTimer <= 0);
message.Write(AnimController.TargetDir == Direction.Right);
message.Write(AnimController.TargetMovement.X);
message.Write(AnimController.TargetMovement.Y);
if (LargeUpdateTimer <= 0)
{
int i = 0;
foreach (Limb limb in AnimController.Limbs)
{
message.Write(limb.body.SimPosition.X);
message.Write(limb.body.SimPosition.Y);
message.Write(limb.body.Rotation);
i++;
}
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer, 0.0f, 60.0f), 0.0f, 60.0f, 8);
message.Write((byte)((health / maxHealth) * 255.0f));
aiController.FillNetworkData(message);
LargeUpdateTimer = 10;
}
else
{
message.Write(AnimController.RefLimb.SimPosition.X);
message.Write(AnimController.RefLimb.SimPosition.Y);
LargeUpdateTimer = Math.Max(0, LargeUpdateTimer - 1);
}
}
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message)
{
if (type == NetworkEventType.KillCharacter)
{
Kill(true);
return;
}
float sendingTime = 0.0f;
Vector2 targetMovement = Vector2.Zero;
bool targetDir = false;
bool isLargeUpdate;
try
{
sendingTime = message.ReadFloat();
isLargeUpdate = message.ReadBoolean();
}
catch
{
return;
}
if (sendingTime <= LastNetworkUpdate) return;
try
{
targetDir = message.ReadBoolean();
targetMovement.X = message.ReadFloat();
targetMovement.Y = message.ReadFloat();
}
catch
{
return;
}
AnimController.TargetDir = (targetDir) ? Direction.Right : Direction.Left;
AnimController.TargetMovement = targetMovement;
if (isLargeUpdate)
{
foreach (Limb limb in AnimController.Limbs)
{
Vector2 pos = Vector2.Zero, vel = Vector2.Zero;
float rotation = 0.0f;
try
{
pos.X = message.ReadFloat();
pos.Y = message.ReadFloat();
rotation = message.ReadFloat();
}
catch
{
return;
}
if (limb.body != null)
{
limb.body.TargetVelocity = limb.body.LinearVelocity;
limb.body.TargetPosition = pos;// +vel * (float)(deltaTime / 60.0);
limb.body.TargetRotation = rotation;// +angularVel * (float)(deltaTime / 60.0);
limb.body.TargetAngularVelocity = limb.body.AngularVelocity;
}
}
float newStunTimer = 0.0f, newHealth = 0.0f;
try
{
newStunTimer = message.ReadRangedSingle(0.0f, 60.0f, 8);
newHealth = (message.ReadByte() / 255.0f) * maxHealth;
}
catch { return; }
AnimController.StunTimer = newStunTimer;
Health = newHealth;
LargeUpdateTimer = 1;
aiController.ReadNetworkData(message);
}
else
{
Vector2 pos = Vector2.Zero;
try
{
pos.X = message.ReadFloat();
pos.Y = message.ReadFloat();
}
catch { return; }
Limb torso = AnimController.GetLimb(LimbType.Torso);
if (torso == null) torso = AnimController.GetLimb(LimbType.Head);
torso.body.TargetPosition = pos;
LargeUpdateTimer = 0;
}
LastNetworkUpdate = sendingTime;
}
}
}
@@ -147,7 +147,7 @@ namespace Subsurface
if (depth > 0.0f)
{
Vector2 camOffset = drawPos - Game1.GameScreen.Cam.WorldViewCenter;
Vector2 camOffset = drawPos - GameMain.GameScreen.Cam.WorldViewCenter;
drawPos = drawPos - camOffset * (depth / MaxDepth) * 0.05f;
}
+67 -100
View File
@@ -56,7 +56,6 @@ namespace Subsurface
private Item[] selectedItems;
public AnimController AnimController;
private AIController aiController;
private Vector2 cursorPosition;
@@ -246,9 +245,9 @@ namespace Subsurface
get { return closestItem; }
}
public AIController AIController
public virtual AIController AIController
{
get { return aiController; }
get { return null; }
}
public bool IsDead
@@ -258,12 +257,12 @@ namespace Subsurface
public override Vector2 SimPosition
{
get { return AnimController.limbs[0].SimPosition; }
get { return AnimController.Limbs[0].SimPosition; }
}
public Vector2 Position
{
get { return ConvertUnits.ToDisplayUnits(AnimController.limbs[0].SimPosition); }
get { return ConvertUnits.ToDisplayUnits(AnimController.Limbs[0].SimPosition); }
}
public Character(string file) : this(file, Vector2.Zero, null)
@@ -332,11 +331,9 @@ namespace Subsurface
AnimController = new FishAnimController(this, doc.Root.Element("ragdoll"));
PressureProtection = 100.0f;
//FishAnimController fishAnim = (FishAnimController)animController;
aiController = new EnemyAIController(this, file);
}
foreach (Limb limb in AnimController.limbs)
foreach (Limb limb in AnimController.Limbs)
{
limb.body.SetTransform(position+limb.SimPosition, 0.0f);
//limb.prevPosition = ConvertUnits.ToDisplayUnits(position);
@@ -397,7 +394,7 @@ namespace Subsurface
{
if (string.IsNullOrEmpty(humanConfigFile))
{
var characterFiles = Game1.SelectedPackage.GetFilesOfType(ContentType.Character);
var characterFiles = GameMain.SelectedPackage.GetFilesOfType(ContentType.Character);
humanConfigFile = characterFiles.Find(c => c.EndsWith("human.xml"));
if (humanConfigFile == null)
@@ -632,15 +629,15 @@ namespace Subsurface
if (moveCam)
{
cam.TargetPos = ConvertUnits.ToDisplayUnits(AnimController.limbs[0].SimPosition);
cam.TargetPos = ConvertUnits.ToDisplayUnits(AnimController.Limbs[0].SimPosition);
cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, 250.0f, 0.05f);
}
cursorPosition = cam.ScreenToWorld(PlayerInput.MousePosition);
Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cursorPosition);
if (Vector2.Distance(AnimController.limbs[0].SimPosition, mouseSimPos)>1.0f)
if (Vector2.Distance(AnimController.Limbs[0].SimPosition, mouseSimPos)>1.0f)
{
Body body = Submarine.PickBody(AnimController.limbs[0].SimPosition, mouseSimPos);
Body body = Submarine.PickBody(AnimController.Limbs[0].SimPosition, mouseSimPos);
Structure structure = null;
if (body != null) structure = body.UserData as Structure;
if (structure != null)
@@ -678,7 +675,7 @@ namespace Subsurface
}
}
public void Update(Camera cam, float deltaTime)
public virtual void Update(Camera cam, float deltaTime)
{
if (isDead) return;
@@ -714,22 +711,13 @@ namespace Subsurface
PressureProtection -= deltaTime*100.0f;
}
if (soundTimer > 0)
{
soundTimer -= deltaTime;
}
else
{
PlaySound((aiController == null) ? AIController.AiState.None : aiController.State);
soundTimer = soundInterval;
}
//foreach (Limb limb in animController.limbs)
//{
Health = health - bleeding * deltaTime;
//}
if (aiController != null) aiController.Update(deltaTime);
}
private void UpdateSightRange()
@@ -738,7 +726,7 @@ namespace Subsurface
//distance is approximated based on the mass of the character
//(which corresponds to size because all the characters have the same limb density)
foreach (Limb limb in AnimController.limbs)
foreach (Limb limb in AnimController.Limbs)
{
aiTarget.SightRange += limb.Mass * 1000.0f;
}
@@ -761,7 +749,7 @@ namespace Subsurface
public void DrawFront(SpriteBatch spriteBatch)
{
Vector2 pos = ConvertUnits.ToDisplayUnits(AnimController.limbs[0].SimPosition);
Vector2 pos = ConvertUnits.ToDisplayUnits(AnimController.Limbs[0].SimPosition);
pos.Y = -pos.Y;
if (this == Character.controlled) return;
@@ -772,7 +760,7 @@ namespace Subsurface
spriteBatch.DrawString(GUI.Font, Info.Name, namePos - new Vector2(1.0f, 1.0f), Color.Black);
spriteBatch.DrawString(GUI.Font, Info.Name, namePos, Color.White);
if (Game1.DebugDraw)
if (GameMain.DebugDraw)
{
spriteBatch.DrawString(GUI.Font, ID.ToString(), namePos - new Vector2(0.0f, 20.0f), Color.White);
}
@@ -790,9 +778,9 @@ namespace Subsurface
if (drowningBar == null)
{
int width = 100, height = 20;
drowningBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight / 2, width, height), Color.Blue, 1.0f);
drowningBar = new GUIProgressBar(new Rectangle(20, GameMain.GraphicsHeight / 2, width, height), Color.Blue, 1.0f);
healthBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight / 2 + 30, width, height), Color.Red, 1.0f);
healthBar = new GUIProgressBar(new Rectangle(20, GameMain.GraphicsHeight / 2 + 30, width, height), Color.Red, 1.0f);
}
drowningBar.BarSize = Controlled.Oxygen / 100.0f;
@@ -860,7 +848,7 @@ namespace Subsurface
if (n == selectedSound && sounds[i]!=null)
{
sounds[i].Play(1.0f, 2000.0f,
AnimController.limbs[0].body.FarseerBody);
AnimController.Limbs[0].body.FarseerBody);
Debug.WriteLine("playing: " + sounds[i]);
return;
}
@@ -874,7 +862,7 @@ namespace Subsurface
Limb closestLimb = null;
float closestDistance = 0.0f;
foreach (Limb limb in AnimController.limbs)
foreach (Limb limb in AnimController.Limbs)
{
float distance = Vector2.Distance(position, limb.SimPosition);
if (closestLimb == null || distance < closestDistance)
@@ -915,7 +903,7 @@ namespace Subsurface
health = 0.0f;
foreach (Limb limb in AnimController.limbs)
foreach (Limb limb in AnimController.Limbs)
{
Vector2 diff = centerOfMass - limb.SimPosition;
if (diff == Vector2.Zero) continue;
@@ -927,12 +915,12 @@ namespace Subsurface
for (int i = 0; i < 10; i++)
{
Particle p = Game1.ParticleManager.CreateParticle("waterblood",
Particle p = GameMain.ParticleManager.CreateParticle("waterblood",
centerOfMass + Rand.Vector(50.0f),
Vector2.Zero);
if (p!=null) p.Size *= 2.0f;
Game1.ParticleManager.CreateParticle("bubbles",
GameMain.ParticleManager.CreateParticle("bubbles",
centerOfMass + Rand.Vector(50.0f),
new Vector2(Rand.Range(-50f, 50f), Rand.Range(-100f,50f)));
}
@@ -949,20 +937,22 @@ namespace Subsurface
float dimDuration = 8.0f;
float timer = 0.0f;
Color prevAmbientLight = Game1.LightManager.AmbientLight;
Color prevAmbientLight = GameMain.LightManager.AmbientLight;
while (timer < dimDuration)
{
AnimController.UpdateAnim(1.0f / 60.0f);
timer += 1.0f / 60.0f;
if (cam != null)
if (Character.controlled == this)
{
cam.TargetPos = ConvertUnits.ToDisplayUnits(AnimController.limbs[0].SimPosition);
cam.OffsetAmount = 0.0f;
}
if (cam != null)
{
cam.TargetPos = ConvertUnits.ToDisplayUnits(AnimController.Limbs[0].SimPosition);
cam.OffsetAmount = 0.0f;
}
Game1.LightManager.AmbientLight = Color.Lerp(prevAmbientLight, Color.DarkGray, timer / dimDuration);
GameMain.LightManager.AmbientLight = Color.Lerp(prevAmbientLight, Color.DarkGray, timer / dimDuration);
}
yield return CoroutineStatus.Running;
}
@@ -977,7 +967,7 @@ namespace Subsurface
{
lerpLightBack = Math.Min(lerpLightBack+0.05f,1.0f);
Game1.LightManager.AmbientLight = Color.Lerp(Color.DarkGray, prevAmbientLight, lerpLightBack);
GameMain.LightManager.AmbientLight = Color.Lerp(Color.DarkGray, prevAmbientLight, lerpLightBack);
yield return CoroutineStatus.Running;
}
@@ -989,7 +979,7 @@ namespace Subsurface
if (isDead) return;
//if the game is run by a client, characters are only killed when the server says so
if (Game1.Client != null)
if (GameMain.Client != null)
{
if (networkMessage)
{
@@ -1001,7 +991,7 @@ namespace Subsurface
}
}
CoroutineManager.StartCoroutine(DeathAnim(Game1.GameScreen.Cam));
CoroutineManager.StartCoroutine(DeathAnim(GameMain.GameScreen.Cam));
health = 0.0f;
@@ -1017,7 +1007,7 @@ namespace Subsurface
aiTarget.Remove();
aiTarget = null;
foreach (Limb limb in AnimController.limbs)
foreach (Limb limb in AnimController.Limbs)
{
if (limb.pullJoint == null) continue;
limb.pullJoint.Enabled = false;
@@ -1029,14 +1019,14 @@ namespace Subsurface
joint.MaxMotorTorque = 0.0f;
}
if (Game1.Server != null)
if (GameMain.Server != null)
{
new NetworkEvent(NetworkEventType.KillCharacter, ID, false);
}
if (Game1.GameSession != null)
if (GameMain.GameSession != null)
{
Game1.GameSession.KillCharacter(this);
GameMain.GameSession.KillCharacter(this);
}
}
@@ -1053,16 +1043,21 @@ namespace Subsurface
return;
}
var hasInputs = (GetInputState(InputType.Left) ||
GetInputState(InputType.Right) ||
GetInputState(InputType.Up) ||
GetInputState(InputType.Down) ||
GetInputState(InputType.ActionHeld) ||
GetInputState(InputType.SecondaryHeld));
var hasInputs =
(GetInputState(InputType.Left) ||
GetInputState(InputType.Right) ||
GetInputState(InputType.Up) ||
GetInputState(InputType.Down) ||
GetInputState(InputType.ActionHeld) ||
GetInputState(InputType.SecondaryHeld));
message.Write(hasInputs || LargeUpdateTimer <= 0);
message.Write((float)NetTime.Now);
// Write byte = move direction
//message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -10.0f, 10.0f), -10.0f, 10.0f, 8);
//message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.Y, -10.0f, 10.0f), -10.0f, 10.0f, 8);
message.Write(keys[(int)InputType.ActionHeld].Dequeue);
message.Write(keys[(int)InputType.SecondaryHeld].Dequeue);
@@ -1074,27 +1069,16 @@ namespace Subsurface
message.Write(keys[(int)InputType.Down].Dequeue);
message.Write(keys[(int)InputType.Run].Dequeue);
// Write byte = move direction
//message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -10.0f, 10.0f), -10.0f, 10.0f, 8);
//message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.Y, -10.0f, 10.0f), -10.0f, 10.0f, 8);
if (aiController==null)
{
message.Write(cursorPosition.X);
message.Write(cursorPosition.Y);
}
else
{
message.Write(AnimController.TargetDir == Direction.Right);
}
message.Write(cursorPosition.X);
message.Write(cursorPosition.Y);
message.Write(LargeUpdateTimer <= 0);
if (LargeUpdateTimer<=0)
{
int i = 0;
foreach (Limb limb in AnimController.limbs)
foreach (Limb limb in AnimController.Limbs)
{
message.Write(limb.body.SimPosition.X);
message.Write(limb.body.SimPosition.Y);
@@ -1110,8 +1094,6 @@ namespace Subsurface
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer,0.0f,60.0f), 0.0f, 60.0f, 8);
message.Write((byte)((health/maxHealth)*255.0f));
if (aiController != null) aiController.FillNetworkData(message);
LargeUpdateTimer = 10;
}
else
@@ -1150,10 +1132,10 @@ namespace Subsurface
else if (type == NetworkEventType.KillCharacter)
{
Kill(true);
if (Game1.NetworkMember != null && controlled == this)
if (GameMain.NetworkMember != null && controlled == this)
{
Game1.Client.AddChatMessage("YOU HAVE DIED. Your chat messages will only be visible to other dead players.", ChatMessageType.Dead);
Game1.LightManager.LosEnabled = false;
GameMain.Client.AddChatMessage("YOU HAVE DIED. Your chat messages will only be visible to other dead players.", ChatMessageType.Dead);
GameMain.LightManager.LosEnabled = false;
}
return;
}
@@ -1161,8 +1143,6 @@ namespace Subsurface
bool actionKeyState = false;
bool secondaryKeyState = false;
float sendingTime = 0.0f;
//Vector2 targetMovement = Vector2.Zero;
bool targetDir = false;
Vector2 cursorPos = Vector2.Zero;
bool leftKeyState = false, rightKeyState = false;
@@ -1211,37 +1191,26 @@ namespace Subsurface
keys[(int)InputType.Down].State = downKeyState;
keys[(int)InputType.Run].State = runState;
bool isLargeUpdate;
try
{
if (aiController == null)
{
cursorPos = new Vector2(
message.ReadFloat(),
message.ReadFloat());
}
else
{
targetDir = message.ReadBoolean();
}
cursorPos = new Vector2(
message.ReadFloat(),
message.ReadFloat());
isLargeUpdate = message.ReadBoolean();
}
catch
{
return;
}
if (aiController == null)
cursorPosition = cursorPos;
if (isLargeUpdate)
{
cursorPosition = cursorPos;
}
else
{
AnimController.TargetDir = (targetDir) ? Direction.Right : Direction.Left;
}
if (message.ReadBoolean())
{
foreach (Limb limb in AnimController.limbs)
foreach (Limb limb in AnimController.Limbs)
{
Vector2 pos = Vector2.Zero, vel = Vector2.Zero;
float rotation = 0.0f;
@@ -1285,8 +1254,6 @@ namespace Subsurface
Health = newHealth;
LargeUpdateTimer = 1;
if (aiController != null) aiController.ReadNetworkData(message);
}
else
{
@@ -1319,7 +1286,7 @@ namespace Subsurface
if (controlled == this) controlled = null;
if (Game1.Client!=null && Game1.Client.Character == this) Game1.Client.Character = null;
if (GameMain.Client!=null && GameMain.Client.Character == this) GameMain.Client.Character = null;
if (inventory != null) inventory.Remove();
@@ -50,7 +50,7 @@ namespace Subsurface
{
if (character.IsDead)
{
UpdateStruggling(deltaTime);
UpdateDying(deltaTime);
return;
}
@@ -64,7 +64,7 @@ namespace Subsurface
if (stunTimer>0.0f)
{
UpdateStruggling(deltaTime);
//UpdateStruggling(deltaTime);
stunTimer -= deltaTime;
return;
}
@@ -185,18 +185,18 @@ namespace Subsurface
if (!inWater) steerForce.Y = 0.0f;
}
for (int i = 0; i < limbs.Count(); i++)
for (int i = 0; i < Limbs.Count(); i++)
{
if (steerForce!=Vector2.Zero)
limbs[i].body.ApplyForce(steerForce * limbs[i].SteerForce * limbs[i].Mass);
Limbs[i].body.ApplyForce(steerForce * Limbs[i].SteerForce * Limbs[i].Mass);
if (limbs[i].type != LimbType.Torso) continue;
if (Limbs[i].type != LimbType.Torso) continue;
float dist = (limbs[0].SimPosition - limbs[i].SimPosition).Length();
float dist = (Limbs[0].SimPosition - Limbs[i].SimPosition).Length();
Vector2 limbPos = limbs[0].SimPosition - Vector2.Normalize(movement) * dist;
Vector2 limbPos = Limbs[0].SimPosition - Vector2.Normalize(movement) * dist;
limbs[i].body.ApplyForce(((limbPos - limbs[i].SimPosition) * 3.0f - limbs[i].LinearVelocity * 3.0f) * limbs[i].Mass);
Limbs[i].body.ApplyForce(((limbPos - Limbs[i].SimPosition) * 3.0f - Limbs[i].LinearVelocity * 3.0f) * Limbs[i].Mass);
}
if (!inWater)
@@ -205,7 +205,7 @@ namespace Subsurface
}
else
{
floorY = limbs[0].SimPosition.Y;
floorY = Limbs[0].SimPosition.Y;
}
}
@@ -247,7 +247,7 @@ namespace Subsurface
//out whether the ragdoll is standing on ground
float closestFraction = 1;
//Structure closestStructure = null;
Game1.World.RayCast((fixture, point, normal, fraction) =>
GameMain.World.RayCast((fixture, point, normal, fraction) =>
{
//other limbs and bodies with no collision detection are ignored
if (fixture == null ||
@@ -301,7 +301,7 @@ namespace Subsurface
(float)Math.Cos(walkPos) * stepSize.X * 3.0f,
(float)Math.Sin(walkPos) * stepSize.Y * 2.0f);
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
switch (limb.type)
{
@@ -343,7 +343,7 @@ namespace Subsurface
}
}
void UpdateStruggling(float deltaTime)
void UpdateDying(float deltaTime)
{
Limb head = GetLimb(LimbType.Head);
Limb tail = GetLimb(LimbType.Tail);
@@ -355,7 +355,7 @@ namespace Subsurface
Vector2 centerOfMass = GetCenterOfMass();
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
if (limb.type == LimbType.Head || limb.type == LimbType.Tail) continue;
@@ -367,7 +367,7 @@ namespace Subsurface
{
base.Flip();
foreach (Limb l in limbs)
foreach (Limb l in Limbs)
{
if (!l.DoesFlip) continue;
@@ -378,22 +378,22 @@ namespace Subsurface
private void Mirror()
{
float leftX = limbs[0].SimPosition.X, rightX = limbs[0].SimPosition.X;
for (int i = 1; i < limbs.Count(); i++ )
float leftX = Limbs[0].SimPosition.X, rightX = Limbs[0].SimPosition.X;
for (int i = 1; i < Limbs.Count(); i++ )
{
if (limbs[i].SimPosition.X < leftX)
if (Limbs[i].SimPosition.X < leftX)
{
leftX = limbs[i].SimPosition.X;
leftX = Limbs[i].SimPosition.X;
}
else if (limbs[i].SimPosition.X > rightX)
else if (Limbs[i].SimPosition.X > rightX)
{
rightX = limbs[i].SimPosition.X;
rightX = Limbs[i].SimPosition.X;
}
}
float midX = GetCenterOfMass().X;
foreach (Limb l in limbs)
foreach (Limb l in Limbs)
{
Vector2 newPos = new Vector2(midX - (l.SimPosition.X - midX), l.SimPosition.Y);
@@ -30,11 +30,7 @@ namespace Subsurface
public override void UpdateAnim(float deltaTime)
{
if (character.IsDead)
{
UpdateStruggling();
return;
}
if (character.IsDead) return;
Vector2 colliderPos = GetLimb(LimbType.Torso).SimPosition;
@@ -49,7 +45,7 @@ namespace Subsurface
//out whether the ragdoll is standing on ground
float closestFraction = 1;
Structure closestStructure = null;
Game1.World.RayCast((fixture, point, normal, fraction) =>
GameMain.World.RayCast((fixture, point, normal, fraction) =>
{
switch (fixture.CollisionCategories)
{
@@ -136,7 +132,7 @@ namespace Subsurface
if (stunTimer > 0)
{
UpdateStruggling();
//UpdateStruggling();
stunTimer -= deltaTime;
return;
}
@@ -159,7 +155,7 @@ namespace Subsurface
if (TargetDir != dir) Flip();
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
limb.Disabled = false;
}
@@ -223,7 +219,7 @@ namespace Subsurface
//place the anchors of the head and the torso to make the ragdoll stand
if (onGround && LowestLimb != null && (LowestLimb.SimPosition.Y-floorY < 0.5f || stairs != null) && head !=null)
{
getUpSpeed = Math.Max(getUpSpeed * (head.SimPosition.Y - colliderPos.Y), 0.25f);
getUpSpeed = getUpSpeed * (head.SimPosition.Y - colliderPos.Y);//, 0.25f);
if (stairs != null)
{
@@ -325,8 +321,7 @@ namespace Subsurface
posAdditon.Y += 0.1f;
}
}
if (!rightHand.Disabled)
{
rightHand.body.ApplyTorque(walkPosY * runningModifier * Dir);
@@ -676,26 +671,7 @@ namespace Subsurface
}
}
void UpdateStruggling()
{
Limb leftLeg = GetLimb(LimbType.LeftFoot);
Limb rightLeg = GetLimb(LimbType.RightFoot);
Limb torso = GetLimb(LimbType.Torso);
//walkPos += 0.2f;
if (inWater) return;
HandIK(GetLimb(LimbType.RightHand), GetLimb(LimbType.Head).SimPosition,0.1f);
HandIK(GetLimb(LimbType.LeftHand), GetLimb(LimbType.Head).SimPosition,0.1f);
//Vector2 footPos = torso.body.Position+ new Vector2(TorsoPosition*Dir,0.0f);
//MoveLimb(leftLeg, footPos, 0.7f);
//MoveLimb(rightLeg, footPos, 0.7f);
}
//float punchTimer;
//bool punching;
@@ -885,7 +861,7 @@ namespace Subsurface
}
}
foreach (Limb l in limbs)
foreach (Limb l in Limbs)
{
switch (l.type)
{
+5 -5
View File
@@ -223,7 +223,7 @@ namespace Subsurface
pullJoint.Enabled = false;
pullJoint.MaxForce = 150.0f * body.Mass;
Game1.World.AddJoint(pullJoint);
GameMain.World.AddJoint(pullJoint);
}
else
{
@@ -325,14 +325,14 @@ namespace Subsurface
Vector2 particleVel = SimPosition - position;
if (particleVel != Vector2.Zero) particleVel = Vector2.Normalize(particleVel);
Game1.ParticleManager.CreateParticle("blood",
GameMain.ParticleManager.CreateParticle("blood",
Position,
particleVel * Rand.Range(100.0f, 300.0f));
}
for (int i = 0; i < bloodAmount / 2; i++)
{
Game1.ParticleManager.CreateParticle("waterblood", Position, Vector2.Zero);
GameMain.ParticleManager.CreateParticle("waterblood", Position, Vector2.Zero);
}
return new AttackResult(amount, bleedingAmount, hitArmor);
@@ -343,7 +343,7 @@ namespace Subsurface
if (LinearVelocity.X>100.0f)
{
DebugConsole.ThrowError("CHARACTER EXPLODED");
foreach (Limb limb in character.AnimController.limbs)
foreach (Limb limb in character.AnimController.Limbs)
{
limb.body.ResetDynamics();
limb.body.SetTransform(body.SimPosition, 0.0f);
@@ -421,7 +421,7 @@ namespace Subsurface
1.0f, spriteEffect, sprite.Depth - 0.000001f);
}
if (!Game1.DebugDraw) return;
if (!GameMain.DebugDraw) return;
if (pullJoint!=null)
{
+38 -38
View File
@@ -18,7 +18,7 @@ namespace Subsurface
protected Hull currentHull;
public Limb[] limbs;
public Limb[] Limbs;
private Dictionary<LimbType, Limb> limbDictionary;
public RevoluteJoint[] limbJoints;
@@ -138,7 +138,7 @@ namespace Subsurface
if (ignorePlatforms == value) return;
ignorePlatforms = value;
foreach (Limb l in limbs)
foreach (Limb l in Limbs)
{
if (l.ignoreCollisions) continue;
@@ -170,7 +170,7 @@ namespace Subsurface
dir = Direction.Right;
//int limbAmount = ;
limbs = new Limb[element.Elements("limb").Count()];
Limbs = new Limb[element.Elements("limb").Count()];
limbJoints = new RevoluteJoint[element.Elements("joint").Count()];
limbDictionary = new Dictionary<LimbType, Limb>();
@@ -193,7 +193,7 @@ namespace Subsurface
limb.body.FarseerBody.OnCollision += OnLimbCollision;
limbs[ID] = limb;
Limbs[ID] = limb;
Mass += limb.Mass;
if (!limbDictionary.ContainsKey(limb.type)) limbDictionary.Add(limb.type, limb);
break;
@@ -207,7 +207,7 @@ namespace Subsurface
Vector2 limb2Pos = ToolBox.GetAttributeVector2(subElement, "limb2anchor", Vector2.Zero);
limb2Pos = ConvertUnits.ToSimUnits(limb2Pos);
RevoluteJoint joint = new RevoluteJoint(limbs[limb1ID].body.FarseerBody, limbs[limb2ID].body.FarseerBody, limb1Pos, limb2Pos);
RevoluteJoint joint = new RevoluteJoint(Limbs[limb1ID].body.FarseerBody, Limbs[limb2ID].body.FarseerBody, limb1Pos, limb2Pos);
joint.CollideConnected = false;
@@ -221,7 +221,7 @@ namespace Subsurface
joint.MotorEnabled = true;
joint.MaxMotorTorque = 0.25f;
Game1.World.AddJoint(joint);
GameMain.World.AddJoint(joint);
for (int i = 0; i < limbJoints.Length; i++ )
{
@@ -257,7 +257,7 @@ namespace Subsurface
startDepth+=increment;
}
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
limb.sprite.Depth = startDepth + limb.sprite.Depth * 0.0001f;
}
@@ -328,16 +328,16 @@ namespace Subsurface
Vector2 normal = contact.Manifold.LocalNormal;
Vector2 avgVelocity = Vector2.Zero;
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
avgVelocity += limb.LinearVelocity;
}
avgVelocity = avgVelocity / limbs.Count();
avgVelocity = avgVelocity / Limbs.Count();
float impact = Vector2.Dot((f1.Body.LinearVelocity + avgVelocity) / 2.0f, -normal);
if (Game1.Server != null) impact = impact / 2.0f;
if (GameMain.Server != null) impact = impact / 2.0f;
Limb l = (Limb)f1.Body.UserData;
@@ -350,20 +350,20 @@ namespace Subsurface
AmbientSoundManager.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body.FarseerBody);
if (Character.Controlled == character) Game1.GameScreen.Cam.Shake = strongestImpact;
if (Character.Controlled == character) GameMain.GameScreen.Cam.Shake = strongestImpact;
}
}
public virtual void Draw(SpriteBatch spriteBatch)
{
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
limb.Draw(spriteBatch);
}
if (!Game1.DebugDraw) return;
if (!GameMain.DebugDraw) return;
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
if (limb.pullJoint != null)
@@ -420,29 +420,29 @@ namespace Subsurface
}
for (int i = 0; i < limbs.Count(); i++)
for (int i = 0; i < Limbs.Count(); i++)
{
if (limbs[i] == null) continue;
if (Limbs[i] == null) continue;
Vector2 spriteOrigin = limbs[i].sprite.Origin;
spriteOrigin.X = limbs[i].sprite.SourceRect.Width - spriteOrigin.X;
limbs[i].sprite.Origin = spriteOrigin;
Vector2 spriteOrigin = Limbs[i].sprite.Origin;
spriteOrigin.X = Limbs[i].sprite.SourceRect.Width - spriteOrigin.X;
Limbs[i].sprite.Origin = spriteOrigin;
limbs[i].Dir = Dir;
Limbs[i].Dir = Dir;
if (limbs[i].pullJoint == null) continue;
if (Limbs[i].pullJoint == null) continue;
limbs[i].pullJoint.LocalAnchorA =
Limbs[i].pullJoint.LocalAnchorA =
new Vector2(
-limbs[i].pullJoint.LocalAnchorA.X,
limbs[i].pullJoint.LocalAnchorA.Y);
-Limbs[i].pullJoint.LocalAnchorA.X,
Limbs[i].pullJoint.LocalAnchorA.Y);
}
}
public Vector2 GetCenterOfMass()
{
Vector2 centerOfMass = Vector2.Zero;
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
centerOfMass += limb.Mass * limb.SimPosition;
}
@@ -465,11 +465,11 @@ namespace Subsurface
public void ResetPullJoints()
{
for (int i = 0; i < limbs.Count(); i++)
for (int i = 0; i < Limbs.Count(); i++)
{
if (limbs[i] == null) continue;
if (limbs[i].pullJoint == null) continue;
limbs[i].pullJoint.Enabled = false;
if (Limbs[i] == null) continue;
if (Limbs[i].pullJoint == null) continue;
Limbs[i].pullJoint.Enabled = false;
}
}
@@ -520,7 +520,7 @@ namespace Subsurface
}
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
Vector2 limbPosition = ConvertUnits.ToDisplayUnits(limb.SimPosition);
@@ -562,7 +562,7 @@ namespace Subsurface
{
//create a splash particle
Subsurface.Particles.Particle splash = Game1.ParticleManager.CreateParticle("watersplash",
Subsurface.Particles.Particle splash = GameMain.ParticleManager.CreateParticle("watersplash",
new Vector2(limb.Position.X, limbHull.Surface),
new Vector2(0.0f, Math.Abs(-limb.LinearVelocity.Y * 10.0f)),
0.0f);
@@ -572,7 +572,7 @@ namespace Subsurface
// limbHull.Rect.Y,
// limbHull.Rect.Y - limbHull.Rect.Height));
Game1.ParticleManager.CreateParticle("bubbles",
GameMain.ParticleManager.CreateParticle("bubbles",
new Vector2(limb.Position.X, limbHull.Surface),
limb.LinearVelocity*0.001f,
0.0f);
@@ -629,7 +629,7 @@ namespace Subsurface
{
if (inWater)
{
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
if (limb.body.TargetPosition == Vector2.Zero) continue;
@@ -647,7 +647,7 @@ namespace Subsurface
{
System.Diagnostics.Debug.WriteLine("reset ragdoll limb positions");
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
if (limb.body.TargetPosition == Vector2.Zero) continue;
@@ -663,7 +663,7 @@ namespace Subsurface
private Vector2 GetFlowForce()
{
Vector2 limbPos = ConvertUnits.ToDisplayUnits(limbs[0].SimPosition);
Vector2 limbPos = ConvertUnits.ToDisplayUnits(Limbs[0].SimPosition);
Vector2 force = Vector2.Zero;
foreach (MapEntity e in MapEntity.mapEntityList)
@@ -693,7 +693,7 @@ namespace Subsurface
{
//find the lowest limb
lowestLimb = null;
foreach (Limb limb in limbs)
foreach (Limb limb in Limbs)
{
if (lowestLimb == null)
lowestLimb = limb;
@@ -704,10 +704,10 @@ namespace Subsurface
public void Remove()
{
foreach (Limb l in limbs) l.Remove();
foreach (Limb l in Limbs) l.Remove();
foreach (RevoluteJoint joint in limbJoints)
{
Game1.World.RemoveJoint(joint);
GameMain.World.RemoveJoint(joint);
}
}