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" 307 for (
unsigned int i = 0; i < m_elems.size(); i++)
324 m_elems[i]->SetOpenness(CalulateFieldOpennessAllCells(i));
326 else m_elems[i]->SetOpenness(0);
329 m_elems[i]->SetOpenness(0);
333 if (a_realcalc) cout << endl;
340 int d0 = m_maxextent;
341 int cx = m_elems[a_pref]->GetCentroidX();
342 int cy = m_elems[a_pref]->GetCentroidY();
347 double dx = 1.0 / 45.0;
349 for (
int deg = 0; deg<90; deg++)
352 int d1 = LineHighTest(cx, cy, offsetx, offsety);
353 int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
357 offsetx = offsetx + dx;
358 offsety = offsety + dy;
364 for (
int deg = 0; deg<90; deg++)
367 int d1 = LineHighTest(cx, cy, offsetx, offsety);
368 int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
372 offsetx = offsetx + dx;
373 offsety = offsety + dy;
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)
389 for (
int ay = minY; ay <= maxY; ay+=10)
395 if (m_land->Get(ax, ay) == a_pref)
403 double dx = 1.0 / 45.0;
405 for (
int deg = 0; deg<90; deg++)
408 int d1 = LineHighTest(cx, cy, offsetx, offsety);
409 int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
412 if (dline > d) dline = d;
413 offsetx = offsetx + dx;
414 offsety = offsety + dy;
420 for (
int deg = 0; deg<90; deg++)
423 int d1 = LineHighTest(cx, cy, offsetx, offsety);
424 int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
427 if (dline > d) dline = d;
428 offsetx = offsetx + dx;
429 offsety = offsety + dy;
431 if (dline > d0) d0 = dline;
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;
457 if (SupplyLEHigh(x,y))
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;
474 pp = m_RodenticideManager->GetRodenticide(a_x, a_y);
483 #ifdef __DETAILED_PESTICIDE_FATE 485 pp =
g_pest->SupplyPesticideS(a_x, a_y);
486 pp +=
g_pest->SupplyPesticideP(a_x, a_y);
496 return m_elems[m_land->Get(a_x, a_y)]->GetSprayedToday();
502 #ifdef __DETAILED_PESTICIDE_FATE 503 pp =
g_pest->SupplyPesticideP(a_x, a_y);
513 #ifdef __DETAILED_PESTICIDE_FATE 514 pp =
g_pest->SupplyPesticideS(a_x, a_y);
523 if (!l_pest_enable_pesticide_engine.
value())
return 0.0;
525 #ifdef __DETAILED_PESTICIDE_FATE 526 pp =
g_pest->SupplyPesticideS(a_polyref);
527 pp +=
g_pest->SupplyPesticideP(a_polyref);
536 if (!l_pest_enable_pesticide_engine.
value())
return 0.0;
538 #ifdef __DETAILED_PESTICIDE_FATE 539 pp =
g_pest->SupplyPesticideS(a_polyref);
548 if (!l_pest_enable_pesticide_engine.
value())
return 0.0;
550 #ifdef __DETAILED_PESTICIDE_FATE 551 pp =
g_pest->SupplyPesticideP(a_polyref);
560 return dynamic_cast<Pond*
>(m_elems[a_polyrefindex])->SubtractLarvalFood(a_food);
577 for (
unsigned int i = 0; i < m_elems.size(); i++)
579 if (m_elems[i]->GetOpenness() > a_minopenness)
581 for (
int g = gs_Pinkfoot; g < gs_foobar; g++)
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);
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();
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();
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);
610 return m_ThePopManager->FarmAnimalCensus(a_farm_ref, a_LifeStage);
615 return m_elems[ a_polyindex ]->GetOwner()->GetIntensity();
620 return m_elems[ m_land->Get( a_x, a_y ) ]->GetOwner()->GetIntensity();
625 return m_elems[ m_polymapping[ a_polyref ]]->GetOwner()->GetIntensity();
630 return m_elems[ m_polymapping[ a_polyref ] ]->GetCentroid();
635 return m_elems[ a_polyrefindex ]->GetCentroid();
656 unsigned sz = (unsigned) m_elems.size();
657 for (
unsigned i=0; i<sz; i++)
659 if ( m_elems[i]->GetOpenness() > a_openness)
661 APoint pt = m_elems[i]->GetCentroid();
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;
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());
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;
691 g_landscape_p =
this;
692 for (
int i = 1; i <= 2000; i++) {
693 g_SpeedyDivides[i] = 1 / double(i);
695 int x_add[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
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];
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());
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());
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 );
713 sprintf(m_versioninfo,
"%d.%d.%d :: %s", version_major, version_minor, version_revision, version_date);
716 printf(
"This program uses the Landscape simulator V%s\n", m_versioninfo);
739 m_LargestPolyNumUsed = -1;
743 m_treatment_counts[i] = 0;
752 if (cfg_OptimisingFarms.
value()){
753 m_FarmManager->InitFarms();
754 m_FarmManager->Save_diff_farm_types_areas();
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;
765 PolysValidate(
false);
768 m_toxShouldSpray =
false;
772 PolysValidate(
false);
773 PolysRemoveInvalid();
777 for (
unsigned int i = 0; i < m_elems.size(); i++) {
784 m_elems[i] =
dynamic_cast<LE*
>(pond);
797 if (m_DoMissingPolygonsManipulations)
800 for (
unsigned int i = 0; i < m_elems.size(); i++)
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))
815 wl->
SetPoly(m_elems[i]->GetPoly());
816 wl->
SetArea(floor(0.5 + area));
827 RemoveMissingValues();
828 for (
unsigned int i = 0; i < m_elems.size(); i++)
834 wl->
SetPoly(m_elems[i]->GetPoly());
835 wl->
SetArea(m_elems[i]->GetArea());
844 PolysValidate(
false);
845 PolysRemoveInvalid();
847 g_msg->
Warn(
"Landscape::Landscape(): Dump and normal exit to follow after resolving missing polygons. ",
"");
858 if ((m_LargestPolyNumUsed != ((
int)m_elems.size() - 1)))
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);
874 didConsolidate =
true;
883 g_msg->
Warn(
WARN_FILE,
"Landscape::Landscape() - BorderRemoval "" map dump to follow.",
"");
890 if (didConsolidate || didCalcOther || m_NeedCentroidCalculation)
892 PolysValidate(
false);
893 PolysRemoveInvalid();
897 CalculateCentroids();
898 didCalcCentroids =
true;
903 else CalculateOpenness(
false);
904 didCalcOpenness =
true;
906 if (didCalcCentroids || didConsolidate || didCalcOpenness || didCalcOther || m_NeedCentroidCalculation || didRenumber || !m_FarmManager->GetIsRenumbered())
909 m_FarmManager->DumpFarmrefs();
912 g_msg->
Warn(
WARN_FILE,
"Landscape::Landscape() ""Normal exit after dump.",
"Remember to rename the new map and polyref file.");
919 didCalcOther =
false;
928 cout <<
"Generating LE Borders around fields" << endl;
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++)
938 if (m_elems[i]->GetBorder() != NULL)
945 BorderAdd(m_elems[i], t);
955 for (
unsigned int i = 0; i < m_elems.size(); i++) {
959 BorderAdd(m_elems[i], t);
972 for (
unsigned int i = 0; i < m_elems.size(); i++)
974 if (m_elems[i]->GetUnsprayedMarginPolyRef() != -1)
977 if (m_elems[i]->GetArea() > 10000)
980 UnsprayedMarginAdd(m_elems[i]);
982 else m_elems[i]->SetUnsprayedMarginPolyRef(-1);
989 cout <<
"Adding beetle banks now" << endl;
1003 PolysValidate(
false);
1004 PolysRemoveInvalid();
1005 PolysValidate(
true);
1008 CalculateCentroids();
1010 m_FarmManager->DumpFarmrefs();
1011 cout <<
"Dumping map" << endl;
1013 cout <<
"Dumping polygon refs file" << endl;
1015 g_msg->
Warn(
WARN_FILE,
"Landscape::Landscape() ""Normal exit after dump.",
"Remember to rename the new map and polyref file.");
1031 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1033 m_elems[i]->SetSubType(l_subtype);
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)
1052 cout <<
"Initiating farm management" << endl;
1053 m_FarmManager->InitiateManagement();
1068 int l_count = SupplyLECount();
1071 for (
int i = 0; i < l_count; i++) {
1074 int a_poly = SupplyLENext();
1085 LE_Signal l_signal = SupplyLESignal(a_poly);
1091 SetLESignal(a_poly, l_signal);
1095 l_vegtype_areas = (
double *)malloc(
sizeof(
double) * (
tov_Undefined + 1));
1097 if (l_vegtype_areas == NULL) {
1125 f = fopen(
"VegDump.txt",
"w");
1127 g_msg->
Warn(
WARN_BUG,
"Landscape::Landscape(): VegDump.txt could not be created",
"");
1130 fprintf(f,
"Year\tDay\tHeight\tBiomass\tGrazed\tDensity\tCover\tWeedBiomass\ttovNum\tInsectBiomass\tLATotal\tLAGreen\tDigestability\tGreenBiomass\tDeadBiomass\tGooseGrazing\tSpilledGrain\nn");
1135 f = fopen(
"EventDump.txt",
"w");
1137 g_msg->
Warn(
WARN_BUG,
"Landscape::Landscape(): EventDump.txt could not be created",
"");
1143 if (!cfg_OptimiseBedriftsmodelCrops.
value()){
1144 m_FarmManager->FindNeighbours();
1147 if (cfg_DumpFarmAreas.
value()){
1148 m_FarmManager->DumpFarmAreas();
1157 m_RodenticideManager =
new RodenticideManager(
"BaitLocations_input.txt",
this);
1158 m_RodenticidePreds =
new RodenticidePredators_Population_Manager(
this);
1162 cout <<
"Running intial start-up year" << endl;
1163 for (
unsigned int i = 0; i < 365; i++) Tick();
1165 if (cfg_OptimisingFarms.
value()) { m_FarmManager->Switch_rotation(); }
1170 GISASCII_Output(
"AsciiLandscape.txt", x, y);
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++)
1193 for (
int y = 0; y < mapheight; y++)
1195 int ele = m_land->Get(x, y);
1197 for (
int t = 0; t < TypesToReplace; t++)
1199 if (tole == replaceList[t])
1202 if (foundList[t] == -1) foundList[t] = ele;
1206 m_land->Put(x, y, foundList[t]);
1213 g_msg->
Warn(
WARN_FILE,
"Landscape::ConsolidatePolys() - ""Consolidate map dump.",
"");
1219 int * l_map = m_land->GetMagicP(0, 0);
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));
1260 for (
unsigned int i = 0; i < m_elems.size(); i++ )
1261 delete m_elems[ i ];
1263 free( m_polymapping );
1264 free( l_vegtype_areas );
1274 delete m_RodenticideManager;
1275 delete m_RodenticidePreds;
1277 delete m_FarmManager;
1288 if(cfg_OptimisingFarms.
value()){
1289 this->m_FarmManager->PrintFinalResults();
1307 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1308 m_elems[ i ]->StoreLAItotal();
1314 m_FarmManager->SetSpilledGrain(
true );
1316 else m_FarmManager->SetSpilledGrain(
false );
1317 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1318 m_elems[ i ]->SetGrowthPhase(
janfirst );
1322 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1327 m_toxShouldSpray =
true;
1328 else m_toxShouldSpray =
false;
1333 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1334 m_elems[ i ]->Tick();
1335 m_elems[ i ]->DoDevelopment();
1339 if (cfg_OptimisingFarms.
value()) {
1340 if (!cfg_OptimiseBedriftsmodelCrops.
value()) {
1344 m_FarmManager->ActualProfit();
1347 ofstream ofile2(
"CropDistribution.txt", ios::app );
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';
1354 for (
int i = 0; i < (int)m_FarmManager->Get_cropTotals_size(); i++) {
1355 m_FarmManager->Set_cropTotals( i, 0 );
1359 m_FarmManager->Save_last_years_crops_for_farms();
1360 m_FarmManager->ChooseDecisionMode_for_farms();
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 ) );
1371 m_FarmManager->pm_data->Set_sellingPrice_lastyr( old_price,
tov_Undefined*f + m_FarmManager->pm_data->Get_cropTypes_almass( c ) );
1378 if (cfg_MaizeEnergy.
value()) {
1381 ofstream ofileEM(
"Maize_energy_price_yearly.txt", ios::app );
1383 ofileEM << year <<
'\t';
1384 ofileEM << m_FarmManager->pm_data->Get_sellingPrice(
tov_Maize );
1414 m_FarmManager->FarmManagement();
1422 m_RodenticideManager->Tick();
1423 m_RodenticidePreds->Tick();
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 );
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);
1457 FILE * vfile=fopen(
"VegDump.txt",
"a" );
1459 g_msg->
Warn(
WARN_FILE,
"Landscape::VegDump(): Unable to open file",
"VegDump.txt" );
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);
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 );
1500 ofstream ofile (
"Daydegrees.txt", ios::app);
1502 ofile << m_FarmManager->GetDD();
1509 FILE * vfile=fopen(
"EventDump.txt",
"a" );
1511 g_msg->
Warn(
WARN_FILE,
"Landscape::EventDump(): Unable to open file",
"EventDump.txt" );
1516 int day = SupplyDayInYear();
1517 fprintf( vfile,
"%d: ", day );
1519 fprintf( vfile,
"%d ", event );
1522 fprintf( vfile,
" - " );
1524 fprintf( vfile,
"%d ", event );
1526 fprintf( vfile,
"\n" );
1532 FILE * vfile=fopen(
"EventDump.txt",
"a" );
1534 g_msg->
Warn(
WARN_FILE,
"Landscape::EventDump(): Unable to open file",
"EventDump.txt" );
1539 int day = this->SupplyGlobalDate();
1551 if (herb+fung+ins >0 ) fprintf( vfile,
"%d\t%d\t%d\t%d\n", day, herb, fung, ins );
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 ) {
1563 sprintf( l_err,
"%d", m_elems[ i ]->GetPoly() );
1569 SetPolyMaxMinExtents();
1571 if ( a_exit_on_invalid ) {
1572 for (
unsigned int i = 0; i < m_elems.size(); i++ ) {
1573 if ( !m_elems[ i ]->GetMapValid() ) {
1575 sprintf( l_err,
"%d", m_elems[ i ]->GetPoly() );
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 ];
1599 m_polymapping[ m_elems[ i ]->GetPoly() ] = -1;
1600 delete m_elems[ i ];
1604 for (
unsigned int i = 0; i < l_temp.size(); i++ ) {
1605 m_elems[ i ] = l_temp[ i ];
1607 m_elems.resize( l_temp.size() );
1608 RebuildPolyMapping();
1614 ofstream outf(a_filename, ios::out);
1615 int l_num_polys = 0;
1617 if (!outf.is_open()) {
1623 unsigned sz = (unsigned)m_elems.size();
1624 for (
unsigned int i = 0; i < sz; i++) {
1625 if (m_elems[i]->GetMapValid())
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;
1639 for (
unsigned int i = 0; i < m_elems.size(); i++)
1641 if (m_elems[i]->GetMapValid())
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;
1710 bool farmsrenum = m_FarmManager->GetIsRenumbered();
1713 string rubbish =
"";
1714 ifstream ifile(a_polyfile);
1715 if (!ifile.is_open()) {
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;
1730 m_polymapping = (
int *)malloc(
sizeof(
int)* (np * 2));
1732 if (m_polymapping == NULL)
1739 for (
int i = 0; i < np * 2; i++) {
1740 m_polymapping[i] = -1;
1745 for (
int x = 0; x < NoPolygons; x++)
1747 int PolyNum, Owner, PolyType, RealPolyType, URef, SoilType, openness, Centroid_x, Centroid_y;
1750 ifile >> PolyType >> PolyNum >> Area >> Owner >> URef >> SoilType >> openness >> Centroid_x >> Centroid_y;
1752 if ((SoilType > 16) || (PolyNum<0))
1754 std::sprintf(error_num,
"%d", NoPolygons);
1756 "reading number of specified polygons (old polygon file format?):", error_num);
1762 if ((-1 != Owner) && !farmsrenum)
1765 Owner = m_FarmManager->GetRenumberedFarmRef(Owner);
1768 RealPolyType = PolyType;
1770 if (PolyType == 150)
1778 m_DoMissingPolygonsManipulations =
true;
1780 if (-1 == m_polymapping[PolyNum])
1784 m_polymapping[PolyNum] = ElemIndex;
1785 LE * newland = NewElement(Type);
1786 m_elems[ElemIndex++] = newland;
1788 newland->
SetArea(floor(0.5 + Area));
1795 if (PolyNum>m_LargestPolyNumUsed) m_LargestPolyNumUsed = PolyNum;
1797 if ((Centroid_x < 0) || (Centroid_y < 0)) m_NeedCentroidCalculation=
true;
1798 if (openness < 0) m_NeedOpennessCalculation =
true;
1804 sprintf(error_num,
"%d", PolyNum);
1805 g_msg->
Warn(
WARN_FILE,
"Landscape::ReadPolys(): Farm polygon does not belong to a farm:", error_num);
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);
1817 m_FarmManager->ConnectFarm(Owner);
1818 m_FarmManager->AddField(Owner, newland, Owner);
1843 sprintf(error_num,
"%d", PolyNum);
1844 g_msg->
Warn(
WARN_FILE,
"Landscape::ReadPolys(): Duplicate polygon in file", error_num);
1850 hb_first_free_poly_num = m_elems[NoPolygons - 1]->GetPoly() + 1;
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;
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++;
1873 cout <<
"In Landscape::Landscape() Polygon renumber." << endl;
1874 for (
unsigned int i = 0; i < m_elems.size(); i++)
1877 int index = m_elems[i]->GetMapIndex();
1878 m_elems[i]->SetPoly(index);
1879 m_polymapping[index] = i;
1881 m_LargestPolyNumUsed = (int) m_elems.size()-1;
1882 g_msg->
Warn(
WARN_FILE,
"Landscape::Landscape() ""Map to be dumped due to polygon renumber",
"");
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;
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!",
"" );
1907 int mapwidth = m_land->MapWidth();
1908 int mapheight = m_land->MapHeight();
1912 found =
false; counter++;
1913 for (
int x = 1; x < mapwidth-1; x++)
1915 for (
int y = 1; y < mapheight-1; y++)
1917 int apoly = m_land->Get(x,y);
1918 if (m_elems[m_polymapping[apoly]]->GetElementType() ==
tole_Missing)
1920 m_land->MissingCellReplace(x, y,
true);
1925 }
while (counter<50);
1927 for (
int x = 0; x < mapwidth; x++)
1929 for (
int y = 0; y < mapheight; y++)
1931 int apoly = m_land->Get(x, y);
1932 if (m_elems[m_polymapping[apoly]]->GetElementType() ==
tole_Missing)
1936 m_land->MissingCellReplaceWrap(x, y,
true);
1950 cout <<
"In Change Map Mapping" << endl;
1951 int mapwidth = m_land->MapWidth();
1952 int mapheight = m_land->MapHeight();
1956 for (
int x = 0; x < mapwidth; x++ )
1958 for (
int y = 0; y < mapheight; y++ )
1960 int polynum = m_land->Get( x, y );
1961 m_elems[ m_polymapping[ polynum ]]->SetMapIndex( m_polymapping[ polynum ] );
1962 m_elems[ m_polymapping[ polynum ]]->SetMapValid(
true );
1964 m_land->Put( x, y, m_polymapping[ polynum ] );
1967 int index = m_polymapping[ SupplyPolyRef( x, y ) ];
1968 if ( index != oldindex )
1970 m_elems[ index ]->SetValidXY( x, y );
1973 int pref = l_y * pest_map_width + l_x;
1974 m_elems[ index ]->SetPesticideCell( pref );
1979 RebuildPolyMapping();
2017 for (
unsigned int i = 0; i < m_elems.size(); i++)
2019 if (m_elems[i]->GetArea() == 1)
2043 APoint pt = m_elems[i]->GetCentroid();
2044 m_land->CellReplacementNeighbour(pt.m_x, pt.m_y, m_elems[i]->GetPoly());
2055 for (
int x=1; x<(m_width-1); x++)
2056 for (
int y=1; y<(m_height-1); y++)
2061 if ( SupplyElementType(x-1,y-1) ==
tole_Field)
2064 int fieldindex = SupplyPolyRefIndex(x-1,y-1);
2065 m_land->Put( x, y, fieldindex );
2072 int fieldindex = SupplyPolyRefIndex(x-1,y);
2073 m_land->Put( x, y, fieldindex );
2077 if ( SupplyElementType(x-1,y+1) ==
tole_Field)
2080 int fieldindex = SupplyPolyRefIndex(x-1,y+1);
2081 m_land->Put( x, y, fieldindex );
2088 int fieldindex = SupplyPolyRefIndex(x,y-1);
2089 m_land->Put( x, y, fieldindex );
2096 int fieldindex = SupplyPolyRefIndex(x,y+1);
2097 m_land->Put( x, y, fieldindex );
2101 if ( SupplyElementType(x+1,y-1) ==
tole_Field)
2104 int fieldindex = SupplyPolyRefIndex(x+1,y-1);
2105 m_land->Put( x, y, fieldindex );
2112 int fieldindex = SupplyPolyRefIndex(x+1,y);
2113 m_land->Put( x, y, fieldindex );
2117 if ( SupplyElementType(x+1,y+1) ==
tole_Field)
2120 int fieldindex = SupplyPolyRefIndex(x+1,y+1);
2121 m_land->Put( x, y, fieldindex );
2132 if ( ( x == -1 ) || ( y == -1 ) ) {
2133 g_msg->
Warn(
WARN_BUG,
"Landscape::BorderAdd(): Uninitialized border coordinate!",
"" );
2136 LE * border = NewElement(a_type);
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++ );
2153 int fieldpoly = a_field->
GetPoly();
2154 int borderpoly = border->
GetPoly();
2155 int borderindex = m_polymapping[ borderpoly ];
2156 int fieldindex = m_polymapping[ fieldpoly ];
2158 if (test != fieldindex)
2160 g_msg->
Warn(
"Landscape::BorderScan - Border Scan centroid does not return correct polygon index. Index :", fieldindex);
2164 int notforever = 50000;
2165 vector<APoint> listoflocs;
2170 for (
int wid = 0; wid < a_width; wid++)
2176 AxisLoop(fieldindex, &coord, random(8));
2177 while (--notforever > 0)
2180 if (BorderTest(fieldindex, -99, coord.m_x, coord.m_y))
2183 m_land->Put(coord.m_x, coord.m_y, -99);
2184 listoflocs.push_back(coord);
2189 sprintf(polynum,
"%d", a_field->
GetPoly());
g_msg->
Warn(
WARN_FILE,
"Landscape::BorderScan(): Polygon reached zero area " "when adding border. Poly num: ", polynum);
2196 if (!BorderStep(fieldindex, -99, &coord))
2201 for (std::vector<APoint>::iterator it = listoflocs.begin(); it != listoflocs.end(); ++it)
2203 m_land->Put((*it).m_x, (*it).m_y, borderindex);
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();
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 ) )
2221 index = m_land->Get( a_x + x_add[ i ], a_y + y_add[ i ] );
2222 if ( index == a_polyindex )
2224 m_elems[a_polyindex]->SetValidXY(a_x + x_add[ i ], a_y + y_add[ i ]);
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();
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 ) ) {
2247 index = m_land->Get( a_x + x_add[ i ], a_y + y_add[ i ] );
2248 if ( ( index != a_fieldindex ) && ( index != a_borderindex ) )
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;
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))
2273 index = m_land->Get((*a_x) + x_add[i], (*a_y) + y_add[i]);
2274 if (index == a_fieldindex)
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))
2294 index = m_land->Get((*a_x) + x_add[i], (*a_y) + y_add[i]);
2295 if (index == a_fieldindex)
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))
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;
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))
2331 index = m_land->Get((a_coord->m_x) + x_add[i], (a_coord->m_y) + y_add[i]);
2332 if (index == a_fieldindex)
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))
2352 index = m_land->Get((a_coord->m_x) + x_add[i], (a_coord->m_y) + y_add[i]);
2353 if (index == a_fieldindex)
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))
2367 (a_coord->m_x) += x_add[i];
2368 (a_coord->m_y) += y_add[i];
2378 for (
unsigned int i = 0; i < m_elems.size(); i++)
2380 if (m_elems[i]->GetElementType() ==
tole_Pond) {
2381 m_PondIndexList.push_back(i);
2382 m_PondRefsList.push_back(m_elems[i]->GetPoly());
2388 return m_PondIndexList[int(
g_rand_uni()*m_PondIndexList.size())];
2392 if (m_PondIndexList.size()>0)
return m_PondRefsList[
int(
g_rand_uni()*m_PondIndexList.size())];
2401 if ( ( x == -1 ) || ( y == -1 ) ) {
2403 g_msg->
Warn(
WARN_BUG,
"Landscape::UnsprayedMarginAdd(): Uninitialized border coordinate!",
"" );
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;
2411 umargin->
SetPoly( hb_first_free_poly_num++ );
2415 UnsprayedMarginScan( a_field, q + 1 );
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;
2433 if ( !FindValidXY( fieldindex, x, y ) )
return;
2435 while ( --notforever ) {
2437 if ( UMarginTest( fieldindex, borderindex, x, y, a_width ) ) {
2439 m_land->Put( x, y, borderindex );
2444 if ( !BorderStep( fieldindex, borderindex, & x, & y ) )
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();
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 ) ) {
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;
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 };
2476 int width = m_land->MapWidth();
2477 int height = m_land->MapHeight();
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;
2518 unsigned sz=(unsigned) m_elems.size();
2519 for (
unsigned i=0; i<sz; i++)
2521 if (m_elems[ i ]->GetElementType() ==
tole_Field)
2524 int cx = m_elems[ i ]->GetCentroidX();
2525 int cy = m_elems[ i ]->GetCentroidY();
2528 if ((cx >= tx1) && (cy >= ty1) && (cx <= tx2) && (cy <= ty2))
2533 else if ((cx < tx1) || (cy < ty1) || (cx > tx2) || (cy > ty2))
2541 if (BeetleBankPossible( m_elems[ i ], a_tole) ) BBs++;
2547 sprintf(str,
"%d",BBs);
2548 g_msg->
Warn(
WARN_MSG,
"Landscape::AddBeetleBanks(): BeetleBanks successfully added:", str );
2560 int farea=(int)a_field->
GetArea();
2561 if (farea<10000)
return false;
2566 if (!FindFieldCenter(a_field, &cx, &cy))
return false;
2569 int alignment=FindLongestAxis(&cx, &cy, &length);
2571 length=int(length*0.8);
2575 BeetleBankAdd(cx, cy, alignment, length , a_field, a_tole);
2584 int ourpoly=SupplyPolyRef(*(x),*(y));
2585 if (ourpoly!=a_field->
GetPoly())
return false;
2594 while ((diff>1) & (tries++<100)) {
2595 for (
unsigned v=0; v<4; v++) {
2598 AxisLoop(ourpoly, &x1, &y1, v);
2599 centers[0][v]=x1-m_x_add[v];
2600 centers[1][v]=y1-m_y_add[v];
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];
2613 for (
int h=0; h<8; h++) {
2614 centreX+=centers[0][h];
2615 centreY+=centers[1][h];
2619 diff=abs(oldx-centreX)+abs(oldy-centreY);
2623 int tourpoly=SupplyPolyRef(*(x),*(y));
2624 if (tourpoly!=ourpoly) {
2634 int ourpoly=SupplyPolyRef(*(a_x),*(a_y));
2644 for (
unsigned v=0; v<8; v++)
2648 AxisLoop(ourpoly, &x1, &y1, v);
2651 dx[v] = abs(*(a_x)-x1);
2652 dy[v] = abs(*(a_y)-y1);
2658 for (
int di = 0; di < 4; di++)
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))
2666 *(a_length) = dist[di];
2669 if (found == -1)
return 0;
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;
2684 int ap1 = a_polyindex;
2685 while (ap1 == a_polyindex)
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);
2703 int ap1 = a_polyindex;
2705 while (ap1 == a_polyindex && count<a_limit)
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);
2724 int ap1 = a_polyindex;
2725 while (ap1 == a_polyindex)
2727 *(a_x) += m_x_add[a_axis];
2728 *(a_y) += m_y_add[a_axis];
2738 if (*(a_x) >= m_width)
2742 if (*(a_y) >= m_height)
2747 ap1 = m_land->Get((*a_x), (*a_y));
2754 ++m_LargestPolyNumUsed;
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 );
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 );
2794 BeetleBank->
SetArea(
double(area) );
2795 BeetleBank->
SetValidXY( a_x+start*m_x_add[a_angle], a_y+start*m_y_add[a_angle] );
2807 for (
unsigned i=0; i<m_elems.size(); i++) {
2808 a_skt->PreCachePoly(m_elems[i]->GetPoly());
2815 for (
unsigned i=0; i<m_elems.size(); i++) {
2816 a_rppm->PreCachePoly(m_elems[i]->GetPoly());
2828 cout <<
"In Centroid Calculations" << endl;
2830 for (
int p = 0; p< (int)m_elems.size(); p++)
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;
2841 CentroidSpiralOut(polyindex, midx, midy);
2846 FindLongestAxis(&midx, &midy, &l);
2847 m_elems[p]->SetCentroid(midx, midy);
2849 BuildingDesignationCalc();
2855 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
return;
2862 for (
int i = 0 - loop; i <= loop; i++)
2865 CorrectCoords(a_x, a_y);
2866 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
2870 for (
int i = 0 - loop; i <= loop; i++)
2873 CorrectCoords(a_x, a_y);
2874 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
2878 for (
int j = 0 - (loop - 1); j< loop; j++)
2881 CorrectCoords(a_x, a_y);
2882 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
2886 for (
int j = 0 - (loop - 1); j< loop; j++)
2889 CorrectCoords(a_x, a_y);
2890 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
2894 }
while (loop<m_width);
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();
2902 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
return;
2909 for (
int i = 0 - loop; i <= loop; i++)
2912 CorrectCoords(a_x, a_y);
2913 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
2915 APoint pt(a_x, a_y);
2919 for (
int d = 0; d < 8; d++)
2921 AxisLoopLtd(a_polyref, &pt, d,10);
2923 dists = sqrt(
double((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));
2928 if (dists > best) { best = dists; ind = d; }
2935 a_x += m_x_add[ind] * 10;
2936 a_y += m_y_add[ind] * 10;
2944 for (
int i = 0 - loop; i <= loop; i++)
2947 CorrectCoords(a_x, a_y);
2948 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
2950 APoint pt(a_x, a_y);
2954 for (
int d = 0; d < 8; d++)
2956 AxisLoopLtd(a_polyref, &pt, d,10);
2958 dists = sqrt(
double((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));
2963 if (dists > best) { best = dists; ind = d; }
2970 a_x += m_x_add[ind] * 10;
2971 a_y += m_y_add[ind] * 10;
2979 for (
int j = 0 - (loop - 1); j< loop; j++)
2982 CorrectCoords(a_x, a_y);
2983 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
2985 APoint pt(a_x, a_y);
2989 for (
int d = 0; d < 8; d++)
2991 AxisLoopLtd(a_polyref, &pt, d,10);
2993 dists = sqrt(
double((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));
2998 if (dists > best) { best = dists; ind = d; }
3005 a_x += m_x_add[ind] * 10;
3006 a_y += m_y_add[ind] * 10;
3014 for (
int j = 0 - (loop - 1); j< loop; j++)
3017 CorrectCoords(a_x, a_y);
3018 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3020 APoint pt(a_x, a_y);
3024 for (
int d = 0; d < 8; d++)
3026 AxisLoopLtd(a_polyref, &pt, d,10);
3028 dists = sqrt(
double((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));
3033 if (dists > best) { best = dists; ind = d; }
3040 a_x += m_x_add[ind] * 10;
3041 a_y += m_y_add[ind] * 10;
3049 }
while (loop<m_width);
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++)
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;
3062 centroidfile.close();
3072 for (
int p = 0; p< (int)m_elems.size(); p++)
3077 int cx = m_elems[p]->GetCentroidX();
3078 int cy = m_elems[p]->GetCentroidY();
3080 for (
int j = 0; j< (int)m_elems.size(); j++)
3084 int nx = m_elems[j]->GetCentroidX();
3085 int ny = m_elems[j]->GetCentroidY();
3093 else m_elems[p]->SetCountryDesignation(0);
3097 m_elems[p]->SetCountryDesignation(2);
3113 int day = SupplyDayInYear();
3114 m_elems[m_polymapping[a_polyref]]->SetGooseNos(a_number, day);
3125 int day = SupplyDayInYear();
3126 m_elems[m_polymapping[a_polyref]]->SetGooseNosTimed(a_number, day);
3137 int day = SupplyDayInYear();
3138 m_elems[m_polymapping[a_polyref]]->SetGooseSpNos(a_number, day, a_goose);
3147 int day = SupplyDayInYear();
3148 m_elems[m_polymapping[a_polyref]]->SetGooseSpNosTimed(a_number, day, a_goose);
3155 return m_elems[m_polymapping[a_polyref]]->GetGooseNos();
3164 return m_elems[m_land->Get(a_x, a_y)]->GetGooseNos();
3228 digest = SupplyVegDigestability(a_polygon);
3230 #ifdef __Perfectfood 3233 #ifdef __YEARLYVARIABLEFOODQUALITY 3234 digest *= m_OurPopulationManager->m_GoodYearBadYear;
3237 double access = 1.0;
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;
3244 bool veg_patchy =
true;
3245 #else // If it is not the special case of the 1950s 3247 bool veg_patchy = SupplyVegPatchy(a_polygon);
3255 access -= ((veg_height - 50)* g_VegHeightForageReduction);
3256 if (access<0) access = 0;
3261 if (veg_height>g_FarmIntensivenessH)
3264 if (access<0) access = 0;
3267 return access * digest * grazedreduction[SupplyGrazingPressure(a_polygon)];
3280 OFILE = fopen( outpfile.c_str(),
"w" );
3283 "Unable to open file for writing:",
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 );
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));
3300 fprintf(OFILE,
"%c", c );
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 ));
3309 fprintf( OFILE,
"%c", c );
3316 le_signal_index = 0;
3320 if ((
unsigned int)le_signal_index == m_elems.size()) {
3323 return m_elems[le_signal_index++]->GetPoly();
3327 return (
int)m_elems.size();
3331 return m_elems[m_polymapping[a_polyref]]->GetSignal();
3335 m_elems[m_polymapping[a_polyref]]->SetSignal(a_signal);
3342 sprintf(errornum,
"%d", a_treat);
3343 g_msg->
Warn(
WARN_BUG,
"Landscape::IncTreatCounter(): Index"" out of range!", errornum);
3346 m_treatment_counts[a_treat] ++;
3351 FILE * l_file = fopen(a_filename,
"w");
3353 g_msg->
Warn(
WARN_FILE,
"Landscape::DumpTreatCounters(): ""Unable to open file for writing: %s\n", a_filename);
3358 fprintf(l_file,
"%3d %s %10d\n", i, EventtypeToString(i).c_str(), m_treatment_counts[i]);
3364 unsigned int linesize = m_maxextent * 3;
3365 unsigned char * frame_buffer = (
unsigned char *)malloc(
sizeof(
unsigned char)* linesize);
3367 if (frame_buffer == NULL) {
3372 FILE * l_file = fopen(a_filename,
"w");
3374 g_msg->
Warn(
WARN_FILE,
"Landscape::DumpMapGraphics(): ""Unable to open file for writing: %s\n", a_filename);
3378 fprintf(l_file,
"P6\n%d %d %d\n", m_width, m_height, 255);
3380 for (
int y = 0; y < m_height; y++) {
3382 for (
int x = 0; x < m_width; x++) {
3383 int eletype = (int)SupplyElementType(x, y);
3384 int localcolor = 16777215 / eletype;
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);
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);
3397 fwrite(frame_buffer,
sizeof(
unsigned char), linesize, l_file);
3407 l_vegtype_areas[i] = 0.0;
3411 for (
unsigned int i = 0; i < m_elems.size(); i++) {
3412 l_vegtype_areas[m_elems[i]->GetVegType()] += m_elems[i]->GetArea();
3420 outf = fopen(a_filename,
"a");
3422 g_msg->
Warn(
WARN_FILE,
"Landscape::DumpMapInfoByArea(): ""Unable to open file for appending", a_filename);
3427 outf = fopen(a_filename,
"w");
3429 g_msg->
Warn(
WARN_FILE,
"Landscape::DumpMapInfoByArea(): ""Unable to open file for writing", a_filename);
3438 if (!a_dump_zero_areas && l_vegtype_areas[i] < 0.5)
3442 if (a_write_veg_names)
3444 fprintf(outf,
"\n");
3457 static char error_num[20];
3660 sprintf(error_num,
"%d", a_type);
3661 g_msg->
Warn(
WARN_FILE,
"Landscape::NewElement(): Unknown landscape element requested:", error_num);
3677 return " sleep_all_day";
3679 return " autumn_plough";
3681 return " autumn_harrow";
3683 return " autumn_roll";
3685 return " autumn_sow";
3687 return " winter_plough";
3689 return " deep_ploughing";
3691 return " spring_plough";
3693 return " spring_harrow";
3695 return " spring_roll";
3697 return " spring_sow";
3705 return " fp_liquidNH3";
3707 return " fp_slurry";
3709 return " fp_manganesesulphate";
3711 return " fp_manure";
3713 return " fp_greenmanure";
3715 return " fp_sludge";
3721 return " fa_slurry";
3723 return " fa_ammoniumsulphate";
3725 return " fa_manure";
3727 return " fa_greenmanure";
3729 return " fa_sludge";
3731 return " herbicide_treat";
3733 return " growth_regulator";
3735 return " fungicide_treat";
3737 return " insecticide_treat";
3739 return "pesticide_product_treat";
3741 return " syninsecticide_treat";
3743 return " molluscicide";
3745 return " row_cultivation";
3747 return " strigling";
3749 return " flammebehandling";
3751 return " hilling_up";
3759 return " cattle_out";
3763 return " cut_to_hay";
3765 return " cut_to_silage";
3767 return " straw_chopping";
3769 return " hay_turning";
3771 return " hay_bailing";
3773 return " stubble_harrowing";
3775 return "autumn_or_spring_plough";
3777 return " burn_straw_stubble";
3781 return " cut_weeds";
3783 return " strigling_sow";
3785 return "PesticideTrialTreatment";
3787 return " PesticideTrialToxic";
3789 return " PesticideTrialControl";
3791 return " Glyphosate on setaside";
3793 sprintf(error_num,
"%d", a_event);
3794 g_msg->
Warn(
WARN_FILE,
"Landscape::EventtypeToString(): Unknown event type:", error_num);
3804 switch (a_le_type) {
3808 return " Roadside Verge";
3812 return " Field Boundary";
3820 return " PermPastureTussocky";
3822 return " Permanent Setaside";
3824 return " Permanent Pasture";
3826 return " PermPastureLowYield";
3828 return " Natural Grass";
3830 return " Natural Grass Wet";
3832 return " Riverside Plants";
3834 return " Pit Disused";
3836 return " Riverside Trees";
3838 return " Deciduous Forest";
3840 return " Mixed Forest";
3842 return " Coniferous Forest";
3844 return " Young Forest";
3846 return " Stone Wall";
3852 return " Small Road";
3854 return " Large Road";
3858 return " Active Pit";
3862 return " Fresh Water";
3866 return " Saltwater";
3870 return " Bare Rock";
3872 return " Hedgebank";
3878 return " Orchard Band";
3880 return " Mown Grass";
3882 return " UnsprayedFieldMargin";
3884 return " AmenityGrass";
3888 return " UrbanNoVeg";
3890 return " UrbanPark";
3892 return " BuiltUpWithParkland";
3898 return " RoadsideSlope";
3900 return " MetalledPath";
3904 return " Churchyard";
3906 return " Saltmarsh";
3910 return " HeritageSite";
3912 return " Beetle Bank";
3914 return " Unknown Grass";
3916 return " Waste/Building Land";
3918 return " IndividualTree";
3920 return " PlantNursery";
3922 return " Vildtager";
3924 return " WindTurbine";
3926 return " WoodyEnergyCrop";
3928 return " WoodlandMargin";
3935 sprintf(error_num,
"%d", a_le_type);
3936 g_msg->
Warn(
WARN_FILE,
"Landscape::PolytypeToString(): Unknown event type:", error_num);
3950 return "BroadBeans ";
3952 return "FodderGrass ";
3954 return "CloverGrassGrazed1 ";
3956 return "CloverGrassGrazed2 ";
3958 return "FieldPeas ";
3960 return "FieldPeasSilage ";
3962 return "FodderBeet ";
3964 return "SugarBeet ";
3966 return "OFodderBeet ";
3972 return "MaizeSilage ";
3974 return "OMaizeSilage ";
3976 return "NaturalGrass ";
3982 return "OrchardCrop ";
3986 return "OBarleyPeaCloverGrass";
3990 return "OCloverGrassGrazed1 ";
3992 return "OCloverGrassGrazed2 ";
3994 return "OCloverGrassSilage1 ";
3996 return "OFieldPeas ";
3998 return "OFieldPeasSilage ";
4000 return "OFirstYearDanger ";
4002 return "OGrazingPigs ";
4006 return "OPermanentGrassGrazed";
4008 return "OPotatoes ";
4010 return "OSBarleySilage ";
4012 return "OSeedGrass1 ";
4014 return "OSeedGrass2 ";
4016 return "OSetaside ";
4018 return "OSpringBarley ";
4020 return "OSpringBarleyExt ";
4022 return "OSpringBarleyClover ";
4024 return "OSpringBarleyGrass ";
4026 return "OSpringBarleyPigs ";
4028 return "OTriticale ";
4030 return "OWinterBarley ";
4032 return "OWinterBarleyExt ";
4034 return "OWinterRape ";
4036 return "OWinterRye ";
4038 return "OWinterWheatUndersown";
4040 return "OWinterWheat";
4042 return "OWinterWheatUsowExt ";
4044 return "PermanentGrassGrazed ";
4046 return "PermanentGrassLowYield";
4048 return "PermanentGrassTussocky";
4050 return "PermanentSetaside ";
4052 return "PotatoesEat ";
4054 return "PotatoesIndustry ";
4056 return "SeedGrass1 ";
4058 return "SeedGrass2 ";
4062 return "SpringBarley ";
4064 return "SpringBarleySpr ";
4066 return "SpringBarleyPTreat ";
4068 return "SpringBarleySKMan ";
4070 return "SprBarleyCloverGrass ";
4072 return "SpringBarleyGrass ";
4074 return "SpringBarleySeed ";
4076 return "SpringBarleySilage ";
4078 return "SpringRape ";
4080 return "SpringWheat ";
4082 return "AgroChemIndustry Cereal ";
4084 return "Triticale ";
4086 return "WinterBarley ";
4088 return "WinterRape ";
4090 return "WinterRye ";
4092 return "WinterWheat ";
4094 return "WinterWheatShort ";
4096 return "P Trial Control ";
4098 return "P Trial Toxic Control";
4100 return "P Trial Treatment ";
4102 return "Undefined ";
4104 return "WWStrigling ";
4106 return "WWStriglingSingle ";
4108 return "WWStriglingCulm ";
4110 return "SBPCGStrigling ";
4112 return "SBarleyStrigling ";
4114 return "SBarleyStriglingSgl ";
4116 return "SBarleyStriglingCulm ";
4118 return "MaizseStrigling ";
4120 return "WRapeStrigling ";
4122 return "WRyeStrigling ";
4124 return "WBStrigling ";
4126 return "FieldPeasStrigling ";
4128 return "SBPeaCloverGrassStr ";
4130 return "Young Forest ";
4132 return "Wasteland ";
4134 return "Heath/Grass ";
4136 return "Plant Nursery ";
4139 sprintf(error_num,
"%d", a_veg);
4140 g_msg->
Warn(
WARN_FILE,
"Landscape::VegtypeToString(): Unknown event type:", error_num);
4148 static char error_num[20];
4149 bool AddBorder =
false;
4220 sprintf(error_num,
"%d", a_letype);
4221 g_msg->
Warn(
WARN_BUG,
"Landscape::BorderNeed(): Unknown element type:", error_num);
4298 if ((a_day % 365) == 0) {
4304 if ((a_day % 365) == 152) {
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)
void SetElementType(int a_type)
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...
CfgFloat cfg_fungi_app_prop2("CROPS_FUNGICIDE_APPLIC_TWO_PROPORTION", CFG_CUSTOM, 1.0)
virtual void SetCentroid(int x, int y)
The landscape class containing all environmental and topographical data.
CfgBool cfg_dumpvegjune("G_VEGAREASJUNE_ON", CFG_CUSTOM, false)
void SimulationClosingActions()
CfgStr cfg_dumpvegjanfile("G_VEGAREASJAN_FILENAME", CFG_CUSTOM,"DUMPVEG_JAN.TXT")
double GetHareFoodQuality(int a_polygon)
void SetLESignal(int a_polyref, LE_Signal a_signal)
CfgFloat cfg_greg_app_prop("CROPS_GROWTHREGULATOR_APPLIC_PROPORTION", CFG_CUSTOM, 1.0)
void ConsolidatePolys(void)
int BackTranslateEleTypes(TTypesOfLandscapeElement EleReference)
double g_VegHeightForageReduction
void IncTreatCounter(int a_treat)
bool FindValidXY(int a_field, int &a_x, int &a_y)
bool BorderStep(int a_fieldpoly, int a_borderpoly, int *a_x, int *a_y)
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()
static const int version_minor
void RemoveMissingValues()
A method for replacing missing values in the map with corrected ones - slow.
double g_SpeedyDivides[2001]
A generally useful array of fast divide calculators by multiplication.
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)
int GetUnsprayedMarginPolyRef(void)
bool SupplyOverspray(int a_x, int a_y)
Gets the overspray flag.
static CfgBool l_map_exit_on_zero_area("MAP_EXIT_ON_ZERO_AREA", CFG_CUSTOM, true)
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)
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.
bool GetAnythingToDecay()
CfgInt cfg_l_treatment_size("LAND_TREATMENTSIZE", CFG_CUSTOM,-1)
CfgBool cfg_BeetleBankInvert("BBANK_INVERT", CFG_CUSTOM, false)
int GetPoly(void)
Returns the polyref number for this polygon.
CfgBool cfg_l_usecustompoly("LAND_USECUSTOMPOLY", CFG_CUSTOM, false)
std::string PolytypeToString(TTypesOfLandscapeElement a_le_type)
virtual int GetCentroidY()
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.
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.
int CalulateFieldOpennessCentroid(int a_pref)
Provides a measure of the shortest distance in 360 degree, e-g- looking NE % SW before tall obstacles...
bool BorderNeed(TTypesOfLandscapeElement a_letype)
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)
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)
Integer configurator entry class.
void PolysRemoveInvalid(void)
static CfgInt cfg_mintownbuildingdistance("MAP_MINTOWNBUILDINGDISTANCE", CFG_CUSTOM, 100)
double g_FarmIntensivenessH
static CfgBool l_map_dump_enable("MAP_DUMP_ENABLE", CFG_CUSTOM, false)
CfgInt cfg_BeetleBankMaxY("BBANK_MAXY", CFG_CUSTOM, 100000)
void DumpMap(const char *a_filename)
double SupplyPesticide(int a_x, int a_y)
void SetUnsprayedMarginPolyRef(int a_unsprayedmargin)
void PolysDump(const char *a_filename)
#define PEST_GRIDSIZE_POW2
Turns on code for detailed pesticide fate handling.
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)
static CfgStr l_map_cropcurves_file("MAP_CROPCURVES_FILE", CFG_CUSTOM,"curves.pre")
APoint SupplyCentroid(int a_polyref)
CfgFloat cfg_ins_app_prop3("CROPS_INSECTICIDE_APPLIC_THREE_PROPORTION", CFG_CUSTOM, 1.0)
void UnsprayedMarginScan(LE *a_field, int a_width)
CfgBool l_pest_enable_pesticide_engine
virtual void SetVegPatchy(bool)
TTypesOfVegetation vegtype
CfgInt cfg_HedgeSubtypeMinimum("HEDGE_SUBTYPEMINIMUM", CFG_CUSTOM, 0)
bool ReadSymbols(const char *a_cfgfile)
void SkylarkEvaluation(SkTerritories *a_skt)
void SetPolyMaxMinExtents(void)
base_generator_type g_generator(static_cast< unsigned int >(std::time(0)))
void AddBeetleBanks(TTypesOfLandscapeElement a_tole)
void GISASCII_Output(string outpfile, int UTMX, int UTMY)
Write ASCII file of the ALMaSS map.
CfgBool cfg_OptimiseBedriftsmodelCrops
If set to true, the original farm optimisation model's crop set is used in the farmer decision making...
CfgInt g_map_le_borders_min_field_size("MAP_LE_BORDERS_MIN_FIELD_SIZE", CFG_CUSTOM, 10000)
void SetBorder(LE *a_border)
TTypesOfLandscapeElement TranslateEleTypes(int EleReference)
A list item entry of field polygon reference numbers with associated openness and goose food scores...
void BeetleBankAdd(int x, int y, int angle, int length, LE *a_field, TTypesOfLandscapeElement a_tole)
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.
CfgBool cfg_rectangularmaps_on
class Weather * g_weather
void SetSoilType(int a_st)
boost::variate_generator< base_generator_type &, boost::uniform_int<> > g_rand_uni2(g_generator, g_uni_dist2)
void RodenticidePredatorsEvaluation(RodenticidePredators_Population_Manager *a_rppm)
void ReadPolys2(const char *a_polyfile)
reads in polygon information. Version 2 including centroid and openness information ...
CfgInt cfg_BeetleBankMinX("BBANK_MINX", CFG_CUSTOM, 0)
void AxisLoopLtd(int a_poly, APoint *a_cor, int a_axis, int a_limit)
static const int version_revision
class LE_TypeClass * g_letype
static const char * version_date
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)
class MapErrorMsg * g_msg
static CfgInt l_map_dump_veg_x("MAP_DUMP_VEG_X", CFG_CUSTOM, 100)
void SetWarnLevel(MapErrorState a_level)
boost::uniform_real g_uni_dist(0, 1)
void CountMapSquares(void)
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.
static CfgBool cfg_AddBeetleBanks("BBANKS_ADD", CFG_CUSTOM, false)
CfgFloat cfg_silage_prop("CROPS_SILAGE_PROPORTION", CFG_CUSTOM, 1.0)
Landscape * g_landscape_p
void CreatePondList()
Creates a list of pond polygon refs/indexes for easy look up.
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)
static CfgBool l_map_dump_exit("MAP_DUMP_EXIT", CFG_CUSTOM, false)
static CfgBool l_map_removesmallpolygons("MAP_REMOVESMALLPOLYGONS", CFG_CUSTOM, false)
void DumpVegAreaData(int a_day)
void BorderAdd(LE *a_field, TTypesOfLandscapeElement a_type)
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)
static CfgInt cfg_mintownbuildingnumber("MAP_MINTOWNBUILDINGNUMBER", CFG_CUSTOM, 6)
void ChangeMapMapping(void)
void UnsprayedMarginAdd(LE *a_field)
virtual TTypesOfLandscapeElement GetElementType(void)
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.
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)
Landscape(const char *a_configfile, const char *a_errorfile)
void SetOpenness(int a_openness)
Records the openness statistic for this polygon.
bool BorderTest(int a_fieldpoly, int a_borderpoly, int a_x, int a_y)
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...
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.
Bool configurator entry class.
void SetMapValid(bool a_valid)
double SupplyPesticideS(int a_x, int a_y)
Gets soil pesticide for a location.
void BorderScan(LE *a_field, int a_width)
vector< unsigned > polylist
void DumpTreatCounters(const char *a_filename)
void CalculateOpenness(bool a_realcalc)
Causes openness to be calulated and stored for all polygons.
void AxisLoop(int a_poly, int *a_x, int *a_y, int a_axis)
static CfgStr l_map_map_file("MAP_MAP_FILE", CFG_CUSTOM,"map.lsb")
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...
int SupplyRandomPondIndex()
Returns random pond index.
static CfgBool cfg_CalculateCentroids("MAP_CALCULATE_CENTROIDS", CFG_CUSTOM, false)
LE_Signal SupplyLESignal(int a_polyref)
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...
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.
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...
void BuildingDesignationCalc()
used to calculate whether a building is rural or town - for rodenticide use
GooseFieldList * GetGooseFields(double)
Gets the list of suitable goose foraging fields today.
void DoCopy(const LE *a_Le)
a copy function to be used because a copy constuctor won't work
std::vector< GooseFieldListItem > GooseFieldList
A list of GooseFieldListItem s.
double SupplyRodenticide(int a_x, int a_y)
Gets total rodenticide for a location.
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)
std::string EventtypeToString(int a_event)
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)
static CfgInt l_map_dump_event_y2("MAP_DUMP_EVENT_YB", CFG_CUSTOM, 2889)
CfgInt g_map_le_border_chance("MAP_LE_BORDER_CHANCE", CFG_CUSTOM, 25)
CfgFloat cfg_fungi_app_prop3("CROPS_FUNGICIDE_APPLIC_THREE_PROPORTION", CFG_CUSTOM, 1.0)
int geesespTimed[gs_foobar]
int FindLongestAxis(int *x, int *y, int *a_length)
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)
static CfgBool l_map_print_version_info("MAP_PRINT_VERSION_INFO", CFG_CUSTOM, true)
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
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)
static CfgInt l_map_dump_veg_y("MAP_DUMP_VEG_Y", CFG_CUSTOM, 100)
int SupplyFarmIntensity(int a_x, int a_y)
APoint SupplyCentroidIndex(int a_polyrefindex)
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...
bool FindFieldCenter(LE *a_field, int *x, int *y)
void PolysValidate(bool a_exit_on_invalid)
CfgBool cfg_rodenticide_reporting_enable("RODENTICIDE_REPORTING_ENABLE", CFG_CUSTOM, false)
void SetValidXY(int a_valid_x, int a_valid_y)
CfgFloat cfg_ins_app_prop1("CROPS_INSECTICIDE_APPLIC_ONE_PROPORTION", CFG_CUSTOM, 1.0)
static const int version_major
void CalculateCentroids(void)
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 DegreesDump()
Prints the sum of day degrees. See FarmManager::daydegrees.
bool BeetleBankPossible(LE *a_field, TTypesOfLandscapeElement a_tole)
CfgBool g_map_le_borders("MAP_LE_BORDERS", CFG_CUSTOM, false)
void CentroidSpiralOut(int a_polyref, int &a_x, int &a_y)
Double configurator entry class.
void DumpMapGraphics(const char *a_filename)
int CalulateFieldOpennessAllCells(int a_pref)
Provides a measure of the shortest distance in 360 degree, e-g- looking NE % SW before tall obstacles...
int SupplyFarmIntensityI(int a_polyindex)
int SupplyRandomPondRef()
Returns random pond polyref.
CfgBool cfg_rodenticide_enable("RODENTICIDE_ENABLE", CFG_CUSTOM, false)
CfgBool g_map_le_unsprayedmargins("MAP_LE_UNSPRAYEDMARGINS", CFG_CUSTOM, false)
virtual int GetCentroidX()
int RemoveSmallPolygons(void)
Removes small polygons from the map.
int SupplyFarmAnimalCensus(int a_farm_ref, int a_LifeStage)
static CfgInt cfg_BeetleBankWidth("BBANK_WIDTH", CFG_CUSTOM, 4)
CfgInt cfg_l_treatment_y("LAND_TREATMENTY", CFG_CUSTOM, 0)
CfgBool g_map_le_borderremoval("MAP_LE_BORDERREMOVAL", CFG_CUSTOM, false)
LE * NewElement(TTypesOfLandscapeElement a_type)
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)
void VegDump(int x, int y)
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)
static CfgBool l_map_calc_openness("MAP_CALC_OPENNESS", CFG_CUSTOM, false)