Skip to content

Commit

Permalink
Show more params in Fishery
Browse files Browse the repository at this point in the history
12.07.2023

- change: reduce worktime in Fishery
- change: reduce weed demand in TendFishTankMeta
- change: vary fresh water to be added in AlgaeFarming
- change: add showing # of weed and total fish weight in
          BuildingPanelFishery
- change: call Animal's growPerFrame() with param time, instead of
		  calling Organism's growPerFrame() without param

Relates to #320, #986, #1169
  • Loading branch information
mokun committed Dec 8, 2023
1 parent a45beef commit 8d9c5c8
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Mars Simulation Project
* TendAlgaePond.java
* @date 2023-09-19
* @date 2023-12-07
* @author Manny
*/
package com.mars_sim.core.person.ai.task;
Expand Down Expand Up @@ -278,10 +278,10 @@ private double tendingPhase(double time) {

double mod = 1;

// Determine amount of effective work time based on "Botany" skill
// Determine amount of effective work time based on skill
int skill = getEffectiveSkillLevel();
if (skill > 0) {
mod += RandomUtil.getRandomDouble(.25, 1) + 1.25 * skill;
mod += RandomUtil.getRandomDouble(.5, .75) + 0.75 * skill;
}

workTime *= mod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Mars Simulation Project
* TendFishTank.java
* @date 2023-09-19
* @date 2023-12-07
* @author Barry Evans
*/
package com.mars_sim.core.person.ai.task;
Expand Down Expand Up @@ -257,10 +257,10 @@ private double tendingPhase(double time) {

double mod = 1;

// Determine amount of effective work time based on "Botany" skill
// Determine amount of effective work time based on skill
int skill = getEffectiveSkillLevel();
if (skill > 0) {
mod += RandomUtil.getRandomDouble(.25, .75) + 1.25 * skill;
mod += RandomUtil.getRandomDouble(.5, .75) + 0.75 * skill;
}

workTime *= mod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Mars Simulation Project
* TendFishTankMeta.java
* @date 2023-09-19
* @date 2023-12-07
* @author Barry Evans
*/
package com.mars_sim.core.person.ai.task.meta;
Expand Down Expand Up @@ -125,11 +125,11 @@ public List<SettlementTask> getSettlementTasks(Settlement settlement) {
RatingScore result = new RatingScore("base", BASE_SCORE);

result.addBase("maintenance",
3 * (200 - fishTank.getCleaningScore() - fishTank.getInspectionScore()));
2 * (200 - fishTank.getCleaningScore() - fishTank.getInspectionScore()));

result.addBase("surplus", Math.abs(fishTank.getSurplusStock()));

result.addBase("fish.weeds", fishTank.getWeedDemand() * 50);
result.addBase("fish.weeds", fishTank.getWeedDemand() * 15);

if (result.getScore() > 0) {
tasks.add(new FishTaskJob(this, fishTank, result));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Mars Simulation Project
* AlgaeFarming.java
* @date 2023-09-19
* @date 2023-12-07
* @author Manny Kung
*/

Expand Down Expand Up @@ -674,7 +674,7 @@ private void birthSpirulina(double time) {
addResourceLog(newAlgae, PRODUCED_ALGAE_ID);

// Compute the amount of fresh water to be replenished at the inlet
double freshWater = newAlgae / ALGAE_TO_WATER_RATIO;
double freshWater = newAlgae / ALGAE_TO_WATER_RATIO * RandomUtil.getRandomDouble(.9, 1.1);
// Consume fresh water
retrieveWater(freshWater, ResourceUtil.waterID);
// Add fresh water to the existing tank water
Expand Down Expand Up @@ -935,7 +935,7 @@ public double getSurplusRatio() {
* @return
*/
public double tending(double workTime) {
double remaining = 0;
double surplus = 0;

// Record the work time
addCumulativeWorkTime(workTime);
Expand All @@ -947,15 +947,15 @@ public double tending(double workTime) {
tendertime -= workTime;

if (tendertime < 0) {
remaining = Math.abs(tendertime);
surplus = Math.abs(tendertime);
tendertime = currentFood * TEND_TIME_FOR_FOOD;
logger.log(building, Level.INFO, 10_000,
"Algae fully tended for "
+ Math.round(tendertime * 100.0)/100.0 + " millisols.");
foodAge = 0;
}

return remaining;
return surplus;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,14 @@ public void setNeed(double newNeed)
**/
public void growPerFrame(double time)
{
super.growPerFrame( );
super.growPerFrame();
totalTime += time;
// For each day
if (totalTime > ONE_SOL && eatenThisFrame < needEachFrame) {
totalTime = totalTime - ONE_SOL;
expire( );
eatenThisFrame = 0;
}

}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Mars Simulation Project
* Fishery.java
* @date 2023-09-19
* @date 2023-12-07
* @author Barry Evans
*/

Expand Down Expand Up @@ -82,9 +82,9 @@ public class Fishery extends Function {
/** kW per litre of water. */
private static final double POWER_PER_LITRE = 0.0001D;
/** kW per fish. */
private static final double POWER_PER_FISH = 0.01D;
private static final double POWER_PER_FISH = 0.02D;
/** kW per weed mass. */
private static final double POWER_PER_WEED_MASS = 0.001D;
private static final double POWER_PER_WEED_MASS = 0.002D;
/** Tend time per weed. */
private static final double TIME_PER_WEED = 0.2D;
/** Adult fish length per litre. Cold water is 2.5cm per 4.55 litre. */
Expand All @@ -110,7 +110,7 @@ public class Fishery extends Function {
/** The amount iteration for nibbling weed */
private double nibbleIterationCache;
/** How long has the weed been tendered. */
private double weedTendertime;
private double tendertime;
/** How old is the weed since the last tendering. */
private double weedAge = 0;
/** The area of tank [in m^2]. */
Expand Down Expand Up @@ -164,7 +164,7 @@ public Fishery(Building building, FunctionSpec spec) {

int numWeeds = numFish * 10;

weedTendertime = numWeeds * TIME_PER_WEED;
tendertime = numWeeds * TIME_PER_WEED;

weedAge = 0;

Expand Down Expand Up @@ -290,7 +290,7 @@ private void simulatePond(double time) {
ListIterator<Herbivore> it = fish.listIterator();
while(it.hasNext()) {
nextFish = it.next();
nextFish.growPerFrame();
nextFish.growPerFrame(time);
if (!nextFish.isAlive())
it.remove();
}
Expand All @@ -310,7 +310,7 @@ private void simulatePond(double time) {
birthIterationCache = birthIterationCache - newFish;
for (i = 0; i < newFish; i++) {
// fish.add(new Herbivore(FISH_WEIGHT, 0, FISH_WEIGHT * FRACTION));

// Assume the beginning weight of a baby fish is 1/30 of an adult fish
double weight = RandomUtil.getRandomDouble(FISH_WEIGHT / 30 *.75, FISH_WEIGHT / 30 * 1.25);
double eatingRate = RandomUtil.getRandomDouble(weight * FRACTION *.75, weight * FRACTION * 1.25);
fish.add(new Herbivore(weight,
Expand Down Expand Up @@ -368,7 +368,7 @@ public double getFullPowerRequired() {
// Power (kW) required for normal operations.
return waterMass * POWER_PER_LITRE
+ getNumFish() * POWER_PER_FISH
+ getWeedMass() * POWER_PER_WEED_MASS;
+ getTotalWeedMass() * POWER_PER_WEED_MASS;
}

/**
Expand Down Expand Up @@ -432,10 +432,18 @@ public int getTankSize() {
return tankSize;
}

public double getWeedMass() {
public double getTotalWeedMass() {
return Math.round(totalMass(weeds)/ OUNCE_PER_KG * 100.0)/100.0;
}

public double getTotalFishMass() {
return Math.round(totalMass(fish)/ OUNCE_PER_KG * 100.0)/100.0;
}

public int getNumWeed() {
return weeds.size();
}

public int getSurplusStock() {
return fish.size() - idealFish;
}
Expand All @@ -457,14 +465,14 @@ public double tendWeeds(double workTime) {
p.growPerFrame();
}

weedTendertime -= workTime;
tendertime -= workTime;

if (weedTendertime < 0) {
surplus = Math.abs(weedTendertime);
weedTendertime = weeds.size() * TIME_PER_WEED;
if (tendertime < 0) {
surplus = Math.abs(tendertime);
tendertime = weeds.size() / fish.size() * TIME_PER_WEED;
logger.log(building, Level.INFO, 10_000L,
"Weeds fully tended for "
+ Math.round(weedTendertime * 100.0)/100.0 + " millisols.");
+ Math.round(tendertime * 100.0)/100.0 + " millisols.");
weedAge = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static void pondWeek(Vector<Herbivore> fish, Vector<Plant> weeds)
while (i < fish.size( ))
{
nextFish = fish.elementAt(i);
nextFish.growPerFrame( );
nextFish.growPerFrame();
if (nextFish.isAlive( ))
i++;
else
Expand Down
4 changes: 3 additions & 1 deletion mars-sim-core/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ BuildingPanelStorage.tabTitle = Storage
BuildingPanelFishery.numFish = # of fish
BuildingPanelFishery.numIdealFish = Ideal # fish
BuildingPanelFishery.maxFish = Max # of fish
BuildingPanelFishery.weedMass = Weed Mass
BuildingPanelFishery.fishMass = Total Fish Mass
BuildingPanelFishery.numWeed = # of weeds
BuildingPanelFishery.weedMass = Total Weed Mass
BuildingPanelFishery.weedDemand = Weed Demand
BuildingPanelFishery.tankSize = Tank Size
BuildingPanelFishery.powerReq = Power Required
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Mars Simulation Project
* BuildingPanelFishery.java
* @date 2023-09-19
* @date 2023-12-07
* @author Barry Evans
*/
package com.mars_sim.ui.swing.unit_window.structure.building;
Expand Down Expand Up @@ -31,7 +31,9 @@ public class BuildingPanelFishery extends BuildingFunctionPanel {
private int numFish;
private int numIdealFish;
private int maxFish;

private int numWeed;

private double fishMass;
private double weedMass;
private double weedDemand;
private double powerReq;
Expand All @@ -43,7 +45,9 @@ public class BuildingPanelFishery extends BuildingFunctionPanel {
private JLabel numFishLabel;
private JLabel numIdealFishLabel;
private JLabel maxFishLabel;
private JLabel fishMassLabel;

private JLabel numWeedLabel;
private JLabel weedMassLabel;
private JLabel weedDemandLabel;

Expand Down Expand Up @@ -72,11 +76,11 @@ public BuildingPanelFishery(Fishery tank, MainDesktopPane desktop) {
}

/**
* Build the UI
* Builds the UI.
*/
@Override
protected void buildUI(JPanel center) {
AttributePanel labelPanel = new AttributePanel(9);
AttributePanel labelPanel = new AttributePanel(11);
center.add(labelPanel, BorderLayout.NORTH);

labelPanel.addTextField(Msg.getString("BuildingPanelFishery.tankSize"),
Expand All @@ -90,6 +94,10 @@ protected void buildUI(JPanel center) {
numFishLabel = labelPanel.addTextField(Msg.getString("BuildingPanelFishery.numFish"),
Integer.toString(numFish), null);

fishMass = tank.getTotalFishMass();
fishMassLabel = labelPanel.addTextField(Msg.getString("BuildingPanelFishery.fishMass"),
StyleManager.DECIMAL_KG2.format(fishMass), null);

numIdealFish = tank.getIdealFish();
numIdealFishLabel = labelPanel.addTextField(Msg.getString("BuildingPanelFishery.numIdealFish"),
Integer.toString(numIdealFish), null);
Expand All @@ -98,7 +106,11 @@ protected void buildUI(JPanel center) {
maxFishLabel = labelPanel.addTextField(Msg.getString("BuildingPanelFishery.maxFish"),
Integer.toString(maxFish), null);

weedMass = tank.getWeedMass();
numWeed = tank.getNumWeed();
numWeedLabel = labelPanel.addTextField(Msg.getString("BuildingPanelFishery.numWeed"),
Integer.toString(numWeed), null);

weedMass = tank.getTotalWeedMass();
weedMassLabel = labelPanel.addTextField(Msg.getString("BuildingPanelFishery.weedMass"),
StyleManager.DECIMAL_KG2.format(weedMass), null);

Expand Down Expand Up @@ -141,7 +153,19 @@ public void update() {
maxFishLabel.setText(Integer.toString(newMaxFish));
}

double newWeedMass = tank.getWeedMass();
int newNumWeed = tank.getNumWeed();
if (numWeed != newNumWeed) {
numWeed = newNumWeed;
numWeedLabel.setText(Integer.toString(newNumWeed));
}

double newFishMass = tank.getTotalFishMass();
if (fishMass != newFishMass) {
fishMass = newFishMass;
fishMassLabel.setText(StyleManager.DECIMAL_KG.format(newFishMass));
}

double newWeedMass = tank.getTotalWeedMass();
if (weedMass != newWeedMass) {
weedMass = newWeedMass;
weedMassLabel.setText(StyleManager.DECIMAL_KG.format(newWeedMass));
Expand Down

0 comments on commit 8d9c5c8

Please sign in to comment.