/** 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 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;
 }
 /**
  * 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;
 }
  /**
   * Calculates if the owner of the characteristics is unsafe, and then returns the result as a
   * boolean.
   *
   * @returns a boolean stating if the owner of the characteristics is unsafe.
   */
  public boolean isUnsafe() {

    // Make it more likely to feel unsafe when the safety is very low
    float probabilityModifier = World.getEnvironment().getDefaultNeedValue() / safety;

    // Time to get safe?
    if (unsafeRandomizer.isSuccessful(probabilityModifier)) {
      return true;
    } else {
      return false;
    }
  }
  /**
   * Calculates if the owner of the characteristics is depressed, and then returns the result as a
   * boolean.
   *
   * @returns a boolean stating if the owner of the characteristics is depressed.
   */
  public boolean isDepressed() {

    // Make it more likely to eat when we're really depressed.
    float probabilityModifier = World.getEnvironment().getDefaultNeedValue() / happiness;

    // Time to get happy?
    if (depressedRandomizer.isSuccessful(probabilityModifier)) {
      return true;
    } else {
      return false;
    }
  }
  /**
   * Calculates if the owner of the characteristics is hungry, and then returns the result as a
   * boolean.
   *
   * @returns a boolean stating if the owner of the characteristics is hungry.
   */
  public boolean isHungry() {

    // Make it more likely to eat when we're really hungry.
    float probabilityModifier = World.getEnvironment().getDefaultNeedValue() / saturation;

    // Time to eat?
    if (hungryRandomizer.isSuccessful(probabilityModifier)) {
      return true;
    } else {
      return false;
    }
  }
 /**
  * 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();
   }
 }
示例#10
0
  /**
   * 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;
  }
示例#11
0
 /**
  * "Converts" a percentual value (like a skill) to a factor value (like the efficiency). A
  * percentual value goes from 0 to 1f and has a default value of 0.5f, a factor goes from 0 to
  * infinity and has a default value of 1f.
  *
  * @param a percentual value to be converted.
  * @return the given percentual value as a factor value.
  */
 private float percentToFactor(float percentualValue) {
   // Takes for example a skill, which is default 0.5f and adds 0.5f
   // resulting in a factor of 1f, which would (correctly) not affect a
   // value it's multiplied with.
   return percentualValue + World.getEnvironment().getDefaultSkillValue();
 }
示例#12
0
 /**
  * Tests if the current age (getAge) is under a constant getAdultAge(). If so, the Individual is a
  * child.
  *
  * @return a boolean stating if the Indiviudal is a child.
  */
 public boolean isChild() {
   return getAge() < World.getEnvironment().getAdultAge();
 }
示例#13
0
 /**
  * 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;
 }
示例#14
0
 /** Increases the happiness with an amount specified by a constant (getUnitNeedRatio). */
 public void increaseHappiness() {
   happiness += World.getEnvironment().getUnitNeedRatio();
   if (happiness > 1f) {
     happiness = 1f;
   }
 }
示例#15
0
 /** Increases the saturation with an amount specified by a constant (getUnitNeedRatio). */
 public void increaseSaturation() {
   saturation += World.getEnvironment().getUnitNeedRatio();
   if (saturation > 1f) {
     saturation = 1f;
   }
 }