ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
WinterBarley.cpp
Go to the documentation of this file.
1 //
2 // WinterBarley.cpp
3 //
4 /*
5 *******************************************************************************************************
6 Copyright (c) 2011, Christopher John Topping, Aarhus University
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without modification, are permitted provided
10 that the following conditions are met:
11 
12 Redistributions of source code must retain the above copyright notice, this list of conditions and the
13 following disclaimer.
14 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
15 the following disclaimer in the documentation and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
20 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ********************************************************************************************************
26 */
27 
28 #include "../../Landscape/ls.h"
29 #include "../../Landscape/cropprogs/WinterBarley.h"
30 #include <math.h>
31 
32 extern CfgFloat cfg_ins_app_prop1;
33 extern CfgFloat cfg_herbi_app_prop;
34 extern CfgFloat cfg_fungi_app_prop1;
35 extern CfgFloat cfg_greg_app_prop;
36 
37 bool WinterBarley::Do( Farm *a_farm, LE *a_field, FarmEvent *a_ev )
38 {
39  double ins_app_prop=cfg_ins_app_prop1.value();
40  double herbi_app_prop=cfg_herbi_app_prop.value();
41  m_farm = a_farm;
42  m_field = a_field;
43  m_ev = a_ev;
44  bool done = false;
45 
46  switch ( m_ev->m_todo )
47  {
48  case wb_start:
49  {
52  // Set up the date management stuff
53  m_last_date=g_date->DayInYear(10,8);
54  // Start and stop dates for all events after harvest
55  int noDates= 3;
56  m_field->SetMDates(0,0,g_date->DayInYear(20,7));
57  // Determined by harvest date - used to see if at all possible
58  m_field->SetMDates(1,0,g_date->DayInYear(5,8));
59  m_field->SetMDates(0,1,g_date->DayInYear(25,7));
60  m_field->SetMDates(1,1,g_date->DayInYear(10,8));
61  m_field->SetMDates(0,2,g_date->DayInYear(20,7));
62  m_field->SetMDates(1,2,g_date->DayInYear(5,8));
63  // Check the next crop for early start, unless it is a spring crop
64  // in which case we ASSUME that no checking is necessary!!!!
65  // So DO NOT implement a crop that runs over the year boundary
66 
67  //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)
68  int d1;
69  if(!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber()>0)){
70 
71  if (m_ev->m_startday>g_date->DayInYear(1,7))
72  {
73  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
74  {
75  g_msg->Warn( WARN_BUG, "WinterBarley::Do(): "
76  "Harvest too late for the next crop to start!!!", "" );
77  exit( 1 );
78  }
79  // Now fix any late finishing problems
80  for (int i=0; i<noDates; i++) {
81  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
82  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
83  }
84  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
85  m_field->SetMConstants(i,0);
86  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
87  }
88  }
89  }
90  // Now no operations can be timed after the start of the next crop.
91 
92  if ( ! m_ev->m_first_year )
93  {
94  int today=g_date->Date();
95  // Are we before July 1st?
96  d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
97  if (today < d1){
98  // Yes, too early. We assumme this is because the last crop was late
99  g_msg->Warn( WARN_BUG, "WinterBarley::Do(): "
100  "Crop start attempt between 1st Jan & 1st July", "" );
101  exit( 1 );
102  }
103  else{
104  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
105  if (today > d1) {
106  // Yes too late - should not happen - raise an error
107  g_msg->Warn( WARN_BUG, "WinterBarley::Do(): "
108  "Crop start attempt after last possible start date", "" );
109  exit( 1 );
110  }
111  }
112  }
113  else
114  {
115  // Is the first year so must start in spring like nothing was unusual
116  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,7 )
117  ,wb_harvest, false );
118  }
119  }//if
120 
121  // End single block date checking code. Please see next line
122  // comment as well.
123  // Reinit d1 to first possible starting date.
124  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
125  if ( g_date->Date() > d1 ) {
126  d1 = g_date->Date();
127  }
128  // OK, let's go.
129  WB_DID_SEVEN_ONE = false;
130  WB_DID_SEVEN_TWO = false;
131  WB_DID_SEVEN_THREE = false;
132  WB_DID_SEVEN_FOUR = false;
133  WB_FUNGICIDE_DATE = 0;
134  WB_HERBICIDE_DATE = 0;
135 
136  if ( m_farm->IsStockFarmer()) {
137  SimpleEvent( d1, wb_fertmanure_stock, false );
138  d1 += 14;
139  SimpleEvent( d1, wb_fertslurry_stock_one, false );
140  } else {
141  SimpleEvent( d1, wb_fertsludge_plant_one, false );
142  }
143  }
144  break;
145 
146  case wb_fertmanure_stock:
147  if ( m_ev->m_lock || m_farm->DoIt( 10 ))
148  {
149  if (!m_farm->FA_Manure( m_field, 0.0,
150  g_date->DayInYear( 5, 9 ) -
151  g_date->DayInYear())) {
152  SimpleEvent( g_date->Date() + 1, wb_fertmanure_stock, true );
153  break;
154  }
155  }
156  break;
157 
159  if ( m_ev->m_lock || m_farm->DoIt( 95 ))
160  {
161  if (!m_farm->FA_Slurry( m_field, 0.0,
162  g_date->DayInYear( 10, 9 ) -
163  g_date->DayInYear())) {
164  SimpleEvent( g_date->Date() + 1, wb_fertslurry_stock_one, true );
165  break;
166  }
167  }
168  SimpleEvent( g_date->Date() + 1, wb_autumn_plough, false );
169  break;
170 
172  if ( m_ev->m_lock || m_farm->DoIt( 10 ))
173  {
174  if (!m_farm->FP_Sludge( m_field, 0.0,
175  g_date->DayInYear( 5, 9 ) -
176  g_date->DayInYear())) {
177  SimpleEvent( g_date->Date() + 1, wb_fertsludge_plant_one, true );
178  break;
179  }
180  }
181  SimpleEvent( g_date->Date() + 1, wb_autumn_plough, false );
182  break;
183 
184  case wb_autumn_plough:
185  if (!m_farm->AutumnPlough( m_field, 0.0,
186  g_date->DayInYear( 5, 9 ) -
187  g_date->DayInYear())) {
188  SimpleEvent( g_date->Date() + 1, wb_autumn_plough, true );
189  break;
190  }
191  SimpleEvent( g_date->Date(), wb_autumn_harrow, false );
192  break;
193 
194  case wb_autumn_harrow:
195  if (!m_farm->AutumnHarrow( m_field, 0.0,
196  g_date->DayInYear( 5, 9 ) -
197  g_date->DayInYear())) {
198  SimpleEvent( g_date->Date() + 1, wb_autumn_harrow, true );
199  break;
200  }
201  {
202  int d1 = g_date->Date();
203  if ( d1 < g_date->OldDays() + g_date->DayInYear( 1, 9 )) {
204  d1 = g_date->OldDays() + g_date->DayInYear( 1, 9 );
205  }
206  SimpleEvent( d1, wb_autumn_sow, false );
207  }
208  break;
209 
210  case wb_autumn_sow:
211  if (!m_farm->AutumnSow( m_field, 0.0,
212  g_date->DayInYear( 15,9 ) -
213  g_date->DayInYear())) {
214  SimpleEvent( g_date->Date() + 1, wb_autumn_sow, true );
215  break;
216  }
217  {
218  int d1 = g_date->Date() + 14;
219  if ( d1 < g_date->OldDays() + g_date->DayInYear( 15, 9 )) {
220  d1 = g_date->OldDays() + g_date->DayInYear( 15, 9 );
221  }
222  SimpleEvent( d1, wb_herbicide_one, false );
223  }
224  break;
225 
226  case wb_herbicide_one:
227  if ( m_ev->m_lock || m_farm->DoIt( (int) floor(100*herbi_app_prop * m_farm->Prob_multiplier()+0.5) )) //modified probability
228  {
229  //new - for decision making
230  TTypesOfVegetation tov = m_field->GetVegType();
231  if(!m_ev->m_lock && !m_farm->Spraying_herbicides(tov)){
232  Field * pf = dynamic_cast<Field*>(m_field);
233  pf->Add_missed_herb_app();
234  if(m_farm->DoIt(35)) pf->Add_missed_herb_app(); //the 2nd missed application
236  } //end of the part for dec. making
237  else{
238  if (!m_farm->HerbicideTreat( m_field, 0.0, g_date->DayInYear( 30,9 ) - g_date->DayInYear())) {
239  SimpleEvent( g_date->Date() + 1, wb_herbicide_one, true );
240  break;
241  }
242  }
243  }
244  if ( m_farm->IsStockFarmer()) {
245  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ) + 365,
246  wb_fertslurry_stock_two, false );
247  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5,4 ) + 365,
248  wb_fertnpk_stock_one, false );
249  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,4 ) + 365,
250  wb_herbicide_two, false );
251  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,5 ) + 365,
252  wb_fungicide_one, false );
253  } else {
254  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 16,9 ),
256  }
257  break;
258 
260  if ( m_ev->m_lock || m_farm->DoIt( 20 ))
261  {
262  if (!m_farm->FP_ManganeseSulphate( m_field, 0.0,
263  g_date->DayInYear( 30,10 ) -
264  g_date->DayInYear())) {
265  SimpleEvent( g_date->Date() + 1, wb_fertmanganese_plant_one, true );
266  break;
267  }
268  // Did first, so do second manganese too.
269  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ) + 365,
271  } else {
272  // Event 'wb_fertmanganese_plant_two' was not queued up, so we will
273  // signal its completion already here...
274  WB_DID_SEVEN_ONE = true;
275  }
276  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5,4 ) + 365,
277  wb_fertnpk_plant_one, false );
278  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,4 ) + 365,
279  wb_herbicide_two, false );
280  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,5 ) + 365,
281  wb_fungicide_one, false );
282  break;
283 
285  if (!m_farm->FP_ManganeseSulphate( m_field, 0.0,
286  g_date->DayInYear( 5,5 ) -
287  g_date->DayInYear())) {
288  SimpleEvent( g_date->Date() + 1, wb_fertmanganese_plant_two, true );
289  break;
290  }
291  WB_DID_SEVEN_ONE = true;
292  if ( WB_DID_SEVEN_TWO &&
295  // We are the last surviving thread. Enter switchboard.
296  SimpleEvent( g_date->Date(), wb_switchboard, false );
297  }
298  break;
299 
301  if (!m_farm->FP_NPK( m_field, 0.0,
302  g_date->DayInYear( 1,5 ) -
303  g_date->DayInYear())) {
304  SimpleEvent( g_date->Date() + 1, wb_fertnpk_plant_one, true );
305  break;
306  }
307  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 2,5 ),
308  wb_fertnpk_plant_two, false );
309  break;
310 
312  if ( m_ev->m_lock || m_farm->DoIt( 15 )) {
313  if (!m_farm->FP_NPK( m_field, 0.0,
314  g_date->DayInYear( 20,5 ) -
315  g_date->DayInYear())) {
316  SimpleEvent( g_date->Date() + 1, wb_fertnpk_plant_two, true );
317  break;
318  }
319  }
320  WB_DID_SEVEN_TWO = true;
321  if ( WB_DID_SEVEN_ONE &&
324  // We are the last surviving thread. Enter switchboard.
325  SimpleEvent( g_date->Date(), wb_switchboard, false );
326  }
327  break;
328 
330  if ( m_ev->m_lock || m_farm->DoIt( 20 )) {
331  if (!m_farm->FA_Slurry( m_field, 0.0,
332  g_date->DayInYear( 15,5 ) -
333  g_date->DayInYear())) {
334  SimpleEvent( g_date->Date() + 1, wb_fertslurry_stock_two, true );
335  break;
336  }
337  }
338  WB_DID_SEVEN_ONE = true;
339  if ( WB_DID_SEVEN_TWO &&
342  // We are the last surviving thread. Enter switchboard.
343  SimpleEvent( g_date->Date(), wb_switchboard, false );
344  }
345  break;
346 
348  if ( m_ev->m_lock || m_farm->DoIt( 90 )) {
349  if (!m_farm->FA_NPK( m_field, 0.0,
350  g_date->DayInYear( 30,4 ) -
351  g_date->DayInYear())) {
352  SimpleEvent( g_date->Date() + 1, wb_fertnpk_stock_one, true );
353  break;
354  }
355  }
356  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,5 ),
357  wb_fertnpk_stock_two, false );
358  break;
359 
361  if ( m_ev->m_lock || m_farm->DoIt( 14 )) {
362  if (!m_farm->FA_NPK( m_field, 0.0,
363  g_date->DayInYear( 15,5 ) -
364  g_date->DayInYear())) {
365  SimpleEvent( g_date->Date() + 1, wb_fertnpk_stock_two, true );
366  break;
367  }
368  }
369  WB_DID_SEVEN_TWO = true;
370  if ( WB_DID_SEVEN_ONE &&
373  // We are the last surviving thread. Enter switchboard.
374  SimpleEvent( g_date->Date(), wb_switchboard, false );
375  }
376  break;
377 
378  case wb_herbicide_two:
379  if ( m_ev->m_lock || m_farm->DoIt( (int) floor(35*herbi_app_prop*WB_DECIDE_TO_HERB * m_farm->Prob_multiplier()+0.5 ))) { //modified probability
380  if (!m_farm->HerbicideTreat( m_field, 0.0,
381  g_date->DayInYear( 30,5 ) -
382  g_date->DayInYear())) {
383  SimpleEvent( g_date->Date() + 1, wb_herbicide_two, true );
384  break;
385  }
386  WB_HERBICIDE_DATE = g_date->Date();
387  }
388  WB_DID_SEVEN_THREE = true;
389  if ( WB_DID_SEVEN_ONE &&
392  // We are the last surviving thread. Enter switchboard.
393  SimpleEvent( g_date->Date(), wb_switchboard, false );
394  }
395  break;
396 
397  case wb_fungicide_one:
398  if ( m_ev->m_lock || m_farm->DoIt( (int) (65*cfg_fungi_app_prop1.value() * m_farm->Prob_multiplier()))) { //modified probability
399 
400  //new - for decision making
401  TTypesOfVegetation tov = m_field->GetVegType();
402  if(!m_ev->m_lock && !m_farm->Spraying_fungins(tov)){
403  Field * pf = dynamic_cast<Field*>(m_field);
404  pf->Add_missed_fi_app();
405  if(m_farm->DoIt(15)) pf->Add_missed_fi_app(); //the 2nd missed application
406  WB_DECIDE_TO_FI=0;
407  } //end of the part for dec. making
408  else{
409  if (!m_farm->FungicideTreat( m_field, 0.0, g_date->DayInYear( 15,5 ) - g_date->DayInYear())) {
410  SimpleEvent( g_date->Date() + 1, wb_fungicide_one, true );
411  break;
412  }
413  }
414  WB_FUNGICIDE_DATE = g_date->Date();
415  }
416  WB_DID_SEVEN_FOUR = true;
417  if ( WB_DID_SEVEN_ONE &&
420  // We are the last surviving thread. Enter switchboard.
421  SimpleEvent( g_date->Date(), wb_switchboard, false );
422  }
423  break;
424 
425  case wb_switchboard:
426  // Welcome to the Winterbarley switchboard, where all threads
427  // meet and have a jolly good time.
428 
429  // Reset all flags for the second round of parallel execution.
430  // Flags double as date indicators when each action took place
431  // (for checking proximity to watering).
432  WB_DID_EIGHT_ONE = false;
433  WB_DID_EIGHT_TWO = false;
434  WB_DID_EIGHT_THREE = false;
435  WB_DID_EIGHT_FOUR = false;
436 
437  // Start all four threads.
438  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,5 ),
439  wb_fungicide_two, false );
440  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,5 ),
441  wb_growth_reg, false );
442  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,5 ),
443  wb_water, false );
444  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,5 ),
445  wb_insecticide, false );
446  break;
447 
448  case wb_fungicide_two:
449  if ( g_date->Date() < WB_DID_EIGHT_THREE + 1 ||
450  g_date->Date() < WB_FUNGICIDE_DATE + 7 ) {
451  // Try again tomorrow.
452  SimpleEvent( g_date->Date() + 1, wb_fungicide_two, m_ev->m_lock );
453  break;
454  }
455  if ( m_ev->m_lock || m_farm->DoIt( (int) (15*cfg_fungi_app_prop1.value() *WB_DECIDE_TO_HERB * m_farm->Prob_multiplier()))) { //modified probability
456  if (!m_farm->FungicideTreat( m_field, 0.0,
457  g_date->DayInYear( 30,5 ) -
458  g_date->DayInYear())) {
459  SimpleEvent( g_date->Date() + 1, wb_fungicide_two, true );
460  break;
461  }
462  }
463  WB_DID_EIGHT_ONE = g_date->Date();
464  if ( WB_DID_EIGHT_TWO &&
467  ChooseNextCrop (3);
468  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,7 ),
469  wb_harvest, false );
470  }
471  break;
472 
473  case wb_growth_reg:
474  if ( g_date->Date() < WB_DID_EIGHT_THREE + 1 ) {
475  // Try again tomorrow.
476  SimpleEvent( g_date->Date() + 1, wb_growth_reg, m_ev->m_lock );
477  break;
478  }
479  if ( m_ev->m_lock || m_farm->DoIt( (int) (50*cfg_greg_app_prop.value() ))) {
480  if (!m_farm->GrowthRegulator( m_field, 0.0,
481  g_date->DayInYear( 31,5 ) -
482  g_date->DayInYear())) {
483  SimpleEvent( g_date->Date() + 1, wb_growth_reg, true );
484  break;
485  }
486  }
487  WB_DID_EIGHT_TWO = g_date->Date();
488  if ( WB_DID_EIGHT_ONE &&
491  ChooseNextCrop (3);
492  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,7 ), wb_harvest, false );
493  }
494  break;
495 
496  case wb_water:
497  if ( g_date->Date() < WB_HERBICIDE_DATE + 1 ||
498  g_date->Date() < WB_DID_EIGHT_ONE + 1 ||
499  g_date->Date() < WB_DID_EIGHT_TWO + 1 ||
500  g_date->Date() < WB_DID_EIGHT_FOUR + 1 ) {
501  // Try again tomorrow.
502  SimpleEvent( g_date->Date() + 1, wb_water, m_ev->m_lock );
503  break;
504  }
505  if ( m_ev->m_lock || m_farm->DoIt( 5 )) {
506  if (!m_farm->Water( m_field, 0.0,
507  g_date->DayInYear( 15,6 ) -
508  g_date->DayInYear())) {
509  SimpleEvent( g_date->Date() + 1, wb_water, true );
510  break;
511  }
512  }
513  WB_DID_EIGHT_THREE = g_date->Date();
514  if ( WB_DID_EIGHT_ONE &&
517  ChooseNextCrop (3);
518  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,7 ),
519  wb_harvest, false );
520  }
521  break;
522 
523  case wb_insecticide:
524  if ( g_date->Date() < WB_DID_EIGHT_THREE + 1 ) {
525  // Try again tomorrow.
526  SimpleEvent( g_date->Date() + 1, wb_insecticide, m_ev->m_lock );
527  break;
528  }
529  if ( m_ev->m_lock || m_farm->DoIt( (int) floor(0.5+16*ins_app_prop * m_farm->Prob_multiplier()))) { //modified probability
530 
531  //new - for decision making
532  TTypesOfVegetation tov = m_field->GetVegType();
533  if(!m_ev->m_lock && !m_farm->Spraying_fungins(tov)){
534  Field * pf = dynamic_cast<Field*>(m_field);
535  pf->Add_missed_fi_app();
536  } //end of the part for dec. making
537  else{
538  if (!m_farm->InsecticideTreat( m_field, 0.0, g_date->DayInYear( 1,6 ) - g_date->DayInYear())) {
539  SimpleEvent( g_date->Date() + 1, wb_insecticide, true );
540  break;
541  }
542  }
543  }
544  WB_DID_EIGHT_FOUR = g_date->Date();
545  if ( WB_DID_EIGHT_ONE &&
548  ChooseNextCrop (3);
549  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,7 ),
550  wb_harvest, false );
551  }
552  break;
553 
554  case wb_harvest:
555  if (m_field->GetMConstants(0)==0) {
556  if (!m_farm->Harvest( m_field, 0.0, -1)) { //raise an error
557  g_msg->Warn( WARN_BUG, "WinterBarley::Do(): failure in 'Harvest' execution", "" );
558  exit( 1 );
559  }
560  }
561  else{
562  if (!m_farm->Harvest( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
563  SimpleEvent( g_date->Date() + 1, wb_harvest, true );
564  break;
565  }
566  }
567 
568  if ( m_farm->IsStockFarmer()) {
569  if ( m_farm->DoIt( 15 )) {
570  // Force straw chopping on the same day as harvest.
571  m_farm->StrawChopping( m_field, 0.0, 0 );
572  SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,1), wb_stubble_harrowing, false );
573  break;
574  }
575  // No chopping and harrowing, so try hay turning.
576  SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,2), wb_hay_turning, false );
577  break;
578  } else {
579  // Plant farmer.
580  if ( m_farm->DoIt( 75 )) {
581  // Force straw chopping on the same day as harvest.
582  m_farm->StrawChopping( m_field, 0.0, 0 );
583  SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,1), wb_stubble_harrowing, false );
584  break;
585  }
586  SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,2), wb_hay_turning, false );
587  }
588  break;
589 
590  case wb_hay_turning:
591  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
592  {
593  if (m_field->GetMConstants(2)==0) {
594  if (!m_farm->HayTurning( m_field, 0.0, -1)) { //raise an error
595  g_msg->Warn( WARN_BUG, "WinterBarley::Do(): failure in 'HayTurning' execution", "" );
596  exit( 1 );
597  }
598  }
599  else {
600  if (!m_farm->HayTurning( m_field, 0.0, m_field->GetMDates(1,2) - g_date->DayInYear())) {
601  SimpleEvent( g_date->Date() + 1, wb_hay_turning, true );
602  break;
603  }
604  }
605  }
606  SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,2), wb_hay_bailing, false );
607  break;
608 
609  case wb_hay_bailing:
610  if (m_field->GetMConstants(2)==0) {
611  if (!m_farm->HayBailing( m_field, 0.0, -1)) { //raise an error
612  g_msg->Warn( WARN_BUG, "WinterBarley::Do(): failure in 'HayBailing' execution", "" );
613  exit( 1 );
614  }
615  }
616  else {
617  if (!m_farm->HayBailing( m_field, 0.0, m_field->GetMDates(1,2) - g_date->DayInYear())) {
618  SimpleEvent( g_date->Date() + 1, wb_hay_bailing, true );
619  break;
620  }
621  }
622  {
623  int d1 = g_date->Date();
624  if ( d1 < g_date->OldDays() + m_field->GetMDates(0,1)) {
625  d1 = g_date->OldDays() + m_field->GetMDates(0,1);
626  }
627  SimpleEvent( d1, wb_stubble_harrowing, false );
628  }
629  break;
630 
632  if ( m_ev->m_lock || m_farm->DoIt( 40 )) {
633  if (m_field->GetMConstants(2)==0) {
634  if (!m_farm->StubbleHarrowing( m_field, 0.0, -1)) { //raise an error
635  g_msg->Warn( WARN_BUG, "WinterBarley::Do(): failure in 'StubbleHarrowing' execution", "" );
636  exit( 1 );
637  }
638  }
639  else {
640  if (!m_farm->StubbleHarrowing( m_field, 0.0, m_field->GetMDates(1,2) - g_date->DayInYear())) {
641  SimpleEvent( g_date->Date() + 1, wb_stubble_harrowing, true );
642  break;
643  }
644  }
645  }
646  done = true;
647  break;
648 
649  default:
650  g_msg->Warn( WARN_BUG, "WinterBarley::Do(): "
651  "Unknown event type! ", "" );
652  exit( 1 );
653  }
654 
655  return done;
656 }
657 
658 
Farm::FP_Sludge
virtual bool FP_Sludge(LE *a_field, double a_user, int a_days)
Spread sewege on a_field owned by an arable farmer.
Definition: farmfuncs.cpp:822
wb_fertslurry_stock_one
Definition: WinterBarley.h:62
Farm::FA_Slurry
virtual bool FA_Slurry(LE *a_field, double a_user, int a_days)
Spready slurry on a_field owned by an stock farmer.
Definition: farmfuncs.cpp:965
wb_fertnpk_plant_one
Definition: WinterBarley.h:69
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: farmfuncs.cpp:1156
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
WinterBarley::Do
bool Do(Farm *a_farm, LE *a_field, FarmEvent *a_ev)
Definition: WinterBarley.cpp:37
Farm::Harvest
virtual bool Harvest(LE *a_field, double a_user, int a_days)
Carry out a harvest on a_field.
Definition: farmfuncs.cpp:1769
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
cfg_greg_app_prop
CfgFloat cfg_greg_app_prop
cfg_fungi_app_prop1
CfgFloat cfg_fungi_app_prop1
Farm::FP_ManganeseSulphate
virtual bool FP_ManganeseSulphate(LE *a_field, double a_user, int a_days)
Apply Manganse Sulphate to a_field owned by an arable farmer.
Definition: farmfuncs.cpp:727
FarmEvent
A struct to hold the information required to trigger a farm event.
Definition: farm.h:463
wb_water
Definition: WinterBarley.h:79
Farm::FP_NPK
virtual bool FP_NPK(LE *a_field, double a_user, int a_days)
Apply NPK fertilizer, on a_field owned by an arable farmer.
Definition: farmfuncs.cpp:629
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
wb_hay_turning
Definition: WinterBarley.h:82
tof_OptimisingFarm
Definition: farm.h:273
wb_fertmanganese_plant_one
Definition: WinterBarley.h:67
wb_autumn_harrow
Definition: WinterBarley.h:64
WB_DECIDE_TO_FI
#define WB_DECIDE_TO_FI
Definition: WinterBarley.h:55
cfg_ins_app_prop1
CfgFloat cfg_ins_app_prop1
Farm::FA_Manure
virtual bool FA_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an stock farmer.
Definition: farmfuncs.cpp:1036
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
WB_DID_EIGHT_THREE
#define WB_DID_EIGHT_THREE
Definition: WinterBarley.h:52
wb_growth_reg
Definition: WinterBarley.h:78
wb_fungicide_two
Definition: WinterBarley.h:77
WB_DID_EIGHT_ONE
#define WB_DID_EIGHT_ONE
Definition: WinterBarley.h:50
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
Farm::FA_NPK
virtual bool FA_NPK(LE *a_field, double a_user, int a_days)
Apply NPK fertilizer to a_field owned by an stock farmer.
Definition: farmfuncs.cpp:917
Farm::FungicideTreat
virtual bool FungicideTreat(LE *a_field, double a_user, int a_days)
Apply fungicide to a_field.
Definition: farmfuncs.cpp:1279
wb_fungicide_one
Definition: WinterBarley.h:75
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
wb_hay_bailing
Definition: WinterBarley.h:83
wb_start
Definition: WinterBarley.h:59
wb_switchboard
Definition: WinterBarley.h:76
wb_fertsludge_plant_one
Definition: WinterBarley.h:60
wb_herbicide_one
Definition: WinterBarley.h:66
Farm::Prob_multiplier
virtual double Prob_multiplier()
Definition: farm.h:786
Farm::AutumnSow
virtual bool AutumnSow(LE *a_field, double a_user, int a_days)
Carry out a sowing event in the autumn on a_field.
Definition: farmfuncs.cpp:364
wb_autumn_plough
Definition: WinterBarley.h:63
WB_FUNGICIDE_DATE
#define WB_FUNGICIDE_DATE
Definition: WinterBarley.h:47
WB_DID_SEVEN_FOUR
#define WB_DID_SEVEN_FOUR
Definition: WinterBarley.h:45
TTypesOfVegetation
TTypesOfVegetation
Definition: tov_declaration.h:30
Farm::Spraying_herbicides
virtual bool Spraying_herbicides(TTypesOfVegetation)
Definition: farm.h:784
Farm::HayBailing
virtual bool HayBailing(LE *a_field, double a_user, int a_days)
Carry out hay bailing on a_field.
Definition: farmfuncs.cpp:2184
WB_DECIDE_TO_HERB
#define WB_DECIDE_TO_HERB
Definition: WinterBarley.h:54
Farm::StrawChopping
virtual bool StrawChopping(LE *a_field, double a_user, int a_days)
Carry out straw chopping on a_field.
Definition: farmfuncs.cpp:2132
wb_fertmanure_stock
Definition: WinterBarley.h:61
wb_herbicide_two
Definition: WinterBarley.h:74
wb_harvest
Definition: WinterBarley.h:81
wb_fertnpk_plant_two
Definition: WinterBarley.h:70
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
Crop::m_field
LE * m_field
Definition: farm.h:538
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
Farm::InsecticideTreat
virtual bool InsecticideTreat(LE *a_field, double a_user, int a_days)
Apply insecticide to a_field.
Definition: farmfuncs.cpp:1348
WB_HERBICIDE_DATE
#define WB_HERBICIDE_DATE
Definition: WinterBarley.h:48
WB_DID_SEVEN_TWO
#define WB_DID_SEVEN_TWO
Definition: WinterBarley.h:43
Farm::Water
virtual bool Water(LE *a_field, double a_user, int a_days)
Carry out a watering on a_field.
Definition: farmfuncs.cpp:1717
Crop::m_last_date
int m_last_date
Definition: farm.h:542
Farm::AutumnPlough
virtual bool AutumnPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the autumn on a_field.
Definition: farmfuncs.cpp:132
WB_DID_EIGHT_TWO
#define WB_DID_EIGHT_TWO
Definition: WinterBarley.h:51
wb_fertslurry_stock_two
Definition: WinterBarley.h:71
cfg_herbi_app_prop
CfgFloat cfg_herbi_app_prop
Farm::AutumnHarrow
virtual bool AutumnHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the autumn on a_field.
Definition: farmfuncs.cpp:261
Farm
The base class for all farm types.
Definition: farm.h:767
wb_fertmanganese_plant_two
Definition: WinterBarley.h:68
WB_DID_EIGHT_FOUR
#define WB_DID_EIGHT_FOUR
Definition: WinterBarley.h:53
WB_DID_SEVEN_THREE
#define WB_DID_SEVEN_THREE
Definition: WinterBarley.h:44
Farm::GrowthRegulator
virtual bool GrowthRegulator(LE *a_field, double a_user, int a_days)
Apply growth regulator to a_field.
Definition: farmfuncs.cpp:1250
wb_insecticide
Definition: WinterBarley.h:80
wb_stubble_harrowing
Definition: WinterBarley.h:84
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: farm.cpp:318
Farm::HayTurning
virtual bool HayTurning(LE *a_field, double a_user, int a_days)
Carry out hay turning on a_field.
Definition: farmfuncs.cpp:2159
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539
wb_fertnpk_stock_two
Definition: WinterBarley.h:73
Farm::Spraying_fungins
virtual bool Spraying_fungins(TTypesOfVegetation)
Definition: farm.h:785
wb_autumn_sow
Definition: WinterBarley.h:65
Farm::StubbleHarrowing
virtual bool StubbleHarrowing(LE *a_field, double a_user, int a_days)
Carry out stubble harrowing on a_field.
Definition: farmfuncs.cpp:2209
WB_DID_SEVEN_ONE
#define WB_DID_SEVEN_ONE
Definition: WinterBarley.h:42
wb_fertnpk_stock_one
Definition: WinterBarley.h:72