fixed railgun, fixed repairtools radar ping & improved rendering, waypoint bugfixes, inventory bugfixes, syncing wires between clients

This commit is contained in:
Regalis
2015-07-15 23:34:13 +03:00
parent 44b9a63c94
commit 237df18765
39 changed files with 461 additions and 405 deletions
+2 -2
View File
@@ -116,7 +116,7 @@ namespace Subsurface
if (startNode == null || endNode == null) if (startNode == null || endNode == null)
{ {
DebugConsole.ThrowError("Pathfinding error, couldn't find pathnodes"); DebugConsole.ThrowError("Pathfinding error, couldn't find pathnodes");
return null; return new SteeringPath();
} }
return FindPath(startNode,endNode); return FindPath(startNode,endNode);
@@ -141,7 +141,7 @@ namespace Subsurface
if (startNode==null || endNode==null) if (startNode==null || endNode==null)
{ {
DebugConsole.ThrowError("Pathfinding error, couldn't find matching pathnodes to waypoints"); DebugConsole.ThrowError("Pathfinding error, couldn't find matching pathnodes to waypoints");
return null; return new SteeringPath();;
} }
} }
+6 -3
View File
@@ -86,9 +86,12 @@ namespace Subsurface
foreach (XElement subElement in element.Elements()) foreach (XElement subElement in element.Elements())
{ {
if (subElement.Name.ToString().ToLower() != "skill") continue;
string skillName = ToolBox.GetAttributeString(subElement, "name", "");
if (string.IsNullOrEmpty(name)) continue;
skills.Add( skills.Add(
subElement.Name.ToString(), skillName,
new Skill(subElement.Name.ToString(), ToolBox.GetAttributeInt(subElement, "level", 0))); new Skill(skillName, ToolBox.GetAttributeInt(subElement, "level", 0)));
} }
} }
@@ -115,7 +118,7 @@ namespace Subsurface
foreach (KeyValuePair<string, Skill> skill in skills) foreach (KeyValuePair<string, Skill> skill in skills)
{ {
jobElement.Add(new XElement(skill.Key, new XAttribute("level", skill.Value.Level))); jobElement.Add(new XElement("skill", new XAttribute("name", skill.Value.Name), new XAttribute("level", skill.Value.Level)));
} }
parentElement.Add(jobElement); parentElement.Add(jobElement);
+1 -1
View File
@@ -609,7 +609,7 @@ namespace Subsurface
float dist = Vector2.Distance(limbPos, gapPos); float dist = Vector2.Distance(limbPos, gapPos);
force += Vector2.Normalize(gap.FlowForce)*(Math.Max(gap.FlowForce.Length() - dist, 0.0f)/500.0f); force += Vector2.Normalize(gap.FlowForce)*(Math.Max(gap.FlowForce.Length() - dist, 0.0f)/1000.0f);
} }
if (force.Length() > 20.0f) return force; if (force.Length() > 20.0f) return force;
@@ -31,6 +31,7 @@
</Steering> </Steering>
<Radar canbeselected = "true"> <Radar canbeselected = "true">
<sound file="radarPing.ogg" type="OnUse" range="4000.0"/>
<GuiFrame rect="0,0,0.5,0.5" alignment="Center" color="0.0,0.0,0.0,0.0"/> <GuiFrame rect="0,0,0.5,0.5" alignment="Center" color="0.0,0.0,0.0,0.0"/>
<PingCircle texture="Content/Items/Engine/pingCircle.png" origin="0.5,0.5"/> <PingCircle texture="Content/Items/Engine/pingCircle.png" origin="0.5,0.5"/>
<ScreenOverlay texture="Content/Items/Engine/radarOverlay.png" origin="0.5,0.5"/> <ScreenOverlay texture="Content/Items/Engine/radarOverlay.png" origin="0.5,0.5"/>
Binary file not shown.
+19 -3
View File
@@ -3,7 +3,8 @@
name="Railgun" name="Railgun"
focusonselected="true" focusonselected="true"
offsetonselected="500" offsetonselected="500"
linkable="true"> linkable="true"
pickdistance="150">
<Sprite texture ="railgunbase.png"/> <Sprite texture ="railgunbase.png"/>
@@ -12,6 +13,13 @@
powerconsumption="500.0"> powerconsumption="500.0">
<Sound file="railgun.ogg" type="OnUse"/> <Sound file="railgun.ogg" type="OnUse"/>
</Turret> </Turret>
<ConnectionPanel canbeselected = "true" msg="Rewire [Screwdriver]">
<requireditem name="Screwdriver,Wire" type="Equipped"/>
<input name="power_in"/>
<input name="position_in"/>
<input name="trigger_in"/>
</ConnectionPanel>
</Item> </Item>
<Item <Item
@@ -28,7 +36,13 @@
<limbposition limb="RightHand" position="38,-125"/> <limbposition limb="RightHand" position="38,-125"/>
</Controller> </Controller>
<trigger x="-50" y="-87" width="200" height ="153"/> <ConnectionPanel canbeselected = "true" msg="Rewire [Screwdriver]">
<requireditem name="Screwdriver,Wire" type="Equipped"/>
<input name="power_in"/>
<output name="position_out"/>
<output name="trigger_out"/>
</ConnectionPanel>
</Item> </Item>
<Item <Item
@@ -54,7 +68,9 @@
<Holdable holdpos="30,-15" handle1="0,20" handle2="0,-20"/> <Holdable holdpos="30,-15" handle1="0,20" handle2="0,-20"/>
<Pickable slots="RightHand"/> <Pickable slots="RightHand"/>
<Projectile launchimpulse="80.0"/> <Projectile launchimpulse="80.0">
<Attack damage="100" bleedingdamage="10" structuredamage="200" damagetype="Blunt"/>
</Projectile>
</Item> </Item>
</Items> </Items>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

+16 -1
View File
@@ -3,7 +3,7 @@
<MonsterEvent name="Under attack" description="" <MonsterEvent name="Under attack" description=""
characterfile="Content/Characters/Crawler/Crawler.xml" characterfile="Content/Characters/Crawler/Crawler.xml"
commonness="10" commonness="10"
difficulty="30" difficulty="10"
minamount="2" maxamount="3" minamount="2" maxamount="3"
starttimemin="15" starttimemax="20" starttimemin="15" starttimemax="20"
musictype="monster"/> musictype="monster"/>
@@ -14,4 +14,19 @@
difficulty="50" difficulty="50"
starttimemin="15" starttimemax="20" starttimemin="15" starttimemax="20"
musictype="monster"/> musictype="monster"/>
<MonsterEvent name="Under attack" description=""
characterfile="Content/Characters/Moloch/moloch.xml"
commonness="10"
difficulty="30"
starttimemin="15" starttimemax="20"
musictype="monster"/>
<MonsterEvent name="Under attack" description=""
characterfile="Content/Characters/Mantis/mantis.xml"
commonness="10"
difficulty="10"
minamount="2" maxamount="3"
starttimemin="15" starttimemax="20"
musictype="monster"/>
</Randomevents> </Randomevents>
+5 -7
View File
@@ -265,20 +265,18 @@ namespace Subsurface
public static void Draw(float deltaTime, SpriteBatch spriteBatch, Camera cam) public static void Draw(float deltaTime, SpriteBatch spriteBatch, Camera cam)
{ {
spriteBatch.DrawString(font, spriteBatch.DrawString(font,
"FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond, "FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond
+ " - Physics: " + Game1.World.UpdateTime
+ " - bodies: " + Game1.World.BodyList.Count,
new Vector2(10, 10), Color.White); new Vector2(10, 10), Color.White);
spriteBatch.DrawString(font,
"Physics: " + Game1.World.UpdateTime
+ " - bodies: " + Game1.World.BodyList.Count,
new Vector2(10, 30), Color.White);
spriteBatch.DrawString(font, spriteBatch.DrawString(font,
"Camera pos: " + Game1.GameScreen.Cam.Position, "Camera pos: " + Game1.GameScreen.Cam.Position,
new Vector2(10, 50), Color.White); new Vector2(10, 30), Color.White);
if (Character.Controlled != null && cam!=null) Character.Controlled.DrawHud(spriteBatch, cam); if (Character.Controlled != null && cam!=null) Character.Controlled.DrawHud(spriteBatch, cam);
if (Game1.NetworkMember != null) Game1.NetworkMember.Draw(spriteBatch);
DrawMessages(spriteBatch, (float)deltaTime); DrawMessages(spriteBatch, (float)deltaTime);
+19 -6
View File
@@ -44,6 +44,17 @@ namespace Subsurface
} }
} }
public float BarScroll
{
get { return scrollBar.BarScroll; }
set { scrollBar.BarScroll = value; }
}
public float BarSize
{
get { return scrollBar.BarSize; }
}
public int Spacing public int Spacing
{ {
get { return spacing; } get { return spacing; }
@@ -173,14 +184,16 @@ namespace Subsurface
{ {
base.AddChild(child); base.AddChild(child);
float oldScroll = scrollBar.BarScroll; //float oldScroll = scrollBar.BarScroll;
float oldSize = scrollBar.BarSize; //float oldSize = scrollBar.BarSize;
UpdateScrollBarSize(); UpdateScrollBarSize();
if (scrollBar.BarSize < 1.0f && oldScroll == 1.0f) //if (oldSize == 1.0f && scrollBar.BarScroll == 0.0f) scrollBar.BarScroll = 1.0f;
{
scrollBar.BarScroll = 1.0f; //if (scrollBar.BarSize < 1.0f && oldScroll == 1.0f)
} //{
// scrollBar.BarScroll = 1.0f;
//}
} }
+3 -2
View File
@@ -107,9 +107,10 @@ namespace Subsurface
private void UpdateRect() private void UpdateRect()
{ {
bar.Rect = new Rectangle( bar.Rect = new Rectangle(
frame.Rect.X, bar.Rect.X,
frame.Rect.Y, bar.Rect.Y,
isHorizontal ? (int)(frame.Rect.Width * barSize) : frame.Rect.Width, isHorizontal ? (int)(frame.Rect.Width * barSize) : frame.Rect.Width,
isHorizontal ? frame.Rect.Height : (int)(frame.Rect.Height * barSize)); isHorizontal ? frame.Rect.Height : (int)(frame.Rect.Height * barSize));
+1 -1
View File
@@ -120,7 +120,7 @@ namespace Subsurface
{ {
if (!isRunning) return; if (!isRunning) return;
if (duration!=TimeSpan.Zero) if (duration != TimeSpan.Zero)
{ {
double elapsedTime = (DateTime.Now - startTime).TotalSeconds; double elapsedTime = (DateTime.Now - startTime).TotalSeconds;
timerBar.BarSize = (float)(elapsedTime / duration.TotalSeconds); timerBar.BarSize = (float)(elapsedTime / duration.TotalSeconds);
+1 -9
View File
@@ -134,14 +134,6 @@ namespace Subsurface
submarine.SetPosition(level.StartPosition - new Vector2(0.0f, 2000.0f)); submarine.SetPosition(level.StartPosition - new Vector2(0.0f, 2000.0f));
} }
foreach (Item item in Item.itemList)
{
foreach (ItemComponent ic in item.components)
{
ic.OnMapLoaded();
}
}
taskManager.StartShift(level); taskManager.StartShift(level);
} }
@@ -227,7 +219,7 @@ namespace Subsurface
//double elapsedTime = (DateTime.Now-startTime).TotalSeconds; //double elapsedTime = (DateTime.Now-startTime).TotalSeconds;
//timerBar.BarSize = (float)(elapsedTime / Math.Max(duration, 1.0)); //timerBar.BarSize = (float)(elapsedTime / Math.Max(duration, 1.0));
if (PlayerInput.KeyHit(Keys.Tab)) if (PlayerInput.KeyHit(Keys.Tab) && textBox!=null)
{ {
if (textBox.Selected) if (textBox.Selected)
{ {
+7 -1
View File
@@ -25,6 +25,12 @@ namespace Subsurface
this.character = character; this.character = character;
} }
protected override void DropItem(Item item)
{
item.Drop(character);
item.body.SetTransform(character.SimPosition, 0.0f);
}
public int FindLimbSlot(LimbSlot limbSlot) public int FindLimbSlot(LimbSlot limbSlot)
{ {
for (int i = 0; i < items.Length; i++) for (int i = 0; i < items.Length; i++)
@@ -232,7 +238,7 @@ namespace Subsurface
else else
{ {
draggingItem.body.SetTransform(character.SimPosition, 0.0f); draggingItem.body.SetTransform(character.SimPosition, 0.0f);
draggingItem.Drop(character); DropItem(draggingItem);
//draggingItem = null; //draggingItem = null;
} }
} }
@@ -129,7 +129,7 @@ namespace Subsurface.Items.Components
targetStructure.HighLightSection(sectionIndex); targetStructure.HighLightSection(sectionIndex);
targetStructure.AddDamage(sectionIndex, -structureFixAmount);
} }
else if ((targetLimb = (targetBody.UserData as Limb)) != null) else if ((targetLimb = (targetBody.UserData as Limb)) != null)
+15 -19
View File
@@ -285,6 +285,11 @@ namespace Subsurface
return false; return false;
} }
public virtual bool Select(Character character)
{
return CanBeSelected;
}
/// <summary>a character has dropped the item</summary> /// <summary>a character has dropped the item</summary>
public virtual void Drop(Character dropper) { } public virtual void Drop(Character dropper) { }
@@ -395,35 +400,26 @@ namespace Subsurface
return true; return true;
} }
public bool HasRequiredEquippedItems(Character character, bool addMessage) public bool HasRequiredItems(Character character, bool addMessage)
{ {
if (!requiredItems.Any()) return true; if (!requiredItems.Any()) return true;
foreach (RelatedItem ri in requiredItems) foreach (RelatedItem ri in requiredItems)
{ {
if (!ri.Type.HasFlag(RelatedItem.RelationType.Equipped) && !ri.Type.HasFlag(RelatedItem.RelationType.Picked)) continue;
bool hasItem = false;
if (ri.Type.HasFlag(RelatedItem.RelationType.Equipped)) if (ri.Type.HasFlag(RelatedItem.RelationType.Equipped))
{ {
for (int i = 0; i < character.SelectedItems.Length; i++ ) if (character.SelectedItems.FirstOrDefault(it => it != null && it.Condition > 0.0f && ri.MatchesItem(it)) != null) hasItem = true;
{
Item selectedItem = character.SelectedItems[i];
if (selectedItem !=null && selectedItem.Condition>0.0f && ri.MatchesItem(selectedItem ))
{
return true;
}
}
//if (addMessage && !String.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
return false;
} }
else if (ri.Type.HasFlag(RelatedItem.RelationType.Picked)) if (!hasItem && ri.Type.HasFlag(RelatedItem.RelationType.Picked))
{ {
Item pickedItem = character.Inventory.items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x)); if (character.Inventory.items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x))!=null) hasItem = true;
if (pickedItem == null)
{
//if (addMessage && !String.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
return false;
}
} }
if (!hasItem) return false;
} }
return true; return true;
+3 -3
View File
@@ -10,11 +10,11 @@ namespace Subsurface.Items.Components
{ {
} }
public override bool Pick(Character picker = null) public override bool Select(Character character = null)
{ {
if (picker == null) return false; if (character == null) return false;
picker.AnimController.Anim = AnimController.Animation.Climbing; character.AnimController.Anim = AnimController.Animation.Climbing;
//picker.SelectedConstruction = item; //picker.SelectedConstruction = item;
return true; return true;
@@ -23,6 +23,8 @@ namespace Subsurface.Items.Components
//the x-position where the user walks to when using the controller //the x-position where the user walks to when using the controller
float userPos; float userPos;
Camera cam;
Character character; Character character;
[HasDefaultValue(1.0f,false)] [HasDefaultValue(1.0f,false)]
@@ -38,19 +40,6 @@ namespace Subsurface.Items.Components
dir = (Direction)Enum.Parse(typeof(Direction), ToolBox.GetAttributeString(element, "direction", "None"), true); dir = (Direction)Enum.Parse(typeof(Direction), ToolBox.GetAttributeString(element, "direction", "None"), true);
//userPos = ToolBox.GetAttributeInt(element, "userpos", 1);
//string allowedIdString = ToolBox.GetAttributeString(element, "allowedids", "");
//if (allowedIdString!="")
//{
// string[] splitIds = allowedIdString.Split(',');
// allowedIDs = new string[splitIds.Length];
// for (int i = 0; i<splitIds.Length; i++)
// {
// allowedIDs[i] = allowedIDs[i].Trim();
// }
//}
foreach (XElement el in element.Elements()) foreach (XElement el in element.Elements())
{ {
if (el.Name != "limbposition") continue; if (el.Name != "limbposition") continue;
@@ -75,6 +64,8 @@ namespace Subsurface.Items.Components
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
this.cam = cam;
if (character == null || character.SelectedConstruction != item) if (character == null || character.SelectedConstruction != item)
{ {
if (character != null) if (character != null)
@@ -126,25 +117,29 @@ namespace Subsurface.Items.Components
fmj.WorldAnchorB = position; fmj.WorldAnchorB = position;
} }
foreach (MapEntity e in item.linkedTo) //foreach (MapEntity e in item.linkedTo)
{ //{
Item linkedItem = e as Item; // Item linkedItem = e as Item;
if (linkedItem == null) continue; // if (linkedItem == null) continue;
linkedItem.Update(cam, deltaTime); // linkedItem.Update(cam, deltaTime);
} //}
item.SendSignal(ToolBox.Vector2ToString(character.CursorPosition), "position_out");
} }
public override bool Use(float deltaTime, Character activator = null) public override bool Use(float deltaTime, Character activator = null)
{ {
character = activator; //character = activator;
foreach (MapEntity e in item.linkedTo) //foreach (MapEntity e in item.linkedTo)
{ //{
Item linkedItem = e as Item; // Item linkedItem = e as Item;
if (linkedItem == null) continue; // if (linkedItem == null) continue;
linkedItem.Use(deltaTime, activator); // linkedItem.Use(deltaTime, activator);
} //}
ApplyStatusEffects(ActionType.OnUse, 1.0f, character); item.SendSignal("1", "trigger_out");
ApplyStatusEffects(ActionType.OnUse, 1.0f, activator);
return true; return true;
} }
@@ -153,15 +148,43 @@ namespace Subsurface.Items.Components
{ {
if (character == null) return; if (character == null) return;
foreach (MapEntity e in item.linkedTo) foreach (Connection c in item.Connections)
{ {
Item linkedItem = e as Item; if (c.Name != "position_out") continue;
if (linkedItem == null) continue;
linkedItem.SecondaryUse(deltaTime, character); foreach (Connection c2 in c.Recipients)
{
if (c2 == null || c2.Item==null || !c2.Item.Prefab.FocusOnSelected) continue;
Vector2 centerPos = c2.Item.Position;
if (character == Character.Controlled && cam != null)
{
Lights.LightManager.ViewPos = centerPos;
cam.TargetPos = c2.Item.Position;
}
break;
}
} }
//foreach (MapEntity e in item.linkedTo)
//{
// Item linkedItem = e as Item;
// if (linkedItem == null) continue;
// linkedItem.SecondaryUse(deltaTime, character);
//}
} }
public override bool Pick(Character activator = null) public override bool Pick(Character picker)
{
item.SendSignal("1", "signal_out");
return true;
}
public override bool Select(Character activator = null)
{ {
if (character!=null && character.SelectedConstruction == item) if (character!=null && character.SelectedConstruction == item)
{ {
+11 -2
View File
@@ -51,10 +51,19 @@ namespace Subsurface.Items.Components
{ {
base.Update(deltaTime, cam); base.Update(deltaTime, cam);
pingState = (pingState + deltaTime * 0.5f) % 1.0f; pingState = (pingState + deltaTime * 0.5f);
if (pingState>1.0f)
{
item.Use(deltaTime,null);
pingState = 0.0f;
}
//angle = (angle + deltaTime) % MathHelper.TwoPi;
}
angle = (angle + deltaTime) % MathHelper.TwoPi; public override bool Use(float deltaTime, Character character = null)
{
return true;
} }
public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character) public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character)
@@ -35,44 +35,36 @@ namespace Subsurface.Items.Components
isActive = true; isActive = true;
} }
public override void OnMapLoaded()
{
PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(Level.Loaded.StartPosition),
ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
}
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
base.Update(deltaTime, cam); base.Update(deltaTime, cam);
if (autoPilot || true)
if (autoPilot)
{ {
steeringPath.GetNode(Vector2.Zero, 5.0f); if (steeringPath==null)
{
PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(Level.Loaded.StartPosition),
ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
}
steeringPath.GetNode(Vector2.Zero, 20.0f);
if (steeringPath.CurrentNode!=null) if (steeringPath.CurrentNode!=null)
{ {
Vector2 targetSpeed = steeringPath.CurrentNode.Position; float prediction = 10.0f;
float dist = targetSpeed.Length(); Vector2 futurePosition = Submarine.Loaded.Speed * prediction;
Vector2 targetSpeed = (steeringPath.CurrentNode.Position - futurePosition);
//float dist = targetSpeed.Length();
targetSpeed = Vector2.Normalize(targetSpeed); targetSpeed = Vector2.Normalize(targetSpeed);
if (dist<2000.0f) TargetVelocity = targetSpeed*100.0f;
{
targetSpeed = targetSpeed * Math.Max(dist / 2000.0f, 0.5f);
}
Vector2 currSpeed = (Submarine.Loaded.Speed == Vector2.Zero) ? Vector2.Zero : Vector2.Normalize(Submarine.Loaded.Speed);
//targetSpeed.X = (targetSpeed.X - currSpeed.X);
//targetSpeed.Y = (targetSpeed.Y - currSpeed.Y);
//TargetVelocity += targetSpeed;
TargetVelocity += (targetSpeed-currSpeed);
} }
} }
@@ -91,6 +83,13 @@ namespace Subsurface.Items.Components
Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40); Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40);
GUI.DrawRectangle(spriteBatch, velRect, Color.White, false); GUI.DrawRectangle(spriteBatch, velRect, Color.White, false);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + width - 150, y + height - 30, 150, 30), "Autopilot"))
{
autoPilot = !autoPilot;
item.NewComponentEvent(this, true);
}
GUI.DrawLine(spriteBatch, GUI.DrawLine(spriteBatch,
new Vector2(velRect.Center.X,velRect.Center.Y), new Vector2(velRect.Center.X,velRect.Center.Y),
new Vector2(velRect.Center.X + currVelocity.X, velRect.Center.Y - currVelocity.Y), new Vector2(velRect.Center.X + currVelocity.X, velRect.Center.Y - currVelocity.Y),
@@ -113,10 +112,10 @@ namespace Subsurface.Items.Components
{ {
targetVelocity = PlayerInput.MousePosition - new Vector2(velRect.Center.X, velRect.Center.Y); targetVelocity = PlayerInput.MousePosition - new Vector2(velRect.Center.X, velRect.Center.Y);
targetVelocity.Y = -targetVelocity.Y; targetVelocity.Y = -targetVelocity.Y;
item.NewComponentEvent(this, true);
} }
} }
item.NewComponentEvent(this, true);
} }
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
@@ -131,14 +130,19 @@ namespace Subsurface.Items.Components
{ {
message.Write(targetVelocity.X); message.Write(targetVelocity.X);
message.Write(targetVelocity.Y); message.Write(targetVelocity.Y);
message.Write(autoPilot);
} }
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message) public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
{ {
Vector2 newTargetVelocity = Vector2.Zero; Vector2 newTargetVelocity = Vector2.Zero;
bool newAutoPilot = false;
try try
{ {
newTargetVelocity = new Vector2(message.ReadFloat(), message.ReadFloat()); newTargetVelocity = new Vector2(message.ReadFloat(), message.ReadFloat());
newAutoPilot = message.ReadBoolean();
} }
catch catch
@@ -147,6 +151,7 @@ namespace Subsurface.Items.Components
} }
TargetVelocity = newTargetVelocity; TargetVelocity = newTargetVelocity;
autoPilot = newAutoPilot;
} }
} }
} }
@@ -1,5 +1,6 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Xml.Linq; using System.Xml.Linq;
@@ -28,26 +29,13 @@ namespace Subsurface.Items.Components
break; break;
} }
} }
isActive = true;
} }
//public override void Move(Vector2 amount)
//{
// base.Move(amount);
// foreach (Connection c in connections)
// {
// foreach (Wire w in c.wires)
// {
// if (w == null) continue;
// w.Move
// }
// }
//}
public override void DrawHUD(SpriteBatch spriteBatch, Character character) public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{ {
if (user!=character) return; if (character != Character.Controlled || character != user) return;
Connection.DrawConnections(spriteBatch, this, character); Connection.DrawConnections(spriteBatch, this, character);
} }
@@ -76,7 +64,7 @@ namespace Subsurface.Items.Components
if (user != null && user.SelectedConstruction != item) user = null; if (user != null && user.SelectedConstruction != item) user = null;
} }
public override bool Pick(Character picker) public override bool Select(Character picker)
{ {
user = picker; user = picker;
isActive = true; isActive = true;
@@ -107,10 +95,12 @@ namespace Subsurface.Items.Components
{ {
foreach (Connection c in connections) foreach (Connection c in connections)
{ {
int wireCount = c.Wires.Length; Wire[] wires = Array.FindAll(c.Wires, w => w != null);
for (int i = 0 ; i < wireCount; i++) message.Write((byte)wires.Length);
for (int i = 0 ; i < c.Wires.Length; i++)
{ {
message.Write(c.Wires[i]==null ? -1 : c.Wires[i].Item.ID); if (c.Wires[i] == null) continue;
message.Write(c.Wires[i].Item.ID);
} }
} }
} }
@@ -120,23 +110,28 @@ namespace Subsurface.Items.Components
System.Diagnostics.Debug.WriteLine("connectionpanel update"); System.Diagnostics.Debug.WriteLine("connectionpanel update");
foreach (Connection c in connections) foreach (Connection c in connections)
{ {
int wireCount = c.Wires.Length; //int wireCount = c.Wires.Length;
c.ClearConnections(); c.ClearConnections();
try
for (int i = 0; i < wireCount; i++)
{ {
int wireId = message.ReadInt32(); byte wireCount = message.ReadByte();
if (wireId == -1) continue;
Item wireItem = MapEntity.FindEntityByID(wireId) as Item; for (int i = 0; i < wireCount; i++)
if (wireItem == null) continue; {
int wireId = message.ReadInt32();
Wire wireComponent = wireItem.GetComponent<Wire>(); Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
if (wireComponent == null) continue; if (wireItem == null) continue;
c.Wires[i] = wireComponent; Wire wireComponent = wireItem.GetComponent<Wire>();
wireComponent.Connect(c, false); if (wireComponent == null) continue;
c.Wires[i] = wireComponent;
wireComponent.Connect(c, false);
}
} }
catch { }
} }
} }
} }
+39 -40
View File
@@ -15,7 +15,7 @@ namespace Subsurface.Items.Components
static Sprite wireSprite; static Sprite wireSprite;
List<Vector2> nodes; public List<Vector2> Nodes;
Connection[] connections; Connection[] connections;
@@ -30,7 +30,7 @@ namespace Subsurface.Items.Components
wireSprite.Depth = 0.85f; wireSprite.Depth = 0.85f;
} }
nodes = new List<Vector2>(); Nodes = new List<Vector2>();
connections = new Connection[2]; connections = new Connection[2];
} }
@@ -38,9 +38,9 @@ namespace Subsurface.Items.Components
public override void Move(Vector2 amount) public override void Move(Vector2 amount)
{ {
amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount); amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount);
for (int i = 0; i<nodes.Count; i++) for (int i = 0; i<Nodes.Count; i++)
{ {
nodes[i] += amount; Nodes[i] += amount;
} }
} }
@@ -76,11 +76,11 @@ namespace Subsurface.Items.Components
if (i == 0) if (i == 0)
{ {
nodes.Insert(0, newConnection.Item.Position); Nodes.Insert(0, newConnection.Item.Position);
} }
else else
{ {
nodes.Add(newConnection.Item.Position); Nodes.Add(newConnection.Item.Position);
} }
@@ -97,8 +97,7 @@ namespace Subsurface.Items.Components
CleanNodes(); CleanNodes();
} }
//new Networking.NetworkEvent(item.ID, true); Item.NewComponentEvent(this, true);
} }
public override void Equip(Character character) public override void Equip(Character character)
@@ -117,7 +116,7 @@ namespace Subsurface.Items.Components
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
if (nodes.Count == 0) return; if (Nodes.Count == 0) return;
item.FindHull(); item.FindHull();
@@ -153,9 +152,9 @@ namespace Subsurface.Items.Components
public override bool Use(float deltaTime, Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
if (newNodePos!= Vector2.Zero && nodes.Count>0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance) if (newNodePos!= Vector2.Zero && Nodes.Count>0 && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
{ {
nodes.Add(newNodePos); Nodes.Add(newNodePos);
newNodePos = Vector2.Zero; newNodePos = Vector2.Zero;
} }
@@ -166,9 +165,9 @@ namespace Subsurface.Items.Components
public override void SecondaryUse(float deltaTime, Character character = null) public override void SecondaryUse(float deltaTime, Character character = null)
{ {
if (nodes.Count > 1) if (Nodes.Count > 1)
{ {
nodes.RemoveAt(nodes.Count - 1); Nodes.RemoveAt(Nodes.Count - 1);
item.NewComponentEvent(this, true); item.NewComponentEvent(this, true);
} }
} }
@@ -182,7 +181,7 @@ namespace Subsurface.Items.Components
private void ClearConnections() private void ClearConnections()
{ {
nodes.Clear(); Nodes.Clear();
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
@@ -198,14 +197,14 @@ namespace Subsurface.Items.Components
private void CleanNodes() private void CleanNodes()
{ {
for (int i = nodes.Count - 2; i > 0; i--) for (int i = Nodes.Count - 2; i > 0; i--)
{ {
if ((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)) (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])) if (Vector2.Distance(Nodes[i - 1], Nodes[i]) == Vector2.Distance(Nodes[i + 1], Nodes[i]))
{ {
nodes.RemoveAt(i); Nodes.RemoveAt(i);
} }
} }
} }
@@ -214,12 +213,12 @@ namespace Subsurface.Items.Components
do do
{ {
removed = false; removed = false;
for (int i = nodes.Count - 2; i > 0; i--) for (int i = Nodes.Count - 2; i > 0; i--)
{ {
if ((nodes[i - 1].X == nodes[i].X && nodes[i + 1].X == nodes[i].X) if ((Nodes[i - 1].X == Nodes[i].X && Nodes[i + 1].X == Nodes[i].X)
|| (nodes[i - 1].Y == nodes[i].Y && nodes[i + 1].Y == nodes[i].Y)) || (Nodes[i - 1].Y == Nodes[i].Y && Nodes[i + 1].Y == Nodes[i].Y))
{ {
nodes.RemoveAt(i); Nodes.RemoveAt(i);
removed = true; removed = true;
} }
} }
@@ -231,21 +230,21 @@ namespace Subsurface.Items.Components
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
{ {
if (nodes.Count == 0) return; if (Nodes.Count == 0) return;
//for (int i = 0; i < nodes.Count; i++) //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); // 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, Color.White); DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], i, Color.White);
} }
if (isActive && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance) if (isActive && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
{ {
DrawSection(spriteBatch, nodes[nodes.Count - 1], newNodePos, nodes.Count, Color.White * 0.5f); DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, Nodes.Count, Color.White * 0.5f);
//nodes.Add(newNodePos); //nodes.Add(newNodePos);
} }
@@ -269,13 +268,13 @@ namespace Subsurface.Items.Components
{ {
XElement componentElement = base.Save(parentElement); XElement componentElement = base.Save(parentElement);
if (nodes == null || nodes.Count == 0) return componentElement; 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++) for (int i = 0; i < Nodes.Count(); i++)
{ {
nodeCoords[i * 2] = nodes[i].X.ToString(CultureInfo.InvariantCulture); nodeCoords[i * 2] = Nodes[i].X.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2 + 1] = nodes[i].Y.ToString(CultureInfo.InvariantCulture); nodeCoords[i * 2 + 1] = Nodes[i].Y.ToString(CultureInfo.InvariantCulture);
} }
componentElement.Add(new XAttribute("nodes", string.Join(";", nodeCoords))); componentElement.Add(new XAttribute("nodes", string.Join(";", nodeCoords)));
@@ -307,28 +306,28 @@ namespace Subsurface.Items.Components
} }
catch { y = 0.0f; } catch { y = 0.0f; }
nodes.Add(new Vector2(x, y)); Nodes.Add(new Vector2(x, y));
} }
} }
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message) public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
{ {
message.Write(nodes.Count); message.Write(Nodes.Count);
for (int i = 0; i < nodes.Count; i++) for (int i = 0; i < Nodes.Count; i++)
{ {
message.Write(nodes[i].X); message.Write(Nodes[i].X);
message.Write(nodes[i].Y); message.Write(Nodes[i].Y);
} }
} }
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message) public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
{ {
nodes.Clear(); Nodes.Clear();
int nodeCount = message.ReadInt32(); int nodeCount = message.ReadInt32();
for (int i = 0; i < nodeCount; i++) for (int i = 0; i < nodeCount; i++)
{ {
nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat())); Nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat()));
} }
} }
} }
+56 -57
View File
@@ -4,6 +4,7 @@ using System.IO;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using FarseerPhysics;
namespace Subsurface.Items.Components namespace Subsurface.Items.Components
{ {
@@ -13,14 +14,11 @@ namespace Subsurface.Items.Components
Vector2 barrelPos; Vector2 barrelPos;
float targetRotation; float rotation, targetRotation;
float rotation;
float reload; float reload, reloadTime;
float reloadTime;
float minRotation; float minRotation, maxRotation;
float maxRotation;
float launchImpulse; float launchImpulse;
@@ -53,12 +51,16 @@ namespace Subsurface.Items.Components
set { reloadTime = value; } set { reloadTime = value; }
} }
[HasDefaultValue("0.0,0.0", false)] [HasDefaultValue("0.0,0.0", true)]
public string RotationLimits public string RotationLimits
{ {
get get
{ {
return ToolBox.Vector2ToString(barrelPos); Vector2 limits = new Vector2(minRotation, maxRotation);
limits.X = MathHelper.ToDegrees(limits.X);
limits.Y = MathHelper.ToDegrees(limits.Y);
return ToolBox.Vector2ToString(limits);
} }
set set
{ {
@@ -75,35 +77,15 @@ namespace Subsurface.Items.Components
barrelSprite = new Sprite(Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\" +element.Attribute("barrelsprite").Value, barrelSprite = new Sprite(Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\" +element.Attribute("barrelsprite").Value,
ToolBox.GetAttributeVector2(element, "origin", Vector2.Zero)); ToolBox.GetAttributeVector2(element, "origin", Vector2.Zero));
//barrelPos = ToolBox.GetAttributeVector2(element, "BarrelPos", Vector2.Zero);
//launchImpulse = ToolBox.GetAttributeFloat(element, "launchimpulse", 0.0f);
//minRotation = ToolBox.GetAttributeFloat(element, "MinimumRotation", 0.0f);
//maxRotation = ToolBox.GetAttributeFloat(element, "MaximumRotation", MathHelper.TwoPi);
//reloadTime = ToolBox.GetAttributeFloat(element, "reload", 5.0f);
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
barrelSprite.Draw(spriteBatch, new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, rotation + MathHelper.PiOver2, 1.0f); barrelSprite.Draw(spriteBatch, new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, rotation + MathHelper.PiOver2, 1.0f);
//GUI.DrawRectangle(spriteBatch,
// new Rectangle((int)(rect.X + barrelPos.X), (int)(-rect.Y + barrelPos.Y), 10, 10),
// Color.White, true);
} }
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
//if (character == null || character.SelectedConstruction != item)
//{
// character = null;
// isActive = false;
// return;
//}
this.cam = cam; this.cam = cam;
if (reload>0.0f) reload -= deltaTime; if (reload>0.0f) reload -= deltaTime;
@@ -118,29 +100,21 @@ namespace Subsurface.Items.Components
rotation = MathUtils.CurveAngle(rotation, targetRotation, 0.05f); rotation = MathUtils.CurveAngle(rotation, targetRotation, 0.05f);
//if (!prefab.FocusOnSelected) return;
//cam.OffsetAmount = prefab.OffsetOnSelected;
} }
public override void SecondaryUse(float deltaTime, Character character = null) //public override void SecondaryUse(float deltaTime, Character character = null)
{ //{
if (character == null) return; // if (character == null) return;
Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
Vector2 offset = character.CursorPosition - centerPos; // Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
offset.Y = -offset.Y;
targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset)); // if (character == Character.Controlled && cam!=null)
// {
isActive = true; // Lights.LightManager.ViewPos = centerPos;
// cam.TargetPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
if (character == Character.Controlled && cam!=null) // }
{ //}
Lights.LightManager.ViewPos = centerPos;
cam.TargetPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
}
}
public override bool Use(float deltaTime, Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
@@ -148,23 +122,25 @@ namespace Subsurface.Items.Components
Projectile projectileComponent = null; Projectile projectileComponent = null;
currPowerConsumption = powerConsumption; //currPowerConsumption = powerConsumption;
float availablePower = 0.0f; float availablePower = 0.0f;
//List<PowerContainer> batteries = new List<PowerContainer>(); //List<PowerContainer> batteries = new List<PowerContainer>();
foreach (MapEntity e in item.linkedTo) foreach (Connection c in item.Connections)
{ {
Item battery = e as Item; foreach (Connection c2 in c.Recipients)
if (battery == null) continue; {
if (c2 == null || c2.Item == null) continue;
PowerContainer batteryComponent = battery.GetComponent<PowerContainer>(); PowerContainer batteryComponent = c2.Item.GetComponent<PowerContainer>();
if (batteryComponent == null) continue; if (batteryComponent == null) continue;
float batteryPower = Math.Min(batteryComponent.Charge, batteryComponent.MaxOutPut); float batteryPower = Math.Min(batteryComponent.Charge, batteryComponent.MaxOutPut);
float takePower = Math.Min(currPowerConsumption - availablePower, batteryPower); float takePower = Math.Min(currPowerConsumption - availablePower, batteryPower);
batteryComponent.Charge -= takePower; batteryComponent.Charge -= takePower;
availablePower += takePower; availablePower += takePower;
}
} }
reload = reloadTime; reload = reloadTime;
@@ -198,7 +174,7 @@ namespace Subsurface.Items.Components
projectile.body.ResetDynamics(); projectile.body.ResetDynamics();
projectile.body.Enabled = true; projectile.body.Enabled = true;
projectile.SetTransform(item.SimPosition, rotation); projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation);
//if (useSounds.Count() > 0) useSounds[Game1.localRandom.Next(useSounds.Count())].Play(1.0f, 800.0f, item.body.FarseerBody); //if (useSounds.Count() > 0) useSounds[Game1.localRandom.Next(useSounds.Count())].Play(1.0f, 800.0f, item.body.FarseerBody);
@@ -207,6 +183,29 @@ namespace Subsurface.Items.Components
return true; return true;
} }
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power)
{
switch (connection.Name)
{
case "position_in":
Vector2 receivedPos = ToolBox.ParseToVector2(signal, false);
Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
Vector2 offset = receivedPos - centerPos;
offset.Y = -offset.Y;
targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
isActive = true;
break;
case "trigger_in":
item.Use((float)Physics.step, null);
break;
}
}
} }
} }
+12 -17
View File
@@ -134,20 +134,17 @@ namespace Subsurface
} }
} }
//protected virtual void DropItem(Item item) protected virtual void DropItem(Item item)
//{ {
// for (int i = 0; i < capacity; i++)
// { item.Drop(null, false);
// if (items[i] == item) items[i] = null; return;
// } }
// item.Drop(); public void DropItem(int i)
// return; {
//} items[i].Drop();
//public void DropItem(int i) items[i] = null;
//{ }
// items[i].Drop();
// items[i] = null;
//}
public virtual void Draw(SpriteBatch spriteBatch) public virtual void Draw(SpriteBatch spriteBatch)
{ {
@@ -188,12 +185,10 @@ namespace Subsurface
} }
else else
{ {
draggingItem.Drop(null, false);
int[] data = { draggingItem.ID, -1 }; int[] data = { draggingItem.ID, -1 };
new NetworkEvent(NetworkEventType.InventoryUpdate, ID, true, data); new NetworkEvent(NetworkEventType.InventoryUpdate, ID, true, data);
//draggingItem = null; DropItem(draggingItem);
} }
} }
} }
+2 -3
View File
@@ -734,9 +734,8 @@ namespace Subsurface
foreach (ItemComponent ic in components) foreach (ItemComponent ic in components)
{ {
if (!ic.HasRequiredSkills(picker)) hasRequiredSkills = false; if (!ic.HasRequiredSkills(picker)) hasRequiredSkills = false;
if ((ic.CanBePicked || ic.CanBeSelected) if (!ic.HasRequiredItems(picker, picker == Character.Controlled) && !forcePick) continue;
&& (ic.HasRequiredEquippedItems(picker, picker == Character.Controlled) || forcePick) if ((ic.CanBePicked && ic.Pick(picker)) || (ic.CanBeSelected && ic.Select(picker)))
&& ic.Pick(picker))
{ {
picked = true; picked = true;
ic.ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker); ic.ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker);
+7
View File
@@ -13,6 +13,13 @@ namespace Subsurface
this.container = container; this.container = container;
} }
protected override void DropItem(Item item)
{
item.Drop();
item.body.Enabled = true;
item.body.SetTransform(container.Item.SimPosition, 0.0f);
}
public override int FindAllowedSlot(Item item) public override int FindAllowedSlot(Item item)
{ {
for (int i = 0; i < capacity; i++) for (int i = 0; i < capacity; i++)
+1 -1
View File
@@ -13,7 +13,7 @@ namespace Subsurface
None = 0, None = 0,
Contained = 1, Contained = 1,
Equipped = 2, Equipped = 2,
Picked = 3 Picked = 4
} }
string[] names; string[] names;
+15 -12
View File
@@ -74,7 +74,7 @@ namespace Subsurface
public Vector2 Position public Vector2 Position
{ {
get { return ConvertUnits.ToDisplayUnits(cells[1].body.Position); } get { return ConvertUnits.ToDisplayUnits(cells[0].body.Position); }
} }
public string Seed public string Seed
@@ -546,10 +546,9 @@ int currentTargetIndex = 1;
List<Vector2> tempVertices = new List<Vector2>(); List<Vector2> tempVertices = new List<Vector2>();
List<Vector2> bodyPoints = new List<Vector2>(); List<Vector2> bodyPoints = new List<Vector2>();
int n = 0; for (int n = cells.Count - 1; n >= 0; n-- )
foreach (VoronoiCell cell in cells)
{ {
n = (n + 30) % 255; VoronoiCell cell = cells[n];
bodyPoints.Clear(); bodyPoints.Clear();
tempVertices.Clear(); tempVertices.Clear();
@@ -568,14 +567,18 @@ int currentTargetIndex = 1;
if (!bodyPoints.Contains(ge.point2)) bodyPoints.Add(ge.point2); if (!bodyPoints.Contains(ge.point2)) bodyPoints.Add(ge.point2);
} }
if (tempVertices.Count < 3) continue; if (tempVertices.Count < 3 || bodyPoints.Count < 2)
{
cells.RemoveAt(n);
continue;
}
var triangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center); var triangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center);
for (int i = 0; i < triangles.Count; i++ ) for (int i = 0; i < triangles.Count; i++)
{ {
foreach (Vector2 vertex in triangles[i]) foreach (Vector2 vertex in triangles[i])
{ {
verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), new Color(n,(n*2)%255,(n*3)%255)*0.5f)); verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), new Color(n*30, (n * 60) % 255, (n * 90) % 255) * 0.5f));
} }
} }
@@ -584,7 +587,7 @@ int currentTargetIndex = 1;
if (bodyPoints.Count < 3) if (bodyPoints.Count < 3)
{ {
foreach(Vector2 vertex in tempVertices) foreach (Vector2 vertex in tempVertices)
{ {
if (bodyPoints.Contains(vertex)) continue; if (bodyPoints.Contains(vertex)) continue;
bodyPoints.Add(vertex); bodyPoints.Add(vertex);
@@ -655,8 +658,8 @@ int currentTargetIndex = 1;
Item item = mapEntity as Item; Item item = mapEntity as Item;
if (item == null) if (item == null)
{ {
if (!mapEntity.MoveWithLevel) continue; //if (!mapEntity.MoveWithLevel) continue;
mapEntity.Move(amount); //mapEntity.Move(amount);
} }
else if (item.body != null) else if (item.body != null)
{ {
@@ -692,8 +695,8 @@ int currentTargetIndex = 1;
Item item = mapEntity as Item; Item item = mapEntity as Item;
if (item == null) if (item == null)
{ {
if (!mapEntity.MoveWithLevel) continue; //if (!mapEntity.MoveWithLevel) continue;
mapEntity.Move(velocity); //mapEntity.Move(velocity);
} }
else if (item.body!=null) else if (item.body!=null)
{ {
+5 -2
View File
@@ -61,13 +61,16 @@ namespace Subsurface
get { return false; } get { return false; }
} }
public Vector2 Position public virtual Vector2 Position
{ {
get get
{ {
return new Vector2( Vector2 rectPos = new Vector2(
rect.X + rect.Width / 2.0f, rect.X + rect.Width / 2.0f,
rect.Y - rect.Height / 2.0f); rect.Y - rect.Height / 2.0f);
if (MoveWithLevel) rectPos += Level.Loaded.Position;
return rectPos;
} }
} }
+9 -13
View File
@@ -40,7 +40,6 @@ namespace Subsurface
Vector2 speed; Vector2 speed;
Vector2 targetPosition; Vector2 targetPosition;
Vector2 targetSpeed;
private Rectangle borders; private Rectangle borders;
@@ -417,7 +416,7 @@ namespace Subsurface
if (targetPosition != Vector2.Zero && Vector2.Distance(targetPosition, Position) > 5.0f) if (targetPosition != Vector2.Zero && Vector2.Distance(targetPosition, Position) > 5.0f)
{ {
translateAmount += (targetPosition - Position) * 0.05f; translateAmount += (targetPosition - Position) * 0.01f;
} }
else else
{ {
@@ -583,6 +582,7 @@ namespace Subsurface
return; return;
} }
newTargetPosition = newTargetPosition + newSpeed * (float)(NetTime.Now - sendingTime);
targetPosition = newTargetPosition; targetPosition = newTargetPosition;
speed = newSpeed; speed = newSpeed;
@@ -818,20 +818,16 @@ namespace Subsurface
hullBody.GravityScale = 0.0f; hullBody.GravityScale = 0.0f;
hullBody.OnCollision += OnCollision; hullBody.OnCollision += OnCollision;
hullBody.OnSeparation += OnSeparation; hullBody.OnSeparation += OnSeparation;
//body.IsSensor = true;
//body.SetTransform();
//HullBody hullBody = new HullBody();
//hullBody.body = body;
////hullBody.shapeTexture = GUI.CreateRectangle(borders.Width, borders.Height);
//hullBodies = new List<HullBody>();
//hullBodies.Add(hullBody);
MapEntity.LinkAll(); MapEntity.LinkAll();
foreach (Item item in Item.itemList)
{
foreach (ItemComponent ic in item.components)
{
ic.OnMapLoaded();
}
}
ID = int.MaxValue-10; ID = int.MaxValue-10;
+5 -8
View File
@@ -42,11 +42,6 @@ namespace Subsurface
} }
} }
public override Vector2 SimPosition
{
get { return ConvertUnits.ToSimUnits(new Vector2(rect.X, rect.Y)); }
}
public WayPoint(Rectangle newRect) public WayPoint(Rectangle newRect)
{ {
rect = newRect; rect = newRect;
@@ -61,14 +56,16 @@ namespace Subsurface
{ {
//if (!editing) return; //if (!editing) return;
Point pos = new Point((int)Position.X, (int)Position.Y);
Color clr = (isSelected) ? Color.Red : Color.LightGreen; Color clr = (isSelected) ? Color.Red : Color.LightGreen;
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, -rect.Y, rect.Width, rect.Height), clr, true); GUI.DrawRectangle(spriteBatch, new Rectangle(pos.X, -pos.Y, rect.Width, rect.Height), clr, true);
foreach (MapEntity e in linkedTo) foreach (MapEntity e in linkedTo)
{ {
GUI.DrawLine(spriteBatch, GUI.DrawLine(spriteBatch,
new Vector2(rect.X + rect.Width / 2, -rect.Y + rect.Height / 2), new Vector2(pos.X, -pos.Y),
new Vector2(e.Rect.X + e.Rect.Width / 2, -e.Rect.Y + e.Rect.Height / 2), new Vector2(e.Position.X + e.Rect.Width / 2, -e.Position.Y + e.Rect.Height / 2),
Color.Green); Color.Green);
} }
} }
+4 -2
View File
@@ -132,7 +132,8 @@ namespace Subsurface.Networking
{ {
// All manually sent messages are type of "Data" // All manually sent messages are type of "Data"
case NetIncomingMessageType.Data: case NetIncomingMessageType.Data:
if (inc.ReadByte() == (byte)PacketTypes.LoggedIn) byte packetType = inc.ReadByte();
if (packetType == (byte)PacketTypes.LoggedIn)
{ {
myID = inc.ReadInt32(); myID = inc.ReadInt32();
@@ -152,7 +153,7 @@ namespace Subsurface.Networking
CanStart = true; CanStart = true;
} }
else if (inc.ReadByte() == (byte)PacketTypes.KickedOut) else if (packetType == (byte)PacketTypes.KickedOut)
{ {
string msg = inc.ReadString(); string msg = inc.ReadString();
DebugConsole.ThrowError(msg); DebugConsole.ThrowError(msg);
@@ -199,6 +200,7 @@ namespace Subsurface.Networking
SendRandomData(); SendRandomData();
} }
if (gameStarted) inGameHUD.Update((float)Physics.step);
if (!connected || updateTimer > DateTime.Now) return; if (!connected || updateTimer > DateTime.Now) return;
+35 -28
View File
@@ -21,6 +21,9 @@ namespace Subsurface.Networking
public GameServer() public GameServer()
{ {
var endRoundButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 170-120, 20, 150, 25), "End round", Alignment.TopLeft, GUI.style, inGameHUD);
endRoundButton.OnClicked = EndButtonHit;
name = "Server"; name = "Server";
Config = new NetPeerConfiguration("subsurface"); Config = new NetPeerConfiguration("subsurface");
@@ -49,13 +52,11 @@ namespace Subsurface.Networking
updateInterval = new TimeSpan(0, 0, 0, 0, 30); updateInterval = new TimeSpan(0, 0, 0, 0, 30);
DebugConsole.NewMessage("Server started", Color.Green); DebugConsole.NewMessage("Server started", Color.Green);
} }
public override void Update() public override void Update()
{ {
// Server.ReadMessage() Returns new messages, that have not yet been read. if (gameStarted) inGameHUD.Update((float)Physics.step);
// If "inc" is null -> ReadMessage returned null -> Its null, so dont do this :)
NetIncomingMessage inc = Server.ReadMessage(); NetIncomingMessage inc = Server.ReadMessage();
if (inc != null) if (inc != null)
@@ -84,6 +85,30 @@ namespace Subsurface.Networking
} }
} }
private void SparseUpdate()
{
foreach (Character c in Character.CharacterList)
{
bool isClient = false;
foreach (Client client in connectedClients)
{
if (client.character != c) continue;
isClient = true;
break;
}
if (!isClient)
{
c.LargeUpdateTimer = 0;
new NetworkEvent(c.ID, false);
}
}
new NetworkEvent(Submarine.Loaded.ID, false);
sparseUpdateTimer = DateTime.Now + SparseUpdateInterval;
}
private void ReadMessage(NetIncomingMessage inc) private void ReadMessage(NetIncomingMessage inc)
{ {
NetOutgoingMessage outmsg; NetOutgoingMessage outmsg;
@@ -224,30 +249,6 @@ namespace Subsurface.Networking
} }
} }
private void SparseUpdate()
{
foreach (Character c in Character.CharacterList)
{
bool isClient = false;
foreach (Client client in connectedClients)
{
if (client.character != c) continue;
isClient = true;
break;
}
if (!isClient)
{
c.LargeUpdateTimer = 0;
new NetworkEvent(c.ID, false);
}
}
new NetworkEvent(Submarine.Loaded.ID, false);
sparseUpdateTimer = DateTime.Now + SparseUpdateInterval;
}
private void SendMessage(NetOutgoingMessage msg, NetDeliveryMethod deliveryMethod, NetConnection excludedConnection) private void SendMessage(NetOutgoingMessage msg, NetDeliveryMethod deliveryMethod, NetConnection excludedConnection)
{ {
List<NetConnection> recipients = new List<NetConnection>(); List<NetConnection> recipients = new List<NetConnection>();
@@ -296,7 +297,6 @@ namespace Subsurface.Networking
Submarine selectedMap = Game1.NetLobbyScreen.SelectedMap as Submarine; Submarine selectedMap = Game1.NetLobbyScreen.SelectedMap as Submarine;
//selectedMap.Load(); //selectedMap.Load();
Game1.GameSession = new GameSession(selectedMap, Game1.NetLobbyScreen.SelectedMode); Game1.GameSession = new GameSession(selectedMap, Game1.NetLobbyScreen.SelectedMode);
@@ -378,6 +378,13 @@ namespace Subsurface.Networking
return true; return true;
} }
private bool EndButtonHit(GUIButton button, object obj)
{
Game1.GameSession.gameMode.End("The round has ended");
return true;
}
public void EndGame(string endMessage) public void EndGame(string endMessage)
{ {
Submarine.Unload(); Submarine.Unload();
+18 -5
View File
@@ -1,5 +1,6 @@
using System; using System;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Subsurface.Networking namespace Subsurface.Networking
{ {
@@ -93,12 +94,17 @@ namespace Subsurface.Networking
Alignment.Left, null, null, true); Alignment.Left, null, null, true);
msg.Padding = new Vector4(20.0f, 0, 0, 0); msg.Padding = new Vector4(20.0f, 0, 0, 0);
chatBox.AddChild(msg);
while (chatBox.CountChildren > 20) //float prevScroll = chatBox.BarScroll;
{
chatBox.RemoveChild(chatBox.children[0]); //chatBox.AddChild(msg);
}
//while (chatBox.CountChildren > 20)
//{
// chatBox.RemoveChild(chatBox.children[0]);
//}
//if (prevScroll == 1.0f) chatBox.BarScroll = 1.0f;
GUI.PlayMessageSound(); GUI.PlayMessageSound();
} }
@@ -107,6 +113,13 @@ namespace Subsurface.Networking
public virtual void Update() { } public virtual void Update() { }
public virtual void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
{
if (!gameStarted) return;
inGameHUD.Draw(spriteBatch);
}
public virtual void Disconnect() { } public virtual void Disconnect() { }
} }
-9
View File
@@ -31,15 +31,6 @@ namespace Subsurface
} }
} }
//[AttributeUsage(AttributeTargets.Property)]
//public class Saveable : Initable
//{
// public Saveable(object defaultValue)
// :base(defaultValue)
// {
// }
//}
class ObjectProperty class ObjectProperty
{ {
readonly PropertyDescriptor property; readonly PropertyDescriptor property;
+8 -39
View File
@@ -31,9 +31,6 @@ namespace Subsurface
private float camAngle; private float camAngle;
//private Body previewPlatform;
//private Hull previewHull;
public bool IsServer; public bool IsServer;
public Submarine SelectedMap public Submarine SelectedMap
@@ -112,7 +109,7 @@ namespace Subsurface
GUI.style, menu); GUI.style, menu);
chatBox = new GUIListBox(new Rectangle(0,0,0,chatFrame.Rect.Height-80), Color.White, GUI.style, chatFrame); chatBox = new GUIListBox(new Rectangle(0,0,0,chatFrame.Rect.Height-80), Color.White, GUI.style, chatFrame);
textBox = new GUITextBox(new Rectangle(0, 0, 0, 25), Alignment.Bottom, GUI.style, chatFrame); textBox = new GUITextBox(new Rectangle(0, 25, 0, 25), Alignment.Bottom, GUI.style, chatFrame);
textBox.OnEnter = EnterChatMessage; textBox.OnEnter = EnterChatMessage;
//player info panel ------------------------------------------------------------ //player info panel ------------------------------------------------------------
@@ -135,18 +132,6 @@ namespace Subsurface
public override void Deselect() public override void Deselect()
{ {
textBox.Deselect(); textBox.Deselect();
//if (previewPlatform!=null)
//{
// Game1.World.RemoveBody(previewPlatform);
// previewPlatform = null;
//}
//if (previewHull!=null)
//{
// previewHull.Remove();
// previewHull = null;
//}
} }
public override void Select() public override void Select()
@@ -186,7 +171,6 @@ namespace Subsurface
new GUITextBlock(new Rectangle(220, 30, 0, 30), "Selected game mode: ", GUI.style, infoFrame); new GUITextBlock(new Rectangle(220, 30, 0, 30), "Selected game mode: ", GUI.style, infoFrame);
modeList = new GUIListBox(new Rectangle(220, 60, 200, 200), GUI.style, infoFrame); modeList = new GUIListBox(new Rectangle(220, 60, 200, 200), GUI.style, infoFrame);
modeList.Enabled = (Game1.Server != null); modeList.Enabled = (Game1.Server != null);
//modeList.OnSelected = new GUIListBox.OnSelectedHandler(SelectEvent);
foreach (GameModePreset mode in GameModePreset.list) foreach (GameModePreset mode in GameModePreset.list)
{ {
@@ -325,6 +309,7 @@ namespace Subsurface
{ {
base.Update(deltaTime); base.Update(deltaTime);
Game1.GameScreen.Cam.TargetPos = Vector2.Zero;
Game1.GameScreen.Cam.MoveCamera((float)deltaTime); Game1.GameScreen.Cam.MoveCamera((float)deltaTime);
Vector2 pos = new Vector2( Vector2 pos = new Vector2(
@@ -342,7 +327,7 @@ namespace Subsurface
menu.Update((float)deltaTime); menu.Update((float)deltaTime);
durationBar.BarScroll = Math.Max(durationBar.BarScroll, 1.0f / 60.0f); //durationBar.BarScroll = Math.Max(durationBar.BarScroll, 1.0f / 60.0f);
} }
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
@@ -361,31 +346,13 @@ namespace Subsurface
spriteBatch.End(); spriteBatch.End();
//if (Game1.Client != null)
//{
// if (Game1.Client.Character != null)
// {
// Vector2 position = new Vector2(playerFrame.Rect.X + playerFrame.Rect.Width * 0.25f, playerFrame.Rect.Y + 25.0f);
// Vector2 pos = Game1.Client.Character.Position;
// pos.Y = -pos.Y;
// Matrix transform = Matrix.CreateTranslation(new Vector3(-pos + position, 0.0f));
// spriteBatch.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, transform);
// Game1.Client.Character.Draw(spriteBatch);
// spriteBatch.End();
// }
// else
// {
// CreatePreviewCharacter();
// }
//}
} }
public void NewChatMessage(string message, Color color) public void NewChatMessage(string message, Color color)
{ {
float prevSize = chatBox.BarSize;
float oldScroll = chatBox.BarScroll;
GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20), GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20),
message, message,
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.1f, color, ((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.1f, color,
@@ -393,6 +360,8 @@ namespace Subsurface
msg.Padding = new Vector4(20, 0, 0, 0); msg.Padding = new Vector4(20, 0, 0, 0);
chatBox.AddChild(msg); chatBox.AddChild(msg);
if ((prevSize == 1.0f && chatBox.BarScroll == 0.0f) || (prevSize < 1.0f && chatBox.BarScroll == 1.0f)) chatBox.BarScroll = 1.0f;
} }
+3
View File
@@ -659,6 +659,9 @@
<None Include="Content\effects.mgfx"> <None Include="Content\effects.mgfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Content\Items\Engine\radarPing.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Items\Reactor\reactor.ogg"> <None Include="Content\Items\Reactor\reactor.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
+1 -1
View File
@@ -9,6 +9,6 @@
<ErrorReportUrlHistory /> <ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture> <FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles> <VerifyUploadedFiles>false</VerifyUploadedFiles>
<ProjectView>ShowAllFiles</ProjectView> <ProjectView>ProjectFiles</ProjectView>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
Binary file not shown.