Beispiel #1
0
 static void Postfix(Caravan __instance, ref bool __result)
 {
     if (!__instance.IsHashIntervalTick(60))
     {
         __result = Base.Instance.cachedResult;
         return;
     }
     if (Base.Instance.GetExtendedDataStorage() is ExtendedDataStorage store)
     {
         if (store.GetExtendedDataFor(__instance) is ExtendedCaravanData data)
         {
             if (data.forceRest)
             {
                 __result = true;
             }
             if (data.fullyIgnoreRest)
             {
                 __result = false;
             }
             if (data.almostThere)
             {
                 var estimatedTicks = (float)CaravanArrivalTimeEstimator.EstimatedTicksToArrive(__instance, allowCaching: true);
                 var restTicksLeft  = CaravanNightRestUtility.LeftRestTicksAt(__instance.Tile, Find.TickManager.TicksAbs);
                 estimatedTicks -= restTicksLeft;
                 if (estimatedTicks / GenDate.TicksPerHour < Base.almostThereHours.Value)
                 {
                     __result = false;
                 }
             }
         }
     }
     Base.Instance.cachedResult = __result;
 }
        /*
         * Faction help must be handled here, since it's independent of whether or not a caravan is here.
         * Make it with a delay of 1/50 s compared to the CaravanComp so both functions end up playing nicely along each other
         * Don't work at night !
         */
        public override void CompTick()
        {
            try
            {
                if (((RoadConstructionSite)parent).helpFromFaction == null ||
                    CaravanNightRestUtility.RestingNowAt(((RoadConstructionSite)parent).Tile) ||
                    Find.TickManager.TicksGame % 100 != 50)
                {
                    return;
                }

                ((RoadConstructionSite)parent).TryToSkipBetterRoads();  // No need to work if there's a better road here
                var amountOfWork = ((RoadConstructionSite)parent).FactionHelp();

                var percentOfWorkLeftToDoAfter = (GetLeft("Work") - amountOfWork) / GetCost("Work");
                foreach (var resourceName in DefModExtension_RotR_RoadDef.allResources)
                {
                    ReduceLeft(resourceName,
                               (int)Math.Round(GetLeft(resourceName) - (percentOfWorkLeftToDoAfter * GetCost(resourceName))));
                }

                UpdateProgress(amountOfWork);
            }
            catch (Exception e)
            {
                RoadsOfTheRim.DebugLog("Construction Site CompTick. parentsite = " + (RoadConstructionSite)parent, e);
            }
        }
Beispiel #3
0
        /*
         * Faction help must be handled here, since it's independent of whether or not a caravan is here.
         * Make it with a delay of 1/50 s compared to the CaravanComp so both functions end up playing nicely along each other
         * Don't work at night !
         */
        public override void CompTick()
        {
            try
            {
                if ((((RoadConstructionSite)parent).helpFromFaction != null) && (!CaravanNightRestUtility.RestingNowAt(((RoadConstructionSite)parent).Tile)) && (Find.TickManager.TicksGame % 100 == 50))
                {
                    ((RoadConstructionSite)parent).TryToSkipBetterRoads();   // No need to work if there's a better road here
                    float amountOfWork = ((RoadConstructionSite)parent).factionHelp();

                    float percentOfWorkLeftToDoAfter = ((float)GetLeft("Work") - amountOfWork) / (float)GetCost("Work");
                    foreach (string resourceName in DefModExtension_RotR_RoadDef.allResources)
                    {
                        ReduceLeft(resourceName, (int)Math.Round((float)GetLeft(resourceName) - (percentOfWorkLeftToDoAfter * (float)GetCost(resourceName))));
                    }
                    UpdateProgress(amountOfWork);
                }
            }
            catch (Exception e)
            {
                RoadsOfTheRim.DebugLog("Construction Site CompTick. parentsite = " + ((RoadConstructionSite)parent), e);
            }
        }