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

#include <OFieldPeasSilage.h>

Inheritance diagram for OFieldPeasSilage:
Crop

Public Member Functions

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

◆ OFieldPeasSilage()

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

Member Function Documentation

◆ Do()

bool OFieldPeasSilage::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 ofps_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(25,7));
52  // Determined by harvest date - used to see if at all possible
53  m_field->SetMDates(1,0,g_date->DayInYear(20,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, "OFieldPeasSilage::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, "OFieldPeasSilage::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, ofps_spring_plough, false );
96  }
97  break;
98 
99  case ofps_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, ofps_spring_plough, true );
103  break;
104  }
105  SimpleEvent( g_date->Date()+1, ofps_spring_harrow, false );
106  break;
107 
108  case ofps_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, ofps_spring_harrow, true );
112  break;
113  }
114  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ),
115  ofps_spring_sow, false );
116  break;
117 
118  case ofps_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, ofps_spring_sow, true );
122  break;
123  }
124  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ),
125  ofps_spring_roll, false );
126  // --FN--
127  break;
128 
129  case ofps_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, ofps_spring_roll, true );
133  break;
134  }
135  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,4 ),
136  ofps_strigling1, false );
137  break;
138 
139  case ofps_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, ofps_strigling1, true );
143  break;
144  }
145  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,5 ),
146  ofps_strigling2, false );
147  break;
148 
149  case ofps_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, ofps_strigling2, true );
153  break;
154  }
155  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 11,5 ),
156  ofps_strigling3, false );
157  break;
158 
159  case ofps_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, ofps_strigling3, true );
163  break;
164  }
165  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 16,5 ),
166  ofps_strigling4, false );
167  break;
168 
169  case ofps_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, ofps_strigling4, true );
175  break;
176  }
177  }
178  // --FN--
179  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10,6 ),
180  ofps_water1, false );
181  break;
182 
183  case ofps_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, ofps_water1, true );
189  break;
190  }
191  SimpleEvent( g_date->Date()+5, ofps_water2, false );
192  }
194  ofps_harvest, false );
195  break;
196 
197  case ofps_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, ofps_water2, true );
202  break;
203  }
204  break;
205 
206  case ofps_harvest:
207  if (!m_farm->Harvest( m_field, 0.0,
208  m_field->GetMDates(1,0) - g_date->DayInYear())) {
209  SimpleEvent( g_date->Date() + 1, ofps_harvest, true );
210  break;
211  }
212  done=true;
213  break;
214 
215  default:
216  g_msg->Warn( WARN_BUG, "OFieldPeasSilage::Do(): "
217  "Unknown event type! ", "" );
218  exit( 1 );
219  }
220 
221  return done;
222 }

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, ofps_harvest, ofps_spring_harrow, ofps_spring_plough, ofps_spring_roll, ofps_spring_sow, ofps_start, ofps_strigling1, ofps_strigling2, ofps_strigling3, ofps_strigling4, ofps_water1, ofps_water2, Calendar::OldDays(), LE::SetMDates(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringRoll(), Farm::SpringSow(), Farm::Strigling(), MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void OFieldPeasSilage::SetUpFarmCategoryInformation ( )
inline
61  {
62  const int elements = 2 + (ofps_foobar - OFPEASSILAGE_BASE);
64 
65  FarmManagementCategory catlist[elements] =
66  {
67  fmc_Others, // zero element unused but must be here
68  fmc_Others, // ofps_start = 1, // Compulsory, start event must always be 1 (one).
69  fmc_Harvest, // ofps_harvest= OFPEASSILAGE_BASE,
70  fmc_Cultivation, // ofps_spring_plough,
71  fmc_Cultivation, // ofps_spring_harrow,
72  fmc_Cultivation, // ofps_spring_roll,
73  fmc_Others, // ofps_spring_sow,
74  fmc_Cultivation, // ofps_strigling1,
75  fmc_Cultivation, // ofps_strigling2,
76  fmc_Cultivation, // ofps_strigling3,
77  fmc_Cultivation, // ofps_strigling4,
78  fmc_Watering, // ofps_water1,
79  fmc_Watering, // ofps_water2,
80  fmc_Cutting // ofps_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_Cutting, fmc_Harvest, fmc_Others, fmc_Watering, Crop::m_base_elements_no, Crop::m_ManagementCategories, OFPEASSILAGE_BASE, and ofps_foobar.

Referenced by OFieldPeasSilage().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
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
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
ofps_strigling4
Definition: OFieldPeasSilage.h:43
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
ofps_spring_roll
Definition: OFieldPeasSilage.h:38
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
ofps_foobar
Definition: OFieldPeasSilage.h:47
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
ofps_water1
Definition: OFieldPeasSilage.h:44
ofps_strigling2
Definition: OFieldPeasSilage.h:41
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
ofps_spring_sow
Definition: OFieldPeasSilage.h:39
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
OFieldPeasSilage::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OFieldPeasSilage.h:61
ofps_water2
Definition: OFieldPeasSilage.h:45
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
ofps_start
Definition: OFieldPeasSilage.h:34
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
ofps_harvest
Definition: OFieldPeasSilage.h:35
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
ofps_strigling1
Definition: OFieldPeasSilage.h:40
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
ofps_strigling3
Definition: OFieldPeasSilage.h:42
OFPEASSILAGE_BASE
#define OFPEASSILAGE_BASE
Definition: OFieldPeasSilage.h:31
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
ofps_spring_harrow
Definition: OFieldPeasSilage.h:37
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
ofps_spring_plough
Definition: OFieldPeasSilage.h:36
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