Loading [MathJax]/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OOats Class Reference

#include <OOats.h>

Inheritance diagram for OOats:
Crop

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 OOats (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
void SetUpFarmCategoryInformation ()
 
- Public Member Functions inherited from Crop
virtual ~Crop ()
 
 Crop (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
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)
 
void GetCropType (TTypesOfCrops a_toc)
 
TTypesOfCrops GetCropType ()
 
FarmManagementCategory LookUpManagementCategory (int a_todo)
 
bool GetForceSpringOK ()
 

Additional Inherited Members

- Public Attributes inherited from Crop
TTypesOfVegetation m_tov
 
- 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...
 
bool StartUpCrop (int a_spring, std::vector< std::vector< int >> a_flexdates, int a_todo)
 
Holds the translation between the farm operation enum for each cropand the farm management category associated with it More...
 
bool AphidDamage (LE *a_field)
 Compares aphid numbers per m2 with a threshold to return true if threshold is exceeded. More...
 
- Protected Attributes inherited from Crop
Farmm_farm
 
LEm_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_base_elements_no
 
Landscapem_OurLandscape
 
bool m_forcespringpossible = false
 Used to signal that the crop can be forced to start in spring. More...
 
TTypesOfCrops m_toc
 The Crop type in terms of the TTypesOfCrops list (smaller list than tov, no country designation) More...
 
int m_CropClassification
 Contains information on whether this is a winter crop, spring crop, or catch crop that straddles the year boundary (0,1,2) More...
 
vector< FarmManagementCategorym_ManagementCategories
 Holds the translation between the farm operation enum for each crop and the farm management category associated with it. More...
 
- Static Protected Attributes inherited from Crop
static int m_date_modifier = 0
 Holds a value that shifts test pesticide use by this many days in crops modified to use it. More...
 

Constructor & Destructor Documentation

◆ OOats()

OOats::OOats ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline

Member Function Documentation

◆ Do()

bool OOats::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  {
43  case ooa_start:
44  {
45  a_field->ClearManagementActionSum();
46 
47  // Set up the date management stuff
48  // Could save the start day in case it is needed later
49  // m_field->m_startday = m_ev->m_startday;
50  m_last_date = g_date->DayInYear(25, 8);
51  // Start and stop dates for all events after harvest
52  int noDates = 2;
53  m_field->SetMDates(0, 0, g_date->DayInYear(11, 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(25, 8));
57  m_field->SetMDates(1, 1, g_date->DayInYear(25, 8));
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  if (m_ev->m_startday > g_date->DayInYear(1, 7))
62  {
63  if (m_field->GetMDates(0, 0) >= m_ev->m_startday)
64  {
65  g_msg->Warn(WARN_BUG, "OOats::Do(): "
66  "Harvest too late for the next crop to start!!!", "");
67  exit(1);
68  }
69  // Now fix any late finishing problems
70  for (int i = 0; i < noDates; i++)
71  {
72  if (m_field->GetMDates(0, i) >= m_ev->m_startday)
73  m_field->SetMDates(0, i, m_ev->m_startday - 1);
74  if (m_field->GetMDates(1, i) >= m_ev->m_startday)
75  m_field->SetMDates(1, i, m_ev->m_startday - 1);
76  }
77  }
78  // Now no operations can be timed after the start of the next crop.
79 
80  int d1;
81  if (!m_ev->m_first_year)
82  {
83  int today = g_date->Date();
84  // Are we before July 1st?
85  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
86  if (today < d1)
87  {
88  // Yes, too early. We assumme this is because the last crop was late
89  g_msg->Warn(WARN_BUG, " OOats::Do(): "
90  "Crop start attempt between 1st Jan & 1st July", "");
91  exit(1);
92  }
93  else
94  {
95  d1 = g_date->OldDays() + m_first_date +365; // Add 365 for spring crop
96  if (today > d1)
97  {
98  // Yes too late - should not happen - raise an error
99  g_msg->Warn(WARN_BUG, " OOats::Do(): "
100  "Crop start attempt after last possible start date", "");
101  exit(1);
102  }
103  }
104  }
105  else
106  {
108  ooa_spring_harrow, false);
109  break;
110  }
111  // End single block date checking code. Please see next line
112  // comment as well.
113  // Reinit d1 to first possible starting date.
114  d1 = g_date->OldDays() + m_first_date + 365;
115  if (g_date->Date() > d1)
116  {
117  d1 = g_date->Date();
118  }
119  // OK, let's go.
120  OOA_SOW_DATE = 0;
121  OOA_DID_STRIGLING_ONE = false;
122  if (m_farm->IsStockFarmer())
123  {
124  SimpleEvent(d1, ooa_fertmanure_stock, false);
125  }
126  else
127  {
128  SimpleEvent(d1, ooa_spring_plough, false);
129  }
130  break;
131  }
132 
134  if ( m_ev->m_lock || m_farm->DoIt( 70 ))
135  {
136  if (!m_farm->FA_Manure( m_field, 0.0,
137  g_date->DayInYear( 30,3 ) -
138  g_date->DayInYear())) {
139  SimpleEvent( g_date->Date() + 1, ooa_fertmanure_stock, true );
140  break;
141  }
142  }
144  break;
145 
146  case ooa_spring_plough:
147  if (!m_farm->SpringPlough( m_field, 0.0,
148  g_date->DayInYear( 30,3 ) -
149  g_date->DayInYear())) {
150  SimpleEvent( g_date->Date() + 1, ooa_spring_plough, true );
151  break;
152  }
153  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ),
154  ooa_spring_harrow, false );
155  break;
156 
157  case ooa_spring_harrow:
158  if (!m_farm->SpringHarrow( m_field, 0.0,
159  g_date->DayInYear( 20,4 ) -
160  g_date->DayInYear())) {
161  SimpleEvent( g_date->Date() + 1, ooa_spring_harrow, true );
162  break;
163  }
164  if ( m_farm->IsStockFarmer()) {
166  } else {
168  }
169  break;
170 
172  if (!m_farm->FA_Slurry( m_field, 0.0,
173  g_date->DayInYear( 20,4 ) -
174  g_date->DayInYear())) {
175  SimpleEvent( g_date->Date() + 1, ooa_fertslurry_stock, true );
176  break;
177  }
179  break;
180 
181  case ooa_spring_sow_one:
182  if (!m_farm->SpringSow( m_field, 0.0,
183  g_date->DayInYear( 20,4 ) -
184  g_date->DayInYear())) {
185  SimpleEvent( g_date->Date() + 1, ooa_spring_sow_one, true );
186  break;
187  }
188  OOA_SOW_DATE = g_date->Date();
189  if ( m_farm->IsStockFarmer()) {
190  int d1 = g_date->Date();
191  if ( d1 < g_date->OldDays() + g_date->DayInYear( 5,4 )) {
192  d1 = g_date->OldDays() + g_date->DayInYear( 5,4 );
193  }
194  SimpleEvent( d1, ooa_spring_roll, false );
195  } else {
196  SimpleEvent( g_date->Date() + 1, ooa_spring_sow_two, false );
197  }
198  break;
199 
200  case ooa_spring_sow_two:
201  if ( m_ev->m_lock || m_farm->DoIt( 60 ))
202  {
203  if (!m_farm->SpringSow( m_field, 0.0,
204  g_date->DayInYear( 22,4 ) -
205  g_date->DayInYear())) {
206  SimpleEvent( g_date->Date() + 1, ooa_spring_sow_two, true );
207  break;
208  }
209  OOA_SOW_DATE = g_date->Date();
210  }
211  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5,4 ),
212  ooa_spring_roll, false );
213  break;
214 
215  case ooa_spring_roll:
216  if ( m_ev->m_lock || m_farm->DoIt( 80 ))
217  {
218  if (!m_farm->SpringRoll( m_field, 0.0,
219  g_date->DayInYear( 20,4 ) -
220  g_date->DayInYear())) {
221  SimpleEvent( g_date->Date() + 1, ooa_spring_roll, true );
222  break;
223  }
224  }
225  {
226  int d1 = g_date->OldDays() + g_date->DayInYear( 15,4 );
227  if ( d1 < OOA_SOW_DATE + 10 ) {
228  d1 = OOA_SOW_DATE + 10;
229  }
230  SimpleEvent( d1, ooa_strigling_one, false );
231  }
232  break;
233 
234  case ooa_strigling_one:
235  if ( m_ev->m_lock || (cfg_strigling_prop.value() * m_farm->DoIt( 80 )))
236  {
237  if (!m_farm->Strigling( m_field, 0.0,
238  g_date->DayInYear( 30,4 ) -
239  g_date->DayInYear())) {
240  SimpleEvent( g_date->Date() + 1, ooa_strigling_one, true );
241  break;
242  }
243  OOA_DID_STRIGLING_ONE = true;
244  }
245  if ( ! OOA_DID_STRIGLING_ONE ) {
246  // No strigling, so jump directly to harvest.
247  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10,8 ),
248  ooa_harvest, false );
249  break;
250  }
251  {
252  int d1 = g_date->Date() + 10;
253  if ( d1 < g_date->OldDays() + g_date->DayInYear( 25,4 ) ) {
254  d1 = g_date->OldDays() + g_date->DayInYear( 25,4 );
255  }
256  SimpleEvent( d1, ooa_strigling_two, false );
257  }
258  break;
259 
260  case ooa_strigling_two:
261  if (!m_farm->Strigling( m_field, 0.0,
262  g_date->DayInYear( 5,5 ) -
263  g_date->DayInYear())) {
264  SimpleEvent( g_date->Date() + 1, ooa_strigling_two, true );
265  break;
266  }
267  {
268  int d1 = g_date->Date() + 10;
269  if ( d1 < g_date->OldDays() + g_date->DayInYear( 5,5 ) ) {
270  d1 = g_date->OldDays() + g_date->DayInYear( 5,5 );
271  }
272  SimpleEvent( d1, ooa_strigling_three, false );
273  }
274  break;
275 
276  case ooa_strigling_three:
277  if ( m_ev->m_lock || (cfg_strigling_prop.value() * m_farm->DoIt( 60 )))
278  {
279  if (!m_farm->Strigling( m_field, 0.0,
280  g_date->DayInYear( 20,5 ) -
281  g_date->DayInYear())) {
282  SimpleEvent( g_date->Date() + 1, ooa_strigling_three, true );
283  break;
284  }
285  }
286  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10,8 ),
287  ooa_harvest, false );
288  break;
289 
290  case ooa_harvest:
291  if (!m_farm->Harvest( m_field, 0.0,
292  m_field->GetMDates(1,0) -
293  g_date->DayInYear())) {
294  SimpleEvent( g_date->Date() + 1, ooa_harvest, true );
295  break;
296  }
298  break;
299 
300  case ooa_straw_chopping:
301  if ( m_ev->m_lock || m_farm->DoIt( 80 ))
302  {
303  if (!m_farm->StrawChopping( m_field, 0.0,
304  m_field->GetMDates(0,1) -
305  g_date->DayInYear())) {
306  SimpleEvent( g_date->Date() + 1, ooa_straw_chopping, true );
307  break;
308  }
309  done = true;
310  break;
311  }
312  SimpleEvent( g_date->Date(), ooa_hay_bailing, false );
313  break;
314 
315  case ooa_hay_bailing:
316  if (!m_farm->HayBailing( m_field, 0.0,
317  m_field->GetMDates(1,1) -
318  g_date->DayInYear())) {
319  SimpleEvent( g_date->Date() + 1, ooa_hay_bailing, true );
320  break;
321  }
322  done = true;
323  break;
324 
325  default:
326  g_msg->Warn( WARN_BUG, "OOats::Do(): "
327  "Unknown event type! ", "" );
328  exit( 1 );
329  }
330 
331  return done;
332 }

References cfg_strigling_prop, LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::FA_Manure(), Farm::FA_Slurry(), g_date, g_msg, LE::GetMDates(), Farm::Harvest(), Farm::HayBailing(), 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, Calendar::OldDays(), OOA_DID_STRIGLING_ONE, ooa_fertmanure_stock, ooa_fertslurry_stock, ooa_harvest, ooa_hay_bailing, OOA_SOW_DATE, ooa_spring_harrow, ooa_spring_plough, ooa_spring_roll, ooa_spring_sow_one, ooa_spring_sow_two, ooa_start, ooa_straw_chopping, ooa_strigling_one, ooa_strigling_three, ooa_strigling_two, LE::SetMDates(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringRoll(), Farm::SpringSow(), Farm::StrawChopping(), Farm::Strigling(), CfgFloat::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void OOats::SetUpFarmCategoryInformation ( )
inline
67  {
68  const int elements = 2 + (ooa_foobar - OOats_BASE);
70 
71  FarmManagementCategory catlist[elements] =
72  {
73  fmc_Others, // zero element unused but must be here
74  fmc_Others, // ooa_start = 1, // Compulsory, start event must always be 1 (one).
75  fmc_Cultivation, // ooa_autumn_plough = OOats_BASE,
76  fmc_Fertilizer, // ooa_fertmanure_stock,
77  fmc_Cultivation, // ooa_spring_plough,
78  fmc_Cultivation, // ooa_spring_harrow,
79  fmc_Fertilizer, // ooa_fertslurry_stock,
80  fmc_Others, // ooa_spring_sow_one,
81  fmc_Others, // ooa_spring_sow_two,
82  fmc_Cultivation, // ooa_spring_roll,
83  fmc_Cultivation, // ooa_strigling_one,
84  fmc_Cultivation, // ooa_strigling_two,
85  fmc_Cultivation, // ooa_strigling_three,
86  fmc_Harvest, // ooa_harvest,
87  fmc_Others, // ooa_straw_chopping,
88  fmc_Others // ooa_hay_bailing,
89 
90 
91  // no foobar entry
92 
93  };
94  // Iterate over the catlist elements and copy them to vector
95  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
96 
97  }

References fmc_Cultivation, fmc_Fertilizer, fmc_Harvest, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, ooa_foobar, and OOats_BASE.

Referenced by OOats().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
OOats_BASE
#define OOats_BASE
Definition: OOats.h:31
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:487
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:1067
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
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:421
OOA_DID_STRIGLING_ONE
#define OOA_DID_STRIGLING_ONE
Definition: OOats.h:34
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
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:1206
Farm::Harvest
virtual bool Harvest(LE *a_field, double a_user, int a_days)
Carry out a harvest on a_field.
Definition: FarmFuncs.cpp:1364
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
ooa_strigling_three
Definition: OOats.h:48
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
ooa_spring_sow_two
Definition: OOats.h:44
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
ooa_straw_chopping
Definition: OOats.h:50
ooa_spring_roll
Definition: OOats.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:1110
Farm::SpringSow
virtual bool SpringSow(LE *a_field, double a_user, int a_days, double a_seed_coating_amount=-1, PlantProtectionProducts a_ppp=ppp_foobar)
Carry out a sowing event in the spring on a_field.
Definition: FarmFuncs.cpp:501
CfgFloat::value
double value() const
Definition: Configurator.h:142
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
ooa_foobar
Definition: OOats.h:52
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
ooa_strigling_two
Definition: OOats.h:47
ooa_harvest
Definition: OOats.h:49
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
Farm::HayBailing
virtual bool HayBailing(LE *a_field, double a_user, int a_days)
Carry out hay bailing on a_field.
Definition: FarmFuncs.cpp:1507
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
Farm::StrawChopping
virtual bool StrawChopping(LE *a_field, double a_user, int a_days)
Carry out straw chopping on a_field.
Definition: FarmFuncs.cpp:1475
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
ooa_hay_bailing
Definition: OOats.h:51
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
OOats::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OOats.h:67
ooa_spring_plough
Definition: OOats.h:40
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
Crop::m_ManagementCategories
vector< FarmManagementCategory > m_ManagementCategories
Holds the translation between the farm operation enum for each crop and the farm management category ...
Definition: Farm.h:530
OOA_SOW_DATE
#define OOA_SOW_DATE
Definition: OOats.h:33
ooa_fertmanure_stock
Definition: OOats.h:39
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
ooa_strigling_one
Definition: OOats.h:46
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
ooa_spring_harrow
Definition: OOats.h:41
ooa_fertslurry_stock
Definition: OOats.h:42
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
ooa_spring_sow_one
Definition: OOats.h:43
cfg_strigling_prop
CfgFloat cfg_strigling_prop
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
ooa_start
Definition: OOats.h:37
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
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:459