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

PLMaize class
. More...

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

PLMaize class
.

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

◆ PLMaize()

PLMaize::PLMaize ( )
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 PLMaize::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 maize.

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_m_start:
72  {
73  // pl_m_start just sets up all the starting conditions and reference dates that are needed to start a pl_m
74  PL_M_FERTI_P1 = false;
75  PL_M_FERTI_S1 = false;
76  PL_M_STUBBLE_PLOUGH = false;
77  PL_M_WINTER_PLOUGH = false;
78  PL_M_FERTI_P3 = false;
79  PL_M_FERTI_S3 = false;
81  PL_M_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(10, 10)); // last possible day of harvest
90  a_field->SetMDates(1, 0, g_date->DayInYear(15, 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(20, 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(20, 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(20, 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, "PLMaize::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, "PLMaize::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, "PLMaize::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_m_ferti_s3, false, a_farm, a_field);
161  }
162  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 3), pl_m_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_m_ferti_s1, false, a_farm, a_field);
175  }
176  else SimpleEvent_(d1, pl_m_ferti_p1, false, a_farm, a_field);
177  }
178  break;
179 
180  // This is the first real farm operation
181  case pl_m_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_m_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_M_FERTI_P1 = true;
195  }
196  }
197  // Queue up the next event -in this case stubble ploughing
198  SimpleEvent_(g_date->Date() + 1, pl_m_stubble_plough, false, a_farm, a_field);
199  break;
200  case pl_m_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_m_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_M_FERTI_S1 = true;
213  }
214  }
215  // Queue up the next event -in this case stubble ploughing
216  SimpleEvent_(g_date->Date() + 1, pl_m_stubble_plough, false, a_farm, a_field);
217  break;
218  case pl_m_stubble_plough:
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_m_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_M_STUBBLE_PLOUGH = true;
230  // Queue up the next event
231  SimpleEvent_(g_date->Date() + 1, pl_m_autumn_harrow1, false, a_farm, a_field);
232  break;
233  }
234  }
235  SimpleEvent_(g_date->Date() + 1, pl_m_stubble_harrow, false, a_farm, a_field);
236  break;
237  case pl_m_autumn_harrow1:
238  if (!a_farm->AutumnHarrow(a_field, 0.0, g_date->DayInYear(5, 11) - g_date->DayInYear())) {
239  SimpleEvent_(g_date->Date() + 1, pl_m_autumn_harrow1, true, a_farm, a_field);
240  break;
241  }
242  SimpleEvent_(g_date->Date() + 2, pl_m_autumn_harrow2, false, a_farm, a_field);
243  break;
244  case pl_m_autumn_harrow2:
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_m_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_m_ferti_s2, false, a_farm, a_field);
259  }
260  else SimpleEvent_(d1, pl_m_ferti_p2, false, a_farm, a_field);
261  break;
262  case pl_m_stubble_harrow:
263  if (!a_farm->StubbleHarrowing(a_field, 0.0, g_date->DayInYear(10, 11) - g_date->DayInYear())) {
264  SimpleEvent_(g_date->Date() + 1, pl_m_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_m_ferti_s2, false, a_farm, a_field);
274  }
275  else SimpleEvent_(d1, pl_m_ferti_p2, false, a_farm, a_field);
276  break;
277  case pl_m_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_M_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_m_ferti_p2, true, a_farm, a_field);
284  break;
285  }
286  }
287  SimpleEvent_(g_date->Date() + 1, pl_m_winter_plough, false, a_farm, a_field);
288  break;
289  case pl_m_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_M_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_m_ferti_s2, true, a_farm, a_field);
296  break;
297  }
298  }
299  SimpleEvent_(g_date->Date() + 1, pl_m_winter_plough, false, a_farm, a_field);
300  break;
301  case pl_m_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_m_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_M_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_m_ferti_s3, false, a_farm, a_field);
317  }
318  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 3) + 365, pl_m_ferti_p3, false, a_farm, a_field);
319  break;
320  }
321  }
322  SimpleEvent_(g_date->Date() + 1, pl_m_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_m_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_m_ferti_s3, false, a_farm, a_field);
333  }
334  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 3) + 365, pl_m_ferti_p3, false, a_farm, a_field);
335  break;
336  case pl_m_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_m_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_M_FERTI_P3 = true;
347  }
348  }
349  SimpleEvent_(g_date->Date() + 1, pl_m_spring_harrow, false, a_farm, a_field);
350  break;
351  case pl_m_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_m_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_M_FERTI_S3 = true;
362  }
363  }
364  SimpleEvent_(g_date->Date() + 1, pl_m_spring_harrow, false, a_farm, a_field);
365  break;
366  case pl_m_spring_harrow:
367  if ((a_ev->m_lock) || (PL_M_FERTI_P3) || (PL_M_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_m_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_m_ferti_s4, false, a_farm, a_field);
381  }
382  else SimpleEvent_(d1, pl_m_ferti_p4, false, a_farm, a_field);
383  break;
384  case pl_m_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_m_ferti_p4, true, a_farm, a_field);
389  break;
390  }
391  PL_M_SPRING_FERTI = true;
392  }
393  SimpleEvent_(g_date->Date() + 1, pl_m_ferti_p5, false, a_farm, a_field);
394  break;
395  case pl_m_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_m_ferti_s4, true, a_farm, a_field);
400  break;
401  }
402  PL_M_SPRING_FERTI = true;
403  }
404  SimpleEvent_(g_date->Date() + 1, pl_m_ferti_s5, false, a_farm, a_field);
405  break;
406  case pl_m_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_m_ferti_p5, true, a_farm, a_field);
411  break;
412  }
413  PL_M_SPRING_FERTI = true;
414  }
415  SimpleEvent_(g_date->Date() + 1, pl_m_heavy_cultivator, false, a_farm, a_field);
416  break;
417  case pl_m_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_m_ferti_s5, true, a_farm, a_field);
422  break;
423  }
424  PL_M_SPRING_FERTI = 1;
425  }
426  SimpleEvent_(g_date->Date() + 1, pl_m_heavy_cultivator, false, a_farm, a_field);
427  break;
429  if (PL_M_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_m_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_m_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_m_preseeding_cultivator, true, a_farm, a_field);
447  break;
448  }
449  }
450  SimpleEvent_(g_date->Date() + 1, pl_m_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_m_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_M_START_FERTI = true;
464  // Here is a fork leading to parallel events
465  SimpleEvent_(g_date->Date() + 1, pl_m_herbicide1, false, a_farm, a_field); // Herbidide thread
466  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 6), pl_m_fungicide1, false, a_farm, a_field); // Fungicide thread
467  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_m_insecticide1, false, a_farm, a_field); // Insecticide thread = MAIN THREAD
468  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(5, 6), pl_m_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_m_ferti_s6, false, a_farm, a_field);
472  }
473  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_m_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_m_ferti_s7, false, a_farm, a_field);
477  }
478  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_m_ferti_p7, false, a_farm, a_field);
479  break;
480  }
481  }
482  SimpleEvent_(g_date->Date() + 1, pl_m_spring_sow, false, a_farm, a_field);
483  break;
484  case pl_m_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_m_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_m_herbicide1, false, a_farm, a_field); // Herbidide thread
491  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 6), pl_m_fungicide1, false, a_farm, a_field); // Fungicide thread
492  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_m_insecticide1, false, a_farm, a_field); // Insecticide thread = MAIN THREAD
493  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(5, 6), pl_m_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_m_ferti_s6, false, a_farm, a_field);
497  }
498  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_m_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_m_ferti_s7, false, a_farm, a_field);
502  }
503  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_m_ferti_p7, false, a_farm, a_field);
504  break;
505  case pl_m_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_m_ferti_p6, true, a_farm, a_field);
511  break;
512  }
513  }
514  // End of thread
515  break;
516  case pl_m_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_m_ferti_s6, true, a_farm, a_field);
521  break;
522  }
523  }
524  // End of thread
525  break;
526  case pl_m_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_m_ferti_p7, true, a_farm, a_field);
532  break;
533  }
534  }
535  // End of thread
536  break;
537  case pl_m_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_m_ferti_s7, true, a_farm, a_field);
542  break;
543  }
544  }
545  // End of thread
546  break;
547  case pl_m_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_m_herbicide1, true, a_farm, a_field);
553  break;
554  }
555  }
556  SimpleEvent_(g_date->Date() + 10, pl_m_herbicide2, false, a_farm, a_field);
557  break;
558  case pl_m_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_m_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_m_herbicide2, true, a_farm, a_field);
570  break;
571  }
572  }
573  }
574  // End of thread
575  break;
576  case pl_m_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_m_fungicide1, true, a_farm, a_field);
582  break;
583  }
584  }
585  // End of thread
586  break;
587  case pl_m_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_m_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_m_insecticide2, false, a_farm, a_field);
609  break;
610  case pl_m_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_m_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(20, 9), pl_m_harvest, false, a_farm, a_field);
627  break;
628 
629 
630  case pl_m_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_m_biocide, true, a_farm, a_field);
636  break;
637  }
638  }
639  // End of thread
640  break;
641  case pl_m_harvest:
642  // Here the MAIN thread continues
643  // We don't move harvest days
644  if (!a_farm->Harvest(a_field, 0.0, a_field->GetMDates(0, 0) - g_date->DayInYear())) {
645  SimpleEvent_(g_date->Date() + 1, pl_m_harvest, true, a_farm, a_field);
646  break;
647  }
648  SimpleEvent_(g_date->Date() + 1, pl_m_straw_chopping, false, a_farm, a_field);
649  break;
650  case pl_m_straw_chopping:
651  if (a_farm->IsStockFarmer()) //Stock Farmer
652  {
653  // 10% of stock farmers will do straw chopping, but rest will do hay bailing instead
654  if (a_ev->m_lock || a_farm->DoIt(10))
655  {
656  if (a_field->GetMConstants(0) == 0) {
657  if (!a_farm->StrawChopping(a_field, 0.0, -1)) { // raise an error
658  g_msg->Warn(WARN_BUG, "PLMaize::Do(): failure in 'StrawChopping' execution", "");
659  exit(1);
660  }
661  }
662  else {
663  if (!a_farm->StrawChopping(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
664  SimpleEvent_(g_date->Date() + 1, pl_m_straw_chopping, true, a_farm, a_field);
665  break;
666  }
667  else
668  {
669  // Queue up the next event
670  SimpleEvent_(g_date->Date(), pl_m_ferti_s8, false, a_farm, a_field);
671  break;
672  }
673  }
674 
675  }
676  SimpleEvent_(g_date->Date() + 1, pl_m_hay_bailing, false, a_farm, a_field);
677  break;
678  }
679  else
680  {
681  // 90% of arable farmers will do straw chopping, but rest will do hay bailing instead
682  if (a_ev->m_lock || a_farm->DoIt(90))
683  {
684  if (a_field->GetMConstants(0) == 0) {
685  if (!a_farm->StrawChopping(a_field, 0.0, -1)) { // raise an error
686  g_msg->Warn(WARN_BUG, "PLMaize::Do(): failure in 'StrawChopping' execution", "");
687  exit(1);
688  }
689  }
690  else {
691  if (!a_farm->StrawChopping(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
692  SimpleEvent_(g_date->Date() + 1, pl_m_straw_chopping, true, a_farm, a_field);
693  break;
694  }
695  else
696  {
697  // Queue up the next event
698  SimpleEvent_(g_date->Date(), pl_m_ferti_p8, false, a_farm, a_field);
699  break;
700  }
701  }
702 
703  }
704  SimpleEvent_(g_date->Date() + 1, pl_m_hay_bailing, false, a_farm, a_field);
705  break;
706  }
707  case pl_m_hay_bailing:
708  if (a_field->GetMConstants(1) == 0) {
709  if (!a_farm->HayBailing(a_field, 0.0, -1)) { // raise an error
710  g_msg->Warn(WARN_BUG, "PLMaize::Do(): failure in 'HayBailing' execution", "");
711  exit(1);
712  }
713  }
714  else {
715  if (!a_farm->HayBailing(a_field, 0.0, a_field->GetMDates(1, 1) - g_date->DayInYear())) {
716  SimpleEvent_(g_date->Date() + 1, pl_m_hay_bailing, true, a_farm, a_field);
717  break;
718  }
719  }
720  if (a_farm->IsStockFarmer()) //Stock Farmer
721  {
722  SimpleEvent_(g_date->Date(), pl_m_ferti_s9, false, a_farm, a_field);
723  }
724  else SimpleEvent_(g_date->Date(), pl_m_ferti_p9, false, a_farm, a_field);
725  break;
726  case pl_m_ferti_p8:
727  if (a_ev->m_lock || a_farm->DoIt(38))
728  {
729  if (a_field->GetMConstants(2) == 0) {
730  if (!a_farm->FP_RSM(a_field, 0.0, -1)) { // raise an error
731  g_msg->Warn(WARN_BUG, "PLMaize::Do(): failure in 'FP_RSM' execution", "");
732  exit(1);
733  }
734  }
735  else {
736  if (!a_farm->FP_RSM(a_field, 0.0, a_field->GetMDates(1, 2) - g_date->DayInYear())) {
737  SimpleEvent_(g_date->Date() + 1, pl_m_ferti_p8, true, a_farm, a_field);
738  break;
739  }
740  }
741  }
742  if (a_farm->IsStockFarmer()) //Stock Farmer
743  {
744  SimpleEvent_(g_date->Date(), pl_m_ferti_s9, false, a_farm, a_field);
745  }
746  else SimpleEvent_(g_date->Date(), pl_m_ferti_p9, false, a_farm, a_field);
747  break;
748  case pl_m_ferti_s8:
749  if (a_ev->m_lock || a_farm->DoIt(38))
750  {
751  if (a_field->GetMConstants(2) == 0) {
752  if (!a_farm->FA_RSM(a_field, 0.0, -1)) { // raise an error
753  g_msg->Warn(WARN_BUG, "PLMaize::Do(): failure in 'FA_RSM' execution", "");
754  exit(1);
755  }
756  }
757  else {
758  if (!a_farm->FA_RSM(a_field, 0.0, a_field->GetMDates(1, 2) - g_date->DayInYear())) {
759  SimpleEvent_(g_date->Date() + 1, pl_m_ferti_s8, true, a_farm, a_field);
760  break;
761  }
762  }
763  }
764  if (a_farm->IsStockFarmer()) //Stock Farmer
765  {
766  SimpleEvent_(g_date->Date(), pl_m_ferti_s9, false, a_farm, a_field);
767  }
768  else SimpleEvent_(g_date->Date(), pl_m_ferti_p9, false, a_farm, a_field);
769  break;
770  case pl_m_ferti_p9:
771  if (a_ev->m_lock || a_farm->DoIt(22))
772  {
773  if (a_field->GetMConstants(3) == 0) {
774  if (!a_farm->FP_Calcium(a_field, 0.0, -1)) { // raise an error
775  g_msg->Warn(WARN_BUG, "PLMaize::Do(): failure in 'FP_Calcium' execution", "");
776  exit(1);
777  }
778  }
779  else {
780  if (!a_farm->FP_Calcium(a_field, 0.0, a_field->GetMDates(1, 3) - g_date->DayInYear())) {
781  SimpleEvent_(g_date->Date() + 1, pl_m_ferti_p9, true, a_farm, a_field);
782  break;
783  }
784  }
785  }
786  done = true;
787  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
788  // END of MAIN THREAD
789  break;
790  case pl_m_ferti_s9:
791  if (a_ev->m_lock || a_farm->DoIt(22))
792  {
793  if (a_field->GetMConstants(3) == 0) {
794  if (!a_farm->FA_Calcium(a_field, 0.0, -1)) { // raise an error
795  g_msg->Warn(WARN_BUG, "PLMaize::Do(): failure in 'FA_Calcium' execution", "");
796  exit(1);
797  }
798  }
799  else {
800  if (!a_farm->FA_Calcium(a_field, 0.0, a_field->GetMDates(1, 3) - g_date->DayInYear())) {
801  SimpleEvent_(g_date->Date() + 1, pl_m_ferti_s9, true, a_farm, a_field);
802  break;
803  }
804  }
805  }
806  done = true;
807  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
808  // END of MAIN THREAD
809  break;
810  default:
811  g_msg->Warn(WARN_BUG, "PLMaize::Do(): "
812  "Unknown event type! ", "");
813  exit(1);
814  }
815  return done;
816 }

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_m_autumn_harrow1, pl_m_autumn_harrow2, pl_m_biocide, PL_M_FERTI_P1, pl_m_ferti_p1, pl_m_ferti_p2, PL_M_FERTI_P3, pl_m_ferti_p3, pl_m_ferti_p4, pl_m_ferti_p5, pl_m_ferti_p6, pl_m_ferti_p7, pl_m_ferti_p8, pl_m_ferti_p9, PL_M_FERTI_S1, pl_m_ferti_s1, pl_m_ferti_s2, PL_M_FERTI_S3, pl_m_ferti_s3, pl_m_ferti_s4, pl_m_ferti_s5, pl_m_ferti_s6, pl_m_ferti_s7, pl_m_ferti_s8, pl_m_ferti_s9, pl_m_fungicide1, pl_m_harvest, pl_m_hay_bailing, pl_m_heavy_cultivator, pl_m_herbicide1, pl_m_herbicide2, pl_m_insecticide1, pl_m_insecticide2, pl_m_preseeding_cultivator, PL_M_SPRING_FERTI, pl_m_spring_harrow, pl_m_spring_sow, pl_m_spring_sow_with_ferti, pl_m_start, PL_M_START_FERTI, pl_m_straw_chopping, pl_m_stubble_harrow, PL_M_STUBBLE_PLOUGH, pl_m_stubble_plough, PL_M_WINTER_PLOUGH, pl_m_winter_plough, pl_m_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_m_ferti_s5
Definition: PLMaize.h:61
pl_m_fungicide1
Definition: PLMaize.h:68
pl_m_spring_sow_with_ferti
Definition: PLMaize.h:64
pl_m_ferti_p2
Definition: PLMaize.h:51
PL_M_FERTI_S1
#define PL_M_FERTI_S1
Definition: PLMaize.h:29
pl_m_ferti_p8
Definition: PLMaize.h:79
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
Landscape::SupplyShouldSpray
bool SupplyShouldSpray()
Definition: Landscape.h:357
pl_m_ferti_s4
Definition: PLMaize.h:59
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
pl_m_harvest
Definition: PLMaize.h:76
pl_m_autumn_harrow1
Definition: PLMaize.h:48
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
pl_m_ferti_s1
Definition: PLMaize.h:46
tof_OptimisingFarm
Definition: farm.h:273
cfg_pest_product_1_amount
CfgFloat cfg_pest_product_1_amount
pl_m_winter_stubble_cultivator_heavy
Definition: PLMaize.h:54
pl_m_ferti_s2
Definition: PLMaize.h:52
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
pl_m_ferti_p4
Definition: PLMaize.h:58
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
pl_m_insecticide1
Definition: PLMaize.h:69
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
pl_m_herbicide2
Definition: PLMaize.h:67
pl_m_ferti_s3
Definition: PLMaize.h:56
PL_M_FERTI_P1
#define PL_M_FERTI_P1
A flag used to indicate autumn ploughing status.
Definition: PLMaize.h:28
pl_m_hay_bailing
Definition: PLMaize.h:78
pl_m_heavy_cultivator
Definition: PLMaize.h:62
pl_m_spring_harrow
Definition: PLMaize.h:57
pl_m_ferti_s7
Definition: PLMaize.h:75
pl_m_ferti_p5
Definition: PLMaize.h:60
pl_m_ferti_p7
Definition: PLMaize.h:74
PL_M_STUBBLE_PLOUGH
#define PL_M_STUBBLE_PLOUGH
Definition: PLMaize.h:30
pl_m_winter_plough
Definition: PLMaize.h:53
pl_m_start
Definition: PLMaize.h:43
pl_m_ferti_p3
Definition: PLMaize.h:55
pl_m_ferti_p1
Definition: PLMaize.h:45
pl_m_ferti_p9
Definition: PLMaize.h:81
pl_m_autumn_harrow2
Definition: PLMaize.h:49
pl_m_ferti_p6
Definition: PLMaize.h:72
PL_M_START_FERTI
#define PL_M_START_FERTI
Definition: PLMaize.h:35
pl_m_insecticide2
Definition: PLMaize.h:70
pl_m_herbicide1
Definition: PLMaize.h:66
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
pl_m_stubble_plough
Definition: PLMaize.h:47
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
pl_m_preseeding_cultivator
Definition: PLMaize.h:63
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
ppp_1
Definition: farm.h:422
pl_m_biocide
Definition: PLMaize.h:71
PL_M_FERTI_P3
#define PL_M_FERTI_P3
Definition: PLMaize.h:32
pl_m_straw_chopping
Definition: PLMaize.h:77
pl_m_stubble_harrow
Definition: PLMaize.h:50
cfg_pest_springwheat_on
CfgBool cfg_pest_springwheat_on
PL_M_WINTER_PLOUGH
#define PL_M_WINTER_PLOUGH
Definition: PLMaize.h:31
PL_M_SPRING_FERTI
#define PL_M_SPRING_FERTI
Definition: PLMaize.h:34
pl_m_ferti_s8
Definition: PLMaize.h:80
pl_m_spring_sow
Definition: PLMaize.h:65
PL_M_FERTI_S3
#define PL_M_FERTI_S3
Definition: PLMaize.h:33
pl_m_ferti_s9
Definition: PLMaize.h:82
g_landscape_p
Landscape * g_landscape_p
Definition: Landscape.cpp:258
pl_m_ferti_s6
Definition: PLMaize.h:73
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