protected virtual WormNode CreateNextCrystalCaveKeyNode(WormSystemGen wormSys, int radius, int nodeSpacing) { int tests = 14; int tilePadding = 8; WormNode currNode = this.KeyNodes[this.KeyNodes.Count - 1]; var testNodes = this.CreateTestNodes(tests, radius, nodeSpacing, currNode); WormNode bestNode = null; float prevGauged = -1f; foreach (WormNode testNode in testNodes) { float gauged = this.GaugeCrystalCaveNode(wormSys, testNode, currNode, tilePadding); if (prevGauged != -1 && gauged > prevGauged) { continue; } prevGauged = gauged; bestNode = testNode; } return(bestNode); }
//////////////// public override void PostPaintTile(WormNode node, int i, int j) { //if( this.KeyNodes[0] == node ) { // return; //} Main.tile[i, j].liquid = 255; Main.tile[i, j].liquidType(0); }
//////////////// public WormNode FindBestBottomNode() { int leftMostX = Main.maxTilesX - 1; int rightMostX = 0; int topMostY = Main.maxTilesY - 1; int bottomMostY = 0; foreach (WormNode node in this.Nodes) { if (node.TileX > rightMostX) { rightMostX = node.TileX; } if (node.TileX < leftMostX) { leftMostX = node.TileX; } if (node.TileY < topMostY) { topMostY = node.TileY; } if (node.TileY > bottomMostY) { bottomMostY = node.TileY; } } WormNode bestNode = null; float bestValue = 0f; float rangeX = rightMostX - leftMostX; float rangeY = bottomMostY - topMostY; foreach (WormNode node in this.Nodes) { float percX = (float)(node.TileX - leftMostX) / rangeX; float percMidX = 0.5f - Math.Abs(0.5f - percX); percMidX *= 2f; float percY = (float)(node.TileY - topMostY) / rangeY; float value = percMidX + (percY * 2f); value += Math.Min((float)node.TileRadius / (float)CrystalCaveGen.MaxNormalRadius, 1f); if (value > bestValue) { bestValue = value; bestNode = node; } } return(bestNode); }
//////////////// protected virtual IList <WormNode> CreateTestNodes(int count, int radius, int nodeSpacing, WormNode currNode) { var testNodes = new List <WormNode>(count); for (int i = 0; i < count; i++) { WormNode testNode = this.CreateTestNode(currNode, radius, nodeSpacing); testNodes.Add(testNode); } return(testNodes); }
//////////////// protected CrystalCavePuddleGen(WormNode sourceNode, int tileX, int tileY, int length, IList <WormGen> forks) : base( tileX: tileX, tileY: tileY, length: length, forks: forks, minRadius: sourceNode.TileRadius * 2, maxRadius: (sourceNode.TileRadius * 2) + 1, starterNodeCount: 0, finisherNodeCount: length ) { this.SourceNode = sourceNode; }
protected override WormNode CreateKeyNode(WormSystemGen wormSys) { this.CalculateNextRadiusAndNodeSpacing(out int radius, out int nodeSpacing); WormNode newNode; if (this.KeyNodes.Count == 0) { newNode = new WormNode(this.OriginTileX, this.OriginTileY, radius, nodeSpacing, this); } else { newNode = this.CreateNextCrystalCaveKeyNode(wormSys, radius, nodeSpacing); } return(newNode); }
//////////////// protected override bool PostProcessNodes( GenerationProgress progress, float postProcessProgress, out ISet <WormGen> newWorms) { WormNode bottomNode = this.FindBestBottomNode(); newWorms = new HashSet <WormGen> { CrystalCavePuddleGen.Create( tileX: bottomNode.TileX, tileY: bottomNode.TileY, length: CrystalCaveSystemGen.PuddleLength, forkCount: WorldGen.genRand.Next(2, 4), sourceNode: bottomNode ) }; return(true); }
//////////////// protected override float GaugeCrystalCaveNode( WormSystemGen wormSys, WormNode testNode, WormNode prevNode, float tilePadding) { float gauged = base.GaugeCrystalCaveNode(wormSys, testNode, prevNode, tilePadding); // downward is best float vertGauge = (testNode.TileY - prevNode.TileY) > 0f ? 0 : 100000f; // closest to center is best float horizGauge = Math.Abs(prevNode.TileX - testNode.TileX); horizGauge *= 10; return(gauged + vertGauge + horizGauge); }
//////////////// protected virtual float GaugeCrystalCaveNode( WormSystemGen wormSys, WormNode testNode, WormNode prevNode, float tilePadding) { float gauged = 0f; foreach (WormNode existingNode in wormSys) { float value = (float)existingNode.GetDistance(testNode); value -= existingNode.TileRadius + testNode.TileRadius + tilePadding; if (value < 0f) { value = 100000 - value; // too close penalty } gauged += value; } return(gauged / (float)wormSys.NodeCount); }
public static CrystalCavePuddleGen Create( WormNode sourceNode, int tileX, int tileY, int length, int forkCount = 0) { var randForks = new List <WormGen>(forkCount); for (int i = 0; i < forkCount; i++) { int randLen = WorldGen.genRand.Next( Math.Max(length / 2, 3), Math.Max(length, 4) ); var fork = CrystalCaveGen.Create(0, 0, randLen, 0); randForks.Add(fork); } return(new CrystalCavePuddleGen(sourceNode, tileX, tileY, length, randForks)); }