示例#1
0
        internal static ThingWithComps findBestMeleeWeapon(Pawn pawn, bool skipDangerous /*, SelectionMode mode*/, Pawn target)
        {
            List <Thing> weapons = getWeaponsOfType(pawn, WeaponSearchType.MeleeCapable);

            if (pawn.equipment != null && pawn.equipment.Primary != null)
            {
                weapons.Add(pawn.equipment.Primary);
            }
            weapons.Add(null);  //for considering unarmed attacks

            /*string candList = "";
             * foreach (Thing thing in weapons)
             *  candList += (thing == null) ? " unarmed" : " " + thing.def.defName;
             * Log.Message("Considering melee swap, candidates:"+candList);*/

            Thing best      = null;
            float bestSoFar = float.MinValue;

            foreach (Thing thing in weapons)
            {
                if (skipDangerous)
                {
                    if (isDangerousWeapon(thing as ThingWithComps))
                    {
                        continue;
                    }
                }

                float dpsAvg = -1f;

                dpsAvg = StatCalculator.MeleeDPS(pawn, thing as ThingWithComps, SpeedSelectionBiasMelee.Value, target);

                /*if(thing == null)
                 *  Log.Message("DPS for unarmed is " + dpsAvg);
                 * else
                 *  Log.Message("DPS for " + thing.def.defName + " is " + dpsAvg);*/

                if (dpsAvg > bestSoFar)
                {
                    bestSoFar = dpsAvg;
                    best      = thing;
                }
            }

            /*if (best == null)
             *  Log.Message("best: unarmed");
             * else
             *  Log.Message("best: " + best.def.defName);*/

            return(best as ThingWithComps);
        }
示例#2
0
        internal static ThingWithComps findBestMeleeWeapon(Pawn pawn, bool skipDangerous /*, SelectionMode mode*/, Pawn target)
        {
            List <Thing> weapons = getWeaponsOfType(pawn, WeaponSearchType.Melee);

            Thing best      = pawn.equipment.Primary;
            float bestSoFar = best == null ? float.MinValue :
                              StatCalculator.MeleeDPS(pawn, best as ThingWithComps, SpeedSelectionBiasMelee.Value, target);

            foreach (Thing thing in weapons)
            {
                if (!(thing is ThingWithComps))
                {
                    continue;
                }

                if (skipDangerous)
                {
                    if (isDangerousWeapon(thing as ThingWithComps))
                    {
                        continue;
                    }
                }

                float dpsAvg = -1f;

                dpsAvg = StatCalculator.MeleeDPS(pawn, thing as ThingWithComps, SpeedSelectionBiasMelee.Value, target);

                if (dpsAvg > bestSoFar)
                {
                    bestSoFar = dpsAvg;
                    best      = thing;
                }
            }

            if (StatCalculator.MeleeDPS(pawn, null, SpeedSelectionBiasMelee.Value, target) > bestSoFar)
            {
                best = null;
            }

            return(best as ThingWithComps);
        }
示例#3
0
        internal static ThingWithComps findBestMeleeWeapon(Pawn pawn, bool skipDangerous, out bool unarmedIsBetter /*, SelectionMode mode*/)
        {
            List <Thing> weapons = getWeaponsOfType(pawn, WeaponSearchType.Melee);

            float bestSoFar = float.MinValue;
            Thing best      = null;

            foreach (Thing thing in weapons)
            {
                if (!(thing is ThingWithComps))
                {
                    continue;
                }

                if (skipDangerous)
                {
                    if (isDangerousWeapon(thing as ThingWithComps))
                    {
                        continue;
                    }
                }

                float dpsAvg = -1f;

                dpsAvg = StatCalculator.MeleeDPS(pawn, thing as ThingWithComps, SpeedSelectionBiasMelee.Value);

                if (dpsAvg > bestSoFar)
                {
                    bestSoFar = dpsAvg;
                    best      = thing;
                }
            }

            unarmedIsBetter = StatCalculator.UnarmedDPS(pawn, SpeedSelectionBiasMelee.Value) > bestSoFar;

            return(best as ThingWithComps);
        }