@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;
  }
Exemple #2
0
 /**
  * Gets the person's job at the time of death.
  *
  * @return job
  */
 public String getJob() {
   if (job != null) return job.getName(gender);
   else return "";
 }