protected override RectTrigger MakeRectTrigger()
        {
            RectTrigger rectTrigger = base.MakeRectTrigger();

            rectTrigger.activateOnExplosion = true;
            return(rectTrigger);
        }
Esempio n. 2
0
        private void SpawnTrigger(CellRect rectToDefend, IntVec3 root, Map map, GenStepParams parms)
        {
            int      nextSignalTagID = Find.UniqueIDsManager.GetNextSignalTagID();
            string   signalTag       = "ambushActivated-" + nextSignalTagID;
            CellRect rect;

            if (root.IsValid)
            {
                rect = CellRect.CenteredOn(root, 17);
            }
            else
            {
                rect = rectToDefend.ExpandedBy(12);
            }
            SignalAction_Ambush signalAction_Ambush = this.MakeAmbushSignalAction(rectToDefend, root, parms);

            signalAction_Ambush.signalTag = signalTag;
            GenSpawn.Spawn(signalAction_Ambush, rect.CenterCell, map, WipeMode.Vanish);
            RectTrigger rectTrigger = this.MakeRectTrigger();

            rectTrigger.signalTag = signalTag;
            rectTrigger.Rect      = rect;
            GenSpawn.Spawn(rectTrigger, rect.CenterCell, map, WipeMode.Vanish);
            TriggerUnfogged triggerUnfogged = (TriggerUnfogged)ThingMaker.MakeThing(ThingDefOf.TriggerUnfogged, null);

            triggerUnfogged.signalTag = signalTag;
            GenSpawn.Spawn(triggerUnfogged, rect.CenterCell, map, WipeMode.Vanish);
        }
        protected override void ScatterAt(IntVec3 loc, Map map, int stackCount = 1)
        {
            int      randomInRange             = GenStep_ScatterShrines.ShrinesCountX.RandomInRange;
            int      randomInRange2            = GenStep_ScatterShrines.ShrinesCountZ.RandomInRange;
            int      randomInRange3            = GenStep_ScatterShrines.ExtraHeightRange.RandomInRange;
            IntVec2  standardAncientShrineSize = SymbolResolver_AncientShrinesGroup.StandardAncientShrineSize;
            int      num  = 1;
            int      num2 = randomInRange * standardAncientShrineSize.x + (randomInRange - 1) * num;
            int      num3 = randomInRange2 * standardAncientShrineSize.z + (randomInRange2 - 1) * num;
            int      num4 = num2 + 2;
            int      num5 = num3 + 2 + randomInRange3;
            CellRect rect = new CellRect(loc.x, loc.z, num4, num5);

            rect.ClipInsideMap(map);
            if (rect.Width != num4 || rect.Height != num5)
            {
                return;
            }
            foreach (IntVec3 current in rect.Cells)
            {
                List <Thing> list = map.thingGrid.ThingsListAt(current);
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].def == ThingDefOf.AncientCryptosleepCasket)
                    {
                        return;
                    }
                }
            }
            if (!base.CanPlaceAncientBuildingInRange(rect, map))
            {
                return;
            }
            ResolveParams resolveParams = default(ResolveParams);

            resolveParams.rect = rect;
            resolveParams.disableSinglePawn           = new bool?(true);
            resolveParams.disableHives                = new bool?(true);
            resolveParams.ancientTempleEntranceHeight = new int?(randomInRange3);
            BaseGen.globalSettings.map                = map;
            BaseGen.symbolStack.Push("ancientTemple", resolveParams);
            BaseGen.Generate();
            int    nextSignalTagID = Find.UniqueIDsManager.GetNextSignalTagID();
            string signalTag       = "ancientTempleApproached-" + nextSignalTagID;
            SignalAction_Letter signalAction_Letter = (SignalAction_Letter)ThingMaker.MakeThing(ThingDefOf.SignalAction_Letter, null);

            signalAction_Letter.signalTag = signalTag;
            signalAction_Letter.letter    = LetterMaker.MakeLetter("LetterLabelAncientShrineWarning".Translate(), "AncientShrineWarning".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(rect.CenterCell, map, false));
            GenSpawn.Spawn(signalAction_Letter, rect.CenterCell, map);
            RectTrigger rectTrigger = (RectTrigger)ThingMaker.MakeThing(ThingDefOf.RectTrigger, null);

            rectTrigger.signalTag         = signalTag;
            rectTrigger.Rect              = rect.ExpandedBy(1).ClipInsideMap(map);
            rectTrigger.destroyIfUnfogged = true;
            GenSpawn.Spawn(rectTrigger, rect.CenterCell, map);
        }
        private void SpawnTrigger(CellRect rectToDefend, IntVec3 root, Map map)
        {
            int                 nextSignalTagID     = Find.UniqueIDsManager.GetNextSignalTagID();
            string              signalTag           = "ambushActivated-" + nextSignalTagID;
            CellRect            rect                = (!root.IsValid) ? rectToDefend.ExpandedBy(12) : CellRect.CenteredOn(root, 17);
            SignalAction_Ambush signalAction_Ambush = this.MakeAmbushSignalAction(rectToDefend, root);

            signalAction_Ambush.signalTag = signalTag;
            GenSpawn.Spawn(signalAction_Ambush, rect.CenterCell, map);
            RectTrigger rectTrigger = this.MakeRectTrigger();

            rectTrigger.signalTag = signalTag;
            rectTrigger.Rect      = rect;
            GenSpawn.Spawn(rectTrigger, rect.CenterCell, map);
        }
 static int InTriggerNow(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         RectTrigger obj = (RectTrigger)ToLua.CheckObject(L, 1, typeof(RectTrigger));
         bool        o   = obj.InTriggerNow();
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    static int set_rect(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            RectTrigger      obj  = (RectTrigger)o;
            UnityEngine.Rect arg0 = (UnityEngine.Rect)ToLua.CheckObject(L, 2, typeof(UnityEngine.Rect));
            obj.rect = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index rect on a nil value" : e.Message));
        }
    }
    static int get_rect(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            RectTrigger      obj = (RectTrigger)o;
            UnityEngine.Rect ret = obj.rect;
            ToLua.PushValue(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index rect on a nil value" : e.Message));
        }
    }
Esempio n. 8
0
        private void SpawnTrigger(CellRect rectToDefend, IntVec3 root, Map map, GenStepParams parms)
        {
            int                 nextSignalTagID     = Find.UniqueIDsManager.GetNextSignalTagID();
            string              signalTag           = "ambushActivated-" + nextSignalTagID;
            CellRect            rect                = (!root.IsValid) ? rectToDefend.ExpandedBy(12) : CellRect.CenteredOn(root, 17);
            SignalAction_Ambush signalAction_Ambush = MakeAmbushSignalAction(rectToDefend, root, parms);

            signalAction_Ambush.signalTag = signalTag;
            GenSpawn.Spawn(signalAction_Ambush, rect.CenterCell, map);
            RectTrigger rectTrigger = MakeRectTrigger();

            rectTrigger.signalTag = signalTag;
            rectTrigger.Rect      = rect;
            GenSpawn.Spawn(rectTrigger, rect.CenterCell, map);
            TriggerUnfogged obj = (TriggerUnfogged)ThingMaker.MakeThing(ThingDefOf.TriggerUnfogged);

            obj.signalTag = signalTag;
            GenSpawn.Spawn(obj, rect.CenterCell, map);
        }
Esempio n. 9
0
        private void MakeBlueprintRoom(CellRect mapRect, Map map, MapGeneratorBlueprintDef blueprint, ThingDef stuffDef)
        {
            blueprint.buildingData = CleanUpBlueprintData(blueprint.buildingData);
            blueprint.floorData    = CleanUpBlueprintData(blueprint.floorData);
            blueprint.pawnData     = CleanUpBlueprintData(blueprint.pawnData);
            blueprint.itemData     = CleanUpBlueprintData(blueprint.itemData);

            if (blueprint.buildingData == null && blueprint.floorData == null)
            {
                Log.ErrorOnce(string.Format("After cleaning the BlueprintData and FloorData of blueprint {0} -> both are null, nothing will be done!", blueprint.defName), 313001);
                return;
            }

            IntVec3 spawnBaseCell = new IntVec3(mapRect.BottomLeft.x, mapRect.TopRight.y, mapRect.TopRight.z);
            IntVec3 spawnCell;

            foreach (IntVec3 cell in mapRect)
            {
                // Check all cells and abort if there is something indestructible found
                if (!CheckCell(cell, map))
                {
                    return;
                }
            }

            allSpawnedPawns = null;
            try
            {
                // Work through blueprint. Note: top-left to bottom-right
                for (int zn = 0; zn < blueprint.size.z; zn++)
                {
                    for (int x = 0; x < blueprint.size.x; x++)
                    {
                        //// map can be clipped, don't work with the clipped parts
                        //if (x > mapRect.Width - 1 || zn > mapRect.Height - 1)
                        //    continue;

                        spawnCell = spawnBaseCell + new IntVec3(x, 0, -zn);

                        int         itemPos     = x + blueprint.size.x * zn;
                        ThingDef    thingDef    = TryGetThingDefFromBuildingData(blueprint, itemPos);
                        Rot4        thingRot    = TryGetRotationFromBuildingData(blueprint, itemPos);
                        TerrainDef  terrainDef  = TryGetTerrainDefFromFloorData(blueprint, itemPos);
                        PawnKindDef pawnKindDef = TryGetPawnKindDefFromPawnData(blueprint, itemPos);
                        ThingDef    itemDef     = TryGetItemDefFromItemData(blueprint, itemPos);

                        List <Thing> list = map.thingGrid.ThingsListAt(spawnCell);
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].def == thingDef)
                            {
                                continue;
                            }
                        }

                        //Only clear the space, if something will be made here
                        if (thingDef != null || terrainDef != null || pawnKindDef != null || itemDef != null)
                        {
                            ClearCell(spawnCell, map);
                        }

                        if ((blueprint.canHaveHoles ||
                             (MapGenerator_ModSettings.createAllNonPawnBPsWithHoles && (blueprint.pawnLegend == null || blueprint.pawnLegend.Count <= 0))) &&
                            Rand.Value < MapGenerator_ModSettings.chanceForHoles)
                        {
                            continue;
                        }

                        // If placed on water, increase the hole chance, if no pawns are to be placed!
                        if (spawnCell.GetTerrain(map).defName.ToLower().Contains("water") &&
                            (blueprint.pawnLegend == null || blueprint.pawnLegend.Count <= 0) &&
                            Rand.Value < MapGenerator_ModSettings.chanceForHolesOnWater)
                        {
                            continue;
                        }

                        TrySetCellAs(spawnCell, map, thingDef, thingRot, stuffDef, terrainDef, pawnKindDef, itemDef, blueprint);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Warning("Misc. MapGenerator -- Error with blueprint '" + blueprint.defName + "'. Placement position at " +
                            mapRect.CenterCell.ToString() + " on a map of the size " + map.Size.ToString() + "\n" +
                            ex.Message + "\n" + ex.StackTrace);
            }


            // If pawns are spawned, place ancient shrine trigger
            if (allSpawnedPawns != null && allSpawnedPawns.Count > 0)
            {
                int    nextSignalTagID = Find.UniqueIDsManager.GetNextSignalTagID();
                string signalTag       = "ancientTempleApproached-" + nextSignalTagID;
                SignalAction_Letter signalAction_Letter = (SignalAction_Letter)ThingMaker.MakeThing(ThingDefOf.SignalAction_Letter, null);
                signalAction_Letter.signalTag = signalTag;
                signalAction_Letter.letter    = LetterMaker.MakeLetter("LetterLabelAncientShrineWarning".Translate(), "AncientShrineWarning".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(mapRect.CenterCell, map, false));
                GenSpawn.Spawn(signalAction_Letter, mapRect.CenterCell, map);
                RectTrigger rectTrigger = (RectTrigger)ThingMaker.MakeThing(ThingDefOf.RectTrigger, null);
                rectTrigger.signalTag         = signalTag;
                rectTrigger.Rect              = mapRect.ExpandedBy(1).ClipInsideMap(map);
                rectTrigger.destroyIfUnfogged = true;
                GenSpawn.Spawn(rectTrigger, mapRect.CenterCell, map);
            }

            // also if pawns are spawned make the appropriate LordJob
            LordJob lordJob;

            if (allSpawnedPawns != null && allSpawnedPawns.Count > 0)
            {
                if (blueprint.factionSelection == FactionSelection.friendly)
                {
                    lordJob = new LordJob_AssistColony(allSpawnedPawns[0].Faction, allSpawnedPawns[0].Position);
                }
                else
                {
                    if (Rand.Value < 0.5f)
                    {
                        lordJob = new LordJob_DefendPoint(allSpawnedPawns[0].Position);
                    }
                    else
                    {
                        lordJob = new LordJob_AssaultColony(allSpawnedPawns[0].Faction, false, false, false, false, false);
                    }
                }
                LordMaker.MakeNewLord(allSpawnedPawns[0].Faction, lordJob, map, allSpawnedPawns);

                allSpawnedPawns = null;
            }
        }
Esempio n. 10
0
        public static bool ExplosionAffectCell(DamageWorker __instance, Explosion explosion, IntVec3 c, List <Thing> damagedThings, List <Thing> ignoredThings, bool canThrowMotes)
        {
            if (__instance.def.explosionCellMote != null && canThrowMotes)
            {
                Mote mote = c.GetFirstThing(explosion.Map, __instance.def.explosionCellMote) as Mote;
                if (mote != null)
                {
                    mote.spawnTick = Find.TickManager.TicksGame;
                }
                else
                {
                    float t     = Mathf.Clamp01((explosion.Position - c).LengthHorizontal / explosion.radius);
                    Color color = Color.Lerp(__instance.def.explosionColorCenter, __instance.def.explosionColorEdge, t);
                    MoteMaker.ThrowExplosionCell(c, explosion.Map, __instance.def.explosionCellMote, color);
                }
            }

            //thingsToAffect.Clear();
            List <Thing> thingsToAffect = new List <Thing>();
            float        num            = float.MinValue;
            bool         flag           = false;
            List <Thing> list           = explosion.Map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (thing.def.category != ThingCategory.Mote && thing.def.category != ThingCategory.Ethereal)
                {
                    thingsToAffect.Add(thing);
                    if (thing.def.Fillage == FillCategory.Full && thing.def.Altitude > num)
                    {
                        flag = true;
                        num  = thing.def.Altitude;
                    }
                }
            }

            for (int j = 0; j < thingsToAffect.Count; j++)
            {
                if (thingsToAffect[j].def.Altitude >= num) //Null Reference Exception
                {
                    ExplosionDamageThing(__instance, explosion, thingsToAffect[j], damagedThings, ignoredThings, c);
                }
            }

            if (!flag)
            {
                ExplosionDamageTerrain(__instance, explosion, c);
            }

            if (__instance.def.explosionSnowMeltAmount > 0.0001f)
            {
                float lengthHorizontal = (c - explosion.Position).LengthHorizontal;
                float num2             = 1f - lengthHorizontal / explosion.radius;
                if (num2 > 0f)
                {
                    explosion.Map.snowGrid.AddDepth(c, (0f - num2) * __instance.def.explosionSnowMeltAmount);
                }
            }

            if (__instance.def != DamageDefOf.Bomb && __instance.def != DamageDefOf.Flame)
            {
                return(false);
            }

            List <Thing> list2 = explosion.Map.listerThings.ThingsOfDef(ThingDefOf.RectTrigger);

            for (int k = 0; k < list2.Count; k++)
            {
                RectTrigger rectTrigger = (RectTrigger)list2[k];
                if (rectTrigger.activateOnExplosion && rectTrigger.Rect.Contains(c))
                {
                    rectTrigger.ActivatedBy(null);
                }
            }
            return(false);
        }
        public override void ExplosionAffectCell(Explosion explosion, IntVec3 c, List <Thing> damagedThings, List <Thing> ignoredThings, bool canThrowMotes)
        {
            if (this.def.explosionCellMote != null && canThrowMotes)
            {
                Mote mote = c.GetFirstThing(explosion.Map, this.def.explosionCellMote) as Mote;
                if (mote != null)
                {
                    mote.spawnTick = Find.TickManager.TicksGame;
                }
                else
                {
                    float t     = Mathf.Clamp01((explosion.Position - c).LengthHorizontal / explosion.radius);
                    Color color = Color.Lerp(this.def.explosionColorCenter, this.def.explosionColorEdge, t);
                    PurpleIvyMoteMaker.ThrowExplosionCell(c, explosion.Map, this.def.explosionCellMote, color);
                }
            }
            DamageWorker_AddInjuryNoCamShaker.thingsToAffect.Clear();
            float        num  = float.MinValue;
            bool         flag = false;
            List <Thing> list = explosion.Map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (thing.def.category != ThingCategory.Mote && thing.def.category != ThingCategory.Ethereal)
                {
                    if (thing.Faction != PurpleIvyData.AlienFaction)
                    {
                        DamageWorker_AddInjuryNoCamShaker.thingsToAffect.Add(thing);
                        if (thing.def.Fillage == FillCategory.Full && thing.def.Altitude > num)
                        {
                            flag = true;
                            num  = thing.def.Altitude;
                        }
                    }
                }
            }
            for (int j = 0; j < DamageWorker_AddInjuryNoCamShaker.thingsToAffect.Count; j++)
            {
                if (DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j].def.Altitude >= num)
                {
                    if (DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j] is Pawn)
                    {
                        Pawn pawn = (Pawn)DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j];
                        if (Rand.Chance(0.3f))
                        {
                            pawn.stances.stunner.StunFor(Rand.RangeInclusive(100, 200), explosion.instigator);
                        }
                    }
                    this.ExplosionDamageThing(explosion, DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j], damagedThings, ignoredThings, c);
                }
            }
            if (!flag)
            {
                this.ExplosionDamageTerrain(explosion, c);
            }
            if (this.def.explosionSnowMeltAmount > 0.0001f)
            {
                float lengthHorizontal = (c - explosion.Position).LengthHorizontal;
                float num2             = 1f - lengthHorizontal / explosion.radius;
                if (num2 > 0f)
                {
                    explosion.Map.snowGrid.AddDepth(c, -num2 * this.def.explosionSnowMeltAmount);
                }
            }
            if (this.def == DamageDefOf.Bomb || this.def == DamageDefOf.Flame)
            {
                List <Thing> list2 = explosion.Map.listerThings.ThingsOfDef(ThingDefOf.RectTrigger);
                for (int k = 0; k < list2.Count; k++)
                {
                    RectTrigger rectTrigger = (RectTrigger)list2[k];
                    if (rectTrigger.activateOnExplosion && rectTrigger.Rect.Contains(c))
                    {
                        rectTrigger.ActivatedBy(null);
                    }
                }
            }
        }
        public override void Resolve(ResolveParams rp)
        {
            Map      map      = BaseGen.globalSettings.map;
            CellRect cellRect = CellRect.Empty;

            RimWorld.SketchGen.ResolveParams parms = default(RimWorld.SketchGen.ResolveParams);
            parms.sketch              = new Sketch();
            parms.monumentOpen        = false;
            parms.monumentSize        = new IntVec2(rp.rect.Width, rp.rect.Height);
            parms.allowMonumentDoors  = false;
            parms.allowWood           = false;
            parms.allowFlammableWalls = false;
            if (rp.allowedMonumentThings != null)
            {
                parms.allowedMonumentThings = rp.allowedMonumentThings;
            }
            else
            {
                parms.allowedMonumentThings = new ThingFilter();
                parms.allowedMonumentThings.SetAllowAll(null, includeNonStorable: true);
            }
            parms.allowedMonumentThings.SetAllow(ThingDefOf.Drape, allow: false);
            Sketch sketch = RimWorld.SketchGen.SketchGen.Generate(SketchResolverDefOf.Monument, parms);

            sketch.Spawn(map, rp.rect.CenterCell, null, Sketch.SpawnPosType.Unchanged, Sketch.SpawnMode.Normal, wipeIfCollides: true, clearEdificeWhereFloor: true, null, dormant: false, buildRoofsInstantly: true);
            CellRect rect = SketchGenUtility.FindBiggestRect(sketch, (IntVec3 x) => sketch.TerrainAt(x) != null && !sketch.ThingsAt(x).Any((SketchThing y) => y.def == ThingDefOf.Wall)).MovedBy(rp.rect.CenterCell);

            for (int i = 0; i < sketch.Things.Count; i++)
            {
                if (sketch.Things[i].def == ThingDefOf.Wall)
                {
                    IntVec3 c = sketch.Things[i].pos + rp.rect.CenterCell;
                    cellRect = ((!cellRect.IsEmpty) ? CellRect.FromLimits(Mathf.Min(cellRect.minX, c.x), Mathf.Min(cellRect.minZ, c.z), Mathf.Max(cellRect.maxX, c.x), Mathf.Max(cellRect.maxZ, c.z)) : CellRect.SingleCell(c));
                }
            }
            if (!rect.IsEmpty)
            {
                ResolveParams resolveParams = rp;
                resolveParams.rect = rect;
                if (rp.allowedMonumentThings != null)
                {
                    resolveParams.allowedMonumentThings = rp.allowedMonumentThings;
                }
                else
                {
                    resolveParams.allowedMonumentThings = new ThingFilter();
                    resolveParams.allowedMonumentThings.SetAllowAll(null, includeNonStorable: true);
                }
                if (ModsConfig.RoyaltyActive)
                {
                    resolveParams.allowedMonumentThings.SetAllow(ThingDefOf.Drape, allow: false);
                }
                BaseGen.symbolStack.Push("interior_ancientTemple", resolveParams);
            }
            if (rp.makeWarningLetter.HasValue && rp.makeWarningLetter.Value)
            {
                int    nextSignalTagID  = Find.UniqueIDsManager.GetNextSignalTagID();
                string signalTag        = "ancientTempleApproached-" + nextSignalTagID;
                SignalAction_Letter obj = (SignalAction_Letter)ThingMaker.MakeThing(ThingDefOf.SignalAction_Letter);
                obj.signalTag = signalTag;
                obj.letter    = LetterMaker.MakeLetter("LetterLabelAncientShrineWarning".Translate(), "AncientShrineWarning".Translate(), LetterDefOf.ThreatBig, new TargetInfo(cellRect.CenterCell, map));
                GenSpawn.Spawn(obj, cellRect.CenterCell, map);
                RectTrigger obj2 = (RectTrigger)ThingMaker.MakeThing(ThingDefOf.RectTrigger);
                obj2.signalTag         = signalTag;
                obj2.Rect              = cellRect.ExpandedBy(1).ClipInsideMap(map);
                obj2.destroyIfUnfogged = true;
                GenSpawn.Spawn(obj2, cellRect.CenterCell, map);
            }
        }