ALMaSS Vole ODDox  1.1
The vole model description following ODdox protocol
PLBeans.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 // PLBeans.cpp
40 //
41 
42 
43 #include "../../Landscape/ls.h"
44 #include "../../Landscape/cropprogs/PLBeans.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_springbarley_on;
49 // check if below are needed
50 extern CfgFloat l_pest_insecticide_amount;
51 extern CfgInt cfg_BNS_InsecticideDay;
52 extern CfgInt cfg_BNS_InsecticideMonth;
53 extern CfgFloat cfg_pest_product_1_amount;
54 
55 
64 bool PLBeans::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_bns_start:
72  {
73  // pl_bns_start just sets up all the starting conditions and reference dates that are needed to start a pl_sb
74  PL_BNS_FERTI_P1 = false;
75  PL_BNS_FERTI_S1 = false;
76  PL_BNS_STUBBLE_PLOUGH = false;
77  PL_BNS_HERBI = false;
78 
79  // Set up the date management stuff
80  // The next bit of code just allows for altering dates after harvest if it is necessary
81  // to allow for a crop which starts its management early.
82 
83  // 5 start and stop dates for all 'movable' events for this crop
84  int noDates = 2;
85  a_field->SetMDates(0, 0, g_date->DayInYear(30, 9)); // last possible day of harvest
86  a_field->SetMDates(1, 0, g_date->DayInYear(30, 9));
87  a_field->SetMDates(0, 1, 0); // start day of calcium application
88  a_field->SetMDates(1, 1, g_date->DayInYear(5, 10)); // end day of calcium application
89  // Can be up to 10 of these. If the shortening code is triggered
90  // then these will be reduced in value to 0
91 
92  a_field->SetMConstants(0, 1);
93 
94  // Check the next crop for early start, unless it is a spring crop
95  // in which case we ASSUME that no checking is necessary!!!!
96  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
97 
98  //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)
99  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
100  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
101 
102  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
103  if (a_field->GetMDates(0, 0) >= a_ev->m_startday)
104  {
105  g_msg->Warn(WARN_BUG, "PLBeans::Do(): ", "Harvest too late for the next crop to start!!!");
106  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
107  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
108  }
109  // Now fix any late finishing problems
110  for (int i = 0; i < noDates; i++) {
111  if (a_field->GetMDates(0, i) >= a_ev->m_startday) {
112  a_field->SetMDates(0, i, a_ev->m_startday - 1); //move the starting date
113  }
114  if (a_field->GetMDates(1, i) >= a_ev->m_startday) {
115  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)
116  a_field->SetMDates(1, i, a_ev->m_startday - 1); //move the finishing date
117  }
118  }
119  }
120  // Now no operations can be timed after the start of the next crop.
121 
122  if (!a_ev->m_first_year) {
123  // Are we before July 1st?
124  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
125  if (g_date->Date() < d1) {
126  // Yes, too early. We assumme this is because the last crop was late
127  printf("Poly: %d\n", a_field->GetPoly());
128  g_msg->Warn(WARN_BUG, "PLBeans::Do(): ", "Crop start attempt between 1st Jan & 1st July");
129  int prev = g_landscape_p->BackTranslateVegTypes(a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex()));
130  g_msg->Warn(WARN_BUG, "Previous Crop ", prev);
131  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
132  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
133  }
134  else {
135  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
136  if (g_date->Date() > d1) {
137  // Yes too late - should not happen - raise an error
138  g_msg->Warn(WARN_BUG, "PLBeans::Do(): ", "Crop start attempt after last possible start date");
139  g_msg->Warn(WARN_BUG, "Previous Crop ", "");
140  a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex());
141  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
142  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
143  }
144  }
145  }
146  else {
147  // Is the first year
148  // Some special code to cope with that first start-up year in ALMaSS - ignore for all practical purposes
149  // Code for first spring treatment used
150  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 3), pl_bns_spring_harrow, false, a_farm, a_field);
151  break;
152  }
153  }//if
154 
155  // End single block date checking code. Please see next line comment as well.
156  // Reinit d1 to first possible starting date.
157  d1 = g_date->OldDays() + g_date->DayInYear(20, 7);
158  // OK, let's go.
159  // Here we queue up the first event - this differs depending on whether we have a
160  // stock or arable farmer
161  if (a_farm->IsStockFarmer()) { // StockFarmer
162  SimpleEvent_(d1, pl_bns_ferti_s1, false, a_farm, a_field);
163  }
164  else SimpleEvent_(d1, pl_bns_ferti_p1, false, a_farm, a_field);
165  }
166  break;
167 
168  // This is the first real farm operation
169  case pl_bns_ferti_p1:
170  // In total 10% of arable farmers do slurry in the autumn, either before stubble plough/harrow or later before autumn plough/cultivation
171  // We therefore assume that half of them (5%) do it now
172  if (a_ev->m_lock || a_farm->DoIt(5))
173  {
174  if (!a_farm->FP_Slurry(a_field, 0.0, g_date->DayInYear(5, 11) - g_date->DayInYear())) {
175  // If we don't suceed on the first try, then try and try again (until 20/8 when we will suceed)
176  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_p1, true, a_farm, a_field);
177  break;
178  }
179  else
180  {
181  //Rest of farmers do slurry before autumn plough/stubble cultivation so we need to remeber who already did it
182  PL_BNS_FERTI_P1 = true;
183  }
184  }
185  // Queue up the next event -in this case stubble ploughing
186  SimpleEvent_(g_date->Date() + 1, pl_bns_stubble_plough, false, a_farm, a_field);
187  break;
188  case pl_bns_ferti_s1:
189  // In total 40% of stock farmers do slurry in the autumn, either before stubble plough/harrow or later before autumn plough/cultivation
190  // We therefore assume that half of them (40%) do it now
191  if (a_ev->m_lock || a_farm->DoIt(40))
192  {
193  if (!a_farm->FA_Slurry(a_field, 0.0, g_date->DayInYear(5, 11) - g_date->DayInYear())) {
194  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_s1, true, a_farm, a_field);
195  break;
196  }
197  else
198  {
199  //Rest of farmers do slurry before autumn plough/stubble cultivation so we need to remeber who already did it
200  PL_BNS_FERTI_S1 = true;
201  }
202  }
203  // Queue up the next event -in this case stubble ploughing
204  SimpleEvent_(g_date->Date() + 1, pl_bns_stubble_plough, false, a_farm, a_field);
205  break;
207  // 50% will do stubble plough, but rest will get away with non-inversion cultivation
208  if (a_ev->m_lock || a_farm->DoIt(50))
209  {
210  if (!a_farm->StubblePlough(a_field, 0.0, g_date->DayInYear(5, 11) - g_date->DayInYear())) {
211  SimpleEvent_(g_date->Date() + 1, pl_bns_stubble_plough, true, a_farm, a_field);
212  break;
213  }
214  else
215  {
216  // 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
217  PL_BNS_STUBBLE_PLOUGH = true;
218  // Queue up the next event
219  SimpleEvent_(g_date->Date() + 1, pl_bns_autumn_harrow1, false, a_farm, a_field);
220  break;
221  }
222  }
223  SimpleEvent_(g_date->Date() + 1, pl_bns_stubble_harrow, false, a_farm, a_field);
224  break;
226  if (!a_farm->AutumnHarrow(a_field, 0.0, g_date->DayInYear(5, 11) - g_date->DayInYear())) {
227  SimpleEvent_(g_date->Date() + 1, pl_bns_autumn_harrow1, true, a_farm, a_field);
228  break;
229  }
230  SimpleEvent_(g_date->Date() + 2, pl_bns_autumn_harrow2, false, a_farm, a_field);
231  break;
233  if (a_ev->m_lock || a_farm->DoIt(40))
234  {
235  if (!a_farm->AutumnHarrow(a_field, 0.0, g_date->Date() + 7 - g_date->DayInYear())) {
236  SimpleEvent_(g_date->Date() + 1, pl_bns_autumn_harrow2, true, a_farm, a_field);
237  break;
238  }
239  }
240  d1 = g_date->Date() + 1;
241  if (d1 < g_date->OldDays() + g_date->DayInYear(10, 9)) {
242  d1 = g_date->OldDays() + g_date->DayInYear(10, 9);
243  }
244  if (a_farm->IsStockFarmer()) //Stock Farmer
245  {
246  SimpleEvent_(d1, pl_bns_ferti_s2, false, a_farm, a_field);
247  }
248  else SimpleEvent_(d1, pl_bns_ferti_p2, false, a_farm, a_field);
249  break;
251  if (!a_farm->StubbleHarrowing(a_field, 0.0, g_date->DayInYear(10, 11) - g_date->DayInYear())) {
252  SimpleEvent_(g_date->Date() + 1, pl_bns_stubble_harrow, true, a_farm, a_field);
253  break;
254  }
255  d1 = g_date->Date() + 1;
256  if (d1 < g_date->OldDays() + g_date->DayInYear(10, 9)) {
257  d1 = g_date->OldDays() + g_date->DayInYear(10, 9);
258  }
259  if (a_farm->IsStockFarmer()) //Stock Farmer
260  {
261  SimpleEvent_(d1, pl_bns_ferti_s2, false, a_farm, a_field);
262  }
263  else SimpleEvent_(d1, pl_bns_ferti_p2, false, a_farm, a_field);
264  break;
265  case pl_bns_ferti_p2:
266  // In total 10% of arable farmers do slurry in the autumn, either before stubble plough/harrow or later before autumn plough/cultivation
267  // We therefore assume that half of them (5%) do it now (if haven't done before)
268  if ((a_ev->m_lock || a_farm->DoIt(static_cast<int>((5.0 / 95.0) * 100))) && (PL_BNS_FERTI_P1 == false))
269  {
270  if (!a_farm->FP_Slurry(a_field, 0.0, g_date->DayInYear(15, 11) - g_date->DayInYear())) {
271  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_p2, true, a_farm, a_field);
272  break;
273  }
274  }
275  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_p3, false, a_farm, a_field);
276  break;
277  case pl_bns_ferti_s2:
278  // In total 80% of stock 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 (40%) do it now (if haven't done before)
280  if ((a_ev->m_lock || a_farm->DoIt(static_cast<int>((40.0 / 60.0) * 100))) && (PL_BNS_FERTI_S1 == false))
281  {
282  if (!a_farm->FA_Slurry(a_field, 0.0, g_date->DayInYear(15, 11) - g_date->DayInYear())) {
283  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_s2, true, a_farm, a_field);
284  break;
285  }
286  }
287  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_s3, false, a_farm, a_field);
288  break;
289  case pl_bns_ferti_p3:
290  if (a_ev->m_lock || a_farm->DoIt(80))
291  {
292  if (!a_farm->FP_PK(a_field, 0.0, g_date->DayInYear(15, 11) - g_date->DayInYear())) {
293  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_p3, true, a_farm, a_field);
294  break;
295  }
296  }
297  SimpleEvent_(g_date->Date() + 1, pl_bns_winter_plough, false, a_farm, a_field);
298  break;
299  case pl_bns_ferti_s3:
300  if (a_ev->m_lock || a_farm->DoIt(80))
301  {
302  if (!a_farm->FA_PK(a_field, 0.0, g_date->DayInYear(15, 11) - g_date->DayInYear())) {
303  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_s3, true, a_farm, a_field);
304  break;
305  }
306  }
307  SimpleEvent_(g_date->Date() + 1, pl_bns_winter_plough, false, a_farm, a_field);
308  break;
310  if (!a_farm->WinterPlough(a_field, 0.0, g_date->DayInYear(15, 11) - g_date->DayInYear())) {
311  SimpleEvent_(g_date->Date() + 1, pl_bns_winter_plough, true, a_farm, a_field);
312  break;
313  }
314  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 3) + 365, pl_bns_spring_harrow, false, a_farm, a_field);
315  break;
317  if (a_ev->m_lock || a_farm->DoIt(90))
318  {
319  if (!a_farm->SpringHarrow(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
320  SimpleEvent_(g_date->Date() + 1, pl_bns_spring_harrow, true, a_farm, a_field);
321  break;
322  }
323  }
324  d1 = g_date->Date() + 1;
325  if (d1 < g_date->OldDays() + g_date->DayInYear(20, 4)) {
326  d1 = g_date->OldDays() + g_date->DayInYear(20, 4);
327  }
328  if (a_farm->IsStockFarmer()) //Stock Farmer
329  {
330  SimpleEvent_(d1, pl_bns_ferti_s4, false, a_farm, a_field);
331  }
332  else SimpleEvent_(d1, pl_bns_ferti_p4, false, a_farm, a_field);
333  break;
334  case pl_bns_ferti_p4:
335  if (!a_farm->FP_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(30, 5) - g_date->DayInYear())) {
336  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_p4, true, a_farm, a_field);
337  break;
338  }
339  SimpleEvent_(g_date->Date() + 1, pl_bns_heavy_cultivator, false, a_farm, a_field);
340  break;
341  case pl_bns_ferti_s4:
342  if (!a_farm->FA_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(30, 5) - g_date->DayInYear())) {
343  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_s4, true, a_farm, a_field);
344  break;
345  }
346  SimpleEvent_(g_date->Date() + 1, pl_bns_heavy_cultivator, false, a_farm, a_field);
347  break;
349  if (!a_farm->HeavyCultivatorAggregate(a_field, 0.0, g_date->DayInYear(30, 5) - g_date->DayInYear())) {
350  SimpleEvent_(g_date->Date() + 1, pl_bns_heavy_cultivator, true, a_farm, a_field);
351  break;
352  }
353  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 5), pl_bns_preseeding_cultivator, false, a_farm, a_field);
354  break;
356  if (a_ev->m_lock || a_farm->DoIt(80))
357  {
358  if (!a_farm->PreseedingCultivator(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
359  SimpleEvent_(g_date->Date() + 1, pl_bns_preseeding_cultivator, true, a_farm, a_field);
360  break;
361  }
362  }
363  SimpleEvent_(g_date->Date() + 1, pl_bns_spring_sow, false, a_farm, a_field);
364  break;
365  case pl_bns_spring_sow:
366  if (!a_farm->SpringSow(a_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
367  SimpleEvent_(g_date->Date() + 1, pl_bns_spring_sow, true, a_farm, a_field);
368  break;
369  }
370  // Here is a fork leading to four parallel events
371  SimpleEvent_(g_date->Date() + 1, pl_bns_herbicide1, false, a_farm, a_field); // Herbidide thread
372  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 7), pl_bns_fungicide1, false, a_farm, a_field); // Fungicide thread = MAIN thread
373  SimpleEvent_(g_date->Date() + 5, pl_bns_insecticide, false, a_farm, a_field); // Insecticide thread
374  if (a_farm->IsStockFarmer()) //Stock Farmer // fertilizers thread
375  {
376  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_bns_ferti_s5, false, a_farm, a_field);
377  }
378  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), pl_bns_ferti_p5, false, a_farm, a_field);
379  break;
380  case pl_bns_ferti_p5:
381  // Here comes fertilizers thread
382  if (a_ev->m_lock || a_farm->DoIt(40))
383  {
384  if (!a_farm->FP_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
385  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_p5, true, a_farm, a_field);
386  break;
387  }
388  }
389  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 6), pl_bns_ferti_p6, false, a_farm, a_field);
390  break;
391  case pl_bns_ferti_s5:
392  if (a_ev->m_lock || a_farm->DoIt(40))
393  {
394  if (!a_farm->FA_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
395  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_s5, true, a_farm, a_field);
396  break;
397  }
398  }
399  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 6), pl_bns_ferti_s6, false, a_farm, a_field);
400  break;
401  case pl_bns_ferti_p6:
402  // Here comes the mickroelements thread
403  if (a_ev->m_lock || a_farm->DoIt(80))
404  {
405  if (!a_farm->FP_ManganeseSulphate(a_field, 0.0, g_date->DayInYear(10, 7) - g_date->DayInYear())) {
406  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_p6, true, a_farm, a_field);
407  break;
408  }
409  }
410  // End of thread
411  break;
412  case pl_bns_ferti_s6:
413  if (a_ev->m_lock || a_farm->DoIt(80))
414  {
415  if (!a_farm->FA_ManganeseSulphate(a_field, 0.0, g_date->DayInYear(10, 7) - g_date->DayInYear())) {
416  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_s6, true, a_farm, a_field);
417  break;
418  }
419  }
420  // End of thread
421  break;
422  case pl_bns_herbicide1: // The first of the pesticide managements.
423  if (a_field->GetGreenBiomass() <= 0)
424  {
425  if (a_ev->m_lock || a_farm->DoIt(50))
426  {
427  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->Date() + 5 - g_date->DayInYear())) {
428  SimpleEvent_(g_date->Date() + 1, pl_bns_herbicide1, true, a_farm, a_field);
429  break;
430  }
431  }
432  // 50% of farmers will do herbicide treatment after emergence followed by one weeding treatment; the rest will do 2/3 weeding treatments
433  if (m_farm->DoIt(50)) {
434  SimpleEvent_(g_date->Date() + 7, pl_bns_herbicide2, false, a_farm, a_field);
435  }
436  else {
437  SimpleEvent_(g_date->Date() + 7, pl_bns_weeding1, false, a_farm, a_field);
438  }
439  break;
440  }
441  // 50% of farmers will do herbicide treatment after emergence followed by one weeding treatment; the rest will do 2/3 weeding treatments
442  if (m_farm->DoIt(50)) {
443  SimpleEvent_(g_date->Date() + 1, pl_bns_herbicide2, false, a_farm, a_field);}
444  else {
445  SimpleEvent_(g_date->Date() + 1, pl_bns_weeding1, false, a_farm, a_field);}
446  break;
447  case pl_bns_herbicide2:
448  if (a_field->GetGreenBiomass() <= 0) {
449  SimpleEvent_(g_date->Date() + 1, pl_bns_herbicide2, true, a_farm, a_field);
450  }
451  else
452  {
453  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
454  SimpleEvent_(g_date->Date() + 1, pl_bns_herbicide2, true, a_farm, a_field);
455  break;
456  }
457  PL_BNS_HERBI = true;
458  SimpleEvent_(g_date->Date() + 10, pl_bns_weeding2, false, a_farm, a_field);
459  break;
460  }
461  break;
462  case pl_bns_weeding1:
463  if (a_field->GetGreenBiomass() <= 0) {
464  SimpleEvent_(g_date->Date() + 1, pl_bns_weeding1, false, a_farm, a_field);
465  }
466  else
467  {
468  if (!a_farm->RowCultivation(a_field, 0.0, g_date->DayInYear(25, 6) - g_date->DayInYear())) {
469  SimpleEvent_(g_date->Date() + 1, pl_bns_weeding1, true, a_farm, a_field);
470  break;
471  }
472  SimpleEvent_(g_date->Date() + 20, pl_bns_weeding2, false, a_farm, a_field);
473  break;
474  }
475  break;
476  case pl_bns_weeding2:
477  if (!a_farm->RowCultivation(a_field, 0.0, g_date->DayInYear(15, 7) - g_date->DayInYear())) {
478  SimpleEvent_(g_date->Date() + 1, pl_bns_weeding2, true, a_farm, a_field);
479  break;
480  }
481  SimpleEvent_(g_date->Date() + 20, pl_bns_weeding3, false, a_farm, a_field);
482  break;
483  case pl_bns_weeding3:
484  if (a_ev->m_lock || a_farm->DoIt(40) && (PL_BNS_HERBI == false)) // which means 20% of farmers who didn't do herbicide2
485  {
486  if (!a_farm->RowCultivation(a_field, 0.0, g_date->DayInYear(5, 8) - g_date->DayInYear())) {
487  SimpleEvent_(g_date->Date() + 1, pl_bns_weeding3, true, a_farm, a_field);
488  break;
489  }
490  }
491  // End of thread
492  break;
493  case pl_bns_fungicide1:
494  // Here comes the fungicide thread = MAIN thread
495  if (a_ev->m_lock || a_farm->DoIt(80))
496  {
497  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(5, 8) - g_date->DayInYear())) {
498  SimpleEvent_(g_date->Date() + 1, pl_bns_fungicide1, true, a_farm, a_field);
499  break;
500  }
501  }
502  SimpleEvent_(g_date->Date() + 14, pl_bns_fungicide2, false, a_farm, a_field);
503  break;
504  case pl_bns_fungicide2:
505  if (a_ev->m_lock || a_farm->DoIt(40))
506  {
507  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(20, 8) - g_date->DayInYear())) {
508  SimpleEvent_(g_date->Date() + 1, pl_bns_fungicide2, true, a_farm, a_field);
509  break;
510  }
511  }
512  d1 = g_date->Date() + 14;
513  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 8)) {
514  d1 = g_date->OldDays() + g_date->DayInYear(1, 8);
515  }
516  SimpleEvent_(d1, pl_bns_harvest, false, a_farm, a_field);
517  break;
518  case pl_bns_insecticide:
519  // Here comes the insecticide thread
520  if (a_field->GetGreenBiomass() <= 0) {
521  SimpleEvent_(g_date->Date() + 1, pl_bns_insecticide, false, a_farm, a_field);
522  }
523  else {
524  if (a_ev->m_lock || a_farm->DoIt(50))
525  {
526  // here we check wheter we are using ERA pesticide or not
527  if (!cfg_pest_springbarley_on.value() ||
528  !g_landscape_p->SupplyShouldSpray()) // Not using pesticide spray
529  {
530  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
531  SimpleEvent_(g_date->Date() + 1, pl_bns_insecticide, true, a_farm, a_field);
532  break;
533  }
534  }
535  else {
536  a_farm->ProductApplication(a_field, 0.0, 0, cfg_pest_product_1_amount.value(), ppp_1);
537  }
538  }
539  }
540  // End of thread
541  break;
542  case pl_bns_harvest:
543  // Here the MAIN thread continues
544  // We don't move harvest days
545  if (!a_farm->Harvest(a_field, 0.0, a_field->GetMDates(0, 0) - g_date->DayInYear())) {
546  SimpleEvent_(g_date->Date() + 1, pl_bns_harvest, true, a_farm, a_field);
547  break;
548  }
549  if (a_farm->IsStockFarmer()) //Stock Farmer
550  {
551  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_s7, false, a_farm, a_field);
552  }
553  else SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_p7, false, a_farm, a_field);
554  break;
555  case pl_bns_ferti_p7:
556  if (a_ev->m_lock || a_farm->DoIt(25))
557  {
558  if (a_field->GetMConstants(1) == 0) {
559  if (!a_farm->FP_Calcium(a_field, 0.0, -1)) { // raise an error
560  g_msg->Warn(WARN_BUG, "PLBeans::Do(): failure in 'FP_Calcium' execution", "");
561  exit(1);
562  }
563  }
564  else {
565  if (!a_farm->FP_Calcium(a_field, 0.0, a_field->GetMDates(1, 1) - g_date->DayInYear())) {
566  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_p7, true, a_farm, a_field);
567  break;
568  }
569  }
570  }
571  done = true;
572  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
573  // END of MAIN THREAD
574  break;
575  case pl_bns_ferti_s7:
576  if (a_ev->m_lock || a_farm->DoIt(25))
577  {
578  if (a_field->GetMConstants(1) == 0) {
579  if (!a_farm->FA_Calcium(a_field, 0.0, -1)) { // raise an error
580  g_msg->Warn(WARN_BUG, "PLBeans::Do(): failure in 'FA_Calcium' execution", "");
581  exit(1);
582  }
583  }
584  else {
585  if (!a_farm->FA_Calcium(a_field, 0.0, a_field->GetMDates(1, 1) - g_date->DayInYear())) {
586  SimpleEvent_(g_date->Date() + 1, pl_bns_ferti_s7, true, a_farm, a_field);
587  break;
588  }
589  }
590  }
591  done = true;
592  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
593  // END of MAIN THREAD
594  break;
595  default:
596  g_msg->Warn(WARN_BUG, "PLBeans::Do(): "
597  "Unknown event type! ", "");
598  exit(1);
599  }
600  return done;
601 }
PL_BNS_FERTI_P1
#define PL_BNS_FERTI_P1
A flag used to indicate autumn ploughing status.
Definition: PLBeans.h:28
pl_bns_ferti_p3
Definition: PLBeans.h:49
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
pl_bns_ferti_s6
Definition: PLBeans.h:69
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
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
pl_bns_stubble_harrow
Definition: PLBeans.h:46
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
pl_bns_fungicide1
Definition: PLBeans.h:63
PLBeans::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: PLBeans.cpp:64
pl_bns_herbicide1
Definition: PLBeans.h:61
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
pl_bns_ferti_s1
Definition: PLBeans.h:42
pl_bns_ferti_p2
Definition: PLBeans.h:47
pl_bns_ferti_p6
Definition: PLBeans.h:68
pl_bns_ferti_s7
Definition: PLBeans.h:72
PL_BNS_HERBI
#define PL_BNS_HERBI
Definition: PLBeans.h:31
pl_bns_harvest
Definition: PLBeans.h:70
pl_bns_weeding2
Definition: PLBeans.h:59
pl_bns_ferti_p5
Definition: PLBeans.h:66
pl_bns_spring_sow
Definition: PLBeans.h:57
pl_bns_autumn_harrow2
Definition: PLBeans.h:45
pl_bns_heavy_cultivator
Definition: PLBeans.h:55
PL_BNS_FERTI_S1
#define PL_BNS_FERTI_S1
Definition: PLBeans.h:29
l_pest_insecticide_amount
CfgFloat l_pest_insecticide_amount
pl_bns_herbicide2
Definition: PLBeans.h:62
pl_bns_spring_harrow
Definition: PLBeans.h:52
pl_bns_ferti_s3
Definition: PLBeans.h:50
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
pl_bns_ferti_s2
Definition: PLBeans.h:48
PL_BNS_STUBBLE_PLOUGH
#define PL_BNS_STUBBLE_PLOUGH
Definition: PLBeans.h:30
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
pl_bns_ferti_s5
Definition: PLBeans.h:67
cfg_BNS_InsecticideDay
CfgInt cfg_BNS_InsecticideDay
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_bns_fungicide2
Definition: PLBeans.h:64
pl_bns_ferti_p1
Definition: PLBeans.h:41
pl_bns_stubble_plough
Definition: PLBeans.h:43
Farm
The base class for all farm types.
Definition: farm.h:767
pl_bns_start
Definition: PLBeans.h:39
pl_bns_winter_plough
Definition: PLBeans.h:51
pl_bns_weeding3
Definition: PLBeans.h:60
pl_bns_insecticide
Definition: PLBeans.h:65
pl_bns_ferti_p7
Definition: PLBeans.h:71
pl_bns_ferti_s4
Definition: PLBeans.h:54
cfg_pest_springbarley_on
CfgBool cfg_pest_springbarley_on
pl_bns_autumn_harrow1
Definition: PLBeans.h:44
pl_bns_ferti_p4
Definition: PLBeans.h:53
pl_bns_preseeding_cultivator
Definition: PLBeans.h:56
cfg_pest_product_1_amount
CfgFloat cfg_pest_product_1_amount
g_landscape_p
Landscape * g_landscape_p
Definition: Landscape.cpp:258
pl_bns_weeding1
Definition: PLBeans.h:58
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
cfg_BNS_InsecticideMonth
CfgInt cfg_BNS_InsecticideMonth