ALMaSS Skylark ODDox  1.1
The skylark model description following ODdox protocol
PLFodderLucerne2 Class Reference

PLFodderLucerne2 class
. More...

#include <PLFodderLucerne2.h>

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...
 
 PLFodderLucerne2 ()
 
- Public Member Functions inherited from Crop
virtual ~Crop ()
 
 Crop ()
 
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)
 

Additional Inherited Members

- 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...
 
- Protected Attributes inherited from Crop
Farmm_farm
 
LE * m_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_CropClassification
 

Detailed Description

PLFodderLucerne2 class
.

See PLFodderLucerne2.h::PLFodderLucerne2ToDo for a complete list of all possible events triggered codes by the fodder lucerne1 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

◆ PLFodderLucerne2()

PLFodderLucerne2::PLFodderLucerne2 ( )
inline
70  {
71  // When we start it off, the first possible date for a farm operation is 31th March
72  // This information is used by other crops when they decide how much post processing of
73  // the management is allowed after harvest before the next crop starts.
74  m_first_date = g_date->DayInYear(31, 3);
75  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

bool PLFodderLucerne2::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 fodder lucerne in the second/third year.

Reimplemented from Crop.

57 {
58  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
59  int d1 = 0;
60  // Depending what event has occured jump to the correct bit of code
61  switch (a_ev->m_todo)
62  {
63  case pl_fl2_start:
64  {
65  // Set up the date management stuff
66 
67  // Check the next crop for early start, unless it is a spring crop
68  // in which case we ASSUME that no checking is necessary!!!!
69  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
70 
71  //new if: do the check only for non-optimising farms and if year>0. (030713 - m_rotation used only in the hidden year, so I modified the condition from >7 to >0)
72  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
73  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
74 
75  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
76  if (g_date->DayInYear(5, 10) >= a_ev->m_startday)
77  {
78  g_msg->Warn(WARN_BUG, "PLFodderLucerne2::Do(): ", "Harvest too late for the next crop to start!!!");
79  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
80  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
81  }
82  }
83  // Now no operations can be timed after the start of the next crop.
84 
85  if (!a_ev->m_first_year) {
86  // Are we before July 1st?
87  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
88  if (g_date->Date() < d1) {
89  // Yes, too early. We assumme this is because the last crop was late
90  printf("Poly: %d\n", a_field->GetPoly());
91  g_msg->Warn(WARN_BUG, "PLFodderLucerne2::Do(): ", "Crop start attempt between 1st Jan & 1st July");
92  int prev = g_landscape_p->BackTranslateVegTypes(a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex()));
93  g_msg->Warn(WARN_BUG, "Previous Crop ", prev);
94  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
95  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
96  }
97  else {
98  d1 = g_date->OldDays() + 365 + m_first_date; // Add 365 for spring crop
99  if (g_date->Date() > d1) {
100  // Yes too late - should not happen - raise an error
101  g_msg->Warn(WARN_BUG, "PLFodderLucerne2::Do(): ", "Crop start attempt after last possible start date");
102  g_msg->Warn(WARN_BUG, "Previous Crop ", "");
103  a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex());
104  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
105  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
106  }
107  }
108  }
109  else {
110  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 3), pl_fl2_spring_harrow, false, a_farm, a_field);
111  break;
112  }
113  }//if
114 
115  // End single block date checking code. Please see next line comment as well.
116  // Reinit d1 to first possible starting date.
117 
118 
119  d1 = g_date->OldDays() + g_date->DayInYear(1, 3);
120  if (g_date->Date() >= d1) d1 += 365;
121  SimpleEvent_(d1, pl_fl2_spring_harrow, false, a_farm, a_field);
122  break;
123  }
124  break;
125 
126  // This is the first real farm operation
128  if ((a_ev->m_lock) || a_farm->DoIt(50))
129  {
130  if (!a_farm->ShallowHarrow(a_field, 0.0, g_date->DayInYear(31, 3) - g_date->DayInYear())) {
131  SimpleEvent_(g_date->Date() + 1, pl_fl2_spring_harrow, true, a_farm, a_field);
132  break;
133  }
134  }
135  d1 = g_date->Date() + 1;
136  if (d1 < g_date->OldDays() + g_date->DayInYear(5, 3)) {
137  d1 = g_date->OldDays() + g_date->DayInYear(5, 3);
138  }
139  if (a_farm->IsStockFarmer()) //Stock Farmer
140  {
141  SimpleEvent_(d1, pl_fl2_ferti_s0, false, a_farm, a_field);
142  }
143  else SimpleEvent_(d1, pl_fl2_ferti_p0, false, a_farm, a_field);
144  break;
145  case pl_fl2_ferti_p0:
146  if (a_ev->m_lock || a_farm->DoIt(66))
147  {
148  if (!a_farm->FP_PK(a_field, 0.0, g_date->DayInYear(20, 4) - g_date->DayInYear())) {
149  SimpleEvent_(g_date->Date() + 1, pl_fl2_ferti_p0, true, a_farm, a_field);
150  break;
151  }
152  }
153  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_fl2_herbicide1, false, a_farm, a_field);
154  break;
155  case pl_fl2_ferti_s0:
156  if (a_ev->m_lock || a_farm->DoIt(66))
157  {
158  if (!a_farm->FA_PK(a_field, 0.0, g_date->DayInYear(20, 4) - g_date->DayInYear())) {
159  SimpleEvent_(g_date->Date() + 1, pl_fl2_ferti_s0, true, a_farm, a_field);
160  break;
161  }
162  }
163  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_fl2_herbicide1, false, a_farm, a_field);
164  break;
165  case pl_fl2_herbicide1:
166  if (a_ev->m_lock || a_farm->DoIt(31))
167  {
168  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(10, 5) - g_date->DayInYear())) {
169  SimpleEvent_(g_date->Date() + 1, pl_fl2_herbicide1, true, a_farm, a_field);
170  break;
171  }
172  }
173  // 70% of farmers will do cutting 4 times, the rest only 3 times
174  if (a_farm->DoIt(70))
175  {
176  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_fl2_cut_to_silage1B, false, a_farm, a_field);
177  }
178  else
179  {
180  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 6), pl_fl2_cut_to_silage1A, false, a_farm, a_field);
181  }
182  break;
184  // Here comes cutting with 3 cutting events
185  if (!a_farm->CutToSilage(a_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
186  SimpleEvent_(g_date->Date() + 1, pl_fl2_cut_to_silage1A, true, a_farm, a_field);
187  break;
188  }
189  SimpleEvent_(g_date->Date() + 1, pl_fl2_harrow1A, false, a_farm, a_field);
190  break;
191  case pl_fl2_harrow1A:
192  if (a_ev->m_lock || a_farm->DoIt(33))
193  {
194  if (!a_farm->ShallowHarrow(a_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
195  SimpleEvent_(g_date->Date() + 1, pl_fl2_harrow1A, true, a_farm, a_field);
196  break;
197  }
198  }
199  if (a_farm->IsStockFarmer()) //Stock Farmer
200  {
201  SimpleEvent_(g_date->Date() + 1, pl_fl2_ferti_s1A, false, a_farm, a_field);
202  }
203  else SimpleEvent_(g_date->Date() + 1, pl_fl2_ferti_p1A, false, a_farm, a_field);
204  break;
205  case pl_fl2_ferti_p1A:
206  if (a_ev->m_lock || a_farm->DoIt(60))
207  {
208  if (!a_farm->FP_PK(a_field, 0.0, g_date->Date() + 10 - g_date->DayInYear())) {
209  SimpleEvent_(g_date->Date() + 1, pl_fl2_ferti_p1A, true, a_farm, a_field);
210  break;
211  }
212  }
213  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 7), pl_fl2_cut_to_silage2A, false, a_farm, a_field);
214  break;
215  case pl_fl2_ferti_s1A:
216  if (a_ev->m_lock || a_farm->DoIt(60))
217  {
218  if (!a_farm->FA_PK(a_field, 0.0, g_date->Date() + 10 - g_date->DayInYear())) {
219  SimpleEvent_(g_date->Date() + 1, pl_fl2_ferti_s1A, true, a_farm, a_field);
220  break;
221  }
222  }
223  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 7), pl_fl2_cut_to_silage2A, false, a_farm, a_field);
224  break;
226  if (!a_farm->CutToSilage(a_field, 0.0, g_date->DayInYear(5, 8) - g_date->DayInYear())) {
227  SimpleEvent_(g_date->Date() + 1, pl_fl2_cut_to_silage2A, true, a_farm, a_field);
228  break;
229  }
230  SimpleEvent_(g_date->Date() + 1, pl_fl2_harrow2A, false, a_farm, a_field);
231  break;
232  case pl_fl2_harrow2A:
233  if (a_ev->m_lock || a_farm->DoIt(25))
234  {
235  if (!a_farm->ShallowHarrow(a_field, 0.0, g_date->DayInYear(5, 8) - g_date->DayInYear())) {
236  SimpleEvent_(g_date->Date() + 1, pl_fl2_harrow2A, true, a_farm, a_field);
237  break;
238  }
239  }
240  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 9), pl_fl2_cut_to_silage3A, false, a_farm, a_field);
241  break;
243  if (!a_farm->CutToSilage(a_field, 0.0, g_date->DayInYear(25, 9) - g_date->DayInYear())) {
244  SimpleEvent_(g_date->Date() + 1, pl_fl2_cut_to_silage3A, true, a_farm, a_field);
245  break;
246  }
247  done = true;
248  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
249  // END of MAIN THREAD
250  break;
252  // Here comes cutting with 4 cutting events
253  if (!a_farm->CutToSilage(a_field, 0.0, g_date->DayInYear(5, 6) - g_date->DayInYear())) {
254  SimpleEvent_(g_date->Date() + 1, pl_fl2_cut_to_silage1B, true, a_farm, a_field);
255  break;
256  }
257  SimpleEvent_(g_date->Date() + 1, pl_fl2_harrow1B, false, a_farm, a_field);
258  break;
259  case pl_fl2_harrow1B:
260  if (a_ev->m_lock || a_farm->DoIt(33))
261  {
262  if (!a_farm->ShallowHarrow(a_field, 0.0, g_date->DayInYear(5, 6) - g_date->DayInYear())) {
263  SimpleEvent_(g_date->Date() + 1, pl_fl2_harrow1B, true, a_farm, a_field);
264  break;
265  }
266  }
267  if (a_farm->IsStockFarmer()) //Stock Farmer
268  {
269  SimpleEvent_(g_date->Date() + 1, pl_fl2_ferti_s1B, false, a_farm, a_field);
270  }
271  else SimpleEvent_(g_date->Date() + 1, pl_fl2_ferti_p1B, false, a_farm, a_field);
272  break;
273  case pl_fl2_ferti_p1B:
274  if (a_ev->m_lock || a_farm->DoIt(60))
275  {
276  if (!a_farm->FP_PK(a_field, 0.0, g_date->Date() + 10 - g_date->DayInYear())) {
277  SimpleEvent_(g_date->Date() + 1, pl_fl2_ferti_p1B, true, a_farm, a_field);
278  break;
279  }
280  }
281  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 7), pl_fl2_cut_to_silage2B, false, a_farm, a_field);
282  break;
283  case pl_fl2_ferti_s1B:
284  if (a_ev->m_lock || a_farm->DoIt(60))
285  {
286  if (!a_farm->FA_PK(a_field, 0.0, g_date->Date() + 10 - g_date->DayInYear())) {
287  SimpleEvent_(g_date->Date() + 1, pl_fl2_ferti_s1B, true, a_farm, a_field);
288  break;
289  }
290  }
291  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 7), pl_fl2_cut_to_silage2B, false, a_farm, a_field);
292  break;
294  if (!a_farm->CutToSilage(a_field, 0.0, g_date->DayInYear(15, 7) - g_date->DayInYear())) {
295  SimpleEvent_(g_date->Date() + 1, pl_fl2_cut_to_silage2B, true, a_farm, a_field);
296  break;
297  }
298  SimpleEvent_(g_date->Date() + 1, pl_fl2_harrow2B, false, a_farm, a_field);
299  break;
300  case pl_fl2_harrow2B:
301  if (a_ev->m_lock || a_farm->DoIt(25))
302  {
303  if (!a_farm->ShallowHarrow(a_field, 0.0, g_date->DayInYear(15, 7) - g_date->DayInYear())) {
304  SimpleEvent_(g_date->Date() + 1, pl_fl2_harrow2B, true, a_farm, a_field);
305  break;
306  }
307  }
308  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 8), pl_fl2_cut_to_silage3B, false, a_farm, a_field);
309  break;
311  if (!a_farm->CutToSilage(a_field, 0.0, g_date->DayInYear(25, 8) - g_date->DayInYear())) {
312  SimpleEvent_(g_date->Date() + 1, pl_fl2_cut_to_silage3B, true, a_farm, a_field);
313  break;
314  }
315  SimpleEvent_(g_date->Date() + 1, pl_fl2_harrow3B, false, a_farm, a_field);
316  break;
317 
318 
319  case pl_fl2_harrow3B:
320  if (a_ev->m_lock || a_farm->DoIt(25))
321  {
322  if (!a_farm->ShallowHarrow(a_field, 0.0, g_date->DayInYear(25, 8) - g_date->DayInYear())) {
323  SimpleEvent_(g_date->Date() + 1, pl_fl2_harrow3B, true, a_farm, a_field);
324  break;
325  }
326  }
327  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 9), pl_fl2_cut_to_silage4B, false, a_farm, a_field);
328  break;
330  if (!a_farm->CutToSilage(a_field, 0.0, g_date->DayInYear(5, 10) - g_date->DayInYear())) {
331  SimpleEvent_(g_date->Date() + 1, pl_fl2_cut_to_silage4B, true, a_farm, a_field);
332  break;
333  }
334  done = true;
335  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
336  // END of MAIN THREAD
337  break;
338  default:
339  g_msg->Warn(WARN_BUG, "PLFodderLucerne2::Do(): "
340  "Unknown event type! ", "");
341  exit(1);
342  }
343  return done;
344 }

References Landscape::BackTranslateVegTypes(), Farm::DoIt(), Farm::FP_PK(), g_landscape_p, Farm::GetType(), Farm::IsStockFarmer(), Crop::m_first_date, FarmEvent::m_first_year, FarmEvent::m_lock, FarmEvent::m_next_tov, FarmEvent::m_startday, FarmEvent::m_todo, pl_fl2_cut_to_silage1A, pl_fl2_cut_to_silage1B, pl_fl2_cut_to_silage2A, pl_fl2_cut_to_silage2B, pl_fl2_cut_to_silage3A, pl_fl2_cut_to_silage3B, pl_fl2_cut_to_silage4B, pl_fl2_ferti_p0, pl_fl2_ferti_p1A, pl_fl2_ferti_p1B, pl_fl2_ferti_s0, pl_fl2_ferti_s1A, pl_fl2_ferti_s1B, pl_fl2_harrow1A, pl_fl2_harrow1B, pl_fl2_harrow2A, pl_fl2_harrow2B, pl_fl2_harrow3B, pl_fl2_herbicide1, pl_fl2_spring_harrow, pl_fl2_start, Farm::ShallowHarrow(), Crop::SimpleEvent_(), and tof_OptimisingFarm.


The documentation for this class was generated from the following files:
pl_fl2_cut_to_silage3A
Definition: PLFodderLucerne2.h:44
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
pl_fl2_harrow1B
Definition: PLFodderLucerne2.h:46
pl_fl2_harrow2B
Definition: PLFodderLucerne2.h:50
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
pl_fl2_ferti_p1B
Definition: PLFodderLucerne2.h:47
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
pl_fl2_spring_harrow
Definition: PLFodderLucerne2.h:34
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
pl_fl2_cut_to_silage2A
Definition: PLFodderLucerne2.h:42
pl_fl2_start
Definition: PLFodderLucerne2.h:32
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
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:653
pl_fl2_cut_to_silage4B
Definition: PLFodderLucerne2.h:53
pl_fl2_ferti_p1A
Definition: PLFodderLucerne2.h:40
pl_fl2_cut_to_silage1B
Definition: PLFodderLucerne2.h:45
pl_fl2_harrow2A
Definition: PLFodderLucerne2.h:43
pl_fl2_ferti_p0
Definition: PLFodderLucerne2.h:35
pl_fl2_ferti_s1B
Definition: PLFodderLucerne2.h:48
pl_fl2_harrow3B
Definition: PLFodderLucerne2.h:52
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
pl_fl2_ferti_s0
Definition: PLFodderLucerne2.h:36
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
Farm::ShallowHarrow
virtual bool ShallowHarrow(LE *a_field, double a_user, int a_days)
Carry out a shallow harrow event on a_field, e.g., after grass cutting event.
Definition: farmfuncs.cpp:498
pl_fl2_cut_to_silage2B
Definition: PLFodderLucerne2.h:49
pl_fl2_ferti_s1A
Definition: PLFodderLucerne2.h:41
pl_fl2_harrow1A
Definition: PLFodderLucerne2.h:39
pl_fl2_cut_to_silage1A
Definition: PLFodderLucerne2.h:38
pl_fl2_herbicide1
Definition: PLFodderLucerne2.h:37
pl_fl2_cut_to_silage3B
Definition: PLFodderLucerne2.h:51
g_landscape_p
Landscape * g_landscape_p
Definition: Landscape.cpp:258
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:312