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