After not playing for too long I had apparently lost my touch and got into sticky situation
Map: Standard Pangea 80%, 3 AI: Persia, Celts, Zulu (on an island), Monarch, Year 1480.
Persia and Celts have MPP and RoP but only Persia is at war with me.
Me (Portugal) and my enemy (Persia) are in early industrial (have rifles and cavs but no infantry and artillery) Persia RoP raped me with a stack of 12 something rifles and 20 immortals and longbows with additional rifles roaming at my core. I have 2 AC armies and 1 cav army for which I had used all my gold and some knights to rush in the military academy, also have a few cannons and replaceable parts is 7 turns away.
What to do? Hope that my 16 cavs , 16 MDI and the armies will break that stack or hope for defensive battle by moving rifles (I have only 6 or so) via rail to the city they will probably attack (and hope for the best), That city have my FP and only Saltpeter source.
A savegame would be really helpful here.
First and most important thing to remember: the AI is dumb. It will move its units to attack the weakest target it can see (on the whole map), even if it can't get there this turn. So heavily fortifying one city will just encourage it to move/attack something softer -- unprotected Workers, lone/ weakened units, un(der)defended cities. When you've been caught on the hop, and especially when your unit-numbers are (too) low, you can actually use that to your advantage, with the 'bait-city' tactic. But you do NOT want their units all attacking a single target, in those numbers, because you can't rely on winning defensive battles to hold your cities -- all that will achieve is attrition of your units without inflicting significant losses on the Persians.
You need to take the fight to them: within your own borders -- and especially if your rail-network is complete -- you have the advantage of mobility, so use it. You also have one other major advantage -- from your description, the Persian do not appear to have Cavs or Knights! If they did, then you would also have a stack of those on your turf already -- which suggests that they don't have Horses. If that's the case, then you want to keep it that way, e.g by signing Embargos with the Zulus and/or Celts. Even better would be bringing them in as allies, and disrupting the Persians' international relations/ trade -- so can you get an MPP with Brennus as well? If so, do it (whatever it costs) -- the presence of Persian troops already inside your borders and attacking your troops/ cities/ infrastructure will instantly bring the Celts into the war on your side, breaking their MPP (and any other deals). And once you've blunted the Persian invasion (they've probably thrown all their free units at you), you'll be able to take the war back across their borders (if you so choose) without fear of a Celtic reprisal. Signing an MPP with Shaka is not necessary, since he can't help you fight the Persians, but if you can get him to sign an MA vs Xerxes, again to break any trade deals they have running, that might be helpful.
Regarding immediate defence: If you have rails, and especially if your unit-numbers are limited, yes, move the majority (possibly all) of your units to those cities which the Persian stack(s) can reach in 1T (i.e. within 1 tile for foot-units) -- you can safely empty the garrisons of any cities that aren't in immediate danger of attack. Doing so may actually encourage the Persians to (split their stacks and) move towards the un(der)defended cities, instead of attacking the defended ones, so you may be able to harass those smaller stack(s) and chisel them down bit by bit, using fast units to minimise losses, as you build up your own forces.
Rifles, Immortals and LBMs are all A=4, M=1 units, so don't have a high win-probability vs. fortified D=6 Rifles, especially those on defensive-bonus tiles (Hills, across Rivers), and/or in cities (Pop7+), and/or backed up by bombard-units. So your cities are probably mostly safe, for the moment -- but your resource-tiles aren't. So you can (and should) ping away at those foot-units with your Cannons, and harass them with your faster Armies and Cavs, to encourage them to leave. Damaged units will usually fortify in place if they can't hide under a healthy defender. Redlined units will usually run directly for the nearest friendly/neutral territory to heal. For the most part, you should let them go -- you'll have another chance to kill them in a couple of turns' time, when they return to the fray -- by which time you'll have built more units yourself.
You can maybe use your ACav-Armies to knock off redlined low-D units, but resist the temptation to chase them all the way to the border. And
especially while your unit numbers are still low, do NOT use M=1 attack-units to chase lone redlined units without a
very good reason. Even if your guy wins that fight, he will be left exposed, and (if there's a healthy enemy attacker within striking distance) will almost certainly get attacked and killed on the following interturn.
Which brings me to the next thing: unit numbers. You have Nationalism, which means that you can Draft, and you can Mobilise. These are both 'emergency response' measures, but if your strength is really that low vs the Persians, then I would argue that this
is an emergency. Yes, drafting will cause unhappiness (1 citizen per draftee, for 20T), but losing your cities/units will cause much more. So draft at least one cRifle in each city (assuming you're running a Republic?) -- and possibly a second Rifle per city next turn -- and move them to/ fortify them in the most endangered cities. Use Luxes+Markets, and the LUX-slider (50% if necessary!) to keep your citizens happy.
Mobilisation will double shield-output in all (uncorrupted) cities, but Mobilised shields can only be used for building mil-units (A/D >1) and mil-improvements (Walls, Barracks, Harbours, etc.), so use that to churn out vCavs from high-SPT Barracks-cities, rRifles from non-Barracks cities (regular units defending cities/ stacks can fight more battles per turn than attackers, so -- if they survive the onslaught -- tend to get promoted to vet/ elite quicker), and Maces+Cannon from smaller/corrupt cities. Try to juggle tile-usage amongst those cities to give efficient shield-numbers if possible, allowing you to build fast with minimal wastage (e.g. to build Cavs+Rifles in 4, 3 or 2T, aim for 20, 27 or 40 SPT).
Once you get RepParts, upgrading those Rifles to Infs is cheap (30g per unit, 15g if you have Leo's): Infs can attack D=1-2 units just as well as Cavs, and defend
much better against A=4 units, which should (also) get you some promotions. (Yes, Infs are slow and can't retreat, but while they're still on your own rails, that's less important). Upgrading Cannon is expensive (120g/60g per unit), but you can also disband them into Arty-builds for 10s per disbanded-Cannon.
However, the increased unit-numbers are going to eat into your budget, so depending on the health of your economy, you may need to slow down/stop your research for a couple of turns. While RepParts is a fantastic tech, this war may be decided before you get it, unless you can significantly drop the turns-to-complete, e.g. by
- Running a deficit
- Signing Lux-import deals with the Celts/Zulus to boost your Market-happiness, allowing you to sell unneeded Temples/ Cathedrals/ Colosseums (gives you immediate gold and saves maintenance-GPT => more gold for lux/science)
- Switching Clowns/Taxmen to Geeks in corrupt '1-shield' cities (for more beakers per turn)
- Building Science-multiplier buildings in high-commerce cities (won't be possible if you Mobilise)
And if you haven't already, try to raise your free-unit upkeep, e.g. get all your core- and semi-core cities to at least Pop7 (e.g. if you still have native Workers and Pop6 towns, joining 1 Worker to each town will both reduce your unit-count
and increase your unit-allowance) or start building '1-shield' farms in the corrupt corners of your continent.
Good luck.