Beispiel #1
0
 public static string ShowConstructionValue(Pawn p)
 {
     if (PawnBuildingUtility.HealthyColonist(p))
     {
         return(String.Format("{0:0.##}", PawnBuildingUtility.ConstructionValue(p)));
     }
     if (PawnBuildingUtility.HealthyPackAnimal(p))
     {
         return(String.Format("+{0:0.##}", PawnBuildingUtility.ConstructionValue(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);
        }