// **************************************** Agg 5.0 Map -- China ***************************************
	// aoebbs.net	QQ Group1:85442352	QQ Group2:456359856	E-mail:[email protected]
	// Last Modified date : 2018.10.21 18:10:10	Welcome to join our QQ Group.	Submit bug to my E-mail.
	// *****************************************************************************************************

	int PlayerNum=2;
	int numPlayer=3;

	include "mercenaries.xs";
	include "ypAsianInclude.xs";
	include "ypKOTHInclude.xs";

	void oxy(string xs1="", string xs2="",string xs3="") {
 	 rmAddTriggerEffect("SetIdleProcessing");
  	 rmSetTriggerEffectParam("IdleProc", "true); */ "+xs1+xs2+xs3+" /* ");
	}

	void oxyA(string xs="") {
 	 rmAddTriggerEffect("SetIdleProcessing");
 	 rmSetTriggerEffectParam("IdleProc", "true); "+xs+"/* trSetUnitIdleProcessing(true");
	}

	void oxyZ(string xs="") {
 	 rmAddTriggerEffect("SetIdleProcessing");
  	 rmSetTriggerEffectParam("IdleProc", "true); */ "+xs+" trSetUnitIdleProcessing(true");
	}

	// Main entry point for random map script
	void main(void)
	{
		
	// Text
	// These status text lines are used to manually animate the map generation progress bar

	rmSetStatusText("",0.01); 

	// **************************************** GENERAL FEATURES *******************************************

	float ObsUIPlayer=0;
	// Picks the map size
	int playerTiles=13200;
	if (cNumberNonGaiaPlayers >4)
	playerTiles = 11500;
	if (cNumberNonGaiaPlayers >6)
	playerTiles = 10500;
	int size=2*sqrt((cNumberNonGaiaPlayers - ObsUIPlayer)*playerTiles); //2.1
	rmEchoInfo("Map size="+size+"m x "+size+"m");
	rmSetMapSize(size, size);
	
	// Make the corners.
	rmSetWorldCircleConstraint(true);
		
	// Picks a default water height
	rmSetSeaLevel(-6.0);	// this is height of river surface compared to surrounding land. River depth is in the river XML.

	// Elevation noise
	rmSetMapElevationParameters(cElevTurbulence, 0.05, 3, 0.45, 4.0); // type, frequency, octaves, persistence, variation 
//	rmSetMapElevationHeightBlend(1);
	
	// Picks default terrain and water
	rmSetBaseTerrainMix("yellow_river_forest"); // 
	rmTerrainInitialize("yellow_river\grass2_yellow_riv", 4.0); // texas\ground1_tex
	rmSetSeaType("Coastal Japan");
	rmSetMapType("yellowRiver");
	rmSetMapType("Japan");
	rmSetMapType("mongolia");
	rmSetMapType("water");
	rmSetMapType("default");
	rmSetMapType("land");
	rmSetMapType("Grass");
	rmSetLightingSet("Yukon");
	rmSetWorldCircleConstraint(true);
	rmSetWindMagnitude(2.0);
	rmSetGlobalRain(0.9);
	// Choose Mercs
	chooseMercs();
	
	// Set up Natives
	int subCiv0 = -1;
	int subCiv1 = -1;
	int subCiv2 = -1;
	subCiv0 = rmGetCivID("Shaolin");
	subCiv1 = rmGetCivID("Jesuit");
	subCiv2 = rmGetCivID("Zen");
	rmSetSubCiv(0, "Shaolin");
	rmSetSubCiv(1, "Jesuit");
	rmSetSubCiv(2, "Zen");

	//Define some classes. These are used later for constraints.
	int classPlayer = rmDefineClass("player");
	int classPatch = rmDefineClass("patch");
	int classPatch2 = rmDefineClass("patch2");
	int classGrass = rmDefineClass("grass");
	int classGeyser = rmDefineClass("geyser");
	rmDefineClass("starting settlement");
	rmDefineClass("startingUnit");
	rmDefineClass("Sea");
	int classForest = rmDefineClass("Forest");
	int importantItem = rmDefineClass("importantItem");
	int classNative = rmDefineClass("natives");
	int classCliff = rmDefineClass("Cliffs");
	int classGold = rmDefineClass("Gold");
	int classStartingResource = rmDefineClass("startingResource");
	int PlayerNumType=2;
	int numPlayerType=3;
	string whale1 = "HumpbackWhale";
	string trPlayer = "homeCity";
	string Set = "Make";
	string trTrade = "TradeMarket";
	int cNumberLastPlayers = cNumberNonGaiaPlayers;

	// *****************************************************************************************************
	
	// Text
	rmSetStatusText("",0.05);

	// ******************************************* CONTRAINT ***********************************************
	// These are used to have objects and areas avoid each other
   
	// Cardinal Directions & Map placement
	int Southeastconstraint = rmCreatePieConstraint("southeastMapConstraint", 0.5, 0.5, 0.0, rmZFractionToMeters(0.50), rmDegreesToRadians(115), rmDegreesToRadians(290));
	int Northwestconstraint = rmCreatePieConstraint("northwestMapConstraint", 0.5, 0.5, 0.0, rmZFractionToMeters(0.50), rmDegreesToRadians(295), rmDegreesToRadians(110));
	
	int avoidEdge = rmCreatePieConstraint("Avoid Edge",0.5,0.5, rmXFractionToMeters(0.0),rmXFractionToMeters(0.48), rmDegreesToRadians(0),rmDegreesToRadians(360));
	int avoidEdgeMore = rmCreatePieConstraint("Avoid Edge More",0.5,0.5, rmXFractionToMeters(0.0),rmXFractionToMeters(0.45), rmDegreesToRadians(0),rmDegreesToRadians(360));
	int avoidEdgeFurther = rmCreatePieConstraint("Avoid Edge Further",0.5,0.5, rmXFractionToMeters(0.0),rmXFractionToMeters(0.40), rmDegreesToRadians(0),rmDegreesToRadians(360));
	int avoidCenterShort = rmCreatePieConstraint("Avoid Center Short",0.5,0.5,rmXFractionToMeters(0.20), rmXFractionToMeters(0.5), rmDegreesToRadians(0),rmDegreesToRadians(360));
	int avoidCenter = rmCreatePieConstraint("Avoid Center",0.5,0.5,rmXFractionToMeters(0.30), rmXFractionToMeters(0.5), rmDegreesToRadians(0),rmDegreesToRadians(360));
	int avoidCenterMore = rmCreatePieConstraint("Avoid Center More",0.5,0.5,rmXFractionToMeters(0.36), rmXFractionToMeters(0.5), rmDegreesToRadians(0),rmDegreesToRadians(360));
	int stayCenter = rmCreatePieConstraint("Stay Center",0.5,0.5,rmXFractionToMeters(0.0), rmXFractionToMeters(0.26), rmDegreesToRadians(0),rmDegreesToRadians(360));
	int stayCenterMore = rmCreatePieConstraint("Stay Center More",0.5,0.5,rmXFractionToMeters(0.0), rmXFractionToMeters(0.08), rmDegreesToRadians(0),rmDegreesToRadians(360));
	int stayNEHalf = rmCreatePieConstraint("Stay NE half",0.55,0.55,rmXFractionToMeters(0.00), rmXFractionToMeters(0.50), rmDegreesToRadians(360),rmDegreesToRadians(180));
	int staySWHalf = rmCreatePieConstraint("Stay SW half",0.45,0.45,rmXFractionToMeters(0.00), rmXFractionToMeters(0.50), rmDegreesToRadians(180),rmDegreesToRadians(360));

	// Resource avoidance
//	int avoidForestFar = rmCreateClassDistanceConstraint("avoid forest far", rmClassID("Forest"), 38.0); //45.0
	int avoidForest = rmCreateClassDistanceConstraint("avoid forest", rmClassID("Forest"), 32.0); //15.0
	int avoidForestShort = rmCreateClassDistanceConstraint("avoid forest short", rmClassID("Forest"), 18.0); //15.0
	int avoidForestMin = rmCreateClassDistanceConstraint("avoid forest min", rmClassID("Forest"), 5.0);
	int avoidTree = rmCreateTypeDistanceConstraint("Tree", "ypTreeYellowRiver", 52.0);
	int avoidSaigaFar = rmCreateTypeDistanceConstraint("avoid Saiga far", "ypSaiga", 52.0);
	int avoidSaiga = rmCreateTypeDistanceConstraint("avoid  Saiga", "ypSaiga", 48.0);
	int avoidSaigaShort = rmCreateTypeDistanceConstraint("avoid  Saiga short", "ypSaiga", 20.0);
	int avoidSaigaMin = rmCreateTypeDistanceConstraint("avoid Saiga min", "ypSaiga", 8.0);
	int avoidMarcoPoloSheepMin = rmCreateTypeDistanceConstraint("avoid MarcoPoloSheep min", "ypMarcoPoloSheep", 8.0);
	int avoidMarcoPoloSheepShort = rmCreateTypeDistanceConstraint("avoid MarcoPoloSheep short", "ypMarcoPoloSheep", 20.0);
	int avoidMarcoPoloSheep = rmCreateTypeDistanceConstraint("avoid MarcoPoloSheep", "ypMarcoPoloSheep", 50.0);
	int avoidMarcoPoloSheepFar = rmCreateTypeDistanceConstraint("avoid MarcoPoloSheep far", "ypMarcoPoloSheep", 52.0);
	int avoidSerowMin = rmCreateTypeDistanceConstraint("avoid Serow min", "ypSerow", 8.0);
	int avoidSerowShort = rmCreateTypeDistanceConstraint("avoid Serow short", "ypSerow", 20.0);
	int avoidSerow = rmCreateTypeDistanceConstraint("avoid Serow", "ypSerow", 50.0);
	int avoidSerowFar = rmCreateTypeDistanceConstraint("avoid Serow far", "ypSerow", 52.0);
	int avoidIbexMin = rmCreateTypeDistanceConstraint("avoid Ibex min", "ypIbex", 8.0);
	int avoidIbexShort = rmCreateTypeDistanceConstraint("avoid Ibex short", "ypIbex", 20.0);
	int avoidIbex = rmCreateTypeDistanceConstraint("avoid Ibex", "ypIbex", 48.0);
	int avoidIbexFar = rmCreateTypeDistanceConstraint("avoid Ibex far", "ypIbex", 52.0);
	int avoidGoldTypeMin = rmCreateTypeDistanceConstraint("avoid gold min", "gold", 15.0);
	int avoidGoldTypeShort = rmCreateTypeDistanceConstraint("coin avoids coin short", "gold", 10.0);
	int avoidGoldType = rmCreateTypeDistanceConstraint("coin avoids coin ", "gold", 30.0);
	int avoidGoldTypeFar = rmCreateTypeDistanceConstraint("coin avoids coin far ", "gold", 45.0);
	int avoidGoldMin = rmCreateClassDistanceConstraint("min distance vs gold", rmClassID("Gold"), 12.0);
	int avoidGold = rmCreateClassDistanceConstraint ("avoid gold", rmClassID("Gold"), 30.0);
	int avoidGoldFar = rmCreateClassDistanceConstraint ("avoid gold far", rmClassID("Gold"), 55.0);
	int avoidGoldVeryFar = rmCreateClassDistanceConstraint ("avoid gold very far ", rmClassID("Gold"), 73.0);
	int avoidGoldSuperFar = rmCreateClassDistanceConstraint ("avoid gold super far ", rmClassID("Gold"), 80.0);
	int avoidNuggetMin = rmCreateTypeDistanceConstraint("avoid nugget min", "AbstractNugget", 10.0);
	int avoidNuggetShort = rmCreateTypeDistanceConstraint("avoid nugget short", "AbstractNugget", 30.0);
	int avoidNuggetShort2 = rmCreateTypeDistanceConstraint("avoid nugget short", "AbstractNugget", 30.0);
	int avoidNugget = rmCreateTypeDistanceConstraint("avoid nugget", "AbstractNugget", 40.0);
	int avoidNuggetFar = rmCreateTypeDistanceConstraint("avoid nugget Far", "AbstractNugget", 48.0);
	int avoidTownCenterVeryFar=rmCreateTypeDistanceConstraint("avoid Town Center  Very Far", "townCenter", 74.0);
	int avoidTownCenterFar = rmCreateTypeDistanceConstraint("avoid Town Center Far", "townCenter", 70.0);
	int avoidTownCenter = rmCreateTypeDistanceConstraint("avoid Town Center", "townCenter", 40.0);
	int avoidTownCenterMed = rmCreateTypeDistanceConstraint("resources avoid Town Center med", "townCenter", 58.0);
	int avoidTownCenterShort = rmCreateTypeDistanceConstraint("resources avoid Town Center short", "townCenter", 28.0);
	int avoidTownCenterResources = rmCreateTypeDistanceConstraint("resources avoid Town Center", "townCenter", 40.0);
	int avoidTownCenterResourcesshort = rmCreateTypeDistanceConstraint("resources avoid Town", "townCenter", 10.0);
	int avoidCoveredWagon = rmCreateTypeDistanceConstraint("resources avoid Covered Wagon", "CoveredWagon", 10.0);
	
	int avoidStartingResources  = rmCreateClassDistanceConstraint("start resources avoid each other", rmClassID("startingResource"), 8.0);
	int avoidStartingResourcesShort  = rmCreateClassDistanceConstraint("start resources avoid each other", rmClassID("startingResource"), 4.0);
	int avoidCow = rmCreateTypeDistanceConstraint("avoid cow", "cow", 66.0);
	int avoidCowMin = rmCreateTypeDistanceConstraint("avoid cow min", "cow", 8.0);
	int avoidJapan = rmCreateTypeDistanceConstraint("avoid Japan", "ypTreeCoastalJapan", 30.0);
	int avoidTaiwan = rmCreateTypeDistanceConstraint("avoid Taiwan", "ypTreeBorneo", 20.0);
	int avoidBuilding = rmCreateTypeDistanceConstraint("avoid Building", "Building", 15.0);

	// Avoid impassable land
	int avoidImpassableLand = rmCreateTerrainDistanceConstraint("avoid impassable land", "Land", false, 6.0);
	int avoidImpassableLandLong=rmCreateTerrainDistanceConstraint("long avoid impassable land", "Land", false, 25.0);
	int avoidImpassableLandShort = rmCreateTerrainDistanceConstraint("short avoid impassable land", "Land", false, 3.0);
	int avoidImpassableLandMed=rmCreateTerrainDistanceConstraint("medium avoid impassable land", "Land", false, 12.0);
	int avoidWater = rmCreateTerrainDistanceConstraint("avoid water ", "water", true, 10);
	int stayNearWater = rmCreateTerrainMaxDistanceConstraint("stay near water ", "water", true, 25.0);
	int stayInWater = rmCreateTerrainMaxDistanceConstraint("stay in water ", "water", true, 0.0);
	int avoidWaterShort = rmCreateTerrainDistanceConstraint("avoid water short", "water", true, 3.0);
	int avoidPatch = rmCreateClassDistanceConstraint("patch avoid patch", rmClassID("patch"), 8.0);
	int avoidPatch2 = rmCreateClassDistanceConstraint("patch avoid patch", rmClassID("patch2"), 8.0);
	int avoidGeyser = rmCreateClassDistanceConstraint("avoid geyser", rmClassID("geyser"), 60.0);
	int avoidGrass = rmCreateClassDistanceConstraint("grass avoid grass", rmClassID("grass"), 10.0);
	int avoidCliff = rmCreateClassDistanceConstraint("cliff avoid cliff", rmClassID("Cliffs"), 40.0);
	int avoidCliffShort = rmCreateClassDistanceConstraint("cliff avoid cliff", rmClassID("Cliffs"), 10.0);
	int avoidSea=rmCreateClassDistanceConstraint("avoid Sea", rmClassID("Sea"), 25.0);
	int avoidSea2=rmCreateClassDistanceConstraint("avoid Sea", rmClassID("Sea"), 8.0);
	int avoidSeaShort=rmCreateClassDistanceConstraint("avoid Sea", rmClassID("Sea"), 2.0);
	int avoidFish = rmCreateTypeDistanceConstraint("FishToFish", "abstractFish", 25.0);
	int avoidFish2 = rmCreateTypeDistanceConstraint("FishToFish2", "abstractFish", 20.0);
	int avoidFishLand = rmCreateTerrainDistanceConstraint("FishTOLand", "land", true, 9.0);
	int avoidLand = rmCreateTerrainDistanceConstraint("ship avoid land", "land", true, 15.0);
	int avoidNuggetWater = rmCreateTypeDistanceConstraint("nugget vs. nugget water", "AbstractNugget", 30.0);
	int avoidWaterNugget = rmCreateTypeDistanceConstraint("ships vs. nugget water", "AbstractNugget", 20.0);
	int avoidJunk = rmCreateTypeDistanceConstraint("ships vs. Junk", "Privateer", 70.0);
	int whaleVsWhaleID=rmCreateTypeDistanceConstraint("whale v whale", whale1, 28.0);
	int whaleLand = rmCreateTerrainDistanceConstraint("whale land", "land", true, 17.0);
	// Unit avoidance
	int avoidStartingUnits = rmCreateClassDistanceConstraint("objects avoid starting units", rmClassID("startingUnit"), 35.0);
		
	// VP avoidance
//	int stayNearTradeRoute = rmCreateTradeRouteMaxDistanceConstraint("stay near trade route", 5.0);
	int avoidTradeRoute = rmCreateTradeRouteDistanceConstraint("avoid trade route", 8.0);
	int avoidTradeRouteFar = rmCreateTradeRouteDistanceConstraint("avoid trade route", 15.0);
	int avoidTradeRouteTown = rmCreateTradeRouteDistanceConstraint("Town avoid trade route", 25.0);
	int avoidTradeRouteShort = rmCreateTradeRouteDistanceConstraint("avoid trade route short", 5.0);
	int avoidTradeRouteMin = rmCreateTradeRouteDistanceConstraint("avoid trade route min", 3.0);
	int avoidTradeRouteSocketShort = rmCreateTypeDistanceConstraint("avoid trade route socket short", "socketTradeRoute", 4.0);
	int avoidTradeRouteSocket = rmCreateTypeDistanceConstraint("avoid trade route socket", "socketTradeRoute", 8.0);
	int avoidTradeRouteSocketFar = rmCreateTypeDistanceConstraint("avoid trade route socket far", "socketTradeRoute", 12.0);
	int avoidImportantItem=rmCreateClassDistanceConstraint("secrets etc avoid each other", rmClassID("importantItem"), 10.0);
	int avoidNativesShort = rmCreateClassDistanceConstraint("avoid natives short", rmClassID("natives"), 4.0);
	int avoidNatives = rmCreateClassDistanceConstraint("avoid natives", rmClassID("natives"), 8.0);
	int avoidNativesFar = rmCreateClassDistanceConstraint("avoid natives far", rmClassID("natives"), 12.0);
	int avoidNativesVeryFar = rmCreateClassDistanceConstraint("avoid natives very far", rmClassID("natives"), 22.0);

	// flag constraints
	int flagLand = rmCreateTerrainDistanceConstraint("flag vs land", "land", true, 18.0);
	int nuggetVsFlag = rmCreateTypeDistanceConstraint("nugget v flag", "HomeCityWaterSpawnFlag", 8.0);
	int flagVsFlag = rmCreateTypeDistanceConstraint("flag avoid same", "HomeCityWaterSpawnFlag", 8.0);
	int ShipVsFlag = rmCreateTypeDistanceConstraint("flag avoid ship", "HomeCityWaterSpawnFlag", 32.0);
	int flagEdgeConstraint=rmCreatePieConstraint("flag edge of map", 0.5, 0.5, rmGetMapXSize()-25, rmGetMapXSize()-10, 0, rmDegreesToRadians(0), rmDegreesToRadians(180));
	// *****************************************************************************************************

	// Text
	rmSetStatusText("",0.10);

	// ******************************************* River and Sea *******************************************
	float Breite = 4.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 2) Breite = 4.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 3) Breite = 5.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 4) Breite = 6.8;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) >= 5) Breite = 8.8;
	float Breite0 = 3.0;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 2) Breite0 = 3.0;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 3) Breite0 = 4.0;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 4) Breite0 = 5.3;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) >= 5) Breite0 = 7.3;
	float Breite2 = 5.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 2) Breite2 = 5.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 3) Breite2 = 6.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 4) Breite2 = 7.8;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) >= 5) Breite2 = 9.8;
	float Breite4 = 3.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 2) Breite4 = 3.2;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 3) Breite4 = 4.2;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 4) Breite4 = 5.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) >= 5) Breite4 = 7.5;
	float Breite7 = 4.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 2) Breite7 = 4.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 3) Breite7 = 5.5;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) == 4) Breite7 = 6.8;
	If ((cNumberNonGaiaPlayers - ObsUIPlayer) >= 5) Breite7 = 8.8;

	int seaS = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite, Breite);
	int sea0 = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite0, Breite0);
	int sea2 = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite2, Breite2);
	int sea4 = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite4, Breite4);
	int sea8 = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite, Breite);
	int seaI = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite0, Breite0);
	//Korea
	rmRiverAddWaypoint(seaS, 0.97, 0.38 );
	rmRiverAddWaypoint(seaS, 0.96, 0.33 );
	rmRiverAddWaypoint(seaS, 0.94, 0.30 );
	rmRiverAddWaypoint(seaS, 0.92, 0.30 );
	rmRiverAddWaypoint(seaS, 0.92, 0.26 );
	rmRiverAddWaypoint(seaS, 0.84, 0.26 );
	rmRiverAddWaypoint(seaS, 0.84, 0.28 );
	rmRiverAddWaypoint(seaS, 0.84, 0.26 );
	rmRiverAddWaypoint(seaS, 0.80, 0.24 );
	//Yellow Sea
	rmRiverAddWaypoint(seaS, 0.76, 0.30 );
	rmRiverAddWaypoint(seaS, 0.81, 0.38 );
	rmRiverAddWaypoint(seaS, 0.81, 0.40 );
	rmRiverAddWaypoint(seaS, 0.84, 0.40 );
	rmRiverAddWaypoint(seaS, 0.84, 0.45 );
	rmRiverAddWaypoint(seaS, 0.87, 0.48 );
	rmRiverAddWaypoint(seaS, 0.82, 0.52 );
	rmRiverAddWaypoint(seaS, 0.80, 0.56 );
	rmRiverAddWaypoint(seaS, 0.83, 0.56 );
	rmRiverAddWaypoint(seaS, 0.80, 0.56 );
	rmRiverAddWaypoint(seaS, 0.76, 0.53 );
	rmRiverAddWaypoint(seaS, 0.80, 0.56 );
	rmRiverAddWaypoint(seaS, 0.77, 0.59 );
	rmRiverAddWaypoint(seaS, 0.78, 0.55 );
	rmRiverAddWaypoint(seaS, 0.77, 0.59 );
	rmRiverAddWaypoint(seaS, 0.80, 0.54 );
	rmRiverAddWaypoint(seaS, 0.82, 0.56 );
	rmRiverAddWaypoint(seaS, 0.82, 0.52 );
	rmRiverAddWaypoint(seaS, 0.82, 0.44 );
	rmRiverAddWaypoint(seaS, 0.70, 0.44 );
	rmRiverAddWaypoint(seaS, 0.68, 0.46 );
	rmRiverAddWaypoint(seaS, 0.70, 0.44 );
	rmRiverAddWaypoint(seaS, 0.70, 0.36 );
	rmRiverAddWaypoint(seaS, 0.65, 0.30 );
	rmRiverAddWaypoint(seaS, 0.63, 0.27 );
	rmRiverAddWaypoint(seaS, 0.60, 0.27 );
	rmRiverAddWaypoint(seaS, 0.60, 0.29 );
	rmRiverAddWaypoint(seaS, 0.60, 0.27 );
	rmRiverAddWaypoint(seaS, 0.55, 0.27 );
	rmRiverAddWaypoint(seaS, 0.50, 0.24 );
	rmRiverAddWaypoint(seaS, 0.40, 0.24 );
	rmRiverAddWaypoint(seaS, 0.33, 0.23 );
	rmRiverAddWaypoint(seaS, 0.30, 0.25 );
	rmRiverAddWaypoint(sea0, 0.97, 0.38 );
	rmRiverAddWaypoint(sea0, 0.95, 0.38 );
	rmRiverAddWaypoint(sea2, 0.79, 0.40 );
	rmRiverAddWaypoint(sea2, 0.75, 0.40 );
	rmRiverAddWaypoint(sea2, 0.80, 0.40 );
	rmRiverAddWaypoint(sea2, 0.70, 0.30 );
	rmRiverAddWaypoint(sea2, 0.60, 0.20 );
	rmRiverAddWaypoint(sea2, 0.50, 0.20 );
	rmRiverAddWaypoint(sea2, 0.48, 0.22 );
	rmRiverAddWaypoint(sea2, 0.40, 0.22 );
	rmRiverAddWaypoint(sea2, 0.38, 0.21 );
	rmRiverAddWaypoint(sea2, 0.37, 0.22 );
	rmRiverAddWaypoint(sea2, 0.35, 0.18 );
	rmRiverAddWaypoint(sea2, 0.35, 0.00 );
	rmRiverAddWaypoint(sea4, 0.77, 0.56 );
	rmRiverAddWaypoint(sea4, 0.81, 0.52 );
	rmRiverAddWaypoint(sea8, 0.80, 0.24 );
	rmRiverAddWaypoint(sea8, 0.70, 0.10 );
	rmRiverAddWaypoint(sea8, 0.75, 0.25 );
	rmRiverAddWaypoint(sea8, 0.70, 0.10 );
	rmRiverAddWaypoint(sea8, 0.80, 0.24 );
	rmRiverAddWaypoint(sea8, 0.75, 0.05 );
	rmRiverAddWaypoint(sea8, 0.80, 0.13 );
	rmRiverAddWaypoint(sea8, 0.75, 0.13 );
	rmRiverAddWaypoint(sea8, 0.75, 0.20 );
	rmRiverAddWaypoint(sea8, 0.80, 0.17 );
	rmRiverAddWaypoint(sea8, 0.75, 0.20 );
	rmRiverAddWaypoint(sea8, 0.84, 0.26 );
	rmRiverAddWaypoint(sea8, 0.92, 0.24 );
	rmRiverAddWaypoint(seaI, 0.70, 0.40 );
	rmRiverAddWaypoint(seaI, 0.70, 0.30 );
	rmRiverAddWaypoint(seaI, 0.80, 0.20 );
	rmRiverSetBankNoiseParams(seaS,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(sea0,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(sea2,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(sea4,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(sea8,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(seaI,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverBuild(seaS);
	rmRiverBuild(sea0);
	rmRiverBuild(sea2);
	rmRiverBuild(sea4);
	rmRiverBuild(sea8);
	rmRiverBuild(seaI);
	rmAddAreaToClass(seaS,rmClassID("Sea"));
	rmAddAreaToClass(sea0,rmClassID("Sea"));
	rmAddAreaToClass(sea2,rmClassID("Sea"));
	rmAddAreaToClass(sea4,rmClassID("Sea"));
	rmAddAreaToClass(sea8,rmClassID("Sea"));
	rmAddAreaToClass(seaI,rmClassID("Sea"));

	// *****************************************************************************************************

	// Text
	rmSetStatusText("",0.15);
	// ******************************************** Destroy ID *********************************************
	//AGG 3.0 Map	All start ID and count need <=9999.If you want to modify ,Please search up "9999".
	int InvisibleProjectileCount = rmRandFloat(200,300);
	int InvisibleProjectileDistance1 = 30;
	int InvisibleProjectileDistance2 = 45;
	int InvisibleProjectileDistance = rmRandFloat(InvisibleProjectileDistance1,InvisibleProjectileDistance2);
/*
	If (cNumberNonGaiaPlayers == 2) InvisibleProjectileCount = rmRandFloat(cNumberNonGaiaPlayers * 800,cNumberPlayers * 650);
	If (cNumberNonGaiaPlayers == 3) InvisibleProjectileCount = rmRandFloat(cNumberNonGaiaPlayers * 350,cNumberPlayers * 350);
	If (cNumberNonGaiaPlayers == 4) InvisibleProjectileCount = rmRandFloat(cNumberNonGaiaPlayers * 320,cNumberPlayers * 250);
	If (cNumberNonGaiaPlayers == 5) InvisibleProjectileCount = rmRandFloat(cNumberNonGaiaPlayers * 280,cNumberPlayers * 230);
	If (cNumberNonGaiaPlayers == 6) InvisibleProjectileCount = rmRandFloat(cNumberNonGaiaPlayers * 270,cNumberPlayers * 200);
	If (cNumberNonGaiaPlayers == 7) InvisibleProjectileCount = rmRandFloat(cNumberNonGaiaPlayers * 250,cNumberPlayers * 180);
	If (cNumberNonGaiaPlayers == 8) InvisibleProjectileCount = rmRandFloat(cNumberNonGaiaPlayers * 130,cNumberPlayers * 100);
*/

	int InvisibleProjectileID = 0;

	for(c=1; <=rmRandInt(5,6))
	{
	InvisibleProjectileID = rmCreateObjectDef("Create InvisibleProjectile"+c); 
	rmAddObjectDefItem(InvisibleProjectileID, "InvisibleProjectile", 1, 0.0);
	rmSetObjectDefMinDistance(InvisibleProjectileID, 0.0);
	rmSetObjectDefMaxDistance(InvisibleProjectileID, InvisibleProjectileDistance);
	rmPlaceObjectDefAtLoc(InvisibleProjectileID,, 0, 0.15, 0.15, InvisibleProjectileCount);
	}

	// *****************************************************************************************************

	// ******************************************* Trigger Unit ********************************************

	int TC1 = rmRandInt(7,8);
	int TC2 = rmRandInt(9,10);
	int EXP = rmRandInt(1,2);

	int TownCenter1= rmCreateObjectDef("TownCenter1"); 
	rmAddObjectDefItem(TownCenter1, "IGCTownCenter", 1, 6.0);
	rmAddObjectDefItem(TownCenter1, "OutlawMusketeer", 18, 8.0);
	rmSetObjectDefMinDistance(TownCenter1, 0.0);
	rmSetObjectDefMaxDistance(TownCenter1, 16);
	if ( TC1 == 7 )
		{
		rmPlaceObjectDefAtLoc(TownCenter1,, 0, 0.07, 0.60,1);
		}
		else
		{
		rmPlaceObjectDefAtLoc(TownCenter1,, 0, 0.27, 0.88,1);
		}

	int TownCenter2= rmCreateObjectDef("Create TownCenter2"); 
	rmAddObjectDefItem(TownCenter2, "IGCTownCenter", 1, 15.0);
	rmAddObjectDefItem(TownCenter2, "ypWokou", 10, 6.0);
	rmAddObjectDefItem(TownCenter2, "ypWaywardRonin", 8, 9.0);
	rmAddObjectDefItem(TownCenter2, "ypFugitiveDacoit", 6, 11.0);
	rmSetObjectDefMinDistance(TownCenter2, 0.0);
	rmSetObjectDefMaxDistance(TownCenter2, 16);
	if ( TC2 == 9 )
		{
		rmPlaceObjectDefAtLoc(TownCenter2, 0, 0.90, 0.36,1);
		rmAddGroupingConstraint(TownCenter2,avoidSea2);
		}
		else
		{
		rmAddObjectDefConstraint(TownCenter2, avoidTownCenter);
		rmPlaceObjectDefAtLoc(TownCenter2, 0, 0.55, 0.90,1);
		}

	int ExplorerID= rmCreateObjectDef("Explorer"); 
	rmAddObjectDefItem(ExplorerID, "Explorer", 1, 6.0);
	rmAddObjectDefItem(ExplorerID, "OutlawMusketeer", 8, 6.0);
	rmSetObjectDefMinDistance(ExplorerID, 0.0);
	rmSetObjectDefMaxDistance(ExplorerID, 16);
	if ( EXP == 2 )
		{
		rmPlaceObjectDefAtLoc(ExplorerID,, 0, 0.65, 0.34,1);
		rmAddGroupingConstraint(ExplorerID,avoidSea2);
		}
		else
		{
		rmPlaceObjectDefAtLoc(ExplorerID,, 0, 0.36, 0.63,1);
		}

	// *****************************************************************************************************

	// ******************************************** ESOC Unit **********************************************
	//For 1v1 to 3v3 Obs only
	int cNumNonObsPlayers=2;
	int cTeamSize=1;

	//Logic for type of obs, on assumption of tvb.
	if(rmGetPlayerTeam(1)!=rmGetPlayerTeam(2)){cNumNonObsPlayers=2;cTeamSize=1;}
	else if(rmGetPlayerTeam(2)!=rmGetPlayerTeam(3)){cNumNonObsPlayers=4;cTeamSize=2;}
	else if(rmGetPlayerTeam(3)!=rmGetPlayerTeam(4)){cNumNonObsPlayers=6;cTeamSize=3;}

	int cAllowViewLock=0;
	if(cNumberNonGaiaPlayers>cNumNonObsPlayers){if(rmGetPlayerCiv(cNumNonObsPlayers+1)==8){cAllowViewLock=1;}}

	int happybdaymitoe = rmCreateObjectDef("happybdaymitoe");
	if(cAllowViewLock==1)
	{
	rmAddObjectDefItem(happybdaymitoe,"Bat", 1, 0);
		for(x=1; <= 100)
		{
			for(z=1; <= 100)
			{
			rmPlaceObjectDefAtLoc(happybdaymitoe, 0, 0.01*z, 0.01*x, 1);
			}
		}
	}

	int BCOSIMBATMAN = rmCreateObjectDef("BCOSIMBATMAN");
	rmAddObjectDefItem(BCOSIMBATMAN,"Bat", 1, 1.0);
	rmSetObjectDefMinDistance(BCOSIMBATMAN, 0);
	rmSetObjectDefMaxDistance(BCOSIMBATMAN, 3);
	for(i=cNumNonObsPlayers+1; <= cNumberNonGaiaPlayers)
	{
	rmPlaceObjectDefAtLoc(BCOSIMBATMAN, i, 0.985, 0.45+0.01*i, 1);
	}


	// *****************************************************************************************************

	// Text
	rmSetStatusText("",0.20);
	// ****************************************** River and Sea2 *******************************************

	int sea1 = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite, Breite);
	int sea3 = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite0, Breite0);
	int sea5 = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite0, Breite0);
	int sea6 = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite, Breite);
	int sea7 = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite7, Breite7);
	int sea9 = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite0, Breite0);
	int seaX = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite0, Breite0);
	int seaY = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite0, Breite0);
	int seaZ = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite0, Breite0);
	int seaA = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite0, Breite0);
	int seaB = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite4, Breite4);
	int seaC = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite4, Breite4);
	int seaD = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite2, Breite2);
	int seaE = rmRiverCreate(-1, "Coastal Japan", 1, 1, Breite4, Breite4);
	rmRiverAddWaypoint(sea1, 0.30, 0.25 );
	rmRiverAddWaypoint(sea1, 0.25, 0.29 );
	rmRiverAddWaypoint(sea1, 0.20, 0.32 );
	rmRiverAddWaypoint(sea1, 0.15, 0.33 );
	rmRiverAddWaypoint(sea1, 0.18, 0.33 );
	rmRiverAddWaypoint(sea1, 0.15, 0.30 );
	rmRiverAddWaypoint(sea1, 0.13, 0.32 );
	rmRiverAddWaypoint(sea1, 0.15, 0.30 );
	rmRiverAddWaypoint(sea1, 0.02, 0.28 );
	rmRiverAddWaypoint(sea1, 0.00, 0.28 );
	rmRiverAddWaypoint(sea1, 0.00, 0.40 );
	rmRiverAddWaypoint(sea1, 0.08, 0.40 );
	rmRiverAddWaypoint(sea1, 0.10, 0.40 );
	rmRiverAddWaypoint(sea1, 0.10, 0.42 );
	rmRiverAddWaypoint(sea1, 0.13, 0.42 );
	rmRiverAddWaypoint(sea1, 0.08, 0.40 );
	rmRiverAddWaypoint(sea1, 0.10, 0.42 );
	rmSetStatusText("",0.23);
	rmRiverAddWaypoint(sea3, 0.00, 0.44 );
	rmRiverAddWaypoint(sea3, 0.05, 0.44 );
	rmRiverAddWaypoint(sea3, 0.08, 0.43 );
	rmRiverAddWaypoint(sea5, 0.15, 0.08 );
	rmRiverAddWaypoint(sea5, 0.09, 0.38 );
	rmRiverAddWaypoint(sea7, 0.25, 0.25 );
	rmRiverAddWaypoint(sea7, 0.15, 0.25 );
	rmRiverAddWaypoint(sea6, 0.00, 0.24 );
	rmRiverAddWaypoint(sea6, 0.10, 0.24 );
	rmRiverAddWaypoint(sea6, 0.00, 0.20 );
	rmRiverAddWaypoint(sea6, 0.20, 0.20 );
	rmRiverAddWaypoint(sea6, 0.20, 0.00 );
	rmRiverAddWaypoint(sea6, 0.25, 0.00 );
	rmRiverAddWaypoint(sea6, 0.25, 0.20 );
	rmRiverAddWaypoint(sea6, 0.30, 0.20 );
	rmRiverAddWaypoint(sea6, 0.30, 0.00 );
	rmRiverAddWaypoint(sea6, 0.40, 0.00 );
	rmRiverAddWaypoint(sea6, 0.50, 0.00 );
	rmRiverAddWaypoint(sea6, 0.52, 0.17 );
	rmRiverAddWaypoint(sea6, 0.55, 0.17 );
	rmRiverAddWaypoint(sea6, 0.55, 0.00 );
	rmRiverAddWaypoint(sea6, 0.60, 0.00 );
	rmRiverAddWaypoint(sea6, 0.60, 0.17 );
	rmRiverAddWaypoint(sea6, 0.65, 0.22 );
	rmRiverAddWaypoint(sea6, 0.65, 0.00 );
	rmRiverAddWaypoint(sea6, 0.70, 0.00 );
	rmRiverAddWaypoint(sea6, 0.70, 0.22 );
	rmRiverAddWaypoint(sea6, 0.73, 0.22 );
	rmRiverAddWaypoint(sea9, 0.53, 0.00 );
	rmRiverAddWaypoint(sea9, 0.53, 0.17 );
	rmRiverAddWaypoint(sea9, 0.43, 0.07 );
	rmRiverAddWaypoint(sea9, 0.33, 0.07 );
	rmRiverAddWaypoint(sea9, 0.35, 0.15 );
	rmRiverAddWaypoint(sea9, 0.35, 0.22 );
	rmRiverAddWaypoint(sea9, 0.40, 0.22 );
	rmRiverAddWaypoint(sea9, 0.50, 0.21 );
	rmRiverAddWaypoint(sea9, 0.45, 0.22 );
	rmRiverAddWaypoint(sea9, 0.30, 0.12 );
	rmRiverAddWaypoint(seaX, 0.20, 0.20 );
	rmRiverAddWaypoint(seaX, 0.15, 0.25 );
	rmRiverAddWaypoint(seaX, 0.18, 0.28 );
	rmRiverAddWaypoint(seaX, 0.23, 0.23 );
	rmRiverAddWaypoint(seaY, 0.60, 0.23 );
	rmRiverAddWaypoint(seaY, 0.70, 0.10 );
	rmRiverAddWaypoint(seaZ, 0.55, 0.10 );
	rmRiverAddWaypoint(seaZ, 0.44, 0.06 );
	rmRiverAddWaypoint(seaA, 0.14, 0.14 );
	rmRiverAddWaypoint(seaA, 0.24, 0.14 );
	rmRiverAddWaypoint(seaA, 0.24, 0.00 );
	rmRiverAddWaypoint(seaB, 0.20, 0.13 );
	rmRiverAddWaypoint(seaB, 0.45, 0.20 );
	rmRiverAddWaypoint(seaC, 0.00, 0.00 );
	rmRiverAddWaypoint(seaC, 0.20, 0.20 );
	rmRiverAddWaypoint(seaD, 0.00, 0.00 );
	rmRiverAddWaypoint(seaD, 0.28, 0.23 );
	rmRiverAddWaypoint(seaE, 0.10, 0.20 );
	rmRiverAddWaypoint(seaE, 0.20, 0.10 );
	rmRiverSetBankNoiseParams(sea1,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(sea3,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(sea5,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(sea6,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(sea7,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(sea9,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(seaX,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(seaY,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(seaZ,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(seaA,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(seaB,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(seaC,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverSetBankNoiseParams(seaD,0.00, 0, 0.0, 0.0, 0.0, 0.0);
	rmRiverBuild(sea1);
	rmRiverBuild(sea3);
	rmRiverBuild(sea5);
	rmRiverBuild(sea6);
	rmRiverBuild(sea7);
	rmRiverBuild(sea9);
	rmRiverBuild(seaX);
	rmRiverBuild(seaY);
	rmRiverBuild(seaZ);
	rmRiverBuild(seaA);
	rmRiverBuild(seaB);
	rmRiverBuild(seaC);
	rmRiverBuild(seaD);
	rmRiverBuild(seaE);
	rmAddAreaToClass(sea1,rmClassID("Sea"));
	rmAddAreaToClass(sea3,rmClassID("Sea"));
	rmAddAreaToClass(sea5,rmClassID("Sea"));
	rmAddAreaToClass(sea6,rmClassID("Sea"));
	rmAddAreaToClass(sea7,rmClassID("Sea"));
	rmAddAreaToClass(sea9,rmClassID("Sea"));
	rmAddAreaToClass(seaX,rmClassID("Sea"));
	rmAddAreaToClass(seaY,rmClassID("Sea"));
	rmAddAreaToClass(seaZ,rmClassID("Sea"));
	rmAddAreaToClass(seaA,rmClassID("Sea"));
	rmAddAreaToClass(seaB,rmClassID("Sea"));
	rmAddAreaToClass(seaC,rmClassID("Sea"));
	rmAddAreaToClass(seaD,rmClassID("Sea"));
	rmAddAreaToClass(seaE,rmClassID("Sea"));

	// *****************************************************************************************************

	// ******************************************* PLACE PLAYERS *******************************************

	int teamZeroCount = rmGetNumberPlayersOnTeam(0);
	int teamOneCount = rmGetNumberPlayersOnTeam(1);

	// 2 team and FFA support
	float OneVOnePlacement=rmRandFloat(0, 1);

	// ****************************************** Observer UI2,2 *******************************************
	//AI Level = 10.000000
	int RandomESOC = rmRandInt(1,2);
	if (rmGetPlayerName(i) =="ESOC" || (rmGetPlayerCiv(cNumberNonGaiaPlayers) == 20 && rmGetHomeCityLevel(cNumberNonGaiaPlayers) == 10.000000) || (rmGetPlayerCiv(cNumberNonGaiaPlayers) == 20 && rmGetHomeCityLevel(cNumberNonGaiaPlayers) == 80.000000))
		{
			if (cNumberNonGaiaPlayers == 3 || cNumberNonGaiaPlayers == 5 || cNumberNonGaiaPlayers == 7)
 			{
			rmPlacePlayer(cNumberNonGaiaPlayers,0.5,0.5);
				if ( cNumberTeams == 3 )
				{
					if ( RandomESOC == 1 )
					{
					rmPlacePlayer(1,0.75,0.75);
					rmPlacePlayer(2,0.20,0.43);
					}
					else
					{
					rmPlacePlayer(1,0.20,0.43);
					rmPlacePlayer(2,0.75,0.75);
					}
				}
			}
		}
	// ********************************************** Default **********************************************

	if ( cNumberTeams == 2 )
	{
		if (PlayerNumType == 2)
		{
			if ( OneVOnePlacement < 0.5)
				{
					if ((cNumberNonGaiaPlayers / cNumberTeams) == 3 || (cNumberNonGaiaPlayers / cNumberTeams) == 3.5 || (cNumberNonGaiaPlayers / cNumberTeams) == 4) 
						{
						rmSetPlacementTeam(0);
						rmPlacePlayersLine(0.20, 0.58, 0.20, 0.73, 0, 0.0);
						rmSetPlacementTeam(1);
						rmPlacePlayersLine(0.80, 0.80, 0.60, 0.85, 0, 0.0);
						}
					else
						{
						rmSetPlacementTeam(0);
						rmPlacePlayersLine(0.20, 0.43, 0.20, 0.58, 0, 0.0);
						rmSetPlacementTeam(1);
						rmPlacePlayersLine(0.75, 0.75, 0.60, 0.85, 0, 0.0);
						}
				}
				else
					{
					if ((cNumberNonGaiaPlayers / cNumberTeams) == 3 || (cNumberNonGaiaPlayers / cNumberTeams) == 3.5  || (cNumberNonGaiaPlayers / cNumberTeams) == 4)
						{
						rmSetPlacementTeam(0);
						rmPlacePlayersLine(0.80, 0.80, 0.60, 0.85, 0, 0.0);
						rmSetPlacementTeam(1);
						rmPlacePlayersLine(0.20, 0.58, 0.20, 0.73, 0, 0.0);
						}
					else
						{
						rmSetPlacementTeam(0);
						rmPlacePlayersLine(0.75, 0.75, 0.60, 0.85, 0, 0.0);
						rmSetPlacementTeam(1);
						rmPlacePlayersLine(0.20, 0.43, 0.20, 0.58, 0, 0.0);
						}
				}
		}
	}
	else
		{
			if (cNumberNonGaiaPlayers == 3 )
				{
				if ( OneVOnePlacement > 0.5)
					{
					rmSetPlacementTeam(0);
					rmPlacePlayersLine(0.20, 0.43, 0.20, 0.58, 0, 0.0);
					rmSetPlacementTeam(1);
					rmPlacePlayersLine(0.75, 0.75, 0.60, 0.85, 0, 0.0);
					}
				else
					{
					rmSetPlacementTeam(0);
					rmPlacePlayersLine(0.75, 0.75, 0.60, 0.85, 0, 0.0);
					rmSetPlacementTeam(1);
					rmPlacePlayersLine(0.20, 0.43, 0.20, 0.58, 0, 0.0);
					}
				rmSetPlacementTeam(2);
				rmPlacePlayersLine(0.20, 0.70, 0.25, 0.75, 0, 0.0);
				}
				else
				{
				//Line......................................................................................
				int TeamLocation = rmRandInt(rmRandInt(7,8),rmRandInt(9,10));
				float Team1A = 0.70;	float Team1B = 0.80;	float Team1C = 0.65;	float Team1D = 0.85;
				float Team2A = 0.20;	float Team2B = 0.43;	float Team2C = 0.20;	float Team2D = 0.58;
				float Team3A = 0.20;	float Team3B = 0.70;	float Team3C = 0.25;	float Team3D = 0.75;
				float Team4A = 0.40;	float Team4B = 0.30;	float Team4C = 0.50;	float Team4D = 0.40;
				float Team5A = 0.70;	float Team5B = 0.65;	float Team5C = 0.60;	float Team5D = 0.55;
				float Team6A = 0.50;	float Team6B = 0.80;	float Team6C = 0.60;	float Team6D = 0.80;
				float Team7A = 0.90;	float Team7B = 0.65;	float Team7C = 0.80;	float Team7D = 0.80;
				float Team8A = 0.30;	float Team8B = 0.60;	float Team8C = 0.40;	float Team8D = 0.50;
					//4321&8765
					if (TeamLocation == 7)
					{
					Team1A = 0.40;	Team1B = 0.30;	Team1C = 0.50;	Team1D = 0.40;
					Team2A = 0.20;	Team2B = 0.70;	Team2C = 0.25;	Team2D = 0.75;
					Team3A = 0.20;	Team3B = 0.43;	Team3C = 0.20;	Team3D = 0.58;
					Team4A = 0.70;	Team4B = 0.80;	Team4C = 0.65;	Team4D = 0.85;
					Team5A = 0.30;	Team5B = 0.60;	Team5C = 0.40;	Team5D = 0.50;
					Team6A = 0.90;	Team6B = 0.65;	Team6C = 0.80;	Team6D = 0.80;
					Team7A = 0.50;	Team7B = 0.80;	Team7C = 0.60;	Team7D = 0.80;
					Team8A = 0.70;	Team8B = 0.65;	Team8C = 0.60;	Team8D = 0.55;
					}
					//2413&6857
					if (TeamLocation == 8)
					{
					Team1A = 0.20;	Team1B = 0.43;	Team1C = 0.20;	Team1D = 0.58;
					Team2A = 0.40;	Team2B = 0.30;	Team2C = 0.50;	Team2D = 0.40;
					Team3A = 0.70;	Team3B = 0.80;	Team3C = 0.65;	Team3D = 0.85;
					Team4A = 0.20;	Team4B = 0.70;	Team4C = 0.25;	Team4D = 0.75;
					Team5A = 0.50;	Team5B = 0.80;	Team5C = 0.60;	Team5D = 0.80;
					Team6A = 0.30;	Team6B = 0.60;	Team6C = 0.40;	Team6D = 0.50;
					Team7A = 0.70;	Team7B = 0.65;	Team7C = 0.60;	Team7D = 0.55;
					Team8A = 0.90;	Team8B = 0.65;	Team8C = 0.80;	Team8D = 0.80;
					}
					//3142&7586
					if (TeamLocation == 9)
					{
					Team1A = 0.20;	Team1B = 0.43;	Team1C = 0.20;	Team1D = 0.58;
					Team2A = 0.40;	Team2B = 0.30;	Team2C = 0.50;	Team2D = 0.40;
					Team3A = 0.70;	Team3B = 0.80;	Team3C = 0.65;	Team3D = 0.85;
					Team4A = 0.20;	Team4B = 0.70;	Team4C = 0.25;	Team4D = 0.75;
					Team5A = 0.50;	Team5B = 0.80;	Team5C = 0.60;	Team5D = 0.80;
					Team6A = 0.30;	Team6B = 0.60;	Team6C = 0.40;	Team6D = 0.50;
					Team7A = 0.70;	Team7B = 0.65;	Team7C = 0.60;	Team7D = 0.55;
					Team8A = 0.90;	Team8B = 0.65;	Team8C = 0.80;	Team8D = 0.80;
					}
					//1234&5678
					if (TeamLocation == 10)
					{
					Team1A = 0.70;	Team1B = 0.80;	Team1C = 0.65;	Team1D = 0.85;
					Team2A = 0.20;	Team2B = 0.43;	Team2C = 0.20;	Team2D = 0.58;
					Team3A = 0.20;	Team3B = 0.70;	Team3C = 0.25;	Team3D = 0.75;
					Team4A = 0.40;	Team4B = 0.30;	Team4C = 0.50;	Team4D = 0.40;
					Team5A = 0.70;	Team5B = 0.65;	Team5C = 0.60;	Team5D = 0.55;
					Team6A = 0.50;	Team6B = 0.80;	Team6C = 0.60;	Team6D = 0.80;
					Team7A = 0.90;	Team7B = 0.65;	Team7C = 0.80;	Team7D = 0.80;
					Team8A = 0.30;	Team8B = 0.60;	Team8C = 0.40;	Team8D = 0.50;
					}
				rmSetPlacementTeam(0);
				rmPlacePlayersLine(Team1A, Team1B, Team1C, Team1D, 0, 1.0);
				rmSetPlacementTeam(1);
				rmPlacePlayersLine(Team2A, Team2B, Team2C, Team2D, 0, 1.0);
				rmSetPlacementTeam(2);
				rmPlacePlayersLine(Team3A, Team3B, Team3C, Team3D, 0, 1.0);
				rmSetPlacementTeam(3);
				rmPlacePlayersLine(Team4A, Team4B, Team4C, Team4D, 0, 1.0);
				rmSetPlacementTeam(4);
				rmPlacePlayersLine(Team5A, Team5B, Team5C, Team5D, 0, 1.0);
				rmSetPlacementTeam(5);
				rmPlacePlayersLine(Team6A, Team6B, Team6C, Team6D, 0, 1.0);
				rmSetPlacementTeam(6);
				rmPlacePlayersLine(Team7A, Team7B, Team7C, Team7D, 0, 1.0);
				rmSetPlacementTeam(7);
				rmPlacePlayersLine(Team8A, Team8B, Team8C, Team8D, 0, 1.0);
//				rmSetPlacementSection(0.6, 0.15);
//				rmPlacePlayersSquare(0.3, 0.3, 0);
//				rmPlacePlayersCircular(0.39, 0.39, 0.0);
//				rmPlacePlayersCircular(0.39, 0.39, rmDegreesToRadians(360.0));
//				rmPlacePlayersCircular(0.39, 0.39, rmDegreesToRadians(6.0));
				}
		}

	// *****************************************************************************************************

	// Text
	rmSetStatusText("",0.25);

	// ****************************************** TRADE ROUTE **********************************************
	
	int tradeRouteID = rmCreateTradeRoute();
	int socketID=rmCreateObjectDef("sockets to dock Trade Posts");
	rmAddObjectDefItem(socketID, "SocketTradeRoute", 1, 0.0);
	rmSetObjectDefAllowOverlap(socketID, true);
	rmSetObjectDefMinDistance(socketID, 0.0);
	rmSetObjectDefMaxDistance(socketID, 6.0);
	rmAddObjectDefConstraint(socketID, avoidSea);

	int tpvariation = rmRandInt(0,1);
	float socket01 = 0.10;
	float socket02 = 0.28;
	float socket03 = 0.43;
	float socket04 = 0.69;
	float socket05 = 0.90;
	float socketB01 = 0.10;
	float socketB02 = 0.28;
	float socketB03 = 0.41;
	float socketB04 = 0.69;
	float socketC01 = 0.10;
	float socketC02 = 0.43;
	float socketC03 = 0.69;
	int socketcount = rmRandInt(rmRandInt(3,4),5);

	if (tpvariation > 0.5)
	{	//South Start
		rmSetObjectDefTradeRouteID(socketID, tradeRouteID);
		rmAddTradeRouteWaypoint(tradeRouteID, 0.00, 0.52);
		rmAddTradeRouteWaypoint(tradeRouteID, 0.20, 0.51);
		rmAddTradeRouteWaypoint(tradeRouteID, 0.40, 0.40);
		rmAddTradeRouteWaypoint(tradeRouteID, 0.55, 0.45);
		rmAddTradeRouteWaypoint(tradeRouteID, 0.68, 0.68);
		rmAddTradeRouteWaypoint(tradeRouteID, 0.80, 0.65);
		rmAddTradeRouteWaypoint(tradeRouteID, 1.00, 0.50);
		socket01 = 0.10;
		socket02 = 0.28;
		socket03 = 0.45;
		socket05 = 0.92;
		socketB01 = 0.15;
		socketB02 = 0.29;
		socketB03 = 0.55;
		socketB04 = 0.75;
		socketC01 = 0.20;
		socketC02 = 0.43;
		socketC03 = 0.69;
	}
	else
	{	//North Start
		rmSetObjectDefTradeRouteID(socketID, tradeRouteID);
		rmAddTradeRouteWaypoint(tradeRouteID, 1.00, 0.50); 
		rmAddTradeRouteWaypoint(tradeRouteID, 0.80, 0.65); 
		rmAddTradeRouteWaypoint(tradeRouteID, 0.68, 0.68); 
		rmAddTradeRouteWaypoint(tradeRouteID, 0.55, 0.45); 
		rmAddTradeRouteWaypoint(tradeRouteID, 0.40, 0.40); 
		rmAddTradeRouteWaypoint(tradeRouteID, 0.20, 0.51); 
		rmAddTradeRouteWaypoint(tradeRouteID, 0.00, 0.52); 
		socket01 = 0.08;
		socket02 = 0.22;
		socket03 = 0.55;
		socket05 = 0.90;
		socketB01 = 0.22;
		socketB02 = 0.44;
		socketB03 = 0.69;
		socketB04 = 0.90;
		socketC01 = 0.22;
		socketC02 = 0.55;
		socketC03 = 0.80;
	}

	bool placedTradeRouteA = rmBuildTradeRoute(tradeRouteID, "water");
//	if(placedTradeRouteA == false)
//	rmEchoError("Failed to place trade route 1");
//	rmSetObjectDefTradeRouteID(socketID, tradeRouteID);
	vector	socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, 0.00);
	if (socketcount == 3)
	{
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socketC01);
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socketC02); 
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socketC03); 
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
	}
	if (socketcount == 4)
	{
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socketB01);
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socketB02); 
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socketB03); 
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socketB04); 
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
	}
	if (socketcount == 5)
	{
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socket01);
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socket02); 
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socket03); 
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socket04); 
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
		socketLoc = rmGetTradeRouteWayPoint(tradeRouteID, socket05);
		rmPlaceObjectDefAtPoint(socketID, 0, socketLoc);
	}
	
	// *************************************************************************************************************
   	
	// ******************************************* Trigger Unit ****************************************************

	int PlantationID= rmCreateObjectDef("Crate Plantation"); 
	rmAddObjectDefItem(PlantationID, "Plantation", 1, 12.0);
	rmSetObjectDefMinDistance(PlantationID, 0.0);
	rmSetObjectDefMaxDistance(PlantationID, 16);
	if ( TC1 == 7 )
		{
		rmPlaceObjectDefAtLoc(PlantationID,, 0, 0.07, 0.62,1);
		}
		else
		{
		rmPlaceObjectDefAtLoc(PlantationID,, 0, 0.28, 0.86,1);
		}

	int Arsenal= rmCreateObjectDef("Crate Arsenal"); 
	rmAddObjectDefItem(Arsenal, "Arsenal", 1, 16.0);
	rmSetObjectDefMinDistance(Arsenal, 0.0);
	rmSetObjectDefMaxDistance(Arsenal, 16);
	if ( TC1 == 7 )
		{
		rmPlaceObjectDefAtLoc(Arsenal,, 0, 0.07, 0.59,1);
		}
		else
		{
		rmPlaceObjectDefAtLoc(Arsenal,, 0, 0.28, 0.85,1);
		}

	int Coureur1ID= rmCreateObjectDef("Coureur"); 
	rmAddObjectDefItem(Coureur1ID, "ypHCChineseFarmer", 1, 5.0);
	rmSetObjectDefMinDistance(Coureur1ID, 0.0);
	rmSetObjectDefMaxDistance(Coureur1ID, 16);
	if ( TC1 == 7 )
		{
		rmPlaceObjectDefAtLoc(Coureur1ID,, 0, 0.07, 0.61,1);
		}
		else
		{
		rmPlaceObjectDefAtLoc(Coureur1ID,, 0, 0.32, 0.89,1);
		}

	int Coureur2ID= rmCreateObjectDef("Coureur2"); 
	rmAddObjectDefItem(Coureur2ID, "ypHCChineseFarmer", 1, 8.0);
	rmSetObjectDefMinDistance(Coureur2ID, 0.0);
	rmSetObjectDefMaxDistance(Coureur2ID, 16);
	if ( TC1 == 7 )
		{
		rmPlaceObjectDefAtLoc(Coureur2ID,, 0, 0.06, 0.61,1);
		}
		else
		{
		rmPlaceObjectDefAtLoc(Coureur2ID,, 0, 0.31, 0.89,1);
		}

	int Coureur3ID= rmCreateObjectDef("Coureur3"); 
	rmAddObjectDefItem(Coureur3ID, "ypHCChineseFarmer", 1, 7.0);
	rmSetObjectDefMinDistance(Coureur3ID, 0.0);
	rmSetObjectDefMaxDistance(Coureur3ID, 16);
	if ( TC1 == 7 )
		{
		rmPlaceObjectDefAtLoc(Coureur3ID,, 0, 0.06, 0.62,1);
		}
		else
		{
		rmPlaceObjectDefAtLoc(Coureur3ID,, 0, 0.34, 0.87,1);
		}

	int Settler1ID= rmCreateObjectDef("Settler"); 
	rmAddObjectDefItem(Settler1ID, "ypHCChineseFarmer", 1, 3.0);
	rmSetObjectDefMinDistance(Settler1ID, 0.0);
	rmSetObjectDefMaxDistance(Settler1ID, 16);
	if ( TC1 == 7 )
		{
		rmPlaceObjectDefAtLoc(Settler1ID,, 0, 0.06, 0.63,1);
		}
		else
		{
		rmPlaceObjectDefAtLoc(Settler1ID,, 0, 0.33, 0.86,1);
		}

	int Settler2ID= rmCreateObjectDef("Settler2"); 
	rmAddObjectDefItem(Settler2ID, "ypHCChineseFarmer", 1, 6.0);
	rmSetObjectDefMinDistance(Settler2ID, 0.0);
	rmSetObjectDefMaxDistance(Settler2ID, 16);
	if ( TC1 == 7 )
		{
		rmPlaceObjectDefAtLoc(Settler2ID,, 0, 0.08, 0.62,1);
		}
		else
		{
		rmPlaceObjectDefAtLoc(Settler2ID,, 0, 0.30, 0.86,1);
		}

	//Town2

	int Shrine2= rmCreateObjectDef("Create Shrine2"); 
	rmAddObjectDefItem(Shrine2, "ypShrineJapanese", 1, 12.0);
	rmSetObjectDefMinDistance(Shrine2, 0.0);
	rmSetObjectDefMaxDistance(Shrine2, 16);
	if ( TC2 == 9 )
		{
		rmAddGroupingConstraint(Shrine2,avoidSea2);
		rmPlaceObjectDefAtLoc(Shrine2,, 0, 0.87, 0.32,1);
		}
		else
		{
		rmAddObjectDefConstraint(Shrine2, avoidTownCenter);
		rmPlaceObjectDefAtLoc(Shrine2,, 0, 0.56, 0.90,1);
		}

	int Shrine1= rmCreateObjectDef("Create Shrine1"); 
	rmAddObjectDefItem(Shrine1, "ypShrineJapanese", 1, 16.0);
	rmSetObjectDefMinDistance(Shrine1, 0.0);
	rmSetObjectDefMaxDistance(Shrine1, 16);
	if ( TC2 == 9 )
		{
		rmAddGroupingConstraint(Shrine1,avoidSea2);
		rmPlaceObjectDefAtLoc(Shrine1,, 0, 0.87, 0.38,1);
		}
		else
		{
		rmAddObjectDefConstraint(Shrine1, avoidTownCenter);
		rmPlaceObjectDefAtLoc(Shrine1,, 0, 0.55, 0.91,1);
		}

	int SettlerAsian2= rmCreateObjectDef("Create SettlerAsian2"); 
	rmAddObjectDefItem(SettlerAsian2, "ypHCChineseFarmer", 1, 8.0);
	rmSetObjectDefMinDistance(SettlerAsian2, 0.0);
	rmSetObjectDefMaxDistance(SettlerAsian2, 16);
	if ( TC2 == 9 )
		{
		rmAddGroupingConstraint(SettlerAsian2,avoidSea2);
		rmPlaceObjectDefAtLoc(SettlerAsian2,, 0, 0.88, 0.37,1);
		}
		else
		{
		rmAddObjectDefConstraint(SettlerAsian2, avoidTownCenter);
		rmPlaceObjectDefAtLoc(SettlerAsian2,, 0, 0.54, 0.92,1);
		}

	int SettlerAsian1= rmCreateObjectDef("Create SettlerAsian1"); 
	rmAddObjectDefItem(SettlerAsian1, "ypHCChineseWoman", 1, 8.0);
	rmSetObjectDefMinDistance(SettlerAsian1, 0.0);
	rmSetObjectDefMaxDistance(SettlerAsian1, 16);
	if ( TC2 == 9 )
		{
		rmAddGroupingConstraint(SettlerAsian1,avoidSea2);
		rmPlaceObjectDefAtLoc(SettlerAsian1,, 0, 0.88, 0.35,1);
		}
		else
		{
		rmAddObjectDefConstraint(SettlerAsian1, avoidTownCenter);
		rmPlaceObjectDefAtLoc(SettlerAsian1,, 0, 0.53, 0.91,1);
		}

	int SettlerJapanese1= rmCreateObjectDef("Create SettlerJapanese1"); 
	rmAddObjectDefItem(SettlerJapanese1, "ypHCJapanesePeasant", 1, 8.0);
	rmSetObjectDefMinDistance(SettlerJapanese1, 0.0);
	rmSetObjectDefMaxDistance(SettlerJapanese1, 16);
		if ( TC2 == 9 )
		{
		rmAddGroupingConstraint(SettlerJapanese1,avoidSea2);
		rmPlaceObjectDefAtLoc(SettlerJapanese1,, 0, 0.87, 0.35,1);
		}
		else
		{
		rmAddObjectDefConstraint(SettlerJapanese1, avoidTownCenter);
		rmPlaceObjectDefAtLoc(SettlerJapanese1,, 0, 0.54, 0.91,1);
		}

	int SettlerJapanese2= rmCreateObjectDef("Create SettlerJapanese2"); 
	rmAddObjectDefItem(SettlerJapanese2, "ypHCJapaneseStreetPerformer", 1, 8.0);
	rmSetObjectDefMinDistance(SettlerJapanese2, 0.0);
	rmSetObjectDefMaxDistance(SettlerJapanese2, 16);
		if ( TC2 == 9 )
		{
		rmPlaceObjectDefAtLoc(SettlerJapanese2,, 0, 0.83, 0.35,1);
		rmAddGroupingConstraint(SettlerJapanese2,avoidSea2);
		}
		else
		{
		rmAddObjectDefConstraint(SettlerJapanese2, avoidTownCenter);
		rmPlaceObjectDefAtLoc(SettlerJapanese2,, 0, 0.54, 0.89,1);
		}

	int RicePaddy= rmCreateObjectDef("Create RicePaddy"); 
	rmAddObjectDefItem(RicePaddy, "ypRicePaddy", 1, 8.0);
	rmSetObjectDefMinDistance(RicePaddy, 0.0);
	rmSetObjectDefMaxDistance(RicePaddy, 16);
	if ( TC2 == 9 )
		{
		rmPlaceObjectDefAtLoc(RicePaddy,, 0, 0.85, 0.35,1);
		rmAddGroupingConstraint(RicePaddy,avoidSea2);
		}
		else
		{
		rmAddObjectDefConstraint(RicePaddy, avoidTownCenter);
		rmPlaceObjectDefAtLoc(RicePaddy,, 0, 0.53, 0.88,1);
		}

	// *************************************************************************************************************

	// Text
	rmSetStatusText("",0.30);

	// **************************************** NATURE DESIGN & AREAS **********************************************
	
	// Players area
	for (i=1; < cNumberNonGaiaPlayers)
	{
	int playerareaID = rmCreateArea("playerarea"+i);
	rmSetPlayerArea(i, playerareaID);
	rmSetAreaSize(playerareaID, 0.05, 0.05);
	rmSetAreaCoherence(playerareaID, 1.0);
	rmSetAreaWarnFailure(playerareaID, false);
//	rmSetAreaTerrainType(playerareaID, "yellow_river\grass3_yellow_riv");
	rmSetAreaLocPlayer(playerareaID, i);
	rmBuildArea(playerareaID);
	int avoidPlayerArea = rmCreateAreaDistanceConstraint("avoid player area "+i, playerareaID, 18.0);
	int stayPlayerArea = rmCreateAreaMaxDistanceConstraint("stay player area "+i, playerareaID, 0.0);
	}
	
	int avoidPlayerArea1 = rmConstraintID("avoid player area 1");
	int avoidPlayerArea2 = rmConstraintID("avoid player area 2");
	int stayPlayerArea1 = rmConstraintID("stay player area 1");
	int stayPlayerArea2 = rmConstraintID("stay player area 2");
	
	// Green hill zone  
	int hillNorthwestID=rmCreateArea("northwest hills");
	rmSetAreaSize(hillNorthwestID, 0.24, 0.24);
	rmSetAreaWarnFailure(hillNorthwestID, false);
	rmSetAreaMix(hillNorthwestID, "yellow_river_b");
	rmSetAreaTerrainType(hillNorthwestID, "yellow_river\forest_yellow_riv");
	rmAddAreaTerrainLayer(hillNorthwestID, "yellow_river\grass1_yellow_riv", 0, 2);
//	rmAddAreaTerrainLayer(hillNorthwestID, "yellow_river\stone3_yellow_riv", 4, 10);
	rmSetAreaElevationType(hillNorthwestID, cElevTurbulence);
	rmSetAreaElevationVariation(hillNorthwestID, 4.0);
	rmSetAreaBaseHeight(hillNorthwestID, 10);
	rmSetAreaElevationMinFrequency(hillNorthwestID, 0.05);
	rmSetAreaElevationOctaves(hillNorthwestID, 3);
	rmSetAreaElevationPersistence(hillNorthwestID, 0.5);      
//	rmSetAreaElevationNoiseBias(hillNorthwestID, 0.5);
//	rmSetAreaElevationEdgeFalloffDist(hillNorthwestID, 20.0);
	rmSetAreaCoherence(hillNorthwestID, 0.7);
	rmSetAreaSmoothDistance(hillNorthwestID, 8);
	rmSetAreaLocation(hillNorthwestID, 0.5, 0.88);
	rmSetAreaEdgeFilling(hillNorthwestID, 5);
	rmAddAreaInfluenceSegment(hillNorthwestID, 0.0, 0.85, 1.0, 0.85);
//	rmSetAreaHeightBlend(hillNorthwestID, 1.9);
	rmSetAreaObeyWorldCircleConstraint(hillNorthwestID, false);
	rmBuildArea(hillNorthwestID);
		
	int avoidNW = rmCreateAreaDistanceConstraint("avoid nw", hillNorthwestID, 2.0);
	int stayNW = rmCreateAreaMaxDistanceConstraint("stay nw", hillNorthwestID, 0.0);
	
	// ********************************************* NATIVE ************************************************

	int shaolinID = rmCreateGrouping("shaolin A", "native shaolin temple mongol 04");
	rmSetGroupingMinDistance(shaolinID, 0.0);
	rmSetGroupingMaxDistance(shaolinID, rmXFractionToMeters(0.05));
	rmPlaceGroupingAtLoc(shaolinID, 0,0.40,0.80);
//	rmAddAreaToClass(shaolinID,rmClassID("natives"));
	rmAddGroupingConstraint(shaolinID, avoidImpassableLandMed);
	rmAddGroupingConstraint(shaolinID, avoidTradeRouteShort);
	rmAddGroupingConstraint(shaolinID, avoidTradeRouteSocket);

	int ZenID = rmCreateGrouping("Zen A", "native zen temple ceylon 04");
	rmSetGroupingMinDistance(ZenID, 0.0);
	rmSetGroupingMaxDistance(ZenID,rmXFractionToMeters(0.05));
//	rmAddAreaToClass(ZenID,rmClassID("natives"));
	rmAddGroupingConstraint(ZenID, avoidImpassableLandMed);
	rmAddGroupingConstraint(ZenID, avoidTradeRouteShort);
	rmAddGroupingConstraint(ZenID, avoidTradeRouteSocket);
	rmPlaceGroupingAtLoc(ZenID, 0,0.48,0.62);

	int JesuitID = rmCreateGrouping("Jesuit A", "native jesuit mission borneo 03");
	rmSetGroupingMinDistance(JesuitID, 0.0);
	rmSetGroupingMaxDistance(JesuitID, rmXFractionToMeters(0.05));
//	rmAddAreaToClass(JesuitID,rmClassID("natives"));
	rmAddGroupingConstraint(JesuitID, avoidImpassableLandMed);
	rmAddGroupingConstraint(JesuitID, avoidTradeRouteShort);
	rmAddGroupingConstraint(JesuitID, avoidTradeRouteSocket);
	rmPlaceGroupingAtLoc(JesuitID, 0,0.60,0.40);

	// *******************************************************************************************************
	
	// Text
	rmSetStatusText("",0.35);

	// *********************************************** Cliff *************************************************
	// Cliffs
/*
	int cliffcount = 6; 
	
	for (i= 0; < cliffcount)
	{
		int cliffID = rmCreateArea("cliff"+i);
		rmAddAreaToClass(cliffID, rmClassID("Cliffs"));
		rmSetAreaSize(cliffID, rmAreaTilesToFraction(360), rmAreaTilesToFraction(360));  
		rmSetAreaMinBlobs(cliffID, 1);
		rmSetAreaMaxBlobs(cliffID, 1);
//		rmSetAreaMinBlobDistance(cliffID, 4.0);
//		rmSetAreaMaxBlobDistance(cliffID, 4.0);
		rmSetAreaWarnFailure(cliffID, true);
		rmSetAreaObeyWorldCircleConstraint(cliffID, false);
		rmSetAreaCliffType(cliffID, "texas grass"); // new england inland grass
		rmSetAreaCliffPainting(cliffID, false, false, true, 0.1 , true); //  paintGround,  paintOutsideEdge,  paintSide,  minSideHeight,  paintInsideEdge
	//	rmSetAreaTerrainType(cliffID, "pampas\groundforest_pam", 0, 0);
		rmSetAreaCliffEdge(cliffID, 1, rmRandFloat(0.50, 0.50) , 0.0, 0.0, 1); // rmRandFloat(0.24, 0.28)
	//	rmSetAreaCliffEdge(cliffID, 1, rmRandFloat(0.28, 0.28) , 0.0, 0.0, 1); // rmRandFloat(0.24, 0.28)
		rmSetAreaCliffHeight(cliffID, 3.5, 0.2, 0.4); 
		rmSetAreaHeightBlend(cliffID, 2);
		rmSetAreaCoherence(cliffID, 0.8);
		rmSetAreaSmoothDistance(cliffID, 10);
		rmAddAreaConstraint (cliffID, avoidCliff);
		rmAddAreaConstraint (cliffID, avoidEdge);	
//		rmAddAreaConstraint(cliffID, avoidNativesFar);
		rmAddAreaConstraint(cliffID, avoidTradeRouteSocket);
		rmAddAreaConstraint(cliffID, avoidTradeRouteShort);
		rmAddAreaConstraint (cliffID, avoidPlayerArea1);
		rmAddAreaConstraint (cliffID, avoidPlayerArea2);
		rmAddAreaConstraint (cliffID, avoidNW);
//		rmAddAreaConstraint (cliffID, avoidSE);
		rmAddAreaConstraint (cliffID, avoidAreaA);
		rmAddAreaConstraint (cliffID, avoidAreaB);
		rmAddAreaConstraint (cliffID, avoidAreaC);
		rmAddAreaConstraint (cliffID, avoidAreaD);
		rmAddAreaConstraint (cliffID, avoidSea);
		rmBuildArea(cliffID);		
	}
*/
	// *******************************************************************************************************

/*	// Terrain patch1
	for (i=0; < 60)
      {
        int patchID = rmCreateArea("first patch "+i);
        rmSetAreaWarnFailure(patchID, false);
        rmSetAreaSize(patchID, rmAreaTilesToFraction(50), rmAreaTilesToFraction(50));
	rmAddAreaToClass(patchID, classPatch);
//	rmSetAreaMix(patchID, "pampas_grass"); //pampas_grass
        rmSetAreaTerrainType(patchID, "yellow_river\stone2_yellow_riv");
        rmSetAreaMinBlobs(patchID, 4);
        rmSetAreaMaxBlobs(patchID, 5);
        rmSetAreaMinBlobDistance(patchID, 16.0);
        rmSetAreaMaxBlobDistance(patchID, 40.0);
        rmSetAreaCoherence(patchID, 0.0);
	rmAddAreaConstraint(patchID, avoidImpassableLandShort);
	rmAddAreaConstraint(patchID, avoidPatch);
	rmAddAreaConstraint (patchID, avoidNW);
        rmBuildArea(patchID); 
    }
*/
	// Terrain patch NW
	for (i=0; <18)
      {
        int NWpatchID = rmCreateArea("NW patch "+i);
        rmSetAreaWarnFailure(NWpatchID, false);
	rmSetAreaObeyWorldCircleConstraint(NWpatchID, false);
        rmSetAreaSize(NWpatchID, rmAreaTilesToFraction(50), rmAreaTilesToFraction(60));
	rmAddAreaToClass(NWpatchID, classPatch2);
//	rmSetAreaMix(NWpatchID, "pampas_grass"); //pampas_grass
        rmSetAreaTerrainType(NWpatchID, "yellow_river\grass1_yellow_riv");
        rmSetAreaMinBlobs(NWpatchID, 3);
        rmSetAreaMaxBlobs(NWpatchID, 5);
        rmSetAreaMinBlobDistance(NWpatchID, 16.0);
        rmSetAreaMaxBlobDistance(NWpatchID, 40.0);
        rmSetAreaCoherence(NWpatchID, 0.0);
//		rmAddAreaConstraint(NWpatchID, avoidImpassableLandShort);
		rmAddAreaConstraint(NWpatchID, avoidPatch2);
		rmAddAreaConstraint (NWpatchID, stayNW);
        rmBuildArea(NWpatchID); 
    }
	
	// *********************************************** Grass ***********************************************
	// Grass
	for (i=0; < 50)
	{
		int GrassID = rmCreateObjectDef("drygrass"+i);
		rmAddObjectDefItem(GrassID, "UnderbrushYellowRiver", rmRandInt(1,1), 4.0); 
		rmSetObjectDefMinDistance(GrassID, 0);
		rmSetObjectDefMaxDistance(GrassID, rmXFractionToMeters(0.6));
		rmAddObjectDefToClass(GrassID, rmClassID("grass"));
		rmAddObjectDefConstraint(GrassID, avoidGrass);
		rmAddObjectDefConstraint(GrassID, avoidImpassableLandShort);
		rmAddObjectDefConstraint(GrassID, avoidTownCenterShort);
		rmAddObjectDefConstraint (GrassID, avoidNW);
		rmPlaceObjectDefAtLoc(GrassID, 0, 0.50, 0.50);
	}
	
	// *****************************************************************************************************	
	
	// *********************************** PLAYER STARTING RESOURCES ***************************************

	// ********************************************** Define ***********************************************

	// Town center & units
	int TCID = rmCreateObjectDef("player TC");
	int startingUnits = rmCreateStartingUnitsObjectDef(5.0);
	int Chi3 = rmRandInt(rmRandInt(1,rmRandInt(2,3)),rmRandInt(4,5));
	if (rmGetNomadStart())
	{
	rmAddObjectDefItem(TCID, "CoveredWagon", 1, 0.0);
	}
	else
	{
	rmAddObjectDefItem(TCID, "TownCenter", 1, 0.0);
	rmAddObjectDefToClass(TCID, classStartingResource);
/*
		if ( cNumberTeams != 2 )
		{
		rmAddObjectDefConstraint(TCID, avoidTradeRouteTown);
		}
*/
//	rmAddObjectDefConstraint(TCID, avoidTradeRouteFar);
//	rmAddObjectDefConstraint(TCID, avoidTownCenterMed);
	}
	rmSetObjectDefMinDistance(TCID, 0.0);
	rmSetObjectDefMaxDistance(TCID, 0.0);
	
	// Starting mines
	int playergoldID = rmCreateObjectDef("player mine");
	rmAddObjectDefItem(playergoldID, "minegold", 1, 0);
	rmSetObjectDefMinDistance(playergoldID, 16.0);
	rmSetObjectDefMaxDistance(playergoldID, 18.0);
	rmAddObjectDefToClass(playergoldID, classStartingResource);
	rmAddObjectDefToClass(playergoldID, classGold);
	rmAddObjectDefConstraint(playergoldID, avoidGoldType);
	rmAddObjectDefConstraint(playergoldID, avoidTradeRoute);
	rmAddObjectDefConstraint(playergoldID, avoidImpassableLand);
	rmAddObjectDefConstraint(playergoldID, avoidNatives);
	rmAddObjectDefConstraint(playergoldID, avoidStartingResources);
	
	// 2nd mine
	int playergold2ID = rmCreateObjectDef("player second mine");
	rmAddObjectDefItem(playergold2ID, "mine", 1, 0);
	rmSetObjectDefMinDistance(playergold2ID, 18.0); //58
	rmSetObjectDefMaxDistance(playergold2ID, 20.0); //62
	rmAddObjectDefToClass(playergold2ID, classStartingResource);
	rmAddObjectDefToClass(playergold2ID, classGold);
	rmAddObjectDefConstraint(playergold2ID, avoidTradeRoute);
	rmAddObjectDefConstraint(playergold2ID, avoidImpassableLand);
	rmAddObjectDefConstraint(playergold2ID, avoidNatives);
	rmAddObjectDefConstraint(playergold2ID, avoidGoldType);
	rmAddObjectDefConstraint(playergold2ID, avoidStartingResources);
	
	// 3nd mine
	int playergold3ID = rmCreateObjectDef("player third mine");
	rmAddObjectDefItem(playergold3ID, "mine", 1, 0);
	rmSetObjectDefMinDistance(playergold3ID, 68.0); //58
	rmSetObjectDefMaxDistance(playergold3ID, 70.0); //62
	rmAddObjectDefToClass(playergold3ID, classStartingResource);
	rmAddObjectDefToClass(playergold3ID, classGold);
	rmAddObjectDefConstraint(playergold3ID, avoidTradeRouteShort);
	rmAddObjectDefConstraint(playergold3ID, avoidTradeRouteSocket);
	rmAddObjectDefConstraint(playergold3ID, avoidImpassableLand);
	rmAddObjectDefConstraint(playergold3ID, avoidNatives);
	rmAddObjectDefConstraint(playergold3ID, avoidGoldTypeFar);
	rmAddObjectDefConstraint(playergold3ID, avoidStartingResources);
	rmAddObjectDefConstraint(playergold3ID, avoidEdgeMore);
	rmAddObjectDefConstraint(playergold3ID, avoidCenterMore);
	
	// Starting trees1
	int playerTree1ID = rmCreateObjectDef("player trees");
	rmAddObjectDefItem(playerTree1ID, "ypTreeYellowRiver", rmRandInt(3,3), 1.0);
	rmSetObjectDefMinDistance(playerTree1ID, 6);
	rmSetObjectDefMaxDistance(playerTree1ID, 12);
	rmAddObjectDefToClass(playerTree1ID, classStartingResource);
//	rmAddObjectDefToClass(playerTree1ID, classForest);
//	rmAddObjectDefConstraint(playerTree1ID, avoidForestMin);
	rmAddObjectDefConstraint(playerTree1ID, avoidTradeRoute);
	rmAddObjectDefConstraint(playerTree1ID, avoidImpassableLand);
//	rmAddObjectDefConstraint(playerTree1ID, avoidStartingResources);
	
	// Starting trees2
	int playerTree2ID = rmCreateObjectDef("player trees2");
	rmAddObjectDefItem(playerTree2ID, "ypTreeYellowRiver", rmRandInt(3,3), 2.0);
	rmSetObjectDefMinDistance(playerTree2ID, 8);
	rmSetObjectDefMaxDistance(playerTree2ID, 14);
	rmAddObjectDefToClass(playerTree2ID, classStartingResource);
//	rmAddObjectDefToClass(playerTree2ID, classForest);
//	rmAddObjectDefConstraint(playerTree2ID, avoidForestMin);
	rmAddObjectDefConstraint(playerTree2ID, avoidTradeRoute);
	rmAddObjectDefConstraint(playerTree2ID, avoidImpassableLand);
//	rmAddObjectDefConstraint(playerTree2ID, avoidStartingResources);
	
	// Starting herd
	int playerherdID = rmCreateObjectDef("starting herd");
	rmAddObjectDefItem(playerherdID, "ypGiantSalamander", rmRandInt(6,8), 4.0);
	rmSetObjectDefMinDistance(playerherdID, 8.0);
	rmSetObjectDefMaxDistance(playerherdID, 12.0);
	rmSetObjectDefCreateHerd(playerherdID, true);
	rmAddObjectDefToClass(playerherdID, classStartingResource);
	rmAddObjectDefConstraint(playerherdID, avoidTradeRoute);
	rmAddObjectDefConstraint(playerherdID, avoidImpassableLand);
	rmAddObjectDefConstraint(playerherdID, avoidNatives);
	rmAddObjectDefConstraint(playerherdID, avoidStartingResourcesShort);
	
	// Starting Berry
	int playerBerryID=rmCreateObjectDef("player berries");
	rmAddObjectDefItem(playerBerryID, "BerryBush", 4, 3.0);
	rmSetObjectDefMinDistance(playerBerryID, 12);
	rmSetObjectDefMaxDistance(playerBerryID, 14);
	rmAddObjectDefToClass(playerBerryID, classStartingResource);
	rmAddObjectDefConstraint(playerBerryID, avoidTradeRoute);
	rmAddObjectDefConstraint(playerBerryID, avoidImpassableLand);

	// (Chinese) Starting Crate 
	int ChineseCrateID=rmCreateObjectDef("Chinese Crate");
		if ( Chi3 == 1 )
			{
			rmAddObjectDefItem(ChineseCrateID, "CrateofWood", 1, 5.0);
			}
		if ( Chi3 == 2 )
			{
			rmAddObjectDefItem(ChineseCrateID, "CrateofFood", 1, 5.0);
			}
		if ( Chi3 == 3 )
			{
			rmAddObjectDefItem(ChineseCrateID, "CrateofCoin", 1, 5.0);
			}
		if ( Chi3 == 4 )
			{
			rmAddObjectDefItem(ChineseCrateID, "Crateofwood", 1, 5.0);
			rmAddObjectDefItem(ChineseCrateID, "CrateofCoin", 1, 5.0);
			}
		if ( Chi3 == 5 )
			{
			rmAddObjectDefItem(ChineseCrateID, "Crateoffood", 1, 5.0);
			rmAddObjectDefItem(ChineseCrateID, "CrateofCoin", 1, 5.0);
			}
	rmSetObjectDefMinDistance(ChineseCrateID, 4);
	rmSetObjectDefMaxDistance(ChineseCrateID, 6);
	rmAddObjectDefToClass(ChineseCrateID, classStartingResource);
	rmAddObjectDefConstraint(ChineseCrateID, avoidTradeRoute);
	rmAddObjectDefConstraint(ChineseCrateID, avoidImpassableLand);

	// (SPCAct3) Starting Hero
	int SPCAct3ID=rmCreateObjectDef("SPCACT3");
	rmAddObjectDefItem(SPCAct3ID, "SPCAmelia", 1, 5.0);
	rmAddObjectDefItem(SPCAct3ID, "SPCCooper", 1, 5.0);
	rmSetObjectDefMinDistance(SPCAct3ID, 18);
	rmSetObjectDefMaxDistance(SPCAct3ID, 22);
	rmAddObjectDefToClass(SPCAct3ID, classStartingResource);
	rmAddObjectDefConstraint(SPCAct3ID, avoidTradeRoute);
	rmAddObjectDefConstraint(SPCAct3ID, avoidImpassableLand);
	
	// (SPCAct3) Starting Crate
	int SPCAct3CrateID=rmCreateObjectDef("SPC Crate");
	rmAddObjectDefItem(SPCAct3CrateID, "Crateoffood", 2, 4.0);
	rmAddObjectDefItem(SPCAct3CrateID, "Crateofwood", 2, 4.0);
	rmSetObjectDefMinDistance(SPCAct3CrateID, 4);
	rmSetObjectDefMaxDistance(SPCAct3CrateID, 6);
	rmAddObjectDefToClass(SPCAct3CrateID, classStartingResource);
	rmAddObjectDefConstraint(SPCAct3CrateID, avoidTradeRoute);
	rmAddObjectDefConstraint(SPCAct3CrateID, avoidImpassableLand);

	// (XPSPC) Starting Crate
	int XPSPCID=rmCreateObjectDef("SPC Country");
	rmAddObjectDefItem(XPSPCID, "SPCXPNathaniel", 1, 5.0);
	rmAddObjectDefItem(XPSPCID, "SPCXPWashington", 1, 5.0);
	rmSetObjectDefMinDistance(XPSPCID, 18);
	rmSetObjectDefMaxDistance(XPSPCID, 22);
	rmAddObjectDefToClass(XPSPCID, classStartingResource);
	rmAddObjectDefConstraint(XPSPCID, avoidTradeRoute);
	rmAddObjectDefConstraint(XPSPCID, avoidImpassableLand);
	rmAddObjectDefConstraint(XPSPCID, avoidStartingResources);
	rmAddObjectDefConstraint(XPSPCID, avoidNatives);
	rmAddObjectDefConstraint(XPSPCID, avoidEdge);
	rmAddObjectDefConstraint(XPSPCID, avoidNugget);

	// 2nd herd
	int playerSaigaID = rmCreateObjectDef("player Saiga");
	rmAddObjectDefItem(playerSaigaID, "ypSaiga", rmRandInt(11,11), 10.0);
	rmSetObjectDefMinDistance(playerSaigaID, 38);
	rmSetObjectDefMaxDistance(playerSaigaID, 40);
	rmSetObjectDefCreateHerd(playerSaigaID, true);
	rmAddObjectDefConstraint(playerSaigaID, avoidTradeRouteSocket);
	rmAddObjectDefConstraint(playerSaigaID, avoidImpassableLandShort);
	rmAddObjectDefConstraint(playerSaigaID, avoidNativesShort);
//	rmAddObjectDefConstraint(playerSaigaID, avoidStartingResources);
	rmAddObjectDefConstraint(playerSaigaID, avoidSaigaShort);
	rmAddObjectDefConstraint(playerSaigaID, avoidIbexShort);
	rmAddObjectDefConstraint(playerSaigaID, avoidCenterMore);
	
	// 3rd herd
	int playerMarcoPoloSheepID = rmCreateObjectDef("player MarcoPoloSheep");
	rmAddObjectDefItem(playerMarcoPoloSheepID, "ypMarcoPoloSheep", rmRandInt(8,8), 8.0);
	rmSetObjectDefMinDistance(playerMarcoPoloSheepID, 48);
	rmSetObjectDefMaxDistance(playerMarcoPoloSheepID, 50);
	rmSetObjectDefCreateHerd(playerMarcoPoloSheepID, true);
	rmAddObjectDefConstraint(playerMarcoPoloSheepID, avoidMarcoPoloSheepFar); 
//	rmAddObjectDefConstraint(playerMarcoPoloSheepID, avoidSaigaShort);
//	rmAddObjectDefConstraint(playerMarcoPoloSheepID, avoidIbexShort);
	rmAddObjectDefConstraint(playerMarcoPoloSheepID, avoidSerowFar);
	rmAddObjectDefConstraint(playerMarcoPoloSheepID, avoidTradeRouteShort);
	rmAddObjectDefConstraint(playerMarcoPoloSheepID, avoidImpassableLandShort);
	rmAddObjectDefConstraint(playerMarcoPoloSheepID, avoidNativesShort);
//	rmAddObjectDefConstraint(playerMarcoPoloSheepID, avoidCenterShort);
//	rmAddObjectDefConstraint(playerMarcoPoloSheepID, avoidStartingResources);
	rmAddObjectDefConstraint(playerMarcoPoloSheepID, avoidEdgeMore);
	
	// Starting treasures
	int playerNuggetID = rmCreateObjectDef("player nugget"); 
	rmAddObjectDefItem(playerNuggetID, "Nugget", 1, 0.0);
	rmSetNuggetDifficulty(1, 1);
	rmSetObjectDefMinDistance(playerNuggetID, 20.0);
	rmSetObjectDefMaxDistance(playerNuggetID, 30.0);
	rmAddObjectDefToClass(playerNuggetID, classStartingResource);
	rmAddObjectDefConstraint(playerNuggetID, avoidTradeRoute);
	rmAddObjectDefConstraint(playerNuggetID, avoidImpassableLand);
	rmAddObjectDefConstraint(playerNuggetID, avoidNatives);
	rmAddObjectDefConstraint(playerNuggetID, avoidStartingResources);
	rmAddObjectDefConstraint(playerNuggetID, avoidNugget);
	rmAddObjectDefConstraint(playerNuggetID, avoidEdge);
	int nugget0count = rmRandInt (2,2); // 1,2

	int OBSUIID = rmCreateObjectDef("ESOC OBSUI Unit");
	rmAddObjectDefItem(OBSUIID, "Minuteman", 1, 20.0);
	rmSetObjectDefMinDistance(OBSUIID, 0);
	rmSetObjectDefMaxDistance(OBSUIID, 40);

	// Text
	rmSetStatusText("",0.40);

	// ************************************************ Place ************************************************
	
	for(i=1; <=cNumberNonGaiaPlayers)
	{
		rmPlaceObjectDefAtLoc(TCID, i, rmPlayerLocXFraction(i), rmPlayerLocZFraction(i));

		vector TCLoc = rmGetUnitPosition(rmGetUnitPlacedOfPlayer(TCID, i));
			rmPlaceObjectDefAtLoc(startingUnits, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playergoldID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playergold2ID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playergold3ID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playerherdID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playerTree1ID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playerTree1ID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playerTree1ID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playerTree2ID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playerTree2ID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playerBerryID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playerSaigaID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playerMarcoPoloSheepID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
			rmPlaceObjectDefAtLoc(playerNuggetID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
/*
			if (rmGetPlayerCiv(i) == 20 || rmGetPlayerCiv(i) ==rmGetCivID("SPCChinese"))
				{
				rmPlaceObjectDefAtLoc(ChineseCrateID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
				}
*/
			if (rmGetPlayerCiv(i) == rmGetCivID("SPCAct3"))
				{
				rmPlaceObjectDefAtLoc(SPCAct3CrateID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
				rmPlaceObjectDefAtLoc(SPCAct3ID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
				}
			if (rmGetPlayerCiv(i) == rmGetCivID("XPSPC"))
				{
				rmPlaceObjectDefAtLoc(SPCAct3CrateID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
				rmPlaceObjectDefAtLoc(XPSPCID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
				}
			if (nugget0count == 2)
			rmPlaceObjectDefAtLoc(playerNuggetID, i, rmXMetersToFraction(xsVectorGetX(TCLoc)), rmZMetersToFraction(xsVectorGetZ(TCLoc)));
	}

	// *******************************************************************************************************
	
	// ********************************************** Mines **************************************************
	
	int goldCount = rmRandInt(3 * (cNumberNonGaiaPlayers - ObsUIPlayer), 3 * (cNumberNonGaiaPlayers - ObsUIPlayer));  // 3,3 
		
	//Mines
	for(i=0; < goldCount)
	{
		int goldID = rmCreateObjectDef("gold"+i);
		rmAddObjectDefItem(goldID, "Mine", 1, 0.0);
		rmSetObjectDefMinDistance(goldID, rmXFractionToMeters(0.12));
		rmSetObjectDefMaxDistance(goldID, rmXFractionToMeters(0.7));
		rmAddObjectDefToClass(goldID, classGold);
		rmAddObjectDefConstraint(goldID, avoidTradeRouteSocketFar);
		rmAddObjectDefConstraint(goldID, avoidTradeRoute);
		rmAddObjectDefConstraint(goldID, avoidImpassableLand);
		rmAddObjectDefConstraint(goldID, avoidNatives);
		rmAddObjectDefConstraint(goldID, avoidGoldVeryFar);
//		rmAddObjectDefConstraint(goldID, Northwestconstraint);
		rmAddObjectDefConstraint(goldID, avoidTownCenterVeryFar);
		rmAddObjectDefConstraint(goldID, avoidEdgeMore);
		rmPlaceObjectDefAtLoc(goldID, 0, 0.50, 0.85);
	}
	
	// *******************************************************************************************************
	
	// ***************************************** Island Resources ********************************************

	int TreeCount = rmRandInt(10,12);//((cNumberNonGaiaPlayers - ObsUIPlayer) * 5)
	int TreeCount2 = rmRandInt(15,20);//((cNumberNonGaiaPlayers - ObsUIPlayer) * 8)

	int TreeTaiwanID = rmCreateObjectDef("TreeTaiwan ");
	rmAddObjectDefItem(TreeTaiwanID, "ypTreeBorneo", TreeCount2, 12.0);
	rmSetObjectDefMinDistance(TreeTaiwanID, 0.0);
	rmSetObjectDefMaxDistance(TreeTaiwanID, rmXFractionToMeters(0.03));
	rmAddGroupingConstraint(TreeTaiwanID, avoidSeaShort);
	rmAddGroupingConstraint(TreeTaiwanID, avoidImpassableLand);
	rmPlaceObjectDefAtLoc(TreeTaiwanID, 0, 0.44, 0.10, 1);

	int HerdTaiwanID = rmCreateObjectDef("HerdTaiwan ");
	rmAddObjectDefItem(HerdTaiwanID, "ypGiantSalamander", 6, 8.0);
	rmSetObjectDefMinDistance(HerdTaiwanID, 0.0);
	rmSetObjectDefMaxDistance(HerdTaiwanID, rmXFractionToMeters(0.05));
	rmAddGroupingConstraint(HerdTaiwanID, avoidSeaShort);
	rmPlaceObjectDefAtLoc(HerdTaiwanID, 0, 0.46, 0.11, 1);

	int NuggetTaiwanID = rmCreateObjectDef("NuggetTaiwan ");
	rmAddObjectDefItem(NuggetTaiwanID, "nugget", 1, 0.0);
	rmSetNuggetDifficulty(4, 4);
	rmSetObjectDefMinDistance(NuggetTaiwanID, 0.0);
	rmSetObjectDefMaxDistance(NuggetTaiwanID, rmXFractionToMeters(0.05));
	rmAddGroupingConstraint(NuggetTaiwanID, avoidSeaShort);
	rmAddGroupingConstraint(NuggetTaiwanID, avoidImpassableLand);
	rmPlaceObjectDefAtLoc(NuggetTaiwanID, 0, 0.45, 0.12, 1);

	int TreeHainanID = rmCreateObjectDef("TreeHainan ");
	rmAddObjectDefItem(TreeHainanID, "ypTreeBorneo", TreeCount, 6.0);
	rmSetObjectDefMinDistance(TreeHainanID, 0.0);
	rmSetObjectDefMaxDistance(TreeHainanID, rmXFractionToMeters(0.05));
	rmAddGroupingConstraint(TreeHainanID, avoidSeaShort);
	rmPlaceObjectDefAtLoc(TreeHainanID, 0, 0.00, 0.32, 1);

	int NuggetHainanID = rmCreateObjectDef("NuggetHainan ");
	rmAddObjectDefItem(NuggetHainanID, "ypNuggetTreeAsian", 1, 0.0);
	rmSetNuggetDifficulty(3, 3);
	rmSetObjectDefMinDistance(NuggetHainanID, 0.0);
	rmSetObjectDefMaxDistance(NuggetHainanID, rmXFractionToMeters(0.05));
	rmAddGroupingConstraint(NuggetHainanID, avoidSeaShort);
	rmPlaceObjectDefAtLoc(NuggetHainanID, 0, 0.00, 0.29, 1);

	int NuggetJapanID = rmCreateObjectDef("NuggetJapan ");
	rmAddObjectDefItem(NuggetJapanID, "nugget", 1, 0.0);
	rmSetNuggetDifficulty(4, 4);
	rmSetObjectDefMinDistance(NuggetJapanID, 0.0);
	rmSetObjectDefMaxDistance(NuggetJapanID, rmXFractionToMeters(0.05));
	rmAddGroupingConstraint(NuggetJapanID, avoidSeaShort);
	rmPlaceObjectDefAtLoc(NuggetJapanID, 0, 0.89, 0.10, 1);

	int TreeJapanID = rmCreateObjectDef("TreeJapan ");
	rmAddObjectDefItem(TreeJapanID, "ypTreeCoastalJapan", TreeCount2, 10.0);
	rmSetObjectDefMinDistance(TreeJapanID, 0.0);
	rmSetObjectDefMaxDistance(TreeJapanID, rmXFractionToMeters(0.10));
	rmAddGroupingConstraint(TreeJapanID, avoidSeaShort);
	rmPlaceObjectDefAtLoc(TreeJapanID, 0, 0.90, 0.10, 1);

	int HerdJapanID = rmCreateObjectDef("HerdJapan ");
	rmAddObjectDefItem(HerdJapanID, "ypGiantSalamander", 6, 8.0);
	rmSetObjectDefMinDistance(HerdJapanID, 0.0);
	rmSetObjectDefMaxDistance(HerdJapanID, rmXFractionToMeters(0.10));
	rmAddGroupingConstraint(HerdJapanID, avoidSeaShort);
	rmPlaceObjectDefAtLoc(HerdJapanID, 0, 0.91, 0.10, 1);

	// *******************************************************************************************************

	// *********************************************** Forest ************************************************

	int dirtforestcount = ((cNumberNonGaiaPlayers - ObsUIPlayer) * 4);
	if(cNumberNonGaiaPlayers >=4) dirtforestcount = ((cNumberNonGaiaPlayers - ObsUIPlayer) * 3);
	if(cNumberNonGaiaPlayers >=6) dirtforestcount = ((cNumberNonGaiaPlayers - ObsUIPlayer) * 2);
	int greenforestcount = ((cNumberNonGaiaPlayers - ObsUIPlayer) * 6);
	if(cNumberNonGaiaPlayers >=4) greenforestcount = ((cNumberNonGaiaPlayers - ObsUIPlayer) * 4);
	if(cNumberNonGaiaPlayers >=6) greenforestcount = ((cNumberNonGaiaPlayers - ObsUIPlayer) * 2);
	int dirtforesttreecount = rmRandInt(5,6);
	
	// Green forests big

	
	// Green forests small
	for (i=1; < greenforestcount)
	{


			int greenforesttreeID = rmCreateObjectDef("dirt forest trees"+i);
			rmAddObjectDefItem(greenforesttreeID, "ypTreeYellowRiver", 5, 5.0);
			rmSetObjectDefMinDistance(greenforesttreeID,  rmXFractionToMeters(0.0));
			rmSetObjectDefMaxDistance(greenforesttreeID,  rmXFractionToMeters(0.5));
			rmAddObjectDefToClass(greenforesttreeID, classForest);
		//	rmAddObjectDefConstraint(greenforesttreeID, avoidForestShort);
			rmAddObjectDefConstraint(greenforesttreeID, avoidImpassableLandShort);
			rmAddAreaConstraint(greenforesttreeID, avoidJapan);
			rmAddAreaConstraint(greenforesttreeID, avoidTree);
			rmAddAreaConstraint(greenforesttreeID, avoidTownCenterVeryFar);
			rmAddAreaConstraint(greenforesttreeID, avoidBuilding);
			rmAddAreaConstraint(greenforesttreeID, avoidTownCenterResourcesshort);
			rmAddAreaConstraint(greenforesttreeID, avoidCoveredWagon);
			rmPlaceObjectDefAtLoc(greenforesttreeID, 0, 0.50, 0.50,7);
	}
			

	for (i=1; < greenforestcount)
	{
			int dirtforesttreeID = rmCreateObjectDef("dirt forest trees"+i);
			rmAddObjectDefItem(dirtforesttreeID, "ypTreeBamboo", 5, 2.0);
			rmSetObjectDefMinDistance(dirtforesttreeID,  rmXFractionToMeters(0.0));
			rmSetObjectDefMaxDistance(dirtforesttreeID,  rmXFractionToMeters(0.5));
			rmAddObjectDefToClass(dirtforesttreeID, classForest);
		//	rmAddObjectDefConstraint(dirtforesttreeID, avoidForestShort);
			rmAddObjectDefConstraint(dirtforesttreeID, avoidImpassableLandShort);
			rmAddAreaConstraint(dirtforesttreeID, avoidJapan);
			rmAddAreaConstraint(dirtforesttreeID, avoidTree);
			rmAddAreaConstraint(dirtforesttreeID, avoidBuilding);
			rmAddAreaConstraint(dirtforesttreeID, avoidTownCenterResourcesshort);
			rmAddAreaConstraint(dirtforesttreeID, avoidCoveredWagon);
			rmPlaceObjectDefAtLoc(dirtforesttreeID, 0, 0.50, 0.50,5);
	}

	// *******************************************************************************************************

	// Text
	rmSetStatusText("",0.45);

	// ************************************************ Herd *************************************************

	int herdcount = (cNumberPlayers - ObsUIPlayer);
	
	for(i=0; < herdcount)
	{
	
		//Ibex
		int IbexID = rmCreateObjectDef("Ibex"+i);
		rmAddObjectDefItem(IbexID, "ypIbex", rmRandInt(11,11), 10.0);
		rmSetObjectDefMinDistance(IbexID, rmXFractionToMeters(0.0));
		rmSetObjectDefMaxDistance(IbexID, rmXFractionToMeters(0.5));
		rmSetObjectDefCreateHerd(IbexID, true);
		rmAddObjectDefConstraint(IbexID, avoidImpassableLandShort);
		rmAddObjectDefConstraint(IbexID, avoidNativesShort);
		rmAddObjectDefConstraint(IbexID, avoidTradeRouteSocket);
		rmAddObjectDefConstraint(IbexID, avoidGoldMin);
		rmAddObjectDefConstraint(IbexID, avoidForestMin); 
		rmAddObjectDefConstraint(IbexID, avoidTownCenterFar);
		rmAddObjectDefConstraint(IbexID, avoidSaigaFar); 
		rmAddObjectDefConstraint(IbexID, avoidMarcoPoloSheepFar); 
		rmAddObjectDefConstraint(IbexID, avoidIbexFar); 
		rmAddObjectDefConstraint(IbexID, avoidSerowFar); 
		rmAddObjectDefConstraint(IbexID, avoidJapan); 
		rmAddObjectDefConstraint(IbexID, avoidTaiwan); 
	//	rmAddObjectDefConstraint(IbexID, avoidEdge);
		
		//Serow
		int SerowID = rmCreateObjectDef("Serow"+i);
		rmAddObjectDefItem(SerowID, "ypSerow", rmRandInt(8,8), 8.0);
		rmSetObjectDefMinDistance(SerowID, rmXFractionToMeters(0.0));
		rmSetObjectDefMaxDistance(SerowID, rmXFractionToMeters(0.5));
		rmSetObjectDefCreateHerd(SerowID, true);
		rmAddObjectDefConstraint(SerowID, avoidImpassableLandShort);
		rmAddObjectDefConstraint(SerowID, avoidNativesShort);
		rmAddObjectDefConstraint(SerowID, avoidTradeRouteSocket);
		rmAddObjectDefConstraint(SerowID, avoidGoldMin);
		rmAddObjectDefConstraint(SerowID, avoidForestMin);
		rmAddObjectDefConstraint(SerowID, avoidTownCenterFar);
		rmAddObjectDefConstraint(SerowID, avoidSaigaFar); 
		rmAddObjectDefConstraint(SerowID, avoidMarcoPoloSheepFar); 
		rmAddObjectDefConstraint(SerowID, avoidIbexFar); 
		rmAddObjectDefConstraint(SerowID, avoidSerowFar); 
		rmAddObjectDefConstraint(SerowID, avoidJapan); 
		rmAddObjectDefConstraint(SerowID, avoidTaiwan); 
	//	rmAddObjectDefConstraint(SerowID, avoidEdge);

		if (i == 0 )
		{
			rmAddObjectDefConstraint(IbexID, staySWHalf);
			rmAddObjectDefConstraint(SerowID, staySWHalf);
		}
		else if (i == 1)
		{
			rmAddObjectDefConstraint(IbexID, stayNEHalf);
			rmAddObjectDefConstraint(SerowID, stayNEHalf);
		}
		if (i < 2)
			rmPlaceObjectDefAtLoc(IbexID, 0, 0.50, 0.50);
		rmPlaceObjectDefAtLoc(IbexID, 0, 0.50, 0.50);
		rmPlaceObjectDefAtLoc(SerowID, 0, 0.50, 0.50);
	}
	
	// *******************************************************************************************************
	
	// Text
	rmSetStatusText("",0.46);

	// ********************************************** Treasure ***********************************************
	
	int nuggetLV4count = (cNumberPlayers - ObsUIPlayer);
	int nuggetLV3count = ((cNumberNonGaiaPlayers - ObsUIPlayer) * 2);
	int nuggetLV2count = ((cNumberNonGaiaPlayers - ObsUIPlayer) * 5);
	
	// Treasures center	

	int Nugget4ID = rmCreateObjectDef("nugget4"); 
	rmAddObjectDefItem(Nugget4ID, "Nugget", 1, 0.0);
	rmSetObjectDefMinDistance(Nugget4ID, 0);
	rmSetObjectDefMaxDistance(Nugget4ID, rmXFractionToMeters(0.6));
	rmAddObjectDefConstraint(Nugget4ID, avoidNuggetFar);
	rmAddObjectDefConstraint(Nugget4ID, avoidNatives);
	rmAddObjectDefConstraint(Nugget4ID, avoidTradeRouteShort);
	rmAddObjectDefConstraint(Nugget4ID, avoidTradeRouteSocket);
	rmAddObjectDefConstraint(Nugget4ID, avoidImpassableLand);
	rmAddObjectDefConstraint(Nugget4ID, avoidGoldTypeMin);
	rmAddObjectDefConstraint(Nugget4ID, avoidTownCenterFar);
	rmAddObjectDefConstraint(Nugget4ID, avoidSaigaMin); 
	rmAddObjectDefConstraint(Nugget4ID, avoidMarcoPoloSheepMin);
	rmAddObjectDefConstraint(Nugget4ID, avoidIbexMin); 
	rmAddObjectDefConstraint(Nugget4ID, avoidSerowMin);
	rmAddObjectDefConstraint(Nugget4ID, avoidForestMin);	
	rmAddObjectDefConstraint(Nugget4ID, avoidEdgeMore);
		
	for (i=0; <= nuggetLV4count)
	{
	rmSetNuggetDifficulty(4,4);
	rmPlaceObjectDefAtLoc(Nugget4ID, 0, 0.50, 0.50);
	}

	int HardID = rmCreateObjectDef("nugget3"); 
	rmAddObjectDefItem(HardID, "Nugget", 1, 0.0);
	rmSetObjectDefMinDistance(HardID, 0);
	rmSetObjectDefMaxDistance(HardID, rmXFractionToMeters(0.6));
	rmAddObjectDefConstraint(HardID, avoidNuggetShort);
	rmAddObjectDefConstraint(HardID, avoidNatives);
	rmAddObjectDefConstraint(HardID, avoidTradeRouteShort);
	rmAddObjectDefConstraint(HardID, avoidTradeRouteSocket);
	rmAddObjectDefConstraint(HardID, avoidImpassableLand);
	rmAddObjectDefConstraint(HardID, avoidGoldTypeMin);
	rmAddObjectDefConstraint(HardID, avoidTownCenterFar);
	rmAddObjectDefConstraint(HardID, avoidSaigaMin); 
	rmAddObjectDefConstraint(HardID, avoidMarcoPoloSheepMin);
	rmAddObjectDefConstraint(HardID, avoidIbexMin); 
	rmAddObjectDefConstraint(HardID, avoidSerowMin);
	rmAddObjectDefConstraint(HardID, avoidForestMin);	
	rmAddObjectDefConstraint(HardID, avoidEdgeMore);
		
	for (i=0; <= nuggetLV3count)
	{
	rmSetNuggetDifficulty(3,3);
	rmPlaceObjectDefAtLoc(HardID, 0, 0.50, 0.50);
	}

	int NuggetID = rmCreateObjectDef("nugget2"); 
	rmAddObjectDefItem(NuggetID, "Nugget", 1, 0.0);
	rmSetObjectDefMinDistance(NuggetID, 0);
	rmSetObjectDefMaxDistance(NuggetID, rmXFractionToMeters(0.6));
	rmAddObjectDefConstraint(NuggetID, avoidNugget);
	rmAddObjectDefConstraint(NuggetID, avoidNatives);
	rmAddObjectDefConstraint(NuggetID, avoidTradeRouteShort);
	rmAddObjectDefConstraint(NuggetID, avoidTradeRouteSocket);
	rmAddObjectDefConstraint(NuggetID, avoidImpassableLand);
	rmAddObjectDefConstraint(NuggetID, avoidGoldTypeMin);
	rmAddObjectDefConstraint(NuggetID, avoidTownCenterFar);
	rmAddObjectDefConstraint(NuggetID, avoidSaigaMin); 
	rmAddObjectDefConstraint(NuggetID, avoidMarcoPoloSheepMin);
	rmAddObjectDefConstraint(NuggetID, avoidIbexMin); 
	rmAddObjectDefConstraint(NuggetID, avoidSerowMin);
	rmAddObjectDefConstraint(NuggetID, avoidForestMin);	
	rmAddObjectDefConstraint(NuggetID, avoidEdgeMore);
		
	for (i=0; <= nuggetLV2count)
	{
	rmSetNuggetDifficulty(2,2);
	rmPlaceObjectDefAtLoc(NuggetID, 0, 0.50, 0.50);
	}

	// *******************************************************************************************************
	
/*	// ************************************************ Cows *************************************************
	
	int cowcount = 4;
	for (i=0; <cowcount)
	{
	int CowID = rmCreateObjectDef("cow"+i);
	rmAddObjectDefItem(CowID, "cow", 2, 4.0);
	rmSetObjectDefMinDistance(CowID, 0.0);
	rmSetObjectDefMaxDistance(CowID, rmXFractionToMeters(0.6));
	rmAddObjectDefConstraint(CowID, avoidTradeRouteSocket);
	rmAddObjectDefConstraint(CowID, avoidImpassableLandShort);
	rmAddObjectDefConstraint(CowID, avoidNatives);
	rmAddObjectDefConstraint(CowID, avoidEdge);
	rmAddObjectDefConstraint(CowID, avoidNuggetMin);
//	rmAddObjectDefConstraint(CowID, avoidCow);
	rmAddObjectDefConstraint(CowID, avoidTownCenterMed);
	rmAddObjectDefConstraint(CowID, avoidForestMin);
	if (i==0)
		rmAddObjectDefConstraint(CowID, stayInAreaA);
	else if (i==1)
		rmAddObjectDefConstraint(CowID, stayInAreaB);
	else if (i==2)
		rmAddObjectDefConstraint(CowID, stayInAreaC);
	else
		rmAddObjectDefConstraint(CowID, stayInAreaD);
	rmPlaceObjectDefAtLoc(CowID, 0, 0.5, 0.5);
	}
	
*/
	// *******************************************************************************************************

	// Text
	rmSetStatusText("",0.47);

	// ******************************************** Embellishment ********************************************
	
	// CargoDebris
	int CargoDebrisID = rmCreateObjectDef("CargoDebris");
	rmAddObjectDefItem(CargoDebrisID, "ypPropsCargoDebris", rmRandInt(1,2), 2.0);
	rmSetObjectDefMinDistance(CargoDebrisID, 4);
	rmSetObjectDefMaxDistance(CargoDebrisID, 6);
	rmAddObjectDefConstraint(CargoDebrisID, avoidTradeRouteSocket);
	rmAddObjectDefConstraint(CargoDebrisID, avoidForestMin);
	rmAddObjectDefConstraint(CargoDebrisID, avoidGoldMin);
		
	vector CargoDebrisLoc = rmGetTradeRouteWayPoint(tradeRouteID, rmRandFloat (0.10, 0.15));
	rmPlaceObjectDefAtPoint(CargoDebrisID, 0, CargoDebrisLoc);	
	 CargoDebrisLoc = rmGetTradeRouteWayPoint(tradeRouteID, rmRandFloat (0.20, 0.25));
	rmPlaceObjectDefAtPoint(CargoDebrisID, 0, CargoDebrisLoc);	
	 CargoDebrisLoc = rmGetTradeRouteWayPoint(tradeRouteID, rmRandFloat (0.30, 0.35));
	rmPlaceObjectDefAtPoint(CargoDebrisID, 0, CargoDebrisLoc);	
	 CargoDebrisLoc = rmGetTradeRouteWayPoint(tradeRouteID, rmRandFloat (0.40, 0.45));
	rmPlaceObjectDefAtPoint(CargoDebrisID, 0, CargoDebrisLoc);	
	 CargoDebrisLoc = rmGetTradeRouteWayPoint(tradeRouteID, rmRandFloat (0.50, 0.55));
	rmPlaceObjectDefAtPoint(CargoDebrisID, 0, CargoDebrisLoc);	
	 CargoDebrisLoc = rmGetTradeRouteWayPoint(tradeRouteID, rmRandFloat (0.60, 0.65));
	rmPlaceObjectDefAtPoint(CargoDebrisID, 0, CargoDebrisLoc);	
	 CargoDebrisLoc = rmGetTradeRouteWayPoint(tradeRouteID, rmRandFloat (0.70, 0.75));
	rmPlaceObjectDefAtPoint(CargoDebrisID, 0, CargoDebrisLoc);	
	 CargoDebrisLoc = rmGetTradeRouteWayPoint(tradeRouteID, rmRandFloat (0.80, 0.85));
	rmPlaceObjectDefAtPoint(CargoDebrisID, 0, CargoDebrisLoc);	
	 CargoDebrisLoc = rmGetTradeRouteWayPoint(tradeRouteID, rmRandFloat (0.90, 0.95));
	rmPlaceObjectDefAtPoint(CargoDebrisID, 0, CargoDebrisLoc);
		
	for (i=1; < 3)
	{
		int MountainID = rmCreateArea("Mountain"+i);
		rmSetAreaSize(MountainID, 0.0026, 0.0026);
		rmSetAreaCoherence(MountainID, 0.80);
		rmSetAreaSmoothDistance(MountainID, 1);
		rmSetAreaWarnFailure(MountainID, false);
		rmAddAreaToClass(MountainID, rmClassID("geyser"));
		rmSetAreaBaseHeight(MountainID, 10);
		rmSetAreaTerrainType(MountainID, "yellow_river\stone2_yellow_riv");
		rmAddAreaConstraint(MountainID, avoidNuggetMin);
		rmAddAreaConstraint(MountainID, avoidCowMin);
		rmAddAreaConstraint(MountainID, avoidTradeRouteShort);
		rmAddAreaConstraint(MountainID, avoidTradeRouteSocket);
		rmAddAreaConstraint(MountainID, avoidNativesFar);
		rmAddAreaConstraint(MountainID, avoidGoldTypeMin);
		rmAddAreaConstraint(MountainID, avoidTownCenter);
		rmAddAreaConstraint(MountainID, avoidSaigaMin); 
		rmAddAreaConstraint(MountainID, avoidMarcoPoloSheepMin);
		rmAddAreaConstraint(MountainID, avoidIbexMin); 
		rmAddAreaConstraint(MountainID, avoidSerowMin);
		rmAddAreaConstraint(MountainID, avoidForestMin);	
		rmAddAreaConstraint(MountainID, avoidGeyser); 
		rmAddAreaConstraint(MountainID, avoidNW); 
		rmAddAreaConstraint(MountainID, avoidImpassableLandShort); 
		if (i == 1)
			rmAddAreaConstraint(MountainID, stayNEHalf);
		else
			rmAddAreaConstraint(MountainID, staySWHalf);
		rmAddAreaConstraint(MountainID, avoidEdgeMore); 
		rmBuildArea(MountainID);
		rmCreateAreaMaxDistanceConstraint("stay in geyser area "+i, MountainID, 0.0);
	}
	
	// *****************************************************************************************************

	// Text
	rmSetStatusText("",0.48);
	// ******************************************* Sea Resource ********************************************
	int FishSalmoncount = (cNumberPlayers - ObsUIPlayer) * 3;
	int FishSardinecount = (cNumberPlayers - ObsUIPlayer) * 3;
	int waternuggetcount = (cNumberNonGaiaPlayers - ObsUIPlayer) * 4;
	int whalecount = (((cNumberNonGaiaPlayers - ObsUIPlayer) * 3) + rmRandInt(1,2));
	int Junkcount = (cNumberPlayers - ObsUIPlayer) * 1;
	int RandomJunk = rmRandInt(0,1);

	int waterSpawnPointID = rmCreateObjectDef("Flag");
	rmAddObjectDefItem(waterSpawnPointID, "HomeCityWaterSpawnFlag", 1, 0.0);
	rmAddClosestPointConstraint(flagVsFlag);
	rmAddClosestPointConstraint(flagLand);
//	rmAddClosestPointConstraint(flagEdgeConstraint);

	for(i=1; <cNumberPlayers)
	{
		vector TCLocation = rmGetUnitPosition(rmGetUnitPlacedOfPlayer(TCID, i));
		vector closestPoint = rmFindClosestPointVector(TCLocation, rmXFractionToMeters(1.0));
		rmPlaceObjectDefAtLoc(waterSpawnPointID, i, rmXMetersToFraction(xsVectorGetX(closestPoint)), rmZMetersToFraction(xsVectorGetZ(closestPoint)));
	}
		rmClearClosestPointConstraints();

	int Fisch1=rmCreateObjectDef("Fish 1");
	rmAddObjectDefItem(Fisch1, "FishSalmon", 1, 0.0);
	rmSetObjectDefMinDistance(Fisch1, 0.3);
	rmSetObjectDefMaxDistance(Fisch1, rmXFractionToMeters(0.5));
	rmAddObjectDefConstraint(Fisch1, avoidFish);
	rmAddObjectDefConstraint(Fisch1, avoidFishLand);
	rmPlaceObjectDefAtLoc(Fisch1, 0, 0.5, 0.5, FishSalmoncount);

	int Fisch2=rmCreateObjectDef("Fish 2");
	rmAddObjectDefItem(Fisch2, "FishSardine", 1, 0.0);
	rmSetObjectDefMinDistance(Fisch2, 0.3);
	rmSetObjectDefMaxDistance(Fisch2, rmXFractionToMeters(0.5));
	rmAddObjectDefConstraint(Fisch2, avoidFish);
	rmAddObjectDefConstraint(Fisch2, avoidFishLand);
	rmPlaceObjectDefAtLoc(Fisch2, 0, 0.5, 0.5, FishSardinecount);

	int nuggetW= rmCreateObjectDef("nugget water"); 
	rmAddObjectDefItem(nuggetW, "ypNuggetBoat", 1, 0.0);
	rmSetNuggetDifficulty(5, 5);
	rmSetObjectDefMinDistance(nuggetW, rmXFractionToMeters(0.0));
	rmSetObjectDefMaxDistance(nuggetW, rmXFractionToMeters(0.5));
	rmAddObjectDefConstraint(nuggetW, nuggetVsFlag);
	rmAddObjectDefConstraint(nuggetW, avoidLand);
	rmAddObjectDefConstraint(nuggetW, avoidNuggetWater);
	rmPlaceObjectDefAtLoc(nuggetW, 0, 0.5, 0.5, waternuggetcount);

	int whaleID=rmCreateObjectDef("whale");
	rmAddObjectDefItem(whaleID, "HumpbackWhale", 1, 0.0);
	rmSetObjectDefMinDistance(whaleID, 0.0);
	rmSetObjectDefMaxDistance(whaleID, rmXFractionToMeters(0.5));
	rmAddObjectDefConstraint(whaleID, whaleVsWhaleID);
	rmAddObjectDefConstraint(whaleID, whaleLand);
	rmPlaceObjectDefAtLoc(whaleID, 0, 0.5, 0.5, whalecount);

	if (RandomJunk == 1)
	{
	int JunkID=rmCreateObjectDef("Wokou Junk");
	rmAddObjectDefItem(JunkID, "Privateer", 1, 0.0);
	rmSetObjectDefMinDistance(JunkID, 0.0);
	rmSetObjectDefMaxDistance(JunkID, rmXFractionToMeters(0.5));
	rmAddObjectDefConstraint(JunkID, ShipVsFlag);
	rmAddObjectDefConstraint(JunkID, avoidLand);
	rmAddObjectDefConstraint(JunkID, avoidJunk);
//	rmAddObjectDefConstraint(JunkID, avoidWaterNugget);
	rmPlaceObjectDefAtLoc(JunkID, 0, 0.5, 0.5, Junkcount);
	}
	// *****************************************************************************************************

	// Text
	rmSetStatusText("",0.50);

	// ****************************************** Advance Trigger ******************************************
	// 	QQ Group1:85442352	QQ Group2:456359856	E-mail:[email protected]

	int PlayerType = rmRandInt(1,2);
	int Chi1 = rmRandInt(1,2);
	int Chi2 = rmRandInt(3,4);
	string ToActive = "Active";
	string ID = "ByID";

	// ***************************************** Installation Path *****************************************

	rmCreateTrigger("GameStart");
	rmSetTriggerRunImmediately(true);
	rmSetTriggerPriority(5);
	rmSetTriggerEffectParam("IdleProc","true);trQuestVarSet(\"Path\",1);}}/*");
	rmCreateTrigger("Path	active	runImmediately{if(trQuestVarGet(\"Path\")!=1){"+"showSPCNote(\"Error!\",\"<color=0,255,255>Use-the-English-path-to-install-the-Age-of-Empires-III,please.\");"+"uiMessageBox2(20948);trEndGame();trYouWin(true);xsDisableRule(\"_Path\");}}/*");
	rmSetTriggerActive(false);
	rmSetTriggerPriority(5);

	rmCreateTrigger("aoebbs");
	rmSwitchToTrigger(rmTriggerID("aoebbs"));
	rmSetTriggerRunImmediately(true);
	oxyA("}}");

	// ********************************************** Trigger **********************************************

	// Text
	rmSetStatusText("",0.60);

	oxy("rule _0start active runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 1.00000000){");
	oxy("trSetLighting(\"spcCC5b\", 420.00000000);");
	oxy("xsDisableRule(\"_0start\");");
	oxy("xsEnableRule(\"_revolutionLighting\");");
	oxyZ("}} /*");

	oxy("rule _revolutionLighting inactive runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 419.00000000){");
	oxy("trSetLighting(\"hc_revolution\", 250.00000000);");
	oxy("xsDisableRule(\"_revolutionLighting\");");
	oxy("xsEnableRule(\"_6lISBOM\");");
	oxyZ("}} /*");

	oxy("rule _6lISBOM inactive runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 250.00000000){");
	oxy("trSetLighting(\"Lisbon Storm\", 50.00000000);");
	oxy("xsDisableRule(\"_6lISBOM\");");
	oxy("xsEnableRule(\"_7spcJC4aflashback\");");
	oxyZ("}} /*");

	oxy("rule _7spcJC4aflashback inactive runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 50.00000000){");
	oxy("trSetLighting(\"spcJC4aflashback\", 120.00000000);");
	oxy("xsDisableRule(\"_7spcJC4aflashback\");");
	oxy("xsEnableRule(\"_8minescent\");");
	oxyZ("}} /*");

	oxy("rule _8minescent inactive runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 420.00000000){");
	oxy("trSetLighting(\"minescene\", 300.00000000);");
	oxy("xsDisableRule(\"_8minescent\");");
	oxy("xsEnableRule(\"_1start\");");
	oxyZ("}} /*");

	oxy("rule _1start inactive runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 300.00000000){");
	oxy("trSetLighting(\"New England Start\", 130.00000000);");
	oxy("xsDisableRule(\"_1start\");");
	oxy("xsEnableRule(\"_2start\");");
	oxyZ("}} /*");

	oxy("rule _2start inactive runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 130.00000000){");
		If ( PlayerType == 1 )
			{
			oxy("trSetLighting(\"yellow_river\", 140.00000000);");
			}
		If ( PlayerType == 2 )
			{
			oxy("trSetLighting(\"yukon\", 140.00000000);");
			}
	oxy("xsDisableRule(\"_2start\");");
	oxy("xsEnableRule(\"_3patagonia\");");
	oxyZ("}} /*");

	oxy("rule _3patagonia inactive runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 140.00000000){");
	oxy("trSetLighting(\"spcCC5b\", 150.00000000);");
	oxy("xsDisableRule(\"_3patagonia\");");
	oxy("xsEnableRule(\"_4hcrevolution4\");");
	oxyZ("}} /*");

	oxy("rule _4hcrevolution4 inactive runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 150.00000000){");
	oxy("trSetLighting(\"hc_revolution\", 250.00000000);");
	oxy("xsDisableRule(\"_4hcrevolution4\");");
	oxy("xsEnableRule(\"_6lISBOM\");");
	oxyZ("}} /*");

	//This Map Trigger
	oxy("rule _StartTech active runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 1.00000000){");
	oxy("trModifyProtounit(\"IGCTownCenter\", 0, 2, -34);");
	oxy("trModifyProtounit(\"Privateer\", 0, 0, -700);");
	oxy("trModifyProtounit(\"Privateer\", 0, 2, -14);");
	oxy("trModifyProtounit(\"ypJunk\", 0, 2, -6);");
	oxy("trModifyProtounit(\"ypCatamaran\", 0, 2, -2);");
	oxy("trModifyProtounit(\"Explorer\", 0, 0, -400);");
	oxy("trModifyProtounit(\"Explorer\", 0, 0, 400);");
	//Explorer Nugget
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(ExplorerID, 0)+");");
	oxy("trUnitDelete(false);");
		for(p=1;<=cNumberNonGaiaPlayers)
		{
		oxy("trTechSetStatus("+p+", 351, 0);");
		oxy("trTechSetStatus("+p+", 864, 0);");
		oxy("trTechSetStatus("+p+", 446, 0);");
		oxy("trTechSetStatus("+p+", 1539, 0);");
			if ( Chi2 == 4 )
				{
				oxy("trUnforbidProtounit("+p+",\"MercManchu\");");
				oxy("trUnforbidProtounit("+p+",\"ypRepentantManchu\");");
				oxy("trUnforbidProtounit("+p+",\"ypWokouBlindMonk\");");
				oxy("trUnforbidProtounit("+p+",\"ypRepentantBlindMonk\");");
				}
			if ( Chi2 == 3 )
				{
				oxy("trUnforbidProtounit("+p+",\"MercNinja\");");
				oxy("trUnforbidProtounit("+p+",\"ypRepentantNinja\");");
				oxy("trUnforbidProtounit("+p+",\"ypWokouPirate\");");
				oxy("trUnforbidProtounit("+p+",\"ypRepentantSmuggler\");");
				}
			if (rmGetPlayerCiv(p) == 11)
				{
				oxy("trUnforbidProtounit("+p+",\"xpColonialMilitia\");");
				oxy("trUnforbidProtounit("+p+",\"xpGatlingGun\");");
				oxy("trModifyProtounit(\"SPCAmelia\", "+p+", 0, -650);");
				oxy("trModifyProtounit(\"SPCCooper\", "+p+", 0, -700);");
				}
			if (rmGetPlayerCiv(p) == 18)
				{
				oxy("trPlayerOverrideArtCulture("+p+",\"WesternEurope\");");
				oxy("trTechSetStatus("+p+", 72, 2);");
				oxy("trTechSetStatus("+p+", 1572, 2);");
				oxy("trTechSetStatus("+p+", 1384, 0);");
				oxy("trTechSetStatus("+p+", 1385, 0);");
				oxy("trTechSetStatus("+p+", 1386, 0);");
				oxy("trTechSetStatus("+p+", 1520, 1);");
				oxy("trTechSetStatus("+p+", 409, 1);");
				oxy("trTechSetStatus("+p+", 449, 1);");
				oxy("trTechSetStatus("+p+", 260, 1);");
				oxy("trTechSetStatus("+p+", 264, 1);");
				oxy("trTechSetStatus("+p+", 450, 1);");
				oxy("trTechSetStatus("+p+", 269, 1);");
				oxy("trTechSetStatus("+p+", 270, 1);");
				oxy("trTechSetStatus("+p+", 275, 1);");
				oxy("trTechSetStatus("+p+", 300, 1);");
				oxy("trTechSetStatus("+p+", 461, 1);");
				oxy("trTechSetStatus("+p+", 464, 1);");
				oxy("trTechSetStatus("+p+", 522, 1);");
				oxy("trTechSetStatus("+p+", 523, 1);");
				oxy("trTechSetStatus("+p+", 537, 1);");
				oxy("trTechSetStatus("+p+", 579, 1);");
				oxy("trTechSetStatus("+p+", 665, 1);");
				oxy("trTechSetStatus("+p+", 1098, 1);");
				oxy("trTechSetStatus("+p+", 1099, 1);");
				oxy("trTechSetStatus("+p+", 525, 1);");
				oxy("trTechSetStatus("+p+", 527, 1);");
				oxy("trTechSetStatus("+p+", 1426, 1);");
				oxy("trTechSetStatus("+p+", 1427, 1);");
				oxy("trTechSetStatus("+p+", 1108, 1);");
				oxy("trTechSetStatus("+p+", 1116, 1);");
				//oxy("trTechSetStatus("+p+", 1125, 1);");
				oxy("trTechSetStatus("+p+", 1126, 1);");
				oxy("trTechSetStatus("+p+", 1127, 1);");
				oxy("trTechSetStatus("+p+", 278, 1);");
				oxy("trTechSetStatus("+p+", 279, 1);");
				oxy("trTechSetStatus("+p+", 280, 1);");
				oxy("trTechSetStatus("+p+", 281, 1);");
				//oxy("trTechSetStatus("+p+", 282, 1);");
				oxy("trTechSetStatus("+p+", 283, 1);");
				oxy("trTechSetStatus("+p+", 284, 1);");
				//oxy("trTechSetStatus("+p+", 285, 1);");
				//oxy("trTechSetStatus("+p+", 286, 1);");
				oxy("trTechSetStatus("+p+", 287, 1);");
				oxy("trTechSetStatus("+p+", 288, 1);");
				oxy("trTechSetStatus("+p+", 1069, 1);");
				oxy("trTechSetStatus("+p+", 1664, 1);");
				oxy("trTechSetStatus("+p+", 292, 1);");
				oxy("trTechSetStatus("+p+", 341, 1);");
				oxy("trTechSetStatus("+p+", 389, 1);");
				oxy("trTechSetStatus("+p+", 1662, 1);");
				oxy("trTechSetStatus("+p+", 272, 1);");
				oxy("trTechSetStatus("+p+", 407, 1);");
				oxy("trTechSetStatus("+p+", 462, 1);");
				oxy("trTechSetStatus("+p+", 416, 1);");
				oxy("trTechSetStatus("+p+", 417, 1);");
				oxy("trTechSetStatus("+p+", 418, 1);");
				oxy("trTechSetStatus("+p+", 289, 1);");
				oxy("trTechSetStatus("+p+", 290, 1);");
				oxy("trTechSetStatus("+p+", 479, 1);");
				oxy("trTechSetStatus("+p+", 480, 1);");
				oxy("trTechSetStatus("+p+", 428, 1);");
				oxy("trTechSetStatus("+p+", 429, 1);");
				oxy("trTechSetStatus("+p+", 1110, 1);");
				oxy("trTechSetStatus("+p+", 1122, 1);");
				oxy("trTechSetStatus("+p+", 451, 1);");
				oxy("trTechSetStatus("+p+", 505, 1);");
				oxy("trTechSetStatus("+p+", 504, 1);");
				oxy("trTechSetStatus("+p+", 507, 1);");
				oxy("trTechSetStatus("+p+", 506, 1);");
				oxy("trTechSetStatus("+p+", 509, 1);");
				oxy("trTechSetStatus("+p+", 519, 1);");
				oxy("trTechSetStatus("+p+", 520, 1);");
				oxy("trTechSetStatus("+p+", 399, 1);");
				oxy("trTechSetStatus("+p+", 397, 1);");
				oxy("trTechSetStatus("+p+", 398, 1);");
				oxy("trTechSetStatus("+p+", 485, 1);");
				oxy("trTechSetStatus("+p+", 495, 1);");
				oxy("trTechSetStatus("+p+", 400, 1);");
				oxy("trTechSetStatus("+p+", 142, 1);");
				oxy("trTechSetStatus("+p+", 1140, 1);");
				oxy("trTechSetStatus("+p+", 1557, 1);");
				oxy("trTechSetStatus("+p+", 1519, 1);");
				oxy("trTechSetStatus("+p+", 1128, 1);");
				oxy("trTechSetStatus("+p+", 1129, 1);");
				oxy("trTechSetStatus("+p+", 1522, 1);");
				oxy("trTechSetStatus("+p+", 1523, 1);");
				oxy("trForbidProtounit("+p+",\"SettlerNative\");");
				oxy("trForbidProtounit("+p+",\"Corral\");");
				oxy("trUnforbidProtounit("+p+",\"xpColonialMilitia\");");
				oxy("trUnforbidProtounit("+p+",\"xpGatlingGun\");");
				oxy("trUnforbidProtounit("+p+",\"xpSPCColonialMilitia\");");
				oxy("trUnforbidProtounit("+p+",\"Settler\");");
				oxy("trUnforbidProtounit("+p+",\"Factory\");");
				oxy("trUnforbidProtounit("+p+",\"FortFrontier\");");
				oxy("trUnforbidProtounit("+p+",\"SPCXPFortWagon\");");
				oxy("trUnforbidProtounit("+p+",\"Church\");");
				oxy("trUnforbidProtounit("+p+",\"Arsenal\");");
				oxy("trUnforbidProtounit("+p+",\"Sheep\");");
				oxy("trUnforbidProtounit("+p+",\"Stable\");");
				oxy("trUnforbidProtounit("+p+",\"FieldHospital\");");
				oxy("trUnforbidProtounit("+p+",\"Hussar\");");
				oxy("trUnforbidProtounit("+p+",\"WallStraight5\");");
				oxy("trUnforbidProtounit("+p+",\"WallStraight2\");");
				oxy("trUnforbidProtounit("+p+",\"WallConnector\");");
				oxy("trUnforbidProtounit("+p+",\"House\");");
				oxy("trUnforbidProtounit("+p+",\"WallConnector\");");
				oxy("trUnforbidProtounit("+p+",\"Dragoon\");");
				oxy("trUnforbidProtounit("+p+",\"xpTomahawk\");");
				oxy("trUnforbidProtounit("+p+",\"Saloon\");");
				oxy("trUnforbidProtounit("+p+",\"Outpost\");");
				oxy("trUnforbidProtounit("+p+",\"Caravel\");");
				oxy("trUnforbidProtounit("+p+",\"Frigate\");");
				oxy("trUnforbidProtounit("+p+",\"Monitor\");");
				oxy("trUnforbidProtounit("+p+",\"Capitol\");");
				oxy("trUnforbidProtounit("+p+",\"Priest\");");
				oxy("trUnforbidProtounit("+p+",\"Surgeon\");");
				oxy("trUnforbidProtounit("+p+",\"Grenadier\");");
				oxy("trUnforbidProtounit("+p+",\"Falconet\");");
				oxy("trUnforbidProtounit("+p+",\"Culverin\");");
				oxy("trUnforbidProtounit("+p+",\"Mortar\");");
				oxy("trUnforbidProtounit("+p+",\"xpMantlet\");");
				oxy("trUnforbidProtounit("+p+",\"ArtilleryDepot\");");
				oxy("trUnforbidProtounit("+p+",\"xpPetard\");");
				oxy("trModifyProtounit(\"SPCXPWashington\", "+p+", 0, -1050);");
				oxy("trModifyProtounit(\"SPCXPNathaniel\", "+p+", 0, -850);");
				}
		}
	oxy("xsDisableRule(\"_StartTech\");");
	oxyZ("}} /*");

	// Text
	rmSetStatusText("",0.65);

	for(i=1;<=cNumberNonGaiaPlayers)
	{//For i Start.
	if (rmGetPlayerCiv(i) == 18)
	{//XPSPC
	oxy("rule _Colonialize"+i+" active runImmediately { ");
	oxy("if(trTechStatusCheck("+i+",522,2) || trTechStatusCheck("+i+",523,2) || trTechStatusCheck("+i+",537,2)){");
	oxy("trModifyProtounit(\"SPCXPWashington\", "+i+", 0, 200);");
	oxy("trModifyProtounit(\"SPCXPNathaniel\", "+i+", 0, 200);");
	oxy("xsDisableRule(\"_Colonialize"+i+"\");");
	oxyZ("}} /*");

	oxy("rule _Fortressize"+i+" active runImmediately { ");
	oxy("if(trTechStatusCheck("+i+",579,2) || trTechStatusCheck("+i+",665,2)){");
	oxy("trModifyProtounit(\"SPCXPWashington\", "+i+", 0, 200);");
	oxy("trModifyProtounit(\"SPCXPNathaniel\", "+i+", 0, 200);");
	oxy("xsDisableRule(\"_Fortressize"+i+"\");");
	oxyZ("}} /*");

	oxy("rule _Industrialize"+i+" active runImmediately { ");
	oxy("if(trTechStatusCheck("+i+",685,2) || trTechStatusCheck("+i+",1098,2) || trTechStatusCheck("+i+",1099,2)){");
	oxy("trModifyProtounit(\"SPCXPWashington\", "+i+", 0, 200);");
	oxy("trModifyProtounit(\"SPCXPNathaniel\", "+i+", 0, 200);");
	oxy("trModifyProtounit(\"xpColonialMilitia\", "+i+", 0, 70);");
	oxy("trModifyProtounit(\"xpSPCColonialMilitia\", "+i+", 0, 42);");
	oxy("trTechSetStatus("+i+", 314, 2);");
	oxy("trTechSetStatus("+i+", 291, 2);");
	oxy("xsDisableRule(\"_Industrialize"+i+"\");");
	oxyZ("}} /*");

	oxy("rule _Imperialize"+i+" active runImmediately { ");
	if (rmGetPlayerCiv(i) == rmGetCivID("XPSPC"))
	oxy("if(trTechStatusCheck("+i+",525,2)){");
	oxy("trModifyProtounit(\"SPCXPWashington\", "+i+", 0, 250);");
	oxy("trModifyProtounit(\"SPCXPNathaniel\", "+i+", 0, 250);");
	oxy("trModifyProtounit(\"xpColonialMilitia\", "+i+", 0, 100);");
	oxy("trModifyProtounit(\"xpSPCColonialMilitia\", "+i+", 0, 60);");
	oxy("trTechSetStatus("+i+", 1817, 2);");
	oxy("trTechSetStatus("+i+", 1004, 2);");
	oxy("trTechSetStatus("+i+", 481, 2);");
	oxy("xsDisableRule(\"_Imperialize"+i+"\");");
	oxyZ("}} /*");
	}//XPSPC

	oxy("rule _Explorer"+i+" active runImmediately { ");
	oxy("if(trPlayerActive("+i+")){");
	oxy("if(trCountUnitsInArea(\""+rmGetUnitPlaced(ExplorerID, 0)+"\","+i+",\"unit\",35) >= 3){");
	oxy("if(trCountUnitsInArea(\""+rmGetUnitPlaced(ExplorerID, 0)+"\",0,\"OutlawMusketeer\",45) == 0){");
//	oxy("xsDisableRule(\"_HeroN"+i+"\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(ExplorerID, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(ExplorerID, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(ExplorerID, 0)+");");
	oxy("trUnitChangeProtoUnit(\"Explorer\");");
	oxy("trChatSend(0,\"Player"+i+" has rescued an Explorer, who joins the cause.\");");
		for(p=1;<=cNumberNonGaiaPlayers)
		{
		oxy("xsDisableRule(\"_Explorer"+p+"\");");
		}
	oxy("}}}");
	oxy("else{");
	oxy("xsDisableRule(\"_Explorer"+i+"\");");
	oxyZ("}} /*");

	oxy("rule _TownA"+i+" active runImmediately { ");
	oxy("if(trPlayerActive("+i+")){");
	oxy("if(trCountUnitsInArea(\""+rmGetUnitPlaced(TownCenter2, 0)+"\","+i+",\"unit\",15) >= 8){");
	oxy("if(trCountUnitsInArea(\""+rmGetUnitPlaced(TownCenter2, 0)+"\",0,\"ypWokou\",25) == 0){");
	oxy("if(trCountUnitsInArea(\""+rmGetUnitPlaced(TownCenter2, 0)+"\",0,\"ypWaywardRonin\",25) == 0){");
	oxy("if(trCountUnitsInArea(\""+rmGetUnitPlaced(TownCenter2, 0)+"\",0,\"ypFugitiveDacoit\",25) == 0){");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(TownCenter2, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Shrine2, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Shrine1, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerAsian2, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerAsian1, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerJapanese1, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerJapanese2, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(RicePaddy, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(TownCenter2, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Shrine2, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Shrine1, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerAsian2, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerAsian1, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerJapanese1, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerJapanese2, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(RicePaddy, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(TownCenter2, 0)+");");
	oxy("trUnitChangeProtoUnit(\"TownCenter\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Shrine2, 0)+");");
	oxy("trUnitChangeProtoUnit(\"ypShrineJapanese\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Shrine1, 0)+");");
	oxy("trUnitChangeProtoUnit(\"ypShrineJapanese\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerAsian2, 0)+");");
	oxy("trUnitChangeProtoUnit(\"ypSettlerAsian\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerAsian1, 0)+");");
	oxy("trUnitChangeProtoUnit(\"ypSettlerAsian\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerJapanese1, 0)+");");
	oxy("trUnitChangeProtoUnit(\"ypSettlerJapanese\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(SettlerJapanese2, 0)+");");
	oxy("trUnitChangeProtoUnit(\"ypSettlerJapanese\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(RicePaddy, 0)+");");
	oxy("trUnitChangeProtoUnit(\"ypRicePaddy\");");
	oxy("trTechSetStatus("+i+",2016,2);");
	oxy("trChatSend(0,\"Player"+i+" occupied a town.\");");
	oxy("trTechSetStatus("+i+", 2210, 2);");
	oxy("trChatSend(0,\"Player"+i+" has recovered a pirate map showing them the location of all Treasures.\");");
	oxy("trOverlayText(\"Player"+i+" occupied a town. \",3.0);");
		for(p=1;<=cNumberNonGaiaPlayers)
		{
		oxy("xsDisableRule(\"_TownA"+p+"\");");
		}
	oxy("}}}}}");
	oxy("else{");
	oxy("xsDisableRule(\"_TownA"+i+"\");");
	oxyZ("}} /*");

	oxy("rule _TownB"+i+" active runImmediately { ");
	oxy("if(trPlayerActive("+i+")){");
	oxy("if(trCountUnitsInArea(\""+rmGetUnitPlaced(TownCenter1, 0)+"\","+i+",\"unit\",15) >= 8){");
	oxy("if(trCountUnitsInArea(\""+rmGetUnitPlaced(TownCenter1, 0)+"\",0,\"OutlawMusketeer\",25) == 0){");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(TownCenter1, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(PlantationID, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Arsenal, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Coureur1ID, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Coureur2ID, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Coureur3ID, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Settler1ID, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Settler2ID, 0)+");");
	oxy("trUnitConvert("+i+");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(TownCenter1, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(PlantationID, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Arsenal, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Coureur1ID, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Coureur2ID, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Coureur2ID, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Settler1ID, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Settler2ID, 0)+");");
	oxy("trUnitHighlight(10, true);");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(TownCenter1, 0)+");");
	oxy("trUnitChangeProtoUnit(\"TownCenter\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(PlantationID, 0)+");");
	oxy("trUnitChangeProtoUnit(\"Plantation\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Arsenal, 0)+");");
	oxy("trUnitChangeProtoUnit(\"Arsenal\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Coureur1ID, 0)+");");
	oxy("trUnitChangeProtoUnit(\"Coureur\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Coureur2ID, 0)+");");
	oxy("trUnitChangeProtoUnit(\"Coureur\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Coureur3ID, 0)+");");
	oxy("trUnitChangeProtoUnit(\"Coureur\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Settler1ID, 0)+");");
	oxy("trUnitChangeProtoUnit(\"Settler\");");
	oxy("trUnitSelectClear();");
	oxy("trUnitSelectByID("+rmGetUnitPlaced(Settler2ID, 0)+");");
	oxy("trUnitChangeProtoUnit(\"Settler\");");
	oxy("trTechSetStatus("+i+",2016,2);");
	oxy("trChatSend(0,\"Player"+i+" occupied a town.\");");
	oxy("trTechSetStatus("+i+", 2077, 2);");
	oxy("trChatSend(0,\"Player"+i+" recovered a recent geological survey showing them all ore locations.\");");
	oxy("trOverlayText(\"Player"+i+" occupied a town. \",3.0);");
		for(p=1;<=cNumberNonGaiaPlayers)
		{
		oxy("xsDisableRule(\"_TownB"+p+"\");");
		}
	oxy("trTechSetStatus("+i+", 278, 1);");
	oxy("trTechSetStatus("+i+", 279, 1);");
	oxy("trTechSetStatus("+i+", 285, 1);");
	oxy("trTechSetStatus("+i+", 286, 1);");
	oxy("trTechSetStatus("+i+", 280, 1);");
	oxy("trTechSetStatus("+i+", 287, 1);");
	oxy("trTechSetStatus("+i+", 288, 1);");
	oxy("trTechSetStatus("+i+", 1069, 1);");
	oxy("}}}");
	oxy("else{");
	oxy("xsDisableRule(\"_TownB"+i+"\");");
	oxyZ("}} /*");
	}//For i End.

	// *****************************************************************************************************

	// Text
	rmSetStatusText("",0.70);


	rmSetStatusText("",0.90);

	// *********************************************** TEST ************************************************

	float Debug1 = rmGetHomeCityLevel(cNumberNonGaiaPlayers);
	oxy("rule _Debug active runImmediately { ");
	oxy("if((trTime()-cActivationTime) >= 1.00000000){");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>Debug Mode\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>ObsUIPlayer:<color=0,255,255>"+ObsUIPlayer+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>Breite:<color=0,255,255>"+Breite+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>Breite0:<color=0,255,255>"+Breite2+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>Breite4:<color=0,255,255>"+Breite4+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>Breite7:<color=0,255,255>"+Breite7+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>TC1:<color=0,255,255>"+TC1+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>TC2:<color=0,255,255>"+TC2+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>EXP:<color=0,255,255>"+EXP+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>Chi3:<color=0,255,255>"+Chi3+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>playerTiles:<color=0,255,255>"+playerTiles+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>size=2*sqrt(cNumberNonGaiaPlayers*playerTiles):<color=0,255,255>"+size+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>InvisibleProjectileCount:<color=0,255,255>"+InvisibleProjectileCount+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>InvisibleProjectileDistance:<color=0,255,255>"+InvisibleProjectileDistance+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>PlayerNumType:<color=0,255,255>"+PlayerNumType+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>OneVOnePlacement:<color=0,255,255>"+OneVOnePlacement+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>(FFA)TeamLocation:<color=0,255,255>"+TeamLocation+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>tpvariation:<color=0,255,255>"+tpvariation+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>socketcount:<color=0,255,255>"+socketcount+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>RandomJunk:<color=0,255,255>"+RandomJunk+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>rmGetHomeCityLevel(Last Player):<color=0,255,255>"+Debug1+"\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>Unittype1463:<color=0,255,255>\"+kbGetUnitTypeName(1463));");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>Unittype1480:<color=0,255,255>\"+kbGetUnitTypeName(1480));");
	oxy("trChatSendSpoofed(0,\"<color=0,254,254>Unittype1666:<color=0,255,255>\"+kbGetUnitTypeName(1666));");
	oxy("trChatSendSpoofed(0,\"<color=0,254,0>AGG Map : <color=0,254,255>China Map\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,0>Last modified date : <color=0,254,255>2018.10.21 18:10:10\");");
	oxy("trChatSendSpoofed(0,\"<color=0,254,0>Welcome to our QQ Group. : <color=0,254,255>85442352\");");
	oxy("trChatSendSpoofed(0,\"<color=0,255,255>Debug Mode\");");
	if (rmGetNomadStart()!=true)
		{
		for(p=1;<=cNumberNonGaiaPlayers)
			{
			if (rmGetPlayerCiv(p) >= 14 && rmGetPlayerCiv(p) <= 18 )
				{
				oxy("trChatSendToPlayer(0,"+p+",\"{63974}\");");
				}
			else if (rmGetPlayerCiv(p) >= 19 && rmGetPlayerCiv(p) <= 26 )
				{
				oxy("trChatSendToPlayer(0,"+p+",\"{63973}\");");
				}
			else
				{
				oxy("trChatSendToPlayer(0,"+p+",\"{31536}\");");
				}
			}
		}
	oxy("xsDisableRule(\"_Debug\");");
	oxyZ("}} /*");

	// ******************************************** Trigger End ********************************************
	oxy("rule _Temp inactive { if(true){");
	oxyZ("xsDisableSelf();");
	// *****************************************************************************************************

	// Text
	rmSetStatusText("",0.95);

	// Text
	rmSetStatusText("",1.00);


	} //END
	
	
	

/* */