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

#include <OPermanentGrassGrazed.h>

Inheritance diagram for OPermanentGrassGrazed:
Crop

Public Member Functions

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

◆ OPermanentGrassGrazed()

OPermanentGrassGrazed::OPermanentGrassGrazed ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
56  : Crop(a_tov, a_toc, a_L)
57  {
60  }

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

Member Function Documentation

◆ Do()

bool OPermanentGrassGrazed::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  case opgg_start:
43  {
44  a_field->ClearManagementActionSum();
45 
46  // Set up the date management stuff
48  // Start and stop dates for all events after harvest
49  m_field->SetMDates(0,0,g_date->DayInYear(25,6));
50  // Determined by harvest date - used to see if at all possible
51  m_field->SetMDates(1,0,g_date->DayInYear(1,10));
52  if (m_ev->m_startday>g_date->DayInYear(1,7))
53  {
54  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
55  {
56  g_msg->Warn( WARN_BUG, "OPermanentGrassGrazed::Do(): "
57  "Harvest too late for the next crop to start!!!", "" );
58  exit( 1 );
59  }
60  // No need to try to fix late fininshing, this crop cannot be in
61  // rotation, and must be followed by itself
62  }
63  int d1;
64 
65  int today=g_date->Date();
66  d1 = g_date->OldDays() + m_first_date;
67  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
68  if (today > d1)
69  {
70  // Yes too late - should not happen - raise an error
71  g_msg->Warn( WARN_BUG, "OPermanentGrassGrazed::Do(): "
72  "Crop start attempt after last possible start date", "" );
73  exit( 1 );
74  }
75  // Reinit d1 to first possible starting date.
76  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
77  if ( g_date->Date() > d1 ) {
78  d1 = g_date->Date();
79  }
80  // OK, let's go.
81  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
82 
84  OPGG_CUT_DATE=0;
85  if (m_farm->IsStockFarmer())
86  SimpleEvent( d1, opgg_ferti_s, false );
87  else SimpleEvent( d1+60, opgg_cut_to_hay, false );
88  }
89  break;
90 
91  case opgg_ferti_s:
92  if ( m_ev->m_lock || m_farm->DoIt( 10 ))
93  {
94  if (!m_farm->FA_Slurry( m_field, 0.0,
95  g_date->DayInYear( 15,6 ) - g_date->DayInYear())) {
96  SimpleEvent( g_date->Date() + 1, opgg_ferti_s, true );
97  break;
98  }
100  SimpleEvent( g_date->Date() + 28,opgg_cut_to_hay, false );
101  break;
102  }
103  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,6 ),
104  opgg_cut_to_hay, false );
105  break;
106 
107  case opgg_cut_to_hay:
108  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
109  {
110  if (!m_farm->CutToHay( m_field, 0.0,
111  g_date->DayInYear( 15,8 ) - g_date->DayInYear())) {
112  SimpleEvent( g_date->Date() + 1, opgg_cut_to_hay, true );
113  break;
114  }
115  // did cut to hay so try turning
116  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 26,6 ),
117  opgg_raking1, false );
119  break;
120  }
121  if (OPGG_FERTI_DATE+28 < g_date->DayInYear( 15, 6 ))
122  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 6 ),
123  opgg_cattle_out2, false ); // 80% of non-cutters graze
124  else
126  opgg_cattle_out2, false ); // 80% of non-cutters graze
127 
128  break;
129 
130  case opgg_raking1:
131  if (!m_farm->HayTurning( m_field, 0.0,
132  (OPGG_CUT_DATE+10) - g_date->DayInYear())) {
133  SimpleEvent( g_date->Date() + 1, opgg_raking1, true );
134  break;
135  }
136  else
138  SimpleEvent( g_date->Date()+1, opgg_raking2, false );
139  break;
140 
141  case opgg_raking2:
142  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
143  {
144  if (!m_farm->HayTurning( m_field, 0.0,
146  SimpleEvent( g_date->Date() + 1, opgg_raking2, true );
147  break;
148  }
149  else
151  }
153  opgg_compress_straw, false );
154  break;
155 
156  case opgg_compress_straw:
157  if (!m_farm->HayBailing( m_field, 0.0,
159  {
160  SimpleEvent( g_date->Date() + 1, opgg_compress_straw, true );
161  break;
162  }
163  // Did compress straw
165  opgg_cattle_out1, false ); // cut but no straw so 100% graze
166  break;
167 
168  case opgg_cattle_out1:
170  if (!m_farm->CattleOutLowGrazing( m_field, 0.0,
171  g_date->DayInYear( 1,10 ) - g_date->DayInYear())) {
172  SimpleEvent( g_date->Date() + 1, opgg_cattle_out1, true );
173  break;
174  }
175  }
176  else {
177  if (!m_farm->CattleOut( m_field, 0.0,
178  g_date->DayInYear( 1,10 ) - g_date->DayInYear())) {
179  SimpleEvent( g_date->Date() + 1, opgg_cattle_out1, true );
180  break;
181  }
182  }
183  SimpleEvent( g_date->Date() + 1, opgg_cattle_is_out, false );
184  break;
185 
186  case opgg_cattle_out2:
187  if ( ( m_ev->m_lock || m_farm->DoIt( 80 )) || (OPGG_FERTI_DATE!=0) )
188  {
190  if (!m_farm->CattleOutLowGrazing( m_field, 0.0,
191  g_date->DayInYear( 1,10 ) - g_date->DayInYear())) {
192  SimpleEvent( g_date->Date() + 1, opgg_cattle_out2, true );
193  break;
194  }
195  }
196  else {
197  if (!m_farm->CattleOut( m_field, 0.0,
198  g_date->DayInYear( 1,10 ) - g_date->DayInYear())) {
199  SimpleEvent( g_date->Date() + 1, opgg_cattle_out2, true );
200  break;
201  }
202  }
203  // Success
204  SimpleEvent( g_date->Date() + 1, opgg_cattle_is_out, false );
205  break;
206  }
208  opgg_cut_weeds, false );
209  break;
210 
211  case opgg_cattle_is_out:
213  if (!m_farm->CattleIsOutLow( m_field, 0.0,
214  g_date->DayInYear( 1, 10 ) - g_date->DayInYear(),g_date->DayInYear( 1, 10 )))
215  {
216  SimpleEvent( g_date->Date() + 1, opgg_cattle_is_out, true );
217  break;
218  }
219  }
220  else {
221  if (!m_farm->CattleIsOut( m_field, 0.0,
222  g_date->DayInYear( 1, 10 ) - g_date->DayInYear(),g_date->DayInYear( 1, 10 )))
223  {
224  SimpleEvent( g_date->Date() + 1, opgg_cattle_is_out, true );
225  break;
226  }
227  }
228  // if they come in the send them out if too early
229  if (g_date->DayInYear()<g_date->DayInYear(10,9))
230  {
231  SimpleEvent( g_date->Date()+1, opgg_cattle_out2, true );
232  break;
233  }
235  opgg_cut_weeds, false );
236  break;
237 
238  case opgg_cut_weeds:
239  if (( m_ev->m_lock || m_farm->DoIt( 25 ))&&
240  (g_date->Date()<g_date->DayInYear(15,9)))
241  {
242  if (!m_farm->CutWeeds( m_field, 0.0,
243  g_date->DayInYear( 15,9 ) - g_date->DayInYear())) {
244  SimpleEvent( g_date->Date() + 1, opgg_cut_weeds, true );
245  break;
246  }
247  }
248  // END MAIN THREAD
249  done = true;
250  break;
251 
252  default:
253  g_msg->Warn( WARN_BUG, "PermanantGrassGrazed::Do(): "
254  "Unknown event type! ", "" );
255  exit( 1 );
256  }
257 
258  return done;
259 }

References Farm::CattleIsOut(), Farm::CattleIsOutLow(), Farm::CattleOut(), Farm::CattleOutLowGrazing(), cfg_organic_extensive, LE::ClearManagementActionSum(), Farm::CutToHay(), Farm::CutWeeds(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::FA_Slurry(), g_date, g_msg, LE::GetMDates(), Farm::HayBailing(), Farm::HayTurning(), 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(), opgg_cattle_is_out, opgg_cattle_out1, opgg_cattle_out2, opgg_compress_straw, OPGG_CUT_DATE, opgg_cut_to_hay, opgg_cut_weeds, OPGG_FERTI_DATE, opgg_ferti_s, opgg_raking1, opgg_raking2, opgg_start, OPGG_TURN_DATE, LE::SetLastSownVeg(), LE::SetMDates(), Crop::SimpleEvent(), CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void OPermanentGrassGrazed::SetUpFarmCategoryInformation ( )
inline
61  {
62  const int elements = 2 + (opgg_foobar - OPGG_BASE);
64 
65  FarmManagementCategory catlist[elements] =
66  {
67  fmc_Others, // zero element unused but must be here
68  fmc_Others, // opgg_start = 1, // Compulsory, start event must always be 1 (one).
69  fmc_Cutting, // opgg_cut_to_hay = OPGG_BASE,
70  fmc_Grazing, // opgg_cattle_out1,
71  fmc_Grazing, // opgg_cattle_out2,
72  fmc_Grazing, // opgg_cattle_is_out,
73  fmc_Cutting, // opgg_cut_weeds,
74  fmc_Fertilizer, // opgg_ferti_s,
75  fmc_Cultivation, // opgg_raking1,
76  fmc_Cultivation, // opgg_raking2,
77  fmc_Others // opgg_compress_straw,
78 
79 
80  // no foobar entry
81 
82  };
83  // Iterate over the catlist elements and copy them to vector
84  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
85 
86  }

References fmc_Cultivation, fmc_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, OPGG_BASE, and opgg_foobar.

Referenced by OPermanentGrassGrazed().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
opgg_cattle_out1
Definition: OPermanentGrassGrazed.h:39
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
OPGG_FERTI_DATE
#define OPGG_FERTI_DATE
Definition: OPermanentGrassGrazed.h:33
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
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::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
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
Farm::CutToHay
virtual bool CutToHay(LE *a_field, double a_user, int a_days)
Carry out hay cutting on a_field.
Definition: FarmFuncs.cpp:1607
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
opgg_cattle_is_out
Definition: OPermanentGrassGrazed.h:41
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
opgg_raking1
Definition: OPermanentGrassGrazed.h:44
opgg_raking2
Definition: OPermanentGrassGrazed.h:45
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
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
opgg_cut_to_hay
Definition: OPermanentGrassGrazed.h:38
opgg_ferti_s
Definition: OPermanentGrassGrazed.h:43
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
opgg_start
Definition: OPermanentGrassGrazed.h:37
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
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
opgg_compress_straw
Definition: OPermanentGrassGrazed.h:46
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
OPermanentGrassGrazed::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OPermanentGrassGrazed.h:61
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
opgg_foobar
Definition: OPermanentGrassGrazed.h:47
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
OPGG_CUT_DATE
#define OPGG_CUT_DATE
Definition: OPermanentGrassGrazed.h:32
opgg_cattle_out2
Definition: OPermanentGrassGrazed.h:40
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
OPGG_TURN_DATE
#define OPGG_TURN_DATE
Definition: OPermanentGrassGrazed.h:34
OPGG_BASE
#define OPGG_BASE
Definition: OPermanentGrassGrazed.h:31
cfg_organic_extensive
CfgBool cfg_organic_extensive
Farm::HayTurning
virtual bool HayTurning(LE *a_field, double a_user, int a_days)
Carry out hay turning on a_field.
Definition: FarmFuncs.cpp:1491
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
opgg_cut_weeds
Definition: OPermanentGrassGrazed.h:42
Farm::CutWeeds
virtual bool CutWeeds(LE *a_field, double a_user, int a_days)
Carry out weed topping on a_field.
Definition: FarmFuncs.cpp:1629