private void CalcShrunkPlots(List <ShrunkPlot> shrunkPlotList, int roadDirection, int townId) { if (plotLeft != null && plotLeft.currentLength >= plotLeft.maxLength) //we are at the end { plotLeft = null; } if (plotRight != null && plotRight.currentLength >= plotRight.maxLength) //we are at the start { plotRight = null; } if (plotLeft == null) { plotLeft = new ShrunkPlot(plotNum, AngleStuff.RotateDirection(roadDirection, 2), townId); plotNum++; shrunkPlotList.Add(plotLeft); } if (plotRight == null) { plotRight = new ShrunkPlot(plotNum, AngleStuff.RotateDirection(roadDirection, -2), townId); plotNum++; shrunkPlotList.Add(plotRight); } plotLeft.currentLength++; plotRight.currentLength++; }
private void AddCornerPoints(int depth, ShrunkPlot shrunkPlot, Point newPoint) { if (shrunkPlot.isFirst) { shrunkPlot.isFirst = false; shrunkPlot.AddPointOne(newPoint); } shrunkPlot.AddPointTwo(newPoint); }
private bool AddPlot(Point expansionPoint, int direction, ShrunkPlot plot, ShrunkNode[,] shrunkMap) { Point nextPoint = expansionPoint; for (int depth = 1; depth <= plot.maxDepth; depth++) { nextPoint = AngleStuff.AddPointToDirection(nextPoint, direction); if (ShrunkWorldBuilder.PointLegit(nextPoint) && CheckIfLandType(nextPoint, shrunkMap, LandType.OPEN)) { AddCornerPoints(depth, plot, nextPoint); shrunkMap[nextPoint.X, nextPoint.Y].SetLandType(LandType.PLOT); } else { if (depth < 3) { return(false); } } } return(true); }
private void LayRoadStretch(Point expansionPoint, int directionToTravel, int distanceToTravel, int townId, List <ConnectingPoint> connectingPointList, ShrunkNode[,] shrunkMap, List <ShrunkPlot> shrunkPlotList) { int depth = GameController.rnd.Next(minRandomPlotDepth, maxRandomPlotDepth); bool addConnectingPoint = false; bool forceThroughPlot = false; for (int roadDistance = 0; roadDistance < distanceToTravel; roadDistance++) { CalcShrunkPlots(shrunkPlotList, directionToTravel, townId); expansionPoint = AngleStuff.AddPointToDirection(expansionPoint, directionToTravel); if (CheckIfLandType(expansionPoint, shrunkMap, LandType.OPEN) || forceThroughPlot) { TurnIntoRoad(expansionPoint, townId, shrunkMap, shrunkPlotList); if (roadDistance != distanceToTravel - 1) //We are not at our last piece { if (!AddPlot(expansionPoint, AngleStuff.RotateDirection(directionToTravel, -2), plotLeft, shrunkMap)) { plotLeft = null; } if (!AddPlot(expansionPoint, AngleStuff.RotateDirection(directionToTravel, 2), plotRight, shrunkMap)) { plotRight = null; } } if (IsMoreThanTwoNeighbours(expansionPoint, shrunkMap)) { addConnectingPoint = false; break; } } else { roadDistance = distanceToTravel - 1; } if (roadDistance > 4) { addConnectingPoint = true; } if (roadDistance == distanceToTravel - 1 && !forceThroughPlot) { int amount = ExtraToReachRoad(shrunkMap, directionToTravel, expansionPoint); if (amount > 0) { TurnIntoRoad(expansionPoint, townId, shrunkMap, shrunkPlotList); distanceToTravel += amount; forceThroughPlot = true; } } //Do we add to road distance //We also check at the end and do the smooth thing } plotLeft = null; plotRight = null; if (addConnectingPoint) { AddConnectingPoint(expansionPoint, directionToTravel, connectingPointList, shrunkMap); } }