Merge branch 'NewCoordinateSystem'

Conflicts:
	Subsurface/Barotrauma.csproj
	Subsurface_Solution.v12.suo
This commit is contained in:
Regalis
2015-12-17 18:29:26 +02:00
105 changed files with 2401 additions and 1288 deletions

View File

@@ -45,7 +45,8 @@ namespace Barotrauma.Items.Components
linkedGap = e as Gap;
if (linkedGap != null) return linkedGap;
}
linkedGap = new Gap(item.Rect);
linkedGap = new Gap(item.Rect, Item.Submarine);
linkedGap.Submarine = item.Submarine;
linkedGap.Open = openState;
item.linkedTo.Add(linkedGap);
return linkedGap;
@@ -144,8 +145,8 @@ namespace Barotrauma.Items.Components
Vector2[] corners = GetConvexHullCorners(doorRect);
convexHull = new ConvexHull(corners, Color.Black);
if (window!=Rectangle.Empty) convexHull2 = new ConvexHull(corners, Color.Black);
convexHull = new ConvexHull(corners, Color.Black, item.CurrentHull == null ? null : item.CurrentHull.Submarine);
if (window!=Rectangle.Empty) convexHull2 = new ConvexHull(corners, Color.Black, item.CurrentHull == null ? null : item.CurrentHull.Submarine);
UpdateConvexHulls();
@@ -262,7 +263,7 @@ namespace Barotrauma.Items.Components
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);
SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, 1.0f, l.body);
//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));
@@ -303,7 +304,12 @@ namespace Barotrauma.Items.Components
if (stuck>0.0f && weldedSprite!=null)
{
weldedSprite.Draw(spriteBatch, new Vector2(item.Rect.X, -item.Rect.Y), Color.White*(stuck/100.0f), 0.0f, 1.0f);
Vector2 weldSpritePos = new Vector2(item.Rect.X, item.Rect.Y);
if (item.Submarine != null) weldSpritePos += item.Submarine.Position;
weldSpritePos.Y = -weldSpritePos.Y;
weldedSprite.Draw(spriteBatch,
weldSpritePos, Color.White*(stuck/100.0f), 0.0f, 1.0f);
}
if (openState == 1.0f)
@@ -311,8 +317,12 @@ namespace Barotrauma.Items.Components
body.Enabled = false;
return;
}
spriteBatch.Draw(doorSprite.Texture, new Vector2(item.Rect.Center.X, -item.Rect.Y),
Vector2 pos = new Vector2(item.Rect.Center.X, item.Rect.Y);
if (item.Submarine != null) pos += item.Submarine.DrawPosition;
pos.Y = -pos.Y;
spriteBatch.Draw(doorSprite.Texture, pos,
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);
@@ -344,12 +354,12 @@ namespace Barotrauma.Items.Components
if (connection.Name=="toggle")
{
isOpen = !isOpen;
PlaySound(ActionType.OnUse, item.Position);
PlaySound(ActionType.OnUse, item.WorldPosition);
}
else if (connection.Name == "set_state")
{
bool newState = (signal!="0");
if (isOpen!=newState) PlaySound(ActionType.OnUse, item.Position);
if (isOpen!=newState) PlaySound(ActionType.OnUse, item.WorldPosition);
isOpen = newState;
}

View File

@@ -110,6 +110,9 @@ namespace Barotrauma.Items.Components
public override void Drop(Character dropper)
{
item.body.Enabled = true;
IsActive = false;
if (picker == null)
{
if (dropper==null) return;
@@ -117,8 +120,8 @@ namespace Barotrauma.Items.Components
}
if (picker.Inventory == null) return;
item.body.Enabled = true;
IsActive = false;
item.Submarine = picker.Submarine;
//item.Unequip();
@@ -236,6 +239,8 @@ namespace Barotrauma.Items.Components
AnimController ac = picker.AnimController;
item.Submarine = picker.Submarine;
//item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f;
ac.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle);

View File

@@ -194,7 +194,7 @@ namespace Barotrauma.Items.Components
if (target == null) return false;
if (attack!=null) attack.DoDamage(user, target, item.Position, 1.0f);
if (attack!=null) attack.DoDamage(user, target, item.WorldPosition, 1.0f);
RestoreCollision();
hitting = false;

View File

@@ -107,6 +107,8 @@ namespace Barotrauma.Items.Components
}
if (picker==null || picker.Inventory == null) return;
item.Submarine = picker.Submarine;
if (item.body!= null && !item.body.Enabled)
{

View File

@@ -88,7 +88,7 @@ namespace Barotrauma.Items.Components
if (!string.IsNullOrWhiteSpace(particles))
{
GameMain.ParticleManager.CreateParticle(particles, item.Position,
GameMain.ParticleManager.CreateParticle(particles, item.WorldPosition,
item.body.Rotation + ((item.body.Dir > 0.0f) ? 0.0f : MathHelper.Pi), 0.0f, item.CurrentHull);
}

View File

@@ -24,8 +24,8 @@ namespace Barotrauma.Items.Components
[HasDefaultValue(0.0f, false)]
public float Range
{
get { return ConvertUnits.ToDisplayUnits(range); }
set { range = ConvertUnits.ToSimUnits(value); }
get { return range; }
set { range = value; }
}
[HasDefaultValue(0.0f, false)]
@@ -61,8 +61,8 @@ namespace Barotrauma.Items.Components
[HasDefaultValue("0.0,0.0", false)]
public string BarrelPos
{
get { return ToolBox.Vector2ToString(ConvertUnits.ToDisplayUnits(barrelPos)); }
set { barrelPos = ConvertUnits.ToSimUnits(ToolBox.ParseToVector2(value)); }
get { return ToolBox.Vector2ToString(barrelPos); }
set { barrelPos = ToolBox.ParseToVector2(value); }
}
public Vector2 TransformedBarrelPos
@@ -72,7 +72,7 @@ namespace Barotrauma.Items.Components
Matrix bodyTransform = Matrix.CreateRotationZ(item.body.Rotation);
Vector2 flippedPos = barrelPos;
if (item.body.Dir < 0.0f) flippedPos.X = -flippedPos.X;
return (Vector2.Transform(flippedPos, bodyTransform) + item.body.SimPosition);
return (Vector2.Transform(flippedPos, bodyTransform));
}
}
@@ -115,7 +115,6 @@ namespace Barotrauma.Items.Components
IsActive = true;
Vector2 targetPosition = item.body.SimPosition;
//targetPosition = targetPosition.X, -targetPosition.Y);
float degreeOfSuccess = DegreeOfSuccess(character)/100.0f;
@@ -126,6 +125,7 @@ namespace Barotrauma.Items.Components
return false;
}
Vector2 targetPosition = item.WorldPosition;
targetPosition += new Vector2(
(float)Math.Cos(item.body.Rotation),
(float)Math.Sin(item.body.Rotation)) * range * item.body.Dir;
@@ -137,14 +137,18 @@ namespace Barotrauma.Items.Components
ignoredBodies.Add(limb.body.FarseerBody);
}
Vector2 rayStart = item.WorldPosition + TransformedBarrelPos;
Vector2 rayEnd = targetPosition;
Body targetBody = Submarine.PickBody(
ConvertUnits.ToSimUnits(rayStart - Submarine.Loaded.Position),
ConvertUnits.ToSimUnits(rayEnd - Submarine.Loaded.Position), ignoredBodies);
Body targetBody = Submarine.PickBody(TransformedBarrelPos, targetPosition, ignoredBodies);
pickedPosition = Submarine.LastPickedPosition;
if (ExtinquishAmount > 0.0f)
{
Vector2 displayPos = ConvertUnits.ToDisplayUnits(TransformedBarrelPos + (targetPosition-TransformedBarrelPos)*Submarine.LastPickedFraction*0.9f);
Vector2 displayPos = rayStart + (rayEnd-rayStart)*Submarine.LastPickedFraction*0.9f;
Hull hull = Hull.FindHull(displayPos, item.CurrentHull);
if (hull != null) hull.Extinquish(deltaTime, ExtinquishAmount, displayPos);
}
@@ -224,7 +228,7 @@ namespace Barotrauma.Items.Components
if (!string.IsNullOrWhiteSpace(particles))
{
GameMain.ParticleManager.CreateParticle(particles, ConvertUnits.ToDisplayUnits(TransformedBarrelPos),
GameMain.ParticleManager.CreateParticle(particles, item.WorldPosition+TransformedBarrelPos,
-item.body.Rotation + ((item.body.Dir>0.0f) ? 0.0f : MathHelper.Pi), ParticleSpeed);
}

View File

@@ -322,6 +322,8 @@ namespace Barotrauma.Items.Components
if (itemSound.Loop)
{
loopingSound = itemSound;
loopingSoundIndex = loopingSound.Sound.Loop(loopingSoundIndex, GetSoundVolume(loopingSound), position, loopingSound.Range);
}
else
{

View File

@@ -163,6 +163,7 @@ namespace Barotrauma.Items.Components
if (item.body == null)
{
transformedItemPos = new Vector2(item.Rect.X, item.Rect.Y);
if (item.Submarine != null) transformedItemPos += item.Submarine.DrawPosition;
transformedItemPos = transformedItemPos + itemPos;
}
else
@@ -179,7 +180,7 @@ namespace Barotrauma.Items.Components
transformedItemPos = Vector2.Transform(transformedItemPos, transform);
transformedItemInterval = Vector2.Transform(transformedItemInterval, transform);
transformedItemPos += ConvertUnits.ToDisplayUnits(item.body.SimPosition);
transformedItemPos += item.DrawPosition;
currentRotation += item.body.Rotation;
}

View File

@@ -61,6 +61,7 @@ namespace Barotrauma.Items.Components
{
base.Draw(spriteBatch, editing);
textBlock.Rect = new Rectangle((int)item.DrawPosition.X - item.Rect.Width/2, -(int)(item.DrawPosition.Y + item.Rect.Height/2), item.Rect.Width, item.Rect.Height);
textBlock.Draw(spriteBatch);
}
}

View File

@@ -118,7 +118,7 @@ namespace Barotrauma.Items.Components
fmj.WorldAnchorB = position;
}
item.SendSignal(ToolBox.Vector2ToString(character.CursorPosition), "position_out");
item.SendSignal(ToolBox.Vector2ToString(character.CursorWorldPosition), "position_out");
}
public override bool Use(float deltaTime, Character activator = null)
@@ -152,12 +152,12 @@ namespace Barotrauma.Items.Components
{
if (c2 == null || c2.Item==null || !c2.Item.Prefab.FocusOnSelected) continue;
Vector2 centerPos = c2.Item.Position;
Vector2 centerPos = c2.Item.WorldPosition;
if (character == Character.Controlled && cam != null)
{
Lights.LightManager.ViewPos = centerPos;
cam.TargetPos = c2.Item.Position;
cam.TargetPos = c2.Item.WorldPosition;
}
break;
@@ -169,7 +169,7 @@ namespace Barotrauma.Items.Components
{
item.SendSignal("1", "signal_out");
PlaySound(ActionType.OnUse, item.Position);
PlaySound(ActionType.OnUse, item.WorldPosition);
return true;
}

View File

@@ -74,7 +74,7 @@ namespace Barotrauma.Items.Components
for (int i = 0; i < 5; i++)
{
GameMain.ParticleManager.CreateParticle("bubbles", item.Position,
GameMain.ParticleManager.CreateParticle("bubbles", item.WorldPosition,
-currForce / 5.0f + new Vector2(Rand.Range(-100.0f, 100.0f), Rand.Range(-50f, 50f)),
0.0f, item.CurrentHull);
}

View File

@@ -103,7 +103,7 @@ namespace Barotrauma.Items.Components
private void GetHull()
{
hull1 = Hull.FindHull(item.Position, item.CurrentHull);
hull1 = Hull.FindHull(item.WorldPosition, item.CurrentHull);
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)

View File

@@ -50,6 +50,8 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
currPowerConsumption = powerConsumption;
base.Update(deltaTime, cam);
for (int i = radarBlips.Count - 1; i >= 0; i-- )
@@ -71,6 +73,8 @@ namespace Barotrauma.Items.Components
{
pingState = 0.0f;
}
voltage = 0.0f;
}
public override bool Use(float deltaTime, Character character = null)
@@ -115,67 +119,67 @@ namespace Barotrauma.Items.Components
float radius = rect.Width / 2.0f;
float simScale = 1.5f;
if (Level.Loaded != null)
{
List<VoronoiCell> cells = Level.Loaded.GetCells(-Level.Loaded.Position, 7);
List<VoronoiCell> cells = Level.Loaded.GetCells(item.WorldPosition, 7);
foreach (VoronoiCell cell in cells)
{
foreach (GraphEdge edge in cell.edges)
{
//if (!edge.isSolid) continue;
float cellDot = Vector2.Dot(cell.Center + Level.Loaded.Position, (edge.point1 + edge.point2) / 2.0f - cell.Center);
if (!edge.isSolid) continue;
float cellDot = Vector2.Dot(cell.Center - item.WorldPosition, edge.Center - cell.Center);
if (cellDot > 0) continue;
float facingDot = Vector2.Dot(Vector2.Normalize(edge.point1 - edge.point2), Vector2.Normalize(cell.Center + Level.Loaded.Position));
facingDot = MathHelper.Clamp(facingDot, -1.0f, 1.0f);
float facingDot = Vector2.Dot(Vector2.Normalize(edge.point1 - edge.point2), Vector2.Normalize(cell.Center-item.WorldPosition));
facingDot = 1.0f;// MathHelper.Clamp(facingDot, -1.0f, 1.0f);
Vector2 point1 = (edge.point1 + Level.Loaded.Position);
Vector2 point2 = (edge.point2 + Level.Loaded.Position);
Vector2 point1 = (edge.point1);
Vector2 point2 = (edge.point2);
float length = (point1 - point2).Length();
for (float x=0; x<length; x+=Rand.Range(600.0f, 800.0f))
for (float x = 0; x < length; x += Rand.Range(600.0f, 800.0f))
{
Vector2 point = point1 + Vector2.Normalize(point2 - point1) * x;
float pointDist = point.Length() * displayScale;
float pointDist = Vector2.Distance(item.WorldPosition, point) * displayScale;
if (pointDist > radius) continue;
if (pointDist < prevPingRadius || pointDist > pingRadius) continue;
float step = 5.0f * (Math.Abs(facingDot)+1.0f);
float step = 3.0f * (Math.Abs(facingDot) + 1.0f);
float alpha = Rand.Range(1.5f, 2.0f);
for (float z = 0; z<radius-pointDist;z+=step)
for (float z = 0; z < radius - pointDist; z += step)
{
var blip = new RadarBlip(
point + Rand.Vector(150.0f) - Level.Loaded.Position + Vector2.Normalize(point) * z / displayScale,
point + Rand.Vector(150.0f) + Vector2.Normalize(point-item.WorldPosition) * z / displayScale,
alpha);
radarBlips.Add(blip);
step += 0.5f;
alpha -= (z == 0) ? 0.5f : 0.1f;
}
}
}
}
for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++)
{
Vector2 start = Submarine.Loaded.HullVertices[i] * simScale;
Vector2 start = (Submarine.Loaded.HullVertices[i] - ConvertUnits.ToSimUnits(item.Position - Submarine.HiddenSubPosition)) * simScale;
start.Y = -start.Y;
Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * simScale;
Vector2 end = (Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] - ConvertUnits.ToSimUnits(item.Position - Submarine.HiddenSubPosition)) * simScale;
end.Y = -end.Y;
Vector2 diff = end - start;
for (float x = 0; x < diff.Length(); x+=4.0f )
for (float x = 0; x < diff.Length(); x += 4.0f)
{
GUI.DrawLine(spriteBatch, center + start, center + end, Color.Green);
}
}
}
}
@@ -186,8 +190,7 @@ namespace Barotrauma.Items.Components
foreach (Limb limb in c.AnimController.Limbs)
{
Vector2 pos = limb.Position;
float pointDist = pos.Length() * displayScale;
float pointDist = (limb.WorldPosition - item.WorldPosition).Length() * displayScale;
if (limb.SimPosition == Vector2.Zero || pointDist > radius) continue;
@@ -195,7 +198,7 @@ namespace Barotrauma.Items.Components
if (pointDist > radius) continue;
if (pointDist > prevPingRadius && pointDist < pingRadius)
{
var blip = new RadarBlip(pos - Level.Loaded.Position, 1.0f);
var blip = new RadarBlip(limb.WorldPosition, 1.0f);
radarBlips.Add(blip);
}
}
@@ -203,14 +206,14 @@ namespace Barotrauma.Items.Components
foreach (RadarBlip radarBlip in radarBlips)
{
DrawBlip(spriteBatch,radarBlip, center, Color.Green * radarBlip.FadeTimer, radius);
DrawBlip(spriteBatch, radarBlip, center, Color.Green * radarBlip.FadeTimer, radius);
}
prevPingRadius = pingRadius;
if (screenOverlay!=null)
if (screenOverlay != null)
{
screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width/screenOverlay.size.X);
screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width / screenOverlay.size.X);
}
//prevPingRadius = pingRadius;
@@ -220,11 +223,11 @@ namespace Barotrauma.Items.Components
DrawMarker(spriteBatch,
(GameMain.GameSession.Map == null) ? "Start" : GameMain.GameSession.Map.CurrentLocation.Name,
(Level.Loaded.StartPosition + Level.Loaded.Position), displayScale, center, (rect.Width * 0.55f));
(Level.Loaded.StartPosition), displayScale, center, (rect.Width * 0.55f));
DrawMarker(spriteBatch,
(GameMain.GameSession.Map == null) ? "End" : GameMain.GameSession.Map.SelectedLocation.Name,
(Level.Loaded.EndPosition + Level.Loaded.Position), displayScale, center, (rect.Width * 0.55f));
(Level.Loaded.EndPosition), displayScale, center, (rect.Width * 0.55f));
if (GameMain.GameSession.Quest != null)
{
@@ -247,15 +250,15 @@ namespace Barotrauma.Items.Components
foreach (WayPoint wp in steering.SteeringPath.Nodes)
{
Vector2 pos = (wp.Position - Submarine.Loaded.Position) * displayScale;
Vector2 pos = (wp.Position - item.WorldPosition) * displayScale;
if (pos.Length() > radius) continue;
pos.Y = -pos.Y;
pos += center;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X -3 / 2, (int)pos.Y - 3, 6, 6), (steering.SteeringPath.CurrentNode==wp) ? Color.LightGreen : Color.Green, false);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X - 3 / 2, (int)pos.Y - 3, 6, 6), (steering.SteeringPath.CurrentNode == wp) ? Color.LightGreen : Color.Green, false);
if (prevPos!=Vector2.Zero)
if (prevPos != Vector2.Zero)
{
GUI.DrawLine(spriteBatch, pos, prevPos, Color.Green);
}
@@ -263,12 +266,12 @@ namespace Barotrauma.Items.Components
prevPos = pos;
}
voltage = 0.0f;
}
private void DrawBlip(SpriteBatch spriteBatch, RadarBlip blip, Vector2 center, Color color, float radius)
{
Vector2 pos = (blip.Position + Level.Loaded.Position) * displayScale;
Vector2 pos = (blip.Position-item.WorldPosition) * displayScale;
pos.Y = -pos.Y;
if (pos.Length() > radius)

View File

@@ -163,7 +163,7 @@ namespace Barotrauma.Items.Components
Vector2 baseVel = Rand.Vector(300.0f);
for (int i = 0; i < 10; i++)
{
var particle = GameMain.ParticleManager.CreateParticle("spark", item.Position,
var particle = GameMain.ParticleManager.CreateParticle("spark", item.WorldPosition,
baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);

View File

@@ -41,7 +41,7 @@ namespace Barotrauma.Items.Components
{
if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(Submarine.Loaded.Position),
ConvertUnits.ToSimUnits(item.WorldPosition),
ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
}
}
@@ -160,31 +160,31 @@ namespace Barotrauma.Items.Components
{
autopilotRayCastTimer -= deltaTime;
steeringPath.CheckProgress(ConvertUnits.ToSimUnits(Submarine.Loaded.Position), 10.0f);
steeringPath.CheckProgress(ConvertUnits.ToSimUnits(item.WorldPosition), 10.0f);
if (autopilotRayCastTimer<=0.0f && steeringPath.NextNode != null)
{
Vector2 diff = ConvertUnits.ToSimUnits(steeringPath.NextNode.Position - Submarine.Loaded.Position);
Vector2 diff = ConvertUnits.ToSimUnits(steeringPath.NextNode.Position - item.WorldPosition);
bool nextVisible = true;
for (int x = -1; x < 2; x += 2)
{
for (int y = -1; y < 2; y += 2)
{
Vector2 cornerPos =
new Vector2(Submarine.Borders.Width * x, Submarine.Borders.Height * y) / 2.0f;
//bool nextVisible = true;
//for (int x = -1; x < 2; x += 2)
//{
// for (int y = -1; y < 2; y += 2)
// {
// Vector2 cornerPos =
// new Vector2(Submarine.Borders.Width * x, Submarine.Borders.Height * y) / 2.0f;
cornerPos = ConvertUnits.ToSimUnits(cornerPos*1.2f);
// cornerPos = ConvertUnits.ToSimUnits(cornerPos*1.2f);
if (Submarine.PickBody(cornerPos, cornerPos + diff, null, Physics.CollisionLevel) == null) continue;
// if (Submarine.PickBody(cornerPos, cornerPos + diff, null, Physics.CollisionLevel) == null) continue;
nextVisible = false;
x = 2;
y = 2;
}
}
// nextVisible = false;
// x = 2;
// y = 2;
// }
//}
if (nextVisible) steeringPath.SkipToNextNode();
//if (nextVisible) steeringPath.SkipToNextNode();
autopilotRayCastTimer = AutopilotRayCastInterval;
}
@@ -193,8 +193,8 @@ namespace Barotrauma.Items.Components
{
float prediction = 5.0f;
Vector2 futurePosition = Submarine.Loaded.Speed * prediction;
Vector2 targetSpeed = ((steeringPath.CurrentNode.Position - Submarine.Loaded.Position) - futurePosition);
Vector2 futurePosition = ConvertUnits.ToDisplayUnits(item.Submarine.Velocity) * prediction;
Vector2 targetSpeed = ((steeringPath.CurrentNode.WorldPosition - item.WorldPosition) - futurePosition);
targetSpeed = Vector2.Normalize(targetSpeed);
TargetVelocity = targetSpeed * 100.0f;

View File

@@ -62,12 +62,12 @@ namespace Barotrauma.Items.Components
if (pt.item.Condition<=0.0f && prevCondition > 0.0f)
{
sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 600.0f, pt.item.Position);
sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 600.0f, pt.item.WorldPosition);
Vector2 baseVel = Rand.Vector(300.0f);
for (int i = 0; i < 10; i++)
{
var particle = GameMain.ParticleManager.CreateParticle("spark", pt.item.Position,
var particle = GameMain.ParticleManager.CreateParticle("spark", pt.item.WorldPosition,
baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);
@@ -75,7 +75,7 @@ namespace Barotrauma.Items.Components
if (FireProbability > 0.0f && Rand.Int((int)(1.0f / FireProbability)) == 1)
{
new FireSource(pt.item.Position);
new FireSource(pt.item.WorldPosition);
}
}
}

View File

@@ -98,7 +98,7 @@ namespace Barotrauma.Items.Components
{
if (!powerOnSoundPlayed)
{
powerOnSound.Play(1.0f, 600.0f, item.Position);
powerOnSound.Play(1.0f, 600.0f, item.WorldPosition);
powerOnSoundPlayed = true;
}
}

View File

@@ -169,11 +169,11 @@ namespace Barotrauma.Items.Components
Structure structure;
if ((limb = (f2.Body.UserData as Limb)) != null)
{
attackResult = attack.DoDamage(User, limb.character, item.SimPosition, 1.0f);
attackResult = attack.DoDamage(User, limb.character, item.WorldPosition, 1.0f);
}
else if ((structure = (f2.Body.UserData as Structure)) != null)
{
attackResult = attack.DoDamage(User, structure, item.SimPosition, 1.0f);
attackResult = attack.DoDamage(User, structure, item.WorldPosition, 1.0f);
}
}

View File

@@ -88,7 +88,7 @@ namespace Barotrauma.Items.Components
// break;
//}
light = new LightSource(item.Position, 100.0f, Color.White);
light = new LightSource(item.Position, 100.0f, Color.White, item.CurrentHull == null ? null : item.CurrentHull.Submarine);
IsActive = true;
@@ -98,6 +98,12 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
base.Update(deltaTime, cam);
if (item.CurrentHull != null)
{
light.Submarine = item.CurrentHull.Submarine;
}
if (item.container != null)
{
@@ -107,7 +113,7 @@ namespace Barotrauma.Items.Components
if (item.body != null)
{
light.Position = ConvertUnits.ToDisplayUnits(item.body.SimPosition);
light.Position = item.WorldPosition;
}
if (powerConsumption == 0.0f)
@@ -121,7 +127,7 @@ namespace Barotrauma.Items.Components
if (Rand.Range(0.0f, 1.0f) < 0.05f && voltage < Rand.Range(0.0f, minVoltage))
{
if (voltage > 0.1f) sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 400.0f, item.Position);
if (voltage > 0.1f) sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 400.0f, item.WorldPosition);
lightBrightness = 0.0f;
}
else

View File

@@ -4,31 +4,17 @@ namespace Barotrauma.Items.Components
{
class OxygenDetector : ItemComponent
{
private Hull hull;
public OxygenDetector(Item item, XElement element)
: base (item, element)
{
hull = Hull.FindHull(item.Position);
IsActive = true;
}
public override void OnMapLoaded()
{
hull = Hull.FindHull(item.Position);
}
public override void Move(Microsoft.Xna.Framework.Vector2 amount)
{
hull = Hull.FindHull(item.Position);
}
public override void Update(float deltaTime, Camera cam)
{
if (hull == null) return;
item.SendSignal(((int)hull.OxygenPercentage).ToString(), "signal_out");
if (item.CurrentHull == null) return;
item.SendSignal(((int)item.CurrentHull.OxygenPercentage).ToString(), "signal_out");
}

View File

@@ -41,11 +41,10 @@ namespace Barotrauma.Items.Components
public override void Move(Vector2 amount)
{
//amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount);
//for (int i = 0; i<Nodes.Count; i++)
//{
// Nodes[i] += amount;
//}
for (int i = 0; i < Nodes.Count; i++)
{
Nodes[i] += amount;
}
}
public Connection OtherConnection(Connection connection)
@@ -315,7 +314,11 @@ namespace Barotrauma.Items.Components
for (int i = 1; i < Nodes.Count; i++)
{
GUI.DrawRectangle(spriteBatch, new Rectangle((int)Nodes[i].X - 3, (int)-Nodes[i].Y - 3, 6, 6), Color.Red, true, 0.0f);
Vector2 worldPos = Nodes[i];
if (item.Submarine != null) worldPos += item.Submarine.Position;
worldPos.Y = -worldPos.Y;
GUI.DrawRectangle(spriteBatch, worldPos+new Vector2(-3,-3), new Vector2(6, 6), Color.Red, true, 0.0f);
if (GUIComponent.MouseOn != null ||
Vector2.Distance(GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition), Nodes[i]) > 10.0f)
@@ -323,7 +326,7 @@ namespace Barotrauma.Items.Components
continue;
}
GUI.DrawRectangle(spriteBatch, new Rectangle((int)Nodes[i].X - 10, (int)-Nodes[i].Y - 10, 20, 20), Color.Red, false, 0.0f);
GUI.DrawRectangle(spriteBatch, worldPos + new Vector2(-10, -10), new Vector2(20, 20), Color.Red, false, 0.0f);
if (selectedNodeIndex == null && !MapEntity.SelectedAny)
{
@@ -348,9 +351,11 @@ namespace Barotrauma.Items.Components
MapEntity.DisableSelect = true;
Nodes[(int)selectedNodeIndex] = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
Vector2 pos = Nodes[(int)selectedNodeIndex];
Vector2 nodeWorldPos = Nodes[(int)selectedNodeIndex];
Nodes[(int)selectedNodeIndex] = RoundNode(Nodes[(int)selectedNodeIndex], Hull.FindHull(Nodes[(int)selectedNodeIndex]));
if (item.Submarine != null) nodeWorldPos += item.Submarine.Position;
Nodes[(int)selectedNodeIndex] = RoundNode(Nodes[(int)selectedNodeIndex], Hull.FindHull(nodeWorldPos));
MapEntity.SelectEntity(item);
}
}
@@ -362,6 +367,12 @@ namespace Barotrauma.Items.Components
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color)
{
if (item.Submarine!=null)
{
start += item.Submarine.DrawPosition;
end += item.Submarine.DrawPosition;
}
start.Y = -start.Y;
end.Y = -end.Y;

View File

@@ -81,8 +81,12 @@ namespace Barotrauma.Items.Components
public override void Draw(SpriteBatch spriteBatch, bool editing)
{
Vector2 drawPos = new Vector2(item.Rect.X, item.Rect.Y);
if (item.Submarine != null) drawPos += item.Submarine.DrawPosition;
drawPos.Y = -drawPos.Y;
barrelSprite.Draw(spriteBatch,
new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, Color.White,
drawPos + barrelPos, Color.White,
rotation + MathHelper.PiOver2, 1.0f,
SpriteEffects.None, item.Sprite.Depth+0.01f);
}
@@ -149,7 +153,7 @@ namespace Barotrauma.Items.Components
projectile.body.ResetDynamics();
projectile.body.Enabled = true;
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation);
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y)), -rotation);
projectiles[0].Use(deltaTime);
if (projectile.container != null) projectile.container.RemoveContained(projectile);
@@ -297,7 +301,7 @@ namespace Barotrauma.Items.Components
case "position_in":
Vector2 receivedPos = ToolBox.ParseToVector2(signal, false);
Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
Vector2 centerPos = new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y);
Vector2 offset = receivedPos - centerPos;
offset.Y = -offset.Y;

View File

@@ -165,7 +165,7 @@ namespace Barotrauma.Items.Components
ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker);
PlaySound(ActionType.OnWearing, picker.Position);
PlaySound(ActionType.OnWearing, picker.WorldPosition);
if (containedItems == null) return;
for (int j = 0; j<containedItems.Length; j++)

View File

@@ -83,7 +83,7 @@ namespace Barotrauma
int width = 400, height = 500;
int x = 0, y = 0;
frame = new GUIFrame(new Rectangle(0, 0, width, height), Color.White * 0.8f, Alignment.Center, GUI.Style);
frame = new GUIFrame(new Rectangle(0, 0, width, height), null, Alignment.Center, GUI.Style);
frame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
frame.UserData = item;

View File

@@ -255,13 +255,14 @@ namespace Barotrauma
//}
public Item(ItemPrefab itemPrefab, Vector2 position)
: this(new Rectangle((int)position.X, (int)position.Y, (int)itemPrefab.sprite.size.X, (int)itemPrefab.sprite.size.Y), itemPrefab)
public Item(ItemPrefab itemPrefab, Vector2 position, Submarine submarine)
: this(new Rectangle((int)position.X, (int)position.Y, (int)itemPrefab.sprite.size.X, (int)itemPrefab.sprite.size.Y), itemPrefab, submarine)
{
}
public Item(Rectangle newRect, ItemPrefab itemPrefab)
public Item(Rectangle newRect, ItemPrefab itemPrefab, Submarine submarine)
: base(submarine)
{
prefab = itemPrefab;
@@ -377,9 +378,8 @@ namespace Barotrauma
if (ItemList != null && body != null)
{
amount = ConvertUnits.ToSimUnits(amount);
//Vector2 pos = new Vector2(rect.X + rect.Width / 2.0f, rect.Y - rect.Height / 2.0f);
body.SetTransform(body.SimPosition+amount, body.Rotation);
body.SetTransform(body.SimPosition+ConvertUnits.ToSimUnits(amount), body.Rotation);
}
foreach (ItemComponent ic in components)
{
@@ -389,15 +389,22 @@ namespace Barotrauma
if (body != null) FindHull();
}
public Rectangle TransformTrigger(Rectangle trigger)
public Rectangle TransformTrigger(Rectangle trigger, bool world = false)
{
return new Rectangle(
return world ?
new Rectangle(
WorldRect.X + trigger.X,
WorldRect.Y + trigger.Y,
(trigger.Width == 0) ? (int)Rect.Width : trigger.Width,
(trigger.Height == 0) ? (int)Rect.Height : trigger.Height)
:
new Rectangle(
Rect.X + trigger.X,
Rect.Y + trigger.Y,
(trigger.Width == 0) ? (int)Rect.Width : trigger.Width,
(trigger.Height == 0) ? (int)Rect.Height : trigger.Height);
}
/// <summary>
/// goes through every item and re-checks which hull they are in
/// </summary>
@@ -408,7 +415,11 @@ namespace Barotrauma
public virtual Hull FindHull()
{
CurrentHull = Hull.FindHull((body == null) ? Position : ConvertUnits.ToDisplayUnits(body.SimPosition), CurrentHull);
CurrentHull = Hull.FindHull(WorldPosition, CurrentHull);
if (body!=null)
{
body.Submarine = CurrentHull == null ? null : Submarine.Loaded;
}
return CurrentHull;
}
@@ -545,7 +556,7 @@ namespace Barotrauma
{
ic.Update(deltaTime, cam);
ic.PlaySound(ActionType.OnActive, Position);
ic.PlaySound(ActionType.OnActive, WorldPosition);
//ic.ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
}
else
@@ -598,7 +609,16 @@ namespace Barotrauma
{
if (body == null)
{
prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), color);
if (prefab.ResizeHorizontal || prefab.ResizeVertical)
{
prefab.sprite.DrawTiled(spriteBatch, new Vector2(DrawPosition.X-rect.Width/2, -(DrawPosition.Y+rect.Height/2)), new Vector2(rect.Width, rect.Height), color);
}
else
{
prefab.sprite.Draw(spriteBatch, new Vector2(DrawPosition.X, -DrawPosition.Y), color);
}
}
else if (body.Enabled)
{
@@ -615,7 +635,7 @@ namespace Barotrauma
depth = holdable.Picker.AnimController.GetLimb(LimbType.LeftArm).sprite.Depth - 0.000001f;
}
body.Draw(spriteBatch, prefab.sprite, color, depth);
body.Draw(spriteBatch, prefab.sprite, color, depth);
}
else
{
@@ -632,13 +652,18 @@ namespace Barotrauma
return;
}
GUI.DrawRectangle(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), Color.Green);
GUI.DrawRectangle(spriteBatch, new Vector2(DrawPosition.X - rect.Width / 2, -(DrawPosition.Y+rect.Height/2)), new Vector2(rect.Width, rect.Height), Color.Green);
foreach (Rectangle t in prefab.Triggers)
{
Rectangle transformedTrigger = TransformTrigger(t);
Vector2 rectWorldPos = new Vector2(transformedTrigger.X, transformedTrigger.Y);
if (Submarine!=null) rectWorldPos += Submarine.Position;
rectWorldPos.Y = -rectWorldPos.Y;
GUI.DrawRectangle(spriteBatch,
new Vector2(transformedTrigger.X, -transformedTrigger.Y),
rectWorldPos,
new Vector2(transformedTrigger.Width, transformedTrigger.Height),
Color.Green);
}
@@ -646,8 +671,8 @@ namespace Barotrauma
foreach (MapEntity e in linkedTo)
{
GUI.DrawLine(spriteBatch,
new Vector2(rect.X + rect.Width / 2, -rect.Y + rect.Height / 2),
new Vector2(e.Rect.X + e.Rect.Width / 2, -e.Rect.Y + e.Rect.Height / 2),
new Vector2(WorldPosition.X, -WorldPosition.Y),
new Vector2(e.WorldPosition.X, -e.WorldPosition.Y),
Color.Red*0.3f);
}
}
@@ -882,13 +907,13 @@ namespace Barotrauma
return closest;
}
public bool IsInsideTrigger(Vector2 position)
public bool IsInsideTrigger(Vector2 worldPosition)
{
foreach (Rectangle trigger in prefab.Triggers)
{
Rectangle transformedTrigger = TransformTrigger(trigger);
Rectangle transformedTrigger = TransformTrigger(trigger, true);
if (Submarine.RectContains(transformedTrigger, position)) return true;
if (Submarine.RectContains(transformedTrigger, worldPosition)) return true;
}
return false;
@@ -989,7 +1014,7 @@ namespace Barotrauma
{
ic.WasUsed = true;
ic.PlaySound(ActionType.OnUse, body==null ? Position : ConvertUnits.ToDisplayUnits(body.SimPosition));
ic.PlaySound(ActionType.OnUse, WorldPosition);
ic.ApplyStatusEffects(ActionType.OnUse, deltaTime, character);
@@ -1124,14 +1149,19 @@ namespace Barotrauma
element.Add(new XAttribute("name", prefab.Name),
new XAttribute("ID", ID));
if (prefab.ResizeHorizontal || prefab.ResizeVertical)
{
element.Add(new XAttribute("rect", rect.X + "," + rect.Y + "," + rect.Width + "," + rect.Height));
element.Add(new XAttribute("rect",
(int)(rect.X - Submarine.HiddenSubPosition.X) + "," +
(int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," +
rect.Width + "," + rect.Height));
}
else
{
element.Add(new XAttribute("rect", rect.X + "," + rect.Y));
element.Add(new XAttribute("rect",
(int)(rect.X - Submarine.HiddenSubPosition.X) + "," +
(int)(rect.Y - Submarine.HiddenSubPosition.Y)));
}
if (linkedTo != null && linkedTo.Count>0)
@@ -1159,8 +1189,8 @@ namespace Barotrauma
return element;
}
public static void Load(XElement element)
{
public static void Load(XElement element, Submarine submarine)
{
string rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0");
string[] rectValues = rectString.Split(',');
Rectangle rect = Rectangle.Empty;
@@ -1196,7 +1226,8 @@ namespace Barotrauma
rect.Height = (int)ip.Size.Y;
}
Item item = new Item(rect, ip);
Item item = new Item(rect, ip, submarine);
item.Submarine = submarine;
item.ID = (ushort)int.Parse(element.Attribute("ID").Value);
item.linkedToID = new List<ushort>();
@@ -1243,6 +1274,16 @@ namespace Barotrauma
}
}
public override void OnMapLoaded()
{
FindHull();
foreach (ItemComponent ic in components)
{
ic.OnMapLoaded();
}
}
public void NewComponentEvent(ItemComponent ic, bool isClient, bool isImportant)

View File

@@ -83,7 +83,7 @@ namespace Barotrauma
{
if (PlayerInput.LeftButtonClicked())
{
new Item(new Rectangle((int)position.X, (int)position.Y, (int)sprite.size.X, (int)sprite.size.Y), this);
new Item(new Rectangle((int)position.X, (int)position.Y, (int)sprite.size.X, (int)sprite.size.Y), this, Submarine.Loaded);
//constructor.Invoke(lobject);
placePosition = Vector2.Zero;
@@ -112,7 +112,7 @@ namespace Barotrauma
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released)
{
new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this);
new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this, Submarine.Loaded);
placePosition = Vector2.Zero;
//selected = null;
return;

View File

@@ -30,7 +30,8 @@ namespace Barotrauma
{
var itemInfo = spawnQueue.Dequeue();
new Item(itemInfo.First, itemInfo.Second);
//!!!!!!!!!!!!!!!!!!!!!!
new Item(itemInfo.First, itemInfo.Second, null);
}
}
}