ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
OFieldPeasSilage.cpp
Go to the documentation of this file.
1 //
2 // OFieldPeasSilage.cpp
3 //
4 /*
5 *******************************************************************************************************
6 Copyright (c) 2011, Christopher John Topping, University of Aarhus
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without modification, are permitted provided
10 that the following conditions are met:
11 
12 Redistributions of source code must retain the above copyright notice, this list of conditions and the
13 following disclaimer.
14 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
15 the following disclaimer in the documentation and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
20 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ********************************************************************************************************
26 */
27 
28 #include "../../Landscape/ls.h"
29 #include "../../Landscape/cropprogs/OFieldPeasSilage.h"
30 
31 extern CfgFloat cfg_strigling_prop;
32 
33 bool OFieldPeasSilage::Do( Farm *a_farm, LE *a_field, FarmEvent *a_ev )
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 ofps_start:
44  {
45  // Set up the date management stuff
46  m_last_date=g_date->DayInYear(25,8);
47  // Start and stop dates for all events after harvest
48  int noDates= 1;
49  m_field->SetMDates(0,0,g_date->DayInYear(25,7));
50  // Determined by harvest date - used to see if at all possible
51  m_field->SetMDates(1,0,g_date->DayInYear(20,8));
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!!!!
54  // So DO NOT implement a crop that runs over the year boundary
55  if (m_ev->m_startday>g_date->DayInYear(1,7))
56  {
57  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
58  {
59  g_msg->Warn( WARN_BUG, "OFieldPeasSilage::Do(): "
60  "Harvest too late for the next crop to start!!!", "" );
61  exit( 1 );
62  }
63  // Now fix any late finishing problems
64  for (int i=0; i<noDates; i++)
65  {
66  if (m_field->GetMDates(0,i)>=m_ev->m_startday)
67  m_field->SetMDates(0,i,m_ev->m_startday-1);
68  if (m_field->GetMDates(1,i)>=m_ev->m_startday)
69  m_field->SetMDates(1,i,m_ev->m_startday-1);
70  }
71  }
72  // Now no operations can be timed after the start of the next crop.
73 
74  int d1;
75  int today=g_date->Date();
76  d1 = g_date->OldDays() + m_first_date +365; // Add 365 for spring crop
77  if (today > d1)
78  {
79  // Yes too late - should not happen - raise an error
80  g_msg->Warn( WARN_BUG, "OFieldPeasSilage::Do(): "
81  "Crop start attempt after last possible start date", "" );
82  exit( 1 );
83  }
84  // End single block date checking code. Please see next line
85  // comment as well.
86  // Reinit d1 to first possible starting date.
87  d1 = g_date->OldDays()+m_first_date;;
88  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
89  if ( g_date->Date() > d1 ) {
90  d1 = g_date->Date();
91  }
92  // OK, let's go.
93  SimpleEvent( d1, ofps_spring_plough, false );
94  }
95  break;
96 
97  case ofps_spring_plough:
98  if (!m_farm->SpringPlough( m_field, 0.0,
99  g_date->DayInYear( 30,3 ) - g_date->DayInYear())) {
100  SimpleEvent( g_date->Date() + 1, ofps_spring_plough, true );
101  break;
102  }
103  SimpleEvent( g_date->Date()+1, ofps_spring_harrow, false );
104  break;
105 
106  case ofps_spring_harrow:
107  if (!m_farm->SpringHarrow( m_field, 0.0,
108  g_date->DayInYear( 5,4 ) - g_date->DayInYear())) {
109  SimpleEvent( g_date->Date() + 1, ofps_spring_harrow, true );
110  break;
111  }
112  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ),
113  ofps_spring_sow, false );
114  break;
115 
116  case ofps_spring_sow:
117  if (!m_farm->SpringSow( m_field, 0.0,
118  g_date->DayInYear( 15,4 ) - g_date->DayInYear())) {
119  SimpleEvent( g_date->Date() + 1, ofps_spring_sow, true );
120  break;
121  }
122  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,4 ),
123  ofps_spring_roll, false );
124  // --FN--
125  break;
126 
127  case ofps_spring_roll:
128  if (!m_farm->SpringRoll( m_field, 0.0,
129  g_date->DayInYear( 20,4 ) - g_date->DayInYear())) {
130  SimpleEvent( g_date->Date() + 1, ofps_spring_roll, true );
131  break;
132  }
133  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20,4 ),
134  ofps_strigling1, false );
135  break;
136 
137  case ofps_strigling1:
138  if (!m_farm->Strigling( m_field, 0.0,
139  g_date->DayInYear( 30,4 ) - g_date->DayInYear())) {
140  SimpleEvent( g_date->Date() + 1, ofps_strigling1, true );
141  break;
142  }
143  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1,5 ),
144  ofps_strigling2, false );
145  break;
146 
147  case ofps_strigling2:
148  if (!m_farm->Strigling( m_field, 0.0,
149  g_date->DayInYear( 10,5 ) - g_date->DayInYear())) {
150  SimpleEvent( g_date->Date() + 1, ofps_strigling2, true );
151  break;
152  }
153  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 11,5 ),
154  ofps_strigling3, false );
155  break;
156 
157  case ofps_strigling3:
158  if (!m_farm->Strigling( m_field, 0.0,
159  g_date->DayInYear( 15,5 ) - g_date->DayInYear())) {
160  SimpleEvent( g_date->Date() + 1, ofps_strigling3, true );
161  break;
162  }
163  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 16,5 ),
164  ofps_strigling4, false );
165  break;
166 
167  case ofps_strigling4:
168  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
169  {
170  if (!m_farm->Strigling( m_field, 0.0,
171  g_date->DayInYear( 26,5 ) - g_date->DayInYear())) {
172  SimpleEvent( g_date->Date() + 1, ofps_strigling4, true );
173  break;
174  }
175  }
176  // --FN--
177  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10,6 ),
178  ofps_water1, false );
179  break;
180 
181  case ofps_water1:
182  if ( m_ev->m_lock || m_farm->DoIt( 20 ))
183  {
184  if (!m_farm->Water( m_field, 0.0,
185  g_date->DayInYear( 20,6 ) - g_date->DayInYear())) {
186  SimpleEvent( g_date->Date() + 1, ofps_water1, true );
187  break;
188  }
189  SimpleEvent( g_date->Date()+5, ofps_water2, false );
190  }
191  SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,0),
192  ofps_harvest, false );
193  break;
194 
195  case ofps_water2:
196  if (!m_farm->Water( m_field, 0.0,
197  g_date->DayInYear( 30,6 ) - g_date->DayInYear())) {
198  // --FN--
199  SimpleEvent( g_date->Date() + 1, ofps_water2, true );
200  break;
201  }
202  break;
203 
204  case ofps_harvest:
205  if (!m_farm->Harvest( m_field, 0.0,
206  m_field->GetMDates(1,0) - g_date->DayInYear())) {
207  SimpleEvent( g_date->Date() + 1, ofps_harvest, true );
208  break;
209  }
210  done=true;
211  break;
212 
213  default:
214  g_msg->Warn( WARN_BUG, "OFieldPeasSilage::Do(): "
215  "Unknown event type! ", "" );
216  exit( 1 );
217  }
218 
219  return done;
220 }
221 
222 
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:525
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:444
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:1545
OFieldPeasSilage::Do
bool Do(Farm *a_farm, LE *a_field, FarmEvent *a_ev)
Definition: OFieldPeasSilage.cpp:33
ofps_strigling4
Definition: OFieldPeasSilage.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:1769
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
ofps_spring_roll
Definition: OFieldPeasSilage.h:38
FarmEvent
A struct to hold the information required to trigger a farm event.
Definition: farm.h:463
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
ofps_water1
Definition: OFieldPeasSilage.h:44
ofps_strigling2
Definition: OFieldPeasSilage.h:41
ofps_spring_sow
Definition: OFieldPeasSilage.h:39
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
ofps_water2
Definition: OFieldPeasSilage.h:45
ofps_start
Definition: OFieldPeasSilage.h:34
ofps_harvest
Definition: OFieldPeasSilage.h:35
ofps_strigling1
Definition: OFieldPeasSilage.h:40
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
cfg_strigling_prop
CfgFloat cfg_strigling_prop
Farm::Water
virtual bool Water(LE *a_field, double a_user, int a_days)
Carry out a watering on a_field.
Definition: farmfuncs.cpp:1717
Crop::m_last_date
int m_last_date
Definition: farm.h:542
Farm::SpringSow
virtual bool SpringSow(LE *a_field, double a_user, int a_days)
Carry out a sowing event in the spring on a_field.
Definition: farmfuncs.cpp:546
ofps_strigling3
Definition: OFieldPeasSilage.h:42
Farm
The base class for all farm types.
Definition: farm.h:767
ofps_spring_harrow
Definition: OFieldPeasSilage.h:37
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539
ofps_spring_plough
Definition: OFieldPeasSilage.h:36
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:471