ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
SpringBarleyCloverGrassStrigling.cpp
Go to the documentation of this file.
1 //
2 // SpringBarleyCloverGrassStrigling.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/SpringBarleyCloverGrassStrigling.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 SpringBarleyCloverGrassStrigling::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 sbcgs_start:
50  {
52  SBCGS_FERTI_DONE=false;
53  SBCGS_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  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
113  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,3 ),
114  sbcgs_spring_plough, false );
115  break;
116  }
117  // End single block date checking code. Please see next line
118  // comment as well.
119  // Reinit d1 to first possible starting date.
120  d1 = g_date->OldDays() + g_date->DayInYear( 1, 11 );
121  if (g_date->Date() >= d1) d1 += 365;
122  SimpleEvent( d1, sbcgs_autumn_plough, false );
123  }
124  break;
125 
126  case sbcgs_autumn_plough:
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, sbcgs_autumn_plough, true );
132  break;
133  }
135  }
136  // +365 for next year
137  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,3 )+365,
138  sbcgs_ferti_s1, false );
139  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,3 )+365,
140  sbcgs_ferti_s2, false );
141  break;
142 
143  case sbcgs_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, sbcgs_ferti_s1, true );
149  break;
150  }
151  // Done fertilizer so remember
152  SBCGS_FERTI_DONE=true;
153  }
154  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,3 ),
155  sbcgs_spring_plough, false );
156  break;
157 
158  case sbcgs_ferti_s2:
159  if (( m_ev->m_lock || m_farm->DoIt( 67 ) ) && (!SBCGS_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, sbcgs_ferti_s2, true );
165  break;
166  }
167  else
168  {
169  // Done fertilizer so remember
170  SBCGS_FERTI_DONE=true;
171  }
172  }
173  break;
174 
175  case sbcgs_spring_plough:
176  if ( !SBCGS_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, sbcgs_spring_plough, true );
181  break;
182  }
183  }
184  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,3 ),
185  sbcgs_spring_harrow, false );
186  break;
187 
188  case sbcgs_spring_harrow:
189  if (!m_farm->SpringHarrow( m_field, 0.0,
190  g_date->DayInYear( 10,4 ) - g_date->DayInYear())) {
191  SimpleEvent( g_date->Date() + 1, sbcgs_spring_harrow, true );
192  break;
193  }
194  SimpleEvent( g_date->Date(), sbcgs_ferti_s3, false );
195  break;
196 
197  case sbcgs_ferti_s3: // The catch all
198  if ((!SBCGS_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, sbcgs_ferti_s3, true );
204  break;
205  }
206  }
207  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,3 ),
208  sbcgs_spring_sow, false );
209  break;
210 
211  case sbcgs_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, sbcgs_spring_sow, true );
215  break;
216  }
217  SimpleEvent( g_date->Date()+1, sbcgs_spring_roll, false );
218  break;
219 
220  case sbcgs_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, sbcgs_spring_roll, true );
226  break;
227  }
228  }
229  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,3 ),
230  sbcgs_strigling1, false );
231  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,3 ),
232  sbcgs_strigling_sow, false );
233  break;
234 
235 case sbcgs_strigling1:
236  if ( m_ev->m_lock || (cfg_strigling_prop.value() * m_farm->DoIt( 90 )))
237  {
238  if (!m_farm->Strigling( m_field, 0.0,
239  g_date->DayInYear( 20,4 ) - g_date->DayInYear())) {
240  SimpleEvent( g_date->Date() + 1, sbcgs_strigling1, true );
241  break;
242  }
243  }
244 // End of thread
245 
246  case sbcgs_strigling_sow:
247  if ( m_ev->m_lock || m_farm->DoIt( 100 ))
248  {
249  if (!m_farm->StriglingSow( m_field, 0.0,
250  g_date->DayInYear( 30,4 ) - g_date->DayInYear())) {
251  SimpleEvent( g_date->Date() + 1, sbcgs_strigling_sow, true );
252  break;
253  }
254  }
255  // Carry on with the next after first treatment or no treatment
256  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10,5 ),
257  sbcgs_GR, false );
258  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10,5 ),
259  sbcgs_fungicide, false );
260  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,6 ),
261  sbcgs_water1, false );
262  break;
263 
264 
265  // GR Thread
266  case sbcgs_GR:
267  if ( m_ev->m_lock || m_farm->DoIt( (int) (5*cfg_greg_app_prop.value()))) // was 60
268  {
269  if (!m_farm->GrowthRegulator( m_field, 0.0,
270  g_date->DayInYear( 25,5 ) - g_date->DayInYear())) {
271  SimpleEvent( g_date->Date() + 1, sbcgs_GR, true );
272  break;
273  }
274  }
275  break;
276 
277  // Water thread
278  case sbcgs_water1:
279  if ( m_ev->m_lock || m_farm->DoIt( 20 ))
280  {
281  if ((!m_farm->Water( m_field, 0.0,
282  g_date->DayInYear( 15,6 ) - g_date->DayInYear()))
283  || (SBCGS_SPRAY==g_date->DayInYear()))
284  {
285  SimpleEvent( g_date->Date() + 1, sbcgs_water1, true );
286  break;
287  }
288  if (g_date->DayInYear()+5<g_date->DayInYear( 16,6 ))
289  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 16,6 ),
290  sbcgs_water2, false );
291  else
292  SimpleEvent( g_date->Date()+5, sbcgs_water2, false );
293  }
294  break;
295 
296  case sbcgs_water2:
297  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
298  {
299  if ((!m_farm->Water( m_field, 0.0,
300  g_date->DayInYear( 1,7 ) - g_date->DayInYear()))
301  || (SBCGS_SPRAY==g_date->DayInYear()))
302  {
303  SimpleEvent( g_date->Date() + 1, sbcgs_water2, true );
304  break;
305  }
306  }
307  break;
308 
309  // Fungicide thread & MAIN THREAD
310  case sbcgs_fungicide:
311  if ( m_ev->m_lock || m_farm->DoIt( (int) (40*cfg_herbi_app_prop.value() ))) // was 60
312  {
313  if (!m_farm->FungicideTreat( m_field, 0.0,
314  g_date->DayInYear( 25,5 ) - g_date->DayInYear())) {
315  SimpleEvent( g_date->Date() + 1, sbcgs_fungicide, true );
316  break;
317  }
318  else
319  {
320  SBCGS_SPRAY=g_date->DayInYear();
321  }
322  }
323  // can also try insecticide
324  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,5 ),
325  sbcgs_insecticide, false );
326  break;
327 
328  // Insecticide & MAIN THREAD
329  case sbcgs_insecticide:
330  if ( m_ev->m_lock || m_farm->DoIt( (int) (35*cfg_ins_app_prop1.value() ))) // was 50
331  {
332  if (!m_farm->InsecticideTreat( m_field, 0.0,
333  g_date->DayInYear( 10,6 ) - g_date->DayInYear())) {
334  SimpleEvent( g_date->Date() + 1, sbcgs_insecticide, true );
335  break;
336  }
337  else SBCGS_SPRAY=g_date->DayInYear();
338  }
339  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,8 ),
340  sbcgs_harvest, false );
341  break;
342 
343  case sbcgs_harvest:
344  if (!m_farm->Harvest( m_field, 0.0,
345  m_field->GetMDates(1,0) - g_date->DayInYear())) {
346  SimpleEvent( g_date->Date() + 1, sbcgs_harvest, true );
347  break;
348  }
349  SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,1),
350  sbcgs_hay_baling, false );
351  break;
352 
353  case sbcgs_hay_baling:
354  if (!m_farm->HayBailing( m_field, 0.0,
355  m_field->GetMDates(1,1) - g_date->DayInYear()))
356  {
357  SimpleEvent( g_date->Date() + 1, sbcgs_hay_baling, true );
358  break;
359  }
360  // Something special here.
361  // If the cattle out period is very short then we don't want to do it at all
362  if (m_field->GetMDates(1,2)-m_field->GetMDates(0,2)<14) done=true;
363  else SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,2),
364  sbcgs_cattle_out, false );
365  break;
366 
367  case sbcgs_cattle_out:
368 // ***CJT*** 010904 possibly causing a problem with unsprayed margins
369  // Uncomment the break if this is a problem
370 done=true;
371 //break;
372 // **CJT*** END
373  if (!m_farm->CattleOut( m_field, 0.0,
374  m_field->GetMDates(1,2) - g_date->DayInYear()))
375  {
376  SimpleEvent( g_date->Date() + 1, sbcgs_cattle_out, true );
377  break;
378  }
379  SimpleEvent( g_date->Date() + 1, sbcgs_cattle_is_out, false );
380  break;
381 
382  case sbcgs_cattle_is_out:
383  if (!m_farm->CattleIsOut( m_field, 0.0,
384  m_field->GetMDates(1,2) - g_date->DayInYear(),m_field->GetMDates(1,2)))
385  {
386  SimpleEvent( g_date->Date() + 1, sbcgs_cattle_is_out, false );
387  break;
388  }
389  // END OF MAIN THREAD
390  done=true;
391  break;
392 
393  default:
394  g_msg->Warn( WARN_BUG, "SpringBarleyCloverGrass::Do(): "
395  "Unknown event type! ", "" );
396  exit( 1 );
397  }
398  return done;
399 }
400 
401 
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
sbcgs_water1
Definition: SpringBarleyCloverGrassStrigling.h:49
sbcgs_spring_plough
Definition: SpringBarleyCloverGrassStrigling.h:42
Farm::Strigling
virtual bool Strigling(LE *a_field, double a_user, int a_days)
Carry out a mechanical weeding on a_field.
Definition: farmfuncs.cpp:1545
sbcgs_strigling1
Definition: SpringBarleyCloverGrassStrigling.h:51
sbcgs_fungicide
Definition: SpringBarleyCloverGrassStrigling.h:54
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
sbcgs_insecticide
Definition: SpringBarleyCloverGrassStrigling.h:53
cfg_herbi_app_prop
CfgFloat cfg_herbi_app_prop
FarmEvent
A struct to hold the information required to trigger a farm event.
Definition: farm.h:463
sbcgs_ferti_s1
Definition: SpringBarleyCloverGrassStrigling.h:38
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
sbcgs_ferti_s2
Definition: SpringBarleyCloverGrassStrigling.h:39
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
cfg_strigling_prop
CfgFloat cfg_strigling_prop
cfg_greg_app_prop
CfgFloat cfg_greg_app_prop
sbcgs_start
Definition: SpringBarleyCloverGrassStrigling.h:37
sbcgs_harvest
Definition: SpringBarleyCloverGrassStrigling.h:41
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
SBCGS_SPRAY
#define SBCGS_SPRAY
Definition: SpringBarleyCloverGrassStrigling.h:34
sbcgs_GR
Definition: SpringBarleyCloverGrassStrigling.h:48
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
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
sbcgs_spring_harrow
Definition: SpringBarleyCloverGrassStrigling.h:44
sbcgs_hay_baling
Definition: SpringBarleyCloverGrassStrigling.h:47
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
cfg_fungi_app_prop1
CfgFloat cfg_fungi_app_prop1
cfg_ins_app_prop1
CfgFloat cfg_ins_app_prop1
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
sbcgs_strigling_sow
Definition: SpringBarleyCloverGrassStrigling.h:52
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
sbcgs_autumn_plough
Definition: SpringBarleyCloverGrassStrigling.h:43
sbcgs_water2
Definition: SpringBarleyCloverGrassStrigling.h:50
sbcgs_ferti_s3
Definition: SpringBarleyCloverGrassStrigling.h:40
sbcgs_spring_roll
Definition: SpringBarleyCloverGrassStrigling.h:45
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
Farm
The base class for all farm types.
Definition: farm.h:767
sbcgs_spring_sow
Definition: SpringBarleyCloverGrassStrigling.h:46
sbcgs_cattle_out
Definition: SpringBarleyCloverGrassStrigling.h:55
Farm::GrowthRegulator
virtual bool GrowthRegulator(LE *a_field, double a_user, int a_days)
Apply growth regulator to a_field.
Definition: farmfuncs.cpp:1250
SBCGS_ISAUTUMNPLOUGH
#define SBCGS_ISAUTUMNPLOUGH
Definition: SpringBarleyCloverGrassStrigling.h:32
SBCGS_FERTI_DONE
#define SBCGS_FERTI_DONE
Definition: SpringBarleyCloverGrassStrigling.h:33
sbcgs_cattle_is_out
Definition: SpringBarleyCloverGrassStrigling.h:56
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
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
SpringBarleyCloverGrassStrigling::Do
bool Do(Farm *a_farm, LE *a_field, FarmEvent *a_ev)
Definition: SpringBarleyCloverGrassStrigling.cpp:38