Images
Terraforming

Terraforming

AI will terraform the surroundings of its cities — improving growth and production. This is a feature originally introduced by player_1.

The Actions

Terraforming City Location

This is a friendly feature for AI and HUMANs: Upon settling the city’s terrain will be terraformed to a better terrain type, if the necessary technologies and PW are available.

Clear The Woods

The AI will slowly clear the woods (terraform them into grassland) around their cities to improve growth.

Terraform Useless Terrain

In the first ring around the city he AI will terraform swamp into grassland, tundra and desert into plains. The AI will try to terraform all glacier terrain around the city into plains.

No PW Cheat

I have stripped all PW cheating from the original script - I just want the AI to act intelligently, nothing more.

The Script

//--------------------------------------------------------------------------
// MoT Mod for CTP2 by BureauBert
// 1.0 BETA
// http://ctp2.free.fr/
//--------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////
// Terraforming Code by player_1
////////////////////////////////////////////////////////////////////////////

//--------------------------------------------------------------------------
// MoT Mod for CTP2 (Apolyton Edition) by BureauBert
// v1.1
// http://motmod.ctp2.info
//--------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////
// Terraforming Code by player_1
////////////////////////////////////////////////////////////////////////////

HandleEvent(MakePop) 'ExpandingCityTileImprovement' post {
	location_t trfLoc;
	location_t trfFirstLoc;
	int_t trfTtype;
	int_t trfTimp;
	int_t trfPwLevel;
	int_t trfCountA;
	int_t trfCountB;
	int_t trfPlayer;
	int_t trfCountC;
	int_t trfRand;
	int_t trfWoodCount;
	
	trfPlayer = city[0].owner;
	player[3] = g.player;
	trfLoc = city[0].location;
	trfPwLevel = player[3].publicworkslevel;
	trfWoodCount = 0;

	// terraform city location

	if(HasGood(trfLoc) == -1) {
		if((TerrainType(trfLoc) == TerrainDB(TERRAIN_FOREST)
		|| TerrainType(trfLoc) == TerrainDB(TERRAIN_JUNGLE))
		&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_AGRICULTURE))) {
			Terraform(trfLoc, TerrainDB(TERRAIN_PLAINS));
		}
		elseif((TerrainType(trfLoc) == TerrainDB(TERRAIN_SWAMP))
		&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_AGRICULTURAL_REVOLUTION))) {
			Terraform(trfLoc, TerrainDB(TERRAIN_GRASSLAND));
		}
		elseif((TerrainType(trfLoc) == TerrainDB(TERRAIN_TUNDRA))
		&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_ADVANCED_COMPOSITES))) {
			Terraform(trfLoc, TerrainDB(TERRAIN_PLAINS));
		}
		elseif((TerrainType(trfLoc) == TerrainDB(TERRAIN_DESERT))
		&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_CONSERVATION))) {
			Terraform(trfLoc, TerrainDB(TERRAIN_PLAINS));
		}
		elseif((TerrainType(trfLoc) == TerrainDB(TERRAIN_DEAD))
		&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_CONSERVATION))) {
			Terraform(trfLoc, TerrainDB(TERRAIN_PLAINS));
		}
		// remove ti's underneath city
		for(trfCountC = 0; trfCountC < TerrainImprovementDB(); trfCountC = trfCountC + 1) {
			if(TileHasImprovement(trfLoc, TerrainImprovementDB(trfCountC))) {
				Event:CutImprovements(trfLoc);
				FinishImprovements(trfLoc);
			}
		}
	}

	// terraform city radius 1

	if(trfPlayer != 0 && !IsHumanPlayer(trfPlayer) && city[0].population > 2) {	// barbs dont't care for terraforming
		for(trfCountA = 0; trfCountA <= 7; trfCountA = trfCountA + 1) {
			if(GetNeighbor(city[0].location, trfCountA, trfLoc)) {
				if (trfTtype == TerrainDB(TERRAIN_FOREST)
				|| trfTtype == TerrainDB(TERRAIN_JUNGLE)) {
					trfWoodCount = trfWoodCount + 1;
				}
			}
		}
		if(trfWoodCount > 4) {
			trfWoodCount = 4 - trfWoodCount;
			for(trfCountA = 0; trfCountA <= 7; trfCountA = trfCountA + 1) {
				if(trfWoodCount < 0
				&& GetNeighbor(city[0].location, trfCountA, trfLoc)) {
					if(CellOwner(trfLoc) == city[0].owner
					&& HasGood(trfLoc) == -1
					&& TileHasFacility(trfLoc) == 0
					&& TileHasWonder(trfLoc) == 0
					&& TileHasCapital(trfLoc) == 0
					&& TileHasMonument(trfLoc) == 0
					) {
						trfTtype = TerrainType(trfLoc);
						if ((trfTtype == TerrainDB(TERRAIN_FOREST)
						|| trfTtype == TerrainDB(TERRAIN_JUNGLE)) 
						&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_AGRICULTURE))
						&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_TOOLMAKING))) {
							trfRand = Random(100);
							if(0 <= trfRand <= 29) {
								trfTimp = TerrainImprovementDB(TILEIMP_TERRAFORM_GRASSLAND);
								Event:CreateImprovement(city[0].owner, trfLoc, trfTimp, 0);
							}
							trfWoodCount = trfWoodCount + 1;
						}
					}
				}
			}
		}
		for(trfCountA = 0; trfCountA <= 7; trfCountA = trfCountA + 1) {
			if(GetNeighbor(city[0].location, trfCountA, trfLoc)) {
				if(CellOwner(trfLoc) == city[0].owner
				&& HasGood(trfLoc) == -1  
				&& TileHasFacility(trfLoc) == 0
				&& TileHasWonder(trfLoc) == 0
				&& TileHasCapital(trfLoc) == 0
				&& TileHasMonument(trfLoc) == 0
				) {
					if((TerrainType(trfLoc) == TerrainDB(TERRAIN_SWAMP)) 
					&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_AGRICULTURAL_REVOLUTION))) {
						trfTimp = TerrainImprovementDB(TILEIMP_TERRAFORM_GRASSLAND);
						Event:CreateImprovement(city[0].owner, trfLoc, trfTimp, 0);
					}
					elseif((TerrainType(trfLoc) == TerrainDB(TERRAIN_TUNDRA)) 
					&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_ADVANCED_COMPOSITES))) {
						trfTimp = TerrainImprovementDB(TILEIMP_TERRAFORM_PLAINS);
						Event:CreateImprovement(city[0].owner, trfLoc, trfTimp, 0);
					}
					elseif((TerrainType(trfLoc) == TerrainDB(TERRAIN_DESERT)) 
					&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_CONSERVATION))) {
						trfTimp = TerrainImprovementDB(TILEIMP_TERRAFORM_PLAINS);
						Event:CreateImprovement(city[0].owner, trfLoc, trfTimp, 0);
					}
				}
			}
		}
	}

	// this triggers when the city's population grows to
	// 8, the min population for citysize1
	// this is just a late support for those unlucky having founded cities on glacier terrain

	if(!IsHumanPlayer(trfPlayer) && city[0].population > 8) {
		if(GetNeighbor(city[0].location, 1, trfFirstLoc)) {	//go north-east of the City
			for(trfCountB = 0; trfCountB <= 2 ; trfCountB = trfCountB + 1) {
				if(GetNeighbor(trfFirstLoc, trfCountB, trfLoc)) {
					if(CellOwner(trfLoc) == city[0].owner && HasGood(trfLoc) == -1 && TileHasFacility(trfLoc) == 0) {
						if(TerrainType(trfLoc) == TerrainDB(TERRAIN_GLACIER)
						&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_GAIA_THEORY))) {
							// if(!IsHumanPlayer(trfPlayer)) {
							//	trfPwLevel = trfPwLevel + 1200;
							//	SetPW(trfPlayer, trfPwLevel);
							// }
							trfTimp = TerrainImprovementDB(TILEIMP_TERRAFORM_PLAINS);
							Event:CreateImprovement(city[0].owner,trfLoc, trfTimp,0);
						}
					}
				}
			}
		}
		if(GetNeighbor(city[0].location, 4, trfFirstLoc)) {	//go south-east of the City
			for(trfCountB = 2; trfCountB <= 7 ; trfCountB = trfCountB + 1) { 
				if(GetNeighbor(trfFirstLoc, trfCountB, trfLoc)) {
					if(CellOwner(trfLoc) == city[0].owner && HasGood(trfLoc) == -1 && TileHasFacility(trfLoc) == 0) {
						if(TerrainType(trfLoc) == TerrainDB(TERRAIN_GLACIER)
						&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_GAIA_THEORY))) {
							// if(!IsHumanPlayer(trfPlayer)) {
							//	trfPwLevel = trfPwLevel + 1200;
							//	SetPW(trfPlayer, trfPwLevel);
							// }
							trfTimp = TerrainImprovementDB(TILEIMP_TERRAFORM_PLAINS);
							Event:CreateImprovement(city[0].owner,trfLoc, trfTimp,0);
						}
					}
					if(trfCountB == 2) {trfCountB = 3;}
					if(trfCountB == 4) {trfCountB = 6;}
				}
			}
		}
		if(GetNeighbor(city[0].location, 6, trfFirstLoc)) {	//go south-west of the City
			for(trfCountB = 5; trfCountB <= 7 ; trfCountB = trfCountB + 1) {
				if(GetNeighbor(trfFirstLoc, trfCountB, trfLoc)) {
					if(CellOwner(trfLoc) == city[0].owner && HasGood(trfLoc) == -1 && TileHasFacility(trfLoc) == 0) {
						if(TerrainType(trfLoc) == TerrainDB(TERRAIN_GLACIER)
						&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_GAIA_THEORY))) {
							// if(!IsHumanPlayer(trfPlayer)) {
							//	trfPwLevel = trfPwLevel + 1200;
							//	SetPW(trfPlayer, trfPwLevel);
							// }
							trfTimp = TerrainImprovementDB(TILEIMP_TERRAFORM_PLAINS);
							Event:CreateImprovement(city[0].owner,trfLoc, trfTimp,0);
						}
					}
				}
			}
		}
		if(GetNeighbor(city[0].location, 3, trfFirstLoc)) {	//go north-west of the City
			for(trfCountB = 0; trfCountB <= 5 ; trfCountB = trfCountB + 1) {
				if(GetNeighbor(trfFirstLoc, trfCountB, trfLoc)) {
					if (CellOwner(trfLoc) == city[0].owner && HasGood(trfLoc) == -1 && TileHasFacility(trfLoc) == 0) {
						if(TerrainType(trfLoc) == TerrainDB(TERRAIN_GLACIER)
						&& HasAdvance(trfPlayer, AdvanceDB(ADVANCE_GAIA_THEORY))) {
							// if(!IsHumanPlayer(trfPlayer)) {
							//	trfPwLevel = trfPwLevel + 1200;
							//	SetPW(trfPlayer, trfPwLevel);
							// }
							trfTimp = TerrainImprovementDB(TILEIMP_TERRAFORM_PLAINS);
							Event:CreateImprovement(city[0].owner,trfLoc, trfTimp,0);
						}
					}
					if(trfCountB == 0) {trfCountB = 2;}
					if(trfCountB == 3) {trfCountB = 4;}
				}
			}
		}
	}
}