• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days. For more updates please see here.

[SDK] Units and Food

Gooblah

Heh...
Joined
Jun 5, 2007
Messages
4,282
I'm trying to implement a system by which units take a certain amount of food per turn. This will require two parts: defining a new tag in UnitInfos, and creating a function that would calculate the total amount of food produced by unworked tiles.

So, I've created a flowchart or two regarding what variables I need and how to go about doing this, and I'm taking classes in C++ right now. What I need to know is where to place these functions (i.e which files). Any ideas?
 
:bump:

I've been following Kael's tutorial and have added the correct things to CvInfos.h/CvInfos.cpp. However, I'm unsure of where to add the necessary functions. To make life easier, I have only a few questions:
1) Where (which file)would I add a function calculating the tile yield of unworked tiles in a player's empire?
2) How would I get an XML value? Would it be through including the CvInfos.h library, then asking for a certain variable?
 
1) If it's all the unworked tiles owned by a player, then it CvPlayer.h and CvPlayer.cpp
2) there are numerous examples in the whole sdk...GC.getUnitInfo(eUnit).getXXXX...for example
 
There are quite a few ways to track the amount of unworked food in a players land. It depends on how comfortable you are with changing things in the DLL, and if you are seeking the lowest impact on turn time for how you'd best approach it.


Cheap and easy method if not comfortable with much programming: Create a function in CvPlayer that cycles over the entire map and checks if the tile is owned by the current player and ask what food is available Subtract out any food available in any cities (quick/easy way to find out what food is being worked). Then have this function be called during ::doTurn to update the number each turn.


This approach will be a hefty hit on turn time though, since you are cycling the entire map for each player. Might not really be too noticeable if the mod already runs fast though.


Quicker approach is harder to code if you aren't comfortable with such things, but you'll have to account for every possible way to enhace the available food (CvPlot::setImprovementType, ::setFeatureType, ::setTerrainType, ::setOwner... possibly some more) and when those happen have any change in YIELD_FOOD also update a function in CvPlayer which tracks how much food is available in the empire. Then again, subtract the amount of food in any city from this number when checking for unworked food available.
 
There are quite a few ways to track the amount of unworked food in a players land. It depends on how comfortable you are with changing things in the DLL, and if you are seeking the lowest impact on turn time for how you'd best approach it.


Cheap and easy method if not comfortable with much programming: Create a function in CvPlayer that cycles over the entire map and checks if the tile is owned by the current player and ask what food is available Subtract out any food available in any cities (quick/easy way to find out what food is being worked). Then have this function be called during ::doTurn to update the number each turn.


This approach will be a hefty hit on turn time though, since you are cycling the entire map for each player. Might not really be too noticeable if the mod already runs fast though.


Quicker approach is harder to code if you aren't comfortable with such things, but you'll have to account for every possible way to enhace the available food (CvPlot::setImprovementType, ::setFeatureType, ::setTerrainType, ::setOwner... possibly some more) and when those happen have any change in YIELD_FOOD also update a function in CvPlayer which tracks how much food is available in the empire. Then again, subtract the amount of food in any city from this number when checking for unworked food available.

Hmmm...thanks.
 
Back
Top Bottom