ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
SpringBarleyPeaCloverGrassStrigling.cpp
Go to the documentation of this file.
1 //
2 // SpringBarleyPeaCloverGrassStrigling.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/SpringBarleyPeaCloverGrassStrigling.h"
30 
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 extern CfgFloat cfg_strigling_prop;
37 
38 bool SpringBarleyPeaCloverGrassStrigling::Do( Farm *a_farm, LE *a_field, FarmEvent *a_ev )
39 {
40  m_farm = a_farm;
41  m_field = a_field;
42  m_ev = a_ev;
43  int d1=0;
44  int noDates=3;
45  bool done = false;
46 
47  switch ( m_ev->m_todo )
48  {
49  case sbpcgs_start:
50  {
52  SBPCGS_FERTI_DONE=false;
53  SBPCGS_SPRAY=0;
54  // Set up the date management stuff
55  // Could save the start day in case it is needed later
56  // m_field->m_startday = m_ev->m_startday;
57  m_last_date=g_date->DayInYear(15,10);
58  // Start and stop dates for all events after harvest
59  m_field->SetMDates(0,0,g_date->DayInYear(1,8));
60  // Determined by harvest date - used to see if at all possible
61  m_field->SetMDates(1,0,g_date->DayInYear(25,8));
62  m_field->SetMDates(0,1,g_date->DayInYear(5,8));
63  m_field->SetMDates(1,1,g_date->DayInYear(30,8));
64  m_field->SetMDates(0,2,g_date->DayInYear(1,9));
65  m_field->SetMDates(1,2,g_date->DayInYear(15,10));
66  // Check the next crop for early start, unless it is a spring crop
67  // in which case we ASSUME that no checking is necessary!!!!
68  // SO DO NOT implement a crop that runs over the year boundary
69  if (m_ev->m_startday>g_date->DayInYear(1,7))
70  {
71  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
72  {
73  g_msg->Warn( WARN_BUG, "SpringBarleyCloverGrass::Do(): "
74  "Harvest too late for the next crop to start!!!", "" );
75  exit( 1 );
76  }
77  // Now fix any late finishing problems
78  for (int i=0; i<noDates; i++)
79  {
80  if (m_field->GetMDates(0,i)>=m_ev->m_startday)
81  m_field->SetMDates(0,i,m_ev->m_startday-1);
82  if (m_field->GetMDates(1,i)>=m_ev->m_startday)
83  m_field->SetMDates(1,i,m_ev->m_startday-1);
84  }
85  }
86  // Now no operations can be timed after the start of the next crop.
87  if ( ! m_ev->m_first_year )
88  {
89  // Are we before July 1st?
90  d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
91  if (g_date->Date() < d1)
92  {
93  // Yes, too early. We assumme this is because the last crop was late
94  g_msg->Warn( WARN_BUG, "SpringBarleyCloverGrass::Do(): "
95  "Crop start attempt between 1st Jan & 1st July", "" );
96  exit( 1 );
97  }
98  else
99  {
100  d1 = g_date->OldDays() + m_first_date; // start day
101  if (g_date->Date() > d1)
102  {
103  // Yes too late - should not happen - raise an error
104  g_msg->Warn( WARN_BUG, "SpringBarleyCloverGrass::Do(): "
105  "Crop start attempt after last possible start date", "" );
106  exit( 1 );
107  }
108  }
109  }
110  else
111  {
112  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,3 ),
113  sbpcgs_spring_plough, false );
114  break;
115  }
116  // End single block date checking code. Please see next line
117  // comment as well.
118  // Reinit d1 to first possible starting date.
119 
120  d1 = g_date->OldDays() + g_date->DayInYear( 1, 11 );
121  if (g_date->Date() >= d1) d1 += 365;
122  SimpleEvent( d1, sbpcgs_autumn_plough, false );
123  }
124  break;
125 
127  if ( m_ev->m_lock || m_farm->DoIt( 70 ))
128  {
129  if (!m_farm->AutumnPlough( m_field, 0.0,
130  g_date->DayInYear( 30,11 ) - g_date->DayInYear())) {
131  SimpleEvent( g_date->Date() + 1, sbpcgs_autumn_plough, true );
132  break;
133  }
135  }
136  // +365 for next year
137  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,3 )+365,
138  sbpcgs_ferti_s1, false );
139  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,3 )+365,
140  sbpcgs_ferti_s2, false );
141  break;
142 
143  case sbpcgs_ferti_s1:
144  if ( m_ev->m_lock || m_farm->DoIt( 90 ))
145  {
146  if (!m_farm->FA_Slurry( m_field, 0.0,
147  g_date->DayInYear( 15, 4 ) - g_date->DayInYear())) {
148  SimpleEvent( g_date->Date() + 1, sbpcgs_ferti_s1, true );
149  break;
150  }
151  // Done fertilizer so remember
152  SBPCGS_FERTI_DONE=true;
153  }
154  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,3 ),
155  sbpcgs_spring_plough, false );
156  break;
157 
158  case sbpcgs_ferti_s2:
159  if (( m_ev->m_lock || m_farm->DoIt( 67 ) ) && (!SBPCGS_ISAUTUMNPLOUGH))
160  {
161  if (!m_farm->FA_Manure( m_field, 0.0,
162  g_date->DayInYear( 15, 4 ) - g_date->DayInYear()))
163  {
164  SimpleEvent( g_date->Date()+1, sbpcgs_ferti_s2, true );
165  break;
166  }
167  else
168  {
169  // Done fertilizer so remember
170  SBPCGS_FERTI_DONE=true;
171  }
172  }
173  break;
174 
176  if ( !SBPCGS_ISAUTUMNPLOUGH ) // Don't plough if you have already
177  {
178  if (!m_farm->SpringPlough( m_field, 0.0,
179  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
180  SimpleEvent( g_date->Date() + 1, sbpcgs_spring_plough, true );
181  break;
182  }
183  }
184  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,3 ),
185  sbpcgs_spring_harrow, false );
186  break;
187 
189  if (!m_farm->SpringHarrow( m_field, 0.0,
190  g_date->DayInYear( 10,4 ) - g_date->DayInYear())) {
191  SimpleEvent( g_date->Date() + 1, sbpcgs_spring_harrow, true );
192  break;
193  }
194  SimpleEvent( g_date->Date(), sbpcgs_ferti_s3, false );
195  break;
196 
197  case sbpcgs_ferti_s3: // The catch all
198  if ((!SBPCGS_FERTI_DONE)||( m_ev->m_lock || m_farm->DoIt( 70 ) ))
199  {
200  if (!m_farm->FA_NPK( m_field, 0.0,
201  g_date->DayInYear( 10, 4 ) - g_date->DayInYear()))
202  {
203  SimpleEvent( g_date->Date()+1, sbpcgs_ferti_s3, true );
204  break;
205  }
206  }
207  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,3 ),
208  sbpcgs_spring_sow, false );
209  break;
210 
211  case sbpcgs_spring_sow:
212  if (!m_farm->SpringSow( m_field, 0.0,
213  g_date->DayInYear( 20,4 ) - g_date->DayInYear())) {
214  SimpleEvent( g_date->Date() + 1, sbpcgs_spring_sow, true );
215  break;
216  }
217  SimpleEvent( g_date->Date()+1, sbpcgs_spring_roll, false );
218  break;
219 
220  case sbpcgs_spring_roll:
221  if ( m_ev->m_lock || m_farm->DoIt( 90 ))
222  {
223  if (!m_farm->SpringRoll( m_field, 0.0,
224  g_date->DayInYear( 21,4 ) - g_date->DayInYear())) {
225  SimpleEvent( g_date->Date() + 1, sbpcgs_spring_roll, true );
226  break;
227  }
228  }
229  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,3 ),
230  sbpcgs_strigling_sow, false );
231  break;
232 
233 
235  if ( m_ev->m_lock || m_farm->DoIt( 100 ))
236  {
237  if (!m_farm->StriglingSow( m_field, 0.0,
238  g_date->DayInYear( 30,4 ) - g_date->DayInYear())) {
239  SimpleEvent( g_date->Date() + 1, sbpcgs_strigling_sow, true );
240  break;
241  }
242  }
243  // Carry on with the next after first treatment or no treatment
244  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10,5 ),
245  sbpcgs_GR, false );
246  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10,5 ),
247  sbpcgs_fungicide, false );
248  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,6 ),
249  sbpcgs_water1, false );
250  break;
251 
252 
253  // GR Thread
254  case sbpcgs_GR:
255  if ( m_ev->m_lock || m_farm->DoIt( (int) (5*cfg_greg_app_prop.value() ))) // was 60
256  {
257  if (!m_farm->GrowthRegulator( m_field, 0.0,
258  g_date->DayInYear( 25,5 ) - g_date->DayInYear())) {
259  SimpleEvent( g_date->Date() + 1, sbpcgs_GR, true );
260  break;
261  }
262  }
263  break;
264 
265  // Water thread
266  case sbpcgs_water1:
267  if ( m_ev->m_lock || m_farm->DoIt( 20 ))
268  {
269  if ((!m_farm->Water( m_field, 0.0,
270  g_date->DayInYear( 15,6 ) - g_date->DayInYear()))
271  || (SBPCGS_SPRAY==g_date->DayInYear()))
272  {
273  SimpleEvent( g_date->Date() + 1, sbpcgs_water1, true );
274  break;
275  }
276  if (g_date->DayInYear()+5<g_date->DayInYear( 16,6 ))
277  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 16,6 ),
278  sbpcgs_water2, false );
279  else
280  SimpleEvent( g_date->Date()+5, sbpcgs_water2, false );
281  }
282  break;
283 
284  case sbpcgs_water2:
285  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
286  {
287  if ((!m_farm->Water( m_field, 0.0,
288  g_date->DayInYear( 1,7 ) - g_date->DayInYear()))
289  || (SBPCGS_SPRAY==g_date->DayInYear()))
290  {
291  SimpleEvent( g_date->Date() + 1, sbpcgs_water2, true );
292  break;
293  }
294  }
295  break;
296 
297  // Fungicide thread & MAIN THREAD
298  case sbpcgs_fungicide:
299  if ( m_ev->m_lock || m_farm->DoIt( (int) (40*cfg_herbi_app_prop.value() ))) // was 60
300  {
301  if (!m_farm->FungicideTreat( m_field, 0.0,
302  g_date->DayInYear( 25,5 ) - g_date->DayInYear())) {
303  SimpleEvent( g_date->Date() + 1, sbpcgs_fungicide, true );
304  break;
305  }
306  else
307  {
308  SBPCGS_SPRAY=g_date->DayInYear();
309  }
310  }
311  // can also try insecticide
312  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,5 ),
313  sbpcgs_insecticide, false );
314  break;
315 
316  // Insecticide & MAIN THREAD
317  case sbpcgs_insecticide:
318  if ( m_ev->m_lock || m_farm->DoIt( (int) (35*cfg_ins_app_prop1.value() ))) // was 50
319  {
320  if (!m_farm->InsecticideTreat( m_field, 0.0,
321  g_date->DayInYear( 10,6 ) - g_date->DayInYear())) {
322  SimpleEvent( g_date->Date() + 1, sbpcgs_insecticide, true );
323  break;
324  }
325  else SBPCGS_SPRAY=g_date->DayInYear();
326  }
327  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,8 ),
328  sbpcgs_harvest, false );
329  break;
330 
331  case sbpcgs_harvest:
332  if (!m_farm->Harvest( m_field, 0.0,
333  m_field->GetMDates(1,0) - g_date->DayInYear())) {
334  SimpleEvent( g_date->Date() + 1, sbpcgs_harvest, true );
335  break;
336  }
337  SimpleEvent(g_date->OldDays() + m_field->GetMDates(0, 1),
338  sbpcgs_hay_baling, false );
339  break;
340 
341  case sbpcgs_hay_baling:
342  if (!m_farm->HayBailing( m_field, 0.0,
343  m_field->GetMDates(1,1) - g_date->DayInYear()))
344  {
345  SimpleEvent( g_date->Date() + 1, sbpcgs_hay_baling, true );
346  break;
347  }
348  // Something special here.
349  // If the cattle out period is very short then we don't want to do it at all
350  if (m_field->GetMDates(1,2)-m_field->GetMDates(0,2)<14) done=true;
351  else SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,2),
352  sbpcgs_cattle_out, false );
353  break;
354 
355  case sbpcgs_cattle_out:
356 // ***CJT*** 010904 possibly causing a problem with unsprayed margins
357  // Uncomment the break if this is a problem
358 done=true;
359 //break;
360 // **CJT*** END
361  if (!m_farm->CattleOut( m_field, 0.0,
362  m_field->GetMDates(1,2) - g_date->DayInYear()))
363  {
364  SimpleEvent( g_date->Date() + 1, sbpcgs_cattle_out, true );
365  break;
366  }
367  SimpleEvent( g_date->Date() + 1, sbpcgs_cattle_is_out, false );
368  break;
369 
371  if (!m_farm->CattleIsOut( m_field, 0.0,
372  m_field->GetMDates(1,2) - g_date->DayInYear(),m_field->GetMDates(1,2)))
373  {
374  SimpleEvent( g_date->Date() + 1, sbpcgs_cattle_is_out, false );
375  break;
376  }
377  // END OF MAIN THREAD
378  done=true;
379  break;
380 
381  default:
382  g_msg->Warn( WARN_BUG, "SpringBarleyCloverGrass::Do(): "
383  "Unknown event type! ", "" );
384  exit( 1 );
385  }
386  return done;
387 }
388 
389 
sbpcgs_hay_baling
Definition: BarleyPeaCloverGrassStrigling.h:57
Farm::SpringRoll
virtual bool SpringRoll(LE *a_field, double a_user, int a_days)
Carry out a roll event in the spring on a_field.
Definition: farmfuncs.cpp:525
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
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
cfg_ins_app_prop1
CfgFloat cfg_ins_app_prop1
sbpcgs_water2
Definition: BarleyPeaCloverGrassStrigling.h:60
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
sbpcgs_cattle_out
Definition: BarleyPeaCloverGrassStrigling.h:63
FarmEvent
A struct to hold the information required to trigger a farm event.
Definition: farm.h:463
Farm::CattleIsOut
virtual bool CattleIsOut(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out' event for every day the cattle are on a_field.
Definition: farmfuncs.cpp:1974
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
sbpcgs_spring_plough
Definition: BarleyPeaCloverGrassStrigling.h:51
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
cfg_herbi_app_prop
CfgFloat cfg_herbi_app_prop
sbpcgs_fungicide
Definition: BarleyPeaCloverGrassStrigling.h:62
sbpcgs_spring_sow
Definition: BarleyPeaCloverGrassStrigling.h:55
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
SBPCGS_SPRAY
#define SBPCGS_SPRAY
Definition: BarleyPeaCloverGrassStrigling.h:43
cfg_strigling_prop
CfgFloat cfg_strigling_prop
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
sbpcgs_autumn_plough
Definition: BarleyPeaCloverGrassStrigling.h:52
sbpcgs_spring_roll
Definition: BarleyPeaCloverGrassStrigling.h:54
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
sbpcgs_ferti_s1
Definition: BarleyPeaCloverGrassStrigling.h:47
sbpcgs_spring_harrow
Definition: BarleyPeaCloverGrassStrigling.h:53
sbpcgs_harvest
Definition: BarleyPeaCloverGrassStrigling.h:50
cfg_greg_app_prop
CfgFloat cfg_greg_app_prop
cfg_fungi_app_prop1
CfgFloat cfg_fungi_app_prop1
sbpcgs_insecticide
Definition: BarleyPeaCloverGrassStrigling.h:61
SBPCGS_ISAUTUMNPLOUGH
#define SBPCGS_ISAUTUMNPLOUGH
Definition: BarleyPeaCloverGrassStrigling.h:41
sbpcgs_water1
Definition: BarleyPeaCloverGrassStrigling.h:59
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
SBPCGS_FERTI_DONE
#define SBPCGS_FERTI_DONE
Definition: BarleyPeaCloverGrassStrigling.h:42
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
Farm::SpringSow
virtual bool SpringSow(LE *a_field, double a_user, int a_days)
Carry out a sowing event in the spring on a_field.
Definition: farmfuncs.cpp:546
sbpcgs_GR
Definition: BarleyPeaCloverGrassStrigling.h:58
Farm::StriglingSow
virtual bool StriglingSow(LE *a_field, double a_user, int a_days)
Carry out a mechanical weeding followed by sowing on a_field.
Definition: farmfuncs.cpp:1597
sbpcgs_start
Definition: BarleyPeaCloverGrassStrigling.h:46
Farm
The base class for all farm types.
Definition: farm.h:767
sbpcgs_ferti_s3
Definition: BarleyPeaCloverGrassStrigling.h:49
Farm::GrowthRegulator
virtual bool GrowthRegulator(LE *a_field, double a_user, int a_days)
Apply growth regulator to a_field.
Definition: farmfuncs.cpp:1250
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539
Farm::CattleOut
virtual bool CattleOut(LE *a_field, double a_user, int a_days)
Start a grazing event on a_field today.
Definition: farmfuncs.cpp:1910
sbpcgs_ferti_s2
Definition: BarleyPeaCloverGrassStrigling.h:48
sbpcgs_cattle_is_out
Definition: BarleyPeaCloverGrassStrigling.h:64
sbpcgs_strigling_sow
Definition: BarleyPeaCloverGrassStrigling.h:56
Farm::SpringHarrow
virtual bool SpringHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the spring on a_field.
Definition: farmfuncs.cpp:471
SpringBarleyPeaCloverGrassStrigling::Do
bool Do(Farm *a_farm, LE *a_field, FarmEvent *a_ev)
Definition: SpringBarleyPeaCloverGrassStrigling.cpp:38