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

#include <OPotatoes.h>

Public Member Functions

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

◆ OPotatoes()

OPotatoes::OPotatoes ( )
inline
66  {
67  m_first_date=g_date->DayInYear(1,3);
68  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

bool OPotatoes::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  int d1;
39 
40  bool done = false;
41 
42  switch ( m_ev->m_todo ) {
43  case ope_start:
44  {
45  OPOT_SLURRY_DATE = 0;
46  OPOT_SOW_DATE = 0;
48  m_field->SetVegPatchy(true); // Root crop so open until tall
49 
50  // Set up the date management stuff
51  m_last_date=g_date->DayInYear(1,11);
52  // Start and stop dates for all events after harvest
53  m_field->SetMDates(0,0,g_date->DayInYear(1,11));
54  // Determined by harvest date - used to see if at all possible
55  m_field->SetMDates(1,0,g_date->DayInYear(1,11));
56  // Check the next crop for early start, unless it is a spring crop
57  // in which case we ASSUME that no checking is necessary!!!!
58  // So DO NOT implement a crop that runs over the year boundary
59  if (m_ev->m_startday>g_date->DayInYear(1,7))
60  {
61  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
62  {
63  g_msg->Warn( WARN_BUG, "OPotatoes::Do(): "
64  "Harvest too late for the next crop to start!!!", "" );
65  exit( 1 );
66  }
67  // No late finishing problems fix possible
68  }
69 
70  int today=g_date->Date();
71  d1 = g_date->OldDays() + m_first_date;
72  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
73  if (today > d1)
74  {
75  // Yes too late - should not happen - raise an error
76  g_msg->Warn( WARN_BUG, "OPotatoes::Do(): "
77  "Crop start attempt after last possible start date", "" );
78  exit( 1 );
79  }
80  // Reinit d1 to first possible starting date.
81  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
82  if ( g_date->Date() > d1 ) {
83  d1 = g_date->Date();
84  }
85  // OK, let's go.
86  if ( m_farm->IsStockFarmer()) {
87  SimpleEvent( d1, ope_fa_slurry, false );
88  } else {
89  SimpleEvent( d1, ope_fp_slurry, false );
90  }
91  break;
92  }
93 
94  case ope_fa_slurry:
95  d1 = g_date->DayInYear();
96  if (!m_farm->FA_Slurry( m_field, 0.0,
97  g_date->DayInYear( 30, 3 ) - g_date->DayInYear())) {
98  SimpleEvent( g_date->Date() + 1, ope_fa_slurry, false );
99  break;
100  }
101  OPOT_SLURRY_DATE = g_date->DayInYear();
102  SimpleEvent( g_date->Date() + 1, ope_fa_manure, false );
103  break;
104 
105  case ope_fa_manure:
106  if ( m_ev->m_lock || m_farm->DoIt( 40 )) {
108  g_date->DayInYear())) {
109  SimpleEvent( g_date->Date() + 1, ope_fa_manure, true );
110  break;
111  }
112  }
113  SimpleEvent( g_date->Date(), ope_spring_plough, false );
114  break;
115 
116  case ope_fp_slurry:
117  d1 = g_date->DayInYear();
118  if (!m_farm->FP_Slurry( m_field, 0.0,
119  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
120  SimpleEvent( g_date->Date() + 1, ope_fp_slurry, false );
121  break;
122  }
123  OPOT_SLURRY_DATE = g_date->DayInYear();
124  SimpleEvent( g_date->Date() + 1, ope_fp_manure, false );
125  break;
126 
127  case ope_fp_manure:
128  if ( m_ev->m_lock || m_farm->DoIt( 15 )) {
130  g_date->DayInYear())) {
131  SimpleEvent( g_date->Date() + 1, ope_fp_manure, true );
132  break;
133  }
134  }
135  SimpleEvent( g_date->Date(), ope_spring_plough, false );
136  break;
137 
138  case ope_spring_plough:
139  d1 = g_date->DayInYear();
140  if (!m_farm->SpringPlough( m_field, 0.0,
142  g_date->DayInYear())) {
143  SimpleEvent( g_date->Date() + 1, ope_spring_plough, false );
144  break;
145  }
146  {
147  d1 = g_date->OldDays() + g_date->DayInYear( 10, 3 );
148  if ( g_date->Date() > d1 ) {
149  d1 = g_date->Date();
150  }
151  SimpleEvent( d1, ope_spring_harrow, false );
152  }
153  break;
154 
155  case ope_spring_harrow:
156  if (!m_farm->SpringHarrow( m_field, 0.0,
157  g_date->DayInYear( 15, 4 ) - g_date->DayInYear())) {
158  SimpleEvent( g_date->Date() + 1, ope_spring_harrow, false );
159  break;
160  }
161  {
162  d1 = g_date->OldDays() + g_date->DayInYear( 1, 4 );
163  if ( g_date->Date() + 1> d1 ) {
164  d1 = g_date->Date() + 1;
165  }
166  SimpleEvent( d1, ope_spring_sow, false );
167  }
168  break;
169 
170  case ope_spring_sow:
171  if (!m_farm->SpringSow( m_field, 0.0,
172  g_date->DayInYear( 1, 5 ) - g_date->DayInYear())) {
173  SimpleEvent( g_date->Date() + 1, ope_spring_sow, false );
174  break;
175  }
176  // Start hilling up sub thread.
177  {
178  d1 = g_date->OldDays() + g_date->DayInYear( 18, 4 );
179  if ( g_date->Date() + 18 > d1 ) {
180  d1 = g_date->Date() + 18;
181  }
182  SimpleEvent( d1, ope_hilling_one, false );
183  }
184  if ( m_farm->DoIt( 10 )) {
185  // Flaming
186  d1 = g_date->OldDays() + g_date->DayInYear( 7, 4 );
187  if ( g_date->Date() + 8 > d1 ) {
188  d1 = g_date->Date() + 8;
189  }
190  SimpleEvent( d1, ope_flaming_one, false );
191  } else {
192  // Strigling
193  d1 = g_date->OldDays() + g_date->DayInYear( 12, 4 );
194  if ( g_date->Date() + 12 > d1 ) {
195  d1 = g_date->Date() + 12;
196  }
197  SimpleEvent( d1, ope_strigling_one, false );
198  }
199  break;
200 
201  case ope_flaming_one:
202  if ( m_ev->m_lock || m_farm->DoIt( 10 )) {
203  if (!m_farm->Swathing( m_field, 0.0,
204  g_date->DayInYear( 10, 5 ) -
205  g_date->DayInYear())) {
206  SimpleEvent( g_date->Date() + 1, ope_flaming_one, true );
207  break;
208  }
209  }
210  {
211  d1 = g_date->OldDays() + g_date->DayInYear( 19, 4 );
212  if ( g_date->Date() + 7 > d1 ) {
213  d1 = g_date->Date() + 7;
214  }
215  SimpleEvent( d1, ope_strigling_two, false );
216  }
217  break;
218 
219  case ope_strigling_one:
220  if (!m_farm->Strigling( m_field, 0.0,
221  g_date->DayInYear( 20, 5 ) - g_date->DayInYear())) {
222  SimpleEvent( g_date->Date() + 1, ope_strigling_one, false );
223  break;
224  }
225  {
226  d1 = g_date->OldDays() + g_date->DayInYear( 19, 4 );
227  if ( g_date->Date() + 7 > d1 ) {
228  d1 = g_date->Date() + 7;
229  }
230  SimpleEvent( d1, ope_strigling_two, false );
231  }
232  break;
233 
234  case ope_strigling_two:
235  if (!m_farm->Strigling( m_field, 0.0,
236  g_date->DayInYear( 27, 5 ) - g_date->DayInYear())) {
237  SimpleEvent( g_date->Date() + 1, ope_strigling_two, false );
238  break;
239  }
240  {
241  d1 = g_date->OldDays() + g_date->DayInYear( 28, 4 );
242  if ( g_date->Date() + 7 > d1 ) {
243  d1 = g_date->Date() + 7;
244  }
245  SimpleEvent( d1, ope_strigling_three, false );
246  }
247  break;
248 
249  case ope_strigling_three:
250  if ( !OPOT_HILLING_THREE &&
251  g_date->Date() >= OPOT_HILLING_THREE + 7 ) {
252  SimpleEvent( g_date->Date() + 1, ope_strigling_three, true );
253  break;
254  }
255  if ( m_ev->m_lock || (cfg_strigling_prop.value() * m_farm->DoIt( 75 ))) {
256  if (!m_farm->Strigling( m_field, 0.0,
257  g_date->DayInYear( 12, 6 ) -
258  g_date->DayInYear())) {
259  SimpleEvent( g_date->Date() + 1, ope_strigling_three, true );
260  break;
261  }
262  }
263  {
264  d1 = g_date->OldDays() + g_date->DayInYear( 15, 6 );
265  if ( g_date->Date() + 3 > d1 ) {
266  d1 = g_date->Date() + 3;
267  }
268  SimpleEvent( d1, ope_water_one, false );
269  }
270  break;
271 
272  case ope_hilling_one:
273  if (!m_farm->HillingUp( m_field, 0.0,
274  g_date->DayInYear( 22, 5 ) - g_date->DayInYear())) {
275  SimpleEvent( g_date->Date() + 1, ope_hilling_one, false );
276  break;
277  }
278  {
279  d1 = g_date->OldDays() + g_date->DayInYear( 5, 5 );
280  if ( g_date->Date() + 14 > d1 ) {
281  d1 = g_date->Date() + 14;
282  }
283  SimpleEvent( d1, ope_hilling_two, false );
284  }
285  break;
286 
287  case ope_hilling_two:
288  if (!m_farm->HillingUp( m_field, 0.0,
289  g_date->DayInYear( 10, 6 ) - g_date->DayInYear())) {
290  SimpleEvent( g_date->Date() + 1, ope_hilling_two, false );
291  break;
292  }
293  {
294  d1 = g_date->OldDays() + g_date->DayInYear( 5, 5 );
295  if ( g_date->Date() + 14 > d1 ) {
296  d1 = g_date->Date() + 14;
297  }
298  SimpleEvent( d1, ope_hilling_three, false );
299  }
300  break;
301 
302  case ope_hilling_three:
303  if ( m_ev->m_lock || m_farm->DoIt( 75 )) {
304  if (!m_farm->HillingUp( m_field, 0.0,
305  g_date->DayInYear( 10, 6 ) -
306  g_date->DayInYear())) {
307  SimpleEvent( g_date->Date() + 1, ope_hilling_three, true );
308  break;
309  }
310  }
311  OPOT_HILLING_THREE = g_date->Date();
312  // Main thread continues from strigling three.
313  break;
314 
315  case ope_water_one:
316  if ( m_ev->m_lock || m_farm->DoIt( 80 )) {
317  if (!m_farm->Water( m_field, 0.0,
318  g_date->DayInYear( 30, 6 ) -
319  g_date->DayInYear())) {
320  SimpleEvent( g_date->Date() + 1, ope_water_one, true );
321  break;
322  }
323  }
324  {
325  d1 = g_date->OldDays() + g_date->DayInYear( 26, 6 );
326  if ( g_date->Date() + 10 > d1 ) {
327  d1 = g_date->Date() + 10;
328  }
329  SimpleEvent( d1, ope_water_two, false );
330  }
331  break;
332 
333  case ope_water_two:
334  if ( m_ev->m_lock || m_farm->DoIt( 70 )) {
335  if (!m_farm->Water( m_field, 0.0,
336  g_date->DayInYear( 25, 7 ) -
337  g_date->DayInYear())) {
338  SimpleEvent( g_date->Date() + 1, ope_water_two, true );
339  break;
340  }
341  }
342  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 8 ),
343  ope_flaming_two, false );
344  break;
345 
346  case ope_flaming_two:
347  {
348  if ( m_ev->m_lock || m_farm->DoIt( 10 ))
349  {
350  if (!m_farm->Swathing( m_field, 0.0,
351  g_date->DayInYear( 15,10 ) -
352  g_date->DayInYear()))
353  {
354  SimpleEvent( g_date->Date() + 1, ope_flaming_two, true );
355  break;
356  }
357  }
358  {
359  int d = g_date->OldDays() + g_date->DayInYear( 1, 9 );
360  int rndval = random(7) + 14;
361  if ( g_date->Date() + rndval > d ) {
362  d = g_date->Date() + rndval;
363  }
364  SimpleEvent( d, ope_harvest, false );
365  }
366  break;
367  }
368 
369  case ope_harvest:
370  if (!m_farm->Harvest( m_field, 0.0,
371  g_date->DayInYear( 1, 11 ) - g_date->DayInYear())) {
372  SimpleEvent( g_date->Date() + 1, ope_harvest, false );
373  break;
374  }
375  m_field->SetVegPatchy(false);
376  done = true;
377  break;
378 
379  default:
380  g_msg->Warn( WARN_BUG, "OPotatoesEat::Do(): "
381  "Unknown event type! ", "" );
382  exit( 1 );
383  }
384 
385  return done;
386 }

References cfg_strigling_prop, Farm::DoIt(), Farm::FA_Manure(), Farm::FA_Slurry(), Farm::FP_Manure(), Farm::FP_Slurry(), Farm::Harvest(), Farm::HillingUp(), 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, ope_fa_manure, ope_fa_slurry, ope_flaming_one, ope_flaming_two, ope_fp_manure, ope_fp_slurry, ope_harvest, ope_hilling_one, ope_hilling_three, ope_hilling_two, ope_spring_harrow, ope_spring_plough, ope_spring_sow, ope_start, ope_strigling_one, ope_strigling_three, ope_strigling_two, ope_water_one, ope_water_two, OPOT_HILLING_THREE, OPOT_SLURRY_DATE, OPOT_SOW_DATE, Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringSow(), Farm::Strigling(), Farm::Swathing(), and Farm::Water().


The documentation for this class was generated from the following files:
ope_hilling_three
Definition: OPotatoes.h:52
ope_hilling_one
Definition: OPotatoes.h:48
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::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
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
ope_fa_slurry
Definition: OPotatoes.h:39
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
ope_water_two
Definition: OPotatoes.h:54
ope_harvest
Definition: OPotatoes.h:56
ope_flaming_two
Definition: OPotatoes.h:55
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
ope_start
Definition: OPotatoes.h:38
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
Farm::HillingUp
virtual bool HillingUp(LE *a_field, double a_user, int a_days)
Do hilling up on a_field, probably of potatoes.
Definition: farmfuncs.cpp:1663
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
ope_flaming_one
Definition: OPotatoes.h:46
Farm::FP_Manure
virtual bool FP_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an arable farmer.
Definition: farmfuncs.cpp:773
ope_water_one
Definition: OPotatoes.h:53
ope_spring_sow
Definition: OPotatoes.h:45
OPOT_HILLING_THREE
#define OPOT_HILLING_THREE
Definition: OPotatoes.h:35
ope_fp_slurry
Definition: OPotatoes.h:41
ope_hilling_two
Definition: OPotatoes.h:50
ope_fp_manure
Definition: OPotatoes.h:42
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
Crop::m_field
LE * m_field
Definition: farm.h:538
OPOT_SLURRY_DATE
#define OPOT_SLURRY_DATE
Definition: OPotatoes.h:33
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
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::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
ope_strigling_two
Definition: OPotatoes.h:49
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
ope_strigling_one
Definition: OPotatoes.h:47
ope_strigling_three
Definition: OPotatoes.h:51
ope_spring_harrow
Definition: OPotatoes.h:44
OPOT_SOW_DATE
#define OPOT_SOW_DATE
Definition: OPotatoes.h:34
cfg_strigling_prop
CfgFloat cfg_strigling_prop
Farm::Swathing
virtual bool Swathing(LE *a_field, double a_user, int a_days)
Cut the crop on a_field and leave it lying (probably rape)
Definition: farmfuncs.cpp:1744
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539
ope_spring_plough
Definition: OPotatoes.h:43
ope_fa_manure
Definition: OPotatoes.h:40
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