Adding new Resource Yields to Future Techs

draco963

Prince
Joined
Jan 26, 2007
Messages
451
Location
Ottawa
What I'm looking to do is to divide up Future Tech into five seperate techs, which would each add one of either:
Happiness
Health
Food
Hammers
Commerce

So, I'm going to have to add 3 new tags to the XML, which means adding them into the SDK, and teaching the AI they exist so it will adequately try to go for them. And making sure they're counted properly in the City screen, so everything totals correctly.

So, a simple text search through the SDK files for "iHealth", then cross-checking for "iHappiness" brought up:
CvCity.cpp
CvCityAI.cpp
CvGameTextMgr.cpp
CvInfos.cpp
CvInfos.h
CvPlayerAI.cpp
which looks right to me (noob that I am :crazyeye:). But, starting with CvCity.cpp, I think I might be ok for just adding the XML tags, but having my Future Food Tech say it adds +1 :food: in the Civilopedia won't do squat if I don't tell the game to count it in when checking how much food a city is garnering each turn. It'll look pretty, but do nothing. Same goes for Hammers & Commerce.

So, I'm asking for help. Is this going to be simple? Better yet, has it already been done (I couldn't find anything...)? Could someone do it for me? :blush: :worship:
 
You are dealing with Techs, so you may need to modify CvTeam as well (any technology learned is registered on the team, then applied to all the members. But most of the decisions/processing of a tech is done through Player, not Team, so you might not need to touch it). But you will certainly need to modify either CvPlayer or CvTeam to actually register the new items from the Tech being accepted.



The best way to approach adding new XML fields if you haven't before, is to start with JUST CvInfos and CvGameTextMgr. CvInfos is responsible for reading the XML into the game, and CvGameTextMgr will display things for you. Work with those 2 to make the field exist at all, and ensure it shows up on Technologies. Once that is working, THEN branch out and make your new fields actually affect other aspects of the game. That will mean CvPlayer or CvTeam, and more work in GameTextMgr so you can see if it is applying things properly. Since you are adding fields which will affect city output/condition, you'll also wind up dealing with CvCity, and possible CvDLLWidgetData + python (we'll leave that alone till you get there).

After it is functioning properly and displaying nicely, then you want to go in and set it up so that the AI acknowledges the new fields in CvCityAI/CvPlayerAI/CvTeamAI
 
the idea sounds cool but cant you just do this with xml?

Have future health, Future happy, future farms (+1 food/per farm) etc. Make them 5 different techs and have different pre-req techs for it?

I havent done it but the xml can work that way, cant it?

or did I miss your intent?
 
Thanks Xienwolf. That's a huge help as a starting point. I'm taking my time with this one, so it'll be a while... :crazyeye:

Ekmek, you've understood my intent, but there is no built-in tag in the XML for adding Food, Production, or Gold; just Health & Happiness. I could make a work-around for that by implementing three buildings that are affected by the Future Food/Prod/Gold to add +1 of each yield with each new Tech, but then I would have to actually write in a Future Food 1, Future Food 2, Future Food 3, etc into CIV4TechInfos.xml. Otherwise, the game will just see the first one, and not the succesive Future Techs, and the buildings would only ever add +1(yield). So, adding the new XML tags will allow me to specify the Future Food/Prod/Gold techs as Future Techs, just like the original, where the game takes care of increasing the cost of each successive one, and counting up how many you have. And, it means you can't run out, 'cause Future Tech can be researched indefinately, whereas ones I write into the XML individually will of course, eventually run out. -Whew!- I hope that cleared things up...
 
I figured it would take a while, that's why I stopped explaining at a decent point for starters and gave a rough outline of what happens afterward :) You'll learn quite a bit while getting the CvInfos straightened out which will help considerably in explaining the next bits.
 
Ekmek, you've understood my intent, but there is no built-in tag in the XML for adding Food, Production, or Gold; just Health & Happiness. I could make a work-around for that by implementing three buildings that are affected by the Future Food/Prod/Gold to add +1 of each yield with each new Tech, but then I would have to actually write in a Future Food 1, Future Food 2, Future Food 3, etc into CIV4TechInfos.xml. Otherwise, the game will just see the first one, and not the succesive Future Techs, and the buildings would only ever add +1(yield). So, adding the new XML tags will allow me to specify the Future Food/Prod/Gold techs as Future Techs, just like the original, where the game takes care of increasing the cost of each successive one, and counting up how many you have. And, it means you can't run out, 'cause Future Tech can be researched indefinately, whereas ones I write into the XML individually will of course, eventually run out. -Whew!- I hope that cleared things up...


thx! I figured you tested it of course, I was just curious as to why adding a +1 food code was affect by the rerpeat tag. weird that it isnt.

Have you thought about just copying the civixc code that allows 10% food increase in all cities? the code should be just a copy and paste then, I think.
 
Starting to try this, and I've added my FutureFood/Prod/Gold to CvInfos.cpp & CvInfos.h, but trying to build it produced the following error:

Spoiler :
CvInfos.cpp|1107|error C2039: 'getFutureFood' : is not a member of 'CvTechInfo'|
CvInfos.cpp|1108|error C2270: 'getFutureFood' : modifiers not allowed on nonmember functions|
CvInfos.cpp|1109|error C2065: 'm_iFutureFood' : undeclared identifier|
CvInfos.cpp|1112|error C2039: 'getFutureProd' : is not a member of 'CvTechInfo'|
CvInfos.cpp|1113|error C2270: 'getFutureProd' : modifiers not allowed on nonmember functions|
CvInfos.cpp|1114|error C2065: 'm_iFutureProd' : undeclared identifier|
CvInfos.cpp|1117|error C2039: 'getFutureGold' : is not a member of 'CvTechInfo'|
CvInfos.cpp|1118|error C2270: 'getFutureGold' : modifiers not allowed on nonmember functions|
CvInfos.cpp|1119|error C2065: 'm_iFutureGold' : undeclared identifier|
||=== Build finished: 9 errors, 0 warnings ===|

Don't know what I did wrong, here's the two files, (file removed, please see post #52). My edits are bracketed by RichMod Start/End.

Oh, and I don't know what to edit/add in CvGameTextMgr.cpp...
 
You need to add the declarations for your three new functions to the header file. Just above where you've declared the fields (e.g. m_iFutureFood) is a section labeled PUBLIC INTERFACE. Add these bold lines to it:

Code:
DllExport int getHealth() const;								// Exposed to Python
DllExport int getHappiness() const;							// Exposed to Python
[B]DllExport int getFutureFood() const;							// Exposed to Python
DllExport int getFutureProd() const;							// Exposed to Python
DllExport int getFutureGold() const;							// Exposed to Python[/B]
DllExport int getFirstFreeTechs() const;				// Exposed to Python
DllExport int getAssetValue() const;						// Exposed to Python

This should fix all the errors you have, as they all stem from the compiler not understanding that these new functions in the cpp file belong to the CvTechInfo class.

Did you really mean Gold and not Commerce? Commerce is the third yield along with Food and Production. I also recommend not abbreviating Production to Prod as it isn't abbreviated anywhere else in the API.
 
Ah! Thank-you EF!

You're right, I do mean Commerce, not Gold. I've changed everything accordingly, so too with Prod -> Production. On that note, when I get these working, I want to try to change the Corporation & Shrine bonus to be Commerce, and not Gold, so that I don't wind up with riduculous sums of cash at the end game that I can't do anything with...

However, staying on topic for now: Although your suggestion worked, and I was able to compile a DLL, and the game accepts the new tags in CIV4TechnologiesSchema.xml & CIV4TechInfos.xml, the Civilopedia doesn't show any bonuses... Don't know what to do from here, I thought that was what CvGameTextMgr.cpp was for (I think I got that file right)...

So, again, my files (CvInfos.cpp, CvInfos.h, CvGameTextMgr.cpp, CvGameTextMgr.h): (file removed, please see post #52). And thank-you again.

One last thing, would :food:, :hammers:, & :commerce: be listed as FOOD_CHAR, HAMMER_CHAR, & COMMERCE_CHAR in the SDK?
 
. . . so that I don't wind up with riduculous sums of cash at the end game that I can't do anything with...

Buy! Buy! Buy! Don't forget (as I often do) that you can rush-buy stuff under US.

The Civilopedia doesn't show any bonuses... I thought that was what CvGameTextMgr.cpp was for

CvGTM only handles hover text, so you should see your new effects when hovering over the tech's icon at the top of the main interface or on the Technology Advisor.

You'll have to modify the Civilopedia itself to see your effects there. Look at CvPediaTech.py (IIRC). Oh wait, that uses the hover text to build its list, doesn't it? I don't have the code in front of me. Do you see your effects in the tech's hover on the F6 screen? If so, it should be on the pedia. In any case, take a look at the pedia code to trace down how it pulls that info.

One last thing, would :food:, :hammers:, & :commerce: be listed as FOOD_CHAR, HAMMER_CHAR, & COMMERCE_CHAR in the SDK?

PRODUCTION_CHAR, I think, but yes those should be processed by CyTranslator.getText() when displaying text from the XML files and I suspect also from CvGTM.
 
Buy! Buy! Buy! Don't forget (as I often do) that you can rush-buy stuff under US.

:lol: Ya, the problem is, I run out of things to buy. I get all my cities finished, and have nothing left but military units to buy... So, switching those to commerce would allow me to better control how much gold I wind up with...

What do you mean by IIRC? You keep using that acronym, I can't figure out what it's for...

To answer, I get no hover text for the new techs that use the new tags. They show only what techs they require, in both the SciAdvisor & 'Pedia. No icons for bonuses (makes sense, as I haven't made any yet), and no hover-text. If that's a Python thing, I'm probably in trouble...
 
What do you mean by IIRC? You keep using that acronym, I can't figure out what it's for...

Google's "define:" prefix is your friend.

To answer, I get no hover text for the new techs that use the new tags.

No hover text at all? A blank box? Text for the tech but just missing the new features you've added?

IIRC (;)), the pedia grabs the hover text using Python and splits it apart line-by-line to add it to the bulleted list of effects. I'll have some time later today to check out the code you posted, but it would really help if you could be very specific about what you do and do not see.

Screenshots perhaps? :goodjob:
 
Ah, Google. Yes, I must remember that useful little upstart... Wait a minute, IIRC - Interactive Illinois Report Card??? :mischief:

:lol: No, really, I get it now. Duh! :p Yeesh, how did I ever miss that...?

OK, screenies:
Spoiler 1st Screenshot :
You can see here the Techs I've added (which proves nothing but that I can copy/paste XML), but you'll notice there is no data within the Tech box. That probably has something to do with not yet defining anything in the Art XML files for the new effects I've added, right?


Spoiler 2nd Screenshot :
Here, you can see the hover text. No data, except the cost of the Tech.

Spoiler 3rd Screenie :
And the Civilopedia does the same.


In trying to find the FOOD_CHAR etc entries, I've found that they don't exist in the SDK, at least not spelt the way we described above. I gave up looking, and decided to just add new entries in the Enums.h & CyEnumsInterface.cpp. Since I'm mucking about with the SDK anyways, why not? Proof of concept is that the GG head still shows in the GG bar (see Screenie 1).

So, do you think this is a Python thing? Will I have to edit both the SciAdvisor file & the Civilopedia file (please gods no...)?

Here also are my newest files: (file removed, please see post #52). Thanks again! :goodjob:
 

Attachments

  • Civ4ScreenShot0000.JPG
    Civ4ScreenShot0000.JPG
    94.9 KB · Views: 582
  • Civ4ScreenShot0001.JPG
    Civ4ScreenShot0001.JPG
    38 KB · Views: 655
  • Civ4ScreenShot0002.JPG
    Civ4ScreenShot0002.JPG
    103.7 KB · Views: 622
Ah yes, I totally forgot about the Technology Advisor (F6) screen. :crazyeye: Sadly, you will have to modify CvTechnologyAdvisor.py to understand your new getExtraFood/Production/Commerce() functions and add icons for them. The easiest way to do this is to search for an existing function (like getExtraHappiness() or whatever it's called in the SDK) and copy the code for it. You need to choose or create an icon for each, of course.

I'll take a look at your posted code shortly and give see what I can see. Clearly the hover works (shows up), but it's just missing the information. Did you first try adding simple text instead of using the fancy icons, such as "More Food" just to see that it detects your fields? That's where I'd start.
 
Well, I'm not sure if it's detecting the fields or not. The entries @ lines 9675, 9687, & 9699 of CvGTM.cpp refer to specific TXT_KEY's. Changing that key to just "More food" did nothing. So, I don't think the game is actually detecing the fields, I've just added enough so that it doesn't encounter a fatal error when it sees them...

I'm going to start trying the Python now... :eek:

--- later ---

OK, I'm officially in over my head. So, the file for the F6 screen is CvTechChooser.py, and there is a specific entry for both the Normal Happiness & Health, so I mimic'd Happiness & made three more, for F/P/C. They look like this:
Code:
		# FutureProduction Rate bonus from this tech...
		if ( gc.getTechInfo(i).getFutureProduction() != 0 ):
			szFutureCommerceRateButton = self.getNextWidgetName("FutureProductionRate")
			screen.addDDSGFCAt( szHappinessRateButton, szTechRecord, ArtFileMgr.getInterfaceArtInfo("INTERFACE_TECH_HAPPINESS").getPath(), iX + fX, iY + Y_ROW, TEXTURE_SIZE, TEXTURE_SIZE, WidgetTypes.WIDGET_HELP_HAPPINESS_RATE, i, -1, False )
			fX += X_INCREMENT

		j = 0
		k = 0
but I have no idea what to do with the 4th line, where (I think) it's calling on an SDK file to define where the art is (anybody want to make some nice icons?). And CyArtFileMgr.cpp scares me...:cry:
 
Sorry, been busy lately so haven't made it over to this side of the forums in a while.



Haven't looked at your code at all yet, but just having added things to CvGameTextManager should get you your hover text as well as text when you actually click on it in the Pedia. If things are all working properly, so apparently they aren't quite doing so.


For the F6 screen to show the cute little buttons, you'll have to invent a few buttons yourself and inform Python that you want them placed.


To get the DLL to display the Production Character, you need to use something like this:

szTempBuffer.Format(L"%s%d%c", NEWLINE, GET_PLAYER(ePlayer).getProductionNeeded(eUnit), GC.getYieldInfo(YIELD_PRODUCTION).getChar());

And just to demonstrate a commerce as well:

szString.Format(L"%c: " SETCOLR L"%d" SETCOLR, GC.getCommerceInfo(COMMERCE_GOLD).getChar(), TEXT_COLOR("COLOR_NEGATIVE_TEXT"), GET_PLAYER(ePlayer).getGold());






To debug your text entries in CvGameTextManager:

First off, make sure that you are working in CvGameTextMgr::setTechHelp

Now, to start with, you want to know that your data is loading correctly, and you are displaying properly. So what I am about to tell you is EXTRA work, this is NOT what you want in your final release at all. But place something like this:

Code:
void CvGameTextMgr::setTechHelp(CvWStringBuffer &szBuffer, TechTypes eTech, bool bCivilopediaText, bool bPlayerContext, bool bStrategyText, bool bTreeInfo, TechTypes eFromTech)
{
	PROFILE_FUNC();

	CvWString szTempBuffer;
	CvWString szFirstBuffer;
	BuildingTypes eLoopBuilding;
	UnitTypes eLoopUnit;
	bool bFirst;
	int iI;


            szBuffer.append(NEWLINE);
            szTempBuffer.Format(L"%d%c", GC.getTechInfo(eTech).getFutureCommerce(), GC.getCommerceInfo(COMMERCE_GOLD).getChar());
            szBuffer.append(gDLL->getText("TXT_KEY_TECH_FUTURE_COMMERCE", szTempBuffer));

	// show debug info if cheat level > 0 and alt down

And your TXT_KEY_TECH_FUTURE_COMMERCE will read something like:
"Grants %s"



Now, normally such an entry like this would come much later in this function (well after the debugging routine and whatnot), but order isn't THAT important. I want you to place it here to make sure you aren't inside of some random IF statement which will block the code. Additionally, you would normally place your line inside of an "if (GC.getTechInfo(eTech).getFutureCommerce() != 0)" statement so it only shows up for a technology that USES this field. But right now, we are debugging, so we WANT to see this value displayed for every single tech in the tech tree (at least then we know something is displaying at all!)



Once you have that running, then you compile, utilize, and load the game with your XML set up properly (so that only 1 tech uses this field at all). Check the techs and see that everything displays "Grants 0:commerce:", except for the tech you wanted to grant a commerce which should read: "Grants 1:commerce:". If that works, then everything is perfect and you can place it inside the IF statement and move it to somewhere appropriate.
 
You won't have to change any art code to get your own button. All you do is give it the name of your button (linked to a file using CIV4ArtDefines.xml.

Assuming you name the new button INTERFACE_TECH_FUTURE_PRODUCTION in the XML, the code should look like this:

Code:
# FutureProduction Rate bonus from this tech...
if ( gc.getTechInfo(i).getFutureProduction() != 0 ):
	szFutureProductionButton = self.getNextWidgetName("FutureProduction")
	screen.addDDSGFCAt( szFutureProductionButton, szTechRecord, ArtFileMgr.getInterfaceArtInfo("INTERFACE_TECH_FUTURE_PRODUCTION").getPath(), iX + fX, iY + Y_ROW, TEXTURE_SIZE, TEXTURE_SIZE, WidgetTypes.[B]WIDGET_HELP_HAPPINESS_RATE[/B], i, -1, False )
	fX += X_INCREMENT

Note the bold part. For now, leave it as is. But once you get the other stuff working, you'll need to add new hover types (WidgetType) and functions for handling them to CvGameTextMgr for your future X effects.
 
xienwolf, you're a savant. I didn't actually need the code example you gave me, cause when I looked at CvGameTextMgr::setTechHelp, I hadn't made any entries for my new functions... yeesh... :mischief:

So, made some entries there, and now everything shows up properly. So, based on your first message, my next goal should be CvPlayer & CvTeam, right?
 
Yes, your next step is to work in void CvTeam::processTech, this is where you assign the Team itself to carry the extra Hammers or whatever. So you'll want to have a line in there like

changeFutureHammers(GC.getTechInfo(eTech).getFutureHammers() * iChange);

Then you'll invent a new function for changeFutureHammers & getFutureHammers, as well as a variable to hold the value, like m_iFutureHammers.


After that, the step you need is to include the Hammers or whatnot in the player's calculations. That is where it gets a bit trickier though. Mainly just finding where precisely to add what you want added. And of course you'll be needing to modify python as well once you get to the final point so that your new values actually display.
 
One thing that might help show where to put what you need is to track down how the Financial trait works. As you know, this trait assigns +1:commerce: to every plot with at least 2:commerce:. If you check where the function on CvTraitInfo that stores this is called, it may help you plug in your other yield changes.
 
Top Bottom