Exemple #1
0
  /**
   * Gets the value of the function for a named building.
   *
   * @param buildingName the building name.
   * @param newBuilding true if adding a new building.
   * @param settlement the settlement.
   * @return value (VP) of building function.
   * @throws Exception if error getting function value.
   */
  public static double getFunctionValue(
      String buildingName, boolean newBuilding, Settlement settlement) {

    // Settlements need enough dining capacity for all associated people.
    double demand = settlement.getAllAssociatedPeople().size();

    // Supply based on wear condition of buildings.
    double supply = 0D;
    Iterator<Building> i = settlement.getBuildingManager().getBuildings(FUNCTION).iterator();
    while (i.hasNext()) {
      Building diningBuilding = i.next();
      Dining dining = (Dining) diningBuilding.getFunction(FUNCTION);
      double capacity = dining.getDiningCapacity();
      double wearFactor =
          ((diningBuilding.getMalfunctionManager().getWearCondition() / 100D) * .75D) + .25D;
      supply += capacity * wearFactor;
    }

    if (!newBuilding) {
      BuildingConfig config = SimulationConfig.instance().getBuildingConfiguration();
      double capacity = config.getDiningCapacity(buildingName);
      supply -= capacity;
      if (supply < 0D) supply = 0D;
    }

    return demand / (supply + 1D);
  }
Exemple #2
0
  /**
   * Constructor.
   *
   * @param building the building this function is for.
   */
  public Dining(Building building) {
    // Use Function constructor.
    super(FUNCTION, building);

    // Populate data members.
    BuildingConfig config = SimulationConfig.instance().getBuildingConfiguration();
    capacity = config.getDiningCapacity(building.getName());

    // Load activity spots
    loadActivitySpots(config.getDiningActivitySpots(building.getName()));
  }
  /**
   * Gets a list of research buildings with available research space from a list of buildings with
   * the research function.
   *
   * @param buildingList list of buildings with research function.
   * @return research buildings with available lab space.
   */
  private static List<Building> getSettlementLabsWithAvailableSpace(List<Building> buildingList) {
    List<Building> result = new ArrayList<Building>();

    Iterator<Building> i = buildingList.iterator();
    while (i.hasNext()) {
      Building building = i.next();
      Research lab = (Research) building.getFunction(BuildingFunction.RESEARCH);
      if (lab.getResearcherNum() < lab.getLaboratorySize()) {
        result.add(building);
      }
    }

    return result;
  }
  /**
   * Gets a list of research buildings with a given science specialty from a list of buildings with
   * the research function.
   *
   * @param science the science specialty.
   * @param buildingList list of buildings with research function.
   * @return research buildings with science specialty.
   */
  private static List<Building> getSettlementLabsWithSpecialty(
      ScienceType science, List<Building> buildingList) {
    List<Building> result = new ArrayList<Building>();

    Iterator<Building> i = buildingList.iterator();
    while (i.hasNext()) {
      Building building = i.next();
      Research lab = (Research) building.getFunction(BuildingFunction.RESEARCH);
      if (lab.hasSpecialty(science)) {
        result.add(building);
      }
    }

    return result;
  }
  /**
   * Gets a settlement lab to research a particular science.
   *
   * @param person the person looking for a lab.
   * @param science the science to research.
   * @return a valid research lab.
   */
  private static Lab getSettlementLab(Person person, ScienceType science) {
    Lab result = null;

    BuildingManager manager = person.getSettlement().getBuildingManager();
    List<Building> labBuildings = manager.getBuildings(BuildingFunction.RESEARCH);
    labBuildings = getSettlementLabsWithSpecialty(science, labBuildings);
    labBuildings = BuildingManager.getNonMalfunctioningBuildings(labBuildings);
    labBuildings = getSettlementLabsWithAvailableSpace(labBuildings);
    labBuildings = BuildingManager.getLeastCrowdedBuildings(labBuildings);

    if (labBuildings.size() > 0) {
      Map<Building, Double> labBuildingProbs =
          BuildingManager.getBestRelationshipBuildings(person, labBuildings);
      Building building = RandomUtil.getWeightedRandomObject(labBuildingProbs);
      result = (Research) building.getFunction(BuildingFunction.RESEARCH);
    }

    return result;
  }
  /** Adds a person to a lab. */
  private void addPersonToLab() {

    try {
      LocationSituation location = person.getLocationSituation();
      if (location == LocationSituation.IN_SETTLEMENT) {
        Building labBuilding = ((Research) lab).getBuilding();

        // Walk to lab building.
        walkToActivitySpotInBuilding(labBuilding, false);

        lab.addResearcher();
        malfunctions = labBuilding.getMalfunctionManager();
      } else if (location == LocationSituation.IN_VEHICLE) {

        // Walk to lab internal location in rover.
        walkToLabActivitySpotInRover((Rover) person.getVehicle(), false);

        lab.addResearcher();
        malfunctions = person.getVehicle().getMalfunctionManager();
      }
    } catch (Exception e) {
      logger.severe("addPersonToLab(): " + e.getMessage());
    }
  }
  @Override
  public double getProbability(Person person) {

    double result = 0D;

    if (person.getLocationSituation() == LocationSituation.IN_SETTLEMENT) {
      boolean isEVA = false;

      Settlement settlement = person.getSettlement();

      // Check if settlement has resource process override set.
      if (!settlement.getResourceProcessOverride()) {
        try {
          Building building = ToggleResourceProcess.getResourceProcessingBuilding(person);
          if (building != null) {
            ResourceProcess process = ToggleResourceProcess.getResourceProcess(building);
            isEVA = !building.hasFunction(BuildingFunction.LIFE_SUPPORT);
            double diff = ToggleResourceProcess.getResourcesValueDiff(settlement, process);
            double baseProb = diff * 10000D;
            if (baseProb > 100D) {
              baseProb = 100D;
            }
            result += baseProb;

            if (!isEVA) {
              // Factor in building crowding and relationship factors.
              result *= TaskProbabilityUtil.getCrowdingProbabilityModifier(person, building);
              result *= TaskProbabilityUtil.getRelationshipModifier(person, building);
            }
          }
        } catch (Exception e) {
          e.printStackTrace(System.err);
        }
      }

      if (isEVA) {
        // Check if an airlock is available
        if (EVAOperation.getWalkableAvailableAirlock(person) == null) {
          result = 0D;
        }

        // Check if it is night time.
        SurfaceFeatures surface = Simulation.instance().getMars().getSurfaceFeatures();
        if (surface.getSolarIrradiance(person.getCoordinates()) == 0D) {
          if (!surface.inDarkPolarRegion(person.getCoordinates())) {
            result = 0D;
          }
        }

        // Crowded settlement modifier
        if (person.getLocationSituation() == LocationSituation.IN_SETTLEMENT) {
          if (settlement.getCurrentPopulationNum() > settlement.getPopulationCapacity()) {
            result *= 2D;
          }
        }
      }

      // Effort-driven task modifier.
      result *= person.getPerformanceRating();

      // Job modifier.
      Job job = person.getMind().getJob();
      if (job != null) {
        result *= job.getStartTaskProbabilityModifier(ToggleResourceProcess.class);
      }

      // Modify if tinkering is the person's favorite activity.
      if (person.getFavorite().getFavoriteActivity().equalsIgnoreCase("Tinkering")) {
        result *= 2D;
      }

      // 2015-06-07 Added Preference modifier
      if (result > 0) result += person.getPreference().getPreferenceScore(this);
      if (result < 0) result = 0;
    }

    return result;
  }