Beispiel #1
0
        /// <summary> Minifies the package</summary>
        public virtual void Minify()
        {
            Map           map     = parent.Map;
            MinifiedThing package = MinifyUtility.MakeMinified(parent);

            GenPlace.TryPlaceThing(package, parent.Position, map, ThingPlaceMode.Near);
            SoundDef.Named("ThingUninstalled").PlayOneShot(new TargetInfo(parent.Position, map));
        }
Beispiel #2
0
 public virtual void MinifyOrDestroy()
 {
     if (base.parent.def.Minifiable)
     {
         Map           map     = parent.Map;
         MinifiedThing package = MinifyUtility.MakeMinified(parent);
         GenPlace.TryPlaceThing(package, parent.Position, map, ThingPlaceMode.Near);
         SoundDef.Named("ThingUninstalled").PlayOneShot(new TargetInfo(parent.Position, map));
     }
     else
     {
         base.parent.Destroy(DestroyMode.KillFinalize);
     }
 }
        protected override void ScatterAt(IntVec3 loc, Map map, int stackCount = 1)
        {
            if (!TryGetRandomValidRotation(loc, map, out Rot4 rot))
            {
                Log.Warning("Could not find any valid rotation for " + thingDef);
                return;
            }
            if (clearSpaceSize > 0)
            {
                using (IEnumerator <IntVec3> enumerator = GridShapeMaker.IrregularLump(loc, map, clearSpaceSize).GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Building edifice = GridsUtility.GetEdifice(enumerator.Current, map);
                        if (edifice != null)
                        {
                            edifice.Destroy(0);
                        }
                    }
                }
            }
            Thing thing = ThingMaker.MakeThing(thingDef, stuff);

            if (thingDef.Minifiable)
            {
                thing = MinifyUtility.MakeMinified(thing);
            }
            if (thing.def.category == ThingCategory.Item)
            {
                thing.stackCount = stackCount;
                ForbidUtility.SetForbidden(thing, true, false);
                GenPlace.TryPlaceThing(thing, loc, map, ThingPlaceMode.Near, out Thing thing2, null);
                if (nearPlayerStart && thing2 != null && thing2.def.category == ThingCategory.Item && TutorSystem.TutorialMode)
                {
                    Find.TutorialState.AddStartingItem(thing2);
                    return;
                }
            }
            else
            {
                GenSpawn.Spawn(thing, loc, map, rot, false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Create the produced AI Pawn
        /// </summary>
        private void Create_Building_AIPawn_Inactive()
        {
            ThingDef thingDef = ThingDef.Named(buildingDefName);
            Thing    thing    = ThingMaker.MakeThing(thingDef);

            thing.SetFaction(this.Faction);

            IntVec3 spawnPos = InteractionCell;

            if (thing.def.Minifiable)
            {
                Thing minified = MinifyUtility.MakeMinified(thing);
                thing = minified;
            }

            if (Rotation == Rot4.North)
            {
                // Create the inactive mai R/H of the interaction square
                spawnPos = spawnPos + new IntVec3(1, 0, 0);     // RH 1cell from the interaction cell
                GenSpawn.Spawn(thing, spawnPos, Map, Rot4.East);
            }
            if (Rotation == Rot4.East)
            {
                spawnPos = spawnPos + new IntVec3(0, 0, -1);     // bottom 1cell from the interaction cell
                GenSpawn.Spawn(thing, spawnPos, Map, Rot4.South);
            }
            if (Rotation == Rot4.South)
            {
                spawnPos = spawnPos + new IntVec3(-1, 0, 0);     // LH 1cell from the interaction cell
                GenSpawn.Spawn(thing, spawnPos, Map, Rot4.West);
            }
            if (Rotation == Rot4.West)
            {
                spawnPos = spawnPos + new IntVec3(0, 0, 1);     // top 1cell from the interaction cell
                GenSpawn.Spawn(thing, spawnPos, Map, Rot4.North);
            }
        }
Beispiel #5
0
        public static PurposeInfo Make(LocalTargetInfo targetInfo)
        {
            //reports of nullrefs in here for somereason.
            try
            {
                PurposeInfo purposeInfo = new PurposeInfo();
                if (targetInfo.IsValid)
                {
                    purposeInfo.pos = targetInfo.CenterVector3;
                }
                if (targetInfo.Thing is Thing target)
                {
                    target = MinifyUtility.GetInnerIfMinified(target);
                    BuildableDef def = target.def;

                    purposeInfo.pos   = target.DrawPos;
                    purposeInfo.color = target.DrawColor;

                    if (target is Pawn || target is Corpse)
                    {
                        Pawn pawn = target as Pawn;
                        if (pawn == null)
                        {
                            pawn = ((Corpse)target).InnerPawn;
                        }
                        if (!pawn.RaceProps.Humanlike)
                        {
                            //This seems unnecessary
                            //if (!pawn.Drawer.renderer.graphics.AllResolved)
                            //{
                            //	pawn.Drawer.renderer.graphics.ResolveAllGraphics();
                            //}
                            Material matSingle = pawn.Drawer.renderer.graphics.nakedGraphic.MatSingle;
                            purposeInfo.icon  = matSingle.mainTexture;
                            purposeInfo.color = matSingle.color;
                        }
                        else
                        {
                            purposeInfo.icon = PortraitsCache.Get(pawn, Vector2.one * Gizmo.Height, Rot4.South, cameraZoom: 1.5f);
                        }
                        purposeInfo.proportions = new Vector2(purposeInfo.icon.width, purposeInfo.icon.height);
                    }
                    else
                    {
                        if (target is IConstructible buildThing)
                        {
                            def = target.def.entityDefToBuild;
                            if (buildThing.EntityToBuildStuff() != null)
                            {
                                purposeInfo.color = buildThing.EntityToBuildStuff().stuffProps.color;
                            }
                            else
                            {
                                purposeInfo.color = def.uiIconColor;
                            }
                        }

                        purposeInfo.icon = def.uiIcon;

                        if (def is ThingDef td)
                        {
                            purposeInfo.proportions = td.graphicData.drawSize;
                            purposeInfo.scale       = GenUI.IconDrawScale(td);
                        }

                        if (def is TerrainDef)
                        {
                            //private static readonly Vector2 TerrainTextureCroppedSize = new Vector2(64f, 64f);
                            purposeInfo.texCoords = new Rect(0f, 0f, 64f / purposeInfo.icon.width, 64f / purposeInfo.icon.height);
                        }
                        else if (def.uiIconPath.NullOrEmpty())
                        {
                            Material iconMat = def.graphic.MatSingle;
                            purposeInfo.texCoords = new Rect(iconMat.mainTextureOffset, iconMat.mainTextureScale);
                        }
                    }
                }
                return(purposeInfo);
            }
            catch (NullReferenceException)
            {
                return(null);
            }
        }