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

#include <OCarrots.h>

Public Member Functions

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

Constructor & Destructor Documentation

◆ OCarrots()

OCarrots::OCarrots ( )
inline

Definition at line 56 of file OCarrots.h.

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

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

Definition at line 32 of file OCarrots.cpp.

33 {
34  m_farm = a_farm;
35  m_field = a_field;
36  m_ev = a_ev;
37 
38  bool done = false;
39 
40  switch ( m_ev->m_todo ) {
41  case oca_start:
42  {
43  OCA_WATER_DATE = 0;
44  // Set up the date management stuff
45  m_last_date=g_date->DayInYear(30,11);
46  // Start and stop dates for all events after harvest
47  m_field->SetMDates(0,0,g_date->DayInYear(30,11));
48  // Determined by harvest date - used to see if at all possible
49  m_field->SetMDates(1,0,g_date->DayInYear(30,11));
50  // Check the next crop for early start, unless it is a spring crop
51  // in which case we ASSUME that no checking is necessary!!!!
52  // So DO NOT implement a crop that runs over the year boundary
53  if (m_ev->m_startday>g_date->DayInYear(1,7))
54  {
55  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
56  {
57  g_msg->Warn( WARN_BUG, "OCarrots::Do(): "
58  "Harvest too late for the next crop to start!!!", "" );
59  exit( 1 );
60  }
61  // Not possible to fix any late finishing problems, harvest too late
62  }
63 
64  int d1;
65 
66  int today=g_date->Date();
67  d1 = g_date->OldDays() + m_first_date;
68  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
69  if (today > d1)
70  {
71  // Yes too late - should not happen - raise an error
72  g_msg->Warn( WARN_BUG, "OCarrots::Do(): "
73  "Crop start attempt after last possible start date", "" );
74  exit( 1 );
75  }
76  // Reinit d1 to first possible starting date.
77  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
78  if ( g_date->Date() > d1 ) {
79  d1 = g_date->Date();
80  }
81  // OK, let's go.
82  if ( m_farm->IsStockFarmer()) {
83  SimpleEvent( d1+14, oca_fa_slurry, false );
84  } else {
85  SimpleEvent( d1, oca_fp_slurry, false );
86  }
87  break;
88  }
89  case oca_fa_slurry:
90  if ( m_ev->m_lock || m_farm->DoIt( 50 )) {
91  if (!m_farm->FA_Slurry( m_field, 0.0,
92  g_date->DayInYear( 30, 3 ) -
93  g_date->DayInYear())) {
94  SimpleEvent( g_date->Date() + 1, oca_fa_slurry, true );
95  break;
96  }
97  }
98  {
99  int d1 = g_date->OldDays() + g_date->DayInYear( 20, 3 );
100  if ( g_date->Date() > d1 ) {
101  d1 = g_date->Date();
102  }
103  SimpleEvent( d1, oca_spring_plough, false );
104  }
105  break;
106 
107  case oca_fp_slurry:
108  if ( m_ev->m_lock || m_farm->DoIt( 50 )) {
109  if (!m_farm->FP_Slurry( m_field, 0.0,
110  g_date->DayInYear( 30, 3 ) -
111  g_date->DayInYear())) {
112  SimpleEvent( g_date->Date() + 1, oca_fp_slurry, true );
113  break;
114  }
115  }
116  {
117  int d1 = g_date->OldDays() + g_date->DayInYear( 20, 3 );
118  if ( g_date->Date() > d1 ) {
119  d1 = g_date->Date();
120  }
121  SimpleEvent( d1, oca_spring_plough, false );
122  }
123  break;
124 
125  case oca_spring_plough:
126  if (!m_farm->SpringPlough( m_field, 0.0,
127  g_date->DayInYear( 10, 4 ) -
128  g_date->DayInYear())) {
129  SimpleEvent( g_date->Date() + 1, oca_spring_plough, false );
130  break;
131  }
132  {
133  int d1 = g_date->OldDays() + g_date->DayInYear( 1, 4 );
134  if ( g_date->Date() > d1 ) {
135  d1 = g_date->Date();
136  }
137  SimpleEvent( d1, oca_spring_harrow_one, false );
138  }
139  break;
140 
142  if (!m_farm->SpringHarrow( m_field, 0.0,
143  g_date->DayInYear( 15, 4 ) -
144  g_date->DayInYear())) {
145  SimpleEvent( g_date->Date() + 1, oca_spring_harrow_one, false );
146  break;
147  }
148  {
149  int d1 = g_date->OldDays() + g_date->DayInYear( 20, 4 );
150  if ( g_date->Date() + 14 > d1 ) {
151  d1 = g_date->Date() + 14;
152  }
153  SimpleEvent( d1, oca_spring_harrow_two, false );
154  }
155  break;
156 
158  if (!m_farm->SpringHarrow( m_field, 0.0,
159  g_date->DayInYear( 15, 5 ) -
160  g_date->DayInYear())) {
161  SimpleEvent( g_date->Date() + 1, oca_spring_harrow_two, false );
162  break;
163  }
164  {
165  int d1 = g_date->OldDays() + g_date->DayInYear( 25, 4 );
166  if ( g_date->Date() > d1 ) {
167  d1 = g_date->Date();
168  }
169  SimpleEvent( d1, oca_spring_sow, false );
170  }
171  break;
172 
173  case oca_spring_sow:
174  if (!m_farm->SpringSow( m_field, 0.0,
175  g_date->DayInYear( 25, 5 ) -
176  g_date->DayInYear())) {
177  SimpleEvent( g_date->Date() + 1, oca_spring_sow, false );
178  break;
179  }
180  {
181  int d1 = g_date->OldDays() + g_date->DayInYear( 3, 5 );
182  if ( g_date->Date() + 7 > d1 ) {
183  d1 = g_date->Date() + 7;
184  }
185  SimpleEvent( d1, oca_rowcul_one, false );
186  }
187  break;
188 
189  case oca_rowcul_one:
190  if (!m_farm->RowCultivation( m_field, 0.0,
191  g_date->DayInYear( 3, 6 ) -
192  g_date->DayInYear())) {
193  SimpleEvent( g_date->Date() + 1, oca_rowcul_one, false );
194  break;
195  }
196  {
197  int d1 = g_date->OldDays() + g_date->DayInYear( 14, 5 );
198  if ( g_date->Date() + 10 > d1 ) {
199  d1 = g_date->Date() + 10;
200  }
201  SimpleEvent( d1, oca_rowcul_two, false );
202  }
203  break;
204 
205  case oca_rowcul_two:
206  if (!m_farm->RowCultivation( m_field, 0.0,
207  g_date->DayInYear( 14, 6 ) -
208  g_date->DayInYear())) {
209  SimpleEvent( g_date->Date() + 1, oca_rowcul_two, false );
210  break;
211  }
212  {
213  int d1 = g_date->OldDays() + g_date->DayInYear( 25, 5 );
214  if ( g_date->Date() + 10 > d1 ) {
215  d1 = g_date->Date() + 10;
216  }
217  SimpleEvent( d1, oca_rowcul_three, false );
218  }
219  break;
220 
221  case oca_rowcul_three:
222  if (!m_farm->RowCultivation( m_field, 0.0,
223  g_date->DayInYear( 25, 6 ) -
224  g_date->DayInYear())) {
225  SimpleEvent( g_date->Date() + 1, oca_rowcul_three, false );
226  break;
227  }
228  {
229  int d1 = g_date->OldDays() + g_date->DayInYear( 8, 6 );
230  if ( g_date->Date() + 10 > d1 ) {
231  d1 = g_date->Date() + 10;
232  }
233  SimpleEvent( d1, oca_rowcul_four, false );
234  }
235  {
236  int d1 = g_date->OldDays() + g_date->DayInYear( 1, 7 );
237  if ( g_date->Date() + 3 > d1 ) {
238  d1 = g_date->Date() + 3;
239  }
240  SimpleEvent( d1, oca_water_one, false );
241  }
242  break;
243 
244  case oca_rowcul_four:
245  if ( OCA_WATER_DATE &&
246  OCA_WATER_DATE >= g_date->Date() - 1 ) {
247  SimpleEvent( g_date->Date() + 1, oca_rowcul_four, false );
248  break;
249  }
250  if (!m_farm->RowCultivation( m_field, 0.0,
251  g_date->DayInYear( 10, 7 ) -
252  g_date->DayInYear())) {
253  SimpleEvent( g_date->Date() + 1, oca_rowcul_four, false );
254  break;
255  }
256  break;
257 
258  case oca_water_one:
259  if ( m_ev->m_lock || m_farm->DoIt( 90 )) {
260  if (!m_farm->Water( m_field, 0.0,
261  g_date->DayInYear( 20, 7 ) -
262  g_date->DayInYear())) {
263  SimpleEvent( g_date->Date() + 1, oca_water_one, true );
264  break;
265  }
266  OCA_WATER_DATE = g_date->Date();
267  }
268  {
269  int d1 = g_date->OldDays() + g_date->DayInYear( 21, 7 );
270  if ( g_date->Date() + 7 > d1 ) {
271  d1 = g_date->Date() + 7;
272  }
273  SimpleEvent( d1, oca_water_two, false );
274  }
275  break;
276 
277  case oca_water_two:
278  if (!m_farm->Water( m_field, 0.0,
279  g_date->DayInYear( 10, 8 ) -
280  g_date->DayInYear())) {
281  SimpleEvent( g_date->Date() + 1, oca_water_two, true );
282  break;
283  }
284  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 11, 8 ),
285  oca_water_three, false );
286  break;
287 
288  case oca_water_three:
289  if ( m_ev->m_lock || m_farm->DoIt( 90 )) {
290  if (!m_farm->Water( m_field, 0.0,
291  g_date->DayInYear( 5, 9 ) -
292  g_date->DayInYear())) {
293  SimpleEvent( g_date->Date() + 1, oca_water_three, true );
294  break;
295  }
296  }
297  {
298  int d1 = g_date->OldDays() + g_date->DayInYear( 1, 9 );
299  if ( g_date->Date() + 7 > d1 ) {
300  d1 = g_date->Date() + 7;
301  }
302  SimpleEvent( d1, oca_harvest, false );
303  }
304  break;
305 
306  case oca_harvest:
307  if (!m_farm->Harvest( m_field, 0.0,
308  g_date->DayInYear( 30, 11 ) - g_date->DayInYear())) {
309  SimpleEvent( g_date->Date() + 1, oca_harvest, false );
310  break;
311  }
312  done = true;
313  break;
314 
315  default:
316  g_msg->Warn( WARN_BUG, "OCarrots::Do(): "
317  "Unknown event type! ", "" );
318  exit( 1 );
319  }
320 
321  return done;
322 }

References Farm::DoIt(), Farm::FA_Slurry(), Farm::FP_Slurry(), Farm::Harvest(), 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, oca_fa_slurry, oca_fp_slurry, oca_harvest, oca_rowcul_four, oca_rowcul_one, oca_rowcul_three, oca_rowcul_two, oca_spring_harrow_one, oca_spring_harrow_two, oca_spring_plough, oca_spring_sow, oca_start, OCA_WATER_DATE, oca_water_one, oca_water_three, oca_water_two, Farm::RowCultivation(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringSow(), 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
oca_spring_harrow_two
Definition: OCarrots.h:40
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::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
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
oca_harvest
Definition: OCarrots.h:49
oca_rowcul_two
Definition: OCarrots.h:43
OCA_WATER_DATE
#define OCA_WATER_DATE
Definition: OCarrots.h:32
oca_rowcul_three
Definition: OCarrots.h:44
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
oca_spring_sow
Definition: OCarrots.h:41
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
oca_rowcul_four
Definition: OCarrots.h:45
oca_spring_plough
Definition: OCarrots.h:38
oca_water_three
Definition: OCarrots.h:48
oca_water_two
Definition: OCarrots.h:47
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
Crop::m_field
LE * m_field
Definition: farm.h:538
oca_water_one
Definition: OCarrots.h:46
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
oca_fp_slurry
Definition: OCarrots.h:37
oca_rowcul_one
Definition: OCarrots.h:42
Farm::FP_Slurry
virtual bool FP_Slurry(LE *a_field, double a_user, int a_days)
Apply slurry to a_field owned by an arable farmer.
Definition: farmfuncs.cpp:701
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
oca_fa_slurry
Definition: OCarrots.h:36
oca_spring_harrow_one
Definition: OCarrots.h:39
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
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539
oca_start
Definition: OCarrots.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