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"
327 cout <<
"In CalculateOpenness" << endl;
329 for (
unsigned int i = 0; i < m_elems.size(); i++)
346 m_elems[i]->SetOpenness(CalulateFieldOpennessAllCells(i));
348 else m_elems[i]->SetOpenness(0);
351 m_elems[i]->SetOpenness(0);
355 if (a_realcalc) cout << endl;
362 int d0 = m_maxextent;
363 int cx = m_elems[a_pref]->GetCentroidX();
364 int cy = m_elems[a_pref]->GetCentroidY();
369 double dx = 1.0 / 45.0;
371 for (
int deg = 0; deg<90; deg++)
374 int d1 = LineHighTest(cx, cy, offsetx, offsety);
375 int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
379 offsetx = offsetx + dx;
380 offsety = offsety + dy;
386 for (
int deg = 0; deg<90; deg++)
389 int d1 = LineHighTest(cx, cy, offsetx, offsety);
390 int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
394 offsetx = offsetx + dx;
395 offsety = offsety + dy;
405 int minX = m_elems[a_pref]->GetMinX();
406 int minY = m_elems[a_pref]->GetMinY();
407 int maxX = m_elems[a_pref]->GetMaxX();
408 int maxY = m_elems[a_pref]->GetMaxY();
409 for (
int ax = minX; ax <= maxX; ax+=10)
411 for (
int ay = minY; ay <= maxY; ay+=10)
417 if (m_land->Get(ax, ay) == a_pref)
425 double dx = 1.0 / 45.0;
427 for (
int deg = 0; deg<90; deg++)
430 int d1 = LineHighTest(cx, cy, offsetx, offsety);
431 int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
434 if (dline > d) dline = d;
435 offsetx = offsetx + dx;
436 offsety = offsety + dy;
442 for (
int deg = 0; deg<90; deg++)
445 int d1 = LineHighTest(cx, cy, offsetx, offsety);
446 int d2 = LineHighTest(cx, cy, 0 - offsetx, 0 - offsety);
449 if (dline > d) dline = d;
450 offsetx = offsetx + dx;
451 offsety = offsety + dy;
453 if (dline > d0) d0 = dline;
473 int x = (int) (a_cx + a_offsetx * counter);
474 int y = (int) (a_cy + a_offsety * counter);
475 if (x<1 || x >= (m_width-2) || y<1 || y >= (m_height-2))
return counter;
479 if (SupplyLEHigh(x,y))
481 x = (int) (a_cx + a_offsetx * (counter+1));
482 y = (int) (a_cy + a_offsety * (counter+1));
483 if (SupplyLEHigh(x,y)) found =
true;
496 pp = m_RodenticideManager->GetRodenticide(a_x, a_y);
527 default:
return false;
581 default:
return false;
588 #ifdef __DETAILED_PESTICIDE_FATE
590 pp =
g_pest->SupplyPesticideS(a_x, a_y, a_ppp);
591 pp +=
g_pest->SupplyPesticideP(a_x, a_y, a_ppp);
601 return m_elems[m_land->Get(a_x, a_y)]->GetSprayedToday();
607 #ifdef __DETAILED_PESTICIDE_FATE
608 pp =
g_pest->SupplyPesticideP(a_x, a_y, a_ppp);
618 #ifdef __DETAILED_PESTICIDE_FATE
619 pp =
g_pest->SupplyPesticideS(a_x, a_y, a_ppp);
630 #ifdef __DETAILED_PESTICIDE_FATE
631 pp =
g_pest->SupplyPesticideS(a_polyref, a_ppp);
632 pp +=
g_pest->SupplyPesticideP(a_polyref, a_ppp);
643 #ifdef __DETAILED_PESTICIDE_FATE
644 pp =
g_pest->SupplyPesticideS(a_polyref, a_ppp);
655 #ifdef __DETAILED_PESTICIDE_FATE
656 pp =
g_pest->SupplyPesticideP(a_polyref, a_ppp);
665 return dynamic_cast<Pond*>(m_elems[a_polyrefindex])->SubtractLarvalFood(a_food);
675 m_PesticideMap->Spray(a_field, a_pcide);
698 for (
unsigned int i = 0; i < m_elems.size(); i++)
700 if (m_elems[i]->GetOpenness() > a_minopenness)
702 for (
int g = gs_Pinkfoot; g < gs_foobar; g++)
704 gfli.
grass[g] = m_elems[i]->GetGooseGrazingForage((GooseSpecies)g);
705 gfli.
geesesp[g] = m_elems[i]->GetGooseSpNosToday((GooseSpecies)g);
706 gfli.
geesespTimed[g] = m_elems[i]->GetGooseSpNosTodayTimed((GooseSpecies)g);
707 gfli.
roostdists[g] = m_elems[i]->GetGooseRoostDist((GooseSpecies)g);
709 gfli.
grain = m_elems[i]->GetBirdSeed();
710 gfli.
maize = m_elems[ i ]->GetBirdMaize();
711 gfli.
openness = m_elems[ i ]->GetOpenness();
712 int pref = m_elems[ i ]->GetPoly();
714 gfli.
geese = m_elems[i]->GetGooseNosToday();
715 gfli.
geeseTimed = m_elems[i]->GetGooseNosTodayTimed();
716 gfli.
vegtype = m_elems[i]->GetVegType();
717 gfli.
vegtypechr = VegtypeToString(m_elems[i]->GetVegType());
718 gfli.
vegheight = m_elems[i]->GetVegHeight();
720 gfli.
vegphase = m_elems[i]->GetVegPhase();
721 gfli.
previouscrop = VegtypeToString( m_elems[ i ]->GetPreviousCrop( m_elems[ i ]->GetRotIndex() ) );
722 gfli.
lastsownveg = VegtypeToString( m_elems[ i ]->GetLastSownVeg() );
723 alist->push_back(gfli);
736 for (
unsigned int i = 0; i < m_elems.size(); i++)
738 m_elems[i]->SetBirdSeed(0.0);
739 m_elems[i]->SetBirdMaize(0.0);
747 return m_ThePopManager->FarmAnimalCensus(a_farm_ref, a_LifeStage);
752 return m_elems[ a_polyindex ]->GetOwner()->GetIntensity();
757 return m_elems[ m_land->Get( a_x, a_y ) ]->GetOwner()->GetIntensity();
762 return m_elems[
m_polymapping[ a_polyref ]]->GetOwner()->GetIntensity();
772 return m_elems[ a_polyrefindex ]->GetCentroid();
793 unsigned sz = (unsigned) m_elems.size();
794 for (
unsigned i=0; i<sz; i++)
796 if ( m_elems[i]->GetOpenness() > a_openness)
798 APoint pt = m_elems[i]->GetCentroid();
800 if (a_x>pt.m_x) dx = a_x-pt.m_x;
else dx = pt.m_x-a_x;
801 if (a_y>pt.m_y) dy = a_y-pt.m_y;
else dy = pt.m_y-a_y;
806 if (dx>dy) dist = dx + (dy * dy) /(2 * dx);
else dist = dy + (dx * dx) /(2 * dy);
807 if (dist<=a_range) p_list->push_back( m_elems[i]->GetPoly());
819 bool didRenumber =
false;
820 bool didCalcCentroids =
false;
821 bool didConsolidate =
false;
822 bool didCalcOpenness =
false;
823 bool didCalcOther =
false;
824 m_NeedCentroidCalculation =
false;
825 m_NeedOpennessCalculation =
false;
826 m_DoMissingPolygonsManipulations =
false;
829 for (
int i = 1; i <= 2000; i++) {
832 int x_add[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
833 int y_add[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
834 for (
int i = 0; i < 8; i++) {
835 m_x_add[i] = x_add[i];
836 m_y_add[i] = y_add[i];
843 printf(
"This program uses the Landscape simulator V%s\n", m_versioninfo);
848 std::cout <<
"hash=" << GIT_HASH <<
", time=" << COMPILE_TIME <<
", branch=" << GIT_BRANCH << std::endl;
864 m_GooseIntakeRateVSVegetationHeight_GL->WriteDataFile(10);
865 m_GooseIntakeRateVSVegetationHeight_BG->WriteDataFile(10);
866 m_GooseIntakeRateVSVegetationHeight_PF->WriteDataFile(10);
869 cout <<
"Creating Calendar Object" << endl;
871 cout <<
"Creating Weather Object" << endl;
873 cout <<
"Creating LE_TypeClass Object" << endl;
875 cout <<
"Creating PlantGrowthData Object" << endl;
877 cout <<
"Creating PollenNectarDevelopmentData Object" << endl;
879 m_LargestPolyNumUsed = -1;
883 m_treatment_counts[i] = 0;
885 cout <<
"Creating FarmManager Object" << endl;
888 cout <<
"Reading polygon reference file" << endl;
893 m_FarmManager->InitFarms();
894 m_FarmManager->Save_diff_farm_types_areas();
897 cout <<
"Creating RasterMap Object" << endl;
900 m_height = m_land->MapHeight();
901 if (m_width > m_height) m_maxextent = m_width;
else m_maxextent = m_height;
902 m_width10 = 10 * m_width;
903 m_height10 = 10 * m_height;
904 if (m_width < m_height) m_minmaxextent = m_width;
else m_minmaxextent = m_height;
909 cout <<
"In PolysValidate" << endl;
910 PolysValidate(
false);
911 cout <<
"In PolysRemoveInvalid" << endl;
912 PolysRemoveInvalid();
913 cout <<
"Creating ponds" << endl;
916 for (
unsigned int i = 0; i < m_elems.size(); i++) {
923 m_elems[i] = dynamic_cast<LE*>(pond);
928 cout <<
"In PolysValidate second time" << endl;
936 if (m_DoMissingPolygonsManipulations)
938 cout <<
"In DoMissingPolygonsManipulations" << endl;
940 for (
unsigned int i = 0; i < m_elems.size(); i++)
944 double area = m_elems[i]->GetArea();
945 int areaMinrect = (m_elems[i]->GetMaxX() - m_elems[i]->GetMinX()) * (m_elems[i]->GetMaxY() - m_elems[i]->GetMinY());
946 if ((areaMinrect / area > 4) || (area < 1000))
955 wl->
SetPoly(m_elems[i]->GetPoly());
956 wl->
SetArea(floor(0.5 + area));
959 wl->SetCentroid(-1, -1);
967 RemoveMissingValues();
968 for (
unsigned int i = 0; i < m_elems.size(); i++)
974 wl->
SetPoly(m_elems[i]->GetPoly());
975 wl->
SetArea(m_elems[i]->GetArea());
978 wl->SetCentroid(-1, -1);
984 cout <<
"In PolysValidate third time" << endl;
985 PolysValidate(
false);
986 if (PolysRemoveInvalid()) {
987 cout <<
"In PolysValidate fourth time" << endl;
990 g_msg->
Warn(
"Landscape::Landscape(): Dump and normal exit to follow after resolving missing polygons. ",
"");
996 cout <<
"In ChangeMapMapping" << endl;
1002 if ((m_LargestPolyNumUsed != ((
int)m_elems.size() - 1)))
1004 cout <<
"In poly renumber" << endl;
1012 cout <<
"In Landscape::Landscape() Small polygon removal" << endl;
1013 int removed = RemoveSmallPolygons();
1014 g_msg->
Warn(
"Landscape::Landscape(): Dump and normal exit to follow after removing small polygons and map dump. Polygons removed:", removed);
1015 didCalcOther =
true;
1020 cout <<
"In consolidate polys" << endl;
1021 didConsolidate =
true;
1026 cout <<
"In map_le_borderremoval" << endl;
1031 g_msg->
Warn(
WARN_FILE,
"Landscape::Landscape() - BorderRemoval "" map dump to follow.",
"");
1032 didCalcOther =
true;
1038 if (didConsolidate || didCalcOther || m_NeedCentroidCalculation)
1040 PolysValidate(
false);
1041 if (PolysRemoveInvalid()) PolysValidate(
true);
1044 CalculateCentroids();
1045 didCalcCentroids =
true;
1047 if (didConsolidate || didCalcOther || m_NeedCentroidCalculation || didCalcCentroids ||
l_map_calc_openness.
value())
1050 else CalculateOpenness(
false);
1051 didCalcOpenness =
true;
1053 if (didCalcCentroids || didConsolidate || didCalcOpenness || didCalcOther || m_NeedCentroidCalculation || didRenumber || !m_FarmManager->GetIsRenumbered())
1056 m_FarmManager->DumpFarmrefs();
1059 g_msg->
Warn(
WARN_FILE,
"Landscape::Landscape() ""Normal exit after dump.",
"Remember to rename the new map and polyref file.");
1066 didCalcOther =
false;
1071 didCalcOther =
true;
1075 cout <<
"Generating LE Borders around fields" << endl;
1079 cout <<
"Setting MaxMin Extents" << endl;
1080 SetPolyMaxMinExtents();
1081 cout <<
"Adding Borders" << endl;
1082 unsigned sz = (unsigned)m_elems.size();
1083 for (
unsigned i = 0; i < sz; i++)
1085 if (m_elems[i]->GetBorder() != NULL)
1092 BorderAdd(m_elems[i], t);
1096 didCalcOther =
true;
1102 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1106 BorderAdd(m_elems[i], t);
1109 didCalcOther =
true;
1119 for (
unsigned int i = 0; i < m_elems.size(); i++)
1121 if (m_elems[i]->GetUnsprayedMarginPolyRef() != -1)
1124 if (m_elems[i]->GetArea() > 10000)
1127 UnsprayedMarginAdd(m_elems[i]);
1129 else m_elems[i]->SetUnsprayedMarginPolyRef(-1);
1132 didCalcOther =
true;
1136 cout <<
"Adding beetle banks now" << endl;
1138 didCalcOther =
true;
1150 PolysValidate(
false);
1151 if (PolysRemoveInvalid()) PolysValidate(
true);
1154 CalculateCentroids();
1156 m_FarmManager->DumpFarmrefs();
1157 cout <<
"Dumping map" << endl;
1159 cout <<
"Dumping polygon refs file" << endl;
1161 g_msg->
Warn(
WARN_FILE,
"Landscape::Landscape() ""Normal exit after dump.",
"Remember to rename the new map and polyref file.");
1177 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1179 m_elems[i]->SetSubType(l_subtype);
1188 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1189 if (m_elems[i]->GetElementType() ==
tole_Hedges) {
1190 m_elems[i]->SetSubType(l_subtype);
1191 if (++l_subtype >= 3)
1198 cout <<
"Initiating farm management" << endl;
1199 m_FarmManager->InitiateManagement();
1201 m_toxShouldSpray =
false;
1217 int l_count = SupplyLECount();
1220 for (
int i = 0; i < l_count; i++) {
1223 int a_poly = SupplyLENext();
1234 LE_Signal l_signal = SupplyLESignal(a_poly);
1240 SetLESignal(a_poly, l_signal);
1244 l_vegtype_areas = (
double *)malloc(
sizeof(
double) * (
tov_Undefined + 1));
1246 if (l_vegtype_areas == NULL) {
1271 #ifdef __RECORDFARMEVENTS
1272 m_farmeventfile =
new ofstream(
"FarmEvents.txt", ofstream::out);
1279 f = fopen(
"VegDump.txt",
"w");
1281 g_msg->
Warn(
WARN_BUG,
"Landscape::Landscape(): VegDump.txt could not be created",
"");
1284 fprintf(f,
"Year\tDay\tHeight\tBiomass\tGrazed\tDensity\tCover\tWeedBiomass\ttovNum\tInsectBiomass\tLATotal\tLAGreen\tDigestability\tGreenBiomass\tDeadBiomass\tGooseGrazing\tSpilledGrain\nn");
1289 f = fopen(
"EventDump.txt",
"w");
1291 g_msg->
Warn(
WARN_BUG,
"Landscape::Landscape(): EventDump.txt could not be created",
"");
1298 m_FarmManager->FindNeighbours();
1302 m_FarmManager->DumpFarmAreas();
1311 m_RodenticideManager =
new RodenticideManager(
"BaitLocations_input.txt",
this);
1312 m_RodenticidePreds =
new RodenticidePredators_Population_Manager(
this);
1316 cout <<
"Running initial start-up year" << endl;
1317 for (
unsigned int i = 0; i < 365; i++) Tick();
1324 GISASCII_Output(
"AsciiLandscape.txt", x, y);
1336 const int TypesToReplace = 16;
1355 int foundList[TypesToReplace];
1356 cout <<
"Consolidating polygons with no special behaviour" << endl;
1357 for (
int i = 0; i < TypesToReplace; i++) foundList[i] = -1;
1358 int mapwidth = m_land->MapWidth();
1359 int mapheight = m_land->MapHeight();
1360 for (
int x = 0; x < mapwidth; x++)
1362 for (
int y = 0; y < mapheight; y++)
1364 int ele = m_land->Get(x, y);
1366 for (
int t = 0; t < TypesToReplace; t++)
1368 if (tole == replaceList[t])
1371 if (foundList[t] == -1) foundList[t] = ele;
1375 m_land->Put(x, y, foundList[t]);
1382 g_msg->
Warn(
WARN_FILE,
"Landscape::ConsolidatePolys() - ""Consolidate map dump.",
"");
1388 int * l_map = m_land->GetMagicP(0, 0);
1413 ofstream OFile( a_filename, ios::binary);
1414 char id[12] = {
"LSB2_Format" };
1415 OFile.write(
id, 12);
1416 OFile.write((
char*)&m_width,
sizeof (
int));
1417 OFile.write((
char*)&m_height,
sizeof (
int));
1418 OFile.write((
char*)l_map, m_width*m_height*
sizeof (
int));
1429 #ifdef __RECORDFARMEVENTS
1430 m_farmeventfile->close();
1431 delete m_farmeventfile;
1434 for (
unsigned int i = 0; i < m_elems.size(); i++ )
1435 delete m_elems[ i ];
1437 free( l_vegtype_areas );
1447 delete m_RodenticideManager;
1448 delete m_RodenticidePreds;
1450 delete m_FarmManager;
1462 this->m_FarmManager->PrintFinalResults();
1480 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1481 m_elems[ i ]->StoreLAItotal();
1487 m_FarmManager->SetSpilledGrain(
true );
1489 else m_FarmManager->SetSpilledGrain(
false );
1490 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1491 m_elems[ i ]->SetGrowthPhase(
janfirst );
1495 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1497 m_elems[i]->SetStubble(
false);
1501 m_toxShouldSpray =
true;
1502 else m_toxShouldSpray =
false;
1507 for (
unsigned int i = 0; i < m_elems.size(); i++) {
1508 m_elems[ i ]->Tick();
1509 m_elems[ i ]->DoDevelopment();
1518 m_FarmManager->ActualProfit();
1521 ofstream ofile2(
"CropDistribution.txt", ios::app );
1524 ofile2 << last_year <<
'\t';
1525 for (
int c = 0; c < m_FarmManager->pm_data->Get_noCrops(); c++) ofile2 << m_FarmManager->Get_cropTotals( c ) <<
'\t';
1528 for (
int i = 0; i < (int)m_FarmManager->Get_cropTotals_size(); i++) {
1529 m_FarmManager->Set_cropTotals( i, 0 );
1533 m_FarmManager->Save_last_years_crops_for_farms();
1534 m_FarmManager->ChooseDecisionMode_for_farms();
1542 int no_crops = m_FarmManager->pm_data->Get_cropTypes_almass_size();
1543 for (
int c = 0; c < no_crops; c++) {
1544 double old_price = m_FarmManager->pm_data->Get_sellingPrice(
tov_Undefined*f + m_FarmManager->pm_data->Get_cropTypes_almass( c ) );
1545 m_FarmManager->pm_data->Set_sellingPrice_lastyr( old_price,
tov_Undefined*f + m_FarmManager->pm_data->Get_cropTypes_almass( c ) );
1555 ofstream ofileEM(
"Maize_energy_price_yearly.txt", ios::app );
1557 ofileEM << year <<
'\t';
1558 ofileEM << m_FarmManager->pm_data->Get_sellingPrice(
tov_Maize );
1594 m_PesticideMap->DumpPMapI();
1595 m_PesticideMap->DumpPMapH();
1596 m_PesticideMap->DumpPMapF();
1600 m_FarmManager->FarmManagement();
1608 m_RodenticideManager->Tick();
1609 m_RodenticidePreds->Tick();
1626 cout <<
"Setting max min polygon extents" << endl;
1627 int mwidth = m_land->MapWidth();
1628 int mheight = m_land->MapHeight();
1629 for (
int x = 0; x < mwidth; x++ ) {
1630 for (
int y = 0; y < mheight; y++ ) {
1631 int polyindex = m_land->Get( x, y );
1633 unsigned int ele_ref= polyindex;
1645 FILE * vfile=fopen(
"VegDump.txt",
"a" );
1647 g_msg->
Warn(
WARN_FILE,
"Landscape::VegDump(): Unable to open file",
"VegDump.txt" );
1652 int day = SupplyDayInYear();
1653 double hei = SupplyVegHeight( x, y );
1654 double bio = SupplyVegBiomass( x, y );
1655 double cover = SupplyVegCover( x, y );
1656 double density = bio / ( hei + 1 );
1657 double weeds = SupplyWeedBiomass( x, y );
1658 double insects = SupplyInsects( x, y );
1659 double LATotal = SupplyLATotal(x, y);
1660 double LAGreen = SupplyLAGreen(x, y);
1661 double digest = SupplyVegDigestability(x, y);
1662 double GreenBiomass = SupplyGreenBiomass(x,y);
1663 double DeadBiomass = SupplyDeadBiomass(x,y);
1664 int grazed = SupplyGrazingPressure(x, y);
1665 double ggraze = GetActualGooseGrazingForage(m_land->Get(x, y), gs_Pinkfoot);
1666 int VegType = BackTranslateVegTypes(SupplyVegType(x, y));
1667 double grain = SupplyBirdSeedForage(x, y);
1669 fprintf( vfile,
"%d\t%d\t%g\t%g\t%d\t%g\t%g\t%g\t%i\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n", year, day, hei, bio, grazed, density, cover, weeds, VegType, insects, LATotal, LAGreen, digest, GreenBiomass, DeadBiomass, ggraze, grain );
1689 ofstream ofile (
"Daydegrees.txt", ios::app);
1691 ofile << m_FarmManager->GetDD();
1698 FILE * vfile=fopen(
"EventDump.txt",
"a" );
1700 g_msg->
Warn(
WARN_FILE,
"Landscape::EventDump(): Unable to open file",
"EventDump.txt" );
1705 int day = SupplyDayInYear();
1706 fprintf( vfile,
"%d: ", day );
1708 fprintf( vfile,
"%d ", event );
1711 fprintf( vfile,
" - " );
1713 fprintf( vfile,
"%d ", event );
1715 fprintf( vfile,
"\n" );
1721 FILE * vfile=fopen(
"EventDump.txt",
"a" );
1723 g_msg->
Warn(
WARN_FILE,
"Landscape::EventDump(): Unable to open file",
"EventDump.txt" );
1728 int day = this->SupplyGlobalDate();
1740 if (herb+fung+ins >0 ) fprintf( vfile,
"%d\t%d\t%d\t%d\n", day, herb, fung, ins );
1748 for (
unsigned int i = 0; i < m_elems.size(); i++ ) {
1749 m_elems[ i ]->SetMapValid(
false );
1752 sprintf( l_err,
"%d", m_elems[ i ]->GetPoly() );
1758 SetPolyMaxMinExtents();
1759 if ( a_exit_on_invalid ) {
1760 for (
unsigned int i = 0; i < m_elems.size(); i++ ) {
1761 if ( !m_elems[ i ]->GetMapValid() ) {
1763 sprintf( l_err,
"%d", m_elems[ i ]->GetPoly() );
1777 bool didsomething =
false;
1778 vector < LE * > l_temp;
1779 cout <<
"Tidying up the polygon map in PolysRemoveInvalid" << endl;
1780 unsigned int sz= (int) m_elems.size();
1781 for (
unsigned int i = 0; i < sz; i++ ) {
1782 if ( m_elems[ i ]->GetMapValid() ) {
1783 unsigned int j = (int) l_temp.size();
1784 l_temp.resize( j + 1 );
1785 l_temp[ j ] = m_elems[ i ];
1789 delete m_elems[ i ];
1790 didsomething =
true;
1794 for (
unsigned int i = 0; i < l_temp.size(); i++ ) {
1795 m_elems[ i ] = l_temp[ i ];
1797 m_elems.resize( l_temp.size() );
1798 RebuildPolyMapping();
1799 return didsomething;
1805 ofstream outf(a_filename, ios::out);
1806 int l_num_polys = 0;
1808 if (!outf.is_open()) {
1814 unsigned sz = (unsigned)m_elems.size();
1815 for (
unsigned int i = 0; i < sz; i++) {
1816 if (m_elems[i]->GetMapValid())
1820 outf << l_num_polys << endl;
1821 outf <<
"PolyType" <<
'\t' <<
"PolyRefNum" <<
'\t' <<
"Area" <<
'\t' <<
"FarmRef" <<
'\t' <<
"UnSprayedMarginRef" <<
'\t' <<
"SoilType" <<
'\t' <<
"Openness" <<
'\t' <<
"CentroidX" <<
'\t' <<
"CentroidY" << endl;
1830 for (
unsigned int i = 0; i < m_elems.size(); i++)
1832 if (m_elems[i]->GetMapValid())
1834 outf << m_elems[i]->GetALMaSSEleType() <<
'\t' << m_elems[i]->GetPoly() <<
'\t' << m_elems[i]->GetArea() <<
'\t' <<
1835 m_elems[i]->GetOwnerFile() <<
'\t' << m_elems[i]->GetUnsprayedMarginPolyRef() <<
'\t' << m_elems[i]->GetSoilType() <<
'\t' << m_elems[i]->GetOpenness()
1836 <<
'\t' << m_elems[i]->GetCentroidX() <<
'\t' << m_elems[i]->GetCentroidY() << endl;
1901 bool farmsrenum = m_FarmManager->GetIsRenumbered();
1904 string rubbish =
"";
1905 ifstream ifile(a_polyfile);
1906 if (!ifile.is_open()) {
1912 ifile >> NoPolygons;
1913 m_elems.resize(NoPolygons);
1915 for (
int i = 0; i < 9; i++){ ifile >> rubbish; }
1919 int np = NoPolygons;
1920 if (NoPolygons < 10000) np = 10000;
1924 for (
int i = 0; i < np * 2; i++) {
1930 for (
int x = 0; x < NoPolygons; x++)
1932 int PolyNum, Owner, PolyType, RealPolyType, URef, SoilType, openness, Centroid_x, Centroid_y;
1935 ifile >> PolyType >> PolyNum >> Area >> Owner >> URef >> SoilType >> openness >> Centroid_x >> Centroid_y;
1937 if ((SoilType > 16) || (PolyNum<0))
1939 std::sprintf(error_num,
"%d", NoPolygons);
1941 "reading number of specified polygons (old polygon file format?):", error_num);
1947 if ((-1 != Owner) && !farmsrenum)
1950 Owner = m_FarmManager->GetRenumberedFarmRef(Owner);
1953 RealPolyType = PolyType;
1955 if (PolyType == 150)
1963 m_DoMissingPolygonsManipulations =
true;
1970 LE * newland = NewElement(Type);
1971 m_elems[ElemIndex++] = newland;
1974 newland->
SetArea(floor(0.5 + Area));
1975 newland->SetALMaSSEleType(RealPolyType);
1978 newland->SetCentroid(Centroid_x,Centroid_y);
1981 if (PolyNum>m_LargestPolyNumUsed) m_LargestPolyNumUsed = PolyNum;
1983 if ((Centroid_x < 0) || (Centroid_y < 0)) m_NeedCentroidCalculation=
true;
1984 if (openness < 0) m_NeedOpennessCalculation =
true;
1990 sprintf(error_num,
"%d", PolyNum);
1991 g_msg->
Warn(
WARN_FILE,
"Landscape::ReadPolys(): Farm polygon does not belong to a farm:", error_num);
1996 sprintf(error_num,
"%d", PolyNum);
1997 g_msg->
Warn(
WARN_FILE,
"Landscape::ReadPolys(): Farm polygon does not have element type tole_Field:", error_num);
2003 m_FarmManager->ConnectFarm(Owner);
2004 m_FarmManager->AddField(Owner, newland, Owner);
2029 sprintf(error_num,
"%d", PolyNum);
2030 g_msg->
Warn(
WARN_FILE,
"Landscape::ReadPolys(): Duplicate polygon in file", error_num);
2036 hb_first_free_poly_num = m_elems[NoPolygons - 1]->GetPoly() + 1;
2041 int mapwidth = m_land->MapWidth();
2042 int mapheight = m_land->MapHeight();
2043 for (
unsigned int i = 0; i < m_elems.size(); i++ ) {
2044 m_elems[i]->SetArea(0);
2045 m_elems[ i ]->m_squares_in_map=0;
2048 for (
int x = 0; x < mapwidth; x++ ) {
2049 for (
int y = 0; y < mapheight; y++ ) {
2050 int l_ele = m_land->Get( x, y );
2051 m_elems[ l_ele ]->m_squares_in_map++;
2059 cout <<
"In Landscape::Landscape() Polygon renumber." << endl;
2060 for (
unsigned int i = 0; i < m_elems.size(); i++)
2063 int index = m_elems[i]->GetMapIndex();
2064 m_elems[i]->SetPoly(index);
2067 m_LargestPolyNumUsed = (int) m_elems.size()-1;
2068 g_msg->
Warn(
WARN_FILE,
"Landscape::Landscape() ""Map to be dumped due to polygon renumber",
"");
2075 for (
unsigned int i = 0; i < m_elems.size(); i++ ) {
2076 m_elems[ i ]->SetArea( (
double )m_elems[ i ]->m_squares_in_map );
2077 if ( m_elems[ i ]->m_squares_in_map > 0 ) {
2078 m_elems[ i ]->SetMapValid(
true );
2079 l_area_sum += m_elems[ i ]->m_squares_in_map;
2083 if ( l_area_sum != m_width * m_height ) {
2084 g_msg->
Warn(
WARN_BUG,
"Landscape::ForceArea(): Polygon areas doesn't"" sum up to map area!",
"" );
2093 int mapwidth = m_land->MapWidth();
2094 int mapheight = m_land->MapHeight();
2098 found =
false; counter++;
2099 for (
int x = 1; x < mapwidth-1; x++)
2101 for (
int y = 1; y < mapheight-1; y++)
2103 int apoly = m_land->Get(x,y);
2106 m_land->MissingCellReplace(x, y,
true);
2111 }
while (counter<50);
2113 for (
int x = 0; x < mapwidth; x++)
2115 for (
int y = 0; y < mapheight; y++)
2117 int apoly = m_land->Get(x, y);
2122 m_land->MissingCellReplaceWrap(x, y,
true);
2136 cout <<
"In Change Map Mapping" << endl;
2137 int mapwidth = m_land->MapWidth();
2138 int mapheight = m_land->MapHeight();
2142 for (
int x = 0; x < mapwidth; x++ )
2144 for (
int y = 0; y < mapheight; y++ )
2146 int polynum = m_land->Get( x, y );
2154 if ( index != oldindex )
2156 m_elems[ index ]->SetValidXY( x, y );
2159 int pref = l_y * pest_map_width + l_x;
2160 m_elems[ index ]->SetPesticideCell( pref );
2165 RebuildPolyMapping();
2205 for (
int i = 0; i < m_elems.size(); i++)
2208 int area = int(m_elems[i]->GetArea());
2234 APoint pt = m_elems[i]->GetCentroid();
2236 int poly = m_elems[i]->GetPoly();
2239 g_msg->
Warn(
WARN_FILE,
"Landscape::RemoveSmallPolygons: Centroid not in polygon: ", i);
2243 if (m_land->CellReplacementNeighbour(pt.m_x, pt.m_y, poly) == 1) {
2245 m_elems[i]->SetMapValid(
false);
2256 grass->
DoCopy(m_elems[i]);
2261 m_elems[i] = dynamic_cast<LE*>(grass);
2265 PolysRemoveInvalid();
2273 for (
int x=1; x<(m_width-1); x++)
2274 for (
int y=1; y<(m_height-1); y++)
2279 if ( SupplyElementType(x-1,y-1) ==
tole_Field)
2282 int fieldindex = SupplyPolyRefIndex(x-1,y-1);
2283 m_land->Put( x, y, fieldindex );
2290 int fieldindex = SupplyPolyRefIndex(x-1,y);
2291 m_land->Put( x, y, fieldindex );
2295 if ( SupplyElementType(x-1,y+1) ==
tole_Field)
2298 int fieldindex = SupplyPolyRefIndex(x-1,y+1);
2299 m_land->Put( x, y, fieldindex );
2306 int fieldindex = SupplyPolyRefIndex(x,y-1);
2307 m_land->Put( x, y, fieldindex );
2314 int fieldindex = SupplyPolyRefIndex(x,y+1);
2315 m_land->Put( x, y, fieldindex );
2319 if ( SupplyElementType(x+1,y-1) ==
tole_Field)
2322 int fieldindex = SupplyPolyRefIndex(x+1,y-1);
2323 m_land->Put( x, y, fieldindex );
2330 int fieldindex = SupplyPolyRefIndex(x+1,y);
2331 m_land->Put( x, y, fieldindex );
2335 if ( SupplyElementType(x+1,y+1) ==
tole_Field)
2338 int fieldindex = SupplyPolyRefIndex(x+1,y+1);
2339 m_land->Put( x, y, fieldindex );
2350 if ( ( x == -1 ) || ( y == -1 ) ) {
2351 g_msg->
Warn(
WARN_BUG,
"Landscape::BorderAdd(): Uninitialized border coordinate!",
"" );
2354 LE * border = NewElement(a_type);
2356 m_polymapping[ hb_first_free_poly_num ] = (int) m_elems.size();
2357 m_elems.resize( m_elems.size() + 1 );
2358 m_elems[ m_elems.size() - 1 ] = border;
2359 border->
SetPoly( hb_first_free_poly_num++ );
2371 int fieldpoly = a_field->
GetPoly();
2372 int borderpoly = border->
GetPoly();
2375 int test = m_land->Get(a_field->GetCentroidX(), a_field->GetCentroidY());
2376 if (test != fieldindex)
2378 g_msg->
Warn(
"Landscape::BorderScan - Border Scan centroid does not return correct polygon index. Index :", fieldindex);
2382 int notforever = 50000;
2383 vector<APoint> listoflocs;
2388 for (
int wid = 0; wid < a_width; wid++)
2392 APoint coord(a_field->GetCentroidX(), a_field->GetCentroidY());
2394 AxisLoop(fieldindex, &coord, random(8));
2395 while (--notforever > 0)
2398 if (BorderTest(fieldindex, -99, coord.m_x, coord.m_y))
2401 m_land->Put(coord.m_x, coord.m_y, -99);
2402 listoflocs.push_back(coord);
2407 sprintf(polynum,
"%d", a_field->
GetPoly());
2408 g_msg->
Warn(
WARN_FILE,
"Landscape::BorderScan(): Polygon reached zero area " "when adding border. Poly num: ", polynum);
2415 if (!BorderStep(fieldindex, -99, &coord))
2420 for (std::vector<APoint>::iterator it = listoflocs.begin(); it != listoflocs.end(); ++it)
2422 m_land->Put((*it).m_x, (*it).m_y, borderindex);
2432 int x_add[ 8 ] = { 1*a_step, 1*a_step, 0, -1*a_step, -1*a_step, -1*a_step, 0, 1*a_step };
2433 int y_add[ 8 ] = { 0, -1*a_step, -1*a_step, -1*a_step, 0, 1*a_step, 1*a_step, 1*a_step };
2434 int width = m_land->MapWidth();
2435 int height = m_land->MapHeight();
2437 for (
unsigned int i = 0; i < 8; i++ ) {
2438 if ( ( a_x + x_add[ i ] < width ) && ( a_x + x_add[ i ] >= 0 ) && ( a_y + y_add[ i ] < height ) && ( a_y + y_add[ i ] >= 0 ) )
2440 index = m_land->Get( a_x + x_add[ i ], a_y + y_add[ i ] );
2441 if ( index == a_polyindex )
2443 m_elems[a_polyindex]->SetValidXY(a_x + x_add[ i ], a_y + y_add[ i ]);
2455 int x_add[ 8 ] = { 1, 1, 0, -1, -1, -1, 0, 1 };
2456 int y_add[ 8 ] = { 0, -1, -1, -1, 0, 1, 1, 1 };
2457 int width = m_land->MapWidth();
2458 int height = m_land->MapHeight();
2460 for (
unsigned int i = 0; i < 8; i++ ) {
2461 if ( ( a_x + x_add[ i ] >= width ) || ( a_x + x_add[ i ] < 0 ) || ( a_y + y_add[ i ] >= height )
2462 || ( a_y + y_add[ i ] < 0 ) ) {
2466 index = m_land->Get( a_x + x_add[ i ], a_y + y_add[ i ] );
2467 if ( ( index != a_fieldindex ) && ( index != a_borderindex ) )
2481 int x_add[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
2482 int y_add[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
2483 int width = m_land->MapWidth();
2484 int height = m_land->MapHeight();
2485 int i = 7, counter = 8;
2486 bool running =
true;
2490 if (!((*a_x) + x_add[i] >= width) && !((*a_x) + x_add[i] < 0) && !((*a_y) + y_add[i] >= height) && !((*a_y) + y_add[i] < 0))
2492 index = m_land->Get((*a_x) + x_add[i], (*a_y) + y_add[i]);
2493 if (index == a_fieldindex)
2511 if (!((*a_x) + x_add[i] >= width) && !((*a_x) + x_add[i] < 0) && !((*a_y) + y_add[i] >= height) && !((*a_y) + y_add[i] < 0))
2513 index = m_land->Get((*a_x) + x_add[i], (*a_y) + y_add[i]);
2514 if (index == a_fieldindex)
2525 if (!((*a_x) + x_add[i] + 1 > width) && !((*a_x) + x_add[i] < 0) && !((*a_y) + y_add[i] + 1 > height) &&
2526 !((*a_y) + y_add[i] < 0) && (m_land->Get((*a_x) + x_add[i], (*a_y) + y_add[i]) == a_fieldindex))
2539 int x_add[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
2540 int y_add[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
2541 int width = m_land->MapWidth();
2542 int height = m_land->MapHeight();
2543 int i = 7, counter = 8;
2544 bool running =
true;
2548 if (!((a_coord->m_x) + x_add[i] >= width) && !((a_coord->m_x) + x_add[i] < 0) && !((a_coord->m_y) + y_add[i] >= height) && !((a_coord->m_y) + y_add[i] < 0))
2550 index = m_land->Get((a_coord->m_x) + x_add[i], (a_coord->m_y) + y_add[i]);
2551 if (index == a_fieldindex)
2569 if (!((a_coord->m_x) + x_add[i] >= width) && !((a_coord->m_x) + x_add[i] < 0) && !((a_coord->m_y) + y_add[i] >= height) && !((a_coord->m_y) + y_add[i] < 0))
2571 index = m_land->Get((a_coord->m_x) + x_add[i], (a_coord->m_y) + y_add[i]);
2572 if (index == a_fieldindex)
2583 if (!((a_coord->m_x) + x_add[i] + 1 > width) && !((a_coord->m_x) + x_add[i] < 0) && !((a_coord->m_y) + y_add[i] + 1 > height) &&
2584 !((a_coord->m_y) + y_add[i] < 0) && (m_land->Get((a_coord->m_x) + x_add[i], (a_coord->m_y) + y_add[i]) == a_fieldindex))
2586 (a_coord->m_x) += x_add[i];
2587 (a_coord->m_y) += y_add[i];
2597 for (
unsigned int i = 0; i < m_elems.size(); i++)
2599 if (m_elems[i]->GetElementType() ==
tole_Pond) {
2600 m_PondIndexList.push_back(i);
2601 m_PondRefsList.push_back(m_elems[i]->GetPoly());
2607 return m_PondIndexList[int(
g_rand_uni()*m_PondIndexList.size())];
2611 if (m_PondIndexList.size()>0)
return m_PondRefsList[
int(
g_rand_uni()*m_PondIndexList.size())];
2620 if ( ( x == -1 ) || ( y == -1 ) ) {
2622 g_msg->
Warn(
WARN_BUG,
"Landscape::UnsprayedMarginAdd(): Uninitialized border coordinate!",
"" );
2626 m_polymapping[ hb_first_free_poly_num ] = (int) m_elems.size();
2627 m_elems.resize( m_elems.size() + 1 );
2628 m_elems[ m_elems.size() - 1 ] = umargin;
2630 umargin->
SetPoly( hb_first_free_poly_num++ );
2634 UnsprayedMarginScan( a_field, q + 1 );
2640 int fieldpoly = a_field->
GetPoly();
2641 int borderpoly = umargin->
GetPoly();
2644 int notforever = 5000;
2652 if ( !FindValidXY( fieldindex, x, y ) )
return;
2654 while ( --notforever ) {
2656 if ( UMarginTest( fieldindex, borderindex, x, y, a_width ) ) {
2658 m_land->Put( x, y, borderindex );
2663 if ( !BorderStep( fieldindex, borderindex, & x, & y ) )
2671 int x_add[ 8 ] = { 1*a_width, 1*a_width, 0, -1*a_width, -1*a_width, -1*a_width, 0, 1*a_width };
2672 int y_add[ 8 ] = { 0, -1*a_width, -1*a_width, -1*a_width, 0, 1*a_width, 1*a_width, 1*a_width };
2673 int width = m_land->MapWidth();
2674 int height = m_land->MapHeight();
2676 for (
unsigned int i = 0; i < 8; i++ ) {
2677 if ( ( a_x + x_add[ i ] >= width ) || ( a_x + x_add[ i ] < 0 ) || ( a_y + y_add[ i ] >= height )
2678 || ( a_y + y_add[ i ] < 0 ) ) {
2682 index = m_land->Get( a_x + x_add[ i ], a_y + y_add[ i ] );
2683 if ( ( index != a_fieldindex ) && ( index != a_marginindex ) )
return true;
2691 int x_add[ 8 ] = { 1, 1, 0, -1, -1, -1, 0, 1 };
2692 int y_add[ 8 ] = { 0, -1, -1, -1, 0, 1, 1, 1 };
2695 int width = m_land->MapWidth();
2696 int height = m_land->MapHeight();
2698 for (
int i = 0; i < 100; i++ ) {
2699 for (
int l = 0; l < 8; l++ ) {
2700 nx = a_x + x_add[ l ] * i;
2701 ny = a_y + y_add[ l ] * i;
2702 if ( ( nx < width ) && ( nx >= 0 ) && ( ny < height ) && ( ny >= 0 ) ) {
2703 index = m_land->Get( nx, ny );
2704 if ( index == a_field ) {
2705 a_x = a_x + x_add[ l ] * i;
2706 a_y = a_y + y_add[ l ] * i;
2737 unsigned sz=(unsigned) m_elems.size();
2738 for (
unsigned i=0; i<sz; i++)
2740 if (m_elems[ i ]->GetElementType() ==
tole_Field)
2743 int cx = m_elems[ i ]->GetCentroidX();
2744 int cy = m_elems[ i ]->GetCentroidY();
2747 if ((cx >= tx1) && (cy >= ty1) && (cx <= tx2) && (cy <= ty2))
2752 else if ((cx < tx1) || (cy < ty1) || (cx > tx2) || (cy > ty2))
2760 if (BeetleBankPossible( m_elems[ i ], a_tole) ) BBs++;
2766 sprintf(str,
"%d",BBs);
2767 g_msg->
Warn(
WARN_MSG,
"Landscape::AddBeetleBanks(): BeetleBanks successfully added:", str );
2779 int farea=(int)a_field->
GetArea();
2780 if (farea<10000)
return false;
2781 int cx=a_field->GetCentroidX();
2782 int cy=a_field->GetCentroidY();
2785 if (!FindFieldCenter(a_field, &cx, &cy))
return false;
2788 int alignment=FindLongestAxis(&cx, &cy, &length);
2790 length=int(length*0.8);
2794 BeetleBankAdd(cx, cy, alignment, length , a_field, a_tole);
2803 int ourpoly=SupplyPolyRef(*(x),*(y));
2804 if (ourpoly!=a_field->
GetPoly())
return false;
2813 while ((diff>1) & (tries++<100)) {
2814 for (
unsigned v=0; v<4; v++) {
2817 AxisLoop(ourpoly, &x1, &y1, v);
2818 centers[0][v]=x1-m_x_add[v];
2819 centers[1][v]=y1-m_y_add[v];
2822 AxisLoop(ourpoly, &x1, &y1, v+4);
2823 centers[0][v+4]=x1-m_x_add[v+4];
2824 centers[1][v+4]=y1-m_y_add[v+4];
2832 for (
int h=0; h<8; h++) {
2833 centreX+=centers[0][h];
2834 centreY+=centers[1][h];
2838 diff=abs(oldx-centreX)+abs(oldy-centreY);
2842 int tourpoly=SupplyPolyRef(*(x),*(y));
2843 if (tourpoly!=ourpoly) {
2853 int ourpoly=SupplyPolyRef(*(a_x),*(a_y));
2863 for (
unsigned v=0; v<8; v++)
2867 AxisLoop(ourpoly, &x1, &y1, v);
2870 dx[v] = abs(*(a_x)-x1);
2871 dy[v] = abs(*(a_y)-y1);
2877 for (
int di = 0; di < 4; di++)
2879 int ddx = distx[di] + distx[di + 4];
2880 int ddy = disty[di] + disty[di + 4];
2881 if (ddx == 0) dist[di] = ddy;
else dist[di] = ddx;
2882 if (dist[di] > *(a_length))
2885 *(a_length) = dist[di];
2888 if (found == -1)
return 0;
2890 int l = (*(a_length) / 2);
2891 if (fx[found] > fx[found + 4]) *(a_x) = fx[found + 4] + m_x_add[found] * l;
else *(a_x) = fx[found + 4] - m_x_add[found + 4] * l;
2892 if (fy[found] > fy[found + 4]) *(a_y) = fy[found + 4] + m_y_add[found] * l;
else *(a_y) = fy[found + 4] - m_y_add[found + 4] * l;
2903 int ap1 = a_polyindex;
2904 while (ap1 == a_polyindex)
2906 a_cor->m_x += m_x_add[a_axis];
2907 a_cor->m_y += m_y_add[a_axis];
2908 if (a_cor->m_x >= m_width - 1) { a_cor->m_x = m_width - 1;
return; }
2909 if (a_cor->m_y >= m_height - 1) { a_cor->m_y = m_height - 1;
return; }
2910 if (a_cor->m_x <= 0) { a_cor->m_x = 0;
return; }
2911 if (a_cor->m_y <= 0) { a_cor->m_y = 0;
return; }
2912 ap1 = m_land->Get(a_cor->m_x, a_cor->m_y);
2922 int ap1 = a_polyindex;
2924 while (ap1 == a_polyindex && count<a_limit)
2926 a_cor->m_x += m_x_add[a_axis];
2927 a_cor->m_y += m_y_add[a_axis];
2928 if (a_cor->m_x >= m_width - 1) { a_cor->m_x = m_width - 1;
return; }
2929 if (a_cor->m_y >= m_height - 1) { a_cor->m_y = m_height - 1;
return; }
2930 if (a_cor->m_x <= 0) { a_cor->m_x = 0;
return; }
2931 if (a_cor->m_y <= 0) { a_cor->m_y = 0;
return; }
2932 ap1 = m_land->Get(a_cor->m_x, a_cor->m_y);
2943 int ap1 = a_polyindex;
2944 while (ap1 == a_polyindex)
2946 *(a_x) += m_x_add[a_axis];
2947 *(a_y) += m_y_add[a_axis];
2957 if (*(a_x) >= m_width)
2961 if (*(a_y) >= m_height)
2966 ap1 = m_land->Get((*a_x), (*a_y));
2973 ++m_LargestPolyNumUsed;
2992 m_polymapping[ m_LargestPolyNumUsed ] = (int) m_elems.size();
2993 m_elems.resize( m_elems.size() + 1 );
3000 if (a_angle==0) angle2=2;
3001 int start=(int)(a_length*0.1);
3002 for (
int i=
start; i<a_length; i++) {
3003 for (
int w=0-width; w<width; w++) {
3004 int tx=w*m_x_add[angle2];
3005 int ty=w*m_y_add[angle2];
3006 m_land->Put( tx+a_x+i*m_x_add[a_angle], ty+a_y+i*m_y_add[a_angle], (
int) m_elems.size() - 1 );
3007 m_land->Put( tx+a_x-i*m_x_add[a_angle], ty+a_y-i*m_y_add[a_angle], (
int) m_elems.size() - 1 );
3026 for (
unsigned i=0; i<m_elems.size(); i++) {
3027 a_skt->PreCachePoly(m_elems[i]->GetPoly());
3034 for (
unsigned i=0; i<m_elems.size(); i++) {
3035 a_rppm->PreCachePoly(m_elems[i]->GetPoly());
3047 cout <<
"In Centroid Calculations" << endl;
3049 for (
int p = 0; p< (int)m_elems.size(); p++)
3052 int x1 = m_elems[p]->GetMinX();
3053 int y1 = m_elems[p]->GetMinY();
3054 int x2 = m_elems[p]->GetMaxX();
3055 int y2 = m_elems[p]->GetMaxY();
3057 int midx = (x1 + x2) / 2;
3058 int midy = (y1 + y2) / 2;
3061 CentroidSpiralOut(polyindex, midx, midy);
3066 FindLongestAxis(&midx, &midy, &l);
3067 m_elems[p]->SetCentroid(midx, midy);
3069 BuildingDesignationCalc();
3075 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
return;
3082 for (
int i = 0 - loop; i <= loop; i++)
3085 CorrectCoords(a_x, a_y);
3086 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3090 for (
int i = 0 - loop; i <= loop; i++)
3093 CorrectCoords(a_x, a_y);
3094 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3098 for (
int j = 0 - (loop - 1); j< loop; j++)
3101 CorrectCoords(a_x, a_y);
3102 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3106 for (
int j = 0 - (loop - 1); j< loop; j++)
3109 CorrectCoords(a_x, a_y);
3110 if (SupplyPolyRefIndex(a_x, a_y) == a_polyref)
3114 }
while (loop<m_minmaxextent);
3115 g_msg->
Warn(
"Landscape::CentroidSpiralOut: Failure of centroid main loop. Looking for polygon index ",a_polyref);
3116 a_x = m_elems[a_polyref]->GetMinX();
3117 a_y = m_elems[a_polyref]->GetMinY();
3277 ofstream centroidfile(
"PolygonCentroids.txt", ios::out);
3278 centroidfile<<
"Polyref"<<
'\t'<<
"CX"<<
'\t'<<
"CY"<<
'\t'<<
"Type"<<
'\t'<<
"Area"<<
'\t'<<
"Country Designation"<<endl;
3279 for (
int p = 0; p< (int)m_elems.size(); p++)
3281 centroidfile<<m_elems[p]->GetPoly()<<
'\t'<<m_elems[p]->GetCentroidX()<<
'\t'<<m_elems[p]->GetCentroidY()<<
'\t'<<m_elems[p]->GetElementType()<<
'\t'<<m_elems[p]->GetArea()<<
'\t'<<m_elems[p]->GetCountryDesignation()<<endl;
3283 centroidfile.close();
3293 cout <<
"In BuildingDesignationCalc" << endl;
3294 for (
int p = 0; p< (int)m_elems.size(); p++)
3299 int cx = m_elems[p]->GetCentroidX();
3300 int cy = m_elems[p]->GetCentroidY();
3302 for (
int j = 0; j< (int)m_elems.size(); j++)
3306 int nx = m_elems[j]->GetCentroidX();
3307 int ny = m_elems[j]->GetCentroidY();
3315 else m_elems[p]->SetCountryDesignation(0);
3319 m_elems[p]->SetCountryDesignation(2);
3335 int day = SupplyDayInYear();
3336 m_elems[
m_polymapping[a_polyref]]->SetGooseNos(a_number, day);
3347 int day = SupplyDayInYear();
3348 m_elems[
m_polymapping[a_polyref]]->SetGooseNosTimed(a_number, day);
3359 int day = SupplyDayInYear();
3360 m_elems[
m_polymapping[a_polyref]]->SetGooseSpNos(a_number, day, a_goose);
3369 int day = SupplyDayInYear();
3370 m_elems[
m_polymapping[a_polyref]]->SetGooseSpNosTimed(a_number, day, a_goose);
3377 m_elems[
m_polymapping[a_polyref]]->SetGooseRoostDist(a_dist, a_goose);
3399 return m_elems[m_land->Get(a_x, a_y)]->GetGooseNos();
3464 digest = SupplyVegDigestability(a_polygon);
3466 #ifdef __Perfectfood
3469 #ifdef __YEARLYVARIABLEFOODQUALITY
3470 digest *= m_OurPopulationManager->m_GoodYearBadYear;
3473 double access = 1.0;
3475 double grazedreduction[4] = { 1.0, 0.8, 0.2, 0.05 };
3476 veg_height = SupplyVegHeight(a_polygon);
3477 double weeds = SupplyWeedBiomass(a_polygon);
3478 if ((veg_height <= 0) && (weeds < 0.1))
return 0.25;
3480 bool veg_patchy =
true;
3481 #else // If it is not the special case of the 1950s
3483 bool veg_patchy = SupplyVegPatchy(a_polygon);
3492 if (access<0) access = 0;
3500 if (access<0) access = 0;
3503 return access * digest * grazedreduction[SupplyGrazingPressure(a_polygon)];
3516 OFILE = fopen( outpfile.c_str(),
"w" );
3519 "Unable to open file for writing:",
3524 fprintf(OFILE,
"ncols %d\n", m_width);
3525 fprintf(OFILE,
"nrows %d\n", m_height);
3526 fprintf(OFILE,
"xllcorner %d\n", UTMX );
3527 fprintf(OFILE,
"yllcorner %d\n", UTMY );
3528 fprintf(OFILE,
"cellsize %d\n", 1 );
3529 fprintf(OFILE,
"NODATA_value %d\n", -9999 );
3532 for (
int y = 0; y < m_height; y++) {
3533 for (
int x = 0; x < m_width; x++) {
3534 fprintf(OFILE,
"%d\t", SupplyPolyRef(x, y));
3536 fprintf(OFILE,
"%c", c );
3541 for (
int y = 0; y < m_height; y++) {
3542 for (
int x = 0; x < m_width; x++) {
3543 fprintf(OFILE,
"%d\t", SupplyElementType( x, y ));
3545 fprintf( OFILE,
"%c", c );
3552 le_signal_index = 0;
3556 if ((
unsigned int)le_signal_index == m_elems.size()) {
3559 return m_elems[le_signal_index++]->GetPoly();
3563 return (
int)m_elems.size();
3578 sprintf(errornum,
"%d", a_treat);
3579 g_msg->
Warn(
WARN_BUG,
"Landscape::IncTreatCounter(): Index"" out of range!", errornum);
3582 m_treatment_counts[a_treat] ++;
3587 FILE * l_file = fopen(a_filename,
"w");
3589 g_msg->
Warn(
WARN_FILE,
"Landscape::DumpTreatCounters(): ""Unable to open file for writing: %s\n", a_filename);
3594 fprintf(l_file,
"%3d %s %10d\n", i, EventtypeToString(i).c_str(), m_treatment_counts[i]);
3600 unsigned int linesize = m_maxextent * 3;
3601 unsigned char * frame_buffer = (
unsigned char *)malloc(
sizeof(
unsigned char)* linesize);
3603 if (frame_buffer == NULL) {
3608 FILE * l_file = fopen(a_filename,
"w");
3610 g_msg->
Warn(
WARN_FILE,
"Landscape::DumpMapGraphics(): ""Unable to open file for writing: %s\n", a_filename);
3614 fprintf(l_file,
"P6\n%d %d %d\n", m_width, m_height, 255);
3616 for (
int y = 0; y < m_height; y++) {
3618 for (
int x = 0; x < m_width; x++) {
3619 int eletype = (int)SupplyElementType(x, y);
3620 int localcolor = 16777215 / eletype;
3624 double hei = SupplyVegHeight(x, y);
3625 if (hei > 50.0) category = 0;
else category = (int)(200.0 - (hei * 4.0));
3626 localcolor = ((category * 65536) + 65535);
3629 frame_buffer[i++] = (
unsigned char)(localcolor & 0xff);
3630 frame_buffer[i++] = (
unsigned char)((localcolor >> 8) & 0xff);
3631 frame_buffer[i++] = (
unsigned char)((localcolor >> 16) & 0xff);
3633 fwrite(frame_buffer,
sizeof(
unsigned char), linesize, l_file);
3643 l_vegtype_areas[i] = 0.0;
3647 for (
unsigned int i = 0; i < m_elems.size(); i++) {
3648 l_vegtype_areas[m_elems[i]->GetVegType()] += m_elems[i]->GetArea();
3656 outf = fopen(a_filename,
"a");
3658 g_msg->
Warn(
WARN_FILE,
"Landscape::DumpMapInfoByArea(): ""Unable to open file for appending", a_filename);
3663 outf = fopen(a_filename,
"w");
3665 g_msg->
Warn(
WARN_FILE,
"Landscape::DumpMapInfoByArea(): ""Unable to open file for writing", a_filename);
3674 if (!a_dump_zero_areas && l_vegtype_areas[i] < 0.5)
3678 if (a_write_veg_names)
3680 fprintf(outf,
"\n");
3690 static char error_num[20];
3907 sprintf(error_num,
"%d", a_type);
3908 g_msg->
Warn(
WARN_FILE,
"Landscape::NewElement(): Unknown landscape element requested:", error_num);
3913 elem->SetElementType(a_type);
3925 return " sleep_all_day";
3927 return " autumn_plough";
3929 return " stubble_plough";
3931 return " stubble_cultivator_heavy";
3933 return " heavy_cultivator_aggregate";
3935 return " autumn_harrow";
3937 return " preseeding_cultivator";
3939 return " preseeding_cultivator_sow";
3941 return " autumn_roll";
3943 return " autumn_sow";
3945 return " winter_plough";
3947 return " deep_ploughing";
3949 return " spring_plough";
3951 return " spring_harrow";
3953 return " spring_roll";
3955 return " spring_sow";
3957 return " spring_sow_with_ferti";
3965 return " fp_liquidNH3";
3967 return " fp_slurry";
3969 return " fp_ammoniumsulphate";
3971 return " fp_manganesesulphate";
3973 return " fp_manure";
3975 return " fp_greenmanure";
3977 return " fp_sludge";
3981 return " fp_calcium";
3987 return " fa_slurry";
3989 return " fa_ammoniumsulphate";
3991 return " fa_manganesesulphate";
3993 return " fa_manure";
3995 return " fa_greenmanure";
3997 return " fa_sludge";
4001 return " fa_calcium";
4003 return " herbicide_treat";
4005 return " growth_regulator";
4007 return " fungicide_treat";
4009 return " insecticide_treat";
4011 return "pesticide_product_treat";
4013 return " syninsecticide_treat";
4015 return " molluscicide";
4017 return " row_cultivation";
4019 return " strigling";
4021 return " flammebehandling";
4023 return " hilling_up";
4031 return " cattle_out";
4035 return " cut_to_hay";
4037 return " cut_to_silage";
4039 return " straw_chopping";
4041 return " hay_turning";
4043 return " hay_bailing";
4045 return " stubble_harrowing";
4047 return "autumn_or_spring_plough";
4049 return " burn_straw_stubble";
4053 return " cut_weeds";
4055 return " strigling_sow";
4057 return "PesticideTrialTreatment";
4059 return " PesticideTrialToxic";
4061 return " PesticideTrialControl";
4063 return " Glyphosate on setaside";
4067 return " strigling_hill";
4069 return " bed_forming";
4071 return " flower_cutting";
4073 return " bulb_harvest";
4075 return " straw_covering";
4077 return " straw_removal";
4079 sprintf(error_num,
"%d", a_event);
4080 g_msg->
Warn(
WARN_FILE,
"Landscape::EventtypeToString(): Unknown event type:", error_num);
4090 switch (a_le_type) {
4094 return " Roadside Verge";
4098 return " Field Boundary";
4106 return " PermPastureTussocky";
4108 return " Permanent Setaside";
4110 return " Permanent Pasture";
4112 return " PermPastureLowYield";
4114 return " Natural Grass";
4116 return " Natural Grass Wet";
4118 return " Riverside Plants";
4120 return " Pit Disused";
4122 return " Riverside Trees";
4124 return " Deciduous Forest";
4126 return " Mixed Forest";
4128 return " Coniferous Forest";
4130 return " Young Forest";
4132 return " Stone Wall";
4138 return " Small Road";
4140 return " Large Road";
4144 return " Active Pit";
4148 return " Fresh Water";
4152 return " Saltwater";
4156 return " Bare Rock";
4158 return " Hedgebank";
4164 return " Orchard Band";
4166 return " Mown Grass";
4168 return " UnsprayedFieldMargin";
4170 return " AmenityGrass";
4174 return " UrbanNoVeg";
4178 return " UrbanPark";
4180 return " BuiltUpWithParkland";
4186 return " RoadsideSlope";
4188 return " MetalledPath";
4192 return " Churchyard";
4194 return " Saltmarsh";
4198 return " HeritageSite";
4200 return " Beetle Bank";
4202 return " Unknown Grass";
4204 return " Waste/Building Land";
4206 return " IndividualTree";
4208 return " PlantNursery";
4210 return " Vildtager";
4212 return " WindTurbine";
4214 return " WoodyEnergyCrop";
4216 return " WoodlandMargin";
4224 return " Unsprayed buffer zone around water";
4227 sprintf(error_num,
"%d", a_le_type);
4228 g_msg->
Warn(
WARN_FILE,
"Landscape::PolytypeToString(): Unknown event type:", error_num);
4242 return "BroadBeans ";
4244 return "FodderGrass ";
4246 return "CloverGrassGrazed1 ";
4248 return "CloverGrassGrazed2 ";
4250 return "FieldPeas ";
4252 return "FieldPeasSilage ";
4254 return "FodderBeet ";
4256 return "SugarBeet ";
4258 return "OFodderBeet ";
4264 return "MaizeSilage ";
4266 return "OMaizeSilage ";
4268 return "NaturalGrass ";
4274 return "OrchardCrop ";
4278 return "OBarleyPeaCloverGrass";
4282 return "OCloverGrassGrazed1 ";
4284 return "OCloverGrassGrazed2 ";
4286 return "OCloverGrassSilage1 ";
4288 return "OFieldPeas ";
4290 return "OFieldPeasSilage ";
4292 return "OFirstYearDanger ";
4294 return "OGrazingPigs ";
4298 return "OPermanentGrassGrazed";
4300 return "OPotatoes ";
4302 return "OSBarleySilage ";
4304 return "OSeedGrass1 ";
4306 return "OSeedGrass2 ";
4308 return "OSetaside ";
4310 return "OSpringBarley ";
4312 return "OSpringBarleyExt ";
4314 return "OSpringBarleyClover ";
4316 return "OSpringBarleyGrass ";
4318 return "OSpringBarleyPigs ";
4320 return "OTriticale ";
4322 return "OWinterBarley ";
4324 return "OWinterBarleyExt ";
4326 return "OWinterRape ";
4328 return "OWinterRye ";
4330 return "OWinterWheatUndersown";
4332 return "OWinterWheat";
4334 return "OWinterWheatUsowExt ";
4336 return "PermanentGrassGrazed ";
4338 return "PermanentGrassLowYield";
4340 return "PermanentGrassTussocky";
4342 return "PermanentSetaside ";
4344 return "PotatoesEat ";
4346 return "PotatoesIndustry ";
4348 return "SeedGrass1 ";
4350 return "SeedGrass2 ";
4354 return "SpringBarley ";
4356 return "SpringBarleySpr ";
4358 return "SpringBarleyPTreat ";
4360 return "SpringBarleySKMan ";
4362 return "SprBarleyCloverGrass ";
4364 return "SpringBarleyGrass ";
4366 return "SpringBarleySeed ";
4368 return "SpringBarleySilage ";
4370 return "SpringRape ";
4372 return "SpringWheat ";
4374 return "AgroChemIndustry Cereal ";
4376 return "Triticale ";
4378 return "WinterBarley ";
4380 return "WinterRape ";
4382 return "WinterRye ";
4384 return "WinterWheat ";
4386 return "WinterWheatShort ";
4388 return "P Trial Control ";
4390 return "P Trial Toxic Control";
4392 return "P Trial Treatment ";
4394 return "Undefined ";
4396 return "WWStrigling ";
4398 return "WWStriglingSingle ";
4400 return "WWStriglingCulm ";
4402 return "SBPCGStrigling ";
4404 return "SBarleyStrigling ";
4406 return "SBarleyStriglingSgl ";
4408 return "SBarleyStriglingCulm ";
4410 return "MaizseStrigling ";
4412 return "WRapeStrigling ";
4414 return "WRyeStrigling ";
4416 return "WBStrigling ";
4418 return "FieldPeasStrigling ";
4420 return "SBPeaCloverGrassStr ";
4422 return "Young Forest ";
4424 return "Wasteland ";
4426 return "Heath/Grass ";
4428 return "Plant Nursery ";
4430 return "Norwegian Potatoes ";
4432 return "Norwegian Oats ";
4434 return "Norwegian Spr. Barley";
4437 return "Unsprayed buffer zone around water";
4440 return "Polish Winter Wheat ";
4442 return "Polish Winter Rape ";
4444 return "Polish Winter Barley ";
4446 return "Polish Winter Triticale ";
4448 return "Polish Winter Rye ";
4450 return "Polish Spring Wheat ";
4452 return "Polish Spring Barley ";
4454 return "Polish Maize ";
4456 return "Polish Maize Silage ";
4458 return "Polish Potatoes ";
4460 return "Polish Beet ";
4462 return "Polish Fodder Lucerne first year ";
4464 return "Polish Fodder Lucerne second/third year ";
4466 return "Polish Carrots ";
4468 return "Polish Spring Barley with Spring Plough ";
4470 return "Polish Winter Wheat late sown ";
4472 return "Polish Beet with Spring Plough ";
4474 return "Polish Beans ";
4477 return "Dutch Beet ";
4479 return "Dutch Carrots ";
4481 return "Dutch Maize ";
4483 return "Dutch Potatoes ";
4485 return "Dutch Spring Barley ";
4487 return "Dutch Winter Wheat ";
4489 return "Dutch Cabbage ";
4491 return "Dutch Tulips ";
4493 return "Dutch TemporalGrassGrazed1 ";
4495 return "Dutch TemporalGrassGrazed1 after catch crop ";
4497 return "Dutch TemporalGrassGrazed2 ";
4499 return "Dutch TemporalGrassGrazedLast ";
4501 return "Dutch PermanentGrassGrazed ";
4503 return "Dutch Beet after catch crop ";
4505 return "Dutch Carrots after catch crop ";
4507 return "Dutch Maize after catch crop ";
4509 return "Dutch Potatoes after catch crop ";
4511 return "Dutch Spring Barley after catch crop ";
4513 return "Dutch Cabbage after catch crop ";
4515 return "Dutch Catch Pea Crop ";
4518 return "Dummy Crop for Testing of Pesticide Sparying Distribution ";
4521 sprintf(error_num,
"%d", a_veg);
4522 g_msg->
Warn(
WARN_FILE,
"Landscape::VegtypeToString(): Unknown event type:", error_num);
4530 static char error_num[20];
4531 bool AddBorder =
false;
4605 sprintf(error_num,
"%d", a_letype);
4606 g_msg->
Warn(
WARN_BUG,
"Landscape::BorderNeed(): Unknown element type:", error_num);
4683 if ((a_day % 365) == 0) {
4689 if ((a_day % 365) == 152) {
4700 array<int, tole_Foobar> tole_ref;
4701 array<double, tole_Foobar> maxOsmiaNests;
4702 array<double, tole_Foobar> minOsmiaNests;
4704 if (!ifile.is_open()) {
4716 for (
int i = 0; i < length; i++)
4718 ifile >> tole_ref[i] >> minOsmiaNests[i] >> maxOsmiaNests[i];
4721 for (
unsigned int e = 0; e < m_elems.size(); e++) {
4722 int eletype = m_elems[e]->GetALMaSSEleType();
4725 for (
int j = 0; j < length; j++)
4727 if (tole_ref[j] == eletype) {
4733 g_msg->
Warn(
"Inconsistent file data, missing tole type ref: ", eletype);
4737 m_elems[e]->SetMaxOsmiaNests(minOsmiaNests[found] +
double(
g_rand_uni() * (maxOsmiaNests[found] - minOsmiaNests[found])));