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

#include <OTriticale.h>

Public Member Functions

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

Constructor & Destructor Documentation

◆ OTriticale()

OTriticale::OTriticale ( )
inline

Definition at line 62 of file OTriticale.h.

63  {
64  m_first_date=g_date->DayInYear(5,10);
65  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

Definition at line 38 of file OTriticale.cpp.

39 {
40  m_farm = a_farm;
41  m_field = a_field;
42  m_ev = a_ev;
43  int d1=0;
44  int noDates=2;
45  bool done = false;
46 
47  switch ( m_ev->m_todo )
48  {
49  case otri_start:
50  // Set up the date management stuff
51  m_last_date=g_date->DayInYear(15,9);
52  // Start and stop dates for all events after harvest
53  m_field->SetMDates(0,0,g_date->DayInYear(5,8));
54  // Determined by harvest date - used to see if at all possible
55  m_field->SetMDates(1,0,g_date->DayInYear(20,8));
56  m_field->SetMDates(0,1,g_date->DayInYear(20,8));
57  m_field->SetMDates(1,1,g_date->DayInYear(15,9));
58  // Check the next crop for early start, unless it is a spring crop
59  // in which case we ASSUME that no checking is necessary!!!!
60  // So DO NOT implement a crop that runs over the year boundary
61 
62  //new if: do the check only for non-optimising farms and if year>0. (030713 - m_rotation used only in the hidden year, so I modified the condition from >7 to >0)
63  if(!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber()>0)){
64  if (m_ev->m_startday>g_date->DayInYear(1,7))
65  {
66  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
67  {
68  g_msg->Warn( WARN_BUG, "OTriticale::Do(): " "Harvest too late for the next crop to start!!!", "" );
69  exit( 1 );
70  }
71  // Now fix any late finishing problems
72  for (int i=0; i<noDates; i++) {
73  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
74  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
75  }
76  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
77  m_field->SetMConstants(i,0);
78  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
79  }
80  }
81  }
82  // Now no operations can be timed after the start of the next crop.
83  // Start single block date checking code to be cut-'n-pasted...
84  if ( ! m_ev->m_first_year )
85  {
86  // Are we before July 1st?
87  d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
88  if (g_date->Date() < d1)
89  {
90  // Yes, too early. We assumme this is because the last crop was late
91  g_msg->Warn( WARN_BUG, "OTriticale::Do(): " "Crop start attempt between 1st Jan & 1st July", "" );
92  exit( 1 );
93  }
94  else
95  {
96  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
97  if (g_date->Date() > d1)
98  {
99  // Yes too late - should not happen - raise an error
100  g_msg->Warn( WARN_BUG, "OTriticale::Do(): " "Crop start attempt after last possible start date", "" );
101  exit( 1 );
102  }
103  }
104  }
105  else
106  {
107  // Is the first year so must start in spring like nothing was unusual
108  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5,8 )
109  ,otri_harvest, false );
110  break;
111  }
112  }//if
113 
114  // End single block date checking code. Please see next line
115  // comment as well.
116  // Reinit d1 to first possible starting date.
117  d1 = g_date->OldDays() + g_date->DayInYear( 20,8 );
118  if ( g_date->Date() > d1 ) {
119  d1 = g_date->Date();
120  }
121 
122  // OK, let's go.
123  OTRI_WATER_DATE = 0;
124 
125  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,8 ),
126  otri_fa_manure, false );
127  break;
128 
129  case otri_fa_manure:
130  if ( m_ev->m_lock || m_farm->DoIt( 40 )) {
131  if (!m_farm->FA_Manure( m_field, 0.0,
132  g_date->DayInYear( 5,10 ) -
133  g_date->DayInYear())) {
134  SimpleEvent( g_date->Date() + 1, otri_fa_manure, true );
135  break;
136  }
137  }
138  {
139  d1 = g_date->Date();
140  if ( d1 < g_date->OldDays() + g_date->DayInYear( 1,9 ))
141  d1 = g_date->OldDays() + g_date->DayInYear( 1,9 );
142  SimpleEvent( d1, otri_autumn_plough, false );
143  }
144  break;
145 
146  case otri_autumn_plough:
147  if (!m_farm->AutumnPlough( m_field, 0.0,
148  g_date->DayInYear( 15,10 ) -
149  g_date->DayInYear())) {
150  SimpleEvent( g_date->Date() + 1, otri_autumn_plough, true );
151  break;
152  }
153  SimpleEvent( g_date->Date() + 1, otri_autumn_harrow, false );
154  break;
155 
156  case otri_autumn_harrow:
157  if (!m_farm->AutumnHarrow( m_field, 0.0,
158  g_date->DayInYear( 15,10 ) -
159  g_date->DayInYear())) {
160  SimpleEvent( g_date->Date() + 1, otri_autumn_harrow, true );
161  break;
162  }
163  SimpleEvent( g_date->Date(), otri_autumn_sow, false );
164  break;
165 
166  case otri_autumn_sow:
167  if (!m_farm->AutumnSow( m_field, 0.0,
168  g_date->DayInYear( 15,10 ) -
169  g_date->DayInYear())) {
170  SimpleEvent( g_date->Date() + 1, otri_autumn_sow, true );
171  break;
172  }
173  SimpleEvent( g_date->Date(), otri_autumn_roll, false );
174  break;
175 
176  case otri_autumn_roll:
177  if ( m_ev->m_lock || m_farm->DoIt( 5 ))
178  {
179  if (!m_farm->AutumnRoll( m_field, 0.0, g_date->DayInYear( 10,10 ) - g_date->DayInYear()))
180  {
181  SimpleEvent( g_date->Date() + 1, otri_autumn_roll, true );
182  break;
183  }
184  }
185  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,3) + 365, otri_spring_roll, false );
186  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ) + 365, otri_fa_npk, false );
187  if (m_farm->IsStockFarmer()) SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5,4 ) + 365, otri_fa_slurry, false ); // StockFarmer
188  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ) + 365, otri_strigling, false );
189  break;
190 
191  case otri_spring_roll:
192  if ( m_ev->m_lock || m_farm->DoIt( 15 ))
193  {
194  if (!m_farm->SpringRoll( m_field, 0.0,
195  g_date->DayInYear( 10,4 ) -
196  g_date->DayInYear())) {
197  SimpleEvent( g_date->Date() + 1, otri_spring_roll, true );
198  break;
199  }
200  }
201  break;
202 
203  case otri_fa_npk:
204  if (!m_farm->FA_NPK( m_field, 0.0, g_date->DayInYear( 30, 4 ) - g_date->DayInYear()))
205  {
206  SimpleEvent( g_date->Date() + 1, otri_fa_npk, true );
207  break;
208  }
209  break;
210 
211  case otri_fa_slurry:
212  if (!m_farm->FA_Slurry( m_field, 0.0, g_date->DayInYear( 250,4 ) - g_date->DayInYear()))
213  {
214  SimpleEvent( g_date->Date() + 1, otri_fa_slurry, true );
215  break;
216  }
217  break;
218 
219  case otri_strigling:
220  if (!m_farm->Strigling( m_field, 0.0, g_date->DayInYear( 30,4 ) - g_date->DayInYear()))
221  {
222  SimpleEvent( g_date->Date() + 1, otri_strigling, true );
223  break;
224  }
225  ChooseNextCrop (2);
226  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5,8 ), otri_harvest, false );
227  break;
228 
229  case otri_water:
230 
231  if ( m_ev->m_lock || m_farm->DoIt( 15 ))
232  {
233  if (!m_farm->Water( m_field, 0.0,
234  g_date->DayInYear( 30,6 ) -
235  g_date->DayInYear())) {
236  SimpleEvent( g_date->Date() + 1, otri_water, true );
237  break;
238  }
239  OTRI_WATER_DATE = g_date->Date();
240  }
241  break;
242 
243  case otri_harvest:
244  if (m_field->GetMConstants(0)==0) {
245  if (!m_farm->Harvest( m_field, 0.0, -1)) { //raise an error
246  g_msg->Warn( WARN_BUG, "OTriticale::Do(): failure in 'Harvest' execution", "" );
247  exit( 1 );
248  }
249  }
250  else {
251  if (!m_farm->Harvest( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
252  SimpleEvent( g_date->Date() + 1, otri_harvest, true );
253  break;
254  }
255  }
256  if ( m_farm->DoIt( 75 ))
257  SimpleEvent( g_date->Date(), otri_chopping, true );
258  else
259  SimpleEvent( g_date->Date(), otri_hay_turning, true );
260  break;
261 
262  case otri_chopping:
263  if (m_field->GetMConstants(0)==0) {
264  if (!m_farm->StrawChopping( m_field, 0.0, -1)) { //raise an error
265  g_msg->Warn( WARN_BUG, "OTriticale::Do(): failure in 'StrawChopping' execution", "" );
266  exit( 1 );
267  }
268  }
269  else {
270  if (!m_farm->StrawChopping( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
271  SimpleEvent( g_date->Date() + 1, otri_chopping, true );
272  break;
273  }
274  }
275  SimpleEvent( g_date->Date(), otri_stubble_harrow, false );
276  break;
277 
278  case otri_hay_turning:
279  if ( m_ev->m_lock || m_farm->DoIt( 20 )) {
280  if (m_field->GetMConstants(0)==0) {
281  if (!m_farm->HayTurning( m_field, 0.0, -1)) { //raise an error
282  g_msg->Warn( WARN_BUG, "OTriticale::Do(): failure in 'HayTurning' execution", "" );
283  exit( 1 );
284  }
285  }
286  else {
287  if (!m_farm->HayTurning( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
288  SimpleEvent( g_date->Date() + 1, otri_hay_turning, true );
289  break;
290  }
291  }
292  }
293  SimpleEvent( g_date->Date(), otri_hay_bailing, false );
294  break;
295 
296  case otri_hay_bailing:
297  if (m_field->GetMConstants(0)==0) {
298  if (!m_farm->HayBailing( m_field, 0.0, -1)) { //raise an error
299  g_msg->Warn( WARN_BUG, "OTriticale::Do(): failure in 'HayBailing' execution", "" );
300  exit( 1 );
301  }
302  }
303  else {
304  if (!m_farm->HayBailing( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
305  SimpleEvent( g_date->Date() + 1, otri_hay_bailing, true );
306  break;
307  }
308  }
309  SimpleEvent( g_date->Date(), otri_stubble_harrow, false );
310  break;
311 
312  case otri_stubble_harrow:
313  if (m_field->GetMConstants(1)==0) {
314  if (!m_farm->StubbleHarrowing( m_field, 0.0, -1)) { //raise an error
315  g_msg->Warn( WARN_BUG, "OTriticale::Do(): failure in 'StubbleHarrowing' execution", "" );
316  exit( 1 );
317  }
318  }
319  else {
320  if (!m_farm->StubbleHarrowing( m_field, 0.0, m_field->GetMDates(1,1) - g_date->DayInYear())) {
321  SimpleEvent( g_date->Date() + 1, otri_stubble_harrow, true );
322  break;
323  }
324  }
325  done = true;
326  break;
327 
328  default:
329  g_msg->Warn( WARN_BUG, "OTriticale::Do(): " "Unknown event type! ", "" );
330  exit( 1 );
331  }
332  return done;
333 }

References Farm::AutumnHarrow(), Farm::AutumnPlough(), Farm::AutumnRoll(), Farm::AutumnSow(), Crop::ChooseNextCrop(), Farm::DoIt(), Farm::FA_Manure(), Farm::FA_NPK(), Farm::FA_Slurry(), Farm::GetType(), Farm::Harvest(), 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, otri_autumn_harrow, otri_autumn_plough, otri_autumn_roll, otri_autumn_sow, otri_chopping, otri_fa_manure, otri_fa_npk, otri_fa_slurry, otri_harvest, otri_hay_bailing, otri_hay_turning, otri_spring_roll, otri_start, otri_strigling, otri_stubble_harrow, otri_water, OTRI_WATER_DATE, Crop::SimpleEvent(), Farm::SpringRoll(), Farm::StrawChopping(), Farm::Strigling(), Farm::StubbleHarrowing(), tof_OptimisingFarm, and Farm::Water().


The documentation for this class was generated from the following files:
otri_hay_bailing
Definition: OTriticale.h:52
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
otri_harvest
Definition: OTriticale.h:49
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
otri_fa_slurry
Definition: OTriticale.h:46
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
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
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
otri_stubble_harrow
Definition: OTriticale.h:53
tof_OptimisingFarm
Definition: farm.h:273
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
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
otri_spring_roll
Definition: OTriticale.h:44
OTRI_WATER_DATE
#define OTRI_WATER_DATE
Definition: OTriticale.h:34
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
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
otri_fa_manure
Definition: OTriticale.h:39
otri_chopping
Definition: OTriticale.h:50
otri_autumn_sow
Definition: OTriticale.h:42
otri_hay_turning
Definition: OTriticale.h:51
Farm::AutumnSow
virtual bool AutumnSow(LE *a_field, double a_user, int a_days)
Carry out a sowing event in the autumn on a_field.
Definition: farmfuncs.cpp:364
otri_fa_npk
Definition: OTriticale.h:45
otri_autumn_roll
Definition: OTriticale.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
otri_water
Definition: OTriticale.h:48
Farm::StrawChopping
virtual bool StrawChopping(LE *a_field, double a_user, int a_days)
Carry out straw chopping on a_field.
Definition: farmfuncs.cpp:2132
otri_autumn_harrow
Definition: OTriticale.h:41
otri_strigling
Definition: OTriticale.h:47
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::AutumnRoll
virtual bool AutumnRoll(LE *a_field, double a_user, int a_days)
Carry out a roll event in the autumn on a_field.
Definition: farmfuncs.cpp:288
otri_start
Definition: OTriticale.h:38
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::AutumnHarrow
virtual bool AutumnHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the autumn on a_field.
Definition: farmfuncs.cpp:261
otri_autumn_plough
Definition: OTriticale.h:40
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: farm.cpp:318
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::StubbleHarrowing
virtual bool StubbleHarrowing(LE *a_field, double a_user, int a_days)
Carry out stubble harrowing on a_field.
Definition: farmfuncs.cpp:2209