Пример #1
0
        private static List <Pawn> NVPawnSetSpawner
        (
            Map map, SkillDef skill, GlowTeam team, int count, IntVec3 spot,
            AorB side
        )
        {
            var     list    = new List <Pawn>();
            Faction faction = FactionUtility.DefaultFactionFrom(ft: side.fac);

            for (var i = 0; i < count; i++)
            {
                var pawngen = new PawnGenerationRequest(
                    kind: side.pkd,
                    faction: faction,
                    context: PawnGenerationContext.NonPlayer,
                    mustBeCapableOfViolence: true,
                    forceGenerateNewPawn: true,
                    worldPawnFactionDoesntMatter: true
                    );

                Pawn newPawn = PawnGenerator.GeneratePawn(request: pawngen);
                newPawn.skills.GetSkill(skillDef: skill).Level = team.Skill;

                newPawn.story.traits.allTraits.RemoveAll(match: trt => side.undesired.Contains(item: trt.def.defName));

                if (team.GlowHediff != null)
                {
                    newPawn.health.AddHediff(
                        def: team.GlowHediff,
                        part: newPawn.RaceProps.body.GetPartsWithTag(tag: BodyPartTagDefOf.ConsciousnessSource).First()
                        );
                }

                IntVec3 loc = CellFinder.RandomClosewalkCellNear(root: spot, map: map, radius: 12, extraValidator: null);
                GenSpawn.Spawn(newThing: newPawn, loc: loc, map: map, rot: Rot4.Random, wipeMode: WipeMode.Vanish, respawningAfterLoad: false);
                list.Add(item: newPawn);
            }

            LordMaker.MakeNewLord(faction: faction, lordJob: new LordJob_DefendPoint(point: map.Center), map: map, startingPawns: list);

            return(list);
        }
Пример #2
0
        private static void NightvisionArenaFight
        (
            SkillDef skill, AorB[]                           sides, GlowTeam lhsTeam, int lhsCount, GlowTeam rhsTeam,
            int rhsCount, Action <ArenaUtility.ArenaResult> callback
        )
        {
            var mapParent = (MapParent)WorldObjectMaker.MakeWorldObject(def: WorldObjectDefOf.Debug_Arena);

            mapParent.Tile = TileFinder.RandomSettlementTileFor(
                faction: Faction.OfPlayer,
                mustBeAutoChoosable: true,
                extraValidator: tile
                => Find.World.tileTemperatures.SeasonAndOutdoorTemperatureAcceptableFor(
                    tile: tile,
                    animalRace: ThingDef.Named(defName: "Human")
                    )
                );

            mapParent.SetFaction(newFaction: Faction.OfPlayer);
            Find.WorldObjects.Add(o: mapParent);

            Map orGenerateMap = GetOrGenerateMapUtility.GetOrGenerateMap(
                tile: mapParent.Tile,
                size: new IntVec3(newX: 50, newY: 1, newZ: 50),
                suggestedMapParentDef: null
                );

            IntVec3 spot;
            IntVec3 spot2;

            MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map: orGenerateMap, first: out spot, second: out spot2);
            List <Pawn> lhs2      = NVPawnSetSpawner(map: orGenerateMap, skill: skill, team: lhsTeam, count: lhsCount, spot: spot, side: sides[0]);
            List <Pawn> rhs2      = NVPawnSetSpawner(map: orGenerateMap, skill: skill, team: rhsTeam, count: rhsCount, spot: spot2, side: sides[1]);
            var         component = mapParent.GetComponent <DebugArena>();

            component.lhs      = lhs2;
            component.rhs      = rhs2;
            component.callback = callback;
        }
Пример #3
0
        public static void PerformBattleRoyale(SkillDef skill)
        {
            if (ArenaUtility.ValidateArenaCapability())
            {
                var ratings = new Dictionary <GlowTeam, float>();

                for (var i = 0; i < GlowHediffs.Length; i++)
                {
                    foreach (int skillLevel in SkillLevels)
                    {
                        float initialR = skillLevel * 10 * (1 + GlowLevels[i]);
                        var   newGT    = new GlowTeam(glowL: GlowHediffs[i], skill: skillLevel, rating: initialR);

                        ratings[key : newGT] = EloUtility.CalculateRating(teamScore : initialR, referenceRating : 1500f, referenceScore : 60f);
                    }
                }

                List <GlowTeam> Teams = ratings.Keys.ToList();
                AorB[]          sides;

                if (skill == Defs_Rimworld.MeleeSkill)
                {
                    sides = ABMelee;
                }
                else
                {
                    sides = ABShoot;
                }

                var currentFights  = 0;
                var completeFights = 0;

                Current.Game.GetComponent <GameComponent_DebugTools>().AddPerFrameCallback(
                    callback: delegate
                {
                    bool result2;

                    if (currentFights >= 15)
                    {
                        result2 = false;
                    }
                    else
                    {
                        GlowTeam lhsTeam = Teams.RandomElement();
                        GlowTeam rhsTeam = Teams.RandomElement();
                        float num        = EloUtility.CalculateExpectation(teamA: ratings[key: lhsTeam], teamB: ratings[key: rhsTeam]);
                        float num2       = 1f - num;
                        float num3       = num;
                        float num4       = Mathf.Min(a: num2, b: num3);
                        num2            /= num4;
                        num3            /= num4;
                        float num5       = Mathf.Max(a: num2, b: num3);

                        if (num5 > 40f)
                        {
                            result2 = false;
                        }
                        else
                        {
                            float num6 = 40f / num5;
                            var num7   = (float)Math.Exp(d: Rand.Range(min: 0f, max: (float)Math.Log(d: num6)));
                            num2      *= num7;
                            num3      *= num7;
                            int lhsNum = GenMath.RoundRandom(f: num2);
                            int rhsNum = GenMath.RoundRandom(f: num3);
                            currentFights++;

                            NightvisionArenaFight(
                                skill : skill,
                                sides : sides,
                                lhsTeam : lhsTeam,
                                lhsCount : lhsNum,
                                rhsTeam : rhsTeam,
                                rhsCount : rhsNum,
                                callback : delegate(ArenaUtility.ArenaResult result)
                            {
                                currentFights--;
                                completeFights++;

                                if (result.winner != ArenaUtility.ArenaResult.Winner.Other)
                                {
                                    float value   = ratings[key: lhsTeam];
                                    float value2  = ratings[key: rhsTeam];
                                    float kfactor = 8f * Mathf.Pow(f: 0.5f, p: Time.realtimeSinceStartup / 900f);

                                    EloUtility.Update(
                                        teamA: ref value,
                                        teamB: ref value2,
                                        expectedA: 0.5f,
                                        scoreA: result.winner != ArenaUtility.ArenaResult.Winner.Lhs ? 0 : 1,
                                        kfactor: kfactor
                                        );

                                    ratings[key: lhsTeam] = value;
                                    ratings[key: rhsTeam] = value2;

                                    Log.Message(
                                        text: string.Format(
                                            "Scores after {0} trials:\n\n{1}",
                                            completeFights,
                                            (
                                                from v in ratings orderby v.Value select string.Format(
                                                    "  {0}: {1}->{2} (rating {2})",
                                                    v.Key.Name,
                                                    v.Key.InitialRating,
                                                    EloUtility.CalculateLinearScore(
                                                        teamRating: v.Value,
                                                        referenceRating: 1500f,
                                                        referenceScore: 60f
                                                        ).ToString(format: "F0"),
                                                    v.Value.ToString(format: "F0")
                                                    )).ToLineList(prefix: "")
                                            ),
                                        ignoreStopLoggingLimit: false
                                        );
                                }
                            }
                                );

                            result2 = false;
                        }
                    }

                    return(result2);
                }
                    );
            }
        }