/** * Gets a collection of malfunctionable entities local to the given person. * * @return collection collection of malfunctionables. */ public static Collection<Malfunctionable> getMalfunctionables(Person person) { Collection<Malfunctionable> entities = new ArrayList<Malfunctionable>(); LocationSituation location = person.getLocationSituation(); if (location == LocationSituation.IN_SETTLEMENT) { entities = getMalfunctionables(person.getSettlement()); } if (location == LocationSituation.IN_VEHICLE) { entities = getMalfunctionables(person.getVehicle()); } Collection<Unit> inventoryUnits = person.getInventory().getContainedUnits(); if (inventoryUnits.size() > 0) { Iterator<Unit> i = inventoryUnits.iterator(); while (i.hasNext()) { Unit unit = i.next(); if ((unit instanceof Malfunctionable) && !entities.contains(unit)) { entities.add((Malfunctionable) unit); } } } return entities; }
/** * 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; }
@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; }