ALMaSS Vole ODDox  1.1
The vole model description following ODdox protocol
PLSpringBarleySpr.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 // PLSpringBarleySpr.cpp
40 //
41 
42 
43 #include "../../Landscape/ls.h"
44 #include "../../Landscape/cropprogs/PLSpringBarleySpr.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_SBS_InsecticideDay;
52 extern CfgInt cfg_SBS_InsecticideMonth;
53 extern CfgFloat cfg_pest_product_1_amount;
54 
55 
64 bool PLSpringBarleySpr::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_sbs_start:
72  {
73  // pl_sbs_start just sets up all the starting conditions and reference dates that are needed to start a pl_sb
75  PL_SBS_DECIDE_TO_GR = false;
76 
77  // Set up the date management stuff
78  // The next bit of code just allows for altering dates after harvest if it is necessary
79  // to allow for a crop which starts its management early.
80 
81  // 5 start and stop dates for all 'movable' events for this crop
82  int noDates = 4;
83  a_field->SetMDates(0, 0, g_date->DayInYear(15, 8)); // last possible day of harvest
84  a_field->SetMDates(1, 0, g_date->DayInYear(20, 8)); // last possible day of starw chopping, equal to harvest in this case
85  a_field->SetMDates(0, 1, 0); // start day of hay bailing (not used as it depend on previous treatment)
86  a_field->SetMDates(1, 1, g_date->DayInYear(25, 8)); // end day of hay bailing
87  a_field->SetMDates(0, 2, 0); // start day of RSM
88  a_field->SetMDates(1, 2, g_date->DayInYear(25, 8)); // end day of RSM
89  a_field->SetMDates(0, 3, 0); // start day of calcium application
90  a_field->SetMDates(1, 3, g_date->DayInYear(25, 8)); // end day of calcium application
91  // Can be up to 10 of these. If the shortening code is triggered
92  // then these will be reduced in value to 0
93 
94  a_field->SetMConstants(0, 1);
95 
96  // Check the next crop for early start, unless it is a spring crop
97  // in which case we ASSUME that no checking is necessary!!!!
98  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
99 
100  //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)
101  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
102  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
103 
104  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
105  if (a_field->GetMDates(0, 0) >= a_ev->m_startday)
106  {
107  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): ", "Harvest too late for the next crop to start!!!");
108  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
109  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
110  }
111  // Now fix any late finishing problems
112  for (int i = 0; i < noDates; i++) {
113  if (a_field->GetMDates(0, i) >= a_ev->m_startday) {
114  a_field->SetMDates(0, i, a_ev->m_startday - 1); //move the starting date
115  }
116  if (a_field->GetMDates(1, i) >= a_ev->m_startday) {
117  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)
118  a_field->SetMDates(1, i, a_ev->m_startday - 1); //move the finishing date
119  }
120  }
121  }
122  // Now no operations can be timed after the start of the next crop.
123 
124  if (!a_ev->m_first_year) {
125  int today = g_date->Date();
126  d1 = g_date->OldDays() + m_first_date + 365; // Add 365 for spring crop
127  if (today > d1) {
128  // Yes too late - should not happen - raise an error
129  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): " "Crop start attempt after last possible start date", "");
130  exit(1);
131  }
132  }
133  else {
134  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 3), pl_sbs_spring_plough, false, a_farm, a_field);
135  break;
136  }
137  }//if
138 
139  // End single block date checking code. Please see next line
140  // comment as well.
141  // Reinit d1 to first possible starting date.
142  d1 = g_date->OldDays() + 365 + g_date->DayInYear(1, 3);
143  // OK, let's go.
144  SimpleEvent_(d1, pl_sbs_spring_plough, false, a_farm, a_field);
145  break;
146  }
147  break;
148 
149  // This is the first real farm operation
151  if (!a_farm->SpringPlough(a_field, 0.0, g_date->DayInYear(25, 3) - g_date->DayInYear())) {
152  SimpleEvent_(g_date->Date() + 1, pl_sbs_spring_plough, true, a_farm, a_field);
153  break;
154  }
155  SimpleEvent_(g_date->Date() + 1, pl_sbs_spring_harrow, false, a_farm, a_field);
156  break;
158  if (!a_farm->SpringHarrow(a_field, 0.0, g_date->DayInYear(25, 3) - g_date->DayInYear())) {
159  SimpleEvent_(g_date->Date() + 1, pl_sbs_spring_harrow, true, a_farm, a_field);
160  break;
161  }
162  d1 = g_date->Date() + 1;
163  if (d1 < g_date->OldDays() + g_date->DayInYear(10, 3)) {
164  d1 = g_date->OldDays() + g_date->DayInYear(10, 3);
165  }
166  if (a_farm->IsStockFarmer()) //Stock Farmer
167  {
168  SimpleEvent_(d1, pl_sbs_ferti_s1, false, a_farm, a_field);
169  }
170  else SimpleEvent_(d1, pl_sbs_ferti_p1, false, a_farm, a_field);
171  break;
172  case pl_sbs_ferti_p1:
173  if (a_ev->m_lock || a_farm->DoIt(88))
174  {
175  if (!a_farm->FP_NPK(a_field, 0.0, g_date->DayInYear(30, 3) - g_date->DayInYear())) {
176  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_p1, true, a_farm, a_field);
177  break;
178  }
179  PL_SBS_SPRING_FERTI = true;
180  }
181  SimpleEvent_(g_date->Date() + 1, pl_sbs_heavy_cultivator, false, a_farm, a_field);
182  break;
183  case pl_sbs_ferti_s1:
184  if (a_ev->m_lock || a_farm->DoIt(88))
185  {
186  if (!a_farm->FA_NPK(a_field, 0.0, g_date->DayInYear(30, 3) - g_date->DayInYear())) {
187  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_s1, true, a_farm, a_field);
188  break;
189  }
191  }
192  SimpleEvent_(g_date->Date() + 1, pl_sbs_heavy_cultivator, false, a_farm, a_field);
193  break;
195  if (PL_SBS_SPRING_FERTI == 1)
196  {
197  if (!a_farm->HeavyCultivatorAggregate(a_field, 0.0, g_date->DayInYear(30, 3) - g_date->DayInYear())) {
198  SimpleEvent_(g_date->Date() + 1, pl_sbs_heavy_cultivator, true, a_farm, a_field);
199  break;
200  }
201  }
202  d1 = g_date->Date() + 1;
203  if (d1 < g_date->OldDays() + g_date->DayInYear(20, 3)) {
204  d1 = g_date->OldDays() + g_date->DayInYear(20, 3);
205  }
206  SimpleEvent_(d1, pl_sbs_preseeding_cultivator, false, a_farm, a_field);
207  break;
209  // 20% will do preseeding cultivation, the rest will do it together with sow
210  if (a_ev->m_lock || a_farm->DoIt(20))
211  {
212  if (!a_farm->PreseedingCultivator(a_field, 0.0, g_date->DayInYear(9, 4) - g_date->DayInYear())) {
213  SimpleEvent_(g_date->Date() + 1, pl_sbs_preseeding_cultivator, true, a_farm, a_field);
214  break;
215  }
216  SimpleEvent_(g_date->Date() + 1, pl_sbs_spring_sow, false, a_farm, a_field);
217  break;
218  }
219  SimpleEvent_(g_date->Date() + 1, pl_sbs_preseeding_cultivator_sow, false, a_farm, a_field);
220  break;
221  case pl_sbs_spring_sow:
222  if (!a_farm->SpringSow(a_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
223  SimpleEvent_(g_date->Date() + 1, pl_sbs_spring_sow, true, a_farm, a_field);
224  break;
225  }
226  // Here is a fork leading to four parallel events
227  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 4), pl_sbs_herbicide1, false, a_farm, a_field); // Herbidide thread
228  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_sbs_fungicide1, false, a_farm, a_field); // Fungicide thread
229  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 5), pl_sbs_insecticide1, false, a_farm, a_field); // Insecticide thread = MAIN THREAD
230  if (a_farm->IsStockFarmer()) //Stock Farmer // N thread
231  {
232  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_sbs_ferti_s2, false, a_farm, a_field);
233  }
234  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_sbs_ferti_p2, false, a_farm, a_field);
235  if (a_farm->IsStockFarmer()) //Stock Farmer // Microelemnts thread
236  {
237  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_sbs_ferti_s3, false, a_farm, a_field);
238  }
239  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_sbs_ferti_p3, false, a_farm, a_field);
240  break;
242  // 80% will do preseeding cultivation with sow
243  if (!a_farm->PreseedingCultivatorSow(a_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
244  SimpleEvent_(g_date->Date() + 1, pl_sbs_preseeding_cultivator_sow, true, a_farm, a_field);
245  break;
246  }
247  // Here is a fork leading to four parallel events
248  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 4), pl_sbs_herbicide1, false, a_farm, a_field); // Herbidide thread
249  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_sbs_fungicide1, false, a_farm, a_field); // Fungicide thread
250  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 5), pl_sbs_insecticide1, false, a_farm, a_field); // Insecticide thread = MAIN THREAD
251  if (a_farm->IsStockFarmer()) //Stock Farmer // N thread
252  {
253  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_sbs_ferti_s2, false, a_farm, a_field);
254  }
255  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_sbs_ferti_p2, false, a_farm, a_field);
256  if (a_farm->IsStockFarmer()) //Stock Farmer // Microelemnts thread
257  {
258  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_sbs_ferti_s3, false, a_farm, a_field);
259  }
260  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), pl_sbs_ferti_p3, false, a_farm, a_field);
261  break;
262  case pl_sbs_ferti_p2:
263  // Here comes N thread
264  if (!a_farm->FP_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(30, 5) - g_date->DayInYear())) {
265  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_p2, true, a_farm, a_field);
266  break;
267  }
268  // End of thread
269  break;
270  case pl_sbs_ferti_s2:
271  if (!a_farm->FA_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(30, 5) - g_date->DayInYear())) {
272  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_s2, true, a_farm, a_field);
273  break;
274  }
275  // End of thread
276  break;
277  case pl_sbs_ferti_p3:
278  // Here comes the mickroelements thread
279  if (a_ev->m_lock || a_farm->DoIt(43))
280  {
281  if (!a_farm->FP_ManganeseSulphate(a_field, 0.0, g_date->DayInYear(30, 5) - g_date->DayInYear())) {
282  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_p3, true, a_farm, a_field);
283  break;
284  }
285  }
286  d1 = g_date->Date() + 14;
287  if (d1 < g_date->OldDays() + g_date->DayInYear(25, 5)) {
288  d1 = g_date->OldDays() + g_date->DayInYear(25, 5);
289  }
290  SimpleEvent_(d1, pl_sbs_ferti_p4, false, a_farm, a_field);
291  break;
292  case pl_sbs_ferti_s3:
293  if (a_ev->m_lock || a_farm->DoIt(43))
294  {
295  if (!a_farm->FA_ManganeseSulphate(a_field, 0.0, g_date->DayInYear(30, 5) - g_date->DayInYear())) {
296  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_s3, true, a_farm, a_field);
297  break;
298  }
299  }
300  d1 = g_date->Date() + 14;
301  if (d1 < g_date->OldDays() + g_date->DayInYear(25, 5)) {
302  d1 = g_date->OldDays() + g_date->DayInYear(25, 5);
303  }
304  SimpleEvent_(d1, pl_sbs_ferti_s4, false, a_farm, a_field);
305  break;
306  case pl_sbs_ferti_p4:
307  if (a_ev->m_lock || a_farm->DoIt(3))
308  {
309  if (!a_farm->FP_ManganeseSulphate(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
310  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_p4, true, a_farm, a_field);
311  break;
312  }
313  }
314  // End of thread
315  break;
316  case pl_sbs_ferti_s4:
317  if (a_ev->m_lock || a_farm->DoIt(3))
318  {
319  if (!a_farm->FA_ManganeseSulphate(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
320  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_s4, true, a_farm, a_field);
321  break;
322  }
323  }
324  // End of thread
325  break;
326  case pl_sbs_herbicide1: // The first of the pesticide managements.
327  // Here comes the herbicide thread
328  if (a_ev->m_lock || a_farm->DoIt(97))
329  {
330  if (a_field->GetGreenBiomass() <= 0) {
331  SimpleEvent_(g_date->Date() + 5, pl_sbs_herbicide1, true, a_farm, a_field);
332  }
333  else
334  {
335  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(10, 5) - g_date->DayInYear())) {
336  SimpleEvent_(g_date->Date() + 1, pl_sbs_herbicide1, true, a_farm, a_field);
337  break;
338  }
339  }
340  }
341  // End of thread
342  break;
343  case pl_sbs_fungicide1:
344  // Here comes the fungicide thread
345  if (a_ev->m_lock || a_farm->DoIt(83))
346  {
347  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
348  SimpleEvent_(g_date->Date() + 1, pl_sbs_fungicide1, true, a_farm, a_field);
349  break;
350  }
351  }
352  SimpleEvent_(g_date->Date() + 14, pl_sbs_fungicide2, false, a_farm, a_field);
353  break;
354  case pl_sbs_fungicide2:
355  if (a_ev->m_lock || a_farm->DoIt(23))
356  {
357  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
358  SimpleEvent_(g_date->Date() + 1, pl_sbs_fungicide2, true, a_farm, a_field);
359  break;
360  }
361  }
362  d1 = g_date->Date() + 14;
363  if (d1 < g_date->OldDays() + g_date->DayInYear(20, 5)) {
364  d1 = g_date->OldDays() + g_date->DayInYear(20, 5);
365  }
366  SimpleEvent_(d1, pl_sbs_fungicide3, false, a_farm, a_field);
367  break;
368  case pl_sbs_fungicide3:
369  if (a_ev->m_lock || a_farm->DoIt(4))
370  {
371  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(20, 6) - g_date->DayInYear())) {
372  SimpleEvent_(g_date->Date() + 1, pl_sbs_fungicide3, true, a_farm, a_field);
373  break;
374  }
375  }
376  // End of thread
377  break;
378  case pl_sbs_insecticide1:
379  // Here comes the insecticide thread = MAIN THREAD
380  if (a_ev->m_lock || a_farm->DoIt(65))
381  {
382  // here we check wheter we are using ERA pesticide or not
383  if (!cfg_pest_springbarley_on.value() ||
384  !g_landscape_p->SupplyShouldSpray()) // Not using pesticide spray
385  {
386  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
387  SimpleEvent_(g_date->Date() + 1, pl_sbs_insecticide1, true, a_farm, a_field);
388  break;
389  }
390  }
391  else {
392  a_farm->ProductApplication(a_field, 0.0, 0, cfg_pest_product_1_amount.value(), ppp_1);
393  }
394  }
395  SimpleEvent_(g_date->Date() + 14, pl_sbs_insecticide2, false, a_farm, a_field);
396  break;
397  case pl_sbs_insecticide2:
398  if (a_ev->m_lock || a_farm->DoIt(46))
399  {
400  // here we check wheter we are using ERA pesticide or not
401  if (!cfg_pest_springbarley_on.value() ||
402  !g_landscape_p->SupplyShouldSpray()) // Not using pesticide spray
403  {
404  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
405  SimpleEvent_(g_date->Date() + 1, pl_sbs_insecticide2, true, a_farm, a_field);
406  break;
407  }
408  }
409  else {
410  a_farm->ProductApplication(a_field, 0.0, 0, cfg_pest_product_1_amount.value(), ppp_1);
411  }
412  }
413  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 7), pl_sbs_harvest, false, a_farm, a_field);
414  break;
415  case pl_sbs_harvest:
416  // Here the MAIN thread continues
417  // We don't move harvest days
418  if (!a_farm->Harvest(a_field, 0.0, a_field->GetMDates(0, 0) - g_date->DayInYear())) {
419  SimpleEvent_(g_date->Date() + 1, pl_sbs_harvest, true, a_farm, a_field);
420  break;
421  }
422  SimpleEvent_(g_date->Date() + 1, pl_sbs_straw_chopping, false, a_farm, a_field);
423  break;
425  if (a_farm->IsStockFarmer()) //Stock Farmer
426  {
427  // 10% of stock farmers will do straw chopping, but rest will do hay bailing instead
428  if (a_ev->m_lock || a_farm->DoIt(10))
429  {
430  if (a_field->GetMConstants(0) == 0) {
431  if (!a_farm->StrawChopping(a_field, 0.0, -1)) { // raise an error
432  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): failure in 'StrawChopping' execution", "");
433  exit(1);
434  }
435  }
436  else {
437  if (!a_farm->StrawChopping(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
438  SimpleEvent_(g_date->Date() + 1, pl_sbs_straw_chopping, true, a_farm, a_field);
439  break;
440  }
441  else
442  {
443  // Queue up the next event
444  SimpleEvent_(g_date->Date(), pl_sbs_ferti_s5, false, a_farm, a_field);
445  break;
446  }
447  }
448 
449  }
450  SimpleEvent_(g_date->Date() + 1, pl_sbs_hay_bailing, false, a_farm, a_field);
451  break;
452  }
453  else
454  {
455  // 90% of arable farmers will do straw chopping, but rest will do hay bailing instead
456  if (a_ev->m_lock || a_farm->DoIt(90))
457  {
458  if (a_field->GetMConstants(0) == 0) {
459  if (!a_farm->StrawChopping(a_field, 0.0, -1)) { // raise an error
460  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): failure in 'StrawChopping' execution", "");
461  exit(1);
462  }
463  }
464  else {
465  if (!a_farm->StrawChopping(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
466  SimpleEvent_(g_date->Date() + 1, pl_sbs_straw_chopping, true, a_farm, a_field);
467  break;
468  }
469  else
470  {
471  // Queue up the next event
472  SimpleEvent_(g_date->Date(), pl_sbs_ferti_p5, false, a_farm, a_field);
473  break;
474  }
475  }
476 
477  }
478  SimpleEvent_(g_date->Date() + 1, pl_sbs_hay_bailing, false, a_farm, a_field);
479  break;
480  }
481  case pl_sbs_hay_bailing:
482  if (a_field->GetMConstants(1) == 0) {
483  if (!a_farm->HayBailing(a_field, 0.0, -1)) { // raise an error
484  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): failure in 'HayBailing' execution", "");
485  exit(1);
486  }
487  }
488  else {
489  if (!a_farm->HayBailing(a_field, 0.0, a_field->GetMDates(1, 1) - g_date->DayInYear())) {
490  SimpleEvent_(g_date->Date() + 1, pl_sbs_hay_bailing, true, a_farm, a_field);
491  break;
492  }
493  }
494  if (a_farm->IsStockFarmer()) //Stock Farmer
495  {
496  SimpleEvent_(g_date->Date(), pl_sbs_ferti_s6, false, a_farm, a_field);
497  }
498  else SimpleEvent_(g_date->Date(), pl_sbs_ferti_p6, false, a_farm, a_field);
499  break;
500  case pl_sbs_ferti_p5:
501  if (a_ev->m_lock || a_farm->DoIt(18))
502  {
503  if (a_field->GetMConstants(2) == 0) {
504  if (!a_farm->FP_RSM(a_field, 0.0, -1)) { // raise an error
505  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): failure in 'FP_RSM' execution", "");
506  exit(1);
507  }
508  }
509  else {
510  if (!a_farm->FP_RSM(a_field, 0.0, a_field->GetMDates(1, 2) - g_date->DayInYear())) {
511  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_p5, true, a_farm, a_field);
512  break;
513  }
514  }
515  }
516  if (a_farm->IsStockFarmer()) //Stock Farmer
517  {
518  SimpleEvent_(g_date->Date(), pl_sbs_ferti_s6, false, a_farm, a_field);
519  }
520  else SimpleEvent_(g_date->Date(), pl_sbs_ferti_p6, false, a_farm, a_field);
521  break;
522  case pl_sbs_ferti_s5:
523  if (a_ev->m_lock || a_farm->DoIt(18))
524  {
525  if (a_field->GetMConstants(2) == 0) {
526  if (!a_farm->FA_RSM(a_field, 0.0, -1)) { // raise an error
527  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): failure in 'FA_RSM' execution", "");
528  exit(1);
529  }
530  }
531  else {
532  if (!a_farm->FA_RSM(a_field, 0.0, a_field->GetMDates(1, 2) - g_date->DayInYear())) {
533  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_s5, true, a_farm, a_field);
534  break;
535  }
536  }
537  }
538  if (a_farm->IsStockFarmer()) //Stock Farmer
539  {
540  SimpleEvent_(g_date->Date(), pl_sbs_ferti_s6, false, a_farm, a_field);
541  }
542  else SimpleEvent_(g_date->Date(), pl_sbs_ferti_p6, false, a_farm, a_field);
543  break;
544  case pl_sbs_ferti_p6:
545  if (a_ev->m_lock || a_farm->DoIt(23))
546  {
547  if (a_field->GetMConstants(3) == 0) {
548  if (!a_farm->FP_Calcium(a_field, 0.0, -1)) { // raise an error
549  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): failure in 'FP_Calcium' execution", "");
550  exit(1);
551  }
552  }
553  else {
554  if (!a_farm->FP_Calcium(a_field, 0.0, a_field->GetMDates(1, 3) - g_date->DayInYear())) {
555  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_p6, true, a_farm, a_field);
556  break;
557  }
558  }
559  }
560  done = true;
561  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
562  // END of MAIN THREAD
563  break;
564  case pl_sbs_ferti_s6:
565  if (a_ev->m_lock || a_farm->DoIt(23))
566  {
567  if (a_field->GetMConstants(3) == 0) {
568  if (!a_farm->FA_Calcium(a_field, 0.0, -1)) { // raise an error
569  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): failure in 'FA_Calcium' execution", "");
570  exit(1);
571  }
572  }
573  else {
574  if (!a_farm->FA_Calcium(a_field, 0.0, a_field->GetMDates(1, 3) - g_date->DayInYear())) {
575  SimpleEvent_(g_date->Date() + 1, pl_sbs_ferti_s6, true, a_farm, a_field);
576  break;
577  }
578  }
579  }
580  done = true;
581  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
582  // END of MAIN THREAD
583  break;
584  default:
585  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): "
586  "Unknown event type! ", "");
587  exit(1);
588  }
589  return done;
590 }
pl_sbs_ferti_p1
Definition: PLSpringBarleySpr.h:41
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
pl_sbs_ferti_p4
Definition: PLSpringBarleySpr.h:57
PL_SBS_SPRING_FERTI
#define PL_SBS_SPRING_FERTI
A flag used to indicate autumn ploughing status.
Definition: PLSpringBarleySpr.h:28
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
pl_sbs_preseeding_cultivator_sow
Definition: PLSpringBarleySpr.h:45
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
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
pl_sbs_ferti_p5
Definition: PLSpringBarleySpr.h:62
tof_OptimisingFarm
Definition: farm.h:273
pl_sbs_fungicide1
Definition: PLSpringBarleySpr.h:48
pl_sbs_ferti_s5
Definition: PLSpringBarleySpr.h:63
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
PL_SBS_DECIDE_TO_GR
#define PL_SBS_DECIDE_TO_GR
Definition: PLSpringBarleySpr.h:29
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
pl_sbs_ferti_p3
Definition: PLSpringBarleySpr.h:55
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
l_pest_insecticide_amount
CfgFloat l_pest_insecticide_amount
pl_sbs_fungicide2
Definition: PLSpringBarleySpr.h:49
cfg_SBS_InsecticideDay
CfgInt cfg_SBS_InsecticideDay
pl_sbs_spring_harrow
Definition: PLSpringBarleySpr.h:40
pl_sbs_preseeding_cultivator
Definition: PLSpringBarleySpr.h:44
cfg_pest_product_1_amount
CfgFloat cfg_pest_product_1_amount
pl_sbs_start
Definition: PLSpringBarleySpr.h:37
pl_sbs_ferti_p6
Definition: PLSpringBarleySpr.h:64
pl_sbs_heavy_cultivator
Definition: PLSpringBarleySpr.h:43
pl_sbs_ferti_p2
Definition: PLSpringBarleySpr.h:53
pl_sbs_hay_bailing
Definition: PLSpringBarleySpr.h:61
pl_sbs_herbicide1
Definition: PLSpringBarleySpr.h:47
pl_sbs_straw_chopping
Definition: PLSpringBarleySpr.h:60
pl_sbs_ferti_s1
Definition: PLSpringBarleySpr.h:42
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
pl_sbs_spring_sow
Definition: PLSpringBarleySpr.h:46
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
PLSpringBarleySpr::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: PLSpringBarleySpr.cpp:64
ppp_1
Definition: farm.h:422
cfg_SBS_InsecticideMonth
CfgInt cfg_SBS_InsecticideMonth
cfg_pest_springbarley_on
CfgBool cfg_pest_springbarley_on
Farm
The base class for all farm types.
Definition: farm.h:767
pl_sbs_harvest
Definition: PLSpringBarleySpr.h:59
pl_sbs_ferti_s6
Definition: PLSpringBarleySpr.h:65
pl_sbs_ferti_s2
Definition: PLSpringBarleySpr.h:54
pl_sbs_ferti_s4
Definition: PLSpringBarleySpr.h:58
pl_sbs_fungicide3
Definition: PLSpringBarleySpr.h:50
pl_sbs_insecticide2
Definition: PLSpringBarleySpr.h:52
pl_sbs_insecticide1
Definition: PLSpringBarleySpr.h:51
pl_sbs_spring_plough
Definition: PLSpringBarleySpr.h:39
pl_sbs_ferti_s3
Definition: PLSpringBarleySpr.h:56
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