ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
OGrazingPigs Class Reference

#include <OGrazingPigs.h>

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 OGrazingPigs ()
 
- Public Member Functions inherited from Crop
void ChooseNextCrop (int a_no_dates)
 Chooses the next crop to grow in a field. More...
 
 Crop ()
 
int GetCropClassification ()
 
int GetFirstDate (void)
 
void SetCropClassification (int a_classification)
 
virtual ~Crop ()
 

Additional Inherited Members

- 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...
 
- Protected Attributes inherited from Crop
int m_count
 
int m_CropClassification
 
int m_ddegstoharvest
 
FarmEventm_ev
 
Farmm_farm
 
LE * m_field
 
int m_first_date
 
int m_last_date
 

Detailed Description

Definition at line 44 of file OGrazingPigs.h.

Constructor & Destructor Documentation

◆ OGrazingPigs()

OGrazingPigs::OGrazingPigs ( )
inline

Definition at line 48 of file OGrazingPigs.h.

48  {
49  m_first_date=g_date->DayInYear(1,11);
50  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

Definition at line 31 of file OGrazingPigs.cpp.

32 {
33  m_farm = a_farm;
34  m_field = a_field;
35  m_ev = a_ev;
36 
37  bool done = false;
38 
39  switch ( m_ev->m_todo )
40  {
41  case ogp_start:
42  {
43  // Set up the date management stuff
44  m_last_date=g_date->DayInYear(2,11);
45  m_field->SetMDates(0,0,g_date->DayInYear(2,11));
46  m_field->SetMDates(1,0,g_date->DayInYear(2,11));
47 
48  // This is a nasty one because it runs one year from when it starts, less one
49  // month
50  // So if the next crop is an autumn one - then it will push the year on one
51  // We cannot allow this - the rotation will be out of sync. So only spring crops
52  // can follow this
53  if ((m_ev->m_startday>g_date->DayInYear(1, 7)) && m_ev->m_startday<g_date->DayInYear(1, 11)) // This allows pigs to follow pigs
54  {
55  g_msg->Warn( WARN_BUG, "GrazingPigs::Do(): "
56  "Autumn Crop Following Grazing Pigs is not allowed!!!", "" );
57  exit( 1 );
58  }
59  if ( ! m_ev->m_first_year )
60  {
61  int today=g_date->Date();
62  // Are we before July 1st?
63  int d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
64  if (today < d1)
65  {
66  // Yes, too early. We assumme this is because the last crop was late
67  g_msg->Warn( WARN_BUG, "GrazingPigs::Do(): "
68  "Crop start attempt between 1st Jan & 1st July", "" );
69  exit( 1 );
70  }
71  else
72  {
73  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
74  if (today > d1)
75  {
76  // Yes too late - should not happen - raise an error
77  g_msg->Warn( WARN_BUG, "GrazingPigs::Do(): "
78  "Crop start attempt after last possible start date", "" );
79  exit( 1 );
80  }
81  }
82  }
83  // OK so if we reach here it is after 1/7 and before 1,11
84 
85  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
86 
87  int d1=g_date->OldDays() + m_first_date;
88  PGP_FIRST_PIGS_IN_DATE=d1+334; // 31 days less than one year
89  PGP_LAST_PIGS_IN_DATE=d1+355; // just less than one year later (So not near the max before 1,11)
90  SimpleEvent( d1, ogp_pigs_out, false );
91  break;
92  }
93  case ogp_pigs_out:
94  {
95  if (!m_farm->PigsOut( m_field, 0.0,
96  PGP_LAST_PIGS_IN_DATE - g_date->Date())) {
97  SimpleEvent( g_date->Date() + 1, ogp_pigs_out, true );
98  break;
99  }
100  SimpleEvent( g_date->Date() + 1, ogp_pigs_are_out_forced, false );
101  break;
102 
104  // Keep the pigs out there
105  m_farm->PigsAreOutForced( m_field, 0.0, 0 );
106  // PGP_FIRST_PIGS_IN_DATE specifies the first day the pigs may come home.
107  // However this event type forces them to stay out. Thus we want to
108  // abandon this chain of events one day before PGP_FIRST_PIGS_IN_DATE.
109  if ( g_date->Date() < PGP_FIRST_PIGS_IN_DATE - 1 )
110  {
111  SimpleEvent( g_date->Date() + 1, ogp_pigs_are_out_forced, false );
112  break;
113  }
114  SimpleEvent( g_date->Date() + 1, ogp_pigs_are_out, false );
115  }
116  break;
117 
118  case ogp_pigs_are_out:
119  // Start testing for taking the pigs home.
120  // PigsAreOut() returns false if it is not time to stop grazing
121  if (!m_farm->PigsAreOut( m_field, 0.0,
122  PGP_LAST_PIGS_IN_DATE - g_date->Date())) {
123  // --FN--
124  SimpleEvent( g_date->Date() + 1, ogp_pigs_are_out, true );
125  break;
126  }
127  done=true;
128  break;
129 
130  default:
131  g_msg->Warn( WARN_BUG, "OGrazingPigs::Do(): "
132  "Unknown event type! ", "" );
133  exit( 1 );
134  }
135 
136  return done;
137 }

References 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, ogp_pigs_are_out, ogp_pigs_are_out_forced, ogp_pigs_out, ogp_start, PGP_FIRST_PIGS_IN_DATE, PGP_LAST_PIGS_IN_DATE, Farm::PigsAreOut(), Farm::PigsAreOutForced(), Farm::PigsOut(), and Crop::SimpleEvent().


The documentation for this class was generated from the following files:
Farm::PigsAreOut
virtual bool PigsAreOut(LE *a_field, double a_user, int a_days)
Start a pig grazing event on a_field today or soon.
Definition: farmfuncs.cpp:2112
Farm::PigsAreOutForced
virtual bool PigsAreOutForced(LE *a_field, double a_user, int a_days)
Start a pig grazing event on a_field today - no exceptions.
Definition: farmfuncs.cpp:2090
ogp_pigs_are_out_forced
Definition: OGrazingPigs.h:39
ogp_start
Definition: OGrazingPigs.h:36
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
ogp_pigs_are_out
Definition: OGrazingPigs.h:38
ogp_pigs_out
Definition: OGrazingPigs.h:37
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
Crop::m_field
LE * m_field
Definition: farm.h:538
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
Crop::m_last_date
int m_last_date
Definition: farm.h:542
PGP_FIRST_PIGS_IN_DATE
#define PGP_FIRST_PIGS_IN_DATE
Definition: OGrazingPigs.h:32
PGP_LAST_PIGS_IN_DATE
#define PGP_LAST_PIGS_IN_DATE
Definition: OGrazingPigs.h:33
Farm::PigsOut
virtual bool PigsOut(LE *a_field, double a_user, int a_days)
Generate a 'pigs_out' event for every day the cattle are on a_field.
Definition: farmfuncs.cpp:2062
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539