HeroParty GetPartyInCityWhichCanFight(MapCity enemyCityOnMap) { // Firt verify if city is protected by Hero's party // Player cannot attack city untill there a party protecting it HeroParty enemyHeroParty = enemyCityOnMap.LCity.GetHeroPartyByMode(PartyMode.Party); if (enemyHeroParty) { // enemy hero is protecting city // battle place is on a city gates // verify if there are units which can fight, because it is possible that player left only dead units in party if (enemyHeroParty.HasUnitsWhichCanFight()) { return(enemyHeroParty); } else { Debug.LogWarning("Party was found, but there is no unit which can fight. Checking city Garnizon."); } } // if we are here, then there is no enemy hero protecting city // get garnizon party // there should be garnizon in every city enemyHeroParty = enemyCityOnMap.LCity.GetHeroPartyByMode(PartyMode.Garnizon); // verify if there are units in party protecting this city, which can fight // it is possible that city is not protected, because all units are dead if (enemyHeroParty.HasUnitsWhichCanFight()) { return(enemyHeroParty); } else { Debug.LogWarning("There is no unit in city Garnizon which can fight"); } // if no party can fight, then return null return(null); }