File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DK_OSpringFodderGrass Class Reference

DK_OSpringFodderGrass class
. More...

#include <DK_OSpringFodderGrass.h>

Inheritance diagram for DK_OSpringFodderGrass:
Crop

Public Member Functions

virtual bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 The one and only method for a crop management plan. All farm actions go through here. More...
 
 DK_OSpringFodderGrass (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
void SetUpFarmCategoryInformation ()
 
- Public Member Functions inherited from Crop
virtual ~Crop ()
 
 Crop (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
int GetFirstDate (void)
 
void ChooseNextCrop (int a_no_dates)
 Chooses the next crop to grow in a field. More...
 
int GetCropClassification ()
 
void SetCropClassification (int a_classification)
 
void GetCropType (TTypesOfCrops a_toc)
 
TTypesOfCrops GetCropType ()
 
FarmManagementCategory LookUpManagementCategory (int a_todo)
 
bool GetForceSpringOK ()
 

Additional Inherited Members

- Public Attributes inherited from Crop
TTypesOfVegetation m_tov
 
- Protected Member Functions inherited from Crop
void SimpleEvent (long a_date, int a_todo, bool a_lock)
 Adds an event to this crop management. More...
 
void SimpleEvent_ (long a_date, int a_todo, bool a_lock, Farm *a_farm, LE *a_field)
 Adds an event to this crop management without relying on member variables. More...
 
bool StartUpCrop (int a_spring, std::vector< std::vector< int >> a_flexdates, int a_todo)
 
Holds the translation between the farm operation enum for each cropand the farm management category associated with it More...
 
bool AphidDamage (LE *a_field)
 Compares aphid numbers per m2 with a threshold to return true if threshold is exceeded. More...
 
- Protected Attributes inherited from Crop
Farmm_farm
 
LEm_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_base_elements_no
 
Landscapem_OurLandscape
 
bool m_forcespringpossible = false
 Used to signal that the crop can be forced to start in spring. More...
 
TTypesOfCrops m_toc
 The Crop type in terms of the TTypesOfCrops list (smaller list than tov, no country designation) More...
 
int m_CropClassification
 Contains information on whether this is a winter crop, spring crop, or catch crop that straddles the year boundary (0,1,2) More...
 
vector< FarmManagementCategorym_ManagementCategories
 Holds the translation between the farm operation enum for each crop and the farm management category associated with it. More...
 
- Static Protected Attributes inherited from Crop
static int m_date_modifier = 0
 Holds a value that shifts test pesticide use by this many days in crops modified to use it. More...
 

Detailed Description

DK_OSpringFodderGrass class
.

See DK_OSpringFodderGrass.h::DK_OSpringFodderGrassToDo for a complete list of all possible events triggered codes by the DK_OSpringFodderGrass management plan. When triggered these events are handled by Farm and are available as information for other objects such as animal and bird models.

Constructor & Destructor Documentation

◆ DK_OSpringFodderGrass()

DK_OSpringFodderGrass::DK_OSpringFodderGrass ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
97  : Crop(a_tov, a_toc, a_L)
98  {
99  // When we start it off, the first possible date for a farm operation
100  // This information is used by other crops when they decide how much post processing of
101  // the management is allowed after harvest before the next crop starts.
102  m_first_date = g_date->DayInYear(31, 3);
104  }

References Calendar::DayInYear(), g_date, Crop::m_first_date, and SetUpFarmCategoryInformation().

Member Function Documentation

◆ Do()

bool DK_OSpringFodderGrass::Do ( Farm a_farm,
LE a_field,
FarmEvent a_ev 
)
virtual

The one and only method for a crop management plan. All farm actions go through here.

Called every time something is done to the crop by the farmer in the first instance it is always called with a_ev->todo set to start, but susequently will be called whenever the farmer wants to carry out a new operation.
This method details all the management and relationships between operations necessary to grow and ALMaSS crop - in this case conventional spring barley Fodder.

Reimplemented from Crop.

88 {
89  m_field = a_field; // this is needed because of possible calls to other methods and currently we do not pass parameters.
90  m_farm = a_farm; // this is needed because of possible calls to other methods and currently we do not pass parameters.
91  m_ev = a_ev;
92  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
93  int d1 = 0;
94  TTypesOfVegetation l_tov = tov_DKOSpringFodderGrass; // The current type - change to match the crop you have
95  // Depending what event has occured jump to the correct bit of code e.g. for ww_start jump to line 67 below
96  switch (a_ev->m_todo)
97  {
98  case dk_osfg_start:
99  {
100  a_field->ClearManagementActionSum();
101 
102  m_last_date = g_date->DayInYear(10, 10); // Should match the last flexdate below
103  //Create a 2d array of 1 plus the number of operations you use. Change only 4+1 to what you need in the line below
104  std::vector<std::vector<int>> flexdates(4 + 1, std::vector<int>(2, 0));
105  // Set up the date management stuff
106  // Start and stop dates for all events after harvest
107  flexdates[0][1] = g_date->DayInYear(31, 8); // last possible day of water in this case
108  // Now these are done in pairs, start & end for each operation. If its not used then -1
109  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
110  flexdates[1][1] = g_date->DayInYear(30, 9); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1) - cutting
111  flexdates[2][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 2 (start op 2)
112  flexdates[2][1] = g_date->DayInYear(10, 10); // This date will be moved back as far as necessary and potentially to flexdates 2 (end op 2) - cutting
113  flexdates[3][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 3 (start op 3)
114  flexdates[3][1] = g_date->DayInYear(10, 10); // This date will be moved back as far as necessary and potentially to flexdates 3 (end op 3) - cattle out
115  flexdates[4][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 3 (start op 3)
116  flexdates[4][1] = g_date->DayInYear(10, 10); // This date will be moved back as far as necessary and potentially to flexdates 4 (end op 4) - cattle is out
117 
118 
119  // Below if this is a spring crop use 365, otherwise first parameter is always 0, second parameter is fixed, and the third is the start up operation in the first year
120  int isSpring = 365;
121  if (StartUpCrop(isSpring, flexdates, int(dk_osfg_harrow))) break;
122 
123  // End single block date checking code. Please see next line comment as well.
124  // Reinit d1 to first possible starting date.
125  d1 = g_date->OldDays() + g_date->DayInYear(1, 3) + isSpring;
126  // OK, let's go.
127  // Here we queue up the first event which changes dependent on whether it is a forced spring sow or not
128  SimpleEvent(d1, dk_osfg_harrow, false);
129  break;
130  }
131  break;
132 
133  case dk_osfg_harrow:
134  if (a_ev->m_lock || a_farm->DoIt(100)) {
135  if (!a_farm->SpringHarrow(a_field, 0.0, g_date->DayInYear(31, 3) - g_date->DayInYear())) {
136  SimpleEvent(g_date->Date() + 1, dk_osfg_harrow, true);
137  break;
138  }
139  }
140  //here comes next events:
141  if (a_farm->IsStockFarmer()) {
143  break;
144  }
145  else SimpleEvent(g_date->Date(), dk_osfg_manure_p, false);
146  break;
147 
148  case dk_osfg_manure_s:
149  if (a_ev->m_lock || a_farm->DoIt(100)) {
150  if (!a_farm->FA_Manure(a_field, 0.0, g_date->DayInYear(31, 3) - g_date->DayInYear())) {
151  SimpleEvent(g_date->Date() + 1, dk_osfg_manure_s, true);
152  break;
153  }
154  }
156  break;
157 
158  case dk_osfg_manure_p:
159  if (a_ev->m_lock || a_farm->DoIt(100)) {
160  if (!a_farm->FP_Manure(a_field, 0.0, g_date->DayInYear(31, 3) - g_date->DayInYear())) {
161  SimpleEvent(g_date->Date() + 1, dk_osfg_manure_p, true);
162  break;
163  }
164  }
166  break;
167 
168  case dk_osfg_ferti_sk_s:
169  if (a_ev->m_lock || a_farm->DoIt(100)) {
170  if (!a_farm->FA_SK(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
171  SimpleEvent(g_date->Date() + 1, dk_osfg_ferti_sk_s, true);
172  break;
173  }
174  }
176  break;
177 
178  case dk_osfg_ferti_sk_p:
179  if (a_ev->m_lock || a_farm->DoIt(100)) {
180  if (!a_farm->FP_SK(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
181  SimpleEvent(g_date->Date() + 1, dk_osfg_ferti_sk_p, true);
182  break;
183  }
184  }
186  break;
187 
189  if (a_ev->m_lock || a_farm->DoIt(100)) {
190  if (!a_farm->SpringPlough(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
192  break;
193  }
194  }
195  SimpleEvent(g_date->Date(), dk_osfg_sow, false);
196  break;
197  case dk_osfg_sow:
198  if (a_ev->m_lock || a_farm->DoIt(100)) {
199  if (!a_farm->SpringSow(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
200  SimpleEvent(g_date->Date() + 1, dk_osfg_sow, true);
201  break;
202  }
203  }
205  break;
206  case dk_osfg_water:
207  if (a_ev->m_lock || a_farm->DoIt(50)) {
208  if (!a_farm->Water(a_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
209  SimpleEvent(g_date->Date() + 1, dk_osfg_water, true);
210  break;
211  }
212  }
213  SimpleEvent(g_date->Date()+1, dk_osfg_cutting1, false);
214  break;
215  case dk_osfg_cutting1: //
216  if (!a_farm->CutToSilage(a_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
217  SimpleEvent(g_date->Date() + 1, dk_osfg_cutting1, true);
218  break;
219  }
220  SimpleEvent(g_date->Date() + 35, dk_osfg_cutting2, false);
221  break;
222  case dk_osfg_cutting2: //50% of the 90% with lay-out (45% in total) will do a second cut, 50% do grazing
223  if (a_ev->m_lock || a_farm->DoIt_prob(0.50)) {
224  if (!m_farm->CutToSilage(m_field, 0.0, m_field->GetMDates(1, 2) - g_date->DayInYear())) {
225  SimpleEvent(g_date->Date() + 1, dk_osfg_cutting2, true);
226  break;
227  }
229  break;
230  }
231  else SimpleEvent(g_date->Date() + 35, dk_osfg_grazing, false);
232  break;
233  case dk_osfg_grazing:
237  SimpleEvent(g_date->Date() + 1, dk_osfg_grazing, true);
238  break;
239  }
241  break;
242  case dk_osfg_cattle_is_out: // Keep the cattle out there
243  // CattleIsOut() returns false if it is not time to stop grazing
248  break;
249  }
251  break;
252 
253  case dk_osfg_force_growth: // Need to add this in the end to make sure grass decays in winter
254  if (g_date->DayInYear() < g_date->DayInYear(1, 11)) {
256  break;
257  }
258  else if (g_date->DayInYear() < g_date->DayInYear(31, 12)) {
259  a_field->ForceGrowthTest();
261  break;
262  }
263  done = true; // end of plan
264  break;
265  default:
266  g_msg->Warn(WARN_BUG, "DK_OSpringFodderGrass::Do(): "
267  "Unknown event type! ", "");
268  exit(1);
269  }
270  if (done) a_ev->m_forcespring = true; // Here we need to force the next crop to spring operation, so set the ev->forcespring to true
271  return done;
272 }

References Farm::CattleIsOut(), Farm::CattleOut(), cfg_farm_cattle_grass_high, cfg_farm_cattle_grass_low, LE::ClearManagementActionSum(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), dk_osfg_cattle_is_out, dk_osfg_cutting1, dk_osfg_cutting2, dk_osfg_ferti_sk_p, dk_osfg_ferti_sk_s, dk_osfg_force_growth, DK_OSFG_GRASS_READY, dk_osfg_grazing, dk_osfg_harrow, dk_osfg_manure_p, dk_osfg_manure_s, dk_osfg_sow, dk_osfg_spring_plough, dk_osfg_start, dk_osfg_water, Farm::DoIt(), Farm::DoIt_prob(), Farm::FA_Manure(), Farm::FA_SK(), LE::ForceGrowthTest(), Farm::FP_Manure(), Farm::FP_SK(), g_date, g_msg, LE::GetMDates(), LE::GetVegHeight(), Farm::IsStockFarmer(), Crop::m_ev, Crop::m_farm, Crop::m_field, FarmEvent::m_forcespring, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringSow(), Crop::StartUpCrop(), tov_DKOSpringFodderGrass, CfgInt::value(), MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void DK_OSpringFodderGrass::SetUpFarmCategoryInformation ( )
inline
105  {
106  const int elements = 2 + (dk_osfg_foobar - DK_OSFG_BASE);
108 
109  FarmManagementCategory catlist[elements] =
110  {
111  fmc_Others, // zero element unused but must be here
112  fmc_Others, // dk_osfg_start = 1, // Compulsory, must always be 1 (one).
113  fmc_Others, // dk_osfg_sleep_all_day = DK_osfg_BASE,
114  fmc_Cultivation, // dk_osfg_harrow,
115  fmc_Fertilizer, // dk_osfg_manure,
116  fmc_Fertilizer, // dk_osfg_ferti_sk,
117  fmc_Fertilizer, // dk_osfg_manure,
118  fmc_Fertilizer, // dk_osfg_ferti_sk,
119  fmc_Cultivation, // dk_osfg_spring_plough,
120  fmc_Others, // dk_osfg_sow,
121  fmc_Watering, // dk_osfg_water,
122  fmc_Cutting, // dk_osfg_cutting1,
123  fmc_Cutting, // dk_osfg_cutting2,
124  fmc_Grazing, // dk_osfg_grazing,
125  fmc_Grazing, // dk_osfg_cattle_is_out,
126  fmc_Others // dk_osfg_force_growth
127 
128  // no foobar entry
129 
130  };
131  // Iterate over the catlist elements and copy them to vector
132  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
133 
134  }

References DK_OSFG_BASE, dk_osfg_foobar, fmc_Cultivation, fmc_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Others, fmc_Watering, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_OSpringFodderGrass().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
dk_osfg_water
Definition: DK_OSpringFodderGrass.h:75
FarmEvent::m_forcespring
bool m_forcespring
Definition: Farm.h:392
dk_osfg_force_growth
Definition: DK_OSpringFodderGrass.h:80
DK_OSFG_GRASS_READY
#define DK_OSFG_GRASS_READY
Definition: DK_OSpringFodderGrass.h:54
Farm::SpringPlough
virtual bool SpringPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the spring on a_field.
Definition: FarmFuncs.cpp:421
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
Farm::CattleIsOut
virtual bool CattleIsOut(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out' event for every day the cattle are on a_field.
Definition: FarmFuncs.cpp:2470
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Farm::CutToSilage
virtual bool CutToSilage(LE *a_field, double a_user, int a_days)
Cut vegetation for silage on a_field.
Definition: FarmFuncs.cpp:1644
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
dk_osfg_start
Definition: DK_OSpringFodderGrass.h:66
LE::ForceGrowthTest
virtual void ForceGrowthTest(void)
Definition: Elements.h:188
Farm::DoIt_prob
bool DoIt_prob(double a_probability)
Return chance out of 0 to 1.
Definition: Farm.cpp:864
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
Farm::FA_Manure
virtual bool FA_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1110
dk_osfg_grazing
Definition: DK_OSpringFodderGrass.h:78
Farm::SpringSow
virtual bool SpringSow(LE *a_field, double a_user, int a_days, double a_seed_coating_amount=-1, PlantProtectionProducts a_ppp=ppp_foobar)
Carry out a sowing event in the spring on a_field.
Definition: FarmFuncs.cpp:501
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
Farm::FP_SK
virtual bool FP_SK(LE *a_field, double a_user, int a_days)
Apply SK fertilizer, on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:794
dk_osfg_cutting2
Definition: DK_OSpringFodderGrass.h:77
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
dk_osfg_harrow
Definition: DK_OSpringFodderGrass.h:68
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
Farm::FP_Manure
virtual bool FP_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:896
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
tov_DKOSpringFodderGrass
Definition: LandscapeFarmingEnums.h:380
DK_OSpringFodderGrass::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OSpringFodderGrass.h:105
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
LE::GetVegHeight
virtual double GetVegHeight(void)
Definition: Elements.h:148
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
Crop::StartUpCrop
bool StartUpCrop(int a_spring, std::vector< std::vector< int >> a_flexdates, int a_todo)
Holds the translation between the farm operation enum for each cropand the farm management category a...
Definition: Farm.cpp:652
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
CfgInt::value
int value() const
Definition: Configurator.h:116
DK_OSFG_BASE
#define DK_OSFG_BASE
Definition: DK_OSpringFodderGrass.h:53
Crop::m_ManagementCategories
vector< FarmManagementCategory > m_ManagementCategories
Holds the translation between the farm operation enum for each crop and the farm management category ...
Definition: Farm.h:530
Farm::FA_SK
virtual bool FA_SK(LE *a_field, double a_user, int a_days)
Apply SK fertilizer, on a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1052
dk_osfg_ferti_sk_s
Definition: DK_OSpringFodderGrass.h:70
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
cfg_farm_cattle_grass_high
CfgInt cfg_farm_cattle_grass_high
dk_osfg_cutting1
Definition: DK_OSpringFodderGrass.h:76
Farm::Water
virtual bool Water(LE *a_field, double a_user, int a_days)
Carry out a watering on a_field.
Definition: FarmFuncs.cpp:1330
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
dk_osfg_manure_s
Definition: DK_OSpringFodderGrass.h:69
dk_osfg_sow
Definition: DK_OSpringFodderGrass.h:74
cfg_farm_cattle_grass_low
CfgInt cfg_farm_cattle_grass_low
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
dk_osfg_ferti_sk_p
Definition: DK_OSpringFodderGrass.h:72
dk_osfg_manure_p
Definition: DK_OSpringFodderGrass.h:71
dk_osfg_cattle_is_out
Definition: DK_OSpringFodderGrass.h:79
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
dk_osfg_spring_plough
Definition: DK_OSpringFodderGrass.h:73
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
Farm::CattleOut
virtual bool CattleOut(LE *a_field, double a_user, int a_days)
Start a grazing event on a_field today.
Definition: FarmFuncs.cpp:2368
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
Farm::SpringHarrow
virtual bool SpringHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the spring on a_field.
Definition: FarmFuncs.cpp:459
dk_osfg_foobar
Definition: DK_OSpringFodderGrass.h:81