Rendering lights, fow penumbra, human anim tweaking, female sprite, electricity bugfixes

This commit is contained in:
Regalis
2015-07-24 00:36:44 +03:00
parent 4820e55e05
commit c2be74324d
36 changed files with 334 additions and 150 deletions
+1 -1
View File
@@ -123,7 +123,7 @@ namespace Subsurface.Items.Components
{
foreach (Item contained in inventory.items)
{
if (contained == null) continue;
if (contained == null || contained.Condition<=0.0f) continue;
if (contained.body!=null) contained.body.Enabled = false;
@@ -162,7 +162,7 @@ namespace Subsurface.Items.Components
// return false;
//}
if (attached) return false;
//if (attached) return false;
item.body = body;
item.body.Enabled = true;
@@ -172,12 +172,14 @@ namespace Subsurface.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
if (!attachable || item.body==null) return false;
if (!attachable || item.body==null) return true;
item.Drop();
item.body.Enabled = false;
item.body = null;
attached = true;
return true;
}
+4 -4
View File
@@ -396,18 +396,18 @@ namespace Subsurface
public bool HasRequiredContainedItems(bool addMessage)
{
if (!requiredItems.Any()) return true;
List<RelatedItem> requiredContained = requiredItems.FindAll(ri=> ri.Type == RelatedItem.RelationType.Contained);
if (!requiredContained.Any()) return true;
Item[] containedItems = item.ContainedItems;
if (containedItems == null || !containedItems.Any()) return false;
foreach (RelatedItem ri in requiredItems)
foreach (RelatedItem ri in requiredContained)
{
if (ri.Type != RelatedItem.RelationType.Contained) continue;
Item containedItem = Array.Find(containedItems, x => x != null && x.Condition > 0.0f && ri.MatchesItem(x));
if (containedItem == null)
{
//if (addMessage && !String.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
if (addMessage && !string.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
return false;
}
+30 -22
View File
@@ -54,7 +54,7 @@ namespace Subsurface.Items.Components
pingState = (pingState + deltaTime * 0.5f);
if (pingState>1.0f)
{
item.Use(deltaTime,null);
item.Use(deltaTime, null);
pingState = 0.0f;
}
@@ -63,7 +63,7 @@ namespace Subsurface.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
return true;
return (pingState > 1.0f);
}
public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character)
@@ -87,7 +87,7 @@ namespace Subsurface.Items.Components
//lineEnd += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Math.Min(width, height) / 2.0f;
//GUI.DrawLine(spriteBatch, GuiFrame.Center, lineEnd, Color.Green);
if (!isActive || Level.Loaded == null) return;
if (!isActive) return;
if (pingCircle!=null)
{
@@ -97,35 +97,43 @@ namespace Subsurface.Items.Components
float scale = 0.015f;
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.Position, 7);
Vector2 offset = Vector2.Zero;
for (int i = 0; i < edges.Count; i++)
if (Level.Loaded != null)
{
GUI.DrawLine(spriteBatch,
center + (edges[i][0] - offset) * scale,
center + (edges[i][1] - offset) * scale, Color.White);
}
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.Position, 7);
Vector2 offset = Vector2.Zero;
scale = ConvertUnits.ToDisplayUnits(scale);
for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++)
{
Vector2 start = Submarine.Loaded.HullVertices[i] * scale;
start.Y = -start.Y;
Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * scale;
end.Y = -end.Y;
for (int i = 0; i < edges.Count; i++)
{
GUI.DrawLine(spriteBatch,
center + (edges[i][0] - offset) * scale,
center + (edges[i][1] - offset) * scale, Color.White);
}
GUI.DrawLine(spriteBatch, center + start, center + end, Color.White);
scale = ConvertUnits.ToDisplayUnits(scale);
for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++)
{
Vector2 start = Submarine.Loaded.HullVertices[i] * scale;
start.Y = -start.Y;
Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * scale;
end.Y = -end.Y;
GUI.DrawLine(spriteBatch, center + start, center + end, Color.White);
}
}
foreach (Character c in Character.CharacterList)
{
if (c.AnimController.CurrentHull != null) continue;
if (c.SimPosition!=Vector2.Zero && c.SimPosition.Length() < 7*Level.GridCellWidth)
if (c.SimPosition != Vector2.Zero && c.SimPosition.Length() < 7 * Level.GridCellWidth)
{
int width = (int)c.Mass/5;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)c.Position.X - width / 2, (int)c.Position.Y - width / 2, width, width), Color.White);
int width = (int)Math.Min(c.Mass / 5, 30);
Vector2 pos = c.Position * scale;
pos.Y = -pos.Y;
pos += center;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X - width / 2, (int)pos.Y - width / 2, width, width), Color.White, true);
}
}
@@ -112,7 +112,7 @@ namespace Subsurface.Items.Components
fissionRate = Math.Min(fissionRate, AvailableFuel);
float heat = 100 * fissionRate;
float heat = 100 * fissionRate * (AvailableFuel/2000.0f);
float heatDissipation = 50 * coolingRate + ExtraCooling;
float deltaTemp = (((heat - heatDissipation) * 5) - temperature) / 1000.0f;
@@ -125,14 +125,14 @@ namespace Subsurface.Items.Components
}
else if (temperature==0.0f)
{
if (powerUpTask==null || powerUpTask.IsFinished)
if (powerUpTask == null || powerUpTask.IsFinished)
{
powerUpTask = new PropertyTask(item, IsRunning, 50.0f, "Power up the reactor");
}
}
}
item.Condition -= temperature*deltaTime*0.00005f;
item.Condition -= temperature * deltaTime * 0.00005f;
if (temperature > shutDownTemp)
{
@@ -360,13 +360,13 @@ namespace Subsurface.Items.Components
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.White);
Vector2 prevPoint = new Vector2(x, y + height - (graph[1] + (graph[0] - graph[1]) * xOffset) * yScale);
Vector2 prevPoint = new Vector2(x + width, y + height - (graph[1] + (graph[0] - graph[1]) * xOffset) * yScale);
float currX = x + ((xOffset - 1.0f) * lineWidth);
float currX = x + width - ((xOffset - 1.0f) * lineWidth);
for (int i = 1; i < graph.Count - 1; i++)
{
currX += lineWidth;
currX -= lineWidth;
Vector2 newPoint = new Vector2(currX, y + height - graph[i] * yScale);
@@ -375,7 +375,7 @@ namespace Subsurface.Items.Components
prevPoint = newPoint;
}
Vector2 lastPoint = new Vector2(x + width,
Vector2 lastPoint = new Vector2(x,
y + height - (graph[graph.Count - 1] + (graph[graph.Count - 2] - graph[graph.Count - 1]) * xOffset) * yScale);
GUI.DrawLine(spriteBatch, prevPoint, lastPoint, Color.Red);
@@ -138,7 +138,7 @@ namespace Subsurface.Items.Components
return;
}
currPowerConsumption = MathHelper.Lerp(currPowerConsumption, maxRechargeSpeed*rechargeSpeed, 0.05f);
currPowerConsumption = MathHelper.Lerp(currPowerConsumption, rechargeSpeed, 0.05f);
charge += currPowerConsumption*voltage / 3600.0f;
}
//provide power to the grid
@@ -3,12 +3,15 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Subsurface.Lights;
using System;
using System.IO;
using System.Xml.Linq;
namespace Subsurface.Items.Components
{
class LightComponent : Powered
{
static Sound[] sparkSounds;
private Color lightColor;
//private Sprite sprite;
@@ -19,7 +22,7 @@ namespace Subsurface.Items.Components
float lightBrightness;
[HasDefaultValue(100.0f, true)]
[Editable, HasDefaultValue(100.0f, true)]
public float Range
{
get { return range; }
@@ -47,6 +50,16 @@ namespace Subsurface.Items.Components
public LightComponent(Item item, XElement element)
: base (item, element)
{
if (sparkSounds==null)
{
sparkSounds = new Sound[4];
string dir = Path.GetDirectoryName(item.Prefab.ConfigFile)+"\\";
for (int i = 0; i<4; i++)
{
sparkSounds[i] = Sound.Load(dir+"zap"+(i+1)+".ogg");
}
}
//foreach (XElement subElement in element.Elements())
//{
// if (subElement.Name.ToString().ToLower() != "sprite") continue;
@@ -79,8 +92,9 @@ namespace Subsurface.Items.Components
currPowerConsumption = powerConsumption;
}
if (voltage < Rand.Range(0.0f, minVoltage))
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);
lightBrightness = 0.0f;
}
else