ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
FarmManager Class Reference

The Farm Manager class. More...

#include <Farm.h>

Public Member Functions

 FarmManager (Landscape *landscape)
 Farm manager constructor. More...
 
 ~FarmManager ()
 Farm manager destructor. More...
 
void FarmManagement ()
 Runs the daily farm management for each farm, but also calculates annual spilled grain and maize. More...
 
void InitiateManagement (void)
 
void UpdateSocialNetworks (bool a_geographic, bool a_associative, bool a_virtual)
 Forces all farmers to update social networks if needed. More...
 
LandscapeGetLandscape (void)
 
void AddField (int a_OwnerIndex, LE *a_newland, int a_Owner)
 
void RemoveField (int a_OwnerIndex, LE *a_field)
 
int ConnectFarm (int a_owner)
 
TTypesOfVegetation TranslateVegCodes (std::string &str)
 Converts strings to tov_
More...
 
TTypesOfCrops TranslateCropCodes (string &str)
 Converts strings to toc_. More...
 
std::string BackTranslateCropCodes (TTypesOfCrops a_crop)
 Converts toc_ to string. More...
 
void ReadCropYieldReturns ()
 Reads in and creates the yield return data for economics. More...
 
void ReadCropManagementNorms ()
 Reads in and creates the crop management norms data for socio-economics. More...
 
void ReadFarmerAttributes ()
 Reads in and creates the farmer attribute information and assigns it to farmers. More...
 
void ReadFarmFunctionsCB ()
 Reads in and creates the data associated with costs and benefits of farm functions. More...
 
void PrintLocationAndArea ()
 Print Farmers' location (x , y) More...
 
void DumpFarmAreas ()
 
void DumpFarmrefs (const char *a_filename)
 dumps the farmrefs file to a standard named file More...
 
int GetFarmTotalSize (int a_farmref)
 Returns the total farm area from the farm ref num. More...
 
int GetFarmArableSize (int a_farmref)
 Returns the arable area from the farm ref num. More...
 
TTypesOfFarm GetFarmType (int a_farmref)
 Returns the farm type from the farm ref num. More...
 
int GetFarmNoFields (int a_farmref)
 Returns the number of fields owned by a from the farm ref num. More...
 
APoint GetFarmValidCoords (int a_farmref)
 Returns the number of fields owned by a from the farm ref num. More...
 
int GetFarmNoOpenFields (int a_farmref, int a_openness)
 Returns the number of fields with openness more than a_openness. More...
 
int GetFarmAreaOpenFields (int a_farmref, int a_openness)
 Returns the area of fields with openness more than a_openness. More...
 
FarmGetFarmPtr (int a_owner)
 Returns the pointer to a farm with a specific number. More...
 
double GetManagementNorm (int a_crop, int a_managementtype)
 Get the norm for managment numbers for a crop and management cominbation. More...
 
FarmGetFarmPtrIndex (int a_index)
 Returns the pointer to a farm with a specific index. More...
 
int GetRandomFarmRefnum ()
 Returns a random farm reference number. More...
 
void CalcCentroids ()
 calculate all farm centroids More...
 
bool InIllegalList (int a_farm_ref, vector< int > *a_farmlist)
 Checks a list to see if a farm matches the illegal list of references. More...
 
void AddToIllegalList (int a_farm_ref, vector< int > *a_farmlist)
 Add to a list if a farm is not already among the illegal list of references. More...
 
int FindClosestFarm (HunterInfo a_hinfo, vector< int > *a_farmlist)
 Finds the closest farm to this co-ordinate. More...
 
int FindClosestFarmOpenness (HunterInfo a_hinfo, vector< int > *a_farmlist, int a_openness)
 Finds the closest farm to this co-ordinate but uses a probability distribtution for acceptance. More...
 
int FindClosestFarmOpennessProb (HunterInfo a_hinfo, vector< int > *a_farmlist, int a_openness)
 Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness. More...
 
int FindClosestFarmOpennessProbSmallIsBest (HunterInfo a_hinfo, vector< int > *a_farmlist, int a_openness, vector< int > *a_farmsizelist)
 Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness and another based on farm size. More...
 
int FindClosestFarmOpennessProbNearRoostIsBest (HunterInfo a_hinfo, vector< int > *a_farmlist, int a_openness, vector< APoint > *a_farmsizelist)
 Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness and another based on farm size. More...
 
int FindFarmWithRandom (vector< int > *a_farmlist)
 Finds a farm openness more than a value not on the list. More...
 
int FindFarmWithOpenness (vector< int > *a_farmlist, int a_openness)
 Finds a farm openness more than a value not on the list. More...
 
int FindOpennessFarm (int a_openness)
 Finds a random farm with at least one field with openness above a_openness. More...
 
bool CheckOpenness (int a_openness, int a_ref)
 Check if a farm has at least one field with openness above a_openness. More...
 
APoint GetFarmCentroid (int a_farmref)
 Gets the farm centroid as an APoint. More...
 
bool IsDuplicateRef (int a_ref, HunterInfo *a_hinfo)
 Checks if we already have this ref. More...
 
double GetSpilledGrain ()
 Returns the average amount of spilled grain in KJ/m2 this year. More...
 
double GetSpilledMaize ()
 Returns the average amount of spilled maize in KJ/m2 this year. More...
 
void SetSpilledGrain (bool a_spilledgrain)
 Set m_SpilledGrain which is the flag for either 2013 (true) or 2014 (false) spilled grain distributions. More...
 
double GetDD (void)
 Returnes day degrees for the period March 1st - November 1st. Used for determining yields of crops that are not harvested. More...
 
void SetDD (double a_dd)
 
int GetFarmNoLookupIndex (int a_ref)
 Get a farm reference from the lookup table. More...
 
int GetFarmNoLookup (int a_ref)
 Get a farm reference from the lookup table. More...
 
int GetFarmTypeLookup (int a_ref)
 Get a farm type from the lookup table. More...
 
bool GetIsRenumbered ()
 Returns the flag for renumbering. More...
 
int GetRenumberedFarmRef (int a_farmref)
 Returns the farm ref index for a farmref. More...
 
int GetNoFarms ()
 
vector< Crop * > * GetCropMgtPlans (void)
 
int GetCropMgtPlansIndex (TTypesOfVegetation a_tov)
 
TTypesOfCrops GetCropTypeFromPlan (TTypesOfVegetation a_tov)
 
FarmerListGetFarmerList ()
 Gets the farmer list pointer (used by social networks and farmers) More...
 
Farmer * GetFarmer (int i)
 Gets the farmer associated with the farm with the index number i. More...
 
void SetFarmer (int i, Farmer *a_farmer)
 Sets the farmer associated with the farm with the index number i. More...
 
FarmGetFarm (int i)
 Get a specific farm i. More...
 
FarmFuncsCostBenefits Get_FarmFuncsCB (FarmToDo a_action)
 Get a specific FarmFunction Cost Benefit. More...
 
void Print_FarmerAttributes ()
 Create an output where Farmer's attribute are shown. More...
 
void AddToManagementStats (FarmEvent *a_ev)
 Adds the event information to the management stats. More...
 
bool GetUseSocioEconomicFarmers ()
 Get the flag for use of socio-economic farmers. More...
 
double GetIncome (TTypesOfCrops a_toc)
 Get tov-based profit per unit area per unit biomass. More...
 

Protected Member Functions

void CreateFarms (const char *a_farmfile)
 Creates ther farms at simulation start. More...
 
void ReadYieldProfitData (string a_filename)
 Reads in base data for biomass related profit on harvest for each crop. More...
 

Static Protected Member Functions

static void SetUseSocioEconomics (bool a_flag)
 Sets the socio-economic use flag. More...
 

Protected Attributes

vector< Crop * > m_cropprogs
 
vector< Farm * > m_farms
 
vector< double > m_YieldReturns
 Holds the list of yield prices indexed by toc_ type (TTypesOfCrop) More...
 
FarmerListm_farmers
 Holds a handy list of the farmers. More...
 
Landscapem_landscape
 Holds a local pointer to the landscape. More...
 
vector< double > m_CropYieldProfit
 Holds the values for profit per unit biomass per unit area for all crops - uses TTypesOfCrops. More...
 
double m_MangagementNorms [toc_Foobar][fmc_Foobar]
 Holds the values for crop management uses norms - uses TTypesOfCrops and FarmManagementCategory as array size determinants. More...
 
double daydegrees
 Daydegrees for period March 1st - November 1st. Used to determine yield of crops that are not harvested (and thus do not have values of biomass at harvest). More...
 
bool m_SpilledGrain {false}
 Is it 2013 (true) or 2014 (false) as far as grain goes. More...
 
int * m_farmmapping_lookup
 Used for a dynamic array of lookups converting farm references to internal renumbering. More...
 
bool m_renumbered
 A flag to show whether renumbering was already done. More...
 
vector< FarmFuncsCostBenefitsm_FarmFuncsCB
 Holds the list of cost benefits for farm functions (management actions) More...
 
string m_ManagementCategoryLabels [fmc_Foobar]
 A list of labels of the main farm management action categories. More...
 

Static Protected Attributes

static bool m_UseSocioEconomicFarmers = false
 Flag for use of socio-economic farmers. More...
 

Detailed Description

The Farm Manager class.

Constructor & Destructor Documentation

◆ FarmManager()

FarmManager::FarmManager ( Landscape landscape)

Farm manager constructor.

3870 {
3871  m_landscape = landscape;
3872  g_farmmanager = this;
3873  m_farmers = new FarmerList();
3875  // Set any static member attributes needed by Farm or Farmer
3877  Farmer::SetStaticParameterValues();
3878 
3880  {
3881  m_YieldReturns.resize(toc_Foobar,0);
3882  // Need to set up the farm economic data
3885 #ifndef __CALCULATE_MANAGEMENT_NORMS
3887 #else
3888  for (int j = 0; j < toc_Foobar; j++)
3889  for (int i = 0; i < fmc_Foobar; i++)
3890  m_MangagementNorms[j][i] = 1; // This is just to stop division by zero when these are not actively set
3891 
3892 #endif
3893  }
3894  if ( l_map_read_farmfile.value() ) {
3896  // Now farmers are created, read their social data
3898  }
3899 #ifdef __CALCULATE_MANAGEMENT_NORMS
3900  for (int i=0; i<toc_Foobar; i++)
3901  for (int j=0; j<=fmc_Foobar; j++) m_managementnormstats[i][j] = 0;
3902 #endif
3903 
3904 }

References cfg_UseSocioEconomicFarm, CreateFarms(), fmc_Foobar, g_farmmanager, l_map_farmref_file, l_map_read_farmfile, last_treatment, m_farmers, m_FarmFuncsCB, m_landscape, m_MangagementNorms, m_UseSocioEconomicFarmers, m_YieldReturns, ReadCropManagementNorms(), ReadCropYieldReturns(), ReadFarmerAttributes(), ReadFarmFunctionsCB(), SetUseSocioEconomics(), toc_Foobar, CfgBool::value(), and CfgStr::value().

◆ ~FarmManager()

FarmManager::~FarmManager ( )

Farm manager destructor.

3908 {
3909 #ifdef __CALCULATE_MANAGEMENT_NORMS
3910  OutputManagementNormStats();
3911 #endif
3912  delete m_farmers;
3913  delete[] m_farmmapping_lookup; // The variable newed in CreateFarms()
3914  for ( unsigned int i = 0; i < m_farms.size(); i++ )
3915  delete m_farms[ i ];
3916  for (unsigned int i = 0; i < m_cropprogs.size(); i++)
3917  delete m_cropprogs[i];
3918  m_FarmFuncsCB.clear();
3919 }

References m_cropprogs, m_farmers, m_FarmFuncsCB, m_farmmapping_lookup, and m_farms.

Member Function Documentation

◆ AddField()

void FarmManager::AddField ( int  a_OwnerIndex,
LE a_newland,
int  a_Owner 
)
3979 {
3980  m_farms[ a_OwnerIndex ]->AddField( a_newland );
3981  a_newland->SetOwner( m_farms[ a_OwnerIndex ], a_Owner, a_OwnerIndex );
3982 }

References m_farms, and LE::SetOwner().

◆ AddToIllegalList()

void FarmManager::AddToIllegalList ( int  a_farm_ref,
vector< int > *  a_farmlist 
)

Add to a list if a farm is not already among the illegal list of references.

a_farmlist is a pointer to a list of integers with illegal farm ref numbers.

5700  {
5704  bool found = false;
5705  unsigned sz = (unsigned)a_farmlist->size();
5706  for (unsigned f = 0; f < sz; f++) {
5707  if ((*a_farmlist)[f] == a_farm_ref) {
5708  found = true;
5709  break;
5710  }
5711  }
5712  if (!found) {
5713  a_farmlist->push_back( a_farm_ref );
5714  }
5715 }

Referenced by FindFarmWithOpenness().

◆ AddToManagementStats()

void FarmManager::AddToManagementStats ( FarmEvent a_ev)

Adds the event information to the management stats.

◆ BackTranslateCropCodes()

std::string FarmManager::BackTranslateCropCodes ( TTypesOfCrops  a_crop)

Converts toc_ to string.

3102  {
3103  // This simply checks through the list of legal crop types and returns
3104  // the correct string
3105 
3106  if (a_crop == toc_AsparagusEstablishedPlantation) return "AsparagusEstablishedPlantation";
3107  if (a_crop == toc_Beans) return "Beans";
3108  if (a_crop == toc_Beans_Whole) return "Beans_Whole";
3109  if (a_crop == toc_Beet) return "Beet";
3110  if (a_crop == toc_BushFruit) return "BushFruit";
3111  if (a_crop == toc_Cabbage) return "Cabbage";
3112  if (a_crop == toc_CabbageSpring) return "CabbageSpring";
3113  if (a_crop == toc_Carrots) return "Carrots";
3114  if (a_crop == toc_CarrotsSpring) return "CarrotsSpring";
3115  if (a_crop == toc_CatchCropPea) return "CatchCropPea";
3116  if (a_crop == toc_CloverGrassGrazed1) return "CloverGrassGrazed1";
3117  if (a_crop == toc_CloverGrassGrazed2) return "CloverGrassGrazed2";
3118  if (a_crop == toc_CloverGrassGrazed3) return "CloverGrassGrazed3";
3119  if (a_crop == toc_CorkOak) return "CorkOak";
3120  if (a_crop == toc_DummyCropPestTesting) return "DummyCropPestTesting";
3121  if (a_crop == toc_FieldPeas) return "FieldPeas";
3122  if (a_crop == toc_FieldPeasSilage) return "FieldPeasSilage";
3123  if (a_crop == toc_FieldPeasStrigling) return "FieldPeasStrigling";
3124  if (a_crop == toc_FodderBeet) return "FodderBeet";
3125  if (a_crop == toc_FodderGrass) return "FodderGrass";
3126  if (a_crop == toc_FodderLucerne1) return "FodderLucerne1";
3127  if (a_crop == toc_FodderLucerne2) return "FodderLucerne2";
3128  if (a_crop == toc_GenericCatchCrop) return "GenericCatchCrop";
3129  if (a_crop == toc_GrassGrazed1) return "GrassGrazed1";
3130  if (a_crop == toc_GrassGrazed2) return "GrassGrazed2";
3131  if (a_crop == toc_GrassGrazedExtensive) return "GrassGrazedExtensive";
3132  if (a_crop == toc_GrassGrazedLast) return "GrassGrazedLast";
3133  if (a_crop == toc_GrazingPigs) return "GrazingPigs";
3134  if (a_crop == toc_Horticulture) return "Horticulture";
3135  if (a_crop == toc_Maize) return "Maize";
3136  if (a_crop == toc_MaizeSilage) return "MaizeSilage";
3137  if (a_crop == toc_MaizeSpring) return "MaizeSpring";
3138  if (a_crop == toc_MaizeStrigling) return "MaizeStrigling";
3139  if (a_crop == toc_MixedVeg) return "MixedVeg";
3140  if (a_crop == toc_OAsparagusEstablishedPlantation) return "OAsparagusEstablishedPlantation";
3141  if (a_crop == toc_Oats) return "Oats";
3142  if (a_crop == toc_OBarleyPeaCloverGrass) return "OBarleyPeaCloverGrass";
3143  if (a_crop == toc_OBeans) return "OBeans";
3144  if (a_crop == toc_OBeans_Whole) return "OBeans_Whole";
3145  if (a_crop == toc_OBushFruit) return "OBushFruit";
3146  if (a_crop == toc_OCabbage) return "OCabbage";
3147  if (a_crop == toc_OCarrots) return "OCarrots";
3148  if (a_crop == toc_OCloverGrassGrazed1) return "OCloverGrassGrazed1";
3149  if (a_crop == toc_OCloverGrassGrazed2) return "OCloverGrassGrazed2";
3150  if (a_crop == toc_OCloverGrassGrazed3) return "OCloverGrassGrazed3";
3151  if (a_crop == toc_OCloverGrassSilage1) return "OCloverGrassSilage1";
3152  if (a_crop == toc_OFieldPeas) return "OFieldPeas";
3153  if (a_crop == toc_OFieldPeasSilage) return "OFieldPeasSilage";
3154  if (a_crop == toc_OFirstYearDanger) return "OFirstYearDanger";
3155  if (a_crop == toc_OFodderGrass) return "OFodderGrass";
3156  if (a_crop == toc_OFodderBeet) return "OFodderBeet";
3157  if (a_crop == toc_OGrazingPigs) return "OGrazingPigs";
3158  if (a_crop == toc_OliveGrove) return "OliveGrove";
3159  if (a_crop == toc_OLentils) return "OLentils";
3160  if (a_crop == toc_OLupines) return "OLupines";
3161  if (a_crop == toc_OMaize) return "OMaize";
3162  if (a_crop == toc_OMaizeSilage) return "OMaizeSilage";
3163  if (a_crop == toc_OOats) return "OOats";
3164  if (a_crop == toc_OPermanentGrassGrazed) return "OPermanentGrassGrazed";
3165  if (a_crop == toc_OPermanentGrassLowYield) return "PermanentGrassLowYield";
3166  if (a_crop == toc_OPotatoes) return "OPotatoes";
3167  if (a_crop == toc_OrchardCrop) return "OrchardCrop";
3168  if (a_crop == toc_OSBarleySilage) return "OSBarleySilage";
3169  if (a_crop == toc_OSeedGrass1) return "OSeedGrass1";
3170  if (a_crop == toc_OSeedGrass2) return "OSeedGrass2";
3171  if (a_crop == toc_OSpringBarley) return "OSpringBarley";
3172  if (a_crop == toc_OSpringBarleyExtensive) return "OSpringBarleyExtensive";
3173  if (a_crop == toc_OSpringBarleyPigs) return "OSpringBarleyPigs";
3174  if (a_crop == toc_OTriticale) return "OTriticale";
3175  if (a_crop == toc_OWinterBarley) return "OWinterBarley";
3176  if (a_crop == toc_OWinterBarleyExtensive) return "OWinterBarleyExtensive";
3177  if (a_crop == toc_OWinterRape) return "OWinterRape";
3178  if (a_crop == toc_OWinterRye) return "OWinterRye";
3179  if (a_crop == toc_OWinterWheat) return "OWinterWheat";
3180  if (a_crop == toc_OWinterWheatUndersown) return "OWinterWheatUndersown";
3181  if (a_crop == toc_OWinterWheatUndersownExtensive) return "OWinterWheatUndersownExtensive";
3182  if (a_crop == toc_PermanentGrassGrazed) return "PermanentGrassGrazed";
3183  if (a_crop == toc_PermanentGrassLowYield) return "PermanentGrassLowYield";
3184  if (a_crop == toc_PermanentGrassTussocky) return "PermanentGrassTussocky";
3185  if (a_crop == toc_PermanentSetAside) return "PermanentSetAside";
3186  if (a_crop == toc_PlantNursery) return "PlantNursery";
3187  if (a_crop == toc_Potatoes) return "Potatoes";
3188  if (a_crop == toc_PotatoesIndustry) return "PotatoesIndustry";
3189  if (a_crop == toc_PotatoesSpring) return "PotatoesSpring";
3190  if (a_crop == toc_Ryegrass) return "Ryegrass";
3191  if (a_crop == toc_ORyegrass) return "ORyegrass";
3192  if (a_crop == toc_SeedGrass1) return "SeedGrass1";
3193  if (a_crop == toc_SeedGrass2) return "SeedGrass2";
3194  if (a_crop == toc_SetAside) return "SetAside";
3195  if (a_crop == toc_Sorghum) return "Sorghum";
3196  if (a_crop == toc_SpringBarley) return "SpringBarley";
3197  if (a_crop == toc_SpringBarleyCloverGrass) return "SpringBarleyCloverGrass";
3198  if (a_crop == toc_SpringBarleyPeaCloverGrass) return "SpringBarleyPeaCloverGrass";
3199  if (a_crop == toc_SpringBarleySeed) return "SpringBarleySeed";
3200  if (a_crop == toc_SpringBarleySilage) return "SpringBarleySilage";
3201  if (a_crop == toc_SpringRape) return "SpringRape";
3202  if (a_crop == toc_SpringRye) return "SpringRye";
3203  if (a_crop == toc_SpringWheat) return "SpringWheat";
3204  if (a_crop == toc_SugarBeet) return "SugarBeet";
3205  if (a_crop == toc_Triticale) return "Triticale";
3206  if (a_crop == toc_Tulips) return "Tulips";
3207  if (a_crop == toc_Turnip) return "Turnip";
3208  if (a_crop == toc_Vineyards) return "Vineyards";
3209  if (a_crop == toc_WinterBarley) return "WinterBarley";
3210  if (a_crop == toc_WinterRape) return "WinterRape";
3211  if (a_crop == toc_WinterRye) return "WinterRye";
3212  if (a_crop == toc_WinterTriticale) return "WinterTriticale";
3213  if (a_crop == toc_WinterWheat) return "WinterWheat";
3214  if (a_crop == toc_YellowLupin) return "YellowLupin";
3215  if (a_crop == toc_YoungForestCrop) return "YoungForestCrop";
3216  if (a_crop == toc_OOrchardCrop) return "OOrchardCrop";
3217  if (a_crop == toc_OrchApple) return "OrchApple";
3218  if (a_crop == toc_OrchPear) return "OrchPear";
3219  if (a_crop == toc_OrchCherry) return "OrchCherry";
3220  if (a_crop == toc_OrchOther) return "OrchOther";
3221  if (a_crop == toc_OOrchApple) return "OOrchApple";
3222  if (a_crop == toc_OOrchPear) return "OOrchPear";
3223  if (a_crop == toc_OOrchCherry) return "OOrchCherry";
3224  if (a_crop == toc_OOrchOther) return "OOrchOther";
3225  if (a_crop == toc_OPotatoes) return "OPotatoes";
3226  if (a_crop == toc_OPotatoesIndustry) return "OPotatoesIndustry";
3227  if (a_crop == toc_OPotatoesSeed) return "OPotatoesSeed";
3228  if (a_crop == toc_OSetAside) return "OSetAside";
3229  if (a_crop == toc_OSetAside_Flower) return "OSetAside_Flower";
3230  if (a_crop == toc_OSpringBarleyCloverGrass) return "OSpringBarleyCloverGrass";
3231  if (a_crop == toc_OSpringBarleyPeaCloverGrass) return "OSpringBarleyPeaCloverGrass";
3232  if (a_crop == toc_OSpringBarleyPigs) return "OSpringBarleyPigs";
3233  if (a_crop == toc_OSpringBarleySilage) return "OSpringBarleySilage";
3234  if (a_crop == toc_OSpringRape) return "OSpringRape";
3235  if (a_crop == toc_OSpringWheat) return "OSpringWheat";
3236  if (a_crop == toc_OStarchPotato) return "OStarchPotato";
3237  if (a_crop == toc_OSugarBeet) return "OSugarBeet";
3238  if (a_crop == toc_OMixedVeg) return "OMixedVeg";
3239  if (a_crop == toc_OVegSeeds) return "OVegSeeds";
3240  if (a_crop == toc_PotatoesSeed) return "PotatoesSeed";
3241  if (a_crop == toc_StarchPotato) return "StarchPotato";
3242  if (a_crop == toc_VegSeeds) return "VegSeeds";
3243  if (a_crop == toc_FarmForest) return "FarmForest";
3244  if (a_crop == toc_OFarmForest) return "OFarmForest";
3245  if (a_crop == toc_OYoungForestCrop) return "OYoungForestCrop";
3246  if (a_crop == toc_Foobar) return "Foobar";
3247 
3248  // No match so issue a warning and quit
3249  g_msg->Warn(WARN_FILE, "FarmManager::TranslateCropCodes():"" Unknown Crop toc ", a_crop);
3250  exit(142);
3251 }

References g_msg, toc_AsparagusEstablishedPlantation, toc_Beans, toc_Beans_Whole, toc_Beet, toc_BushFruit, toc_Cabbage, toc_CabbageSpring, toc_Carrots, toc_CarrotsSpring, toc_CatchCropPea, toc_CloverGrassGrazed1, toc_CloverGrassGrazed2, toc_CloverGrassGrazed3, toc_CorkOak, toc_DummyCropPestTesting, toc_FarmForest, toc_FieldPeas, toc_FieldPeasSilage, toc_FieldPeasStrigling, toc_FodderBeet, toc_FodderGrass, toc_FodderLucerne1, toc_FodderLucerne2, toc_Foobar, toc_GenericCatchCrop, toc_GrassGrazed1, toc_GrassGrazed2, toc_GrassGrazedExtensive, toc_GrassGrazedLast, toc_GrazingPigs, toc_Horticulture, toc_Maize, toc_MaizeSilage, toc_MaizeSpring, toc_MaizeStrigling, toc_MixedVeg, toc_OAsparagusEstablishedPlantation, toc_Oats, toc_OBarleyPeaCloverGrass, toc_OBeans, toc_OBeans_Whole, toc_OBushFruit, toc_OCabbage, toc_OCarrots, toc_OCloverGrassGrazed1, toc_OCloverGrassGrazed2, toc_OCloverGrassGrazed3, toc_OCloverGrassSilage1, toc_OFarmForest, toc_OFieldPeas, toc_OFieldPeasSilage, toc_OFirstYearDanger, toc_OFodderBeet, toc_OFodderGrass, toc_OGrazingPigs, toc_OLentils, toc_OliveGrove, toc_OLupines, toc_OMaize, toc_OMaizeSilage, toc_OMixedVeg, toc_OOats, toc_OOrchApple, toc_OOrchardCrop, toc_OOrchCherry, toc_OOrchOther, toc_OOrchPear, toc_OPermanentGrassGrazed, toc_OPermanentGrassLowYield, toc_OPotatoes, toc_OPotatoesIndustry, toc_OPotatoesSeed, toc_OrchApple, toc_OrchardCrop, toc_OrchCherry, toc_OrchOther, toc_OrchPear, toc_ORyegrass, toc_OSBarleySilage, toc_OSeedGrass1, toc_OSeedGrass2, toc_OSetAside, toc_OSetAside_Flower, toc_OSpringBarley, toc_OSpringBarleyCloverGrass, toc_OSpringBarleyExtensive, toc_OSpringBarleyPeaCloverGrass, toc_OSpringBarleyPigs, toc_OSpringBarleySilage, toc_OSpringRape, toc_OSpringWheat, toc_OStarchPotato, toc_OSugarBeet, toc_OTriticale, toc_OVegSeeds, toc_OWinterBarley, toc_OWinterBarleyExtensive, toc_OWinterRape, toc_OWinterRye, toc_OWinterWheat, toc_OWinterWheatUndersown, toc_OWinterWheatUndersownExtensive, toc_OYoungForestCrop, toc_PermanentGrassGrazed, toc_PermanentGrassLowYield, toc_PermanentGrassTussocky, toc_PermanentSetAside, toc_PlantNursery, toc_Potatoes, toc_PotatoesIndustry, toc_PotatoesSeed, toc_PotatoesSpring, toc_Ryegrass, toc_SeedGrass1, toc_SeedGrass2, toc_SetAside, toc_Sorghum, toc_SpringBarley, toc_SpringBarleyCloverGrass, toc_SpringBarleyPeaCloverGrass, toc_SpringBarleySeed, toc_SpringBarleySilage, toc_SpringRape, toc_SpringRye, toc_SpringWheat, toc_StarchPotato, toc_SugarBeet, toc_Triticale, toc_Tulips, toc_Turnip, toc_VegSeeds, toc_Vineyards, toc_WinterBarley, toc_WinterRape, toc_WinterRye, toc_WinterTriticale, toc_WinterWheat, toc_YellowLupin, toc_YoungForestCrop, MapErrorMsg::Warn(), and WARN_FILE.

◆ CalcCentroids()

void FarmManager::CalcCentroids ( )
inline

calculate all farm centroids

1556 { for (unsigned int i = 0; i < m_farms.size(); i++) m_farms[i]->Centroids(); }

References m_farms.

◆ CheckOpenness()

bool FarmManager::CheckOpenness ( int  a_openness,
int  a_ref 
)

Check if a farm has at least one field with openness above a_openness.

6000  {
6001  if (m_farms[ a_ref ]->GetMaxOpenness() > a_openness) return true;
6002  return false;
6003 }

References m_farms.

◆ ConnectFarm()

int FarmManager::ConnectFarm ( int  a_owner)
3990 {
3991  for ( unsigned int i = 0; i < m_farms.size(); i++ )
3992  {
3993  if ( a_owner == m_farms[ i ]->GetFarmNumber() )
3994  {
3995  // Found it. Set mapping and return.
3996  return i;
3997  }
3998  }
3999  // We didn't find the owner in the list of farms,
4000  // pregenerated in CreateFarms() above. Something
4001  // is not correct here, so raise an appropriate
4002  // error and exit.
4003  char error_num[ 20 ];
4004  sprintf( error_num, "%d", a_owner );
4005  g_msg->Warn( WARN_FILE, "FarmManager::ConnectFarm(): Unknown farm number"" referenced in polygon file:", error_num );
4006  exit( 1 );
4007 }

References g_msg, m_farms, MapErrorMsg::Warn(), and WARN_FILE.

◆ CreateFarms()

void FarmManager::CreateFarms ( const char *  a_farmfile)
protected

Creates ther farms at simulation start.

4010 {
4011  int No, FType, NoFarms;
4012  string firstline = ""; // added for parsing between the two formats, could use "rubbish" below but better for readability
4013  string rubbish = ""; //put here the names of the parameters;
4014  float latitude, longitude;
4015  std::string country_code;
4016 
4017  ifstream ifile(a_farmfile);
4018  if (!ifile.is_open()) {
4019  g_msg->Warn( WARN_FILE, "Landscape::CreateFarms(): Unable to open file", a_farmfile );
4020  std::exit(1);
4021  }
4022 
4023  ifile >> NoFarms;
4024  m_farms.resize(NoFarms);
4025 
4026  m_farmmapping_lookup = new int[NoFarms * 2];
4027 
4028  for (int i = 0; i < NoFarms; i++)
4029  {
4030  // File format:
4031  //
4032  // Two colunms of numbers 0..number of farms, 0-number of farmtypes-1
4033  // the second column determines what type of farm we have
4034  ifile >> No >> FType;
4035  m_farmmapping_lookup[i * 2] = No;
4036  m_farmmapping_lookup[i * 2 + 1] = FType;
4037  }
4038  ifile.close();
4039 
4040  std::unordered_set<int> crop_set;
4041 
4043  int fv = g_farm_fixed_crop_type.value();
4044  TTypesOfVegetation fixed_crop_veg;
4045  fixed_crop_veg = g_letype->TranslateVegTypes(fv);
4046  crop_set.insert((int)fixed_crop_veg);
4047  }
4048 
4049  // Add the possible permanent crops without checking they really are on the current landscape
4050  // more difficult to check if really presents
4051  // as it is a combination of tole number and polygon belonging to a farm
4052  // so have to iterate over all polygons. This is faster for now.
4053 
4054  crop_set.insert((int)tov_PTPermanentGrassGrazed);
4055  crop_set.insert((int)tov_PTOliveGroveIntensive);
4056  crop_set.insert((int)tov_PTOliveGroveSuperIntensive);
4057  crop_set.insert((int)tov_PTOliveGroveTraditional);
4058  crop_set.insert((int)tov_PTOliveGroveTradOrganic);
4059  crop_set.insert((int)tov_PermanentGrassLowYield);
4060  crop_set.insert((int)tov_PlantNursery);
4061  crop_set.insert((int)tov_YoungForest);
4062  crop_set.insert((int)tov_DEPermanentGrassGrazed);
4063  crop_set.insert((int)tov_DEPermanentGrassLowYield);
4064  crop_set.insert((int)tov_DEOPermanentGrassGrazed);
4065  crop_set.insert((int)tov_DEOPermanentGrassLowYield);
4066  crop_set.insert((int)tov_NLPermanentGrassGrazed);
4067  crop_set.insert((int)tov_NLPermanentGrassGrazedExtensive);
4068  crop_set.insert((int)tov_PermanentGrassGrazed);
4069  crop_set.insert((int)tov_PermanentGrassTussocky);
4070  crop_set.insert((int)tov_PermanentSetAside);
4071  crop_set.insert((int)tov_BEOrchardCrop);
4072  crop_set.insert((int)tov_NLOrchardCrop);
4073  crop_set.insert((int)tov_OrchardCrop);
4074  crop_set.insert((int)tov_DEAsparagusEstablishedPlantation);
4075  crop_set.insert((int)tov_DEOAsparagusEstablishedPlantation);
4076  crop_set.insert((int)tov_DKBushFruit_Perm1);
4077  crop_set.insert((int)tov_DKBushFruit_Perm2);
4078  crop_set.insert((int)tov_DKChristmasTrees_Perm);
4079  crop_set.insert((int)tov_DKOChristmasTrees_Perm);
4080  crop_set.insert((int)tov_DEOrchard);
4081  crop_set.insert((int)tov_DEOOrchard);
4082  crop_set.insert((int)tov_DEBushFruitPerm);
4083  crop_set.insert((int)tov_DEOBushFruitPerm);
4084  crop_set.insert((int)tov_DKOBushFruit_Perm1);
4085  crop_set.insert((int)tov_DKOBushFruit_Perm2);
4086  crop_set.insert((int)tov_DKGrassGrazed_Perm);
4087  crop_set.insert((int)tov_DKGrassTussocky_Perm);
4088  crop_set.insert((int)tov_DKOGrassGrazed_Perm);
4089  crop_set.insert((int)tov_DKGrassLowYield_Perm);
4090  crop_set.insert((int)tov_DKOGrassLowYield_Perm);
4091  crop_set.insert((int)tov_DKGrazingPigs_Perm);
4092  crop_set.insert((int)tov_DKOGrazingPigs_Perm);
4093  crop_set.insert((int)tov_DKEnergyCrop_Perm);
4094  crop_set.insert((int)tov_DKOEnergyCrop_Perm);
4095  crop_set.insert((int)tov_DKFarmForest_Perm);
4096  crop_set.insert((int)tov_DKOFarmForest_Perm);
4097  crop_set.insert((int)tov_DKFarmYoungForest_Perm);
4098  crop_set.insert((int)tov_DKOFarmYoungForest_Perm);
4099  crop_set.insert((int)tov_DKOrchApple);
4100  crop_set.insert((int)tov_DKOOrchApple);
4101  crop_set.insert((int)tov_DKOrchCherry);
4102  crop_set.insert((int)tov_DKOOrchCherry);
4103  crop_set.insert((int)tov_DKOrchPear);
4104  crop_set.insert((int)tov_DKOOrchPear);
4105  crop_set.insert((int)tov_DKOrchOther);
4106  crop_set.insert((int)tov_DKOOrchOther);
4107  crop_set.insert((int)tov_DKOrchardCrop_Perm);
4108  crop_set.insert((int)tov_DKOOrchardCrop_Perm);
4109  crop_set.insert((int)tov_DKPlantNursery_Perm);
4110  crop_set.insert((int)tov_FINaturalGrassland_Perm);
4111  crop_set.insert((int)tov_FIFeedingGround);
4112  crop_set.insert((int)tov_FIGreenFallow_Perm);
4113  crop_set.insert((int)tov_FIBufferZone_Perm);
4114  crop_set.insert((int)tov_FRGrassland_Perm);
4115 
4116  for (int i = 0; i < NoFarms; i++)
4117  {
4118  /*
4119  //If we are testing crop management, then ignore farm type from
4120  // the file and set to fixed one instead.
4121  if ( g_farm_test_crop.value() ) {
4122  FType = g_farm_test_crop_farmtype.value();
4123  }
4124  */
4125  // If we are running in fixed, sync'ed rotation mode, set all farms to
4126  // be of the requested type.
4129  }
4130 
4131  switch (m_farmmapping_lookup[i * 2 + 1]) // FType
4132  {
4133  case 0:
4134  m_farms[i] = new ConventionalCattle(this);
4135  break;
4136  case 1:
4137  m_farms[i] = new ConventionalPig(this);
4138  break;
4139  case 2:
4140  m_farms[i] = new ConventionalPlant(this);
4141  break;
4142  case 3:
4143  m_farms[i] = new OrganicCattle(this);
4144  break;
4145  case 4:
4146  m_farms[i] = new OrganicPig(this);
4147  break;
4148  case 5:
4149  m_farms[i] = new OrganicPlant(this);
4150  break;
4151  case 6:
4152  m_farms[i] = new PesticideTrialControl(this);
4153  break;
4154  case 7:
4155  m_farms[i] = new PesticideTrialToxicControl(this);
4156  break;
4157  case 8:
4158  m_farms[i] = new PesticideTrialTreatment(this);
4159  break;
4160  case 9:
4161  m_farms[i] = new ConvMarginalJord(this);
4162  break;
4163  case 10:
4164  m_farms[i] = new AgroChemIndustryCerealFarm1(this);
4165  break;
4166  case 11:
4167  m_farms[i] = new AgroChemIndustryCerealFarm2(this);
4168  break;
4169  case 12:
4170  m_farms[i] = new AgroChemIndustryCerealFarm3(this);
4171  break;
4172  case 13:
4173  m_farms[i] = new NoPesticideBaseFarm(this);
4174  break;
4175  case 14:
4176  m_farms[i] = new NoPesticideNoPFarm(this);
4177  break;
4178  case 15:
4179  m_farms[i] = new UserDefinedFarm1(this);
4180  break;
4181  case 16:
4182  m_farms[i] = new UserDefinedFarm2(this);
4183  break;
4184  case 17:
4185  m_farms[i] = new UserDefinedFarm3(this);
4186  break;
4187  case 18:
4188  m_farms[i] = new UserDefinedFarm4(this);
4189  break;
4190  case 19:
4191  m_farms[i] = new UserDefinedFarm5(this);
4192  break;
4193  case 20:
4194  m_farms[i] = new UserDefinedFarm6(this);
4195  break;
4196  case 21:
4197  m_farms[i] = new UserDefinedFarm7(this);
4198  break;
4199  case 22:
4200  m_farms[i] = new UserDefinedFarm8(this);
4201  break;
4202  case 23:
4203  m_farms[i] = new UserDefinedFarm9(this);
4204  break;
4205  case 24:
4206  m_farms[i] = new UserDefinedFarm10(this);
4207  break;
4208  case 25:
4209  m_farms[i] = new UserDefinedFarm11(this);
4210  break;
4211  case 26:
4212  m_farms[i] = new UserDefinedFarm12(this);
4213  break;
4214  case 27:
4215  m_farms[i] = new UserDefinedFarm13(this);
4216  break;
4217  case 28:
4218  m_farms[i] = new UserDefinedFarm14(this);
4219  break;
4220  case 29:
4221  m_farms[i] = new UserDefinedFarm15(this);
4222  break;
4223  case 30:
4224  m_farms[i] = new UserDefinedFarm16(this);
4225  break;
4226  case 31:
4227  m_farms[i] = new UserDefinedFarm17(this);
4228  break;
4229  // NB the user defing farms below require an extra parameter in the rotation file denoting the intensity (0 or 1 = high low)
4230  case 32:
4231  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm18, "UserDefinedFarm18.rot", this);
4232  break;
4233  case 33:
4234  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm19, "UserDefinedFarm19.rot", this);
4235  break;
4236  case 34:
4237  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm20, "UserDefinedFarm20.rot", this);
4238  break;
4239  case 35:
4240  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm21, "UserDefinedFarm21.rot", this);
4241  break;
4242  case 36:
4243  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm22, "UserDefinedFarm22.rot", this);
4244  break;
4245  case 37:
4246  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm23, "UserDefinedFarm23.rot", this);
4247  break;
4248  case 38:
4249  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm24, "UserDefinedFarm24.rot", this);
4250  break;
4251  case 39:
4252  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm25, "UserDefinedFarm25.rot", this);
4253  break;
4254  case 40:
4255  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm26, "UserDefinedFarm26.rot", this);
4256  break;
4257  case 41:
4258  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm27, "UserDefinedFarm27.rot", this);
4259  break;
4260  case 42:
4261  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm28, "UserDefinedFarm28.rot", this);
4262  break;
4263  case 43:
4264  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm29, "UserDefinedFarm29.rot", this);
4265  break;
4266  case 44:
4267  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm30, "UserDefinedFarm30.rot", this);
4268  break;
4269  case 45:
4270  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm31, "UserDefinedFarm31.rot", this);
4271  break;
4272  case 46:
4273  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm32, "UserDefinedFarm32.rot", this);
4274  break;
4275  case 47:
4276  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm33, "UserDefinedFarm33.rot", this);
4277  break;
4278  case 48:
4279  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm34, "UserDefinedFarm34.rot", this);
4280  break;
4281  case 49:
4282  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm35, "UserDefinedFarm35.rot", this);
4283  break;
4284  case 50:
4285  m_farms[i] = new UserDefinedFarm(tof_UserDefinedFarm36, "UserDefinedFarm36.rot", this);
4286  break;
4287  default:
4288  g_msg->Warn(WARN_FILE, "FarmManager::CreateFarms(): Unknown farm type reference number: ", m_farmmapping_lookup[i * 2 + 1]);
4289  exit(1);
4290  }
4291  m_farms[i]->SetFarmNumber(i); // We use 'i' here because we renumber the farms internally. If the file did not come in this way then a dump file is created - tested in ReadPolys2
4292  m_farmers->AddFarmer(m_farms[i]->GetFarmer()); // Pushes the farm to the end of the vector (index should be i)
4293  /* Add crop/tov to the set (making for unique entries) */
4294  for (int j = 0; j < m_farms[i]->GetNoCrops(); j++) {
4295  crop_set.insert((int)m_farms[i]->GetCrop(j));
4296  }
4297 
4298  }
4299 
4300  // Load the selected cropprogs (for the entire lanscape) into the FarmManager
4301  for (std::unordered_set<int>::iterator itr = crop_set.begin(); itr != crop_set.end(); ++itr)
4302  {
4303  switch (*itr)
4304  {
4305  case tov_BEBeet:
4307  break;
4308  case tov_BEBeetSpring:
4310  break;
4311  //case tov_BECatchPeaCrop:
4312  //m_cropprogs.push_back(new BECatchPeaCrop(tov_BECatchPeaCrop, toc_CatchCropPea, g_landscape_ptr));
4313  //break;
4314  case tov_BEGrassGrazed1:
4316  break;
4319  break;
4320  case tov_BEGrassGrazed2:
4322  break;
4323  case tov_BEGrassGrazedLast:
4325  break;
4326  case tov_BEMaize:
4328  break;
4329  case tov_BEMaizeSpring:
4331  break;
4332  case tov_BEOrchardCrop:
4334  break;
4335  case tov_BEPotatoes:
4337  break;
4338  case tov_BEPotatoesSpring:
4340  break;
4341  case tov_BEWinterBarley:
4343  break;
4344  case tov_BEWinterWheat:
4346  break;
4347  case tov_BEWinterWheatCC:
4349  break;
4350  case tov_BEWinterBarleyCC:
4352  break;
4353  case tov_BEMaizeCC:
4355  break;
4356 
4357  case tov_DKBushFruit_Perm1:
4359  break;
4360  case tov_DKBushFruit_Perm2:
4362  break;
4363  case tov_DKCabbages:
4365  break;
4366  case tov_DKCarrots:
4368  break;
4371  break;
4372  case tov_DKCerealLegume:
4374  break;
4377  break;
4380  break;
4383  break;
4386  break;
4389  break;
4392  break;
4395  break;
4396  case tov_DKEnergyCrop_Perm:
4398  break;
4399  case tov_DKFarmForest_Perm:
4401  break;
4404  break;
4405  case tov_DKFodderBeets:
4407  break;
4410  break;
4413  break;
4416  break;
4419  break;
4422  break;
4423  case tov_DKGrazingPigs:
4425  break;
4428  break;
4429  case tov_DKLegume_Whole:
4431  break;
4432  case tov_DKLegume_Peas:
4434  break;
4435  case tov_DKLegume_Beans:
4437  break;
4438  case tov_DKMaize:
4440  break;
4441  case tov_DKMaizeSilage:
4443  break;
4444  case tov_DKMixedVeg:
4446  break;
4449  break;
4452  break;
4453  case tov_DKOCabbages:
4455  break;
4456  case tov_DKOCarrots:
4458  break;
4459  case tov_DKOCerealLegume:
4461  break;
4464  break;
4467  break;
4470  break;
4473  break;
4474  case tov_DKOFodderBeets:
4476  break;
4479  break;
4482  break;
4485  break;
4488  break;
4489  case tov_DKOGrazingPigs:
4491  break;
4494  break;
4495  case tov_DKOMaize:
4497  break;
4498  case tov_DKOMaizeSilage:
4500  break;
4501  case tov_DKOMixedVeg:
4503  break;
4504  case tov_DKOPotato:
4506  break;
4507  case tov_DKOPotatoIndustry:
4509  break;
4510  case tov_DKOPotatoSeed:
4512  break;
4515  break;
4518  break;
4521  break;
4524  break;
4527  break;
4528  case tov_DKOrchApple:
4530  break;
4531  case tov_DKOrchPear:
4533  break;
4534  case tov_DKOrchCherry:
4536  break;
4537  case tov_DKOrchOther:
4539  break;
4540  case tov_DKOOrchApple:
4542  break;
4543  case tov_DKOOrchPear:
4545  break;
4546  case tov_DKOOrchCherry:
4548  break;
4549  case tov_DKOOrchOther:
4551  break;
4554  break;
4557  break;
4560  break;
4563  break;
4564  case tov_DKOLegume_Beans:
4566  break;
4567  case tov_DKOLegume_Peas:
4569  break;
4570  case tov_DKOLegume_Whole:
4572  break;
4575  break;
4576  case tov_DKOLegume_Peas_CC:
4578  break;
4581  break;
4582  case tov_DKOLentils:
4584  break;
4585  case tov_DKOLupines:
4587  break;
4590  break;
4591  case tov_DKOSetAside:
4593  break;
4596  break;
4599  break;
4602  break;
4603  case tov_DKOSpringBarley:
4605  break;
4608  break;
4611  break;
4614  break;
4615  case tov_DKOSpringOats:
4617  break;
4618  case tov_DKOSpringOats_CC:
4620  break;
4621  case tov_DKOSpringWheat:
4623  break;
4624  case tov_DKOSugarBeets:
4626  break;
4627  case tov_DKOVegSeeds:
4629  break;
4630  case tov_DKOWinterBarley:
4632  break;
4633  case tov_DKOWinterRape:
4635  break;
4636  case tov_DKOWinterRye:
4638  break;
4639  case tov_DKOWinterRye_CC:
4641  break;
4642  case tov_DKOWinterWheat:
4644  break;
4645  case tov_DKOWinterWheat_CC:
4647  break;
4650  break;
4651  case tov_DKPotato:
4653  break;
4654  case tov_DKPotatoIndustry:
4656  break;
4657  case tov_DKPotatoSeed:
4659  break;
4662  break;
4665  break;
4666  case tov_DKSetAside:
4668  break;
4671  break;
4672  case tov_DKSpringBarley:
4674  break;
4675  case tov_DKSpringBarley_CC:
4677  break;
4680  break;
4683  break;
4686  break;
4687  case tov_DKSpringOats:
4689  break;
4690  case tov_DKSpringOats_CC:
4692  break;
4693  case tov_DKSpringWheat:
4695  break;
4696  case tov_DKSugarBeets:
4698  break;
4699  case tov_DKVegSeeds:
4701  break;
4702  case tov_DKWinterBarley:
4704  break;
4705  case tov_DKWinterRape:
4707  break;
4708  case tov_DKWinterRye:
4710  break;
4711  case tov_DKWinterRye_CC:
4713  break;
4714  case tov_DKWinterWheat:
4716  break;
4717  case tov_DKWinterWheat_CC:
4719  break;
4720  case tov_FIBufferZone:
4722  break;
4723  case tov_FIBufferZone_Perm:
4725  break;
4726  case tov_FICaraway1:
4728  break;
4729  case tov_FICaraway2:
4731  break;
4732  case tov_FIOCaraway1:
4734  break;
4735  case tov_FIOCaraway2:
4737  break;
4738  case tov_FIFabaBean:
4740  break;
4741  case tov_FIFeedingGround:
4743  break;
4746  break;
4749  break;
4752  break;
4755  break;
4758  break;
4761  break;
4764  break;
4767  break;
4770  break;
4771  case tov_FIOFabaBean:
4773  break;
4774  case tov_FIOPotato_North:
4776  break;
4777  case tov_FIOPotato_South:
4779  break;
4782  break;
4785  break;
4788  break;
4791  break;
4792  case tov_FIOSpringOats:
4794  break;
4795  case tov_FIOSpringRape:
4797  break;
4798  case tov_FIOSpringWheat:
4800  break;
4803  break;
4806  break;
4807  case tov_FIOTurnipRape:
4809  break;
4810  case tov_FIOWinterRye:
4812  break;
4813  case tov_FIOWinterWheat:
4815  break;
4816  case tov_FIPotato_North:
4818  break;
4819  case tov_FIPotato_South:
4821  break;
4824  break;
4827  break;
4830  break;
4833  break;
4836  break;
4837  case tov_FISpringOats:
4839  break;
4840  case tov_FISpringRape:
4842  break;
4843  case tov_FISpringWheat:
4845  break;
4848  break;
4851  break;
4852  case tov_FISugarBeet:
4854  break;
4855  case tov_FITurnipRape:
4857  break;
4858  case tov_FIWinterRye:
4860  break;
4861  case tov_FIWinterWheat:
4863  break;
4864  case tov_SESpringBarley:
4866  break;
4867  case tov_SEWinterRape_Seed:
4869  break;
4870  case tov_SEWinterWheat:
4872  break;
4873  case tov_FRWinterWheat:
4875  break;
4876  case tov_FRWinterBarley:
4878  break;
4879  case tov_FRWinterTriticale:
4881  break;
4882  case tov_FRWinterRape:
4884  break;
4885  case tov_FRMaize:
4887  break;
4888  case tov_FRMaize_Silage:
4890  break;
4891  case tov_FRSpringBarley:
4893  break;
4894  case tov_FRGrassland:
4896  break;
4897  case tov_FRGrassland_Perm:
4899  break;
4900  case tov_FRSpringOats:
4902  break;
4903  case tov_FRSunflower:
4905  break;
4906  case tov_FRSpringWheat:
4908  break;
4909  case tov_FRPotatoes:
4911  break;
4912  case tov_FRSorghum:
4914  break;
4915  case tov_ITGrassland:
4917  break;
4918  case tov_ITOrchard:
4920  break;
4921  case tov_ITOOrchard:
4923  break;
4924  case tov_BroadBeans:
4926  break;
4927  case tov_Carrots:
4929  break;
4932  break;
4935  break;
4936 
4937  case tov_DEBushFruitPerm:
4939  break;
4940  case tov_DEOBushFruitPerm:
4942  break;
4943  case tov_DEOats:
4945  break;
4946  case tov_DESpringRye:
4948  break;
4949  case tov_DEWinterWheat:
4951  break;
4952  case tov_DEWinterWheatLate:
4954  break;
4955  case tov_DEMaizeSilage:
4957  break;
4958  case tov_DEPotatoes:
4960  break;
4963  break;
4964  case tov_DEMaize:
4966  break;
4967  case tov_DEWinterRye:
4969  break;
4970  case tov_DEWinterBarley:
4972  break;
4973  case tov_DESugarBeet:
4975  break;
4976  case tov_DEWinterRape:
4978  break;
4979  case tov_DETriticale:
4981  break;
4982  case tov_DECabbage:
4984  break;
4985  case tov_DECarrots:
4987  break;
4990  break;
4993  break;
4994  case tov_DELegumes:
4996  break;
4997  case tov_DEOCabbages:
4999  break;
5000  case tov_DEOCarrots:
5002  break;
5005  break;
5008  break;
5009  case tov_DEOLegume:
5011  break;
5012  case tov_DEOMaize:
5014  break;
5015  case tov_DEOMaizeSilage:
5017  break;
5018  case tov_DEOOats:
5020  break;
5021  case tov_DEOPeas:
5023  break;
5026  break;
5029  break;
5030  case tov_DEOPotatoes:
5032  break;
5033  case tov_DEOSpringRye:
5035  break;
5036  case tov_DEOSugarBeet:
5038  break;
5039  case tov_DEOTriticale:
5041  break;
5042  case tov_DEOWinterBarley:
5044  break;
5045  case tov_DEOWinterRape:
5047  break;
5048  case tov_DEOWinterRye:
5050  break;
5051  case tov_DEOWinterWheat:
5053  break;
5054  case tov_DEPeas:
5056  break;
5059  break;
5062  break;
5065  break;
5068  break;
5071  break;
5074  break;
5077  break;
5080  break;
5081  case tov_DESpringBarley:
5083  break;
5084  case tov_DEOrchard:
5086  break;
5087  case tov_DEOOrchard:
5089  break;
5090 
5093  break;
5094  case tov_FieldPeas:
5096  break;
5097  case tov_FieldPeasSilage:
5099  break;
5102  break;
5103  case tov_FodderBeet:
5105  break;
5106  case tov_FodderGrass:
5108  break;
5109  case tov_GenericCatchCrop:
5111  break;
5112 
5113  case tov_IRSpringWheat:
5115  break;
5116  case tov_IRSpringBarley:
5118  break;
5119  case tov_IRSpringOats:
5121  break;
5124  break;
5127  break;
5128  case tov_IRWinterBarley:
5130  break;
5131  case tov_IRWinterWheat:
5133  break;
5134  case tov_IRWinterOats:
5136  break;
5137 
5138  case tov_Maize:
5140  break;
5141  case tov_MaizeSilage:
5143  break;
5144  case tov_MaizeStrigling:
5146  break;
5147  case tov_NLBeet:
5149  break;
5150  case tov_NLBeetSpring:
5152  break;
5153  case tov_NLCabbage:
5155  break;
5156  case tov_NLCabbageSpring:
5158  break;
5159  case tov_NLCarrots:
5161  break;
5162  case tov_NLCarrotsSpring:
5164  break;
5165  case tov_NLGrassGrazed1:
5167  break;
5170  break;
5171  case tov_NLGrassGrazed2:
5173  break;
5176  break;
5179  break;
5182  break;
5185  break;
5186  case tov_NLGrassGrazedLast:
5188  break;
5189  case tov_NLMaize:
5191  break;
5192  case tov_NLMaizeSpring:
5194  break;
5195  case tov_NLOrchardCrop:
5197  break;
5200  break;
5203  break;
5204  case tov_NLPotatoes:
5206  break;
5207  case tov_NLPotatoesSpring:
5209  break;
5210  case tov_NLSpringBarley:
5212  break;
5215  break;
5216  case tov_NLTulips:
5218  break;
5219  case tov_NLWinterWheat:
5221  break;
5222  case tov_NorwegianOats:
5224  break;
5225  case tov_NorwegianPotatoes:
5227  break;
5230  break;
5231  case tov_Oats:
5232  m_cropprogs.push_back(new Oats(tov_Oats, toc_Oats, g_landscape_ptr));
5233  break;
5236  break;
5237  case tov_OCarrots:
5239  break;
5242  break;
5245  break;
5248  break;
5249  case tov_OFieldPeas:
5251  break;
5252  case tov_OFieldPeasSilage:
5254  break;
5255  case tov_OFirstYearDanger:
5257  break;
5258  case tov_OFodderBeet:
5260  break;
5261  case tov_OGrazingPigs:
5263  break;
5264  case tov_OMaizeSilage:
5266  break;
5267  case tov_OOats:
5269  break;
5272  break;
5273  case tov_OPotatoes:
5275  break;
5276  case tov_OrchardCrop:
5278  break;
5279  case tov_OSBarleySilage:
5281  break;
5282  case tov_OSeedGrass1:
5284  break;
5285  case tov_OSeedGrass2:
5287  break;
5288  case tov_OSpringBarley:
5290  break;
5291  case tov_OSpringBarleyExt:
5293  break;
5294  case tov_OSpringBarleyPigs:
5296  break;
5297  case tov_OTriticale:
5299  break;
5300  case tov_OWinterBarley:
5302  break;
5303  case tov_OWinterBarleyExt:
5305  break;
5306  case tov_OWinterRape:
5308  break;
5309  case tov_OWinterRye:
5311  break;
5312  case tov_OWinterWheat:
5314  break;
5317  break;
5320  break;
5323  break;
5326  break;
5329  break;
5330  case tov_PermanentSetAside:
5332  break;
5333  case tov_PLBeans:
5335  break;
5336  case tov_PLBeet:
5338  break;
5339  case tov_PLBeetSpr:
5341  break;
5342  case tov_PLCarrots:
5344  break;
5345  case tov_PLFodderLucerne1:
5347  break;
5348  case tov_PLFodderLucerne2:
5350  break;
5351  case tov_PLMaize:
5353  break;
5354  case tov_PLMaizeSilage:
5356  break;
5357  case tov_PLPotatoes:
5359  break;
5360  case tov_PLSpringBarley:
5362  break;
5363  case tov_PLSpringBarleySpr:
5365  break;
5366  case tov_PLSpringWheat:
5368  break;
5369  case tov_PLWinterBarley:
5371  break;
5372  case tov_PLWinterRape:
5374  break;
5375  case tov_PLWinterRye:
5377  break;
5378  case tov_PLWinterTriticale:
5380  break;
5381  case tov_PLWinterWheat:
5383  break;
5384  case tov_PLWinterWheatLate:
5386  break;
5387  case tov_Potatoes:
5389  break;
5390  case tov_PotatoesIndustry:
5392  break;
5393  case tov_PTBeans:
5395  break;
5398  break;
5401  break;
5402  case tov_PTCorkOak:
5404  break;
5405  case tov_PTFodderMix:
5407  break;
5408  case tov_PTGrassGrazed:
5410  break;
5411  case tov_PTCabbage:
5413  break;
5414  case tov_PTCabbage_Hort:
5416  break;
5417  case tov_PTMaize:
5419  break;
5420  case tov_PTMaize_Hort:
5422  break;
5423  case tov_PTOats:
5425  break;
5428  break;
5431  break;
5434  break;
5437  break;
5438  case tov_PTOtherDryBeans:
5440  break;
5441  case tov_PTRyegrass:
5443  break;
5446  break;
5447  case tov_PTPotatoes:
5449  break;
5450  case tov_PTShrubPastures:
5452  break;
5453  case tov_PTSorghum:
5455  break;
5456  case tov_PTTriticale:
5458  break;
5459  case tov_PTVineyards:
5461  break;
5462  case tov_PTWinterBarley:
5464  break;
5465  case tov_PTWinterRye:
5467  break;
5468  case tov_PTWinterWheat:
5470  break;
5471  case tov_PTYellowLupin:
5473  break;
5474  case tov_PTSetAside:
5476  break;
5477  case tov_SeedGrass1:
5479  break;
5480  case tov_SeedGrass2:
5482  break;
5483  case tov_SetAside:
5485  break;
5486  case tov_SpringBarley:
5488  break;
5491  break;
5494  break;
5497  break;
5498  case tov_SpringBarleySeed:
5500  break;
5503  break;
5506  break;
5507  case tov_SpringBarleySpr:
5509  break;
5512  break;
5515  break;
5518  break;
5519  case tov_SpringRape:
5521  break;
5522  case tov_SugarBeet:
5524  break;
5525  case tov_Triticale:
5527  break;
5528  case tov_UKBeans:
5530  break;
5531  case tov_UKBeet:
5533  break;
5534  case tov_UKMaize:
5536  break;
5537  case tov_UKPermanentGrass:
5539  break;
5540  case tov_UKPotatoes:
5542  break;
5543  case tov_UKSpringBarley:
5545  break;
5546  case tov_UKTempGrass:
5547  m_cropprogs.push_back(new UKTempGrass(tov_UKTempGrass, toc_GrassGrazed1, g_landscape_ptr)); //EZ: toc to be checked!
5548  break;
5549  case tov_UKWinterBarley:
5551  break;
5552  case tov_UKWinterRape:
5554  break;
5555  case tov_UKWinterWheat:
5557  break;
5558  case tov_WinterBarley:
5560  break;
5563  break;
5564  case tov_WinterRape:
5566  break;
5569  break;
5570  case tov_WinterRye:
5572  break;
5575  break;
5576  case tov_WinterWheat:
5578  break;
5581  break;
5584  break;
5587  break;
5588  case tov_YoungForest:
5590  break;
5591  case tov_PlantNursery: // "uses youngforest management because this effectively does nothing, but stops the crop management creating looping errors"
5593  break;
5594  default:
5595  g_msg->Warn(WARN_FILE, "Landscape::CreateFarms(): Missing Cropprog definition for TOV code", to_string(*itr));
5596  exit(1);
5597  }
5598  }
5599  // These crops are not part of a defined management so need to be loaded in case they are used
5606 
5607 
5608  if (GetFarmNoLookup(NoFarms - 1) != NoFarms - 1)
5609  m_renumbered = false;
5610  else
5611  m_renumbered = true;
5612 }

References FarmerList::AddFarmer(), g_farm_fixed_crop_enable, g_farm_fixed_crop_type, g_farm_fixed_rotation_enable, g_farm_fixed_rotation_farmtype, g_landscape_ptr, g_letype, g_msg, GetFarmer(), GetFarmNoLookup(), m_cropprogs, m_farmers, m_farmmapping_lookup, m_farms, m_renumbered, toc_AsparagusEstablishedPlantation, toc_Beans, toc_Beans_Whole, toc_Beet, toc_BushFruit, toc_Cabbage, toc_CabbageSpring, toc_Carrots, toc_CarrotsSpring, toc_CatchCropPea, toc_CloverGrassGrazed1, toc_CloverGrassGrazed2, toc_CloverGrassGrazed3, toc_CorkOak, toc_DummyCropPestTesting, toc_FarmForest, toc_FieldPeas, toc_FieldPeasSilage, toc_FieldPeasStrigling, toc_FodderBeet, toc_FodderGrass, toc_FodderLucerne1, toc_FodderLucerne2, toc_GenericCatchCrop, toc_GrassGrazed1, toc_GrassGrazed2, toc_GrassGrazedExtensive, toc_GrassGrazedLast, toc_GrazingPigs, toc_Horticulture, toc_Maize, toc_MaizeSilage, toc_MaizeSpring, toc_MaizeStrigling, toc_MixedVeg, toc_OAsparagusEstablishedPlantation, toc_Oats, toc_OBarleyPeaCloverGrass, toc_OBeans, toc_OBeans_Whole, toc_OBushFruit, toc_OCabbage, toc_OCarrots, toc_OCloverGrassGrazed1, toc_OCloverGrassGrazed2, toc_OCloverGrassGrazed3, toc_OCloverGrassSilage1, toc_OFarmForest, toc_OFieldPeas, toc_OFieldPeasSilage, toc_OFirstYearDanger, toc_OFodderBeet, toc_OFodderGrass, toc_OGrazingPigs, toc_OLentils, toc_OliveGrove, toc_OLupines, toc_OMaize, toc_OMaizeSilage, toc_OMixedVeg, toc_OOats, toc_OOrchApple, toc_OOrchardCrop, toc_OOrchCherry, toc_OOrchOther, toc_OOrchPear, toc_OPermanentGrassGrazed, toc_OPermanentGrassLowYield, toc_OPotatoes, toc_OPotatoesIndustry, toc_OPotatoesSeed, toc_OrchApple, toc_OrchardCrop, toc_OrchCherry, toc_OrchOther, toc_OrchPear, toc_ORyeGrass, toc_ORyegrass, toc_OSBarleySilage, toc_OSeedGrass1, toc_OSeedGrass2, toc_OSetAside, toc_OSetAside_Flower, toc_OSpringBarley, toc_OSpringBarleyCloverGrass, toc_OSpringBarleyExtensive, toc_OSpringBarleyPeaCloverGrass, toc_OSpringBarleyPigs, toc_OSpringBarleySilage, toc_OSpringRape, toc_OSpringRye, toc_OSpringWheat, toc_OStarchPotato, toc_OSugarBeet, toc_OTriticale, toc_OVegSeeds, toc_OWinterBarley, toc_OWinterBarleyExtensive, toc_OWinterRape, toc_OWinterRye, toc_OWinterWheat, toc_OWinterWheatUndersown, toc_OWinterWheatUndersownExtensive, toc_OYoungForestCrop, toc_PermanentGrassGrazed, toc_PermanentGrassLowYield, toc_PermanentGrassTussocky, toc_PermanentSetAside, toc_PlantNursery, toc_Potatoes, toc_PotatoesIndustry, toc_PotatoesSeed, toc_PotatoesSpring, toc_Ryegrass, toc_SeedGrass1, toc_SeedGrass2, toc_SetAside, toc_Sorghum, toc_SpringBarley, toc_SpringBarleyCloverGrass, toc_SpringBarleyPeaCloverGrass, toc_SpringBarleySeed, toc_SpringBarleySilage, toc_SpringRape, toc_SpringRye, toc_SpringWheat, toc_StarchPotato, toc_SugarBeet, toc_Sunflower, toc_Triticale, toc_Tulips, toc_Turnip, toc_VegSeeds, toc_Vineyards, toc_WinterBarley, toc_WinterRape, toc_WinterRye, toc_WinterTriticale, toc_WinterWheat, toc_YellowLupin, toc_YoungForestCrop, tof_UserDefinedFarm18, tof_UserDefinedFarm19, tof_UserDefinedFarm20, tof_UserDefinedFarm21, tof_UserDefinedFarm22, tof_UserDefinedFarm23, tof_UserDefinedFarm24, tof_UserDefinedFarm25, tof_UserDefinedFarm26, tof_UserDefinedFarm27, tof_UserDefinedFarm28, tof_UserDefinedFarm29, tof_UserDefinedFarm30, tof_UserDefinedFarm31, tof_UserDefinedFarm32, tof_UserDefinedFarm33, tof_UserDefinedFarm34, tof_UserDefinedFarm35, tof_UserDefinedFarm36, tov_BEBeet, tov_BEBeetSpring, tov_BECatchPeaCrop, tov_BEGrassGrazed1, tov_BEGrassGrazed1Spring, tov_BEGrassGrazed2, tov_BEGrassGrazedLast, tov_BEMaize, tov_BEMaizeCC, tov_BEMaizeSpring, tov_BEOrchardCrop, tov_BEPotatoes, tov_BEPotatoesSpring, tov_BEWinterBarley, tov_BEWinterBarleyCC, tov_BEWinterWheat, tov_BEWinterWheatCC, tov_BroadBeans, tov_Carrots, tov_CloverGrassGrazed1, tov_CloverGrassGrazed2, tov_DEAsparagusEstablishedPlantation, tov_DEBushFruitPerm, tov_DECabbage, tov_DECarrots, tov_DEGrasslandSilageAnnual, tov_DEGreenFallow_1year, tov_DEHerbsPerennial_1year, tov_DEHerbsPerennial_after1year, tov_DELegumes, tov_DEMaize, tov_DEMaizeSilage, tov_DEOAsparagusEstablishedPlantation, tov_DEOats, tov_DEOBushFruitPerm, tov_DEOCabbages, tov_DEOCarrots, tov_DEOGrasslandSilageAnnual, tov_DEOGreenFallow_1year, tov_DEOHerbsPerennial_1year, tov_DEOHerbsPerennial_after1year, tov_DEOLegume, tov_DEOMaize, tov_DEOMaizeSilage, tov_DEOOats, tov_DEOOrchard, tov_DEOPeas, tov_DEOPermanentGrassGrazed, tov_DEOPermanentGrassLowYield, tov_DEOPotatoes, tov_DEOrchard, tov_DEOSpringRye, tov_DEOSugarBeet, tov_DEOTriticale, tov_DEOWinterBarley, tov_DEOWinterRape, tov_DEOWinterRye, tov_DEOWinterWheat, tov_DEPeas, tov_DEPermanentGrassGrazed, tov_DEPermanentGrassLowYield, tov_DEPotatoes, tov_DEPotatoesIndustry, tov_DESpringBarley, tov_DESpringRye, tov_DESugarBeet, tov_DETriticale, tov_DEWinterBarley, tov_DEWinterRape, tov_DEWinterRye, tov_DEWinterWheat, tov_DEWinterWheatLate, tov_DKBushFruit_Perm1, tov_DKBushFruit_Perm2, tov_DKCabbages, tov_DKCarrots, tov_DKCatchCrop, tov_DKCerealLegume, tov_DKCerealLegume_Whole, tov_DKChristmasTrees_Perm, tov_DKCloverGrassGrazed1, tov_DKCloverGrassGrazed2, tov_DKCloverGrassGrazed3, tov_DKEnergyCrop_Perm, tov_DKFarmForest_Perm, tov_DKFarmYoungForest_Perm, tov_DKFodderBeets, tov_DKGrassGrazed_Perm, tov_DKGrassLowYield_Perm, tov_DKGrassTussocky_Perm, tov_DKGrazingPigs, tov_DKGrazingPigs_Perm, tov_DKLegume_Beans, tov_DKLegume_Peas, tov_DKLegume_Whole, tov_DKMaize, tov_DKMaizeSilage, tov_DKMixedVeg, tov_DKOBushFruit_Perm1, tov_DKOBushFruit_Perm2, tov_DKOCabbages, tov_DKOCarrots, tov_DKOCatchCrop, tov_DKOCerealLegume, tov_DKOCerealLegume_Whole, tov_DKOChristmasTrees_Perm, tov_DKOCloverGrassGrazed1, tov_DKOCloverGrassGrazed2, tov_DKOCloverGrassGrazed3, tov_DKOEnergyCrop_Perm, tov_DKOFarmForest_Perm, tov_DKOFarmYoungForest_Perm, tov_DKOFodderBeets, tov_DKOGrassGrazed_Perm, tov_DKOGrassLowYield_Perm, tov_DKOGrazingPigs, tov_DKOGrazingPigs_Perm, tov_DKOLegume_Beans, tov_DKOLegume_Beans_CC, tov_DKOLegume_Peas, tov_DKOLegume_Peas_CC, tov_DKOLegume_Whole, tov_DKOLegume_Whole_CC, tov_DKOLegumeCloverGrass_Whole, tov_DKOLentils, tov_DKOLupines, tov_DKOMaize, tov_DKOMaizeSilage, tov_DKOMixedVeg, tov_DKOOrchApple, tov_DKOOrchardCrop_Perm, tov_DKOOrchCherry, tov_DKOOrchOther, tov_DKOOrchPear, tov_DKOPotato, tov_DKOPotatoIndustry, tov_DKOPotatoSeed, tov_DKOptimalFlowerMix1, tov_DKOptimalFlowerMix2, tov_DKOptimalFlowerMix3, tov_DKOrchApple, tov_DKOrchardCrop_Perm, tov_DKOrchCherry, tov_DKOrchOther, tov_DKOrchPear, tov_DKOSeedGrassRye_Spring, tov_DKOSetAside, tov_DKOSetAside_AnnualFlower, tov_DKOSetAside_PerennialFlower, tov_DKOSetAside_SummerMow, tov_DKOSpringBarley, tov_DKOSpringBarley_CC, tov_DKOSpringBarleyCloverGrass, tov_DKOSpringBarleySilage, tov_DKOSpringFodderGrass, tov_DKOSpringOats, tov_DKOSpringOats_CC, tov_DKOSpringWheat, tov_DKOSugarBeets, tov_DKOVegSeeds, tov_DKOWinterBarley, tov_DKOWinterCloverGrassGrazedSown, tov_DKOWinterFodderGrass, tov_DKOWinterRape, tov_DKOWinterRye, tov_DKOWinterRye_CC, tov_DKOWinterWheat, tov_DKOWinterWheat_CC, tov_DKPlantNursery_Perm, tov_DKPotato, tov_DKPotatoIndustry, tov_DKPotatoSeed, tov_DKSeedGrassFescue_Spring, tov_DKSeedGrassRye_Spring, tov_DKSetAside, tov_DKSetAside_SummerMow, tov_DKSpringBarley, tov_DKSpringBarley_CC, tov_DKSpringBarley_Green, tov_DKSpringBarleyCloverGrass, tov_DKSpringBarleySilage, tov_DKSpringFodderGrass, tov_DKSpringOats, tov_DKSpringOats_CC, tov_DKSpringWheat, tov_DKSugarBeets, tov_DKVegSeeds, tov_DKWinterBarley, tov_DKWinterCloverGrassGrazedSown, tov_DKWinterFodderGrass, tov_DKWinterRape, tov_DKWinterRye, tov_DKWinterRye_CC, tov_DKWinterWheat, tov_DKWinterWheat_CC, tov_DummyCropPestTesting, tov_FIBufferZone, tov_FIBufferZone_Perm, tov_FICaraway1, tov_FICaraway2, tov_FieldPeas, tov_FieldPeasSilage, tov_FieldPeasStrigling, tov_FIFabaBean, tov_FIFeedingGround, tov_FIGrasslandPasturePerennial1, tov_FIGrasslandPasturePerennial2, tov_FIGrasslandSilageAnnual, tov_FIGrasslandSilagePerennial1, tov_FIGrasslandSilagePerennial2, tov_FIGreenFallow_1year, tov_FIGreenFallow_Perm, tov_FINaturalGrassland, tov_FINaturalGrassland_Perm, tov_FIOCaraway1, tov_FIOCaraway2, tov_FIOFabaBean, tov_FIOPotato_North, tov_FIOPotato_South, tov_FIOPotatoIndustry_North, tov_FIOPotatoIndustry_South, tov_FIOSpringBarley_Fodder, tov_FIOSpringBarley_Malt, tov_FIOSpringOats, tov_FIOSpringRape, tov_FIOSpringWheat, tov_FIOStarchPotato_North, tov_FIOStarchPotato_South, tov_FIOTurnipRape, tov_FIOWinterRye, tov_FIOWinterWheat, tov_FIPotato_North, tov_FIPotato_South, tov_FIPotatoIndustry_North, tov_FIPotatoIndustry_South, tov_FISpringBarley_Fodder, tov_FISpringBarley_Malt, tov_FISpringOats, tov_FISpringRape, tov_FISpringWheat, tov_FISprSpringBarley_Fodder, tov_FIStarchPotato_North, tov_FIStarchPotato_South, tov_FISugarBeet, tov_FITurnipRape, tov_FIWinterRye, tov_FIWinterWheat, tov_FodderBeet, tov_FodderGrass, tov_FRGrassland, tov_FRGrassland_Perm, tov_FRMaize, tov_FRMaize_Silage, tov_FRPotatoes, tov_FRSorghum, tov_FRSpringBarley, tov_FRSpringOats, tov_FRSpringWheat, tov_FRSunflower, tov_FRWinterBarley, tov_FRWinterRape, tov_FRWinterTriticale, tov_FRWinterWheat, tov_GenericCatchCrop, tov_IRGrassland_no_reseed, tov_IRGrassland_reseed, tov_IRSpringBarley, tov_IRSpringOats, tov_IRSpringWheat, tov_IRWinterBarley, tov_IRWinterOats, tov_IRWinterWheat, tov_ITGrassland, tov_ITOOrchard, tov_ITOrchard, tov_Maize, tov_MaizeSilage, tov_MaizeStrigling, tov_NLBeet, tov_NLBeetSpring, tov_NLCabbage, tov_NLCabbageSpring, tov_NLCarrots, tov_NLCarrotsSpring, tov_NLCatchCropPea, tov_NLGrassGrazed1, tov_NLGrassGrazed1Spring, tov_NLGrassGrazed2, tov_NLGrassGrazedExtensive1, tov_NLGrassGrazedExtensive1Spring, tov_NLGrassGrazedExtensive2, tov_NLGrassGrazedExtensiveLast, tov_NLGrassGrazedLast, tov_NLMaize, tov_NLMaizeSpring, tov_NLOrchardCrop, tov_NLPermanentGrassGrazed, tov_NLPermanentGrassGrazedExtensive, tov_NLPotatoes, tov_NLPotatoesSpring, tov_NLSpringBarley, tov_NLSpringBarleySpring, tov_NLTulips, tov_NLWinterWheat, tov_NorwegianOats, tov_NorwegianPotatoes, tov_NorwegianSpringBarley, tov_Oats, tov_OBarleyPeaCloverGrass, tov_OCarrots, tov_OCloverGrassGrazed1, tov_OCloverGrassGrazed2, tov_OCloverGrassSilage1, tov_OFieldPeas, tov_OFieldPeasSilage, tov_OFirstYearDanger, tov_OFodderBeet, tov_OGrazingPigs, tov_OMaizeSilage, tov_OOats, tov_OPermanentGrassGrazed, tov_OPotatoes, tov_OrchardCrop, tov_OSBarleySilage, tov_OSeedGrass1, tov_OSeedGrass2, tov_OSpringBarley, tov_OSpringBarleyExt, tov_OSpringBarleyPigs, tov_OTriticale, tov_OWinterBarley, tov_OWinterBarleyExt, tov_OWinterRape, tov_OWinterRye, tov_OWinterWheat, tov_OWinterWheatUndersown, tov_OWinterWheatUndersownExt, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetAside, tov_PlantNursery, tov_PLBeans, tov_PLBeet, tov_PLBeetSpr, tov_PLCarrots, tov_PLFodderLucerne1, tov_PLFodderLucerne2, tov_PLMaize, tov_PLMaizeSilage, tov_PLPotatoes, tov_PLSpringBarley, tov_PLSpringBarleySpr, tov_PLSpringWheat, tov_PLWinterBarley, tov_PLWinterRape, tov_PLWinterRye, tov_PLWinterTriticale, tov_PLWinterWheat, tov_PLWinterWheatLate, tov_Potatoes, tov_PotatoesIndustry, tov_PTBeans, tov_PTCabbage, tov_PTCabbage_Hort, tov_PTCloverGrassGrazed1, tov_PTCloverGrassGrazed2, tov_PTCorkOak, tov_PTFodderMix, tov_PTGrassGrazed, tov_PTHorticulture, tov_PTMaize, tov_PTMaize_Hort, tov_PTOats, tov_PTOliveGroveIntensive, tov_PTOliveGroveSuperIntensive, tov_PTOliveGroveTraditional, tov_PTOliveGroveTradOrganic, tov_PTOtherDryBeans, tov_PTPermanentGrassGrazed, tov_PTPotatoes, tov_PTRyegrass, tov_PTSetAside, tov_PTShrubPastures, tov_PTSorghum, tov_PTTriticale, tov_PTTurnipGrazed, tov_PTVineyards, tov_PTWinterBarley, tov_PTWinterRye, tov_PTWinterWheat, tov_PTYellowLupin, tov_SeedGrass1, tov_SeedGrass2, tov_SESpringBarley, tov_SetAside, tov_SEWinterRape_Seed, tov_SEWinterWheat, tov_SpringBarley, tov_SpringBarleyCloverGrass, tov_SpringBarleyCloverGrassStrigling, tov_SpringBarleyPeaCloverGrassStrigling, tov_SpringBarleySeed, tov_SpringBarleySilage, tov_SpringBarleySKManagement, tov_SpringBarleySpr, tov_SpringBarleyStrigling, tov_SpringBarleyStriglingCulm, tov_SpringBarleyStriglingSingle, tov_SpringRape, tov_SugarBeet, tov_Triticale, tov_UKBeans, tov_UKBeet, tov_UKMaize, tov_UKPermanentGrass, tov_UKPotatoes, tov_UKSpringBarley, tov_UKTempGrass, tov_UKWinterBarley, tov_UKWinterRape, tov_UKWinterWheat, tov_WinterBarley, tov_WinterBarleyStrigling, tov_WinterRape, tov_WinterRapeStrigling, tov_WinterRye, tov_WinterRyeStrigling, tov_WinterWheat, tov_WinterWheatStrigling, tov_WinterWheatStriglingCulm, tov_WinterWheatStriglingSingle, tov_YoungForest, LE_TypeClass::TranslateVegTypes(), CfgInt::value(), CfgBool::value(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by FarmManager().

◆ DumpFarmAreas()

void FarmManager::DumpFarmAreas ( )
3253  {
3254 
3255  //create a text file with the farm areas
3256  ofstream ofile("FarmTotalAreas_almass.txt", ios::out);
3257  ofile << "Farm no" << '\t' << "Area" << endl;
3258 
3259  //print each farms no and then the numbers of its neighbours
3260  for (int i = 0; i < (int)m_farms.size(); i++) {
3261  ofile << i << '\t' << m_farms[i]->GetArea() << endl;
3262  }
3263 
3264  ofile.close();
3265 }

◆ DumpFarmrefs()

void FarmManager::DumpFarmrefs ( const char *  a_filename)

dumps the farmrefs file to a standard named file

5615 {
5616  ofstream opf(a_filename, ios::out);
5617  if (!opf.is_open())
5618  {
5619  g_msg->Warn(WARN_FILE, "Landscape::CreateFarms(): Unable to open file", a_filename);
5620  exit(1);
5621  }
5622  int NoFarms = (int) m_farms.size();
5623  opf << NoFarms << endl;
5624  for (int i = 0; i < NoFarms; i++)
5625  {
5626  opf << i << '\t' << m_farmmapping_lookup[i * 2 + 1] << endl;
5627  }
5628  opf.close();
5629 }

References g_msg, m_farmmapping_lookup, m_farms, MapErrorMsg::Warn(), and WARN_FILE.

◆ FarmManagement()

void FarmManager::FarmManagement ( )

Runs the daily farm management for each farm, but also calculates annual spilled grain and maize.

The crop management does not need to be recursively called so is looped through for each farm first

This next section effectively implements the Step code for the farmer, so that we can include complex behaviour

3922 {
3924  for (unsigned int i = 0; i < m_farms.size(); i++) {
3925  m_farms[i]->FarmActions();
3926  }
3937 
3938 
3942  bool AllDone;
3944  {
3945  do
3946  {
3947  AllDone = true;
3948  for (int i = 0; i < m_farmers->GetSize(); i++) {
3949  if (!m_farmers->GetFarmer(i)->GetFarm()->FarmerActions()) AllDone = false;
3950  }
3951  } while (AllDone == false);
3953  for (int i = 0; i < m_farmers->GetSize(); i++) {
3954  m_farmers->GetFarmer(i)->EndStep();
3955  }
3956  if (g_date->DayInYear() == 0) {
3958  }
3959  }
3960 }

References Calendar::DayInYear(), fmc_Cultivation, fmc_Cutting, fmc_Fertilizer, fmc_Fungicide, fmc_Grazing, fmc_Harvest, fmc_Herbicide, fmc_Insecticide, fmc_Others, fmc_Watering, g_date, FarmerList::GetFarmer(), FarmerList::GetSize(), m_farmers, m_farms, m_ManagementCategoryLabels, m_UseSocioEconomicFarmers, Print_FarmerAttributes(), and FarmerList::ResetAllDone().

◆ FindClosestFarm()

int FarmManager::FindClosestFarm ( HunterInfo  a_hinfo,
vector< int > *  a_farmlist 
)

Finds the closest farm to this co-ordinate.

Centroid calculation on farms must be called before calling this method for the first time.
a_farmlist is a pointer to a list of integers with illegal farm ref numbers. The first entry lists the number of illegal numbers.

5727  {
5732  double best = 99999999999999999.0;
5733  int bestref = -1;
5734  double dist = best;
5735  for (unsigned i = 0; i < m_farms.size(); i++) {
5736  int fnum = m_farms[i]->GetFarmNumber();
5737  if (!InIllegalList(fnum, a_farmlist)) {
5738  if (!IsDuplicateRef(fnum, &a_hinfo)) {
5739  // Is possible to use this farm, so test it.
5740  APoint FPt = m_farms[i]->GetCentroids();
5741  dist = sqrt((double( FPt.m_x - a_hinfo.homeX ) * double( FPt.m_x - a_hinfo.homeX ) + double( FPt.m_y - a_hinfo.homeY ) * double( FPt.m_y - a_hinfo.homeY )));
5742  if (dist < best) {
5743  best = dist;
5744  bestref = fnum;
5745  }
5746  }
5747  }
5748  }
5749  if (bestref == -1) {
5750  g_msg->Warn( "FarmManager::FindClosestFarm - Cannot find open farm.", "" );
5751  exit( 0 );
5752  }
5753  return bestref;
5754 }

References g_msg, HunterInfo::homeX, HunterInfo::homeY, InIllegalList(), IsDuplicateRef(), m_farms, APoint::m_x, APoint::m_y, and MapErrorMsg::Warn().

◆ FindClosestFarmOpenness()

int FarmManager::FindClosestFarmOpenness ( HunterInfo  a_hinfo,
vector< int > *  a_farmlist,
int  a_openness 
)

Finds the closest farm to this co-ordinate but uses a probability distribtution for acceptance.

Finds the closest farm to this co-ordinate with openness more than a value

5756  {
5757  // Centroid calculation on farms must be called before calling this method for the first time
5758  double best = 99999999999999999.0;
5759  int bestref = -1;
5760  double dist = best;
5761  for (unsigned i = 0; i < m_farms.size(); i++) {
5762  if (m_farms[ i ]->GetMaxOpenness() > a_openness) {
5763  int fref = m_farms[ i ]->GetFarmNumber();
5764  if (!InIllegalList( fref, a_farmlist )) {
5765  if (!IsDuplicateRef( fref, &a_hunterinfo )) {
5766  APoint FPt = m_farms[ i ]->GetCentroids();
5767  dist = sqrt( (double( FPt.m_x - a_hunterinfo.homeX ) * double( FPt.m_x - a_hunterinfo.homeX ) + double( FPt.m_y - a_hunterinfo.homeY ) * double( FPt.m_y - a_hunterinfo.homeY )) );
5768  if (dist < best) {
5769  best = dist;
5770  bestref = fref;
5771  }
5772  }
5773  }
5774  }
5775  }
5776  if (bestref == -1) {
5777  g_msg->Warn( "FarmManager::FindClosestFarmOpenness( ) - Cannot find open farm.", "" );
5778  exit( 0 );
5779  }
5780  return bestref;
5781 }

References g_msg, HunterInfo::homeX, HunterInfo::homeY, InIllegalList(), IsDuplicateRef(), m_farms, APoint::m_x, APoint::m_y, and MapErrorMsg::Warn().

◆ FindClosestFarmOpennessProb()

int FarmManager::FindClosestFarmOpennessProb ( HunterInfo  a_hinfo,
vector< int > *  a_farmlist,
int  a_openness 
)

Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness.

Centroid calculation on farms must be called before calling this method for the first time.
a_farmlist is a pointer to a list of integers with illegal farm ref numbers. The first entry lists the number of illegal numbers. The chance of acceptance is probability based, taking the nearest farm first then testing the next etc.. The probability is based on y = 1*EXP(-x*cfg) with cfg being a fitting parameter in cfg_ClosestFarmProbParam1

We use typedef here to create our own name for APoint - but it is just two unsigned ints. We will use 'x' for the farm num and 'y' for the distance.

We use a vector of AFarmDists to be able to sort it easily

Struct redefining operator < - used for sorting distances from smallest to largest.

5783  {
5790 
5792  typedef APoint AFarmDist;
5794  vector <AFarmDist> farmdists;
5796  struct FarmDistSort {
5797  bool operator()( AFarmDist a, AFarmDist b ) {
5798  return a.m_y < b.m_y;
5799  }
5800  };
5801  for (unsigned i = 0; i < m_farms.size(); i++) {
5802  int fnum = m_farms[ i ]->GetFarmNumber();
5803  if (!InIllegalList( fnum, a_farmlist )) {
5804  if (m_farms[ i ]->GetMaxOpenness() > a_openness) {
5805  if (!IsDuplicateRef( fnum, &a_hunterinfo )) {
5806  // Is possible to use this farm, so test it.
5807  APoint FPt = m_farms[ i ]->GetCentroids();
5808  int dist = int(sqrt( (double( FPt.m_x - a_hunterinfo.homeX ) * double( FPt.m_x - a_hunterinfo.homeX ) + double( FPt.m_y - a_hunterinfo.homeY ) * double( FPt.m_y - a_hunterinfo.homeY )) ));
5809  if (dist>40000) dist = 40000;
5810  AFarmDist fd( int( fnum ), dist );
5811  farmdists.push_back( fd );
5812  }
5813  }
5814  }
5815  }
5816  // By here we have a list of farms and their distances - now we have the option to sort it or randomise it - one or other line below should be commented out.
5817  // sort(farmdists.begin(), farmdists.end(), FarmDistSort()); // Sort
5818  std::shuffle( farmdists.begin(), farmdists.end(), g_generator ); // Randomise
5819  // Now the vector is sorted/randomised we loop through and test probabilities
5820  for (int ch = 1; ch < 100000; ch++) // This loop just makes sure small chances don't mess up the run by tripping out early
5821  {
5822  int sz = int( farmdists.size() );
5823  for (int i = 0; i < sz; i++) {
5824  double chance = g_rand_uni_fnc();
5825  // Uses ch from the outer loop to scale probabilities - tripping out here will occur often for farms a long way from the area otherwise
5826  double calc = cfg_ClosestFarmProbParam2.value()* exp( (cfg_ClosestFarmProbParam1.value() / double( ch ))* farmdists[ i ].m_y );
5827  if (chance <= calc) return farmdists[ i ].m_x;
5828  }
5829  }
5830  g_msg->Warn( "FarmManager::FindClosestFarmProb", "- No suitable farm found" );
5831  exit( 0 );
5832 }

References cfg_ClosestFarmProbParam1, cfg_ClosestFarmProbParam2, g_generator, g_msg, g_rand_uni_fnc(), HunterInfo::homeX, HunterInfo::homeY, InIllegalList(), IsDuplicateRef(), m_farms, APoint::m_x, APoint::m_y, CfgFloat::value(), and MapErrorMsg::Warn().

◆ FindClosestFarmOpennessProbNearRoostIsBest()

int FarmManager::FindClosestFarmOpennessProbNearRoostIsBest ( HunterInfo  a_hinfo,
vector< int > *  a_farmlist,
int  a_openness,
vector< APoint > *  a_farmsizelist 
)

Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness and another based on farm size.

Centroid calculation on farms must be called before calling this method for the first time.
a_farmlist is a pointer to a list of integers with illegal farm ref numbers. The first entry lists the number of illegal numbers. The chance of acceptance is probability based, taking the nearest farm first then testing the next etc.. The probability is based on y = 1*EXP(-x*cfg) with cfg being a fitting parameter in cfg_ClosestFarmProbParam1

We use typedef here to create our own name for APoint - but it is just two unsigned ints. We will use 'x' for the farm num and 'y' for the distance.

We use a vector of AFarmDists to be able to sort it easily

Struct redefining operator < - used for sorting distances from smallest to largest.

5890  {
5897 
5899  typedef APoint AFarmDist;
5901  vector <AFarmDist> farmdists;
5903  struct FarmDistSort {
5904  bool operator()( AFarmDist a, AFarmDist b ) {
5905  return a.m_y < b.m_y;
5906  }
5907  };
5908  for (unsigned i = 0; i < m_farms.size(); i++) {
5909  int fnum = m_farms[ i ]->GetFarmNumber();
5910  if (!InIllegalList( fnum, a_farmlist )) {
5911  if (m_farms[ i ]->GetMaxOpenness() > a_openness) {
5912  if (!IsDuplicateRef( fnum, &a_hunterinfo )) {
5913  // Is possible to use this farm, so test it.
5914  APoint FPt = m_farms[ i ]->GetCentroids();
5915  int dist = int(sqrt( (double( FPt.m_x - a_hunterinfo.homeX ) * double( FPt.m_x - a_hunterinfo.homeX ) + double( FPt.m_y - a_hunterinfo.homeY ) * double( FPt.m_y - a_hunterinfo.homeY )) ));
5916  if (dist>40000) dist = 40000;
5917  AFarmDist fd( unsigned( fnum ), dist );
5918  farmdists.push_back( fd );
5919  }
5920  }
5921  }
5922  }
5923  // By here we have a list of farms and their distances - now we have the option to sort it or randomise it - one or other line below should be commented out.
5924  // sort(farmdists.begin(), farmdists.end(), FarmDistSort()); // Sort
5925  std::shuffle( farmdists.begin(), farmdists.end(), g_generator ); // Randomise
5926  // Now the vector is sorted/randomised we loop through and test probabilities
5927  for (int ch = 1; ch < 100000; ch++) // This loop just makes sure small chances don't mess up the run by tripping out early
5928  {
5929  int sz = int( farmdists.size() );
5930  for (int i = 0; i < sz; i++) {
5931  double chance = g_rand_uni_fnc();
5932  // Uses ch from the outer loop to scale probabilities - tripping out here will occur often for farms a long way from the area otherwise
5933  double calc = cfg_ClosestFarmProbParam2.value()* exp( (cfg_ClosestFarmProbParam1.value() / double( ch ))* farmdists[ i ].m_y );
5934  if (chance <= calc) {
5935  // We passed the first test now take a second test based on roost distance
5936  chance = g_rand_uni_fnc();
5937  // Loop through each roost and find the closest to the farm - then do probability based on that distance.
5938  double dist = 10000;
5939  for (int r = 0; r < int( a_roostlist->size() ); r++) {
5940  double fdistroostx = farmdists[ i ].m_x - (*a_roostlist)[ r ].m_x;
5941  double fdistroosty = farmdists[ i ].m_y - (*a_roostlist)[ r ].m_y;
5942  double distf = sqrt( fdistroostx * fdistroostx + fdistroosty * fdistroostx );
5943  if (distf < dist) dist = distf;
5944  }
5945  calc = -0.01 + pow( dist / 10000.0, cfg_RoostDistProbParam1.value() );
5946  if (chance>calc) return farmdists[ i ].m_x;
5947  }
5948  }
5949  }
5950  g_msg->Warn( "FarmManager::FindClosestFarmProbNearRoostBest", "- No suitable farm found" );
5951  exit( 0 );
5952 }

References cfg_ClosestFarmProbParam1, cfg_ClosestFarmProbParam2, cfg_RoostDistProbParam1, g_generator, g_msg, g_rand_uni_fnc(), HunterInfo::homeX, HunterInfo::homeY, InIllegalList(), IsDuplicateRef(), m_farms, APoint::m_x, APoint::m_y, CfgFloat::value(), and MapErrorMsg::Warn().

◆ FindClosestFarmOpennessProbSmallIsBest()

int FarmManager::FindClosestFarmOpennessProbSmallIsBest ( HunterInfo  a_hinfo,
vector< int > *  a_farmlist,
int  a_openness,
vector< int > *  a_farmsizelist 
)

Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness and another based on farm size.

Centroid calculation on farms must be called before calling this method for the first time.
a_farmlist is a pointer to a list of integers with illegal farm ref numbers. The first entry lists the number of illegal numbers. The chance of acceptance is probability based, taking the nearest farm first then testing the next etc.. The probability is based on y = 1*EXP(-x*cfg) with cfg being a fitting parameter in cfg_ClosestFarmProbParam1

We use typedef here to create our own name for APoint - but it is just two unsigned ints. We will use 'x' for the farm num and 'y' for the distance.

We use a vector of AFarmDists to be able to sort it easily

Struct redefining operator < - used for sorting distances from smallest to largest.

5834  {
5841 
5843  typedef APoint AFarmDist;
5845  vector <AFarmDist> farmdists;
5847  struct FarmDistSort {
5848  bool operator()( AFarmDist a, AFarmDist b ) {
5849  return a.m_y < b.m_y;
5850  }
5851  };
5852  for (unsigned i = 0; i < m_farms.size(); i++) {
5853  int fnum = m_farms[ i ]->GetFarmNumber();
5854  if (!InIllegalList( fnum, a_farmlist )) {
5855  if (m_farms[ i ]->GetMaxOpenness() > a_openness) {
5856  if (!IsDuplicateRef( fnum, &a_hunterinfo )) {
5857  // Is possible to use this farm, so test it.
5858  APoint FPt = m_farms[ i ]->GetCentroids();
5859  int dist = int(sqrt( (double( FPt.m_x - a_hunterinfo.homeX ) * double( FPt.m_x - a_hunterinfo.homeX ) + double( FPt.m_y - a_hunterinfo.homeY ) * double( FPt.m_y - a_hunterinfo.homeY )) ));
5860  if (dist>40000) dist = 40000;
5861  AFarmDist fd( unsigned( fnum ), dist );
5862  farmdists.push_back( fd );
5863  }
5864  }
5865  }
5866  }
5867  // By here we have a list of farms and their distances - now we have the option to sort it or randomise it - one or other line below should be commented out.
5868  // sort(farmdists.begin(), farmdists.end(), FarmDistSort()); // Sort
5869  std::shuffle( farmdists.begin(), farmdists.end(), g_generator ); // Randomise
5870  // Now the vector is sorted/randomised we loop through and test probabilities
5871  for (int ch = 1; ch < 100000; ch++) // This loop just makes sure small chances don't mess up the run by tripping out early
5872  {
5873  int sz = int( farmdists.size() );
5874  for (int i = 0; i < sz; i++) {
5875  double chance = g_rand_uni_fnc();
5876  // Uses ch from the outer loop to scale probabilities - tripping out here will occur often for farms a long way from the area otherwise
5877  double calc = cfg_ClosestFarmProbParam2.value()* exp( (cfg_ClosestFarmProbParam1.value() / double( ch ))* farmdists[ i ].m_y );
5878  if (chance <= calc) {
5879  // We passed the first test now take a second test based on farm size
5880  chance = g_rand_uni_fnc();
5881  calc = pow( double( (*a_farmsizelist)[ farmdists[ i ].m_x ] / 4000.0 ), cfg_FarmSizeProbParam1.value() );
5882  if (chance>calc) return farmdists[ i ].m_x;
5883  }
5884  }
5885  }
5886  g_msg->Warn( "FarmManager::FindClosestFarmProb", "- No suitable farm found" );
5887  exit( 0 );
5888 }

References cfg_ClosestFarmProbParam1, cfg_ClosestFarmProbParam2, cfg_FarmSizeProbParam1, g_generator, g_msg, g_rand_uni_fnc(), HunterInfo::homeX, HunterInfo::homeY, InIllegalList(), IsDuplicateRef(), m_farms, APoint::m_x, APoint::m_y, CfgFloat::value(), and MapErrorMsg::Warn().

◆ FindFarmWithOpenness()

int FarmManager::FindFarmWithOpenness ( vector< int > *  a_farmlist,
int  a_openness 
)

Finds a farm openness more than a value not on the list.

5972 {
5973  // Centroid calculation on farms must be called before calling this method for the first time
5974  int sz = (int)m_farms.size();
5975  int seed = g_random_fnc( sz );
5976  for (unsigned i = 0; i < m_farms.size(); i++) {
5977  int index = (i + seed) % sz;
5978  if (m_farms[ index ]->GetMaxOpenness() > a_openness)
5979  {
5980  if (!InIllegalList( m_farms[ index ]->GetFarmNumber(), a_farmlist )) return m_farms[ index ]->GetFarmNumber();
5981  }
5982  else AddToIllegalList(m_farms[ index ]->GetFarmNumber(), a_farmlist );
5983  }
5984  g_msg->Warn("FarmManager::FindFarmWithOpenness", "- No suitable farm found");
5985  exit(0);
5986 }

References AddToIllegalList(), g_msg, g_random_fnc(), InIllegalList(), m_farms, and MapErrorMsg::Warn().

◆ FindFarmWithRandom()

int FarmManager::FindFarmWithRandom ( vector< int > *  a_farmlist)

Finds a farm openness more than a value not on the list.

5955 {
5956  int sz= (int)m_farms.size();
5957  int f = g_random_fnc(sz);
5958  while (InIllegalList(m_farms[f]->GetFarmNumber(), a_farmlist))
5959  {
5960  f = g_random_fnc(sz);
5961  if (a_farmlist->size() >= m_farms.size())
5962  {
5963  g_msg->Warn("FarmManager::FindFarmWithRandom"," - farm density rule means all hunters cannot be placed");
5964  exit(0);
5965  }
5966  }
5967  return m_farms[f]->GetFarmNumber();
5968 
5969 }

References g_msg, g_random_fnc(), InIllegalList(), m_farms, and MapErrorMsg::Warn().

◆ FindOpennessFarm()

int FarmManager::FindOpennessFarm ( int  a_openness)

Finds a random farm with at least one field with openness above a_openness.

5989 {
5990  int sz = (int) m_farms.size();
5991  int seed = g_random_fnc(sz);
5992  for (unsigned i = 0; i < m_farms.size(); i++)
5993  {
5994  int index = (i + seed) % sz;
5995  if (m_farms[index]->GetMaxOpenness() > a_openness) return m_farms[index]->GetFarmNumber();
5996  }
5997  return -1; // Should never happen but if it does we need to handle the -1 error code.
5998 }

References g_random_fnc(), and m_farms.

◆ Get_FarmFuncsCB()

FarmFuncsCostBenefits FarmManager::Get_FarmFuncsCB ( FarmToDo  a_action)
inline

Get a specific FarmFunction Cost Benefit.

1662 { return m_FarmFuncsCB[a_action]; }

References m_FarmFuncsCB.

Referenced by Farm::CalculateTreatmentCosts().

◆ GetCropMgtPlans()

vector<Crop*>* FarmManager::GetCropMgtPlans ( void  )
inline
1640 { return &m_cropprogs; }

References m_cropprogs.

◆ GetCropMgtPlansIndex()

int FarmManager::GetCropMgtPlansIndex ( TTypesOfVegetation  a_tov)
inline
1641  {
1642  for (unsigned int i = 0; i < m_cropprogs.size(); i++)
1643  {
1644  if (a_tov == m_cropprogs[i]->m_tov) return i;
1645  }
1646  g_msg->Warn(WARN_MSG, "Mismatch in rotation file looking for tov ", a_tov);
1647  exit(1);
1648  }

References g_msg, m_cropprogs, MapErrorMsg::Warn(), and WARN_MSG.

Referenced by GetCropTypeFromPlan().

◆ GetCropTypeFromPlan()

TTypesOfCrops FarmManager::GetCropTypeFromPlan ( TTypesOfVegetation  a_tov)
inline
1649  {
1650  return m_cropprogs[GetCropMgtPlansIndex(a_tov)]->GetCropType();
1651  }

References GetCropMgtPlansIndex(), and m_cropprogs.

◆ GetDD()

double FarmManager::GetDD ( void  )
inline

Returnes day degrees for the period March 1st - November 1st. Used for determining yields of crops that are not harvested.

1605 {return daydegrees;};

References daydegrees.

◆ GetFarm()

Farm* FarmManager::GetFarm ( int  i)
inline

Get a specific farm i.

1660 { return m_farms[i]; }

References m_farms.

◆ GetFarmArableSize()

int FarmManager::GetFarmArableSize ( int  a_farmref)
inline

Returns the arable area from the farm ref num.

1504  {
1505  return (GetFarmPtr(a_farmref)->GetArea());
1506  }

References GetFarmPtr().

◆ GetFarmAreaOpenFields()

int FarmManager::GetFarmAreaOpenFields ( int  a_farmref,
int  a_openness 
)
inline

Returns the area of fields with openness more than a_openness.

1531  {
1532  return (GetFarmPtr(a_farmref)->GetAreaOpenFields(a_openness));
1533  }

References GetFarmPtr().

◆ GetFarmCentroid()

APoint FarmManager::GetFarmCentroid ( int  a_farmref)
inline

Gets the farm centroid as an APoint.

1583  {
1584  for (unsigned int i = 0; i < m_farms.size(); i++)
1585  {
1586  if (a_farmref == m_farms[i]->GetFarmNumber())
1587  {
1588  return m_farms[i]->GetCentroids();
1589  }
1590  }
1591  g_msg->Warn("FarmManager::GetFarmCentroid - missing farm ref", a_farmref);
1592  exit(92);
1593  }

References g_msg, m_farms, and MapErrorMsg::Warn().

◆ GetFarmer()

Farmer* FarmManager::GetFarmer ( int  i)
inline

Gets the farmer associated with the farm with the index number i.

1656 { return m_farmers->GetFarmer(i); }

References FarmerList::GetFarmer(), and m_farmers.

Referenced by CreateFarms().

◆ GetFarmerList()

FarmerList* FarmManager::GetFarmerList ( )
inline

Gets the farmer list pointer (used by social networks and farmers)

1654 { return m_farmers; }

References m_farmers.

Referenced by Farm::Farm().

◆ GetFarmNoFields()

int FarmManager::GetFarmNoFields ( int  a_farmref)
inline

Returns the number of fields owned by a from the farm ref num.

1514  {
1515  return (GetFarmPtr(a_farmref)->GetNoFields());
1516  }

References GetFarmPtr().

◆ GetFarmNoLookup()

int FarmManager::GetFarmNoLookup ( int  a_ref)
inline

Get a farm reference from the lookup table.

1618 { return m_farmmapping_lookup[a_ref * 2]; }

References m_farmmapping_lookup.

Referenced by CreateFarms(), and GetFarmNoLookupIndex().

◆ GetFarmNoLookupIndex()

int FarmManager::GetFarmNoLookupIndex ( int  a_ref)
inline

Get a farm reference from the lookup table.

1609  {
1610  for (int i = 0; i < (int)m_farms.size(); i++)
1611  {
1612  if (GetFarmNoLookup(i) == a_ref) return i;
1613  }
1614  g_msg->Warn("FarmManager::GetFarmNoLookupIndex: Farm ref not found", a_ref);
1615  exit(142);
1616  }

References g_msg, GetFarmNoLookup(), m_farms, and MapErrorMsg::Warn().

Referenced by ReadFarmerAttributes().

◆ GetFarmNoOpenFields()

int FarmManager::GetFarmNoOpenFields ( int  a_farmref,
int  a_openness 
)
inline

Returns the number of fields with openness more than a_openness.

1525  {
1526  return (GetFarmPtr(a_farmref)->GetNoOpenFields(a_openness));
1527  }

References GetFarmPtr().

◆ GetFarmPtr()

Farm* FarmManager::GetFarmPtr ( int  a_owner)
inline

Returns the pointer to a farm with a specific number.

1536  {
1537  for (unsigned int i = 0; i < m_farms.size( ); i++) {
1538  if (a_owner == m_farms[ i ]->GetFarmNumber( )) {
1539  return m_farms[ i ];
1540  }
1541  }
1542  g_msg->Warn( "FarmManager::GetFarmPtr - missing farm ref", a_owner );
1543  exit( 92 );
1544  }

References g_msg, m_farms, and MapErrorMsg::Warn().

Referenced by GetFarmArableSize(), GetFarmAreaOpenFields(), GetFarmNoFields(), GetFarmNoOpenFields(), GetFarmTotalSize(), GetFarmType(), GetFarmValidCoords(), and Landscape::SupplyFarmPtr().

◆ GetFarmPtrIndex()

Farm* FarmManager::GetFarmPtrIndex ( int  a_index)
inline

Returns the pointer to a farm with a specific index.

1550  {
1551  return m_farms[ a_index ];
1552  }

References m_farms.

◆ GetFarmTotalSize()

int FarmManager::GetFarmTotalSize ( int  a_farmref)
inline

Returns the total farm area from the farm ref num.

1499  {
1500  return (GetFarmPtr(a_farmref)->GetTotalArea());
1501  }

References GetFarmPtr().

◆ GetFarmType()

TTypesOfFarm FarmManager::GetFarmType ( int  a_farmref)
inline

Returns the farm type from the farm ref num.

1509  {
1510  return (GetFarmPtr(a_farmref)->GetType());
1511  }

References GetFarmPtr().

◆ GetFarmTypeLookup()

int FarmManager::GetFarmTypeLookup ( int  a_ref)
inline

Get a farm type from the lookup table.

1620 { return m_farmmapping_lookup[a_ref * 2 + 1]; }

References m_farmmapping_lookup.

◆ GetFarmValidCoords()

APoint FarmManager::GetFarmValidCoords ( int  a_farmref)
inline

Returns the number of fields owned by a from the farm ref num.

1519  {
1520  return (GetFarmPtr(a_farmref)->GetValidCoords());
1521  }

References GetFarmPtr().

◆ GetIncome()

double FarmManager::GetIncome ( TTypesOfCrops  a_toc)

Get tov-based profit per unit area per unit biomass.

Uses the toc code as a look-up table to get the current return per unit area for that vegetation type

6119 {
6123  return m_YieldReturns[a_toc];

References m_YieldReturns.

Referenced by Farm::Harvested().

◆ GetIsRenumbered()

bool FarmManager::GetIsRenumbered ( )
inline

Returns the flag for renumbering.

1622 { return m_renumbered; }

References m_renumbered.

◆ GetLandscape()

Landscape* FarmManager::GetLandscape ( void  )
inline
1473 { return m_landscape; }

References m_landscape.

Referenced by Farm::Farm().

◆ GetManagementNorm()

double FarmManager::GetManagementNorm ( int  a_crop,
int  a_managementtype 
)
inline

Get the norm for managment numbers for a crop and management cominbation.

1547 { return m_MangagementNorms[a_crop][a_managementtype]; }

References m_MangagementNorms.

◆ GetNoFarms()

int FarmManager::GetNoFarms ( )
inline
1636  {
1637  return (int)m_farms.size();
1638  }

References m_farms.

Referenced by Landscape::SupplyNumberOfFarms().

◆ GetRandomFarmRefnum()

int FarmManager::GetRandomFarmRefnum ( )
inline

Returns a random farm reference number.

1554 { return m_farms[g_random_fnc((int)m_farms.size())]->GetFarmNumber(); }

References g_random_fnc(), and m_farms.

◆ GetRenumberedFarmRef()

int FarmManager::GetRenumberedFarmRef ( int  a_farmref)
inline

Returns the farm ref index for a farmref.

1625  {
1626  for (int i = 0; i < (int)m_farms.size(); i++)
1627  {
1628  if (m_farmmapping_lookup[i * 2] == a_farmref)
1629  {
1630  return i;
1631  }
1632  }
1633  g_msg->Warn( "FarmManager::GetRenumberedFarmRef(int a_farmref) Farm reference number not found in m_farmmapping_lookup ", a_farmref );
1634  exit( 9 );
1635  }

References g_msg, m_farmmapping_lookup, m_farms, and MapErrorMsg::Warn().

◆ GetSpilledGrain()

double FarmManager::GetSpilledGrain ( )

Returns the average amount of spilled grain in KJ/m2 this year.

5632 {
5633  /*
5634  * This data is grain distributions based on 2013 & 2014 data from cereal fields in Jutland counted in September.
5635  * Counts made in squares of 0.0196 m2 and scaled up, hence the decimal numbers.
5636  * The numbers represent number of grains.
5637  */
5638  double graindist2013[26] = {
5639  29.59, 172.68, 60.59, 39.68, 51.02, 81.63, 268.71, 134.84, 57.40, 30.61, 204.08, 683.67, 108.04,
5640  141.29, 505.10, 444.61, 293.37, 355.18, 386.90, 381.83, 372.45, 377.55, 320.70, 392.46, 392.86, 435.17
5641  };
5642  double graindist2014[28] = {
5643  109.33, 382.65, 94.19, 765.31, 29.15, 70.15, 1096.94, 436.51, 309.21, 286.28, 480.44, 249.73, 784.10,
5644  688.78, 2035.45, 920.80, 341.61, 12.24, 113.38, 80.17, 178.57, 480.44, 0.00, 2.83, 1447.12, 1846.94, 1017.86,
5645  477.74
5646  };
5647  int grain_dist_value = cfg_grain_distribution.value();
5648  if (grain_dist_value == 0) // The default - random pick between the two years
5649  {
5650  if (m_SpilledGrain) return graindist2013[(int)(g_rand_uni_fnc() * 26)];
5651  else return graindist2014[(int)(g_rand_uni_fnc() * 28)];
5652  }
5653  if (grain_dist_value == 1) {
5654  return graindist2013[(int)(g_rand_uni_fnc() * 26)];
5655  }
5656  else
5657  {
5658  return graindist2014[(int)(g_rand_uni_fnc() * 28)];
5659  }
5660 }

References cfg_grain_distribution, g_rand_uni_fnc(), m_SpilledGrain, and CfgInt::value().

◆ GetSpilledMaize()

double FarmManager::GetSpilledMaize ( )

Returns the average amount of spilled maize in KJ/m2 this year.

5663 {
5664  /*
5665  * This data is maize distributions in kJ/m2 based on 2015, 2016 & 2017 field data from maize fields in Jutland
5666  * Two fields with extraordinarily high values were omitted (6812, 5393)
5667  */
5668  double maizedist[17] = {
5669  102.7905327,
5670  58.19878648,
5671  85.65877728,
5672  110.9055748,
5673  30.65682555,
5674  63.11699379,
5675  59.05947276,
5676  41.9277173,
5677  95.57716202,
5678  14.42674144,
5679  6.311699379,
5680  20.73844082,
5681  12.62339876,
5682  25.24679751,
5683  146.070757,
5684  // 6812.0,
5685  5393.0};
5686  return maizedist[(int)(g_rand_uni_fnc() * 17)];
5687 }

References g_rand_uni_fnc().

◆ GetUseSocioEconomicFarmers()

bool FarmManager::GetUseSocioEconomicFarmers ( )
inline

Get the flag for use of socio-economic farmers.

1671 { return m_UseSocioEconomicFarmers; }

References m_UseSocioEconomicFarmers.

◆ InIllegalList()

bool FarmManager::InIllegalList ( int  a_farm_ref,
vector< int > *  a_farmlist 
)

Checks a list to see if a farm matches the illegal list of references.

a_farmlist is a pointer to a list of integers with illegal farm ref numbers. The first entry lists the number of illegal numbers.

5689  {
5693  unsigned sz = (unsigned) a_farmlist->size();
5694  for (unsigned f = 0; f < sz; f++) {
5695  if ((*a_farmlist)[f] == a_farm_ref) return true;
5696  }
5697  return false;
5698 }

Referenced by FindClosestFarm(), FindClosestFarmOpenness(), FindClosestFarmOpennessProb(), FindClosestFarmOpennessProbNearRoostIsBest(), FindClosestFarmOpennessProbSmallIsBest(), FindFarmWithOpenness(), and FindFarmWithRandom().

◆ InitiateManagement()

void FarmManager::InitiateManagement ( void  )
3963 {
3964  cout << "Farms initiating management and centroid calculation" << endl;
3965  for ( unsigned int i = 0; i < m_farms.size(); i++ )
3966  {
3967  m_farms[i]->InitiateManagement();
3968  m_farms[i]->Centroids();
3969  }
3970  // forces updating of all three social network types if present */
3972  {
3973  m_farmers->UpdateSocialNetworks(true, true, true);
3975  }
3976 }

References cfg_UseFarmerNetworks, m_farmers, m_farms, PrintLocationAndArea(), FarmerList::UpdateSocialNetworks(), and CfgBool::value().

◆ IsDuplicateRef()

bool FarmManager::IsDuplicateRef ( int  a_ref,
HunterInfo a_hinfo 
)

Checks if we already have this ref.

5718 {
5719  for (int i = 0; i < int( a_hinfo->FarmHuntRef.size() ); i++)
5720  {
5721 
5722  if (a_ref == a_hinfo->FarmHuntRef[ i ]) return true;
5723  }
5724  return false;
5725 }

References HunterInfo::FarmHuntRef.

Referenced by FindClosestFarm(), FindClosestFarmOpenness(), FindClosestFarmOpennessProb(), FindClosestFarmOpennessProbNearRoostIsBest(), and FindClosestFarmOpennessProbSmallIsBest().

◆ Print_FarmerAttributes()

void FarmManager::Print_FarmerAttributes ( )

Create an output where Farmer's attribute are shown.

Opens a stream file and output farm's attributes, tab separated.

6241 {
6243  string str1 = "SocioEconomic\\FarmerAttributeInformation_end.txt";
6244 
6245  if (g_date->OldDays() == 0) {
6246  ofstream ofile(str1.c_str(), ios::out);
6247  if (!ofile.is_open()) {
6248  g_msg->Warn("FarmManager::Print_FarmerAttributes() Cannot open outpuit file ", "FarmerAttributeInformation_end.txt");
6249  exit(142);
6250  }
6251  //ofile << "FarmRef" << '\t' << "RiskAv" << '\t' << "EnvAttitude" << '\t' << "Collective" << '\t' << "Age" << '\t' << "Risk_Span" << '\t' << m_landscape->SupplyYearNumber() << endl;
6252  }
6253  ofstream ofile(str1.c_str(), ios::app);
6254  for (auto farm : m_farms) {
6255  Farmer* farmer = farm->GetFarmer();
6256  FarmerAttributes Attribute;
6257  Attribute = farmer->GetPersonalAttributes();
6258  ofile << farmer->GetFarmerRef() << '\t' << Attribute.riskA << '\t' << Attribute.envA << '\t' << Attribute.Cooperative << '\t' << Attribute.Age << '\t' << Attribute.riskSpan <<endl;
6259  //what happens when this is called multiple time?
6260  }
6261  ofile.close();

References FarmerAttributes::Age, FarmerAttributes::Cooperative, FarmerAttributes::envA, g_date, g_msg, m_farms, Calendar::OldDays(), FarmerAttributes::riskA, FarmerAttributes::riskSpan, and MapErrorMsg::Warn().

Referenced by FarmManagement().

◆ PrintLocationAndArea()

void FarmManager::PrintLocationAndArea ( )

Print Farmers' location (x , y)

Opens a stream file and output farmers' location and farm area.

6370  {
6372  string str1 = "SocioEconomic\\FarmerLocation.txt";
6373  ofstream ofile(str1.c_str(), ios::out);
6374  if (!ofile.is_open()) {
6375  g_msg->Warn("FarmManager::PrintLocationAndArea() Cannot open output file ", "FarmerLocation.txt");
6376  exit(142);
6377  }
6378  ofile << "FarmRef" << '\t' << "X" << '\t' << "Y" << '\t' << "Area" << endl;
6379  int NoFarmers = int(m_farmers->GetSize());
6380  vector<int>distances;
6381 
6382  for (int i = 0; i < NoFarmers; i++){
6383 
6384  Farmer* farmer = m_farmers->GetFarmer(i);
6385  APoint p = farmer->SupplyPoint();
6386 
6387  ofile << farmer->GetFarmerRef() << '\t' << p.m_x << '\t' << p.m_y << '\t' << farmer->GetFarmArea() <<endl;
6388  }
6389  ofile.close();

References g_msg, FarmerList::GetFarmer(), FarmerList::GetSize(), m_farmers, APoint::m_x, APoint::m_y, and MapErrorMsg::Warn().

Referenced by InitiateManagement().

◆ ReadCropManagementNorms()

void FarmManager::ReadCropManagementNorms ( )

Reads in and creates the crop management norms data for socio-economics.

This method is the input method for getting the number of management actions normally used for each type per crop

The data is stored in a vector of toc_Foobar length by fmc_Foobar, it matches the format created by FarmManager::OutputManagementNormStats()

6158  {
6164  ifstream ifile("SocioEconomic\\CropManagementNorms.txt", ios::in);
6165  //check if there is an input file
6166  if (!ifile.is_open()) {
6167  g_msg->Warn("FarmManager::ReadCropManagementNorms Cannot open input file ", "CropManagementNorms.txt");
6168  exit(142);
6169  }
6170  // read the number of entries
6171  string str;
6172  int entries;
6173  ifile >> entries >> str;
6174  if (entries != int(toc_Foobar))
6175  {
6176  g_msg->Warn("FarmManager::ReadCropManagementNorms entries does not match toc_Foobar ", entries);
6177  exit(142);
6178  }
6179  //get rid of the column headers
6180  ifile >> str;
6181  for (int i = 0; i <= fmc_Foobar; i++) ifile >> str;
6182  // now read fmc_Foobar entries until the end of file is reached
6183  for (int i=0; i<entries; i++)
6184  {
6185  ifile >> str;
6186  // Match the string to toc_
6187  int toc = int(TranslateCropCodes(str));
6188  // Set the corresponding entry in the YieldReturns vector
6189  for (int i = 0; i < fmc_Foobar; i++)
6190  {
6191  ifile >> m_MangagementNorms[toc][i];
6192  }
6193  ifile >> str; // this is just the totals the norms are based on and not needed for the use inside ALMaSS
6194  }
6195  // All values are read, close
6196  ifile.close();

References fmc_Foobar, g_msg, m_MangagementNorms, toc_Foobar, TranslateCropCodes(), and MapErrorMsg::Warn().

Referenced by FarmManager().

◆ ReadCropYieldReturns()

void FarmManager::ReadCropYieldReturns ( )

Reads in and creates the yield return data for economics.

This method is the input method for storing the prices of crops when sold. The method assumes that the price obtained is per unit biomass on the field.

The data is stored in a vector of toc_Foobar length, and all values not found in the file are assumed to be zero There is no way to check if the values are correct unless an error is created by the associated crop name translation. Therefore it is important to be sure of the input file.

6126  {
6135  ifstream ifile("SocioEconomic\\CropYieldReturns.txt", ios::in);
6136  //check if there is an input file
6137  if (!ifile.is_open()) {
6138  g_msg->Warn("FarmManager::ReadCropYieldReturns Cannot open input file ", "CropYieldReturns.txt");
6139  exit(142);
6140  }
6141  //get rid of the column headers
6142  string str;
6143  double price;
6144  ifile >> str >> str;
6145  // now read each pair of entries until the end of file is reached
6146  while (!ifile.eof())
6147  {
6148  ifile >> str >> price;
6149  // Match the string to toc_
6150  int toc = int(TranslateCropCodes(str));
6151  // Set the corresponding entry in the YieldReturns vector
6152  m_YieldReturns[toc] = price;
6153  }
6154  // All values are read, close
6155  ifile.close();

References g_msg, m_YieldReturns, TranslateCropCodes(), and MapErrorMsg::Warn().

Referenced by FarmManager().

◆ ReadFarmerAttributes()

void FarmManager::ReadFarmerAttributes ( )

Reads in and creates the farmer attribute information and assigns it to farmers.

This reads the farmer attribute information and allocates it to each relevant farmer. The information read is in tab-separated text form. The first value in the file is the number of farmers in the file - this must match the number of farmers in the Farmrefs.ini Col1: FarmerRef Col2: RiskAversion(0-1) Col3: EnvironmentalAttitude(0-1): Col4: CooperativeNumber(-1 for none) Col5: FarmerAge(-1 for ALMaSS generation)

Reads all entries for each farmer from the file and assigns them to the farmer. If there are any actions needed as a result of the entry this is done by the farmer (e.g. if the farmer needs to generate a value based on -1 entries).

6199  {
6206  ifstream ifile("SocioEconomic\\FarmerAttributeInformation.txt", ios::in);
6207  //check if there is an input file
6208  if (!ifile.is_open()) {
6209  g_msg->Warn("FarmManager::ReadFarmerAttributes Cannot open input file ", "FarmerAttributeInformation.txt");
6210  exit(142);
6211  }
6212 
6213  string str;
6214  int NoFarmers, FarmerRef;
6215  FarmerAttributes Attributes;
6216  ifile >> str >> NoFarmers;
6217  if (NoFarmers != m_farms.size()) {
6218  g_msg->Warn("FarmManager::ReadFarmerAttributes inconsistent farmer records. Farmers in input: ", NoFarmers);
6219  g_msg->Warn("Farmers expected: ", int(m_farms.size()));
6220  exit(142);
6221  }
6222  //get rid of the column headers
6223  ifile >> str >> str >> str >> str >> str >> str;
6224  for (int i=0; i<NoFarmers; i++)
6225  {
6230  ifile >> FarmerRef >> Attributes.riskA >> Attributes.envA >> Attributes.Cooperative >> Attributes.Age >> Attributes.riskSpan;
6231 
6232  int index = GetFarmNoLookupIndex(FarmerRef); // Gets the index in the m_farms
6233  m_farms[index]->GetFarmer()->SetPersonalAttributes(Attributes);
6234  m_farms[index]->GetFarmer()->SetFarmerRef(FarmerRef);
6235  }
6236  // All values are read, close
6237  ifile.close();

References FarmerAttributes::Age, FarmerAttributes::Cooperative, FarmerAttributes::envA, g_msg, GetFarmNoLookupIndex(), m_farms, FarmerAttributes::riskA, FarmerAttributes::riskSpan, and MapErrorMsg::Warn().

Referenced by FarmManager().

◆ ReadFarmFunctionsCB()

void FarmManager::ReadFarmFunctionsCB ( )

Reads in and creates the data associated with costs and benefits of farm functions.

This reads the farmer function attribute information and allocates it to cost benefit tables. The information read is in tab-separated text form. The first value in the file is the number of farm functions in the file - this must match the number of farm functions defined in the enum FarmToDo in Treatment.h Col1: FarmToDo Col2: LabourCostHrs/Ha Col3: EconomicCost/Ha: Col4: RiskAvoidenceValue(0-1.0) Col5:EnvImpact(0-1.0)

6299 {
6306  ifstream ifile("SocioEconomic\\FarmFunctionCostBenefit.txt", ios::in);
6307  //check if there is an input file
6308  if (!ifile.is_open()) {
6309  g_msg->Warn("FarmManager::ReadFarmFunctionsCB Cannot open input file ", "FarmFunctionCostBenefit.txt");
6310  exit(142);
6311  }
6312  //get rid of the column headers
6313  string str;
6314  int NoTreatments, index;
6315  ifile >> str >> NoTreatments;
6316  if (NoTreatments != FarmToDo::last_treatment) {
6317  g_msg->Warn("FarmManager::ReadFarmFunctionsCB inconsistent farm function records. Functions in input: ", NoTreatments);
6318  g_msg->Warn("Farm functions expected: ",int(FarmToDo::last_treatment));
6319  exit(142);
6320  }
6321  FarmFuncsCostBenefits FFCB;
6322  ifile >> str >> str >> str >> str >> str >> str;
6323  for (int i = 0; i < NoTreatments; i++)
6324  {
6325  ifile >> index >> FFCB.LabourCost >> FFCB.EconomicCost >> FFCB.RiskAvoidance >> FFCB.EnvImpact >> str;
6326  if (str == "other")
6328  else if (str == "cultivation")
6330  else if (str == "fertilizer")
6332  else if (str == "insecticide")
6334  else if (str == "herbicide")
6336  else if (str == "fungicide")
6338  else if (str == "cutting")
6340  else if (str == "grazing")
6342  else if (str == "watering")
6344  else if (str == "harvest")
6346  else
6348  m_FarmFuncsCB[index] = FFCB;
6349  }
6350  ifile.close();

References FarmFuncsCostBenefits::EconomicCost, FarmFuncsCostBenefits::EnvImpact, fmc_Cultivation, fmc_Cutting, fmc_Fertilizer, fmc_Foobar, fmc_Fungicide, fmc_Grazing, fmc_Harvest, fmc_Herbicide, fmc_Insecticide, fmc_Others, fmc_Watering, g_msg, FarmFuncsCostBenefits::LabourCost, last_treatment, m_FarmFuncsCB, FarmFuncsCostBenefits::ManagementCategory, FarmFuncsCostBenefits::RiskAvoidance, and MapErrorMsg::Warn().

Referenced by FarmManager().

◆ ReadYieldProfitData()

void FarmManager::ReadYieldProfitData ( string  a_filename)
protected

Reads in base data for biomass related profit on harvest for each crop.

◆ RemoveField()

void FarmManager::RemoveField ( int  a_OwnerIndex,
LE a_field 
)
3985 {
3986  m_farms[ a_OwnerIndex ]->RemoveField( a_field );
3987 }

References m_farms.

◆ SetDD()

void FarmManager::SetDD ( double  a_dd)
inline
1606 {daydegrees = a_dd;};

References daydegrees.

◆ SetFarmer()

void FarmManager::SetFarmer ( int  i,
Farmer *  a_farmer 
)
inline

Sets the farmer associated with the farm with the index number i.

1658 { ; }

◆ SetSpilledGrain()

void FarmManager::SetSpilledGrain ( bool  a_spilledgrain)
inline

Set m_SpilledGrain which is the flag for either 2013 (true) or 2014 (false) spilled grain distributions.

1601  {
1602  m_SpilledGrain = a_spilledgrain;
1603  }

References m_SpilledGrain.

◆ SetUseSocioEconomics()

static void FarmManager::SetUseSocioEconomics ( bool  a_flag)
inlinestaticprotected

Sets the socio-economic use flag.

1709 { m_UseSocioEconomicFarmers = a_flag; }

References m_UseSocioEconomicFarmers.

Referenced by FarmManager().

◆ TranslateCropCodes()

TTypesOfCrops FarmManager::TranslateCropCodes ( string &  str)

Converts strings to toc_.

2953  {
2954  // This simply checks through the list of legal crop names and returns
2955  // the correct crop type
2956  string str = astr;
2957 
2958  if (str == "AsparagusEstablishedPlantation") return toc_AsparagusEstablishedPlantation;
2959  if (str == "Beans") return toc_Beans;
2960  if (str == "Beans_Whole") return toc_Beans_Whole;
2961  if (str == "Beet") return toc_Beet;
2962  if (str == "BushFruit") return toc_BushFruit;
2963  if (str == "Cabbage") return toc_Cabbage;
2964  if (str == "CabbageSpring") return toc_CabbageSpring;
2965  if (str == "Carrots") return toc_Carrots;
2966  if (str == "CarrotsSpring") return toc_CarrotsSpring;
2967  if (str == "CatchCropPea") return toc_CatchCropPea;
2968  if (str == "CloverGrassGrazed1") return toc_CloverGrassGrazed1;
2969  if (str == "CloverGrassGrazed2") return toc_CloverGrassGrazed2;
2970  if (str == "CloverGrassGrazed3") return toc_CloverGrassGrazed3;
2971  if (str == "DummyCropPestTesting") return toc_DummyCropPestTesting;
2972  if (str == "FarmForest") return toc_FarmForest;
2973  if (str == "FieldPeas") return toc_FieldPeas;
2974  if (str == "FieldPeasSilage") return toc_FieldPeasSilage;
2975  if (str == "FieldPeasStrigling") return toc_FieldPeasStrigling;
2976  if (str == "FodderBeet") return toc_FodderBeet;
2977  if (str == "FodderGrass") return toc_FodderGrass;
2978  if (str == "FodderLucerne1") return toc_FodderLucerne1;
2979  if (str == "FodderLucerne2") return toc_FodderLucerne2;
2980  if (str == "GenericCatchCrop") return toc_GenericCatchCrop;
2981  if (str == "GrassGrazed1") return toc_GrassGrazed1;
2982  if (str == "GrassGrazed2") return toc_GrassGrazed2;
2983  if (str == "GrassGrazedExtensive") return toc_GrassGrazedExtensive;
2984  if (str == "GrassGrazedLast") return toc_GrassGrazedLast;
2985  if (str == "GrazingPigs") return toc_GrazingPigs;
2986  if (str == "Maize") return toc_Maize;
2987  if (str == "MaizeSilage") return toc_MaizeSilage;
2988  if (str == "MaizeSpring") return toc_MaizeSpring;
2989  if (str == "MaizeStrigling") return toc_MaizeStrigling;
2990  if (str == "MixedVeg") return toc_MixedVeg;
2991  if (str == "OAsparagusEstablishedPlantation") return toc_OAsparagusEstablishedPlantation;
2992  if (str == "Oats") return toc_Oats;
2993  if (str == "OBarleyPeaCloverGrass") return toc_OBarleyPeaCloverGrass;
2994  if (str == "OBeans") return toc_OBeans;
2995  if (str == "OBeans_Whole") return toc_OBeans_Whole;
2996  if (str == "OBushFruit") return toc_OBushFruit;
2997  if (str == "OCabbage") return toc_OCabbage;
2998  if (str == "OCarrots") return toc_OCarrots;
2999  if (str == "OCloverGrassGrazed1") return toc_OCloverGrassGrazed1;
3000  if (str == "OCloverGrassGrazed2") return toc_OCloverGrassGrazed2;
3001  if (str == "OCloverGrassGrazed3") return toc_OCloverGrassGrazed3;
3002  if (str == "OCloverGrassSilage1") return toc_OCloverGrassSilage1;
3003  if (str == "OFarmForest") return toc_OFarmForest;
3004  if (str == "OFieldPeas") return toc_OFieldPeas;
3005  if (str == "OFieldPeasSilage") return toc_OFieldPeasSilage;
3006  if (str == "OFirstYearDanger") return toc_OFirstYearDanger;
3007  if (str == "OFodderBeet") return toc_OFodderBeet;
3008  if (str == "OFodderGrass") return toc_OFodderGrass;
3009  if (str == "OGrazingPigs") return toc_OGrazingPigs;
3010  if (str == "OliveGrove") return toc_OliveGrove;
3011  if (str == "OLentils") return toc_OLentils;
3012  if (str == "OLupines") return toc_OLupines;
3013  if (str == "OMaize") return toc_OMaize;
3014  if (str == "OMaizeSilage") return toc_OMaizeSilage;
3015  if (str == "OMixedVeg") return toc_OMixedVeg;
3016  if (str == "OOats") return toc_OOats;
3017  if (str == "OOrchardCrop") return toc_OOrchardCrop;
3018  if (str == "OPermanentGrassLowYield") return toc_OPermanentGrassLowYield;
3019  if (str == "OrchApple") return toc_OrchApple;
3020  if (str == "OrchPear") return toc_OrchPear;
3021  if (str == "OrchCherry") return toc_OrchCherry;
3022  if (str == "OrchOther") return toc_OrchOther;
3023  if (str == "OOrchApple") return toc_OOrchApple;
3024  if (str == "OOrchPear") return toc_OOrchPear;
3025  if (str == "OOrchCherry") return toc_OOrchCherry;
3026  if (str == "OOrchOther") return toc_OOrchOther;
3027  if (str == "OPermanentGrassGrazed") return toc_OPermanentGrassGrazed;
3028  if (str == "OPermanentGrassLowYield") return toc_OPermanentGrassLowYield;
3029  if (str == "OPotatoes") return toc_OPotatoes;
3030  if (str == "OPotatoesIndustry") return toc_OPotatoesIndustry;
3031  if (str == "OPotatoesSeed") return toc_OPotatoesSeed;
3032  if (str == "OrchardCrop") return toc_OrchardCrop;
3033  if (str == "OSBarleySilage") return