Current Git (Needs more documentation)
Current working prototype to play with (Git code is after a BIG refactor)
Background: I'm making a javascript text city/nation builder along the lines of A Dark Room or Candy Box. This is going to be the player managing a city but be able to vassalise other cities (Ala Europa Universalis), giving you a tribute of their income but no specific control over it like your own one.
Each city has a tree of things in it, including buildings, resources, tools/machines and intermediate crafting items. These types each have their own object constructors and can easily have a complex object of about 5-50 keys depending on the item just from a few lines of code. Each tree starts at the top, a category for sorting on the UI/namespace, and then inside that is the actual object itself. So whenever referencing an item in a crafting recipe or production chain there's a "resource.material.wood"
or "buildingHouse.tent.small"
or such.
The player or "empire" can own multiple cities, but only directly control one in the city view screen (You can tell your city exactly how to be managed, but all other cities you've taken over live their own life, but you can send them requests and investments to boost specific things). Because the item trees are so expansive (170 items in the prototype on my website) I need an easy way to hide things away that aren't unlocked yet. Decided to go with the Civ 5 tech tree route.
Current problem: In the prototype I had the tech tree and items bound to the window instead of to the city. This meant there was only ever a single instance of everything and to unlock something in the UI I could just go (simplified) foreach (unlockedItem) {item.unlocked = true}
. I can't do this as easily in the multiple city model because the tech system is player specific, not city specific, and so if you take over a new city they should retroactively build the city's tech level from that player's tech level. I'm not sure how I want to handle inheriting resources/buildings from a more advanced civ yet either.
Relevant code pulled from the Git as an example: pastebin.com/DbbUXbaL
As far as I can tell, there's a not so easy way I can work around this.
Flip the way I unlock things. The item is then bound to a tech that unlocks it instead of a tech being bound to multiple items. In my head I prefer the latter way because it means I can group like items together (The resource with the building that produces it) and it's easier to list the items that the tech unlocks when you're in the research menu. It's also much easier in the code to see what a tech unlocks at a glance, instead of going from class to class. The problem with the latter way though is that it's hard to retroactively unlock things in a newly unlocked city.
The question to Gamedev: Those of you with more experience than I, how would you go about designing a technology system for an entity heavy game like the Anno series or Civ if each tech unlocked 5+ things? Do I have the right idea binding the item to the tech or is there a much simpler way of doing it I'm just not seeing?