public static void AssignKeys(ThinkNode rootNode, int startHash)
 {
     Rand.PushState();
     Rand.Seed = startHash;
     foreach (ThinkNode current in rootNode.ThisAndChildrenRecursive)
     {
         current.SetUniqueSaveKey(ThinkTreeKeyAssigner.NextUnusedKey());
     }
     Rand.PopState();
 }
        private void PrintScratches(Building b)
        {
            int num = 0;
            List <DamageOverlay> overlays = BuildingsDamageSectionLayerUtility.GetOverlays(b);

            for (int i = 0; i < overlays.Count; i++)
            {
                if (overlays[i] == DamageOverlay.Scratch)
                {
                    num++;
                }
            }
            if (num == 0)
            {
                return;
            }
            Rect  damageRect = BuildingsDamageSectionLayerUtility.GetDamageRect(b);
            float num2       = Mathf.Min(0.5f * Mathf.Min(damageRect.width, damageRect.height), 1f);

            damageRect = damageRect.ContractedBy(num2 / 2f);
            if (damageRect.width <= 0f || damageRect.height <= 0f)
            {
                return;
            }
            float minDist = Mathf.Max(damageRect.width, damageRect.height) * 0.7f;

            scratches.Clear();
            Rand.PushState();
            Rand.Seed = b.thingIDNumber * 3697;
            for (int j = 0; j < num; j++)
            {
                AddScratch(b, damageRect.width, damageRect.height, ref minDist);
            }
            Rand.PopState();
            float            damageTexturesAltitude = GetDamageTexturesAltitude(b);
            IList <Material> scratchMats            = BuildingsDamageSectionLayerUtility.GetScratchMats(b);

            Rand.PushState();
            Rand.Seed = b.thingIDNumber * 7;
            for (int k = 0; k < scratches.Count; k++)
            {
                float x    = scratches[k].x;
                float y    = scratches[k].y;
                float rot  = Rand.Range(0f, 360f);
                float num3 = num2;
                if (damageRect.width > 0.95f && damageRect.height > 0.95f)
                {
                    num3 *= Rand.Range(0.85f, 1f);
                }
                Vector3 center = new Vector3(damageRect.xMin + x, damageTexturesAltitude, damageRect.yMin + y);
                Printer_Plane.PrintPlane(this, center, new Vector2(num3, num3), scratchMats.RandomElement(), rot, flipUv: false, null, null, 0f);
            }
            Rand.PopState();
        }
示例#3
0
        public void ResolveAllGraphics()
        {
            ClearCache();
            if (pawn.RaceProps.Humanlike)
            {
                nakedGraphic               = GraphicDatabase.Get <Graphic_Multi>(pawn.story.bodyType.bodyNakedGraphicPath, ShaderDatabase.CutoutSkin, Vector2.one, pawn.story.SkinColor);
                rottingGraphic             = GraphicDatabase.Get <Graphic_Multi>(pawn.story.bodyType.bodyNakedGraphicPath, ShaderDatabase.CutoutSkin, Vector2.one, RottingColor);
                dessicatedGraphic          = GraphicDatabase.Get <Graphic_Multi>(pawn.story.bodyType.bodyDessicatedGraphicPath, ShaderDatabase.Cutout);
                headGraphic                = GraphicDatabaseHeadRecords.GetHeadNamed(pawn.story.HeadGraphicPath, pawn.story.SkinColor);
                desiccatedHeadGraphic      = GraphicDatabaseHeadRecords.GetHeadNamed(pawn.story.HeadGraphicPath, RottingColor);
                skullGraphic               = GraphicDatabaseHeadRecords.GetSkull();
                headStumpGraphic           = GraphicDatabaseHeadRecords.GetStump(pawn.story.SkinColor);
                desiccatedHeadStumpGraphic = GraphicDatabaseHeadRecords.GetStump(RottingColor);
                hairGraphic                = GraphicDatabase.Get <Graphic_Multi>(pawn.story.hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, pawn.story.hairColor);
                ResolveApparelGraphics();
                return;
            }
            PawnKindLifeStage curKindLifeStage = pawn.ageTracker.CurKindLifeStage;

            if (pawn.gender != Gender.Female || curKindLifeStage.femaleGraphicData == null)
            {
                nakedGraphic = curKindLifeStage.bodyGraphicData.Graphic;
            }
            else
            {
                nakedGraphic = curKindLifeStage.femaleGraphicData.Graphic;
            }
            if (pawn.RaceProps.packAnimal)
            {
                packGraphic = GraphicDatabase.Get <Graphic_Multi>(nakedGraphic.path + "Pack", ShaderDatabase.Cutout, nakedGraphic.drawSize, Color.white);
            }
            rottingGraphic = nakedGraphic.GetColoredVersion(ShaderDatabase.CutoutSkin, RottingColor, RottingColor);
            if (curKindLifeStage.dessicatedBodyGraphicData != null)
            {
                if (pawn.gender != Gender.Female || curKindLifeStage.femaleDessicatedBodyGraphicData == null)
                {
                    dessicatedGraphic = curKindLifeStage.dessicatedBodyGraphicData.GraphicColoredFor(pawn);
                }
                else
                {
                    dessicatedGraphic = curKindLifeStage.femaleDessicatedBodyGraphicData.GraphicColoredFor(pawn);
                }
            }
            if (!pawn.kindDef.alternateGraphics.NullOrEmpty())
            {
                Rand.PushState(pawn.thingIDNumber ^ 0xB415);
                if (Rand.Value <= pawn.kindDef.alternateGraphicChance)
                {
                    nakedGraphic = pawn.kindDef.alternateGraphics.RandomElementByWeight((AlternateGraphic x) => x.Weight).GetGraphic(nakedGraphic);
                }
                Rand.PopState();
            }
        }
        protected override string ToGameStringFromPOV_Worker(Thing pov, bool forceLog)
        {
            if (this.initiator == null || this.recipient == null)
            {
                Log.ErrorOnce("PlayLogEntry_Interaction has a null pawn reference.", 34422, false);
                return("[" + this.intDef.label + " error: null pawn reference]");
            }
            Rand.PushState();
            Rand.Seed = this.logID;
            GrammarRequest request = base.GenerateGrammarRequest();
            string         text;

            if (pov == this.initiator)
            {
                request.IncludesBare.Add(this.intDef.logRulesInitiator);
                request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, request.Constants));
                request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipient, request.Constants));
                text = GrammarResolver.Resolve("r_logentry", request, "interaction from initiator", forceLog, null);
            }
            else if (pov == this.recipient)
            {
                if (this.intDef.logRulesRecipient != null)
                {
                    request.IncludesBare.Add(this.intDef.logRulesRecipient);
                }
                else
                {
                    request.IncludesBare.Add(this.intDef.logRulesInitiator);
                }
                request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, request.Constants));
                request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipient, request.Constants));
                text = GrammarResolver.Resolve("r_logentry", request, "interaction from recipient", forceLog, null);
            }
            else
            {
                Log.ErrorOnce("Cannot display PlayLogEntry_Interaction from POV who isn't initiator or recipient.", 51251, false);
                text = this.ToString();
            }
            if (this.extraSentencePacks != null)
            {
                for (int i = 0; i < this.extraSentencePacks.Count; i++)
                {
                    request.Clear();
                    request.Includes.Add(this.extraSentencePacks[i]);
                    request.Rules.AddRange(GrammarUtility.RulesForPawn("INITIATOR", this.initiator, request.Constants));
                    request.Rules.AddRange(GrammarUtility.RulesForPawn("RECIPIENT", this.recipient, request.Constants));
                    text = text + " " + GrammarResolver.Resolve(this.extraSentencePacks[i].FirstRuleKeyword, request, "extraSentencePack", forceLog, this.extraSentencePacks[i].FirstUntranslatedRuleKeyword);
                }
            }
            Rand.PopState();
            return(text);
        }
        public override string ToGameStringFromPOV(Thing pov)
        {
            if (this.initiator == null || this.recipient == null)
            {
                Log.ErrorOnce("PlayLogEntry_Interaction has a null pawn reference.", 34422);
                return("[" + this.intDef.label + " error: null pawn reference]");
            }
            Rand.PushState();
            Rand.Seed = this.randSeed;
            GrammarRequest request = default(GrammarRequest);
            string         text;

            if (pov == this.initiator)
            {
                request.Rules.AddRange(this.intDef.logRulesInitiator.Rules);
                request.Rules.AddRange(GrammarUtility.RulesForPawn("me", this.initiator, request.Constants));
                request.Rules.AddRange(GrammarUtility.RulesForPawn("other", this.recipient, request.Constants));
                text = GrammarResolver.Resolve("logentry", request, "interaction from initiator", false);
            }
            else if (pov == this.recipient)
            {
                if (this.intDef.logRulesRecipient != null)
                {
                    request.Rules.AddRange(this.intDef.logRulesRecipient.Rules);
                }
                else
                {
                    request.Rules.AddRange(this.intDef.logRulesInitiator.Rules);
                }
                request.Rules.AddRange(GrammarUtility.RulesForPawn("me", this.recipient, request.Constants));
                request.Rules.AddRange(GrammarUtility.RulesForPawn("other", this.initiator, request.Constants));
                text = GrammarResolver.Resolve("logentry", request, "interaction from recipient", false);
            }
            else
            {
                Log.ErrorOnce("Cannot display PlayLogEntry_Interaction from POV who isn't initiator or recipient.", 51251);
                text = this.ToString();
            }
            if (this.extraSentencePacks != null)
            {
                for (int i = 0; i < this.extraSentencePacks.Count; i++)
                {
                    request.Clear();
                    request.Includes.Add(this.extraSentencePacks[i]);
                    request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiator, request.Constants));
                    request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipient, request.Constants));
                    text = text + " " + GrammarResolver.Resolve(this.extraSentencePacks[i].RulesPlusIncludes[0].keyword, request, "extraSentencePack", false);
                }
            }
            Rand.PopState();
            return(text);
        }
        public override void DrawWorker(Vector3 loc, Rot4 rot, ThingDef thingDef, Thing thing, float extraRotation)
        {
            Rand.PushState();
            Rand.Seed = thing.thingIDNumber.GetHashCode();
            float     angle  = (float)Rand.Range(0, 360) + ((thing as Gas)?.graphicRotation ?? 0f);
            Vector3   pos    = thing.TrueCenter() + new Vector3(Rand.Range(-0.45f, 0.45f), 0f, Rand.Range(-0.45f, 0.45f));
            Vector3   s      = new Vector3(Rand.Range(0.8f, 1.2f) * drawSize.x, 0f, Rand.Range(0.8f, 1.2f) * drawSize.y);
            Matrix4x4 matrix = default(Matrix4x4);

            matrix.SetTRS(pos, Quaternion.AngleAxis(angle, Vector3.up), s);
            Graphics.DrawMesh(MeshPool.plane10, matrix, MatSingle, 0);
            Rand.PopState();
        }
示例#7
0
        private void PrintScratches(Building b)
        {
            int num = 0;
            List <DamageOverlay> overlays = BuildingsDamageSectionLayerUtility.GetOverlays(b);

            for (int i = 0; i < overlays.Count; i++)
            {
                if (overlays[i] == DamageOverlay.Scratch)
                {
                    num++;
                }
            }
            if (num != 0)
            {
                Rect  rect = BuildingsDamageSectionLayerUtility.GetDamageRect(b);
                float num2 = Mathf.Min((float)(0.5 * Mathf.Min(rect.width, rect.height)), 1f);
                rect = rect.ContractedBy((float)(num2 / 2.0));
                if (!(rect.width <= 0.0) && !(rect.height <= 0.0))
                {
                    float num3 = (float)(Mathf.Max(rect.width, rect.height) * 0.699999988079071);
                    SectionLayer_BuildingsDamage.scratches.Clear();
                    Rand.PushState();
                    Rand.Seed = b.thingIDNumber * 3697;
                    for (int j = 0; j < num; j++)
                    {
                        this.AddScratch(b, rect.width, rect.height, ref num3);
                    }
                    Rand.PopState();
                    float            damageTexturesAltitude = this.GetDamageTexturesAltitude(b);
                    IList <Material> scratchMats            = BuildingsDamageSectionLayerUtility.GetScratchMats(b);
                    Rand.PushState();
                    Rand.Seed = b.thingIDNumber * 7;
                    for (int k = 0; k < SectionLayer_BuildingsDamage.scratches.Count; k++)
                    {
                        Vector2 vector  = SectionLayer_BuildingsDamage.scratches[k];
                        float   x       = vector.x;
                        Vector2 vector2 = SectionLayer_BuildingsDamage.scratches[k];
                        float   y       = vector2.y;
                        float   rot     = Rand.Range(0f, 360f);
                        float   num4    = num2;
                        if (rect.width > 0.949999988079071 && rect.height > 0.949999988079071)
                        {
                            num4 *= Rand.Range(0.85f, 1f);
                        }
                        Vector3 center = new Vector3(rect.xMin + x, damageTexturesAltitude, rect.yMin + y);
                        Printer_Plane.PrintPlane(this, center, new Vector2(num4, num4), scratchMats.RandomElement(), rot, false, null, null, 0f);
                    }
                    Rand.PopState();
                }
            }
        }
 private void PrintCornersAndEdges(Building b)
 {
     Rand.PushState();
     Rand.Seed = b.thingIDNumber * 3;
     if (BuildingsDamageSectionLayerUtility.UsesLinkableCornersAndEdges(b))
     {
         DrawLinkableCornersAndEdges(b);
     }
     else
     {
         DrawFullThingCorners(b);
     }
     Rand.PopState();
 }
示例#9
0
 private void CreateListIfShould()
 {
     if (this.randomizedCells == null)
     {
         this.randomizedCells = new List <IntVec3>(this.map.Area);
         foreach (IntVec3 item in this.map.AllCells)
         {
             this.randomizedCells.Add(item);
         }
         Rand.PushState();
         Rand.Seed = (Find.World.info.Seed ^ this.map.Tile);
         this.randomizedCells.Shuffle <IntVec3>();
         Rand.PopState();
     }
 }
 private void CreateListIfShould()
 {
     if (randomizedCells == null)
     {
         randomizedCells = new List <IntVec3>(map.Area);
         foreach (IntVec3 allCell in map.AllCells)
         {
             randomizedCells.Add(allCell);
         }
         Rand.PushState();
         Rand.Seed = (Find.World.info.Seed ^ map.Tile);
         randomizedCells.Shuffle();
         Rand.PopState();
     }
 }
        public override string ToGameStringFromPOV(Thing pov)
        {
            Rand.PushState();
            Rand.Seed = base.randSeed;
            GrammarRequest request = default(GrammarRequest);

            request.Includes.Add(RulePackDefOf.Combat_ExplosionImpact);
            if (this.initiatorPawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiatorPawn, request.Constants));
            }
            else if (this.initiatorThing != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("initiator", this.initiatorThing));
            }
            else
            {
                request.Constants["initiator_missing"] = "True";
            }
            if (this.recipientPawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipientPawn, request.Constants));
            }
            else if (this.recipientThing != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("recipient", this.recipientThing));
            }
            else
            {
                request.Constants["recipient_missing"] = "True";
            }
            request.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("weapon", this.weaponDef, this.projectileDef));
            if (this.projectileDef != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("projectile", this.projectileDef));
            }
            if (this.damageDef != null && this.damageDef.combatLogRules != null)
            {
                request.Includes.Add(this.damageDef.combatLogRules);
            }
            request.Rules.AddRange(PlayLogEntryUtility.RulesForDamagedParts("recipient_part", this.damagedParts, this.damagedPartsDestroyed, request.Constants));
            string result = GrammarResolver.Resolve("logentry", request, "ranged explosion", false);

            Rand.PopState();
            return(result);
        }
示例#12
0
        public override string ToGameStringFromPOV(Thing pov)
        {
            if (this.recipientPawn == null)
            {
                Log.ErrorOnce("BattleLogEntry_DamageTaken has a null recipient.", 60465709);
                return("[BattleLogEntry_DamageTaken error: null pawn reference]");
            }
            Rand.PushState();
            Rand.Seed = base.randSeed;
            GrammarRequest request = default(GrammarRequest);

            request.Includes.Add(this.ruleDef);
            request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipientPawn, request.Constants));
            request.Rules.AddRange(PlayLogEntryUtility.RulesForDamagedParts("recipient_part", this.damagedParts, this.damagedPartsDestroyed, request.Constants));
            string result = GrammarResolver.Resolve("logentry", request, "damage taken", false);

            Rand.PopState();
            return(result);
        }
        public override void Print(SectionLayer layer, Thing thing)
        {
            Vector3 a = thing.TrueCenter();

            Rand.PushState();
            Rand.Seed = thing.Position.GetHashCode();
            int num = (thing as Filth)?.thickness ?? 3;

            for (int i = 0; i < num; i++)
            {
                Material matSingle = MatSingle;
                Vector3  center    = a + new Vector3(Rand.Range(-0.45f, 0.45f), 0f, Rand.Range(-0.45f, 0.45f));
                Vector2  size      = new Vector2(Rand.Range(data.drawSize.x * 0.8f, data.drawSize.x * 1.2f), Rand.Range(data.drawSize.y * 0.8f, data.drawSize.y * 1.2f));
                float    rot       = Rand.RangeInclusive(0, 360);
                bool     flipUv    = Rand.Value < 0.5f;
                Printer_Plane.PrintPlane(layer, center, size, matSingle, rot, flipUv);
            }
            Rand.PopState();
        }
示例#14
0
        public override string ToGameStringFromPOV(Thing pov)
        {
            if (this.initiatorPawn == null && this.initiatorThing == null)
            {
                Log.ErrorOnce("BattleLogEntry_RangedFire has a null initiator.", 60465709);
                return("[BattleLogEntry_RangedFire error: null pawn reference]");
            }
            Rand.PushState();
            Rand.Seed = base.randSeed;
            GrammarRequest request = default(GrammarRequest);

            request.Includes.Add(RulePackDefOf.Combat_RangedFire);
            if (this.initiatorPawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiatorPawn, request.Constants));
            }
            else if (this.initiatorThing != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("initiator", this.initiatorThing));
            }
            else
            {
                request.Constants["initiator_missing"] = "True";
            }
            if (this.recipientPawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipientPawn, request.Constants));
            }
            else if (this.recipientThing != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("recipient", this.recipientThing));
            }
            else
            {
                request.Constants["recipient_missing"] = "True";
            }
            request.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("weapon", this.weaponDef, this.projectileDef));
            request.Constants["burst"] = this.burst.ToString();
            string result = GrammarResolver.Resolve("logentry", request, "ranged fire", false);

            Rand.PopState();
            return(result);
        }
        public override string ToGameStringFromPOV(Thing pov)
        {
            Rand.PushState();
            Rand.Seed = base.randSeed;
            GrammarRequest request = default(GrammarRequest);

            request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiator, request.Constants));
            if (this.recipientPawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipientPawn, request.Constants));
            }
            else if (this.recipientThing != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("recipient", this.recipientThing));
            }
            request.Includes.Add(this.outcomeRuleDef);
            request.Includes.Add(this.maneuverRuleDef);
            if (!this.toolLabel.NullOrEmpty())
            {
                request.Rules.Add(new Rule_String("tool_label", this.toolLabel));
            }
            if (this.implementType != null && !this.implementType.implementOwnerRuleName.NullOrEmpty())
            {
                if (this.ownerEquipmentDef != null)
                {
                    request.Rules.AddRange(GrammarUtility.RulesForDef(this.implementType.implementOwnerRuleName, this.ownerEquipmentDef));
                }
                else if (this.ownerHediffDef != null)
                {
                    request.Rules.AddRange(GrammarUtility.RulesForDef(this.implementType.implementOwnerRuleName, this.ownerHediffDef));
                }
            }
            if (this.implementType != null && !this.implementType.implementOwnerTypeValue.NullOrEmpty())
            {
                request.Constants["implementOwnerType"] = this.implementType.implementOwnerTypeValue;
            }
            request.Rules.AddRange(PlayLogEntryUtility.RulesForDamagedParts("recipient_part", this.damagedParts, this.damagedPartsDestroyed, request.Constants));
            string result = GrammarResolver.Resolve("logentry", request, "combat interaction", false);

            Rand.PopState();
            return(result);
        }
示例#16
0
        public static CellRect FindLargestRect(Map map, Predicate <IntVec3> predicate, int breakEarlyOn = -1)
        {
            if (visited == null)
            {
                visited = new BoolGrid(map);
            }
            visited.ClearAndResizeTo(map);
            Rand.PushState(map.uniqueID ^ 0x1CDAF373);
            CellRect largestRect = CellRect.Empty;

            for (int i = 0; i < 3; i++)
            {
                tmpProcessed.Clear();
                foreach (IntVec3 item in map.cellsInRandomOrder.GetAll().InRandomOrder(randomOrderWorkingList))
                {
                    CellRect cellRect = FindLargestRectAt(item, map, tmpProcessed, predicate);
                    if (cellRect.Area > largestRect.Area)
                    {
                        largestRect = cellRect;
                        if (ShouldBreakEarly())
                        {
                            break;
                        }
                    }
                }
                if (ShouldBreakEarly())
                {
                    break;
                }
            }
            Rand.PopState();
            return(largestRect);

            bool ShouldBreakEarly()
            {
                if (breakEarlyOn >= 0 && largestRect.Width >= breakEarlyOn)
                {
                    return(largestRect.Height >= breakEarlyOn);
                }
                return(false);
            }
        }
        public override void Print(SectionLayer layer, Thing thing)
        {
            Vector3 a = thing.TrueCenter();

            Rand.PushState();
            Rand.Seed = thing.Position.GetHashCode();
            Filth filth = thing as Filth;
            int   num   = (filth != null) ? filth.thickness : 3;

            for (int i = 0; i < num; i++)
            {
                Material matSingle = this.MatSingle;
                Vector3  center    = a + new Vector3(Rand.Range(-0.45f, 0.45f), 0f, Rand.Range(-0.45f, 0.45f));
                Vector2  size      = new Vector2(Rand.Range(0.8f, 1.2f), Rand.Range(0.8f, 1.2f));
                float    rot       = (float)Rand.RangeInclusive(0, 360);
                bool     flipUv    = Rand.Value < 0.5;
                Printer_Plane.PrintPlane(layer, center, size, matSingle, rot, flipUv, null, null, 0.01f);
            }
            Rand.PopState();
        }
示例#18
0
 public string ToGameStringFromPOV(Thing pov, bool forceLog = false)
 {
     if (cachedString == null || pov == null != (cachedStringPov == null) || (cachedStringPov != null && pov != cachedStringPov.Target) || DebugViewSettings.logGrammarResolution || forceLog)
     {
         Rand.PushState();
         try
         {
             Rand.Seed         = logID;
             cachedStringPov   = ((pov != null) ? new WeakReference <Thing>(pov) : null);
             cachedString      = ToGameStringFromPOV_Worker(pov, forceLog);
             cachedHeightWidth = 0f;
             cachedHeight      = 0f;
         }
         finally
         {
             Rand.PopState();
         }
     }
     return(cachedString);
 }
示例#19
0
 public static void GenerateContentsIntoMap(IEnumerable <GenStepWithParams> genStepDefs, Map map, int seed)
 {
     data.Clear();
     Rand.PushState();
     try
     {
         Rand.Seed = seed;
         RockNoises.Init(map);
         tmpGenSteps.Clear();
         tmpGenSteps.AddRange(from x in genStepDefs
                              orderby x.def.order, x.def.index
                              select x);
         for (int i = 0; i < tmpGenSteps.Count; i++)
         {
             GenStepWithParams genStepWithParams = tmpGenSteps[i];
             DeepProfiler.Start("GenStep - " + genStepWithParams.def);
             try
             {
                 Rand.Seed = Gen.HashCombineInt(seed, GetSeedPart(tmpGenSteps, i));
                 GenStepWithParams genStepWithParams2 = tmpGenSteps[i];
                 GenStep           genStep            = genStepWithParams2.def.genStep;
                 GenStepWithParams genStepWithParams3 = tmpGenSteps[i];
                 genStep.Generate(map, genStepWithParams3.parms);
             }
             catch (Exception arg)
             {
                 Log.Error("Error in GenStep: " + arg);
             }
             finally
             {
                 DeepProfiler.End();
             }
         }
     }
     finally
     {
         Rand.PopState();
         RockNoises.Reset();
         data.Clear();
     }
 }
示例#20
0
        public float ImmunityChangePerTick(Pawn pawn, bool sick, Hediff diseaseInstance)
        {
            if (!pawn.RaceProps.IsFlesh)
            {
                return(0f);
            }
            HediffCompProperties_Immunizable hediffCompProperties_Immunizable = this.hediffDef.CompProps <HediffCompProperties_Immunizable>();

            if (sick)
            {
                float num = hediffCompProperties_Immunizable.immunityPerDaySick;
                num *= pawn.GetStatValue(StatDefOf.ImmunityGainSpeed, true);
                if (diseaseInstance != null)
                {
                    Rand.PushState();
                    Rand.Seed = Gen.HashCombineInt(diseaseInstance.loadID ^ Find.World.info.persistentRandomValue, 156482735);
                    num      *= Mathf.Lerp(0.8f, 1.2f, Rand.Value);
                    Rand.PopState();
                }
                return(num / 60000f);
            }
            return(hediffCompProperties_Immunizable.immunityPerDayNotSick / 60000f);
        }
示例#21
0
        public static List <DamageOverlay> GetOverlays(Building b)
        {
            BuildingsDamageSectionLayerUtility.overlays.Clear();
            BuildingsDamageSectionLayerUtility.overlaysWorkingList.Clear();
            BuildingsDamageSectionLayerUtility.overlaysWorkingList.AddRange(BuildingsDamageSectionLayerUtility.GetAvailableOverlays(b));
            if (!BuildingsDamageSectionLayerUtility.overlaysWorkingList.Any())
            {
                return(BuildingsDamageSectionLayerUtility.overlays);
            }
            Rand.PushState();
            Rand.Seed = Gen.HashCombineInt(b.thingIDNumber, 1958376471);
            int damageOverlaysCount = BuildingsDamageSectionLayerUtility.GetDamageOverlaysCount(b, b.HitPoints);
            int num = 0;

            while (num < damageOverlaysCount && BuildingsDamageSectionLayerUtility.overlaysWorkingList.Any())
            {
                DamageOverlay item = BuildingsDamageSectionLayerUtility.overlaysWorkingList.RandomElement();
                BuildingsDamageSectionLayerUtility.overlaysWorkingList.Remove(item);
                BuildingsDamageSectionLayerUtility.overlays.Add(item);
                num++;
            }
            Rand.PopState();
            return(BuildingsDamageSectionLayerUtility.overlays);
        }
示例#22
0
        public override string ToGameStringFromPOV(Thing pov)
        {
            Rand.PushState();
            Rand.Seed = base.randSeed;
            GrammarRequest request = default(GrammarRequest);

            if (this.subjectPawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("subject", this.subjectPawn, request.Constants));
            }
            else if (this.subjectThing != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("subject", this.subjectThing));
            }
            request.Includes.Add(this.transitionDef);
            if (this.initiator != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiator, request.Constants));
            }
            if (this.culpritHediffDef != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("culpritHediff", this.culpritHediffDef));
            }
            if (this.culpritHediffTargetDef != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("culpritHediff_target", this.culpritHediffTargetDef));
            }
            if (this.culpritTargetDef != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("culpritHediff_originaltarget", this.culpritTargetDef));
            }
            string result = GrammarResolver.Resolve("logentry", request, "state transition", false);

            Rand.PopState();
            return(result);
        }
示例#23
0
 public static void PushState(int replacementSeed)
 {
     Rand.PushState();
     Rand.Seed = replacementSeed;
 }
示例#24
0
        protected void MakeMote(TargetInfo A, TargetInfo B)
        {
            Vector3 vector = Vector3.zero;

            switch (def.spawnLocType)
            {
            case MoteSpawnLocType.OnSource:
                vector = A.CenterVector3;
                break;

            case MoteSpawnLocType.BetweenPositions:
            {
                Vector3 vector2 = A.HasThing ? A.Thing.DrawPos : A.Cell.ToVector3Shifted();
                Vector3 vector3 = B.HasThing ? B.Thing.DrawPos : B.Cell.ToVector3Shifted();
                vector = ((A.HasThing && !A.Thing.Spawned) ? vector3 : ((!B.HasThing || B.Thing.Spawned) ? (vector2 * def.positionLerpFactor + vector3 * (1f - def.positionLerpFactor)) : vector2));
                break;
            }

            case MoteSpawnLocType.RandomCellOnTarget:
                vector = ((!B.HasThing) ? CellRect.CenteredOn(B.Cell, 0) : B.Thing.OccupiedRect()).RandomCell.ToVector3Shifted();
                break;

            case MoteSpawnLocType.BetweenTouchingCells:
                vector = A.Cell.ToVector3Shifted() + (B.Cell - A.Cell).ToVector3().normalized * 0.5f;
                break;
            }
            if (parent != null)
            {
                Rand.PushState(parent.GetHashCode());
                if (A.CenterVector3 != B.CenterVector3)
                {
                    vector += (B.CenterVector3 - A.CenterVector3).normalized * parent.def.offsetTowardsTarget.RandomInRange;
                }
                vector += Gen.RandomHorizontalVector(parent.def.positionRadius);
                Rand.PopState();
            }
            Map   map = A.Map ?? B.Map;
            float num = def.absoluteAngle ? 0f : (B.Cell - A.Cell).AngleFlat;

            if (map == null || !vector.ShouldSpawnMotesAt(map))
            {
                return;
            }
            int randomInRange = def.burstCount.RandomInRange;

            for (int i = 0; i < randomInRange; i++)
            {
                Mote obj = (Mote)ThingMaker.MakeThing(def.moteDef);
                GenSpawn.Spawn(obj, vector.ToIntVec3(), map);
                obj.Scale         = def.scale.RandomInRange;
                obj.exactPosition = vector + Gen.RandomHorizontalVector(def.positionRadius);
                obj.rotationRate  = def.rotationRate.RandomInRange;
                obj.exactRotation = def.rotation.RandomInRange + num;
                obj.instanceColor = def.color;
                MoteThrown moteThrown = obj as MoteThrown;
                if (moteThrown != null)
                {
                    moteThrown.airTimeLeft = def.airTime.RandomInRange;
                    moteThrown.SetVelocity(def.angle.RandomInRange + num, def.speed.RandomInRange);
                }
            }
        }
示例#25
0
        public override string ToGameStringFromPOV(Thing pov)
        {
            Rand.PushState();
            Rand.Seed = this.randSeed;
            GrammarRequest request = default(GrammarRequest);

            if (this.recipientPawn != null || this.recipientThing != null)
            {
                request.Includes.Add(RulePackDefOf.Combat_RangedDamage);
            }
            else
            {
                request.Includes.Add(RulePackDefOf.Combat_RangedMiss);
            }
            if (this.initiatorPawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("initiator", this.initiatorPawn, request.Constants));
            }
            else if (this.initiatorThing != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("initiator", this.initiatorThing));
            }
            else
            {
                request.Constants["initiator_missing"] = "True";
            }
            if (this.recipientPawn != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForPawn("recipient", this.recipientPawn, request.Constants));
            }
            else if (this.recipientThing != null)
            {
                request.Rules.AddRange(GrammarUtility.RulesForDef("recipient", this.recipientThing));
            }
            else
            {
                request.Constants["recipient_missing"] = "True";
            }
            if (this.originalTargetPawn != this.recipientPawn || this.originalTargetThing != this.recipientThing)
            {
                if (this.originalTargetPawn != null)
                {
                    request.Rules.AddRange(GrammarUtility.RulesForPawn("originalTarget", this.originalTargetPawn, request.Constants));
                    request.Constants["originalTarget_mobile"] = this.originalTargetMobile.ToString();
                }
                else if (this.originalTargetThing != null)
                {
                    request.Rules.AddRange(GrammarUtility.RulesForDef("originalTarget", this.originalTargetThing));
                }
                else
                {
                    request.Constants["originalTarget_missing"] = "True";
                }
            }
            request.Rules.AddRange(PlayLogEntryUtility.RulesForOptionalWeapon("weapon", this.weaponDef, this.projectileDef));
            request.Rules.AddRange(PlayLogEntryUtility.RulesForDamagedParts("recipient_part", this.damagedParts, this.damagedPartsDestroyed, request.Constants));
            string result = GrammarResolver.Resolve("logentry", request, "ranged damage", false);

            Rand.PopState();
            return(result);
        }
示例#26
0
        internal static void RandTests()
        {
            StringBuilder stringBuilder = new StringBuilder();
            int           @int          = Rand.Int;

            stringBuilder.AppendLine("Repeating single ValueSeeded with seed " + @int + ". This should give the same result:");
            for (int i = 0; i < 4; i++)
            {
                stringBuilder.AppendLine("   " + Rand.ValueSeeded(@int));
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Long-term tests");
            for (int j = 0; j < 3; j++)
            {
                int num = 0;
                for (int k = 0; k < 5000000; k++)
                {
                    if (Rand.MTBEventOccurs(250f, 60000f, 60f))
                    {
                        num++;
                    }
                }
                string value = string.Concat(new object[]
                {
                    "MTB=",
                    250,
                    " days, MTBUnit=",
                    60000,
                    ", check duration=",
                    60,
                    " Simulated ",
                    5000,
                    " days (",
                    5000000,
                    " tests). Got ",
                    num,
                    " events."
                });
                stringBuilder.AppendLine(value);
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Short-term tests");
            for (int l = 0; l < 5; l++)
            {
                int num2 = 0;
                for (int m = 0; m < 10000; m++)
                {
                    if (Rand.MTBEventOccurs(1f, 24000f, 12000f))
                    {
                        num2++;
                    }
                }
                string value2 = string.Concat(new object[]
                {
                    "MTB=",
                    1f,
                    " days, MTBUnit=",
                    24000f,
                    ", check duration=",
                    12000f,
                    ", ",
                    10000,
                    " tests got ",
                    num2,
                    " events."
                });
                stringBuilder.AppendLine(value2);
            }
            for (int n = 0; n < 5; n++)
            {
                int num3 = 0;
                for (int num4 = 0; num4 < 10000; num4++)
                {
                    if (Rand.MTBEventOccurs(2f, 24000f, 6000f))
                    {
                        num3++;
                    }
                }
                string value3 = string.Concat(new object[]
                {
                    "MTB=",
                    2f,
                    " days, MTBUnit=",
                    24000f,
                    ", check duration=",
                    6000f,
                    ", ",
                    10000,
                    " tests got ",
                    num3,
                    " events."
                });
                stringBuilder.AppendLine(value3);
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Near seed tests");
            DebugHistogram debugHistogram = new DebugHistogram(new float[]
            {
                0f,
                0.1f,
                0.2f,
                0.3f,
                0.4f,
                0.5f,
                0.6f,
                0.7f,
                0.8f,
                0.9f,
                1f
            });

            Rand.PushState();
            for (int num5 = 0; num5 < 1000; num5++)
            {
                Rand.Seed = num5;
                debugHistogram.Add(Rand.Value);
            }
            Rand.PopState();
            debugHistogram.Display(stringBuilder);
            Log.Message(stringBuilder.ToString(), false);
        }
示例#27
0
 public static void AssignSingleKey(ThinkNode node, int startHash)
 {
     Rand.PushState(startHash);
     node.SetUniqueSaveKey(ThinkTreeKeyAssigner.NextUnusedKeyFor(node));
     Rand.PopState();
 }
        protected void MakeMote(TargetInfo A, TargetInfo B)
        {
            Vector3 vector = Vector3.zero;

            switch (this.def.spawnLocType)
            {
            case MoteSpawnLocType.OnSource:
                vector = A.CenterVector3;
                break;

            case MoteSpawnLocType.BetweenPositions:
            {
                Vector3 vector2 = (!A.HasThing) ? A.Cell.ToVector3Shifted() : A.Thing.DrawPos;
                Vector3 vector3 = (!B.HasThing) ? B.Cell.ToVector3Shifted() : B.Thing.DrawPos;
                if (A.HasThing && !A.Thing.Spawned)
                {
                    vector = vector3;
                }
                else if (B.HasThing && !B.Thing.Spawned)
                {
                    vector = vector2;
                }
                else
                {
                    vector = vector2 * this.def.positionLerpFactor + vector3 * (1f - this.def.positionLerpFactor);
                }
                break;
            }

            case MoteSpawnLocType.BetweenTouchingCells:
                vector = A.Cell.ToVector3Shifted() + (B.Cell - A.Cell).ToVector3().normalized * 0.5f;
                break;

            case MoteSpawnLocType.RandomCellOnTarget:
            {
                CellRect cellRect;
                if (B.HasThing)
                {
                    cellRect = B.Thing.OccupiedRect();
                }
                else
                {
                    cellRect = CellRect.CenteredOn(B.Cell, 0);
                }
                vector = cellRect.RandomCell.ToVector3Shifted();
                break;
            }
            }
            if (this.parent != null)
            {
                Rand.PushState(this.parent.GetHashCode());
                if (A.CenterVector3 != B.CenterVector3)
                {
                    vector += (B.CenterVector3 - A.CenterVector3).normalized * this.parent.def.offsetTowardsTarget.RandomInRange;
                }
                vector += Gen.RandomHorizontalVector(this.parent.def.positionRadius);
                Rand.PopState();
            }
            Map   map = A.Map ?? B.Map;
            float num = (!this.def.absoluteAngle) ? (B.Cell - A.Cell).AngleFlat : 0f;

            if (map != null && vector.ShouldSpawnMotesAt(map))
            {
                int randomInRange = this.def.burstCount.RandomInRange;
                for (int i = 0; i < randomInRange; i++)
                {
                    Mote mote = (Mote)ThingMaker.MakeThing(this.def.moteDef, null);
                    GenSpawn.Spawn(mote, vector.ToIntVec3(), map, WipeMode.Vanish);
                    mote.Scale         = this.def.scale.RandomInRange;
                    mote.exactPosition = vector + Gen.RandomHorizontalVector(this.def.positionRadius);
                    mote.rotationRate  = this.def.rotationRate.RandomInRange;
                    mote.exactRotation = this.def.rotation.RandomInRange + num;
                    MoteThrown moteThrown = mote as MoteThrown;
                    if (moteThrown != null)
                    {
                        moteThrown.airTimeLeft = this.def.airTime.RandomInRange;
                        moteThrown.SetVelocity(this.def.angle.RandomInRange + num, this.def.speed.RandomInRange);
                    }
                }
            }
        }
示例#29
0
        public static Map GenerateMap(IntVec3 mapSize, MapParent parent, MapGeneratorDef mapGenerator, IEnumerable <GenStepWithParams> extraGenStepDefs = null, Action <Map> extraInitBeforeContentGen = null)
        {
            ProgramState programState = Current.ProgramState;

            Current.ProgramState            = ProgramState.MapInitializing;
            MapGenerator.playerStartSpotInt = IntVec3.Invalid;
            MapGenerator.rootsToUnfog.Clear();
            MapGenerator.data.Clear();
            MapGenerator.mapBeingGenerated = null;
            DeepProfiler.Start("InitNewGeneratedMap");
            Rand.PushState();
            int seed = Gen.HashCombineInt(Find.World.info.Seed, parent.Tile);

            Rand.Seed = seed;
            Map result;

            try
            {
                if (parent != null && parent.HasMap)
                {
                    Log.Error("Tried to generate a new map and set " + parent + " as its parent, but this world object already has a map. One world object can't have more than 1 map.", false);
                    parent = null;
                }
                DeepProfiler.Start("Set up map");
                Map map = new Map();
                map.uniqueID = Find.UniqueIDsManager.GetNextMapID();
                MapGenerator.mapBeingGenerated = map;
                map.info.Size   = mapSize;
                map.info.parent = parent;
                map.ConstructComponents();
                DeepProfiler.End();
                Current.Game.AddMap(map);
                if (extraInitBeforeContentGen != null)
                {
                    extraInitBeforeContentGen(map);
                }
                if (mapGenerator == null)
                {
                    Log.Error("Attempted to generate map without generator; falling back on encounter map", false);
                    mapGenerator = MapGeneratorDefOf.Encounter;
                }
                IEnumerable <GenStepWithParams> enumerable = from x in mapGenerator.genSteps
                                                             select new GenStepWithParams(x, default(GenStepParams));
                if (extraGenStepDefs != null)
                {
                    enumerable = enumerable.Concat(extraGenStepDefs);
                }
                map.areaManager.AddStartingAreas();
                map.weatherDecider.StartInitialWeather();
                DeepProfiler.Start("Generate contents into map");
                MapGenerator.GenerateContentsIntoMap(enumerable, map, seed);
                DeepProfiler.End();
                Find.Scenario.PostMapGenerate(map);
                DeepProfiler.Start("Finalize map init");
                map.FinalizeInit();
                DeepProfiler.End();
                DeepProfiler.Start("MapComponent.MapGenerated()");
                MapComponentUtility.MapGenerated(map);
                DeepProfiler.End();
                if (parent != null)
                {
                    parent.PostMapGenerate();
                }
                result = map;
            }
            finally
            {
                DeepProfiler.End();
                MapGenerator.mapBeingGenerated = null;
                Current.ProgramState           = programState;
                Rand.PopState();
            }
            return(result);
        }