#1 will be easy but #2 will be difficult, maybe not possible, but I'll have to give it some thought first. The issue with #2 is that the game adds resources to each trade network on a per-tile basis. In other words, it processes all tiles on the map and for each one with a resource, it marks every city on the same trade network as that tile as having access to the tile's resource. A city could add a resource to its tile but the assumption that each tile only has one resource is baked in. So enabling cities to add resources to their trade networks will either require extensive machine code edits, or I'll have to think of something clever.
(Quoting myself here for an update) I've since figured out a way to enable buildings to generate resources and add them to the trade network. It didn't require anything super clever. First, for some context, the game begins by calculating trade networks, i.e. what tiles & cities connect to what others, then it calls a function I've called "recompute_resources" that fills in the available resources on each trade network. recompute_resources begins by looping over every tile on the map and for every tile that's owned by a player and has a resource, propagates that resource throughout whatever trade network that tile is part of, including recording access for all cities on the network. After the loop, recompute_resources runs some logic that I don't fully understand but can see includes something about player trade agreements, recomputing city happiness, and displaying those advisor popups that go like "we've connected [luxury], this will make our people happy."
The ideal way to enable buildings to generate tradeable resources, i.e. what I would do if I had the source code, is to modify that loop over tiles to include additional logic for the case where a tile has a city with buildings that are generating resources. In that case, it would simply process those resources in addition to any on the tile itself. But it would not be practical to patch that in to the compiled code because it was written assuming that each tile had only one resource, if any at all. I realized I could work around this problem by extending the loop. In other words, I wanted multiple resources per tile, so instead of changing how each tile is processed, I could make it process the same tile multiple times with different resources.
The loop works over tile indices, 0 1 2 ... up to the tile count, and calls a method I called "get_tile" to get the tile object for each index. I was able to make the loop visit the same tile multiple times by temporarily increasing the tile count just for the recompute_resources function and intercepting its calls to get_tile so that, once it runs past the tile count, it starts getting the tiles that I want to be processed again. Making it so that those tiles have different resources on their multiple passes was similarly easy, as recompute_resources calls a function to get the resource on any tile and I intercepted that too. The last piece of the puzzle is that I injected some code that runs before recompute_resources to check every city on the map for buildings that are generating resources. For each one it finds, it records the tile the city is on and the resource generated so that info can be used by the mechanism I described.
So buildings generating resources now works. There are only a couple of small things left to do, for example I need to add a check for the case where a building is generating a resource that its owning player doesn't have the tech for. Right now the resource is provided, but it shouldn't be. Also if a building generating a resource is sold or destroyed, the resource is still provided until the end of the turn. That's because the game doesn't recompute resource access when a building is lost unless the building was enabling air or sea trade. I need to make it do that too for buildings that are generating a resource.
I also made it so buildings can generate resources not for the trade network, just for their city alone. That was much easier. I only had to modify the single function that checks if a given city has access to a given resource to include a check for if that resource is being generated by a building. The other thing I wanted to do before R11 (the first thing was resource generation by buildings) was allowing buildings as prerequisites for unit construction. That's done too. It took a while but doesn't make for an interesting story. The gameplay code modifications were simple, I just had to modify the single function that determines if a given city can produce a given unit. The hard part was reading in the rules from the text config. The mod is written in C and doing text processing in C is always a pain. Here's an example of what it looks like in the config:
Code:
building_prereqs_for_units = [Factory: Tank "Modern Armor",
Barracks: Swordsman Cavalry Tank "Modern Armor",
Airport: Bomber]
That's it for R11. Like I mentioned before, I don't want to keep adding things because then it will never be done. I'll look into that maximum hypertext links thing for R12. R11 still needs some finishing touches then I'll post it. That'll be soon... ish, like not this week but for sure by the end of June.