Orbital Buildings

ls612

Deity
Moderator
Joined
Mar 10, 2008
Messages
8,114
Location
America
Orbital mechanics, similar to how they were done in SMAC, are now on the SVN. Here is an overview for how they work and how to add them.

New Tags:

The bOrbital and bOrbitalInfrastructure tags have been added to the SVN. bOrbital marks a building as Orbital, meaning that its commerces will be handled differently. This may be added to later. NOTE, that all other effects on an building, such as Yields, Health, Happiness, and so forth, remain unchanged for now. This will change in the future.

bOrbitalInfrastructure means that a building counts as Orbital Infrastructure for the purpose of calculating the commerces from Orbital Buildings (see below). These buildings should cost some good money to maintain.

How Orbital Commerces Work:

A building with bOrbital enabled will not gain the normal amount of commerce from the CommerceChanges tag. It will instead get commerce equal to the result of the following formula. An Orbital Building will get commerce equal to the XML value times the number of cities you have with Orbital Infrastructure. This means that these buildings can be really valuable if you invest heavily in going into space. Now, it can't go indefinitely like this, so the number is capped at the population of the city, thus encouraging bigger cities in the Transhuman Era. Also, if the city that building is in does not have Orbital Infrastructure, the benefits from all orbital buildings are halved.

Example:

A building with bOrbital in a pop 50 city with Orbital Infrastructure and a civ having 15 cities with Orbital Infrastructure, and having the following XML:

Code:
			<CommerceChanges>
				<iCommerce>0</iCommerce>
				<iCommerce>0</iCommerce>
				<iCommerce>0</iCommerce>
				<iCommerce>4</iCommerce>
			</CommerceChanges>

It could give a max of (15*4)= 60 espionage, but since the city is size 50 it will only get +50 Espionage, which is reasonable for the TH era. If that city did not have Orbital Infrastructure, it would get (60/2)=30 espionage, since 30 is less than 50.

NOTEs: I think the AI will handle this fine, because it sees the results of the Orbital calculations, but if not I'll have to write a quick-and-dirty AI routine for this. Other than that it's fully functional.
 
NOTEs: I think the AI will handle this fine, because it sees the results of the Orbital calculations, but if not I'll have to write a quick-and-dirty AI routine for this. Other than that it's fully functional.

Nope - invisible to the AI unless you add something to the building value evaluation methods (which are rather complicated I'm afraid).
 
Nope - invisible to the AI unless you add something to the building value evaluation methods (which are rather complicated I'm afraid).

I thought that the AI saw the arrays of building commerces, which are what I'm modifying. If not then AI weights could be used as a stopgap measure. I can add some basic evaluations for orbital buildings to CvPlayerAI myself, or you could write more advanced ones, whichever you want.
 
Interesting. Do you recall how many Orbital buildings we have? Off the top of my head ...

- Commercial Satellite [NW]
- Hubble Telescope [WP]
- International Space Station [WP]
- Interstellar Speedway [NW]
- Military Satellite [NW]
- Orbital Factory
- Orbital Hotel [NW]
- SDI [WP]
- Solar Power Satellite
- Space Laboratory [NW]
- Zero G Sports Arena

Also some questionable ones if they are orbital or not ...

- Laser Auto-Defense [WP]
- The Space Elevator [WW]

Let me know if I forgot any.
 
@Hydro:

Here are the ones i'd suggest changing first. I'd also like it if these tags got used to make new buildings as well. Remember this only applies to commerce for now.

  • Commercial Satellite :)gold:)
  • Military Satellite :)espionage:)
  • Orbital Power Plant :)gold:) and power in the future

Also you'll need to make one (or more) Orbital Infrastructure buildings for this to function. The Commercial Spaceport could be one, but there are probably others. To see it in the XML, check out the Palace.
 
@ls612

1. When you say "Orbital Power Plant" did you mean the "Solar Power Satellite"? Its a relay that beams down solar power via microwaves to the Microwave Power Plant. At the moment it only gives -1 :gold:. Or did you mean a new building?

2. I assume I will need to update all my building schemas right?

3. Can you give me a code example to cut and paste?
 
@ls612

1. When you say "Orbital Power Plant" did you mean the "Solar Power Satellite"? Its a relay that beams down solar power via microwaves to the Microwave Power Plant. At the moment it only gives -1 :gold:. Or did you mean a new building?

2. I assume I will need to update all my building schemas right?

3. Can you give me a code example to cut and paste?

1. Yes, also that brings up the point that negative :gold: will NOT be affected by Orbital, as it is already treated as maintenance.

2. Yes.

3. Check out the Palace, it has where both tags are, those are the only ones that are changed.
 
I thought that the AI saw the arrays of building commerces, which are what I'm modifying. If not then AI weights could be used as a stopgap measure. I can add some basic evaluations for orbital buildings to CvPlayerAI myself, or you could write more advanced ones, whichever you want.

It sees the commce, yes. But it has no idea that they will get mullied by the nu ver of cities with orbital infrastructure, or halved if the ci itself doesn't have orbital infrastructure. It also won't attach any value t the orbital infrastructure itself since nothing will cause it to realize that it has any effect. Aiweights won't work well for all sorts of reasons - they dont have any scaling (so it won't realize that the more it builds the more the value of the other buildings, or that they are capped by population). Something as significant as this, and with the unique scaling pattern will definately need explicit code to evaluate it.
 
It sees the commce, yes. But it has no idea that they will get mullied by the nu ver of cities with orbital infrastructure, or halved if the ci itself doesn't have orbital infrastructure. It also won't attach any value t the orbital infrastructure itself since nothing will cause it to realize that it has any effect. Aiweights won't work well for all sorts of reasons - they dont have any scaling (so it won't realize that the more it builds the more the value of the other buildings, or that they are capped by population). Something as significant as this, and with the unique scaling pattern will definately need explicit code to evaluate it.

Sure, I can do that. Which function is AI building evaluation done in?
 
Sure, I can do that. Which function is AI building evaluation done in?

Well, this is a rather complicated area.

The way cities evaluate buildings is with a categorization and thresholding scheme that allows the city AI to ask questions like 'what value does building X have from the primary perspective of (parameterisable set of properties such as science, culture, gold, military, ...), taking account of non-primary factors only if the primary value exceeds threshold X'.

To do this the original BTS had a method called CvCityAI::AI_buildingValueThreshold() which took a building type + a set of flags to determine the primary perspective to evaluate with respect to, plus the threshold.

This was very expensive because it caused recalculation for every building for every question (and CvCityAI::doProduction() asks about 30 or so). Hence it was recoded in C2C to do a one-time evaluation of all the constituent values for each building for each perspective flag. Those constituent elements are then cached, which allows the original value for any set of perspective flags and threshold values to be recalculated from the underlying sub-values very quickly.

The original BTS function has been renamed to CvCityAI::AI_buildingValueThresholdOriginal() - it is still used for one-off needs (where its cheaper than calculating the cached values for all possible questions), but not in the main city production choice code. Changes to building evaluation must be placed there. The one-time calculation code is in CvCityAI::CalculateAllBuildingValues(). The code there MUST parallel the code in CvCityAI::AI_buildingValueThresholdOriginal() so that both methods always give the same answer. So you also need to make changes to that routine (it's structure follows that of the simpler original routine with a fairly obvious mechanical transformation).

Usually one adds to CvCityAI::AI_buildingValueThresholdOriginal() first (easier to test) and then adds the equivalent code to CvCityAI::CalculateAllBuildingValues(). You can then enable the #define 'VALIDATE_BUILDING_CACHE_CONSISTENCY' and run a few test turns that involve your new code in the DEBUG build - it will validate that the cache-based routine returns the same values as the original by calling the original every time to validate the cached result (VERY slow - do NOT leave this turned on when you're done testing).
 
Awesome. I do have some suggestions on how these orbital structures should be handled in-game though. First and foremost, I believe that for the TH era, there should be entire orbital cities, but that's another story which I will be more than happy to draw out and XML it up. But I feel like this tag is just a primitive beginning of a network of building tags to jumpstart orbital cities.

1. More on topic of this tag, I think that these buildings should have a series of requirements. First is a launch pad (I'll talk about the space elevator in a moment) and the city will then need to build the structure supplies which is an immobile unit. The unit will then launch on completion and it'll take some more turns to assemble the actual building in addition to more cost (for labor, fuel, and supplies to assemble something in space). Seeing as how the unit is actually still on the city tile, that'll just make a timer count down on that city until the building is finished.

2. An orbital factory should be implemented to lessen the assembly time of said buildings after the unit is launched and decrease the launch cost.

3. Should the city have a space elevator, the supply ships will be made obsolete in that city and will unlock building the structure directly which will allow for much shorter build times, smaller maintenance and obsoletes the launch cost(labor and supplies to assemble the structure in space).

When this tag is fully implemented we can continue on with building concepts of orbital cities.
 
Slightly off-topic - but are we going to make the (physically reasonable, but gameplay-dubious) restriction that space elevators can only be built on the equator?
 
Slightly off-topic - but are we going to make the (physically reasonable, but gameplay-dubious) restriction that space elevators can only be built on the equator?

:dunno:
To be honest, it would make a HUUUUUGE advantage for civs on the equator cuz all other civs without one can be rained down upon by legions of space craft that comes easier with an elevator.

I view the elevator like a landmark. The first is who gets the tribal unit to build cities first, the next is a religion, the next would be aluminum/oil next is nukes and next is the elevator. If every civ not on the equator can't build one, they'll be wiped off the map easily and only makes for a shorter and less interesting game as the player being rather smart, can rush to the equator. The AI will not.
 
:dunno:
To be honest, it would make a HUUUUUGE advantage for civs on the equator cuz all other civs without one can be rained down upon by legions of space craft that comes easier with an elevator.

I view the elevator like a landmark. The first is who gets the tribal unit to build cities first, the next is a religion, the next would be aluminum/oil next is nukes and next is the elevator. If every civ not on the equator can't build one, they'll be wiped off the map easily and only makes for a shorter and less interesting game as the player being rather smart, can rush to the equator. The AI will not.

Yeh, that's what I was alluding to by 'gameplay-dubious'. I think I agree with you - we'll just have to accept the physical implausibility of non-equatorial space elevators for the sake of gameplay.
 
Problem with launch loops is coding them. We would need two base improvements, mid-section improvements, an event to launch the loop and AI to support it. Although realistically it would prove more stable and efficient than an elevator, it would be a huge pain to code and build in-game.
 
Well, this is a rather complicated area.

The way cities evaluate buildings is with a categorization and thresholding scheme that allows the city AI to ask questions like 'what value does building X have from the primary perspective of (parameterisable set of properties such as science, culture, gold, military, ...), taking account of non-primary factors only if the primary value exceeds threshold X'.

To do this the original BTS had a method called CvCityAI::AI_buildingValueThreshold() which took a building type + a set of flags to determine the primary perspective to evaluate with respect to, plus the threshold.

This was very expensive because it caused recalculation for every building for every question (and CvCityAI::doProduction() asks about 30 or so). Hence it was recoded in C2C to do a one-time evaluation of all the constituent values for each building for each perspective flag. Those constituent elements are then cached, which allows the original value for any set of perspective flags and threshold values to be recalculated from the underlying sub-values very quickly.

The original BTS function has been renamed to CvCityAI::AI_buildingValueThresholdOriginal() - it is still used for one-off needs (where its cheaper than calculating the cached values for all possible questions), but not in the main city production choice code. Changes to building evaluation must be placed there. The one-time calculation code is in CvCityAI::CalculateAllBuildingValues(). The code there MUST parallel the code in CvCityAI::AI_buildingValueThresholdOriginal() so that both methods always give the same answer. So you also need to make changes to that routine (it's structure follows that of the simpler original routine with a fairly obvious mechanical transformation).

Usually one adds to CvCityAI::AI_buildingValueThresholdOriginal() first (easier to test) and then adds the equivalent code to CvCityAI::CalculateAllBuildingValues(). You can then enable the #define 'VALIDATE_BUILDING_CACHE_CONSISTENCY' and run a few test turns that involve your new code in the DEBUG build - it will validate that the cache-based routine returns the same values as the original by calling the original every time to validate the cached result (VERY slow - do NOT leave this turned on when you're done testing).

Bloah, that sounds like it would be beyond my abilities. I'll have to be more careful about new stuff in the future, because I thought the building eval AI was much simpler, and I certainly don't want to give you more work.

@Hydro:

I like the ideas for the Space elevator, that may be a prereq for Orbital buildings, in addition to Orbital Infrastructure. Which brings me to my other point, those three buildings should NOT be Orbital for now, first we need some more content in the TH era to balance them against. I would like to have this on buildings by the end of the V28 cycle though.
 
Top Bottom