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

#include <OCloverGrassGrazed2.h>

Inheritance diagram for OCloverGrassGrazed2:
Crop

Public Member Functions

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

◆ OCloverGrassGrazed2()

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

39 {
40  m_farm = a_farm;
41  m_field = a_field;
42  m_ev = a_ev;
43  bool done = false;
44  long d1 = 0;
45  int noDates= 2;
46 
47  switch ( m_ev->m_todo ) {
48  case ocgg2_start:
49  OCGG2_CUT_DATE = 0;
50  OCGG2_WATER_DATE = 0;
51  a_field->ClearManagementActionSum();
52 
53 
54  // Set up the date management stuff
55  // Could save the start day in case it is needed later
56  // m_field->m_startday = m_ev->m_startday;
58  // Start and stop dates for all events after harvest
59  m_field->SetMDates(0,0,g_date->DayInYear(27,7));
60  // Determined by harvest date - used to see if at all possible
61  m_field->SetMDates(1,0,g_date->DayInYear(10,10));
62  m_field->SetMDates(0,1,g_date->DayInYear(1,9));
63  m_field->SetMDates(1,1,g_date->DayInYear(1,10));
64  // Check the next crop for early start, unless it is a spring crop
65  // in which case we ASSUME that no checking is necessary!!!!
66  // So DO NOT implement a crop that runs over the year boundary
67  if (m_ev->m_startday>g_date->DayInYear(1,7))
68  {
69  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
70  {
71  g_msg->Warn( WARN_BUG, "OCloverGrassGrazed2::Do(): "
72  "Harvest too late for the next crop to start!!!", "" );
73  exit( 1 );
74  }
75  // Now fix any late finishing problems
76  for (int i=0; i<noDates; i++)
77  {
80  }
81  }
82  // Now no operations can be timed after the start of the next crop.
83  // Added test for management plan testing. FN, 19/5-2003.
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, "OCloverGrassGrazed2::Do(): "
90  "Crop start attempt between 1st Jan & 1st July", "" );
91  exit( 1 );
92  } else {
93  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
94  if (g_date->Date() > d1) {
95  // Yes too late - should not happen - raise an error
96  g_msg->Warn( WARN_BUG, "OCloverGrassGrazed2::Do(): "
97  "Crop start attempt after last possible start date",
98  "" );
99  exit( 1 );
100  }
101  }
102  } else {
103  // First (invisible) year or testing. Force the correct starting date.
104  d1 = g_date->OldDays() + g_date->DayInYear( 1, 4 );
105  // If testing and not the first year, then push all events
106  // into next year (start event is called in the autumn after
107  // the current year has finished). FN, 20/5-2003.
108  if (!m_ev->m_first_year) d1 += 365;
109  }
111  // OK, let's go.
112  OCGG2_CUT_DATE=0;
113  SimpleEvent( d1, ocgg2_ferti_zero, false );
114  break;
115  case ocgg2_ferti_zero:
116  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
117  {
118  if (!m_farm->FA_Slurry( m_field, 0.0,
119  g_date->DayInYear( 30, 4 ) - g_date->DayInYear())) {
120  // We didn't do it today, try again tomorrow.
121  SimpleEvent( g_date->Date() + 1, ocgg2_ferti_zero, true );
122  break;
123  }
124  }
125  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,5 ),
126  ocgg2_cattle_out, false );
127 // SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,5 ),
128 // cgg2_cut_to_silage, false );
129 
130 // Start a watering thread
131  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 5 ),
132  ocgg2_water_zero, false );
133  break;
134 
135 
136 case ocgg2_cattle_out:
137  if ( m_ev->m_lock || m_farm->DoIt( (int) (100-(cfg_silage_prop.value()*40) ))) {
139  if (!m_farm->CattleOutLowGrazing( m_field, 0.0,
140  m_field->GetMDates(1,1) -
141  g_date->DayInYear())) {
142  SimpleEvent( g_date->Date() + 1, ocgg2_cattle_out, true );
143  break;
144  }
145  }
146  else {
147  if (!m_farm->CattleOut( m_field, 0.0,
148  m_field->GetMDates(1,1) -
149  g_date->DayInYear())) {
150  SimpleEvent( g_date->Date() + 1, ocgg2_cattle_out, true );
151  break;
152  }
153  }
154  // Success
155  // Keep them out there
156  SimpleEvent( g_date->Date() + 1, ocgg2_cattle_is_out, false );
157  break;
158  }
159  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,5 ),
160  ocgg2_cut_to_silage, false );
161  break;
162 
163 case ocgg2_cattle_is_out: // Keep the cattle out there
164  // CattleIsOut() returns false if it is not time to stop grazing
166  if (!m_farm->CattleIsOutLow( m_field, 0.0, m_field->GetMDates(1,1) -
167  g_date->DayInYear(),m_field->GetMDates(1,1))) {
168  SimpleEvent( g_date->Date() + 1, ocgg2_cattle_is_out, false );
169  break;
170  }
171  }
172  else {
173  if ( !m_farm->CattleIsOut( m_field, 0.0,
174  m_field->GetMDates(1,1) -
175  g_date->DayInYear(),m_field->GetMDates(1,1)))
176  {
177  SimpleEvent( g_date->Date() + 1, ocgg2_cattle_is_out, false );
178  break;
179  }
180  }
181  done=true;
182  break;
183 
185 if ( m_ev->m_lock || m_farm->DoIt( 100 )) {
186  if ( g_date->Date() < OCGG2_WATER_DATE + 7 ) {
187  SimpleEvent( g_date->Date() + 1, ocgg2_cut_to_silage, true );
188  break;
189  }
190  if (!m_farm->CutToSilage( m_field, 0.0,
191  g_date->DayInYear( 25, 6 ) -
192  g_date->DayInYear())) {
193  // We didn't do it today, try again tomorrow.
194  SimpleEvent( g_date->Date() + 1, ocgg2_cut_to_silage, true );
195  break;
196  }
199  // But we need to graze too
200  SimpleEvent( g_date->Date()+14, ocgg2_cattle_out, true );
201 }
202 break;
203 
205 if ( m_ev->m_lock || m_farm->DoIt( 20 )) {
206  // But first if we are grazing then we must stop this
207  //
208  if (!m_farm->StubbleHarrowing( m_field, 0.0,
209  m_field->GetMDates(1,1) -
210  g_date->DayInYear())) {
211  // We didn't do it today, try again tomorrow.
212  SimpleEvent( g_date->Date() + 1, ocgg2_stubble_harrow, true );
213  break;
214  }
215  // If we ran, then we also happen to be the last event,
216  // so terminate the program by stopping grazing
217  m_field->SetMDates(1,1,g_date->DayInYear()-1);
218 }
219 break;
220 
221 case ocgg2_water_zero:
222  if ( m_ev->m_lock || m_farm->DoIt( 25 )) {
223  if ( g_date->Date() < OCGG2_CUT_DATE + 3 ) {
224  // Try again tomorrow, too close to silage cutting.
225  SimpleEvent( g_date->Date() + 1, ocgg2_water_zero, true );
226  break;
227  }
228  if (!m_farm->Water( m_field, 0.0,
229  g_date->DayInYear( 30, 5 ) -
230  g_date->DayInYear())) {
231  // We didn't do it today, try again tomorrow.
232  SimpleEvent( g_date->Date() + 1, ocgg2_water_zero, true );
233  break;
234  }
236 
237  long newdate1 = g_date->OldDays() + g_date->DayInYear( 1,6 );
238  long newdate2 = g_date->Date() + 7;
239  if ( newdate2 > newdate1 )
240  newdate1 = newdate2;
241  SimpleEvent( newdate1, ocgg2_water_one, false );
242  }
243  break;
244 
245 case ocgg2_water_one:
246  if ( m_ev->m_lock || m_farm->DoIt( 25 )) {
247  if ( g_date->Date() < OCGG2_CUT_DATE + 3 ) {
248  // Try again tomorrow, too close to silage cutting.
249  SimpleEvent( g_date->Date() + 1, ocgg2_water_one, true );
250  break;
251  }
252  if (!m_farm->Water( m_field, 0.0,
253  g_date->DayInYear( 15, 6 ) -
254  g_date->DayInYear())) {
255  // We didn't do it today, try again tomorrow.
256  SimpleEvent( g_date->Date() + 1, ocgg2_water_one, true );
257  break;
258  }
260  }
261  break;
262  // End of watering thread.
263 
264 
265  default:
266  g_msg->Warn( WARN_BUG, "OCloverGrassGrazed2::Do(): "
267  "Unknown event type! ", "" );
268  exit( 1 );
269  }
270 
271  return done;
272 }

References cfg_organic_extensive, cfg_silage_prop, LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), g_date, g_msg, ocgg2_cattle_is_out, ocgg2_cattle_out, OCGG2_CUT_DATE, ocgg2_cut_to_silage, ocgg2_ferti_zero, ocgg2_start, ocgg2_stubble_harrow, OCGG2_WATER_DATE, ocgg2_water_one, ocgg2_water_zero, Calendar::OldDays(), CfgFloat::value(), CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void OCloverGrassGrazed2::SetUpFarmCategoryInformation ( )
inline
58  {
59  const int elements = 2 + (ocgg2_foobar - OCGG2_BASE);
61 
62  FarmManagementCategory catlist[elements] =
63  {
64  fmc_Others, // zero element unused but must be here
65  fmc_Others, // ocgg2_start = 1, // Compulsory, start event must always be 1 (one).
66  fmc_Fertilizer, // ocgg2_ferti_zero=OCGG2_BASE,
67  fmc_Cutting, // ocgg2_cut_to_silage,
68  fmc_Watering, // ocgg2_water_zero,
69  fmc_Watering, // ocgg2_water_one,
70  fmc_Grazing, // ocgg2_cattle_out,
71  fmc_Grazing, // ocgg2_cattle_is_out,
72  fmc_Cultivation // ocgg2_stubble_harrow,
73 
74 
75  // no foobar entry
76 
77  };
78  // Iterate over the catlist elements and copy them to vector
79  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
80 
81  }

References fmc_Cultivation, fmc_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Others, fmc_Watering, Crop::m_base_elements_no, Crop::m_ManagementCategories, OCGG2_BASE, and ocgg2_foobar.

Referenced by OCloverGrassGrazed2().


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
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
ocgg2_start
Definition: OCloverGrassGrazed2.h:36
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
OCGG2_WATER_DATE
#define OCGG2_WATER_DATE
Definition: OCloverGrassGrazed2.h:32
OCGG2_BASE
#define OCGG2_BASE
Definition: OCloverGrassGrazed2.h:33
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
Farm::GetNextCrop
TTypesOfVegetation GetNextCrop(int a_index)
Definition: Farm.h:974
CfgFloat::value
double value() const
Definition: Configurator.h:142
OCloverGrassGrazed2::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OCloverGrassGrazed2.h:58
OCGG2_CUT_DATE
#define OCGG2_CUT_DATE
Definition: OCloverGrassGrazed2.h:31
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
cfg_organic_extensive
CfgBool cfg_organic_extensive
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
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
ocgg2_water_zero
Definition: OCloverGrassGrazed2.h:39
CfgBool::value
bool value() const
Definition: Configurator.h:164
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
cfg_silage_prop
CfgFloat cfg_silage_prop
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
ocgg2_stubble_harrow
Definition: OCloverGrassGrazed2.h:43
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
ocgg2_ferti_zero
Definition: OCloverGrassGrazed2.h:37
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
LE::GetRotIndex
int GetRotIndex(void)
Definition: Elements.h:373
ocgg2_cut_to_silage
Definition: OCloverGrassGrazed2.h:38
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
ocgg2_cattle_is_out
Definition: OCloverGrassGrazed2.h:42
ocgg2_foobar
Definition: OCloverGrassGrazed2.h:44
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
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
LE::GetOwner
Farm * GetOwner(void)
Definition: Elements.h:256
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
ocgg2_cattle_out
Definition: OCloverGrassGrazed2.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
ocgg2_water_one
Definition: OCloverGrassGrazed2.h:40
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