Beispiel #1
0
        public static bool CanReplaceStuffFor(ThingDef stuff, Thing thing, ThingDef matchDef = null)
        {
            if (thing.Faction != Faction.OfPlayer && thing.Faction != null)             //can't replace enemy things
            {
                return(false);
            }

            BuildableDef builtDef = GenConstruct.BuiltDefOf(thing.def);

            if (matchDef != null && builtDef != matchDef)
            {
                return(false);
            }

            if (thing is Blueprint bp)
            {
                if (bp.EntityToBuildStuff() == stuff)
                {
                    return(false);
                }
            }
            else if (thing is Frame frame)
            {
                if (frame.EntityToBuildStuff() == stuff)
                {
                    return(false);
                }
            }
            else if (thing.def.HasReplaceFrame())
            {
                if (thing.Stuff == stuff)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            if (!GenConstruct.CanBuildOnTerrain(builtDef, thing.Position, thing.Map, thing.Rotation, thing, stuff))
            {
                return(false);               //TODO: place bridges under &&
            }
            if (thing.BeingReplacedByNewThing() != null)
            {
                return(false);               //being upgraded.
            }
            return(GenStuff.AllowedStuffsFor(builtDef).Contains(stuff));
        }