public override float MoodMultiplier(Pawn p)
        {
            Need_Hope            hope      = p.GetNeedHope();
            HopeWorker_TotalHope totalHope = p.GetTotalHope();

            if (hope == null || totalHope == null)
            {
                return(0);
            }
            float ratio = totalHope.CurrentHopeLevel / hope.MaxHopeRange;

            /*
             * We have a piecewise function:
             * from 0 to 0.5: linear 0.5x
             * from 0.5 onwards: quadratic x^2, capped to 1 (or -1 if negative)
             */
            if (Mathf.Abs(ratio) < 0.5f)
            {
                return(0.5f * Mathf.Abs(ratio));
            }
            else
            {
                float outputRatio = Mathf.Pow(Mathf.Clamp(ratio, -1, 1), 2);
                return(outputRatio);
            }
        }
Exemplo n.º 2
0
 public static HopeWorker_Rest GetRestHope(this Need_Hope hope)
 {
     if (hope == null)
     {
         return(null);
     }
     return(hope.AllHopeWorkers.Where((HopeWorker worker) => worker is HopeWorker_Rest).FirstOrDefault() as HopeWorker_Rest);
 }
Exemplo n.º 3
0
 public override void Tick150Interval()
 {
     // Recalculate hope level every once in a while
     hopeLevel = 0;
     if (hope == null)
     {
         hope = pawn.GetNeedHope();
     }
     if (hope == null)
     {
         return;
     }
     foreach (HopeWorker worker in hope.AllHopeWorkers)
     {
         if (worker == this)
         {
             continue;
         }
         hopeLevel += worker.CurrentHopeLevel;
     }
 }
        public static HopeState GetHopeStateOf(Pawn p)
        {
            Need_Hope            hope      = p.GetNeedHope();
            HopeWorker_TotalHope totalHope = p.GetTotalHope();

            if (hope == null || totalHope == null)
            {
                return(HopeState.NEUTRAL);
            }
            float hopePercentage = totalHope.CurrentHopeLevel / hope.MaxHopeRange;

            if (hopePercentage >= 1)
            {
                return(HopeState.VERY_HOPEFUL);
            }
            if (hopePercentage >= 0.5f)
            {
                return(HopeState.HOPEFUL);
            }
            if (hopePercentage >= 0.1f)
            {
                return(HopeState.SLIGHTLY_HOPEFUL);
            }
            if (hopePercentage <= -0.1f)
            {
                return(HopeState.SLIGHTLY_HOPELESS);
            }
            if (hopePercentage <= -0.5f)
            {
                return(HopeState.HOPELESS);
            }
            if (hopePercentage <= -1)
            {
                return(HopeState.VERY_HOPELESS);
            }
            return(HopeState.NEUTRAL);
        }