View Full Version : Hammer Upgrade


Lord Olleus
Apr 18, 2007, 01:16 PM
The aim of this modcomp is to upgrade units with hammers instead of gold, which makes more sence as units are built with hammers, and not gold, to start off with.

Instead of just clicking on a unit and paying some gold to upgrade it, things are now a little more complicated. To upgrade a unit (say an archer) to another unit (a longbowman for example) you must move the archer to a city which is building a longbowman, then click on the upgrade button. The archer will disappear and 75% of the hammer cost of the archer will be reinvested into the longbowman, reducing the build time. When the longbowman is finished it will have all of the promotions of the archer and all of its experience*.

You can only upgrade one unit per target unit type at the time. If you have two archers which you want to upgrade to longbowmen, you have to upgrade one, wait untill it has finished building, then upgrade the second one. However, you can interupt the upgrading of one unit (warrior to axeman), upgrade a completely different unit (warrior to spearman), finish building the spearman, and then finish building the axeman without loosing the promotions and exp of the first warrior.

In this version, the AI will upgrade units that are near a city which is building a unit that they can upgrade to. A city is also more likely to build a unit if there is a unit inside the city which can upgrade to it. The AI get extra hammers when upgrading a unit, just like they could upgrade units at a lower cost.

If you want to intergrate this into other mods, please look at the ChangeLog. All changes are in the SDK, and the appropriate files are included. Feel free to use this for what ever you want but please include credits.

DOWNLOAD HERE (http://forums.civfanatics.com/downloads.php?do=file&id=4632)


* Well, not quite. The Experience of a unit will always drop back down to 10, unless the city can built units with higher exp, in which case the unit will have that exp.


This is a list of everything that I have changed in the game files whilst making this mod.This is only of interests to modders who want to see how I've done these changes or wantto merge this with other components.



CvUnit::upgradePrice 16th April 07
Commented out from CvUnit.cpp and CvUnit.h and CyUnit.cpp and CyUnit.h and CyUnitInterface1


CvPlayer::upgradeAllPrice 16th April 07
Commented out from .cpp and .h


CvDLLWidgetData::parseActionHelp 16th April 07
Removed a large chunk of this function at line 2480+. No price is now displayed when mouse overing the 'upgrade' button because there is no price.
Added another condition to if clause a few lines before (in order to remove the "<alt> for all units" string)


CvCity 17th April 07
This is the complicated bit.
There is an array of length getNumberUnitTypes(). Each of its elements is a pointer to a structure of type upgrade. That structure is used to add experience and promotions when the correct unit is finished. The advantage of doing it this way is that you can interupt the build queue without loosing all the information regarding the upgraded unit.

Added the definitions of the struct upgrade and m_sUpgrade in .h. Added a line in CvCity::CvCity() as well as in ::uninit() and ::reset concerning m_sUpgrade. Also added a reference to it in the read and write functions. Added createUpgradeStruct() and changePromotionToUpgradeStruct() to .h and .cpp.


CvUnit::canUpgrade 17th April 07
Removed check for money and for TESTVISIBLE as the function always returned false if it was left as before with just the moey checked removed. Added section saying that city must be building unit of correct type AND the upgrade structure must be empty before it can be upgraded.

CvUnit::upgrade 17th April 07
Rewrote most of the function.


CvCity::addProductionExperience 18th April 07
Changed function to account experience stored in the upgrade structure.

CvCity 18th April 07
Added a new attribute to the upgrade structure called 'm_iLevel'. Referenced it everywhere needed.

CvUnitAI::AI_upgrade 18th April 07
Removed a lot of stuff from function as there is no need to check for 'best unit' as there is only one possible upgrade. Added a section so that a unit will move to a nearby city (2 squares away) if that city is building a unit to which it can upgrade to.

CvCityAI::AI_bestUnitAI 18th April 07
Modified this function so that City is more likely to build a unit, if there is a unit on this tile which can upgrade to it.

CvUnit::upgrade 18th April 07
AI now gets extra production when upgrading a unit. The formula for this is:
(100 - <iAIUnitUpgradePercent>) / 100 + 1
This means that instead of upgrading a unit for x% of the normal price, they get a bonus of 100-x% hammers when they are upgrading. Note, the formula above simplifies to:
2 - (<iAIUnitUpgradePercent> / 100)


Credits:
Lord Olleus

JavalTigar
Apr 18, 2007, 02:58 PM
This sounds like an awesome idea!!!

I can't wait to play this.

Zuul
Apr 19, 2007, 06:24 AM
Nice idea! Wanted this for a long time. Maybe also add a dispand function (adding something like 25% of the cost to shields/money to a city you dispand into).

Vadus
Apr 19, 2007, 05:52 PM
hey, this sounds cool ! :goodjob:

Zebra 9
Apr 19, 2007, 06:42 PM
Now will the normal upgrade system work, and if not could you make it so it does? IMO that would be cool to be able to use a unit to increase the production towards another unit and still be able to upgrade in the field.

Lord Olleus
Apr 20, 2007, 02:12 AM
No I removed the old system of upgrading. If you want to upgrade quickly, switch to universal suffrage and gold rush units.

asioasioasio
Apr 20, 2007, 04:35 AM
Very good idea - I'll use this in ww2 1939 mod

Thorn
Apr 20, 2007, 08:09 AM
Instead of just clicking on a unit and paying some gold to upgrade it, things are now a little more complicated. To upgrade a unit (say an archer) to another unit (a longbowman for example) you must move the archer to a city which is building a longbowman, then click on the upgrade button. The archer will disappear and 75% of the hammer cost of the archer will be reinvested into the longbowman, reducing the build time. When the longbowman is finished it will have all of the promotions of the archer and all of its experience*.

I never would have thought of that. Great idea!!!

Dom Pedro II
Apr 20, 2007, 08:14 AM
So basically, you've brought back the old disbanding system but have given more hammers than one used to get from disbanding but limited which units an obsolete unit can contribute its hammers to... interesting. The current system definitely makes it easy (too easy really) for people with piles of money to update units after discovering a new tech. This is especially true when in the middle of war. I've had instances where I've captured a large enemy city, completely surrounded by the enemy's culture, moved in my armies and planes and then upgraded them right there in the enemy city under occupation, and I'm sure plenty of other players have done the exact same thing.

So the AI definitely does use this? That would really be my main concern. The AI struggles enough as it is to keep up with the human player.

Lord Olleus
Apr 20, 2007, 09:40 AM
I'm not too sure how well the AI uses it. I've done a few tests to see if the AI uses, and it does; but I'm not too sure it uses it particularly well.

jojoweb
Apr 27, 2007, 08:13 AM
Very very good idea !