Skip to content

Commit

Permalink
v0.1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Regalis committed Aug 18, 2015
1 parent 00c64f0 commit e19ac60
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 58 deletions.
4 changes: 2 additions & 2 deletions Subsurface/Content/Jobs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</Skills>
</Captain>

<Engineer>
<Engineer minnumber="1">
<Skills>
<Skill name="Weapons" level="10,30"/>
<Skill name="Construction" level="30,40"/>
Expand All @@ -24,7 +24,7 @@
<Item name="Screwdriver"/>
</Engineer>

<Mechanic>
<Mechanic minnumber="1">
<Skills>
<Skill name="Weapons" level="10,30"/>
<Skill name="Construction" level="50,60"/>
Expand Down
4 changes: 2 additions & 2 deletions Subsurface/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.3.1")]
[assembly: AssemblyFileVersion("0.1.3.1")]
[assembly: AssemblyVersion("0.1.3.2")]
[assembly: AssemblyFileVersion("0.1.3.2")]
6 changes: 3 additions & 3 deletions Subsurface/Source/Characters/AI/EnemyAIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,9 @@ public override void FillNetworkData(NetOutgoingMessage message)
}

message.Write(MathUtils.AngleToByte(steeringManager.WanderAngle));
message.WriteRangedSingle(Math.Max(updateTargetsTimer,0.0f), 0.0f, UpdateTargetsInterval, 8);
message.WriteRangedSingle(Math.Max(raycastTimer,0.0f), 0.0f, RaycastInterval, 8);
message.WriteRangedSingle(Math.Max(coolDownTimer, 0.0f), 0.0f, attackCoolDown*2.0f, 8);
message.WriteRangedSingle(MathHelper.Clamp(updateTargetsTimer,0.0f, UpdateTargetsInterval), 0.0f, UpdateTargetsInterval, 8);
message.WriteRangedSingle(MathHelper.Clamp(raycastTimer, 0.0f, RaycastInterval), 0.0f, RaycastInterval, 8);
message.WriteRangedSingle(MathHelper.Clamp(coolDownTimer, 0.0f, attackCoolDown * 2.0f), 0.0f, attackCoolDown * 2.0f, 8);

message.Write(targetEntity==null ? -1 : (targetEntity as Entity).ID);
}
Expand Down
24 changes: 11 additions & 13 deletions Subsurface/Source/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ public void ControlLocalPlayer(Camera cam, bool moveCam = true)
}
}


if (AnimController.onGround &&
!AnimController.InWater &&
AnimController.Anim != AnimController.Animation.UsingConstruction)
Expand Down Expand Up @@ -1037,15 +1036,15 @@ public override void FillNetworkData(NetworkEventType type, NetOutgoingMessage m
message.Write(NetTime.Now);

// Write byte = move direction
message.WriteRangedSingle(AnimController.TargetMovement.X, -10.0f, 10.0f, 8);
message.WriteRangedSingle(AnimController.TargetMovement.Y, -10.0f, 10.0f, 8);
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -10.0f, 10.0f), -10.0f, 10.0f, 8);
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.Y, -10.0f, 10.0f), -10.0f, 10.0f, 8);

message.Write(AnimController.TargetDir==Direction.Right);

if (aiController!=null)
if (aiController==null)
{
message.WriteRangedSingle(cursorPosition.X, -1000.0f, 1000.0f, 16);
message.WriteRangedSingle(cursorPosition.Y, -1000.0f, 1000.0f, 16);
message.Write(cursorPosition.X);
message.Write(cursorPosition.Y);
}

message.Write(LargeUpdateTimer <= 0);
Expand All @@ -1061,12 +1060,12 @@ public override void FillNetworkData(NetworkEventType type, NetOutgoingMessage m
message.Write(limb.body.LinearVelocity.X);
message.Write(limb.body.LinearVelocity.Y);

message.Write(MathUtils.AngleToByte(limb.body.Rotation));
message.Write(limb.body.Rotation);
message.Write(limb.body.AngularVelocity);
i++;
}

message.WriteRangedSingle(AnimController.StunTimer, 0.0f, 60.0f, 8);
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer,0.0f,60.0f), 0.0f, 60.0f, 8);
message.Write((byte)health);

if (aiController != null) aiController.FillNetworkData(message);
Expand Down Expand Up @@ -1140,13 +1139,12 @@ public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage m

targetDir = message.ReadBoolean();

if (aiController!=null)
if (aiController==null)
{
cursorPos = new Vector2(
message.ReadRangedSingle(-1000.0f, 1000.0f, 16),
message.ReadRangedSingle(-1000.0f, 1000.0f, 16));
message.ReadFloat(),
message.ReadFloat());
}

}

catch
Expand Down Expand Up @@ -1181,7 +1179,7 @@ public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage m
vel.X = message.ReadFloat();
vel.Y = message.ReadFloat();

rotation = MathUtils.ByteToAngle(message.ReadByte());
rotation = message.ReadFloat();
angularVel = message.ReadFloat();
}
catch
Expand Down
2 changes: 2 additions & 0 deletions Subsurface/Source/GUI/GUITextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public GUITextBlock(Rectangle rect, string text, GUIStyle style, Alignment align
: this (rect, text, null, null, alignment, textAlignment, style, parent, wrap)
{
this.Font = font == null ? GUI.Font : font;

SetTextPos();
}

public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment textAlignment = Alignment.Left, GUIStyle style = null, GUIComponent parent = null, bool wrap = false)
Expand Down
23 changes: 17 additions & 6 deletions Subsurface/Source/GUI/GUITickBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,26 @@ public GUITickBox(Rectangle rect, string label, Alignment alignment, GUIComponen
box.HoverColor = Color.Gray;
box.SelectedColor = Color.DarkGray;

text = new GUITextBlock(new Rectangle(rect.X + 40, rect.Y, 200, 30), label, Color.Transparent, Color.White, Alignment.TopLeft, null, this);
text = new GUITextBlock(new Rectangle(rect.X + 40, rect.Y, 200, rect.Height), label, Color.Transparent, Color.White, Alignment.TopLeft, null, this);

Enabled = true;
}

public override void Update(float deltaTime)
{
base.Update(deltaTime);
if (rect.Width ==420)
{
int asd = 1;
}
//base.Update(deltaTime);

if (!Enabled) return;

if (box.Rect.Contains(PlayerInput.GetMouseState.Position))
{



box.State = ComponentState.Hover;

if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
Expand All @@ -77,12 +84,16 @@ public override void Update(float deltaTime)

public override void Draw(SpriteBatch spriteBatch)
{
if (rect.Width == 420)
{
int asd = 1;
}

DrawChildren(spriteBatch);

if (Selected)
{
GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 2, box.Rect.Y + 2, box.Rect.Width - 4, box.Rect.Height - 4), Color.Green * 0.8f, true);
}
GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 2, box.Rect.Y + 2, box.Rect.Width - 4, box.Rect.Height - 4),
selected ? Color.Green * 0.8f : Color.Black, true);

}
}
}
24 changes: 16 additions & 8 deletions Subsurface/Source/Networking/GameClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void ConnectToServer(string hostIP, string password = "")
// Create new instance of configs. Parameter is "application Id". It has to be same on client and server.
NetPeerConfiguration Config = new NetPeerConfiguration("subsurface");

Config.SimulatedLoss = 0.2f;
Config.SimulatedMinimumLatency = 0.5f;
//Config.SimulatedLoss = 0.2f;
//Config.SimulatedMinimumLatency = 0.5f;

// Create new client, with previously created configs
client = new NetClient(Config);
Expand Down Expand Up @@ -111,8 +111,11 @@ public void ConnectToServer(string hostIP, string password = "")
//update.Elapsed += new System.Timers.ElapsedEventHandler(Update);

// Funtion that waits for connection approval info from server
if (reconnectBox==null)
{
reconnectBox = new GUIMessageBox("CONNECTING", "Connecting to " + serverIP, new string[0]);
}

reconnectBox = new GUIMessageBox("CONNECTING", "Connecting to " + serverIP, new string[0]);
CoroutineManager.StartCoroutine(WaitForStartingInfo());

// Start the timer
Expand Down Expand Up @@ -239,14 +242,19 @@ public override void Update(float deltaTime)

if (!connected || updateTimer > DateTime.Now) return;

if (client.ConnectionStatus == NetConnectionStatus.Disconnected && reconnectBox==null)
if (client.ConnectionStatus == NetConnectionStatus.Disconnected)
{
reconnectBox = new GUIMessageBox("CONNECTION LOST", "You have been disconnected from the server. Reconnecting...", new string[0]);
connected = false;
ConnectToServer(serverIP);
if (reconnectBox==null)
{
reconnectBox = new GUIMessageBox("CONNECTION LOST", "You have been disconnected from the server. Reconnecting...", new string[0]);
connected = false;
ConnectToServer(serverIP);
}

return;
}
else if (reconnectBox!=null)

if (reconnectBox!=null)
{
reconnectBox.Close(null,null);
reconnectBox = null;
Expand Down
28 changes: 16 additions & 12 deletions Subsurface/Source/Networking/GameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GameServer : NetworkMember

private Client myClient;

public GameServer(string name, int port, bool isPublic = false, string password="")
public GameServer(string name, int port, bool isPublic = false, string password="", bool attemptUPnP = false, int maxPlayers = 10)
{
var endRoundButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 290, 20, 150, 25), "End round", Alignment.TopLeft, GUI.style, inGameHUD);
endRoundButton.OnClicked = EndButtonHit;
Expand All @@ -41,26 +41,30 @@ public GameServer(string name, int port, bool isPublic = false, string password=

config = new NetPeerConfiguration("subsurface");

config.SimulatedLoss = 0.2f;
config.SimulatedMinimumLatency = 0.5f;
//config.SimulatedLoss = 0.2f;
//config.SimulatedMinimumLatency = 0.5f;

config.Port = port;
Port = port;

config.EnableUPnP = true;
if (attemptUPnP)
{
config.EnableUPnP = true;
}

config.MaximumConnections = 10;

config.MaximumConnections = maxPlayers;
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

try
{
server = new NetServer(config);
server.Start();

// attempt to forward port
server.UPnP.ForwardPort(port, "subsurface");

if (attemptUPnP)
{
server.UPnP.ForwardPort(port, "subsurface");
}
}

catch (Exception e)
Expand Down Expand Up @@ -126,7 +130,7 @@ private IEnumerable<object> RefreshMaster()
masterServerResponded = false;
var restRequestHandle = client.ExecuteAsync(request, response => MasterServerCallBack(response));

DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 10);
DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 15);
while (!masterServerResponded)
{
if (DateTime.Now > timeOut)
Expand Down Expand Up @@ -220,9 +224,9 @@ private void SparseUpdate()
break;
}

if (!isClient)
if (!isClient && (c.SimPosition==Vector2.Zero || c.SimPosition.Length() < 300.0f))
{
//c.LargeUpdateTimer = 0;
c.LargeUpdateTimer -= 2;
new NetworkEvent(c.ID, false);
}
}
Expand Down
55 changes: 45 additions & 10 deletions Subsurface/Source/Screens/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public enum Tabs { Main = 0, NewGame = 1, LoadGame = 2, HostServer = 3 }

private GUITextBox saveNameBox, seedBox;

private GUITextBox serverNameBox, portBox, passwordBox;
private GUITickBox isPublicBox;
private GUITextBox serverNameBox, portBox, passwordBox, maxPlayersBox;
private GUITickBox isPublicBox, useUpnpBox;

private Game1 game;

Expand Down Expand Up @@ -113,18 +113,41 @@ public MainMenuScreen(Game1 game)

new GUITextBlock(new Rectangle(0, -25, 0, 30), "Host Server", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer], false, GUI.LargeFont);

new GUITextBlock(new Rectangle(0, 30, 0, 30), "Server Name:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer]);
serverNameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), null, null, Alignment.CenterX, Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.HostServer]);
new GUITextBlock(new Rectangle(0, 50, 0, 30), "Server Name:", GUI.style, Alignment.TopLeft, Alignment.Left, menuTabs[(int)Tabs.HostServer]);
serverNameBox = new GUITextBox(new Rectangle(160, 50, 200, 30), null, null, Alignment.TopLeft, Alignment.Left, GUI.style, menuTabs[(int)Tabs.HostServer]);

new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server port:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer]);
portBox = new GUITextBox(new Rectangle(0, 130, 200, 30), null, null, Alignment.CenterX, Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.HostServer]);
new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server port:", GUI.style, Alignment.TopLeft, Alignment.Left, menuTabs[(int)Tabs.HostServer]);
portBox = new GUITextBox(new Rectangle(160, 100, 200, 30), null, null, Alignment.TopLeft, Alignment.Left, GUI.style, menuTabs[(int)Tabs.HostServer]);
portBox.Text = NetworkMember.DefaultPort.ToString();
portBox.ToolTip = "Server port";

isPublicBox = new GUITickBox(new Rectangle(portBox.Rect.X - menuTabs[(int)Tabs.HostServer].Rect.X, 200, 20, 20), "Public server", Alignment.TopLeft, menuTabs[(int)Tabs.HostServer]);
new GUITextBlock(new Rectangle(0, 150, 100, 30), "Max players:", GUI.style, Alignment.TopLeft, Alignment.Left, menuTabs[(int)Tabs.HostServer]);
maxPlayersBox = new GUITextBox(new Rectangle(195, 150, 30, 30), null, null, Alignment.TopLeft, Alignment.Center, GUI.style, menuTabs[(int)Tabs.HostServer]);
maxPlayersBox.Text = "8";
maxPlayersBox.Enabled = false;

var plusPlayersBox = new GUIButton(new Rectangle(230, 150, 30, 30), "+", GUI.style, menuTabs[(int)Tabs.HostServer]);
plusPlayersBox.UserData = 1;
plusPlayersBox.OnClicked = ChangeMaxPlayers;

var minusPlayersBox = new GUIButton(new Rectangle(160, 150, 30, 30), "-", GUI.style, menuTabs[(int)Tabs.HostServer]);
minusPlayersBox.UserData = -1;
minusPlayersBox.OnClicked = ChangeMaxPlayers;

new GUITextBlock(new Rectangle(0, 200, 0, 30), "Password (optional):", GUI.style, Alignment.TopLeft, Alignment.Left, menuTabs[(int)Tabs.HostServer]);
passwordBox = new GUITextBox(new Rectangle(160, 200, 200, 30), null, null, Alignment.TopLeft, Alignment.Left, GUI.style, menuTabs[(int)Tabs.HostServer]);


isPublicBox = new GUITickBox(new Rectangle(10, 250, 20, 20), "Public server", Alignment.TopLeft, menuTabs[(int)Tabs.HostServer]);

useUpnpBox = new GUITickBox(new Rectangle(10, 300, 20, 20), "Attempt UPnP port forwarding", Alignment.TopLeft, menuTabs[(int)Tabs.HostServer]);
new GUITextBlock(new Rectangle(0, 330, 0, 30),
"UPnP can be used for forwarding ports on your router to allow players join the server."
+ " However, UPnP isn't supported by all routers, so you may need to setup port forwards manually"
+" if players are unable to join the server (see the readme for instructions).",
GUI.style, Alignment.TopLeft, Alignment.TopLeft, menuTabs[(int)Tabs.HostServer], true, GUI.SmallFont);


new GUITextBlock(new Rectangle(0, 240, 0, 30), "Password (optional):", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer]);
passwordBox = new GUITextBox(new Rectangle(0, 270, 200, 30), null, null, Alignment.CenterX, Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.HostServer]);

GUIButton hostButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.BottomCenter, GUI.style, menuTabs[(int)Tabs.HostServer]);
hostButton.OnClicked = HostServerClicked;
Expand Down Expand Up @@ -163,6 +186,18 @@ private bool JoinServerClicked(GUIButton button, object obj)
return true;
}

private bool ChangeMaxPlayers(GUIButton button, object obj)
{
int currMaxPlayers = 10;

int.TryParse(maxPlayersBox.Text, out currMaxPlayers);
currMaxPlayers = MathHelper.Clamp(currMaxPlayers+(int)button.UserData, 1, 10);

maxPlayersBox.Text = currMaxPlayers.ToString();

return true;
}

private bool HostServerClicked(GUIButton button, object obj)
{
string name = serverNameBox.Text;
Expand All @@ -181,7 +216,7 @@ private bool HostServerClicked(GUIButton button, object obj)
return false;
}

Game1.NetworkMember = new GameServer(name, port, isPublicBox.Selected, passwordBox.Text);
Game1.NetworkMember = new GameServer(name, port, isPublicBox.Selected, passwordBox.Text, useUpnpBox.Selected, int.Parse(maxPlayersBox.Text));

Game1.NetLobbyScreen.IsServer = true;
Game1.NetLobbyScreen.Select();
Expand Down
Loading

0 comments on commit e19ac60

Please sign in to comment.