public override void Resolve(ResolveParams rp)
        {
            ThingDef thingDef = rp.singleThingDef ?? ThingSetMakerUtility.allGeneratableItems.Where((ThingDef x) => x.IsWeapon || x.IsMedicine || x.IsDrug).RandomElement();
            Rot4     rot      = rp.thingRot ?? Rot4.North;
            IntVec3  center   = IntVec3.Zero;
            IntVec2  size     = thingDef.size;
            int      num      = rp.fillWithThingsPadding ?? 0;

            if (num < 0)
            {
                num = 0;
            }
            GenAdj.AdjustForRotation(ref center, ref size, rot);
            if (size.x <= 0 || size.z <= 0)
            {
                Log.Error("Thing has 0 size.");
                return;
            }
            for (int i = rp.rect.minX; i <= rp.rect.maxX - size.x + 1; i += size.x + num)
            {
                for (int j = rp.rect.minZ; j <= rp.rect.maxZ - size.z + 1; j += size.z + num)
                {
                    ResolveParams resolveParams = rp;
                    resolveParams.rect           = new CellRect(i, j, size.x, size.z);
                    resolveParams.singleThingDef = thingDef;
                    resolveParams.thingRot       = rot;
                    BaseGen.symbolStack.Push("thing", resolveParams);
                }
            }
            BaseGen.symbolStack.Push("clear", rp);
        }
Exemple #2
0
        public override bool CanResolve(ResolveParams rp)
        {
            bool result;

            if (!base.CanResolve(rp))
            {
                result = false;
            }
            else if (rp.singleThingToSpawn != null)
            {
                result = false;
            }
            else
            {
                if (rp.singleThingDef != null)
                {
                    Rot4?   thingRot = rp.thingRot;
                    Rot4    rot      = (thingRot == null) ? Rot4.North : thingRot.Value;
                    IntVec3 zero     = IntVec3.Zero;
                    IntVec2 size     = rp.singleThingDef.size;
                    GenAdj.AdjustForRotation(ref zero, ref size, rot);
                    if (rp.rect.Width < size.x || rp.rect.Height < size.z)
                    {
                        return(false);
                    }
                }
                result = true;
            }
            return(result);
        }
Exemple #3
0
        public override bool CanResolve(ResolveParams rp)
        {
            if (!base.CanResolve(rp))
            {
                return(false);
            }
            if (rp.singleThingToSpawn != null)
            {
                return(false);
            }
            if (rp.singleThingDef != null)
            {
                Rot4?   thingRot = rp.thingRot;
                Rot4    rot      = (!thingRot.HasValue) ? Rot4.North : thingRot.Value;
                IntVec3 zero     = IntVec3.Zero;
                IntVec2 size     = rp.singleThingDef.size;
                GenAdj.AdjustForRotation(ref zero, ref size, rot);
                if (rp.rect.Width >= size.x && rp.rect.Height >= size.z)
                {
                    goto IL_009d;
                }
                return(false);
            }
            goto IL_009d;
IL_009d:
            return(true);
        }
        private bool TryFindSpawnCell(CellRect rect, ThingDef thingDef, Rot4 rot, out IntVec3 spawnCell)
        {
            Map     map  = BaseGen.globalSettings.map;
            IntVec3 zero = IntVec3.Zero;
            IntVec2 size = thingDef.size;

            GenAdj.AdjustForRotation(ref zero, ref size, rot);
            CellRect             empty         = CellRect.Empty;
            Predicate <CellRect> basePredicate = delegate(CellRect x)
            {
                if (x.Cells.All((IntVec3 y) => y.Standable(map)))
                {
                    if (!GenSpawn.WouldWipeAnythingWith(x, thingDef, map, (Thing z) => z.def.category == ThingCategory.Building))
                    {
                        return(thingDef.category != ThingCategory.Item || x.CenterCell.GetFirstItem(map) == null);
                    }
                }
                return(false);
            };
            bool flag = false;

            if (thingDef.category == ThingCategory.Building)
            {
                flag = rect.TryFindRandomInnerRectTouchingEdge(size, out empty, (CellRect x) => basePredicate(x) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(x, map) && GenConstruct.TerrainCanSupport(x, map, thingDef));
                if (!flag)
                {
                    flag = rect.TryFindRandomInnerRectTouchingEdge(size, out empty, (CellRect x) => basePredicate(x) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(x, map));
                }
            }
            bool result;

            if (!flag && !rect.TryFindRandomInnerRectTouchingEdge(size, out empty, basePredicate))
            {
                spawnCell = IntVec3.Invalid;
                result    = false;
            }
            else
            {
                CellRect.CellRectIterator iterator = empty.GetIterator();
                while (!iterator.Done())
                {
                    if (GenAdj.OccupiedRect(iterator.Current, rot, thingDef.size) == empty)
                    {
                        spawnCell = iterator.Current;
                        return(true);
                    }
                    iterator.MoveNext();
                }
                Log.Error("We found a valid rect but we couldn't find the root position. This should never happen.", false);
                spawnCell = IntVec3.Invalid;
                result    = false;
            }
            return(result);
        }
Exemple #5
0
        public static bool AdjacentCellsCardinal(ref List <IntVec3> __result,
                                                 IntVec3 thingCenter,
                                                 Rot4 thingRot,
                                                 IntVec2 thingSize)
        {
            if (thingSize.x == 1 && thingSize.z == 1)
            {
                List <IntVec3> r1 = null;
                AdjacentCellsCardinal(ref r1, thingCenter);
                __result = r1;
                return(false);
            }
            //if (GenAdjFast.working)
            //throw new InvalidOperationException("GenAdjFast is already working.");
            //GenAdjFast.resultList.Clear();
            List <IntVec3> resultList = new List <IntVec3>();

            //GenAdjFast.working = true;
            GenAdj.AdjustForRotation(ref thingCenter, ref thingSize, thingRot);
            int     newX    = thingCenter.x - (thingSize.x - 1) / 2 - 1;
            int     num1    = newX + thingSize.x + 1;
            int     newZ    = thingCenter.z - (thingSize.z - 1) / 2 - 1;
            int     num2    = newZ + thingSize.z + 1;
            IntVec3 intVec3 = new IntVec3(newX, 0, newZ);

            do
            {
                ++intVec3.x;
                resultList.Add(intVec3);
            }while (intVec3.x < num1 - 1);
            ++intVec3.x;
            do
            {
                ++intVec3.z;
                resultList.Add(intVec3);
            }while (intVec3.z < num2 - 1);
            ++intVec3.z;
            do
            {
                --intVec3.x;
                resultList.Add(intVec3);
            }while (intVec3.x > newX + 1);
            --intVec3.x;
            do
            {
                --intVec3.z;
                resultList.Add(intVec3);
            }while (intVec3.z > newZ + 1);
            //GenAdjFast.working = false;
            __result = resultList;
            return(false);
        }
Exemple #6
0
        public static bool TryFindRandomAdjacentCell8WayWithRoomGroup(ref bool __result, IntVec3 center, Rot4 rot, IntVec2 size, Map map, out IntVec3 result)
        {
            GenAdj.AdjustForRotation(ref center, ref size, rot);
            //validCells.Clear();
            List <IntVec3> validCells = new List <IntVec3>();

            foreach (IntVec3 item in GenAdj.CellsAdjacent8Way(center, rot, size))
            {
                if (item.InBounds(map) && item.GetRoomGroup(map) != null)
                {
                    validCells.Add(item);
                }
            }

            __result = validCells.TryRandomElement(out result);
            return(false);
        }
Exemple #7
0
        public override void Resolve(ResolveParams rp)
        {
            ThingDef thingDef;

            if ((thingDef = rp.singleThingDef) == null)
            {
                thingDef = (from x in ThingSetMakerUtility.allGeneratableItems
                            where x.IsWeapon || x.IsMedicine || x.IsDrug
                            select x).RandomElement <ThingDef>();
            }
            ThingDef thingDef2             = thingDef;
            Rot4?    thingRot              = rp.thingRot;
            Rot4     rot                   = (thingRot == null) ? Rot4.North : thingRot.Value;
            IntVec3  zero                  = IntVec3.Zero;
            IntVec2  size                  = thingDef2.size;
            int?     fillWithThingsPadding = rp.fillWithThingsPadding;
            int      num                   = (fillWithThingsPadding == null) ? 0 : fillWithThingsPadding.Value;

            if (num < 0)
            {
                num = 0;
            }
            GenAdj.AdjustForRotation(ref zero, ref size, rot);
            if (size.x <= 0 || size.z <= 0)
            {
                Log.Error("Thing has 0 size.", false);
            }
            else
            {
                for (int i = rp.rect.minX; i <= rp.rect.maxX - size.x + 1; i += size.x + num)
                {
                    for (int j = rp.rect.minZ; j <= rp.rect.maxZ - size.z + 1; j += size.z + num)
                    {
                        ResolveParams resolveParams = rp;
                        resolveParams.rect           = new CellRect(i, j, size.x, size.z);
                        resolveParams.singleThingDef = thingDef2;
                        resolveParams.thingRot       = new Rot4?(rot);
                        BaseGen.symbolStack.Push("thing", resolveParams);
                    }
                }
                BaseGen.symbolStack.Push("clear", rp);
            }
        }
 public override bool CanResolve(ResolveParams rp)
 {
     if (!base.CanResolve(rp))
     {
         return(false);
     }
     if (rp.singleThingToSpawn != null)
     {
         return(false);
     }
     if (rp.singleThingDef != null)
     {
         Rot4    rot    = rp.thingRot ?? Rot4.North;
         IntVec3 center = IntVec3.Zero;
         IntVec2 size   = rp.singleThingDef.size;
         GenAdj.AdjustForRotation(ref center, ref size, rot);
         if (rp.rect.Width < size.x || rp.rect.Height < size.z)
         {
             return(false);
         }
     }
     return(true);
 }
        private bool TryFindSpawnCell(CellRect rect, ThingDef thingDef, Rot4 rot, bool mustReachMapEdge, out IntVec3 spawnCell)
        {
            Map     map    = BaseGen.globalSettings.map;
            IntVec3 center = IntVec3.Zero;
            IntVec2 size   = thingDef.size;

            GenAdj.AdjustForRotation(ref center, ref size, rot);
            CellRect             rect2         = CellRect.Empty;
            TraverseParms        traverseParms = TraverseParms.For(TraverseMode.PassDoors);
            Predicate <CellRect> basePredicate = (CellRect x) => x.Cells.All((IntVec3 y) => y.Standable(map)) && !GenSpawn.WouldWipeAnythingWith(x, thingDef, map, (Thing z) => z.def.category == ThingCategory.Building) && (thingDef.category != ThingCategory.Item || x.CenterCell.GetFirstItem(map) == null) && (!mustReachMapEdge || map.reachability.CanReachMapEdge(x.CenterCell, traverseParms));
            bool flag = false;

            if (thingDef.category == ThingCategory.Building)
            {
                flag = rect.TryFindRandomInnerRectTouchingEdge(size, out rect2, (CellRect x) => basePredicate(x) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(x, map) && GenConstruct.TerrainCanSupport(x, map, thingDef));
                if (!flag)
                {
                    flag = rect.TryFindRandomInnerRectTouchingEdge(size, out rect2, (CellRect x) => basePredicate(x) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(x, map));
                }
            }
            if (!flag && !rect.TryFindRandomInnerRectTouchingEdge(size, out rect2, basePredicate))
            {
                spawnCell = IntVec3.Invalid;
                return(false);
            }
            foreach (IntVec3 item in rect2)
            {
                if (GenAdj.OccupiedRect(item, rot, thingDef.size) == rect2)
                {
                    spawnCell = item;
                    return(true);
                }
            }
            Log.Error("We found a valid rect but we couldn't find the root position. This should never happen.");
            spawnCell = IntVec3.Invalid;
            return(false);
        }