Ejemplo n.º 1
0
            private static bool Prefix(TradeShip __instance, Thing toGive, int countToGive, Pawn playerNegotiator, List <Pawn> ___soldPrisoners)
            {
                if (__instance.Map != null)
                {
                    MapParent_PocketDimension mapParent = __instance.Map.info.parent as MapParent_PocketDimension;
                    if (mapParent != null)
                    {
                        Map containingMap = PocketDimensionUtility.GetHighestContainingMap(__instance.Map);

                        // If there was no containing map found (should mean box is in a caravan; could mean the box was nested inside itself, it which case, oh well, give them their goods anyway :P)
                        if (containingMap == __instance.Map)
                        {
                            Building_PocketDimensionExit exit = PocketDimensionUtility.GetExit(mapParent.dimensionSeed);
                            if (exit != null && exit.SpawnedOrAnyParentSpawned)
                            {
                                Thing thing = toGive.SplitOff(countToGive);
                                thing.PreTraded(TradeAction.PlayerBuys, playerNegotiator, __instance);
                                Pawn pawn = thing as Pawn;
                                if (pawn != null)
                                {
                                    ___soldPrisoners.Remove(pawn);
                                }

                                IntVec3 positionHeld = exit.PositionHeld;
                                Map     mapHeld      = exit.MapHeld;
                                GenPlace.TryPlaceThing(thing, positionHeld, mapHeld, ThingPlaceMode.Near);
                                return(false);
                            }
                        }
                    }
                }

                return(true);
            }
        public float CalculateAdditionalMarketValue(float baseValue)
        {
            if (this.doingRecursiveThing)
            {
                Logger.MessageFormat(this, "Counting box wealth again recursively. Skipping...");
                return(0.0f);
            }

            float componentValue = CalculateUsedComponentValue();
            float contentValue   = 0.0f;

            MapParent_PocketDimension innerMapParent = PocketDimensionUtility.GetMapParent(this.dimensionSeed);

            if (innerMapParent != null && innerMapParent.Map != null)
            {
                this.doingRecursiveThing = true;
                try
                {
                    contentValue = innerMapParent.Map.wealthWatcher.WealthTotal;
                }
                finally
                {
                    this.doingRecursiveThing = false;
                }
            }

            Logger.MessageFormat(this, "Adding value to box: {0}, {1} + {2} + {3} = {4}", this.Label, baseValue, contentValue, componentValue, (baseValue + contentValue + componentValue));

            return(contentValue + componentValue);
        }
Ejemplo n.º 3
0
        public static MapParent_PocketDimension GetMapParent(string dimensionSeed)
        {
            MapParent_PocketDimension mapParent = null;

            if (dimensionSeed != null)
            {
                MapParents.TryGetValue(dimensionSeed, out mapParent);
            }
            return(mapParent);
        }
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            base.Destroy(mode);

            MapParent_PocketDimension dimensionMapParent = null;

            if (!string.IsNullOrEmpty(dimensionSeed) && PocketDimensionUtility.MapParents.TryGetValue(dimensionSeed, out dimensionMapParent))
            {
                dimensionMapParent.Abandon(GetLost);
            }
        }
Ejemplo n.º 5
0
        public static List <Thing> GetWalls(string dimensionSeed)
        {
            MapParent_PocketDimension mapParent = GetMapParent(dimensionSeed);

            if (mapParent != null && mapParent.Map != null)
            {
                List <Thing> wallList = mapParent.Map.listerThings.ThingsOfDef(PocketDimensionDefOf.CM_PocketDimensionWall);

                if (wallList.Count == 0)
                {
                    return(null);
                }

                return(wallList);
            }

            return(null);
        }
Ejemplo n.º 6
0
        public static Map GetHighestContainingMap(Map map)
        {
            Map result = map;

            if (map != null)
            {
                MapParent_PocketDimension mapParent = map.info.parent as MapParent_PocketDimension;
                if (mapParent != null)
                {
                    Building_PocketDimensionBox box = PocketDimensionUtility.GetBox(mapParent.dimensionSeed);
                    if (box == null)
                    {
                        Logger.ErrorFormat(map, "Looking for a map containing a box that does not exist!");
                    }
                    else if (box.doingRecursiveThing)
                    {
                        Logger.WarningFormat(map, "Tried to find a containing map for a pocket dimension nested in a loop!");
                    }
                    else if (box.SpawnedOrAnyParentSpawned)
                    {
                        box.doingRecursiveThing = true;
                        try
                        {
                            result = GetHighestContainingMap(box.MapHeld);
                        }
                        finally
                        {
                            box.doingRecursiveThing = false;
                        }
                    }
                    else
                    {
                        //Logger.WarningFormat(map, "Could not find map containing pocket dimension box. Is it in a caravan?");
                    }
                }
                else
                {
                    //Logger.MessageFormat(map, "Not a pocket dimension.");
                }
            }

            return(result);
        }
            public static void GetOutdoorTemp(ref float __result, Map ___map)
            {
                MapParent_PocketDimension mapParent = ___map.info.parent as MapParent_PocketDimension;

                if (mapParent != null)
                {
                    Building_PocketDimensionEntranceBase box = PocketDimensionUtility.GetBox(mapParent.dimensionSeed);
                    if (box != null)
                    {
                        __result = 21.0f;

                        if (box.Spawned)
                        {
                            __result = GenTemperature.GetTemperatureForCell(box.Position, box.Map);
                        }
                        else if (box.ParentHolder != null)
                        {
                            for (IThingHolder parentHolder = box.ParentHolder; parentHolder != null; parentHolder = parentHolder.ParentHolder)
                            {
                                if (ThingOwnerUtility.TryGetFixedTemperature(parentHolder, box, out __result))
                                {
                                    return;// false;
                                }
                            }
                        }
                        else if (box.SpawnedOrAnyParentSpawned)
                        {
                            __result = GenTemperature.GetTemperatureForCell(box.PositionHeld, box.MapHeld);
                        }
                        else if (box.Tile >= 0)
                        {
                            __result = GenTemperature.GetTemperatureFromSeasonAtTile(GenTicks.TicksAbs, box.Tile);
                        }

                        // Above logic derived from the following function call. Can't call it here due to an edge case which results in infinite loop
                        //__result = box.AmbientTemperature;
                        return;// false;
                    }
                }

                //return true;
            }
Ejemplo n.º 8
0
        public static void OnCriticalMapObjectDestroyed(Thing thingInMap, bool getLost = false)
        {
            Thing thingHolder = thingInMap.SpawnedParentOrMe;
            Map   map         = thingInMap.Map;

            if (map == null)
            {
                map = thingHolder.Map;
            }

            if (map != null)
            {
                MapParent_PocketDimension parent = map.Parent as MapParent_PocketDimension;

                if (parent != null)
                {
                    parent.Abandon(getLost);
                }
            }
        }
        public override void Generate(Map map, GenStepParams parms)
        {
            MapParent_PocketDimension mapParent = map.Parent as MapParent_PocketDimension;
            List <IntVec3>            list      = new List <IntVec3>();
            TerrainGrid terrainGrid             = map.terrainGrid;
            RoofGrid    roofGrid = map.roofGrid;

            string   terrainDefName = "CM_PocketDimensionFloor";
            ThingDef boxStuffDef    = null;

            // Build terrain defname
            Building_PocketDimensionBox box = PocketDimensionUtility.GetBox(mapParent.dimensionSeed);

            if (box != null && box.Stuff != null)
            {
                boxStuffDef = box.Stuff;
                if (boxStuffDef.stuffProps.categories.Contains(StuffCategoryDefOf.Metallic))
                {
                    terrainDefName += "Metal";
                }
                else if (boxStuffDef.stuffProps.categories.Contains(StuffCategoryDefOf.Stony))
                {
                    terrainDefName += "Stone";
                }
                else if (boxStuffDef.stuffProps.categories.Contains(StuffCategoryDefOf.Woody))
                {
                    terrainDefName += "Wood";
                }

                terrainDefName += "_" + boxStuffDef.defName;
            }

            // If that terrain was not found, use default metal terrain
            TerrainDef terrainDef = DefDatabase <TerrainDef> .GetNamedSilentFail(terrainDefName);

            if (terrainDef == null)
            {
                terrainDef = PocketDimensionDefOf.CM_PocketDimensionFloorMetal;
            }

            foreach (IntVec3 current in map.AllCells)
            {
                terrainGrid.SetTerrain(current, terrainDef);

                if (current.OnEdge(map))
                {
                    Thing wall = ThingMaker.MakeThing(PocketDimensionDefOf.CM_PocketDimensionWall, boxStuffDef);
                    wall.SetFaction(Faction.OfPlayer);
                    GenSpawn.Spawn(wall, current, map);
                }

                roofGrid.SetRoof(current, PocketDimensionDefOf.CM_PocketDimensionRoof);
            }
            MapGenFloatGrid elevation = MapGenerator.Elevation;

            foreach (IntVec3 allCell in map.AllCells)
            {
                elevation[allCell] = 0.0f;
            }
            MapGenFloatGrid fertility = MapGenerator.Fertility;

            foreach (IntVec3 allCell2 in map.AllCells)
            {
                fertility[allCell2] = 0.0f;
            }
        }
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);

            Logger.MessageFormat(this, "Spawning");

            compCreator     = this.GetComp <CompPocketDimensionCreator>();
            compTransporter = this.GetComp <CompTransporter>();

            if (mapSize == 0)
            {
                mapSize = 1;
            }

            if (fuel >= 1.0f)
            {
                if (compCreator != null)
                {
                    compCreator.AddComponents((int)Mathf.Round(fuel));
                    fuel = 0.0f;

                    if (compCreator.SupplyCount > desiredComponentCount)
                    {
                        int amountToRefund = compCreator.SupplyCount - desiredComponentCount;
                        if (compCreator.ConsumeComponents(amountToRefund))
                        {
                            ThingDef thingToRefundDef = compCreator.Props.componentDef;

                            RefundComponents(thingToRefundDef, amountToRefund);
                        }
                    }
                }
                else
                {
                    ThingDef thingToRefundDef = ThingDefOf.ComponentSpacer;

                    int amountToRefund = (int)Mathf.Round(fuel);
                    fuel = 0.0f;

                    RefundComponents(thingToRefundDef, amountToRefund);
                }
            }

            // Reconfigure runtime-set comp property values
            SetDesiredMapSize(desiredMapSize);

            if (MapCreated)
            {
                MapParent_PocketDimension dimensionMapParent = PocketDimensionUtility.GetMapParent(this.dimensionSeed);

                // Looks like we just got installed somewhere. Make sure map tile is the same as our current tile
                if (this.Map != null && dimensionMapParent != null)
                {
                    dimensionMapParent.Tile = this.Map.Parent.Tile;
                }
            }
            else
            {
                if (compCreator != null && compCreator.Props.preMadeMapSize > 0)
                {
                    SetDesiredMapSize(compCreator.Props.preMadeMapSize);
                    mapSize = desiredMapSize;
                    CreateMap(this.MapDiameter);
                }
            }
        }