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

#include <DKOBroadBeans_test.h>

Inheritance diagram for DKOBroadBeans_test:
Crop

Public Member Functions

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

◆ DKOBroadBeans_test()

DKOBroadBeans_test::DKOBroadBeans_test ( )
inline
77  {
78  m_first_date = g_date->DayInYear( 25,2 ),
79  }

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

Member Function Documentation

◆ Do()

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

!What does this line mean!!

! How do I add broad sow?!!

! How do I add row sow?!!

! How do I write so they do it twice!!

Reimplemented from Crop.

51  {
52  m_farm = a_farm;
53  m_field = a_field;
54  m_ev = a_ev;
55 
56  bool done = false;
57  int d1 = 0;
58  int d2 = 0;
59 
60  switch (m_ev->m_todo) {
61  case dkobbtest_start:
62  m_field->SetVegPatchy(true); // A crop with wide rows, so set patchy
63 
64  // Set up the date management stuff
65  // Could save the start day in case it is needed later
66  // m_field->m_startday = m_ev->m_startday;
67  m_last_date = g_date->DayInYear(10, 10);
68  // Start and stop dates for all events after harvest
69  m_field->SetMDates(0, 0, g_date->DayInYear(1, 9));
70 
71  // Broad beans does not fit into the normal crop management, so must precede a spring sown crop (SpringBarleySpr probably!)
72 
73  //new if: do the check only for non-optimising farms and if year>0. (030713 - m_rotation used only in the hidden year, so I modified the condition from >7 to >0)
74  if (!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
75 
76  if ((m_ev->m_startday > g_date->DayInYear(1, 7)) // this means spring start crop is OK !!Does this have to be the same as the start day i line 69?!!
77  || (m_field->GetMDates(0, 0) >= m_ev->m_startday)) { // This checks that the spring start is not too early
78  char veg_type[20];
79  sprintf(veg_type, "%d", m_ev->m_next_tov);
80  g_msg->Warn(WARN_FILE, "DKOBroadBeans_test::Do(): Harvest too late for the next crop to start!!! The next crop is: ", veg_type);
81  exit(1);
82  }
83  // Not allowed to fix any late finishing problems!
84  /*
85  for (int i = 0; i < noDates; i++) {
86  if (m_field->GetMDates( 0, i ) >= m_ev->m_startday) {
87  m_field->SetMDates( 0, i, m_ev->m_startday - 1 ); //move the starting date
88  }
89  if (m_field->GetMDates( 1, i ) >= m_ev->m_startday) {
90  m_field->SetMConstants( i, 0 );
91  m_field->SetMDates( 1, i, m_ev->m_startday - 1 ); //move the finishing date
92  }
93  }
94  */
95 
96  if (!m_ev->m_first_year) {
97  // Here we need to allow a start before 1/7 in case we run over the year - the only crop to do this (2802215)
98  d1 = g_date->OldDays() + m_first_date + 365; // Add 365 for spring crop
99  if (g_date->Date() > d1) {
100  // Yes too late - should not happen - raise an error
101  g_msg->Warn(WARN_BUG, "DKOBroadBeans_test::Do(): Crop start attempt after last possible start date", "");
102  exit(1);
103  }
104  }
105  else {
106  // If this is the first year of running then it is possible to start
107  // on day 0, so need this to tell us what to do:
109  dkobbtest_spring_harrow, false);
110  break;
111  }
112  }//if
113  // End single block date checking code. Please see next line
114  // comment as well.
115  // Reinit d1 to first possible starting date.
116  d1 = g_date->OldDays() + g_date->DayInYear(25, 2); // The first date an event (management action) can take place
117  if (g_date->Date() > d1) {
118  d1 = g_date->Date();
119  }
120  // OK, let's go.
122  break;
123 
125  if (m_ev->m_lock || m_farm->DoIt(100)) { // 100% of the farmers do this action !!does this DoIt have to be here in the first case!!
126  if (!m_farm->SpringHarrow(m_field, 0.0,
127  g_date->DayInYear(25, 3) - // !!Should this be the last day the event should take place!!
128  g_date->DayInYear())) {
129  // If we don't suceed on the first try, then try and try again (until 25/3 when we will suceed)
131  break;
132  }
133  }
134  d1 = g_date->Date() + 1; // !!Does this section set up the next even?!!
135  d2 = g_date->OldDays() + g_date->DayInYear(1, 3); //If date 1 (d1) is less or equal to day 2 (d2) then the next event (spring plogh) can't take place (false)
136  if (d1 < d2) d1 = d2;
138  break;
139 
141  if (!m_farm->SpringPlough(m_field, 0.0, g_date->DayInYear(1, 4) - g_date->DayInYear())) {
143  break; // If we don't suceed on the first try, then try and try again (until 1/4 when we will suceed)
144  }
145  d1 = g_date->Date();
146  d2 = g_date->OldDays() + g_date->DayInYear(5, 3);
147  if (d1 < d2) d1 = d2;
148  SimpleEvent(d1, dkobbtest_ferti_k_s, false);
149  break;
150 
151  case dkobbtest_ferti_k_s:
152  if (!m_farm->SpringFertiKS(m_field, 0.0, g_date->DayInYear(5, 4) - g_date->DayInYear()))
153  { // !!The SpringFertiKS is not valid, How do I make it valid?!!
155  break;
156  }
157  if (a_farm->DoIt(50)) SimpleEvent(g_date->Date(), dkobbtest_broad_sow, false);
158  else SimpleEvent(g_date->Date(), dkobbtest_row_sow, false);
159  break;
160 
161  case dkobbtest_broad_sow:
162  if (!m_farm->BroadSow(m_field, 0.0, g_date->DayInYear(1, 5) - g_date->DayInYear())) {
164  break;
165  }
167  break;
168 
169  case dkobbtest_row_sow:
170  if (!m_farm->RowSow(m_field, 0.0, g_date->DayInYear(1, 5) - g_date->DayInYear())) {
172  break;
173  }
175  break;
176 
178  if (m_ev->m_lock || (cfg_strigling_prop.value() * m_farm->DoIt(100))) {
179  if (!m_farm->Strigling(m_field, 0.0, g_date->DayInYear(5, 5) - g_date->DayInYear())) {
181  break;
182  }
183  }
185  break;
186 
188  // 50% of the farmers will stringlig2, which is stirling one time
189  if (a_ev->m_lock || a_farm->DoIt(100))
190  if (!m_farm->Strigling(m_field, 0.0, g_date->DayInYear(1, 5) - g_date->DayInYear())) {
192  break;
193  }
195  break;
196 
198  // 50% of the farmers will go this, this is strigling 1-2 times
199  if (a_ev->m_lock || a_farm->DoIt(50))
200  if (!m_farm->Strigling(m_field, 0.0, g_date->DayInYear(1, 5) - g_date->DayInYear())) {
202  break;
203  }
205  break;
206 
207  case dkobbtest_watering:
208  // The farmers will water as many times as needed !! is there a way to have them water "when needed"!!
209  if (a_ev->m_lock || a_farm->DoIt(100))
210  {
211  if (!m_farm->Water(m_field, 0.0, g_date->DayInYear(25, 9) - g_date->DayInYear()))
212  {
213  break;
214  }
215  }
217  break;
218 
219 
220  case dkobbtest_harvest:
221  if (!m_farm->Harvest(m_field, 0.0, g_date->DayInYear(1, 10) - g_date->DayInYear())) {
222  // If we don't suceed on the first try, then try and try again (until 1/10 when we will suceed)
223  SimpleEvent(g_date->Date() + 1, dkobbtest_harvest, true);
224  break;
225  }
226  d1 = g_date->Date();
227  d2 = g_date->OldDays() + g_date->DayInYear(1, 9);
228  if (d1 < d2) d1 = d2;
230  break;
231 
233  if (!m_farm->AutumnHarrow(m_field, 0.0, g_date->DayInYear(5, 10) - g_date->DayInYear())) {
235  break;
236  }
238  break;
239 
241  if (!m_farm->AutumnPlough(m_field, 0.0, g_date->DayInYear(10, 10) - g_date->DayInYear())) {
243  break;
244  }
246  break;
247 
249  // 33.3% of the farmers will sow catch crop
250  if (a_ev->m_lock || a_farm->DoIt(33))
251  if (!m_farm->SowCatchCrop(m_field, 0.0, g_date->DayInYear(15, 10) - g_date->DayInYear())) {
253  break;
254  }
255  else
256  {
257  //Too remember who sowed ctach crop !!I don't know if this is correct!!
258  DKOBBTEST_SOW_CATCHCROP = true;
259  }
261  break;
263  // 66.6% of the farmers will sow winter crop
264  if (a_ev->m_lock || a_farm->DoIt(66))
265  if (!m_farm->SowWinterCrop(m_field, 0.0, g_date->DayInYear(15, 10) - g_date->DayInYear())) {
267  break;
268  }
269  else
270  {
271  //Too remember who sowed wintercrop !!I don't know if this is correct!!
272  DKOBBTEST_SOW_WINTERCROP = true;
273  }
275  break;
276 
277  case dkobbtest_wait:
278  // End Main Thread
279  m_field->SetVegPatchy(false); // reverse the patchy before the next crop
280  done = true;
281  break;
282 
283 
284  default:
285  g_msg->Warn(WARN_BUG, "DKOBroadBeans::Do(): " "Unknown event type! ", "");
286  exit(1);
287  }
288 
289  return done;
290 }

References Farm::AutumnHarrow(), Farm::AutumnPlough(), cfg_strigling_prop, Calendar::Date(), Calendar::DayInYear(), dkobbtest_autumn_harrow, dkobbtest_autumn_plough, dkobbtest_broad_sow, dkobbtest_ferti_k_s, dkobbtest_harvest, dkobbtest_row_sow, dkobbtest_sow_catchcrop, dkobbtest_sow_wintercrop, dkobbtest_spring_harrow, dkobbtest_spring_plough, dkobbtest_start, dkobbtest_strigling1, dkobbtest_strigling2, dkobbtest_strigling3, dkobbtest_wait, dkobbtest_watering, Farm::DoIt(), g_date, g_msg, LE::GetMDates(), Farm::GetType(), Calendar::GetYearNumber(), 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_next_tov, FarmEvent::m_startday, FarmEvent::m_todo, Calendar::OldDays(), LE::SetMDates(), LE::SetVegPatchy(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::Strigling(), tof_OptimisingFarm, CfgFloat::value(), MapErrorMsg::Warn(), WARN_BUG, WARN_FILE, and Farm::Water().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
dkobbtest_harvest
Definition: DKOBroadBeans_test.h:64
WARN_FILE
Definition: MapErrorMsg.h:37
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
dkobbtest_broad_sow
Definition: DKOBroadBeans_test.h:58
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
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
Calendar::GetYearNumber
int GetYearNumber(void)
Definition: Calendar.h:72
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
dkobbtest_watering
Definition: DKOBroadBeans_test.h:63
dkobbtest_autumn_harrow
Definition: DKOBroadBeans_test.h:65
dkobbtest_start
Definition: DKOBroadBeans_test.h:52
CfgFloat::value
double value() const
Definition: Configurator.h:142
Farm::GetType
TTypesOfFarm GetType(void)
Definition: Farm.h:956
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
dkobbtest_sow_catchcrop
Definition: DKOBroadBeans_test.h:67
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
dkobbtest_row_sow
Definition: DKOBroadBeans_test.h:59
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
dkobbtest_strigling3
Definition: DKOBroadBeans_test.h:62
dkobbtest_spring_harrow
Definition: DKOBroadBeans_test.h:54
dkobbtest_autumn_plough
Definition: DKOBroadBeans_test.h:66
cfg_strigling_prop
CfgFloat cfg_strigling_prop
dkobbtest_spring_plough
Definition: DKOBroadBeans_test.h:55
Calendar::Date
long Date(void)
Definition: Calendar.h:57
dkobbtest_ferti_k_s
Definition: DKOBroadBeans_test.h:56
LE::SetVegPatchy
void SetVegPatchy(bool p)
Definition: Elements.h:229
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
dkobbtest_wait
Definition: DKOBroadBeans_test.h:69
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: Farm.h:390
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
dkobbtest_strigling2
Definition: DKOBroadBeans_test.h:61
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
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
dkobbtest_sow_wintercrop
Definition: DKOBroadBeans_test.h:68
Farm::AutumnPlough
virtual bool AutumnPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the autumn on a_field.
Definition: FarmFuncs.cpp:212
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
Farm::AutumnHarrow
virtual bool AutumnHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the autumn on a_field.
Definition: FarmFuncs.cpp:285
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
dkobbtest_strigling1
Definition: DKOBroadBeans_test.h:60
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
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