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

#include <YoungForest.h>

Inheritance diagram for YoungForestCrop:
Crop

Public Member Functions

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

◆ YoungForestCrop()

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

33 {
34  m_farm = a_farm;
35  m_field = a_field;
36  m_ev = a_ev;
37  bool done = false;
38  int d1;
39 
40  switch ( m_ev->m_todo ) {
41  case yf_start:
42  {
43  a_field->ClearManagementActionSum();
44 
45  // Set up the date management stuff
47  // Start and stop dates for all events after harvest
48  int noDates= 1;
49  m_field->SetMDates(0,0,g_date->DayInYear(1,9));
50  // Determined by harvest date - used to see if at all possible
51  m_field->SetMDates(1,0,g_date->DayInYear(1,9));
52  // Check the next crop for early start, unless it is a spring crop
53  // in which case we ASSUME that no checking is necessary!!!!F
54  // So DO NOT implement a crop that runs over the year boundary
55 
56  //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)
58 
59  if (m_ev->m_startday>g_date->DayInYear(1,7))
60  {
61  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
62  {
63  g_msg->Warn( WARN_BUG, "YoungForestCrop::Do(): "
64  "Harvest too late for the next crop to start!!!", "" );
65  exit( 1 );
66  }
67  // Now fix any late finishing problems
68  for (int i=0; i<noDates; i++) {
69  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
70  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
71  }
72  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
73  m_field->SetMConstants(i,0);
74  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
75  }
76  }
77  }
78  // Now no operations can be timed after the start of the next crop.
79 
80  int today=g_date->Date();
81  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
82  if (today > d1)
83  {
84  // Yes too late - should not happen - raise an error
85  g_msg->Warn( WARN_BUG, " YoungForestCrop::Do(): "
86  "Crop start attempt after last possible start date", "" );
87  exit( 1 );
88  }
89  }//if
90 
91  // Reinit d1 to first possible starting date.
92  d1 = g_date->OldDays()+m_first_date;;
93  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
94  if ( g_date->Date() > d1 )
95  {
96  d1 = g_date->Date();
97  }
98  // OK, let's go.
99  SimpleEvent( d1, yf_do_nothing_start, false );
100  }
101  break;
102 
103  case yf_do_nothing_start:
104  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 9 ),
105  yf_do_nothing_stop, false );
106  break;
107 
108  case yf_do_nothing_stop:
109 
110  ChooseNextCrop (1);
111 
112  done = true;
113  break;
114 
115  default:
116  g_msg->Warn( WARN_BUG, "YoungForestCrop::Do(): "
117  "Unknown event type! ", "" );
118  exit( 1 );
119  }
120 
121  return done;
122 }

References Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), g_date, g_msg, LE::GetMDates(), Farm::GetType(), Calendar::GetYearNumber(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_first_date, FarmEvent::m_first_year, Crop::m_last_date, FarmEvent::m_startday, FarmEvent::m_todo, Calendar::OldDays(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), tof_OptimisingFarm, MapErrorMsg::Warn(), WARN_BUG, yf_do_nothing_start, yf_do_nothing_stop, and yf_start.

◆ SetUpFarmCategoryInformation()

void YoungForestCrop::SetUpFarmCategoryInformation ( )
inline
60  {
61  const int elements = 2 + (yf_foobar - YOUNGFOREST_BASE);
63 
64  FarmManagementCategory catlist[elements] =
65  {
66  fmc_Others, // zero element unused but must be here
67  fmc_Others, // yf_start = 1, // Compulsory, start event must always be 1 (one).
68  fmc_Others, // yf_do_nothing_start = YOUNGFOREST_BASE,
69  fmc_Others // yf_do_nothing_stop,
70  // No foobar entry
71  };
72  // Iterate over the catlist elements and copy them to vector
73  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
74  }

References fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, yf_foobar, and YOUNGFOREST_BASE.

Referenced by YoungForestCrop().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
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
yf_do_nothing_stop
Definition: YoungForest.h:45
Farm::GetType
TTypesOfFarm GetType(void)
Definition: Farm.h:956
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
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
YoungForestCrop::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: YoungForest.h:60
Calendar::Date
long Date(void)
Definition: Calendar.h:57
yf_start
Definition: YoungForest.h:43
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
yf_do_nothing_start
Definition: YoungForest.h:44
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
yf_foobar
Definition: YoungForest.h:46
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
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
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
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
YOUNGFOREST_BASE
#define YOUNGFOREST_BASE
Definition: YoungForest.h:40
LE::SetMConstants
void SetMConstants(int a, int c)
Definition: Elements.h:408
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: Farm.cpp:756
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001