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
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