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

#include <OMaizeSilage.h>

Public Member Functions

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

Constructor & Destructor Documentation

◆ OMaizeSilage()

OMaizeSilage::OMaizeSilage ( )
inline

Definition at line 57 of file OMaizeSilage.h.

58  {
59  m_first_date = g_date->DayInYear(25, 4);
60  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

Definition at line 32 of file OMaizeSilage.cpp.

33 {
34  m_farm = a_farm;
35  m_field = a_field;
36  m_ev = a_ev;
37  int d1=0;
38 
39  bool done = false;
40  switch ( m_ev->m_todo ) {
41  case oms_start:
42  {
44  // Set up the date management stuff
45  m_last_date=g_date->DayInYear(30,9);
46  // Start and stop dates for all events after harvest
47  int noDates= 2;
48  m_field->SetMDates(0,0,g_date->DayInYear(1,9));
49  // 0,0 determined by harvest date - used to see if at all possible
50  m_field->SetMDates(1,0,g_date->DayInYear(10,9));
51  m_field->SetMDates(0,1,g_date->DayInYear(15,9));
52  m_field->SetMDates(1,1,g_date->DayInYear(30,9));
53  // Check the next crop for early start, unless it is a spring crop
54  // in which case we ASSUME that no checking is necessary!!!!
55  // So DO NOT implement a crop that runs over the year boundary
56  if (m_ev->m_startday>g_date->DayInYear(1,7))
57  {
58  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
59  {
60  char veg_type[20];
61  sprintf(veg_type, "%d", m_ev->m_next_tov);
62  g_msg->Warn(WARN_FILE, "OMaizeSilage::Do(): Harvest too late for the next crop to start!!! The next crop is: ", veg_type);
63  exit(1);
64  }
65  // Now fix any late finishing problems
66  for (int i=0; i<noDates; i++)
67  {
68  if (m_field->GetMDates(0,i)>=m_ev->m_startday)
69  m_field->SetMDates(0,i,m_ev->m_startday-1);
70  if (m_field->GetMDates(1,i)>=m_ev->m_startday)
71  m_field->SetMDates(1,i,m_ev->m_startday-1);
72  }
73  }
74  // Now no operations can be timed after the start of the next crop.
75 
76  if ( ! m_ev->m_first_year )
77  {
78  int today=g_date->Date();
79  // Are we before July 1st?
80  d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
81  if (today < d1)
82  {
83  // Yes, too early. We assumme this is because the last crop was late
84  g_msg->Warn( WARN_BUG, "OMaizeSilage::Do(): "
85  "Crop start attempt between 1st Jan & 1st July", "" );
86  exit( 1 );
87  }
88  else
89  {
90  d1 = g_date->OldDays() + m_first_date +365; // Add 365 for spring crop
91  if (today > d1)
92  {
93  // Yes too late - should not happen - raise an error
94  g_msg->Warn( WARN_BUG, "OMaizeSilage::Do(): "
95  "Crop start attempt after last possible start date", "" );
96  exit( 1 );
97  }
98  }
99  }
100  else
101  {
102  SimpleEvent( d1, oms_spring_plough, false );
103  break;
104  }
105  // End single block date checking code. Please see next line
106  // comment as well.
107  // Reinit d1 to first possible starting date.
108  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
109  if ( g_date->Date() > d1 ) {
110  d1 = g_date->Date();
111  }
112  // OK, let's go.
113  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20, 3 ) + 365, oms_fa_manure_b, false );
114  break;
115  }
116 
117  case oms_fa_manure_b:
118  if (!m_farm->FA_Manure( m_field, 0.0,
119  g_date->DayInYear( 25, 4 ) - g_date->DayInYear())) {
120  SimpleEvent( g_date->Date() + 1, oms_fa_manure_b, false );
121  break;
122  }
123  {
124  d1 = g_date->OldDays() + g_date->DayInYear( 1, 4 );
125  if ( g_date->Date()+1 > d1 ) {
126  d1 = g_date->Date()+1;
127  }
128  SimpleEvent( d1, oms_fa_slurry_one, false );
129  }
130  break;
131 
132  case oms_fa_slurry_one:
133  if (!m_farm->FA_Slurry( m_field, 0.0,
134  g_date->DayInYear( 30, 4 ) - g_date->DayInYear())) {
135  SimpleEvent( g_date->Date() + 1, oms_fa_slurry_one, false );
136  break;
137  }
138  SimpleEvent( g_date->Date() + 1, oms_spring_plough, false );
139  break;
140 
141  case oms_spring_plough:
142  if (!m_farm->SpringPlough( m_field, 0.0,
143  g_date->DayInYear( 1, 5 ) - g_date->DayInYear())) {
144  SimpleEvent( g_date->Date() + 1, oms_spring_plough, false );
145  break;
146  }
147  SimpleEvent( g_date->Date(), oms_spring_harrow, false );
148  break;
149 
150  case oms_spring_harrow:
151  if (!m_farm->SpringHarrow( m_field, 0.0,
152  g_date->DayInYear( 10, 5 ) - g_date->DayInYear())) {
153  SimpleEvent( g_date->Date() + 1, oms_spring_harrow, false );
154  break;
155  }
156  {
157  d1 = g_date->OldDays() + g_date->DayInYear( 25, 4 );
158  if ( g_date->Date() > d1 ) {
159  d1 = g_date->Date();
160  }
161  SimpleEvent( d1, oms_spring_sow, false );
162  }
163  break;
164 
165  case oms_spring_sow:
166  if (!m_farm->SpringSow( m_field, 0.0,
167  g_date->DayInYear( 15, 5 ) - g_date->DayInYear())) {
168  SimpleEvent( g_date->Date() + 1, oms_spring_sow, false );
169  break;
170  }
171  OMAIZESILAGE_SOW_DATE = g_date->Date();
172  SimpleEvent( g_date->Date(), oms_fa_npk, false );
173  break;
174 
175  case oms_fa_npk:
176  if (!m_farm->FA_NPK( m_field, 0.0,
177  g_date->DayInYear( 20, 5 ) - g_date->DayInYear())) {
178  SimpleEvent( g_date->Date() + 1, oms_fa_npk, false );
179  break;
180  }
181  {
182  d1 = g_date->OldDays() + g_date->DayInYear( 2, 5 );
183  if ( OMAIZESILAGE_SOW_DATE + 7 > d1 ) {
184  d1 = OMAIZESILAGE_SOW_DATE + 7;
185  }
186  SimpleEvent( d1, oms_row_one, false );
187  }
188  break;
189 
190  case oms_row_one:
191  if (!m_farm->RowCultivation( m_field, 0.0,
192  g_date->DayInYear( 25, 5 ) - g_date->DayInYear())) {
193  SimpleEvent( g_date->Date() + 1, oms_row_one, false );
194  break;
195  }
196  {
197  d1 = g_date->OldDays() + g_date->DayInYear( 1, 5 );
198  if ( OMAIZESILAGE_SOW_DATE + 5 > d1 ) {
199  d1 = OMAIZESILAGE_SOW_DATE + 5;
200  }
201  SimpleEvent( d1, oms_fa_slurry_two, false );
202  }
203  break;
204 
205  case oms_fa_slurry_two:
206  if (!m_farm->FA_Slurry( m_field, 0.0,
207  g_date->DayInYear( 25, 5 ) - g_date->DayInYear())) {
208  SimpleEvent( g_date->Date() + 1, oms_fa_slurry_two, false );
209  break;
210  }
211  d1 = g_date->OldDays() + g_date->DayInYear( 21, 5 );
212  if ( g_date->Date() + 1 > d1 ) {
213  d1 = g_date->Date() + 1;
214  }
215  SimpleEvent( d1, oms_row_two, false );
216  break;
217 
218  case oms_row_two:
219  if (!m_farm->RowCultivation( m_field, 0.0,
220  g_date->DayInYear( 20, 6 ) - g_date->DayInYear())) {
221  SimpleEvent( g_date->Date() + 1, oms_row_two, false );
222  break;
223  }
224  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 7 ),
225  oms_water_one, false );
226  break;
227 
228  case oms_water_one:
229  if ( m_ev->m_lock || m_farm->DoIt( 30 )) {
230  if (!m_farm->Water( m_field, 0.0,
231  g_date->DayInYear( 15, 7 ) - g_date->DayInYear())) {
232  SimpleEvent( g_date->Date() + 1, oms_water_one, false );
233  break;
234  }
235  }
236  {
237  d1 = g_date->OldDays() + g_date->DayInYear( 16, 7 );
238  if ( g_date->Date() + 7 > d1 ) {
239  d1 = g_date->Date() + 7;
240  }
241  SimpleEvent( d1, oms_water_two, false );
242  }
243  break;
244 
245  case oms_water_two:
246  if (!m_farm->Water( m_field, 0.0,
247  g_date->DayInYear( 30, 7 ) - g_date->DayInYear())) {
248  SimpleEvent( g_date->Date() + 1, oms_water_two, false );
249  break;
250  }
251  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 9 ),
252  oms_harvest, false );
253  break;
254 
255  case oms_harvest:
256  if (!m_farm->Harvest( m_field, 0.0,
257  m_field->GetMDates(1,0) - g_date->DayInYear())) {
258  SimpleEvent( g_date->Date() + 1, oms_harvest, false );
259  break;
260  }
261  {
262  d1 = g_date->OldDays() + m_field->GetMDates(0,1);
263  if ( g_date->Date() > d1 ) {
264  d1 = g_date->Date();
265  }
266  SimpleEvent( d1, oms_stubble, false );
267  }
268  break;
269 
270  case oms_stubble:
271  if ( m_ev->m_lock || m_farm->DoIt( 25 )) {
272  if (!m_farm->StubbleHarrowing( m_field, 0.0,
273  m_field->GetMDates(1,1) -
274  g_date->DayInYear())) {
275  SimpleEvent( g_date->Date() + 1, oms_stubble, false );
276  break;
277  }
278  }
279  d1=g_date->DayInYear();
280  done = true;
281  break;
282 
283  default:
284  g_msg->Warn( WARN_BUG, "OMaizeSilage::Do(): "
285  "Unknown event type! ", "" );
286  exit( 1 );
287  }
288 
289  return done;
290 }

References Farm::DoIt(), Farm::FA_Manure(), Farm::FA_NPK(), 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_next_tov, FarmEvent::m_startday, FarmEvent::m_todo, OMAIZESILAGE_SOW_DATE, oms_fa_manure_b, oms_fa_npk, oms_fa_slurry_one, oms_fa_slurry_two, oms_harvest, oms_row_one, oms_row_two, oms_spring_harrow, oms_spring_plough, oms_spring_sow, oms_start, oms_stubble, oms_water_one, oms_water_two, Farm::RowCultivation(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringSow(), Farm::StubbleHarrowing(), and Farm::Water().


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
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
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
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
oms_spring_sow
Definition: OMaizeSilage.h:40
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
oms_row_two
Definition: OMaizeSilage.h:44
oms_water_one
Definition: OMaizeSilage.h:45
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
oms_spring_plough
Definition: OMaizeSilage.h:38
oms_harvest
Definition: OMaizeSilage.h:47
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
oms_spring_harrow
Definition: OMaizeSilage.h:39
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
oms_row_one
Definition: OMaizeSilage.h:42
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
Crop::m_field
LE * m_field
Definition: farm.h:538
oms_fa_npk
Definition: OMaizeSilage.h:41
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
Farm::RowCultivation
virtual bool RowCultivation(LE *a_field, double a_user, int a_days)
Carry out a harrowing between crop rows on a_field.
Definition: farmfuncs.cpp:1510
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
OMAIZESILAGE_SOW_DATE
#define OMAIZESILAGE_SOW_DATE
Definition: OMaizeSilage.h:32
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
oms_water_two
Definition: OMaizeSilage.h:46
oms_fa_manure_b
Definition: OMaizeSilage.h:36
oms_stubble
Definition: OMaizeSilage.h:48
oms_fa_slurry_two
Definition: OMaizeSilage.h:43
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539
oms_start
Definition: OMaizeSilage.h:35
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
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
oms_fa_slurry_one
Definition: OMaizeSilage.h:37