File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/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
OMaizeSilage Class Reference

#include <OMaizeSilage.h>

Inheritance diagram for OMaizeSilage:
Crop

Public Member Functions

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

◆ OMaizeSilage()

OMaizeSilage::OMaizeSilage ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
58  : Crop(a_tov, a_toc, a_L)
59  {
60  m_first_date = g_date->DayInYear(25, 4);
62  }

References Calendar::DayInYear(), g_date, Crop::m_first_date, and SetUpFarmCategoryInformation().

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

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

References LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::FA_Manure(), Farm::FA_NPK(), Farm::FA_Slurry(), g_date, g_msg, LE::GetMDates(), 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, Calendar::OldDays(), 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(), LE::SetMDates(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringSow(), Farm::StubbleHarrowing(), MapErrorMsg::Warn(), WARN_BUG, WARN_FILE, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void OMaizeSilage::SetUpFarmCategoryInformation ( )
inline
63  {
64  const int elements = 2 + (oms_foobar - OMAIZESILAGE_BASE);
66 
67  FarmManagementCategory catlist[elements] =
68  {
69  fmc_Others, // zero element unused but must be here
70  fmc_Others, // oms_start = 1, // Compulsory, start event must always be 1 (one).
71  fmc_Fertilizer, // oms_fa_manure_b = OMAIZESILAGE_BASE,
72  fmc_Fertilizer, // oms_fa_slurry_one,
73  fmc_Cultivation, // oms_spring_plough,
74  fmc_Cultivation, // oms_spring_harrow,
75  fmc_Others, // oms_spring_sow,
76  fmc_Fertilizer, // oms_fa_npk,
77  fmc_Cultivation, // oms_row_one,
78  fmc_Fertilizer, // oms_fa_slurry_two,
79  fmc_Cultivation, // oms_row_two,
80  fmc_Watering, // oms_water_one,
81  fmc_Watering, // oms_water_two,
82  fmc_Harvest, // oms_harvest,
83  fmc_Cultivation // oms_stubble,
84 
85 
86  // no foobar entry
87 
88  };
89  // Iterate over the catlist elements and copy them to vector
90  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
91 
92  }

References fmc_Cultivation, fmc_Fertilizer, fmc_Harvest, fmc_Others, fmc_Watering, Crop::m_base_elements_no, Crop::m_ManagementCategories, OMAIZESILAGE_BASE, and oms_foobar.

Referenced by OMaizeSilage().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
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
WARN_FILE
Definition: MapErrorMsg.h:37
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
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
oms_spring_sow
Definition: OMaizeSilage.h:40
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
oms_row_two
Definition: OMaizeSilage.h:44
OMaizeSilage::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OMaizeSilage.h:63
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
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: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
oms_spring_plough
Definition: OMaizeSilage.h:38
oms_harvest
Definition: OMaizeSilage.h:47
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
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:982
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:747
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
oms_row_one
Definition: OMaizeSilage.h:42
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: Farm.h:390
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
oms_fa_npk
Definition: OMaizeSilage.h:41
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
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
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:1183
Farm::Water
virtual bool Water(LE *a_field, double a_user, int a_days)
Carry out a watering on a_field.
Definition: FarmFuncs.cpp:1330
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
OMAIZESILAGE_SOW_DATE
#define OMAIZESILAGE_SOW_DATE
Definition: OMaizeSilage.h:32
oms_water_two
Definition: OMaizeSilage.h:46
oms_foobar
Definition: OMaizeSilage.h:49
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
oms_fa_manure_b
Definition: OMaizeSilage.h:36
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
oms_stubble
Definition: OMaizeSilage.h:48
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
OMAIZESILAGE_BASE
#define OMAIZESILAGE_BASE
Definition: OMaizeSilage.h:31
oms_fa_slurry_two
Definition: OMaizeSilage.h:43
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
oms_start
Definition: OMaizeSilage.h:35
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
Farm::StubbleHarrowing
virtual bool StubbleHarrowing(LE *a_field, double a_user, int a_days)
Carry out stubble harrowing on a_field.
Definition: FarmFuncs.cpp:1523
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
oms_fa_slurry_one
Definition: OMaizeSilage.h:37