ALMaSS Skylark ODDox  1.1
The skylark model description following ODdox protocol
OPermanentGrassGrazed Class Reference

#include <OPermanentGrassGrazed.h>

Public Member Functions

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

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
Farmm_farm
 
LE * m_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_CropClassification
 

Constructor & Destructor Documentation

◆ OPermanentGrassGrazed()

OPermanentGrassGrazed::OPermanentGrassGrazed ( )
inline
56  {
57  m_first_date=g_date->DayInYear(14,4);
58  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

34 {
35  m_farm = a_farm;
36  m_field = a_field;
37  m_ev = a_ev;
38 
39  bool done = false;
40 
41  switch ( m_ev->m_todo ) {
42  case opgg_start:
43  {
44  // Set up the date management stuff
45  m_last_date=g_date->DayInYear(1,10);
46  // Start and stop dates for all events after harvest
47  m_field->SetMDates(0,0,g_date->DayInYear(25,6));
48  // Determined by harvest date - used to see if at all possible
49  m_field->SetMDates(1,0,g_date->DayInYear(1,10));
50  if (m_ev->m_startday>g_date->DayInYear(1,7))
51  {
52  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
53  {
54  g_msg->Warn( WARN_BUG, "OPermanentGrassGrazed::Do(): "
55  "Harvest too late for the next crop to start!!!", "" );
56  exit( 1 );
57  }
58  // No need to try to fix late fininshing, this crop cannot be in
59  // rotation, and must be followed by itself
60  }
61  int d1;
62 
63  int today=g_date->Date();
64  d1 = g_date->OldDays() + m_first_date;
65  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
66  if (today > d1)
67  {
68  // Yes too late - should not happen - raise an error
69  g_msg->Warn( WARN_BUG, "OPermanentGrassGrazed::Do(): "
70  "Crop start attempt after last possible start date", "" );
71  exit( 1 );
72  }
73  // Reinit d1 to first possible starting date.
74  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
75  if ( g_date->Date() > d1 ) {
76  d1 = g_date->Date();
77  }
78  // OK, let's go.
79  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
80 
82  OPGG_CUT_DATE=0;
83  if (m_farm->IsStockFarmer())
84  SimpleEvent( d1, opgg_ferti_s, false );
85  else SimpleEvent( d1+60, opgg_cut_to_hay, false );
86  }
87  break;
88 
89  case opgg_ferti_s:
90  if ( m_ev->m_lock || m_farm->DoIt( 10 ))
91  {
92  if (!m_farm->FA_Slurry( m_field, 0.0,
93  g_date->DayInYear( 15,6 ) - g_date->DayInYear())) {
94  SimpleEvent( g_date->Date() + 1, opgg_ferti_s, true );
95  break;
96  }
97  OPGG_FERTI_DATE=g_date->DayInYear();
98  SimpleEvent( g_date->Date() + 28,opgg_cut_to_hay, false );
99  break;
100  }
101  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,6 ),
102  opgg_cut_to_hay, false );
103  break;
104 
105  case opgg_cut_to_hay:
106  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
107  {
108  if (!m_farm->CutToHay( m_field, 0.0,
109  g_date->DayInYear( 15,8 ) - g_date->DayInYear())) {
110  SimpleEvent( g_date->Date() + 1, opgg_cut_to_hay, true );
111  break;
112  }
113  // did cut to hay so try turning
114  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 26,6 ),
115  opgg_raking1, false );
116  OPGG_CUT_DATE=g_date->DayInYear();
117  break;
118  }
119  if (OPGG_FERTI_DATE+28 < g_date->DayInYear( 15, 6 ))
120  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 6 ),
121  opgg_cattle_out2, false ); // 80% of non-cutters graze
122  else
123  SimpleEvent( g_date->OldDays() + OPGG_FERTI_DATE+28,
124  opgg_cattle_out2, false ); // 80% of non-cutters graze
125 
126  break;
127 
128  case opgg_raking1:
129  if (!m_farm->HayTurning( m_field, 0.0,
130  (OPGG_CUT_DATE+10) - g_date->DayInYear())) {
131  SimpleEvent( g_date->Date() + 1, opgg_raking1, true );
132  break;
133  }
134  else
135  OPGG_TURN_DATE=g_date->DayInYear()+7;
136  SimpleEvent( g_date->Date()+1, opgg_raking2, false );
137  break;
138 
139  case opgg_raking2:
140  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
141  {
142  if (!m_farm->HayTurning( m_field, 0.0,
143  OPGG_TURN_DATE - g_date->DayInYear())) {
144  SimpleEvent( g_date->Date() + 1, opgg_raking2, true );
145  break;
146  }
147  else
148  OPGG_TURN_DATE=g_date->DayInYear()+7;
149  }
150  SimpleEvent( g_date->OldDays() + g_date->DayInYear()+1,
151  opgg_compress_straw, false );
152  break;
153 
154  case opgg_compress_straw:
155  if (!m_farm->HayBailing( m_field, 0.0,
156  OPGG_TURN_DATE - g_date->DayInYear()))
157  {
158  SimpleEvent( g_date->Date() + 1, opgg_compress_straw, true );
159  break;
160  }
161  // Did compress straw
162  SimpleEvent( g_date->OldDays() + g_date->DayInYear()+21,
163  opgg_cattle_out1, false ); // cut but no straw so 100% graze
164  break;
165 
166  case opgg_cattle_out1:
167  if (cfg_organic_extensive.value()){
168  if (!m_farm->CattleOutLowGrazing( m_field, 0.0,
169  g_date->DayInYear( 1,10 ) - g_date->DayInYear())) {
170  SimpleEvent( g_date->Date() + 1, opgg_cattle_out1, true );
171  break;
172  }
173  }
174  else {
175  if (!m_farm->CattleOut( m_field, 0.0,
176  g_date->DayInYear( 1,10 ) - g_date->DayInYear())) {
177  SimpleEvent( g_date->Date() + 1, opgg_cattle_out1, true );
178  break;
179  }
180  }
181  SimpleEvent( g_date->Date() + 1, opgg_cattle_is_out, false );
182  break;
183 
184  case opgg_cattle_out2:
185  if ( ( m_ev->m_lock || m_farm->DoIt( 80 )) || (OPGG_FERTI_DATE!=0) )
186  {
187  if (cfg_organic_extensive.value()){
188  if (!m_farm->CattleOutLowGrazing( m_field, 0.0,
189  g_date->DayInYear( 1,10 ) - g_date->DayInYear())) {
190  SimpleEvent( g_date->Date() + 1, opgg_cattle_out2, true );
191  break;
192  }
193  }
194  else {
195  if (!m_farm->CattleOut( m_field, 0.0,
196  g_date->DayInYear( 1,10 ) - g_date->DayInYear())) {
197  SimpleEvent( g_date->Date() + 1, opgg_cattle_out2, true );
198  break;
199  }
200  }
201  // Success
202  SimpleEvent( g_date->Date() + 1, opgg_cattle_is_out, false );
203  break;
204  }
205  SimpleEvent( g_date->OldDays() + g_date->DayInYear(5,9),
206  opgg_cut_weeds, false );
207  break;
208 
209  case opgg_cattle_is_out:
210  if (cfg_organic_extensive.value()){
211  if (!m_farm->CattleIsOutLow( m_field, 0.0,
212  g_date->DayInYear( 1, 10 ) - g_date->DayInYear(),g_date->DayInYear( 1, 10 )))
213  {
214  SimpleEvent( g_date->Date() + 1, opgg_cattle_is_out, true );
215  break;
216  }
217  }
218  else {
219  if (!m_farm->CattleIsOut( m_field, 0.0,
220  g_date->DayInYear( 1, 10 ) - g_date->DayInYear(),g_date->DayInYear( 1, 10 )))
221  {
222  SimpleEvent( g_date->Date() + 1, opgg_cattle_is_out, true );
223  break;
224  }
225  }
226  // if they come in the send them out if too early
227  if (g_date->DayInYear()<g_date->DayInYear(10,9))
228  {
229  SimpleEvent( g_date->Date()+1, opgg_cattle_out2, true );
230  break;
231  }
232  SimpleEvent( g_date->OldDays() + g_date->DayInYear(15,6),
233  opgg_cut_weeds, false );
234  break;
235 
236  case opgg_cut_weeds:
237  if (( m_ev->m_lock || m_farm->DoIt( 25 ))&&
238  (g_date->Date()<g_date->DayInYear(15,9)))
239  {
240  if (!m_farm->CutWeeds( m_field, 0.0,
241  g_date->DayInYear( 15,9 ) - g_date->DayInYear())) {
242  SimpleEvent( g_date->Date() + 1, opgg_cut_weeds, true );
243  break;
244  }
245  }
246  // END MAIN THREAD
247  done = true;
248  break;
249 
250  default:
251  g_msg->Warn( WARN_BUG, "PermanantGrassGrazed::Do(): "
252  "Unknown event type! ", "" );
253  exit( 1 );
254  }
255 
256  return done;
257 }

References Farm::CattleIsOut(), Farm::CattleIsOutLow(), Farm::CattleOut(), Farm::CattleOutLowGrazing(), cfg_organic_extensive, Farm::CutToHay(), Farm::CutWeeds(), Farm::DoIt(), Farm::FA_Slurry(), Farm::HayBailing(), Farm::HayTurning(), Farm::IsStockFarmer(), 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, opgg_cattle_is_out, opgg_cattle_out1, opgg_cattle_out2, opgg_compress_straw, OPGG_CUT_DATE, opgg_cut_to_hay, opgg_cut_weeds, OPGG_FERTI_DATE, opgg_ferti_s, opgg_raking1, opgg_raking2, opgg_start, OPGG_TURN_DATE, and Crop::SimpleEvent().


The documentation for this class was generated from the following files:
opgg_cattle_out1
Definition: OPermanentGrassGrazed.h:39
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
OPGG_FERTI_DATE
#define OPGG_FERTI_DATE
Definition: OPermanentGrassGrazed.h:33
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
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::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::CutToHay
virtual bool CutToHay(LE *a_field, double a_user, int a_days)
Carry out hay cutting on a_field.
Definition: farmfuncs.cpp:2269
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
opgg_cattle_is_out
Definition: OPermanentGrassGrazed.h:41
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
opgg_raking1
Definition: OPermanentGrassGrazed.h:44
opgg_raking2
Definition: OPermanentGrassGrazed.h:45
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
opgg_cut_to_hay
Definition: OPermanentGrassGrazed.h:38
opgg_ferti_s
Definition: OPermanentGrassGrazed.h:43
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
opgg_start
Definition: OPermanentGrassGrazed.h:37
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
Crop::m_field
LE * m_field
Definition: farm.h:538
opgg_compress_straw
Definition: OPermanentGrassGrazed.h:46
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
Crop::m_last_date
int m_last_date
Definition: farm.h:542
OPGG_CUT_DATE
#define OPGG_CUT_DATE
Definition: OPermanentGrassGrazed.h:32
opgg_cattle_out2
Definition: OPermanentGrassGrazed.h:40
OPGG_TURN_DATE
#define OPGG_TURN_DATE
Definition: OPermanentGrassGrazed.h:34
cfg_organic_extensive
CfgBool cfg_organic_extensive
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
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
opgg_cut_weeds
Definition: OPermanentGrassGrazed.h:42
Farm::CutWeeds
virtual bool CutWeeds(LE *a_field, double a_user, int a_days)
Carry out weed topping on a_field.
Definition: farmfuncs.cpp:2303