예제 #1
0
        public static string ShowBestRoad(Pawn p)
        {
            RoadDef BestRoadDef = null;

            if (PawnBuildingUtility.HealthyColonist(p))
            {
                foreach (RoadDef thisDef in DefDatabase <RoadDef> .AllDefs)
                {
                    if (thisDef.HasModExtension <DefModExtension_RotR_RoadDef>() && thisDef.GetModExtension <DefModExtension_RotR_RoadDef>().built) // Only add RoadDefs that are buildable, based on DefModExtension_RotR_RoadDef.built
                    {
                        DefModExtension_RotR_RoadDef RoadDefMod = thisDef.GetModExtension <DefModExtension_RotR_RoadDef>();
                        if (PawnBuildingUtility.ConstructionLevel(p) >= RoadDefMod.minConstruction)
                        {
                            if ((BestRoadDef == null) || (thisDef.movementCostMultiplier < BestRoadDef.movementCostMultiplier))
                            {
                                BestRoadDef = thisDef;
                            }
                        }
                    }
                }
                if (BestRoadDef != null)
                {
                    return(BestRoadDef.label);
                }
            }
            return("-");
        }
예제 #2
0
 public static string ShowSkill(Pawn p)
 {
     if (PawnBuildingUtility.HealthyColonist(p))
     {
         return(String.Format("{0:0}", PawnBuildingUtility.ConstructionLevel(p)));
     }
     return("-");
 }
        /*
         * Amount of work :
         * - Construction speed (0.5 + 0.15 per level) times the construct success chance (0.75 to 1.13 - lvl 8 is 1)
         * - Pack animals help as well (see below)
         */
        public float AmountOfWork(bool verbose = false)
        {
            var pawns = GetCaravan().PawnsListForReading;
            DefModExtension_RotR_RoadDef roadDefModExtension = null;

            try
            {
                roadDefModExtension = site.roadDef.GetModExtension <DefModExtension_RotR_RoadDef>();
            }
            catch
            {
                /* Either there's no site, no roaddef, or no modextension. In any case, not much to do here */
            }

            //site.roadDef.GetModExtension<DefModExtension_RotR_RoadDef>().minConstruction ;
            var totalConstruction = 0f;
            var totalConstructionAboveMinLevel = 0f;
            var animalConstruction             = 0f;

            foreach (var pawn in pawns)
            {
                /*
                 * if (pawn.IsFreeColonist && pawn.health.State == PawnHealthState.Mobile)
                 * {
                 *  totalConstruction += pawn.GetStatValue(StatDefOf.ConstructionSpeed) * pawn.GetStatValue(StatDefOf.ConstructSuccessChance);
                 *
                 *  if (roadDefModExtension!=null && pawn.skills.GetSkill(SkillDefOf.Construction).levelInt >= roadDefModExtension.minConstruction)
                 *  {
                 *      totalConstructionAboveMinLevel += pawn.GetStatValue(StatDefOf.ConstructionSpeed) * pawn.GetStatValue(StatDefOf.ConstructSuccessChance);
                 *  }
                 * }
                 * else if (pawn.RaceProps.packAnimal  && pawn.health.State == PawnHealthState.Mobile)
                 * {
                 *  animalConstruction += pawn.GetStatValue(StatDefOf.ConstructionSpeed) * pawn.GetStatValue(StatDefOf.ConstructSuccessChance);
                 * }
                 */
                var PawnConstructionValue = PawnBuildingUtility.ConstructionValue(pawn);

                if (PawnBuildingUtility.HealthyColonist(pawn))
                {
                    totalConstruction += PawnConstructionValue;

                    if (roadDefModExtension != null && PawnBuildingUtility.ConstructionLevel(pawn) >=
                        roadDefModExtension.minConstruction)
                    {
                        totalConstructionAboveMinLevel += PawnConstructionValue;
                    }

                    continue;
                }

                if (PawnBuildingUtility.HealthyPackAnimal(pawn))
                {
                    animalConstruction += PawnConstructionValue;
                }
            }

            if (roadDefModExtension != null)
            {
                var ratioOfConstructionAboveMinLevel = totalConstructionAboveMinLevel / totalConstruction;
                if (ratioOfConstructionAboveMinLevel < roadDefModExtension.percentageOfminConstruction)
                {
                    // Check minimum construction level requirements if needed
                    var ratioActuallyWorked = ratioOfConstructionAboveMinLevel /
                                              roadDefModExtension.percentageOfminConstruction;
                    totalConstruction *= ratioActuallyWorked;
                    if (verbose)
                    {
                        Messages.Message(
                            "RoadsOfTheRim_InsufficientConstructionMinLevel".Translate(totalConstruction,
                                                                                       roadDefModExtension.percentageOfminConstruction.ToString("P0"),
                                                                                       roadDefModExtension.minConstruction), MessageTypeDefOf.NegativeEvent);
                    }
                }
            }

            // Pack animals can only add as much work as humans (i.e. : at best, pack animals double the amount of work)
            if (animalConstruction > totalConstruction)
            {
                animalConstruction = totalConstruction;
            }

            totalConstruction += animalConstruction;
            return(totalConstruction);
        }