Skip to content

Commit

Permalink
v1.6.4
Browse files Browse the repository at this point in the history
* Fixed initial placement of wormholes appearing over obstructed terrain (hopefully for good)
* Restored debug config settings and added a wormholes force-reset setting
* Note: Wormholes will be regenerated for all worlds
  • Loading branch information
hamstar committed Jun 10, 2017
1 parent 25c3bac commit bd37e57
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 77 deletions.
52 changes: 25 additions & 27 deletions Wormholes/WormholeManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HamstarHelpers.TileHelpers;
using HamstarHelpers.MiscHelpers;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
Expand Down Expand Up @@ -39,18 +40,15 @@ public WormholeManager( WormholesMod mymod ) {
/////////////////

public bool Load( WormholesMod mymod, TagCompound tags ) {
if( mymod.Config.Data.DisableNaturalWormholes ) {
return false;
}
if( mymod.Config.Data.DisableNaturalWormholes ) { return false; }
if( !tags.ContainsKey("wormhole_count") ) { return false; }

int holes = tags.GetInt( "wormhole_count" );
if( holes == 0 ) {
return false;
}
if( holes == 0 ) { return false; }

//if( (DebugHelper.DEBUGMODE & 1) > 0 ) {
// ErrorLogger.Log( "Loading world ids (" + Main.netMode + "): " + holes );
//}
if( (WormholesMod.DEBUGMODE & 1) > 0 ) {
DebugHelpers.Log( "Loading world ids (" + Main.netMode + "): " + holes );
}

int[] worm_l_x = tags.GetIntArray( "wormhole_left_x" );
int[] worm_l_y = tags.GetIntArray( "wormhole_left_y" );
Expand All @@ -63,9 +61,9 @@ public bool Load( WormholesMod mymod, TagCompound tags ) {
}

string id = tags.GetString( "wormhole_id_" + i );
//if( (DebugHelper.DEBUGMODE & 1) > 0 ) {
// ErrorLogger.Log( " world load id: " + id + " (" + i + ")" );
//}
if( (WormholesMod.DEBUGMODE & 1) > 0 ) {
DebugHelpers.Log( " world load id: " + id + " (" + i + ")" );
}

Vector2 pos_l = new Vector2( worm_l_x[i], worm_l_y[i] );
Vector2 pos_r = new Vector2( worm_r_x[i], worm_r_y[i] );
Expand Down Expand Up @@ -93,9 +91,9 @@ public TagCompound Save() {
int[] worm_r_x = new int[WormholeManager.PortalCount];
int[] worm_r_y = new int[WormholeManager.PortalCount];

//if( (DebugHelper.DEBUGMODE & 1) > 0 ) {
// ErrorLogger.Log( "Save world ids (" + Main.netMode + "): " + WormholeManager.PortalCount );
//}
if( (WormholesMod.DEBUGMODE & 1) > 0 ) {
DebugHelpers.Log( "Save world ids (" + Main.netMode + "): " + WormholeManager.PortalCount );
}

int i;
for( i = 0; i < this.Links.Count; i++ ) {
Expand All @@ -120,10 +118,10 @@ public TagCompound Save() {

for( i = 0; i < this.Links.Count; i++ ) {
tags.Set( "wormhole_id_" + i, ids[i] );
//if( (DebugHelper.DEBUGMODE & 1) > 0 ) {
// ErrorLogger.Log( " world save id: " + ids[i] + " (" + i + ") = "
// + worm_l_x[i] + "," + worm_l_y[i] + " | " + worm_r_x[i] + "," + worm_r_y[i] );
//}
if( (WormholesMod.DEBUGMODE & 1) > 0 ) {
DebugHelpers.Log( " world save id: " + ids[i] + " (" + i + ") = "
+ worm_l_x[i] + "," + worm_l_y[i] + " | " + worm_r_x[i] + "," + worm_r_y[i] );
}
}

return tags;
Expand Down Expand Up @@ -168,9 +166,12 @@ private Vector2 GetRandomClearMapPos() {
is_empty = true;
for( int i=world_x; i<world_x+6; i++ ) {
for( int j=world_y; j<world_y+8; j++ ) {
is_empty = TileHelpers.IsSolid( Main.tile[i, j], true, true );
Tile tile = Framing.GetTileSafely( i, j );

is_empty = !TileHelpers.IsSolid( tile, true, true ) && !tile.lava() && !TileHelpers.IsDungeon(tile);
if( !is_empty ) { break; }
}
if( !is_empty ) { break; }
}
} while( !is_empty );
//} while( Collision.SolidCollision( new Vector2(world_x*16f, world_y*16f), WormholePortal.Width, WormholePortal.Height ) );
Expand Down Expand Up @@ -217,7 +218,7 @@ private WormholeLink CreateRandomWormholePair( WormholesMod mymod, Color color )
//}


public void SetupWormholes( WormholesMod mymod ) {
public void FinishSettingUpWormholes( WormholesMod mymod ) {
if( this.WormholesSpawned ) { return; }

if( WormholeManager.ForceRegenWormholes ) {
Expand All @@ -226,16 +227,13 @@ public void SetupWormholes( WormholesMod mymod ) {
}

for( int i = 0; i < WormholeManager.PortalCount; i++ ) {
// Skip already-loaded wormholes
if( i < this.Links.Count && this.Links[i] != null ) { continue; }

var link = this.CreateRandomWormholePair( mymod, WormholeLink.GetColor(i) );
if( i >= this.Links.Count ) {
this.Links.Add( link );
} else {
this.Links.Insert( i, link );
}
this.Links.Add( link );
}

this.WormholesSpawned = true;
}

Expand Down
4 changes: 3 additions & 1 deletion Wormholes/WormholePortal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using HamstarHelpers.MiscHelpers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
Expand Down Expand Up @@ -53,6 +54,7 @@ public WormholePortal( WormholesMod mymod, Vector2 pos, Color color ) {

pos.X = MathHelper.Clamp( pos.X, 160, (Main.maxTilesX-10) * 16 );
pos.Y = MathHelper.Clamp( pos.Y, 160, (Main.maxTilesY-10) * 16 );
//DebugHelpers.Log( "wall of "+color.ToString()+": "+Main.tile[(int)(pos.X/16f)+2, (int)(pos.Y/16f)+4].wall );

this._pos = pos;
this.BaseColor = color;
Expand Down
25 changes: 21 additions & 4 deletions WormholesMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,47 @@
namespace Wormholes {
public class ConfigurationData {
public string VersionSinceUpdate = "";

public int TinyWorldPortals = 4; // SmallWorldPortals / 2
public int SmallWorldPortals = 8; // 4200 x 1200 = 5040000
public int MediumWorldPortals = 14; // 6400 x 1800 = 11520000
public int LargeWorldPortals = 20; // 8400 x 2400 = 20160000
public int HugeWorldPortals = 27;

public bool CraftableTownPortalScrolls = true;
public int TownPortalDuration = 60 * 60; // 1 hour

public float WormholeSoundVolume = 0.45f;
public float WormholeLightScale = 1.25f;
public float WormholeEntrySoundVolume = 0.9f;
public float TeleportItemDelayMultiplier = 3f;

public bool DisableNaturalWormholes = false;

public int ChaosBombWormholeCloseOdds = 5;
public int ChaosBombRadius = 4;
public int ChaosBombScatterRadius = 32;
public int DEBUGFLAGS = 0;

public int DEBUGFLAGS = 0; // 1: Info; 2: View wormholes on map; 4: Reset wormholes
}



public class WormholesMod : Mod {
public static readonly Version ConfigVersion = new Version( 1, 6, 3 );
public static int DEBUGMODE { get; private set; }

public static readonly Version ConfigVersion = new Version( 1, 6, 4 );
public JsonConfig<ConfigurationData> Config { get; private set; }

private WormholesUI UI;



static WormholesMod() {
WormholesMod.DEBUGMODE = 0;
}



public WormholesMod() : base() {
this.Properties = new ModProperties() {
Autoload = true,
Expand Down Expand Up @@ -73,13 +87,16 @@ public override void Load() {
if( vers_since < new Version( 1, 6, 0 ) ) {
this.Config.Data.WormholeSoundVolume = new ConfigurationData().WormholeSoundVolume;
}
if( vers_since < new Version( 1, 6, 4 ) ) {
WormholeManager.ForceRegenWormholes = true;
}

this.Config.Data.VersionSinceUpdate = WormholesMod.ConfigVersion.ToString();
this.Config.SaveFile();
}
}

//DebugHelper.DEBUGMODE = this.Config.Data.DEBUGFLAGS;
WormholesMod.DEBUGMODE = this.Config.Data.DEBUGFLAGS;

// Clients and single only
if( Main.netMode != 2 ) {
Expand Down
2 changes: 1 addition & 1 deletion WormholesNetProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void SendWormholesAndSettingsViaServer( WormholesMod mymod, Player
ModPacket packet = mymod.GetPacket();

// Be sure our wormholes are ready to send (if not already)
modworld.Wormholes.SetupWormholes( mymod );
modworld.SetupWormholes();

packet.Write( (byte)WormholeNetProtocolTypes.WormholesAndModSettings );
packet.Write( (string)mymod.Config.SerializeMe() );
Expand Down
46 changes: 23 additions & 23 deletions WormholesPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using HamstarHelpers.MiscHelpers;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
using Terraria.ModLoader;
Expand All @@ -11,8 +12,8 @@ public class WormholesPlayer : ModPlayer {
public WormholeLink MyPortal;
public ISet<string> ChartedLinks { get; private set; }

private IDictionary<string, Vector2> MyPortalsRightPositions = new Dictionary<string, Vector2>();
private IDictionary<string, Vector2> MyPortalsLeftPositions = new Dictionary<string, Vector2>();
private IDictionary<string, Vector2> TownPortalRightPositions = new Dictionary<string, Vector2>();
private IDictionary<string, Vector2> TownPortalLeftPositions = new Dictionary<string, Vector2>();

public bool HasEnteredWorld { get; private set; }
public bool HasLoadedTownPortals { get; private set; }
Expand All @@ -30,8 +31,8 @@ public override void clientClone( ModPlayer clone ) {

myclone.MyPortal = this.MyPortal;
myclone.ChartedLinks = this.ChartedLinks;
myclone.MyPortalsRightPositions = this.MyPortalsRightPositions;
myclone.MyPortalsLeftPositions = this.MyPortalsLeftPositions;
myclone.TownPortalRightPositions = this.TownPortalRightPositions;
myclone.TownPortalLeftPositions = this.TownPortalLeftPositions;
myclone.HasEnteredWorld = this.HasEnteredWorld;
myclone.HasLoadedTownPortals = this.HasLoadedTownPortals;
}
Expand All @@ -54,8 +55,8 @@ public override void Load( TagCompound tag ) {
float left_x = tag.GetFloat( "my_town_left_portal_x_" + i );
float left_y = tag.GetFloat( "my_town_left_portal_y_" + i );

this.MyPortalsRightPositions[ world_id ] = new Vector2( right_x, right_y );
this.MyPortalsLeftPositions[ world_id ] = new Vector2( left_x, left_y );
this.TownPortalRightPositions[ world_id ] = new Vector2( right_x, right_y );
this.TownPortalLeftPositions[ world_id ] = new Vector2( left_x, left_y );
}
}

Expand All @@ -76,24 +77,24 @@ public override TagCompound Save() {

if( this.MyPortal != null ) {
if( this.MyPortal.IsClosed ) {
if( this.MyPortalsRightPositions.Keys.Contains(world_id) ) {
this.MyPortalsRightPositions.Remove( world_id );
this.MyPortalsLeftPositions.Remove( world_id );
if( this.TownPortalRightPositions.Keys.Contains(world_id) ) {
this.TownPortalRightPositions.Remove( world_id );
this.TownPortalLeftPositions.Remove( world_id );
}
} else {
this.MyPortalsRightPositions[world_id] = this.MyPortal.RightPortal.Pos;
this.MyPortalsLeftPositions[world_id] = this.MyPortal.LeftPortal.Pos;
this.TownPortalRightPositions[world_id] = this.MyPortal.RightPortal.Pos;
this.TownPortalLeftPositions[world_id] = this.MyPortal.LeftPortal.Pos;
}
}

tags.Set( "my_town_portal_count", this.MyPortalsRightPositions.Count );
tags.Set( "my_town_portal_count", this.TownPortalRightPositions.Count );
i = 0;
foreach( string id in this.MyPortalsRightPositions.Keys ) {
foreach( string id in this.TownPortalRightPositions.Keys ) {
tags.Set( "my_town_portal_id_"+i, id );
tags.Set( "my_town_right_portal_x_" + i, this.MyPortalsRightPositions[id].X );
tags.Set( "my_town_right_portal_y_" + i, this.MyPortalsRightPositions[id].Y );
tags.Set( "my_town_left_portal_x_" + i, this.MyPortalsLeftPositions[id].X );
tags.Set( "my_town_left_portal_y_" + i, this.MyPortalsLeftPositions[id].Y );
tags.Set( "my_town_right_portal_x_" + i, this.TownPortalRightPositions[id].X );
tags.Set( "my_town_right_portal_y_" + i, this.TownPortalRightPositions[id].Y );
tags.Set( "my_town_left_portal_x_" + i, this.TownPortalLeftPositions[id].X );
tags.Set( "my_town_left_portal_y_" + i, this.TownPortalLeftPositions[id].Y );
i++;
}

Expand All @@ -108,7 +109,6 @@ public override void OnEnterWorld( Player player ) {
if( player.whoAmI == this.player.whoAmI ) { // Current player
var mymod = (WormholesMod)this.mod;
var modworld = this.mod.GetModWorld<WormholesWorld>();
string world_id = modworld.ID;

if( !mymod.Config.LoadFile() ) {
mymod.Config.SaveFile();
Expand All @@ -123,7 +123,7 @@ public override void OnEnterWorld( Player player ) {
if( Main.netMode == 1 ) { // Client
WormholesNetProtocol.SendWormholesAndSettingsRequestViaClient( mymod, player );
} else if( Main.netMode == 0 ) { // Single
modworld.Wormholes.SetupWormholes( mymod );
modworld.SetupWormholes();
}

this.HasEnteredWorld = true;
Expand All @@ -135,9 +135,9 @@ public void ReopenTownPortal() {
var modworld = this.mod.GetModWorld<WormholesWorld>();
string world_id = modworld.ID;

if( this.MyPortalsRightPositions.Keys.Contains( world_id ) ) {
Vector2 r_pos = this.MyPortalsRightPositions[world_id];
Vector2 l_pos = this.MyPortalsLeftPositions[world_id];
if( this.TownPortalRightPositions.Keys.Contains( world_id ) ) {
Vector2 r_pos = this.TownPortalRightPositions[world_id];
Vector2 l_pos = this.TownPortalLeftPositions[world_id];
TownPortalScrollItem.OpenPortal( mymod, this.player, r_pos, l_pos );
}

Expand Down
6 changes: 3 additions & 3 deletions WormholesUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Update() {


public void DrawMiniMap( WormholeLink link, SpriteBatch sb ) {
if( /*(DebugHelper.DEBUGMODE & 2) == 0 &&*/ !link.IsCharted( Main.player[Main.myPlayer] ) ) { return; }
if( (WormholesMod.DEBUGMODE & 2) == 0 && !link.IsCharted( Main.player[Main.myPlayer] ) ) { return; }
float scale = Main.mapMinimapScale / 1.5f;

Rectangle l_rect = new Rectangle( (int)link.LeftPortal.Pos.X, (int)link.LeftPortal.Pos.Y, this.Tex.Width, this.Tex.Height );
Expand All @@ -43,7 +43,7 @@ public void DrawMiniMap( WormholeLink link, SpriteBatch sb ) {
}

public void DrawOverlayMap( WormholeLink link, SpriteBatch sb ) {
if( /*(DebugHelper.DEBUGMODE & 2) == 0 &&*/ !link.IsCharted( Main.player[Main.myPlayer] ) ) { return; }
if( (WormholesMod.DEBUGMODE & 2) == 0 && !link.IsCharted( Main.player[Main.myPlayer] ) ) { return; }
float scale = Main.mapOverlayScale / 1.5f;

Rectangle l_rect = new Rectangle( (int)link.LeftPortal.Pos.X, (int)link.LeftPortal.Pos.Y, this.Tex.Width, this.Tex.Height );
Expand All @@ -63,7 +63,7 @@ public void DrawOverlayMap( WormholeLink link, SpriteBatch sb ) {
}

public void DrawFullscreenMap( WormholeLink link, SpriteBatch sb ) {
if( /*(DebugHelper.DEBUGMODE & 2) == 0 &&*/ !link.IsCharted( Main.player[Main.myPlayer] ) ) { return; }
if( (WormholesMod.DEBUGMODE & 2) == 0 && !link.IsCharted( Main.player[Main.myPlayer] ) ) { return; }
float scale = Main.mapFullscreenScale / 1.5f;

Rectangle l_rect = new Rectangle( (int)link.LeftPortal.Pos.X, (int)link.LeftPortal.Pos.Y, this.Tex.Width, this.Tex.Height );
Expand Down
Loading

0 comments on commit bd37e57

Please sign in to comment.