PerfectMongoose (PW3 Civ4 Port)

Joined
Jan 29, 2006
Messages
731
Location
Boston, MA, USA
PerfectMongoose 3.2


DESCRIPTION

Major Update of LM's official Civ4 Port of Civ5's PerfectWorld3_v2, using PerfectWorld_2.06f as base.

The initial version of this project took a week of 24/7, every-waking-minute work to complete. The 3.1 update took 2 more weeks, and this 3.2 update has taken a whole month. It is posted with permission from the original author, Cephalo.

This is a definitive release: I am very confident everything is finally fixed and working properly, and all the improvements I had been planning to make are now implemented.


NOTICE

If you use this in a mod you need to give me credit... in addition to Cephalo of course. :) It took way too much time and energy, with a relatively-high level of difficulty programming-wise, to not insist on that, and to not be allowed to shamelessly insert my name into the project name. :p Besides, Sevo put his name in the Sevopedia and everyone worships it (including me), so I don't feel too bad lol.


FULL NOTES

Version 3.2

* Added AIAndy's square grid evaluation, float division and geostrophic fixes, his bonus placement and starting location speed enhancements, and his PythonRandom multiplayer support.
* Added a game option to continue using the old hex-grid-based Perlin Noise code if desired, since the previous PW3 landmass shapes are different and still fully viable.
* Merged in the remaining PW 2.0.8 functionality with a game option to select the PW2 landmass generator if desired.
* Changed the rainfall thresholds from absolute values to global percents like the temperature thresholds, set them to ignore Peaks, and merged the climate system constants back together.
* Enforced the current map's x and y wrap settings in a number of places in the code, which fixes some bugs with -1 data values near the edges and should get rivers wrapping only when they're supposed to.
* Fixed natural harbor bug, and added shape randomization to natural harbor creation on diagonals.
* Changed sea ice to vary with map size instead of always being 4 tiles thick, and to require water temperature to be near freezing so the bands have some limited shape to them.
* Switched to PW2's oversized internal grid when using the PW3 LMG with the PW2 climate system so the latter works correctly.
* Changed the +/- 10% tolerances on elevation, rainfall and sea level thresholds to +/- 2%.
* Removed MeteorCompensationFactor since the system does indeed work best without it. (My apologies Ceph; you were right!)
* Made a number of additional code improvements.

Version 3.1

* Fuyu's 2.0.6f bonus placement, starting location enhancement, minimum hill enforcement and bad feature removal code were added, along with his control variables.
* Reverted some more settings for use with vanilla that were still set for my mod.
* Added allowance in getPlotPotentialValue() for clearing features with negative food (ie Jungles), since it already accounted for cleared features with tile improvements that require it (only useful in mods).
* Added StartEra checks to verify the tech requirements are met for clearing features in both cases.
* Agreeing with Cephalo, I left the starting location production resource food override threshold at half the city plots being workable, rather than two-thirds.
* Changed the TechCityTrade requirement for resource valuation and placement to TechReveal since the former makes no sense: if a bonus is visible it enhances the tile, and if it isn't visible it doesn't enhance the tile, regardless of whether it can be harvested or traded with other cities.
* Added BonusMaxGroupSize option of -1 for setting Fuyu's clump limit based on WorldSize, clarified the description of what the 0 option there actually does, and fixed the random bounds.
* Added a minimum value to the StartEra checks to include all Classical resources, improvements and clearing abilities in the plot valuations.
* Changed allowWonderBonusChance to allow any strategic resource (not just Stone or Marble), and the city sweetener to allow non-strategic resources - both up through Classical (or later).
* Adjusted lake and river values again, and added separate controls for them for the two climate systems.
* Increased Desert slightly and Plains considerably in the PW2 system.
* Synchronized the PM3/PW2 code substantially more to make future updates easier.
* Scaled temperature from normal linearly down to zero in the top and bottom thirds of the map in the PW3 climate system, to get Tundra and Snow in the higher and lower latitudes as there should be.
* Lowered Tundra/Snow temperatures to compensate.
* Increased PW3 Grassland level slightly.

Version 3.0

* The PW2 HeightMap and ClimateMap have been replaced with their PW3 counterparts.
* PW2's high-altitude randomization was removed since it was causing 80-100% of land tiles to be Peaks regardless of settings.
* PW2's SmallMaps were removed since the new Perlin Noise landmass generator does not require an oversized map to avoid looking bad.
* The YToXRatio hex grid scale factor has been removed.
* PW2 control variables that are now unused have been removed, and the necessary PW3 ones have been added. Values have also been adjusted as needed or desired.
* mc.MeteorCompensationFactor was added to try and help preserve total land percent when using Break Pangaeas. It is currently set to 1.1 which just adds a little style to my version... crank it up to around 2.0 if you want full compensation (though the result may not look as good).
* The Sea Level menu option has been enabled, and mc.SeaLevelFactor was added to support it.
* The Use menu option has been added, and a slightly-modified version of the PW2 ClimateMap was added back in, to support having a choice between the PW2 and PW3 climate systems.
* PW3's north and south attenuation were removed.
* PW2's code that forced Snow to be at higher elevation than Tundra, Tundra to be higher than everything else, and Desert to not be, well, something... was removed.
* Plains in the PW3 ClimateMap were set to have a null rainfall window and a relatively large temperature window, so that they form exclusively as a result of cold deserts; this helps create Great Plains type areas. (You also don't seem to get enough Grassland unless you max it out by doing things this way.)
* RiverThreshold's dependence on PlainsPercent (via PlainsThreshold) was removed so that its value can be set reliably.


DOWNLOAD

PerfectMongoose 3.2


SCREENSHOTS

These were taken while running MongooseMod so it's not vanilla terrain graphics, sorry.

EARTH!!! Well, minus Africa lol. - It coughed this up in an early test generation. Look at the minimap. :)

Perlin Noise + Pangaea Breaker - Just a random cool-looking map.

The Great Plains... have arrived. - This happens fairly often with my settings.

The Great Plains... have returned. - Most of these screenshots had the Pangaea Breaker on just since it's the default menu option; I'll post some with it off when I get a chance.
 
Those coastlines look great! One comment I have is that you should really fill in all lakes below a certain size before running your rivers. It looks bad to have a major river flowing into a tiny lake. The AreaMap class is good to use for that. Let me know if you have any questions regarding its use.
 
Those coastlines look great! One comment I have is that you should really fill in all lakes below a certain size before running your rivers. It looks bad to have a major river flowing into a tiny lake. The AreaMap class is good to use for that. Let me know if you have any questions regarding its use.

I still do that. The minSize for the fill-in procedure got reduced from 100 to 50 b/c 50 was the new default value in PW3... I also changed the lake generator's default values a fair bit (reducing minimum elevation, increasing drainage->size factor a little and turning off siltification completely) since I thought lakes were way too too small and infrequent in general before and had never really thought to adjust them til now.

I dunno, I think they look great the way they are, and you had rivers flowing in or out of size 2-3 lakes all the time in PW2 before just b/c ALL lakes were size 2-3 almost heh... But yeah I can try changing the settings some more in a future version. Those are all user-adjustable for now though if people want to look at the values in PW 2.06 and revert them. :)
 
I could have sworn I got rid of that in PW2, but maybe I'm mis-remembering. I remember eliminating small lakes entirely, and then adding them back in a way that didn't interfere with the river system. I mentioned it because several of your screenshots have a long river leading into a small lake. No big deal if you think that's ok, it was something that really bugged me from PW1 so I worked extra hard to get rid of it.
 
Thanks for this, but I'm disappointed that you didn't base it on PerfectWorld2f. I would never play 2.06.
 
Edit - Oh wait, you mean Fuyu's version. Well I can probably switch it over to that pretty easily actually, but I'll have to look and see what it does differently first to see if I want to. Sorry, I did download 2f a while ago but I kinda forgot about it heh.

Oh, and you're probably right Ceph; I was only paying attention to lake size and frequency and not to rivers flowing into them or not. I definitely remember getting only a few small lakes with your settings, but that doesn't mean they had rivers... dunno why I jumped to that conclusion heh. Sorry. I probably messed it up switching to PW3's minOceanSize value of 50 for the lake filler.
 
Okay, just took a quick look at 2f vs 2.06 in WinMerge, and it's just a few changes to resource placement and player starting location modification (plus a couple control variables for those things). None of which has anything to do with the PW3 components or my own changes or additions, so it'd take about 5 minutes to convert my files over to being based on 2f, heh.

Let me read up on exactly what 2f does and make sure I agree with it first, and I probably need to mess with the river/lake values some more, but I may post an update fairly soon for these two things.
 
Well I tested it heavily and tweaked the control variables for two solid days pretty much... Grass, Plains and Desert should all be roughly equal in quantity, in general, on most maps (though Desert gets killed by really small map sizes which is unavoidable; mountain ranges dictate it spawning). You can also try the PW2 Climate menu option which will give you exactly what you're used to on PW2f, terrain-type wise.

But yeah I was specifically shooting for Great Plains areas with this new PW3 climate system, since someone in the PW2 thread was complaining he wanted to see those, and they are kinda cool. :)
 
I'm sorry if I seem overly critical, because I am happy to see someone update PW2. I'm glad you worked on the plains, too. You never got many large plains and the donut desert gots old.

The problem with PW2 was always that the starting locations were completely broken, and that's why PerfectWorld2f is so much better.
 
One problem I had in Civ4 with plains is that for BtS it is plains tiles can't feed themselves, making them far, far less valueable. You can't farm brown because if you build a farm on it then it can only feed itself, making it basically useless. Somebody starting on all plains needs a major food boost, and adding bonuses is only barely adequate for that. A town on green is basically more powerful than any bonus. That's why I had to keep plains under tight control. Deserts at least have floodplains so you can work the surrounding hills, with plains you can't even do that.

By having fewer plains, I could somewhat limit those "all plains" starts that everyone hates.
 
One problem I had in Civ4 with plains is that for BtS it is plains tiles can't feed themselves, making them far, far less valueable. You can't farm brown because if you build a farm on it then it can only feed itself, making it basically useless. Somebody starting on all plains needs a major food boost, and adding bonuses is only barely adequate for that. A town on green is basically more powerful than any bonus. That's why I had to keep plains under tight control. Deserts at least have floodplains so you can work the surrounding hills, with plains you can't even do that.

By having fewer plains, I could somewhat limit those "all plains" starts that everyone hates.
The solution is to simply allow the floodplains feature on plains. In real life, floodplains exist in places all over the world that are certainly not what you'd call deserts, including the Mississippi river! To balance this, have the script only place floodplains in fewer, more suitable desert areas rather than every single desert in the world.

Regarding starting locations, the issue in PW2 is that when the location is improved for the starting city, food resources are considered after other resources are placed. Reverse this, and even a plains location will be reasonably good. The surrounding area may not be, but that's true of other starting situations, like tundra and jungle.
 
Regarding starting locations, the issue in PW2 is that when the location is improved for the starting city, food resources are considered after other resources are placed. Reverse this, and even a plains location will be reasonably good. The surrounding area may not be, but that's true of other starting situations, like tundra and jungle.

That shouldn't be true in the recent versions of PW2. I can't remember exactly how I did it now since it was a long time ago, but I'm pretty sure I always placed food any time there was not enough food to support some other resource.

That said, there were also some continent rules that could prevent things like wheat being placed on plains, and since wheat is the only food resource that can be placed there, you could have a situation where the rules prevented food bonuses because they were present on different continents.
 
That shouldn't be true in the recent versions of PW2. I can't remember exactly how I did it now since it was a long time ago, but I'm pretty sure I always placed food any time there was not enough food to support some other resource.

That said, there were also some continent rules that could prevent things like wheat being placed on plains, and since wheat is the only food resource that can be placed there, you could have a situation where the rules prevented food bonuses because they were present on different continents.
I had it wrong. When PW2 is sweetening starting spots it places resources in the order of production, commerce, and then food, but the first two passes will place food resources instead if there isn't enough food to work half of the city tiles. In PW2f it will switch to food resources if there isn't enough food to work 2/3 of the tiles, and then it does a fourth pass for more production resources.

Also, there's a 5% chance per resource placed in the starting spot to ignore terrain restrictions.
 
Version 3.1 posted, which is a fairly major update. Please see above for details.

@Cephalo: If you load up plain ordinary PW 2.06 in vanilla BTS and run a couple of test games, you will see that there are still plenty of size 2 and 3 lakes that have rivers, both short and long, coming out of them, so this wasn't something I broke in my versions here heh.

@OnmyojiOmn: I have actually gone ahead and added Flood Plains on flat Plains tiles with rivers to my mod since I liked your idea so much, but it requires either a new Feature entry in the XML, or else a modification in the SDK of how yields are calculated... unless you're willing to let the tiles have a value of 4 food 1 hammer 1 commerce which is a bit much imo. So I am not including it in this vanilla version of PerfectMongoose since it is beyond the scope of a mapscript alone.
 
I'm getting a "page not found" error when I try to download this.

Gah, sorry. It's fixed now. Thanks for speaking up. :) Forgot to update the link string in the CF entry for the new version number in the filename. I'd successfully avoided making that mistake a number of times with a number of files up til now, but I guess it had to happen sooner or later. In my defense I was/am super busy and distracted finishing my big mod update hehe.

I will post some neat and more current screenshots too when I get a chance here.
 
Thank you so much for the update!

Regarding flood plains, you could check to see whether a modded feature with a certain name (FEATURE_FLOODPLAINS_PLAINS or whatever) is present in the game, and use that.
 
Regarding flood plains, you could check to see whether a modded feature with a certain name (FEATURE_FLOODPLAINS_PLAINS or whatever) is present in the game, and use that.

I'm not gonna release a whole update just for this, but I'll be happy to show you how to add it if you want, since it's pretty simple. :)

In PerfectMongoose_v310.py, search for "def addFeatures" and scroll down slightly, or just go to line 5036. Then replace:

Code:
				if cm.RainfallMap.data[i] > tm.plainsThreshold * mc.TreeFactor and PRand.random() < mc.MaxTreeChance:#jungle

with:

Code:
				if plot.isRiver() and tm.data2[i] == mc.PLAINS and tm.data1[i] == mc.LAND:
					plot.setFeatureType(fPlainsFloodPlains, 0)
				elif cm.RainfallMap.data[i] > tm.plainsThreshold * mc.TreeFactor and PRand.random() < mc.MaxTreeChance:#jungle

Finally, define your new feature type at the top of the function, probably inserted at line 5016 would be good. Something like:

Code:
	fPlainsFloodPlains = gc.getInfoTypeForString("FEATURE_PLAINS_FLOOD_PLAINS")

The procedure is the same for PerfectWorld_v208.py, except "tm.data2" is "sm.terrainMap", and "tm.data1" is "sm.plotMap" (as you can see by looking around the addFeatures() function).

For the new feature itself, you'll want to just copy/paste a duplicate version of the existing Flood Plains entry in XML/Terrain/CvFeatureInfos.xml, then set the food/production/commerce stats to either 2/0/0, 1/0/0, or 2/-1/0.

Be advised that while I can't think of anything off the top of my head that would be affected in regular BTS, any events, animal FeatureNative settings, unit/promotion feature movement/combat effects, or custom DLL code that references specific FeatureTypes directly, that involve Flood Plains will not support the new Plains Flood Plains feature by default (which is part of why I didn't do it this way in my mod, heh).
 
Top Bottom