Improved level generation algorithm, fixed invisible hulls, turret projectile fix, fabricators work in mp

This commit is contained in:
Regalis
2016-02-11 21:37:37 +02:00
parent 5a38c4b1ef
commit 4f54e04c8c
32 changed files with 435 additions and 161 deletions
+13
View File
@@ -331,6 +331,16 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Characters\Husk\DivingSuit.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Husk\head1.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Husk\husk.xml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\damagedhead.png"> <Content Include="Content\Characters\Human\damagedhead.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@@ -397,6 +407,9 @@
<Content Include="Content\Characters\Human\torso.png"> <Content Include="Content\Characters\Human\torso.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Characters\Husk\legs.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\TigerThresher\damagedtigerthresher.png"> <Content Include="Content\Characters\TigerThresher\damagedtigerthresher.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@@ -4,7 +4,7 @@
name="Skyholder Artifact" name="Skyholder Artifact"
pickdistance="150"> pickdistance="150">
<Sprite texture="artifact.png" depth="0.8" sourcerect="0,0,38,60"/> <Sprite texture="artifact.png" depth="0.7" sourcerect="0,0,38,60"/>
<Deconstruct time="30"> <Deconstruct time="30">
<Item name="Steel Bar"/> <Item name="Steel Bar"/>
@@ -23,7 +23,7 @@
name="Thermal Artifact" name="Thermal Artifact"
pickdistance="150"> pickdistance="150">
<Sprite texture="artifact.png" depth="0.8" sourcerect="74,0,44,61"/> <Sprite texture="artifact.png" depth="0.7" sourcerect="74,0,44,61"/>
<Deconstruct time="30"> <Deconstruct time="30">
<Item name="Steel Bar"/> <Item name="Steel Bar"/>
@@ -45,7 +45,7 @@
name="Faraday Artifact" name="Faraday Artifact"
pickdistance="150"> pickdistance="150">
<Sprite texture="artifact.png" depth="0.8" sourcerect="40,0,33,61"/> <Sprite texture="artifact.png" depth="0.7" sourcerect="40,0,33,61"/>
<Deconstruct time="30"> <Deconstruct time="30">
<Item name="Steel Bar"/> <Item name="Steel Bar"/>
@@ -16,10 +16,13 @@
<sound file="fabricator.ogg" type="OnActive" range="1000.0" loop="true"/> <sound file="fabricator.ogg" type="OnActive" range="1000.0" loop="true"/>
<fabricableitem name="Harpoon Gun" requireditems="Steel Bar, Polycarbonate Bar" requiredtime="20"/> <fabricableitem name="Harpoon Gun" requireditems="Steel Bar, Polycarbonate Bar" requiredtime="20"/>
<fabricableitem name="Spear" requireditems="Steel Bar" requiredtime="10"/>
<fabricableitem name="Plasma Cutter" requireditems="Steel Bar, Polycarbonate Bar" requiredtime="20"/> <fabricableitem name="Plasma Cutter" requireditems="Steel Bar, Polycarbonate Bar" requiredtime="20"/>
<fabricableitem name="Welding Tool" requireditems="Steel Bar, Polycarbonate Bar" requiredtime="20"/> <fabricableitem name="Welding Tool" requireditems="Steel Bar, Polycarbonate Bar" requiredtime="20"/>
<fabricableitem name="Railgun Shell" requireditems="Steel Bar, Steel Bar, Polycarbonate Bar" requiredtime="20"/> <fabricableitem name="Railgun Shell" requireditems="Steel Bar, Steel Bar, Polycarbonate Bar" requiredtime="20"/>
<fabricableitem name="Nuclear Shell" requireditems="Steel Bar, Steel Bar, Uranium Bar, Polycarbonate Bar" requiredtime="30"/>
<fabricableitem name="And Component" requireditems="Steel Bar, FPGA Circuit" requiredtime="10"/> <fabricableitem name="And Component" requireditems="Steel Bar, FPGA Circuit" requiredtime="10"/>
<fabricableitem name="Or Component" requireditems="Steel Bar, FPGA Circuit" requiredtime="10"/> <fabricableitem name="Or Component" requireditems="Steel Bar, FPGA Circuit" requiredtime="10"/>
@@ -8,7 +8,7 @@
<Sprite texture ="oxygengenerator.png" depth="0.8"/> <Sprite texture ="oxygengenerator.png" depth="0.8"/>
<OxygenGenerator powerconsumption="1000.0" minvoltage="0.5" canbeselected = "true"> <OxygenGenerator powerconsumption="1000.0" minvoltage="0.5" canbeselected = "true">
<StatusEffect type="OnActive" target="Contained" targetnames="Oxygen Tank" Condition="2.0"/> <StatusEffect type="OnActive" target="Contained" targetnames="Oxygen Tank" Condition="0.5"/>
<sound file="oxygengenerator.ogg" type="OnActive" range="1000.0" volume="CurrFlow" volumemultiplier="0.001f" loop="true"/> <sound file="oxygengenerator.ogg" type="OnActive" range="1000.0" volume="CurrFlow" volumemultiplier="0.001f" loop="true"/>
</OxygenGenerator> </OxygenGenerator>
@@ -57,6 +57,11 @@
pickdistance="150" pickdistance="150"
price="200"> price="200">
<Deconstruct time="10">
<Item name="Steel Bar"/>
<Item name="Uranium Bar"/>
</Deconstruct>
<Sprite texture ="fuelrod.png"/> <Sprite texture ="fuelrod.png"/>
<Body radius="6" height="22" density="5"/> <Body radius="6" height="22" density="5"/>
@@ -71,6 +76,11 @@
pickdistance="150" pickdistance="150"
spritecolor="0.5,0.0,0.0,1.0"> spritecolor="0.5,0.0,0.0,1.0">
<Deconstruct time="10">
<Item name="Steel Bar"/>
<Item name="Incendium Bar"/>
</Deconstruct>
<Sprite texture ="fuelrod.png"/> <Sprite texture ="fuelrod.png"/>
<Body radius="6" height="22" density="5"/> <Body radius="6" height="22" density="5"/>
+2 -2
View File
@@ -30,7 +30,7 @@
<sound file="weldingTool.ogg" type="OnUse" range="500.0" loop="true"/> <sound file="weldingTool.ogg" type="OnUse" range="500.0" loop="true"/>
<!-- when using, the contained welding fuel tank will detoriate (= lose fuel) --> <!-- when using, the contained welding fuel tank will detoriate (= lose fuel) -->
<StatusEffect type="OnUse" target="Contained" targetnames="Welding Fuel Tank" Condition="-0.7"/> <StatusEffect type="OnUse" target="Contained" targetnames="Welding Fuel Tank" Condition="-1.0"/>
<!-- welding a door, it will get stuck after a while --> <!-- welding a door, it will get stuck after a while -->
<StatusEffect type="OnUse" target="UseTarget" targetnames="Door,Windowed Door" Stuck="20.0" Condition="3.0"/> <StatusEffect type="OnUse" target="UseTarget" targetnames="Door,Windowed Door" Stuck="20.0" Condition="3.0"/>
@@ -77,7 +77,7 @@
<RepairTool structurefixamount="-2.0" limbfixamount="-0.5" range="100" barrelpos="28,8" particles="plasma"> <RepairTool structurefixamount="-2.0" limbfixamount="-0.5" range="100" barrelpos="28,8" particles="plasma">
<RequiredItems name="Oxygen Tank" type="Contained" msg="Oxygen tank required"/> <RequiredItems name="Oxygen Tank" type="Contained" msg="Oxygen tank required"/>
<StatusEffect type="OnUse" target="Contained" targetnames="Oxygen Tank" Condition="-0.7"/> <StatusEffect type="OnUse" target="Contained" targetnames="Oxygen Tank" Condition="-1.0"/>
<StatusEffect type="OnUse" target="UseTarget" targetnames="Door,Windowed Door" Stuck="-20.0" Condition="-3.0"/> <StatusEffect type="OnUse" target="UseTarget" targetnames="Door,Windowed Door" Stuck="-20.0" Condition="-3.0"/>
<sound file="plasmaCutter.ogg" type="OnUse" range="500.0" loop="true"/> <sound file="plasmaCutter.ogg" type="OnUse" range="500.0" loop="true"/>
@@ -58,6 +58,7 @@
<ItemContainer hideitems="false" drawinventory="true" capacity="6" slotsperrow="6" itempos="24,-75" iteminterval="26,0" itemrotation="90" canbeselected = "true"> <ItemContainer hideitems="false" drawinventory="true" capacity="6" slotsperrow="6" itempos="24,-75" iteminterval="26,0" itemrotation="90" canbeselected = "true">
<Containable name="Railgun Shell"/> <Containable name="Railgun Shell"/>
<Containable name="Nuclear Shell"/>
</ItemContainer> </ItemContainer>
</Item> </Item>
@@ -88,5 +89,37 @@
<Containable name="smallitem"/> <Containable name="smallitem"/>
</ItemContainer> </ItemContainer>
</Item> </Item>
<Item
name="Nuclear Shell"
category="Misc"
pickdistance="200"
price="100">
<Deconstruct time="10">
<Item name="Steel Bar"/>
<Item name="Steel Bar"/>
<Item name="Uranium Bar"/>
<Item name="Polycarbonate Bar"/>
</Deconstruct>
<Sprite texture="weapons.png" sourcerect="0,77,88,20" depth ="0.5"/>
<Body width="87" height="18"/>
<Holdable slots="RightHand+LeftHand" holdpos="0,-50" handle1="-10,0" handle2="10,0" aimable="false"/>
<Projectile launchimpulse="80.0">
<Attack damage="100" bleedingdamage="10" structuredamage="200" damagetype="Blunt"/>
<StatusEffect type="OnUse" Condition="-100.0" stun="10.0" disabledeltatime="true" sound="Content/Items/Reactor/explosion.ogg">
<Explosion range="1000.0" structuredamage="1000" damage="1000" stun="10" force="50.0"/>
</StatusEffect>
</Projectile>
<ItemContainer hideitems="true" capacity="1" canbeselected = "true">
<Containable name="smallitem"/>
</ItemContainer>
</Item>
</Items> </Items>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 11 KiB

+1 -1
View File
@@ -102,7 +102,7 @@
<Item name="Polycarbonate Bar"/> <Item name="Polycarbonate Bar"/>
</Deconstruct> </Deconstruct>
<Sprite texture="weapons.png" sourcerect="20,0,77,23" depth="0.5"/> <Sprite texture="weapons.png" sourcerect="21,0,77,22" depth="0.5"/>
<Body width="90" height="30" density="10"/> <Body width="90" height="30" density="10"/>
+2 -2
View File
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.1.0")] [assembly: AssemblyVersion("0.3.1.1")]
[assembly: AssemblyFileVersion("0.3.1.0")] [assembly: AssemblyFileVersion("0.3.1.1")]
@@ -789,6 +789,8 @@ namespace Barotrauma
public override void DragCharacter(Character target) public override void DragCharacter(Character target)
{ {
if (target == null) return;
Limb leftHand = GetLimb(LimbType.LeftHand); Limb leftHand = GetLimb(LimbType.LeftHand);
Limb rightHand = GetLimb(LimbType.RightHand); Limb rightHand = GetLimb(LimbType.RightHand);
@@ -39,7 +39,7 @@ namespace Barotrauma
public Vector2 SimPosition public Vector2 SimPosition
{ {
get { return position; } get { return FarseerPhysics.ConvertUnits.ToSimUnits(position); }
} }
public Vector2 Velocity public Vector2 Velocity
@@ -81,29 +81,51 @@ namespace Barotrauma
depth = MathHelper.Clamp(depth + velocity.Z * deltaTime, 0.0f, MaxDepth); depth = MathHelper.Clamp(depth + velocity.Z * deltaTime, 0.0f, MaxDepth);
checkWallsTimer -= deltaTime; checkWallsTimer -= deltaTime;
if (checkWallsTimer<=0.0f && Level.Loaded!=null) if (checkWallsTimer <= 0.0f && Level.Loaded != null)
{ {
checkWallsTimer = CheckWallsInterval; checkWallsTimer = CheckWallsInterval;
obstacleDiff = Vector2.Zero; obstacleDiff = Vector2.Zero;
if (position.Y > Level.Loaded.Size.Y)
var cells = Level.Loaded.GetCells(position, 1);
if (cells.Count > 0)
{ {
obstacleDiff = Vector2.UnitY;
foreach (Voronoi2.VoronoiCell cell in cells)
{
obstacleDiff += cell.Center - position;
}
obstacleDiff = Vector2.Normalize(obstacleDiff) * prefab.Speed;
} }
} else if (position.Y < 0.0f)
{
obstacleDiff = -Vector2.UnitY;
}
else if (position.X < 0.0f)
{
obstacleDiff = Vector2.UnitX;
}
else if (position.X > Level.Loaded.Size.X)
{
obstacleDiff = -Vector2.UnitX;
}
else
{
var cells = Level.Loaded.GetCells(position, 1);
if (cells.Count > 0)
{
foreach (Voronoi2.VoronoiCell cell in cells)
{
obstacleDiff += cell.Center - position;
}
obstacleDiff /= cells.Count;
obstacleDiff = Vector2.Normalize(obstacleDiff) * prefab.Speed;
}
}
}
if (Swarm!=null) if (Swarm!=null)
{ {
Vector2 midPoint = Swarm.MidPoint(); Vector2 midPoint = Swarm.MidPoint();
float midPointDist = Vector2.Distance(position, midPoint); float midPointDist = Vector2.Distance(SimPosition, midPoint);
if (midPointDist > Swarm.MaxDistance) if (midPointDist > Swarm.MaxDistance)
{ {
@@ -116,9 +138,12 @@ namespace Barotrauma
steeringManager.SteeringWander(prefab.Speed); steeringManager.SteeringWander(prefab.Speed);
} }
//Level.Loaded.Size
if (obstacleDiff != Vector2.Zero) if (obstacleDiff != Vector2.Zero)
{ {
steeringManager.SteeringSeek(-obstacleDiff, prefab.Speed); steeringManager.SteeringSeek(SimPosition-obstacleDiff, prefab.Speed*2.0f);
} }
steeringManager.Update(prefab.Speed); steeringManager.Update(prefab.Speed);
+3 -3
View File
@@ -918,10 +918,10 @@ namespace Barotrauma
if (!(AnimController is FishAnimController)) if (!(AnimController is FishAnimController))
{ {
bool protectedFromPressure = PressureProtection > 0.0f; bool protectedFromPressure = PressureProtection > 0.0f;
if (Submarine.Loaded!=null && Level.Loaded !=null) if (Submarine.Loaded != null && Level.Loaded != null)
{ {
protectedFromPressure = protectedFromPressure && Position.Y > SubmarineBody.DamageDepth; protectedFromPressure = protectedFromPressure && WorldPosition.Y > SubmarineBody.DamageDepth;
} }
if (!protectedFromPressure && if (!protectedFromPressure &&
+9 -1
View File
@@ -532,6 +532,7 @@ namespace Barotrauma
break; break;
} }
} }
spriteBatch.Draw( spriteBatch.Draw(
bodyShapeTexture, bodyShapeTexture,
new Vector2(body.DrawPosition.X, -body.DrawPosition.Y), new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
@@ -546,7 +547,14 @@ namespace Barotrauma
{ {
sprite.Remove(); sprite.Remove();
body.Remove(); body.Remove();
if (hitSound!=null) hitSound.Remove();
if (bodyShapeTexture != null)
{
bodyShapeTexture.Dispose();
}
if (hitSound != null) hitSound.Remove();
} }
} }
} }
@@ -27,7 +27,7 @@ namespace Barotrauma
public override void Start(Level level) public override void Start(Level level)
{ {
Vector2 position = level.PositionsOfInterest[Rand.Int(level.PositionsOfInterest.Count, false)]; Vector2 position = level.GetRandomInterestingPosition(monster.Mass > 500.0f, true);
monster = Character.Create(monsterFile, position); monster = Character.Create(monsterFile, position);
monster.Enabled = false; monster.Enabled = false;
@@ -314,6 +314,7 @@ namespace Barotrauma
characters.Clear(); characters.Clear();
listBox.ClearChildren(); listBox.ClearChildren();
orderListBox.ClearChildren();
} }
public void Draw(SpriteBatch spriteBatch) public void Draw(SpriteBatch spriteBatch)
@@ -30,7 +30,7 @@ namespace Barotrauma.Items.Components
[HasDefaultValue(false, true)] [HasDefaultValue(false, true)]
public bool Attached public bool Attached
{ {
get { return attached; } get { return attached && item.Inventory == null; }
set { attached = value; } set { attached = value; }
} }
@@ -101,7 +101,7 @@ namespace Barotrauma.Items.Components
Msg = ""; Msg = "";
} }
if (attachedByDefault || (Screen.Selected == GameMain.EditMapScreen && Submarine.Loaded!=null)) Use(1.0f); if (attachedByDefault || (Screen.Selected == GameMain.EditMapScreen && Submarine.Loaded!=null)) Use(1.0f);
//holdAngle = ToolBox.GetAttributeFloat(element, "holdangle", 0.0f); //holdAngle = ToolBox.GetAttributeFloat(element, "holdangle", 0.0f);
@@ -259,12 +259,22 @@ namespace Barotrauma.Items.Components
{ {
//prevRequiredItems = new List<RelatedItem>(requiredItems); //prevRequiredItems = new List<RelatedItem>(requiredItems);
if (attached) if (Attached)
{ {
Use(1.0f); Use(1.0f);
} }
else else
{ {
if (item.Inventory!=null)
{
if (body != null)
{
item.body = body;
body.Enabled = false;
}
attached = false;
}
requiredItems.Clear(); requiredItems.Clear();
Msg = ""; Msg = "";
} }
@@ -9,6 +9,8 @@ namespace Barotrauma.Items.Components
{ {
class ItemContainer : ItemComponent class ItemContainer : ItemComponent
{ {
public const int MaxInventoryCount = 4;
List<RelatedItem> containableItems; List<RelatedItem> containableItems;
public ItemInventory Inventory; public ItemInventory Inventory;
@@ -301,6 +301,10 @@ namespace Barotrauma.Items.Components
int itemIndex = fabricatedItem == null ? -1 : fabricableItems.IndexOf(fabricatedItem); int itemIndex = fabricatedItem == null ? -1 : fabricableItems.IndexOf(fabricatedItem);
message.WriteRangedInteger(-1, fabricableItems.Count-1, itemIndex); message.WriteRangedInteger(-1, fabricableItems.Count-1, itemIndex);
var containers = item.GetComponents<ItemContainer>();
containers[0].Inventory.FillNetworkData(type, message, null);
containers[1].Inventory.FillNetworkData(type, message, null);
return true; return true;
} }
@@ -311,6 +315,10 @@ namespace Barotrauma.Items.Components
int itemIndex = message.ReadRangedInteger(-1, fabricableItems.Count-1); int itemIndex = message.ReadRangedInteger(-1, fabricableItems.Count-1);
var containers = item.GetComponents<ItemContainer>();
containers[0].Inventory.ReadNetworkData(type, message, sendingTime);
containers[1].Inventory.ReadNetworkData(type, message, sendingTime);
if (itemIndex == -1) if (itemIndex == -1)
{ {
CancelFabricating(); CancelFabricating();
@@ -324,7 +332,6 @@ namespace Barotrauma.Items.Components
SelectItem(null, fabricableItems[itemIndex]); SelectItem(null, fabricableItems[itemIndex]);
StartFabricating(fabricableItems[itemIndex]); StartFabricating(fabricableItems[itemIndex]);
timeUntilReady -= sendingTime - (float)Lidgren.Network.NetTime.Now;
} }
lastNetworkUpdate = sendingTime; lastNetworkUpdate = sendingTime;
@@ -177,6 +177,8 @@ namespace Barotrauma.Items.Components
} }
} }
ApplyStatusEffects(ActionType.OnUse, 1.0f, null);
item.body.FarseerBody.OnCollision -= OnProjectileCollision; item.body.FarseerBody.OnCollision -= OnProjectileCollision;
item.body.FarseerBody.IsBullet = false; item.body.FarseerBody.IsBullet = false;
@@ -172,6 +172,8 @@ namespace Barotrauma.Items.Components
projectile.body.ResetDynamics(); projectile.body.ResetDynamics();
projectile.body.Enabled = true; projectile.body.Enabled = true;
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y)), -rotation); projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y)), -rotation);
projectile.FindHull();
projectile.Submarine = projectile.body.Submarine;
projectiles[0].Use(deltaTime); projectiles[0].Use(deltaTime);
projectiles[0].User = character; projectiles[0].User = character;
+20 -8
View File
@@ -1370,9 +1370,16 @@ namespace Barotrauma
message.Write(requirementIndex); message.Write(requirementIndex);
break; break;
case NetworkEventType.InventoryUpdate: case NetworkEventType.InventoryUpdate:
var itemContainer = GetComponent<ItemContainer>(); var itemContainers = GetComponents<ItemContainer>();
if (itemContainer == null || itemContainer.Inventory == null) return false; if (itemContainers == null || !itemContainers.Any()) return false;
return itemContainer.Inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
message.WriteRangedInteger(1, ItemContainer.MaxInventoryCount, itemContainers.Count);
foreach (ItemContainer container in itemContainers)
{
container.Inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
}
return true;
case NetworkEventType.ComponentUpdate: case NetworkEventType.ComponentUpdate:
case NetworkEventType.ImportantComponentUpdate: case NetworkEventType.ImportantComponentUpdate:
@@ -1434,7 +1441,7 @@ namespace Barotrauma
{ {
case NetworkEventType.DropItem: case NetworkEventType.DropItem:
Vector2 newSimPos = Vector2.Zero; Vector2 newSimPos = Vector2.Zero;
newSimPos = new Vector2(message.ReadFloat(), message.ReadFloat()); newSimPos = new Vector2(message.ReadFloat(), message.ReadFloat());
SetTransform(newSimPos, body.Rotation); SetTransform(newSimPos, body.Rotation);
Drop(null, false); Drop(null, false);
break; break;
@@ -1443,15 +1450,20 @@ namespace Barotrauma
byte requirementIndex = message.ReadByte(); byte requirementIndex = message.ReadByte();
data = requirementIndex; data = requirementIndex;
if (requirementIndex>=FixRequirements.Count) return; if (requirementIndex >= FixRequirements.Count) return;
FixRequirements[requirementIndex].Fixed = true; FixRequirements[requirementIndex].Fixed = true;
break; break;
case NetworkEventType.InventoryUpdate: case NetworkEventType.InventoryUpdate:
var itemContainers = GetComponents<ItemContainer>();
if (itemContainers == null || !itemContainers.Any()) return;
int containerCount = message.ReadRangedInteger(1, ItemContainer.MaxInventoryCount);
for (int i = 0; i < containerCount;i++ )
{
itemContainers[i].Inventory.ReadNetworkData(type, message, sendingTime);
}
var itemContainer = GetComponent<ItemContainer>();
if (itemContainer == null || itemContainer.Inventory == null) return;
itemContainer.Inventory.ReadNetworkData(NetworkEventType.DropItem, message, sendingTime);
break; break;
case NetworkEventType.ComponentUpdate: case NetworkEventType.ComponentUpdate:
case NetworkEventType.ImportantComponentUpdate: case NetworkEventType.ImportantComponentUpdate:
+12 -5
View File
@@ -41,10 +41,16 @@ namespace Barotrauma
{ {
GameMain.ParticleManager.CreateParticle("shockwave", worldPosition, GameMain.ParticleManager.CreateParticle("shockwave", worldPosition,
Vector2.Zero, 0.0f, hull); Vector2.Zero, 0.0f, hull);
} }
for (int i = 0; i < attack.Range * 0.1f; i++) for (int i = 0; i < attack.Range * 0.1f; i++)
{ {
Vector2 bubblePos = Rand.Vector(attack.Range * 0.5f);
GameMain.ParticleManager.CreateParticle("bubbles", worldPosition+bubblePos,
bubblePos, 0.0f, hull);
if (sparks) if (sparks)
{ {
GameMain.ParticleManager.CreateParticle("spark", worldPosition, GameMain.ParticleManager.CreateParticle("spark", worldPosition,
@@ -75,16 +81,17 @@ namespace Barotrauma
foreach (Character c in Character.CharacterList) foreach (Character c in Character.CharacterList)
{ {
float dist = Vector2.Distance(c.WorldPosition, worldPosition);
if (dist > attack.Range) continue;
float distFactor = 1.0f - dist / attack.Range;
foreach (Limb limb in c.AnimController.Limbs) foreach (Limb limb in c.AnimController.Limbs)
{ {
float dist = Vector2.Distance(limb.WorldPosition, worldPosition);
if (dist > attack.Range) continue;
float distFactor = 1.0f - dist / attack.Range;
if (limb.WorldPosition == worldPosition) continue; if (limb.WorldPosition == worldPosition) continue;
distFactor = 1.0f - Vector2.Distance(limb.WorldPosition, worldPosition)/attack.Range;
c.AddDamage(limb.SimPosition, DamageType.None, c.AddDamage(limb.SimPosition, DamageType.None,
attack.GetDamage(1.0f) / c.AnimController.Limbs.Length * distFactor, 0.0f, attack.Stun * distFactor, false); attack.GetDamage(1.0f) / c.AnimController.Limbs.Length * distFactor, 0.0f, attack.Stun * distFactor, false);
+1 -1
View File
@@ -407,7 +407,7 @@ namespace Barotrauma
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true)
{ {
if (back) return; //if (back) return;
if (!ShowHulls && !GameMain.DebugDraw) return; if (!ShowHulls && !GameMain.DebugDraw) return;
+204 -73
View File
@@ -13,12 +13,25 @@ using Voronoi2;
namespace Barotrauma namespace Barotrauma
{ {
class Level class Level
{ {
public static Level Loaded public static Level Loaded
{ {
get { return loaded; } get { return loaded; }
} }
struct InterestingPosition
{
public readonly Vector2 Position;
public readonly bool IsLarge;
public InterestingPosition(Vector2 position, bool isLarge)
{
Position = position;
IsLarge = isLarge;
}
}
static Level loaded; static Level loaded;
@@ -49,7 +62,7 @@ namespace Barotrauma
private List<Body> bodies; private List<Body> bodies;
private List<Vector2> positionsOfInterest; private List<InterestingPosition> positionsOfInterest;
public Vector2 StartPosition public Vector2 StartPosition
{ {
@@ -65,12 +78,7 @@ namespace Barotrauma
{ {
get { return endPosition; } get { return endPosition; }
} }
public List<Vector2> PositionsOfInterest
{
get { return positionsOfInterest; }
}
public WrappingWall[,] WrappingWalls public WrappingWall[,] WrappingWalls
{ {
get { return wrappingWalls; } get { return wrappingWalls; }
@@ -101,7 +109,7 @@ namespace Barotrauma
this.Difficulty = difficulty; this.Difficulty = difficulty;
positionsOfInterest = new List<Vector2>(); positionsOfInterest = new List<InterestingPosition>();
borders = new Rectangle(0, 0, width, height); borders = new Rectangle(0, 0, width, height);
} }
@@ -109,7 +117,7 @@ namespace Barotrauma
public static Level CreateRandom(LocationConnection locationConnection) public static Level CreateRandom(LocationConnection locationConnection)
{ {
string seed = locationConnection.Locations[0].Name + locationConnection.Locations[1].Name; string seed = locationConnection.Locations[0].Name + locationConnection.Locations[1].Name;
return new Level(seed, locationConnection.Difficulty, 100000, 40000, 2000); return new Level(seed, locationConnection.Difficulty, 100000, 50000, 2000);
} }
public static Level CreateRandom(string seed = "") public static Level CreateRandom(string seed = "")
@@ -118,7 +126,7 @@ namespace Barotrauma
{ {
seed = Rand.Range(0, int.MaxValue, false).ToString(); seed = Rand.Range(0, int.MaxValue, false).ToString();
} }
return new Level(seed, Rand.Range(30.0f,80.0f,false), 100000, 40000, 2000); return new Level(seed, Rand.Range(30.0f,80.0f,false), 100000, 50000, 2000);
} }
public void Generate(bool mirror=false) public void Generate(bool mirror=false)
@@ -140,6 +148,63 @@ namespace Barotrauma
Rand.SetSyncedSeed(ToolBox.StringToInt(seed)); Rand.SetSyncedSeed(ToolBox.StringToInt(seed));
float minWidth = Submarine.Loaded == null ? 3000.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height);
startPosition = new Vector2(minWidth * 2, borders.Height);
endPosition = new Vector2(borders.Width - minWidth * 2, borders.Height);
List<Vector2> pathNodes = new List<Vector2>();
Rectangle pathBorders = borders;// new Rectangle((int)minWidth, (int)minWidth, borders.Width - (int)minWidth * 2, borders.Height - (int)minWidth);
pathBorders.Inflate(-minWidth*2, -minWidth*2);
pathNodes.Add(startPosition);
//pathNodes.Add(new Vector2(minWidth * 3, Rand.Range(minWidth * 2, borders.Height - minWidth * 2, false)));
for (float x = startPosition.X; x < endPosition.X; x += Rand.Range(2000.0f, 10000.0f, false))
{
pathNodes.Add(new Vector2(x, Rand.Range(pathBorders.Y, pathBorders.Bottom, false)));
//if (x > borders.Center.X)
//{
// positionsOfInterest.Add(pathNodes.Last());
//}
}
//pathNodes.Add(new Vector2(borders.Width - minWidth * 3, borders.Height / 2));
pathNodes.Add(endPosition);
int smallTunnelCount = 5;
List<List<Vector2>> smallTunnels = new List<List<Vector2>>();
for (int i = 0; i < smallTunnelCount; i++)
{
var tunnelStartPos = pathNodes[Rand.Range(2, pathNodes.Count - 2, false)];
tunnelStartPos.X = MathHelper.Clamp(tunnelStartPos.X, pathBorders.X, pathBorders.Right);
float tunnelLength = Rand.Range(5000.0f, 10000.0f, false);
var tunnelNodes = MathUtils.GenerateJaggedLine(tunnelStartPos, tunnelStartPos + Rand.Vector(tunnelLength,false) + Vector2.UnitY*5000.0f, 3, 1000.0f);
List<Vector2> tunnel = new List<Vector2>();
foreach (Vector2[] tunnelNode in tunnelNodes)
{
if (!pathBorders.Contains(tunnelNode[0])) break;
tunnel.Add(tunnelNode[0]);
}
if (tunnel.Any())
{
smallTunnels.Add(tunnel);
positionsOfInterest.Add(new InterestingPosition(tunnel.Last(), false));
if (tunnel.Count() > 4) positionsOfInterest.Add(new InterestingPosition(tunnel[tunnel.Count()/2], false));
}
}
float siteVariance = siteInterval * 0.4f; float siteVariance = siteInterval * 0.4f;
for (int x = siteInterval / 2; x < borders.Width; x += siteInterval) for (int x = siteInterval / 2; x < borders.Width; x += siteInterval)
{ {
@@ -147,6 +212,13 @@ namespace Barotrauma
{ {
Vector2 site = new Vector2(x, y) + Rand.Vector(siteVariance, false); Vector2 site = new Vector2(x, y) + Rand.Vector(siteVariance, false);
if (smallTunnels.Any(t => t.Any(node => Vector2.Distance(node, site) < siteInterval)))
{
if (x < borders.Width - siteInterval) sites.Add(new Vector2(x, y) + Vector2.UnitX * siteInterval * 0.2f);
if (y < borders.Height - siteInterval) sites.Add(new Vector2(x, y) + Vector2.UnitY * siteInterval * 0.2f);
if (x < borders.Width - siteInterval && y < borders.Height - siteInterval) sites.Add(new Vector2(x, y) + Vector2.One * siteInterval * 0.2f);
}
if (mirror) site.X = borders.Width - site.X; if (mirror) site.X = borders.Width - site.X;
sites.Add(site); sites.Add(site);
@@ -205,68 +277,63 @@ namespace Barotrauma
Debug.WriteLine("find cells: " + sw2.ElapsedMilliseconds + " ms"); Debug.WriteLine("find cells: " + sw2.ElapsedMilliseconds + " ms");
sw2.Restart(); sw2.Restart();
float minWidth = Submarine.Loaded == null ? 3000.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height);
//generate a path from the left edge of the map to right edge //if (mirror)
Rectangle pathBorders = new Rectangle( //{
borders.X + (int)minWidth * 2, borders.Y + (int)minWidth * 2, // pathNodes.Reverse();
borders.Right - (int)minWidth * 4, borders.Y + borders.Height - (int)minWidth * 4); //}
List<Vector2> pathNodes = new List<Vector2>();
startPosition = new Vector2((int)minWidth * 2, Rand.Range((int)minWidth * 2, borders.Height - (int)minWidth * 2, false));
endPosition = new Vector2(borders.Width - (int)minWidth * 2, Rand.Range((int)minWidth * 2, borders.Height - (int)minWidth * 2, false));
pathNodes.Add(new Vector2(startPosition.X, borders.Height));
pathNodes.Add(startPosition);
pathNodes.Add(endPosition);
pathNodes.Add(new Vector2(endPosition.X, borders.Height));
if (mirror)
{
pathNodes.Reverse();
}
List<VoronoiCell> pathCells = GeneratePath(pathNodes, cells, pathBorders, minWidth, 0.3f, mirror, true); List<VoronoiCell> pathCells = GeneratePath(pathNodes, cells, pathBorders, minWidth, 0.3f, mirror, true);
//place some enemy spawnpoints at random points in the path foreach (InterestingPosition positionOfInterest in positionsOfInterest)
for (int i = 0; i <3 ; i++ )
{ {
Vector2 position = pathCells[Rand.Range((int)(pathCells.Count * 0.5f), pathCells.Count - 2, false)].Center; WayPoint wayPoint = new WayPoint(positionOfInterest.Position, SpawnType.Enemy, null);
WayPoint wayPoint = new WayPoint(new Rectangle((int)position.X, (int)position.Y, 10, 10), null);
wayPoint.MoveWithLevel = true; wayPoint.MoveWithLevel = true;
wayPoint.SpawnType = SpawnType.Enemy;
} }
startPosition = pathCells[0].Center; startPosition = pathCells[0].Center;
endPosition = pathCells[pathCells.Count - 1].Center; endPosition = pathCells[pathCells.Count - 1].Center;
//generate a couple of random paths foreach (List<Vector2> tunnel in smallTunnels)
for (int i = 0; i <= Rand.Range(1,4,false); i++)
{ {
//pathBorders = new Rectangle( if (tunnel.Count<2) continue;
//borders.X + siteInterval * 2, borders.Y - siteInterval * 2,
//borders.Right - siteInterval * 2, borders.Y + borders.Height - siteInterval * 2);
Vector2 start = pathCells[Rand.Range(1, pathCells.Count - 2,false)].Center; var newPathCells = GeneratePath(tunnel, cells, pathBorders, 0.0f, 0.0f);
float x = pathBorders.X + Rand.Range(0, pathBorders.Right - pathBorders.X, false); //for (int n = 0; n < newPathCells.Count; n += 5)
float y = pathBorders.Y + Rand.Range(0,pathBorders.Bottom - pathBorders.Y, false); //{
// positionsOfInterest.Add(newPathCells[n].Center);
if (mirror) x = borders.Width - x; //}
Vector2 end = new Vector2(x, y);
var newPathCells = GeneratePath(new List<Vector2> { start, end }, cells, pathBorders, 0.0f, 0.8f, mirror);
for (int n = 0; n < newPathCells.Count; n += 5)
{
positionsOfInterest.Add(newPathCells[n].Center);
}
pathCells.AddRange(newPathCells); pathCells.AddRange(newPathCells);
} }
////generate a couple of random paths
//for (int i = 0; i <= Rand.Range(1,4,false); i++)
//{
// //pathBorders = new Rectangle(
// //borders.X + siteInterval * 2, borders.Y - siteInterval * 2,
// //borders.Right - siteInterval * 2, borders.Y + borders.Height - siteInterval * 2);
// Vector2 start = pathCells[Rand.Range(1, pathCells.Count - 2,false)].Center;
// float x = pathBorders.X + Rand.Range(0, pathBorders.Right - pathBorders.X, false);
// float y = pathBorders.Y + Rand.Range(0,pathBorders.Bottom - pathBorders.Y, false);
// if (mirror) x = borders.Width - x;
// Vector2 end = new Vector2(x, y);
// var newPathCells = GeneratePath(new List<Vector2> { start, end }, cells, pathBorders, 0.0f, 0.8f, mirror);
// for (int n = 0; n < newPathCells.Count; n += 5)
// {
// positionsOfInterest.Add(newPathCells[n].Center);
// }
// pathCells.AddRange(newPathCells);
//}
Debug.WriteLine("path: " + sw2.ElapsedMilliseconds + " ms"); Debug.WriteLine("path: " + sw2.ElapsedMilliseconds + " ms");
sw2.Restart(); sw2.Restart();
@@ -282,9 +349,9 @@ namespace Barotrauma
cells = CleanCells(pathCells); cells = CleanCells(pathCells);
pathCells.AddRange(CreateBottomHoles(0.8f, new Rectangle( pathCells.AddRange(CreateBottomHoles(Rand.Range(0.2f,0.8f, false), new Rectangle(
(int)(borders.Width * 0.2f), 0, (int)(borders.Width * 0.2f), 0,
(int)(borders.Width * 0.6f), (int)(borders.Height * 0.5f)))); (int)(borders.Width * 0.6f), (int)(borders.Height * 0.3f))));
foreach (VoronoiCell cell in pathCells) foreach (VoronoiCell cell in pathCells)
{ {
@@ -345,7 +412,11 @@ namespace Barotrauma
ShaftBodies[i] = BodyFactory.CreateRectangle(GameMain.World, 100.0f, 10.0f, 5.0f); ShaftBodies[i] = BodyFactory.CreateRectangle(GameMain.World, 100.0f, 10.0f, 5.0f);
ShaftBodies[i].BodyType = BodyType.Static; ShaftBodies[i].BodyType = BodyType.Static;
ShaftBodies[i].CollisionCategories = Physics.CollisionLevel; ShaftBodies[i].CollisionCategories = Physics.CollisionLevel;
ShaftBodies[i].SetTransform(ConvertUnits.ToSimUnits((i == 0) ? startPosition : endPosition), 0.0f);
Vector2 shaftPos = (i == 0) ? startPosition : endPosition;
shaftPos.Y = borders.Height;
ShaftBodies[i].SetTransform(ConvertUnits.ToSimUnits(shaftPos), 0.0f);
bodies.Add(ShaftBodies[i]); bodies.Add(ShaftBodies[i]);
} }
@@ -403,7 +474,9 @@ namespace Barotrauma
VoronoiCell currentCell = targetCells[0]; VoronoiCell currentCell = targetCells[0];
pathCells.Add(currentCell); pathCells.Add(currentCell);
int currentTargetIndex = 1; int currentTargetIndex = 1;
wanderAmount = 0.0f;
do do
{ {
@@ -416,7 +489,7 @@ namespace Barotrauma
allowedEdges.Add(edge); allowedEdges.Add(edge);
} }
//steer towards target //steer towards target
if (Rand.Range(0.0f, 1.0f, false) > wanderAmount || allowedEdges.Count == 0) if (Rand.Range(0.0f, 1.0f, false) > wanderAmount || allowedEdges.Count == 0)
{ {
@@ -544,22 +617,31 @@ namespace Barotrauma
minDistance *= 0.5f; minDistance *= 0.5f;
do do
{ {
for (int x = -1; x <= 1; x++) var closeCells = GetCells(position, 2);
{
for (int y = -1; y <= 1; y++)
{
if (x == 0 && y == 0) continue;
Vector2 cornerPos = position + new Vector2(x * minDistance, y * minDistance);
int cellIndex = FindCellIndex(cornerPos); foreach (VoronoiCell cell in closeCells)
if (cellIndex == -1) continue; {
if (!tooCloseCells.Contains(cells[cellIndex])) if (!cell.edges.Any(e => Vector2.Distance(position, e.point1) < minDistance || Vector2.Distance(position, e.point2) < minDistance)) continue;
{
tooCloseCells.Add(cells[cellIndex]); if (!tooCloseCells.Contains(cell)) tooCloseCells.Add(cell);
}
}
} }
//for (int x = -1; x <= 1; x++)
//{
// for (int y = -1; y <= 1; y++)
// {
// if (x == 0 && y == 0) continue;
// Vector2 cornerPos = position + new Vector2(x * minDistance, y * minDistance);
// int cellIndex = FindCellIndex(cornerPos);
// if (cellIndex == -1) continue;
// if (!tooCloseCells.Contains(cells[cellIndex]))
// {
// tooCloseCells.Add(cells[cellIndex]);
// }
// }
//}
position += Vector2.Normalize(emptyCells[targetCellIndex].Center - position) * step; position += Vector2.Normalize(emptyCells[targetCellIndex].Center - position) * step;
if (Vector2.Distance(emptyCells[targetCellIndex].Center, position) < step * 2.0f) targetCellIndex++; if (Vector2.Distance(emptyCells[targetCellIndex].Center, position) < step * 2.0f) targetCellIndex++;
@@ -771,6 +853,15 @@ namespace Barotrauma
} }
if (!leftNormal.IsValid())
{
#if DEBUG
DebugConsole.ThrowError("Invalid right normal");
#endif
leftNormal = Vector2.UnitX;
}
if (rightEdge == null) if (rightEdge == null)
{ {
rightNormal = GetEdgeNormal(edge, cell); rightNormal = GetEdgeNormal(edge, cell);
@@ -782,6 +873,14 @@ namespace Barotrauma
Vector2.Normalize(rightEdge.Center - edge.point2); Vector2.Normalize(rightEdge.Center - edge.point2);
} }
if (!rightNormal.IsValid())
{
#if DEBUG
DebugConsole.ThrowError("Invalid right normal");
#endif
rightNormal = Vector2.UnitX;
}
@@ -856,6 +955,8 @@ namespace Barotrauma
public Vector2 GetRandomItemPos(float offsetFromWall = 10.0f) public Vector2 GetRandomItemPos(float offsetFromWall = 10.0f)
{ {
if (!positionsOfInterest.Any()) return Size*0.5f;
Vector2 position = Vector2.Zero; Vector2 position = Vector2.Zero;
offsetFromWall = ConvertUnits.ToSimUnits(offsetFromWall); offsetFromWall = ConvertUnits.ToSimUnits(offsetFromWall);
@@ -863,7 +964,7 @@ namespace Barotrauma
int tries = 0; int tries = 0;
do do
{ {
Vector2 startPos = ConvertUnits.ToSimUnits(PositionsOfInterest[Rand.Int(PositionsOfInterest.Count, false)]); Vector2 startPos = ConvertUnits.ToSimUnits(positionsOfInterest[Rand.Int(positionsOfInterest.Count, false)].Position);
Vector2 endPos = startPos - ConvertUnits.ToSimUnits(Vector2.UnitY * Size.Y); Vector2 endPos = startPos - ConvertUnits.ToSimUnits(Vector2.UnitY * Size.Y);
@@ -888,6 +989,23 @@ namespace Barotrauma
return position; return position;
} }
public Vector2 GetRandomInterestingPosition(bool requireSpace, bool useSyncedRand)
{
if (!positionsOfInterest.Any()) return Size * 0.5f;
if (requireSpace)
{
var positionsWithSpace = positionsOfInterest.FindAll(p => p.IsLarge);
if (!positionsWithSpace.Any()) return Size * 0.5f;
return positionsWithSpace[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position;
}
else
{
return positionsOfInterest[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position;
}
}
public void Update (float deltaTime) public void Update (float deltaTime)
{ {
if (Submarine.Loaded!=null) if (Submarine.Loaded!=null)
@@ -902,6 +1020,14 @@ namespace Barotrauma
{ {
if (renderer == null) return; if (renderer == null) return;
renderer.Draw(spriteBatch); renderer.Draw(spriteBatch);
if (GameMain.DebugDraw)
{
foreach (InterestingPosition pos in positionsOfInterest)
{
GUI.DrawRectangle(spriteBatch, new Vector2(pos.Position.X-15.0f, -pos.Position.Y-15.0f), new Vector2(30.0f, 30.0f), Color.Gold, true);
}
}
} }
public void DrawBack(SpriteBatch spriteBatch, Camera cam, BackgroundCreatureManager backgroundSpriteManager = null) public void DrawBack(SpriteBatch spriteBatch, Camera cam, BackgroundCreatureManager backgroundSpriteManager = null)
@@ -934,10 +1060,14 @@ namespace Barotrauma
} }
} }
if (wrappingWalls == null) return cells;
for (int side = 0; side < 2; side++) for (int side = 0; side < 2; side++)
{ {
for (int n = 0; n < 2; n++) for (int n = 0; n < 2; n++)
{ {
if (wrappingWalls[side, n] == null) continue;
if (Vector2.Distance(wrappingWalls[side, n].MidPos, pos) > WrappingWall.WallWidth) continue; if (Vector2.Distance(wrappingWalls[side, n].MidPos, pos) > WrappingWall.WallWidth) continue;
foreach (VoronoiCell cell in wrappingWalls[side, n].Cells) foreach (VoronoiCell cell in wrappingWalls[side, n].Cells)
@@ -1015,6 +1145,7 @@ namespace Barotrauma
private void Unload() private void Unload()
{ {
renderer.Dispose(); renderer.Dispose();
renderer = null; renderer = null;
@@ -144,7 +144,7 @@ namespace Barotrauma
public void Draw(SpriteBatch spriteBatch) public void Draw(SpriteBatch spriteBatch)
{ {
Vector2 pos = new Vector2(0.0f, -level.StartPosition.Y);// level.EndPosition; Vector2 pos = new Vector2(0.0f, -level.Size.Y);// level.EndPosition;
if (GameMain.GameScreen.Cam.WorldView.Y < -pos.Y - 512) return; if (GameMain.GameScreen.Cam.WorldView.Y < -pos.Y - 512) return;
@@ -232,8 +232,8 @@ namespace Barotrauma
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
wallVertices.Dispose(); if (wallVertices!=null) wallVertices.Dispose();
bodyVertices.Dispose(); if (bodyVertices != null) bodyVertices.Dispose();
} }
} }
+2 -2
View File
@@ -198,8 +198,8 @@ namespace Barotrauma
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
wallVertices.Dispose(); if (wallVertices!=null) wallVertices.Dispose();
bodyVertices.Dispose(); if (bodyVertices!=null) bodyVertices.Dispose();
} }
} }
} }
+1 -34
View File
@@ -176,7 +176,7 @@ namespace Barotrauma
Vector2 start = connection.Locations[0].MapPosition; Vector2 start = connection.Locations[0].MapPosition;
Vector2 end = connection.Locations[1].MapPosition; Vector2 end = connection.Locations[1].MapPosition;
int generations = (int)(Math.Sqrt(Vector2.Distance(start, end) / 10.0f)); int generations = (int)(Math.Sqrt(Vector2.Distance(start, end) / 10.0f));
connection.CrackSegments = GenerateCrack(start, end, generations); connection.CrackSegments = MathUtils.GenerateJaggedLine(start, end, generations, 5.0f);
} }
} }
@@ -200,39 +200,6 @@ namespace Barotrauma
} }
} }
private List<Vector2[]> GenerateCrack(Vector2 start, Vector2 end, int generations)
{
List<Vector2[]> segments = new List<Vector2[]>();
segments.Add(new Vector2[] {start, end});
float offsetAmount = 5.0f;
for (int n = 0; n < generations; n++)
{
for (int i = 0; i < segments.Count; i++)
{
Vector2 startSegment = segments[i][0];
Vector2 endSegment = segments[i][1];
segments.RemoveAt(i);
Vector2 midPoint = (startSegment + endSegment) / 2.0f;
Vector2 normal = Vector2.Normalize(endSegment - startSegment);
normal = new Vector2(-normal.Y, normal.X);
midPoint += normal * Rand.Range(-offsetAmount, offsetAmount, false);
segments.Insert(i, new Vector2[] { startSegment, midPoint });
segments.Insert(i+1, new Vector2[] { midPoint, endSegment });
i++;
}
}
return segments;
}
public void MoveToNextLocation() public void MoveToNextLocation()
{ {
currentLocation = selectedLocation; currentLocation = selectedLocation;
+1 -1
View File
@@ -68,7 +68,7 @@ namespace Barotrauma
{ {
file = ToolBox.GetAttributeString(element, "texture", ""); file = ToolBox.GetAttributeString(element, "texture", "");
} }
if (file == "") if (file == "")
{ {
DebugConsole.ThrowError("Sprite " + element + " doesn't have a texture specified!"); DebugConsole.ThrowError("Sprite " + element + " doesn't have a texture specified!");
+31
View File
@@ -242,6 +242,37 @@ namespace Barotrauma
return triangles; return triangles;
} }
public static List<Vector2[]> GenerateJaggedLine(Vector2 start, Vector2 end, int generations, float offsetAmount)
{
List<Vector2[]> segments = new List<Vector2[]>();
segments.Add(new Vector2[] { start, end });
for (int n = 0; n < generations; n++)
{
for (int i = 0; i < segments.Count; i++)
{
Vector2 startSegment = segments[i][0];
Vector2 endSegment = segments[i][1];
segments.RemoveAt(i);
Vector2 midPoint = (startSegment + endSegment) / 2.0f;
Vector2 normal = Vector2.Normalize(endSegment - startSegment);
normal = new Vector2(-normal.Y, normal.X);
midPoint += normal * Rand.Range(-offsetAmount, offsetAmount, false);
segments.Insert(i, new Vector2[] { startSegment, midPoint });
segments.Insert(i + 1, new Vector2[] { midPoint, endSegment });
i++;
}
}
return segments;
}
} }
class CompareCCW : IComparer<Vector2> class CompareCCW : IComparer<Vector2>
+8
View File
@@ -1,3 +1,11 @@
---------------------------------------------------------------------------------------------------------
v0.3.1.1
---------------------------------------------------------------------------------------------------------
- fixed a major bug that caused item/monster ID mismatches between the server and the clients, which
accounted for many of the monster/inventory/item syncing issues
- improved player position syncing
--------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------
v0.3.1.0 v0.3.1.0
--------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------
Binary file not shown.