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

PLWinterRye class
. More...

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

PLWinterRye class
.

See PLWinterRye.h::PLWinterRyeToDo for a complete list of all possible events triggered codes by the winter rye 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

◆ PLWinterRye()

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

References Crop::m_first_date.

Member Function Documentation

◆ Do()

bool PLWinterRye::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 winter rye.

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

References Landscape::BackTranslateVegTypes(), 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_wrye_autumn_harrow1, pl_wrye_autumn_harrow2, pl_wrye_autumn_plough, pl_wrye_autumn_roll, pl_wrye_autumn_sow, PL_WRYE_FERTI_P1, pl_wrye_ferti_p1, pl_wrye_ferti_p10, pl_wrye_ferti_p11, pl_wrye_ferti_p2, pl_wrye_ferti_p3, pl_wrye_ferti_p4, pl_wrye_ferti_p5, pl_wrye_ferti_p6, pl_wrye_ferti_p7, pl_wrye_ferti_p8, pl_wrye_ferti_p9, PL_WRYE_FERTI_S1, pl_wrye_ferti_s1, pl_wrye_ferti_s10, pl_wrye_ferti_s11, pl_wrye_ferti_s2, pl_wrye_ferti_s3, pl_wrye_ferti_s4, pl_wrye_ferti_s5, pl_wrye_ferti_s6, pl_wrye_ferti_s7, pl_wrye_ferti_s8, pl_wrye_ferti_s9, pl_wrye_fungicide1, pl_wrye_fungicide2, pl_wrye_growth_regulator1, pl_wrye_harvest, pl_wrye_hay_bailing, pl_wrye_herbicide1, pl_wrye_herbicide2, pl_wrye_preseeding_cultivator, pl_wrye_preseeding_cultivator_sow, pl_wrye_start, pl_wrye_straw_chopping, pl_wrye_stubble_cultivator_heavy, pl_wrye_stubble_harrow, PL_WRYE_STUBBLE_PLOUGH, pl_wrye_stubble_plough, Crop::SimpleEvent_(), and tof_OptimisingFarm.


The documentation for this class was generated from the following files:
pl_wrye_ferti_s1
Definition: PLWinterRye.h:41
pl_wrye_ferti_s7
Definition: PLWinterRye.h:65
PL_WRYE_STUBBLE_PLOUGH
#define PL_WRYE_STUBBLE_PLOUGH
Definition: PLWinterRye.h:30
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
pl_wrye_growth_regulator1
Definition: PLWinterRye.h:72
pl_wrye_autumn_harrow1
Definition: PLWinterRye.h:43
pl_wrye_ferti_s4
Definition: PLWinterRye.h:59
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
pl_wrye_ferti_p9
Definition: PLWinterRye.h:68
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
pl_wrye_ferti_p7
Definition: PLWinterRye.h:64
pl_wrye_ferti_p8
Definition: PLWinterRye.h:66
pl_wrye_ferti_p11
Definition: PLWinterRye.h:78
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
pl_wrye_harvest
Definition: PLWinterRye.h:73
pl_wrye_ferti_s2
Definition: PLWinterRye.h:47
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
pl_wrye_autumn_sow
Definition: PLWinterRye.h:55
pl_wrye_autumn_harrow2
Definition: PLWinterRye.h:44
pl_wrye_autumn_plough
Definition: PLWinterRye.h:48
pl_wrye_preseeding_cultivator_sow
Definition: PLWinterRye.h:54
PL_WRYE_FERTI_S1
#define PL_WRYE_FERTI_S1
Definition: PLWinterRye.h:29
pl_wrye_ferti_p6
Definition: PLWinterRye.h:62
pl_wrye_stubble_harrow
Definition: PLWinterRye.h:45
pl_wrye_ferti_p4
Definition: PLWinterRye.h:58
pl_wrye_ferti_s5
Definition: PLWinterRye.h:61
pl_wrye_ferti_s11
Definition: PLWinterRye.h:79
pl_wrye_stubble_cultivator_heavy
Definition: PLWinterRye.h:50
pl_wrye_ferti_s6
Definition: PLWinterRye.h:63
pl_wrye_start
Definition: PLWinterRye.h:38
pl_wrye_herbicide2
Definition: PLWinterRye.h:70
pl_wrye_herbicide1
Definition: PLWinterRye.h:56
pl_wrye_ferti_s3
Definition: PLWinterRye.h:52
pl_wrye_fungicide1
Definition: PLWinterRye.h:57
pl_wrye_fungicide2
Definition: PLWinterRye.h:71
pl_wrye_stubble_plough
Definition: PLWinterRye.h:42
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
PL_WRYE_FERTI_P1
#define PL_WRYE_FERTI_P1
A flag used to indicate autumn ploughing status.
Definition: PLWinterRye.h:28
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
pl_wrye_straw_chopping
Definition: PLWinterRye.h:74
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_wrye_ferti_p2
Definition: PLWinterRye.h:46
pl_wrye_ferti_s8
Definition: PLWinterRye.h:67
pl_wrye_preseeding_cultivator
Definition: PLWinterRye.h:53
pl_wrye_hay_bailing
Definition: PLWinterRye.h:75
pl_wrye_ferti_p1
Definition: PLWinterRye.h:40
pl_wrye_ferti_p3
Definition: PLWinterRye.h:51
pl_wrye_ferti_p5
Definition: PLWinterRye.h:60
pl_wrye_ferti_s10
Definition: PLWinterRye.h:77
pl_wrye_autumn_roll
Definition: PLWinterRye.h:49
pl_wrye_ferti_p10
Definition: PLWinterRye.h:76
pl_wrye_ferti_s9
Definition: PLWinterRye.h:69
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