electricity bugfixes, destructable doors, ai improvements, removed rope, container changes
This commit is contained in:
@@ -54,17 +54,19 @@ namespace Subsurface.Items.Components
|
||||
set { itemRotation = value; }
|
||||
}
|
||||
|
||||
//[Initable(Vector2.Zero)]
|
||||
//private Vector2 ItemPos
|
||||
//{
|
||||
// set { itemPos = ConvertUnits.ToSimUnits(value); }
|
||||
//}
|
||||
[HasDefaultValue("0.0,0.0", false)]
|
||||
public string ItemPos
|
||||
{
|
||||
get { return ToolBox.Vector2ToString(itemPos); }
|
||||
set { itemPos = ToolBox.ParseToVector2(value); }
|
||||
}
|
||||
|
||||
//[Initable(Vector2.Zero)]
|
||||
//private Vector2 ItemInterval
|
||||
//{
|
||||
// set { itemInterval = ConvertUnits.ToSimUnits(value); }
|
||||
//}
|
||||
[HasDefaultValue("0.0,0.0", false)]
|
||||
public string ItemInterval
|
||||
{
|
||||
get { return ToolBox.Vector2ToString(itemInterval); }
|
||||
set { itemInterval = ToolBox.ParseToVector2(value); }
|
||||
}
|
||||
|
||||
public ItemContainer(Item item, XElement element)
|
||||
: base (item, element)
|
||||
@@ -72,11 +74,11 @@ namespace Subsurface.Items.Components
|
||||
inventory = new ItemInventory(this, capacity);
|
||||
containableItems = new List<RelatedItem>();
|
||||
|
||||
itemPos = ToolBox.GetAttributeVector2(element, "ItemPos", Vector2.Zero);
|
||||
itemPos = ConvertUnits.ToSimUnits(itemPos);
|
||||
//itemPos = ToolBox.GetAttributeVector2(element, "ItemPos", Vector2.Zero);
|
||||
//itemPos = ConvertUnits.ToSimUnits(itemPos);
|
||||
|
||||
itemInterval = ToolBox.GetAttributeVector2(element, "ItemInterval", Vector2.Zero);
|
||||
itemInterval = ConvertUnits.ToSimUnits(itemInterval);
|
||||
//itemInterval = ToolBox.GetAttributeVector2(element, "ItemInterval", Vector2.Zero);
|
||||
//itemInterval = ConvertUnits.ToSimUnits(itemInterval);
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
@@ -106,7 +108,7 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
if (contained == null) continue;
|
||||
|
||||
if (contained.body!=null) contained.body.Enabled = !hideItems;
|
||||
if (contained.body!=null) contained.body.Enabled = false;
|
||||
|
||||
RelatedItem ri = containableItems.Find(x => x.MatchesItem(item));
|
||||
if (ri == null) continue;
|
||||
@@ -120,40 +122,74 @@ namespace Subsurface.Items.Components
|
||||
contained.ApplyStatusEffects(ActionType.OnContained, deltaTime);
|
||||
}
|
||||
|
||||
if (hideItems) return;
|
||||
//if (hideItems) return;
|
||||
|
||||
//Vector2 transformedItemPos;
|
||||
//Vector2 transformedItemInterval = itemInterval;
|
||||
////float transformedItemRotation = itemRotation;
|
||||
//if (item.body==null)
|
||||
//{
|
||||
// transformedItemPos = new Vector2(item.Rect.X, item.Rect.Y);
|
||||
// transformedItemPos = ConvertUnits.ToSimUnits(transformedItemPos) + itemPos;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// Matrix transform = Matrix.CreateRotationZ(item.body.Rotation);
|
||||
|
||||
// transformedItemPos = item.body.Position + Vector2.Transform(itemPos, transform);
|
||||
// transformedItemInterval = Vector2.Transform(transformedItemInterval, transform);
|
||||
// //transformedItemRotation += item.body.Rotation;
|
||||
//}
|
||||
|
||||
//foreach (Item containedItem in inventory.items)
|
||||
//{
|
||||
// if (containedItem == null) continue;
|
||||
|
||||
// Vector2 itemDist = (transformedItemPos - containedItem.body.Position);
|
||||
// Vector2 force = (itemDist - containedItem.body.LinearVelocity * 0.1f) * containedItem.body.Mass * 60.0f;
|
||||
|
||||
// containedItem.body.ApplyForce(force);
|
||||
|
||||
// containedItem.body.SmoothRotate(itemRotation);
|
||||
|
||||
// transformedItemPos += transformedItemInterval;
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
if (hideItems) return;
|
||||
|
||||
Vector2 transformedItemPos;
|
||||
Vector2 transformedItemInterval = itemInterval;
|
||||
float currentRotation = itemRotation;
|
||||
//float transformedItemRotation = itemRotation;
|
||||
if (item.body==null)
|
||||
if (item.body == null)
|
||||
{
|
||||
transformedItemPos = new Vector2(item.Rect.X, item.Rect.Y);
|
||||
transformedItemPos = ConvertUnits.ToSimUnits(transformedItemPos) + itemPos;
|
||||
transformedItemPos = transformedItemPos + itemPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
Matrix transform = Matrix.CreateRotationZ(item.body.Rotation);
|
||||
|
||||
transformedItemPos = Vector2.Transform(item.body.Position + itemPos, transform);
|
||||
transformedItemInterval = Vector2.Transform(transformedItemInterval, transform);
|
||||
//transformedItemRotation += item.body.Rotation;
|
||||
transformedItemPos = ConvertUnits.ToDisplayUnits(item.body.Position) + Vector2.Transform(itemPos, transform);
|
||||
transformedItemInterval = Vector2.Transform(transformedItemInterval, transform);
|
||||
currentRotation += item.body.Rotation;
|
||||
}
|
||||
|
||||
foreach (Item containedItem in inventory.items)
|
||||
{
|
||||
if (containedItem == null) continue;
|
||||
|
||||
Vector2 itemDist = (transformedItemPos - containedItem.body.Position);
|
||||
Vector2 force = (itemDist - containedItem.body.LinearVelocity * 0.1f) * containedItem.body.Mass * 60.0f;
|
||||
|
||||
containedItem.body.ApplyForce(force);
|
||||
|
||||
containedItem.body.SmoothRotate(itemRotation);
|
||||
containedItem.sprite.Draw(spriteBatch, new Vector2(transformedItemPos.X, -transformedItemPos.Y), -currentRotation, 1.0f);
|
||||
|
||||
transformedItemPos += transformedItemInterval;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||
|
||||
@@ -60,82 +60,30 @@ namespace Subsurface.Items.Components
|
||||
set
|
||||
{
|
||||
isOpen = value;
|
||||
openState = (isOpen) ? 1.0f : 0.0f;
|
||||
OpenState = (isOpen) ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
private Rectangle doorRect;
|
||||
|
||||
|
||||
|
||||
public float OpenState
|
||||
{
|
||||
get { return openState; }
|
||||
set
|
||||
{
|
||||
if (openState == value) return;
|
||||
|
||||
float prevValue = openState;
|
||||
openState = MathHelper.Clamp(value, 0.0f, 1.0f);
|
||||
if (openState == prevValue) return;
|
||||
|
||||
|
||||
|
||||
if (window==null)
|
||||
{
|
||||
Rectangle rect = item.Rect;
|
||||
rect.Height = (int)(rect.Height * (1.0f - openState));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//Rectangle rect = item.Rect;
|
||||
//rect.Height = (int)(rect.Height * (1.0f - openState));
|
||||
|
||||
Rectangle rect1 = doorRect;
|
||||
rect1.Height = -window.Y;
|
||||
|
||||
rect1.Y += (int)(doorRect.Height * openState);
|
||||
rect1.Height = Math.Max(rect1.Height - (rect1.Y - doorRect.Y), 0);
|
||||
rect1.Y = Math.Min(doorRect.Y, rect1.Y);
|
||||
|
||||
if (rect1.Height == 0)
|
||||
{
|
||||
convexHull.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
convexHull.SetVertices(GetConvexHullCorners(rect1));
|
||||
}
|
||||
|
||||
if (convexHull2 != null)
|
||||
{
|
||||
Rectangle rect2 = doorRect;
|
||||
rect2.Y = rect2.Y + window.Y - window.Height;
|
||||
|
||||
rect2.Y += (int)(doorRect.Height * openState);
|
||||
rect2.Y = Math.Min(doorRect.Y, rect2.Y);
|
||||
rect2.Height = rect2.Y - (doorRect.Y - (int)(doorRect.Height * (1.0f - openState)));
|
||||
convexHull2.SetVertices(GetConvexHullCorners(rect2));
|
||||
|
||||
if (rect2.Height == 0)
|
||||
{
|
||||
convexHull2.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
convexHull2.SetVertices(GetConvexHullCorners(rect2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
UpdateConvexHulls();
|
||||
}
|
||||
}
|
||||
|
||||
PhysicsBody body;
|
||||
|
||||
Sprite doorSprite;
|
||||
|
||||
|
||||
public Door(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
@@ -160,7 +108,9 @@ namespace Subsurface.Items.Components
|
||||
ConvertUnits.ToSimUnits(Math.Max(doorRect.Width, 1)),
|
||||
ConvertUnits.ToSimUnits(Math.Max(doorRect.Height, 1)),
|
||||
1.5f));
|
||||
|
||||
|
||||
body.CollisionCategories = Physics.CollisionWall;
|
||||
body.UserData = item;
|
||||
body.BodyType = BodyType.Static;
|
||||
body.SetTransform(
|
||||
ConvertUnits.ToSimUnits(new Vector2(doorRect.Center.X, doorRect.Y - doorRect.Height / 2)),
|
||||
@@ -169,21 +119,69 @@ namespace Subsurface.Items.Components
|
||||
|
||||
|
||||
//string spritePath = Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\"+ ToolBox.GetAttributeString(element, "sprite", "");
|
||||
|
||||
|
||||
|
||||
isActive = true;
|
||||
|
||||
|
||||
|
||||
Vector2[] corners = GetConvexHullCorners(doorRect);
|
||||
|
||||
convexHull = new ConvexHull(corners, Color.Black);
|
||||
if (window!=null) convexHull2 = new ConvexHull(corners, Color.Black);
|
||||
if (window!=null && window!=Rectangle.Empty) convexHull2 = new ConvexHull(corners, Color.Black);
|
||||
|
||||
OpenState = openState;
|
||||
//powerConsumption = -100.0f;
|
||||
UpdateConvexHulls();
|
||||
|
||||
//LinkedGap.Open = openState;
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
private void UpdateConvexHulls()
|
||||
{
|
||||
Rectangle rect = doorRect;
|
||||
|
||||
rect.Height = (int)(rect.Height * (1.0f - openState));
|
||||
if (window.Height == 0 || window.Width == 0)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//Rectangle rect = item.Rect;
|
||||
//rect.Height = (int)(rect.Height * (1.0f - openState));
|
||||
|
||||
rect.Height = -window.Y;
|
||||
|
||||
rect.Y += (int)(doorRect.Height * openState);
|
||||
rect.Height = Math.Max(rect.Height - (rect.Y - doorRect.Y), 0);
|
||||
rect.Y = Math.Min(doorRect.Y, rect.Y);
|
||||
|
||||
|
||||
if (convexHull2 != null)
|
||||
{
|
||||
Rectangle rect2 = doorRect;
|
||||
rect2.Y = rect2.Y + window.Y - window.Height;
|
||||
|
||||
rect2.Y += (int)(doorRect.Height * openState);
|
||||
rect2.Y = Math.Min(doorRect.Y, rect2.Y);
|
||||
rect2.Height = rect2.Y - (doorRect.Y - (int)(doorRect.Height * (1.0f - openState)));
|
||||
//convexHull2.SetVertices(GetConvexHullCorners(rect2));
|
||||
|
||||
if (rect2.Height == 0)
|
||||
{
|
||||
convexHull2.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
convexHull2.Enabled = true;
|
||||
convexHull2.SetVertices(GetConvexHullCorners(rect2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rect.Height == 0)
|
||||
{
|
||||
convexHull.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
convexHull.Enabled = true;
|
||||
convexHull.SetVertices(GetConvexHullCorners(rect));
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2[] GetConvexHullCorners(Rectangle rect)
|
||||
@@ -212,7 +210,6 @@ namespace Subsurface.Items.Components
|
||||
|
||||
public override bool Pick(Character picker)
|
||||
{
|
||||
isActive = true;
|
||||
isOpen = !isOpen;
|
||||
|
||||
return true;
|
||||
@@ -222,22 +219,30 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
OpenState += deltaTime * ((isOpen) ? 3.0f : -3.0f);
|
||||
|
||||
LinkedGap.Open = openState;
|
||||
|
||||
item.SendSignal((isOpen) ? "1" : "0", "state_out");
|
||||
}
|
||||
|
||||
public override void UpdateBroken(float deltaTime, Camera cam)
|
||||
{
|
||||
body.Enabled = false;
|
||||
convexHull.Enabled = false;
|
||||
linkedGap.Open = 1.0f;
|
||||
if (convexHull2 != null) convexHull2.Enabled = false;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
|
||||
LinkedGap.Open = openState;
|
||||
|
||||
Color color = (item.IsSelected) ? Color.Green : Color.White;
|
||||
color = color * (item.Condition / 100.0f);
|
||||
color.A = 255;
|
||||
|
||||
//prefab.sprite.Draw(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), color);
|
||||
|
||||
if (openState == 1.0f)
|
||||
{
|
||||
body.Enabled = false;
|
||||
convexHull.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -246,8 +251,6 @@ namespace Subsurface.Items.Components
|
||||
(int)doorSprite.size.X, (int)(doorSprite.size.Y * (1.0f - openState))),
|
||||
color, 0.0f, doorSprite.Origin, 1.0f, SpriteEffects.None, doorSprite.Depth);
|
||||
|
||||
convexHull.Enabled = true;
|
||||
|
||||
if (openState == 0.0f)
|
||||
{
|
||||
body.Enabled = true;
|
||||
@@ -290,7 +293,6 @@ namespace Subsurface.Items.Components
|
||||
|
||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
||||
{
|
||||
isActive = true;
|
||||
if (connection.name=="toggle")
|
||||
{
|
||||
isOpen = !isOpen;
|
||||
|
||||
@@ -176,54 +176,26 @@ namespace Subsurface
|
||||
}
|
||||
}
|
||||
|
||||
//public List<ObjectProperty> GetProperties<T>()
|
||||
//{
|
||||
// List<ObjectProperty> editableProperties = new List<ObjectProperty>();
|
||||
|
||||
// foreach (var property in properties.Values)
|
||||
// {
|
||||
// if (property.Attributes.OfType<T>().Count() > 0) editableProperties.Add(property);
|
||||
// }
|
||||
|
||||
// return editableProperties;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
private int loopingSoundIndex;
|
||||
|
||||
|
||||
public void PlaySound(ActionType type, float volume, Vector2 position, bool loop=false)
|
||||
{
|
||||
|
||||
if (!loop)
|
||||
{
|
||||
List<ItemSound> matchingSounds = sounds.FindAll(x=> x.type == type);
|
||||
|
||||
if (matchingSounds.Count == 0 || item.Prefab.sounds.Count == 0) return;
|
||||
|
||||
int index = Game1.localRandom.Next(Math.Min(matchingSounds.Count,item.Prefab.sounds.Count));
|
||||
if (loop && Sounds.SoundManager.IsPlaying(loopingSoundIndex)) return;
|
||||
|
||||
Sound sound = item.Prefab.sounds[matchingSounds[index].index];
|
||||
List<ItemSound> matchingSounds = sounds.FindAll(x => x.type == type);
|
||||
if (matchingSounds.Count == 0 || item.Prefab.sounds.Count == 0) return;
|
||||
|
||||
sound.Play(volume, matchingSounds[index].range, position);
|
||||
int index = Game1.localRandom.Next(Math.Min(matchingSounds.Count, item.Prefab.sounds.Count));
|
||||
|
||||
Sound sound = item.Prefab.sounds[matchingSounds[index].index];
|
||||
|
||||
if (loop)
|
||||
{
|
||||
loopingSoundIndex = sound.Loop(loopingSoundIndex, volume, position, matchingSounds[index].range);
|
||||
}
|
||||
else
|
||||
{
|
||||
//todo: get rid of copypaste
|
||||
if (!Sounds.SoundManager.IsPlaying(loopingSoundIndex))
|
||||
{
|
||||
List<ItemSound> matchingSounds = sounds.FindAll(x => x.type == type);
|
||||
|
||||
if (matchingSounds.Count == 0 || item.Prefab.sounds.Count == 0) return;
|
||||
|
||||
int index = Game1.localRandom.Next(Math.Min(matchingSounds.Count, item.Prefab.sounds.Count));
|
||||
|
||||
Sound sound = item.Prefab.sounds[matchingSounds[index].index];
|
||||
|
||||
loopingSoundIndex = sound.Loop(loopingSoundIndex, volume, position, matchingSounds[index].range);
|
||||
}
|
||||
}
|
||||
sound.Play(volume, matchingSounds[index].range, position);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Move(Vector2 amount) { }
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
if (picker == null) return false;
|
||||
|
||||
picker.SelectedConstruction = item;
|
||||
//picker.SelectedConstruction = item;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace Subsurface.Items.Components
|
||||
[Editable, HasDefaultValue(10.0f, true)]
|
||||
public float MaxOutPut
|
||||
{
|
||||
set { maxOutput = value; }
|
||||
get { return maxOutput; }
|
||||
}
|
||||
|
||||
@@ -42,21 +43,24 @@ namespace Subsurface.Items.Components
|
||||
|
||||
|
||||
[HasDefaultValue(10.0f, false)]
|
||||
private float Capacity
|
||||
public float Capacity
|
||||
{
|
||||
get { return capacity; }
|
||||
set { capacity = Math.Max(value,1.0f); }
|
||||
}
|
||||
|
||||
[HasDefaultValue(10.0f, false)]
|
||||
private float MaxInput
|
||||
{
|
||||
set { MaxInput = value; }
|
||||
}
|
||||
//[HasDefaultValue(10.0f, false)]
|
||||
//public float MaxInput
|
||||
//{
|
||||
// get { return maxInput; }
|
||||
// set { maxInput = value; }
|
||||
//}
|
||||
|
||||
[HasDefaultValue(10.0f, false)]
|
||||
private float MaxOutput
|
||||
public float MaxRechargeSpeed
|
||||
{
|
||||
set { maxOutput = value; }
|
||||
get { return maxRechargeSpeed; }
|
||||
set { maxRechargeSpeed = Math.Max(value, 1.0f); }
|
||||
}
|
||||
|
||||
public PowerContainer(Item item, XElement element)
|
||||
@@ -65,9 +69,7 @@ namespace Subsurface.Items.Components
|
||||
//capacity = ToolBox.GetAttributeFloat(element, "capacity", 10.0f);
|
||||
//maxRechargeSpeed = ToolBox.GetAttributeFloat(element, "maxinput", 10.0f);
|
||||
//maxOutput = ToolBox.GetAttributeFloat(element, "maxoutput", 10.0f);
|
||||
|
||||
rechargeSpeed = maxRechargeSpeed;
|
||||
|
||||
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
@@ -129,7 +131,7 @@ namespace Subsurface.Items.Components
|
||||
return;
|
||||
}
|
||||
|
||||
currPowerConsumption = MathHelper.Lerp(currPowerConsumption, rechargeSpeed, 0.05f);
|
||||
currPowerConsumption = MathHelper.Lerp(currPowerConsumption, maxRechargeSpeed*rechargeSpeed, 0.05f);
|
||||
charge += currPowerConsumption*voltage / 3600.0f;
|
||||
}
|
||||
//provide power to the grid
|
||||
@@ -142,10 +144,10 @@ namespace Subsurface.Items.Components
|
||||
return;
|
||||
}
|
||||
|
||||
currPowerConsumption = MathHelper.Lerp(
|
||||
currPowerConsumption,
|
||||
-maxOutput * chargeRate,
|
||||
0.1f);
|
||||
//currPowerConsumption = MathHelper.Lerp(
|
||||
// currPowerConsumption,
|
||||
// -maxOutput * chargeRate,
|
||||
// 0.1f);
|
||||
|
||||
currPowerConsumption = MathHelper.Lerp(
|
||||
currPowerConsumption,
|
||||
|
||||
@@ -49,9 +49,11 @@ namespace Subsurface.Items.Components
|
||||
pt.powerLoad += (fullLoad - pt.powerLoad) / inertia;
|
||||
pt.currPowerConsumption += (-fullPower - pt.currPowerConsumption) / inertia;
|
||||
pt.Item.SendSignal((fullPower / Math.Max(fullLoad,1.0f)).ToString(), "power_out");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//p.Power = fullPower;
|
||||
}
|
||||
}
|
||||
@@ -103,15 +105,15 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
connectedList.Add(powered);
|
||||
//positive power consumption = the construction requires power -> increase load
|
||||
if (powered.PowerConsumption > 0.0f)
|
||||
if (powered.CurrPowerConsumption > 0.0f)
|
||||
{
|
||||
fullLoad += powered.PowerConsumption;
|
||||
fullLoad += powered.CurrPowerConsumption;
|
||||
}
|
||||
else if (powered.PowerConsumption < 0.0f)
|
||||
else if (powered.CurrPowerConsumption < 0.0f)
|
||||
//negative power consumption = the construction is a
|
||||
//generator/battery or another junction box
|
||||
{
|
||||
fullPower -= powered.PowerConsumption;
|
||||
fullPower -= powered.CurrPowerConsumption;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,38 +155,42 @@ namespace Subsurface.Items.Components
|
||||
//f2.Body.ApplyLinearImpulse(force);
|
||||
//f1.Body.ApplyLinearImpulse(-f1.Body.LinearVelocity * f1.Body.Mass);
|
||||
|
||||
float damage = f1.Body.LinearVelocity.Length();
|
||||
//float damage = f1.Body.LinearVelocity.Length();
|
||||
|
||||
Limb limb;
|
||||
Structure structure;
|
||||
if ((limb = (f2.Body.UserData as Limb)) != null)
|
||||
if (attack!=null)
|
||||
{
|
||||
attack.DoDamage(limb.character, item.SimPosition, 0.0f);
|
||||
//limb.Damage += damage;
|
||||
//limb.Bleeding += bleedingDamage;
|
||||
Limb limb;
|
||||
Structure structure;
|
||||
if ((limb = (f2.Body.UserData as Limb)) != null)
|
||||
{
|
||||
attack.DoDamage(limb.character, item.SimPosition, 0.0f);
|
||||
//limb.Damage += damage;
|
||||
//limb.Bleeding += bleedingDamage;
|
||||
|
||||
//if (bleedingDamage>0.0f)
|
||||
//{
|
||||
// for (int i = 0; i < 5; i++ )
|
||||
// {
|
||||
// Game1.particleManager.CreateParticle(limb.SimPosition,
|
||||
// ToolBox.VectorToAngle(-f1.Body.LinearVelocity*0.5f) + ToolBox.RandomFloat(-0.5f, 0.5f),
|
||||
// ToolBox.RandomFloat(1.0f, 3.0f), "blood");
|
||||
// }
|
||||
//if (bleedingDamage>0.0f)
|
||||
//{
|
||||
// for (int i = 0; i < 5; i++ )
|
||||
// {
|
||||
// Game1.particleManager.CreateParticle(limb.SimPosition,
|
||||
// ToolBox.VectorToAngle(-f1.Body.LinearVelocity*0.5f) + ToolBox.RandomFloat(-0.5f, 0.5f),
|
||||
// ToolBox.RandomFloat(1.0f, 3.0f), "blood");
|
||||
// }
|
||||
|
||||
// Game1.particleManager.CreateParticle(limb.SimPosition,
|
||||
// 0.0f,
|
||||
// Vector2.Zero, "waterblood");
|
||||
//}
|
||||
// Game1.particleManager.CreateParticle(limb.SimPosition,
|
||||
// 0.0f,
|
||||
// Vector2.Zero, "waterblood");
|
||||
//}
|
||||
|
||||
//AmbientSoundManager.PlayDamageSound(DamageType.LimbBlunt, damage, limb.body.FarseerBody);
|
||||
//AmbientSoundManager.PlayDamageSound(DamageType.LimbBlunt, damage, limb.body.FarseerBody);
|
||||
}
|
||||
else if ((structure = (f2.Body.UserData as Structure)) != null)
|
||||
{
|
||||
attack.DoDamage(structure, item.SimPosition, 0.0f);
|
||||
|
||||
//AmbientSoundManager.PlayDamageSound(DamageType.StructureBlunt, damage, f2.Body);
|
||||
}
|
||||
}
|
||||
else if ((structure = (f2.Body.UserData as Structure)) != null)
|
||||
{
|
||||
attack.DoDamage(structure, item.SimPosition, 0.0f);
|
||||
|
||||
//AmbientSoundManager.PlayDamageSound(DamageType.StructureBlunt, damage, f2.Body);
|
||||
}
|
||||
|
||||
item.body.FarseerBody.OnCollision -= OnProjectileCollision;
|
||||
|
||||
|
||||
@@ -18,8 +18,9 @@ namespace Subsurface.Items.Components
|
||||
Hull hull1, hull2;
|
||||
|
||||
[HasDefaultValue(100.0f, false)]
|
||||
private float MaxFlow
|
||||
{
|
||||
public float MaxFlow
|
||||
{
|
||||
get { return maxFlow; }
|
||||
set { maxFlow = value; }
|
||||
}
|
||||
|
||||
@@ -41,14 +42,14 @@ namespace Subsurface.Items.Components
|
||||
if (voltage < minVoltage) return;
|
||||
|
||||
if (hull2 == null && hull1 == null) return;
|
||||
|
||||
float powerFactor = (currPowerConsumption==0.0f) ? 1.0f : voltage;
|
||||
flow = maxFlow * powerFactor;
|
||||
|
||||
float deltaVolume = flow * ((flowIn) ? 1.0f : -1.0f);
|
||||
hull1.Volume += deltaVolume;
|
||||
if (hull2 != null) hull2.Volume -= deltaVolume;
|
||||
|
||||
float powerFactor = (currPowerConsumption==0.0f) ? 1.0f : voltage;
|
||||
flow = maxFlow * powerFactor;
|
||||
|
||||
voltage = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,9 +126,10 @@ namespace Subsurface.Items.Components
|
||||
if (powerUpTask==null || powerUpTask.IsFinished)
|
||||
{
|
||||
powerUpTask = new PropertyTask(Game1.gameSession.taskManager, item, IsRunning, 20.0f, "Power up the reactor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
item.Condition -= temperature*deltaTime*0.00005f;
|
||||
|
||||
if (temperature > shutDownTemp)
|
||||
@@ -157,7 +158,7 @@ namespace Subsurface.Items.Components
|
||||
FissionRate = Math.Max(fissionRate, heat / 200.0f);
|
||||
|
||||
//the power generated by the reactor is equal to the temperature
|
||||
currPowerConsumption = -temperature;
|
||||
currPowerConsumption = -temperature*powerPerTemp;
|
||||
|
||||
if (item.currentHull != null)
|
||||
{
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
gunJoint.Length = Math.Max(gunJoint.Length-0.003f,0.01f);
|
||||
gunJoint.Length = Math.Max(gunJoint.Length-0.01f,0.01f);
|
||||
gunJoint.Frequency = 30;
|
||||
gunJoint.DampingRatio = 0.05f;
|
||||
//gunJoint.MotorEnabled = true;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -32,7 +34,12 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character)
|
||||
public override void Move(Vector2 amount)
|
||||
{
|
||||
base.Move(amount);
|
||||
}
|
||||
|
||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||
{
|
||||
if (user!=character) return;
|
||||
Connection.DrawConnections(spriteBatch, this, character);
|
||||
@@ -44,8 +51,6 @@ namespace Subsurface.Items.Components
|
||||
|
||||
foreach (Connection c in connections)
|
||||
{
|
||||
//XElement newElement = new XElement(c.isOutput ? "output" : "input", new XAttribute("name", c.name));
|
||||
|
||||
c.Save(componentElement);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,20 +11,23 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
class Wire : ItemComponent
|
||||
{
|
||||
const float nodeDistance = 128.0f;
|
||||
const float nodeDistance = 32.0f;
|
||||
const float heightFromFloor = 128.0f;
|
||||
|
||||
static Sprite wireSprite;
|
||||
|
||||
List<Vector2> nodes;
|
||||
|
||||
|
||||
Connection[] connections;
|
||||
|
||||
private Vector2 newNodePos;
|
||||
|
||||
public Wire(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
if (wireSprite==null)
|
||||
if (wireSprite == null)
|
||||
{
|
||||
wireSprite = new Sprite("Content/Items/wireHorizontal.png",new Vector2(0.5f,0.5f));
|
||||
wireSprite = new Sprite("Content/Items/wireHorizontal.png", new Vector2(0.5f, 0.5f));
|
||||
wireSprite.Depth = 0.85f;
|
||||
}
|
||||
|
||||
@@ -35,9 +38,9 @@ namespace Subsurface.Items.Components
|
||||
|
||||
public Connection OtherConnection(Connection connection)
|
||||
{
|
||||
if (connection==null) return null;
|
||||
if (connection==connections[0]) return connections[1];
|
||||
if (connection==connections[1]) return connections[0];
|
||||
if (connection == null) return null;
|
||||
if (connection == connections[0]) return connections[1];
|
||||
if (connection == connections[1]) return connections[0];
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -49,7 +52,7 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
|
||||
public void Connect(Connection newConnection, bool addNode = true)
|
||||
{
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (connections[i] == newConnection) return;
|
||||
@@ -62,8 +65,8 @@ namespace Subsurface.Items.Components
|
||||
connections[i] = newConnection;
|
||||
|
||||
if (!addNode) break;
|
||||
|
||||
if (i==0)
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
nodes.Insert(0, newConnection.Item.Position);
|
||||
}
|
||||
@@ -71,16 +74,18 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
nodes.Add(newConnection.Item.Position);
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (connections[0]!=null && connections[1]!=null)
|
||||
if (connections[0] != null && connections[1] != null)
|
||||
{
|
||||
item.Drop(null, false);
|
||||
item.body.Enabled = false;
|
||||
|
||||
isActive = false;
|
||||
|
||||
CleanNodes();
|
||||
}
|
||||
|
||||
@@ -98,61 +103,80 @@ namespace Subsurface.Items.Components
|
||||
public override void Unequip(Character character)
|
||||
{
|
||||
ClearConnections();
|
||||
|
||||
isActive = false;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
if (nodes.Count == 0) return;
|
||||
|
||||
if (Math.Abs(item.Position.X-nodes[nodes.Count-1].X)>nodeDistance)
|
||||
{
|
||||
nodes.Add(new Vector2(
|
||||
ToolBox.Round(item.Position.X, Map.gridSize.X),
|
||||
nodes[nodes.Count - 1].Y));
|
||||
item.FindHull();
|
||||
|
||||
item.NewComponentEvent(this, true);
|
||||
}
|
||||
else if (Math.Abs(item.Position.Y-nodes[nodes.Count-1].Y)>nodeDistance)
|
||||
Vector2 position = item.Position;
|
||||
position.X = ToolBox.Round(item.Position.X, nodeDistance);
|
||||
if (item.currentHull == null)
|
||||
{
|
||||
nodes.Add(new Vector2(nodes[nodes.Count - 1].X,
|
||||
ToolBox.Round(item.Position.Y, Map.gridSize.Y)));
|
||||
|
||||
item.NewComponentEvent(this, true);
|
||||
position.Y = ToolBox.Round(item.Position.Y, nodeDistance);
|
||||
}
|
||||
else
|
||||
{
|
||||
position.Y -= item.currentHull.Rect.Y - item.currentHull.Rect.Height;
|
||||
position.Y = Math.Max(ToolBox.Round(position.Y, nodeDistance), heightFromFloor);
|
||||
position.Y += item.currentHull.Rect.Y - item.currentHull.Rect.Height;
|
||||
}
|
||||
|
||||
newNodePos = position;
|
||||
|
||||
//if (Vector2.Distance(position, nodes[nodes.Count - 1]) > nodeDistance*10)
|
||||
//{
|
||||
// nodes.Add(position);
|
||||
|
||||
// item.NewComponentEvent(this, true);
|
||||
//}
|
||||
//else if (Math.Abs(position.Y - nodes[nodes.Count - 1].Y) > nodeDistance)
|
||||
//{
|
||||
// nodes.Add(new Vector2(nodes[nodes.Count - 1].X,
|
||||
// position.Y));
|
||||
|
||||
// item.NewComponentEvent(this, true);
|
||||
//}
|
||||
}
|
||||
|
||||
//public override bool Use(Character character = null)
|
||||
//{
|
||||
// Vector2 nodePos = item.Position;
|
||||
// ToolBox.Round(nodePos.X, Map.gridSize.X);
|
||||
// ToolBox.Round(nodePos.Y, Map.gridSize.Y);
|
||||
public override bool Use(Character character = null)
|
||||
{
|
||||
if (newNodePos!= Vector2.Zero && nodes.Count>0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
|
||||
{
|
||||
nodes.Add(newNodePos);
|
||||
newNodePos = Vector2.Zero;
|
||||
}
|
||||
|
||||
// nodes.Add(nodePos);
|
||||
|
||||
// return true;
|
||||
//}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void SecondaryUse(Character character = null)
|
||||
{
|
||||
if (nodes.Count > 0)
|
||||
if (nodes.Count > 1)
|
||||
{
|
||||
nodes.RemoveAt(nodes.Count - 1);
|
||||
item.NewComponentEvent(this, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override bool Pick(Character picker)
|
||||
{
|
||||
ClearConnections();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void ClearConnections()
|
||||
{
|
||||
nodes.Clear();
|
||||
|
||||
for (int i = 0; i < 2; i++ )
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (connections[i] == null) continue;
|
||||
int wireIndex = connections[i].FindWireIndex(item);
|
||||
@@ -168,8 +192,8 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
for (int i = nodes.Count - 2; i > 0; i--)
|
||||
{
|
||||
if ((nodes[i-1].X == nodes[i].X || nodes[i-1].Y == nodes[i].Y) &&
|
||||
(nodes[i+1].X == nodes[i].X || nodes[i+1].Y == nodes[i].Y))
|
||||
if ((nodes[i - 1].X == nodes[i].X || nodes[i - 1].Y == nodes[i].Y) &&
|
||||
(nodes[i + 1].X == nodes[i].X || nodes[i + 1].Y == nodes[i].Y))
|
||||
{
|
||||
if (Vector2.Distance(nodes[i - 1], nodes[i]) == Vector2.Distance(nodes[i + 1], nodes[i]))
|
||||
{
|
||||
@@ -199,29 +223,38 @@ namespace Subsurface.Items.Components
|
||||
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
{
|
||||
if (nodes.Count == 0) return;
|
||||
|
||||
for (int i = 0; i < nodes.Count; i++)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)nodes[i].X, (int)-nodes[i].Y, 5, 5), Color.DarkGray, true, wireSprite.Depth - 0.01f);
|
||||
}
|
||||
|
||||
for (int i = 1; i<nodes.Count; i++)
|
||||
for (int i = 1; i < nodes.Count; i++)
|
||||
{
|
||||
DrawSection(spriteBatch, nodes[i], nodes[i - 1], i);
|
||||
DrawSection(spriteBatch, nodes[i], nodes[i - 1], i, Color.White);
|
||||
}
|
||||
|
||||
if (isActive && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
|
||||
{
|
||||
DrawSection(spriteBatch, nodes[nodes.Count - 1], newNodePos, nodes.Count, Color.White * 0.5f);
|
||||
//nodes.Add(newNodePos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, int i)
|
||||
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, int i, Color color)
|
||||
{
|
||||
start.Y = -start.Y;
|
||||
end.Y = -end.Y;
|
||||
|
||||
|
||||
spriteBatch.Draw(wireSprite.Texture,
|
||||
start, null, Color.White,
|
||||
start, null, color,
|
||||
ToolBox.VectorToAngle(end - start),
|
||||
new Vector2(0.0f, wireSprite.size.Y / 2.0f),
|
||||
new Vector2((Vector2.Distance(start, end)) / wireSprite.Texture.Width, 0.3f),
|
||||
SpriteEffects.None,
|
||||
wireSprite.Depth +0.1f + i * 0.00001f);
|
||||
wireSprite.Depth + 0.1f + i * 0.00001f);
|
||||
}
|
||||
|
||||
public override XElement Save(XElement parentElement)
|
||||
@@ -230,7 +263,7 @@ namespace Subsurface.Items.Components
|
||||
|
||||
if (nodes == null || nodes.Count == 0) return componentElement;
|
||||
|
||||
string[] nodeCoords = new string[nodes.Count()*2];
|
||||
string[] nodeCoords = new string[nodes.Count() * 2];
|
||||
for (int i = 0; i < nodes.Count(); i++)
|
||||
{
|
||||
nodeCoords[i * 2] = nodes[i].X.ToString(CultureInfo.InvariantCulture);
|
||||
@@ -250,7 +283,7 @@ namespace Subsurface.Items.Components
|
||||
if (nodeString == "") return;
|
||||
|
||||
string[] nodeCoords = nodeString.Split(';');
|
||||
for (int i = 0; i<nodeCoords.Length/2; i++)
|
||||
for (int i = 0; i < nodeCoords.Length / 2; i++)
|
||||
{
|
||||
float x = 0.0f, y = 0.0f;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user