Пример #1
0
        /*
         * Build the road and move the construction site
         */
        public bool finishWork(Caravan caravan = null)
        {
            RoadConstructionSite parentSite = this.parent as RoadConstructionSite;
            int  fromTile_int = parentSite.Tile;
            int  toTile_int   = parentSite.GetNextLeg().Tile;
            Tile fromTile     = Find.WorldGrid[fromTile_int];
            Tile toTile       = Find.WorldGrid[toTile_int];

            // Remove lesser roads, they don't deserve to live
            if (fromTile.potentialRoads != null)
            {
                foreach (Tile.RoadLink aLink in fromTile.potentialRoads.ToArray())
                {
                    if (aLink.neighbor == toTile_int & RoadsOfTheRim.isRoadBetter(parentSite.roadDef, aLink.road))
                    {
                        fromTile.potentialRoads.Remove(aLink);
                    }
                }
            }
            else
            {
                fromTile.potentialRoads = new List <Tile.RoadLink>();
            }

            if (toTile.potentialRoads != null)
            {
                foreach (Tile.RoadLink aLink in toTile.potentialRoads.ToArray())
                {
                    if (aLink.neighbor == parentSite.Tile & RoadsOfTheRim.isRoadBetter(parentSite.roadDef, aLink.road))
                    {
                        toTile.potentialRoads.Remove(aLink);
                    }
                }
            }
            else
            {
                toTile.potentialRoads = new List <Tile.RoadLink>();
            }

            // Add the road to fromTile & toTile
            fromTile.potentialRoads.Add(new Tile.RoadLink {
                neighbor = toTile_int, road = parentSite.roadDef
            });
            toTile.potentialRoads.Add(new Tile.RoadLink {
                neighbor = fromTile_int, road = parentSite.roadDef
            });
            try
            {
                Find.World.renderer.SetDirty <WorldLayer_Roads>();
                Find.World.renderer.SetDirty <WorldLayer_Paths>();
                Find.WorldPathGrid.RecalculatePerceivedMovementDifficultyAt(fromTile_int);
                Find.WorldPathGrid.RecalculatePerceivedMovementDifficultyAt(toTile_int);
            }
            catch (Exception e)
            {
                RoadsOfTheRim.DebugLog("[RotR] Exception : ", e);
            }

            // The Construction site and the caravan can move to the next leg
            RoadConstructionLeg nextLeg = parentSite.GetNextLeg();

            if (nextLeg != null)
            {
                int CurrentTile = parentSite.Tile;
                parentSite.Tile = nextLeg.Tile;
                RoadConstructionLeg nextNextLeg = nextLeg.Next;
                // TO DO Here : Check if there's an existing road that is the same or better as the one being built. If there is, skip the next leg
                if (nextNextLeg != null)
                {
                    nextNextLeg.Previous = null;
                    setCosts();
                    parentSite.MoveWorkersToNextLeg(CurrentTile); // Move any caravans working on this site to the next leg, and delay faction help if any
                }
                else
                {
                    EndConstruction(caravan);  // We have built the last leg. Notify & remove the site
                }
                Find.World.worldObjects.Remove(nextLeg);
            }

            return(true);
        }