コード例 #1
0
  /**
   * 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;
  }
コード例 #2
0
  /**
   * Gets a local lab for scientific research.
   *
   * @param person the person checking for the lab.
   * @param science the science to research.
   * @return laboratory found or null if none.
   * @throws Exception if error getting a lab.
   */
  public static Lab getLocalLab(Person person, ScienceType science) {
    Lab result = null;

    LocationSituation location = person.getLocationSituation();
    if (location == LocationSituation.IN_SETTLEMENT) {
      result = getSettlementLab(person, science);
    } else if (location == LocationSituation.IN_VEHICLE) {
      result = getVehicleLab(person.getVehicle(), science);
    }

    return result;
  }
コード例 #3
0
ファイル: TabPanelFavorite.java プロジェクト: mokun/mars-sim
    private PreferenceTableModel(Unit unit) {
      Person person = null;
      Robot robot = null;

      if (unit instanceof Person) {
        person = (Person) unit;
        manager = person.getPreference();
      } else if (unit instanceof Robot) {

      }

      metaTaskStringList = manager.getMetaTaskStringList();
      metaTaskStringMap = manager.getMetaTaskStringMap();
    }
コード例 #4
0
  /**
   * Gets the effective research time based on the person's science skill.
   *
   * @param time the real amount of time (millisol) for research.
   * @return the effective amount of time (millisol) for research.
   */
  private double getEffectiveResearchTime(double time) {
    // Determine effective research time based on the science skill.
    double researchTime = time;
    int scienceSkill = getEffectiveSkillLevel();
    if (scienceSkill == 0) {
      researchTime /= 2D;
    } else if (scienceSkill > 1) {
      researchTime += researchTime * (.2D * scienceSkill);
    }

    // Modify by tech level of laboratory.
    int techLevel = lab.getTechnologyLevel();
    if (techLevel > 0) {
      researchTime *= techLevel;
    }

    // If research assistant, modify by assistant's effective skill.
    if (hasResearchAssistant()) {
      SkillManager manager = researchAssistant.getMind().getSkillManager();
      int assistantSkill = manager.getEffectiveSkillLevel(science.getSkill());
      if (scienceSkill > 0) {
        researchTime *= 1D + ((double) assistantSkill / (double) scienceSkill);
      }
    }

    return researchTime;
  }
コード例 #5
0
  /**
   * Checks if the person is in a moving vehicle.
   *
   * @param person the person.
   * @return true if person is in a moving vehicle.
   */
  public static boolean inMovingRover(Person person) {

    boolean result = false;

    if (person.getLocationSituation() == LocationSituation.IN_VEHICLE) {
      Vehicle vehicle = person.getVehicle();
      if (vehicle.getStatus().equals(Vehicle.MOVING)) {
        result = true;
      } else if (vehicle.getStatus().equals(Vehicle.TOWED)) {
        Vehicle towingVehicle = vehicle.getTowingVehicle();
        if (towingVehicle.getStatus().equals(Vehicle.MOVING)
            || towingVehicle.getStatus().equals(Vehicle.TOWED)) {
          result = false;
        }
      }
    }

    return result;
  }
コード例 #6
0
 /**
  * Gets the crowding modifier for a researcher to use a given laboratory building.
  *
  * @param researcher the researcher.
  * @param lab the laboratory.
  * @return crowding modifier.
  */
 public static double getLabCrowdingModifier(Person researcher, Lab lab) {
   double result = 1D;
   if (researcher.getLocationSituation() == LocationSituation.IN_SETTLEMENT) {
     Building labBuilding = ((Research) lab).getBuilding();
     if (labBuilding != null) {
       result *= Task.getCrowdingProbabilityModifier(researcher, labBuilding);
       result *= Task.getRelationshipModifier(researcher, labBuilding);
     }
   }
   return result;
 }
コード例 #7
0
  /**
   * Gets all malfunctionables associated with a settlement.
   *
   * @param settlement the settlement.
   * @return collection of malfunctionables.
   */
  public static Collection<Malfunctionable> getAssociatedMalfunctionables(Settlement settlement) {

    // Add settlement, buildings and all other malfunctionables in settlement inventory.
    Collection<Malfunctionable> entities = getMalfunctionables(settlement);

    // Add all associated rovers out on missions and their inventories.
    Iterator<Mission> i =
        Simulation.instance().getMissionManager().getMissionsForSettlement(settlement).iterator();
    while (i.hasNext()) {
      Mission mission = i.next();
      if (mission instanceof VehicleMission) {
        Vehicle vehicle = ((VehicleMission) mission).getVehicle();
        if ((vehicle != null) && !settlement.equals(vehicle.getSettlement()))
          entities.addAll(getMalfunctionables(vehicle));
      }
    }

    // Get entities carried by robots
    Iterator<Robot> jj = settlement.getAllAssociatedRobots().iterator();
    while (jj.hasNext()) {
      Robot robot = jj.next();
      if (robot.getLocationSituation() == LocationSituation.OUTSIDE)
        entities.addAll(getMalfunctionables(robot));
    }

    // TODO: how to ask robots first and only ask people if robots are not available so that the
    // tasks are not duplicated ?
    // Get entities carried by people on EVA.
    Iterator<Person> j = settlement.getAllAssociatedPeople().iterator();
    while (j.hasNext()) {
      Person person = j.next();
      if (person.getLocationSituation() == LocationSituation.OUTSIDE)
        entities.addAll(getMalfunctionables(person));
    }

    return entities;
  }
コード例 #8
0
ファイル: DeathInfo.java プロジェクト: mokun/mars-sim
  /**
   * The construct creates an instance of a DeathInfo class.
   *
   * @param person the dead person
   */
  public DeathInfo(Person person) {

    // Initialize data members
    timeOfDeath = Simulation.instance().getMasterClock().getMarsClock().getDateTimeStamp();

    Complaint serious = person.getPhysicalCondition().getMostSerious();
    if (serious != null) illness = serious.getName();

    if (person.getLocationSituation() == LocationSituation.OUTSIDE) placeOfDeath = "Outside";
    else {
      containerUnit = person.getContainerUnit();
      placeOfDeath = containerUnit.getName();
    }

    locationOfDeath = person.getCoordinates();

    Mind mind = person.getMind();

    job = mind.getJob();

    if (mind.getMission() != null) {
      mission = mind.getMission().getName();
      missionPhase = mind.getMission().getPhaseDescription();
    }

    TaskManager taskMgr = mind.getTaskManager();
    if (taskMgr.hasTask()) {
      task = taskMgr.getTaskName();
      TaskPhase phase = taskMgr.getPhase();
      if (phase != null) {
        taskPhase = phase.getName();
      } else {
        taskPhase = "";
      }
    }

    Iterator<Malfunctionable> i = MalfunctionFactory.getMalfunctionables(person).iterator();
    Malfunction mostSerious = null;
    int severity = 0;
    while (i.hasNext()) {
      Malfunctionable entity = i.next();
      MalfunctionManager malfunctionMgr = entity.getMalfunctionManager();
      if (malfunctionMgr.hasEmergencyMalfunction()) {
        Malfunction m = malfunctionMgr.getMostSeriousEmergencyMalfunction();
        if (m.getSeverity() > severity) {
          mostSerious = m;
          severity = m.getSeverity();
        }
      }
    }
    if (mostSerious != null) malfunction = mostSerious.getName();
    this.gender = person.getGender();
  }
コード例 #9
0
  /**
   * 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;
  }
コード例 #10
0
ファイル: TabPanelFavorite.java プロジェクト: mokun/mars-sim
  /**
   * Constructor.
   *
   * @param unit the unit to display.
   * @param desktop the main desktop.
   */
  public TabPanelFavorite(Unit unit, MainDesktopPane desktop) {
    // Use the TabPanel constructor
    super(
        Msg.getString("TabPanelFavorite.title"), // $NON-NLS-1$
        null,
        Msg.getString("TabPanelFavorite.tooltip"), // $NON-NLS-1$
        unit,
        desktop);

    Person person = (Person) unit;

    // Create Favorite label panel.
    JPanel favoriteLabelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    topContentPanel.add(favoriteLabelPanel);

    // Prepare  Favorite label
    JLabel favoriteLabel =
        new JLabel(Msg.getString("TabPanelFavorite.label"), JLabel.CENTER); // $NON-NLS-1$
    favoriteLabelPanel.add(favoriteLabel);

    // Prepare info panel.
    JPanel infoPanel = new JPanel(new GridLayout(4, 2, 0, 0));
    infoPanel.setBorder(new MarsPanelBorder());
    topContentPanel.add(infoPanel, BorderLayout.NORTH);

    // Prepare main dish name label
    JLabel mainDishNameLabel =
        new JLabel(Msg.getString("TabPanelFavorite.mainDish"), JLabel.RIGHT); // $NON-NLS-1$
    infoPanel.add(mainDishNameLabel);

    // Prepare main dish label
    String mainDish = person.getFavorite().getFavoriteMainDish();
    // JLabel mainDishLabel = new JLabel(mainDish, JLabel.RIGHT);
    // infoPanel.add(mainDishLabel);
    JTextField mainDishTF = new JTextField(WordUtils.capitalize(mainDish));
    mainDishTF.setEditable(false);
    mainDishTF.setColumns(20);
    infoPanel.add(mainDishTF);

    // Prepare side dish name label
    JLabel sideDishNameLabel =
        new JLabel(Msg.getString("TabPanelFavorite.sideDish"), JLabel.RIGHT); // $NON-NLS-1$
    infoPanel.add(sideDishNameLabel);

    // Prepare side dish label
    String sideDish = person.getFavorite().getFavoriteSideDish();
    // JLabel sideDishLabel = new JLabel(sideDish, JLabel.RIGHT);
    // infoPanel.add(sideDishLabel);
    JTextField sideDishTF = new JTextField(WordUtils.capitalize(sideDish));
    sideDishTF.setEditable(false);
    sideDishTF.setColumns(20);
    infoPanel.add(sideDishTF);

    // Prepare dessert name label
    JLabel dessertNameLabel =
        new JLabel(Msg.getString("TabPanelFavorite.dessert"), JLabel.RIGHT); // $NON-NLS-1$
    infoPanel.add(dessertNameLabel);

    // Prepare dessert label
    String dessert = person.getFavorite().getFavoriteDessert();
    // JLabel dessertLabel = new JLabel(WordUtils.capitalize(dessert), JLabel.RIGHT);
    // infoPanel.add(dessertLabel);
    JTextField dessertTF = new JTextField(WordUtils.capitalize(dessert));
    dessertTF.setEditable(false);
    dessertTF.setColumns(20);
    infoPanel.add(dessertTF);

    // Prepare activity name label
    JLabel activityNameLabel =
        new JLabel(Msg.getString("TabPanelFavorite.activity"), JLabel.RIGHT); // $NON-NLS-1$
    infoPanel.add(activityNameLabel);

    // Prepare activity label
    String activity = person.getFavorite().getFavoriteActivity();
    JTextField activityTF = new JTextField(WordUtils.capitalize(activity));
    activityTF.setEditable(false);
    activityTF.setColumns(20);
    infoPanel.add(activityTF);
    // JLabel activityLabel = new JLabel(WordUtils.capitalize(activity), JLabel.RIGHT);
    // infoPanel.add(activityLabel);

    // Create label panel.
    JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    centerContentPanel.add(labelPanel, BorderLayout.NORTH);

    // Create preference label
    JLabel label = new JLabel("Preferences");
    labelPanel.add(label);

    // Create scroll panel
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBorder(new MarsPanelBorder());
    scrollPane.getVerticalScrollBar().setUnitIncrement(10);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    centerContentPanel.add(scrollPane, BorderLayout.CENTER);

    // Create skill table
    tableModel = new PreferenceTableModel(person);
    JTable table = new JTable(tableModel);
    table.setPreferredScrollableViewportSize(new Dimension(225, 100));
    table.getColumnModel().getColumn(0).setPreferredWidth(100);
    table.getColumnModel().getColumn(1).setPreferredWidth(30);
    table.setCellSelectionEnabled(false);
    table.setDefaultRenderer(Integer.class, new NumberCellRenderer());

    // 2015-06-08 Added sorting
    table.setAutoCreateRowSorter(true);
    table.getTableHeader().setDefaultRenderer(new MultisortTableHeaderCellRenderer());

    // 2015-06-08 Added setTableStyle()
    TableStyle.setTableStyle(table);

    scrollPane.setViewportView(table);
  }
コード例 #11
0
ファイル: TabPanelDeath.java プロジェクト: mokun/mars-sim
  /**
   * Constructor.
   *
   * @param unit the unit to display.
   * @param desktop the main desktop.
   */
  public TabPanelDeath(Unit unit, MainDesktopPane desktop) {
    // Use the TabPanel constructor
    super(
        Msg.getString("TabPanelDeath.title"), // $NON-NLS-1$
        null,
        Msg.getString("TabPanelDeath.tooltip"), // $NON-NLS-1$
        unit,
        desktop);

    Person person = (Person) unit;
    PhysicalCondition condition = person.getPhysicalCondition();
    DeathInfo death = condition.getDeathDetails();

    // Create death info label panel.
    JPanel deathInfoLabelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    topContentPanel.add(deathInfoLabelPanel);

    // Prepare death info label
    JLabel deathInfoLabel =
        new JLabel(Msg.getString("TabPanelDeath.label"), JLabel.CENTER); // $NON-NLS-1$
    deathInfoLabelPanel.add(deathInfoLabel);

    // Prepare death label panel
    JPanel deathLabelPanel = new JPanel(new GridLayout(3, 1, 0, 0));
    deathLabelPanel.setBorder(new MarsPanelBorder());
    centerContentPanel.add(deathLabelPanel, BorderLayout.NORTH);

    // Prepare cause label
    JLabel causeLabel =
        new JLabel(
            Msg.getString("TabPanelDeath.cause") + death.getIllness(), JLabel.LEFT); // $NON-NLS-1$
    deathLabelPanel.add(causeLabel);

    // Prepare time label
    JLabel timeLabel =
        new JLabel(
            Msg.getString("TabPanelDeath.time") + death.getTimeOfDeath(),
            JLabel.LEFT); // $NON-NLS-1$
    deathLabelPanel.add(timeLabel);

    // Prepare malfunction label
    JLabel malfunctionLabel =
        new JLabel(
            Msg.getString("TabPanelDeath.malfunctionIfAny") + death.getMalfunction(),
            JLabel.LEFT); // $NON-NLS-1$
    deathLabelPanel.add(malfunctionLabel);

    // Prepare bottom content panel
    JPanel bottomContentPanel = new JPanel(new BorderLayout(0, 0));
    centerContentPanel.add(bottomContentPanel, BorderLayout.CENTER);

    // Prepare location panel
    JPanel locationPanel = new JPanel(new BorderLayout());
    locationPanel.setBorder(new MarsPanelBorder());
    bottomContentPanel.add(locationPanel, BorderLayout.NORTH);

    // Prepare location label panel
    JPanel locationLabelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    locationPanel.add(locationLabelPanel, BorderLayout.NORTH);

    // Prepare center map button
    JButton centerMapButton =
        new JButton(ImageLoader.getIcon(Msg.getString("img.centerMap"))); // $NON-NLS-1$
    centerMapButton.setMargin(new Insets(1, 1, 1, 1));
    centerMapButton.addActionListener(this);
    centerMapButton.setToolTipText(Msg.getString("TabPanelDeath.tooltip.centerMap")); // $NON-NLS-1$
    locationLabelPanel.add(centerMapButton);

    // Prepare location label
    JLabel locationLabel =
        new JLabel(Msg.getString("TabPanelDeath.location"), JLabel.CENTER); // $NON-NLS-1$
    locationLabelPanel.add(locationLabel);

    if (death.getContainerUnit() != null) {
      // Prepare top container button
      JButton topContainerButton = new JButton(death.getContainerUnit().getName());
      topContainerButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              DeathInfo death = ((Person) getUnit()).getPhysicalCondition().getDeathDetails();
              getDesktop().openUnitWindow(death.getContainerUnit(), false);
            }
          });
      locationLabelPanel.add(topContainerButton);
    } else {
      JLabel locationLabel2 = new JLabel(death.getPlaceOfDeath(), JLabel.CENTER);
      locationLabelPanel.add(locationLabel2);
    }

    // Prepare location coordinates panel
    JPanel locationCoordsPanel = new JPanel(new GridLayout(2, 1, 0, 0));
    locationPanel.add(locationCoordsPanel, BorderLayout.CENTER);

    // Initialize location cache
    Coordinates deathLocation = death.getLocationOfDeath();

    // Prepare latitude label
    JLabel latitudeLabel =
        new JLabel(
            Msg.getString("TabPanelDeath.latitude") + deathLocation.getFormattedLatitudeString(),
            JLabel.LEFT); // $NON-NLS-1$
    locationCoordsPanel.add(latitudeLabel);

    // Prepare longitude label
    JLabel longitudeLabel =
        new JLabel(
            Msg.getString("TabPanelDeath.longitude") + deathLocation.getFormattedLongitudeString(),
            JLabel.LEFT); // $NON-NLS-1$
    locationCoordsPanel.add(longitudeLabel);

    // Add empty panel
    bottomContentPanel.add(new JPanel(), BorderLayout.CENTER);
  }
コード例 #12
0
  @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;
  }