[BTS] Exclusive technologies

Jarmrik

Prince
Joined
Oct 9, 2016
Messages
307
Hi,
Actually working on deep mechanics for a basis for my several WIP mods, I am looking for a way to make some technologies "exclusive".
Explanation:
The aim is to make it so that, if the player researches "tech_A", he/she cannot research anymore "tech_B" (and vice-versa), this way forbidding the access to a full branch of the tech tree, and the ressources/buildings/units/etc made available by this tech.
I'm of course looking for the easiest method to do so, as I don't work with C++, and I'm nothing more than a Python monkey (just able to copy and paste code with changing some variables).
I realised that I don't really know the base game mechanics, so asking here: how do tech obsolescence work? I had the idea of making tech_A obsolete by having tech_B, and tech_B obsolete by having tech_A. Would it work this way? Is it more complicated and requires deeper programming?
 
The game does not actually have a concept of tech obsolescence. Only certain things enabled by technologies (buildings or improvements) can be obsoleted by another technology, but that doesn't sound like it would be helpful for your goal.

The only condition for a tech to be researchable is having its prereq techs, so I don't think there is much room for an XML workaround of some kind.

However, the game provides the cannotResearch Python callback, which you can find in CvGameUtils.py. I am not sure how far you want to go with Python, but a basic condition should not be too complex. Here's an example of what it would look like:
Code:
    def cannotResearch(self,argsList):
        ePlayer = argsList[0]
        eTech = argsList[1]
        bTrade = argsList[2]

        eTechA = gc.getInfoTypeForString("TECH_A")
        eTechB = gc.getInfoTypeForString("TECH_B")

        if eTech == eTechA:
            if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(eTechB):
                return True

        elif eTech == eTechB:
            if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(eTechA):
                return True

        return False
Basically, if the game asks for TECH_A you check if the player already has TECH_B and vice versa. The function needs to return True to disable access to the tech because it is "cannotResearch". Note that "TECH_A" and "TECH_B" need to match the actual XML tags of the technologies you want to be mutually exclusive in this way. Please be aware that I did not actually test this code.
 
Thanks a lot Leoreth for your clear explanations and your possible code.
Two questions:
- Would this code need more checks or should it be enough?
- Won't the use of callback be too "greedy" for the game engine?
 
Actually working on deep mechanics for a basis for my several WIP mods, I am looking for a way to make some technologies "exclusive".
Good ol' MoO2 ways :cowboy:

- Would this code need more checks or should it be enough?
I believe that's all but you need to set up every tech pair separately.

- Won't the use of callback be too "greedy" for the game engine?
Hardly. It's just a simple check.
However I'm not sure about the impact on the AI.
- The AI won't understand that it cant research both techs.
- If the AI cannot research some important tech (e.g. religion founding) it may stop researching altogether.

And don't forget that Civs may still get the tech via diplomacy, unless you set them to non tradable.
 
you need to set up every tech pair separately
Can you develop/rephrase? I'm not sure to understand
However I'm not sure about the impact on the AI.
That's my concern with python, and the reason I secretly hoped there would be an XML solution.

As an alternative, I've thought about spawning a special unit with an event. It would be able to build the respective buildings (oh? really?) necessary to build the exclusive units and buildings of each branch. But I remember I have read somewhere here that AI doesn't like units unlocked by buildings. Your feeling/experience on this?
 
Can you develop/rephrase? I'm not sure to understand
Something like:
Python:
def cannotResearch(self,argsList):
        ePlayer = argsList[0]
        eTech = argsList[1]
        bTrade = argsList[2]

        eTechA = gc.getInfoTypeForString("TECH_WRITING")
        eTechB = gc.getInfoTypeForString("TECH_READING")

        if eTech == eTechA:
            if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(eTechB):
                return True

        elif eTech == eTechB:
            if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(eTechA):
                return True

        return False

def cannotResearch(self,argsList):
        ePlayer = argsList[0]
        eTech = argsList[1]
        bTrade = argsList[2]

        eTechA = gc.getInfoTypeForString("TECH_SINGING")
        eTechB = gc.getInfoTypeForString("TECH_DANCING")

        if eTech == eTechA:
            if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(eTechB):
                return True

        elif eTech == eTechB:
            if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(eTechA):
                return True

        return False

So you can have Writing or Reading, Singing or Dancing.


As an alternative, I've thought about spawning a special unit with an event. It would be able to build the respective buildings (oh? really?) necessary to build the exclusive units and buildings of each branch. But I remember I have read somewhere here that AI doesn't like units unlocked by buildings. Your feeling/experience on this?
If events than I'd recommend events with multiple choices. This way the AI has to choose something one option.
And you can even give different options different flavors: military, science, etc.
You can even come up with custom flavors. In my mod civics often have 'autocratic', 'oligarchic' or 'democratic' flavor. And I have also added one or two of those to leaderheads in the xml.

So I think events are a pretty good workaround. A bit tedious but could work :)
 
Regarding the tech AI: it will be aware which techs it can research, but it won't be directly aware when a choice forecloses a branch of the tech tree. The AI doesn't pick techs one at a time but searches a few steps down the tech tree, so you do not have to worry about losing access to a tech it wants.

I think you have a similar issues with building/unit approaches. The AI will probably struggle to understand that buildings unlock units etc.

Maybe this is useful but: I just remembered that events can also obsolete buildings.
 
Oh true, I was thinking of an event that implements this in Python, so not better than what we are discussing already.
 
Thank you both for your analysis.
It appears then the event should be the best/less problematic choice in terms of implementation and overall AI. But how to make it? I found no example of events giving a tech to the player/AI in the regular events.
As a trigger, I can use the standard system with the OrPrereq>PrereqTechs, it's ok. With the event itself, I thought of using the "airliner crash" event, but it's a % of research that is given to the player. Will a 100% research costs for techA (or techB) give it to the player, while it's defined as "not searchable"?
 
The bad news is, that you cannot add tech purely via events. Even if the the requires only 1:science: and you gain 1000 :science: , you still don't get the tech AFAIK.

So what do you want to have as different choices? If it's only units and buildings, than you can make the event place building A or B providing 1 copy of resource A or B that are required for different units and buildings
 
That's what I was afraid of...
Your lastest solution was my first idea. But I was looking for something tech-related to have a progression in the possibilty of getting new attributes, units, buildings, etc...
Now if I understand well your last proposal, the event will give a dummy building that would give a ressource necessary for the exclusive elements. Will AI understand this? Won't it get stuck when not getting ressource B because ressource A chosen in the event?
 
As long as I hold you, do you have knowledge in how healing works in the base game, and how we can alter it?
I would like to make two medic promotions: one for the organic units, one for the mechanical units. Sounds doable?
 
As long as I hold you, do you have knowledge in how healing works in the base game, and how we can alter it?
I would like to make two medic promotions: one for the organic units, one for the mechanical units. Sounds doable?
Not without dll editing.
 
Back
Top Bottom