Loading [MathJax]/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
DE_HerbsPerennial_1year Class Reference

#include <DE_HerbsPerennial_1year.h>

Inheritance diagram for DE_HerbsPerennial_1year:
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...
 
 DE_HerbsPerennial_1year (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...
 

Constructor & Destructor Documentation

◆ DE_HerbsPerennial_1year()

DE_HerbsPerennial_1year::DE_HerbsPerennial_1year ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
88  : Crop(a_tov, a_toc, a_L)
89  {
90  // When we start it off, the first possible date for a farm operation is 1st October
91  // This information is used by other crops when they decide how much post processing of
92  // the management is allowed after harvest before the next crop starts.
93  m_first_date = g_date->DayInYear(31, 12);
95  }

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

Member Function Documentation

◆ Do()

bool DE_HerbsPerennial_1year::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 m_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.

83 {
84  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
85  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
86  m_field = a_field;
87  m_ev = a_ev;
88  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
89  int d1 = 0;
91 
92  // Depending what event has occured jump to the correct bit of code
93  switch (m_ev->m_todo)
94  {
95  case de_hp1y_start:
96  {
98 
99  m_last_date = g_date->DayInYear(30, 11); // Should match the last flexdate below
100  //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
101  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
102  // Set up the date management stuff
103  // Start and stop dates for all events after harvest
104  flexdates[0][1] = g_date->DayInYear(30, 11); // last possible day of cutting2 - this is in effect day before the earliest date that a following crop can use
105 
106  flexdates[1][0] = -1;
107  flexdates[1][1] = g_date->DayInYear(30, 11); // last possible day of grazing
108 
109  // Below if this is a spring crop use 365, otherwise set this to 0, second parameter is fixed, and the third is the start up operation in the first year
110  int isSpring = 0;
111  if (StartUpCrop(isSpring, flexdates, int(de_hp1y_spring_harrow))) break;
112 
113  // End single block date checking code. Please see next line comment as well.
114  // Reinit d1 to first possible starting date.
115  d1 = g_date->OldDays() + g_date->DayInYear(1, 10) + isSpring;
116  // OK, let's go.
117  if (m_ev->m_forcespring) {
118  int day_num_shift = 365;
119  if (g_date->DayInYear() < 70) day_num_shift = 0;
120  if (m_farm->IsStockFarmer()) //Stock Farmer
121  {
122  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 3) + day_num_shift, de_hp1y_ferti_s1, false, m_farm, m_field);
123  break;
124  }
125  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 3) + day_num_shift, de_hp1y_ferti_p1, false, m_farm, m_field);
126  break;
127  }
129  break;
130  }
131  break;
132 
133  // This is the first real farm operation
134  // For now all the operations are done by 100% farmers
136  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
137  {
138  if (!m_farm->WinterPlough(m_field, 0.0, g_date->DayInYear(5, 12) - g_date->DayInYear())) {
140  break;
141  }
142  }
143  if (m_farm->IsStockFarmer()) //Stock Farmer
144  {
146  break;
147  }
148  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 3) + 365, de_hp1y_ferti_p1, false, m_farm, m_field);
149  break;
150 
151  case de_hp1y_ferti_s1:
152  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
153  {
154  if (!m_farm->FA_PK(m_field, 0.0, g_date->DayInYear(30, 3) - g_date->DayInYear())) {
156  break;
157  }
158  }
160  break;
161 
162  case de_hp1y_ferti_p1:
163  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
164  {
165  if (!m_farm->FP_PK(m_field, 0.0, g_date->DayInYear(30, 3) - g_date->DayInYear())) {
167  break;
168  }
169  }
171  break;
172 
174  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
175  {
176  if (!m_farm->SpringHarrow(m_field, 0.0, g_date->DayInYear(31, 3) - g_date->DayInYear())) {
178  break;
179  }
180  }
181  d1 = g_date->Date() + 7;
182  if (d1 < g_date->OldDays() + g_date->DayInYear(25, 3)) {
183  d1 = g_date->OldDays() + g_date->DayInYear(25, 3);
184  }
185  if (m_farm->IsStockFarmer()) //Stock Farmer
186  {
188  break;
189  }
190  else SimpleEvent_(d1, de_hp1y_ferti_p2, false, m_farm, m_field);
191  break;
192 
193  case de_hp1y_ferti_s2:
194  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
195  {
196  if (!m_farm->FA_N(m_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
198  break;
199  }
200  }
202  break;
203 
204  case de_hp1y_ferti_p2:
205  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
206  {
207  if (!m_farm->FP_N(m_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
209  break;
210  }
211  }
213  break;
214 
216  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
217  {
218  if (!m_farm->PreseedingCultivator(m_field, 0.0, g_date->DayInYear(11, 4) - g_date->DayInYear())) {
220  break;
221  }
222  }
224  break;
225 
226  case de_hp1y_planting:
227  if (!m_farm->SpringSow(m_field, 0.0, g_date->DayInYear(15, 4) - g_date->DayInYear())) {
229  break;
230  }
232  break;
233 
234  case de_hp1y_weeding:
235  if (m_ev->m_lock || m_farm->DoIt_prob(0.50))
236  {
237  if (!m_farm->CutWeeds(m_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
239  break;
240  }
241  if (m_farm->IsStockFarmer()) //Stock Farmer
242  {
244  break;
245  }
247  break;
248  }
250  break;
251 
252  case de_hp1y_herbicide:
253  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
254  {
255  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
257  break;
258  }
259  }
260  if (m_farm->IsStockFarmer()) //Stock Farmer
261  {
263  break;
264  }
266  break;
267 
268  case de_hp1y_ferti_s3:
269  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
270  {
271  if (!m_farm->FA_N(m_field, 0.0, g_date->DayInYear(20, 5) - g_date->DayInYear())) {
273  break;
274  }
275  }
277  break;
278 
279  case de_hp1y_ferti_p3:
280  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
281  {
282  if (!m_farm->FP_N(m_field, 0.0, g_date->DayInYear(20, 5) - g_date->DayInYear())) {
284  break;
285  }
286  }
288  break;
289 
290  case de_hp1y_harvest:
291  if (!m_farm->GreenHarvest(m_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
293  break;
294  }
295  if (m_farm->IsStockFarmer()) //Stock Farmer
296  {
298  break;
299  }
300  else SimpleEvent_(g_date->Date() + 5, de_hp1y_ferti_p4, false, m_farm, m_field);
301  break;
302 
303  case de_hp1y_ferti_s4:
304  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
305  {
306  if (!m_farm->FA_N(m_field, 0.0, g_date->DayInYear(30, 7) - g_date->DayInYear())) {
308  break;
309  }
310  }
312  break;
313 
314  case de_hp1y_ferti_p4:
315  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
316  {
317  if (!m_farm->FP_N(m_field, 0.0, g_date->DayInYear(30, 7) - g_date->DayInYear())) {
319  break;
320  }
321  }
323  break;
324 
325  case de_hp1y_harrow:
326  if (m_ev->m_lock || m_farm->DoIt_prob(1.00))
327  {
328  if (!m_farm->AutumnHarrow(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
330  break;
331  }
332  }
333  done = true;
334  break;
335 
336  default:
337  g_msg->Warn(WARN_BUG, "DE_HerbsPerennial_1year::Do(): "
338  "Unknown event type! ", "");
339  exit(1);
340  }
341  if (done) m_ev->m_forcespring = true; // Here we need to force the next crop to spring operation, so set the ev->forcespring to true
342  return done;
343 }

References Farm::AutumnHarrow(), LE::ClearManagementActionSum(), Farm::CutWeeds(), Calendar::Date(), Calendar::DayInYear(), de_hp1y_ferti_p1, de_hp1y_ferti_p2, de_hp1y_ferti_p3, de_hp1y_ferti_p4, de_hp1y_ferti_s1, de_hp1y_ferti_s2, de_hp1y_ferti_s3, de_hp1y_ferti_s4, de_hp1y_harrow, de_hp1y_harvest, de_hp1y_herbicide, de_hp1y_planting, de_hp1y_preseeding_cultivation, de_hp1y_spring_harrow, de_hp1y_start, de_hp1y_weeding, de_hp1y_winter_plough, Farm::DoIt_prob(), Farm::FA_N(), Farm::FA_PK(), Farm::FP_N(), Farm::FP_PK(), g_date, g_msg, LE::GetMDates(), Farm::GreenHarvest(), Farm::HerbicideTreat(), 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(), Farm::PreseedingCultivator(), Crop::SimpleEvent_(), Farm::SpringHarrow(), Farm::SpringSow(), Crop::StartUpCrop(), tov_DEHerbsPerennial_1year, MapErrorMsg::Warn(), WARN_BUG, and Farm::WinterPlough().

◆ SetUpFarmCategoryInformation()

void DE_HerbsPerennial_1year::SetUpFarmCategoryInformation ( )
inline
96  {
97  const int elements = 2 + (de_hp1y_foobar - DE_HP1Y_BASE);
99 
100  FarmManagementCategory catlist[elements] =
101  {
102  fmc_Others, // zero element unused but must be here
103  fmc_Others, // de_hp1y_start = 1, // Compulsory, must always be 1 (one).
104  fmc_Others, // de_hp1y_sleep_all_day = DE_HP_BASE,
105  fmc_Cultivation, // de_hp1y_winter_plough,
106  fmc_Fertilizer, // de_hp1y_ferti_p1,//PK
107  fmc_Fertilizer, // de_hp1y_ferti_s1,//PK
108  fmc_Cultivation, // de_hp1y_spring_harrow,
109  fmc_Fertilizer, // de_hp1y_ferti_p2,//N I
110  fmc_Fertilizer, // de_hp1y_ferti_s2,//N I
111  fmc_Cultivation, // de_hp1y_preeseding_cultivation,
112  fmc_Others, // de_hp1y_planting,
113  fmc_Others, // de_hp1y_weeding,
114  fmc_Herbicide, // de_hp1y_herbicide,
115  fmc_Fertilizer, // de_hp1y_ferti_p3,//N II
116  fmc_Fertilizer, // de_hp1y_ferti_s3,//N II
117  fmc_Harvest, // de_hp1y_harvest,
118  fmc_Fertilizer, // de_hp1y_ferti_p4,//N III
119  fmc_Fertilizer, // de_hp1y_ferti_s4,//N III
120  fmc_Cultivation, // de_hp1y_harrow,
121 
122  // no foobar entry
123 
124  };
125  // Iterate over the catlist elements and copy them to vector
126  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
127 
128  }

References DE_HP1Y_BASE, de_hp1y_foobar, fmc_Cultivation, fmc_Fertilizer, fmc_Harvest, fmc_Herbicide, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DE_HerbsPerennial_1year().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
FarmEvent::m_forcespring
bool m_forcespring
Definition: Farm.h:392
de_hp1y_weeding
Definition: DE_HerbsPerennial_1year.h:71
Farm::PreseedingCultivator
virtual bool PreseedingCultivator(LE *a_field, double a_user, int a_days)
Carry out preseeding cultivation on a_field (tilling set including cultivator and string roller to co...
Definition: FarmFuncs.cpp:312
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: FarmFuncs.cpp:2025
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
de_hp1y_preseeding_cultivation
Definition: DE_HerbsPerennial_1year.h:69
de_hp1y_ferti_p4
Definition: DE_HerbsPerennial_1year.h:76
de_hp1y_spring_harrow
Definition: DE_HerbsPerennial_1year.h:66
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
de_hp1y_start
Definition: DE_HerbsPerennial_1year.h:61
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
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
DE_HP1Y_BASE
#define DE_HP1Y_BASE
Definition: DE_HerbsPerennial_1year.h:53
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
de_hp1y_herbicide
Definition: DE_HerbsPerennial_1year.h:72
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
Farm::FP_PK
virtual bool FP_PK(LE *a_field, double a_user, int a_days)
Apply PK fertilizer, on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:673
de_hp1y_planting
Definition: DE_HerbsPerennial_1year.h:70
Farm::GreenHarvest
virtual bool GreenHarvest(LE *a_field, double a_user, int a_days)
GreenHarvest (remove of excess production that may affect the desired quality of the fruits,...
Definition: FarmFuncs.cpp:1942
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
de_hp1y_winter_plough
Definition: DE_HerbsPerennial_1year.h:63
Calendar::Date
long Date(void)
Definition: Calendar.h:57
de_hp1y_foobar
Definition: DE_HerbsPerennial_1year.h:79
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
Farm::FP_N
virtual bool FP_N(LE *a_field, double a_user, int a_days)
Apply N fertilizer, on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:700
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
de_hp1y_ferti_s1
Definition: DE_HerbsPerennial_1year.h:65
tov_DEHerbsPerennial_1year
Definition: LandscapeFarmingEnums.h:513
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
de_hp1y_ferti_p1
Definition: DE_HerbsPerennial_1year.h:64
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
Farm::FA_N
virtual bool FA_N(LE *a_field, double a_user, int a_days)
Apply N fertilizer, on a_field owned by a stock farmer.
Definition: FarmFuncs.cpp:713
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
de_hp1y_ferti_p3
Definition: DE_HerbsPerennial_1year.h:73
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
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
de_hp1y_ferti_s4
Definition: DE_HerbsPerennial_1year.h:77
de_hp1y_ferti_s2
Definition: DE_HerbsPerennial_1year.h:68
de_hp1y_ferti_p2
Definition: DE_HerbsPerennial_1year.h:67
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
de_hp1y_harvest
Definition: DE_HerbsPerennial_1year.h:75
Farm::AutumnHarrow
virtual bool AutumnHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the autumn on a_field.
Definition: FarmFuncs.cpp:285
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
Farm::WinterPlough
virtual bool WinterPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the winter on a_field.
Definition: FarmFuncs.cpp:395
de_hp1y_ferti_s3
Definition: DE_HerbsPerennial_1year.h:74
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
DE_HerbsPerennial_1year::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DE_HerbsPerennial_1year.h:96
Farm::FA_PK
virtual bool FA_PK(LE *a_field, double a_user, int a_days)
Apply PK fertilizer to a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1010
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
de_hp1y_harrow
Definition: DE_HerbsPerennial_1year.h:78
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
Crop::SimpleEvent_
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.
Definition: Farm.cpp:751
Farm::CutWeeds
virtual bool CutWeeds(LE *a_field, double a_user, int a_days)
Carry out weed topping on a_field.
Definition: FarmFuncs.cpp:1629