/**
  * Decreases the happiness with an amount calculated from the time since the last update cycle
  * multiplied by a constant (getNeedDecreaseSpeed). Needs to be called every update cycle to
  * calculate correctly.
  */
 void decreaseHappiness() {
   // Calculates the factor of decrease that should be multiplied
   // with the happiness
   float decreaseFactor =
       1 - (World.getEnvironment().getNeedDecreaseSpeed() * World.getWorld().getTimeSinceCycle());
   happiness *= decreaseFactor;
 }
 /**
  * Decreases the saturation with an amount calculated from the time since the last update cycle
  * multiplied by a constant (getNeedDecreaseSpeed). Needs to be called every update cycle to
  * calculate correctly.
  */
 void decreaseSaturation() {
   // Calculates the factor of decrease that should be multiplied
   // with the saturation
   float decreaseFactor =
       1 - (World.getEnvironment().getNeedDecreaseSpeed() * World.getWorld().getTimeSinceCycle());
   saturation *= decreaseFactor;
 }
  /** Constructs default characteristics. */
  public Characteristics(int gender, int age) {
    saturation = World.getEnvironment().getDefaultNeedValue();
    happiness = World.getEnvironment().getDefaultNeedValue();
    // The value will be recalculates immideately
    safety = 1.0f;

    // Set up the randomizers
    hungryRandomizer = new IntervalRandomizer(World.getEnvironment().getNeedInterval());
    depressedRandomizer = new IntervalRandomizer(World.getEnvironment().getNeedInterval());
    // TODO Take from Environment.
    unsafeRandomizer = new ProbabilityRandomizer(0.5f);
    strollRandomizer = new IntervalRandomizer(World.getEnvironment().getStrollInterval());

    // Set health, with max health as the full health
    maximumHealth = 1f;
    recalculateHealth();

    this.gender = gender;

    startAge = age;
    timeOfBirth = World.getWorld().getWorldTime();

    gatherSkill = World.getEnvironment().getDefaultSkillValue();
    sacrificeSkill = World.getEnvironment().getDefaultSkillValue();
    transportationSkill = World.getEnvironment().getDefaultSkillValue();
  }
 /**
  * Decreases the value of the transportation skill, using a formula containing getTimeSinceCycle
  * and getSkillDecreaseSpeed.
  */
 private void decreaseTransportationSkill() {
   // Decreases the transportation skill with the speed multiplied by the
   // timeSinceCycle, but then modified with a factor of how close
   // the mininimum skill value the current skill is. This means that
   // the skill will never decrease to less than 0f.
   transportationSkill -=
       World.getEnvironment().getSkillDecreaseSpeed()
           * World.getWorld().getTimeSinceCycle()
           * transportationSkill;
 }
 /**
  * Sets the safety according to the given Point. The safety is calculated through the distance
  * from the light pillar, with a constant (getSacrificedUnitsDistanceRatio).
  *
  * @param point the Point describing the position of the owner of the characteristics.
  */
 void setSafety(Point point) {
   LightPillarNode lightPillar = World.getWorld().getLightPillar();
   float distance = point.distanceTo(lightPillar.getPoint());
   distance = distance - lightPillar.getInfluenceRadius();
   if (distance > 0) {
     // Decreases the safety (which is 1) with the percentual value
     // that is defined by safetyDecreaseFactor. The decrease is made
     // distance times, so that safety = safetyDecrease ^ distance.
     safety = (float) Math.pow(World.getEnvironment().getSafetyDecreaseFactor(), distance);
   } else {
     safety = 1;
   }
 }
 /**
  * Increases the value of the transportation skill, using a formula containing getTimeSinceCycle
  * and getSkillIncreaseSpeed.
  */
 public void increaseTransportationSkill() {
   // Children to dont get better or worse in any skills.
   if (!isChild()) {
     // Increases the transportation skill with the speed multiplied by the
     // timeSinceCycle, but then modified with a factor of how close
     // the maximum skill value the current skill is. This means that
     // the skill will never increase to over 1f.
     transportationSkill +=
         World.getEnvironment().getSkillIncreaseSpeed()
             * World.getWorld().getTimeSinceCycle()
             * (1f - transportationSkill);
     // Decrease the other two skills.
     decreaseSacrificeSkill();
     decreaseGatherSkill();
   }
 }
  /**
   * Recalculates the health using the mean value of the three needs and the time since the last
   * cycle. Health cannot be greater than the current maximum health, which is decreased constantly
   * with a percentual constant. Needs to be called every update cycle to calculate correctly.
   */
  void recalculateHealth() {
    // Calculates the factor of decrease that should be multiplied
    // with the maximum health
    if (!isChild()) {
      float agingFactor =
          1 - (World.getEnvironment().getAgingFactor() * World.getWorld().getTimeSinceCycle());
      maximumHealth *= agingFactor;
    }

    float newHealth = (saturation + happiness + (safety / 2f)) / 3f;
    if (newHealth > maximumHealth) {
      newHealth = maximumHealth;
    }

    health = newHealth;
  }
 /**
  * Returns an integer representing the age in pseudo years, as and individual would experience it.
  * The age is calculated from a constant (getTimeYearRatio()).
  *
  * @return a int representing the age in pseudo years.
  */
 public int getAge() {
   return (int)
           ((World.getWorld().getWorldTime() - timeOfBirth)
               / World.getEnvironment().getYearSecondsRatio())
       + startAge;
 }