C2C - Units

With the resource caluclation I was referring to what was being discussed here:

"I don't really want to go down a huge rabbit hole with this, and get into how and why some bonuses are so hard to get, like Soap and Drugs and Tools, but I'm wondering if there's some way we can get a bonus list that includes some guidelines about how hard or easy they are to obtain at various points. Just looking at when they become valid seems to be what I did to cause some major problems for the AI, and sometimes for the player. So how should I know how accessible some bonuses are without a full building/map/tech evaluation on them all? hmm..."

I was talking about a python script that for each resource could get a value for accessiblilty. I didn't realize all of the unit code was done in XML, so the language of the script wouldn't really matter it would just have to pull the data from the XML. What you would want to do is pull the data from the xml and run a script where for each resource or resource like item not seen yet pull the resource into a hashmap or dict with the key being the resource and the value being an array of requirements. This could be done fairly quickly (O(n) time). Then you could think of this hashmap like a DAG and use a recursive function accessibility(resource) = {x*sum(a*accessibility(resource-1) + (b*accessibility(resource-1) + etc...) for resource > 0, x = resourceRarity (as defined in the xml) for resource == 0} Where x is arbitraily defined as a cost for number of steps needed and a, b are defined based on type of resource resource-1 is (if wanted, this is not really necessary). This could be memoized pretty simply by topologically sorting the DAG and running a memoization function in-order and the output would determine the accessibility of each type of resource. This could all be done pretty efficiently in O(n) time and then another script could be used to automatically use these values in a function to determine the new value of units and place them automatically into the xml. The only thing to look out here is that when you put the resources into the hashmap that no cycles are being created, or that if there are you have a way to deal with them so that the recursive function does do an infinite number of calls and cause all values to be equal to infinity. Obviously the script would have to be re-run if resource percentage values were changed, but if it inserted all of the new values automatically into the XML that shouldn't be too bad.
What I'm asking for is help from the community in determining this difficulty outside the game.

I assigned Tools, for example, as a prerequisite for the Cartwright and although the bonus is technically accessible before then by tech prerequisite came to find out it wasn't ACTUALLY something you could make until a later tech so the Cartwright was left unable to be trained basically until its upgrade until we put in different prerequisites (interesting choices there by the way team - I like!) As I replan out every bonus prerequisite on nearly every unit, I'm trying to avoid doing this in another hundred cases of mistakes we have to fix later, having learned that just looking at the tech access point for a bonus is not enough.

This is not a coding problem of trying to find an ingame evaluation valuation mechanism that somehow relates to the cost of the unit or trade value of the unit - it's a problem I'm trying to address before I commit too much time to the XML planning documentation on these units to begin with. Make sense?

Female Christian priest has 3 movement speed while the male has 2. (edit: 2 and 1, respectively. I forgot I had Famen Temple)
I'll answer or address every point you make here but I have to say this wasn't the time to make this list here because I'm trying to have a more focused discussion - so MOST of these points, being unrelated to the discussion specifically regarding bonuses (resources) in relationship to units, will be placed inside this here
Spoiler :

I haven't added all the missionaries to the list of units to be evaluated yet but there ARE some intentional variations, though not usually between the male and female versions. We WERE talking about possibly doing away somehow with M/F versioning and just choosing some to be female and some to be male - can't wait for that to happen if it hasn't already - the getting half of one half of the other makes missionary management a bit of a PITA.

Tamed Animals and Breeding Pairs could be merged. They should probably be able to build the Myth buildings as well; not having access to the Myth effects even though you still have the animals as a resource can cause a little weirdness sometimes.

It would be cool to be able to plant other animal resources on the map the same way that you can plant Donkeys and Cows.

Some Animals don't have Tamed/Breeding Pair versions that it seems like should (sheep, kangaroos, poultry).

Tamed/Breeding Pair units should probably be tradeable via diplomacy.
They were once the same thing - and at this point it's stuck in mid-development between one methodology and the next by a modder who has given up on the project. That said, my review does not currently include animal units and that's a very different effort to what I'm engaged in but we well know there are disharmonies all over the place there.

Only lightly touches on units - but, corporations and their relationship to resources that can be duplicated easily (e.g. with Herd - Cows and planting Cows on the map) should probably be re-examined.
A project to come will change a lot about how corporations work and will invite some of that re-examining for sure. It's not related to the current project though. Much.

Transport troops promotion seems to do nothing; it doesn't reflect on total cargo space, anyways.
The current project has replanned a major overhaul to the entire transportation system. There are numerous bugs and things its limited in ways I no longer accept, particularly for space/multimaps. So yeah, that's already been replotted out and awaits some of the application of all this planning effort.

Mounted units that have flanking/stack bonuses against siege units should maybe have them apply more generally, instead of against a couple very specific units?
Yeah the tags that will be used for that have been in place for many years now - they just have never been updated to using them properly. I have planned the units to do exactly this and that portion of the planning is complete and awaiting the application to XML phase.

It would be good to be able to preview stealth combat modifiers when moving onto a tile against a unit you can see when they apply, instead of only being able to preview normal odds.
The problem is you don't want to give away whether the opponent unit can see yours or not so there is some intended uncertainty at that juncture. Sure it'd be helpful, but maybe more fun to not know EVERYTHING all the time, leaving some mystery and questionability of your judgement of a situation now and then. That was my thinking anyhow.

Not sure if, given the recent rebalance of merchant costs, you still want buildings or traits that give a boost to trader production speed, e.g. the Negotiator trait or the Caravan Post.
There's rebalancing and some things have been discovered about this issue earlier, and there are long term plans to replace the one-shot production/food delivery mechanism entirely but it's for a project beyond this one so I haven't included it in the immediate unit plan. Suffice to say, once what we have is implemented, we'll see if everything works as desired enough and if not, trade mechanics deepening is likely to come soon after.

Unsure if this is intended, but Food Merchants in general represent an easy way to convert hammers into food and really speed up your city's population growth (up to the point that food consumed = food produced).
Yeah I completely agree thus one of many reasons why some of the changes I intend are coming eventually.

Not sure if you should still be able to build the base Worker and animal Workers at the same time? This lets you build base Workers then spend a little money to upgrade them, skipping some of the hammer cost.
You'll see some correction in this once the current unit review plan goes into application.

Maybe the Carrack should not be an Explorer unit, so that it's able to merge and split?
Exactly why it is. The point is to deny settling and invading for a while before allowing it. Now... the Carrack is the old Portuguese special unit right? Maybe that one could be the exception - but I'm not currently looking at naval nor cultural special units YET. I was a big fan of the way the old Carrack worked though so... it probably will be changed eventually to something like what you suggest, at least into something that CAN allow for settling on other continents earlier than other cultures.

By being exploration, it also gets some special abilities so we'll see if that's the perfect way to address it or not.

The Caravel does not get better results from tribal villages, unlike the Outrigger that it upgrades from.
Strongly agree that oversight should be repaired so when I start evaluating naval units again I'll make sure to fix that.

Not directly Unit stuff, but the AI should probably value manufactured resources more on the diplomacy trade screen. At the moment the AI just gives most of it to you for free, or for trivial amounts of gold. I'm receiving Tin ingots for nothing right now, and it's really weird.
It's at least more relative to the discussion I'm trying to have here. It's not what I'm trying to solve for but it's good to know that's where we are with that so thanks for the footnote.

It would be cool to be able to see the % success chance your missionary has of spreading a religion (affected by traits, wonders, and civics).
I agree - though I consider it low priority because at some point I hope to make them not one shot use units so much as units that can exist in a town and slowly influence the people to their views more than being blast use units.

Bandit Riders and Footpads are ridiculously strong units for their era, and remain the strongest for quite a long time.
They are meant to be. If you're NOT on Size Matters, they are slightly stronger units so as to be durable pains in the arse when they march with impunity across borders to pillage and cause trouble and invite unit sacrifices to take them out. If you ARE on Size Matters, they are that, PLUS they start off merged an extra layer than most units normally do so as to really add to that element, BUT they cannot merge or split so a double merged standard military unit should find them easy enough to dispatch and would eat them for XP to the point that you might find that you're just strengthening your foe more than weakening them by their use.

Thanks for your feedback! Even though much of it is not on the questions I have at the moment, it's all very useful to know what the pain points are out there and we agree about most of them.


I want to first say that I'm not really familiar enough with the code to assess how complicated it would be to implement this so feel free to discard the idea without further thought if it unnecessarily complicates the workings of the mod.

My idea regarding this is thus: Arrange the availability of different types of units primarily by the presence of a certain set of buildings. If you want a stone axeman, you need a stone tool maker. The stone tool maker requires some "rock stockpile" or "stone gatherer" building. If you want an obsidian swordsman, you need access to both a source of obsidian and the stone tool maker within that city or your trade network. An obsidian swordsman is principally a stone clubman with an obsidian tool, so we just apply a mutually exclusive "weapons" and "armor" upgrade to the unit - clubmen entering a city with the appropriate facilities and resources can thus receive the upgrade. The upgrades are arranged in tiers so the city applies the upgrade of the highest tier of weapon to any compatible unit that passes over it, or perhaps the upgrade is purchasable with money by units within the city limits or by some other means.

As the game progresses, more specific unit templates become available to reflect the evolving format of warfare, and new buildings become necessary to further equip your units. Unique, rare, or technologically optional paths may open up to equip normal units with exceptional or unusual equipment, perhaps even a third upgrade can provide a unit with one unusual "equipment" to customize it. At the start this could look like equipping a ground unit with ladders or hooks to provide a percent chance to bypass city defenses, or traps to provide bonuses against animals, or camouflage requiring pigments, etc. and later it could look like providing early medieval ships with rare sunstones so they can cross short patches of deep ocean, and eventually providing infantry with an anti-tank support company that gives a reasonable chance against tanks, or furnishing a destroyer with anti-air cannons that decrease incoming bomber damage and increase aerial attrition.

The AI might follow a series of procedural templates to approach building units in a city. When new units become available in a city, the AI generates a template that directs it regarding how to equip any optional upgrades to the unit, and uses the costs and properties of each template to assess its' valuableness for any mission it has in mind. When new tools become available, the AI either upgrades existing templates or spawns a new one if the tools do something special. As units become unavailable due to upgrades, some templates will naturally be removed or updated to fit the new unit if possible.

Some unique units could require access to certain upgrades which they absorb and improve on, and may have limited upgradeability. So a hoplite is a spearman with a bronze weapon, bronze armor and a bronze shield as its' equipment - there is no/limited opportunity to upgrade these properties. It's cultural upgrades give it an exceptional defense against infantry or some such. Other unique units may just be a standard unit with some special quality - minutemen are enlightenment-era gunmen with an unusually low cost that makes them more rapidly deployable, but are otherwise normal units.
Most of this is in the realm of the equipment mod plan - which is even more extensive than you've laid forth but is somewhat related. At the moment, I'm looking to define minimum prereqs to be established on units, with the eventual understanding that yes, more advanced accesses will lead to more powerful unit equipment assignments that will vary units significantly by the kinds of equipment their civilization has gained access to and the various qualities of those equipments. I understand I didn't say that was part of the plan so I don't blame you for mentioning all this - it's just... a number of projects down the line, this being one to help form the minimum basis for that eventually.
 
We could probably clear up some data usage if we could kill the 2 original tags entirely and if that's the plan then I can start expressing all bonus prereqs in these terms.
This would be strongly recommended, but first be absolutely sure the system works properly! If it's like anything else in this mod, there are likely oddities that need fixing xD
Perhaps we need to consider WHAT resources are more a representation of a 'large amount of access but everyone has it' vs WHAT resources represent 'if you don't have it, you really DON'T have it'.

Somewhat like the definition on D&D 3e skill checks that states whether you can attempt a skill if you haven't learned it or not.
General rule of thumb could be that if a unit requires a raw, non-living(maybe?) map resource - stone, saltpepper, etc - then it can be done without, albeit with the +100% cost per requirement missing or some such. Reasoning behind this is that a "Stone" resource represents a vein of easily accessed, high quality stone for instance, such that the lack thereof merely means lacking a high quality/quantity access of it rather than the somewhat nonsensical complete and utter lack of any stone whatsoever (and the lack of quality/quantity being that which drives up the cost of units requiring it). Living resources (horses, etc) and manufactured resources, however, would be required absolutely; need rifles for riflemen, large herds for cavalry, etc (camel riders without camels would be weird, hence non-living prereq). This may require a slight to moderate expansion to introduce more manufactured resources, however.

It also opens an interesting possibility where you might support a war ally by gifting them manufactured resources - e.g. rifles - for them to produce basic units with despite them not having the tech. Could open some interesting options, but also require careful thinking.
"how the info is presented ..." Yeah alright good points but anyone have any suggestions as to what could make that easier? ... But what about for the players? Should we be trying to provide some kind of in play screen that shows what resources by tech you could have but don't - and then some way to say whether you'll need to get it from the map (what improvements would access it, what units can build such improvements) or if it comes from a specific building and what you might be missing in other prereqs to build that building somewhere or if you CAN build it somewhere now but you've just overlooked that?

Ideas maybe?
This is more of a pedia issue than otherwise; probably safe to shelve as it is fundamentally solvable in some manner, no matter the decision that's made regarding unit prereqs. Toffer's work in making the pedia faster, for instance, has gone a long way in making it much easier to discern prereqs. Just keep clicking on elements in the 'requires' section at the bottom xD

Not worth putting too much extra brainpower into this now. It'll be solved later, functional now, not worth making current task harder/larger than it already is.
Not sure if, given the recent rebalance of merchant costs, you still want buildings or traits that give a boost to trader production speed, e.g. the Negotiator trait or the Caravan Post.
Ah, I was wondering what gave those. The "Freight" unit will have to be examined if it can escape the >1 return value with maximum production bonuses, not sure if it does now.
 
Last edited:
You're taking the problems I proposed head on in your comments - thanks Blaze! Would you be willing to help me with evaluations regarding this?
This would be strongly recommended, but first be absolutely sure the system works properly! If it's like anything else in this mod, there are likely oddities that need fixing xD
 
You're taking the problems I proposed head on in your comments - thanks Blaze! Would you be willing to help me with evaluations regarding this?
Hah, why not.

Currently my branches include:
Audio changes w/Philososhy
Lake tweaks (almost done?)
TD alterations
Importing, making changes to Toffer's MToS wrt Myths

I'll see if I can actually finish, hmm, two of those, then see about investigating the GOMType structure for prereqs.
 
It also opens an interesting possibility where you might support a war ally by gifting them manufactured resources - e.g. rifles - for them to produce basic units with despite them not having the tech.
This is why I LOVE this mod - it ever evolves in the most bizarre ways, and it's still GREAT.
 
It actually does allow for nested conditions yes, so it's pretty cool in that way. I've just been told here and there that the 'AI doesn't have visibility on it' and I THINK we've fixed problems with pedia visibility on those issues but there used to be some struggles there even making it so the player could see it. Also might be tougher to identify what's missing when you hover over a greyed out unit that isn't getting something it needs rather than seeing there the red highlighted 'NEEDS THIS' notification, particularly since it might be a bit more complicated - BUT I also think that was resolved too. I don't know for sure so that's part of what I'm asking here.

Another neat thing you can do is make a tech vs building vs resource prereq. So you either have x tech, y building OR z bonus. Things like that appear possible though so far I only see buildings and bonuses being employed in the TrainCondition tag and I'm not sure about civic and tech use behavior but I suspect it would check for if the player has those things now. Thus what could be cool is, say, on some nukes, you either need Heavy Water, OR you have an advanced enough tech that you no longer require it. That sort of thing.

I also think you can use it to nest entirely different comparison sets, like you must have one of either A or B AND One of either C or D OR ignore all of that if you have E. From what I saw in the few forms of examples, there could be some really interesting stuff one COULD do. @AIAndy may have set up something more interesting than I realized here because I got caught up in some of the unanswered vaguaries, like, what does it mean to HAVE exactly, and how do I bracket various things I might want to say? Some of the examples seem to actually answer better to that last question than I understood before as I've seen AND condition lists and THEN ALSO Or conditions.

A look through the code from one of you better programmers might be helpful here to help me see what I'm really working with.

We could probably clear up some data usage if we could kill the 2 original tags entirely and if that's the plan then I can start expressing all bonus prereqs in these terms.
The boolean expressions can be nested and there is no depth limit. You can consider them a tree that describes the order of evaluation. The leafs are evaluated first and then you work up the tree until you get to the root. In the XML representation of the tree you write the operator (And, Or, Not) first as tag and then the subtrees inside it. Maybe this helps (although in this case you are not restricted to a binary tree): https://en.wikipedia.org/wiki/Binary_expression_tree
And of course the forum post that describes the boolean expressions: http://forums.civfanatics.com/showpost.php?p=11598257&postcount=27
If you want to know what HAVE means in each case, check the hasGOM functions in CvGameObject.cpp (especially CvGameObjectCity::hasGOM).
 
The boolean expressions can be nested and there is no depth limit. You can consider them a tree that describes the order of evaluation. The leafs are evaluated first and then you work up the tree until you get to the root. In the XML representation of the tree you write the operator (And, Or, Not) first as tag and then the subtrees inside it. Maybe this helps (although in this case you are not restricted to a binary tree): https://en.wikipedia.org/wiki/Binary_expression_tree
And of course the forum post that describes the boolean expressions: http://forums.civfanatics.com/showpost.php?p=11598257&postcount=27
If you want to know what HAVE means in each case, check the hasGOM functions in CvGameObject.cpp (especially CvGameObjectCity::hasGOM).
OK, I pretty much was starting to feel clear on this so this confirms what I thought I was figuring out there. Thanks!
 
Hah, why not.

Currently my branches include:
Audio changes w/Philososhy
Lake tweaks (almost done?)
TD alterations
Importing, making changes to Toffer's MToS wrt Myths

I'll see if I can actually finish, hmm, two of those, then see about investigating the GOMType structure for prereqs.
The main thing I think we need to figure out is what so many modders before have said about 'the AI is blind to these' - and find how it 'isn't' to the original tags and how we can update the AI to understand the adjusted valuation for needing prereqs if we were only using AIAndy's system. On my end, I just need to know that I can start planning on getting rid of the original tags safely.
 
The main thing I think we need to figure out is what so many modders before have said about 'the AI is blind to these' - and find how it 'isn't' to the original tags and how we can update the AI to understand the adjusted valuation for needing prereqs if we were only using AIAndy's system. On my end, I just need to know that I can start planning on getting rid of the original tags safely.
Well, there is AI code for the existing tags. While you probably could not do it in its full generality, you could do the same for the standard cases of TrainCondition that are similar to what the old tags express.
As an example here is the code for determining if a bonus that a building provides enables the city to build a new unit and therefore the building value should be increased to include the unit value:
Code:
if ( kUnit.getPrereqAndBonus() != NO_BONUS )
{
  if ( isFreeBonusOfBuilding(kBuilding, (BonusTypes)kUnit.getPrereqAndBonus()) )
  {
    if ( !hasBonus((BonusTypes)kUnit.getPrereqAndBonus()) )
    {
      bUnitIsEnabler = true;
    }
  }
  else
  {
    if ( !hasBonus((BonusTypes)kUnit.getPrereqAndBonus()) )
    {
      bUnitIsBonusEnabled = false;
    }
  }
}

bool bHasORBonusAlready = false;
bool bFreeBonusIsORBonus = false;
int iFreeExtraBonusCount = 0;

for (int iK = 0; iK < GC.getNUM_UNIT_PREREQ_OR_BONUSES(); iK++)
{
   BonusTypes eXtraFreeBonus = (BonusTypes)kUnit.getPrereqOrBonuses(iK);

   if ( eXtraFreeBonus != NO_BONUS )
   {
     iFreeExtraBonusCount++;

     if ( hasBonus(eXtraFreeBonus) )
     {
       bHasORBonusAlready = true;
     }
     else if ( isFreeBonusOfBuilding(kBuilding, eXtraFreeBonus) )
     {
       bFreeBonusIsORBonus = true;
     }
   }
}

if ( iFreeExtraBonusCount > 0 && !bHasORBonusAlready )
{
   if ( bFreeBonusIsORBonus )
   {
     bUnitIsEnabler = true;
   }
   else
   {
     bUnitIsBonusEnabled = false;
   }
}
The best way would be to add a "What if" evaluation to BoolExpr. You give the evaluate method an override list like "Has Bonus X" and "Has Building Y", it passes it down the expression tree and when BoolExprHas is evaluated, it checks the override list first before checking the real game object. That way you can then evaluate the TrainCondition without override and if it returns false but after you set the override to what the building provides and afterwards the evaluation returns true, then that building enables the unit.
So actually, now that I think about it, it would not be that hard to do that in a pretty generic way.
 
Well, there is AI code for the existing tags. While you probably could not do it in its full generality, you could do the same for the standard cases of TrainCondition that are similar to what the old tags express.
As an example here is the code for determining if a bonus that a building provides enables the city to build a new unit and therefore the building value should be increased to include the unit value:
Code:
if ( kUnit.getPrereqAndBonus() != NO_BONUS )
{
  if ( isFreeBonusOfBuilding(kBuilding, (BonusTypes)kUnit.getPrereqAndBonus()) )
  {
    if ( !hasBonus((BonusTypes)kUnit.getPrereqAndBonus()) )
    {
      bUnitIsEnabler = true;
    }
  }
  else
  {
    if ( !hasBonus((BonusTypes)kUnit.getPrereqAndBonus()) )
    {
      bUnitIsBonusEnabled = false;
    }
  }
}

bool bHasORBonusAlready = false;
bool bFreeBonusIsORBonus = false;
int iFreeExtraBonusCount = 0;

for (int iK = 0; iK < GC.getNUM_UNIT_PREREQ_OR_BONUSES(); iK++)
{
   BonusTypes eXtraFreeBonus = (BonusTypes)kUnit.getPrereqOrBonuses(iK);

   if ( eXtraFreeBonus != NO_BONUS )
   {
     iFreeExtraBonusCount++;

     if ( hasBonus(eXtraFreeBonus) )
     {
       bHasORBonusAlready = true;
     }
     else if ( isFreeBonusOfBuilding(kBuilding, eXtraFreeBonus) )
     {
       bFreeBonusIsORBonus = true;
     }
   }
}

if ( iFreeExtraBonusCount > 0 && !bHasORBonusAlready )
{
   if ( bFreeBonusIsORBonus )
   {
     bUnitIsEnabler = true;
   }
   else
   {
     bUnitIsBonusEnabled = false;
   }
}
The best way would be to add a "What if" evaluation to BoolExpr. You give the evaluate method an override list like "Has Bonus X" and "Has Building Y", it passes it down the expression tree and when BoolExprHas is evaluated, it checks the override list first before checking the real game object. That way you can then evaluate the TrainCondition without override and if it returns false but after you set the override to what the building provides and afterwards the evaluation returns true, then that building enables the unit.
So actually, now that I think about it, it would not be that hard to do that in a pretty generic way.
@Blazenclaw @Toffer90 @MattCA Any of you guys follow that enough to implement it? I actually probably do but I'm not ready to get back into the code for a while yet.

@AIAndy - thank you for this! It's too bad you haven't decided to come back and work with us further - I think you'd REALLY like how things are being done so much more efficiently now with Git and the automatic compiling and such. I remember you saying how much you were turned away by the compiling time last you considered it.
 
Hey is it important to call removeDelayedResolution in the info class destructors?
Absolutely. This is a memory patching technique. If an info class is destroyed while it has a delayed resolution pointing to a part of its memory and that delayed resolution is not removed, then the delayed resolution will patch the memory anyway. At best it will be currently unused memory, at worst this memory will now be part of something else and overwrite some part of it.
@AIAndy - thank you for this! It's too bad you haven't decided to come back and work with us further - I think you'd REALLY like how things are being done so much more efficiently now with Git and the automatic compiling and such. I remember you saying how much you were turned away by the compiling time last you considered it.
Mostly I am turned away by the archaic C++ dialect. But it is also that when you program a lot during the day as part of your job, then it is more interesting to do something different in your free time.
 
Mostly I am turned away by the archaic C++ dialect. But it is also that when you program a lot during the day as part of your job, then it is more interesting to do something different in your free time.
Totally understood. My involvement with this has indeed shrunk some in response to more intensive computer work at the job - of course I also credit what I've done here for preparing me to DO some of that work too which is cool. But yeah, I can see how if I was actually coding at work I'd REALLY not feel like doing it much during my time off.
 
Totally understood. My involvement with this has indeed shrunk some in response to more intensive computer work at the job - of course I also credit what I've done here for preparing me to DO some of that work too which is cool. But yeah, I can see how if I was actually coding at work I'd REALLY not feel like doing it much during my time off.
Well, I have actually implemented the code for the "What if" evaluation of BoolExpr and applied it to the AI code that values buildings that enable buildings with ConstructCondition. The code there is pretty clear as it evaluates canConstruct with an extra building parameter so it checks if the building is actually constructable.
The equivalent code that values buildings that enable units I have quoted up there. But it is different in that it only checks a very specific subset of what canTrain checks. I wonder if this is a well chosen subset as it seems a bit limited so it might easily add value to buildings for enabling training of units that the AI cannot actually build even with that building. Of course that depends on what is actually used in the XML as condition for a unit (which I don't know as I last played C2C a long, long time ago).
 
I have been skimming the XML files and it seems like the unit and building dependencies have changed a lot in the last years (well, nearly a decade ...). So if I get that correctly, to build a unit you usually need a building in the city itself and certain resources that are produced anywhere in your empire.
That means that constructing a building can enable another city to produce a unit (or enable it to construct another building).
How important is that?
When you play C2C yourself, do you consider that an important strategic decision? Or do those resources happen more or less automatically when you need them without specifically trying to set them up for your empire?

After looking at it some more it seems like the building and unit considerations in regards to resources are a bit of a duplicate in the building value calculation as it also includes the resource value for every resource produced by the building which in turn then includes separate calculations for enabling units and buildings.
I wonder if that is intended.
 
Last edited:
That means that constructing a building can enable another city to produce a unit (or enable it to construct another building).
How important is that?
When you play C2C yourself, do you consider that an important strategic decision? Or do those resources happen more or less automatically when you need them without specifically trying to set them up for your empire?
It can be quite important sometimes, other times a bit less so. For instance, it might take me a hot sec to get a settler to a copper resource if there's not one in my borders when the resource is revealed, so it's not infrequent for me to have a young 1-2 pop city placed on/near a resource I need for some building chain (e.g. copper mine/smelter). That city will strongly prioritize those buildings; by themselves, the stats would indicate I should build them much much later (very low production return on investment, better do mining camp/tool workshop etc instead), but it's quite beneficial for the rest of my cities to have that resource.

I guess for me the rule of thumb for me is something like:
Buildings that provide a new resource I don't have already are 2-5x more valuable than their stats would indicate, in the top 10% or so of cities that can construct it when sorted by city production.

When I unlock salt mining, for instance, I don't want a salt granting improvement being constructed in every single city at high priority, just the one that can construct it soon and isn't currently working on a wonder or something else critical like defensive units, settlers, etc. After that, it has just regular value as any other buildings.
 
Last edited:
I have been skimming the XML files and it seems like the unit and building dependencies have changed a lot in the last years (well, nearly a decade ...). So if I get that correctly, to build a unit you usually need a building in the city itself and certain resources that are produced anywhere in your empire.
That means that constructing a building can enable another city to produce a unit (or enable it to construct another building).
How important is that?
When you play C2C yourself, do you consider that an important strategic decision? Or do those resources happen more or less automatically when you need them without specifically trying to set them up for your empire?

After looking at it some more it seems like the building and unit considerations in regards to resources are a bit of a duplicate in the building value calculation as it also includes the resource value for every resource produced by the building which in turn then includes separate calculations for enabling units and buildings.
I wonder if that is intended.
It's probably overprocessing and unnecessary but we've had such a hard time in some cases getting the AI to generate what it needs for itself that this redundancy has come about. I'd like to think it's really only important for a nation to recognize that it doesn't have a resource and seek it through a building during building evaluations, and perhaps just have some kind of valuation building up if it recognizes it COULD have a unit access but doesn't due to the lack of a resource, and to note what resource that may be for later use in adding to cause to trade and go to war to take that resource if it cannot get it through buildings and has somewhere planned to obtain it already and is just waiting for that plan to finalize.

In play, that's exactly how that CAN play out - you sometimes have to either get a trade partner for critical unit access - or plan for war because there's no other alternative.

And sometimes that can be due to a failure of ANOTHER resource access. For example, if I cannot build a building that gets me Copper Wares, that is because I don't have access to Copper Ingots. If I can't trade to get them, and I can't build a building that gets me copper ingots anywhere, then that is likely because I don't yet have access to copper ore (and nobody else has it or is willing to trade it). I may be able to identify that a friendly neighbor has copper ore but has yet to get copper ingots for some reason (maybe vicinity is lacking despite the ORE being on the map in their territory) and maybe I'd wait with the plan to trade it from them when possible. I may be able to identify that there is some copper ore I could settle to obtain (at which point the national need for that resource should really influence my next settling selection) and I might also be able to see that only a hostile neighbor has that ore and if I ever want to be able to keep up in war, I HAVE to plan to attack them to get it right away.

That's how it plays out for a player sometimes - that's a heck of a string of things to consider for an AI though broken down into various steps and using a national sense of urgency for a resource that reflects the power difference they'd have if they could achieve such a complex objective, would perhaps be possible. I was hoping in the planned unit AI stuff I'm working on, to start building into this sort of 'objective' type thinking somehow. At least in the sense that obtaining resources, as a general 'desire' for helping to define military priorities, might be able to play a role in target objectives - as well as the idea of 'denying' an enemy access to key critical resources they rely on for ongoing production of units at the cutting edge of their value in the roles they play.

I may have given more complex an answer than is needed here.
 
The redundancy does not necessarily make it better as they increase the complexity and calculate parts of the same thing but in different ways.
Both try to include the value of being able to produce a unit into the value of something else but instead of calling some unit value function, they try to replicate it.
One of them considers all enabled units the same value, the other values them by the square of their combat strength.
Neither compares it to what they could currently build.
 
The redundancy does not necessarily make it better as they increase the complexity and calculate parts of the same thing but in different ways.
I completely agree. The purposes should be different at both checkpoints.
1) Buildings - need to know if by providing this bonus they can actually make a highly significant contribution and thus be more important to build
2) Units - When checked to see if they can be trained, if they can't due to a bonus (or perhaps specific building) but are otherwise qualified, need to give a value to the player level to track to help the player level decisions that may lead to gaining access.
Both try to include the value of being able to produce a unit into the value of something else but instead of calling some unit value function, they try to replicate it.
One of them considers all enabled units the same value, the other values them by the square of their combat strength.
Neither compares it to what they could currently build.
I've noted these issues are a huge problem in the way our units are evaluated and have been building an in-depth plan to restructure the entire philosophy behind how the AI 'values' units entirely. It is much too in-game evaluatory what the value of a unit is and inconsistent to any kind of centralized mechanism. It's also heavily flawed in HOW it evaluates and the massive complexity of our units makes it almost impossible to resolve in an automated sense.

So my plan is to basically hard set in the XML the value of a unit according to its AI role vs any and all other units that can participate in that role. It will make it VERY clear, very quickly, in the code, how to select a 'best' unit or compare a unit in value according to the purpose of the evaluation which would always be specific to the AI type role. There MAY be times when a very small number of units are tied for 'Best' for a purpose, and in such a case, a cyclic selection of such tied units becomes tracked according to a small vector that tracks the last selected unit in that tie.

In addressing what you're pointing to, when a 'better' unit for a role should be possible but denied as a result of a missing bonus that COULD be obtained, it's not worried about strength or any other unit evaluation, it would just simply note that basically the player is missing out and here's why and then that bonus becomes more important to get for the player by a constant and influential degree (possibly even something that the leader personality profile might interact with - some might be more sensitive to these needs than others.)

Anyhow that's a very very brief overview of part of the planning taking place for that ultimately. I've already charted out increasing value ratings for all upgrades along all planned UnitAI types for land units and yeah that took some many months. It has a bit before it can be implemented though so any improvements in the meantime are great, particularly if they prepare for this sort of implementation.
 
Ok, so I'm evaluating bonus prerequisites for units now and there's a few things I need in terms of buildings.

I might have to make these buildings myself I suppose. So I guess I need to know if the concepts conflict with anything else in the mod design.

1) Wood: I brought this up elsewhere earlier today but got no response and that's fine but now that I'm looking closer, there's another consideration that goes beyond what I originally stated AND this is more on topic in this thread anyhow.

Wood, as a resource, is useful as a unit prerequisite, particularly for spears and clubs and such. However, I can't currently USE it as one, despite how beneficial it would be to have access to, because although we have the
BUILDING_GATHERER_DRIFTWOOD at Gathering, we have no OTHER way to get wood that early. Which is just frustrating.

What I need is a simple Stick Gatherer building that comes in at Gathering that comes from having any kind of wooded, even bamboo, feature in city vicinity that gives wood as a resource. I can think of ways to go further with this when equipment mod starts coming closer in on the horizon but for now this would suit the basic need for assuring that there's cause for spears and clubs. I know you might say - oh but what if you actually don't HAVE ANY wood in the region (which of course is quite rare) - I say then it should be interesting working more with stone throwers and such for a while longer.

At the moment, it's quite odd that the only way we can get wood so early is if we're on a ... a beach?

2) Bone: the obvious alternative to me here would be to use heavy bones as clubs. However, strangely, bones aren't opened up until cooking. What... you can't pick them from a carcass, particularly after leaving the carcass to sit for a while? I mean what's left of a carcass when it runs its course but bone? I don't think we should have to know how to cook before we could use it as an alternative to wood for clubs.

So I would also like to have a 'Bone Collector' building that requires access to Carcass, which is common at Scavenging. Carcasses are usually larger animals for the sake of this mod so that works pretty well here. If we can get carcasses out of rabbits, this might not fit as well as hoped on just a Carcass prerequisite.

Interestingly, between both buildings, Scavenging and Gathering would both give a new building with +1 Production and access to a resource as a base I think, which would make an even more interesting x2 grid selection divide.
 
Top Bottom