[SDK] Merging Advanced Diplomacy 2 into K-Mod 1.45

Xyth

History Rewritten
Joined
Jul 14, 2004
Messages
4,106
Location
Aotearoa
I've merged everything so far except one function in CvPlayerAI.cpp, which has been significantly rewritten in both mods. Normally I prefer doing it all myself, but this particular function is melting my brain a bit. Does anyone know if such a merge has been done before and, if so, where I might find it? Or have any tips on how best to tackle this?

I've attached the two files. The troublesome function is AI_counterPropose()
 

Attachments

It's a bit hard to comment on this because the AD2 file won't download. All I get is a 1x1 gif image. However looking at K-Mod alone gives a strong pointer towards what the problem is.

I looked at the function in K-Mod and it looks to me like a merge is not possible, at least in the sense that most people use the word merge. Usually merging is about getting a function to also do A and perhaps some other mod wants it to do B and you can then just add A and B. That's not even remotely possible here.

Here the problem is that the two mods changes behavior of a vanilla function, meaning instead of vanilla, it does A. Then you can't add the other mod because the recipe for that one is "instead of vanilla, do B". You can't replace the vanilla behavior with A and B at the same time.

Let's make a simple example to display the type of issue you seem to have here. Say we have two mods, which alters the cost of hurrying building a unit. They both alter the very same code and if you just add one to the end of the other, it ends up with a cost of A and then it cost B, meaning you suddenly pay twice, which is not the intended goal. You can't just put the mods together and expect them to work together in such as case.

I fear the only solution is to take a step backwards and think about this. What is it that you want the function to do? Can you get away with just using the code from one mod? If you really need some code from both mods, then be prepared to program and you will have to consider how to merge them. Essentially you will end up programming a new mod, which is not just the sum of two mods, but with something none of those two mods have.

The quality of my answer would be better if I had seen the code for both mods, but the answer would still be the same: the solution is real programming, code design and considerations of a behavioral goal, not the copy paste you usually do when you merge mods.


Last, I will add the note that games which can load multiple mods at the same time would not be able to solve this problem. In fact when they run into problems like this, the two mods would list each other as incompatible because loading both would break one or both of them. It's not a problem due to only being able to load one mod at the time. It's a true code design conflict. In fact the odds of fixing it is better because it's a merge and not loading multiple mods.
 
It's a bit hard to comment on this because the AD2 file won't download. All I get is a 1x1 gif image.

Odd that it won't download. I've rezipped it and attached it to this post, if you want to try again.

I looked at the function in K-Mod and it looks to me like a merge is not possible, at least in the sense that most people use the word merge. Usually merging is about getting a function to also do A and perhaps some other mod wants it to do B and you can then just add A and B. That's not even remotely possible here.

Yeah, it's definitely not a merge as such. AD2 adds code to the BTS function, which K-Mod has rewritten extensively. Basically that function deals with how the AI responds to different trade options, and AD2 adds some new types of trades. I need to rewrite the AD2 additions to correspond to K-mod's approach. I've managed to achieve similar things elsewhere in the DLL, just this particular function has me a bit stumped. I'm very confident with Python but still adjusting to working with C++. I'll persevere, but I wanted to check in case its been done before, or an obvious solution is apparent to someone more experienced with the DLL than I.
 

Attachments

Last edited:
In that case, you can probably just merge the K-mod section entirely and have it work. Potentially, the only effect would be that the AI wouldnt propose the new trade types -- you might also need to add some catches to have it skip some of the logic if it does run into one of the new trade types.

Then go back and work on adding in logic for the new trades.
 
So from how I understand counterPropose(), the important part is the section where "case TRADE_MAPS" etc. comes into play, i.e. the actual tradable items where the AI needs to determine their gold value to figure out what it needs to propose to balance the deal in its favour. So if Advanced Diplomacy adds a new item to trade (e.g. units), it should probably be added there as well. Since the code usually relays this calculation to some AI_xyzTradeVal() method (either in CvPlayer and CvTeam), it's probably a good litmus test to see if Advanced Diplomacy adds such a method for its new tradeable items and make sure it is also called in counterPropose() whenever the others are.
 
yes, as Leoreth said, it actually boils down to adding the new trades in the section following the switch statement switch (pNode->m_data.m_eItemType), so that the AI considers the new trades when trying to balance a trade. For example
Code:
switch (pNode->m_data.m_eItemType)
{
        case TRADE_CONTACT:

                    iItemValue = GET_TEAM(getTeam()).AI_contactTradeVal(GET_PLAYER(ePlayer).getTeam(), (TeamTypes)pNode->m_data.m_iData);
                    break;

AFAIK kmod didn't change the scaling of the itemValues, but this should be verified.
 
Back
Top Bottom