/**
  * 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;
 }
Beispiel #3
0
 /** Add all parts of the car to the world. */
 public void addToWorld(World world) {
   super.addToWorld(world);
   world.addObject(rightFront);
   world.addObject(rightRear);
   world.addObject(leftFront);
   world.addObject(leftRear);
 }
 /**
  * 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;
 }
  /** 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();
  }
 /**
  * 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;
  }
Beispiel #9
0
 /** @param world */
 public static void startGame(World world) {
   boolean playGame = true;
   while (playGame) {
     for (Obj obj : world.getObjs()) {
       obj.tick();
     }
   }
 }
  /**
   * 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;
    }
  }
  public static void main(String[] args) {
    // boolean makes sure game runs continuously
    boolean run = true;
    String name = null;

    // Creates the grid on which the characters move
    World theWorld = new World(10, 10, "Earth");

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // sets the username
    System.out.println("Welcome User. Please enter your NAME below.");
    try {
      name = br.readLine();
    } catch (IOException ioe) {
      System.out.println("Wow. You broke it. All I asked for was a name.");
      System.exit(1);
    }
    System.out.println("\n\n\n\n\n\nWelcome, " + name + ", to the world.");
    User b = new User(name, theWorld);
    Viewer a = new Viewer(theWorld, b);
    double str = 0;
    double sma = 0;
    double mor = 0;

    try {
      System.out.println(
          "Now, tell me a little about yourself.\n\nOn a scale of one to ten, how strong are you?\n1 is having trouble lifting this laptop, 10 is a participant in the 'World's Strongest Man' competitions.\nFeel free to use decimals.");
      str = (Double.parseDouble(br.readLine()));
      System.out.println(
          "\n\nGreat! Now, on a scale of one to ten, how would you place your intellect?\n1 is never having passed the first grade, 10 is Stephen Hawking.");
      sma = (Double.parseDouble(br.readLine()));
      System.out.println(
          "\n\nWell done! Now, for the final question, on a scale of one to ten, how moral are you?\n1 is cheating, stealing, and possibly even murdering without regret, 10 is never doing anything wrong ever, and feeling terrible when you tell even a little white lie.");
      mor = (Double.parseDouble(br.readLine()));
      b.setStats(str, sma, 10.7, 0, 0, 0, 0, 0, 500, mor);
    } catch (IOException ioe) {
      System.out.println("DON'T DO THAT. EVER.");
      System.exit(1);
    }
    try {
      System.out.println("Hit ENTER to continue.");
      br.readLine();
    } catch (IOException ioe) {
      System.out.println(
          "Really? You just had to hit ENTER. That's it. Nothing special, just a button I know you know how to press, because you just pressed it. God you're stupid. I'm glad you broke it. Saves me the trouble of watching you play.");
      System.exit(1);
    }

    // selects a random number of movers. Movers are the class that are the "characters"
    int characterNum = (int) Math.ceil(Math.random() * 20);

    // makes sure that there are no less than 10 movers at a time. It would be pretty boring to just
    // have one guy walking around on his own.
    while (characterNum < 10) {
      characterNum = (int) Math.ceil(Math.random() * 20);
    }

    // Populates the grid with movers. Their respective locations are randomly selected in their
    // constructors.
    for (int x = 0; x < characterNum; x++) {
      theWorld.createMover();
    }

    // Printing the world prints out a grid that shows where all of the movers are.
    System.out.println(theWorld);

    // Start of it all.
    while (run) {

      // Makes sure the input is readable
      String input = null;
      // String input2 = null;
      // String miscString = null;
      try {
        input = br.readLine();

      } catch (IOException ioe) {
        System.out.println("I don't know what you're saying. You lose. Automatically. Forever.");
        System.exit(1);
      }
      input = input.toLowerCase();

      if (!b.getMode()) {
        a.command(input);
      } else {
        b.start(input);
      }

      // allows the player to "hit enter to continue"
      System.out.println("");
      System.out.println("Type a command, or hit enter to continue");
    }
  }
 /**
  * "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();
 }
 /**
  * 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();
 }
 /**
  * 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;
 }
 /** Increases the saturation with an amount specified by a constant (getUnitNeedRatio). */
 public void increaseSaturation() {
   saturation += World.getEnvironment().getUnitNeedRatio();
   if (saturation > 1f) {
     saturation = 1f;
   }
 }
 /** Increases the happiness with an amount specified by a constant (getUnitNeedRatio). */
 public void increaseHappiness() {
   happiness += World.getEnvironment().getUnitNeedRatio();
   if (happiness > 1f) {
     happiness = 1f;
   }
 }
  public void startSetup() {
    clearAll();

    int i = 0;

    for (Player p : server.getOnlinePlayers()) {
      if (!isSpectator(p) && !isTribute(p)) {
        hidePlayer(p);
      }

      if (isTribute(p)) {
        if (i >= getTubes().size()) i = 0;

        Location to = getTubes().get(i);
        p.setHealth(20);
        p.setFoodLevel(20);
        p.setSprinting(false);
        p.setSneaking(false);
        p.setPassenger(null);
        p.setGameMode(GameMode.SURVIVAL);
        p.setFireTicks(0);
        clearItems(p);
        getTribute(p).start = to;
        p.teleport(toCenter(to));

        i++;
      }
    }

    for (String s : ServerGames.worlds) {
      World w = ServerGames.server.getWorld(s);
      w.getEntities().clear();
      w.setThundering(false);
      w.setTime(0);
      w.setWeatherDuration(0);
      w.setStorm(false);
    }

    // ----- WORLD RESETTING -----
    LogBlock logblock = (LogBlock) getServer().getPluginManager().getPlugin("LogBlock");
    QueryParams params = new QueryParams(logblock);

    params.world = getCorn().getWorld();
    params.silent = false;

    try {
      logblock.getCommandsHandler()
      .new CommandRollback(this.getServer().getConsoleSender(), params, false);
    } catch (Exception e) {
    }

    clearEnt();

    // ----- WORLD RESETTING -----

    server.broadcastMessage(DARK_AQUA + "This plugin was created by Brenhien and NerdsWBNerds.");
    server.broadcastMessage(
        DARK_AQUA
            + "Email [email protected] or tweet us (@NerdsWBNerds) with ideas or bugs you have found.");

    load();

    state = State.SET_UP;
    game = new Setup(this);

    startTimer();
  }