ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
PLBeetSpr.cpp
Go to the documentation of this file.
1 /*
2 *******************************************************************************************************
3 Copyright (c) 2017, Christopher John Topping, Aarhus University
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided
7 that the following conditions are met:
8 
9 Redistributions of source code must retain the above copyright notice, this list of conditions and the
10 following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12 the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
17 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
19 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 ********************************************************************************************************
23 */
38 //
39 // PLBeetSpr.cpp
40 //
41 
42 
43 #include "../../Landscape/ls.h"
44 #include "../../Landscape/cropprogs/PLBeetSpr.h"
45 
46 // Some things that are defined externally - in this case these variables allow
47 // scaling of the percentage application figures for insecticides, herbicides etc..
48 extern CfgBool cfg_pest_beet_on;
49 // check if below are needed
50 extern CfgFloat l_pest_insecticide_amount;
51 extern CfgInt cfg_BES_InsecticideDay;
52 extern CfgInt cfg_BES_InsecticideMonth;
53 extern CfgFloat cfg_pest_product_1_amount;
54 
55 
64 bool PLBeetSpr::Do(Farm *a_farm, LE *a_field, FarmEvent *a_ev)
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_bes_start:
72  {
73  // pl_bes_start just sets up all the starting conditions and reference dates that are needed to start a pl_sw
77  PL_BES_HERBI1 = false;
78  PL_BES_HERBI3 = false;
79 
80  // Set up the date management stuff
81  // The next bit of code just allows for altering dates after harvest if it is necessary
82  // to allow for a crop which starts its management early.
83 
84  // 2 start and stop dates for all 'movable' events for this crop
85  int noDates = 2;
86  a_field->SetMDates(0, 0, g_date->DayInYear(30, 12)); // last possible day of harvest
87  a_field->SetMDates(1, 0, g_date->DayInYear(30, 12)); // end day of calcium application
88  a_field->SetMDates(0, 1, 0);
89  a_field->SetMDates(1, 1, g_date->DayInYear(30, 12));
90 
91  a_field->SetMConstants(0, 1);
92 
93  // Check the next crop for early start, unless it is a spring crop
94  // in which case we ASSUME that no checking is necessary!!!!
95  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
96 
97  //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)
98  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
99  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
100 
101  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
102  if (a_field->GetMDates(0, 0) >= a_ev->m_startday)
103  {
104  g_msg->Warn(WARN_BUG, "PLBeetSpr::Do(): ", "Harvest too late for the next crop to start!!!");
105  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
106  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
107  }
108  // Now fix any late finishing problems
109  for (int i = 0; i < noDates; i++) {
110  if (a_field->GetMDates(0, i) >= a_ev->m_startday) {
111  a_field->SetMDates(0, i, a_ev->m_startday - 1); //move the starting date
112  }
113  if (a_field->GetMDates(1, i) >= a_ev->m_startday) {
114  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)
115  a_field->SetMDates(1, i, a_ev->m_startday - 1); //move the finishing date
116  }
117  }
118  }
119  // Now no operations can be timed after the start of the next crop.
120 
121  if (!a_ev->m_first_year) {
122  // Are we before July 1st?
123  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
124  if (g_date->Date() < d1) {
125  // Yes, too early. We assumme this is because the last crop was late
126  printf("Poly: %d\n", a_field->GetPoly());
127  g_msg->Warn(WARN_BUG, "PLBeetSpr::Do(): ", "Crop start attempt between 1st Jan & 1st July");
128  int prev = g_landscape_p->BackTranslateVegTypes(a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex()));
129  g_msg->Warn(WARN_BUG, "Previous Crop ", prev);
130  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
131  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
132  }
133  else {
134  d1 = g_date->OldDays() + 365 + m_first_date; // Add 365 for spring crop
135  if (g_date->Date() > d1) {
136  // Yes too late - should not happen - raise an error
137  g_msg->Warn(WARN_BUG, "PLBeetSpr::Do(): ", "Crop start attempt after last possible start date");
138  g_msg->Warn(WARN_BUG, "Previous Crop ", "");
139  a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex());
140  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
141  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
142  }
143  }
144  }
145  else {
146  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 3), pl_bes_spring_plough, false, a_farm, a_field);
147  break;
148  }
149  }//if
150 
151  // End single block date checking code. Please see next line comment as well.
152  // Reinit d1 to first possible starting date.
153 
154 
155  d1 = g_date->OldDays() + g_date->DayInYear(1, 3);
156  if (g_date->Date() >= d1) d1 += 365;
157  SimpleEvent_(d1, pl_bes_spring_plough, false, a_farm, a_field);
158  break;
159  }
160  break;
161 
162  // This is the first real farm operation
164  if (!a_farm->SpringPlough(a_field, 0.0, g_date->DayInYear(30, 3) - g_date->DayInYear())) {
165  SimpleEvent_(g_date->Date() + 1, pl_bes_spring_plough, true, a_farm, a_field);
166  break;
167  }
168 
169  SimpleEvent_(g_date->Date() + 1, pl_bes_spring_harrow, false, a_farm, a_field);
170  break;
172  if (!a_farm->SpringHarrow(a_field, 0.0, g_date->DayInYear(31, 3) - g_date->DayInYear())) {
173  SimpleEvent_(g_date->Date() + 1, pl_bes_spring_harrow, true, a_farm, a_field);
174  break;
175  }
176  d1 = g_date->Date() + 1;
177  if (d1 < g_date->OldDays() + g_date->DayInYear(15, 3)) {
178  d1 = g_date->OldDays() + g_date->DayInYear(15, 3);
179  }
180  if (a_farm->IsStockFarmer()) //Stock Farmer
181  {
182  SimpleEvent_(d1, pl_bes_ferti_s4, false, a_farm, a_field);
183  }
184  else SimpleEvent_(d1, pl_bes_ferti_p4, false, a_farm, a_field);
185  break;
186  case pl_bes_ferti_p4:
187  if (a_ev->m_lock || a_farm->DoIt(98))
188  {
189  if (!a_farm->FP_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
190  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_p4, true, a_farm, a_field);
191  break;
192  }
193  PL_BES_SPRING_FERTI = true;
194  }
195  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_p5, false, a_farm, a_field);
196  break;
197  case pl_bes_ferti_s4:
198  if (a_ev->m_lock || a_farm->DoIt(98))
199  {
200  if (!a_farm->FA_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
201  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_s4, true, a_farm, a_field);
202  break;
203  }
204  PL_BES_SPRING_FERTI = true;
205  }
206  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_s5, false, a_farm, a_field);
207  break;
208  case pl_bes_ferti_p5:
209  if (a_ev->m_lock || a_farm->DoIt(25))
210  {
211  if (!a_farm->FP_PK(a_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
212  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_p5, true, a_farm, a_field);
213  break;
214  }
215  PL_BES_SPRING_FERTI = true;
216  }
217  SimpleEvent_(g_date->Date() + 1, pl_bes_heavy_cultivator, false, a_farm, a_field);
218  break;
219  case pl_bes_ferti_s5:
220  if (a_ev->m_lock || a_farm->DoIt(25))
221  {
222  if (!a_farm->FA_PK(a_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
223  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_s5, true, a_farm, a_field);
224  break;
225  }
227  }
228  SimpleEvent_(g_date->Date() + 1, pl_bes_heavy_cultivator, false, a_farm, a_field);
229  break;
231  if (PL_BES_SPRING_FERTI == 1)
232  {
233  if (!a_farm->HeavyCultivatorAggregate(a_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
234  SimpleEvent_(g_date->Date() + 1, pl_bes_heavy_cultivator, true, a_farm, a_field);
235  break;
236  }
237  }
238  d1 = g_date->Date() + 1;
239  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 4)) {
240  d1 = g_date->OldDays() + g_date->DayInYear(1, 4);
241  }
242  SimpleEvent_(d1, pl_bes_preseeding_cultivator, false, a_farm, a_field);
243  break;
245  // 90% will do preseeding cultivation, the rest will do it together with sow
246  if (a_ev->m_lock || a_farm->DoIt(90))
247  {
248  if (!a_farm->PreseedingCultivator(a_field, 0.0, g_date->DayInYear(19, 4) - g_date->DayInYear())) {
249  SimpleEvent_(g_date->Date() + 1, pl_bes_preseeding_cultivator, true, a_farm, a_field);
250  break;
251  }
252  SimpleEvent_(g_date->Date() + 1, pl_bes_spring_sow, false, a_farm, a_field);
253  break;
254  }
255  SimpleEvent_(g_date->Date() + 1, pl_bes_preseeding_cultivator_sow, false, a_farm, a_field);
256  break;
257  case pl_bes_spring_sow:
258  if (!a_farm->SpringSow(a_field, 0.0, g_date->DayInYear(20, 4) - g_date->DayInYear())) {
259  SimpleEvent_(g_date->Date() + 1, pl_bes_spring_sow, true, a_farm, a_field);
260  break;
261  }
262  // Here is a fork leading to four parallel events
263  SimpleEvent_(g_date->Date() + 5, pl_bes_harrow_before_emergence, false, a_farm, a_field); // Harrowing before emergence, followed by thinning after emergence
264  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_bes_watering1, false, a_farm, a_field); // Watering thread
265  SimpleEvent_(g_date->Date() + 5, pl_bes_herbicide1, false, a_farm, a_field); // Herbicide thread
266  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 7), pl_bes_fungicide1, false, a_farm, a_field); // Fungicide thread = MAIN THREAD
267  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 6), pl_bes_insecticide, false, a_farm, a_field); // Insecticide thread
268  if (a_farm->IsStockFarmer()) //Stock Farmer
269  {
270  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(25, 4), pl_bes_ferti_s6, false, a_farm, a_field); // Fertilizers thread
271  }
272  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(25, 4), pl_bes_ferti_p6, false, a_farm, a_field);
273  break;
275  // 10% will do preseeding cultivation with sow
276  if (!a_farm->PreseedingCultivatorSow(a_field, 0.0, g_date->DayInYear(20, 4) - g_date->DayInYear())) {
277  SimpleEvent_(g_date->Date() + 1, pl_bes_preseeding_cultivator_sow, true, a_farm, a_field);
278  break;
279  }
280  // Here is a fork leading to four parallel events
281  SimpleEvent_(g_date->Date() + 5, pl_bes_harrow_before_emergence, false, a_farm, a_field); // Harrowing before emergence, followed by thinning after emergence
282  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_bes_watering1, false, a_farm, a_field); // Watering thread
283  SimpleEvent_(g_date->Date() + 5, pl_bes_herbicide1, false, a_farm, a_field); // Herbicide thread
284  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 7), pl_bes_fungicide1, false, a_farm, a_field); // Fungicide thread = MAIN THREAD
285  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 6), pl_bes_insecticide, false, a_farm, a_field); // Insecticide thread
286  if (a_farm->IsStockFarmer()) //Stock Farmer
287  {
288  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_bes_ferti_s6, false, a_farm, a_field); // Fertilizers thread
289  }
290  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_bes_ferti_p6, false, a_farm, a_field);
291  break;
293  if (a_field->GetGreenBiomass() <= 0)
294  {
295  if (a_ev->m_lock || a_farm->DoIt(3))
296  {
297  if (!a_farm->SpringHarrow(a_field, 0.0, g_date->DayInYear(25, 4) - g_date->DayInYear())) {
298  SimpleEvent_(g_date->Date() + 1, pl_bes_harrow_before_emergence, true, a_farm, a_field);
299  break;
300  }
301  }
302  SimpleEvent_(g_date->Date() + 5, pl_bes_thinning, false, a_farm, a_field);
303  break;
304  }
305  else {
306  SimpleEvent_(g_date->Date() + 1, pl_bes_thinning, false, a_farm, a_field);
307  }
308  break;
309  case pl_bes_thinning:
310  if (a_ev->m_lock || a_farm->DoIt(5))
311  {
312  if (a_field->GetGreenBiomass() <= 0) {
313  SimpleEvent_(g_date->Date() + 1, pl_bes_thinning, true, a_farm, a_field);
314  }
315  else
316  {
317  if (!a_farm->RowCultivation(a_field, 0.0, g_date->DayInYear(5, 5) - g_date->DayInYear())) {
318  SimpleEvent_(g_date->Date() + 1, pl_bes_thinning, true, a_farm, a_field);
319  break;
320  }
321  }
322  }
323  // End of thread
324  break;
325  case pl_bes_watering1:
326  if (a_ev->m_lock || a_farm->DoIt(3))
327  {
328  if (a_field->GetGreenBiomass() <= 0) {
329  SimpleEvent_(g_date->Date() + 1, pl_bes_watering1, true, a_farm, a_field);
330  }
331  else
332  {
333  if (!a_farm->Water(a_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
334  SimpleEvent_(g_date->Date() + 1, pl_bes_watering1, true, a_farm, a_field);
335  break;
336  }
337  PL_BES_WATER_DATE = g_date->Date();
338  }
339  d1 = g_date->Date() + 7;
340  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 6)) {
341  d1 = g_date->OldDays() + g_date->DayInYear(1, 6);
342  }
343  SimpleEvent_(d1, pl_bes_watering2, false, a_farm, a_field);
344  break;
345  }
346  break;
347 
348  case pl_bes_watering2:
349  if (!a_farm->Water(a_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
350  SimpleEvent_(g_date->Date() + 1, pl_bes_watering2, true, a_farm, a_field);
351  break;
352  }
353  PL_BES_WATER_DATE = g_date->Date();
354  d1 = g_date->Date() + 7;
355  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 7)) {
356  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
357  }
358  SimpleEvent_(d1, pl_bes_watering3, false, a_farm, a_field);
359  break;
360  case pl_bes_watering3:
361  if (!a_farm->Water(a_field, 0.0, g_date->DayInYear(31, 7) - g_date->DayInYear())) {
362  SimpleEvent_(g_date->Date() + 1, pl_bes_watering3, true, a_farm, a_field);
363  break;
364  }
365  PL_BES_WATER_DATE = g_date->Date();
366  // End of thread
367  break;
368  case pl_bes_ferti_p6:
369  // Here comes fertilizers thread
370  if (a_field->GetGreenBiomass() <= 0) {
371  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_p6, false, a_farm, a_field);
372  }
373  else
374  {
375  if (!a_farm->FP_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(25, 5) - g_date->DayInYear())) {
376  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_p6, true, a_farm, a_field);
377  break;
378  }
379  d1 = g_date->Date() + 1;
380  if (d1 < g_date->OldDays() + g_date->DayInYear(20, 5)) {
381  d1 = g_date->OldDays() + g_date->DayInYear(20, 5);
382  }
383  SimpleEvent_(d1, pl_bes_ferti_p7, false, a_farm, a_field);
384  break;
385  }
386  break;
387  case pl_bes_ferti_s6:
388  if (a_field->GetGreenBiomass() <= 0) {
389  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_s6, false, a_farm, a_field);
390  }
391  else
392  {
393  if (!a_farm->FA_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(25, 5) - g_date->DayInYear())) {
394  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_s6, true, a_farm, a_field);
395  break;
396  }
397  d1 = g_date->Date() + 1;
398  if (d1 < g_date->OldDays() + g_date->DayInYear(20, 5)) {
399  d1 = g_date->OldDays() + g_date->DayInYear(20, 5);
400  }
401  SimpleEvent_(d1, pl_bes_ferti_s7, false, a_farm, a_field);
402  break;
403  }
404  break;
405  case pl_bes_ferti_p7:
406  if (a_ev->m_lock || a_farm->DoIt(89))
407  {
408  if (!a_farm->FP_ManganeseSulphate(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
409  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_p7, true, a_farm, a_field);
410  break;
411  }
412  }
413  // End of thread
414  break;
415  case pl_bes_ferti_s7:
416  if (a_ev->m_lock || a_farm->DoIt(89))
417  {
418  if (!a_farm->FA_ManganeseSulphate(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
419  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_s7, true, a_farm, a_field);
420  break;
421  }
422  }
423  // End of thread
424  break;
425  case pl_bes_herbicide1: // The first of the pesticide managements.
426  // Here comes the herbicide thread
427  // We assume that farmers do max 3 herbicide treatments
428  if (a_field->GetGreenBiomass() <= 0)
429  {
430  if (a_ev->m_lock || a_farm->DoIt(43))
431  {
432  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(25, 4) - g_date->DayInYear())) {
433  SimpleEvent_(g_date->Date() + 1, pl_bes_herbicide1, true, a_farm, a_field);
434  break;
435  }
436  PL_BES_HERBI1 = true;
437  PL_BES_HERBI_DATE = g_date->Date();
438  }
439  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 5), pl_bes_herbicide2, false, a_farm, a_field);
440  break;
441  }
442  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 5), pl_bes_herbicide2, false, a_farm, a_field);
443  break;
444  case pl_bes_herbicide2:
445  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
446  SimpleEvent_(g_date->Date() + 1, pl_bes_herbicide2, true, a_farm, a_field);
447  break;
448  }
449  PL_BES_HERBI_DATE = g_date->Date();
450  SimpleEvent_(g_date->Date() + 10, pl_bes_herbicide3, false, a_farm, a_field);
451  break;
452  case pl_bes_herbicide3:
453  if (a_ev->m_lock || a_farm->DoIt(93))
454  {
455  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
456  SimpleEvent_(g_date->Date() + 1, pl_bes_herbicide3, true, a_farm, a_field);
457  break;
458  }
459  PL_BES_HERBI_DATE = g_date->Date();
460  PL_BES_HERBI3 = true;
461  }
462  SimpleEvent_(g_date->Date() + 10, pl_bes_herbicide4, false, a_farm, a_field);
463  break;
464  case pl_bes_herbicide4:
465  if (a_ev->m_lock || (a_farm->DoIt(81) && (PL_BES_HERBI1 == false || PL_BES_HERBI3 == false))) // which gives 46% of all farmers (and 81% of those who did not apply herbicides before beet emergence)
466  {
467  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(20, 6) - g_date->DayInYear())) {
468  SimpleEvent_(g_date->Date() + 1, pl_bes_herbicide4, true, a_farm, a_field);
469  break;
470  }
471  PL_BES_HERBI_DATE = g_date->Date();
472  }
473  // End of thread
474  break;
475  case pl_bes_fungicide1:
476  // Here comes the fungicide thread
477  if (a_ev->m_lock || a_farm->DoIt(83))
478  {
479  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(5, 8) - g_date->DayInYear())) {
480  SimpleEvent_(g_date->Date() + 1, pl_bes_fungicide1, true, a_farm, a_field);
481  break;
482  }
483  }
484  SimpleEvent_(g_date->Date() + 21, pl_bes_fungicide2, false, a_farm, a_field);
485  break;
486  case pl_bes_fungicide2:
487  if (a_ev->m_lock || a_farm->DoIt(63))
488  {
489  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(25, 8) - g_date->DayInYear())) {
490  SimpleEvent_(g_date->Date() + 1, pl_bes_fungicide2, true, a_farm, a_field);
491  break;
492  }
493  }
494  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(25, 9), pl_bes_harvest, false, a_farm, a_field);
495  break;
496  case pl_bes_insecticide:
497  // Here comes the insecticide thread
498 
499  if (PL_BES_HERBI_DATE >= g_date->Date() - 2) { // Should by at least 3 days after herbicide
500  SimpleEvent_(g_date->Date() + 1, pl_bes_insecticide, false, a_farm, a_field);
501  }
502  else
503  {
504  if (a_ev->m_lock || a_farm->DoIt(58))
505  {
506  // here we check wheter we are using ERA pesticide or not
507  if (!cfg_pest_beet_on.value() ||
508  !g_landscape_p->SupplyShouldSpray()) // Not using pesticide spray
509  {
510  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(25, 7) - g_date->DayInYear())) {
511  SimpleEvent_(g_date->Date() + 1, pl_bes_insecticide, true, a_farm, a_field);
512  break;
513  }
514  }
515  else {
516  a_farm->ProductApplication(a_field, 0.0, 0, cfg_pest_product_1_amount.value(), ppp_1);
517  }
518  }
519  }
520  // End of thread
521  break;
522  case pl_bes_harvest:
523  // Here the MAIN thread continues
524  // We don't move harvest days
525  if (!a_farm->Harvest(a_field, 0.0, a_field->GetMDates(0, 0) - g_date->DayInYear())) {
526  SimpleEvent_(g_date->Date() + 1, pl_bes_harvest, true, a_farm, a_field);
527  break;
528  }
529  if (a_farm->IsStockFarmer()) //Stock Farmer
530  {
531  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_s8, false, a_farm, a_field);
532  }
533  else SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_p8, false, a_farm, a_field);
534  break;
535 
536  case pl_bes_ferti_p8:
537  if (a_ev->m_lock || a_farm->DoIt(28))
538  {
539  if (a_field->GetMConstants(3) == 0) {
540  if (!a_farm->FP_Calcium(a_field, 0.0, -1)) { // raise an error
541  g_msg->Warn(WARN_BUG, "PLBeetSpr::Do(): failure in 'FP_Calcium' execution", "");
542  exit(1);
543  }
544  }
545  else {
546  if (!a_farm->FP_Calcium(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
547  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_p8, true, a_farm, a_field);
548  break;
549  }
550  }
551  }
552  done = true;
553  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
554  // END of MAIN THREAD
555  break;
556  case pl_bes_ferti_s8:
557  if (a_ev->m_lock || a_farm->DoIt(28))
558  {
559  if (a_field->GetMConstants(3) == 0) {
560  if (!a_farm->FA_Calcium(a_field, 0.0, -1)) { // raise an error
561  g_msg->Warn(WARN_BUG, "PLBeetSpr::Do(): failure in 'FA_Calcium' execution", "");
562  exit(1);
563  }
564  }
565  else {
566  if (!a_farm->FA_Calcium(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
567  SimpleEvent_(g_date->Date() + 1, pl_bes_ferti_s8, true, a_farm, a_field);
568  break;
569  }
570  }
571  }
572  done = true;
573  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
574  // END of MAIN THREAD
575  break;
576  default:
577  g_msg->Warn(WARN_BUG, "PLBeetSpr::Do(): "
578  "Unknown event type! ", "");
579  exit(1);
580  }
581  return done;
582 }
pl_bes_herbicide4
Definition: PLBeetSpr.h:61
PL_BES_HERBI1
#define PL_BES_HERBI1
Definition: PLBeetSpr.h:31
Farm::SpringPlough
virtual bool SpringPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the spring on a_field.
Definition: farmfuncs.cpp:444
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
Landscape::SupplyShouldSpray
bool SupplyShouldSpray()
Definition: Landscape.h:357
FarmEvent
A struct to hold the information required to trigger a farm event.
Definition: farm.h:463
pl_bes_spring_plough
Definition: PLBeetSpr.h:43
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
cfg_pest_beet_on
CfgBool cfg_pest_beet_on
PL_BES_WATER_DATE
#define PL_BES_WATER_DATE
Definition: PLBeetSpr.h:29
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
pl_bes_watering2
Definition: PLBeetSpr.h:56
PL_BES_HERBI3
#define PL_BES_HERBI3
Definition: PLBeetSpr.h:32
cfg_pest_product_1_amount
CfgFloat cfg_pest_product_1_amount
pl_bes_heavy_cultivator
Definition: PLBeetSpr.h:49
cfg_BES_InsecticideMonth
CfgInt cfg_BES_InsecticideMonth
pl_bes_ferti_s5
Definition: PLBeetSpr.h:48
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
pl_bes_watering1
Definition: PLBeetSpr.h:55
l_pest_insecticide_amount
CfgFloat l_pest_insecticide_amount
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
pl_bes_ferti_s6
Definition: PLBeetSpr.h:66
PL_BES_HERBI_DATE
#define PL_BES_HERBI_DATE
Definition: PLBeetSpr.h:30
pl_bes_ferti_p6
Definition: PLBeetSpr.h:65
pl_bes_insecticide
Definition: PLBeetSpr.h:64
pl_bes_herbicide1
Definition: PLBeetSpr.h:58
pl_bes_start
Definition: PLBeetSpr.h:41
pl_bes_spring_sow
Definition: PLBeetSpr.h:52
pl_bes_watering3
Definition: PLBeetSpr.h:57
pl_bes_ferti_p7
Definition: PLBeetSpr.h:67
pl_bes_ferti_p5
Definition: PLBeetSpr.h:47
pl_bes_preseeding_cultivator_sow
Definition: PLBeetSpr.h:51
pl_bes_ferti_p4
Definition: PLBeetSpr.h:45
pl_bes_herbicide2
Definition: PLBeetSpr.h:59
pl_bes_fungicide1
Definition: PLBeetSpr.h:62
pl_bes_thinning
Definition: PLBeetSpr.h:54
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
pl_bes_ferti_s7
Definition: PLBeetSpr.h:68
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
pl_bes_ferti_p8
Definition: PLBeetSpr.h:70
ppp_1
Definition: farm.h:422
pl_bes_harvest
Definition: PLBeetSpr.h:69
pl_bes_spring_harrow
Definition: PLBeetSpr.h:44
pl_bes_ferti_s8
Definition: PLBeetSpr.h:71
Farm
The base class for all farm types.
Definition: farm.h:767
pl_bes_harrow_before_emergence
Definition: PLBeetSpr.h:53
pl_bes_ferti_s4
Definition: PLBeetSpr.h:46
pl_bes_herbicide3
Definition: PLBeetSpr.h:60
pl_bes_preseeding_cultivator
Definition: PLBeetSpr.h:50
PL_BES_SPRING_FERTI
#define PL_BES_SPRING_FERTI
A flag used to indicate autumn ploughing status.
Definition: PLBeetSpr.h:28
PLBeetSpr::Do
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.
Definition: PLBeetSpr.cpp:64
cfg_BES_InsecticideDay
CfgInt cfg_BES_InsecticideDay
pl_bes_fungicide2
Definition: PLBeetSpr.h:63
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