ALMaSS Rabbit ODdox  1.1
The rabbit model description following ODdox protocol
Landscape.cpp
Go to the documentation of this file.
1 /*
2 *******************************************************************************************************
3 Copyright (c) 2011, Christopher John Topping, University of Aarhus
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided
7 that the following conditions are met:
8 
9 Redistributions of source code must retain the above copyright notice, this list of conditions and the
10 following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12 the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
17 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
19 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 ********************************************************************************************************
23 */
24 #include <iostream>
25 #include <fstream>
26 #include <string>
27 #include "../Landscape/ls.h"
28 #include "../BatchALMaSS/PopulationManager.h"
29 #include "../Skylark/skylarks_all.h"
30 #include "../RodenticideModelling/RodenticidePredators.h"
31 #include "../Landscape/map_cfg.h"
32 #include "../BatchALMaSS/BoostRandomGenerators.h"
33 
34 
35 using namespace std;
36 /*
37 This is where all the boost random number generators are created
38 */
39 base_generator_type g_generator(static_cast<unsigned int>(std::time(0)));
40 boost::uniform_real<> g_uni_dist(0,1);
41 boost::uniform_int<> g_uni_dist2(0, 9999);
42 boost::uniform_int<> g_uni_dist3(0, 999);
43 boost::variate_generator<base_generator_type&, boost::uniform_real<> > g_rand_uni(g_generator, g_uni_dist);
44 boost::variate_generator<base_generator_type&, boost::uniform_int<> > g_rand_uni2(g_generator, g_uni_dist2);
45 boost::variate_generator<base_generator_type&, boost::uniform_int<> > g_rand_uni3(g_generator, g_uni_dist3);
46 // End boost random number generators
47 
48 // Version info.
49 static const int version_major = 1;
50 static const int version_minor = 0;
51 static const int version_revision = 0;
52 static const char * version_date = "2014-02-03";
53 
54 
56 CfgBool cfg_rodenticide_enable("RODENTICIDE_ENABLE",CFG_CUSTOM,false);
57 CfgBool cfg_rodenticide_reporting_enable("RODENTICIDE_REPORTING_ENABLE",CFG_CUSTOM,false);
58 
59 static CfgBool cfg_map_usesoiltypes("MAP_USESOILTYPES",CFG_CUSTOM,false);
60 static CfgBool cfg_CalculateCentroids("MAP_CALCULATE_CENTROIDS",CFG_CUSTOM,false);
61 
66 
67 // Hedge Subtype controls
68 CfgInt cfg_HedgeSubtypeMinimum("HEDGE_SUBTYPEMINIMUM",CFG_CUSTOM,0);
69 CfgInt cfg_HedgeSubtypeMaximum("HEDGE_SUBTYPEMAXIMUM",CFG_CUSTOM,3); // actual max is 2 (<3)
70 
71 // Beetlebank variables
72 static CfgBool cfg_AddBeetleBanks("BBANKS_ADD",CFG_CUSTOM,false);
73 static CfgInt cfg_BeetleBankWidth("BBANK_WIDTH",CFG_CUSTOM,4);
74 static CfgInt cfg_BeetleBankChance("BBANK_CHANCE",CFG_CUSTOM,100); // out of 100
75 static CfgFloat cfg_BeetleBankMaxArea("BBANK_MAXAREA",CFG_CUSTOM,0.05);
76 CfgBool cfg_BeetleBankInvert("BBANK_INVERT",CFG_CUSTOM,false);
77 CfgInt cfg_BeetleBankMinX("BBANK_MINX",CFG_CUSTOM,0);
78 CfgInt cfg_BeetleBankMinY("BBANK_MINY",CFG_CUSTOM,0);
79 CfgInt cfg_BeetleBankMaxX("BBANK_MAXX",CFG_CUSTOM,100000);
80 CfgInt cfg_BeetleBankMaxY("BBANK_MAXY",CFG_CUSTOM,100000);
81 static CfgInt cfg_BeetleBankType("BBANK_TYPE",CFG_CUSTOM, (int)tole_BeetleBank);
82 
83 // Veg area dump config variables
84 CfgBool cfg_dumpvegjan( "G_VEGAREASJAN_ON", CFG_CUSTOM, false );
85 CfgStr cfg_dumpvegjanfile( "G_VEGAREASJAN_FILENAME", CFG_CUSTOM, "DUMPVEG_JAN.TXT" );
86 CfgBool cfg_dumpvegjune( "G_VEGAREASJUNE_ON", CFG_CUSTOM, false );
87 CfgStr cfg_dumpvegjunefile( "G_VEGAREASJUNE_FILENAME", CFG_CUSTOM, "DUMPVEG_JUNE.TXT" );
88 
89 // Crops configuration options
90 CfgFloat cfg_strigling_prop( "CROPS_STRIGLING_PROPORTION", CFG_CUSTOM, 1.0 );
91 CfgFloat cfg_silage_prop( "CROPS_SILAGE_PROPORTION", CFG_CUSTOM, 1.0 );
92 CfgFloat cfg_ins_app_prop1("CROPS_INSECTICIDE_APPLIC_ONE_PROPORTION", CFG_CUSTOM, 1.0);
93 CfgFloat cfg_ins_app_prop2("CROPS_INSECTICIDE_APPLIC_TWO_PROPORTION", CFG_CUSTOM, 1.0);
94 CfgFloat cfg_ins_app_prop3("CROPS_INSECTICIDE_APPLIC_THREE_PROPORTION", CFG_CUSTOM, 1.0);
95 CfgFloat cfg_herbi_app_prop("CROPS_HERBICIDE_APPLIC_PROPORTION", CFG_CUSTOM, 1.0);
96 CfgFloat cfg_fungi_app_prop1("CROPS_FUNGICIDE_APPLIC_ONE_PROPORTION", CFG_CUSTOM, 1.0);
97 CfgFloat cfg_fungi_app_prop2("CROPS_FUNGICIDE_APPLIC_TWO_PROPORTION", CFG_CUSTOM, 1.0);
98 CfgFloat cfg_fungi_app_prop3("CROPS_FUNGICIDE_APPLIC_THREE_PROPORTION", CFG_CUSTOM, 1.0);
99 CfgFloat cfg_greg_app_prop("CROPS_GROWTHREGULATOR_APPLIC_PROPORTION", CFG_CUSTOM, 1.0);
100 
101 // Below define the area for custom actions, if valid_x, and valid_y fall in the
102 // area defined by x,y,size, then something can be set on that polygon
103 // The something is hard-coded each time it is used
104 CfgInt cfg_l_treatment_x( "LAND_TREATMENTX", CFG_CUSTOM, 0 );
105 CfgInt cfg_l_treatment_y( "LAND_TREATMENTY", CFG_CUSTOM, 0 );
106 CfgInt cfg_l_treatment_size( "LAND_TREATMENTSIZE", CFG_CUSTOM, -1 );
107 CfgBool cfg_l_usecustompoly( "LAND_USECUSTOMPOLY", CFG_CUSTOM, false );
108 
109 // The config variable below notes the year from the start of the sim when
110 // the pesticide engine will start to spray its pesticide
111 // A test for the value m_toxShouldSpray in landscape is required before sprays
112 // can be used.
113 CfgInt cfg_productapplicstartyear("PEST_PROCTAPPLICSTARTYEAR",CFG_CUSTOM,9999999);
114 CfgInt cfg_productapplicendyear("PEST_PROCTAPPLICENDYEAR",CFG_CUSTOM,-1);
115 CfgInt cfg_pesticidetesttype("PESTICIDETESTYPE",CFG_CUSTOM, -1);
116 
118 CfgBool cfg_pesticidemapon("PEST_MAP_ON", CFG_CUSTOM, false);
120 CfgInt cfg_pesticidemapstartyear("PEST_MAP_STARTYEAR", CFG_CUSTOM, 0);
122 CfgInt cfg_pesticidemapnoyears("PEST_MAP_NOYEARS", CFG_CUSTOM, 1);
124 CfgInt cfg_pesticidemapdayinyear("PEST_MAP_DAYINYEAR", CFG_CUSTOM, 364);
126 CfgInt cfg_pesticidemapcellsize("PEST_MAP_CELLSIZE", CFG_CUSTOM, 10);
128 CfgBool cfg_pesticidemaptype("PEST_MAP_TYPE", CFG_CUSTOM, false);
129 
130 
131 
132 // Local configuration options:
134 static CfgInt cfg_MaxPondSize( "MAP_MAXPONDSIZE", CFG_CUSTOM, 5000 );
135 static CfgInt l_map_no_pesticide_fields( "MAP_NO_PESTICIDE_FIELDS", CFG_CUSTOM, 0 );
136 static CfgBool l_map_print_version_info( "MAP_PRINT_VERSION_INFO", CFG_CUSTOM, true );
138 CfgBool l_map_print_git_version_info( "MAP_PRINT_GIT_VERSION_INFO", CFG_CUSTOM, false );
139 
140 // Whether to exit on the condition that the number of covered squares
141 // on the map becomes zero upon adding the border to a very slim polygon.
142 static CfgBool l_map_exit_on_zero_area( "MAP_EXIT_ON_ZERO_AREA", CFG_CUSTOM, true );
143 
144 // Whether to check in the map for the existence of polygons that are
145 // mentioned in the polygon reference file.
146 static CfgBool l_map_check_polygon_xref( "MAP_CHECK_POLYGON_XREF", CFG_CUSTOM, true );
147 
148 // Whether to add artificial hedgebanks to every hedge polygon in the map.
149 static CfgBool l_map_art_hedgebanks( "MAP_ART_HEDGEBANKS", CFG_CUSTOM, false );
150 
151 static CfgStr l_map_map_file( "MAP_MAP_FILE", CFG_CUSTOM, "map.lsb" );
152 static CfgStr l_map_poly_file( "MAP_POLY_FILE", CFG_CUSTOM, "polygonrefs.txt" );
153 static CfgStr l_map_weather_file( "MAP_WEATHER_FILE", CFG_CUSTOM, "weather.pre" );
154 static CfgStr l_map_cropcurves_file( "MAP_CROPCURVES_FILE", CFG_CUSTOM, "curves.pre" );
155 
156 static CfgInt l_map_chameleon_replace_num( "MAP_CHAMELEON_REPLACE_NUM", CFG_CUSTOM, 58 );
157 
158 //'''''''''''''''''' CIPE LANDSCAPE MAKER CODE HERE //'''''''''''''''''''''
159 static CfgBool l_map_CIPEmaker_enable( "MAP_CIPEMAKER_ENABLE", CFG_CUSTOM, false );
160 //'''''''''''''''''' CIPE LANDSCAPE MAKER CODE ABOVE //'''''''''''''''''''''
161 
162 static CfgBool l_map_dump_enable( "MAP_DUMP_ENABLE", CFG_CUSTOM, false );
163 static CfgBool l_map_removesmallpolygons("MAP_REMOVESMALLPOLYGONS", CFG_CUSTOM, false);
164 CfgStr l_map_dump_map_file( "MAP_DUMP_MAP_FILE", CFG_CUSTOM, "dump.lsb" );
165 static CfgBool l_map_dump_gfx_enable( "MAP_DUMP_GFX_ENABLE", CFG_CUSTOM, false );
166 static CfgStr l_map_dump_gfx_file( "MAP_DUMP_GFX_FILE", CFG_CUSTOM, "dump.ppm" );
167 static CfgBool l_map_dump_exit( "MAP_DUMP_EXIT", CFG_CUSTOM, false );
168 CfgStr l_map_dump_poly_file( "MAP_DUMP_POLY_FILE", CFG_CUSTOM, "dump_polyrefs.txt" );
169 static CfgInt l_map_umargin_width( "MAP_UMARGINWIDTH", CFG_CUSTOM, 12 );
170 static CfgStr l_map_dump_margin_file( "MAP_DUMP_MARGIN_FILE", CFG_CUSTOM, "dumpunsprayedmargins.txt" );
171 static CfgBool l_map_dump_treatcounts_enable( "MAP_DUMP_TREATCOUNTS_ENABLE", CFG_CUSTOM, false );
172 static CfgStr l_map_dump_treatcounts_file( "MAP_DUMP_TREATCOUNTS_FILE", CFG_CUSTOM, "treatment_counts.txt" );
173 
174 static CfgBool l_map_dump_veg_enable( "MAP_DUMP_VEG_ENABLE", CFG_CUSTOM, true );
175 static CfgInt l_map_dump_veg_x( "MAP_DUMP_VEG_X", CFG_CUSTOM, 100 );
176 static CfgInt l_map_dump_veg_y( "MAP_DUMP_VEG_Y", CFG_CUSTOM, 100 );
177 static CfgBool l_map_dump_event_enable( "MAP_DUMP_EVENT_ENABLE", CFG_CUSTOM, false );
178 static CfgInt l_map_dump_event_x1( "MAP_DUMP_EVENT_XA", CFG_CUSTOM, 4287 );
179 static CfgInt l_map_dump_event_y1( "MAP_DUMP_EVENT_YA", CFG_CUSTOM, 2909 );
180 static CfgInt l_map_dump_event_x2( "MAP_DUMP_EVENT_XB", CFG_CUSTOM, 4333 );
181 static CfgInt l_map_dump_event_y2( "MAP_DUMP_EVENT_YB", CFG_CUSTOM, 2889 );
182 /*
183 static CfgBool l_map_renumberpolys("MAP_RENUMBERPOLY", CFG_CUSTOM, false);
184 */
186 static CfgBool l_map_consolidatepolys("MAP_CONSOLIDATEPOLYS", CFG_CUSTOM, false);
187 static CfgBool l_map_calc_openness("MAP_CALC_OPENNESS",CFG_CUSTOM,false );
189 static CfgBool l_map_write_ascii( "MAP_WRITE_ASCII", CFG_CUSTOM, false );
191 static CfgInt l_map_ascii_utm_x( "MAP_ASCII_UTM_X", CFG_CUSTOM, 0 );
193 static CfgInt l_map_ascii_utm_y( "MAP_ASCII_UTM_Y", CFG_CUSTOM, 0 );
195 static CfgInt l_map_ascii_map_entity( "MAP_ASCII_MAP_ENTITY", CFG_CUSTOM, 1 );
196 /*
197 static CfgBool l_map_read_openness("MAP_READ_OPENNESS",CFG_CUSTOM,true );
198 static CfgBool l_map_write_openness("MAP_WRITE_OPENNESS",CFG_CUSTOM,false );
199 static CfgStr l_map_opennessfile("MAP_OPENNESSFILE",CFG_CUSTOM,"FieldOpennessScores.txt");
200 */
201 // For building centroid calculations
202 static CfgInt cfg_mintownbuildingdistance("MAP_MINTOWNBUILDINGDISTANCE",CFG_CUSTOM, 100);
203 static CfgInt cfg_mintownbuildingnumber("MAP_MINTOWNBUILDINGNUMBER",CFG_CUSTOM, 6);
204 
205 static CfgStr cfg_OsmiaNestByLE_Datafile("OSMIA_NESTBYLEDATAFILE", CFG_CUSTOM, "OsmiaNestsByHabitat.txt");
206 
208 
209 extern CfgFloat cfg_P1A;// Parameter 1
210 extern CfgFloat cfg_P1B; // Parameter 2
211 extern CfgFloat cfg_P1C; // Parameter 3
212 extern CfgFloat cfg_P1D; // The scaler to change to from g/dw to KJ
213 extern CfgBool cfg_P1E; // reverse axis values
214 extern CfgFloat cfg_P1F; // Max x-value - at this point the curve tends to 0, must stope here to avoid negative values
215 extern CfgFloat cfg_P1G; // Min x-value
216 extern CfgStr cfg_P1H;
217 
218 // For hareas
219 extern double g_FarmIntensivenessH;
220 extern double g_VegHeightForageReduction;
221 
222 extern CfgFloat cfg_G6A;// Parameter 1
223 extern CfgFloat cfg_G6B; // Parameter 2
224 extern CfgFloat cfg_G6C; // Parameter 3
225 extern CfgFloat cfg_G6D; // The scaler to change to from g/dw to KJ
226 extern CfgBool cfg_G6E; // reverse axis values
227 extern CfgFloat cfg_G6F; // Max x-value - at this point the curve tends to 0, must stope here to avoid negative values
228 extern CfgFloat cfg_G6G; // Min x-value
229 extern CfgStr cfg_G6H;
230 
231 extern CfgFloat cfg_B6A;// Parameter 1
232 extern CfgFloat cfg_B6B; // Parameter 2
233 extern CfgFloat cfg_B6C; // Parameter 3
234 extern CfgFloat cfg_B6D; // The scaler to change to from g/dw to KJ
235 extern CfgBool cfg_B6E; // reverse axis values
236 extern CfgFloat cfg_B6F; // Max x-value - at this point the curve tends to 0, must stope here to avoid negative values
237 extern CfgFloat cfg_B6G; // Min x-value
238 extern CfgStr cfg_B6H;
239 
240 extern CfgBool cfg_WriteCurve;
242 
244 // Globals ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
246 
250 double g_SpeedyDivides[2001];
251 
257 vector<int> * m_polymapping;
259 
260 // End Globals ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
261 
262 /*
263 void Landscape::ReadOpenness()
264 {
268 /*
269  int sz = (int) m_elems.size();
270  ifstream ifile(l_map_opennessfile.value(),ios::in);
271  if ( !ifile.is_open() )
272  {
273  Warn("Landscape::ReadOpenness() Cannot open input file ", "FieldOpennessScores.txt" );
274  }
275  int n, openness, polyref, cx, cy;
276  ifile >> n;
277  if (n != sz)
278  {
279  Warn("Landscape::ReadOpenness() number of entries differs from number of polygons ", l_map_opennessfile.value());
280  std::exit(0);
281  }
282  for (int i=0; i<n; i++)
283  {
284  ifile >> polyref >> openness >> cx >> cy;
285  // We have read a polygon reference in, but we need to find the associated m_elems entry.
286  // This can be done using the polymapping.
287  int polyindex = m_polymapping[polyref];
288  if (polyref != m_elems[polyindex]->GetPoly())
289  {
290  g_msg->Warn("Landscape::ReadOpenness() mismatch in polyref number at entry ", i);
291  std::exit(0);
292  }
293  // All OK so save this
294  m_elems[polyindex]->SetOpenness(openness);
295  m_elems[polyindex]->SetCentroid(cx, cy);
296  }
297  ifile.close();
298 }
299 //-----------------------------------------------------------------------------------------------------------------------------
300 
301 void Landscape::WriteOpenness()
302 {
306 /*
307  int sz = (int) m_elems.size();
308  ofstream ofile(l_map_opennessfile.value(),ios::out);
309  if ( !ofile.is_open() )
310  {
311  Warn("Landscape::WriteOpenness() Cannot open output file ", l_map_opennessfile.value() );
312  }
313  ofile << sz << endl;
314  for (int i=0; i<sz; i++)
315  {
316  ofile << m_elems[i]->GetPoly() << '\t' << m_elems[i]->GetOpenness() << '\t' << m_elems[i]->GetCentroidX()<<'\t'<<m_elems[i]->GetCentroidY()<<'\t'<< endl;
317  }
318  ofile.close();
319 }
320 //-----------------------------------------------------------------------------------------------------------------------------
321 */
322 void Landscape::CalculateOpenness( bool a_realcalc)
323 {
327  cout << "In CalculateOpenness" << endl;
328 
329  for (unsigned int i = 0; i < m_elems.size(); i++)
330  {
331  TTypesOfLandscapeElement tole = m_elems[i]->GetElementType();
332  switch (tole)
333  {
334  case tole_Field:
335  case tole_Marsh:
336  case tole_Scrub:
340  case tole_PermPasture:
343  if (a_realcalc)
344  {
345  cout << i << " ";
346  m_elems[i]->SetOpenness(CalulateFieldOpennessAllCells(i));
347  }
348  else m_elems[i]->SetOpenness(0);
349  break;
350  default:
351  m_elems[i]->SetOpenness(0);
352  break;
353  }
354  }
355  if (a_realcalc) cout << endl;
356 }
357 //-----------------------------------------------------------------------------------------------------------------------------
358 
360 {
361  // Get the centre point for this field
362  int d0 = m_maxextent; // this is the width of the landscape and will always be at least as big as the biggest return value possible
363  int cx = m_elems[a_pref]->GetCentroidX();
364  int cy = m_elems[a_pref]->GetCentroidY();
365 
367  double offsetx = -1;
368  double offsety = -1;
369  double dx = 1.0 / 45.0;
370  double dy = 0.0;
371  for (int deg = 0; deg<90; deg++)
372  {
374  int d1 = LineHighTest(cx, cy, offsetx, offsety);
375  int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
376  int d = d1;
377  if (d1 > d2) d = d2;
378  if (d0 > d) d0 = d;
379  offsetx = offsetx + dx;
380  offsety = offsety + dy;
381  }
382  offsetx = 1;
383  offsety = 1;
384  dy = 0 - dx;
385  dx = 0;
386  for (int deg = 0; deg<90; deg++)
387  {
389  int d1 = LineHighTest(cx, cy, offsetx, offsety);
390  int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
391  int d = d1;
392  if (d1 > d2) d = d2;
393  if (d0 > d) d0 = d;
394  offsetx = offsetx + dx;
395  offsety = offsety + dy;
396  }
397  return d0;
398 }
399 //-----------------------------------------------------------------------------------------------------------------------------
400 
402 {
403  int dline;
404  int d0 = 0;
405  int minX = m_elems[a_pref]->GetMinX();
406  int minY = m_elems[a_pref]->GetMinY();
407  int maxX = m_elems[a_pref]->GetMaxX();
408  int maxY = m_elems[a_pref]->GetMaxY();
409  for (int ax = minX; ax <= maxX; ax+=10)
410  {
411  for (int ay = minY; ay <= maxY; ay+=10)
412  {
413  dline = m_maxextent; // this is the width of the landscape and will always be at least as big as the biggest return value possible
414  // Get a possible point for this field
415  int cx = ax;
416  int cy = ay;
417  if (m_land->Get(ax, ay) == a_pref)
418  {
423  double offsetx = -1;
424  double offsety = -1;
425  double dx = 1.0 / 45.0;
426  double dy = 0.0;
427  for (int deg = 0; deg<90; deg++)
428  {
430  int d1 = LineHighTest(cx, cy, offsetx, offsety);
431  int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
432  int d = d1;
433  if (d1 > d2) d = d2;
434  if (dline > d) dline = d; // get the minimum
435  offsetx = offsetx + dx;
436  offsety = offsety + dy;
437  }
438  offsetx = 1;
439  offsety = 1;
440  dy = 0 - dx;
441  dx = 0;
442  for (int deg = 0; deg<90; deg++)
443  {
445  int d1 = LineHighTest(cx, cy, offsetx, offsety);
446  int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
447  int d = d1;
448  if (d1 > d2) d = d2;
449  if (dline > d) dline = d;
450  offsetx = offsetx + dx;
451  offsety = offsety + dy;
452  }
453  if (dline > d0) d0 = dline; // Get the maximum. Here we might also want to do something like create statistics from the range of dline
454  }
455  }
456  }
457  return d0;
458 }
459 //-----------------------------------------------------------------------------------------------------------------------------
460 
461 inline int Landscape::LineHighTest(int a_cx, int a_cy, double a_offsetx, double a_offsety)
462 {
467  int d1=-1;
468  int counter = 1;
469  bool found = false;
470  while (!found)
471  {
473  int x = (int) (a_cx + a_offsetx * counter);
474  int y = (int) (a_cy + a_offsety * counter);
475  if (x<1 || x >= (m_width-2) || y<1 || y >= (m_height-2)) return counter;
477  TTypesOfLandscapeElement tole = this->SupplyElementType(x,y);
478  if ((tole == tole_LargeRoad) || (tole == tole_SmallRoad) || (tole == tole_HedgeBank)) return counter;
479  if (SupplyLEHigh(x,y))
480  {
481  x = (int) (a_cx + a_offsetx * (counter+1));
482  y = (int) (a_cy + a_offsety * (counter+1));
483  if (SupplyLEHigh(x,y)) found = true;
484  d1=counter;
485  }
486  counter++;
487  }
488  return d1;
489 }
490 //-----------------------------------------------------------------------------------------------------------------------------
491 
492 double Landscape::SupplyRodenticide(int a_x, int a_y) {
494  {
495  double pp;
496  pp = m_RodenticideManager->GetRodenticide(a_x, a_y);
497  return pp;
498  }
499  return 0;
500 }
501 //-----------------------------------------------------------------------------------------------------------------------------
502 
504 {
505  switch (a_vege_type)
506  {
507  case tov_NaturalGrass:
512  case tov_Setaside:
513  case tov_SeedGrass1:
514  case tov_SeedGrass2:
515  case tov_OSeedGrass1:
516  case tov_OSeedGrass2:
521  case tov_OrchardCrop:
522  case tov_YoungForest:
523  case tov_FodderGrass:
524  case tov_Heath:
525  case tov_WaterBufferZone:
526  return true;
527  default: return false;
528  }
529 }
530 //-----------------------------------------------------------------------------------------------------------------------------
531 
533 {
534  switch (a_vege_type)
535  {
536  case tov_SpringBarley:
537  case tov_SpringBarleySpr:
538  case tov_WinterBarley:
539  case tov_SpringWheat:
540  case tov_WinterWheat:
541  case tov_WinterRye:
542  case tov_Oats:
543  case tov_Triticale:
551  case tov_OWinterBarley:
553  case tov_OWinterRye:
557  case tov_OSpringBarley:
560  case tov_OWinterWheat:
561  case tov_OOats:
562  case tov_OTriticale:
563  case tov_WWheatPControl:
572  case tov_PLWinterWheat:
573  case tov_PLWinterBarley:
574  case tov_PLWinterRye:
576  case tov_PLSpringWheat:
577  case tov_PLSpringBarley:
578  case tov_NLWinterWheat:
579  case tov_NLSpringBarley:
580  return true;
581  default: return false;
582 }
583 }
584 //-----------------------------------------------------------------------------------------------------------------------------
585 
586 double Landscape::SupplyPesticide(int a_x, int a_y, PlantProtectionProducts a_ppp) {
587  double pp;
588 #ifdef __DETAILED_PESTICIDE_FATE
589  // This should be avoided if possible because it is inefficient
590  pp = g_pest->SupplyPesticideS(a_x, a_y, a_ppp);
591  pp += g_pest->SupplyPesticideP(a_x, a_y, a_ppp);
592 #else
593  pp = g_pest->SupplyPesticide(a_x, a_y, a_ppp);
594 #endif
595  return pp;
596 }
597 //-----------------------------------------------------------------------------------------------------------------------------
598 
599 bool Landscape::SupplyOverspray(int a_x, int a_y)
600 {
601  return m_elems[m_land->Get(a_x, a_y)]->GetSprayedToday();
602 }
603 //-----------------------------------------------------------------------------------------------------------------------------
604 
605 double Landscape::SupplyPesticideP(int a_x, int a_y, PlantProtectionProducts a_ppp) {
606  double pp;
607 #ifdef __DETAILED_PESTICIDE_FATE
608  pp = g_pest->SupplyPesticideP(a_x, a_y, a_ppp);
609 #else
610  pp = g_pest->SupplyPesticide(a_x, a_y, a_ppp);
611 #endif
612  return pp;
613 }
614 //-----------------------------------------------------------------------------------------------------------------------------
615 
616 double Landscape::SupplyPesticideS(int a_x, int a_y, PlantProtectionProducts a_ppp) {
617  double pp;
618 #ifdef __DETAILED_PESTICIDE_FATE
619  pp = g_pest->SupplyPesticideS(a_x, a_y, a_ppp);
620 #else
621  pp = g_pest->SupplyPesticide(a_x, a_y, a_ppp);
622 #endif
623  return pp;
624 }
625 //-----------------------------------------------------------------------------------------------------------------------------
626 
628  if (!l_pest_enable_pesticide_engine.value()) return 0.0;
629  double pp;
630 #ifdef __DETAILED_PESTICIDE_FATE
631  pp = g_pest->SupplyPesticideS(a_polyref, a_ppp);
632  pp += g_pest->SupplyPesticideP(a_polyref, a_ppp);
633 #else
634  pp = g_pest->SupplyPesticide(a_polyref, a_ppp);
635 #endif
636  return pp;
637 }
638 //-----------------------------------------------------------------------------------------------------------------------------
639 
641  if (!l_pest_enable_pesticide_engine.value()) return 0.0;
642  double pp;
643 #ifdef __DETAILED_PESTICIDE_FATE
644  pp = g_pest->SupplyPesticideS(a_polyref, a_ppp);
645 #else
646  pp = g_pest->SupplyPesticide(a_polyref, a_ppp);
647 #endif
648  return pp;
649 }
650 //-----------------------------------------------------------------------------------------------------------------------------
651 
653  if (!l_pest_enable_pesticide_engine.value()) return 0.0;
654  double pp;
655 #ifdef __DETAILED_PESTICIDE_FATE
656  pp = g_pest->SupplyPesticideP(a_polyref, a_ppp);
657 #else
658  pp = g_pest->SupplyPesticide(a_polyref, a_ppp);
659 #endif
660  return pp;
661 }
662 //-----------------------------------------------------------------------------------------------------------------------------
663 
664 bool Landscape::SubtractPondLarvalFood(double a_food,int a_polyrefindex) {
665  return dynamic_cast<Pond*>(m_elems[a_polyrefindex])->SubtractLarvalFood(a_food);
666 }
667 //-----------------------------------------------------------------------------------------------------------------------------
668 
670 {
672  {
673  if (cfg_pesticidemaptype.value() == false)
674  {
675  m_PesticideMap->Spray(a_field, a_pcide);
676  }
677  else
678  {
679  if (a_pcide == testpesticide) m_PesticideMap->Spray(a_field, insecticide);
680  }
681  }
682 }
683 //-----------------------------------------------------------------------------------------------------------------------------
684 
686 {
693  GooseFieldList* alist = new GooseFieldList;
697  GooseFieldListItem gfli;
698  for (unsigned int i = 0; i < m_elems.size(); i++)
699  {
700  if (m_elems[i]->GetOpenness() > a_minopenness)
701  {
702  for (int g = gs_Pinkfoot; g < gs_foobar; g++)
703  {
704  gfli.grass[g] = m_elems[i]->GetGooseGrazingForage((GooseSpecies)g);
705  gfli.geesesp[g] = m_elems[i]->GetGooseSpNosToday((GooseSpecies)g);
706  gfli.geesespTimed[g] = m_elems[i]->GetGooseSpNosTodayTimed((GooseSpecies)g);
707  gfli.roostdists[g] = m_elems[i]->GetGooseRoostDist((GooseSpecies)g);
708  }
709  gfli.grain = m_elems[i]->GetBirdSeed();
710  gfli.maize = m_elems[ i ]->GetBirdMaize();
711  gfli.openness = m_elems[ i ]->GetOpenness();
712  int pref = m_elems[ i ]->GetPoly();
713  gfli.polyref = pref;
714  gfli.geese = m_elems[i]->GetGooseNosToday();
715  gfli.geeseTimed = m_elems[i]->GetGooseNosTodayTimed();
716  gfli.vegtype = m_elems[i]->GetVegType();
717  gfli.vegtypechr = VegtypeToString(m_elems[i]->GetVegType());
718  gfli.vegheight = m_elems[i]->GetVegHeight();
719  gfli.digestability = m_elems[i]->GetDigestability();
720  gfli.vegphase = m_elems[i]->GetVegPhase();
721  gfli.previouscrop = VegtypeToString( m_elems[ i ]->GetPreviousCrop( m_elems[ i ]->GetRotIndex() ) );
722  gfli.lastsownveg = VegtypeToString( m_elems[ i ]->GetLastSownVeg() );
723  alist->push_back(gfli);
724  }
725  }
726  return alist;
727 }
728 //-----------------------------------------------------------------------------------------------------------------------------
729 
731 {
736  for (unsigned int i = 0; i < m_elems.size(); i++)
737  {
738  m_elems[i]->SetBirdSeed(0.0);
739  m_elems[i]->SetBirdMaize(0.0);
740  }
741 }
742 //-----------------------------------------------------------------------------------------------------------------------------
743 
744 
745 int Landscape::SupplyFarmAnimalCensus(int a_farm_ref, int a_LifeStage)
746 {
747  return m_ThePopManager->FarmAnimalCensus(a_farm_ref, a_LifeStage);
748 }
749 //-----------------------------------------------------------------------------------------------------------------------------
750 
751 int Landscape::SupplyFarmIntensityI( int a_polyindex ) {
752  return m_elems[ a_polyindex ]->GetOwner()->GetIntensity();
753 }
754 //-----------------------------------------------------------------------------------------------------------------------------
755 
756 int Landscape::SupplyFarmIntensity( int a_x, int a_y ) {
757  return m_elems[ m_land->Get( a_x, a_y ) ]->GetOwner()->GetIntensity();
758 }
759 //-----------------------------------------------------------------------------------------------------------------------------
760 
761 int Landscape::SupplyFarmIntensity( int a_polyref ) {
762  return m_elems[ m_polymapping[ a_polyref ]]->GetOwner()->GetIntensity();
763 }
764 //-----------------------------------------------------------------------------------------------------------------------------
765 
766 APoint Landscape::SupplyCentroid( int a_polyref ) {
767  return m_elems[ m_polymapping[ a_polyref ] ]->GetCentroid();
768 }
769 //-----------------------------------------------------------------------------------------------------------------------------
770 
771 APoint Landscape::SupplyCentroidIndex( int a_polyrefindex ) {
772  return m_elems[ a_polyrefindex ]->GetCentroid();
773 }
774 //-----------------------------------------------------------------------------------------------------------------------------
775 
777 {
778  return g_pest->GetAnythingToDecay(a_ppp);
779 }
780 //-----------------------------------------------------------------------------------------------------------------------------
781 
782 polylist* Landscape::SupplyLargeOpenFieldsNearXY(int a_x, int a_y, int a_range, int a_openness)
783 {
792  polylist* p_list = new polylist;
793  unsigned sz = (unsigned) m_elems.size();
794  for (unsigned i=0; i<sz; i++)
795  {
796  if ( m_elems[i]->GetOpenness() > a_openness)
797  {
798  APoint pt = m_elems[i]->GetCentroid();
799  int dx, dy;
800  if (a_x>pt.m_x) dx = a_x-pt.m_x; else dx = pt.m_x-a_x;
801  if (a_y>pt.m_y) dy = a_y-pt.m_y; else dy = pt.m_y-a_y;
802  dx++; dy++; // prevents crash with maths below.
804  int dist;
806  if (dx>dy) dist = dx + (dy * dy) /(2 * dx); else dist = dy + (dx * dx) /(2 * dy);
807  if (dist<=a_range) p_list->push_back( m_elems[i]->GetPoly());
808  }
809  }
810  return p_list;
811 }
812 //-----------------------------------------------------------------------------------------------------------------------------
813 
815 
818  // Set up operation flags
819  bool didRenumber = false;
820  bool didCalcCentroids = false;
821  bool didConsolidate = false;
822  bool didCalcOpenness = false;
823  bool didCalcOther = false;
824  m_NeedCentroidCalculation = false;
825  m_NeedOpennessCalculation = false;
826  m_DoMissingPolygonsManipulations = false;
827  // Set up globals
828  g_landscape_p = this;
829  for (int i = 1; i <= 2000; i++) {
830  g_SpeedyDivides[i] = 1 / double(i);
831  }
832  int x_add[8] = { 1, 1, 0, -1, -1, -1, 0, 1 }; // W,SW,S,SE,E,NE,N,NW
833  int y_add[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
834  for (int i = 0; i < 8; i++) {
835  m_x_add[i] = x_add[i];
836  m_y_add[i] = y_add[i];
837  }
838 
839 
840  sprintf(m_versioninfo, "%d.%d.%d :: %s", version_major, version_minor, version_revision, version_date);
841 
843  printf("This program uses the Landscape simulator V%s\n", m_versioninfo);
844  }
845 #ifdef __GITVERSION
847  {
848  std::cout << "hash=" << GIT_HASH << ", time=" << COMPILE_TIME << ", branch=" << GIT_BRANCH << std::endl;
849  }
850 #endif
851 
852 
853  // For testing.
854  //g_cfg->DumpPublicSymbols( "publicsymbols.cfg", CFG_PUBLIC );
855  //exit(1);
856 
857  //Pinkfeet
858  m_GooseIntakeRateVSVegetationHeight_PF = new Polynomial2CurveClass(cfg_P1A.value(), cfg_P1B.value(), cfg_P1C.value(), cfg_P1D.value(), cfg_P1E.value(), cfg_P1F.value(), cfg_P1G.value(), cfg_P1H.value());
859  //Barnacle
860  m_GooseIntakeRateVSVegetationHeight_BG = new Polynomial2CurveClass(cfg_B6A.value(), cfg_B6B.value(), cfg_B6C.value(), cfg_B6D.value(), cfg_B6E.value(), cfg_B6F.value(), cfg_B6G.value(), cfg_B6H.value());
861  //Greylag
862  m_GooseIntakeRateVSVegetationHeight_GL = new Polynomial2CurveClass(cfg_G6A.value(), cfg_G6B.value(), cfg_G6C.value(), cfg_G6D.value(), cfg_G6E.value(), cfg_G6F.value(), cfg_G6G.value(), cfg_G6H.value());
863  if (cfg_WriteCurve.value()) {
864  m_GooseIntakeRateVSVegetationHeight_GL->WriteDataFile(10);
865  m_GooseIntakeRateVSVegetationHeight_BG->WriteDataFile(10);
866  m_GooseIntakeRateVSVegetationHeight_PF->WriteDataFile(10);
867  }
868 
869  cout << "Creating Calendar Object" << endl;
870  g_date = new Calendar;
871  cout << "Creating Weather Object" << endl;
873  cout << "Creating LE_TypeClass Object" << endl;
874  g_letype = new LE_TypeClass;
875  cout << "Creating PlantGrowthData Object" << endl;
877  cout << "Creating PollenNectarDevelopmentData Object" << endl;
878  g_nectarpollen = new PollenNectarDevelopmentData("toleALMaSSNectarPollenInput.txt", "tovALMaSSNectarPollenInput.txt", this);
879  m_LargestPolyNumUsed = -1;
880 
881  // Reset treatment counters.
882  for (int i = 0; i < last_treatment; i++) {
883  m_treatment_counts[i] = 0;
884  }
885  cout << "Creating FarmManager Object" << endl;
886  m_FarmManager = new FarmManager();
887 
888  cout << "Reading polygon reference file" << endl;
889  ReadPolys2(l_map_poly_file.value());
890 
891  //this carries out the optimisation
892  if (cfg_OptimisingFarms.value()){
893  m_FarmManager->InitFarms();
894  m_FarmManager->Save_diff_farm_types_areas();
895  }
896 
897  cout << "Creating RasterMap Object" << endl;
898  m_land = new RasterMap(l_map_map_file.value(), this);
899  m_width = m_land->MapWidth();
900  m_height = m_land->MapHeight();
901  if (m_width > m_height) m_maxextent = m_width; else m_maxextent = m_height;
902  m_width10 = 10 * m_width;
903  m_height10 = 10 * m_height;
904  if (m_width < m_height) m_minmaxextent = m_width; else m_minmaxextent = m_height;
905 
906 
907  // Validate polygons, ie. ensure those reference in the
908  // polygon file also shows up in the map.
909  cout << "In PolysValidate" << endl;
910  PolysValidate(false);
911  cout << "In PolysRemoveInvalid" << endl;
912  PolysRemoveInvalid();
913  cout << "Creating ponds" << endl;
914  if (cfg_MaxPondSize.value() > 0) {
915  // This takes any small freshwater and converts it to a pond.
916  for (unsigned int i = 0; i < m_elems.size(); i++) {
917  if (m_elems[i]->GetElementType() == tole_Freshwater) {
918  if (m_elems[i]->GetArea() <= cfg_MaxPondSize.value()) {
919  Pond* pond = new Pond;
920  pond->DoCopy(m_elems[i]);
921  pond->SetALMaSSEleType(g_letype->BackTranslateEleTypes(tole_Pond));
922  pond->SetElementType(tole_Pond);
923  m_elems[i] = dynamic_cast<LE*>(pond);
924  }
925  }
926  }
927  }
928  cout << "In PolysValidate second time" << endl;
929  PolysValidate(true);
930 
936  if (m_DoMissingPolygonsManipulations)
937  {
938  cout << "In DoMissingPolygonsManipulations" << endl;
939  // Find big continuous polygons
940  for (unsigned int i = 0; i < m_elems.size(); i++)
941  {
942  if (m_elems[i]->GetElementType() == tole_Missing)
943  {
944  double area = m_elems[i]->GetArea();
945  int areaMinrect = (m_elems[i]->GetMaxX() - m_elems[i]->GetMinX()) * (m_elems[i]->GetMaxY() - m_elems[i]->GetMinY());
946  if ((areaMinrect / area > 4) || (area < 1000))
947  {
948  // Unlikely to be a field, or if so a very narrow odd one. We will assume this is a missing data issue.
949  }
950  else
951  {
952  // Big poly with more than 25% of the included rectangle covered, must be a field of some sort.
953  // create a new wasteland and swap this in to the m_elems, then delete the old missing polygon
954  LE * wl = NewElement(tole_Wasteland);
955  wl->SetPoly(m_elems[i]->GetPoly());
956  wl->SetArea(floor(0.5 + area));
957  wl->SetSoilType(m_elems[i]->GetSoilType());
959  wl->SetCentroid(-1, -1);
960  wl->SetOpenness(0);
961  delete m_elems[i];
962  m_elems[i] = wl;
963  }
964  }
965  }
966  // By here all the big ones should be safely tidied away to wasteland and now we need to deal with the raster map.
967  RemoveMissingValues();
968  for (unsigned int i = 0; i < m_elems.size(); i++)
969  {
970  // Now we deal with all the little ones that were not by fields
971  if (m_elems[i]->GetElementType() == tole_Missing)
972  {
973  LE * wl = NewElement(tole_Wasteland);
974  wl->SetPoly(m_elems[i]->GetPoly());
975  wl->SetArea(m_elems[i]->GetArea());
976  wl->SetSoilType(m_elems[i]->GetSoilType());
978  wl->SetCentroid(-1, -1);
979  wl->SetOpenness(0);
980  delete m_elems[i];
981  m_elems[i] = wl;
982  }
983  }
984  cout << "In PolysValidate third time" << endl;
985  PolysValidate(false);
986  if (PolysRemoveInvalid()) {
987  cout << "In PolysValidate fourth time" << endl;
988  PolysValidate(true);
989  }
990  g_msg->Warn("Landscape::Landscape(): Dump and normal exit to follow after resolving missing polygons. ", "");
991  didCalcOther = true;
992  }
993 
994  // ChangeMapMapping() also enters a valid starting
995  // coordinate for the border generating farm method below.
996  cout << "In ChangeMapMapping" << endl;
997  ChangeMapMapping();
998 
1002  if ((m_LargestPolyNumUsed != ((int)m_elems.size() - 1)))
1003  {
1004  cout << "In poly renumber" << endl;
1005 
1006  PolysRenumber();
1007  didRenumber = true;
1008  }
1009  // do we want to remove small polygons?
1011  {
1012  cout << "In Landscape::Landscape() Small polygon removal" << endl;
1013  int removed = RemoveSmallPolygons();
1014  g_msg->Warn("Landscape::Landscape(): Dump and normal exit to follow after removing small polygons and map dump. Polygons removed:", removed);
1015  didCalcOther = true;
1016  }
1017  // Do we want to re-write the current files and consolidate polys?
1018  else if (l_map_consolidatepolys.value())
1019  {
1020  cout << "In consolidate polys" << endl;
1021  didConsolidate = true;
1022  ConsolidatePolys();
1023  }
1024  else if (g_map_le_borderremoval.value())
1025  {
1026  cout << "In map_le_borderremoval" << endl;
1027  // Does not use centroids so is safe to use here
1028  BorderRemoval();
1029  CountMapSquares();
1030  ForceArea();
1031  g_msg->Warn(WARN_FILE, "Landscape::Landscape() - BorderRemoval "" map dump to follow.", "");
1032  didCalcOther = true;
1033  }
1034 
1035 
1036  // By the time we reach this point we need to have completed all major polygon removal and are ready to calculate centroids if they are needed. There
1037  // are two reasons for this - 1) that we did not have them in the original polyref file, 2) that we changed the map
1038  if (didConsolidate || didCalcOther || m_NeedCentroidCalculation)
1039  {
1040  PolysValidate(false);
1041  if (PolysRemoveInvalid()) PolysValidate(true);
1042  ChangeMapMapping();
1043  PolysRenumber();
1044  CalculateCentroids();
1045  didCalcCentroids = true;
1046  }
1047  if (didConsolidate || didCalcOther || m_NeedCentroidCalculation || didCalcCentroids || l_map_calc_openness.value())
1048  {
1049  if (l_map_calc_openness.value()) CalculateOpenness(true);
1050  else CalculateOpenness(false);
1051  didCalcOpenness = true;
1052  }
1053  if (didCalcCentroids || didConsolidate || didCalcOpenness || didCalcOther || m_NeedCentroidCalculation || didRenumber || !m_FarmManager->GetIsRenumbered())
1054  {
1055  // We need to dump the map and polyrefs
1056  m_FarmManager->DumpFarmrefs();
1057  DumpMap(l_map_dump_map_file.value());
1058  PolysDump(l_map_dump_poly_file.value());
1059  g_msg->Warn(WARN_FILE, "Landscape::Landscape() ""Normal exit after dump.", "Remember to rename the new map and polyref file.");
1060  exit(0);
1061  }
1062 
1063  // Below here we have the more complicated map manipulations. These will need recalculation of centroids and openness after they are run.
1064  // However, we really do not want to get here with invalid centroids, hence forced dump and exit for manipulations up to this point.
1065 
1066  didCalcOther = false;
1067  // Add artificial hedgebanks to the hedges in the landscape,
1068  // if requested.
1069  if (l_map_art_hedgebanks.value()) {
1070  hb_Add();
1071  didCalcOther = true;
1072  }
1073  else if (g_map_le_borders.value())
1074  {
1075  cout << "Generating LE Borders around fields" << endl;
1076  cout << "Border chance = " << g_map_le_border_chance.value() << endl;
1077  cout << "Border width = " << g_map_le_borderwidth.value() << endl;
1078  // Generate border around each *farm* landscape element.
1079  cout << "Setting MaxMin Extents" << endl;
1080  SetPolyMaxMinExtents();
1081  cout << "Adding Borders" << endl;
1082  unsigned sz = (unsigned)m_elems.size();
1083  for (unsigned i = 0; i < sz; i++)
1084  {
1085  if (m_elems[i]->GetBorder() != NULL)
1086  {
1087  // Border around this element, so must be a farm field.
1088  // If the field is too small then ignore it
1089  if (m_elems[i]->GetArea() > g_map_le_borders_min_field_size.value())
1090  {
1092  BorderAdd(m_elems[i], t);
1093  }
1094  }
1095  }
1096  didCalcOther = true;
1097  }
1098  else // Some special code to 'soften' the edges of orchards
1100  {
1101  // Generate border around each *farm* landscape element.
1102  for (unsigned int i = 0; i < m_elems.size(); i++) {
1103  if (m_elems[i]->GetElementType() == tole_Orchard)
1104  {
1106  BorderAdd(m_elems[i], t);
1107  }
1108  }
1109  didCalcOther = true;
1110  }
1111  else
1112  // Unsprayed Margin Code....
1114  {
1115  CountMapSquares();
1116  ForceArea();
1117 
1118  // Generate border around each *farm* landscape element.
1119  for (unsigned int i = 0; i < m_elems.size(); i++)
1120  {
1121  if (m_elems[i]->GetUnsprayedMarginPolyRef() != -1)
1122  {
1123  // But not if the field is too small to have them (<1Ha)
1124  if (m_elems[i]->GetArea() > 10000)
1125  {
1126  // Border around this element, so must be a farm field.
1127  UnsprayedMarginAdd(m_elems[i]);
1128  }
1129  else m_elems[i]->SetUnsprayedMarginPolyRef(-1);
1130  }
1131  }
1132  didCalcOther = true;
1133  }
1134  else if (cfg_AddBeetleBanks.value())
1135  {
1136  cout << "Adding beetle banks now" << endl;
1138  didCalcOther = true;
1139  }
1140 
1142  {
1143  DumpMapGraphics(l_map_dump_gfx_file.value());
1144  }
1145 
1146  if (l_map_dump_enable.value() || didCalcOther)
1147  {
1148  CountMapSquares();
1149  ForceArea();
1150  PolysValidate(false);
1151  if (PolysRemoveInvalid()) PolysValidate(true);
1152  ChangeMapMapping();
1153  PolysRenumber();
1154  CalculateCentroids();
1155  CalculateOpenness(l_map_calc_openness.value());
1156  m_FarmManager->DumpFarmrefs();
1157  cout << "Dumping map" << endl;
1158  DumpMap(l_map_dump_map_file.value());
1159  cout << "Dumping polygon refs file" << endl;
1160  PolysDump(l_map_dump_poly_file.value());
1161  g_msg->Warn(WARN_FILE, "Landscape::Landscape() ""Normal exit after dump.", "Remember to rename the new map and polyref file.");
1162  exit(0);
1163  }
1164 
1165  /*'''''''''''''''''' CIPE LANDSCAPE MAKER CODE HERE //'''''''''''''''''''''
1166  if ( l_map_CIPEmaker_enable.value() ) {
1167  CIPELandscapeMaker();
1168  if ( l_map_dump_exit.value() ) {
1169  g_msg->Warn( WARN_FILE, "Landscape::Landscape(): ""Normal exit after map dump.", "" );
1170  exit( 0 );
1171  }
1172  }
1173  //'''''''''''''''''' CIPE LANDSCAPE MAKER CODE ABOVE //'''''''''''''''''''''
1174  */
1175  // Set the type of hedgebanks.
1176  int l_subtype = cfg_HedgeSubtypeMinimum.value();
1177  for (unsigned int i = 0; i < m_elems.size(); i++) {
1178  if (m_elems[i]->GetElementType() == tole_HedgeBank) {
1179  m_elems[i]->SetSubType(l_subtype);
1180  if (++l_subtype >= cfg_HedgeSubtypeMaximum.value())
1181  l_subtype = cfg_HedgeSubtypeMinimum.value();
1182  }
1183  }
1184 
1185  // And another to set the type of hedges
1186  // ***CJT*** 2003-12-02
1187  l_subtype = 0;
1188  for (unsigned int i = 0; i < m_elems.size(); i++) {
1189  if (m_elems[i]->GetElementType() == tole_Hedges) {
1190  m_elems[i]->SetSubType(l_subtype);
1191  if (++l_subtype >= 3)
1192  l_subtype = 0;
1193  }
1194  }
1195  // Count up the ponds and store them now we are finished with polygon handling.
1196  CreatePondList();
1197 
1198  cout << "Initiating farm management" << endl;
1199  m_FarmManager->InitiateManagement();
1200  g_pest = new Pesticide(m_land, this);
1201  m_toxShouldSpray = false; // Flag for special pesticide tests
1203  g_date->Reset();
1204 
1205  /*
1206  if ( g_farm_test_crop.value() ) {
1207  TestCropManagement();
1208  exit( 0 );
1209  }
1210  */
1211 
1212  // Set up treatment flags
1213  // Reset internal state for the LE loop generator.
1214  // Compulsory!
1215  SupplyLEReset();
1216  // Get number of *all* landscape elements.
1217  int l_count = SupplyLECount();
1218 
1219  // Now loop through then.
1220  for (int i = 0; i < l_count; i++) {
1221  // Fetch next LE by its polygon reference number. Alternative
1222  // loop mechanism: This will return -1 at end-of-loop.
1223  int a_poly = SupplyLENext();
1224 
1225  // Skip uninteresting polygons by type, ownership,
1226  // phase of the moon, whatever.
1227  // if ( these_are_not_the_droids_we_are_looking_for( a_poly )) {
1228  if (SupplyElementType(a_poly) != tole_Field)
1229  continue;
1230 
1231  // Example: Set x% of them to ignore insecticide of all types.
1232  if (random(100) < l_map_no_pesticide_fields.value()) {
1233  // Get current signal mask for polygon.
1234  LE_Signal l_signal = SupplyLESignal(a_poly);
1235  // Logical OR in/AND out the signals you are interested in.
1236  // The current signals are at the top of elements.h
1237  //l_signal |= LE_SIG_NO_INSECTICIDE | LE_SIG_NO_SYNG_INSECT | LE_SIG_NO_HERBICIDE | LE_SIG_NO_FUNGICIDE | LE_SIG_NO_GROWTH_REG;
1238  //l_signal |= LE_SIG_NO_INSECTICIDE | LE_SIG_NO_SYNG_INSECT | LE_SIG_NO_HERBICIDE;
1239  // Write the mask back out to the polygon.
1240  SetLESignal(a_poly, l_signal);
1241  }
1242  }
1243 
1244  l_vegtype_areas = (double *)malloc(sizeof(double) * (tov_Undefined + 1));
1245 
1246  if (l_vegtype_areas == NULL) {
1247  g_msg->Warn(WARN_BUG, "Landscape::Landscape(): Out of memory!", "");
1248  exit(1);
1249  }
1250  FILE * outf;
1251  if (cfg_dumpvegjan.value()) {
1252  outf = fopen(cfg_dumpvegjanfile.value(), "w");
1253  if (!outf) {
1254  g_msg->Warn(WARN_FILE, "Landscape::DumpMapInfoByArea(): ""Unable to create file", cfg_dumpvegjanfile.value());
1255  exit(1);
1256  }
1257  else
1258  fclose(outf);
1259  }
1260 
1261  if (cfg_dumpvegjune.value()) {
1262  outf = fopen(cfg_dumpvegjunefile.value(), "w");
1263  if (!outf) {
1264  g_msg->Warn(WARN_FILE, "Landscape::DumpMapInfoByArea(): ""Unable to create file", cfg_dumpvegjunefile.value());
1265  exit(1);
1266  }
1267  else
1268  fclose(outf);
1269  }
1270 
1271 #ifdef __RECORDFARMEVENTS
1272  m_farmeventfile = new ofstream("FarmEvents.txt", ofstream::out);
1273 #endif
1274 
1275 
1276  // Dump veg information if necessary
1277  if (l_map_dump_veg_enable.value()) {
1278  FILE * f;
1279  f = fopen("VegDump.txt", "w");
1280  if (!f) {
1281  g_msg->Warn(WARN_BUG, "Landscape::Landscape(): VegDump.txt could not be created", "");
1282  exit(1);
1283  }
1284  fprintf(f, "Year\tDay\tHeight\tBiomass\tGrazed\tDensity\tCover\tWeedBiomass\ttovNum\tInsectBiomass\tLATotal\tLAGreen\tDigestability\tGreenBiomass\tDeadBiomass\tGooseGrazing\tSpilledGrain\nn");
1285  fclose(f);
1286  }
1288  FILE * f;
1289  f = fopen("EventDump.txt", "w");
1290  if (!f) {
1291  g_msg->Warn(WARN_BUG, "Landscape::Landscape(): EventDump.txt could not be created", "");
1292  exit(1);
1293  }
1294  fclose(f);
1295  }
1296 
1298  m_FarmManager->FindNeighbours();
1299  }
1300 
1301  if (cfg_DumpFarmAreas.value()){
1302  m_FarmManager->DumpFarmAreas();
1303  }
1304 
1305  // If we are testing a pesticide then set the enum attribute
1306  m_PesticideType = (TTypesOfPesticide)cfg_pesticidetesttype.value();
1307 
1310  {
1311  m_RodenticideManager = new RodenticideManager("BaitLocations_input.txt", this);
1312  m_RodenticidePreds = new RodenticidePredators_Population_Manager(this);
1313  }
1314 
1315  // Run a year to remove any start up effects
1316  cout << "Running initial start-up year" << endl;
1317  for (unsigned int i = 0; i < 365; i++) Tick();
1318  //switch the rotation after running the hidden year (only for optimising farms), AM, 030713
1319  if (cfg_OptimisingFarms.value()) { m_FarmManager->Switch_rotation(); }
1320  // Write ASCII file:
1321  if (l_map_write_ascii.value()) {
1322  int x = l_map_ascii_utm_x.value();
1323  int y = l_map_ascii_utm_y.value();
1324  GISASCII_Output("AsciiLandscape.txt", x, y);
1325  }
1326 }
1327 //-----------------------------------------------------------------------------------------------------------------------------
1328 
1330 {
1336  const int TypesToReplace = 16;
1337  TTypesOfLandscapeElement replaceList[TypesToReplace] = {
1338  tole_River,
1342  tole_BareRock,
1344  tole_Carpark,
1346  tole_Coast,
1347  tole_Garden,
1352  tole_SandDune,
1354  };
1355  int foundList[TypesToReplace];
1356  cout << "Consolidating polygons with no special behaviour" << endl;
1357  for (int i = 0; i < TypesToReplace; i++) foundList[i] = -1;
1358  int mapwidth = m_land->MapWidth();
1359  int mapheight = m_land->MapHeight();
1360  for (int x = 0; x < mapwidth; x++)
1361  {
1362  for (int y = 0; y < mapheight; y++)
1363  {
1364  int ele = m_land->Get(x, y);
1365  TTypesOfLandscapeElement tole = m_elems[m_polymapping[ele]]->GetElementType();
1366  for (int t = 0; t < TypesToReplace; t++)
1367  {
1368  if (tole == replaceList[t])
1369  {
1370  // Must do something with this cell
1371  if (foundList[t] == -1) foundList[t] = ele;
1372  else
1373  {
1374  // Need to replace this cell
1375  m_land->Put(x, y, foundList[t]);
1376  }
1377  }
1378  }
1379  }
1380  }
1381  // At this point there should be many polygons that are not in the map. So we need to run the valid test.
1382  g_msg->Warn(WARN_FILE, "Landscape::ConsolidatePolys() - ""Consolidate map dump.", "");
1383 }
1384 //-----------------------------------------------------------------------------------------------------------------------------
1385 
1386 void Landscape::DumpMap( const char * a_filename )
1387 {
1388  int * l_map = m_land->GetMagicP(0, 0); // Hmmm - this is a nasty way round the class data protection. Gets a pointer direct to m_map in rastermap.
1389  /* FILE * l_file;
1390  l_file = fopen(a_filename, "wb" );
1391  if ( !l_file ) {
1392  g_msg->Warn( WARN_FILE, "Landscape::DumpMap(): Unable to open file", a_filename );
1393  exit( 0 );
1394  }
1395 
1396  char * l_id = m_land->GetID();
1397 
1398 
1399  fwrite( l_id, 1, 12, l_file );
1400  fwrite( & m_width, 1, sizeof( int ), l_file );
1401  if (cfg_rectangularmaps_on.value() )
1402  {
1403  fwrite( & m_height, 1, sizeof( int ), l_file );
1404  }
1405  for ( int i = 0; i < m_width * m_height; i++ )
1406  {
1407  LE* le = m_elems[m_polymapping[l_map[i]]];
1408  int l_poly = le->GetPoly();
1409  fwrite( & l_poly, 1, sizeof( int ), l_file );
1410  }
1411  fclose( l_file );
1412  */
1413  ofstream OFile( a_filename, ios::binary);
1414  char id[12] = { "LSB2_Format" };
1415  OFile.write(id, 12);
1416  OFile.write((char*)&m_width, sizeof (int));
1417  OFile.write((char*)&m_height, sizeof (int));
1418  OFile.write((char*)l_map, m_width*m_height*sizeof (int));
1419  OFile.close();
1420 }
1421 //-----------------------------------------------------------------------------------------------------------------------------
1422 
1423 
1426  DumpTreatCounters( l_map_dump_treatcounts_file.value() );
1427  }
1428 
1429 #ifdef __RECORDFARMEVENTS
1430  m_farmeventfile->close();
1431  delete m_farmeventfile;
1432 #endif
1433 
1434  for ( unsigned int i = 0; i < m_elems.size(); i++ )
1435  delete m_elems[ i ];
1436 
1437  free( l_vegtype_areas );
1438  delete m_land;
1439  //delete g_rotation;
1440  delete g_crops;
1441  delete g_letype;
1442  delete g_weather;
1443  delete g_date;
1444  delete g_pest;
1446  {
1447  delete m_RodenticideManager;
1448  delete m_RodenticidePreds;
1449  }
1450  delete m_FarmManager;
1451  delete g_msg; // Must be last.
1452 }
1453 //-----------------------------------------------------------------------------------------------------------------------------
1454 
1456 {
1461  if(cfg_OptimisingFarms.value()){
1462  this->m_FarmManager->PrintFinalResults();
1463  }
1464 }
1465 //-----------------------------------------------------------------------------------------------------------------------------
1466 
1467 void Landscape::Tick( void ) {
1476  g_date->Tick();
1477  g_weather->Tick();
1478 
1479  // Remember todays LAItotal for veg elements
1480  for (unsigned int i = 0; i < m_elems.size(); i++) {
1481  m_elems[ i ]->StoreLAItotal();
1482  }
1483 
1484  // Update the growth curve phases if needed.
1485  if (g_date->JanFirst()) {
1486  if (g_rand_uni() > 0.5) {
1487  m_FarmManager->SetSpilledGrain( true );
1488  }
1489  else m_FarmManager->SetSpilledGrain( false );
1490  for (unsigned int i = 0; i < m_elems.size(); i++) {
1491  m_elems[ i ]->SetGrowthPhase( janfirst );
1492  }
1493  }
1494  else if (g_date->MarchFirst()) {
1495  for (unsigned int i = 0; i < m_elems.size(); i++) {
1496  m_elems[ i ]->SetGrowthPhase( marchfirst );
1497  m_elems[i]->SetStubble(false);
1498  }
1499  // Check and see if the pesticide engine flag should be set
1500  if (l_pest_enable_pesticide_engine.value() && (SupplyYearNumber() >= cfg_productapplicstartyear.value()) && (SupplyYearNumber() <= cfg_productapplicendyear.value()))
1501  m_toxShouldSpray = true;
1502  else m_toxShouldSpray = false;
1503  }
1504 
1505 
1506  // Grow the green stuff and let the bugs have some too.
1507  for (unsigned int i = 0; i < m_elems.size(); i++) {
1508  m_elems[ i ]->Tick();
1509  m_elems[ i ]->DoDevelopment();
1510  }
1511 
1512  //call ActualProfit function, then save this year's crop prices - for the next year's expected results calculation, then change price
1513  if (cfg_OptimisingFarms.value()) {
1514  if (!cfg_OptimiseBedriftsmodelCrops.value()) { //do this just in almass crop mode
1515 
1516  if (g_date->DayInYear() == g_date->DayInYear( 1, 03 ) && g_date->GetYearNumber()>1) { //March 1st - do the accounting; 1 corresponds to 0 in the visual version year counter.
1517 
1518  m_FarmManager->ActualProfit();
1519 
1520  //print the m_cropTotals
1521  ofstream ofile2( "CropDistribution.txt", ios::app );
1522  // the distibution of crops from last year!
1523  int last_year = g_date->GetYearNumber() - 1;
1524  ofile2 << last_year << '\t';
1525  for (int c = 0; c < m_FarmManager->pm_data->Get_noCrops(); c++) ofile2 << m_FarmManager->Get_cropTotals( c ) << '\t';
1526  ofile2 << endl;
1527  //restart the m_cropTotals:
1528  for (int i = 0; i < (int)m_FarmManager->Get_cropTotals_size(); i++) {
1529  m_FarmManager->Set_cropTotals( i, 0 );
1530  }
1531 
1532  if (g_date->GetYearNumber() > 7) { //it's been 6 years since the first accounting was carried out (5 would be enough, but exclude one year to avoid start up effects)
1533  m_FarmManager->Save_last_years_crops_for_farms(); //saves m_rotational_crops in m_rotational_crops_visible
1534  m_FarmManager->ChooseDecisionMode_for_farms();
1535  }
1536 
1537  }
1538 
1539  //save the last year crop price;
1540  if (g_date->GetYearNumber() > 1 && g_date->DayInYear() == g_date->DayInYear( 1, 03 )) {
1541  for (int f = 0; f < (toof_Foobar * tos_Foobar); f++) { //need to save the price for all farm types and soil types, so just run through the whole vector;
1542  int no_crops = m_FarmManager->pm_data->Get_cropTypes_almass_size();
1543  for (int c = 0; c < no_crops; c++) {
1544  double old_price = m_FarmManager->pm_data->Get_sellingPrice( tov_Undefined*f + m_FarmManager->pm_data->Get_cropTypes_almass( c ) ); //get the current price
1545  m_FarmManager->pm_data->Set_sellingPrice_lastyr( old_price, tov_Undefined*f + m_FarmManager->pm_data->Get_cropTypes_almass( c ) ); //save it
1546  }
1547  }
1548  }
1549  //-----
1550 
1551 
1552  if (cfg_MaizeEnergy.value()) { //modify energy maize price
1553 
1554  if (g_date->DayInYear() == g_date->DayInYear( 1, 03 ) && g_date->GetYearNumber() != 0) { //print the price once a year
1555  ofstream ofileEM( "Maize_energy_price_yearly.txt", ios::app );
1556  int year = g_date->GetYearNumber();
1557  ofileEM << year << '\t';
1558  ofileEM << m_FarmManager->pm_data->Get_sellingPrice( tov_Maize );
1559  ofileEM << endl;
1560  ofileEM.close();
1561  }
1562 
1563  //changing price according to the input file EM_price.txt
1564  if (g_date->DayInYear() == g_date->DayInYear( 1, 03 ) && g_date->GetYearNumber() > 0) {//exclude the hidden year
1565  for (int f = 0; f < (toof_Foobar * tos_Foobar); f++) { //need to change the price for all farm types and soil types
1566  double new_price = m_FarmManager->pm_data->Get_emaize_price( g_date->GetYearNumber() );
1567  m_FarmManager->pm_data->Set_sellingPrice( new_price, tov_Undefined*f + tov_Maize );
1568  }
1569  }
1570  }// if energy maize
1571 
1572  }//almass crop mode
1573  }//optimising farms
1574 
1575  /* Testing removal - may cause issues with increasing or decreasing permanent vegetation
1576  if ( g_date->DayInYear() == g_date->DayInYear( 1, 11 ) ) {
1577  // Set all elements to smooth curve transition mode at November 1st.
1578  for ( unsigned int i = 0; i < m_elems.size(); i++ ) {
1579  m_elems[ i ]->ForceGrowthInitialize();
1580  }
1581  //save the day degrees - used for crops that are not harvested instead of biomass to determine yield; done on Nov 1st
1582  //m_FarmManager->SetDD (SupplyTempPeriod( g_date->Date(), 245)); // from Nov 1 - 245 days back till March 1;
1583  //DegreesDump();
1584  }
1585  */
1586 
1587  if (cfg_pesticidemapon.value())
1590  if (g_date->GetDayInMonth() == 1)
1591  //if (g_date->DayInYear() == cfg_pesticidemapdayinyear.value())
1592  if (cfg_pesticidemaptype.value()) m_PesticideMap->DumpPMapI();
1593  else {
1594  m_PesticideMap->DumpPMapI();
1595  m_PesticideMap->DumpPMapH();
1596  m_PesticideMap->DumpPMapF();
1597  }
1598 
1599  // Put the farmers to work.
1600  m_FarmManager->FarmManagement();
1601 
1602 
1603  // Update pesticide information.
1604  g_pest->Tick();
1605 
1606  // Update rodenticide information if we are using this
1607  if (cfg_rodenticide_enable.value()) {
1608  m_RodenticideManager->Tick();
1609  m_RodenticidePreds->Tick();
1610  }
1611 
1612  // Dump event information if necessary
1616  //EventDumpPesticides( l_map_dump_event_x1.value(), l_map_dump_event_y1.value() );
1617 
1618 
1619 }
1620 //-----------------------------------------------------------------------------------------------------------------------------
1621 
1623 {
1624  // All polygon manipulation is settled now we need to give the polygons some information about themselves
1625  // This takes a little time but save time later one
1626  cout << "Setting max min polygon extents" << endl;
1627  int mwidth = m_land->MapWidth();
1628  int mheight = m_land->MapHeight();
1629  for ( int x = 0; x < mwidth; x++ ) {
1630  for ( int y = 0; y < mheight; y++ ) {
1631  int polyindex = m_land->Get( x, y );
1632  // Mark that we have seen this polygon.
1633  unsigned int ele_ref= polyindex;
1634  if (m_elems[m_polymapping[ele_ref]]->GetMaxX() < x) m_elems[m_polymapping[ele_ref]]->SetMaxX(x);
1635  if (m_elems[m_polymapping[ele_ref]]->GetMaxY() < y) m_elems[m_polymapping[ele_ref]]->SetMaxY(y);
1636  if (m_elems[m_polymapping[ele_ref]]->GetMinX() > x) m_elems[m_polymapping[ele_ref]]->SetMinX(x);
1637  if (m_elems[m_polymapping[ele_ref]]->GetMinY() > y) m_elems[m_polymapping[ele_ref]]->SetMinY(y);
1638  m_elems[m_polymapping[ele_ref]]->SetMapValid(true);
1639  }
1640  }
1641 }
1642 //-----------------------------------------------------------------------------------------------------------------------------
1643 
1644 void Landscape::VegDump( int x, int y ) {
1645  FILE * vfile=fopen("VegDump.txt", "a" );
1646  if (!vfile) {
1647  g_msg->Warn( WARN_FILE, "Landscape::VegDump(): Unable to open file", "VegDump.txt" );
1648  exit( 1 );
1649  }
1650  //int year = SupplyYearNumber();
1651  int year = g_date->GetYear();
1652  int day = SupplyDayInYear();
1653  double hei = SupplyVegHeight( x, y );
1654  double bio = SupplyVegBiomass( x, y );
1655  double cover = SupplyVegCover( x, y );
1656  double density = bio / ( hei + 1 );
1657  double weeds = SupplyWeedBiomass( x, y );
1658  double insects = SupplyInsects( x, y );
1659  double LATotal = SupplyLATotal(x, y);
1660  double LAGreen = SupplyLAGreen(x, y);
1661  double digest = SupplyVegDigestability(x, y);
1662  double GreenBiomass = SupplyGreenBiomass(x,y);
1663  double DeadBiomass = SupplyDeadBiomass(x,y);
1664  int grazed = SupplyGrazingPressure(x, y);
1665  double ggraze = GetActualGooseGrazingForage(m_land->Get(x, y), gs_Pinkfoot);
1666  int VegType = BackTranslateVegTypes(SupplyVegType(x, y));
1667  double grain = SupplyBirdSeedForage(x, y);
1668 
1669  fprintf( vfile, "%d\t%d\t%g\t%g\t%d\t%g\t%g\t%g\t%i\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n", year, day, hei, bio, grazed, density, cover, weeds, VegType, insects, LATotal, LAGreen, digest, GreenBiomass, DeadBiomass, ggraze, grain );
1670  /*
1671  y += 100;
1672  x += 100;
1673  hei = SupplyVegHeight( x, y );
1674  bio = SupplyVegBiomass( x, y );
1675  cover = SupplyVegCover( x, y );
1676  density = bio / ( hei + 1 );
1677  weeds = SupplyWeedBiomass( x, y );
1678  VegType = SupplyVegType( x, y );
1679  insects = SupplyInsects( x, y );
1680  digest = SupplyVegDigestability(x,y);
1681  fprintf( vfile, "%g\t%g\t%g\t%g\t%g\t%i\t%g\t%g\n", hei, bio, density, cover, weeds, VegType, insects, digest );
1682  */
1683  fclose( vfile );
1684 }
1685 //-----------------------------------------------------------------------------------------------------------------------------
1686 
1688 
1689  ofstream ofile ("Daydegrees.txt", ios::app);
1690  //print degrees
1691  ofile << m_FarmManager->GetDD();
1692  ofile << endl;
1693  ofile.close();
1694 }
1695 //-----------------------------------------------------------------------------------------------------------------------------
1696 
1697 void Landscape::EventDump( int x1, int y1, int x2, int y2 ) {
1698  FILE * vfile=fopen("EventDump.txt", "a" );
1699  if (!vfile) {
1700  g_msg->Warn( WARN_FILE, "Landscape::EventDump(): Unable to open file", "EventDump.txt" );
1701  exit( 1 );
1702  }
1703  FarmToDo event;
1704  int i = 0;
1705  int day = SupplyDayInYear();
1706  fprintf( vfile, "%d: ", day );
1707  while ( ( event = ( FarmToDo )SupplyLastTreatment( x1, y1, & i ) ) != sleep_all_day ) {
1708  fprintf( vfile, "%d ", event );
1709  }
1710  i = 0;
1711  fprintf( vfile, " - " );
1712  while ( ( event = ( FarmToDo )SupplyLastTreatment( x2, y2, & i ) ) != sleep_all_day ) {
1713  fprintf( vfile, "%d ", event );
1714  }
1715  fprintf( vfile, "\n" );
1716  fclose( vfile );
1717 }
1718 //-----------------------------------------------------------------------------------------------------------------------------
1719 
1720 void Landscape::EventDumpPesticides( int x1, int y1 ) {
1721  FILE * vfile=fopen("EventDump.txt", "a" );
1722  if (!vfile) {
1723  g_msg->Warn( WARN_FILE, "Landscape::EventDump(): Unable to open file", "EventDump.txt" );
1724  exit( 1 );
1725  }
1726  FarmToDo a_event;
1727  int i = 0;
1728  int day = this->SupplyGlobalDate();
1729  int herb = 0;
1730  int fung = 0;
1731  int ins = 0;
1732  while ( ( a_event = ( FarmToDo )SupplyLastTreatment( x1, y1, & i ) ) != sleep_all_day ) {
1733  if (a_event == herbicide_treat )
1734  {
1735  herb++;
1736  }
1737  else if (a_event == fungicide_treat ) fung++;
1738  else if (a_event == insecticide_treat) ins++;
1739  }
1740  if (herb+fung+ins >0 ) fprintf( vfile, "%d\t%d\t%d\t%d\n", day, herb, fung, ins );
1741  i = 0;
1742  fclose( vfile );
1743 }
1744 //-----------------------------------------------------------------------------------------------------------------------------
1745 
1746 void Landscape::PolysValidate( bool a_exit_on_invalid ) {
1747  // First loop just sets the MapValid as false (and checks for a major screw-up if this elemenent does not exist even in the list
1748  for ( unsigned int i = 0; i < m_elems.size(); i++ ) {
1749  m_elems[ i ]->SetMapValid( false );
1750  if ( m_polymapping[ m_elems[ i ]->GetPoly() ] == -1 ) {
1751  char l_err[ 20 ];
1752  sprintf( l_err, "%d", m_elems[ i ]->GetPoly() );
1753  g_msg->Warn( WARN_FILE, "Landscape::PolysValidate(): Invalid polymapping ", l_err );
1754  exit( 1 );
1755  }
1756  }
1757  // Now go through the whole map and for each polygon found set MapValid as true.
1758  SetPolyMaxMinExtents();
1759  if ( a_exit_on_invalid ) {
1760  for ( unsigned int i = 0; i < m_elems.size(); i++ ) {
1761  if ( !m_elems[ i ]->GetMapValid() ) {
1762  char l_err[ 20 ];
1763  sprintf( l_err, "%d", m_elems[ i ]->GetPoly() );
1764  g_msg->Warn( WARN_FILE, "Landscape::PolysValidate(): Invalid polygon ", l_err );
1765  exit( 0 );
1766  }
1767  }
1768  }
1769 }
1770 //-----------------------------------------------------------------------------------------------------------------------------
1771 
1773 {
1777  bool didsomething = false;
1778  vector < LE * > l_temp;
1779  cout << "Tidying up the polygon map in PolysRemoveInvalid" << endl;
1780  unsigned int sz= (int) m_elems.size();
1781  for ( unsigned int i = 0; i < sz; i++ ) {
1782  if ( m_elems[ i ]->GetMapValid() ) {
1783  unsigned int j = (int) l_temp.size();
1784  l_temp.resize( j + 1 );
1785  l_temp[ j ] = m_elems[ i ];
1786  } else {
1787  // cout << "Deleted m_elems index:" << m_polymapping[ m_elems[ i ]->GetPoly() ] << " Polynumber :" << m_elems[ i ]->GetPoly() << BackTranslateEleTypes(m_elems[ i ]->GetElementType()) << endl;
1788  m_polymapping[ m_elems[ i ]->GetPoly() ] = -1;
1789  delete m_elems[ i ];
1790  didsomething = true;
1791  }
1792  }
1793 
1794  for ( unsigned int i = 0; i < l_temp.size(); i++ ) {
1795  m_elems[ i ] = l_temp[ i ];
1796  }
1797  m_elems.resize( l_temp.size() );
1798  RebuildPolyMapping();
1799  return didsomething;
1800 }
1801 //-----------------------------------------------------------------------------------------------------------------------------
1802 
1803 void Landscape::PolysDump(const char * a_filename)
1804 {
1805  ofstream outf(a_filename, ios::out);
1806  int l_num_polys = 0;
1807 
1808  if (!outf.is_open()) {
1809  g_msg->Warn(WARN_FILE, "Landscape::PolysDump(): Unable to open file", a_filename);
1810  exit(1);
1811  }
1812 
1813  // Count up number if active polygons in our list.
1814  unsigned sz = (unsigned)m_elems.size();
1815  for (unsigned int i = 0; i < sz; i++) {
1816  if (m_elems[i]->GetMapValid())
1817  l_num_polys++;
1818  }
1819 
1820  outf << l_num_polys << endl;
1821  outf << "PolyType" << '\t' << "PolyRefNum" << '\t' << "Area" << '\t' << "FarmRef" << '\t' << "UnSprayedMarginRef" << '\t' << "SoilType" << '\t' << "Openness" << '\t' << "CentroidX" << '\t' << "CentroidY" << endl;
1822 
1823  /*
1824  if ( l_map_renumberpolys.value() )
1825  {
1826  RenumberPolys( true );
1827  }
1828  */
1829  // Now we can output the file
1830  for (unsigned int i = 0; i < m_elems.size(); i++)
1831  {
1832  if (m_elems[i]->GetMapValid())
1833  {
1834  outf << m_elems[i]->GetALMaSSEleType() << '\t' << m_elems[i]->GetPoly() << '\t' << m_elems[i]->GetArea() << '\t' <<
1835  m_elems[i]->GetOwnerFile() << '\t' << m_elems[i]->GetUnsprayedMarginPolyRef() << '\t' << m_elems[i]->GetSoilType() << '\t' << m_elems[i]->GetOpenness()
1836  << '\t' << m_elems[i]->GetCentroidX() << '\t' << m_elems[i]->GetCentroidY() << endl;
1837  }
1838  }
1839  outf.close();
1840 }
1841 //-----------------------------------------------------------------------------------------------------------------------------
1842 
1843 /*
1844 void Landscape::RenumberPolys( bool a_checkvalid)
1845 {
1846  // First need a second list of polyrefs
1847  vector < int > oldpolys;
1848  oldpolys.resize( m_elems.size() );
1849  if (a_checkvalid)
1850  {
1851  for ( unsigned int i = 0; i < m_elems.size(); i++ )
1852  {
1853  if ( m_elems[ i ]->GetMapValid() )
1854  {
1855  oldpolys[ i ] = m_elems[ i ]->GetPoly();
1856  // Need to reset the poly number
1857  m_elems[ i ]->SetPoly( i );
1858  }
1859  }
1860  }
1861  else
1862  {
1863  for ( unsigned int i = 0; i < m_elems.size(); i++ )
1864  {
1865  oldpolys[ i ] = m_elems[ i ]->GetPoly();
1866  // Need to reset the poly number
1867  m_elems[ i ]->SetPoly( i );
1868  }
1869  }
1870 
1871  // Now need to go through and set the unsprayed margin poly refs
1872  for ( unsigned int j = 0; j < m_elems.size(); j++ )
1873  {
1874  int um = m_elems[ j ]->GetUnsprayedMarginPolyRef();
1875  if ( um != -1 )
1876  {
1877  unsigned ff = (int) oldpolys.size();
1878  for ( unsigned int u = 0; u < ff; u++ )
1879  {
1880  if ( oldpolys[ u ] == um )
1881  {
1882  m_elems[ j ]->SetUnsprayedMarginPolyRef( u );
1883  break;
1884  }
1885  }
1886  }
1887  }
1888 }
1889 //-----------------------------------------------------------------------------------------------------------------------------
1890 */
1891 
1892 void Landscape::ReadPolys2(const char * a_polyfile)
1893 {
1900  // Need to figure out if the farms are already renumbered - as the Farm manager
1901  bool farmsrenum = m_FarmManager->GetIsRenumbered();
1902 
1903  int NoPolygons;
1904  string rubbish = ""; //put here the names of the parameters;
1905  ifstream ifile(a_polyfile);
1906  if (!ifile.is_open()) {
1907  g_msg->Warn(WARN_FILE, "Landscape::ReadPolys(): Unable to open file", a_polyfile);
1908  std::exit(1);
1909  }
1910  char error_num[20];
1911  // First read the number of polygons
1912  ifile >> NoPolygons;
1913  m_elems.resize(NoPolygons);
1915  for (int i = 0; i < 9; i++){ ifile >> rubbish; }
1919  int np = NoPolygons;
1920  if (NoPolygons < 10000) np = 10000; // this is just to cope with old maps with < 10000 polygons that do not follow the rules for new maps
1921  m_polymapping.resize(np * 2);
1922 
1923  // Set all mappings to unused.
1924  for (int i = 0; i < np * 2; i++) {
1925  m_polymapping[i] = -1;
1926  }
1927 
1928  int ElemIndex = 0;
1929 
1930  for (int x = 0; x < NoPolygons; x++)
1931  {
1932  int PolyNum, Owner, PolyType, RealPolyType, URef, SoilType, openness, Centroid_x, Centroid_y;
1934  float Area;
1935  ifile >> PolyType >> PolyNum >> Area >> Owner >> URef >> SoilType >> openness >> Centroid_x >> Centroid_y;
1936  // Here we make some tests to check input validity
1937  if ((SoilType > 16) || (PolyNum<0))
1938  {
1939  std::sprintf(error_num, "%d", NoPolygons);
1940  g_msg->Warn(WARN_FILE, "Landscape::ReadPolys(): Polygon file empty before "
1941  "reading number of specified polygons (old polygon file format?):", error_num);
1942  std::exit(1);
1943  }
1944 
1945  // Owner is the farm number or -1. If farms have not been renumbered then this needs mapped to the index in the list of farms.
1946  // Because we create this sequentially in Farm.cpp we have a constant index.
1947  if ((-1 != Owner) && !farmsrenum)
1948  {
1949  // Need to replace the Owner with the new renumbered ref.
1950  Owner = m_FarmManager->GetRenumberedFarmRef(Owner);
1951  }
1952 
1953  RealPolyType = PolyType;
1955  if (PolyType == 150)
1956  {
1957  PolyType = l_map_chameleon_replace_num.value();
1958  }
1959 
1960  Type = g_letype->TranslateEleTypes(PolyType);
1961  if (Type == tole_Missing)
1962  {
1963  m_DoMissingPolygonsManipulations = true;
1964  }
1965  if (-1 == m_polymapping[PolyNum])
1966  {
1967  // First time we have encountered this polygon number.
1968  // Borders are not mapped in this list.
1969  m_polymapping[PolyNum] = ElemIndex;
1970  LE * newland = NewElement(Type);
1971  m_elems[ElemIndex++] = newland;
1972  newland->SetPoly(PolyNum);
1973  newland->SetMapIndex(PolyNum);
1974  newland->SetArea(floor(0.5 + Area));
1975  newland->SetALMaSSEleType(RealPolyType);
1976  newland->SetSoilType(SoilType);
1977  newland->SetUnsprayedMarginPolyRef(URef);
1978  newland->SetCentroid(Centroid_x,Centroid_y);
1979  newland->SetOpenness(openness);
1980  // Just for fun, or maybe because we might need it later, remember the actual largest polynum used
1981  if (PolyNum>m_LargestPolyNumUsed) m_LargestPolyNumUsed = PolyNum;
1982  // Now set any centroid or openness recalcuation flags
1983  if ((Centroid_x < 0) || (Centroid_y < 0)) m_NeedCentroidCalculation= true;
1984  if (openness < 0) m_NeedOpennessCalculation = true;
1985  // Two types of possible errors: Landscape element that is a field,
1986  // but doesn't belong to a farm, or a farm element not of type field.
1987  // Check for both cases.
1988  if (-1 == Owner && (Type == tole_Field || Type == tole_YoungForest || Type == tole_Orchard || Type == tole_PermPastureTussocky || Type == tole_PermPasture || Type == tole_PermanentSetaside || Type == tole_PermPastureLowYield || Type == tole_WoodyEnergyCrop || Type == tole_Vildtager || Type == tole_PlantNursery)) {
1989  // No owner but field polygon.
1990  sprintf(error_num, "%d", PolyNum);
1991  g_msg->Warn(WARN_FILE, "Landscape::ReadPolys(): Farm polygon does not belong to a farm:", error_num);
1992  exit(1);
1993  }
1994  if (-1 != Owner && Type != tole_Field && Type != tole_YoungForest && Type != tole_Orchard && Type != tole_PermPastureTussocky && Type != tole_PermPasture && Type != tole_PermanentSetaside && Type != tole_PermPastureLowYield && Type != tole_WoodyEnergyCrop && Type != tole_Vildtager && Type != tole_PlantNursery) {
1995  // An owner but not field elements.
1996  sprintf(error_num, "%d", PolyNum);
1997  g_msg->Warn(WARN_FILE, "Landscape::ReadPolys(): Farm polygon does not have element type tole_Field:", error_num);
1998  exit(1);
1999  }
2000 
2001  if (-1 != Owner)
2002  {
2003  m_FarmManager->ConnectFarm(Owner);
2004  m_FarmManager->AddField(Owner, newland, Owner);
2005  if (g_map_le_borders.value())
2006  {
2007  if (random(100) < g_map_le_border_chance.value())
2008  {
2009  // This is a farm element, so signal adding a border.
2010  newland->SetBorder((LE *)1);
2011  }
2012  }
2013  // Code to generate unsprayed margins....
2014  if (newland->GetElementType() == tole_Field)
2015  {
2017  {
2018  if (random(100) < g_map_le_unsprayedmargins_chance.value())
2019  {
2020  // This is a farm field, so signal adding a margin
2021  newland->SetUnsprayedMarginPolyRef(1);
2022  }
2023  }
2024  }
2025  // ..to here
2026  }
2027  }
2028  else {
2029  sprintf(error_num, "%d", PolyNum);
2030  g_msg->Warn(WARN_FILE, "Landscape::ReadPolys(): Duplicate polygon in file", error_num);
2031  exit(1);
2032  }
2033  }
2034  ifile.close();
2036  hb_first_free_poly_num = m_elems[NoPolygons - 1]->GetPoly() + 1;
2037 }
2038 //-----------------------------------------------------------------------------------------------------------------------------
2039 
2041  int mapwidth = m_land->MapWidth();
2042  int mapheight = m_land->MapHeight();
2043  for ( unsigned int i = 0; i < m_elems.size(); i++ ) {
2044  m_elems[i]->SetArea(0);
2045  m_elems[ i ]->m_squares_in_map=0;
2046  }
2047 
2048  for ( int x = 0; x < mapwidth; x++ ) {
2049  for ( int y = 0; y < mapheight; y++ ) {
2050  int l_ele = m_land->Get( x, y );
2051  m_elems[ l_ele ]->m_squares_in_map++;
2052  }
2053  }
2054 }
2055 //-----------------------------------------------------------------------------------------------------------------------------
2056 
2058 {
2059  cout << "In Landscape::Landscape() Polygon renumber." << endl;
2060  for (unsigned int i = 0; i < m_elems.size(); i++)
2061  {
2062  // Need to reset the poly number
2063  int index = m_elems[i]->GetMapIndex(); // This is the number currently in the map matrix
2064  m_elems[i]->SetPoly(index); // The map index and the polygon number are now one and the same
2065  m_polymapping[index] = i; // The polymapping is now linked via index to the m_elems index (i)
2066  }
2067  m_LargestPolyNumUsed = (int) m_elems.size()-1;
2068  g_msg->Warn(WARN_FILE, "Landscape::Landscape() ""Map to be dumped due to polygon renumber", "");
2069 }
2070 //-----------------------------------------------------------------------------------------------------------------------------
2071 
2072 void Landscape::ForceArea( void ) {
2073  int l_area_sum = 0;
2074 
2075  for ( unsigned int i = 0; i < m_elems.size(); i++ ) {
2076  m_elems[ i ]->SetArea( ( double )m_elems[ i ]->m_squares_in_map );
2077  if ( m_elems[ i ]->m_squares_in_map > 0 ) {
2078  m_elems[ i ]->SetMapValid( true );
2079  l_area_sum += m_elems[ i ]->m_squares_in_map;
2080  }
2081  }
2082 
2083  if ( l_area_sum != m_width * m_height ) {
2084  g_msg->Warn( WARN_BUG, "Landscape::ForceArea(): Polygon areas doesn't"" sum up to map area!", "" );
2085  exit( 1 );
2086  }
2087 }
2088 //-----------------------------------------------------------------------------------------------------------------------------
2089 
2091 {
2092  bool found; // the flag for something left to work with
2093  int mapwidth = m_land->MapWidth();
2094  int mapheight = m_land->MapHeight();
2095  int counter = 0;
2096  do
2097  {
2098  found = false; counter++;
2099  for (int x = 1; x < mapwidth-1; x++)
2100  {
2101  for (int y = 1; y < mapheight-1; y++)
2102  {
2103  int apoly = m_land->Get(x,y);
2104  if (m_elems[m_polymapping[apoly]]->GetElementType() == tole_Missing)
2105  {
2106  m_land->MissingCellReplace(x, y, true);
2107  }
2108  }
2109  }
2110  counter++;
2111  } while (counter<50);
2112  // Now we only have the edges to deal with
2113  for (int x = 0; x < mapwidth; x++)
2114  {
2115  for (int y = 0; y < mapheight; y++)
2116  {
2117  int apoly = m_land->Get(x, y);
2118  if (m_elems[m_polymapping[apoly]]->GetElementType() == tole_Missing)
2119  {
2120  found = true;
2121  counter++;
2122  m_land->MissingCellReplaceWrap(x, y, true);
2123  }
2124  }
2125  }
2126  // Now we the ones that are not next to fields to deal with
2127 }
2128 //-----------------------------------------------------------------------------------------------------------------------------
2129 
2136  cout << "In Change Map Mapping" << endl;
2137  int mapwidth = m_land->MapWidth();
2138  int mapheight = m_land->MapHeight();
2139  int pest_map_width = mapwidth >> PEST_GRIDSIZE_POW2;
2140  if ( mapwidth & ( PEST_GRIDSIZE - 1 ) ) pest_map_width++;
2141  int oldindex = -1;
2142  for ( int x = 0; x < mapwidth; x++ )
2143  {
2144  for ( int y = 0; y < mapheight; y++ )
2145  {
2146  int polynum = m_land->Get( x, y ); // the polyref e.g. = 1, m_polymapping[ polynum ] = 0
2147  m_elems[ m_polymapping[ polynum ]]->SetMapIndex( m_polymapping[ polynum ] ); // Here we set index in the map to the index in elements, i.e. 0
2148  m_elems[ m_polymapping[ polynum ]]->SetMapValid( true );
2149  // Do the translation.
2150  m_land->Put( x, y, m_polymapping[ polynum ] ); // and now we write this to the map, i.e. 0
2151  // This coordinate is now valid. Throw these coordinates into
2152  // the associated landscape element.
2153  int index = m_polymapping[ SupplyPolyRef( x, y ) ];
2154  if ( index != oldindex )
2155  {
2156  m_elems[ index ]->SetValidXY( x, y );
2157  int l_x = x >> PEST_GRIDSIZE_POW2;
2158  int l_y = y >> PEST_GRIDSIZE_POW2;
2159  int pref = l_y * pest_map_width + l_x;
2160  m_elems[ index ]->SetPesticideCell( pref );
2161  oldindex = index;
2162  }
2163  }
2164  }
2165  RebuildPolyMapping();
2166 /*
2167 // Check that all of the polygons are mentioned in the map.
2168  if ( l_map_check_polygon_xref.value() )
2169  {
2170  for ( unsigned int i = 0; i < m_elems.size(); i++ )
2171  {
2172  if ( !m_elems[ i ]->GetMapValid() ) {
2173  char poly[ 20 ];
2174  sprintf( poly, "%d", m_elems[ i ]->GetPoly() );
2175  g_msg->Warn( WARN_FILE, "Landscape::ChangeMapMapping(): ""Polygon number referenced but not in map file: ", poly );
2176  exit( 1 );
2177  }
2178  }
2179  }
2180 */
2181 }
2182 //-----------------------------------------------------------------------------------------------------------------------------
2183 
2185 {
2199  // To be sure we first count the map squares
2200  CountMapSquares();
2201  // Then force the area to match the counted squares
2202  ForceArea();
2203  // Next find polygons that don't match other rules and are single cells - remove these
2204  int removed = 0;
2205  for (int i = 0; i < m_elems.size(); i++)
2206  {
2207  TTypesOfLandscapeElement tole = m_elems[i]->GetElementType();
2208  int area = int(m_elems[i]->GetArea());
2209  if (area == 1)
2210  {
2211  switch (tole)
2212  {
2213  case tole_FieldBoundary:
2214  case tole_HedgeBank:
2215  case tole_Hedges:
2216  case tole_IndividualTree:
2217  case tole_MetalledPath:
2218  case tole_River:
2219  case tole_RiversidePlants:
2220  case tole_RiversideTrees:
2221  case tole_RoadsideSlope:
2222  case tole_RoadsideVerge:
2223  case tole_SmallRoad:
2224  case tole_StoneWall:
2225  case tole_Fence:
2226  case tole_Stream:
2227  case tole_Track:
2229  case tole_WaterBufferZone:
2230  // These could be part of a bigger polygon, so leave them alone for now.
2231  break;
2232  default:
2233  // Get rid of this one.
2234  APoint pt = m_elems[i]->GetCentroid();
2235  // Just check that the centroid is correct
2236  int poly = m_elems[i]->GetPoly();
2237  if (poly != i)
2238  {
2239  g_msg->Warn(WARN_FILE, "Landscape::RemoveSmallPolygons: Centroid not in polygon: ", i);
2240  exit(99);
2241  }
2242  // The next line just fixes the map, and replaces the cell value
2243  if (m_land->CellReplacementNeighbour(pt.m_x, pt.m_y, poly) == 1) {
2244  // Now we need to remove the polygon. This means we must also rebuild the map later.
2245  m_elems[i]->SetMapValid(false);
2246  removed++;
2247  }
2248  }
2249  }
2250  // Field removal below 100m2
2251  else if (tole == tole_Field)
2252  {
2253  if (area < 100) {
2254  // Need to copy the useful information to new grassland element and switch that one in, removing the field.
2255  NaturalGrassDry* grass = new NaturalGrassDry;
2256  grass->DoCopy(m_elems[i]);
2257  grass->SetALMaSSEleType(g_letype->BackTranslateEleTypes(tole_NaturalGrassDry));
2258  grass->SetElementType(tole_NaturalGrassDry);
2259  grass->SetOwner(NULL,-1,-1);
2260  delete m_elems[i]; // remove the old LE
2261  m_elems[i] = dynamic_cast<LE*>(grass);
2262  }
2263  }
2264  }
2265  PolysRemoveInvalid();
2266  ChangeMapMapping();
2267  return removed;
2268 }
2269 //-----------------------------------------------------------------------------------------------------------------------------
2270 
2272  // This does not need to be efficient, just do the job
2273  for (int x=1; x<(m_width-1); x++)
2274  for (int y=1; y<(m_height-1); y++)
2275  {
2276  TTypesOfLandscapeElement tole = SupplyElementType(x,y);
2277  if ((tole==tole_FieldBoundary) || (tole==tole_HedgeBank) || (tole==tole_Hedges))
2278  {
2279  if ( SupplyElementType(x-1,y-1) == tole_Field)
2280  {
2281  // Set the x,y location to be this field
2282  int fieldindex = SupplyPolyRefIndex(x-1,y-1);
2283  m_land->Put( x, y, fieldindex );
2284 
2285  }
2286  else
2287  if ( SupplyElementType(x-1,y) == tole_Field)
2288  {
2289  // Set the x,y location to be this field
2290  int fieldindex = SupplyPolyRefIndex(x-1,y);
2291  m_land->Put( x, y, fieldindex );
2292 
2293  }
2294  else
2295  if ( SupplyElementType(x-1,y+1) == tole_Field)
2296  {
2297  // Set the x,y location to be this field
2298  int fieldindex = SupplyPolyRefIndex(x-1,y+1);
2299  m_land->Put( x, y, fieldindex );
2300 
2301  }
2302  else
2303  if ( SupplyElementType(x,y-1) == tole_Field)
2304  {
2305  // Set the x,y location to be this field
2306  int fieldindex = SupplyPolyRefIndex(x,y-1);
2307  m_land->Put( x, y, fieldindex );
2308 
2309  }
2310  else
2311  if ( SupplyElementType(x,y+1) == tole_Field)
2312  {
2313  // Set the x,y location to be this field
2314  int fieldindex = SupplyPolyRefIndex(x,y+1);
2315  m_land->Put( x, y, fieldindex );
2316 
2317  }
2318  else
2319  if ( SupplyElementType(x+1,y-1) == tole_Field)
2320  {
2321  // Set the x,y location to be this field
2322  int fieldindex = SupplyPolyRefIndex(x+1,y-1);
2323  m_land->Put( x, y, fieldindex );
2324 
2325  }
2326  else
2327  if ( SupplyElementType(x+1,y) == tole_Field)
2328  {
2329  // Set the x,y location to be this field
2330  int fieldindex = SupplyPolyRefIndex(x+1,y);
2331  m_land->Put( x, y, fieldindex );
2332 
2333  }
2334  else
2335  if ( SupplyElementType(x+1,y+1) == tole_Field)
2336  {
2337  // Set the x,y location to be this field
2338  int fieldindex = SupplyPolyRefIndex(x+1,y+1);
2339  m_land->Put( x, y, fieldindex );
2340 
2341  }
2342  }
2343  }
2344 }
2345 //-----------------------------------------------------------------------------------------------------------------------------
2346 
2348  int x = a_field->GetValidX();
2349  int y = a_field->GetValidY();
2350  if ( ( x == -1 ) || ( y == -1 ) ) {
2351  g_msg->Warn( WARN_BUG, "Landscape::BorderAdd(): Uninitialized border coordinate!", "" );
2352  exit( 1 );
2353  }
2354  LE * border = NewElement(a_type);
2355  a_field->SetBorder( border );
2356  m_polymapping[ hb_first_free_poly_num ] = (int) m_elems.size();
2357  m_elems.resize( m_elems.size() + 1 );
2358  m_elems[ m_elems.size() - 1 ] = border;
2359  border->SetPoly( hb_first_free_poly_num++ );
2360  border->SetArea( 0.0 );
2361  BorderScan(a_field, g_map_le_borderwidth.value());
2362 }
2363 //-----------------------------------------------------------------------------------------------------------------------------
2364 
2365 void Landscape::BorderScan( LE * a_field, int a_width )
2366 {
2370  LE * border = a_field->GetBorder(); // border is the a border object
2371  int fieldpoly = a_field->GetPoly(); // fieldpoly is the polygon number
2372  int borderpoly = border->GetPoly(); // borderpoly is the polygon number
2373  int borderindex = m_polymapping[ borderpoly ]; // borderindex is the elems index for the border
2374  int fieldindex = m_polymapping[ fieldpoly ]; // fieldindex is the elems index
2375  int test = m_land->Get(a_field->GetCentroidX(), a_field->GetCentroidY());
2376  if (test != fieldindex)
2377  {
2378  g_msg->Warn("Landscape::BorderScan - Border Scan centroid does not return correct polygon index. Index :", fieldindex);
2379  g_msg->Warn(" Returned ", test);
2380  exit(0);
2381  }
2382  int notforever = 50000;
2383  vector<APoint> listoflocs;
2388  for (int wid = 0; wid < a_width; wid++)
2389  {
2390  notforever = 50000;
2391  // These two will be modified through pointer operations in BorderStep().
2392  APoint coord(a_field->GetCentroidX(), a_field->GetCentroidY());
2393  // Find the first edge cell
2394  AxisLoop(fieldindex, &coord, random(8));
2395  while (--notforever > 0)
2396  {
2397  // Check if this position should be made into a border.
2398  if (BorderTest(fieldindex, -99, coord.m_x, coord.m_y))
2399  {
2400  // Add this pixel to the border element in the big map, but using a code for later replacement.
2401  m_land->Put(coord.m_x, coord.m_y, -99); // this puts the elems index into our map in memory
2402  listoflocs.push_back(coord);
2403  a_field->AddArea(-1.0);
2404  if (l_map_exit_on_zero_area.value() && (a_field->GetArea()<1))
2405  {
2406  char polynum[20];
2407  sprintf(polynum, "%d", a_field->GetPoly());
2408  g_msg->Warn(WARN_FILE, "Landscape::BorderScan(): Polygon reached zero area " "when adding border. Poly num: ", polynum);
2409  exit(1);
2410  }
2411  border->AddArea(1.0);
2412  border->SetMapValid(true);
2413  }
2414  // Step to next coordinate. Quit when done.
2415  if (!BorderStep(fieldindex, -99, &coord))
2416  {
2417  break;
2418  }
2419  }
2420  for (std::vector<APoint>::iterator it = listoflocs.begin(); it != listoflocs.end(); ++it)
2421  {
2422  m_land->Put((*it).m_x, (*it).m_y, borderindex);
2423  }
2424  listoflocs.clear();
2425  }
2426 }
2427 //-----------------------------------------------------------------------------------------------------------------------------
2428 
2429 bool Landscape::StepOneValid( int a_polyindex, int a_x, int a_y, int a_step )
2430 {
2431  int index;
2432  int x_add[ 8 ] = { 1*a_step, 1*a_step, 0, -1*a_step, -1*a_step, -1*a_step, 0, 1*a_step };
2433  int y_add[ 8 ] = { 0, -1*a_step, -1*a_step, -1*a_step, 0, 1*a_step, 1*a_step, 1*a_step };
2434  int width = m_land->MapWidth();
2435  int height = m_land->MapHeight();
2436  // Scan anti-clockwise from center pixel coordinate.
2437  for ( unsigned int i = 0; i < 8; i++ ) {
2438  if ( ( a_x + x_add[ i ] < width ) && ( a_x + x_add[ i ] >= 0 ) && ( a_y + y_add[ i ] < height ) && ( a_y + y_add[ i ] >= 0 ) )
2439  {
2440  index = m_land->Get( a_x + x_add[ i ], a_y + y_add[ i ] );
2441  if ( index == a_polyindex )
2442  {
2443  m_elems[a_polyindex]->SetValidXY(a_x + x_add[ i ], a_y + y_add[ i ]);
2444  return true;
2445  }
2446  }
2447  }
2448  return false;
2449 }
2450 //-----------------------------------------------------------------------------------------------------------------------------
2451 
2452 bool Landscape::BorderTest( int a_fieldindex, int a_borderindex, int a_x, int a_y )
2453 {
2454  int index;
2455  int x_add[ 8 ] = { 1, 1, 0, -1, -1, -1, 0, 1 };
2456  int y_add[ 8 ] = { 0, -1, -1, -1, 0, 1, 1, 1 };
2457  int width = m_land->MapWidth();
2458  int height = m_land->MapHeight();
2459  // Scan anti-clockwise from center pixel coordinate.
2460  for ( unsigned int i = 0; i < 8; i++ ) {
2461  if ( ( a_x + x_add[ i ] >= width ) || ( a_x + x_add[ i ] < 0 ) || ( a_y + y_add[ i ] >= height )
2462  || ( a_y + y_add[ i ] < 0 ) ) {
2463  return true;
2464  }
2465  //continue;
2466  index = m_land->Get( a_x + x_add[ i ], a_y + y_add[ i ] );
2467  if ( ( index != a_fieldindex ) && ( index != a_borderindex ) )
2468  {
2469  return true;
2470  // Test removed 1/07/2014 CJT
2471  //if ( BorderNeed( m_elems[ index ]->GetElementType() ) ) return true;
2472  //else return false;
2473  }
2474  }
2475  return false;
2476 }
2477 //-----------------------------------------------------------------------------------------------------------------------------
2478 
2479 bool Landscape::BorderStep(int a_fieldindex, int /* a_borderindex */, int * a_x, int * a_y) {
2480  int index;
2481  int x_add[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
2482  int y_add[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
2483  int width = m_land->MapWidth();
2484  int height = m_land->MapHeight();
2485  int i = 7, counter = 8;
2486  bool running = true;
2487  // First scan for another pixel that belongs to this field.
2488  while (running)
2489  {
2490  if (!((*a_x) + x_add[i] >= width) && !((*a_x) + x_add[i] < 0) && !((*a_y) + y_add[i] >= height) && !((*a_y) + y_add[i] < 0))
2491  {
2492  index = m_land->Get((*a_x) + x_add[i], (*a_y) + y_add[i]);
2493  if (index == a_fieldindex)
2494  {
2495  // Found the first field pixel while scanning around always
2496  // in the same direction.
2497  running = false;
2498  }
2499  }
2500  if (--i < 0) {
2501  // Didn't find any of our pixels. We are in a blind alley. Exit
2502  // gracefully.
2503  return false; // Signal done scanning this field.
2504  }
2505  }
2506 
2507  // Now scan around from our present facing direction and find the border
2508  // (if any).
2509  while (--counter)
2510  {
2511  if (!((*a_x) + x_add[i] >= width) && !((*a_x) + x_add[i] < 0) && !((*a_y) + y_add[i] >= height) && !((*a_y) + y_add[i] < 0))
2512  {
2513  index = m_land->Get((*a_x) + x_add[i], (*a_y) + y_add[i]);
2514  if (index == a_fieldindex)
2515  {
2516  if (--i < 0) i = 7;
2517  continue;
2518  }
2519  }
2520 
2521  // Aha! This pixel is not ours. Step one step in the
2522  // opposite(!) direction. If that pixel is ours, then
2523  // modify hotspot coordinates and exit.
2524  if (++i > 7) i = 0;
2525  if (!((*a_x) + x_add[i] + 1 > width) && !((*a_x) + x_add[i] < 0) && !((*a_y) + y_add[i] + 1 > height) &&
2526  !((*a_y) + y_add[i] < 0) && (m_land->Get((*a_x) + x_add[i], (*a_y) + y_add[i]) == a_fieldindex))
2527  {
2528  (*a_x) += x_add[i];
2529  (*a_y) += y_add[i];
2530  return true;
2531  }
2532  }
2533  return false;
2534 }
2535 //-----------------------------------------------------------------------------------------------------------------------------
2536 
2537 bool Landscape::BorderStep(int a_fieldindex, int /* a_borderindex */, APoint* a_coord) {
2538  int index;
2539  int x_add[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
2540  int y_add[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
2541  int width = m_land->MapWidth();
2542  int height = m_land->MapHeight();
2543  int i = 7, counter = 8;
2544  bool running = true;
2545  // First scan for another pixel that belongs to this field.
2546  while (running)
2547  {
2548  if (!((a_coord->m_x) + x_add[i] >= width) && !((a_coord->m_x) + x_add[i] < 0) && !((a_coord->m_y) + y_add[i] >= height) && !((a_coord->m_y) + y_add[i] < 0))
2549  {
2550  index = m_land->Get((a_coord->m_x) + x_add[i], (a_coord->m_y) + y_add[i]);
2551  if (index == a_fieldindex)
2552  {
2553  // Found the first field pixel while scanning around always
2554  // in the same direction.
2555  running = false;
2556  }
2557  }
2558  if (--i < 0) {
2559  // Didn't find any of our pixels. We are in a blind alley. Exit
2560  // gracefully.
2561  return false; // Signal done scanning this field.
2562  }
2563  }
2564 
2565  // Now scan around from our present facing direction and find the border
2566  // (if any).
2567  while (--counter)
2568  {
2569  if (!((a_coord->m_x) + x_add[i] >= width) && !((a_coord->m_x) + x_add[i] < 0) && !((a_coord->m_y) + y_add[i] >= height) && !((a_coord->m_y) + y_add[i] < 0))
2570  {
2571  index = m_land->Get((a_coord->m_x) + x_add[i], (a_coord->m_y) + y_add[i]);
2572  if (index == a_fieldindex)
2573  {
2574  if (--i < 0) i = 7;
2575  continue;
2576  }
2577  }
2578 
2579  // Aha! This pixel is not ours. Step one step in the
2580  // opposite(!) direction. If that pixel is ours, then
2581  // modify hotspot coordinates and exit.
2582  if (++i > 7) i = 0;
2583  if (!((a_coord->m_x) + x_add[i] + 1 > width) && !((a_coord->m_x) + x_add[i] < 0) && !((a_coord->m_y) + y_add[i] + 1 > height) &&
2584  !((a_coord->m_y) + y_add[i] < 0) && (m_land->Get((a_coord->m_x) + x_add[i], (a_coord->m_y) + y_add[i]) == a_fieldindex))
2585  {
2586  (a_coord->m_x) += x_add[i];
2587  (a_coord->m_y) += y_add[i];
2588  return true;
2589  }
2590  }
2591  return false;
2592 }
2593 //-----------------------------------------------------------------------------------------------------------------------------
2595 {
2597  for (unsigned int i = 0; i < m_elems.size(); i++)
2598  {
2599  if (m_elems[i]->GetElementType() == tole_Pond) {
2600  m_PondIndexList.push_back(i);
2601  m_PondRefsList.push_back(m_elems[i]->GetPoly());
2602  }
2603  }
2604 }
2605 
2607  return m_PondIndexList[int(g_rand_uni()*m_PondIndexList.size())];
2608 }
2609 
2611  if (m_PondIndexList.size()>0) return m_PondRefsList[int(g_rand_uni()*m_PondIndexList.size())];
2612  return -1;
2613 }
2614 
2615 
2616 // Unsprayed Margin Code....
2618  int x = a_field->GetValidX();
2619  int y = a_field->GetValidY();
2620  if ( ( x == -1 ) || ( y == -1 ) ) {
2621  // Tripping this probably means it is not a field
2622  g_msg->Warn( WARN_BUG, "Landscape::UnsprayedMarginAdd(): Uninitialized border coordinate!", "" );
2623  exit( 1 );
2624  }
2625  LE * umargin = NewElement( tole_UnsprayedFieldMargin );
2626  m_polymapping[ hb_first_free_poly_num ] = (int) m_elems.size();
2627  m_elems.resize( m_elems.size() + 1 );
2628  m_elems[ m_elems.size() - 1 ] = umargin;
2629  a_field->SetUnsprayedMarginPolyRef( hb_first_free_poly_num );
2630  umargin->SetPoly( hb_first_free_poly_num++ );
2631  umargin->SetArea( 0.0 );
2632 
2633  for ( int q = 0; q < l_map_umargin_width.value(); q++ )
2634  UnsprayedMarginScan( a_field, q + 1 );
2635 }
2636 //-----------------------------------------------------------------------------------------------------------------------------
2637 
2638 void Landscape::UnsprayedMarginScan( LE * a_field, int a_width ) {
2639  LE * umargin = g_landscape_p->SupplyLEPointer( a_field->GetUnsprayedMarginPolyRef() );
2640  int fieldpoly = a_field->GetPoly();
2641  int borderpoly = umargin->GetPoly();
2642  int borderindex = m_polymapping[ borderpoly ];
2643  int fieldindex = m_polymapping[ fieldpoly ];
2644  int notforever = 5000;
2645 
2646  // These two will be modified through pointer operations
2647  // in BorderStep().
2648  int x = a_field->GetValidX();
2649  int y = a_field->GetValidY();
2650  // Now the problem is that GetValid does not always return a valid co-ord!
2651  // so we need to search for one
2652  if ( !FindValidXY( fieldindex, x, y ) ) return;
2653 
2654  while ( --notforever ) {
2655  // Check if this position should be made into a border.
2656  if ( UMarginTest( fieldindex, borderindex, x, y, a_width ) ) {
2657  // Add this pixel to the border element in the big map.
2658  m_land->Put( x, y, borderindex );
2659  a_field->AddArea( -1.0 );
2660  umargin->AddArea( 1.0 );
2661  };
2662  // Step to next coordinate. Quit when done.
2663  if ( !BorderStep( fieldindex, borderindex, & x, & y ) )
2664  return;
2665  }
2666 }
2667 //-----------------------------------------------------------------------------------------------------------------------------
2668 
2669 bool Landscape::UMarginTest( int a_fieldindex, int a_marginindex, int a_x, int a_y, int a_width ) {
2670  int index;
2671  int x_add[ 8 ] = { 1*a_width, 1*a_width, 0, -1*a_width, -1*a_width, -1*a_width, 0, 1*a_width };
2672  int y_add[ 8 ] = { 0, -1*a_width, -1*a_width, -1*a_width, 0, 1*a_width, 1*a_width, 1*a_width };
2673  int width = m_land->MapWidth();
2674  int height = m_land->MapHeight();
2675  // Scan anti-clockwise from center pixel coordinate.
2676  for ( unsigned int i = 0; i < 8; i++ ) {
2677  if ( ( a_x + x_add[ i ] >= width ) || ( a_x + x_add[ i ] < 0 ) || ( a_y + y_add[ i ] >= height )
2678  || ( a_y + y_add[ i ] < 0 ) ) {
2679  return true;
2680  }
2681  //continue;
2682  index = m_land->Get( a_x + x_add[ i ], a_y + y_add[ i ] );
2683  if ( ( index != a_fieldindex ) && ( index != a_marginindex ) ) return true;
2684  }
2685  return false;
2686 }
2687 
2688 bool Landscape::FindValidXY( int a_field, int & a_x, int & a_y ) {
2689  // From a hopefully sensible starting point this method scans in the
2690  // 8 directions to find a good valid x and y matching a_field
2691  int x_add[ 8 ] = { 1, 1, 0, -1, -1, -1, 0, 1 };
2692  int y_add[ 8 ] = { 0, -1, -1, -1, 0, 1, 1, 1 };
2693  int index;
2694  int nx, ny;
2695  int width = m_land->MapWidth();
2696  int height = m_land->MapHeight();
2697  // Assume it has to within 100m
2698  for ( int i = 0; i < 100; i++ ) {
2699  for ( int l = 0; l < 8; l++ ) {
2700  nx = a_x + x_add[ l ] * i;
2701  ny = a_y + y_add[ l ] * i;
2702  if ( ( nx < width ) && ( nx >= 0 ) && ( ny < height ) && ( ny >= 0 ) ) {
2703  index = m_land->Get( nx, ny );
2704  if ( index == a_field ) {
2705  a_x = a_x + x_add[ l ] * i;
2706  a_y = a_y + y_add[ l ] * i;
2707  return true;
2708  }
2709  }
2710  }
2711  }
2712  return false;
2713 }
2714 //-----------------------------------------------------------------------------------------------------------------------------
2715 // ...to here..S
2716 
2717 // **************************************************************************************
2721 // **************************************************************************************
2722 
2731  int BBs=0;
2732  int tx1 = cfg_BeetleBankMinX.value();
2733  int tx2 = cfg_BeetleBankMaxX.value();
2734  int ty1 = cfg_BeetleBankMinY.value();
2735  int ty2 = cfg_BeetleBankMaxY.value();
2736  bool doit = false;
2737  unsigned sz=(unsigned) m_elems.size();
2738  for (unsigned i=0; i<sz; i++)
2739  {
2740  if (m_elems[ i ]->GetElementType() == tole_Field)
2741  {
2742  doit = false;
2743  int cx = m_elems[ i ]->GetCentroidX();
2744  int cy = m_elems[ i ]->GetCentroidY();
2745  if (!cfg_BeetleBankInvert.value())
2746  {
2747  if ((cx >= tx1) && (cy >= ty1) && (cx <= tx2) && (cy <= ty2))
2748  {
2749  doit = true;
2750  }
2751  }
2752  else if ((cx < tx1) || (cy < ty1) || (cx > tx2) || (cy > ty2))
2753  {
2754  doit = true;
2755  }
2756  if (doit)
2757  {
2758  if (random(100)<cfg_BeetleBankChance.value())
2759  {
2760  if (BeetleBankPossible( m_elems[ i ], a_tole) ) BBs++;
2761  }
2762  }
2763  }
2764  }
2765  char str[25];
2766  sprintf(str,"%d",BBs);
2767  g_msg->Warn( WARN_MSG, "Landscape::AddBeetleBanks(): BeetleBanks successfully added:", str );
2768 }
2769 //-----------------------------------------------------------------------------------------------------------------------------
2770 // **************************************************************************************
2771 
2779  int farea=(int)a_field->GetArea();
2780  if (farea<10000) return false;
2781  int cx=a_field->GetCentroidX();
2782  int cy=a_field->GetCentroidY();
2783  // The centroid is the only estimate we have (and it at least should be in the field).
2784  // So start here and find the centre
2785  if (!FindFieldCenter(a_field, &cx, &cy)) return false;
2786  // now get the alignment
2787  int length=0;
2788  int alignment=FindLongestAxis(&cx, &cy, &length);
2789  // reduce length by 20%
2790  length=int(length*0.8);
2791  int area=2*length*cfg_BeetleBankWidth.value(); // 12m wide fixed size
2792  if (area>(farea*cfg_BeetleBankMaxArea.value())) return false;
2793  // Must be small engough so lets draw it
2794  BeetleBankAdd(cx, cy, alignment, length , a_field, a_tole);
2795  return true;
2796 }
2797 //-----------------------------------------------------------------------------------------------------------------------------
2798 
2799 bool Landscape::FindFieldCenter(LE* a_field, int* x, int* y) {
2800  // Start at x,y
2801  // works by selecting the point that is a mean of the co-ords of the centers of 4 axes from this point that are in the field.
2802  // Then do it again, and again until we don't move more than 1m or we have tried too many times
2803  int ourpoly=SupplyPolyRef(*(x),*(y));
2804  if (ourpoly!=a_field->GetPoly()) return false;
2805  int centers[2][8];
2806  int tries=0;
2807  int diff=999;
2808  int x1=*(x);
2809  int y1=*(y);
2810  int centreX=x1;
2811  int centreY=y1;
2812  // NB we might escape without bounds checking here because the polygon number does not wrap round - will only ever be a problem if we go SimX+1,SimY+1
2813  while ((diff>1) & (tries++<100)) {
2814  for (unsigned v=0; v<4; v++) {
2815  x1=centreX;
2816  y1=centreY;
2817  AxisLoop(ourpoly, &x1, &y1, v);
2818  centers[0][v]=x1-m_x_add[v];
2819  centers[1][v]=y1-m_y_add[v];
2820  x1=centreX;
2821  y1=centreY;
2822  AxisLoop(ourpoly, &x1, &y1, v+4);
2823  centers[0][v+4]=x1-m_x_add[v+4];
2824  centers[1][v+4]=y1-m_y_add[v+4];
2825 // centreX+=((centers[0][v]+x1-m_x_add[v+4])/2);
2826 // centreY+=((centers[1][v]+y1-m_y_add[v+4])/2);
2827  }
2828  int oldx=centreX;
2829  int oldy=centreY;
2830  centreX=0;
2831  centreY=0;
2832  for (int h=0; h<8; h++) {
2833  centreX+=centers[0][h];
2834  centreY+=centers[1][h];
2835  }
2836  centreX/=8;
2837  centreY/=8;
2838  diff=abs(oldx-centreX)+abs(oldy-centreY);
2839  }
2840  *(x)=centreX;
2841  *(y)=centreY;
2842  int tourpoly=SupplyPolyRef(*(x),*(y));
2843  if (tourpoly!=ourpoly) {
2844  return false; // can happen eg if there is a pond in the middle of the field
2845  }
2846 
2847  return true;
2848 }
2849 //-----------------------------------------------------------------------------------------------------------------------------
2850 
2851 int Landscape::FindLongestAxis(int* a_x, int* a_y, int* a_length)
2852 {
2853  int ourpoly=SupplyPolyRef(*(a_x),*(a_y));
2854  int dist[4];
2855  int distx[8];
2856  int disty[8];
2857  int found = -1;
2858  *(a_length) = 0;
2859  int dx[8];
2860  int dy[8];
2861  int fx[8];
2862  int fy[8];
2863  for (unsigned v=0; v<8; v++)
2864  {
2865  int x1=*(a_x);
2866  int y1=*(a_y);
2867  AxisLoop(ourpoly, &x1, &y1, v);
2868  x1 -= m_x_add[v];
2869  y1 -= m_y_add[v];
2870  dx[v] = abs(*(a_x)-x1);
2871  dy[v] = abs(*(a_y)-y1);
2872  fx[v] = x1;
2873  fy[v] = y1;
2874  distx[v] = dx[v];
2875  disty[v] = dy[v];
2876  }
2877  for (int di = 0; di < 4; di++)
2878  {
2879  int ddx = distx[di] + distx[di + 4];
2880  int ddy = disty[di] + disty[di + 4];
2881  if (ddx == 0) dist[di] = ddy; else dist[di] = ddx;
2882  if (dist[di] > *(a_length))
2883  {
2884  found = di;
2885  *(a_length) = dist[di];
2886  }
2887  }
2888  if (found == -1) return 0;
2889  // Now need to find the middle of the axis.
2890  int l = (*(a_length) / 2);
2891  if (fx[found] > fx[found + 4]) *(a_x) = fx[found + 4] + m_x_add[found] * l; else *(a_x) = fx[found + 4] - m_x_add[found + 4] * l;
2892  if (fy[found] > fy[found + 4]) *(a_y) = fy[found + 4] + m_y_add[found] * l; else *(a_y) = fy[found + 4] - m_y_add[found + 4] * l;
2893 
2894  return found;
2895 }
2896 //-----------------------------------------------------------------------------------------------------------------------------
2897 
2898 void Landscape::AxisLoop(int a_polyindex, APoint* a_cor, int a_axis) {
2903  int ap1 = a_polyindex;
2904  while (ap1 == a_polyindex)
2905  {
2906  a_cor->m_x += m_x_add[a_axis];
2907  a_cor->m_y += m_y_add[a_axis];
2908  if (a_cor->m_x >= m_width - 1) { a_cor->m_x = m_width - 1; return; }
2909  if (a_cor->m_y >= m_height - 1) { a_cor->m_y = m_height - 1; return; }
2910  if (a_cor->m_x <= 0) { a_cor->m_x = 0; return; }
2911  if (a_cor->m_y <= 0) { a_cor->m_y = 0; return; }
2912  ap1 = m_land->Get(a_cor->m_x, a_cor->m_y); // NB this returns the m_elemens index not the polyref (ChangeMapMapping has been called by here)
2913  }
2914 }
2915 //-----------------------------------------------------------------------------------------------------------------------------
2916 
2917 void Landscape::AxisLoopLtd(int a_polyindex, APoint* a_cor, int a_axis, int a_limit) {
2922  int ap1 = a_polyindex;
2923  int count = 0;
2924  while (ap1 == a_polyindex && count<a_limit)
2925  {
2926  a_cor->m_x += m_x_add[a_axis];
2927  a_cor->m_y += m_y_add[a_axis];
2928  if (a_cor->m_x >= m_width - 1) { a_cor->m_x = m_width - 1; return; }
2929  if (a_cor->m_y >= m_height - 1) { a_cor->m_y = m_height - 1; return; }
2930  if (a_cor->m_x <= 0) { a_cor->m_x = 0; return; }
2931  if (a_cor->m_y <= 0) { a_cor->m_y = 0; return; }
2932  ap1 = m_land->Get(a_cor->m_x, a_cor->m_y); // NB this returns the m_elemens index not the polyref (ChangeMapMapping has been called by here)
2933  count++;
2934  }
2935 }
2936 //-----------------------------------------------------------------------------------------------------------------------------
2937 
2938 void Landscape::AxisLoop(int a_polyindex, int* a_x, int* a_y, int a_axis) {
2943  int ap1 = a_polyindex;
2944  while (ap1 == a_polyindex)
2945  {
2946  *(a_x) += m_x_add[a_axis];
2947  *(a_y) += m_y_add[a_axis];
2948  // Before we try to get a polyindex from the map, check we are still on the world
2949  if (*(a_x) < 0)
2950  {
2951  return;
2952  }
2953  if (*(a_y) < 0)
2954  {
2955  return;
2956  }
2957  if (*(a_x) >= m_width)
2958  {
2959  return;
2960  }
2961  if (*(a_y) >= m_height)
2962  {
2963  return;
2964  }
2965  // OK still in the map, get the polyindex
2966  ap1 = m_land->Get((*a_x), (*a_y)); // NB this returns the m_elemens index not the polyref (ChangeMapMapping has been called by here)
2967  }
2968 }
2969 //-----------------------------------------------------------------------------------------------------------------------------
2970 
2971 void Landscape::BeetleBankAdd(int a_x, int a_y, int a_angle, int a_length, LE* a_field, TTypesOfLandscapeElement a_tole ) {
2972  // Need to get a new number
2973  ++m_LargestPolyNumUsed;
2974  // Make the new landscape element
2975  LE * BeetleBank;
2976  switch (a_tole)
2977  {
2978  case tole_MownGrass:
2979  BeetleBank = NewElement( tole_MownGrass );
2980  BeetleBank->SetALMaSSEleType( g_letype->BackTranslateEleTypes( tole_MownGrass ) );
2981  break;
2983  BeetleBank = NewElement( tole_PermanentSetaside );
2985  break;
2986  case tole_BeetleBank:
2987  default:
2988  BeetleBank = NewElement( tole_BeetleBank );
2989  BeetleBank->SetALMaSSEleType( g_letype->BackTranslateEleTypes( tole_BeetleBank ) );
2990  }
2991  BeetleBank->SetVegPatchy(true);
2992  m_polymapping[ m_LargestPolyNumUsed ] = (int) m_elems.size();
2993  m_elems.resize( m_elems.size() + 1 );
2994  m_elems[ m_elems.size() - 1 ] = BeetleBank;
2995  BeetleBank->SetPoly( m_LargestPolyNumUsed );
2996  // write lengthx12m to the map at alignment angle
2997  int area=0;
2998  int angle2=0;
2999  int width=cfg_BeetleBankWidth.value();
3000  if (a_angle==0) angle2=2;
3001  int start=(int)(a_length*0.1);
3002  for (int i=start; i<a_length; i++) {
3003  for (int w=0-width; w<width; w++) {
3004  int tx=w*m_x_add[angle2];
3005  int ty=w*m_y_add[angle2];
3006  m_land->Put( tx+a_x+i*m_x_add[a_angle], ty+a_y+i*m_y_add[a_angle], (int) m_elems.size() - 1 );
3007  m_land->Put( tx+a_x-i*m_x_add[a_angle], ty+a_y-i*m_y_add[a_angle], (int) m_elems.size() - 1 );
3008  area+=2;
3009  a_field->AddArea( -2.0 );
3010 
3011  }
3012  }
3013  BeetleBank->SetArea( double(area) );
3014  BeetleBank->SetValidXY( a_x+start*m_x_add[a_angle], a_y+start*m_y_add[a_angle] );
3015  BeetleBank->SetMapValid(true);
3016 
3017 }
3018 //-----------------------------------------------------------------------------------------------------------------------------
3019 
3020 // **************************************************************************************
3021 /* End beetle bank addition code */
3022 // **************************************************************************************/
3023 
3024 
3025 void Landscape::SkylarkEvaluation(SkTerritories* a_skt) {
3026  for (unsigned i=0; i<m_elems.size(); i++) {
3027  a_skt->PreCachePoly(m_elems[i]->GetPoly());
3028  }
3029 }
3030 //-----------------------------------------------------------------------------------------------------------------------------
3031 
3032 void Landscape::RodenticidePredatorsEvaluation(RodenticidePredators_Population_Manager* a_rppm)
3033 {
3034  for (unsigned i=0; i<m_elems.size(); i++) {
3035  a_rppm->PreCachePoly(m_elems[i]->GetPoly());
3036  }
3037 }
3038 //-----------------------------------------------------------------------------------------------------------------------------
3039 
3041 {
3047  cout << "In Centroid Calculations" << endl;
3048  // For each polygon
3049  for (int p = 0; p< (int)m_elems.size(); p++)
3050  {
3051  // Calcuate the actual centre
3052  int x1 = m_elems[p]->GetMinX();
3053  int y1 = m_elems[p]->GetMinY();
3054  int x2 = m_elems[p]->GetMaxX();
3055  int y2 = m_elems[p]->GetMaxY();
3056 
3057  int midx = (x1 + x2) / 2;
3058  int midy = (y1 + y2) / 2;
3059  // Now from midx & midy we move outwards in concentric circles until we find a location that matches our polyref.
3060  int polyindex = p; // Change mapmapping has been called by now, so the map contains m_elems indices.
3061  CentroidSpiralOut(polyindex, midx, midy);
3062  // Now we want to be sure that we are in the middle of the polygon not on the edge. This is tricky for complex shaped polygons,
3063  // but we have a stab at it by using the FindLongestAxis method. This puts us in the centre of the longest axis in 8 directions
3064  // from this point
3065  int l;
3066  FindLongestAxis(&midx, &midy, &l);
3067  m_elems[p]->SetCentroid(midx, midy);
3068  }
3069  BuildingDesignationCalc();
3070 }
3071 //-----------------------------------------------------------------------------------------------------------------------------
3072 
3073 void Landscape::CentroidSpiralOut(int a_polyref, int &a_x, int &a_y)
3074 {
3075  if (SupplyPolyRefIndex(a_x, a_y) == a_polyref) return; // Found it so return
3076  // Otherwise its not found so we need to start to spiral out
3077  int loop = 1;
3078  int sx = a_x;
3079  int sy = a_y;
3080  do {
3081  a_y = sy - loop;
3082  for (int i = 0 - loop; i <= loop; i++)
3083  {
3084  a_x = sx + i;
3085  CorrectCoords(a_x, a_y);
3086  if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3087  return; // Found it so return
3088  }
3089  a_y = sy + loop;
3090  for (int i = 0 - loop; i <= loop; i++)
3091  {
3092  a_x = sx + i;
3093  CorrectCoords(a_x, a_y);
3094  if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3095  return; // Found it so return
3096  }
3097  a_x = sx + loop;
3098  for (int j = 0 - (loop - 1); j< loop; j++)
3099  {
3100  a_y = sy + j;
3101  CorrectCoords(a_x, a_y);
3102  if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3103  return; // Found it so return
3104  }
3105  a_x = sx - loop;
3106  for (int j = 0 - (loop - 1); j< loop; j++)
3107  {
3108  a_y = sy + j;
3109  CorrectCoords(a_x, a_y);
3110  if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3111  return; // Found it so return
3112  }
3113  loop++;
3114  } while (loop<m_minmaxextent); // This stopping rule should hopefully not be needed, it is set very high.
3115  g_msg->Warn("Landscape::CentroidSpiralOut: Failure of centroid main loop. Looking for polygon index ",a_polyref);
3116  a_x = m_elems[a_polyref]->GetMinX();
3117  a_y = m_elems[a_polyref]->GetMinY();
3118 }
3119 //-----------------------------------------------------------------------------------------------------------------------------
3120 /* N0t used
3121 void Landscape::CentroidSpiralOutBlocks(int a_polyref, int &a_x, int &a_y)
3122 {
3123  if (SupplyPolyRefIndex(a_x, a_y) == a_polyref) return; // Found it so return
3124  // Otherwise its not found so we need to start to spiral out until we find a 10x10m block of our field.
3125  int loop = 1;
3126  int sx = a_x;
3127  int sy = a_y;
3128  do {
3129  a_y = sy - loop;
3130  for (int i = 0 - loop; i <= loop; i++)
3131  {
3132  a_x = sx + i;
3133  CorrectCoords(a_x, a_y);
3134  if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3135  {
3136  APoint pt(a_x, a_y);
3137  double dists = -1;
3138  double best = -1;
3139  int ind = -1;
3140  for (int d = 0; d < 8; d++)
3141  {
3142  AxisLoopLtd(a_polyref, &pt, d,10);
3143 #ifdef __BORLANDC__
3144  dists = sqrt(double((a_x - pt.m_x)*(a_x - pt.m_x) + (a_y - pt.m_y) * (a_y - pt.m_y)));
3145 #else
3146  //dists = sqrt((a_x - pt.m_x)*(a_x - pt.m_x) + (a_y - pt.m_y) * (a_y - pt.m_y));
3147  dists = (abs(a_x - pt.m_x) + abs(a_y - pt.m_y));
3148 #endif
3149  if (dists > best) { best = dists; ind = d; }
3150  }
3151  if (ind > -1)
3152  {
3153  // best /= 2;
3154  if (best >= 10)
3155  {
3156  a_x += m_x_add[ind] * 10;
3157  a_y += m_y_add[ind] * 10;
3158  return;
3159  }
3160  }
3161  return; // Found it so return even without the 10 distance
3162  }
3163  }
3164  a_y = sy + loop;
3165  for (int i = 0 - loop; i <= loop; i++)
3166  {
3167  a_x = sx + i;
3168  CorrectCoords(a_x, a_y);
3169  if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3170  {
3171  APoint pt(a_x, a_y);
3172  double dists = -1;
3173  double best = -1;
3174  int ind = -1;
3175  for (int d = 0; d < 8; d++)
3176  {
3177  AxisLoopLtd(a_polyref, &pt, d,10);
3178 #ifdef __BORLANDC__
3179  dists = sqrt(double((a_x - pt.m_x)*(a_x - pt.m_x) + (a_y - pt.m_y) * (a_y - pt.m_y)));
3180 #else
3181  //dists = sqrt((a_x - pt.m_x)*(a_x - pt.m_x) + (a_y - pt.m_y) * (a_y - pt.m_y));
3182  dists = (abs(a_x - pt.m_x) + abs(a_y - pt.m_y));
3183 #endif
3184  if (dists > best) { best = dists; ind = d; }
3185  }
3186  if (ind > -1)
3187  {
3188  // best /= 2;
3189  if (best >= 10)
3190  {
3191  a_x += m_x_add[ind] * 10;
3192  a_y += m_y_add[ind] * 10;
3193  return;
3194  }
3195  }
3196  return; // Found it so return even without the 10 distance
3197  }
3198  }
3199  a_x = sx + loop;
3200  for (int j = 0 - (loop - 1); j< loop; j++)
3201  {
3202  a_y = sy + j;
3203  CorrectCoords(a_x, a_y);
3204  if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3205  {
3206  APoint pt(a_x, a_y);
3207  double dists = -1;
3208  double best = -1;
3209  int ind = -1;
3210  for (int d = 0; d < 8; d++)
3211  {
3212  AxisLoopLtd(a_polyref, &pt, d,10);
3213 #ifdef __BORLANDC__
3214  dists = sqrt(double((a_x - pt.m_x)*(a_x - pt.m_x) + (a_y - pt.m_y) * (a_y - pt.m_y)));
3215 #else
3216  //dists = sqrt((a_x - pt.m_x)*(a_x - pt.m_x) + (a_y - pt.m_y) * (a_y - pt.m_y));
3217  dists = (abs(a_x - pt.m_x) + abs(a_y - pt.m_y));
3218 #endif
3219  if (dists > best) { best = dists; ind = d; }
3220  }
3221  if (ind > -1)
3222  {
3223  // best /= 2;
3224  if (best >= 10)
3225  {
3226  a_x += m_x_add[ind] * 10;
3227  a_y += m_y_add[ind] * 10;
3228  return;
3229  }
3230  }
3231  return; // Found it so return even without the 10 distance
3232  }
3233  }
3234  a_x = sx - loop;
3235  for (int j = 0 - (loop - 1); j< loop; j++)
3236  {
3237  a_y = sy + j;
3238  CorrectCoords(a_x, a_y);
3239  if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3240  {
3241  APoint pt(a_x, a_y);
3242  double dists = -1;
3243  double best = -1;
3244  int ind = -1;
3245  for (int d = 0; d < 8; d++)
3246  {
3247  AxisLoopLtd(a_polyref, &pt, d,10);
3248 #ifdef __BORLANDC__
3249  dists = sqrt(double((a_x - pt.m_x)*(a_x - pt.m_x) + (a_y - pt.m_y) * (a_y - pt.m_y)));
3250 #else
3251  //dists = sqrt((a_x - pt.m_x)*(a_x - pt.m_x) + (a_y - pt.m_y) * (a_y - pt.m_y));
3252  dists = (abs(a_x - pt.m_x) + abs(a_y - pt.m_y));
3253 #endif
3254  if (dists > best) { best = dists; ind = d; }
3255  }
3256  if (ind > -1)
3257  {
3258  // best /= 2;
3259  if (best >= 10)
3260  {
3261  a_x += m_x_add[ind] * 10;
3262  a_y += m_y_add[ind] * 10;
3263  return;
3264  }
3265  }
3266  return; // Found it so return even without the 10 distance
3267  }
3268  }
3269  loop++;
3270  } while (loop<m_width); // This stopping rule should hopefully not be needed, it is set very high.
3271  exit(0);
3272 }
3273 //-----------------------------------------------------------------------------------------------------------------------------*/
3274 
3276 {
3277  ofstream centroidfile("PolygonCentroids.txt", ios::out);
3278  centroidfile<<"Polyref"<<'\t'<<"CX"<<'\t'<<"CY"<<'\t'<<"Type"<<'\t'<<"Area"<<'\t'<<"Country Designation"<<endl;
3279  for (int p = 0; p< (int)m_elems.size(); p++)
3280  {
3281  centroidfile<<m_elems[p]->GetPoly()<<'\t'<<m_elems[p]->GetCentroidX()<<'\t'<<m_elems[p]->GetCentroidY()<<'\t'<<m_elems[p]->GetElementType()<<'\t'<<m_elems[p]->GetArea()<<'\t'<<m_elems[p]->GetCountryDesignation()<<endl;
3282  }
3283  centroidfile.close();
3284 }
3285 //-----------------------------------------------------------------------------------------------------------------------------
3286 
3288 {
3293  cout << "In BuildingDesignationCalc" << endl;
3294  for (int p = 0; p< (int)m_elems.size(); p++)
3295  {
3296  TTypesOfLandscapeElement tole = m_elems[p]->GetElementType();
3297  if ( tole == tole_Building)
3298  {
3299  int cx = m_elems[p]->GetCentroidX();
3300  int cy = m_elems[p]->GetCentroidY();
3301  int near = 0;
3302  for (int j = 0; j< (int)m_elems.size(); j++)
3303  {
3304  if (m_elems[j]->GetElementType() == tole_Building)
3305  {
3306  int nx = m_elems[j]->GetCentroidX();
3307  int ny = m_elems[j]->GetCentroidY();
3308  int dx =abs(cx-nx);
3309  int dy =abs(cy-ny);
3310  if ((dx < cfg_mintownbuildingdistance.value()) && (dy < cfg_mintownbuildingdistance.value())) near++;
3311  if (near > cfg_mintownbuildingdistance.value()) break;
3312  }
3313  }
3314  if (near <= cfg_mintownbuildingnumber.value()) m_elems[p]->SetCountryDesignation(1); // Not enough buildings close by, so it is a country building
3315  else m_elems[p]->SetCountryDesignation(0);
3316  }
3317  else if (tole == tole_YoungForest)
3318  {
3319  m_elems[p]->SetCountryDesignation(2);
3320  }
3321  else if ((tole == tole_DeciduousForest) || ( tole == tole_MixedForest) || ( tole == tole_ConiferousForest ) ) m_elems[p]->SetCountryDesignation(3);
3322 
3323  }
3324 }
3325 //-----------------------------------------------------------------------------------------------------------------------------
3326 
3327 
3328 void Landscape::RecordGooseNumbers(int a_polyref, int a_number)
3329 {
3335  int day = SupplyDayInYear();
3336  m_elems[m_polymapping[a_polyref]]->SetGooseNos(a_number, day);
3337 }
3338 
3339 //-----------------------------------------------------------------------------------------------------------------------------
3340 
3341 void Landscape::RecordGooseNumbersTimed(int a_polyref, int a_number)
3342 {
3347  int day = SupplyDayInYear();
3348  m_elems[m_polymapping[a_polyref]]->SetGooseNosTimed(a_number, day);
3349 }
3350 
3351 //-----------------------------------------------------------------------------------------------------------------------------
3352 void Landscape::RecordGooseSpNumbers(int a_polyref, int a_number, GooseSpecies a_goose) {
3359  int day = SupplyDayInYear();
3360  m_elems[m_polymapping[a_polyref]]->SetGooseSpNos(a_number, day, a_goose);
3361  }
3362  //-----------------------------------------------------------------------------------------------------------------------------
3363  void Landscape::RecordGooseSpNumbersTimed(int a_polyref, int a_number, GooseSpecies a_goose) {
3369  int day = SupplyDayInYear();
3370  m_elems[m_polymapping[a_polyref]]->SetGooseSpNosTimed(a_number, day, a_goose);
3371  }
3372  //-----------------------------------------------------------------------------------------------------------------------------
3373  void Landscape::RecordGooseRoostDist(int a_polyref, int a_dist, GooseSpecies a_goose) {
3377  m_elems[m_polymapping[a_polyref]]->SetGooseRoostDist(a_dist, a_goose);
3378  }
3379  //-----------------------------------------------------------------------------------------------------------------------------
3383  int Landscape::GetGooseNumbers(int a_polyref) {
3384  return m_elems[m_polymapping[a_polyref]]->GetGooseNos();
3385  }
3386  //-----------------------------------------------------------------------------------------------------------------------------
3390  int Landscape::GetQuarryNumbers(int a_polyref) {
3391  return m_elems[m_polymapping[a_polyref]]->GetQuarryNos();
3392  }
3393  //-----------------------------------------------------------------------------------------------------------------------------
3397  int Landscape::GetGooseNumbers(int a_x, int a_y)
3398  {
3399  return m_elems[m_land->Get(a_x, a_y)]->GetGooseNos();
3400  }
3401  //-----------------------------------------------------------------------------------------------------------------------------
3402 
3403 double Landscape::GetHareFoodQuality(int a_polygon) // actually only works for a single square, but who cares, a polygon is uniform
3404 {
3405  double digest;
3406  TTypesOfLandscapeElement habitat = SupplyElementType(a_polygon);
3407  switch (habitat) {
3408  // Impossible stuff
3409  case tole_Building:
3410  case tole_Pond:
3411  case tole_Freshwater:
3412  case tole_River:
3413  case tole_Saltwater:
3414  case tole_Coast:
3415  case tole_BareRock:
3416  case tole_ConiferousForest:
3417  case tole_DeciduousForest:
3418  case tole_MixedForest:
3419  case tole_SmallRoad:
3420  case tole_LargeRoad:
3421  case tole_ActivePit:
3422  case tole_UrbanNoVeg:
3423  case tole_UrbanPark:
3424  case tole_SandDune:
3425  case tole_Copse:
3426  case tole_Stream:
3427  case tole_MetalledPath:
3428  case tole_Carpark:
3429  case tole_FishFarm:
3430  case tole_Fence:
3431  // EnergyBalance(activity_Foraging, 100); // This is a bug - it penalises for foraging in impossible areas - not intended but not found until after parameter fitting! Removed 28/07/2014
3432  return 0.0;
3433 
3434  // Questionable stuff
3435  case tole_RiversidePlants:
3436  case tole_RiversideTrees:
3437  case tole_Garden:
3438  case tole_Track:
3439  case tole_StoneWall:
3440  case tole_Hedges:
3441  case tole_Marsh:
3442  case tole_PitDisused:
3443  case tole_RoadsideVerge:
3444  case tole_Railway:
3445  case tole_Scrub:
3446  case tole_AmenityGrass:
3447  case tole_Parkland:
3449  case tole_Churchyard:
3450  case tole_HeritageSite:
3451  return 0.25; // was 0.25 being half of access to low digestability stuff
3452  // case tole_MownGrass:
3453  // digest = 0.8; // Added 28/07/2014 this is a way to compensate for the lack of choice when foraging, i.e. the whole area is assumed to be foraged equally.
3455  case tole_Wasteland:
3456  case tole_IndividualTree:
3457  case tole_WoodyEnergyCrop:
3458  case tole_PlantNursery:
3459  case tole_Pylon:
3460  case tole_WindTurbine:
3461  case tole_WoodlandMargin:
3462  case tole_Vildtager:
3463  default:
3464  digest = SupplyVegDigestability(a_polygon);
3465  }
3466 #ifdef __Perfectfood
3467  return 0.8;
3468 #else
3469 #ifdef __YEARLYVARIABLEFOODQUALITY
3470  digest *= m_OurPopulationManager->m_GoodYearBadYear;
3471 #endif
3472  double veg_height;
3473  double access = 1.0;
3474  // double grazedreduction[4] = { 1.0, 0.75, 0.5, 0.25 };
3475  double grazedreduction[4] = { 1.0, 0.8, 0.2, 0.05 };
3476  veg_height = SupplyVegHeight(a_polygon);
3477  double weeds = SupplyWeedBiomass(a_polygon);
3478  if ((veg_height <= 0) && (weeds < 0.1)) return 0.25; // Always something to eat, but not much.
3479 #ifdef __Hare1950s
3480  bool veg_patchy = true;
3481 #else // If it is not the special case of the 1950s
3482  //
3483  bool veg_patchy = SupplyVegPatchy(a_polygon);
3484 #endif
3485  if (veg_patchy)
3486  {
3487  // Patchy vegetation - normally full access
3488  if (veg_height>50)
3489  {
3490  // no food at only at very very tall
3491  access -= ((veg_height - 50)* g_VegHeightForageReduction);
3492  if (access<0) access = 0;
3493  }
3494  }
3495  else
3496  {
3497  if (veg_height>g_FarmIntensivenessH)
3498  {
3499  access -= ((veg_height - g_FarmIntensivenessH)* /* g_FarmIntensiveness * */ g_VegHeightForageReduction);
3500  if (access<0) access = 0;
3501  }
3502  }
3503  return access * digest * grazedreduction[SupplyGrazingPressure(a_polygon)];
3504 #endif
3505 }
3506 
3507 void Landscape::GISASCII_Output( string outpfile, int UTMX, int UTMY ) {
3515  FILE* OFILE;
3516  OFILE = fopen( outpfile.c_str(), "w" );
3517  if (!OFILE) {
3518  g_msg->Warn( WARN_FILE, "Landscape::GISASCII_Output() "
3519  "Unable to open file for writing:",
3520  outpfile );
3521  exit( 1 );
3522  }
3523  char c = '\n';
3524  fprintf(OFILE, "ncols %d\n", m_width);
3525  fprintf(OFILE, "nrows %d\n", m_height);
3526  fprintf(OFILE, "xllcorner %d\n", UTMX );
3527  fprintf(OFILE, "yllcorner %d\n", UTMY );
3528  fprintf(OFILE, "cellsize %d\n", 1 );
3529  fprintf(OFILE, "NODATA_value %d\n", -9999 );
3530  // The polyref loop
3531  if (l_map_ascii_map_entity.value() == 1) {
3532  for (int y = 0; y < m_height; y++) {
3533  for (int x = 0; x < m_width; x++) {
3534  fprintf(OFILE, "%d\t", SupplyPolyRef(x, y));
3535  }
3536  fprintf(OFILE, "%c", c );
3537  }
3538  }
3539  // The element type loop
3540  if (l_map_ascii_map_entity.value() == 2) {
3541  for (int y = 0; y < m_height; y++) {
3542  for (int x = 0; x < m_width; x++) {
3543  fprintf(OFILE, "%d\t", SupplyElementType( x, y ));
3544  }
3545  fprintf( OFILE, "%c", c );
3546  }
3547  }
3548  fclose( OFILE );
3549 }
3550 
3552  le_signal_index = 0;
3553 }
3554 
3556  if ((unsigned int)le_signal_index == m_elems.size()) {
3557  return -1;
3558  }
3559  return m_elems[le_signal_index++]->GetPoly();
3560 }
3561 
3563  return (int)m_elems.size();
3564 }
3565 
3567  return m_elems[m_polymapping[a_polyref]]->GetSignal();
3568 }
3569 
3570 void Landscape::SetLESignal(int a_polyref, LE_Signal a_signal) {
3571  m_elems[m_polymapping[a_polyref]]->SetSignal(a_signal);
3572 }
3573 
3574 
3575 void Landscape::IncTreatCounter(int a_treat) {
3576  if (a_treat < 0 || a_treat >= last_treatment) {
3577  char errornum[20];
3578  sprintf(errornum, "%d", a_treat);
3579  g_msg->Warn(WARN_BUG, "Landscape::IncTreatCounter(): Index"" out of range!", errornum);
3580  exit(1);
3581  }
3582  m_treatment_counts[a_treat] ++;
3583 }
3584 
3585 
3586 void Landscape::DumpTreatCounters(const char * a_filename) {
3587  FILE * l_file = fopen(a_filename, "w");
3588  if (!l_file) {
3589  g_msg->Warn(WARN_FILE, "Landscape::DumpTreatCounters(): ""Unable to open file for writing: %s\n", a_filename);
3590  exit(1);
3591  }
3592 
3593  for (int i = start; i < last_treatment; i++) {
3594  fprintf(l_file, "%3d %s %10d\n", i, EventtypeToString(i).c_str(), m_treatment_counts[i]);
3595  }
3596  fclose(l_file);
3597 }
3598 
3599 void Landscape::DumpMapGraphics(const char * a_filename) {
3600  unsigned int linesize = m_maxextent * 3;
3601  unsigned char * frame_buffer = (unsigned char *)malloc(sizeof(unsigned char)* linesize);
3602 
3603  if (frame_buffer == NULL) {
3604  g_msg->Warn(WARN_FILE, "Landscape::DumpMapGraphics(): Out of memory!", "");
3605  exit(1);
3606  }
3607 
3608  FILE * l_file = fopen(a_filename, "w");
3609  if (!l_file) {
3610  g_msg->Warn(WARN_FILE, "Landscape::DumpMapGraphics(): ""Unable to open file for writing: %s\n", a_filename);
3611  exit(1);
3612  }
3613 
3614  fprintf(l_file, "P6\n%d %d %d\n", m_width, m_height, 255);
3615 
3616  for (int y = 0; y < m_height; y++) {
3617  int i = 0;
3618  for (int x = 0; x < m_width; x++) {
3619  int eletype = (int)SupplyElementType(x, y);
3620  int localcolor = 16777215 / eletype;
3621 
3622  if (eletype == (int)tole_Field) {
3623  int category;
3624  double hei = SupplyVegHeight(x, y);
3625  if (hei > 50.0) category = 0; else category = (int)(200.0 - (hei * 4.0));
3626  localcolor = ((category * 65536) + 65535);
3627  }
3628 
3629  frame_buffer[i++] = (unsigned char)(localcolor & 0xff);
3630  frame_buffer[i++] = (unsigned char)((localcolor >> 8) & 0xff);
3631  frame_buffer[i++] = (unsigned char)((localcolor >> 16) & 0xff);
3632  }
3633  fwrite(frame_buffer, sizeof(unsigned char), linesize, l_file);
3634  }
3635 
3636  fclose(l_file);
3637 
3638  free(frame_buffer);
3639 }
3640 
3642  for (unsigned int i = 0; i < (tov_Undefined + 1); i++) {
3643  l_vegtype_areas[i] = 0.0;
3644  }
3645 
3646  // Sum up statistics on element type.
3647  for (unsigned int i = 0; i < m_elems.size(); i++) {
3648  l_vegtype_areas[m_elems[i]->GetVegType()] += m_elems[i]->GetArea();
3649  }
3650 }
3651 
3652 void Landscape::DumpMapInfoByArea(const char * a_filename, bool a_append, bool a_dump_zero_areas, bool a_write_veg_names) {
3653  FillVegAreaData();
3654  FILE * outf;
3655  if (a_append) {
3656  outf = fopen(a_filename, "a");
3657  if (!outf) {
3658  g_msg->Warn(WARN_FILE, "Landscape::DumpMapInfoByArea(): ""Unable to open file for appending", a_filename);
3659  exit(1);
3660  }
3661  }
3662  else {
3663  outf = fopen(a_filename, "w");
3664  if (!outf) {
3665  g_msg->Warn(WARN_FILE, "Landscape::DumpMapInfoByArea(): ""Unable to open file for writing", a_filename);
3666  exit(1);
3667  }
3668  }
3669 
3670  // Emit element type info.
3671  for (unsigned int i = 0; i < tov_Undefined + 1; i++) {
3672  if (i == tov_OFirstYearDanger)
3673  continue;
3674  if (!a_dump_zero_areas && l_vegtype_areas[i] < 0.5)
3675  continue;
3676 
3677  fprintf(outf, "%6ld\t%3d\t%10.0f", g_date->OldDays() + g_date->DayInYear() - 364, i, l_vegtype_areas[i]);
3678  if (a_write_veg_names)
3679  fprintf(outf, "\t%s\n", VegtypeToString((TTypesOfVegetation)i).c_str()); else
3680  fprintf(outf, "\n");
3681  }
3682 
3683  fclose(outf);
3684 }
3685 
3686 
3687 
3689  LE * elem;
3690  static char error_num[20];
3691 
3692  switch (a_type) {
3693  case tole_Hedges:
3694  elem = new Hedges;
3695  break;
3696  case tole_HedgeBank:
3697  elem = new HedgeBank;
3698  break;
3699  case tole_BeetleBank:
3700  elem = new BeetleBank;
3701  break;
3702  case tole_RoadsideVerge:
3703  elem = new RoadsideVerge;
3704  break;
3705  case tole_Railway:
3706  elem = new Railway;
3707  break;
3708  case tole_FieldBoundary:
3709  elem = new FieldBoundary;
3710  break;
3711  case tole_Marsh:
3712  elem = new Marsh;
3713  break;
3714  case tole_Orchard:
3715  elem = new Orchard;
3716  break;
3717  case tole_OrchardBand:
3718  elem = new OrchardBand;
3719  break;
3720  case tole_MownGrass:
3721  elem = new MownGrass;
3722  break;
3723  case tole_Heath:
3724  elem = new Heath;
3725  break;
3726  case tole_Scrub:
3727  elem = new Scrub;
3728  break;
3729  case tole_Field:
3730  elem = new Field;
3731  break;
3733  elem = new PermanentSetaside;
3734  break;
3735  case tole_PermPasture:
3736  elem = new PermPasture;
3737  break;
3739  elem = new PermPastureLowYield;
3740  break;
3742  elem = new PermPastureTussocky;
3743  break;
3744  case tole_NaturalGrassDry:
3745  elem = new NaturalGrassDry;
3746  break;
3747  case tole_UnknownGrass:
3748  elem = new NaturalGrassDry;
3749  break;
3750  case tole_RiversidePlants:
3751  elem = new RiversidePlants;
3752  break;
3753  case tole_PitDisused:
3754  elem = new PitDisused;
3755  break;
3756  case tole_RiversideTrees:
3757  elem = new RiversideTrees;
3758  break;
3759  case tole_DeciduousForest:
3760  elem = new DeciduousForest;
3761  break;
3762  case tole_MixedForest:
3763  elem = new MixedForest;
3764  break;
3765  case tole_YoungForest:
3766  elem = new YoungForest;
3767  break;
3768  case tole_ConiferousForest:
3769  elem = new ConiferousForest;
3770  break;
3771  case tole_StoneWall:
3772  elem = new StoneWall;
3773  break;
3774  case tole_Fence:
3775  elem = new Fence;
3776  break;
3777  case tole_Garden:
3778  elem = new Garden;
3779  break;
3780  case tole_Track:
3781  elem = new Track;
3782  break;
3783  case tole_SmallRoad:
3784  elem = new SmallRoad;
3785  break;
3786  case tole_LargeRoad:
3787  elem = new LargeRoad;
3788  break;
3789  case tole_Building:
3790  elem = new Building;
3791  break;
3792  case tole_ActivePit:
3793  elem = new ActivePit;
3794  break;
3795  case tole_Freshwater:
3796  elem = new Freshwater;
3797  break;
3798  case tole_Pond:
3799  elem = new Pond;
3800  break;
3801  case tole_River:
3802  elem = new River;
3803  break;
3804  case tole_Saltwater:
3805  elem = new Saltwater;
3806  break;
3807  case tole_Coast:
3808  elem = new Coast;
3809  break;
3810  case tole_BareRock:
3811  elem = new BareRock;
3812  break;
3813  case tole_AmenityGrass:
3814  elem = new AmenityGrass;
3815  break;
3816  case tole_Parkland:
3817  elem = new Parkland;
3818  break;
3819  case tole_UrbanNoVeg:
3820  elem = new UrbanNoVeg;
3821  break;
3822  case tole_UrbanPark:
3823  elem = new UrbanPark;
3824  break;
3826  elem = new BuiltUpWithParkland;
3827  break;
3828  case tole_SandDune:
3829  elem = new SandDune;
3830  break;
3831  case tole_Copse:
3832  elem = new Copse;
3833  break;
3834  case tole_RoadsideSlope:
3835  elem = new RoadsideSlope;
3836  break;
3837  case tole_MetalledPath:
3838  elem = new MetalledPath;
3839  break;
3840  case tole_Carpark:
3841  elem = new Carpark;
3842  break;
3843  case tole_Churchyard:
3844  elem = new Churchyard;
3845  break;
3846  case tole_NaturalGrassWet:
3847  elem = new NaturalGrassWet;
3848  break;
3849  case tole_Saltmarsh:
3850  elem = new Saltmarsh;
3851  break;
3852  case tole_Stream:
3853  elem = new Stream;
3854  break;
3855  case tole_HeritageSite:
3856  elem = new HeritageSite;
3857  break;
3859  elem = new UnsprayedFieldMargin;
3860  break;
3861  case tole_Wasteland:
3862  elem = new Wasteland;
3863  break;
3864  case tole_IndividualTree:
3865  elem = new IndividualTree;
3866  break;
3867  case tole_PlantNursery:
3868  elem = new PlantNursery;
3869  break;
3870  case tole_Vildtager:
3871  elem = new Vildtager;
3872  break;
3873  case tole_WindTurbine:
3874  elem = new WindTurbine;
3875  break;
3876  case tole_WoodyEnergyCrop:
3877  elem = new WoodyEnergyCrop;
3878  break;
3879  case tole_WoodlandMargin:
3880  elem = new WoodlandMargin;
3881  break;
3882  case tole_Pylon:
3883  elem = new Pylon;
3884  break;
3885  case tole_FishFarm:
3886  elem = new FishFarm;
3887  break;
3888  case tole_Missing:
3889  elem = new LE; // These should never be actually used.
3890  break;
3891  case tole_Chameleon:
3892  elem = new ChameleonLE;
3893  break;
3894  case tole_DrainageDitch:
3895  elem = new DrainageDitch;
3896  break;
3897  case tole_UrbanVeg:
3898  elem = new UrbanVeg;
3899  break;
3900  case tole_WaterBufferZone:
3901  elem = new WaterBufferZone;
3902  break;
3903  case tole_Canal:
3904  elem = new Canal;
3905  break;
3906  default:
3907  sprintf(error_num, "%d", a_type);
3908  g_msg->Warn(WARN_FILE, "Landscape::NewElement(): Unknown landscape element requested:", error_num);
3909  exit(1);
3910  } //switch
3911 
3912  elem->SetALMaSSEleType(g_letype->BackTranslateEleTypes(a_type));
3913  elem->SetElementType(a_type);
3915  return elem;
3916 }
3917 
3918 std::string Landscape::EventtypeToString(int a_event) {
3919  char error_num[20];
3920 
3921  switch (a_event) {
3922  case start:
3923  return " start";
3924  case sleep_all_day:
3925  return " sleep_all_day";
3926  case autumn_plough:
3927  return " autumn_plough";
3928  case stubble_plough:
3929  return " stubble_plough";
3931  return " stubble_cultivator_heavy";
3933  return " heavy_cultivator_aggregate";
3934  case autumn_harrow:
3935  return " autumn_harrow";
3936  case preseeding_cultivator:
3937  return " preseeding_cultivator";
3939  return " preseeding_cultivator_sow";
3940  case autumn_roll:
3941  return " autumn_roll";
3942  case autumn_sow:
3943  return " autumn_sow";
3944  case winter_plough:
3945  return " winter_plough";
3946  case deep_ploughing:
3947  return " deep_ploughing";
3948  case spring_plough:
3949  return " spring_plough";
3950  case spring_harrow:
3951  return " spring_harrow";
3952  case spring_roll:
3953  return " spring_roll";
3954  case spring_sow:
3955  return " spring_sow";
3956  case spring_sow_with_ferti:
3957  return " spring_sow_with_ferti";
3958  case fp_npks:
3959  return " fp_npks";
3960  case fp_npk:
3961  return " fp_npk";
3962  case fp_pk:
3963  return " fp_pk";
3964  case fp_liquidNH3:
3965  return " fp_liquidNH3";
3966  case fp_slurry:
3967  return " fp_slurry";
3968  case fp_ammoniumsulphate:
3969  return " fp_ammoniumsulphate";
3970  case fp_manganesesulphate:
3971  return " fp_manganesesulphate";
3972  case fp_manure:
3973  return " fp_manure";
3974  case fp_greenmanure:
3975  return " fp_greenmanure";
3976  case fp_sludge:
3977  return " fp_sludge";
3978  case fp_rsm:
3979  return " fp_rsm";
3980  case fp_calcium:
3981  return " fp_calcium";
3982  case fa_npk:
3983  return " fa_npk";
3984  case fa_pk:
3985  return " fa_pk";
3986  case fa_slurry:
3987  return " fa_slurry";
3988  case fa_ammoniumsulphate:
3989  return " fa_ammoniumsulphate";
3990  case fa_manganesesulphate:
3991  return " fa_manganesesulphate";
3992  case fa_manure:
3993  return " fa_manure";
3994  case fa_greenmanure:
3995  return " fa_greenmanure";
3996  case fa_sludge:
3997  return " fa_sludge";
3998  case fa_rsm:
3999  return " fa_rsm";
4000  case fa_calcium:
4001  return " fa_calcium";
4002  case herbicide_treat:
4003  return " herbicide_treat";
4004  case growth_regulator:
4005  return " growth_regulator";
4006  case fungicide_treat:
4007  return " fungicide_treat";
4008  case insecticide_treat:
4009  return " insecticide_treat";
4010  case product_treat:
4011  return "pesticide_product_treat";
4012  case syninsecticide_treat:
4013  return " syninsecticide_treat";
4014  case molluscicide:
4015  return " molluscicide";
4016  case row_cultivation:
4017  return " row_cultivation";
4018  case strigling:
4019  return " strigling";
4020  case flammebehandling:
4021  return " flammebehandling";
4022  case hilling_up:
4023  return " hilling_up";
4024  case water:
4025  return " water";
4026  case swathing:
4027  return " swathing";
4028  case harvest:
4029  return " harvest";
4030  case cattle_out:
4031  return " cattle_out";
4032  case pigs_out:
4033  return " pigs_out";
4034  case cut_to_hay:
4035  return " cut_to_hay";
4036  case cut_to_silage:
4037  return " cut_to_silage";
4038  case straw_chopping:
4039  return " straw_chopping";
4040  case hay_turning:
4041  return " hay_turning";
4042  case hay_bailing:
4043  return " hay_bailing";
4044  case stubble_harrowing:
4045  return " stubble_harrowing";
4047  return "autumn_or_spring_plough";
4048  case burn_straw_stubble:
4049  return " burn_straw_stubble";
4050  case mow:
4051  return " mow";
4052  case cut_weeds:
4053  return " cut_weeds";
4054  case strigling_sow:
4055  return " strigling_sow";
4057  return "PesticideTrialTreatment";
4058  case trial_toxiccontrol:
4059  return " PesticideTrialToxic";
4060  case trial_control:
4061  return " PesticideTrialControl";
4062  case glyphosate:
4063  return " Glyphosate on setaside";
4064  case biocide:
4065  return " biocide";
4066  case strigling_hill:
4067  return " strigling_hill";
4068  case bed_forming:
4069  return " bed_forming";
4070  case flower_cutting:
4071  return " flower_cutting";
4072  case bulb_harvest:
4073  return " bulb_harvest";
4074  case straw_covering:
4075  return " straw_covering";
4076  case straw_removal:
4077  return " straw_removal";
4078  default:
4079  sprintf(error_num, "%d", a_event);
4080  g_msg->Warn(WARN_FILE, "Landscape::EventtypeToString(): Unknown event type:", error_num);
4081  exit(1);
4082  }
4083 }
4084 
4085 
4086 
4088  char error_num[20];
4089 
4090  switch (a_le_type) {
4091  case tole_Hedges:
4092  return " Hedge";
4093  case tole_RoadsideVerge:
4094  return " Roadside Verge";
4095  case tole_Railway:
4096  return " Railway";
4097  case tole_FieldBoundary:
4098  return " Field Boundary";
4099  case tole_Marsh:
4100  return " Marsh";
4101  case tole_Scrub:
4102  return " Scrub";
4103  case tole_Field:
4104  return " Field";
4106  return " PermPastureTussocky";
4108  return " Permanent Setaside";
4109  case tole_PermPasture:
4110  return " Permanent Pasture";
4112  return " PermPastureLowYield";
4113  case tole_NaturalGrassDry:
4114  return " Natural Grass";
4115  case tole_NaturalGrassWet:
4116  return " Natural Grass Wet";
4117  case tole_RiversidePlants:
4118  return " Riverside Plants";
4119  case tole_PitDisused:
4120  return " Pit Disused";
4121  case tole_RiversideTrees:
4122  return " Riverside Trees";
4123  case tole_DeciduousForest:
4124  return " Deciduous Forest";
4125  case tole_MixedForest:
4126  return " Mixed Forest";
4127  case tole_ConiferousForest:
4128  return " Coniferous Forest";
4129  case tole_YoungForest:
4130  return " Young Forest";
4131  case tole_StoneWall:
4132  return " Stone Wall";
4133  case tole_Garden:
4134  return " Garden";
4135  case tole_Track:
4136  return " Track";
4137  case tole_SmallRoad:
4138  return " Small Road";
4139  case tole_LargeRoad:
4140  return " Large Road";
4141  case tole_Building:
4142  return " Building";
4143  case tole_ActivePit:
4144  return " Active Pit";
4145  case tole_Pond:
4146  return " Pond";
4147  case tole_Freshwater:
4148  return " Fresh Water";
4149  case tole_River:
4150  return " River";
4151  case tole_Saltwater:
4152  return " Saltwater";
4153  case tole_Coast:
4154  return " Coast";
4155  case tole_BareRock:
4156  return " Bare Rock";
4157  case tole_HedgeBank:
4158  return " Hedgebank";
4159  case tole_Heath:
4160  return " Heath";
4161  case tole_Orchard:
4162  return " Orchard";
4163  case tole_OrchardBand:
4164  return " Orchard Band";
4165  case tole_MownGrass:
4166  return " Mown Grass";
4168  return " UnsprayedFieldMargin";
4169  case tole_AmenityGrass:
4170  return " AmenityGrass";
4171  case tole_Parkland:
4172  return " Parkland";
4173  case tole_UrbanNoVeg:
4174  return " UrbanNoVeg";
4175  case tole_UrbanVeg:
4176  return " UrbanVeg";
4177  case tole_UrbanPark:
4178  return " UrbanPark";
4180  return " BuiltUpWithParkland";
4181  case tole_SandDune:
4182  return " SandDune";
4183  case tole_Copse:
4184  return " Copse";
4185  case tole_RoadsideSlope:
4186  return " RoadsideSlope";
4187  case tole_MetalledPath:
4188  return " MetalledPath";
4189  case tole_Carpark:
4190  return " Carpark";
4191  case tole_Churchyard:
4192  return " Churchyard";
4193  case tole_Saltmarsh:
4194  return " Saltmarsh";
4195  case tole_Stream:
4196  return " Stream";
4197  case tole_HeritageSite:
4198  return " HeritageSite";
4199  case tole_BeetleBank: //141
4200  return " Beetle Bank";
4201  case tole_UnknownGrass:
4202  return " Unknown Grass";
4203  case tole_Wasteland:
4204  return " Waste/Building Land";
4205  case tole_IndividualTree:
4206  return " IndividualTree";
4207  case tole_PlantNursery:
4208  return " PlantNursery";
4209  case tole_Vildtager:
4210  return " Vildtager";
4211  case tole_WindTurbine:
4212  return " WindTurbine";
4213  case tole_WoodyEnergyCrop:
4214  return " WoodyEnergyCrop";
4215  case tole_WoodlandMargin:
4216  return " WoodlandMargin";
4217  case tole_Pylon:
4218  return " Pylon";
4219  case tole_FishFarm:
4220  return " FishFarm";
4221  case tole_Fence:
4222  return " Fence";
4223  case tole_WaterBufferZone:
4224  return " Unsprayed buffer zone around water";
4225  case tole_Foobar:
4226  default:
4227  sprintf(error_num, "%d", a_le_type);
4228  g_msg->Warn(WARN_FILE, "Landscape::PolytypeToString(): Unknown event type:", error_num);
4229  exit(1);
4230  }
4231 }
4232 
4233 
4234 
4236  char error_num[20];
4237 
4238  switch (a_veg) {
4239  case tov_Carrots:
4240  return "Carrots ";
4241  case tov_BroadBeans:
4242  return "BroadBeans ";
4243  case tov_FodderGrass:
4244  return "FodderGrass ";
4246  return "CloverGrassGrazed1 ";
4248  return "CloverGrassGrazed2 ";
4249  case tov_FieldPeas:
4250  return "FieldPeas ";
4251  case tov_FieldPeasSilage:
4252  return "FieldPeasSilage ";
4253  case tov_FodderBeet:
4254  return "FodderBeet ";
4255  case tov_SugarBeet:
4256  return "SugarBeet ";
4257  case tov_OFodderBeet:
4258  return "OFodderBeet ";
4259  case tov_Lawn:
4260  return "Lawn ";
4261  case tov_Maize:
4262  return "Maize ";
4263  case tov_MaizeSilage:
4264  return "MaizeSilage ";
4265  case tov_OMaizeSilage:
4266  return "OMaizeSilage ";
4267  case tov_NaturalGrass:
4268  return "NaturalGrass ";
4269  case tov_NoGrowth:
4270  return "NoGrowth ";
4271  case tov_None:
4272  return "None ";
4273  case tov_OrchardCrop:
4274  return "OrchardCrop ";
4275  case tov_Oats:
4276  return "Oats ";
4278  return "OBarleyPeaCloverGrass";
4279  case tov_OCarrots:
4280  return "OCarrots ";
4282  return "OCloverGrassGrazed1 ";
4284  return "OCloverGrassGrazed2 ";
4286  return "OCloverGrassSilage1 ";
4287  case tov_OFieldPeas:
4288  return "OFieldPeas ";
4289  case tov_OFieldPeasSilage:
4290  return "OFieldPeasSilage ";
4291  case tov_OFirstYearDanger:
4292  return "OFirstYearDanger ";
4293  case tov_OGrazingPigs:
4294  return "OGrazingPigs ";
4295  case tov_OOats:
4296  return "OOats ";
4298  return "OPermanentGrassGrazed";
4299  case tov_OPotatoes:
4300  return "OPotatoes ";
4301  case tov_OSBarleySilage:
4302  return "OSBarleySilage ";
4303  case tov_OSeedGrass1:
4304  return "OSeedGrass1 ";
4305  case tov_OSeedGrass2:
4306  return "OSeedGrass2 ";
4307  case tov_OSetaside:
4308  return "OSetaside ";
4309  case tov_OSpringBarley:
4310  return "OSpringBarley ";
4311  case tov_OSpringBarleyExt:
4312  return "OSpringBarleyExt ";
4314  return "OSpringBarleyClover ";
4316  return "OSpringBarleyGrass ";
4317  case tov_OSpringBarleyPigs:
4318  return "OSpringBarleyPigs ";
4319  case tov_OTriticale:
4320  return "OTriticale ";
4321  case tov_OWinterBarley:
4322  return "OWinterBarley ";
4323  case tov_OWinterBarleyExt:
4324  return "OWinterBarleyExt ";
4325  case tov_OWinterRape:
4326  return "OWinterRape ";
4327  case tov_OWinterRye:
4328  return "OWinterRye ";
4330  return "OWinterWheatUndersown";
4331  case tov_OWinterWheat:
4332  return "OWinterWheat";
4334  return "OWinterWheatUsowExt ";
4336  return "PermanentGrassGrazed ";
4338  return "PermanentGrassLowYield";
4340  return "PermanentGrassTussocky";
4341  case tov_PermanentSetaside:
4342  return "PermanentSetaside ";
4343  case tov_Potatoes:
4344  return "PotatoesEat ";
4345  case tov_PotatoesIndustry:
4346  return "PotatoesIndustry ";
4347  case tov_SeedGrass1:
4348  return "SeedGrass1 ";
4349  case tov_SeedGrass2:
4350  return "SeedGrass2 ";
4351  case tov_Setaside:
4352  return "Setaside ";
4353  case tov_SpringBarley:
4354  return "SpringBarley ";
4355  case tov_SpringBarleySpr:
4356  return "SpringBarleySpr ";
4358  return "SpringBarleyPTreat ";
4360  return "SpringBarleySKMan ";
4362  return "SprBarleyCloverGrass ";
4363  case tov_SpringBarleyGrass:
4364  return "SpringBarleyGrass ";
4365  case tov_SpringBarleySeed:
4366  return "SpringBarleySeed ";
4368  return "SpringBarleySilage ";
4369  case tov_SpringRape:
4370  return "SpringRape ";
4371  case tov_SpringWheat:
4372  return "SpringWheat ";
4374  return "AgroChemIndustry Cereal ";
4375  case tov_Triticale:
4376  return "Triticale ";
4377  case tov_WinterBarley:
4378  return "WinterBarley ";
4379  case tov_WinterRape:
4380  return "WinterRape ";
4381  case tov_WinterRye:
4382  return "WinterRye ";
4383  case tov_WinterWheat:
4384  return "WinterWheat ";
4385  case tov_WinterWheatShort:
4386  return "WinterWheatShort ";
4387  case tov_WWheatPControl:
4388  return "P Trial Control ";
4390  return "P Trial Toxic Control";
4391  case tov_WWheatPTreatment:
4392  return "P Trial Treatment ";
4393  case tov_Undefined:
4394  return "Undefined ";
4396  return "WWStrigling ";
4398  return "WWStriglingSingle ";
4400  return "WWStriglingCulm ";
4402  return "SBPCGStrigling ";
4404  return "SBarleyStrigling ";
4406  return "SBarleyStriglingSgl ";
4408  return "SBarleyStriglingCulm ";
4409  case tov_MaizeStrigling:
4410  return "MaizseStrigling ";
4412  return "WRapeStrigling ";
4414  return "WRyeStrigling ";
4416  return "WBStrigling ";
4418  return "FieldPeasStrigling ";
4420  return "SBPeaCloverGrassStr ";
4421  case tov_YoungForest:
4422  return "Young Forest ";
4423  case tov_Wasteland:
4424  return "Wasteland ";
4425  case tov_Heath:
4426  return "Heath/Grass ";
4427  case tov_PlantNursery:
4428  return "Plant Nursery ";
4429  case tov_NorwegianPotatoes:
4430  return "Norwegian Potatoes ";
4431  case tov_NorwegianOats:
4432  return "Norwegian Oats ";
4434  return "Norwegian Spr. Barley";
4435 
4436  case tov_WaterBufferZone:
4437  return "Unsprayed buffer zone around water";
4438 
4439  case tov_PLWinterWheat:
4440  return "Polish Winter Wheat ";
4441  case tov_PLWinterRape:
4442  return "Polish Winter Rape ";
4443  case tov_PLWinterBarley:
4444  return "Polish Winter Barley ";
4445  case tov_PLWinterTriticale:
4446  return "Polish Winter Triticale ";
4447  case tov_PLWinterRye:
4448  return "Polish Winter Rye ";
4449  case tov_PLSpringWheat:
4450  return "Polish Spring Wheat ";
4451  case tov_PLSpringBarley:
4452  return "Polish Spring Barley ";
4453  case tov_PLMaize:
4454  return "Polish Maize ";
4455  case tov_PLMaizeSilage:
4456  return "Polish Maize Silage ";
4457  case tov_PLPotatoes:
4458  return "Polish Potatoes ";
4459  case tov_PLBeet:
4460  return "Polish Beet ";
4461  case tov_PLFodderLucerne1:
4462  return "Polish Fodder Lucerne first year ";
4463  case tov_PLFodderLucerne2:
4464  return "Polish Fodder Lucerne second/third year ";
4465  case tov_PLCarrots:
4466  return "Polish Carrots ";
4467  case tov_PLSpringBarleySpr:
4468  return "Polish Spring Barley with Spring Plough ";
4469  case tov_PLWinterWheatLate:
4470  return "Polish Winter Wheat late sown ";
4471  case tov_PLBeetSpr:
4472  return "Polish Beet with Spring Plough ";
4473  case tov_PLBeans:
4474  return "Polish Beans ";
4475 
4476  case tov_NLBeet:
4477  return "Dutch Beet ";
4478  case tov_NLCarrots:
4479  return "Dutch Carrots ";
4480  case tov_NLMaize:
4481  return "Dutch Maize ";
4482  case tov_NLPotatoes:
4483  return "Dutch Potatoes ";
4484  case tov_NLSpringBarley:
4485  return "Dutch Spring Barley ";
4486  case tov_NLWinterWheat:
4487  return "Dutch Winter Wheat ";
4488  case tov_NLCabbage:
4489  return "Dutch Cabbage ";
4490  case tov_NLTulips:
4491  return "Dutch Tulips ";
4492  case tov_NLGrassGrazed1:
4493  return "Dutch TemporalGrassGrazed1 ";
4495  return "Dutch TemporalGrassGrazed1 after catch crop ";
4496  case tov_NLGrassGrazed2:
4497  return "Dutch TemporalGrassGrazed2 ";
4498  case tov_NLGrassGrazedLast:
4499  return "Dutch TemporalGrassGrazedLast ";
4501  return "Dutch PermanentGrassGrazed ";
4502  case tov_NLBeetSpring:
4503  return "Dutch Beet after catch crop ";
4504  case tov_NLCarrotsSpring:
4505  return "Dutch Carrots after catch crop ";
4506  case tov_NLMaizeSpring:
4507  return "Dutch Maize after catch crop ";
4508  case tov_NLPotatoesSpring:
4509  return "Dutch Potatoes after catch crop ";
4511  return "Dutch Spring Barley after catch crop ";
4512  case tov_NLCabbageSpring:
4513  return "Dutch Cabbage after catch crop ";
4514  case tov_NLCatchPeaCrop:
4515  return "Dutch Catch Pea Crop ";
4516 
4518  return "Dummy Crop for Testing of Pesticide Sparying Distribution ";
4519 
4520  default:
4521  sprintf(error_num, "%d", a_veg);
4522  g_msg->Warn(WARN_FILE, "Landscape::VegtypeToString(): Unknown event type:", error_num);
4523  exit(1);
4524  }
4525 }
4526 
4527 
4528 
4530  static char error_num[20];
4531  bool AddBorder = false;
4532  switch (a_letype) {
4533  // No border is needed toward these neighbouring element types.
4534  case tole_Hedges:
4535  case tole_HedgeBank:
4536  case tole_BeetleBank:
4537  case tole_RoadsideVerge:
4538  case tole_Marsh:
4539  case tole_RiversidePlants:
4541  case tole_OrchardBand:
4542  case tole_MownGrass:
4543  case tole_WaterBufferZone:
4544  break;
4545 
4546  case tole_IndividualTree:
4547  case tole_PlantNursery:
4548  case tole_Vildtager:
4549  case tole_WindTurbine:
4550  case tole_WoodyEnergyCrop:
4551  case tole_WoodlandMargin:
4552  case tole_Pylon:
4553  case tole_NaturalGrassDry:
4554  case tole_Railway:
4555  case tole_FieldBoundary:
4556  case tole_Scrub:
4557  case tole_Field:
4559  case tole_PermPasture:
4562  case tole_PitDisused:
4563  case tole_RiversideTrees:
4564  case tole_DeciduousForest:
4565  case tole_MixedForest:
4566  case tole_YoungForest:
4567  case tole_ConiferousForest:
4568  case tole_StoneWall:
4569  case tole_Fence:
4570  case tole_Garden:
4571  case tole_Track:
4572  case tole_SmallRoad:
4573  case tole_LargeRoad:
4574  case tole_Building:
4575  case tole_ActivePit:
4576  case tole_Pond:
4577  case tole_FishFarm:
4578  case tole_Freshwater:
4579  case tole_River:
4580  case tole_Saltwater:
4581  case tole_Coast:
4582  case tole_BareRock:
4583  case tole_Heath:
4584  case tole_Orchard:
4585  case tole_AmenityGrass:
4586  case tole_Parkland:
4587  case tole_UrbanNoVeg:
4588  case tole_UrbanVeg:
4589  case tole_UrbanPark:
4591  case tole_SandDune:
4592  case tole_Copse:
4593  case tole_NaturalGrassWet:
4594  case tole_RoadsideSlope:
4595  case tole_MetalledPath:
4596  case tole_Carpark:
4597  case tole_Churchyard:
4598  case tole_Saltmarsh:
4599  case tole_Stream:
4600  case tole_HeritageSite:
4601  AddBorder = true;
4602  break;
4603 
4604  default:
4605  sprintf(error_num, "%d", a_letype);
4606  g_msg->Warn(WARN_BUG, "Landscape::BorderNeed(): Unknown element type:", error_num);
4607  exit(1);
4608  }
4609  return AddBorder;
4610 }
4611 
4612 
4613 
4614 /* Caution: The trace file file generated has an offset * in the reported date off by one! This looks like
4615 * something is severely broken, but in reality I'm just * too lazy to fix this (design problem). */
4616 /*
4617 void Landscape::TestCropManagement( void ) {
4618 FILE * tracefile;
4619 
4620 tracefile = fopen(g_farm_test_crop_filename.value(), "w" )
4621 if (!tracefile){
4622 g_msg->Warn( WARN_FILE, "Landscape::TestCropManagement(): ""Unable to open file for writing: ",
4623 g_farm_test_crop_filename.value() );
4624 exit( 1 );
4625 }
4626 
4627 // Loop through the polygons and find one with 'our'
4628 // vegetation type.
4629 int l_poly;
4630 for ( unsigned int i = 0; i < m_elems.size(); i++ ) {
4631 if ( m_elems[ i ]->GetVegType() == g_farm_test_crop_type.value() ) {
4632 l_poly = m_elems[ i ]->GetPoly();
4633 break;
4634 }
4635 }
4636 
4637 //int poly = SupplyPolyRef( g_farm_test_crop_sample_x.value(),
4638 // g_farm_test_crop_sample_y.value() );
4639 //int poly = 943;
4640 int inf = 0;
4641 int d = 0;
4642 while ( 1 ) { //Mysterious - what does this do?
4643 Tick();
4644 if ( ++inf > 364 ) {
4645 printf( "%6d\n", ++d );
4646 inf = 0;
4647 }
4648 }
4649 
4650 fprintf( tracefile, "Polygon: %d\n", l_poly );
4651 fprintf( tracefile, "EleType: %d\n", SupplyElementType( l_poly ) ),
4652 fprintf( tracefile, "VegType: %d\n", SupplyVegType( l_poly ) );
4653 
4654 for ( int x = 0; x < g_farm_test_crop_daystorun.value(); x++ ) {
4655 Tick();
4656 int index = 0, last;
4657 int day = SupplyDayInMonth();
4658 int month = SupplyMonth();
4659 int year = SupplyYear();
4660 long date = SupplyGlobalDate();
4661 int veg = SupplyVegType( l_poly );
4662 
4663 do {
4664 last = SupplyLastTreatment( l_poly, & index );
4665 
4666 // Comment out if you want to know *everything*,
4667 // including nothing, that happens evey day on the test field.
4668 if ( last == sleep_all_day && !g_farm_test_crop_reportdaily.value() )
4669 continue;
4670 
4671 fprintf( tracefile, "%2d %2d %4d %5ld %s %2d :: ""%7.2f %7.2f %7.2f %7.2f\n", day, month, year, date, EventtypeToString( last ),
4672 veg, SupplyVegBiomass( l_poly ), SupplyVegCover( l_poly ), SupplyVegHeight( l_poly ), SupplyInsects( l_poly ) );
4673 } while ( last != sleep_all_day );
4674 }
4675 
4676 fclose( tracefile );
4677 }
4678 */
4679 
4681 
4682  if (cfg_dumpvegjan.value()) {
4683  if ((a_day % 365) == 0) { // Jan 1st
4684  DumpMapInfoByArea(cfg_dumpvegjanfile.value(), true, true, true);
4685  return;
4686  }
4687  }
4688  if (cfg_dumpvegjune.value()) {
4689  if ((a_day % 365) == 152) { // 1st June
4690  DumpMapInfoByArea(cfg_dumpvegjunefile.value(), true, true, true);
4691  }
4692  }
4693 
4694 }
4695 //------------------------------------------------------------------------------
4696 
4698 {
4700  array<int, tole_Foobar> tole_ref;
4701  array<double, tole_Foobar> maxOsmiaNests;
4702  array<double, tole_Foobar> minOsmiaNests;
4703  fstream ifile(cfg_OsmiaNestByLE_Datafile.value(), ios::in);
4704  if (!ifile.is_open()) {
4705  g_msg->Warn("Cannot open file: ", cfg_OsmiaNestByLE_Datafile.value());
4706  exit(1);
4707  }
4708  // Read the file tole type by tole type - here we can't rely on the order but need the tole number
4709  int length;
4710  ifile >> length;
4711  if (length != tole_Foobar) {
4712  g_msg->Warn("Inconsistent file length with tole_Foobar: ", int(tole_Foobar));
4713  exit(1);
4714  }
4715  // read the file
4716  for (int i = 0; i < length; i++)
4717  {
4718  ifile >> tole_ref[i] >> minOsmiaNests[i] >> maxOsmiaNests[i];
4719  }
4720  ifile.close();
4721  for (unsigned int e = 0; e < m_elems.size(); e++) {
4722  int eletype = m_elems[e]->GetALMaSSEleType();
4723  // first find the eletype
4724  int found = -1;
4725  for (int j = 0; j < length; j++)
4726  {
4727  if (tole_ref[j] == eletype) {
4728  found = j;
4729  break;
4730  }
4731  }
4732  if (found == -1) {
4733  g_msg->Warn("Inconsistent file data, missing tole type ref: ", eletype);
4734  exit(1);
4735  }
4736  // We have the ref type, so now calculate the number of nests and set it
4737  m_elems[e]->SetMaxOsmiaNests(minOsmiaNests[found] + double(g_rand_uni() * (maxOsmiaNests[found] - minOsmiaNests[found])));
4738  }
4739 }
4740 
version_major
static const int version_major
Definition: Landscape.cpp:49
LE_TypeClass::BackTranslateEleTypes
int BackTranslateEleTypes(TTypesOfLandscapeElement EleReference)
Definition: elements.cpp:3610
insecticide_treat
Definition: treatment.h:74
cfg_BeetleBankType
static CfgInt cfg_BeetleBankType("BBANK_TYPE", CFG_CUSTOM,(int) tole_BeetleBank)
Landscape::CalculateCentroids
void CalculateCentroids(void)
Definition: Landscape.cpp:3040
tov_AgroChemIndustryCereal
Definition: tov_declaration.h:55
cfg_B6B
CfgFloat cfg_B6B
cfg_herbi_app_prop
CfgFloat cfg_herbi_app_prop("CROPS_HERBICIDE_APPLIC_PROPORTION", CFG_CUSTOM, 1.0)
tov_OSpringBarleyClover
Definition: tov_declaration.h:46
tole_HedgeBank
Definition: tole_declaration.h:68
tole_UrbanNoVeg
Definition: tole_declaration.h:78
tov_SpringBarleyStrigling
Definition: tov_declaration.h:58
tov_PLWinterWheatLate
Definition: tov_declaration.h:85
cfg_dumpvegjan
CfgBool cfg_dumpvegjan("G_VEGAREASJAN_ON", CFG_CUSTOM, false)
tov_PLSpringWheat
Definition: tov_declaration.h:75
tov_NLSpringBarley
Definition: tov_declaration.h:93
Landscape::ResetGrainAndMaize
void ResetGrainAndMaize()
Resets all grain.
Definition: Landscape.cpp:730
tole_Saltwater
Definition: tole_declaration.h:66
l_map_dump_veg_enable
static CfgBool l_map_dump_veg_enable("MAP_DUMP_VEG_ENABLE", CFG_CUSTOM, true)
HeritageSite
Definition: elements.h:1304
Landscape::SupplyLEPointer
LE * SupplyLEPointer(int a_polyref)
Definition: landscape.h:1099
tov_NLMaizeSpring
Definition: tov_declaration.h:102
ConiferousForest
Definition: elements.h:961
cfg_B6F
CfgFloat cfg_B6F
Landscape::DumpMapInfoByArea
void DumpMapInfoByArea(const char *a_filename, bool a_append, bool a_dump_zero_areas, bool a_write_veg_names)
Definition: Landscape.cpp:3652
GooseFieldListItem::grass
double grass[gs_foobar]
Definition: landscape.h:91
g_map_le_borderwidth
CfgInt g_map_le_borderwidth("MAP_LE_BORDER_WIDTH", CFG_CUSTOM, 1)
cfg_map_usesoiltypes
static CfgBool cfg_map_usesoiltypes("MAP_USESOILTYPES", CFG_CUSTOM, false)
tov_Oats
Definition: tov_declaration.h:40
tole_UnsprayedFieldMargin
Definition: tole_declaration.h:72
tov_OWinterBarley
Definition: tov_declaration.h:47
tole_UrbanVeg
Definition: tole_declaration.h:103
LE::SetOwner
void SetOwner(Farm *a_owner, int a_owner_num, int a_owner_index)
Definition: elements.h:219
strigling
Definition: treatment.h:77
Landscape::SubtractPondLarvalFood
bool SubtractPondLarvalFood(double a_food, int a_polyrefindex)
Removes larval food from a pond and returns true if it was possible, otherwise false.
Definition: Landscape.cpp:664
GooseFieldListItem::lastsownveg
std::string lastsownveg
Definition: landscape.h:98
tov_NLPotatoes
Definition: tov_declaration.h:92
tole_Missing
Definition: tole_declaration.h:109
CfgStr::value
const char * value(void)
Definition: configurator.h:152
cfg_strigling_prop
CfgFloat cfg_strigling_prop("CROPS_STRIGLING_PROPORTION", CFG_CUSTOM, 1.0)
hay_bailing
Definition: treatment.h:89
PlantProtectionProducts
PlantProtectionProducts
A list PPP names for tracking by the Pesticide class.
Definition: farm.h:420
flower_cutting
Definition: treatment.h:109
Calendar::GetYear
int GetYear(void)
Definition: calendar.h:67
autumn_roll
Definition: treatment.h:38
DrainageDitch
Definition: elements.h:1239
g_generator
base_generator_type g_generator(static_cast< unsigned int >(std::time(0)))
l_map_dump_event_x2
static CfgInt l_map_dump_event_x2("MAP_DUMP_EVENT_XB", CFG_CUSTOM, 4333)
spring_sow_with_ferti
Definition: treatment.h:103
tole_Building
Definition: tole_declaration.h:62
l_map_dump_treatcounts_file
static CfgStr l_map_dump_treatcounts_file("MAP_DUMP_TREATCOUNTS_FILE", CFG_CUSTOM, "treatment_counts.txt")
Landscape::SupplyPesticideDecay
bool SupplyPesticideDecay(PlantProtectionProducts a_ppp)
Returns true if there is any pesticide in the system at all at this point.
Definition: Landscape.cpp:776
l_map_check_polygon_xref
static CfgBool l_map_check_polygon_xref("MAP_CHECK_POLYGON_XREF", CFG_CUSTOM, true)
cfg_BeetleBankMinY
CfgInt cfg_BeetleBankMinY("BBANK_MINY", CFG_CUSTOM, 0)
g_landscape_p
Landscape * g_landscape_p
Definition: Landscape.cpp:258
Landscape::DumpMap
void DumpMap(const char *a_filename)
Definition: Landscape.cpp:1386
cfg_P1H
CfgStr cfg_P1H
tole_Freshwater
Definition: tole_declaration.h:64
GooseFieldListItem::vegheight
double vegheight
Definition: landscape.h:94
Landscape::SupplyRandomPondRef
int SupplyRandomPondRef()
Returns random pond polyref.
Definition: Landscape.cpp:2610
tov_OPermanentGrassGrazed
Definition: tov_declaration.h:44
g_map_le_borders_min_field_size
CfgInt g_map_le_borders_min_field_size("MAP_LE_BORDERS_MIN_FIELD_SIZE", CFG_CUSTOM, 10000)
LE::GetArea
double GetArea(void)
Definition: elements.h:196
l_map_dump_event_x1
static CfgInt l_map_dump_event_x1("MAP_DUMP_EVENT_XA", CFG_CUSTOM, 4287)
Orchard
Definition: elements.h:992
NaturalGrassWet
Definition: elements.h:874
g_pest
class Pesticide * g_pest
Definition: pesticide.cpp:92
tole_Parkland
Definition: tole_declaration.h:77
Railway
Definition: elements.h:920
Landscape::PolysDump
void PolysDump(const char *a_filename)
Definition: Landscape.cpp:1803
tole_StoneWall
Definition: tole_declaration.h:56
Copse
Definition: elements.h:947
cfg_pesticidemapstartyear
CfgInt cfg_pesticidemapstartyear("PEST_MAP_STARTYEAR", CFG_CUSTOM, 0)
The first simulation year the pesticide is mapped.
cfg_MaizeEnergy
CfgBool cfg_MaizeEnergy
If set to true, the energy maize crop is included in the simulation.
Landscape::CalulateFieldOpennessCentroid
int CalulateFieldOpennessCentroid(int a_pref)
Provides a measure of the shortest distance in 360 degree, e-g- looking NE % SW before tall obstacles...
Definition: Landscape.cpp:359
tole_RiversidePlants
Definition: tole_declaration.h:49
tole_FishFarm
Definition: tole_declaration.h:102
tov_PLSpringBarleySpr
Definition: tov_declaration.h:84
GooseFieldListItem::geeseTimed
int geeseTimed
Definition: landscape.h:85
Landscape::VegtypeToString
std::string VegtypeToString(TTypesOfVegetation a_veg)
Definition: Landscape.cpp:4235
Landscape::RemoveSmallPolygons
int RemoveSmallPolygons(void)
Removes small polygons from the map.
Definition: Landscape.cpp:2184
g_rand_uni2
boost::variate_generator< base_generator_type &, boost::uniform_int<> > g_rand_uni2(g_generator, g_uni_dist2)
cfg_fungi_app_prop3
CfgFloat cfg_fungi_app_prop3("CROPS_FUNGICIDE_APPLIC_THREE_PROPORTION", CFG_CUSTOM, 1.0)
tole_Garden
Definition: tole_declaration.h:58
Landscape::~Landscape
~Landscape(void)
Definition: Landscape.cpp:1424
g_rand_uni3
boost::variate_generator< base_generator_type &, boost::uniform_int<> > g_rand_uni3(g_generator, g_uni_dist3)
Landscape::SupplyLECount
int SupplyLECount(void)
Definition: Landscape.cpp:3562
Landscape::UMarginTest
bool UMarginTest(int a_fieldpoly, int a_borderpoly, int a_x, int a_y, int a_width)
Definition: Landscape.cpp:2669
tov_OOats
Definition: tov_declaration.h:44
cfg_B6H
CfgStr cfg_B6H
Pesticide::SupplyPesticide
double SupplyPesticide(int a_x, int a_y, PlantProtectionProducts a_ppp)
Definition: pesticide.h:329
tole_Churchyard
Definition: tole_declaration.h:86
cfg_pesticidemapon
CfgBool cfg_pesticidemapon("PEST_MAP_ON", CFG_CUSTOM, false)
Flag determining whether we are using the pesticide map.
fa_ammoniumsulphate
Definition: treatment.h:65
Calendar::GetYearNumber
int GetYearNumber(void)
Definition: calendar.h:68
tole_RoadsideSlope
Definition: tole_declaration.h:83
autumn_harrow
Definition: treatment.h:37
Landscape::BorderStep
bool BorderStep(int a_fieldpoly, int a_borderpoly, int *a_x, int *a_y)
Definition: Landscape.cpp:2479
polylist
vector< unsigned > polylist
Definition: farm.h:207
tole_MixedForest
Definition: tole_declaration.h:53
g_map_le_borders
CfgBool g_map_le_borders("MAP_LE_BORDERS", CFG_CUSTOM, false)
preseeding_cultivator
Definition: treatment.h:39
cfg_G6H
CfgStr cfg_G6H
g_uni_dist3
boost::uniform_int g_uni_dist3(0, 999)
Landscape::RecordGooseNumbersTimed
void RecordGooseNumbersTimed(int a_poly, int a_number)
This records the number of geese on the polygon the day before at a predefined time....
Definition: Landscape.cpp:3341
cfg_ins_app_prop2
CfgFloat cfg_ins_app_prop2("CROPS_INSECTICIDE_APPLIC_TWO_PROPORTION", CFG_CUSTOM, 1.0)
tov_OSetaside
Definition: tov_declaration.h:46
tov_PLMaizeSilage
Definition: tov_declaration.h:78
cfg_BeetleBankChance
static CfgInt cfg_BeetleBankChance("BBANK_CHANCE", CFG_CUSTOM, 100)
tov_OTriticale
Definition: tov_declaration.h:47
Landscape::RemoveMissingValues
void RemoveMissingValues()
A method for replacing missing values in the map with corrected ones - slow.
Definition: Landscape.cpp:2090
flammebehandling
Definition: treatment.h:78
cfg_WriteCurve
CfgBool cfg_WriteCurve
GooseFieldListItem::previouscrop
std::string previouscrop
Definition: landscape.h:97
tov_MaizeStrigling
Definition: tov_declaration.h:58
Landscape::VegDump
void VegDump(int x, int y)
Definition: Landscape.cpp:1644
cfg_silage_prop
CfgFloat cfg_silage_prop("CROPS_SILAGE_PROPORTION", CFG_CUSTOM, 1.0)
g_letype
class LE_TypeClass * g_letype
Definition: elements.cpp:277
Landscape::GISASCII_Output
void GISASCII_Output(string outpfile, int UTMX, int UTMY)
Write ASCII file of the ALMaSS map.
Definition: Landscape.cpp:3507
Pond
Ponds are defined as freshwater bodies between 25m2 and 5000m2. For newts the effective size is limit...
Definition: elements.h:1183
Parkland
Definition: elements.h:1082
LE::GetPoly
int GetPoly(void)
Returns the polyref number for this polygon.
Definition: elements.h:189
g_nectarpollen
PollenNectarDevelopmentData * g_nectarpollen
Definition: Landscape.cpp:241
UnsprayedFieldMargin
Definition: elements.h:894
autumn_sow
Definition: treatment.h:41
tov_OWinterWheatUndersown
Definition: tov_declaration.h:49
tole_Copse
Definition: tole_declaration.h:82
tov_Undefined
Definition: tov_declaration.h:114
CfgStr
String configurator entry class.
Definition: configurator.h:144
cfg_HedgeSubtypeMaximum
CfgInt cfg_HedgeSubtypeMaximum("HEDGE_SUBTYPEMAXIMUM", CFG_CUSTOM, 3)
tole_UnknownGrass
Definition: tole_declaration.h:91
glyphosate
Definition: treatment.h:102
Wasteland
Definition: elements.h:881
cfg_rodenticide_reporting_enable
CfgBool cfg_rodenticide_reporting_enable("RODENTICIDE_REPORTING_ENABLE", CFG_CUSTOM, false)
ChameleonLE
Definition: elements.h:1034
LE::SetSoilType
void SetSoilType(int a_st)
Definition: elements.h:287
cfg_pesticidemapdayinyear
CfgInt cfg_pesticidemapdayinyear("PEST_MAP_DAYINYEAR", CFG_CUSTOM, 364)
The interval between maps.
harvest
Definition: treatment.h:82
LE::SetBorder
void SetBorder(LE *a_border)
Definition: elements.h:320
tov_FieldPeasStrigling
Definition: tov_declaration.h:56
Landscape::DumpCentroids
void DumpCentroids(void)
Definition: Landscape.cpp:3275
tole_BareRock
Definition: tole_declaration.h:75
tov_WinterBarleyStrigling
Definition: tov_declaration.h:59
tole_Saltmarsh
Definition: tole_declaration.h:88
tov_NLBeetSpring
Definition: tov_declaration.h:100
cfg_P1F
CfgFloat cfg_P1F
cfg_BeetleBankMaxArea
static CfgFloat cfg_BeetleBankMaxArea("BBANK_MAXAREA", CFG_CUSTOM, 0.05)
Coast
Definition: elements.h:1245
l_map_dump_event_y2
static CfgInt l_map_dump_event_y2("MAP_DUMP_EVENT_YB", CFG_CUSTOM, 2889)
PermPastureTussocky
Definition: elements.h:754
tov_PLFodderLucerne1
Definition: tov_declaration.h:81
Freshwater
Definition: elements.h:1160
g_VegHeightForageReduction
double g_VegHeightForageReduction
tov_WinterWheat
Definition: tov_declaration.h:55
fp_slurry
Definition: treatment.h:52
Pesticide
Definition: pesticide.h:106
IndividualTree
Definition: elements.h:954
LE::GetValidX
int GetValidX(void)
Definition: elements.h:330
cfg_greg_app_prop
CfgFloat cfg_greg_app_prop("CROPS_GROWTHREGULATOR_APPLIC_PROPORTION", CFG_CUSTOM, 1.0)
PEST_GRIDSIZE_POW2
#define PEST_GRIDSIZE_POW2
Definition: pesticide.h:39
tov_OCloverGrassSilage1
Definition: tov_declaration.h:43
Calendar
Definition: calendar.h:38
l_map_dump_map_file
CfgStr l_map_dump_map_file("MAP_DUMP_MAP_FILE", CFG_CUSTOM, "dump.lsb")
SandDune
Definition: elements.h:1124
tov_PermanentGrassTussocky
Definition: tov_declaration.h:49
HedgeBank
Definition: elements.h:779
tole_Railway
Definition: tole_declaration.h:39
l_map_dump_event_y1
static CfgInt l_map_dump_event_y1("MAP_DUMP_EVENT_YA", CFG_CUSTOM, 2909)
tov_PLWinterTriticale
Definition: tov_declaration.h:73
GooseFieldListItem::polyref
int polyref
Definition: landscape.h:82
tov_Heath
Definition: tov_declaration.h:66
Landscape::SkylarkEvaluation
void SkylarkEvaluation(SkTerritories *a_skt)
Definition: Landscape.cpp:3025
MownGrass
Definition: elements.h:1015
l_map_map_file
static CfgStr l_map_map_file("MAP_MAP_FILE", CFG_CUSTOM, "map.lsb")
tole_RoadsideVerge
Definition: tole_declaration.h:38
fp_rsm
Definition: treatment.h:58
tole_Pylon
Definition: tole_declaration.h:96
Landscape::BorderNeed
bool BorderNeed(TTypesOfLandscapeElement a_letype)
Definition: Landscape.cpp:4529
fa_sludge
Definition: treatment.h:68
tov_OCloverGrassGrazed2
Definition: tov_declaration.h:43
tov_PLPotatoes
Definition: tov_declaration.h:79
fa_rsm
Definition: treatment.h:69
tov_NLCabbage
Definition: tov_declaration.h:95
Saltmarsh
Definition: elements.h:849
tov_PLBeet
Definition: tov_declaration.h:80
Landscape::SupplyOverspray
bool SupplyOverspray(int a_x, int a_y)
Gets the overspray flag.
Definition: Landscape.cpp:599
WARN_BUG
Definition: maperrormsg.h:34
PlantNursery
Definition: elements.h:1064
cfg_OptimisingFarms
CfgBool cfg_OptimisingFarms
If set to true, the farmer decision making model is active.
tole_WoodlandMargin
Definition: tole_declaration.h:98
fp_greenmanure
Definition: treatment.h:56
cfg_P1D
CfgFloat cfg_P1D
Calendar::GetDayInMonth
int GetDayInMonth(void)
Definition: calendar.h:72
start
Definition: treatment.h:32
tov_PermanentSetaside
Definition: tov_declaration.h:49
tole_WindTurbine
Definition: tole_declaration.h:97
l_map_dump_event_enable
static CfgBool l_map_dump_event_enable("MAP_DUMP_EVENT_ENABLE", CFG_CUSTOM, false)
tole_ActivePit
Definition: tole_declaration.h:63
l_map_cropcurves_file
static CfgStr l_map_cropcurves_file("MAP_CROPCURVES_FILE", CFG_CUSTOM, "curves.pre")
straw_removal
Definition: treatment.h:112
GooseFieldListItem::geesesp
int geesesp[gs_foobar]
Definition: landscape.h:84
insecticide
Definition: landscape.h:63
hay_turning
Definition: treatment.h:88
tov_Lawn
Definition: tov_declaration.h:63
l_map_dump_veg_x
static CfgInt l_map_dump_veg_x("MAP_DUMP_VEG_X", CFG_CUSTOM, 100)
tov_NLSpringBarleySpring
Definition: tov_declaration.h:104
LE::SetUnsprayedMarginPolyRef
void SetUnsprayedMarginPolyRef(int a_unsprayedmargin)
Definition: elements.h:322
bulb_harvest
Definition: treatment.h:110
Landscape::FillVegAreaData
void FillVegAreaData()
Definition: Landscape.cpp:3641
tov_PLWinterRye
Definition: tov_declaration.h:74
cfg_G6B
CfgFloat cfg_G6B
tov_OSpringBarley
Definition: tov_declaration.h:46
straw_covering
Definition: treatment.h:111
cfg_fungi_app_prop2
CfgFloat cfg_fungi_app_prop2("CROPS_FUNGICIDE_APPLIC_TWO_PROPORTION", CFG_CUSTOM, 1.0)
cfg_pesticidemapnoyears
CfgInt cfg_pesticidemapnoyears("PEST_MAP_NOYEARS", CFG_CUSTOM, 1)
The numer of years of pesticide mapping.
tov_Setaside
Definition: tov_declaration.h:50
cfg_pesticidetesttype
CfgInt cfg_pesticidetesttype("PESTICIDETESTYPE", CFG_CUSTOM, -1)
MetalledPath
Definition: elements.h:1280
heavy_cultivator_aggregate
Definition: treatment.h:108
Landscape::PolytypeToString
std::string PolytypeToString(TTypesOfLandscapeElement a_le_type)
Definition: Landscape.cpp:4087
Pesticide::Tick
void Tick(void)
Definition: pesticide.cpp:97
tov_OrchardCrop
Definition: tov_declaration.h:65
Saltwater
Definition: elements.h:1152
water
Definition: treatment.h:80
tov_SpringBarleySeed
Definition: tov_declaration.h:52
Carpark
Definition: elements.h:1286
tov_SpringBarleySKManagement
Definition: tov_declaration.h:65
g_map_le_unsprayedmargins_chance
CfgInt g_map_le_unsprayedmargins_chance("MAP_LE_UMARGIN_CHANCE", CFG_CUSTOM, 25)
RiversideTrees
Definition: elements.h:908
cfg_mintownbuildingnumber
static CfgInt cfg_mintownbuildingnumber("MAP_MINTOWNBUILDINGNUMBER", CFG_CUSTOM, 6)
cfg_DumpFarmAreas
CfgBool cfg_DumpFarmAreas
If set to true, an output file with farm areas is produced.
fp_liquidNH3
Definition: treatment.h:51
l_map_CIPEmaker_enable
static CfgBool l_map_CIPEmaker_enable("MAP_CIPEMAKER_ENABLE", CFG_CUSTOM, false)
tole_MownGrass
Definition: tole_declaration.h:74
tov_WWheatPToxicControl
Definition: tov_declaration.h:55
tov_NLMaize
Definition: tov_declaration.h:91
Landscape::AxisLoopLtd
void AxisLoopLtd(int a_poly, APoint *a_cor, int a_axis, int a_limit)
Definition: Landscape.cpp:2917
molluscicide
Definition: treatment.h:75
tov_OWinterWheat
Definition: tov_declaration.h:66
Landscape::GetGooseNumbers
int GetGooseNumbers(int a_poly)
This returns the number of geese on the polygon the day before.
Definition: Landscape.cpp:3383
l_map_consolidatepolys
static CfgBool l_map_consolidatepolys("MAP_CONSOLIDATEPOLYS", CFG_CUSTOM, false)
Used to consolidate polygons with no special behaviour into a single polygon of that type.
tov_SpringBarleyStriglingCulm
Definition: tov_declaration.h:62
LE::SetOpenness
void SetOpenness(int a_openness)
Records the openness statistic for this polygon.
Definition: elements.h:380
l_map_dump_veg_y
static CfgInt l_map_dump_veg_y("MAP_DUMP_VEG_Y", CFG_CUSTOM, 100)
tov_FieldPeasSilage
Definition: tov_declaration.h:65
burn_straw_stubble
Definition: treatment.h:92
g_rand_uni
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni(g_generator, g_uni_dist)
Landscape::InitOsmiaBeeNesting
void InitOsmiaBeeNesting()
Read in the Osmia nest density files and allocate to each LE object.
Definition: Landscape.cpp:4697
Weather::Tick
void Tick(void)
Definition: weather.cpp:58
tov_OCarrots
Definition: tov_declaration.h:43
tole_YoungForest
Definition: tole_declaration.h:55
cfg_AddBeetleBanks
static CfgBool cfg_AddBeetleBanks("BBANKS_ADD", CFG_CUSTOM, false)
l_map_exit_on_zero_area
static CfgBool l_map_exit_on_zero_area("MAP_EXIT_ON_ZERO_AREA", CFG_CUSTOM, true)
tov_OWinterWheatUndersownExt
Definition: tov_declaration.h:63
tole_Stream
Definition: tole_declaration.h:89
tov_NLGrassGrazedLast
Definition: tov_declaration.h:108
PitDisused
Definition: elements.h:1144
l_map_calc_openness
static CfgBool l_map_calc_openness("MAP_CALC_OPENNESS", CFG_CUSTOM, false)
tole_Foobar
Definition: tole_declaration.h:111
Calendar::Tick
void Tick(void)
Definition: calendar.cpp:141
tov_OBarleyPeaCloverGrass
Definition: tov_declaration.h:41
tole_ConiferousForest
Definition: tole_declaration.h:54
tos_Foobar
Definition: farm.h:290
tov_WinterWheatShort
Definition: tov_declaration.h:56
g_msg
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:41
Pylon
Definition: elements.h:1052
tov_SpringBarleyGrass
Definition: tov_declaration.h:52
Landscape::SetPolyMaxMinExtents
void SetPolyMaxMinExtents(void)
Definition: Landscape.cpp:1622
cfg_G6F
CfgFloat cfg_G6F
tov_NorwegianOats
Definition: tov_declaration.h:68
cfg_B6D
CfgFloat cfg_B6D
GooseFieldListItem::vegtype
TTypesOfVegetation vegtype
Definition: landscape.h:92
tole_LargeRoad
Definition: tole_declaration.h:61
GooseFieldListItem::roostdists
int roostdists[gs_foobar]
Definition: landscape.h:87
WoodlandMargin
Definition: elements.h:967
LE_TypeClass::TranslateEleTypes
TTypesOfLandscapeElement TranslateEleTypes(int EleReference)
Definition: elements.cpp:2995
Landscape::BorderAdd
void BorderAdd(LE *a_field, TTypesOfLandscapeElement a_type)
Definition: Landscape.cpp:2347
Landscape::Tick
void Tick(void)
Definition: Landscape.cpp:1467
fp_pk
Definition: treatment.h:50
l_map_poly_file
static CfgStr l_map_poly_file("MAP_POLY_FILE", CFG_CUSTOM, "polygonrefs.txt")
cfg_BeetleBankInvert
CfgBool cfg_BeetleBankInvert("BBANK_INVERT", CFG_CUSTOM, false)
testpesticide
Definition: landscape.h:63
fa_npk
Definition: treatment.h:61
Landscape
The landscape class containing all environmental and topographical data.
Definition: landscape.h:112
cattle_out
Definition: treatment.h:83
cfg_pesticidemapcellsize
CfgInt cfg_pesticidemapcellsize("PEST_MAP_CELLSIZE", CFG_CUSTOM, 10)
The output cell size for pesticides - a performance penalty if this does not match the pesticide cell...
cfg_B6G
CfgFloat cfg_B6G
LE::AddArea
void AddArea(double a_area_diff)
Definition: elements.h:316
tov_YoungForest
Definition: tov_declaration.h:60
Landscape::UnsprayedMarginAdd
void UnsprayedMarginAdd(LE *a_field)
Definition: Landscape.cpp:2617
tov_OWinterBarleyExt
Definition: tov_declaration.h:65
cfg_l_treatment_size
CfgInt cfg_l_treatment_size("LAND_TREATMENTSIZE", CFG_CUSTOM, -1)
tov_NorwegianSpringBarley
Definition: tov_declaration.h:68
Pesticide::GetAnythingToDecay
bool GetAnythingToDecay(PlantProtectionProducts a_ppp)
Definition: pesticide.h:228
cfg_l_treatment_y
CfgInt cfg_l_treatment_y("LAND_TREATMENTY", CFG_CUSTOM, 0)
tov_SpringBarleySilage
Definition: tov_declaration.h:52
g_uni_dist2
boost::uniform_int g_uni_dist2(0, 9999)
tov_NLGrassGrazed1Spring
Definition: tov_declaration.h:107
MixedForest
Definition: elements.h:974
fp_npk
Definition: treatment.h:49
Landscape::ReadPolys2
void ReadPolys2(const char *a_polyfile)
reads in polygon information. Version 2 including centroid and openness information
Definition: Landscape.cpp:1892
cfg_G6G
CfgFloat cfg_G6G
stubble_harrowing
Definition: treatment.h:90
Landscape::PolysRenumber
void PolysRenumber(void)
Definition: Landscape.cpp:2057
Landscape::SupplyCentroid
APoint SupplyCentroid(int a_polyref)
Definition: Landscape.cpp:766
LE_TypeClass
Definition: elements.h:70
tov_DummyCropPestTesting
Definition: tov_declaration.h:112
tole_Marsh
Definition: tole_declaration.h:41
Landscape::UnsprayedMarginScan
void UnsprayedMarginScan(LE *a_field, int a_width)
Definition: Landscape.cpp:2638
Landscape::SupplyPesticide
double SupplyPesticide(int a_x, int a_y, PlantProtectionProducts a_ppp)
Gets total pesticide for a location.
Definition: Landscape.cpp:586
TTypesOfVegetation
TTypesOfVegetation
Definition: tov_declaration.h:30
cfg_OsmiaNestByLE_Datafile
static CfgStr cfg_OsmiaNestByLE_Datafile("OSMIA_NESTBYLEDATAFILE", CFG_CUSTOM, "OsmiaNestsByHabitat.txt")
tole_OrchardBand
Definition: tole_declaration.h:73
tov_SpringRape
Definition: tov_declaration.h:53
stubble_plough
Definition: treatment.h:35
autumn_plough
Definition: treatment.h:34
tole_Pond
Definition: tole_declaration.h:101
AmenityGrass
Definition: elements.h:1076
BeetleBank
Definition: elements.h:787
tov_PotatoesIndustry
Definition: tov_declaration.h:50
Calendar::Reset
void Reset(void)
Definition: calendar.cpp:40
fp_manure
Definition: treatment.h:55
tov_SpringBarleyPTreatment
Definition: tov_declaration.h:63
cfg_G6A
CfgFloat cfg_G6A
strigling_sow
Definition: treatment.h:95
tov_FodderGrass
Definition: tov_declaration.h:62
tov_PLBeetSpr
Definition: tov_declaration.h:86
tov_PlantNursery
Definition: tov_declaration.h:66
tov_NLCatchPeaCrop
Definition: tov_declaration.h:106
tov_Carrots
Definition: tov_declaration.h:31
cfg_P1A
CfgFloat cfg_P1A
tov_NLCarrotsSpring
Definition: tov_declaration.h:101
CfgBool
Bool configurator entry class.
Definition: configurator.h:127
tole_PermPasture
Definition: tole_declaration.h:47
WaterBufferZone
Definition: elements.h:808
l_map_dump_poly_file
CfgStr l_map_dump_poly_file("MAP_DUMP_POLY_FILE", CFG_CUSTOM, "dump_polyrefs.txt")
Landscape::AddBeetleBanks
void AddBeetleBanks(TTypesOfLandscapeElement a_tole)
Definition: Landscape.cpp:2723
Landscape::BorderScan
void BorderScan(LE *a_field, int a_width)
Definition: Landscape.cpp:2365
tov_NLPotatoesSpring
Definition: tov_declaration.h:103
cfg_l_usecustompoly
CfgBool cfg_l_usecustompoly("LAND_USECUSTOMPOLY", CFG_CUSTOM, false)
FishFarm
Definition: elements.h:1166
m_polymapping
vector< int > * m_polymapping
m_polymapping is a mapping from polygon numbers into the list of landscape elements,...
Definition: Landscape.cpp:257
tov_SpringBarleyCloverGrass
Definition: tov_declaration.h:52
cfg_B6A
CfgFloat cfg_B6A
cfg_B6E
CfgBool cfg_B6E
winter_plough
Definition: treatment.h:42
tov_WinterRape
Definition: tov_declaration.h:53
tov_OGrazingPigs
Definition: tov_declaration.h:44
tov_SugarBeet
Definition: tov_declaration.h:66
Hedges
Definition: elements.h:768
Landscape::SupplyLESignal
LE_Signal SupplyLESignal(int a_polyref)
Definition: Landscape.cpp:3566
l_map_print_version_info
static CfgBool l_map_print_version_info("MAP_PRINT_VERSION_INFO", CFG_CUSTOM, true)
BuiltUpWithParkland
Definition: elements.h:1118
Landscape::BeetleBankAdd
void BeetleBankAdd(int x, int y, int angle, int length, LE *a_field, TTypesOfLandscapeElement a_tole)
Definition: Landscape.cpp:2971
tov_NLBeet
Definition: tov_declaration.h:89
Landscape::GetQuarryNumbers
int GetQuarryNumbers(int a_poly)
This returns the number of geese which are legal quarry on the polygon the day before.
Definition: Landscape.cpp:3390
tov_NorwegianPotatoes
Definition: tov_declaration.h:68
GooseFieldListItem::maize
double maize
Definition: landscape.h:90
tole_PermanentSetaside
Definition: tole_declaration.h:46
tov_OSBarleySilage
Definition: tov_declaration.h:56
cfg_rectangularmaps_on
CfgBool cfg_rectangularmaps_on
Calendar::OldDays
long OldDays(void)
Definition: calendar.h:60
tole_Canal
Definition: tole_declaration.h:106
tov_SpringBarleyPeaCloverGrassStrigling
Definition: tov_declaration.h:60
tov_PermanentGrassGrazed
Definition: tov_declaration.h:49
Landscape::GetGooseFields
GooseFieldList * GetGooseFields(double)
Gets the list of suitable goose foraging fields today.
Definition: Landscape.cpp:685
tole_UrbanPark
Definition: tole_declaration.h:79
Landscape::LineHighTest
int LineHighTest(int a_cx, int a_cy, double a_offsetx, double a_offsety)
Provides a measure of the shortest distance in using a vector from a_cx,a_cy unitl tall obstacles are...
Definition: Landscape.cpp:461
cfg_MaxPondSize
static CfgInt cfg_MaxPondSize("MAP_MAXPONDSIZE", CFG_CUSTOM, 5000)
If freshwater area is below this it is designated a pond.
LE::SetPoly
void SetPoly(int a_poly)
Definition: elements.h:226
tov_CloverGrassGrazed2
Definition: tov_declaration.h:33
Landscape::RodenticidePredatorsEvaluation
void RodenticidePredatorsEvaluation(RodenticidePredators_Population_Manager *a_rppm)
Definition: Landscape.cpp:3032
Canal
Definition: elements.h:1227
tole_Track
Definition: tole_declaration.h:59
Landscape::CountMapSquares
void CountMapSquares(void)
Definition: Landscape.cpp:2040
tov_WWheatPControl
Definition: tov_declaration.h:55
PollenNectarDevelopmentData
A standard class to manage a range of pollen and nectar development curves based on indexed rates.
Definition: plants.h:224
tov_PLWinterRape
Definition: tov_declaration.h:71
cfg_productapplicendyear
CfgInt cfg_productapplicendyear("PEST_PROCTAPPLICENDYEAR", CFG_CUSTOM,-1)
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
RoadsideVerge
Definition: elements.h:795
Stream
Definition: elements.h:1298
tov_PLBeans
Definition: tov_declaration.h:87
tov_SpringBarleyCloverGrassStrigling
Definition: tov_declaration.h:58
Landscape::SupplyRodenticide
double SupplyRodenticide(int a_x, int a_y)
Gets total rodenticide for a location.
Definition: Landscape.cpp:492
fp_sludge
Definition: treatment.h:57
straw_chopping
Definition: treatment.h:87
tov_Potatoes
Definition: tov_declaration.h:50
fungicide_treat
Definition: treatment.h:73
deep_ploughing
Definition: treatment.h:43
tov_WinterRyeStrigling
Definition: tov_declaration.h:59
preseeding_cultivator_sow
Definition: treatment.h:40
tov_PLWinterBarley
Definition: tov_declaration.h:72
cfg_G6C
CfgFloat cfg_G6C
cfg_rodenticide_enable
CfgBool cfg_rodenticide_enable("RODENTICIDE_ENABLE", CFG_CUSTOM, false)
Landscape::DumpTreatCounters
void DumpTreatCounters(const char *a_filename)
Definition: Landscape.cpp:3586
PEST_GRIDSIZE
#define PEST_GRIDSIZE
Definition: pesticide.h:40
tov_WinterWheatStriglingCulm
Definition: tov_declaration.h:62
mow
Definition: treatment.h:93
fa_pk
Definition: treatment.h:62
cfg_ins_app_prop1
CfgFloat cfg_ins_app_prop1("CROPS_INSECTICIDE_APPLIC_ONE_PROPORTION", CFG_CUSTOM, 1.0)
WARN_MSG
Definition: maperrormsg.h:38
tov_NLTulips
Definition: tov_declaration.h:96
tov_WinterRapeStrigling
Definition: tov_declaration.h:59
SmallRoad
Definition: elements.h:1266
l_map_no_pesticide_fields
static CfgInt l_map_no_pesticide_fields("MAP_NO_PESTICIDE_FIELDS", CFG_CUSTOM, 0)
ActivePit
Definition: elements.h:1251
Landscape::FindLongestAxis
int FindLongestAxis(int *x, int *y, int *a_length)
Definition: Landscape.cpp:2851
spring_harrow
Definition: treatment.h:45
Landscape::CheckForPesticideRecord
void CheckForPesticideRecord(LE *a_field, TTypesOfPesticideCategory a_pcide)
Check if needed and record pesticide application.
Definition: Landscape.cpp:669
TTypesOfPesticideCategory
TTypesOfPesticideCategory
Definition: landscape.h:63
RoadsideSlope
Definition: elements.h:818
tole_NaturalGrassWet
Definition: tole_declaration.h:87
PermPasture
Definition: elements.h:740
Landscape::RecordGooseNumbers
void RecordGooseNumbers(int a_poly, int a_number)
This records the number of geese on the polygon the day before. To prevent lots of unnecessary cleari...
Definition: Landscape.cpp:3328
Field
Definition: elements.h:727
tov_OMaizeSilage
Definition: tov_declaration.h:65
tole_Orchard
Definition: tole_declaration.h:71
l_map_write_ascii
static CfgBool l_map_write_ascii("MAP_WRITE_ASCII", CFG_CUSTOM, false)
Used if an ASCII file for use in GIS applications should be written.
tole_MetalledPath
Definition: tole_declaration.h:84
g_uni_dist
boost::uniform_real g_uni_dist(0, 1)
tov_Maize
Definition: tov_declaration.h:36
LE_Signal
unsigned int LE_Signal
Definition: elements.h:35
l_pest_enable_pesticide_engine
CfgBool l_pest_enable_pesticide_engine
Used to turn on or off the PPP functionality of ALMaSS.
g_SpeedyDivides
double g_SpeedyDivides[2001]
A generally useful array of fast divide calculators by multiplication.
Definition: Landscape.cpp:250
Landscape::ChangeMapMapping
void ChangeMapMapping(void)
Definition: Landscape.cpp:2130
l_map_dump_margin_file
static CfgStr l_map_dump_margin_file("MAP_DUMP_MARGIN_FILE", CFG_CUSTOM, "dumpunsprayedmargins.txt")
tov_OWinterRape
Definition: tov_declaration.h:47
tov_WWheatPTreatment
Definition: tov_declaration.h:55
l_map_ascii_utm_x
static CfgInt l_map_ascii_utm_x("MAP_ASCII_UTM_X", CFG_CUSTOM, 0)
If we write an ASCII file provide UTM-x of lower lefthand corner.
tole_SandDune
Definition: tole_declaration.h:81
Churchyard
Definition: elements.h:1292
CfgFloat::value
double value(void)
Definition: configurator.h:118
g_crops
class PlantGrowthData * g_crops
Definition: plants.cpp:41
tole_WoodyEnergyCrop
Definition: tole_declaration.h:94
UrbanPark
Definition: elements.h:1100
cfg_P1B
CfgFloat cfg_P1B
LE::SetValidXY
void SetValidXY(int a_valid_x, int a_valid_y)
Definition: elements.h:325
tov_FieldPeas
Definition: tov_declaration.h:34
tov_SpringBarleyStriglingSingle
Definition: tov_declaration.h:60
tov_BroadBeans
Definition: tov_declaration.h:66
cfg_mintownbuildingdistance
static CfgInt cfg_mintownbuildingdistance("MAP_MINTOWNBUILDINGDISTANCE", CFG_CUSTOM, 100)
PermanentSetaside
Definition: elements.h:761
Landscape::FindFieldCenter
bool FindFieldCenter(LE *a_field, int *x, int *y)
Definition: Landscape.cpp:2799
LE::SetMapValid
void SetMapValid(bool a_valid)
Definition: elements.h:227
PlantGrowthData
Definition: plants.h:81
tov_Wasteland
Definition: tov_declaration.h:66
hilling_up
Definition: treatment.h:79
LargeRoad
Definition: elements.h:1257
tov_NLGrassGrazed1
Definition: tov_declaration.h:97
Landscape::EventtypeToString
std::string EventtypeToString(int a_event)
Definition: Landscape.cpp:3918
GooseFieldListItem
A list item entry of field polygon reference numbers with associated openness and goose food scores.
Definition: landscape.h:80
tole_River
Definition: tole_declaration.h:65
tov_OSeedGrass1
Definition: tov_declaration.h:46
biocide
Definition: treatment.h:104
Landscape::ForceArea
void ForceArea(void)
Definition: Landscape.cpp:2072
tov_OFodderBeet
Definition: tov_declaration.h:65
cfg_P1E
CfgBool cfg_P1E
tov_NLWinterWheat
Definition: tov_declaration.h:94
tole_Scrub
Definition: tole_declaration.h:42
LE::SetPollenNectarData
void SetPollenNectarData(int a_almasstype)
sets the pollen and nectar information
Definition: elements.cpp:605
BareRock
Definition: elements.h:1130
fa_calcium
Definition: treatment.h:70
WindTurbine
Definition: elements.h:1058
tov_PLMaize
Definition: tov_declaration.h:77
CFG_CUSTOM
Definition: configurator.h:60
tov_OCloverGrassGrazed1
Definition: tov_declaration.h:43
Landscape::CreatePondList
void CreatePondList()
Creates a list of pond polygon refs/indexes for easy look up.
Definition: Landscape.cpp:2594
syninsecticide_treat
Definition: treatment.h:99
fa_manure
Definition: treatment.h:66
cfg_BeetleBankWidth
static CfgInt cfg_BeetleBankWidth("BBANK_WIDTH", CFG_CUSTOM, 4)
tole_PermPastureTussocky
Definition: tole_declaration.h:45
tov_OSpringBarleyPigs
Definition: tov_declaration.h:47
cfg_pesticidemaptype
CfgBool cfg_pesticidemaptype("PEST_MAP_TYPE", CFG_CUSTOM, false)
True for specific pesticide, false for general pesticides.
fp_npks
Definition: treatment.h:48
row_cultivation
Definition: treatment.h:76
RiversidePlants
Definition: elements.h:861
tov_SpringBarleySpr
Definition: tov_declaration.h:66
River
Definition: elements.h:1221
Landscape::BorderRemoval
void BorderRemoval(void)
Definition: Landscape.cpp:2271
l_map_ascii_utm_y
static CfgInt l_map_ascii_utm_y("MAP_ASCII_UTM_Y", CFG_CUSTOM, 0)
If we write an ASCII file provide UTM-y of lower lefthand corner.
g_map_le_borderstype
CfgInt g_map_le_borderstype("MAP_LE_BORDERSTYPE", CFG_CUSTOM, 160)
Landscape::SupplyPesticideP
double SupplyPesticideP(int a_x, int a_y, PlantProtectionProducts a_ppp)
Gets plant pesticide for a location.
Definition: Landscape.cpp:605
trial_insecticidetreat
Definition: treatment.h:96
Landscape::BeetleBankPossible
bool BeetleBankPossible(LE *a_field, TTypesOfLandscapeElement a_tole)
Definition: Landscape.cpp:2772
LE
Definition: elements.h:81
tov_PLSpringBarley
Definition: tov_declaration.h:76
Landscape::CalculateOpenness
void CalculateOpenness(bool a_realcalc)
Causes openness to be calulated and stored for all polygons.
Definition: Landscape.cpp:322
l_map_removesmallpolygons
static CfgBool l_map_removesmallpolygons("MAP_REMOVESMALLPOLYGONS", CFG_CUSTOM, false)
Landscape::Landscape
Landscape(void)
Definition: Landscape.cpp:814
Vildtager
Definition: elements.h:914
tov_PermanentGrassLowYield
Definition: tov_declaration.h:63
Track
Definition: elements.h:1274
Landscape::DumpVegAreaData
void DumpVegAreaData(int a_day)
Definition: Landscape.cpp:4680
tov_WinterWheatStrigling
Definition: tov_declaration.h:59
tole_Field
Definition: tole_declaration.h:43
base_generator_type
boost::lagged_fibonacci19937 base_generator_type
Definition: BoostRandomGenerators.h:30
tov_WinterWheatStriglingSingle
Definition: tov_declaration.h:62
tole_FieldBoundary
Definition: tole_declaration.h:40
g_map_le_border_chance
CfgInt g_map_le_border_chance("MAP_LE_BORDER_CHANCE", CFG_CUSTOM, 25)
Landscape::SupplyFarmIntensityI
int SupplyFarmIntensityI(int a_polyindex)
Definition: Landscape.cpp:751
tole_PermPastureLowYield
Definition: tole_declaration.h:44
last_treatment
Definition: treatment.h:113
Landscape::SupplyRandomPondIndex
int SupplyRandomPondIndex()
Returns random pond index.
Definition: Landscape.cpp:2606
GooseFieldListItem::geese
int geese
Definition: landscape.h:83
Garden
Definition: elements.h:1040
tole_WaterBufferZone
Definition: tole_declaration.h:108
cfg_BeetleBankMinX
CfgInt cfg_BeetleBankMinX("BBANK_MINX", CFG_CUSTOM, 0)
GooseFieldListItem::vegtypechr
std::string vegtypechr
Definition: landscape.h:93
Landscape::SupplyIsCereal2
bool SupplyIsCereal2(TTypesOfVegetation a_vege_type)
Definition: Landscape.cpp:532
WARN_FILE
Definition: maperrormsg.h:37
GooseFieldListItem::geesespTimed
int geesespTimed[gs_foobar]
Definition: landscape.h:86
Landscape::CalulateFieldOpennessAllCells
int CalulateFieldOpennessAllCells(int a_pref)
Provides a measure of the shortest distance in 360 degree, e-g- looking NE % SW before tall obstacles...
Definition: Landscape.cpp:401
fp_ammoniumsulphate
Definition: treatment.h:54
Landscape::SupplyPesticideS
double SupplyPesticideS(int a_x, int a_y, PlantProtectionProducts a_ppp)
Gets soil pesticide for a location.
Definition: Landscape.cpp:616
CfgInt
Integer configurator entry class.
Definition: configurator.h:87
stubble_cultivator_heavy
Definition: treatment.h:36
tole_RiversideTrees
Definition: tole_declaration.h:51
l_map_dump_enable
static CfgBool l_map_dump_enable("MAP_DUMP_ENABLE", CFG_CUSTOM, false)
OrchardBand
Definition: elements.h:1004
tov_PLCarrots
Definition: tov_declaration.h:83
UrbanNoVeg
Definition: elements.h:1088
tov_WinterBarley
Definition: tov_declaration.h:53
spring_plough
Definition: treatment.h:44
fa_greenmanure
Definition: treatment.h:67
VegElement::SetVegPatchy
virtual void SetVegPatchy(bool p)
Definition: elements.h:585
version_revision
static const int version_revision
Definition: Landscape.cpp:51
tov_NaturalGrass
Definition: tov_declaration.h:37
cfg_dumpvegjanfile
CfgStr cfg_dumpvegjanfile("G_VEGAREASJAN_FILENAME", CFG_CUSTOM, "DUMPVEG_JAN.TXT")
l_map_ascii_map_entity
static CfgInt l_map_ascii_map_entity("MAP_ASCII_MAP_ENTITY", CFG_CUSTOM, 1)
If we write an ASCII file what should be the mapped entity? 1 = polyref, 2 = elementype.
TTypesOfLandscapeElement
TTypesOfLandscapeElement
Definition: tole_declaration.h:36
LE::DoCopy
void DoCopy(const LE *a_Le)
a copy function to be used because a copy constuctor won't work
Definition: elements.cpp:372
tole_IndividualTree
Definition: tole_declaration.h:93
Marsh
Definition: elements.h:843
g_map_le_unsprayedmargins
CfgBool g_map_le_unsprayedmargins("MAP_LE_UNSPRAYEDMARGINS", CFG_CUSTOM, false)
Landscape::RecordGooseSpNumbersTimed
void RecordGooseSpNumbersTimed(int a_poly, int a_number, GooseSpecies a_goose)
This records the number of geese of each species on the polygon the day before at a predefined time....
Definition: Landscape.cpp:3363
l_map_dump_gfx_file
static CfgStr l_map_dump_gfx_file("MAP_DUMP_GFX_FILE", CFG_CUSTOM, "dump.ppm")
Landscape::SupplyFarmAnimalCensus
int SupplyFarmAnimalCensus(int a_farm_ref, int a_LifeStage)
Definition: Landscape.cpp:745
tov_SeedGrass2
Definition: tov_declaration.h:50
Landscape::BorderTest
bool BorderTest(int a_fieldpoly, int a_borderpoly, int a_x, int a_y)
Definition: Landscape.cpp:2452
tov_WaterBufferZone
Definition: tov_declaration.h:110
fp_calcium
Definition: treatment.h:59
CfgFloat
Double configurator entry class.
Definition: configurator.h:106
Scrub
Definition: elements.h:833
tole_PitDisused
Definition: tole_declaration.h:50
tov_MaizeSilage
Definition: tov_declaration.h:62
trial_toxiccontrol
Definition: treatment.h:97
spring_roll
Definition: treatment.h:46
tov_NoGrowth
Definition: tov_declaration.h:38
tole_Wasteland
Definition: tole_declaration.h:92
DeciduousForest
Definition: elements.h:940
fa_manganesesulphate
Definition: treatment.h:64
tov_OPotatoes
Definition: tov_declaration.h:44
Landscape::RecordGooseRoostDist
void RecordGooseRoostDist(int a_polyref, int a_dist, GooseSpecies a_goose)
Records the distance to the closest roost of goose species.
Definition: Landscape.cpp:3373
tole_HeritageSite
Definition: tole_declaration.h:90
Heath
Definition: elements.h:855
GooseFieldListItem::digestability
double digestability
Definition: landscape.h:95
bed_forming
Definition: treatment.h:106
Landscape::DegreesDump
void DegreesDump()
Prints the sum of day degrees. See FarmManager::daydegrees.
Definition: Landscape.cpp:1687
cut_weeds
Definition: treatment.h:94
Landscape::NewElement
LE * NewElement(TTypesOfLandscapeElement a_type)
Definition: Landscape.cpp:3688
CfgInt::value
int value(void)
Definition: configurator.h:98
tole_PlantNursery
Definition: tole_declaration.h:95
Landscape::PolysRemoveInvalid
bool PolysRemoveInvalid(void)
Definition: Landscape.cpp:1772
GooseFieldListItem::openness
double openness
Definition: landscape.h:88
Landscape::SupplyIsGrass2
bool SupplyIsGrass2(TTypesOfVegetation a_vege_type)
Definition: Landscape.cpp:503
StoneWall
Definition: elements.h:1136
cfg_productapplicstartyear
CfgInt cfg_productapplicstartyear("PEST_PROCTAPPLICSTARTYEAR", CFG_CUSTOM, 9999999)
Landscape::SupplyLEReset
void SupplyLEReset(void)
Definition: Landscape.cpp:3551
Landscape::AxisLoop
void AxisLoop(int a_poly, int *a_x, int *a_y, int a_axis)
Definition: Landscape.cpp:2938
fp_manganesesulphate
Definition: treatment.h:53
tole_DrainageDitch
Definition: tole_declaration.h:105
WoodyEnergyCrop
Definition: elements.h:986
tov_OSeedGrass2
Definition: tov_declaration.h:46
cfg_P1C
CfgFloat cfg_P1C
PesticideMap
Definition: pesticide.h:369
Landscape::DumpMapGraphics
void DumpMapGraphics(const char *a_filename)
Definition: Landscape.cpp:3599
herbicide_treat
Definition: treatment.h:71
Landscape::CentroidSpiralOut
void CentroidSpiralOut(int a_polyref, int &a_x, int &a_y)
Definition: Landscape.cpp:3073
LE::GetUnsprayedMarginPolyRef
int GetUnsprayedMarginPolyRef(void)
Definition: elements.h:319
janfirst
Definition: plants.h:52
NaturalGrassDry
Definition: elements.h:867
FieldBoundary
Definition: elements.h:888
YoungForest
Definition: elements.h:980
g_map_orchards_borders
CfgBool g_map_orchards_borders("MAP_ORCHARDS_BORDERS", CFG_CUSTOM, false)
tov_NLGrassGrazed2
Definition: tov_declaration.h:98
LE::SetArea
void SetArea(double a_area)
Definition: elements.h:229
tov_OFieldPeasSilage
Definition: tov_declaration.h:56
RasterMap
Definition: rastermap.h:40
growth_regulator
Definition: treatment.h:72
Calendar::DayInYear
int DayInYear(void)
Definition: calendar.h:58
cut_to_silage
Definition: treatment.h:86
product_treat
Definition: treatment.h:101
tov_SpringWheat
Definition: tov_declaration.h:53
cfg_G6E
CfgBool cfg_G6E
tov_SpringBarley
Definition: tov_declaration.h:52
Landscape::BuildingDesignationCalc
void BuildingDesignationCalc()
used to calculate whether a building is rural or town - for rodenticide use
Definition: Landscape.cpp:3287
FarmToDo
FarmToDo
Definition: treatment.h:31
tov_OWinterRye
Definition: tov_declaration.h:49
tole_Carpark
Definition: tole_declaration.h:85
Landscape::RecordGooseSpNumbers
void RecordGooseSpNumbers(int a_poly, int a_number, GooseSpecies a_goose)
This records the number of geese of each species on the polygon the day before. To prevent lots of un...
Definition: Landscape.cpp:3352
tov_NLCarrots
Definition: tov_declaration.h:90
g_date
class Calendar * g_date
Definition: calendar.cpp:38
g_FarmIntensivenessH
double g_FarmIntensivenessH
PermPastureLowYield
Definition: elements.h:747
Calendar::MarchFirst
bool MarchFirst(void)
Definition: calendar.h:75
tov_OFirstYearDanger
Definition: tov_declaration.h:44
tole_DeciduousForest
Definition: tole_declaration.h:52
GooseFieldList
std::vector< GooseFieldListItem > GooseFieldList
A list of GooseFieldListItem s.
Definition: landscape.h:103
tov_CloverGrassGrazed1
Definition: tov_declaration.h:32
tole_Hedges
Definition: tole_declaration.h:37
LE::GetBorder
LE * GetBorder(void)
Definition: elements.h:317
version_date
static const char * version_date
Definition: Landscape.cpp:52
pigs_out
Definition: treatment.h:84
tov_OFieldPeas
Definition: tov_declaration.h:43
tov_FodderBeet
Definition: tov_declaration.h:35
Landscape::EventDumpPesticides
void EventDumpPesticides(int x1, int y1)
Definition: Landscape.cpp:1720
cfg_dumpvegjune
CfgBool cfg_dumpvegjune("G_VEGAREASJUNE_ON", CFG_CUSTOM, false)
trial_control
Definition: treatment.h:98
tov_WinterRye
Definition: tov_declaration.h:55
tov_PLFodderLucerne2
Definition: tov_declaration.h:82
l_map_print_git_version_info
CfgBool l_map_print_git_version_info("MAP_PRINT_GIT_VERSION_INFO", CFG_CUSTOM, false)
Should git version info be printed to file and console?
tov_Triticale
Definition: tov_declaration.h:53
l_map_dump_exit
static CfgBool l_map_dump_exit("MAP_DUMP_EXIT", CFG_CUSTOM, false)
Landscape::PolysValidate
void PolysValidate(bool a_exit_on_invalid)
Definition: Landscape.cpp:1746
l_map_dump_treatcounts_enable
static CfgBool l_map_dump_treatcounts_enable("MAP_DUMP_TREATCOUNTS_ENABLE", CFG_CUSTOM, false)
tov_PLWinterWheat
Definition: tov_declaration.h:70
Landscape::SupplyLENext
int SupplyLENext(void)
Definition: Landscape.cpp:3555
tole_Vildtager
Definition: tole_declaration.h:99
version_minor
static const int version_minor
Definition: Landscape.cpp:50
cut_to_hay
Definition: treatment.h:85
GooseFieldListItem::grain
double grain
Definition: landscape.h:89
toof_Foobar
Definition: farm.h:283
RasterMap::MapWidth
int MapWidth(void)
Definition: rastermap.h:52
Landscape::FindValidXY
bool FindValidXY(int a_field, int &a_x, int &a_y)
Definition: Landscape.cpp:2688
spring_sow
Definition: treatment.h:47
Calendar::JanFirst
bool JanFirst(void)
Definition: calendar.h:74
l_map_chameleon_replace_num
static CfgInt l_map_chameleon_replace_num("MAP_CHAMELEON_REPLACE_NUM", CFG_CUSTOM, 58)
sleep_all_day
Definition: treatment.h:33
tole_Chameleon
Definition: tole_declaration.h:110
Weather
Definition: weather.h:385
cfg_fungi_app_prop1
CfgFloat cfg_fungi_app_prop1("CROPS_FUNGICIDE_APPLIC_ONE_PROPORTION", CFG_CUSTOM, 1.0)
FarmManager
The Farm Manager class.
Definition: farm.h:1706
cfg_ins_app_prop3
CfgFloat cfg_ins_app_prop3("CROPS_INSECTICIDE_APPLIC_THREE_PROPORTION", CFG_CUSTOM, 1.0)
CfgBool::value
bool value(void)
Definition: configurator.h:135
cfg_G6D
CfgFloat cfg_G6D
tov_NLPermanentGrassGrazed
Definition: tov_declaration.h:99
Fence
Definition: elements.h:1171
tole_AmenityGrass
Definition: tole_declaration.h:76
GooseFieldListItem::vegphase
int vegphase
Definition: landscape.h:96
cfg_B6C
CfgFloat cfg_B6C
Landscape::StepOneValid
bool StepOneValid(int a_polyindex, int a_x, int a_y, int step)
Definition: Landscape.cpp:2429
TTypesOfPesticide
TTypesOfPesticide
Definition: landscape.h:65
cfg_BeetleBankMaxX
CfgInt cfg_BeetleBankMaxX("BBANK_MAXX", CFG_CUSTOM, 100000)
tole_NaturalGrassDry
Definition: tole_declaration.h:48
autumn_or_spring_plough
Definition: treatment.h:91
cfg_HedgeSubtypeMinimum
CfgInt cfg_HedgeSubtypeMinimum("HEDGE_SUBTYPEMINIMUM", CFG_CUSTOM, 0)
tole_BeetleBank
Definition: tole_declaration.h:69
tov_SeedGrass1
Definition: tov_declaration.h:50
cfg_dumpvegjunefile
CfgStr cfg_dumpvegjunefile("G_VEGAREASJUNE_FILENAME", CFG_CUSTOM, "DUMPVEG_JUNE.TXT")
cfg_CalculateCentroids
static CfgBool cfg_CalculateCentroids("MAP_CALCULATE_CENTROIDS", CFG_CUSTOM, false)
Landscape::EventDump
void EventDump(int x, int y, int x2, int y2)
Definition: Landscape.cpp:1697
Landscape::SupplyFarmIntensity
int SupplyFarmIntensity(int a_x, int a_y)
Definition: Landscape.cpp:756
LE::GetValidY
int GetValidY(void)
Definition: elements.h:331
strigling_hill
Definition: treatment.h:105
Landscape::SupplyCentroidIndex
APoint SupplyCentroidIndex(int a_polyrefindex)
Definition: Landscape.cpp:771
tov_OSpringBarleyGrass
Definition: tov_declaration.h:46
g_weather
class Weather * g_weather
Definition: weather.cpp:41
LE::SetMapIndex
void SetMapIndex(int a_map_index)
Definition: elements.h:191
cfg_OptimiseBedriftsmodelCrops
CfgBool cfg_OptimiseBedriftsmodelCrops
If set to true, the original farm optimisation model's crop set is used in the farmer decision making...
tole_Coast
Definition: tole_declaration.h:67
cfg_P1G
CfgFloat cfg_P1G
tole_BuiltUpWithParkland
Definition: tole_declaration.h:80
cfg_BeetleBankMaxY
CfgInt cfg_BeetleBankMaxY("BBANK_MAXY", CFG_CUSTOM, 100000)
fa_slurry
Definition: treatment.h:63
swathing
Definition: treatment.h:81
tole_SmallRoad
Definition: tole_declaration.h:60
Landscape::SupplyLargeOpenFieldsNearXY
polylist * SupplyLargeOpenFieldsNearXY(int x, int y, int range, int a_openness)
Returns a pointer to a list of polygonrefs to large open fields within a range of location x,...
Definition: Landscape.cpp:782
Landscape::SimulationClosingActions
void SimulationClosingActions()
Definition: Landscape.cpp:1455
UrbanVeg
Definition: elements.h:1094
Building
Definition: elements.h:1046
l_map_dump_gfx_enable
static CfgBool l_map_dump_gfx_enable("MAP_DUMP_GFX_ENABLE", CFG_CUSTOM, false)
g_map_le_borderremoval
CfgBool g_map_le_borderremoval("MAP_LE_BORDERREMOVAL", CFG_CUSTOM, false)
Landscape::GetHareFoodQuality
double GetHareFoodQuality(int a_polygon)
Definition: Landscape.cpp:3403
tov_None
Definition: tov_declaration.h:39
Landscape::SetLESignal
void SetLESignal(int a_polyref, LE_Signal a_signal)
Definition: Landscape.cpp:3570
tole_Fence
Definition: tole_declaration.h:57
l_map_weather_file
static CfgStr l_map_weather_file("MAP_WEATHER_FILE", CFG_CUSTOM, "weather.pre")
l_map_art_hedgebanks
static CfgBool l_map_art_hedgebanks("MAP_ART_HEDGEBANKS", CFG_CUSTOM, false)
tov_OSpringBarleyExt
Definition: tov_declaration.h:63
cfg_l_treatment_x
CfgInt cfg_l_treatment_x("LAND_TREATMENTX", CFG_CUSTOM, 0)
marchfirst
Definition: plants.h:54
l_map_umargin_width
static CfgInt l_map_umargin_width("MAP_UMARGINWIDTH", CFG_CUSTOM, 12)
Landscape::ConsolidatePolys
void ConsolidatePolys(void)
Definition: Landscape.cpp:1329
Landscape::IncTreatCounter
void IncTreatCounter(int a_treat)
Definition: Landscape.cpp:3575
tole_Heath
Definition: tole_declaration.h:70
tov_NLCabbageSpring
Definition: tov_declaration.h:105