-
-
Save pgelinas/7a6ac0c79d85554878a7 to your computer and use it in GitHub Desktop.
Simple test file for the crop growth mechanism in TFC. It outputs the growth time for each crops on 3 different year legnth, for a worst case and best case.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bioxx.tfc.TileEntities; | |
import com.bioxx.tfc.Core.TFC_Time; | |
import com.bioxx.tfc.Food.CropIndex; | |
import com.bioxx.tfc.Food.CropManager; | |
import com.bioxx.tfc.api.TFCOptions; | |
public class TestCropGrowth { | |
public static void main(String[] args) { | |
for (CropIndex crop : CropManager.getInstance().Crops) { | |
// Worst case on a new farmland: no fertilizer, minimum growing temp. | |
testCropGrowth(96, crop, false, crop.minGrowthTemp); | |
// Best case on a new farmland: fertilized and optimal growing temp. | |
testCropGrowth(96, crop, true, 28); | |
testCropGrowth(192, crop, false, crop.minGrowthTemp); | |
testCropGrowth(192, crop, true, 28); | |
testCropGrowth(360, crop, false, crop.minGrowthTemp); | |
testCropGrowth(360, crop, true, 28); | |
} | |
} | |
private static void testCropGrowth(int yearLength, CropIndex cropID, boolean fertilize, float ambientTemp) { | |
// Reset static constant! | |
TFC_Time.timeRatio360 = yearLength / 360f; | |
TFC_Time.timeRatio96 = yearLength / 96f; | |
Farmland farmland = new Farmland(); | |
if (fertilize) { | |
farmland.fertilize(); | |
} | |
Crop crop = new Crop(); | |
int days = 0; | |
while (crop.growth < cropID.numGrowthStages) { | |
days++; | |
crop.grow(cropID, farmland, ambientTemp); | |
} | |
System.out.println(String.format( | |
"Crop [%s] took %d days to grow for year length %d. Nutrients left: %d. Ferlizer left: %d", | |
cropID.cropName, days, yearLength, farmland.nutrients[cropID.cycleType], farmland.nutrients[3])); | |
} | |
// Based on TECrop | |
static class Crop { | |
public float growth = 0.1f; | |
public void grow(CropIndex cropID, Farmland farmland, float ambientTemp) { | |
float waterBoost = 0.1f; // Assume always near water. | |
int nutriType = cropID.cycleType; | |
int nutri = farmland.nutrients[nutriType]; | |
int fert = farmland.nutrients[3]; | |
int soilMax = farmland.getSoilMax(); | |
nutri = Math.min(nutri + fert, (int) (soilMax * 1.25f)); | |
float nutriMult = (0.2f + (nutri / (float) soilMax) * 0.5f) + waterBoost; | |
farmland.drainNutrients(nutriType, cropID.nutrientUsageMult); | |
farmland.drainNutrients(3, cropID.nutrientUsageMult); | |
// Ignore temperature change, assume lowest growth temp. | |
float tempAdded = ambientTemp * 0.00035f; | |
// See TECrop line 161 | |
float growthRate = ((((cropID.numGrowthStages / ((float) cropID.growthTime * TFC_Time.timeRatio96)) + tempAdded) * nutriMult) * 3) | |
* TFCOptions.cropGrowthMultiplier; | |
growth += growthRate; | |
} | |
} | |
// Based on TEFarmland | |
static class Farmland { | |
public int[] nutrients = { getSoilMax(), getSoilMax(), getSoilMax(), 0 }; | |
// See TEFarmland line 142 | |
public int getSoilMax() { | |
// float timeMultiplier = TFC_Time.daysInYear / 360f; | |
// return (int) (25000 * timeMultiplier); | |
return 6666; // 25000 * TFC_Time.daysInYear/360f = 6666.66... so round that to 6666 | |
} | |
// See TEFarmland line 148 | |
public void drainNutrients(int type, float multiplier) { | |
nutrients[type] -= (100 * multiplier) / TFC_Time.timeRatio360; | |
if (nutrients[type] < 0) | |
nutrients[type] = 0; | |
} | |
public void fertilize() { | |
nutrients[3] = getSoilMax(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment