public override void GenerateWhereAppropriate() { WorldGrid worldGrid = Find.WorldGrid; int tilesCount = worldGrid.TilesCount; edgeTiles.Clear(); for (int i = 0; i < tilesCount; i++) { if (IsRoot(i)) { edgeTiles.Add(i); } } if (edgeTiles.Any()) { group.Clear(); Find.WorldFloodFiller.FloodFill(-1, (int x) => CanTraverse(x), delegate(int tile, int traversalDist) { group.Add(tile); return(false); }, int.MaxValue, edgeTiles); group.RemoveAll((int x) => worldGrid[x].feature != null); if (group.Count >= def.minSize && group.Count <= def.maxSize) { AddFeature(group, group); } } }
private void GenerateLakes() { WorldGrid grid = Find.WorldGrid; bool[] touched = new bool[grid.TilesCount]; List <int> oceanChunk = new List <int>(); for (int i = 0; i < grid.TilesCount; i++) { if (!touched[i]) { if (grid[i].biome == BiomeDefOf.Ocean) { Find.WorldFloodFiller.FloodFill(i, (int tid) => grid[tid].biome == BiomeDefOf.Ocean, delegate(int tid) { oceanChunk.Add(tid); touched[tid] = true; }, 2147483647, null); if (oceanChunk.Count <= 15) { for (int j = 0; j < oceanChunk.Count; j++) { grid[oceanChunk[j]].biome = BiomeDefOf.Lake; } } oceanChunk.Clear(); } } } }
public void DrawPath(Caravan pathingCaravan) { if (!Found || NodesLeftCount <= 0) { return; } WorldGrid worldGrid = Find.WorldGrid; float d = 0.05f; for (int i = 0; i < NodesLeftCount - 1; i++) { Vector3 tileCenter = worldGrid.GetTileCenter(Peek(i)); Vector3 tileCenter2 = worldGrid.GetTileCenter(Peek(i + 1)); tileCenter += tileCenter.normalized * d; tileCenter2 += tileCenter2.normalized * d; GenDraw.DrawWorldLineBetween(tileCenter, tileCenter2); } if (pathingCaravan != null) { Vector3 drawPos = pathingCaravan.DrawPos; Vector3 tileCenter3 = worldGrid.GetTileCenter(Peek(0)); drawPos += drawPos.normalized * d; tileCenter3 += tileCenter3.normalized * d; if ((drawPos - tileCenter3).sqrMagnitude > 0.005f) { GenDraw.DrawWorldLineBetween(drawPos, tileCenter3); } } }
private static int FindRandomStartingTileBasedOnExitDir(int tileID, Direction8Way exitDir) { CaravanExitMapUtility.tileCandidates.Clear(); World world = Find.World; WorldGrid grid = world.grid; grid.GetTileNeighbors(tileID, CaravanExitMapUtility.tmpNeighbors); for (int i = 0; i < CaravanExitMapUtility.tmpNeighbors.Count; i++) { int num = CaravanExitMapUtility.tmpNeighbors[i]; if (CaravanExitMapUtility.IsGoodCaravanStartingTile(num)) { if (grid.GetDirection8WayFromTo(tileID, num) == exitDir) { CaravanExitMapUtility.tileCandidates.Add(num); } } } int result; if (CaravanExitMapUtility.tileCandidates.TryRandomElement(out result)) { return(result); } if (CaravanExitMapUtility.tmpNeighbors.Where(new Func <int, bool>(CaravanExitMapUtility.IsGoodCaravanStartingTile)).TryRandomElement(out result)) { return(result); } return(tileID); }
public void DrawPath(Caravan pathingCaravan) { if (!this.Found) { return; } if (this.NodesLeftCount > 0) { WorldGrid worldGrid = Find.WorldGrid; float d = 0.05f; for (int i = 0; i < this.NodesLeftCount - 1; i++) { Vector3 a = worldGrid.GetTileCenter(this.Peek(i)); Vector3 vector = worldGrid.GetTileCenter(this.Peek(i + 1)); a += a.normalized * d; vector += vector.normalized * d; GenDraw.DrawWorldLineBetween(a, vector); } if (pathingCaravan != null) { Vector3 a2 = pathingCaravan.DrawPos; Vector3 vector2 = worldGrid.GetTileCenter(this.Peek(0)); a2 += a2.normalized * d; vector2 += vector2.normalized * d; if ((a2 - vector2).sqrMagnitude > 0.005f) { GenDraw.DrawWorldLineBetween(a2, vector2); } } } }
public static void GetExitMapEdges(WorldGrid grid, int fromTileID, int toTileID, out Rot4 primary, out Rot4 secondary) { primary = (secondary = Rot4.Invalid); int num = 0; float heading = grid.GetHeadingFromTo(fromTileID, toTileID); if (heading >= 292.5f || heading <= 67.5f) { rotTmp[num++] = Rot4.North; } else if (heading >= 112.5f && heading <= 247.5f) { rotTmp[num++] = Rot4.South; } if (heading >= 22.5f && heading <= 157.5f) { rotTmp[num++] = Rot4.East; } else if (heading >= 202.5f && heading <= 337.5f) { rotTmp[num++] = Rot4.West; } Array.Sort(rotTmp, (Rot4 r1, Rot4 r2) => Mathf.Abs(r1.AsAngle - heading).CompareTo(Mathf.Abs(r2.AsAngle - heading))); if (num >= 1) { primary = rotTmp[0]; } if (num >= 2) { secondary = rotTmp[1]; } }
public override void GenerateWhereAppropriate() { WorldGrid worldGrid = Find.WorldGrid; int tilesCount = worldGrid.TilesCount; this.edgeTiles.Clear(); for (int i = 0; i < tilesCount; i++) { if (this.IsRoot(i)) { this.edgeTiles.Add(i); } } if (this.edgeTiles.Any <int>()) { this.group.Clear(); WorldFloodFiller worldFloodFiller = Find.WorldFloodFiller; int rootTile = -1; Predicate <int> passCheck = (int x) => this.CanTraverse(x); Func <int, int, bool> processor = delegate(int tile, int traversalDist) { this.group.Add(tile); return(false); }; List <int> extraRootTiles = this.edgeTiles; worldFloodFiller.FloodFill(rootTile, passCheck, processor, int.MaxValue, extraRootTiles); this.group.RemoveAll((int x) => worldGrid[x].feature != null); if (this.group.Count >= this.def.minSize && this.group.Count <= this.def.maxSize) { base.AddFeature(this.group, this.group); } } }
public override void GenerateWhereAppropriate() { WorldGrid worldGrid = Find.WorldGrid; int tilesCount = worldGrid.TilesCount; edgeTiles.Clear(); for (int i = 0; i < tilesCount; i++) { if (IsRoot(i)) { edgeTiles.Add(i); } } if (edgeTiles.Any()) { group.Clear(); WorldFloodFiller worldFloodFiller = Find.WorldFloodFiller; int rootTile = -1; Predicate <int> passCheck = (int x) => CanTraverse(x); Func <int, int, bool> processor = delegate(int tile, int traversalDist) { group.Add(tile); return(false); }; List <int> extraRootTiles = edgeTiles; worldFloodFiller.FloodFill(rootTile, passCheck, processor, 2147483647, extraRootTiles); group.RemoveAll((int x) => worldGrid[x].feature != null); if (group.Count >= def.minSize && group.Count <= def.maxSize) { AddFeature(group, group); } } }
public void RenderMote() { float num = (Time.time - this.lastOrderedToTileTime) / 0.5f; if (num > 1f) { return; } if (Caravan_GotoMoteRenderer.cachedMaterial == null) { Caravan_GotoMoteRenderer.cachedMaterial = MaterialPool.MatFrom((Texture2D)Caravan_GotoMoteRenderer.FeedbackGoto.mainTexture, Caravan_GotoMoteRenderer.FeedbackGoto.shader, Color.white, WorldMaterials.DynamicObjectRenderQueue); } WorldGrid worldGrid = Find.WorldGrid; Vector3 tileCenter = worldGrid.GetTileCenter(this.tile); Color value = new Color(1f, 1f, 1f, 1f - num); Caravan_GotoMoteRenderer.propertyBlock.SetColor(ShaderPropertyIDs.Color, value); Vector3 pos = tileCenter; float size = 0.8f * worldGrid.averageTileSize; float altOffset = 0.018f; Material material = Caravan_GotoMoteRenderer.cachedMaterial; MaterialPropertyBlock materialPropertyBlock = Caravan_GotoMoteRenderer.propertyBlock; WorldRendererUtility.DrawQuadTangentialToPlanet(pos, size, altOffset, material, false, false, materialPropertyBlock); }
public static Vector3 PatherTweenedPosRoot(Caravan caravan) { WorldGrid worldGrid = Find.WorldGrid; if (!caravan.Spawned) { return(worldGrid.GetTileCenter(caravan.Tile)); } if (caravan.pather.Moving) { float num; if (!caravan.pather.IsNextTilePassable()) { num = 0f; } else { num = 1f - caravan.pather.nextTileCostLeft / caravan.pather.nextTileCostTotal; } int tileID; if (caravan.pather.nextTile == caravan.Tile && caravan.pather.previousTileForDrawingIfInDoubt != -1) { tileID = caravan.pather.previousTileForDrawingIfInDoubt; } else { tileID = caravan.Tile; } return(worldGrid.GetTileCenter(caravan.pather.nextTile) * num + worldGrid.GetTileCenter(tileID) * (1f - num)); } return(worldGrid.GetTileCenter(caravan.Tile)); }
private static int FindRandomStartingTileBasedOnExitDir(int tileID, Direction8Way exitDir) { tileCandidates.Clear(); World world = Find.World; WorldGrid grid = world.grid; grid.GetTileNeighbors(tileID, tmpNeighbors); for (int i = 0; i < tmpNeighbors.Count; i++) { int num = tmpNeighbors[i]; if (IsGoodCaravanStartingTile(num) && grid.GetDirection8WayFromTo(tileID, num) == exitDir) { tileCandidates.Add(num); } } if (tileCandidates.TryRandomElement(out int result)) { return(result); } if (tmpNeighbors.Where(IsGoodCaravanStartingTile).TryRandomElement(out result)) { return(result); } return(tileID); }
public override IEnumerable Regenerate() { foreach (object result in base.Regenerate()) { yield return(result); } World world = Find.World; WorldGrid grid = world.grid; int tilesCount = grid.TilesCount; List <Tile> tiles = grid.tiles; List <int> tileIDToVerts_offsets = grid.tileIDToVerts_offsets; List <Vector3> verts = grid.verts; this.triangleIndexToTileID.Clear(); foreach (object result2 in this.CalculateInterpolatedVerticesParams()) { yield return(result2); } int colorsAndUVsIndex = 0; for (int i = 0; i < tilesCount; i++) { Tile tile = tiles[i]; BiomeDef biome = tile.biome; int j; LayerSubMesh subMesh = base.GetSubMesh(biome.DrawMaterial, out j); while (j >= this.triangleIndexToTileID.Count) { this.triangleIndexToTileID.Add(new List <int>()); } int count = subMesh.verts.Count; int num = 0; int num2 = (i + 1 >= tileIDToVerts_offsets.Count) ? verts.Count : tileIDToVerts_offsets[i + 1]; for (int k = tileIDToVerts_offsets[i]; k < num2; k++) { subMesh.verts.Add(verts[k]); subMesh.uvs.Add(this.elevationValues[colorsAndUVsIndex]); colorsAndUVsIndex++; if (k < num2 - 2) { subMesh.tris.Add(count + num + 2); subMesh.tris.Add(count + num + 1); subMesh.tris.Add(count); this.triangleIndexToTileID[j].Add(i); } num++; } } base.FinalizeMesh(MeshParts.All); foreach (object result3 in this.RegenerateMeshColliders()) { yield return(result3); } this.elevationValues.Clear(); this.elevationValues.TrimExcess(); }
public void FlashLine(int tileA, int tileB, int duration = 50) { WorldGrid worldGrid = Find.WorldGrid; Vector3 tileCenter = worldGrid.GetTileCenter(tileA); Vector3 tileCenter2 = worldGrid.GetTileCenter(tileB); DebugWorldLine debugWorldLine = new DebugWorldLine(tileCenter, tileCenter2, true); debugWorldLine.TicksLeft = duration; this.debugLines.Add(debugWorldLine); }
private bool IsRoot(int tile) { WorldGrid worldGrid = Find.WorldGrid; if (worldGrid.IsOnEdge(tile) && CanTraverse(tile)) { return(worldGrid[tile].feature == null); } return(false); }
public static void Erode(List <int> tiles, int count, Predicate <int> extraPredicate = null) { if (count <= 0) { return; } WorldGrid worldGrid = Find.WorldGrid; GenPlanetMorphology.tilesSet.Clear(); GenPlanetMorphology.tilesSet.AddRange(tiles); GenPlanetMorphology.tmpEdgeTiles.Clear(); for (int i = 0; i < tiles.Count; i++) { worldGrid.GetTileNeighbors(tiles[i], GenPlanetMorphology.tmpNeighbors); for (int j = 0; j < GenPlanetMorphology.tmpNeighbors.Count; j++) { if (!GenPlanetMorphology.tilesSet.Contains(GenPlanetMorphology.tmpNeighbors[j])) { GenPlanetMorphology.tmpEdgeTiles.Add(tiles[i]); break; } } } if (!GenPlanetMorphology.tmpEdgeTiles.Any <int>()) { return; } GenPlanetMorphology.tmpOutput.Clear(); Predicate <int> predicate; if (extraPredicate != null) { predicate = ((int x) => GenPlanetMorphology.tilesSet.Contains(x) && extraPredicate(x)); } else { predicate = ((int x) => GenPlanetMorphology.tilesSet.Contains(x)); } WorldFloodFiller arg_13F_0 = Find.WorldFloodFiller; int rootTile = -1; Predicate <int> passCheck = predicate; Func <int, int, bool> processor = delegate(int tile, int traversalDist) { if (traversalDist >= count) { GenPlanetMorphology.tmpOutput.Add(tile); } return(false); }; List <int> extraRootTiles = GenPlanetMorphology.tmpEdgeTiles; arg_13F_0.FloodFill(rootTile, passCheck, processor, 2147483647, extraRootTiles); tiles.Clear(); tiles.AddRange(GenPlanetMorphology.tmpOutput); }
public override IEnumerable Regenerate() { foreach (object result in base.Regenerate()) { yield return(result); } Rand.PushState(); Rand.Seed = Find.World.info.Seed; WorldGrid grid = Find.WorldGrid; int tilesCount = grid.TilesCount; int i = 0; while (i < tilesCount) { Tile tile = grid[i]; Material material; FloatRange floatRange; switch (tile.hilliness) { case Hilliness.SmallHills: material = WorldMaterials.SmallHills; floatRange = WorldLayer_Hills.BasePosOffsetRange_SmallHills; goto IL_180; case Hilliness.LargeHills: material = WorldMaterials.LargeHills; floatRange = WorldLayer_Hills.BasePosOffsetRange_LargeHills; goto IL_180; case Hilliness.Mountainous: material = WorldMaterials.Mountains; floatRange = WorldLayer_Hills.BasePosOffsetRange_Mountains; goto IL_180; case Hilliness.Impassable: material = WorldMaterials.ImpassableMountains; floatRange = WorldLayer_Hills.BasePosOffsetRange_ImpassableMountains; goto IL_180; } IL_25C: i++; continue; IL_180: LayerSubMesh subMesh = base.GetSubMesh(material); Vector3 vector = grid.GetTileCenter(i); Vector3 posForTangents = vector; float magnitude = vector.magnitude; vector = (vector + Rand.UnitVector3 * floatRange.RandomInRange * grid.averageTileSize).normalized * magnitude; WorldRendererUtility.PrintQuadTangentialToPlanet(vector, posForTangents, WorldLayer_Hills.BaseSizeRange.RandomInRange * grid.averageTileSize, 0.005f, subMesh, false, true, false); WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, WorldLayer_Hills.TexturesInAtlas.x), Rand.Range(0, WorldLayer_Hills.TexturesInAtlas.z), WorldLayer_Hills.TexturesInAtlas.x, WorldLayer_Hills.TexturesInAtlas.z, subMesh); goto IL_25C; } Rand.PopState(); base.FinalizeMesh(MeshParts.All); }
private static int FindRandomStartingTileBasedOnExitDir(int tileID, Rot4 exitDir) { CaravanExitMapUtility.tileCandidates.Clear(); World world = Find.World; WorldGrid grid = world.grid; grid.GetTileNeighbors(tileID, CaravanExitMapUtility.tmpNeighbors); for (int i = 0; i < CaravanExitMapUtility.tmpNeighbors.Count; i++) { int num = CaravanExitMapUtility.tmpNeighbors[i]; if (CaravanExitMapUtility.IsGoodCaravanStartingTile(num)) { if (!exitDir.IsValid || !(grid.GetRotFromTo(tileID, num) != exitDir)) { CaravanExitMapUtility.tileCandidates.Add(num); } } } int num2; int result; if (CaravanExitMapUtility.tileCandidates.TryRandomElement(out num2)) { result = num2; } else if (CaravanExitMapUtility.tmpNeighbors.Where(delegate(int x) { bool result2; if (!CaravanExitMapUtility.IsGoodCaravanStartingTile(x)) { result2 = false; } else { Rot4 rotFromTo = grid.GetRotFromTo(tileID, x); result2 = (((exitDir == Rot4.North || exitDir == Rot4.South) && (rotFromTo == Rot4.East || rotFromTo == Rot4.West)) || ((exitDir == Rot4.East || exitDir == Rot4.West) && (rotFromTo == Rot4.North || rotFromTo == Rot4.South))); } return(result2); }).TryRandomElement(out num2)) { result = num2; } else if ((from x in CaravanExitMapUtility.tmpNeighbors where CaravanExitMapUtility.IsGoodCaravanStartingTile(x) select x).TryRandomElement(out num2)) { result = num2; } else { result = tileID; } return(result); }
public override IEnumerable Regenerate() { foreach (object item in base.Regenerate()) { yield return(item); } WorldGrid grid = Find.World.grid; int tilesCount = grid.TilesCount; List <Tile> tiles = grid.tiles; List <int> tileIDToVerts_offsets = grid.tileIDToVerts_offsets; List <Vector3> verts = grid.verts; triangleIndexToTileID.Clear(); foreach (object item2 in CalculateInterpolatedVerticesParams()) { yield return(item2); } int num = 0; for (int i = 0; i < tilesCount; i++) { BiomeDef biome = tiles[i].biome; int subMeshIndex; LayerSubMesh subMesh = GetSubMesh(biome.DrawMaterial, out subMeshIndex); while (subMeshIndex >= triangleIndexToTileID.Count) { triangleIndexToTileID.Add(new List <int>()); } int count = subMesh.verts.Count; int num2 = 0; int num3 = ((i + 1 < tileIDToVerts_offsets.Count) ? tileIDToVerts_offsets[i + 1] : verts.Count); for (int j = tileIDToVerts_offsets[i]; j < num3; j++) { subMesh.verts.Add(verts[j]); subMesh.uvs.Add(elevationValues[num]); num++; if (j < num3 - 2) { subMesh.tris.Add(count + num2 + 2); subMesh.tris.Add(count + num2 + 1); subMesh.tris.Add(count); triangleIndexToTileID[subMeshIndex].Add(i); } num2++; } } FinalizeMesh(MeshParts.All); foreach (object item3 in RegenerateMeshColliders()) { yield return(item3); } elevationValues.Clear(); elevationValues.TrimExcess(); }
public override IEnumerable Regenerate() { foreach (object item2 in base.Regenerate()) { yield return(item2); } LayerSubMesh subMesh = GetSubMesh(WorldMaterials.Rivers); LayerSubMesh subMeshBorder = GetSubMesh(WorldMaterials.RiversBorder); WorldGrid grid = Find.WorldGrid; List <OutputDirection> outputs = new List <OutputDirection>(); List <OutputDirection> outputsBorder = new List <OutputDirection>(); int i = 0; while (i < grid.TilesCount) { if (i % 1000 == 0) { yield return(null); } if (subMesh.verts.Count > 60000) { subMesh = GetSubMesh(WorldMaterials.Rivers); subMeshBorder = GetSubMesh(WorldMaterials.RiversBorder); } Tile tile = grid[i]; if (tile.potentialRivers != null) { outputs.Clear(); outputsBorder.Clear(); for (int j = 0; j < tile.potentialRivers.Count; j++) { OutputDirection item = new OutputDirection { neighbor = tile.potentialRivers[j].neighbor, width = tile.potentialRivers[j].river.widthOnWorld - 0.2f }; outputs.Add(item); item = new OutputDirection { neighbor = tile.potentialRivers[j].neighbor, width = tile.potentialRivers[j].river.widthOnWorld }; outputsBorder.Add(item); } GeneratePaths(subMesh, i, outputs, riverColor, allowSmoothTransition: true); GeneratePaths(subMeshBorder, i, outputsBorder, riverColor, allowSmoothTransition: true); } int num = i + 1; i = num; } FinalizeMesh(MeshParts.All); }
public bool AnySettlementBaseAtOrAdjacent(int tile) { WorldGrid worldGrid = Find.WorldGrid; for (int i = 0; i < settlementBases.Count; i++) { if (worldGrid.IsNeighborOrSame(settlementBases[i].Tile, tile)) { return(true); } } return(false); }
public override IEnumerable Regenerate() { foreach (object item in base.Regenerate()) { yield return(item); } Rand.PushState(); Rand.Seed = Find.World.info.Seed; WorldGrid worldGrid = Find.WorldGrid; int tilesCount = worldGrid.TilesCount; for (int i = 0; i < tilesCount; i++) { Material material; FloatRange floatRange; switch (worldGrid[i].hilliness) { case Hilliness.SmallHills: material = WorldMaterials.SmallHills; floatRange = BasePosOffsetRange_SmallHills; break; case Hilliness.LargeHills: material = WorldMaterials.LargeHills; floatRange = BasePosOffsetRange_LargeHills; break; case Hilliness.Mountainous: material = WorldMaterials.Mountains; floatRange = BasePosOffsetRange_Mountains; break; case Hilliness.Impassable: material = WorldMaterials.ImpassableMountains; floatRange = BasePosOffsetRange_ImpassableMountains; break; default: continue; } LayerSubMesh subMesh = GetSubMesh(material); Vector3 tileCenter = worldGrid.GetTileCenter(i); Vector3 posForTangents = tileCenter; float magnitude = tileCenter.magnitude; tileCenter = (tileCenter + Rand.UnitVector3 * floatRange.RandomInRange * worldGrid.averageTileSize).normalized * magnitude; WorldRendererUtility.PrintQuadTangentialToPlanet(tileCenter, posForTangents, BaseSizeRange.RandomInRange * worldGrid.averageTileSize, 0.005f, subMesh, counterClockwise: false, randomizeRotation: true, printUVs: false); WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, TexturesInAtlas.x), Rand.Range(0, TexturesInAtlas.z), TexturesInAtlas.x, TexturesInAtlas.z, subMesh); } Rand.PopState(); FinalizeMesh(MeshParts.All); }
public static Vector3 PatherTweenedPosRoot(Caravan caravan) { WorldGrid worldGrid = Find.WorldGrid; if (!caravan.Spawned) { return(worldGrid.GetTileCenter(caravan.Tile)); } if (caravan.pather.Moving) { float num = (float)(caravan.pather.IsNextTilePassable() ? (1.0 - caravan.pather.nextTileCostLeft / caravan.pather.nextTileCostTotal) : 0.0); return(worldGrid.GetTileCenter(caravan.pather.nextTile) * num + worldGrid.GetTileCenter(caravan.Tile) * (float)(1.0 - num)); } return(worldGrid.GetTileCenter(caravan.Tile)); }
public void ExposeData() { Scribe_Collections.Look(ref features, "features", LookMode.Deep); if (Scribe.mode == LoadSaveMode.PostLoadInit) { WorldGrid grid = Find.WorldGrid; if (grid.tileFeature != null && grid.tileFeature.Length != 0) { DataSerializeUtility.LoadUshort(grid.tileFeature, grid.TilesCount, delegate(int i, ushort data) { grid[i].feature = ((data != 65535) ? GetFeatureWithID(data) : null); }); } textsCreated = false; } }
public void ExposeData() { Scribe_Collections.Look <WorldFeature>(ref this.features, "features", LookMode.Deep, new object[0]); if (Scribe.mode == LoadSaveMode.PostLoadInit) { WorldGrid grid = Find.WorldGrid; if (grid.tileFeature != null && grid.tileFeature.Length != 0) { DataSerializeUtility.LoadUshort(grid.tileFeature, grid.TilesCount, delegate(int i, ushort data) { grid[i].feature = ((data != ushort.MaxValue) ? this.GetFeatureWithID((int)data) : null); }); } this.textsCreated = false; } }
public static Vector3 PatherTweenedPosRoot(Caravan caravan) { WorldGrid worldGrid = Find.WorldGrid; if (!caravan.Spawned) { return(worldGrid.GetTileCenter(caravan.Tile)); } if (caravan.pather.Moving) { float num = (caravan.pather.IsNextTilePassable() ? (1f - caravan.pather.nextTileCostLeft / caravan.pather.nextTileCostTotal) : 0f); int tileID = ((caravan.pather.nextTile != caravan.Tile || caravan.pather.previousTileForDrawingIfInDoubt == -1) ? caravan.Tile : caravan.pather.previousTileForDrawingIfInDoubt); return(worldGrid.GetTileCenter(caravan.pather.nextTile) * num + worldGrid.GetTileCenter(tileID) * (1f - num)); } return(worldGrid.GetTileCenter(caravan.Tile)); }
public override IEnumerable Regenerate() { foreach (object result in base.Regenerate()) { yield return(result); } LayerSubMesh subMesh = base.GetSubMesh(WorldMaterials.Rivers); LayerSubMesh subMeshBorder = base.GetSubMesh(WorldMaterials.RiversBorder); WorldGrid grid = Find.WorldGrid; List <WorldLayer_Paths.OutputDirection> outputs = new List <WorldLayer_Paths.OutputDirection>(); List <WorldLayer_Paths.OutputDirection> outputsBorder = new List <WorldLayer_Paths.OutputDirection>(); for (int i = 0; i < grid.TilesCount; i++) { if (i % 1000 == 0) { yield return(null); } if (subMesh.verts.Count > 60000) { subMesh = base.GetSubMesh(WorldMaterials.Rivers); subMeshBorder = base.GetSubMesh(WorldMaterials.RiversBorder); } Tile tile = grid[i]; if (tile.potentialRivers != null) { outputs.Clear(); outputsBorder.Clear(); for (int j = 0; j < tile.potentialRivers.Count; j++) { outputs.Add(new WorldLayer_Paths.OutputDirection { neighbor = tile.potentialRivers[j].neighbor, width = tile.potentialRivers[j].river.widthOnWorld - 0.2f }); outputsBorder.Add(new WorldLayer_Paths.OutputDirection { neighbor = tile.potentialRivers[j].neighbor, width = tile.potentialRivers[j].river.widthOnWorld }); } base.GeneratePaths(subMesh, i, outputs, this.riverColor, true); base.GeneratePaths(subMeshBorder, i, outputsBorder, this.riverColor, true); } } base.FinalizeMesh(MeshParts.All); }
public void RenderMote() { float num = (Time.time - lastOrderedToTileTime) / 0.5f; if (!(num > 1f)) { if (cachedMaterial == null) { cachedMaterial = MaterialPool.MatFrom((Texture2D)FeedbackGoto.mainTexture, FeedbackGoto.shader, Color.white, WorldMaterials.DynamicObjectRenderQueue); } WorldGrid worldGrid = Find.WorldGrid; Vector3 tileCenter = worldGrid.GetTileCenter(tile); Color value = new Color(1f, 1f, 1f, 1f - num); propertyBlock.SetColor(ShaderPropertyIDs.Color, value); WorldRendererUtility.DrawQuadTangentialToPlanet(tileCenter, 0.8f * worldGrid.averageTileSize, 0.018f, cachedMaterial, counterClockwise: false, useSkyboxLayer: false, propertyBlock); } }
public static void Erode(List <int> tiles, int count, Predicate <int> extraPredicate = null) { if (count > 0) { WorldGrid worldGrid = Find.WorldGrid; GenPlanetMorphology.tilesSet.Clear(); GenPlanetMorphology.tilesSet.AddRange(tiles); GenPlanetMorphology.tmpEdgeTiles.Clear(); for (int i = 0; i < tiles.Count; i++) { worldGrid.GetTileNeighbors(tiles[i], GenPlanetMorphology.tmpNeighbors); int num = 0; while (num < GenPlanetMorphology.tmpNeighbors.Count) { if (GenPlanetMorphology.tilesSet.Contains(GenPlanetMorphology.tmpNeighbors[num])) { num++; continue; } GenPlanetMorphology.tmpEdgeTiles.Add(tiles[i]); break; } } if (GenPlanetMorphology.tmpEdgeTiles.Any()) { GenPlanetMorphology.tmpOutput.Clear(); Predicate <int> predicate = (extraPredicate == null) ? ((Predicate <int>)((int x) => GenPlanetMorphology.tilesSet.Contains(x))) : ((Predicate <int>)((int x) => GenPlanetMorphology.tilesSet.Contains(x) && extraPredicate(x))); WorldFloodFiller worldFloodFiller = Find.WorldFloodFiller; int rootTile = -1; Predicate <int> passCheck = predicate; Func <int, int, bool> processor = delegate(int tile, int traversalDist) { if (traversalDist >= count) { GenPlanetMorphology.tmpOutput.Add(tile); } return(false); }; List <int> extraRootTiles = GenPlanetMorphology.tmpEdgeTiles; worldFloodFiller.FloodFill(rootTile, passCheck, processor, 2147483647, extraRootTiles); tiles.Clear(); tiles.AddRange(GenPlanetMorphology.tmpOutput); } } }
private void CreateTextsAndSetPosition() { this.CreateOrDestroyTexts(); WorldGrid worldGrid = Find.WorldGrid; float averageTileSize = worldGrid.averageTileSize; for (int i = 0; i < this.features.Count; i++) { WorldFeatures.texts[i].Text = this.features[i].name.WordWrapAt(WorldFeatures.TextWrapThreshold); WorldFeatures.texts[i].Size = this.features[i].EffectiveDrawSize * averageTileSize; Vector3 normalized = this.features[i].drawCenter.normalized; Quaternion quaternion = Quaternion.LookRotation(Vector3.Cross(normalized, Vector3.up), normalized); quaternion *= Quaternion.Euler(Vector3.right * 90f); quaternion *= Quaternion.Euler(Vector3.forward * (90f - this.features[i].drawAngle)); WorldFeatures.texts[i].Rotation = quaternion; WorldFeatures.texts[i].LocalPosition = this.features[i].drawCenter; WorldFeatures.texts[i].WrapAroundPlanetSurface(); WorldFeatures.texts[i].SetActive(false); } }
private void CreateTextsAndSetPosition() { this.CreateOrDestroyTexts(); WorldGrid worldGrid = Find.WorldGrid; float averageTileSize = worldGrid.averageTileSize; for (int i = 0; i < this.features.Count; i++) { WorldFeatures.texts[i].text = this.features[i].name; WorldFeatures.texts[i].rectTransform.sizeDelta = new Vector2(this.features[i].maxDrawSizeInTiles.x * averageTileSize, this.features[i].maxDrawSizeInTiles.y * averageTileSize); Vector3 normalized = this.features[i].drawCenter.normalized; Quaternion quaternion = Quaternion.LookRotation(Vector3.Cross(normalized, Vector3.up), normalized); quaternion *= Quaternion.Euler(Vector3.right * 90f); quaternion *= Quaternion.Euler(Vector3.forward * (90f - this.features[i].drawAngle)); WorldFeatures.texts[i].transform.rotation = quaternion; WorldFeatures.texts[i].transform.localPosition = this.features[i].drawCenter; this.WrapAroundPlanetSurface(WorldFeatures.texts[i]); WorldFeatures.texts[i].gameObject.SetActive(false); } }