A simple way to do something like this is just make a tech for each unique unit and building, and make them available to all civs with the tech. The tech has as a prereq the prereq for the regular unit that the uu used to replace, ie the Praetorian tech would require Ironworking and cost the same as iron working. Unless you seriously cared to specialize in one type of unit your best bet would always be to just go for the regular one (Swordsman). That could be done in XML and would be essentially similar. Of course, there's no random element there. Maybe you could make shadow civs which are all identical to each other from as far as the player is concerned, ie there are 5 Romes, all of which have the same text and leaders and city lists and everything, except they have these hidden free techs that allow different follow up techs to standard techs, so one game you might be Rome4 and find that IronWorking gets you the opportunity to get Praetorian, while in another game you may discover that you ar Rome2 and it may allow you to get a different unit. Regarding trading beakers, simple way to do that is with intermediate do-nothing techs that exist just to be traded. There's probably some simple way in python to give a free random tech from among a list, upon getting another specific tech. Some kind of event. Then you could build what you want on that. There might be something you could copy somewhere and then just modify it to suit your purpose.