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

PLMaizeSilage class
. More...

#include <PLMaizeSilage.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...
 
 PLMaizeSilage ()
 
- 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

PLMaizeSilage class
.

See PLMaizeSilage.h::PLMaizeSilageToDo for a complete list of all possible events triggered codes by the maize 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

◆ PLMaizeSilage()

PLMaizeSilage::PLMaizeSilage ( )
inline
99  {
100  // When we start it off, the first possible date for a farm operation is 5th November
101  // This information is used by other crops when they decide how much post processing of
102  // the management is allowed after harvest before the next crop starts.
103  m_first_date=g_date->DayInYear( 5,11 );
104  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

bool PLMaizeSilage::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 maizesilage.

Reimplemented from Crop.

65 {
66  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
67  int d1 = 0;
68  // Depending what event has occured jump to the correct bit of code
69  switch (a_ev->m_todo)
70  {
71  case pl_ms_start:
72  {
73  // pl_ms_start just sets up all the starting conditions and reference dates that are needed to start a pl_m
74  PL_MS_FERTI_P1 = false;
75  PL_MS_FERTI_S1 = false;
76  PL_MS_STUBBLE_PLOUGH = false;
77  PL_MS_WINTER_PLOUGH = false;
78  PL_MS_FERTI_P3 = false;
79  PL_MS_FERTI_S3 = false;
81  PL_MS_START_FERTI = false;
82 
83  // Set up the date management stuff
84  // The next bit of code just allows for altering dates after harvest if it is necessary
85  // to allow for a crop which starts its management early.
86 
87  // 5 start and stop dates for all 'movable' events for this crop
88  int noDates = 4;
89  a_field->SetMDates(0, 0, g_date->DayInYear(30, 9)); // last possible day of harvest
90  a_field->SetMDates(1, 0, g_date->DayInYear(5, 10)); // last possible day of starw chopping, equal to harvest in this case
91  a_field->SetMDates(0, 1, 0); // start day of hay bailing (not used as it depend on previous treatment)
92  a_field->SetMDates(1, 1, g_date->DayInYear(10, 10)); // end day of hay bailing
93  a_field->SetMDates(0, 2, 0); // start day of RSM
94  a_field->SetMDates(1, 2, g_date->DayInYear(10, 10)); // end day of RSM
95  a_field->SetMDates(0, 3, 0); // start day of calcium application
96  a_field->SetMDates(1, 3, g_date->DayInYear(10, 10)); // end day of calcium application
97  // Can be up to 10 of these. If the shortening code is triggered
98  // then these will be reduced in value to 0
99 
100  a_field->SetMConstants(0, 1);
101 
102  // Check the next crop for early start, unless it is a spring crop
103  // in which case we ASSUME that no checking is necessary!!!!
104  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
105 
106  //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)
107  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
108  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
109 
110  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
111  if (a_field->GetMDates(0, 0) >= a_ev->m_startday)
112  {
113  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): ", "Harvest too late for the next crop to start!!!");
114  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
115  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
116  }
117  // Now fix any late finishing problems
118  for (int i = 0; i < noDates; i++) {
119  if (a_field->GetMDates(0, i) >= a_ev->m_startday) {
120  a_field->SetMDates(0, i, a_ev->m_startday - 1); //move the starting date
121  }
122  if (a_field->GetMDates(1, i) >= a_ev->m_startday) {
123  a_field->SetMConstants(i, 0); //change the default value of the MConst (=1) to 0 (necessary to correctly execute farm events in case the finishing date (MDate) was moved)
124  a_field->SetMDates(1, i, a_ev->m_startday - 1); //move the finishing date
125  }
126  }
127  }
128  // Now no operations can be timed after the start of the next crop.
129 
130  if (!a_ev->m_first_year) {
131  // Are we before July 1st?
132  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
133  if (g_date->Date() < d1) {
134  // Yes, too early. We assumme this is because the last crop was late
135  printf("Poly: %d\n", a_field->GetPoly());
136  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): ", "Crop start attempt between 1st Jan & 1st July");
137  int prev = g_landscape_p->BackTranslateVegTypes(a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex()));
138  g_msg->Warn(WARN_BUG, "Previous Crop ", prev);
139  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
140  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
141  }
142  else {
143  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
144  if (g_date->Date() > d1) {
145  // Yes too late - should not happen - raise an error
146  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): ", "Crop start attempt after last possible start date");
147  g_msg->Warn(WARN_BUG, "Previous Crop ", "");
148  a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex());
149  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
150  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
151  }
152  }
153  }
154  else {
155  // Is the first year
156  // Some special code to cope with that first start-up year in ALMaSS - ignore for all practical purposes
157  // Code for first spring treatment used
158  if (a_farm->IsStockFarmer()) //Stock Farmer
159  {
160  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 3), pl_ms_ferti_s3, false, a_farm, a_field);
161  }
162  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 3), pl_ms_ferti_p3, false, a_farm, a_field);
163  break;
164  }
165  }//if
166 
167  // End single block date checking code. Please see next line comment as well.
168  // Reinit d1 to first possible starting date.
169  d1 = g_date->OldDays() + g_date->DayInYear(20, 7);
170  // OK, let's go.
171  // Here we queue up the first event - this differs depending on whether we have a
172  // stock or arable farmer
173  if (a_farm->IsStockFarmer()) { // StockFarmer
174  SimpleEvent_(d1, pl_ms_ferti_s1, false, a_farm, a_field);
175  }
176  else SimpleEvent_(d1, pl_ms_ferti_p1, false, a_farm, a_field);
177  }
178  break;
179 
180  // This is the first real farm operation
181  case pl_ms_ferti_p1:
182  // In total 10% of arable farmers do slurry in the autumn, either before stubble plough/harrow or later before autumn plough/cultivation
183  // We therefore assume that half of them (5%) do it now
184  if (a_ev->m_lock || a_farm->DoIt(5))
185  {
186  if (!a_farm->FP_Slurry(a_field, 0.0, g_date->DayInYear(5, 11) - g_date->DayInYear())) {
187  // If we don't suceed on the first try, then try and try again (until 20/8 when we will suceed)
188  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_p1, true, a_farm, a_field);
189  break;
190  }
191  else
192  {
193  //Rest of farmers do slurry before autumn plough/stubble cultivation so we need to remeber who already did it
194  PL_MS_FERTI_P1 = true;
195  }
196  }
197  // Queue up the next event -in this case stubble ploughing
198  SimpleEvent_(g_date->Date() + 1, pl_ms_stubble_plough, false, a_farm, a_field);
199  break;
200  case pl_ms_ferti_s1:
201  // In total 80% of stock farmers do slurry in the autumn, either before stubble plough/harrow or later before autumn plough/cultivation
202  // We therefore assume that half of them (40%) do it now
203  if (a_ev->m_lock || a_farm->DoIt(40))
204  {
205  if (!a_farm->FA_Slurry(a_field, 0.0, g_date->DayInYear(5, 11) - g_date->DayInYear())) {
206  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_s1, true, a_farm, a_field);
207  break;
208  }
209  else
210  {
211  //Rest of farmers do slurry before autumn plough/stubble cultivation so we need to remeber who already did it
212  PL_MS_FERTI_S1 = true;
213  }
214  }
215  // Queue up the next event -in this case stubble ploughing
216  SimpleEvent_(g_date->Date() + 1, pl_ms_stubble_plough, false, a_farm, a_field);
217  break;
219  // 20% will do stubble plough, but rest will get away with non-inversion cultivation
220  if (a_ev->m_lock || a_farm->DoIt(43))
221  {
222  if (!a_farm->StubblePlough(a_field, 0.0, g_date->DayInYear(5, 11) - g_date->DayInYear())) {
223  SimpleEvent_(g_date->Date() + 1, pl_ms_stubble_plough, true, a_farm, a_field);
224  break;
225  }
226  else
227  {
228  // 20% of farmers will do this, but the other 80% won't so we need to remember whether we are in one or the other group
229  PL_MS_STUBBLE_PLOUGH = true;
230  // Queue up the next event
231  SimpleEvent_(g_date->Date() + 1, pl_ms_autumn_harrow1, false, a_farm, a_field);
232  break;
233  }
234  }
235  SimpleEvent_(g_date->Date() + 1, pl_ms_stubble_harrow, false, a_farm, a_field);
236  break;
238  if (!a_farm->AutumnHarrow(a_field, 0.0, g_date->DayInYear(5, 11) - g_date->DayInYear())) {
239  SimpleEvent_(g_date->Date() + 1, pl_ms_autumn_harrow1, true, a_farm, a_field);
240  break;
241  }
242  SimpleEvent_(g_date->Date() + 2, pl_ms_autumn_harrow2, false, a_farm, a_field);
243  break;
245  if (a_ev->m_lock || a_farm->DoIt(40))
246  {
247  if (!a_farm->AutumnHarrow(a_field, 0.0, g_date->Date() + 7 - g_date->DayInYear())) {
248  SimpleEvent_(g_date->Date() + 1, pl_ms_autumn_harrow2, true, a_farm, a_field);
249  break;
250  }
251  }
252  d1 = g_date->Date() + 1;
253  if (d1 < g_date->OldDays() + g_date->DayInYear(10, 9)) {
254  d1 = g_date->OldDays() + g_date->DayInYear(10, 9);
255  }
256  if (a_farm->IsStockFarmer()) //Stock Farmer
257  {
258  SimpleEvent_(d1, pl_ms_ferti_s2, false, a_farm, a_field);
259  }
260  else SimpleEvent_(d1, pl_ms_ferti_p2, false, a_farm, a_field);
261  break;
263  if (!a_farm->StubbleHarrowing(a_field, 0.0, g_date->DayInYear(10, 11) - g_date->DayInYear())) {
264  SimpleEvent_(g_date->Date() + 1, pl_ms_stubble_harrow, true, a_farm, a_field);
265  break;
266  }
267  d1 = g_date->Date() + 1;
268  if (d1 < g_date->OldDays() + g_date->DayInYear(10, 9)) {
269  d1 = g_date->OldDays() + g_date->DayInYear(10, 9);
270  }
271  if (a_farm->IsStockFarmer()) //Stock Farmer
272  {
273  SimpleEvent_(d1, pl_ms_ferti_s2, false, a_farm, a_field);
274  }
275  else SimpleEvent_(d1, pl_ms_ferti_p2, false, a_farm, a_field);
276  break;
277  case pl_ms_ferti_p2:
278  // In total 10% of arable farmers do slurry in the autumn, either before stubble plough/harrow or later before autumn plough/cultivation
279  // We therefore assume that half of them (5%) do it now (if haven't done before)
280  if ((a_ev->m_lock || a_farm->DoIt(static_cast<int>((5.0/95.0)*100)))&&(PL_MS_FERTI_P1==false))
281  {
282  if (!a_farm->FP_Slurry(a_field, 0.0, g_date->DayInYear(15, 11) - g_date->DayInYear())) {
283  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_p2, true, a_farm, a_field);
284  break;
285  }
286  }
287  SimpleEvent_(g_date->Date() + 1, pl_ms_winter_plough, false, a_farm, a_field);
288  break;
289  case pl_ms_ferti_s2:
290  // In total 80% of stock farmers do slurry in the autumn, either before stubble plough/harrow or later before autumn plough/cultivation
291  // We therefore assume that half of them (40%) do it now (if haven't done before)
292  if ((a_ev->m_lock || a_farm->DoIt(static_cast<int>((40.0/60.0)*100))) && (PL_MS_FERTI_S1==false))
293  {
294  if (!a_farm->FA_Slurry(a_field, 0.0, g_date->DayInYear(15, 11) - g_date->DayInYear())) {
295  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_s2, true, a_farm, a_field);
296  break;
297  }
298  }
299  SimpleEvent_(g_date->Date() + 1, pl_ms_winter_plough, false, a_farm, a_field);
300  break;
301  case pl_ms_winter_plough:
302  // 73% will do winter plough, but rest will get away with non-inversion cultivation
303  if (a_ev->m_lock || a_farm->DoIt(73))
304  {
305  if (!a_farm->WinterPlough(a_field, 0.0, g_date->DayInYear(15, 11) - g_date->DayInYear())) {
306  SimpleEvent_(g_date->Date() + 1, pl_ms_winter_plough, true, a_farm, a_field);
307  break;
308  }
309  else
310  {
311  // 20% of farmers will do this, but the other 80% won't so we need to remember whether we are in one or the other group
312  PL_MS_WINTER_PLOUGH = true;
313  // Queue up the next event
314  if (a_farm->IsStockFarmer()) //Stock Farmer
315  {
316  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 3) + 365, pl_ms_ferti_s3, false, a_farm, a_field);
317  }
318  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 3) + 365, pl_ms_ferti_p3, false, a_farm, a_field);
319  break;
320  }
321  }
322  SimpleEvent_(g_date->Date() + 1, pl_ms_winter_stubble_cultivator_heavy, false, a_farm, a_field);
323  break;
325  // the rest 20% who did not plough do heavy stubble cultivation
326  if (!a_farm->StubbleCultivatorHeavy(a_field, 0.0, g_date->DayInYear(15, 11) - g_date->DayInYear())) {
327  SimpleEvent_(g_date->Date() + 1, pl_ms_winter_stubble_cultivator_heavy, true, a_farm, a_field);
328  break;
329  }
330  if (a_farm->IsStockFarmer()) //Stock Farmer
331  {
332  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 3) + 365, pl_ms_ferti_s3, false, a_farm, a_field);
333  }
334  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 3) + 365, pl_ms_ferti_p3, false, a_farm, a_field);
335  break;
336  case pl_ms_ferti_p3:
337  if (a_ev->m_lock || a_farm->DoIt(58))
338  {
339  if (!a_farm->FP_Slurry(a_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
340  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_p3, true, a_farm, a_field);
341  break;
342  }
343  else
344  {
345  //All farmers who do spring slurry have to do harrow
346  PL_MS_FERTI_P3 = true;
347  }
348  }
349  SimpleEvent_(g_date->Date() + 1, pl_ms_spring_harrow, false, a_farm, a_field);
350  break;
351  case pl_ms_ferti_s3:
352  if (a_ev->m_lock || a_farm->DoIt(58))
353  {
354  if (!a_farm->FA_Slurry(a_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
355  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_s3, true, a_farm, a_field);
356  break;
357  }
358  else
359  {
360  //All farmers who do spring slurry have to do harrow
361  PL_MS_FERTI_S3 = true;
362  }
363  }
364  SimpleEvent_(g_date->Date() + 1, pl_ms_spring_harrow, false, a_farm, a_field);
365  break;
366  case pl_ms_spring_harrow:
367  if ((a_ev->m_lock) || (PL_MS_FERTI_P3) || (PL_MS_FERTI_S3) || (a_farm->DoIt(83)))
368  {
369  if (!a_farm->SpringHarrow(a_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
370  SimpleEvent_(g_date->Date() + 1, pl_ms_spring_harrow, true, a_farm, a_field);
371  break;
372  }
373  }
374  d1 = g_date->Date() + 1;
375  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 4)) {
376  d1 = g_date->OldDays() + g_date->DayInYear(1, 4);
377  }
378  if (a_farm->IsStockFarmer()) //Stock Farmer
379  {
380  SimpleEvent_(d1, pl_ms_ferti_s4, false, a_farm, a_field);
381  }
382  else SimpleEvent_(d1, pl_ms_ferti_p4, false, a_farm, a_field);
383  break;
384  case pl_ms_ferti_p4:
385  if (a_ev->m_lock || a_farm->DoIt(95))
386  {
387  if (!a_farm->FP_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
388  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_p4, true, a_farm, a_field);
389  break;
390  }
391  PL_MS_SPRING_FERTI = true;
392  }
393  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_p5, false, a_farm, a_field);
394  break;
395  case pl_ms_ferti_s4:
396  if (a_ev->m_lock || a_farm->DoIt(95))
397  {
398  if (!a_farm->FA_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
399  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_s4, true, a_farm, a_field);
400  break;
401  }
402  PL_MS_SPRING_FERTI = true;
403  }
404  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_s5, false, a_farm, a_field);
405  break;
406  case pl_ms_ferti_p5:
407  if (a_ev->m_lock || a_farm->DoIt(75))
408  {
409  if (!a_farm->FP_PK(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
410  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_p5, true, a_farm, a_field);
411  break;
412  }
413  PL_MS_SPRING_FERTI = true;
414  }
415  SimpleEvent_(g_date->Date() + 1, pl_ms_heavy_cultivator, false, a_farm, a_field);
416  break;
417  case pl_ms_ferti_s5:
418  if (a_ev->m_lock || a_farm->DoIt(75))
419  {
420  if (!a_farm->FA_PK(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
421  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_s5, true, a_farm, a_field);
422  break;
423  }
424  PL_MS_SPRING_FERTI = 1;
425  }
426  SimpleEvent_(g_date->Date() + 1, pl_ms_heavy_cultivator, false, a_farm, a_field);
427  break;
429  if (PL_MS_SPRING_FERTI == 1)
430  {
431  if (!a_farm->HeavyCultivatorAggregate(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
432  SimpleEvent_(g_date->Date() + 1, pl_ms_heavy_cultivator, true, a_farm, a_field);
433  break;
434  }
435  }
436  d1 = g_date->Date() + 1;
437  if (d1 < g_date->OldDays() + g_date->DayInYear(15, 4)) {
438  d1 = g_date->OldDays() + g_date->DayInYear(15, 4);
439  }
440  SimpleEvent_(d1, pl_ms_preseeding_cultivator, false, a_farm, a_field);
441  break;
443  if (a_ev->m_lock || a_farm->DoIt(99))
444  {
445  if (!a_farm->PreseedingCultivator(a_field, 0.0, g_date->DayInYear(4, 5) - g_date->DayInYear())) {
446  SimpleEvent_(g_date->Date() + 1, pl_ms_preseeding_cultivator, true, a_farm, a_field);
447  break;
448  }
449  }
450  SimpleEvent_(g_date->Date() + 1, pl_ms_spring_sow_with_ferti, false, a_farm, a_field);
451  break;
453  // 88% will do sow with firtilizer
454  if (a_ev->m_lock || a_farm->DoIt(88))
455  {
456  if (!a_farm->SpringSowWithFerti(a_field, 0.0, g_date->DayInYear(5, 5) - g_date->DayInYear())) {
457  SimpleEvent_(g_date->Date() + 1, pl_ms_spring_sow_with_ferti, true, a_farm, a_field);
458  break;
459  }
460  else
461  {
462  // 88% of farmers will do this, but the other 12% won't so we need to remember whether we are in one or the other group
463  PL_MS_START_FERTI = true;
464  // Here is a fork leading to parallel events
465  SimpleEvent_(g_date->Date() + 1, pl_ms_herbicide1, false, a_farm, a_field); // Herbidide thread
466  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 6), pl_ms_fungicide1, false, a_farm, a_field); // Fungicide thread
467  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_ms_insecticide1, false, a_farm, a_field); // Insecticide thread = MAIN THREAD
468  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(5, 6), pl_ms_biocide, false, a_farm, a_field); // Biocide thread
469  if (a_farm->IsStockFarmer()) //Stock Farmer // N thread
470  {
471  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_ms_ferti_s6, false, a_farm, a_field);
472  }
473  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_ms_ferti_p6, false, a_farm, a_field);
474  if (a_farm->IsStockFarmer()) //Stock Farmer // Microelemnts thread
475  {
476  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_ms_ferti_s7, false, a_farm, a_field);
477  }
478  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_ms_ferti_p7, false, a_farm, a_field);
479  break;
480  }
481  }
482  SimpleEvent_(g_date->Date() + 1, pl_ms_spring_sow, false, a_farm, a_field);
483  break;
484  case pl_ms_spring_sow:
485  if (!a_farm->SpringSow(a_field, 0.0, g_date->DayInYear(5, 5) - g_date->DayInYear())) {
486  SimpleEvent_(g_date->Date() + 1, pl_ms_spring_sow, true, a_farm, a_field);
487  break;
488  }
489  // Here is a fork leading to parallel events
490  SimpleEvent_(g_date->Date() + 1, pl_ms_herbicide1, false, a_farm, a_field); // Herbidide thread
491  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 6), pl_ms_fungicide1, false, a_farm, a_field); // Fungicide thread
492  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_ms_insecticide1, false, a_farm, a_field); // Insecticide thread = MAIN THREAD
493  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(5, 6), pl_ms_biocide, false, a_farm, a_field); // Biocide thread
494  if (a_farm->IsStockFarmer()) //Stock Farmer // N thread
495  {
496  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_ms_ferti_s6, false, a_farm, a_field);
497  }
498  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_ms_ferti_p6, false, a_farm, a_field);
499  if (a_farm->IsStockFarmer()) //Stock Farmer // Microelemnts thread
500  {
501  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_ms_ferti_s7, false, a_farm, a_field);
502  }
503  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_ms_ferti_p7, false, a_farm, a_field);
504  break;
505  case pl_ms_ferti_p6:
506  // Here comes N thread
507  if (a_ev->m_lock || a_farm->DoIt(58))
508  {
509  if (!a_farm->FP_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
510  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_p6, true, a_farm, a_field);
511  break;
512  }
513  }
514  // End of thread
515  break;
516  case pl_ms_ferti_s6:
517  if (a_ev->m_lock || a_farm->DoIt(58))
518  {
519  if (!a_farm->FA_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
520  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_s6, true, a_farm, a_field);
521  break;
522  }
523  }
524  // End of thread
525  break;
526  case pl_ms_ferti_p7:
527  // Here comes the mickroelements thread
528  if (a_ev->m_lock || a_farm->DoIt(75))
529  {
530  if (!a_farm->FP_ManganeseSulphate(a_field, 0.0, g_date->DayInYear(25, 6) - g_date->DayInYear())) {
531  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_p7, true, a_farm, a_field);
532  break;
533  }
534  }
535  // End of thread
536  break;
537  case pl_ms_ferti_s7:
538  if (a_ev->m_lock || a_farm->DoIt(75))
539  {
540  if (!a_farm->FA_ManganeseSulphate(a_field, 0.0, g_date->DayInYear(25, 6) - g_date->DayInYear())) {
541  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_s7, true, a_farm, a_field);
542  break;
543  }
544  }
545  // End of thread
546  break;
547  case pl_ms_herbicide1: // The first of the pesticide managements.
548  // Here comes the herbicide thread
549  if (a_ev->m_lock || a_farm->DoIt(78))
550  {
551  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->Date() + 15 - g_date->DayInYear())) {
552  SimpleEvent_(g_date->Date() + 1, pl_ms_herbicide1, true, a_farm, a_field);
553  break;
554  }
555  }
556  SimpleEvent_(g_date->Date() + 10, pl_ms_herbicide2, false, a_farm, a_field);
557  break;
558  case pl_ms_herbicide2: // The first of the pesticide managements.
559  // Here comes the herbicide thread
560  if (a_ev->m_lock || a_farm->DoIt(58))
561  {
562  if (a_field->GetGreenBiomass() <= 0) { // spraying should be after the rape emergence
563  SimpleEvent_(g_date->Date() + 1, pl_ms_herbicide2, true, a_farm, a_field);
564  break;
565  }
566  else
567  {
568  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
569  SimpleEvent_(g_date->Date() + 1, pl_ms_herbicide2, true, a_farm, a_field);
570  break;
571  }
572  }
573  }
574  // End of thread
575  break;
576  case pl_ms_fungicide1:
577  // Here comes the fungicide thread
578  if (a_ev->m_lock || a_farm->DoIt(23))
579  {
580  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(25, 6) - g_date->DayInYear())) {
581  SimpleEvent_(g_date->Date() + 1, pl_ms_fungicide1, true, a_farm, a_field);
582  break;
583  }
584  }
585  // End of thread
586  break;
587  case pl_ms_insecticide1:
588  // Here comes the insecticide thread = MAIN THREAD
589  if (a_ev->m_lock || a_farm->DoIt(3))
590  {
591  // here we check wheter we are using ERA pesticide or not
592  if (!cfg_pest_springwheat_on.value() ||
593  !g_landscape_p->SupplyShouldSpray()) // Not using pesticide spray
594  {
595  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
596  SimpleEvent_(g_date->Date() + 1, pl_ms_insecticide1, true, a_farm, a_field);
597  break;
598  }
599  }
600  else {
601  a_farm->ProductApplication(a_field, 0.0, 0, cfg_pest_product_1_amount.value(), ppp_1);
602  }
603  }
604  d1 = g_date->Date() + 14;
605  if (d1 < g_date->OldDays() + g_date->DayInYear(5, 6)) {
606  d1 = g_date->OldDays() + g_date->DayInYear(5, 6);
607  }
608  SimpleEvent_(d1, pl_ms_insecticide2, false, a_farm, a_field);
609  break;
610  case pl_ms_insecticide2:
611  if (a_ev->m_lock || a_farm->DoIt(20))
612  {
613  // here we check wheter we are using ERA pesticide or not
614  if (!cfg_pest_springwheat_on.value() ||
615  !g_landscape_p->SupplyShouldSpray()) // Not using pesticide spray
616  {
617  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(15, 7) - g_date->DayInYear())) {
618  SimpleEvent_(g_date->Date() + 1, pl_ms_insecticide2, true, a_farm, a_field);
619  break;
620  }
621  }
622  else {
623  a_farm->ProductApplication(a_field, 0.0, 0, cfg_pest_product_1_amount.value(), ppp_1);
624  }
625  }
626  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 9), pl_ms_harvest, false, a_farm, a_field);
627  break;
628 
629 
630  case pl_ms_biocide:
631  // Here comes the biocide thread
632  if (a_ev->m_lock || a_farm->DoIt(8))
633  {
634  if (!a_farm->Biocide(a_field, 0.0, g_date->DayInYear(15, 7) - g_date->DayInYear())) {
635  SimpleEvent_(g_date->Date() + 1, pl_ms_biocide, true, a_farm, a_field);
636  break;
637  }
638  }
639  // End of thread
640  break;
641 
642 
643  case pl_ms_harvest:
644  // Here the MAIN thread continues
645  // We don't move harvest days
646  if (!a_farm->Harvest(a_field, 0.0, a_field->GetMDates(0, 0) - g_date->DayInYear())) {
647  SimpleEvent_(g_date->Date() + 1, pl_ms_harvest, true, a_farm, a_field);
648  break;
649  }
650  SimpleEvent_(g_date->Date() + 1, pl_ms_straw_chopping, false, a_farm, a_field);
651  break;
653  if (a_farm->IsStockFarmer()) //Stock Farmer
654  {
655  // 10% of stock farmers will do straw chopping, but rest will do hay bailing instead
656  if (a_ev->m_lock || a_farm->DoIt(10))
657  {
658  if (a_field->GetMConstants(0) == 0) {
659  if (!a_farm->StrawChopping(a_field, 0.0, -1)) { // raise an error
660  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): failure in 'StrawChopping' execution", "");
661  exit(1);
662  }
663  }
664  else {
665  if (!a_farm->StrawChopping(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
666  SimpleEvent_(g_date->Date() + 1, pl_ms_straw_chopping, true, a_farm, a_field);
667  break;
668  }
669  else
670  {
671  // Queue up the next event
672  SimpleEvent_(g_date->Date(), pl_ms_ferti_s8, false, a_farm, a_field);
673  break;
674  }
675  }
676 
677  }
678  SimpleEvent_(g_date->Date() + 1, pl_ms_hay_bailing, false, a_farm, a_field);
679  break;
680  }
681  else
682  {
683  // 90% of arable farmers will do straw chopping, but rest will do hay bailing instead
684  if (a_ev->m_lock || a_farm->DoIt(90))
685  {
686  if (a_field->GetMConstants(0) == 0) {
687  if (!a_farm->StrawChopping(a_field, 0.0, -1)) { // raise an error
688  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): failure in 'StrawChopping' execution", "");
689  exit(1);
690  }
691  }
692  else {
693  if (!a_farm->StrawChopping(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
694  SimpleEvent_(g_date->Date() + 1, pl_ms_straw_chopping, true, a_farm, a_field);
695  break;
696  }
697  else
698  {
699  // Queue up the next event
700  SimpleEvent_(g_date->Date(), pl_ms_ferti_p8, false, a_farm, a_field);
701  break;
702  }
703  }
704 
705  }
706  SimpleEvent_(g_date->Date() + 1, pl_ms_hay_bailing, false, a_farm, a_field);
707  break;
708  }
709  case pl_ms_hay_bailing:
710  if (a_field->GetMConstants(1) == 0) {
711  if (!a_farm->HayBailing(a_field, 0.0, -1)) { // raise an error
712  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): failure in 'HayBailing' execution", "");
713  exit(1);
714  }
715  }
716  else {
717  if (!a_farm->HayBailing(a_field, 0.0, a_field->GetMDates(1, 1) - g_date->DayInYear())) {
718  SimpleEvent_(g_date->Date() + 1, pl_ms_hay_bailing, true, a_farm, a_field);
719  break;
720  }
721  }
722  if (a_farm->IsStockFarmer()) //Stock Farmer
723  {
724  SimpleEvent_(g_date->Date(), pl_ms_ferti_s9, false, a_farm, a_field);
725  }
726  else SimpleEvent_(g_date->Date(), pl_ms_ferti_p9, false, a_farm, a_field);
727  break;
728  case pl_ms_ferti_p8:
729  if (a_ev->m_lock || a_farm->DoIt(38))
730  {
731  if (a_field->GetMConstants(2) == 0) {
732  if (!a_farm->FP_RSM(a_field, 0.0, -1)) { // raise an error
733  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): failure in 'FP_RSM' execution", "");
734  exit(1);
735  }
736  }
737  else {
738  if (!a_farm->FP_RSM(a_field, 0.0, a_field->GetMDates(1, 2) - g_date->DayInYear())) {
739  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_p8, true, a_farm, a_field);
740  break;
741  }
742  }
743  }
744  if (a_farm->IsStockFarmer()) //Stock Farmer
745  {
746  SimpleEvent_(g_date->Date(), pl_ms_ferti_s9, false, a_farm, a_field);
747  }
748  else SimpleEvent_(g_date->Date(), pl_ms_ferti_p9, false, a_farm, a_field);
749  break;
750  case pl_ms_ferti_s8:
751  if (a_ev->m_lock || a_farm->DoIt(38))
752  {
753  if (a_field->GetMConstants(2) == 0) {
754  if (!a_farm->FA_RSM(a_field, 0.0, -1)) { // raise an error
755  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): failure in 'FA_RSM' execution", "");
756  exit(1);
757  }
758  }
759  else {
760  if (!a_farm->FA_RSM(a_field, 0.0, a_field->GetMDates(1, 2) - g_date->DayInYear())) {
761  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_s8, true, a_farm, a_field);
762  break;
763  }
764  }
765  }
766  if (a_farm->IsStockFarmer()) //Stock Farmer
767  {
768  SimpleEvent_(g_date->Date(), pl_ms_ferti_s9, false, a_farm, a_field);
769  }
770  else SimpleEvent_(g_date->Date(), pl_ms_ferti_p9, false, a_farm, a_field);
771  break;
772  case pl_ms_ferti_p9:
773  if (a_ev->m_lock || a_farm->DoIt(22))
774  {
775  if (a_field->GetMConstants(3) == 0) {
776  if (!a_farm->FP_Calcium(a_field, 0.0, -1)) { // raise an error
777  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): failure in 'FP_Calcium' execution", "");
778  exit(1);
779  }
780  }
781  else {
782  if (!a_farm->FP_Calcium(a_field, 0.0, a_field->GetMDates(1, 3) - g_date->DayInYear())) {
783  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_p9, true, a_farm, a_field);
784  break;
785  }
786  }
787  }
788  done = true;
789  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
790  // END of MAIN THREAD
791  break;
792  case pl_ms_ferti_s9:
793  if (a_ev->m_lock || a_farm->DoIt(22))
794  {
795  if (a_field->GetMConstants(3) == 0) {
796  if (!a_farm->FA_Calcium(a_field, 0.0, -1)) { // raise an error
797  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): failure in 'FA_Calcium' execution", "");
798  exit(1);
799  }
800  }
801  else {
802  if (!a_farm->FA_Calcium(a_field, 0.0, a_field->GetMDates(1, 3) - g_date->DayInYear())) {
803  SimpleEvent_(g_date->Date() + 1, pl_ms_ferti_s9, true, a_farm, a_field);
804  break;
805  }
806  }
807  }
808  done = true;
809  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
810  // END of MAIN THREAD
811  break;
812  default:
813  g_msg->Warn(WARN_BUG, "PLMaizeSilage::Do(): "
814  "Unknown event type! ", "");
815  exit(1);
816  }
817  return done;
818 }

References Landscape::BackTranslateVegTypes(), cfg_pest_product_1_amount, cfg_pest_springwheat_on, Farm::DoIt(), Farm::FP_Slurry(), 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_ms_autumn_harrow1, pl_ms_autumn_harrow2, pl_ms_biocide, PL_MS_FERTI_P1, pl_ms_ferti_p1, pl_ms_ferti_p2, PL_MS_FERTI_P3, pl_ms_ferti_p3, pl_ms_ferti_p4, pl_ms_ferti_p5, pl_ms_ferti_p6, pl_ms_ferti_p7, pl_ms_ferti_p8, pl_ms_ferti_p9, PL_MS_FERTI_S1, pl_ms_ferti_s1, pl_ms_ferti_s2, PL_MS_FERTI_S3, pl_ms_ferti_s3, pl_ms_ferti_s4, pl_ms_ferti_s5, pl_ms_ferti_s6, pl_ms_ferti_s7, pl_ms_ferti_s8, pl_ms_ferti_s9, pl_ms_fungicide1, pl_ms_harvest, pl_ms_hay_bailing, pl_ms_heavy_cultivator, pl_ms_herbicide1, pl_ms_herbicide2, pl_ms_insecticide1, pl_ms_insecticide2, pl_ms_preseeding_cultivator, PL_MS_SPRING_FERTI, pl_ms_spring_harrow, pl_ms_spring_sow, pl_ms_spring_sow_with_ferti, pl_ms_start, PL_MS_START_FERTI, pl_ms_straw_chopping, pl_ms_stubble_harrow, PL_MS_STUBBLE_PLOUGH, pl_ms_stubble_plough, PL_MS_WINTER_PLOUGH, pl_ms_winter_plough, pl_ms_winter_stubble_cultivator_heavy, ppp_1, Crop::SimpleEvent_(), Landscape::SupplyShouldSpray(), and tof_OptimisingFarm.


The documentation for this class was generated from the following files:
pl_ms_ferti_s4
Definition: PLMaizeSilage.h:59
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
pl_ms_autumn_harrow2
Definition: PLMaizeSilage.h:49
pl_ms_stubble_harrow
Definition: PLMaizeSilage.h:50
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
PL_MS_WINTER_PLOUGH
#define PL_MS_WINTER_PLOUGH
Definition: PLMaizeSilage.h:31
pl_ms_ferti_p2
Definition: PLMaizeSilage.h:51
Landscape::SupplyShouldSpray
bool SupplyShouldSpray()
Definition: Landscape.h:357
pl_ms_ferti_s5
Definition: PLMaizeSilage.h:61
pl_ms_biocide
Definition: PLMaizeSilage.h:71
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
pl_ms_ferti_s7
Definition: PLMaizeSilage.h:75
pl_ms_fungicide1
Definition: PLMaizeSilage.h:68
pl_ms_ferti_p3
Definition: PLMaizeSilage.h:55
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
PL_MS_START_FERTI
#define PL_MS_START_FERTI
Definition: PLMaizeSilage.h:35
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
PL_MS_FERTI_P3
#define PL_MS_FERTI_P3
Definition: PLMaizeSilage.h:32
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
pl_ms_ferti_s8
Definition: PLMaizeSilage.h:80
Crop::m_first_date
int m_first_date
Definition: farm.h:540
pl_ms_spring_harrow
Definition: PLMaizeSilage.h:57
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
pl_ms_spring_sow
Definition: PLMaizeSilage.h:65
pl_ms_hay_bailing
Definition: PLMaizeSilage.h:78
PL_MS_FERTI_S3
#define PL_MS_FERTI_S3
Definition: PLMaizeSilage.h:33
pl_ms_start
Definition: PLMaizeSilage.h:43
pl_ms_winter_stubble_cultivator_heavy
Definition: PLMaizeSilage.h:54
pl_ms_insecticide2
Definition: PLMaizeSilage.h:70
pl_ms_insecticide1
Definition: PLMaizeSilage.h:69
pl_ms_preseeding_cultivator
Definition: PLMaizeSilage.h:63
pl_ms_ferti_p8
Definition: PLMaizeSilage.h:79
pl_ms_ferti_p9
Definition: PLMaizeSilage.h:81
pl_ms_ferti_p5
Definition: PLMaizeSilage.h:60
pl_ms_ferti_p4
Definition: PLMaizeSilage.h:58
pl_ms_ferti_s6
Definition: PLMaizeSilage.h:73
pl_ms_autumn_harrow1
Definition: PLMaizeSilage.h:48
pl_ms_heavy_cultivator
Definition: PLMaizeSilage.h:62
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
pl_ms_ferti_s9
Definition: PLMaizeSilage.h:82
pl_ms_winter_plough
Definition: PLMaizeSilage.h:53
pl_ms_harvest
Definition: PLMaizeSilage.h:76
pl_ms_ferti_p6
Definition: PLMaizeSilage.h:72
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
pl_ms_ferti_p7
Definition: PLMaizeSilage.h:74
cfg_pest_product_1_amount
CfgFloat cfg_pest_product_1_amount
Farm::FP_Slurry
virtual bool FP_Slurry(LE *a_field, double a_user, int a_days)
Apply slurry to a_field owned by an arable farmer.
Definition: farmfuncs.cpp:701
pl_ms_ferti_s3
Definition: PLMaizeSilage.h:56
ppp_1
Definition: farm.h:422
pl_ms_spring_sow_with_ferti
Definition: PLMaizeSilage.h:64
cfg_pest_springwheat_on
CfgBool cfg_pest_springwheat_on
pl_ms_ferti_s1
Definition: PLMaizeSilage.h:46
pl_ms_straw_chopping
Definition: PLMaizeSilage.h:77
pl_ms_stubble_plough
Definition: PLMaizeSilage.h:47
PL_MS_SPRING_FERTI
#define PL_MS_SPRING_FERTI
Definition: PLMaizeSilage.h:34
pl_ms_ferti_p1
Definition: PLMaizeSilage.h:45
PL_MS_FERTI_S1
#define PL_MS_FERTI_S1
Definition: PLMaizeSilage.h:29
pl_ms_herbicide1
Definition: PLMaizeSilage.h:66
PL_MS_FERTI_P1
#define PL_MS_FERTI_P1
A flag used to indicate autumn ploughing status.
Definition: PLMaizeSilage.h:28
PL_MS_STUBBLE_PLOUGH
#define PL_MS_STUBBLE_PLOUGH
Definition: PLMaizeSilage.h:30
g_landscape_p
Landscape * g_landscape_p
Definition: Landscape.cpp:258
pl_ms_herbicide2
Definition: PLMaizeSilage.h:67
pl_ms_ferti_s2
Definition: PLMaizeSilage.h:52
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