Making new "tradeable" categories

JDHalfrack

Chieftain
Joined
Mar 18, 2009
Messages
35
If this has been asked/answered somewhere else, please direct me to it. I have been searching for the last hour and have come up with nothing that explains what I am looking for.

I would like to make the option to add "Unique Buildings" (after "Construction" has been learned) and "Unique Units" (after "Bronze Working") to the "Tradeable Items" list. I cannot figure out how to do this. If anyone can help me by explaining where to start, I would greatly appreciate it. The programming is easy enough for me to figure out, I just have no clue where to even begin.

Thanks in advance!

JD
 
I don't understand what you're asking.
 
I don't understand what you're asking.
When you start diplomatic talks with another player, you can trade gold, world maps, resources, cities, etc..." I would also like the ability to trade Unique Buildings. So, if I am America, I would like to be able to trade the "Mall" to France for gold or something. Now, France can build the Mall instead of supermarkets. Get it?

JD
 
Yeah, that clarifies things. Sorry I don't know where trading resources with other civs is handled. My gut tells me it would be in CvPlayer, or an AI file assosiated with CvPlayer.

Edit: Found this in CvGame.cpp

void CvGame::implementDeal(PlayerTypes eWho, PlayerTypes eOtherWho, CLinkList<TradeData>* pOurList, CLinkList<TradeData>* pTheirList, bool bForce)
Code:
{
	CvDeal* pDeal;

	FAssertMsg(eWho != NO_PLAYER, "Who is not assigned a valid value");
	FAssertMsg(eOtherWho != NO_PLAYER, "OtherWho is not assigned a valid value");
	FAssertMsg(eWho != eOtherWho, "eWho is not expected to be equal with eOtherWho");

	pDeal = addDeal();
	pDeal->init(pDeal->getID(), eWho, eOtherWho);
	pDeal->addTrades(pOurList, pTheirList, !bForce);
	if ((pDeal->getLengthFirstTrades() == 0) && (pDeal->getLengthSecondTrades() == 0))
	{
		pDeal->kill();
	}
}

Edit2:
Oh, looking at the whole source, I'm pretty sure it'd be in CvDeal.
 
CvDeal will allow you to make the effects happen, but I don't think that makes those options show up in the Trade Window. Unfortunately, that window is in the EXE AFAICT. I would love to see this; it's a great idea, and for units I'd want it to be a GPT deal so I can cancel it and stop them from building Cossacks after a while.

I find where to modify code by starting with something I'd expect it to call and then using "Find all references" in the IDE. For example, showing the list of cities that can be traded requires grabbing the city's name, so I'd go to CvCity::getName() and then find all places in the code that use that function. Check each one for the one that creates the list of tradeable cities. You'd want to insert your code there.

Plus, you'll need to make CvPlayerAI capable of evaluating such a deal and CvDeal capable of implementing the deal. CvCity will need to be made aware of the current deals to make those new buildings/units available, etc.
 
Do you know this for a fact?

Searching the SDK, I see that CvGlobals tracks a CvDiplomacyScreen. However, this class is only declared--not defined. This means its definition (the data and functions that make it work) are in the EXE. CvGlobals has a function to store a pointer to the screen. This makes me suspect that the EXE creates it, and gives a pointer to it to the SDK so it can be accessed from Python.

The only part of the window that's in Python is placing and interpreting the choices in the center panel under the leaderhead and triggering the leaderhead animations based on those responses.
 
Okay, this is definitely doable within the SDK. After spending a couple of hours on this, I think I have it figured out. The hard part is going to be the AI aspect of it. But, I'll cross that bridge later.

Thanks for the help, though, guys

JD
 
Can you give us a quick idea of what you need to do to make new items show up on the Trade Window?
 
Can you give us a quick idea of what you need to do to make new items show up on the Trade Window?
As soon as I get it all figured out, I'll post a tutorial. But if you're looking to try on your own, go to the BuildTradeTable function in CvPlayer.cpp and start from there. Basically, for what I am doing, I am following the "TRADE_TECNOLOGIES" route.

JD
 
Okay, I have this pretty much almost done. Here's a screen shot.



I have something wrong somewhere though because if I demand a building, and they give it to me, I gain +2 relations with them for "voting for them"

Whoops....

JD
 
Wow. This is some cool stuff.
Well, I've run into a weird issue... So, I am probably going to start over again from scratch. I have definitely made it so I can trade unique buildings, but I messed up the main interface somehow in the process. I didn't do enough tests along the way, and I editted a bunch of code at once. Of course, it only kind of worked, and I have no idea where I made the mistake. But I know what I'm doing now, so it shouldn't be too long. I'll work on it tonight and see if I can get some more screen shots and some code up here soon.

JD
 
so basically if you are trading the item then it enables the buildng or unit for other civs. Is it a per turn thing? Can it be cancelled?
Currently it is a one and done thing. This is why I have based it almost entirely off of trading technologies (which is where I think I have messed a couple of things up). The basic thought it that the other civilization has "taught" you the secrets of building their unique buildings. Once you learn those secrets, you don't "unlearn" them.

However, I may be able to convert this into a "per turn" trade. I'll work with that after I get the basic idea hammered out.

Now hypothetically speaking, what happens if the Greeks trade the Odeon to say Babylon or the Byzantine Empire. Does Babylon and Byzantine empire loose the ability to build their unique building?
Well, right now, it completely overwrites the building that falls into the same BuildingClass as the "traded for" unique building. This can cause some unique buildings to be overwritten. For example, there are like 3 civilizations that have unique buildings for the courthouse. If one of these civilizations trades for the unique building of another civilization that has a unique building based on the courthouse, it will overwrite the original unique building. I figure this will be something to work with on a per MOD bases. In the mod I am working on, I have made new unique buildings for some civilizations so that no two unique buildings use the same BuildingClass.

There are still some things to iron out, but once I get the basics figured out, I'll have some of you try it out. then, we can get all the details figured out.

JD
 
I like it. I wonder if you can spread religions or even better corporations this way too.

You mean via the trade window?
 
Back
Top Bottom