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

#include <OSpringBarleyPigs.h>

Inheritance diagram for OSpringBarleyPigs:
Crop

Public Member Functions

 OSpringBarleyPigs (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
void SetUpFarmCategoryInformation ()
 
bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
- 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

◆ OSpringBarleyPigs()

OSpringBarleyPigs::OSpringBarleyPigs ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
58  : Crop(a_tov, a_toc, a_L)
59  {
60  m_first_date = g_date->DayInYear(1, 3);
62  }

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

Member Function Documentation

◆ Do()

bool OSpringBarleyPigs::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 osbp_start:
44  {
45  a_field->ClearManagementActionSum();
46 
47  // Start date checking block.
48  int d1 = g_date->OldDays() + g_date->DayInYear( 10, 4 );
49  if ( ! m_ev->m_first_year ) {
50  if (g_date->Date() > d1) {
51  // No, later. It might be possible to start next spring if
52  // we are called very late in the year.
53  d1 = g_date->OldDays() + g_date->DayInYear( 1, 7 );
54  if (g_date->Date() >= d1) {
55  // We can run next spring!
56  // Calculate starting date.
57  d1 = g_date->OldDays() + g_date->DayInYear( 1, 3 ) + 365;
58  } else {
59  // Not possible to run. Bail out.
60  done = true;
61  break;
62  }
63  }
64  }
65  // End date checking block.
66  SimpleEvent( d1, osbp_spring_plough, false );
67  SimpleEvent( d1, osbp_ferti, false );
68  }
69  break;
70 
71 
72  case osbp_spring_plough:
73  if (!m_farm->SpringPlough( m_field, 0.0,
74  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
75  SimpleEvent( g_date->Date() + 1, osbp_spring_plough, true );
76  break;
77  }
79  break;
80 
81  case osbp_ferti:
82  if (!m_farm->FP_Slurry( m_field, 0.0,
83  g_date->DayInYear( 10, 4 ) - g_date->DayInYear())) {
84  SimpleEvent( g_date->Date() + 1, osbp_ferti, true );
85  break;
86  }
87  // end of thread
88  break;
89 
90  case osbp_spring_harrow:
91  if (!m_farm->SpringHarrow( m_field, 0.0,
92  g_date->DayInYear( 15,4 ) - g_date->DayInYear())) {
93  SimpleEvent( g_date->Date() + 1, osbp_spring_harrow, true );
94  break;
95  }
96  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,3 ),
97  osbp_spring_sow1, false );
98  break;
99 
100  case osbp_spring_sow1:
101  if (!m_farm->SpringSow( m_field, 0.0,
102  g_date->DayInYear( 15,4 ) - g_date->DayInYear())) {
103  SimpleEvent( g_date->Date() + 1, osbp_spring_sow1, true );
104  break;
105  }
107  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 16,3 ),
108  osbp_spring_roll, false );
109  break;
110 
111  case osbp_spring_roll:
112  if ( m_ev->m_lock || m_farm->DoIt( 90 ))
113  {
114  if (!m_farm->SpringRoll( m_field, 0.0,
115  g_date->DayInYear( 25,4 ) - g_date->DayInYear())) {
116  SimpleEvent( g_date->Date() + 1, osbp_spring_roll, true );
117  break;
118  }
119  }
120  if (OSBP_SOW_DATE+5 >g_date->DayInYear( 20,3 ))
122  osbp_strigling1, false );
123  else
124  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,3 ),
125  osbp_strigling1, false );
126  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,3 ),
127  osbp_strigling_sow, false );
128  break;
129 
130  case osbp_strigling1:
131  if ( m_ev->m_lock || (cfg_strigling_prop.value() * m_farm->DoIt( 90 )))
132  {
133  if (!m_farm->Strigling( m_field, 0.0,
134  g_date->DayInYear( 20,4 ) - g_date->DayInYear())) {
135  SimpleEvent( g_date->Date() + 1, osbp_strigling1, true );
136  break;
137  }
139  // End of thread
140  }
141  break;
142 
143  case osbp_strigling_sow:
144  if ( m_ev->m_lock || m_farm->DoIt( 60 ))
145  {
146  if (!m_farm->StriglingSow( m_field, 0.0,
147  g_date->DayInYear( 30,4 ) - g_date->DayInYear())) {
148  SimpleEvent( g_date->Date() + 1, osbp_strigling_sow, true );
149  break;
150  }
151  else
152  {
153  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,8 ),
154  osbp_harvest, false );
155  break;
156  }
157  }
158  {
159  long newdate1 = g_date->OldDays() + g_date->DayInYear( 25,3 );
160  long newdate2 = OSBP_STRIGLING_DATE + 5;
161  if ( newdate2 > newdate1 )
162  newdate1 = newdate2;
163  SimpleEvent( newdate1, osbp_strigling2, false );
164  }
165  // End of thread
166  break;
167 
168  case osbp_strigling2:
169  if (!m_farm->Strigling( m_field, 0.0,
170  g_date->DayInYear( 5,5 ) - g_date->DayInYear())) {
171  SimpleEvent( g_date->Date() + 1, osbp_strigling2, true );
172  break;
173  }
174  {
175  long newdate1 = g_date->OldDays() + g_date->DayInYear( 30,3 );
176  long newdate2 = g_date->Date() + 5;
177  if ( newdate2 > newdate1 )
178  newdate1 = newdate2;
179  SimpleEvent( newdate1, osbp_strigling3, false );
180  }
181  break;
182 
183  case osbp_strigling3:
184  if ( m_ev->m_lock || (cfg_strigling_prop.value() * m_farm->DoIt( 89 )))
185  {
186  if (!m_farm->Strigling( m_field, 0.0,
187  g_date->DayInYear( 15,5 ) - g_date->DayInYear())) {
188  SimpleEvent( g_date->Date() + 1, osbp_strigling3, true );
189  break;
190  }
191  }
192  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,8 ),
193  osbp_harvest, false );
194  break;
195 
196  case osbp_harvest:
197  if (!m_farm->Harvest( m_field, 0.0,
198  g_date->DayInYear( 15,8 ) - g_date->DayInYear())) {
199  SimpleEvent( g_date->Date() + 1, osbp_harvest, true );
200  break;
201  }
203  break;
204 
205  case osbp_straw_chopping:
206  if ( m_ev->m_lock || m_farm->DoIt( 20 ))
207  {
208  if (!m_farm->StrawChopping( m_field, 0.0,
209  g_date->DayInYear( 15,8 ) - g_date->DayInYear())) {
210  SimpleEvent( g_date->Date() + 1, osbp_straw_chopping, true );
211  break;
212  }
213  // END MAIN THREAD
214  done=true;
215  break;
216  }
217  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5,8 ),
218  osbp_hay, false );
219  break;
220 
221  case osbp_hay:
222  if (!m_farm->HayBailing( m_field, 0.0,
223  g_date->DayInYear( 20,8 ) - g_date->DayInYear())) {
224  SimpleEvent( g_date->Date() + 1, osbp_hay, true );
225  break;
226  }
227  // END MAIN THREAD
228  done=true;
229  break;
230 
231  default:
232  g_msg->Warn( WARN_BUG, "OSpringBarleyPigs::Do(): "
233  "Unknown event type! ", "" );
234  exit( 1 );
235  }
236 
237  return done;
238 }

References cfg_strigling_prop, LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::FP_Slurry(), g_date, g_msg, Farm::Harvest(), Farm::HayBailing(), Crop::m_ev, Crop::m_farm, Crop::m_field, FarmEvent::m_first_year, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), osbp_ferti, osbp_harvest, osbp_hay, OSBP_SOW_DATE, osbp_spring_harrow, osbp_spring_plough, osbp_spring_roll, osbp_spring_sow1, osbp_start, osbp_straw_chopping, osbp_strigling1, osbp_strigling2, osbp_strigling3, OSBP_STRIGLING_DATE, osbp_strigling_sow, Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringRoll(), Farm::SpringSow(), Farm::StrawChopping(), Farm::Strigling(), Farm::StriglingSow(), CfgFloat::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void OSpringBarleyPigs::SetUpFarmCategoryInformation ( )
inline
63  {
64  const int elements = 2 + (osbp_foobar - OSBarleyPigs_BASE);
66 
67  FarmManagementCategory catlist[elements] =
68  {
69  fmc_Others, // zero element unused but must be here
70  fmc_Others, // osbp_start = 1, // Compulsory, start event must always be 1 (one).
71  fmc_Fertilizer, // osbp_ferti = OSBarleyPigs_BASE,
72  fmc_Harvest, // osbp_harvest,
73  fmc_Cultivation, // osbp_spring_plough,
74  fmc_Cultivation, // osbp_autumn_plough,
75  fmc_Cultivation, // osbp_spring_harrow,
76  fmc_Cultivation, // osbp_spring_roll,
77  fmc_Others, // osbp_spring_sow1,
78  fmc_Cultivation, // osbp_strigling_sow,
79  fmc_Others, // osbp_hay,
80  fmc_Cultivation, // osbp_strigling1,
81  fmc_Cultivation, // osbp_strigling2,
82  fmc_Cultivation, // osbp_strigling3,
83  fmc_Others // osbp_straw_chopping,
84 
85 
86  // no foobar entry
87 
88  };
89  // Iterate over the catlist elements and copy them to vector
90  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
91 
92  }

References fmc_Cultivation, fmc_Fertilizer, fmc_Harvest, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, OSBarleyPigs_BASE, and osbp_foobar.

Referenced by OSpringBarleyPigs().


The documentation for this class was generated from the following files:
osbp_harvest
Definition: OSpringBarleyPigs.h:38
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
osbp_ferti
Definition: OSpringBarleyPigs.h:37
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
osbp_spring_sow1
Definition: OSpringBarleyPigs.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
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
cfg_strigling_prop
CfgFloat cfg_strigling_prop
osbp_hay
Definition: OSpringBarleyPigs.h:45
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
osbp_straw_chopping
Definition: OSpringBarleyPigs.h:49
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
CfgFloat::value
double value() const
Definition: Configurator.h:142
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
osbp_spring_roll
Definition: OSpringBarleyPigs.h:42
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
osbp_spring_harrow
Definition: OSpringBarleyPigs.h:41
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
osbp_start
Definition: OSpringBarleyPigs.h:36
osbp_strigling3
Definition: OSpringBarleyPigs.h:48
OSBP_SOW_DATE
#define OSBP_SOW_DATE
Definition: OSpringBarleyPigs.h:32
osbp_foobar
Definition: OSpringBarleyPigs.h:50
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
osbp_strigling_sow
Definition: OSpringBarleyPigs.h:44
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
OSpringBarleyPigs::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OSpringBarleyPigs.h:63
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
OSBarleyPigs_BASE
#define OSBarleyPigs_BASE
Definition: OSpringBarleyPigs.h:31
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
osbp_spring_plough
Definition: OSpringBarleyPigs.h:39
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::FP_Slurry
virtual bool FP_Slurry(LE *a_field, double a_user, int a_days)
Apply slurry to a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:823
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
osbp_strigling1
Definition: OSpringBarleyPigs.h:46
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
osbp_strigling2
Definition: OSpringBarleyPigs.h:47
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
OSBP_STRIGLING_DATE
#define OSBP_STRIGLING_DATE
Definition: OSpringBarleyPigs.h:33
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
Farm::StriglingSow
virtual bool StriglingSow(LE *a_field, double a_user, int a_days, double a_seed_coating_amount=-1, PlantProtectionProducts a_ppp=ppp_foobar)
Carry out a mechanical weeding followed by sowing on a_field.
Definition: FarmFuncs.cpp:1226
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