Bugfix: restored AI diplomats in civdos v03/04/05 and cumulative bugfix for civdos v05

tupi

Warlord
Joined
Jun 25, 2011
Messages
214
Location
Russia
You see, I usually play v05 because I think it's "finished" and "definitive". But alas, it turned out at least one new bug was introduced (in v03). But I want a definitive civdos experience.

In civdos v01 AI can produce diplomats and will use them to steal tech from you. In v03 and later, a bug was fixed when produced AI caravan is not spawned but game tries to create a trade route from non-existent caravan anyway. This is, however, introduced a new bug: AI cannot longer produce diplomats, because new rule includes not only caravan, but also diplomat (which is not spawned yet so it's always -1 at the moment) and also some other code.

This patch for JCivED restores AI diplomat spawning from v01 in civdos v03, v04 and v05 (english version). It keeps caravan fix, but removes new condition from "set timer to talk with player, if nuke was produced and total amount of nukes of AI civ is 1 after that" and from "change production after previous production (unit) is finished". In the case of nuke, this condition from v03 does not really matter and it does not fix any bugs, and my patch simply reverts this part of game logic to v01. In the case of "change production" this patch actually fix a pretty serious new problem in v03 and later: when AI reaches its unit limit (127 units), it cannot change production in a city when unit production is completed. (EDIT 2022/12/13: in v03/04/05, if AI failed to add a produced unit, it nullified the shield storage of the city. As by-product of this patch, this behavior is averted too, so it is like in v01)

Second patch here (only for v05) includes:
1) AI diplomats patch
2) AI space ship launch conditions fix
3) fix of AI rule to speed-up production a first nuke with gold
and
4) fix for destroyed Great Library: it no longer "works" in this case, so barbarians will no longer try to get civ. advances from destroyed GL (which led to stack overflow). Stack overflow still will happen when city with the GL is captured by barbarians, this case is not fixed.

Problem with (2): to check that player has more than 1000 gold, game uses "active civs flags" variable instead of "player civ" variable, this has no sense and this causes the game to read beyond the array in most cases, and even when it reads within the array (when only white and green civs are active), it still has no sense.
Problem with (3): game uses "city flags" field of city structure instead of "current production" field. This is clearly a typo, the result has no sense, and the game can read beyond the array in the cases when current production is not a unit.

Other possible fixes (dubious):
1) AI rule to speed-up palace with gold: cannot be sure that this was Palace and not Militia. But if Palace was intended, game reads beyond the array so it should be fixed.
2) trade arrows from trade routes should be like they are shown on a city screen. Logically, it should be so, and also in this case pre-calculated corruption will actually be used for something, and previous trade routes will not increase income from the next ones. But it will decrease trade routes per-turn profit for both you and AI, and also there's a small chance that "increase current trade route income according to previous trade routes income" behavior was intentional.
3) rule "AI can't build a WotW on chieftain, if player doesn't know civ. advance to build a city improvement with the same id as a wonder". Rule "AI can't buld a wonder on chieftain, if player doesn't know civ advance to build this wonder" looks much more sensible, especially bearing in mind that there's a rule "AI can't build a wonder on Chief or Lord, if player is building this wonder". And it looks like a typo. But it's possible that this rule was intended this way, so it should implement kinda random element.
4) change a year in rule "1 turn = 1 year, when SS is launched". Now it's 1750. This rule creates some buggy effects now and everything will look even more buggy if we will change it, for example, to 1000 AD or to 1 AD. Maybe the art of 20-year space ship is a better solution.
5) make it so that AI actually declares the war on 3rd civ in "mercenary" routine in diplomacy. But the price is so extremely low here, that maybe it was intended for AI to trick you here... And it's hard to implement such a patch in a neat and not ugly way (without jump to beyond the routine and then back).

Maybe I will create 3rd patch that will include these dubious fixes.

EDIT: patch IDs fixed, forgot to change them from "enable debug in vv03-05" patch
 

Attachments

  • patch202_ai_diplomats.xml
    1.6 KB · Views: 21
  • patch203_cumulative_bugfix_for_v05.xml
    4.6 KB · Views: 15
Last edited:

pureciv

Chieftain
Joined
May 31, 2021
Messages
13
Although I play V.01 this still makes a great read.
Trade routes being mutiplicative on each other makes sense, but somehow overall trade should not grow too much as it gets out of hand when you stack wonders on top and everything.
 

rhaul

Warlord
Joined
Mar 25, 2010
Messages
221
Location
Madrid
@tupi
simply wonderful, anything to fix and therefore improve the game is a great feat.

By the way, the second patch could you also modify it for the .04 version?
 
Last edited:

tupi

Warlord
Joined
Jun 25, 2011
Messages
214
Location
Russia
Is it ok if I include your patch in JCivEd directly?
Yes, of course.

By the way, the second patch could you also modify it for the .04 version?
I should search for corresponding places in .04, then yeah, I can tell you where these bytes are.
 

rhaul

Warlord
Joined
Mar 25, 2010
Messages
221
Location
Madrid
thank you very much. I am looking forward to seeing the new behavior of the diplomats.
 

tupi

Warlord
Joined
Jun 25, 2011
Messages
214
Location
Russia
for "AI buys 1st nuclear" condition:
You can search: 80 bf f2 70 19 74 03
change f2 to f5
Address in CIV.EXE:
v03: 0xee99
v04: 0xee9f

for "AI launch SS if player is "space-enabled" and has more than 1000 gold" condition:
You can search: 8a 6b d1 e3 81 bf d6 b1 e8 03
change 8a 6b to ee dc
Address in CIV.EXE:
v03: 0xe8ce
v04: 0xe8d4
 

rhaul

Warlord
Joined
Mar 25, 2010
Messages
221
Location
Madrid
Thank you very much tupi, I just made the changes to my civ.exe file. These modifications make me eternally happy, thank goodness we have JcivED to preserve, document and apply these patches in the future if needed.

One question.
If I only had "0xe8d4" how could I interpret it to look for the string "80 bf f2 70 19 74 03" with a hex editor?
 

tupi

Warlord
Joined
Jun 25, 2011
Messages
214
Location
Russia
Sorry, I don't understand your question. 0xe8d4 (59604 in decimal) is just an address in exe where you should change bytes. If everything's ok (i.e. your and my exe are identical), at this address there should be "8a" and then "6b" bytes (before you change them). I simply gave you exact address to patch bytes for your convenience, just in case you don't want to search for this address using one-time sequence (8a 6b d1 e3 81 bf d6 b1 e8 03).
 

rhaul

Warlord
Joined
Mar 25, 2010
Messages
221
Location
Madrid
sure, that's what I meant, I know it is an address to search and change bytes those bytes ("8a" to "8b") but I don't know how to interpret it to be able to search those bytes in my hexadecimal editor without using the hexadecimal sequence "8a 6b d1 e3 81 bf d6 b1 e8 03".


I don't know if I make myself clear. I'm sorry I have such poor English.
 

rhaul

Warlord
Joined
Mar 25, 2010
Messages
221
Location
Madrid
Other possible fixes (dubious):
1) AI rule to speed-up palace with gold: cannot be sure that this was Palace and not Militia. But if Palace was intended, game reads beyond the array so it should be fixed.
2) trade arrows from trade routes should be like they are shown on a city screen. Logically, it should be so, and also in this case pre-calculated corruption will actually be used for something, and previous trade routes will not increase income from the next ones. But it will decrease trade routes per-turn profit for both you and AI, and also there's a small chance that "increase current trade route income according to previous trade routes income" behavior was intentional.
3) rule "AI can't build a WotW on chieftain, if player doesn't know civ. advance to build a city improvement with the same id as a wonder". Rule "AI can't buld a wonder on chieftain, if player doesn't know civ advance to build this wonder" looks much more sensible, especially bearing in mind that there's a rule "AI can't build a wonder on Chief or Lord, if player is building this wonder". And it looks like a typo. But it's possible that this rule was intended this way, so it should implement kinda random element.
4) change a year in rule "1 turn = 1 year, when SS is launched". Now it's 1750. This rule creates some buggy effects now and everything will look even more buggy if we will change it, for example, to 1000 AD or to 1 AD. Maybe the art of 20-year space ship is a better solution.
5) make it so that AI actually declares the war on 3rd civ in "mercenary" routine in diplomacy. But the price is so extremely low here, that maybe it was intended for AI to trick you here... And it's hard to implement such a patch in a neat and not ugly way (without jump to beyond the routine and then back).

Maybe I will create 3rd patch that will include these dubious fixes.

@tupi were you able to make any progress with this third patch? I am particularly interested in this work, especially point 5).
 

tupi

Warlord
Joined
Jun 25, 2011
Messages
214
Location
Russia
Fix for "working" destroyed Great Library was added to cumulative patch. Destroyed Great Library will no longer cause stack overflow. But city with the Great Library actually captured by barbarians still will cause the bug.

@tupi were you able to make any progress with this third patch? I am particularly interested in this work, especially point 5).
There's no easy way to do that. Maybe it's possible to jump from function to an area at the end of overlay and then back, so we can add new code here. There are some zeroes at the end of overlay, and I'm not sure but possibly overlay is loaded into RAM as a whole, including these zeroes. But even if this is possible, it will be very dirty patch so I will not include it in cumulative patch. Maybe instead of jump we can create small funciton at the end of overlay and call it... Also, two AI civs talk every 4 turns (civ 1 number + civ 2 number + game turn is divisible by 4), and also after every 16th game turn (when "contact" flag is reset to 0), so this code will be pretty useless, as max duration of war will be 3 turns (and it will be totally useless every 4th turn - they will simply make a peace again immediately).
 
Last edited:

Humungus

Chieftain
Joined
Mar 2, 2007
Messages
23
Hello Tupi,
I discover today this patch which re-activate the possibility for ai to create and use diplomats, that can steal techs. It seems very interesting !
Do you know if, with this patch, an ia civ can steal techs to other ia civs ? If answer is yes, the difficulty at high levels (emperor, ...), will be notably increased ! have you remarked such thing ?
Thanx,
Humungus
 

Mize

Prince
Joined
Jun 17, 2011
Messages
394
Hello Tupi,
I discover today this patch which re-activate the possibility for ai to create and use diplomats, that can steal techs. It seems very interesting !
Do you know if, with this patch, an ia civ can steal techs to other ia civs ? If answer is yes, the difficulty at high levels (emperor, ...), will be notably increased ! have you remarked such thing ?
Thanx,
Humungus
I'm pretty sure they sometimes steal from each other. Will snap a screenshot if it happens in one of my future games.
 

rhaul

Warlord
Joined
Mar 25, 2010
Messages
221
Location
Madrid
There's no easy way to do that. Maybe it's possible to jump from function to an area at the end of overlay and then back, so we can add new code here. There are some zeroes at the end of overlay, and I'm not sure but possibly overlay is loaded into RAM as a whole, including these zeroes. But even if this is possible, it will be very dirty patch so I will not include it in cumulative patch. Maybe instead of jump we can create small funciton at the end of overlay and call it... Also, two AI civs talk every 4 turns (civ 1 number + civ 2 number + game turn is divisible by 4), and also after every 16th game turn (when "contact" flag is reset to 0), so this code will be pretty useless, as max duration of war will be 3 turns (and it will be totally useless every 4th turn - they will simply make a peace again immediately).

I suppose that in principle it sounds like a foolishness to pay only for 3 turns but it is also true that the money asked is very little, therefore, they can be profitable and totally justifiable.

In certain situations I would gladly pay 200 or 400 coins to be helped even if it was only 3 turns, and it would even be totally profitable to pay that price every 3 turns if necessary (to give an example).

I'm pretty sure they sometimes steal from each other. Will snap a screenshot if it happens in one of my future games.

Unbelievable, I have never seen it before. Could you also attach the saved game so I can play it?
 
Last edited:

Skybuck

Warlord
Joined
Apr 23, 2005
Messages
286
Yeah me too, I haven't seen them in ages, I do play .05 so now I am very much interested in trying out these fixes.

Also the AI getting stuck building the same units rings a bell in my mind and sounds horrible, so I want to free the AI from it's misery/shackles and limittedness...

Very interested in this path... now trying to figure out how to apply it.

So far to figure out the civilization version, just start civ1.exe and look at the screen it should say the version somewhere

My version says: 474.05

Maybe it's interesting to modify this screen if possible, to include which patches were applied or to up this version number somewhat... to indicate this patch was applied ! ;)

Ok I save the xml file in:

C:\Tools\JcivEd\version 0.0.19a\patches

So far so good, I make a backup of civ1 just in case, already have a bunch hehe.. hmmm...

One question about this patch though ?

Once it's applied to the executable will it effect save games ? Can the older save games be played... I am kinda currently into a certain game but ok =D

I guess it will lol, a bit late now... but maybe I will notice the AI switching/producing some other units... hmmm....

OK Cummulative Patched applied ! I am very excited by this ! I may report back on this especially if I see any diplomats stealing techs ! LOL.

Also nice touch to keep the diplomat and unit switch build bug seperately, from perhaps the other stack fixes ? In case the cummulative one fails/produces new bugs I could try the other smaller/diplomay/unit switch only patch ! ;) But for now I go full mounty ! =D I haven't seen a civ crash in a while now, thanks to new dos-box-x version 2022.09.0. I can highly recommend that version =D
 
Last edited:

Skybuck

Warlord
Joined
Apr 23, 2005
Messages
286
One question though about this:

"
5) make it so that AI actually declares the war on 3rd civ in "mercenary" routine in diplomacy. But the price is so extremely low here, that maybe it was intended for AI to trick you here... And it's hard to implement such a patch in a neat and not ugly way (without jump to beyond the routine and then back).
"

I think you mean when I ask the AI to attack another CIV, it asks for money, I give it... but then it does not declare war on the other CIV ! LOL.

So indeed was this a trick ? LOL, Maybe something random ? Maybe sometimes it does sometimes it does not ? ;)

Hmmmm... would be cool if the AI sometimes does declare war on the requested civ but ok...
 

Skybuck

Warlord
Joined
Apr 23, 2005
Messages
286
I notice one difference when applieing this patch, or actually both.

The graphics of the diplomacy screen with the russians look different.

The background seems to shine through the front letters/text.

Also later the colors seem to be off... hmmm..

Not yet sure if it's a fluke of bad luck or if it is patch related. You may want to check graphics of diplomacy screen with Russian before and after the patch.

There was also another screen... I can't remember... maybe the invention screen, it colors looked different... hmm...

One possible reason why this game feels different is that I disabled animations. Something I normally don't do... it's quite interesting/amusing.

Instead of showing how the barracks is build... it just shows a newspaper item... hehe... still kinda distracting cost time but it does allow the game to be played a little bit faster.

I am just rushing it to see what happens, fastest diplomat I ever build probably haha ! lol.

This could explain why maybe the graphics are a bit different or at least the game feels a bit different hmmm.. not sure yet.

So far now more strange graphics/colors, must it occured because I was in windowed mode while tabbing to this forum.

Anyway I will keep testing the patch and if I notice any more strange graphics issues I will report back... for now take it with a grain of salt.

I do recommend playing with animation off and movement of enemies off, it's quite amuzing and amazing gives the game a totally different feel ! =D

I also play with sound off... but now I kinda miss it a bit somehow.. strange ! =D I am used to playing with nosound the last few days, but now I somehow want it back because no more annoying barracks and invented technology screens, I will turn sound back on to see if I like it and less jingles !

No still many annoying jingles, especially diplomacy screen.

But now I think I know what the civpedia text on option is for... it's too disable the civpedia text for when an invention is made. I will try and turn that option off, maybe it will play faster and less annoying invention jingles !

Ah horsehocky it still produces annoying jingles... the civpedia text is missing, but it still shows another text for new units... hmmm... and a newspaper item.. hmmm..

Maybe create some patches to turn this on or off... or maybe I need to use other startup options... like sound but no music ! ;) hmmm...

Tip while testing this: give writing to the greek ! LOL I am so used to not giving tech early on ! HAHA ! =D

I will build diplomat contact him again, maybe he will ask for it again ! ;)

Would be nice if tech could be traded with civilizations on demand/request/selection etc.. hmmm...

Also giving gold or giving cities would be nice ! ;) I miss that from civ3 !

Well disabling the civpedia text is an improvement for researching technology, usually I just skip it anyway... though I do kinda like looking at it's graphics as an "achievement" "ok I got that" ! ;)

The crazy thing I think is that civpedia text is now replace with a news item, I am not sure if the news item was there as well if this option is on, I ll try turning it on again... cause if the new option isn't there when it's on then it doesn't really matter when it comes to number of key presses ! ;) and loading time is instant... so... hmmm maybe some fade in and fade out savings... but not much... hmmm..
 
Last edited:

Skybuck

Warlord
Joined
Apr 23, 2005
Messages
286
I just re-discovered I trick I used to use when I was young, I totally forgot about it... first I was trying F1 to F7, then I noticed F7 doesn't do anything yet.

But then I looked at top cities... since there are only so few cities, basically 1 per civ it's possible to see how my civ is doing compared to others so early on in the game.

It also indicates if I have a quick start or a late start... I think the game might be doing some kind of evolution/pre-processing/gaming before it actually drops me onto the world, not sure though, but sometimes I notice I am a bit later to the party ! Very interesting hypothesis ! ;)

This forum has editing issues though, can't edit if smiley is last character oh well.. that a bit annoying.

This trick can also be used to estimate what kind of building the enemy might have created, like a granary or something, but probably game resource or so !

OK, that is odd, when pressing F7 it displays no screen, apperently F7 is for wonders of the world, when there are no wonders it refuses to display the screen.

I am not sure if this is normal behaviour I will start another copy of civ to check ! ;)

Haha funny ! F7 is indeed blocked if no wonders yet ! HAHA ! I miss that screen, feels weird !

It should have said: no wonders yet ! LOL =D That be better ! =D Civ trivia quiz ! HAHA.

Nope the news item is still there even when civpedia is on.

I love building diplomat first ! LOL let's me see earlier on who is trading tech with who, and who is in the game ! LOL.

Chinese were trading loads of tech with greece and gives me a sense of how advanced they are.

I was also wondering about the white text in the technology screen F6 it indicated with which tech the civ started according the the manual I think... hmmm..

I was wondering if maybe it would indicate which other techs the enemies dont have hehe.

Great for stealing too lol... they probably too weak anyway to kill me hehe. Since there is so much to invent and I usually have some extra techs as well, it's probably easy to make peace again... very interesting idea to steal tech early !

Well that's not true, they can kill me lol... mongols just raped my paris... hmmm... this will take some more time to test... but I love the idea of diplomats early in the game... just have to combine it with some gold and high tax rate to bribe enemy units ! ;)

Well that concludes some fast testing for today, too tired now to continue/test my full blown advanced war game. Though I tested it briefly... I did notice something which I am not sure if it's an effect of this patch.

Both Zulus and another civ invented SDI defense at the same time... not sure if that was coincidence and normal... or if maybe this patch also fixes some SDI defense research bug for AI... could be...

Well hopefully so more fun times ahead !

Amazing if you fixed this stuff ! Keep up the good work ! I wonder how you do it ! LOL Maybe make a youtube video about that ?! ;) =DDDD
 
Last edited:
Top Bottom