Exemple #1
0
        /*
         * Remove all legs up to and including the one passed in argument
         */
        public static void Remove(RoadConstructionLeg leg)
        {
            RoadConstructionSite site       = leg.site;
            RoadConstructionLeg  CurrentLeg = (RoadConstructionLeg)site.LastLeg;

            while (CurrentLeg != leg.previous)
            {
                if (CurrentLeg.previous != null)
                {
                    RoadConstructionLeg PreviousLeg = CurrentLeg.previous;
                    PreviousLeg.SetNext(null);
                    site.LastLeg = PreviousLeg;
                    Find.WorldObjects.Remove(CurrentLeg);
                    CurrentLeg = PreviousLeg;
                }
                else
                {
                    Find.WorldObjects.Remove(CurrentLeg);
                    site.LastLeg = site;
                    break;
                }
            }
        }
Exemple #2
0
        // Here, test if we picked a tile that's already part of the chain for this construction site (different construction sites can cross each other's paths)
        // Yes ->
        //      Was it the construction site itself ?
        //      Yes -> We are done creating the site
        //      No ->  delete this leg and all legs after it
        // No -> create a new Leg
        public static bool ActionOnTile(RoadConstructionSite site, int tile)
        {
            if (site.def != DefDatabase <WorldObjectDef> .GetNamed("RoadConstructionSite", true))
            {
                Log.Error("[RotR] - The RoadConstructionSite given is somehow wrong");
                return(true);
            }
            try
            {
                foreach (WorldObject o in Find.WorldObjects.ObjectsAt(tile))
                {
                    // Action on the construction site = we're done
                    if ((o.def == DefDatabase <WorldObjectDef> .GetNamed("RoadConstructionSite", true)) && (RoadConstructionSite)o == site)
                    {
                        return(true);
                    }
                    // Action on a leg that's part of this chain = we should delete all legs after that & keep targetting
                    if ((o.def == DefDatabase <WorldObjectDef> .GetNamed("RoadConstructionLeg", true)) && ((RoadConstructionLeg)o).site == site)
                    {
                        RoadConstructionLeg.Remove((RoadConstructionLeg)o);
                        Target(site);
                        return(false);
                    }
                }

                // Check whether we clicked on a neighbour
                List <int> neighbouringTiles = new List <int>();
                Find.WorldGrid.GetTileNeighbors(tile, neighbouringTiles);
                // This is not a neighbour : do nothing
                if (!neighbouringTiles.Contains(site.LastLeg.Tile))
                {
                    Target(site);
                    return(false);
                }

                // There can be no ConstructionLeg on a biome that doesn't allow roads
                if (!DefModExtension_RotR_RoadDef.BiomeAllowed(tile, site.roadDef, out BiomeDef biomeHere))
                {
                    Messages.Message("RoadsOfTheRim_BiomePreventsConstruction".Translate(site.roadDef.label, biomeHere.label), MessageTypeDefOf.RejectInput);
                    Target(site);
                    return(false);
                }
                else if (!DefModExtension_RotR_RoadDef.ImpassableAllowed(tile, site.roadDef))
                {
                    Messages.Message("RoadsOfTheRim_BiomePreventsConstruction".Translate(site.roadDef.label, " impassable mountains"), MessageTypeDefOf.RejectInput);
                    Target(site);
                    return(false);
                }

                RoadConstructionLeg newLeg = (RoadConstructionLeg)WorldObjectMaker.MakeWorldObject(DefDatabase <WorldObjectDef> .GetNamed("RoadConstructionLeg", true));
                newLeg.Tile = tile;
                newLeg.site = site;
                // This is not the first Leg
                if (site.LastLeg.def == DefDatabase <WorldObjectDef> .GetNamed("RoadConstructionLeg", true))
                {
                    RoadConstructionLeg l = site.LastLeg as RoadConstructionLeg;
                    l.SetNext(newLeg);
                    newLeg.previous = l;
                }
                else
                {
                    newLeg.previous = null;
                }
                newLeg.SetNext(null);
                Find.WorldObjects.Add(newLeg);
                site.LastLeg = newLeg;
                Target(site);
                return(false);
            }
            catch (Exception e)
            {
                Log.Error("[RotR] Exception : " + e);
                return(true);
            }
        }