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

#include <OFieldPeas.h>

Inheritance diagram for OFieldPeas:
Crop

Public Member Functions

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

◆ OFieldPeas()

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

Member Function Documentation

◆ Do()

bool OFieldPeas::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  {
43  case ofp_start:
44  {
45  a_field->ClearManagementActionSum();
46 
47  // Set up the date management stuff
49  // Start and stop dates for all events after harvest
50  int noDates= 1;
51  m_field->SetMDates(0,0,g_date->DayInYear(10,8));
52  // Determined by harvest date - used to see if at all possible
53  m_field->SetMDates(1,0,g_date->DayInYear(25,8));
54  // Check the next crop for early start, unless it is a spring crop
55  // in which case we ASSUME that no checking is necessary!!!!
56  // So DO NOT implement a crop that runs over the year boundary
57  if (m_ev->m_startday>g_date->DayInYear(1,7))
58  {
59  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
60  {
61  g_msg->Warn( WARN_BUG, "OFieldPeas::Do(): "
62  "Harvest too late for the next crop to start!!!", "" );
63  exit( 1 );
64  }
65  // Now fix any late finishing problems
66  for (int i=0; i<noDates; i++)
67  {
68  if (m_field->GetMDates(0,i)>=m_ev->m_startday)
70  if (m_field->GetMDates(1,i)>=m_ev->m_startday)
72  }
73  }
74  // Now no operations can be timed after the start of the next crop.
75 
76  int d1;
77  int today=g_date->Date();
78  d1 = g_date->OldDays() + m_first_date +365; // Add 365 for spring crop
79  if (today > d1)
80  {
81  // Yes too late - should not happen - raise an error
82  g_msg->Warn( WARN_BUG, "OFieldPeas::Do(): "
83  "Crop start attempt after last possible start date", "" );
84  exit( 1 );
85  }
86  // End single block date checking code. Please see next line
87  // comment as well.
88  // Reinit d1 to first possible starting date.
89  d1 = g_date->OldDays()+m_first_date;;
90  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
91  if ( g_date->Date() > d1 ) {
92  d1 = g_date->Date();
93  }
94  // OK, let's go.
95  SimpleEvent( d1, ofp_spring_plough, false );
96  }
97  break;
98 
99  case ofp_spring_plough:
100  if (!m_farm->SpringPlough( m_field, 0.0,
101  g_date->DayInYear( 30,3 ) - g_date->DayInYear())) {
102  SimpleEvent( g_date->Date() + 1, ofp_spring_plough, true );
103  break;
104  }
105  SimpleEvent( g_date->Date()+1, ofp_spring_harrow, false );
106  break;
107 
108  case ofp_spring_harrow:
109  if (!m_farm->SpringHarrow( m_field, 0.0,
110  g_date->DayInYear( 5,4 ) - g_date->DayInYear())) {
111  SimpleEvent( g_date->Date() + 1, ofp_spring_harrow, true );
112  break;
113  }
114  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ),
115  ofp_spring_sow, false );
116  break;
117 
118  case ofp_spring_sow:
119  if (!m_farm->SpringSow( m_field, 0.0,
120  g_date->DayInYear( 15,4 ) - g_date->DayInYear())) {
121  SimpleEvent( g_date->Date() + 1, ofp_spring_sow, true );
122  break;
123  }
124  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ),
125  ofp_spring_roll, false );
126  // --FN--
127  break;
128 
129  case ofp_spring_roll:
130  if (!m_farm->SpringRoll( m_field, 0.0,
131  g_date->DayInYear( 20,4 ) - g_date->DayInYear())) {
132  SimpleEvent( g_date->Date() + 1, ofp_spring_roll, true );
133  break;
134  }
135  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,4 ),
136  ofp_strigling1, false );
137  break;
138 
139  case ofp_strigling1:
140  if (!m_farm->Strigling( m_field, 0.0,
141  g_date->DayInYear( 30,4 ) - g_date->DayInYear())) {
142  SimpleEvent( g_date->Date() + 1, ofp_strigling1, true );
143  break;
144  }
145  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,5 ),
146  ofp_strigling2, false );
147  break;
148 
149  case ofp_strigling2:
150  if (!m_farm->Strigling( m_field, 0.0,
151  g_date->DayInYear( 10,5 ) - g_date->DayInYear())) {
152  SimpleEvent( g_date->Date() + 1, ofp_strigling2, true );
153  break;
154  }
155  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 11,5 ),
156  ofp_strigling3, false );
157  break;
158 
159  case ofp_strigling3:
160  if (!m_farm->Strigling( m_field, 0.0,
161  g_date->DayInYear( 15,5 ) - g_date->DayInYear())) {
162  SimpleEvent( g_date->Date() + 1, ofp_strigling3, true );
163  break;
164  }
165  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 16,5 ),
166  ofp_strigling4, false );
167  break;
168 
169  case ofp_strigling4:
170  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
171  {
172  if (!m_farm->Strigling( m_field, 0.0,
173  g_date->DayInYear( 26,5 ) - g_date->DayInYear())) {
174  SimpleEvent( g_date->Date() + 1, ofp_strigling4, true );
175  break;
176  }
177  }
178  // --FN--
179  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10,6 ),
180  ofp_water1, false );
181  break;
182 
183  case ofp_water1:
184  if ( m_ev->m_lock || m_farm->DoIt( 20 ))
185  {
186  if (!m_farm->Water( m_field, 0.0,
187  g_date->DayInYear( 20,6 ) - g_date->DayInYear())) {
188  SimpleEvent( g_date->Date() + 1, ofp_water1, true );
189  break;
190  }
191  SimpleEvent( g_date->Date()+5, ofp_water2, false );
192  }
194  ofp_harvest, false );
195  break;
196 
197  case ofp_water2:
198  if (!m_farm->Water( m_field, 0.0,
199  g_date->DayInYear( 30,6 ) - g_date->DayInYear())) {
200  // --FN--
201  SimpleEvent( g_date->Date() + 1, ofp_water2, true );
202  break;
203  }
204  // --FN--
205  //SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10,8 ),
206  // ofp_harvest, false );
207  break;
208 
209  case ofp_harvest:
210  if (!m_farm->Harvest( m_field, 0.0,
211  m_field->GetMDates(1,0) - g_date->DayInYear())) {
212  SimpleEvent( g_date->Date() + 1, ofp_harvest, true );
213  break;
214  }
215  SimpleEvent( g_date->Date(), ofp_straw_chopping, false ); // Must do it
216  break;
217 
218  case ofp_straw_chopping:
219  if ( m_ev->m_lock || m_farm->DoIt( 100 ))
220  {
221  if (!m_farm->StrawChopping( m_field, 0.0,
222  m_field->GetMDates(1,0) - g_date->DayInYear())) {
223  SimpleEvent( g_date->Date()+1, ofp_straw_chopping, true );
224  break;
225  }
226  }
227  // End Main Thread
228  done=true;
229  break;
230 
231  default:
232  g_msg->Warn( WARN_BUG, "OFieldPeas::Do(): "
233  "Unknown event type! ", "" );
234  exit( 1 );
235  }
236 
237  return done;
238 }

References LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), 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_startday, FarmEvent::m_todo, ofp_harvest, ofp_spring_harrow, ofp_spring_plough, ofp_spring_roll, ofp_spring_sow, ofp_start, ofp_straw_chopping, ofp_strigling1, ofp_strigling2, ofp_strigling3, ofp_strigling4, ofp_water1, ofp_water2, Calendar::OldDays(), LE::SetMDates(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringRoll(), Farm::SpringSow(), Farm::StrawChopping(), Farm::Strigling(), MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void OFieldPeas::SetUpFarmCategoryInformation ( )
inline
61  {
62  const int elements = 2 + (ofp_foobar - OFPEAS_BASE);
64 
65  FarmManagementCategory catlist[elements] =
66  {
67  fmc_Others, // zero element unused but must be here
68  fmc_Others, // ofp_start = 1, // Compulsory, start event must always be 1 (one).
69  fmc_Harvest, // ofp_harvest= OFPEAS_BASE,
70  fmc_Cultivation, // ofp_spring_plough,
71  fmc_Cultivation, // ofp_spring_harrow,
72  fmc_Cultivation, // ofp_spring_roll,
73  fmc_Others, // ofp_spring_sow,
74  fmc_Cultivation, // ofp_strigling1,
75  fmc_Cultivation, // ofp_strigling2,
76  fmc_Cultivation, // ofp_strigling3,
77  fmc_Cultivation, // ofp_strigling4,
78  fmc_Watering, // ofp_water1,
79  fmc_Watering, // ofp_water2,
80  fmc_Others // ofp_straw_chopping,
81 
82 
83  // no foobar entry
84 
85  };
86  // Iterate over the catlist elements and copy them to vector
87  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
88 
89  }

References fmc_Cultivation, fmc_Harvest, fmc_Others, fmc_Watering, Crop::m_base_elements_no, Crop::m_ManagementCategories, ofp_foobar, and OFPEAS_BASE.

Referenced by OFieldPeas().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
ofp_strigling3
Definition: OFieldPeas.h:42
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
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
ofp_spring_harrow
Definition: OFieldPeas.h:37
Farm::Strigling
virtual bool Strigling(LE *a_field, double a_user, int a_days)
Carry out a mechanical weeding on a_field.
Definition: FarmFuncs.cpp:1206
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
ofp_spring_sow
Definition: OFieldPeas.h:39
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
ofp_water1
Definition: OFieldPeas.h:44
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
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
OFieldPeas::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OFieldPeas.h:61
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
ofp_strigling1
Definition: OFieldPeas.h:40
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
ofp_spring_plough
Definition: OFieldPeas.h:36
ofp_foobar
Definition: OFieldPeas.h:47
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
ofp_strigling4
Definition: OFieldPeas.h:43
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
Farm::StrawChopping
virtual bool StrawChopping(LE *a_field, double a_user, int a_days)
Carry out straw chopping on a_field.
Definition: FarmFuncs.cpp:1475
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
OFPEAS_BASE
#define OFPEAS_BASE
Definition: OFieldPeas.h:31
ofp_start
Definition: OFieldPeas.h:34
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
ofp_spring_roll
Definition: OFieldPeas.h:38
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
ofp_harvest
Definition: OFieldPeas.h:35
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
ofp_water2
Definition: OFieldPeas.h:45
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
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
ofp_strigling2
Definition: OFieldPeas.h:41
ofp_straw_chopping
Definition: OFieldPeas.h:46
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
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