Images
City Ruins

City Ruins

In modern days destroyed cities will no longer just disappear from the map but their ruins will remain.

If a city is destroyed immediately upon capture, the ruins will belong to the previous owner thereby preserving his territory.

The Script

//--------------------------------------------------------------------------
// MoT Mod for CTP2 (Apolyton Edition) by BureauBert
// v1.1
// http://motmod.ctp2.info
//--------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////
// City Ruins code 
// by BureauBert
// When a city is destroyed it does not just disappear from the map -- its
// ruins will remain and the surrounding territory will be preserved for
// its last owner.
////////////////////////////////////////////////////////////////////////////

///////////////////////////////////
// Global variables
///////////////////////////////////

// declared in main.slc

///////////////////////////////////
// Event Handlers
///////////////////////////////////

// store 'previous' owner and location pre capture

HandleEvent(CaptureCity) 'ButTheRuinsAreMine' pre {
	CIR_PrevOwner = city[0].owner;
	CIR_PrevLoc = city[0].location;
	return CONTINUE;
}

// store 'previous' owner and location pre gift

HandleEvent(GiveCity) 'IfYouDestoyItIGetTheRuins' pre {
	CIR_PrevOwner = city[0].owner;
	CIR_PrevLoc = city[0].location;
	return CONTINUE;
}

// store 'previous' and 'current' owner pre park creation

HandleEvent(CreatePark) 'ItsMyCityItsMyPark' pre {
	CIR_PrevOwner = city[0].owner;
	CIR_PrevLoc = city[0].location;
	CIR_CurrOwner = city[0].owner;
	CIR_CurrLoc = city[0].location;
	return CONTINUE;
}

// before a city is killed ...

HandleEvent(KillCity) 'WhatWeNeedToKnowAboutKilledCity' pre {
	CIR_CurrOwner = city[0].owner;
	CIR_CurrLoc = city[0].location;
	return CONTINUE;
}

// after a city is killed ...

HandleEvent(KillCity) 'DestroyedToRuins' post {
	int_t cirTimpToBuild;

	if(CIR_PrevOwner > 0) {
		if(IsPlayerAlive(CIR_PrevOwner)) {
			if(HasAdvance(CIR_PrevOwner, AdvanceDB(ADVANCE_ADV_URBAN_PLANNING))) {
				cirTimpToBuild = TerrainImprovementDB(TILEIMP_CITY_RUINS);
			}
			else {
				cirTimpToBuild = TerrainImprovementDB(TILEIMP_CITY_RUINS_ANCIENT);
			}
		}
		else {
			cirTimpToBuild = TerrainImprovementDB(TILEIMP_CITY_RUINS_ANCIENT);
		}
		if(CIR_CurrLoc == CIR_PrevLoc) {
			if(IsPlayerAlive(CIR_PrevOwner) && PlayerCityCount(CIR_PrevOwner) > 1) {
				VIS_VisiStuffPlacement = 1;
				GrantAdvance(CIR_PrevOwner, AdvanceDB(ADVANCE_SUBNEURAL_ADS));
				Event:CreateImprovement(CIR_PrevOwner, CIR_CurrLoc, cirTimpToBuild, 0);
				FinishImprovements(CIR_CurrLoc);
			}
		}
		if(CIR_CurrLoc != CIR_PrevLoc) {
			if(CIR_CurrOwner > 0 && IsPlayerAlive(CIR_CurrOwner) && PlayerCityCount(CIR_CurrOwner) > 1) {
				VIS_VisiStuffPlacement = 1;
				GrantAdvance(CIR_CurrOwner, AdvanceDB(ADVANCE_SUBNEURAL_ADS));
				Event:CreateImprovement(CIR_CurrOwner, CIR_CurrLoc, cirTimpToBuild, 0);
				FinishImprovements(CIR_CurrLoc);
			}
		}
	}
}

// before a city is disbanded ...

HandleEvent(DisbandCity) 'WhatWeNeedToKnowAboutDisbandedCity' pre {
	CIR_CurrOwner = city[0].owner;
	CIR_CurrLoc = city[0].location;
	return CONTINUE;
}

// after a city is disbanded

HandleEvent(DisbandCity) 'DisbandedToRuins' post {
	int_t cirTimpToBuild;

	if(CIR_PrevOwner > 0) {
		if(IsPlayerAlive(CIR_PrevOwner)) {
			if(HasAdvance(CIR_PrevOwner, AdvanceDB(ADVANCE_ADV_URBAN_PLANNING))) {
				cirTimpToBuild = TerrainImprovementDB(TILEIMP_CITY_RUINS);
			}
			else {
				cirTimpToBuild = TerrainImprovementDB(TILEIMP_CITY_RUINS_ANCIENT);
			}
		}
		else {
			cirTimpToBuild = TerrainImprovementDB(TILEIMP_CITY_RUINS_ANCIENT);
		}

		// if the city is disbanded immediately upon capture ...

		if(IsPlayerAlive(CIR_PrevOwner) && PlayerCityCount(CIR_PrevOwner) > 1 && CIR_CurrLoc == CIR_PrevLoc) {
			VIS_VisiStuffPlacement = 1;
			GrantAdvance(CIR_PrevOwner, AdvanceDB(ADVANCE_SUBNEURAL_ADS));
			Event:CreateImprovement(CIR_PrevOwner, CIR_CurrLoc, cirTimpToBuild, 0);
			FinishImprovements(CIR_CurrLoc);
		}

		// if the city is not disbanded immediately upon capture ...

		if(CIR_CurrOwner > 0 && IsPlayerAlive(CIR_CurrOwner) && PlayerCityCount(CIR_CurrOwner) > 1 && CIR_CurrLoc != CIR_PrevLoc) {
			VIS_VisiStuffPlacement = 1;
			GrantAdvance(CIR_CurrOwner, AdvanceDB(ADVANCE_SUBNEURAL_ADS));
			Event:CreateImprovement(CIR_CurrOwner, CIR_CurrLoc, cirTimpToBuild, 0);
			FinishImprovements(CIR_CurrLoc);
		}
	}
}

// these are already ruins, so just leave them alone ...

HandleEvent(PillageOrder) 'RuinsPillageProtectionA' pre {
	location_t cirTmpLoc;

	cirTmpLoc = army[0].location;

	if(TileHasImprovement(cirTmpLoc, TerrainImprovementDB(TILEIMP_CITY_RUINS))
	|| TileHasImprovement(cirTmpLoc, TerrainImprovementDB(TILEIMP_CITY_RUINS_ANCIENT))
	|| TileHasImprovement(cirTmpLoc, TerrainImprovementDB(TILEIMP_RUINS))) {
		return STOP;
	}
	else {
		return CONTINUE;
	}
}

HandleEvent(PillageUnit) 'RuinsPillageProtectionB' pre {
	location_t cirTmpLoc;
	
	cirTmpLoc = unit[0].location;

	if(TileHasImprovement(cirTmpLoc, TerrainImprovementDB(TILEIMP_CITY_RUINS))
	|| TileHasImprovement(cirTmpLoc, TerrainImprovementDB(TILEIMP_CITY_RUINS_ANCIENT))
	|| TileHasImprovement(cirTmpLoc, TerrainImprovementDB(TILEIMP_RUINS))) {
		return STOP;
	}
	else {
		return CONTINUE;
	}
}

// end turn: reset owner holding variables, just for being on the safe side ...
// subneural ads already being removed by MoT_s_visiwonders.slc every BeginTurn

HandleEvent(EndTurn) 'ResetCityRuinsVars' pre {
	CIR_PrevOwner = -1;
	CIR_PrevLoc = CIR_EmptyLoc;
	CIR_CurrOwner = -1;
	CIR_CurrLoc = CIR_EmptyLoc;
	return CONTINUE;
}