[MOD] More Naval AI

We often get a first turn OOS where when we reload the game the OOS person will start in a different location on the map.

I also got a OOS on start a few times... I did not report it because I wasn't able to reproduce it. It only appeared when we had 3 players, but before that we were not able to determine what caused it. At first we assumed some game option combination but we managed to get the OOS without any special game options enabled (Advanced Tactics and Puppet States & Revolutions were off too).
 
In addition to previous post, i have modified CvPlayerAI::AI_doTurnUnitsPost method.

This method is used
- CvPlayer::doTurnUnits
- CvPlayer::setTurnActive
- CvPlayer::setAutoMoves
- CvGame::updateMoves
- CvGame::update
* As you know, this is main AI routine.

But, there are inefficient routine in the method.

CvUnit::hasUpgrade method is heavy routine and slow. so that condition must be checked late than the others to speed up. I have changed and test this method.

After small fix, this method speed up to 2x. (2secs to 1secs, 1-turn)
This fix is very small but effective, i marked USE_OLD_CODE too.

Attachment include the previous modifications.
 

Attachments

  • CvGameCoreDLL_mod2.zip
    312.5 KB · Views: 47
Running as Administrator worked, but now the Scenarios have become more diffcult. Do you have any strategies for The Momus and The Cult?
 
Running as Administrator worked, but now the Scenarios have become more diffcult. Do you have any strategies for The Momus and The Cult?

For the Momus, use ritualists. A lot. There are a number of cities by water, and you'll able to swamp their defenders. Stygian guards are awesome as well. Don't let the Infernals stay alive for too long.
(Actual scenario spoiler ahoy)
Spoiler :
If you want to help Beeri and kill Perpentach, then... I have no idea. I'm sorry.
 
Should I apply this Master of Mana, RiFe, and Magister's mod?

In addition to previous post, i have modified CvPlayerAI::AI_doTurnUnitsPost method.

This method is used
- CvPlayer::doTurnUnits
- CvPlayer::setTurnActive
- CvPlayer::setAutoMoves
- CvGame::updateMoves
- CvGame::update
* As you know, this is main AI routine.

But, there are inefficient routine in the method.

CvUnit::hasUpgrade method is heavy routine and slow. so that condition must be checked late than the others to speed up. I have changed and test this method.

After small fix, this method speed up to 2x. (2secs to 1secs, 1-turn)
This fix is very small but effective, i marked USE_OLD_CODE too.

Attachment include the previous modifications.
 
Attachment include the previous modifications.

Hey lesslol. When I try to compile after merging your changes, I'm getting an error in CvEventReporter.cpp

Code:
CvEventReporter.cpp(529) : error C2274: 'function-style cast' : illegal as right side of '.' operator

On lines with code like this:

Code:
strKey.format("unit_%d_built", j);

Is there an updated CvEventReporter?
 
Should I apply this Master of Mana, RiFe, and Magister's mod?
This modification will be fit in FfH2 (+Naval AI). I don't know that you could apply this for other ffh2 modmod. Maybe some code possible. This modification is partial, thus this is suggestion for modder.

Hey lesslol. When I try to compile after merging your changes, I'm getting an error in CvEventReporter.cpp

Code:
strKey.format("unit_%d_built", j);

Is there an updated CvEventReporter?

Yes, that code was wrong and useless. CvString::format was static method, return new CvString. (sub class in My version)
I had changed "strKey.format(...)" to "strKey.Format(...)". You should change format to Format.
 
For the Momus, use ritualists. A lot. There are a number of cities by water, and you'll able to swamp their defenders. Stygian guards are awesome as well. Don't let the Infernals stay alive for too long.
(Actual scenario spoiler ahoy)
Spoiler :
If you want to help Beeri and kill Perpentach, then... I have no idea. I'm sorry.

Anything that doesn't involve an Evil religion?
 
Yes, that code was wrong and useless. CvString::format was static method, return new CvString. (sub class in My version)
I had changed "strKey.format(...)" to "strKey.Format(...)". You should change format to Format.

OK. That took care of that error. However, I now have a new one in CvXMLLoadUtilitySet.cpp. I copied your version over completely, so I'm not sure how you're able to build a DLL with it

On this line:
Code:
SetGameText("Civ4GameText", "Civ4GameText/TEXT");

I get the following error.

Code:
1>CvXMLLoadUtilitySet.cpp(799) : error C2660: 'CvXMLLoadUtility::SetGameText' : function does not take 2 arguments
 
OK. That took care of that error. However, I now have a new one in CvXMLLoadUtility.cpp. I copied your version over completely, so I'm not sure how you're able to build a DLL with it

On this line:
Code:
SetGameText("Civ4GameText", "Civ4GameText/TEXT");

Code:
1>CvXMLLoadUtilitySet.cpp(799) : error C2660: 'CvXMLLoadUtility::SetGameText' : function does not take 2 arguments

This change is not important.

Line 307, File CvXMLLoadUtility.h

void SetGameText(const char* szTextGroup, const char* szTagName, /*lol*/ int iCurrentLanguage);

You should change this line to original.

void SetGameText(const char* szTextGroup, const char* szTagName);

My copy has some more changes, but unimportant. Sorry for incomplete code. :)

ps. Some code use INLINE version method, but this INLINE version didn't included in pre-attached file. You only need to delete INLINE from the method name. Also, i attach a copy of other changes and my profiling codes here.
 

Attachments

  • CvGameCoreDLL_others.zip
    161.3 KB · Views: 47
You should change this line to original.

OK. That seemed to do it. I was able to make a build and ran a test by having the AI play against itself for 200 turns. Overall speed improvement came out to about 17%!

I'll run some more tests today and if everything goes well your code will be included in the next release. Thanks!
 
Anything that doesn't involve an Evil religion?

Hm. Radiant guard and catapult spam, perhaps? Life II mages are good for getting rid of drown, also.
 
My pre-change has a bug. Next code should be changed. (CvPlayerAI.cpp, line 792)

Code:
if (((pLoopUnit->AI_getUnitAIType() == UNITAI_HERO) || pLoopUnit->isChanneler()) && pLoopUnit->hasUpgrade())
{
  pUnitPlot = pLoopUnit->plot();
  if (AI_getPlotDanger(pUnitPlot, 1, false) > 0)
  {
     pLoopUnit->AI_upgrade();

To this.

Code:
pUnitPlot = pLoopUnit->plot();
if (((pLoopUnit->AI_getUnitAIType() == UNITAI_HERO) || pLoopUnit->isChanneler() ||
     (AI_getPlotDanger(pUnitPlot, 1, false) > 0)) && pLoopUnit->hasUpgrade())
{
   pLoopUnit->AI_upgrade();
 
I had a speed-test for my upload-codes with new 942 rev.

Here the results. (From 520 for 5 turns, Top time-consumed methods)

Case 1. Original code. AI routine unchanged.
NUM [ TOTAL SEC ( %) / COUNT = SINGLE ] NAME
---------------------------------------------------------------------------
001. Elapsed = [0045.86374 (11%) / 0000000468 = 00.09799943] CvGame::update
002. Elapsed = [0044.07878 (11%) / 0000000468 = 00.09418543] CvGame::updateMoves
003. Elapsed = [0035.73589 (09%) / 0000000070 = 00.51051265] CvPlayer::setTurnActive
004. Elapsed = [0031.15223 (08%) / 0001427512 = 00.00002182] CvPlayerAI::AI_unitValue
005. Elapsed = [0029.85752 (07%) / 0000004498 = 00.00663796] CvUnit::getUpgradeCity(bSearch) // HasUpgrade
006. Elapsed = [0028.08683 (07%) / 0000000035 = 00.80248088] CvPlayer::doTurnUnits
007. Elapsed = [0027.52033 (07%) / 0000000035 = 00.78629506] CvPlayerAI::AI_doTurnUnitsPost
008. Elapsed = [0026.93664 (07%) / 0000451928 = 00.00005960] CvPlayerAI::AI_trueCombatValue
009. Elapsed = [0023.06164 (06%) / 0026757392 = 00.00000086] CvPlayer::getNumAvailableBonuses
010. Elapsed = [0021.74756 (05%) / 0030464062 = 00.00000071] CvPlayer::isFullMember
011. Elapsed = [0007.80961 (02%) / 0000000480 = 00.01627002] CvPlayerAI::AI_unitUpdate
012. Elapsed = [0007.79302 (02%) / 0000013313 = 00.00058537] CvSelectionGroupAI::AI_update
013. Elapsed = [0007.59723 (02%) / 0000000035 = 00.21706381] CvPlayer::doTurn
014. Elapsed = [0007.44909 (02%) / 0000001987 = 00.00374891] CvUnitAI::AI_update
015. Elapsed = [0003.92268 (01%) / 0000000163 = 00.02406553] CvCity::doTurn()
016. Elapsed = [0003.89846 (01%) / 0000027713 = 00.00014067] CvSelectionGroup::generatePath()
017. Elapsed = [0003.83005 (01%) / 0000000428 = 00.00894872] CvCityAI::AI_assignWorkingPlots
018. Elapsed = [0003.71445 (01%) / 0000000150 = 00.02476303] CvUnitAI::AI_exploreMove
019. Elapsed = [0003.51440 (01%) / 0000000112 = 00.03137859] CvXMLLoadUtility::SetGlobalClassInfo
020. Elapsed = [0003.51300 (01%) / 0000005455 = 00.00064400] CvCityAI::AI_addBestCitizen
021. Elapsed = [0003.48209 (01%) / 0000000163 = 00.02136253] CvCityAI::AI_doTurn
022. Elapsed = [0003.19257 (01%) / 0000000325 = 00.00982329] CvUnitAI::AI_travelToUpgradeCity
023. Elapsed = [0003.18898 (01%) / 0000064666 = 00.00004931] CvCityAI::AI_plotValue
024. Elapsed = [0002.12128 (01%) / 0000000240 = 00.00883868] CvXMLLoadUtility::LoadCivXml
025. Elapsed = [0002.04082 (00%) / 0000000035 = 00.05830910] CvPlayerAI::AI_doTurnPre
...

Case 2. AI routine changed.
NUM [ TOTAL SEC ( %) / COUNT = SINGLE ] NAME
---------------------------------------------------------------------------
001. Elapsed = [0017.96720 (12%) / 0000000426 = 00.04217653] CvGame::update
002. Elapsed = [0016.29733 (11%) / 0000000426 = 00.03825665] CvGame::updateMoves
003. Elapsed = [0009.96231 (07%) / 0000000070 = 00.14231874] CvPlayer::setTurnActive
004. Elapsed = [0006.01166 (04%) / 0000693205 = 00.00000867] CvPlayerAI::AI_unitValue
005. Elapsed = [0005.82479 (04%) / 0000000438 = 00.01329860] CvPlayerAI::AI_unitUpdate
006. Elapsed = [0005.80813 (04%) / 0000012271 = 00.00047332] CvSelectionGroupAI::AI_update
007. Elapsed = [0005.62127 (04%) / 0000000035 = 00.16060764] CvPlayer::doTurnUnits
008. Elapsed = [0005.48135 (04%) / 0000002025 = 00.00270684] CvUnit::getUpgradeCity(bSearch)
009. Elapsed = [0005.46267 (04%) / 0000001987 = 00.00274920] CvUnitAI::AI_update
010. Elapsed = [0005.09113 (03%) / 0000000035 = 00.14546083] CvPlayerAI::AI_doTurnUnitsPost
011. Elapsed = [0004.29954 (03%) / 0000000035 = 00.12284392] CvPlayer::doTurn
012. Elapsed = [0004.20463 (03%) / 0000221891 = 00.00001895] CvPlayerAI::AI_combatValue
013. Elapsed = [0004.11198 (03%) / 0000221891 = 00.00001853] CvPlayerAI::AI_trueCombatValue
014. Elapsed = [0003.92439 (03%) / 0000027713 = 00.00014161] CvSelectionGroup::generatePath()
015. Elapsed = [0003.50460 (02%) / 0000000112 = 00.03129108] CvXMLLoadUtility::SetGlobalClassInfo
016. Elapsed = [0002.55676 (02%) / 0000000150 = 00.01704506] CvUnitAI::AI_exploreMove
017. Elapsed = [0002.43831 (02%) / 0000000163 = 00.01495898] CvCity::doTurn()
018. Elapsed = [0002.25218 (01%) / 0013193996 = 00.00000017] CvPlayer::getNumAvailableBonuses
019. Elapsed = [0002.11624 (01%) / 0000000240 = 00.00881766] CvXMLLoadUtility::LoadCivXml
020. Elapsed = [0002.05441 (01%) / 0000000163 = 00.01260377] CvCityAI::AI_doTurn
021. Elapsed = [0001.80598 (01%) / 0000000428 = 00.00421957] CvCityAI::AI_assignWorkingPlots
022. Elapsed = [0001.60533 (01%) / 0000005455 = 00.00029429] CvCityAI::AI_addBestCitizen
023. Elapsed = [0001.45433 (01%) / 0000064666 = 00.00002249] CvCityAI::AI_plotValue
024. Elapsed = [0001.26635 (01%) / 0000002704 = 00.00046833] CvPlot::setupGraphical
025. Elapsed = [0001.21857 (01%) / 0000000325 = 00.00374946] CvUnitAI::AI_travelToUpgradeCity
...

Just fun, see lightly.
 

Attachments

  • profiling log.zip
    14 KB · Views: 52
Does the Revolutions option include the Barbarian Civ mod component or no? Just wondering, thanks.
 
I think it was mentioned upthread that no, the Barbarian Civ component was stripped out as there aren't any Civs for them to become. After all, they're Orcs and Goblins... going to Human? Dwarves? Elves? The ONLY Civ they could become would be Clan, and suddenly having 20 Clan players (if one of every Civ) + any Clan leaders that revolt out of the original Clan Civ makes no sense.
 
I have also noticed the issue with getting great commanders from the shrine fo the champion. after you take the promotion you can detach the great commanders from the unit getting infinite great commanders. Also my friends and I have noticed a marked increase in OOS since the new version. We often get a first turn OOS where when we reload the game the OOS person will start in a different location on the map.

Thank you for all you efforts. My friends and I had gotten burned out on base FFH because of the weak AI. You've given us back one of our favorite games :)

If you're using a variant of the "Full of Resources" map script, this happens every time, and it documents that the game creator needs to host a reload on the first turn. For whatever reason, the map is not properly transmitted to the other players on creation, only on loading. I suppose it might happen with other mapscripts as well. We consider it just a known time cost involved with setting up our favorite maps.
 
Are barb Thane(s) of Kilmorph a concern? I remember a couple of posts about them. I have some saves with the guys running around. If wanted, I'll post them.
 
I'm not sure if this is a known issue but it doesn't seem to be intended--with Shrine of the Champion, I am able to "promote" units to having a Great General attached to them, even when "Advanced Tactics" is not enabled.

I have also noticed the issue with getting great commanders from the shrine fo the champion.

This bug will be fixed in the net release.

If they are not going to be used, the Strategy1_CIV4GameText and Strategy2_CIV4GameText files should be removed. They are quite big :)

OK.

Does the Revolutions option include the Barbarian Civ mod component or no? Just wondering, thanks.

I think it was mentioned upthread that no, the Barbarian Civ component was stripped out as there aren't any Civs for them to become. After all, they're Orcs and Goblins... going to Human? Dwarves? Elves? The ONLY Civ they could become would be Clan, and suddenly having 20 Clan players (if one of every Civ) + any Clan leaders that revolt out of the original Clan Civ makes no sense.

Also, part of the criteria for a Barb city becoming a civ was based on culture, so Acheron's city was always the first to change, which then pushed Acheron out of the city and resulted in other weirdness. I might bring back the Barbarian Civ concept at some point in the future, but it will require a lot of changes to work properly with FFH.

Are barb Thane(s) of Kilmorph a concern? I remember a couple of posts about them. I have some saves with the guys running around. If wanted, I'll post them.

This issue should already be fixed for the next release.
 
Top Bottom