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

#include <OCloverGrassGrazed2.h>

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 OCloverGrassGrazed2 ()
 
- 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 48 of file OCloverGrassGrazed2.h.

Constructor & Destructor Documentation

◆ OCloverGrassGrazed2()

OCloverGrassGrazed2::OCloverGrassGrazed2 ( )
inline

Definition at line 52 of file OCloverGrassGrazed2.h.

53  {
54  m_first_date=g_date->DayInYear(1,4);
55  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

Definition at line 38 of file OCloverGrassGrazed2.cpp.

39 {
40  m_farm = a_farm;
41  m_field = a_field;
42  m_ev = a_ev;
43  bool done = false;
44  long d1 = 0;
45  int noDates= 2;
46 
47  switch ( m_ev->m_todo ) {
48  case ocgg2_start:
49  OCGG2_CUT_DATE = 0;
50  OCGG2_WATER_DATE = 0;
51 
52  // Set up the date management stuff
53  // Could save the start day in case it is needed later
54  // m_field->m_startday = m_ev->m_startday;
55  m_last_date=g_date->DayInYear(10,10);
56  // Start and stop dates for all events after harvest
57  m_field->SetMDates(0,0,g_date->DayInYear(27,7));
58  // Determined by harvest date - used to see if at all possible
59  m_field->SetMDates(1,0,g_date->DayInYear(10,10));
60  m_field->SetMDates(0,1,g_date->DayInYear(1,9));
61  m_field->SetMDates(1,1,g_date->DayInYear(1,10));
62  // Check the next crop for early start, unless it is a spring crop
63  // in which case we ASSUME that no checking is necessary!!!!
64  // So DO NOT implement a crop that runs over the year boundary
65  if (m_ev->m_startday>g_date->DayInYear(1,7))
66  {
67  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
68  {
69  g_msg->Warn( WARN_BUG, "OCloverGrassGrazed2::Do(): "
70  "Harvest too late for the next crop to start!!!", "" );
71  exit( 1 );
72  }
73  // Now fix any late finishing problems
74  for (int i=0; i<noDates; i++)
75  {
76  if (m_field->GetMDates(0,i)>=m_ev->m_startday) m_field->SetMDates(0,i,m_ev->m_startday-1);
77  if (m_field->GetMDates(1,i)>=m_ev->m_startday) m_field->SetMDates(1,i,m_ev->m_startday-1);
78  }
79  }
80  // Now no operations can be timed after the start of the next crop.
81  // Added test for management plan testing. FN, 19/5-2003.
82  if ( ! ( m_ev->m_first_year )) {
83  // Are we before July 1st?
84  d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
85  if (g_date->Date() < d1) {
86  // Yes, too early. We assumme this is because the last crop was late
87  g_msg->Warn( WARN_BUG, "OCloverGrassGrazed2::Do(): "
88  "Crop start attempt between 1st Jan & 1st July", "" );
89  exit( 1 );
90  } else {
91  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
92  if (g_date->Date() > d1) {
93  // Yes too late - should not happen - raise an error
94  g_msg->Warn( WARN_BUG, "OCloverGrassGrazed2::Do(): "
95  "Crop start attempt after last possible start date",
96  "" );
97  exit( 1 );
98  }
99  }
100  } else {
101  // First (invisible) year or testing. Force the correct starting date.
102  d1 = g_date->OldDays() + g_date->DayInYear( 1, 4 );
103  // If testing and not the first year, then push all events
104  // into next year (start event is called in the autumn after
105  // the current year has finished). FN, 20/5-2003.
106  if (!m_ev->m_first_year) d1 += 365;
107  }
108  m_field->SetLastSownVeg( m_field->GetOwner()->GetNextCrop( m_field->GetRotIndex() ) );
109  // OK, let's go.
110  OCGG2_CUT_DATE=0;
111  SimpleEvent( d1, ocgg2_ferti_zero, false );
112  break;
113  case ocgg2_ferti_zero:
114  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
115  {
116  if (!m_farm->FA_Slurry( m_field, 0.0,
117  g_date->DayInYear( 30, 4 ) - g_date->DayInYear())) {
118  // We didn't do it today, try again tomorrow.
119  SimpleEvent( g_date->Date() + 1, ocgg2_ferti_zero, true );
120  break;
121  }
122  }
123  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,5 ),
124  ocgg2_cattle_out, false );
125 // SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,5 ),
126 // cgg2_cut_to_silage, false );
127 
128 // Start a watering thread
129  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 5 ),
130  ocgg2_water_zero, false );
131  break;
132 
133 
134 case ocgg2_cattle_out:
135  if ( m_ev->m_lock || m_farm->DoIt( (int) (100-(cfg_silage_prop.value()*40) ))) {
136  if (cfg_organic_extensive.value()) {
137  if (!m_farm->CattleOutLowGrazing( m_field, 0.0,
138  m_field->GetMDates(1,1) -
139  g_date->DayInYear())) {
140  SimpleEvent( g_date->Date() + 1, ocgg2_cattle_out, true );
141  break;
142  }
143  }
144  else {
145  if (!m_farm->CattleOut( m_field, 0.0,
146  m_field->GetMDates(1,1) -
147  g_date->DayInYear())) {
148  SimpleEvent( g_date->Date() + 1, ocgg2_cattle_out, true );
149  break;
150  }
151  }
152  // Success
153  // Keep them out there
154  SimpleEvent( g_date->Date() + 1, ocgg2_cattle_is_out, false );
155  break;
156  }
157  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,5 ),
158  ocgg2_cut_to_silage, false );
159  break;
160 
161 case ocgg2_cattle_is_out: // Keep the cattle out there
162  // CattleIsOut() returns false if it is not time to stop grazing
163  if (cfg_organic_extensive.value()) {
164  if (!m_farm->CattleIsOutLow( m_field, 0.0, m_field->GetMDates(1,1) -
165  g_date->DayInYear(),m_field->GetMDates(1,1))) {
166  SimpleEvent( g_date->Date() + 1, ocgg2_cattle_is_out, false );
167  break;
168  }
169  }
170  else {
171  if ( !m_farm->CattleIsOut( m_field, 0.0,
172  m_field->GetMDates(1,1) -
173  g_date->DayInYear(),m_field->GetMDates(1,1)))
174  {
175  SimpleEvent( g_date->Date() + 1, ocgg2_cattle_is_out, false );
176  break;
177  }
178  }
179  done=true;
180  break;
181 
183 if ( m_ev->m_lock || m_farm->DoIt( 100 )) {
184  if ( g_date->Date() < OCGG2_WATER_DATE + 7 ) {
185  SimpleEvent( g_date->Date() + 1, ocgg2_cut_to_silage, true );
186  break;
187  }
188  if (!m_farm->CutToSilage( m_field, 0.0,
189  g_date->DayInYear( 25, 6 ) -
190  g_date->DayInYear())) {
191  // We didn't do it today, try again tomorrow.
192  SimpleEvent( g_date->Date() + 1, ocgg2_cut_to_silage, true );
193  break;
194  }
195  OCGG2_CUT_DATE = g_date->Date();
196  SimpleEvent(g_date->OldDays() + m_field->GetMDates(0,1), ocgg2_stubble_harrow, false );
197  // But we need to graze too
198  SimpleEvent( g_date->Date()+14, ocgg2_cattle_out, true );
199 }
200 break;
201 
203 if ( m_ev->m_lock || m_farm->DoIt( 20 )) {
204  // But first if we are grazing then we must stop this
205  //
206  if (!m_farm->StubbleHarrowing( m_field, 0.0,
207  m_field->GetMDates(1,1) -
208  g_date->DayInYear())) {
209  // We didn't do it today, try again tomorrow.
210  SimpleEvent( g_date->Date() + 1, ocgg2_stubble_harrow, true );
211  break;
212  }
213  // If we ran, then we also happen to be the last event,
214  // so terminate the program by stopping grazing
215  m_field->SetMDates(1,1,g_date->DayInYear()-1);
216 }
217 break;
218 
219 case ocgg2_water_zero:
220  if ( m_ev->m_lock || m_farm->DoIt( 25 )) {
221  if ( g_date->Date() < OCGG2_CUT_DATE + 3 ) {
222  // Try again tomorrow, too close to silage cutting.
223  SimpleEvent( g_date->Date() + 1, ocgg2_water_zero, true );
224  break;
225  }
226  if (!m_farm->Water( m_field, 0.0,
227  g_date->DayInYear( 30, 5 ) -
228  g_date->DayInYear())) {
229  // We didn't do it today, try again tomorrow.
230  SimpleEvent( g_date->Date() + 1, ocgg2_water_zero, true );
231  break;
232  }
233  OCGG2_WATER_DATE = g_date->Date();
234 
235  long newdate1 = g_date->OldDays() + g_date->DayInYear( 1,6 );
236  long newdate2 = g_date->Date() + 7;
237  if ( newdate2 > newdate1 )
238  newdate1 = newdate2;
239  SimpleEvent( newdate1, ocgg2_water_one, false );
240  }
241  break;
242 
243 case ocgg2_water_one:
244  if ( m_ev->m_lock || m_farm->DoIt( 25 )) {
245  if ( g_date->Date() < OCGG2_CUT_DATE + 3 ) {
246  // Try again tomorrow, too close to silage cutting.
247  SimpleEvent( g_date->Date() + 1, ocgg2_water_one, true );
248  break;
249  }
250  if (!m_farm->Water( m_field, 0.0,
251  g_date->DayInYear( 15, 6 ) -
252  g_date->DayInYear())) {
253  // We didn't do it today, try again tomorrow.
254  SimpleEvent( g_date->Date() + 1, ocgg2_water_one, true );
255  break;
256  }
257  OCGG2_WATER_DATE = g_date->Date();
258  }
259  break;
260  // End of watering thread.
261 
262 
263  default:
264  g_msg->Warn( WARN_BUG, "OCloverGrassGrazed2::Do(): "
265  "Unknown event type! ", "" );
266  exit( 1 );
267  }
268 
269  return done;
270 }

References cfg_organic_extensive, cfg_silage_prop, ocgg2_cattle_is_out, ocgg2_cattle_out, OCGG2_CUT_DATE, ocgg2_cut_to_silage, ocgg2_ferti_zero, ocgg2_start, ocgg2_stubble_harrow, OCGG2_WATER_DATE, ocgg2_water_one, and ocgg2_water_zero.


The documentation for this class was generated from the following files:
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
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
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
ocgg2_start
Definition: OCloverGrassGrazed2.h:36
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
OCGG2_WATER_DATE
#define OCGG2_WATER_DATE
Definition: OCloverGrassGrazed2.h:32
OCGG2_CUT_DATE
#define OCGG2_CUT_DATE
Definition: OCloverGrassGrazed2.h:31
cfg_organic_extensive
CfgBool cfg_organic_extensive
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
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
ocgg2_water_zero
Definition: OCloverGrassGrazed2.h:39
cfg_silage_prop
CfgFloat cfg_silage_prop
ocgg2_stubble_harrow
Definition: OCloverGrassGrazed2.h:43
ocgg2_ferti_zero
Definition: OCloverGrassGrazed2.h:37
ocgg2_cut_to_silage
Definition: OCloverGrassGrazed2.h:38
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
ocgg2_cattle_is_out
Definition: OCloverGrassGrazed2.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
ocgg2_cattle_out
Definition: OCloverGrassGrazed2.h:41
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
ocgg2_water_one
Definition: OCloverGrassGrazed2.h:40
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