[SDK] Question re: TechResearch & TechTrade

Joined
Jul 21, 2003
Messages
7,819
Location
Adelaide, South Australia
Hi guys. I am currently looking at doing an SDK mod for a group of people that would limit the trade in techs to those nations who actually researched them. i.e. no "second-hand" trades would be allowed in game. As far as I can see, it should be easy enough to add another argument to the TechTrade section of CvPlayer, but what I was wondering was-is there a specific tech function, already around, which allows the computer to differentiate between a researched tech and a tech recieved in trade? If so, where can I find it? Any help would be very much appreciated :).

Aussie_Lurker.
 
So I take it then that no-one can help me with this question?

Aussie_Lurker.
 
I think the answer is no, although I haven't tested it to be sure.

If you compare (unmodified) CvTeam.cpp:3810 to CvDeal.cpp:656, it looks like the same setHasTech function is used to add a tech to the relevant player/team, but there's nothing in that function that references how the tech was received.

That same function looks like a good place to start though. It could be extended to include an extra researched/traded parameter to track and modify things appropriately.

Monty
 
In CvDeal or CvTeam-or both? Thanks for your help :).

Aussie_Lurker.
 
What I had in mind was to change setHasTech to include another boolean parameter, say bCanTradeFurther, which could be set depending on whether you wanted to allow the tech to be tradeable. That would need to go into both references above, true in one, false in the other. However, setHasTech is exported from the DLL (i.e. visible to the game engine core that we can't touch) so changing it's signature is liable to mess something up.

Looking closer, I think there's a better way:

The game already has to keep track of the techs a player received on a given turn so they can't be traded on to a 3rd player until the next turn. Why not extend that so we can specify the number of turns for which the tech cannot be traded? Setting that number to -1 could satisfy the case where the tech can’t be traded further. Making that change might not be trivial as I suspect those functions are used in a few places and exposed to Python, but I think it's the cleanest way to go.

Assuming you want to go that way, the variable in question is an array of booleans (1 per tech) in the CvTeam class, namely m_pabNoTradeTech. That has two associated functions, setNoTradeTech and isNoTradeTech. Modifying all of those to work with integers rather than booleans should do the trick. I'll let a bit of (untested) code do the explaining. Compare the following to CvTeam.cpp:4305 and hopefully what I'm saying will make sense:

Code:
// m_paiNoTradeTech[eIndex] = n
// n<0 means tech can never be traded
// n==0 means tech can be traded now
// n>0 means tech can be traded in n turns

bool CvTeam::isNoTradeTech(TechTypes eIndex) const
{
	FAssertMsg(eIndex >= 0, "eIndex is expected to be non-negative (invalid Index)");
	FAssertMsg(eIndex < GC.getNumTechInfos(), "eIndex is expected to be within maximum bounds (invalid Index)");
	// return m_pabNoTradeTech[eIndex];
	return !(m_paiNoTradeTech[eIndex] == 0); 
}

// note this is already called when a player researches a tech or receives it by trade
// so it should be easy to modify a little
void CvTeam::setNoTradeTech(TechTypes eIndex, int iNewValue /*bool bNewValue*/)
{
	FAssertMsg(eIndex >= 0, "eIndex is expected to be non-negative (invalid Index)");
	FAssertMsg(eIndex < GC.getNumTechInfos(), "eIndex is expected to be within maximum bounds (invalid Index)");
	// m_pabNoTradeTech[eIndex] = bNewValue;
	m_paiNoTradeTech[eIndex] = iNewValue;
}

// this new function should be called in doTurn 
// instead of the current setNoTradeTech(((TechTypes)iI), false)
void CvTeam::decrementNoTradeTech(TechTypes eIndex)
{
	FAssertMsg(eIndex >= 0, "eIndex is expected to be non-negative (invalid Index)");
	FAssertMsg(eIndex < GC.getNumTechInfos(), "eIndex is expected to be within maximum bounds (invalid Index)");
	if (m_paiNoTradeTech[eIndex] > 0)
	{
		m_paiNoTradeTech[eIndex] -= 1;
	}
}


There are plenty of other things to change like the declaration/initialisation/deletion of that array, exposing those functions to Python, making into an option the number of turns a tech is unavailable for after trade, and so on.

Hope that's useful!

Monty
 
Back
Top Bottom