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

#include <OSBarleySilage.h>

Inheritance diagram for OSBarleySilage:
Crop

Public Member Functions

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

◆ OSBarleySilage()

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

32 {
33  m_farm = a_farm;
34  m_field = a_field;
35  m_ev = a_ev;
36  bool done = false;
37 
38  switch ( m_ev->m_todo )
39  {
40  case osbs_start:
41  {
42  a_field->ClearManagementActionSum();
43 
44  // Set up the date management stuff
46  // Start and stop dates for all events after harvest
47  int noDates= 3;
48  m_field->SetMDates(0,0,g_date->DayInYear(25,7));
49  // Determined by harvest date - used to see if at all possible
50  m_field->SetMDates(1,0,g_date->DayInYear(25,8));
51  m_field->SetMDates(0,1,g_date->DayInYear(10,10));
52  m_field->SetMDates(1,1,g_date->DayInYear(10,10));
53  m_field->SetMDates(0,2,g_date->DayInYear(25,7));
54  m_field->SetMDates(1,2,g_date->DayInYear(1,8));
55  // Check the next crop for early start, unless it is a spring crop
56  // in which case we ASSUME that no checking is necessary!!!!
57  // So DO NOT implement a crop that runs over the year boundary
58  if (m_ev->m_startday>g_date->DayInYear(1,7))
59  {
60  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
61  {
62  g_msg->Warn( WARN_BUG, "OSBarleySilage::Do(): "
63  "Harvest too late for the next crop to start!!!", "" );
64  exit( 1 );
65  }
66  // Now fix any late finishing problems
67  for (int i=0; i<noDates; i++)
68  {
69  if (m_field->GetMDates(0,i)>=m_ev->m_startday)
71  if (m_field->GetMDates(1,i)>=m_ev->m_startday)
73  }
74  }
75  // Now no operations can be timed after the start of the next crop.
76  int d1 = 0;
77  if ( ! m_ev->m_first_year )
78  {
79  int today=g_date->Date();
80  // Are we before July 1st?
81  d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
82  if (today < d1)
83  {
84  // Yes, too early. We assumme this is because the last crop was late
85  g_msg->Warn( WARN_BUG, "OSBarleySilage::Do(): "
86  "Crop start attempt between 1st Jan & 1st July", "" );
87  exit( 1 );
88  }
89  else
90  {
91  d1 = g_date->OldDays() + m_first_date + 365; // Add 365 for spring crop
92  if (today > d1)
93  {
94  // Yes too late - should not happen - raise an error
95  g_msg->Warn( WARN_BUG, "OBarleySilage::Do(): "
96  "Crop start attempt after last possible start date", "" );
97  exit( 1 );
98  }
99  }
100  }
101  // All OK, let's go.
102  SimpleEvent( d1, osbs_ferti_zero, false );
103  }
104  break;
105 
106  case osbs_ferti_zero:
107  if ( m_ev->m_lock || m_farm->DoIt( 20 ))
108  {
109  if (!m_farm->FA_Manure( m_field, 0.0,
110  g_date->DayInYear( 10, 4 ) - g_date->DayInYear()))
111  {
112  SimpleEvent( g_date->Date() + 1, osbs_ferti_zero, true );
113  break;
114  }
115  }
116  SimpleEvent( g_date->Date(),osbs_ferti_one, false );
117  break;
118 
119  case osbs_ferti_one:
120  if ( m_ev->m_lock || m_farm->DoIt( 100 ))
121  {
122  if (!m_farm->FA_Slurry( m_field, 0.0,
123  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
124  SimpleEvent( g_date->Date() + 1, osbs_ferti_one, true );
125  break;
126  }
127  }
128  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 3 ),
129  osbs_spring_plough, false );
130  break;
131 
132  case osbs_spring_plough:
133  if (!m_farm->SpringPlough( m_field, 0.0,
134  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
135  SimpleEvent( g_date->Date() + 1, osbs_spring_plough, true );
136  break;
137  }
139  break;
140 
141  case osbs_spring_harrow:
142  if (!m_farm->SpringHarrow( m_field, 0.0,
143  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
144  SimpleEvent( g_date->Date() + 1, osbs_spring_harrow, true );
145  break;
146  }
147  SimpleEvent( g_date->Date(), osbs_spring_roll, false );
148  break;
149 
150  case osbs_spring_roll:
151  if (!m_farm->SpringRoll( m_field, 0.0,
152  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
153  SimpleEvent( g_date->Date() + 1, osbs_spring_roll, true );
154  break;
155  }
156  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20, 3 ),
157  osbs_spring_sow1, false );
158  break;
159 
160  case osbs_spring_sow1:
161  if (!m_farm->SpringSow( m_field, 0.0,
162  g_date->DayInYear( 12, 4 ) - g_date->DayInYear())) {
163  SimpleEvent( g_date->Date() + 1, osbs_spring_sow1, true );
164  break;
165  }
166  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,3 ),
167  osbs_spring_sow2, false );
168  break;
169 
170  case osbs_spring_sow2:
171  if (!m_farm->SpringSow( m_field, 0.0,
172  g_date->DayInYear( 12, 4 ) - g_date->DayInYear())) {
173  SimpleEvent( g_date->Date() + 1, osbs_spring_sow2, true );
174  break;
175  }
176  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5,6 ),
177  osbs_water1, false );
178  break;
179 
180  case osbs_water1:
181  if ( m_ev->m_lock || m_farm->DoIt( 10 ))
182  {
183  if (!m_farm->Water( m_field, 0.0,
184  g_date->DayInYear( 15,6 ) - g_date->DayInYear())) {
185  SimpleEvent( g_date->Date() + 1, osbs_water1, true );
186  break;
187  }
188  // Must have watered so do it again
189  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 16,6 ),
190  osbs_water2, false );
191  break;
192  }
193  // Must have failed to water so go straight to cut to silage
194  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,7 ),
195  osbs_cut_to_silage, false );
196  break;
197 
198  case osbs_water2:
199  if (!m_farm->Water( m_field, 0.0,
200  g_date->DayInYear( 30,6 ) - g_date->DayInYear())) {
201  SimpleEvent( g_date->Date() + 1, osbs_water2, true );
202  break;
203  }
205  osbs_cut_to_silage, false );
206  break;
207 
208  case osbs_cut_to_silage:
209  if (!m_farm->CutToSilage( m_field, 0.0,
210  m_field->GetMDates(1,2) - g_date->DayInYear())) {
211  SimpleEvent( g_date->Date() + 1, osbs_cut_to_silage, true );
212  break;
213  }
215  done=true;
216  // END OF MAIN THREAD
217  break;
218 
219 
220  default:
221  g_msg->Warn( WARN_BUG, "OSBarleySilage::Do(): "
222  "Unknown event type! ", "" );
223  exit( 1 );
224  }
225 
226  return done;
227 }

References LE::ClearManagementActionSum(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::FA_Manure(), Farm::FA_Slurry(), g_date, g_msg, LE::GetMDates(), 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, Calendar::OldDays(), osbs_cut_to_silage, osbs_ferti_one, osbs_ferti_zero, osbs_spring_harrow, osbs_spring_plough, osbs_spring_roll, osbs_spring_sow1, osbs_spring_sow2, osbs_start, osbs_water1, osbs_water2, LE::SetGrowthPhase(), LE::SetMDates(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringRoll(), Farm::SpringSow(), MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void OSBarleySilage::SetUpFarmCategoryInformation ( )
inline
60  {
61  const int elements = 2 + (osbs_foobar - OSBS_BASE);
63 
64  FarmManagementCategory catlist[elements] =
65  {
66  fmc_Others, // zero element unused but must be here
67  fmc_Others, // osbs_start = 1, // Compulsory, start event must always be 1 (one).
68  fmc_Fertilizer, // osbs_ferti_zero = OSBS_BASE,
69  fmc_Watering, // osbs_water1,
70  fmc_Watering, // osbs_water2,
71  fmc_Fertilizer, // osbs_ferti_one,
72  fmc_Cultivation, // osbs_spring_plough,
73  fmc_Cultivation, // osbs_spring_harrow,
74  fmc_Cultivation, // osbs_spring_roll,
75  fmc_Others, // osbs_spring_sow,
76  fmc_Others, // osbs_spring_sow1,
77  fmc_Others, // osbs_spring_sow2,
78  fmc_Cutting // osbs_cut_to_silage,
79 
80 
81  // no foobar entry
82 
83  };
84  // Iterate over the catlist elements and copy them to vector
85  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
86 
87  }

References fmc_Cultivation, fmc_Cutting, fmc_Fertilizer, fmc_Others, fmc_Watering, Crop::m_base_elements_no, Crop::m_ManagementCategories, OSBS_BASE, and osbs_foobar.

Referenced by OSBarleySilage().


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
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
osbs_ferti_zero
Definition: OSBarleySilage.h:35
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
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
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
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
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
osbs_water1
Definition: OSBarleySilage.h:36
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
osbs_spring_roll
Definition: OSBarleySilage.h:41
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
osbs_spring_plough
Definition: OSBarleySilage.h:39
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
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
osbs_ferti_one
Definition: OSBarleySilage.h:38
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
osbs_spring_sow1
Definition: OSBarleySilage.h:43
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
osbs_cut_to_silage
Definition: OSBarleySilage.h:45
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
LE::SetGrowthPhase
virtual void SetGrowthPhase(int)
Definition: Elements.h:185
OSBarleySilage::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OSBarleySilage.h:60
osbs_water2
Definition: OSBarleySilage.h:37
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
osbs_spring_harrow
Definition: OSBarleySilage.h:40
osbs_spring_sow2
Definition: OSBarleySilage.h:44
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
osbs_foobar
Definition: OSBarleySilage.h:46
osbs_start
Definition: OSBarleySilage.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
OSBS_BASE
#define OSBS_BASE
Definition: OSBarleySilage.h:31
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