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

#include <OBarleyPeaCloverGrass.h>

Inheritance diagram for OBarleyPeaCloverGrass:
Crop

Public Member Functions

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

◆ OBarleyPeaCloverGrass()

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

Member Function Documentation

◆ Do()

bool OBarleyPeaCloverGrass::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=0;
39 
40  bool done = false;
41 
42  switch ( m_ev->m_todo )
43  {
44  case obpcg_start:
45  {
46  a_field->ClearManagementActionSum();
47 
48  // Set up the date management stuff
50  // Start and stop dates for all events after harvest
51  int noDates= 3;
52  m_field->SetMDates(0,0,g_date->DayInYear(25,7));
53  // Determined by harvest date - used to see if at all possible
54  m_field->SetMDates(1,0,g_date->DayInYear(25,8));
55  m_field->SetMDates(0,1,g_date->DayInYear(10,10));
56  m_field->SetMDates(1,1,g_date->DayInYear(10,10));
57  m_field->SetMDates(0,2,g_date->DayInYear(25,7));
58  m_field->SetMDates(1,2,g_date->DayInYear(1,8));
59  // Check the next crop for early start, unless it is a spring crop
60  // in which case we ASSUME that no checking is necessary!!!!
61  // So DO NOT implement a crop that runs over the year boundary
62  if (m_ev->m_startday>g_date->DayInYear(1,7))
63  {
64  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
65  {
66  g_msg->Warn( WARN_BUG, "OBarleyPeaCloverGrass::Do(): "
67  "Harvest too late for the next crop to start!!!", "" );
68  exit( 1 );
69  }
70  // Now fix any late finishing problems
71  for (int i=0; i<noDates; i++)
72  {
73  if (m_field->GetMDates(0,i)>=m_ev->m_startday)
75  if (m_field->GetMDates(1,i)>=m_ev->m_startday)
77  }
78  }
79  // Now no operations can be timed after the start of the next crop.
80 
81  // Now no operations can be timed after the start of the next crop.
82 
83  int today=g_date->Date();
84  d1 = g_date->OldDays() + m_first_date;
85  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
86  if (today > d1)
87  {
88  // Yes too late - should not happen - raise an error
89  g_msg->Warn( WARN_BUG, "OBarleyPeaCloverGrass::Do(): "
90  "Crop start attempt after last possible start date", "" );
91  exit( 1 );
92  }
93  // OK, let's go.
94  SimpleEvent( d1, obpcg_ferti_zero, false );
95  }
96  break;
97 
98  case obpcg_ferti_zero:
99  if ( m_ev->m_lock || m_farm->DoIt( 20 ))
100  {
101  if (!m_farm->FA_Manure( m_field, 0.0,
102  g_date->DayInYear( 10, 4 ) - g_date->DayInYear()))
103  {
104  SimpleEvent( g_date->Date() + 1, obpcg_ferti_zero, true );
105  break;
106  }
107  }
108  SimpleEvent( g_date->Date(),obpcg_ferti_one, false );
109  break;
110 
111  case obpcg_ferti_one:
112  if ( m_ev->m_lock || m_farm->DoIt( 100 ))
113  {
114  if (!m_farm->FA_Slurry( m_field, 0.0,
115  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
116  SimpleEvent( g_date->Date() + 1, obpcg_ferti_one, true );
117  break;
118  }
119  }
120  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 3 ),
121  obpcg_spring_plough, false );
122  break;
123 
124  case obpcg_spring_plough:
125  if (!m_farm->SpringPlough( m_field, 0.0,
126  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
127  SimpleEvent( g_date->Date() + 1, obpcg_spring_plough, true );
128  break;
129  }
131  break;
132 
133  case obpcg_spring_harrow:
134  if (!m_farm->SpringHarrow( m_field, 0.0,
135  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
136  SimpleEvent( g_date->Date() + 1, obpcg_spring_harrow, true );
137  break;
138  }
140  break;
141 
142  case obpcg_spring_roll:
143  if (!m_farm->SpringRoll( m_field, 0.0,
144  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
145  SimpleEvent( g_date->Date() + 1, obpcg_spring_roll, true );
146  break;
147  }
148  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20, 3 ),
149  obpcg_spring_sow1, false );
150  break;
151 
152  case obpcg_spring_sow1:
153  if (!m_farm->SpringSow( m_field, 0.0,
154  g_date->DayInYear( 12, 4 ) - g_date->DayInYear())) {
155  SimpleEvent( g_date->Date() + 1, obpcg_spring_sow1, true );
156  break;
157  }
158  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,3 ),
159  obpcg_spring_sow2, false );
160  break;
161 
162  case obpcg_spring_sow2:
163  if (!m_farm->SpringSow( m_field, 0.0,
164  g_date->DayInYear( 12, 4 ) - g_date->DayInYear())) {
165  SimpleEvent( g_date->Date() + 1, obpcg_spring_sow2, true );
166  break;
167  }
168  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5,6 ),
169  obpcg_water1, false );
170  break;
171 
172  case obpcg_water1:
173  if ( m_ev->m_lock || m_farm->DoIt( 10 ))
174  {
175  if (!m_farm->Water( m_field, 0.0,
176  g_date->DayInYear( 15,6 ) - g_date->DayInYear())) {
177  SimpleEvent( g_date->Date() + 1, obpcg_water1, true );
178  break;
179  }
180  // Must have watered so do it again
181  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 16,6 ),
182  obpcg_water2, false );
183  break;
184  }
185  // Must have failed to water so go straight to cut to silage
186  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,7 ),
187  obpcg_cut_to_silage, false );
188  break;
189 
190  case obpcg_water2:
191  if (!m_farm->Water( m_field, 0.0,
192  g_date->DayInYear( 30,6 ) - g_date->DayInYear())) {
193  SimpleEvent( g_date->Date() + 1, obpcg_water2, true );
194  break;
195  }
197  obpcg_cut_to_silage, false );
198  break;
199 
200  case obpcg_cut_to_silage:
201  if ( m_ev->m_lock || m_farm->DoIt( 95 ))
202  {
203  if (!m_farm->CutToSilage( m_field, 0.0,
204  m_field->GetMDates(1,2) - g_date->DayInYear())) {
205  SimpleEvent( g_date->Date() + 1, obpcg_cut_to_silage, true );
206  break;
207  }
209  // cjt 210503 need some special checking here to make sure we don't go
210  // over the last date possible
211  if ((g_date->DayInYear( )+21)>= m_field->GetMDates(0,1))
212  d1=m_field->GetMDates(0,1);
213  else d1=g_date->DayInYear( )+21;
214  SimpleEvent( d1,obpcg_cattle_out, false );
215  break;
216  }
217  // Did not cut for silage to do harvest instead
219  obpcg_harvest, false );
220  break;
221 
222  case obpcg_harvest:
223  if (!m_farm->Harvest( m_field, 0.0,
224  m_field->GetMDates(1,0) - g_date->DayInYear())) {
225  SimpleEvent( g_date->Date() + 1, obpcg_harvest, true );
226  break;
227  }
228  // cjt 210503 need some special checking here to make sure we don't go
229  // over the last date possible
230  if ((g_date->DayInYear( )+21)>= m_field->GetMDates(0,1))
231  d1=m_field->GetMDates(0,1);
232  else d1=g_date->DayInYear( )+21;
233  SimpleEvent( g_date->OldDays() + d1,obpcg_cattle_out, false );
234  break;
235 
236  case obpcg_cattle_out:
237  if ( m_ev->m_lock || m_farm->DoIt( 90 ))
238  {
240  if (!m_farm->CattleOutLowGrazing( m_field, 0.0,
241  m_field->GetMDates(0,1) - g_date->DayInYear())) {
242  SimpleEvent( g_date->Date() + 1, obpcg_cattle_out, true );
243  break;
244  }
245  }
246  else {
247  if (!m_farm->CattleOut( m_field, 0.0,
248  m_field->GetMDates(0,1) - g_date->DayInYear())) {
249  SimpleEvent( g_date->Date() + 1, obpcg_cattle_out, true );
250  break;
251  }
252  }
253 
254  SimpleEvent( g_date->Date() + 1, obpcg_cattle_is_out, false );
255  break;
256  }
257  done=true;
258  // END OF MAIN THREAD
259  break;
260 
261  case obpcg_cattle_is_out:
262 
264  if (!m_farm->CattleIsOutLow( m_field, 0.0,
266  {
267  SimpleEvent( g_date->Date() + 1, obpcg_cattle_is_out, false );
268  break;
269  }
270  }
271  else {
272  if (!m_farm->CattleIsOut( m_field, 0.0,
274  {
275  SimpleEvent( g_date->Date() + 1, obpcg_cattle_is_out, false );
276  break;
277  }
278  }
279  // END OF MAIN THREAD
280  done = true;
281  break;
282 
283  default:
284  g_msg->Warn( WARN_BUG, "OBarleyPeaCloverGrass::Do(): "
285  "Unknown event type! ", "" );
286  exit( 1 );
287  }
288 
289  return done;
290 }

References Farm::CattleIsOut(), Farm::CattleIsOutLow(), Farm::CattleOut(), Farm::CattleOutLowGrazing(), cfg_organic_extensive, LE::ClearManagementActionSum(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::FA_Manure(), Farm::FA_Slurry(), g_date, g_msg, LE::GetMDates(), Farm::Harvest(), harvest1, 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, obpcg_cattle_is_out, obpcg_cattle_out, obpcg_cut_to_silage, obpcg_ferti_one, obpcg_ferti_zero, obpcg_harvest, obpcg_spring_harrow, obpcg_spring_plough, obpcg_spring_roll, obpcg_spring_sow1, obpcg_spring_sow2, obpcg_start, obpcg_water1, obpcg_water2, Calendar::OldDays(), LE::SetGrowthPhase(), LE::SetMDates(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringRoll(), Farm::SpringSow(), CfgBool::value(), MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void OBarleyPeaCloverGrass::SetUpFarmCategoryInformation ( )
inline
63  {
64  const int elements = 2 + (obpcg_foobar - OBPCG_BASE);
66 
67  FarmManagementCategory catlist[elements] =
68  {
69  fmc_Others, // zero element unused but must be here
70  fmc_Others, // obpcg_start = 1, // Compulsory, start event must always be 1 (one).
71  fmc_Fertilizer, // obpcg_ferti_zero = OBPCG_BASE,
72  fmc_Watering, // obpcg_water1,
73  fmc_Watering, // obpcg_water2,
74  fmc_Harvest, // obpcg_harvest,
75  fmc_Fertilizer, // obpcg_ferti_one,
76  fmc_Cultivation, // obpcg_spring_plough,
77  fmc_Cultivation, // obpcg_spring_harrow,
78  fmc_Cultivation, // obpcg_spring_roll,
79  fmc_Others, // obpcg_spring_sow,
80  fmc_Others, // obpcg_spring_sow1,
81  fmc_Others, // obpcg_spring_sow2,
82  fmc_Cutting, // obpcg_cut_to_silage,
83  fmc_Grazing, // obpcg_cattle_out,
84  fmc_Grazing // obpcg_cattle_is_out,
85 
86 
87  // no foobar entry
88 
89  };
90  // Iterate over the catlist elements and copy them to vector
91  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
92 
93  }

References fmc_Cultivation, fmc_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Harvest, fmc_Others, fmc_Watering, Crop::m_base_elements_no, Crop::m_ManagementCategories, OBPCG_BASE, and obpcg_foobar.

Referenced by OBarleyPeaCloverGrass().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
harvest1
Definition: Plants.h:55
obpcg_foobar
Definition: OBarleyPeaCloverGrass.h:49
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
OBPCG_BASE
#define OBPCG_BASE
Definition: OBarleyPeaCloverGrass.h:31
obpcg_harvest
Definition: OBarleyPeaCloverGrass.h:38
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
obpcg_water2
Definition: OBarleyPeaCloverGrass.h:37
obpcg_ferti_one
Definition: OBarleyPeaCloverGrass.h:39
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
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
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
cfg_organic_extensive
CfgBool cfg_organic_extensive
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
obpcg_cattle_out
Definition: OBarleyPeaCloverGrass.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
obpcg_spring_sow1
Definition: OBarleyPeaCloverGrass.h:44
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
obpcg_spring_harrow
Definition: OBarleyPeaCloverGrass.h:41
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
obpcg_start
Definition: OBarleyPeaCloverGrass.h:34
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
obpcg_spring_sow2
Definition: OBarleyPeaCloverGrass.h:45
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
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
obpcg_spring_plough
Definition: OBarleyPeaCloverGrass.h:40
obpcg_spring_roll
Definition: OBarleyPeaCloverGrass.h:42
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
OBarleyPeaCloverGrass::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OBarleyPeaCloverGrass.h:63
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
obpcg_cattle_is_out
Definition: OBarleyPeaCloverGrass.h:48
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
obpcg_water1
Definition: OBarleyPeaCloverGrass.h:36
LE::SetGrowthPhase
virtual void SetGrowthPhase(int)
Definition: Elements.h:185
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
obpcg_cut_to_silage
Definition: OBarleyPeaCloverGrass.h:46
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
obpcg_ferti_zero
Definition: OBarleyPeaCloverGrass.h:35
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