ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
OBarleyPeaCloverGrass Class Reference

#include <OBarleyPeaCloverGrass.h>

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 OBarleyPeaCloverGrass ()
 
- Public Member Functions inherited from Crop
void ChooseNextCrop (int a_no_dates)
 Chooses the next crop to grow in a field. More...
 
 Crop ()
 
int GetCropClassification ()
 
int GetFirstDate (void)
 
void SetCropClassification (int a_classification)
 
virtual ~Crop ()
 

Additional Inherited Members

- Protected Member Functions inherited from Crop
void SimpleEvent (long a_date, int a_todo, bool a_lock)
 Adds an event to this crop management. More...
 
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. More...
 
- Protected Attributes inherited from Crop
int m_count
 
int m_CropClassification
 
int m_ddegstoharvest
 
FarmEventm_ev
 
Farmm_farm
 
LE * m_field
 
int m_first_date
 
int m_last_date
 

Detailed Description

Definition at line 53 of file OBarleyPeaCloverGrass.h.

Constructor & Destructor Documentation

◆ OBarleyPeaCloverGrass()

OBarleyPeaCloverGrass::OBarleyPeaCloverGrass ( )
inline

Definition at line 57 of file OBarleyPeaCloverGrass.h.

58  {
59  m_first_date=g_date->DayInYear(1,3);
60  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

bool OBarleyPeaCloverGrass::Do ( Farm a_farm,
LE *  a_field,
FarmEvent a_ev 
)
virtual

Reimplemented from Crop.

Definition at line 33 of file OBarleyPeaCloverGrass.cpp.

34 {
35  m_farm = a_farm;
36  m_field = a_field;
37  m_ev = a_ev;
38  int d1=0;
39 
40  bool done = false;
41 
42  switch ( m_ev->m_todo )
43  {
44  case obpcg_start:
45  {
46  // Set up the date management stuff
47  m_last_date=g_date->DayInYear(10,10);
48  // Start and stop dates for all events after harvest
49  int noDates= 3;
50  m_field->SetMDates(0,0,g_date->DayInYear(25,7));
51  // Determined by harvest date - used to see if at all possible
52  m_field->SetMDates(1,0,g_date->DayInYear(25,8));
53  m_field->SetMDates(0,1,g_date->DayInYear(10,10));
54  m_field->SetMDates(1,1,g_date->DayInYear(10,10));
55  m_field->SetMDates(0,2,g_date->DayInYear(25,7));
56  m_field->SetMDates(1,2,g_date->DayInYear(1,8));
57  // Check the next crop for early start, unless it is a spring crop
58  // in which case we ASSUME that no checking is necessary!!!!
59  // So DO NOT implement a crop that runs over the year boundary
60  if (m_ev->m_startday>g_date->DayInYear(1,7))
61  {
62  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
63  {
64  g_msg->Warn( WARN_BUG, "OBarleyPeaCloverGrass::Do(): "
65  "Harvest too late for the next crop to start!!!", "" );
66  exit( 1 );
67  }
68  // Now fix any late finishing problems
69  for (int i=0; i<noDates; i++)
70  {
71  if (m_field->GetMDates(0,i)>=m_ev->m_startday)
72  m_field->SetMDates(0,i,m_ev->m_startday-1);
73  if (m_field->GetMDates(1,i)>=m_ev->m_startday)
74  m_field->SetMDates(1,i,m_ev->m_startday-1);
75  }
76  }
77  // Now no operations can be timed after the start of the next crop.
78 
79  // Now no operations can be timed after the start of the next crop.
80 
81  int today=g_date->Date();
82  d1 = g_date->OldDays() + m_first_date;
83  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
84  if (today > d1)
85  {
86  // Yes too late - should not happen - raise an error
87  g_msg->Warn( WARN_BUG, "OBarleyPeaCloverGrass::Do(): "
88  "Crop start attempt after last possible start date", "" );
89  exit( 1 );
90  }
91  // OK, let's go.
92  SimpleEvent( d1, obpcg_ferti_zero, false );
93  }
94  break;
95 
96  case obpcg_ferti_zero:
97  if ( m_ev->m_lock || m_farm->DoIt( 20 ))
98  {
99  if (!m_farm->FA_Manure( m_field, 0.0,
100  g_date->DayInYear( 10, 4 ) - g_date->DayInYear()))
101  {
102  SimpleEvent( g_date->Date() + 1, obpcg_ferti_zero, true );
103  break;
104  }
105  }
106  SimpleEvent( g_date->Date(),obpcg_ferti_one, false );
107  break;
108 
109  case obpcg_ferti_one:
110  if ( m_ev->m_lock || m_farm->DoIt( 100 ))
111  {
112  if (!m_farm->FA_Slurry( m_field, 0.0,
113  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
114  SimpleEvent( g_date->Date() + 1, obpcg_ferti_one, true );
115  break;
116  }
117  }
118  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 3 ),
119  obpcg_spring_plough, false );
120  break;
121 
122  case obpcg_spring_plough:
123  if (!m_farm->SpringPlough( m_field, 0.0,
124  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
125  SimpleEvent( g_date->Date() + 1, obpcg_spring_plough, true );
126  break;
127  }
128  SimpleEvent( g_date->Date(), obpcg_spring_harrow, false );
129  break;
130 
131  case obpcg_spring_harrow:
132  if (!m_farm->SpringHarrow( m_field, 0.0,
133  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
134  SimpleEvent( g_date->Date() + 1, obpcg_spring_harrow, true );
135  break;
136  }
137  SimpleEvent( g_date->Date(), obpcg_spring_roll, false );
138  break;
139 
140  case obpcg_spring_roll:
141  if (!m_farm->SpringRoll( m_field, 0.0,
142  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
143  SimpleEvent( g_date->Date() + 1, obpcg_spring_roll, true );
144  break;
145  }
146  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20, 3 ),
147  obpcg_spring_sow1, false );
148  break;
149 
150  case obpcg_spring_sow1:
151  if (!m_farm->SpringSow( m_field, 0.0,
152  g_date->DayInYear( 12, 4 ) - g_date->DayInYear())) {
153  SimpleEvent( g_date->Date() + 1, obpcg_spring_sow1, true );
154  break;
155  }
156  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,3 ),
157  obpcg_spring_sow2, false );
158  break;
159 
160  case obpcg_spring_sow2:
161  if (!m_farm->SpringSow( m_field, 0.0,
162  g_date->DayInYear( 12, 4 ) - g_date->DayInYear())) {
163  SimpleEvent( g_date->Date() + 1, obpcg_spring_sow2, true );
164  break;
165  }
166  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5,6 ),
167  obpcg_water1, false );
168  break;
169 
170  case obpcg_water1:
171  if ( m_ev->m_lock || m_farm->DoIt( 10 ))
172  {
173  if (!m_farm->Water( m_field, 0.0,
174  g_date->DayInYear( 15,6 ) - g_date->DayInYear())) {
175  SimpleEvent( g_date->Date() + 1, obpcg_water1, true );
176  break;
177  }
178  // Must have watered so do it again
179  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 16,6 ),
180  obpcg_water2, false );
181  break;
182  }
183  // Must have failed to water so go straight to cut to silage
184  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,7 ),
185  obpcg_cut_to_silage, false );
186  break;
187 
188  case obpcg_water2:
189  if (!m_farm->Water( m_field, 0.0,
190  g_date->DayInYear( 30,6 ) - g_date->DayInYear())) {
191  SimpleEvent( g_date->Date() + 1, obpcg_water2, true );
192  break;
193  }
194  SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,2),
195  obpcg_cut_to_silage, false );
196  break;
197 
198  case obpcg_cut_to_silage:
199  if ( m_ev->m_lock || m_farm->DoIt( 95 ))
200  {
201  if (!m_farm->CutToSilage( m_field, 0.0,
202  m_field->GetMDates(1,2) - g_date->DayInYear())) {
203  SimpleEvent( g_date->Date() + 1, obpcg_cut_to_silage, true );
204  break;
205  }
206  m_field->SetGrowthPhase( harvest1 );
207  // cjt 210503 need some special checking here to make sure we don't go
208  // over the last date possible
209  if ((g_date->DayInYear( )+21)>= m_field->GetMDates(0,1))
210  d1=m_field->GetMDates(0,1);
211  else d1=g_date->DayInYear( )+21;
212  SimpleEvent( d1,obpcg_cattle_out, false );
213  break;
214  }
215  // Did not cut for silage to do harvest instead
216  SimpleEvent( g_date->OldDays() + m_field->GetMDates( 0,0 ),
217  obpcg_harvest, false );
218  break;
219 
220  case obpcg_harvest:
221  if (!m_farm->Harvest( m_field, 0.0,
222  m_field->GetMDates(1,0) - g_date->DayInYear())) {
223  SimpleEvent( g_date->Date() + 1, obpcg_harvest, true );
224  break;
225  }
226  // cjt 210503 need some special checking here to make sure we don't go
227  // over the last date possible
228  if ((g_date->DayInYear( )+21)>= m_field->GetMDates(0,1))
229  d1=m_field->GetMDates(0,1);
230  else d1=g_date->DayInYear( )+21;
231  SimpleEvent( g_date->OldDays() + d1,obpcg_cattle_out, false );
232  break;
233 
234  case obpcg_cattle_out:
235  if ( m_ev->m_lock || m_farm->DoIt( 90 ))
236  {
237  if (cfg_organic_extensive.value()){
238  if (!m_farm->CattleOutLowGrazing( m_field, 0.0,
239  m_field->GetMDates(0,1) - g_date->DayInYear())) {
240  SimpleEvent( g_date->Date() + 1, obpcg_cattle_out, true );
241  break;
242  }
243  }
244  else {
245  if (!m_farm->CattleOut( m_field, 0.0,
246  m_field->GetMDates(0,1) - g_date->DayInYear())) {
247  SimpleEvent( g_date->Date() + 1, obpcg_cattle_out, true );
248  break;
249  }
250  }
251 
252  SimpleEvent( g_date->Date() + 1, obpcg_cattle_is_out, false );
253  break;
254  }
255  done=true;
256  // END OF MAIN THREAD
257  break;
258 
259  case obpcg_cattle_is_out:
260 
261  if (cfg_organic_extensive.value()){
262  if (!m_farm->CattleIsOutLow( m_field, 0.0,
263  m_field->GetMDates(1,1) - g_date->DayInYear(),m_field->GetMDates(1,1)))
264  {
265  SimpleEvent( g_date->Date() + 1, obpcg_cattle_is_out, false );
266  break;
267  }
268  }
269  else {
270  if (!m_farm->CattleIsOut( m_field, 0.0,
271  m_field->GetMDates(1,1) - g_date->DayInYear(),m_field->GetMDates(1,1)))
272  {
273  SimpleEvent( g_date->Date() + 1, obpcg_cattle_is_out, false );
274  break;
275  }
276  }
277  // END OF MAIN THREAD
278  done = true;
279  break;
280 
281  default:
282  g_msg->Warn( WARN_BUG, "OBarleyPeaCloverGrass::Do(): "
283  "Unknown event type! ", "" );
284  exit( 1 );
285  }
286 
287  return done;
288 }

References Farm::CattleIsOut(), Farm::CattleIsOutLow(), Farm::CattleOut(), Farm::CattleOutLowGrazing(), cfg_organic_extensive, Farm::CutToSilage(), Farm::DoIt(), Farm::FA_Manure(), Farm::FA_Slurry(), Farm::Harvest(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_first_date, FarmEvent::m_first_year, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_startday, FarmEvent::m_todo, obpcg_cattle_is_out, obpcg_cattle_out, obpcg_cut_to_silage, obpcg_ferti_one, obpcg_ferti_zero, obpcg_harvest, obpcg_spring_harrow, obpcg_spring_plough, obpcg_spring_roll, obpcg_spring_sow1, obpcg_spring_sow2, obpcg_start, obpcg_water1, obpcg_water2, Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringRoll(), Farm::SpringSow(), and Farm::Water().


The documentation for this class was generated from the following files:
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
obpcg_harvest
Definition: OBarleyPeaCloverGrass.h:38
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
obpcg_water2
Definition: OBarleyPeaCloverGrass.h:37
obpcg_ferti_one
Definition: OBarleyPeaCloverGrass.h:39
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::CutToSilage
virtual bool CutToSilage(LE *a_field, double a_user, int a_days)
Cut vegetation for silage on a_field.
Definition: farmfuncs.cpp:2329
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
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_organic_extensive
CfgBool cfg_organic_extensive
obpcg_cattle_out
Definition: OBarleyPeaCloverGrass.h:47
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
obpcg_spring_sow1
Definition: OBarleyPeaCloverGrass.h:44
Farm::CattleIsOutLow
virtual bool CattleIsOutLow(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out_low' event for every day the cattle are on a_field.
Definition: farmfuncs.cpp:2018
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
Farm::CattleOutLowGrazing
virtual bool CattleOutLowGrazing(LE *a_field, double a_user, int a_days)
Start a extensive grazing event on a_field today.
Definition: farmfuncs.cpp:1944
obpcg_spring_harrow
Definition: OBarleyPeaCloverGrass.h:41
obpcg_start
Definition: OBarleyPeaCloverGrass.h:34
obpcg_spring_sow2
Definition: OBarleyPeaCloverGrass.h:45
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
obpcg_spring_plough
Definition: OBarleyPeaCloverGrass.h:40
obpcg_spring_roll
Definition: OBarleyPeaCloverGrass.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::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
obpcg_cattle_is_out
Definition: OBarleyPeaCloverGrass.h:48
obpcg_water1
Definition: OBarleyPeaCloverGrass.h:36
obpcg_cut_to_silage
Definition: OBarleyPeaCloverGrass.h:46
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
obpcg_ferti_zero
Definition: OBarleyPeaCloverGrass.h:35
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