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
OCloverGrassGrazed1 Class Reference

#include <OCloverGrassGrazed1.h>

Inheritance diagram for OCloverGrassGrazed1:
Crop

Public Member Functions

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

◆ OCloverGrassGrazed1()

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

38 {
39  m_farm = a_farm;
40  m_field = a_field;
41  m_ev = a_ev;
42 
43  bool done = false;
44  int d1 = 0;
45  int noDates= 2;
46 
47  switch ( m_ev->m_todo ) {
48  case ocgg1_start:
49  {
50  a_field->ClearManagementActionSum();
51 
52  // Set up the date management stuff
53  // Could save the start day in case it is needed later
54  // m_field->m_startday = m_ev->m_startday;
55  m_last_date = g_date->DayInYear(10, 10);
56  // Start and stop dates for all events after harvest
57  m_field->SetMDates(0, 0, g_date->DayInYear(7, 8));
58  // Determined by harvest date - used to see if at all possible
59  m_field->SetMDates(1, 0, g_date->DayInYear(1, 10));
60  m_field->SetMDates(0, 1, g_date->DayInYear(10, 10));
61  m_field->SetMDates(1, 1, g_date->DayInYear(10, 10));
62  // Check the next crop for early start, unless it is a spring crop
63  // in which case we ASSUME that no checking is necessary!!!!
64  // So DO NOT implement a crop that runs over the year boundary
65  if (m_ev->m_startday > g_date->DayInYear(1, 7))
66  {
67  if (m_field->GetMDates(0, 0) >= m_ev->m_startday)
68  {
69  g_msg->Warn(WARN_BUG, "OCloverGrassGrazed1::Do(): "
70  "Harvest too late for the next crop to start!!!", "");
71  exit(1);
72  }
73  // Now fix any late finishing problems
74  for (int i = 0; i < noDates; i++)
75  {
76  if (m_field->GetMDates(0, i) >= m_ev->m_startday)
77  m_field->SetMDates(0, i, m_ev->m_startday - 1);
78  if (m_field->GetMDates(1, i) >= m_ev->m_startday)
79  m_field->SetMDates(1, i, m_ev->m_startday - 1);
80  }
81  }
82  // Now no operations can be timed after the start of the next crop.
83  // Added test for management plan testing.
84  if (!(m_ev->m_first_year)) {
85  // Are we before July 1st?
86  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
87  if (g_date->Date() < d1) {
88  // Yes, too early. We assumme this is because the last crop was late
89  g_msg->Warn(WARN_BUG, "OCloverGrassGrazed1::Do(): "
90  "Crop start attempt between 1st Jan & 1st July", "");
91  exit(1);
92  }
93  else {
94  d1 = g_date->OldDays() + m_first_date + 365; // Add 365 for spring crop
95  if (g_date->Date() > d1) {
96  // Yes too late - should not happen - raise an error
97  g_msg->Warn(WARN_BUG, "OCloverGrassGrazed1::Do(): "
98  "Crop start attempt after last possible start date",
99  "");
100  exit(1);
101  }
102  }
103  }
104  else {
105  // First (invisible) year or testing. Force the correct starting date.
106  d1 = g_date->OldDays() + g_date->DayInYear(1, 4);
107  // If testing and not the first year, then push all events
108  // into next year (start event is called in the autumn after
109  // the current year has finished).
110  if (!m_ev->m_first_year) d1 += 365;
111  }
112  m_field->SetLastSownVeg(m_field->GetVegType()); //Force last sown, needed for goose habitat classification
113  // OK, let's go.
114  OCGG1_CUT_DATE = 0;
115  SimpleEvent(d1, ocgg1_ferti_zero, false);
116  }
117  break;
118 
119  case ocgg1_ferti_zero:
120  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
121  {
122  if (!m_farm->FA_Slurry( m_field, 0.0,
123  g_date->DayInYear( 30, 4 ) - g_date->DayInYear())) {
124  // We didn't do it today, try again tomorrow.
125  SimpleEvent( g_date->Date() + 1, ocgg1_ferti_zero, true );
126  break;
127  }
128  }
129  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25, 5 ),
130  ocgg1_cut_to_silage, false );
131  // Start a watering thread
132  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 6 ),
133  ocgg1_water_zero, false );
134  break;
135 
136  case ocgg1_cut_to_silage:
137  if ( m_ev->m_lock || m_farm->DoIt( (int) (cfg_silage_prop.value()*100 )))
138  {
139  if (!m_farm->CutToSilage( m_field, 0.0,
140  g_date->DayInYear( 15, 6 ) - g_date->DayInYear())) {
141  // We didn't do it today, try again tomorrow.
142  SimpleEvent( g_date->Date() + 1, ocgg1_cut_to_silage, true );
143  break;
144  }
145  // Success so queue up the next event
147  if ( OCGG1_CUT_DATE+14>g_date->DayInYear(25,5) )
149  ocgg1_cattle_out, false );
150  else
151  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25, 5 ),
152  ocgg1_cattle_out, false );
153  break;
154  }
155  else
156  {
157  // Didn't want to cut so go direct to graze
158  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25, 5 ),
159  ocgg1_cattle_out, true );
160 
161  }
162  break;
163 
164  case ocgg1_water_zero:
165  if ( m_ev->m_lock || m_farm->DoIt( 30 ))
166  {
167  if (!m_farm->Water( m_field, 0.0,
168  g_date->DayInYear( 15, 6 ) - g_date->DayInYear())) {
169  // We didn't do it today, try again tomorrow.
170  SimpleEvent( g_date->Date() + 1, ocgg1_water_zero, true );
171  break;
172  }
173  // Success
174  if ( (g_date->DayInYear()+7)<g_date->DayInYear( 25,6 ) )
176  ocgg1_water_one, false );
177  else
178  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,6 ),
179  ocgg1_water_one, false );
180  break;
181  }
182  // Didn't water so let the thread die
183  break;
184 
185  case ocgg1_water_one:
186  if ( m_ev->m_lock || m_farm->DoIt( 67 )) //**CJT** check this or 20
187  {
188  // --FN--
189  if (!m_farm->Water( m_field, 0.0,
190  g_date->DayInYear( 25, 7 ) - g_date->DayInYear())) {
191  // We didn't do it today, try again tomorrow.
192  SimpleEvent( g_date->Date() + 1, ocgg1_water_one, true );
193  break;
194  }
195  }
196  break;
197  // End of watering thread
198 
199  case ocgg1_cattle_out:
200  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
201  {
203  if (!m_farm->CattleOutLowGrazing( m_field, 0.0,
204  m_field->GetMDates(1,0) - g_date->DayInYear())) {
205  SimpleEvent( g_date->Date() + 1, ocgg1_cattle_out, true );
206  break;
207  }
208  }
209  else {
210  if (!m_farm->CattleOut( m_field, 0.0,
211  m_field->GetMDates(1,0) - g_date->DayInYear())) {
212  SimpleEvent( g_date->Date() + 1, ocgg1_cattle_out, true );
213  break;
214  }
215  }
216  // Success
217  // Keep them out there
218  SimpleEvent( g_date->Date() + 1, ocgg1_cattle_is_out, false );
219  break;
220  }
221  // don't graze so carry on with fertilizer etc.
222  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,5 ),
223  ocgg1_ferti_one, false );
224  break;
225 
226  case ocgg1_cattle_is_out: // Keep the cattle out there
227  // CattleIsOut() returns false if it is not time to stop grazing
229  if (!m_farm->CattleIsOutLow( m_field, 0.0,
230  m_field->GetMDates(0,1) - g_date->DayInYear(),m_field->GetMDates(0,1))) {
231  SimpleEvent( g_date->Date() + 1, ocgg1_cattle_is_out, false );
232  break;
233  }
234  }
235  else {
236  if (!m_farm->CattleIsOut( m_field, 0.0,
237  m_field->GetMDates(0,1) - g_date->DayInYear(),m_field->GetMDates(0,1))) {
238  SimpleEvent( g_date->Date() + 1, ocgg1_cattle_is_out, false );
239  break;
240  }
241  }
242  // if it is time to stop grazing then that years activities are over
243  done = true; // End of activities
244  break;
245 
246  case ocgg1_ferti_one:
247  if (!m_farm->FA_Slurry( m_field, 0.0,
248  ( OCGG1_CUT_DATE+4 ) - g_date->DayInYear())) {
249  SimpleEvent( g_date->Date() + 1, ocgg1_ferti_one, true );
250  break;
251  }
253  if ( (g_date->DayInYear(15,6))<OCGG1_CUT_DATE+21 )
255  ocgg1_cut_to_silage1, false );
256  else
257  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,6 ),
258  ocgg1_cut_to_silage1, false );
259  break;
260 
262  if ( m_ev->m_lock || m_farm->DoIt((int) (cfg_silage_prop.value()* 60 )))
263  {
264  if (!m_farm->CutToSilage( m_field, 0.0,
265  g_date->DayInYear( 7,7 ) - g_date->DayInYear())) {
266  // We didn't do it today, try again tomorrow.
267  SimpleEvent( g_date->Date() + 1, ocgg1_cut_to_silage, true );
268  break;
269  }
270  // Success so queue up the next event
272  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 6 ),
273  ocgg1_ferti_two, false );
274  break;
275  }
276  else
277  {
278  // Didn't want to cut so go direct to graze
280  ocgg1_cattle_out, true ); // Must do it
281  }
282  break;
283 
284  case ocgg1_ferti_two:
285  if ( m_ev->m_lock || m_farm->DoIt( 60 ))
286  {
287  if (!m_farm->FA_Slurry( m_field, 0.0,
288  (OCGG1_CUT_DATE+4) - g_date->DayInYear())) {
289  SimpleEvent( g_date->Date() + 2, ocgg1_ferti_two, true );
290  break;
291  }
293  }
294  {
295  d1=OCGG1_SLURRY+21;
296  long d2=g_date->DayInYear(1,7);
297  if (d2>d1) d1=d2;
298  SimpleEvent( g_date->OldDays() + d1,
299  ocgg1_cut_to_silage2, false );
300  }
301  break;
302 
304  if ( m_ev->m_lock || m_farm->DoIt( (int) (cfg_silage_prop.value()*60) ))
305  {
306  if (!m_farm->CutToSilage( m_field, 0.0,
307  g_date->DayInYear( 30, 6 ) - g_date->DayInYear())) {
308  // We didn't do it today, try again tomorrow.
309  SimpleEvent( g_date->Date() + 1, ocgg1_cut_to_silage2, true );
310  break;
311  }
312  // Success so queue up the next event
313  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5, 7 ),
314  ocgg1_ferti_three, false );
315  break;
316  }
317  else
318  {
319  // Didn't want to cut so go direct to graze
321  ocgg1_cattle_out, true ); // Must do it !
322  }
323  break;
324 
325  case ocgg1_ferti_three:
326  if (!m_farm->FA_Slurry( m_field, 0.0,
327  m_field->GetMDates(0,0) - g_date->DayInYear())) {
328  SimpleEvent( g_date->Date() + 1, ocgg1_ferti_three, true );
329  break;
330  }
331  done = true; // nothing else to do
332  break;
333 
334  default:
335  g_msg->Warn( WARN_BUG, "OCloverGrassGrazed1::Do(): "
336  "Unknown event type! ", "" );
337  exit( 1 );
338  }
339  return done;
340 }

References cfg_organic_extensive, cfg_silage_prop, LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), g_date, g_msg, ocgg1_cattle_is_out, ocgg1_cattle_out, OCGG1_CUT_DATE, ocgg1_cut_to_silage, ocgg1_cut_to_silage1, ocgg1_cut_to_silage2, ocgg1_ferti_one, ocgg1_ferti_three, ocgg1_ferti_two, ocgg1_ferti_zero, OCGG1_SLURRY, ocgg1_start, ocgg1_water_one, ocgg1_water_zero, Calendar::OldDays(), CfgFloat::value(), CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void OCloverGrassGrazed1::SetUpFarmCategoryInformation ( )
inline
61  {
62  const int elements = 2 + (ocgg1_foobar - OCGG1_BASE);
64 
65  FarmManagementCategory catlist[elements] =
66  {
67  fmc_Others, // zero element unused but must be here
68  fmc_Others, // ocgg1_start = 1, // Compulsory, start event must always be 1 (one).
69  fmc_Fertilizer, // ocgg1_ferti_zero=OCGG1_BASE,
70  fmc_Fertilizer, // ocgg1_ferti_one,
71  fmc_Fertilizer, // ocgg1_ferti_two,
72  fmc_Fertilizer, // ocgg1_ferti_three,
73  fmc_Cutting, // ocgg1_cut_to_silage,
74  fmc_Cutting, // ocgg1_cut_to_silage1,
75  fmc_Cutting, // ocgg1_cut_to_silage2,
76  fmc_Watering, // ocgg1_water_zero,
77  fmc_Watering, // ocgg1_water_one,
78  fmc_Grazing, // ocgg1_cattle_out,
79  fmc_Grazing // ocgg1_cattle_is_out,
80 
81 
82  // no foobar entry
83 
84  };
85  // Iterate over the catlist elements and copy them to vector
86  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
87 
88  }

References fmc_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Others, fmc_Watering, Crop::m_base_elements_no, Crop::m_ManagementCategories, OCGG1_BASE, and ocgg1_foobar.

Referenced by OCloverGrassGrazed1().


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
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
LE::SetLastSownVeg
void SetLastSownVeg(TTypesOfVegetation a_tov)
Records the last vegetation type to be sown.
Definition: Elements.h:357
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
OCGG1_SLURRY
#define OCGG1_SLURRY
Definition: OCloverGrassGrazed1.h:33
Farm::CattleIsOut
virtual bool CattleIsOut(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out' event for every day the cattle are on a_field.
Definition: FarmFuncs.cpp:2470
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Farm::CutToSilage
virtual bool CutToSilage(LE *a_field, double a_user, int a_days)
Cut vegetation for silage on a_field.
Definition: FarmFuncs.cpp:1644
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
ocgg1_cut_to_silage2
Definition: OCloverGrassGrazed1.h:42
ocgg1_ferti_three
Definition: OCloverGrassGrazed1.h:39
ocgg1_cattle_out
Definition: OCloverGrassGrazed1.h:45
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
CfgFloat::value
double value() const
Definition: Configurator.h:142
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
OCGG1_CUT_DATE
#define OCGG1_CUT_DATE
Definition: OCloverGrassGrazed1.h:31
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
cfg_organic_extensive
CfgBool cfg_organic_extensive
ocgg1_ferti_one
Definition: OCloverGrassGrazed1.h:37
Farm::CattleIsOutLow
virtual bool CattleIsOutLow(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out_low' event for every day the cattle are on a_field.
Definition: FarmFuncs.cpp:2561
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
Farm::CattleOutLowGrazing
virtual bool CattleOutLowGrazing(LE *a_field, double a_user, int a_days)
Start a extensive grazing event on a_field today.
Definition: FarmFuncs.cpp:2439
CfgBool::value
bool value() const
Definition: Configurator.h:164
ocgg1_water_zero
Definition: OCloverGrassGrazed1.h:43
OCGG1_BASE
#define OCGG1_BASE
Definition: OCloverGrassGrazed1.h:32
ocgg1_start
Definition: OCloverGrassGrazed1.h:35
ocgg1_cut_to_silage
Definition: OCloverGrassGrazed1.h:40
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
ocgg1_cattle_is_out
Definition: OCloverGrassGrazed1.h:46
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
ocgg1_water_one
Definition: OCloverGrassGrazed1.h:44
Calendar::Date
long Date(void)
Definition: Calendar.h:57
cfg_silage_prop
CfgFloat cfg_silage_prop
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
ocgg1_foobar
Definition: OCloverGrassGrazed1.h:47
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
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
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
ocgg1_ferti_zero
Definition: OCloverGrassGrazed1.h:36
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
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
ocgg1_ferti_two
Definition: OCloverGrassGrazed1.h:38
ocgg1_cut_to_silage1
Definition: OCloverGrassGrazed1.h:41
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
Farm::CattleOut
virtual bool CattleOut(LE *a_field, double a_user, int a_days)
Start a grazing event on a_field today.
Definition: FarmFuncs.cpp:2368
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
OCloverGrassGrazed1::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OCloverGrassGrazed1.h:61