New Resource Model - Inconsistent Behavior

sman1975

Emperor
Joined
Aug 27, 2016
Messages
1,370
Location
Dallas, TX
Hello, I'm working on a mod that adds about 30 new resources to the game. Most of them come from Horem's work and Skaz' work here (https://forums.civfanatics.com/resources/resource-expansion-packs-on-map-generator.22621/).

All the resources load properly and the logs are clean. However, on a few of the new resource instances, I'm seeing things like this:

upload_2020-12-5_9-43-48.jpeg upload_2020-12-6_7-35-46.jpeg

There are 2 "Hardwood" and "Clay" resources in adjacent tiles. In one (on top), the model appears correctly on the map. In the other (on bottom), the resource is technically on the map, but the model does not appear.


Different model, same effect. I've tried several different models, all with similar behavior:

upload_2020-12-5_16-13-34.jpeg


After I improve both of these tiles with a plantation, the "empty" tile does not show a plantation improvement, but the new resources are added to the player's holdings.

Screen grab of what happens when a visible Hardwood resource is improved:

upload_2020-12-5_16-36-48.jpeg


Screen grab of what happens when an invisible Hardwood resource is improved:

upload_2020-12-5_16-37-30.jpeg

The map seems to think the resource is there and is improved, it just doesn't show this properly on the map.

Please note: the resources are added properly to the player's account. Also, the Strategic View shows the correct entries for the incorrect improvement in the previous picture:

upload_2020-12-5_16-38-39.jpeg


Manually adding the resources via IGE always seems to place the "visible" (correct) version of the resource. Additionally, the same errors occur on DUEL sized maps, as well as larger ones.


Here is the code used to add the resource:
Code:
ALTER TABLE Resources ADD COLUMN Rivers boolean DEFAULT 0;

INSERT INTO Resources (Type,                ResourceClassType,        Rivers,    NoRiverSide,    Hills,    Flatlands,    MaxLatitude,    Happiness,    TechCityTrade,                IconAtlas,                        PortraitIndex,    ArtDefineTag,                                IconString,                            Description,                                Civilopedia,                                        Help,                                            AIObjective,    AITradeModifier,    ResourceUsage,    PlacementOrder,    ConstAppearance,    MinAreaSize,    Player,        TilesPer,    RandApp1,    RandApp2,    GroupRange,        GroupRand,        Normalize,    'Unique')
SELECT 'RESOURCE_SMAN_AWAW_HARDWOOD',        'RESOURCECLASS_RUSH',    0,        0,                1,        1,            90,                0,            'TECH_AGRICULTURE',            'SMAN_AWAW_RESOURCE_ATLAS',        0,                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        '[ICON_RES_SMAN_AWAW_HARDWOOD]',    'TXT_KEY_RESOURCE_SMAN_AWAW_HARDWOOD',        'TXT_KEY_RESOURCE_SMAN_AWAW_HARDWOOD_PEDIA',        'TXT_KEY_RESOURCE_SMAN_AWAW_HARDWOOD_HELP',        2,                20,                    1,                2,                50,           3,                67,            5,            25,            25,            0,                0,                0,            0            ;


Here is the ArtDefine_Landmarks entry:
Code:
INSERT INTO ArtDefine_Landmarks (Era,                State,                        Scale,    ImprovementType,                            LayoutHandler,            ResourceType,                                Model,                                                                        TerrainContour) VALUES
                                             
                                ('Any',                'Any',                        1,        'ART_DEF_IMPROVEMENT_NONE',                    'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Pinetrees.fxsxml',                                    1),
                                ('Ancient',            'Constructed',                1,        'ART_DEF_IMPROVEMENT_PLANTATION',            'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Lumbermill_MID_Pinetrees.fxsxml',                        1),
                                ('Ancient',            'UnderConstruction',        1,        'ART_DEF_IMPROVEMENT_PLANTATION',            'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Lumbermill_MID_Pinetrees_HB.fxsxml',                    1),
                                ('Ancient',            'Pillaged',                    1,        'ART_DEF_IMPROVEMENT_PLANTATION',            'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Lumbermill_MID_Pinetrees_PIL.fxsxml',                    1)        ;--,

I've attached a link to the working version of the mod here:

https://forums.civfanatics.com/resources/smans-the-ancient-world-at-war-awaw.28593/


Would appreciate if anyone can help me getting these resource models working more consistently.

Thanks.
 
Last edited:
Hey, @Nomad or What - Apologize for the confusion. I was using several different tree models to see if my problem was tied to the model itself or my definition of the resource. The SQL statement above is from a later version of the mod. Here is the statement that was used for the published mod for this resource:

Code:
('Any',                'Any',                        1.25,    'ART_DEF_IMPROVEMENT_NONE',                    'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Art/Resources/00_Hardwood/Lumbertrees.fxsxml',                                1),
                                ('Industrial',        'Constructed',                1,        'ART_DEF_IMPROVEMENT_PLANTATION',            'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Art/Resources/00_Hardwood/Plantation_IND_Lumbertrees.fxsxml',                1),
                                ('Industrial',        'UnderConstruction',        1,        'ART_DEF_IMPROVEMENT_PLANTATION',            'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Art/Resources/00_Hardwood/Plantation_IND_Lumbertrees_HB.fxsxml',            1),
                                ('Industrial',        'Pillaged',                    1,        'ART_DEF_IMPROVEMENT_PLANTATION',            'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Art/Resources/00_Hardwood/Plantation_IND_Lumbertrees_PIL.fxsxml',            1),
                                ('Ancient',            'Constructed',                1,        'ART_DEF_IMPROVEMENT_PLANTATION',            'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Art/Resources/00_Hardwood/Plantation_MID_Lumbertrees.fxsxml',                1),
                                ('Ancient',            'UnderConstruction',        1,        'ART_DEF_IMPROVEMENT_PLANTATION',            'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Art/Resources/00_Hardwood/Plantation_MID_Lumbertrees_HB.fxsxml',            1),
                                ('Ancient',            'Pillaged',                    1,        'ART_DEF_IMPROVEMENT_PLANTATION',            'SNAPSHOT',                'ART_DEF_RESOURCE_SMAN_AWAW_HARDWOOD',        'Art/Resources/00_Hardwood/Plantation_MID_Lumbertrees_PIL.fxsxml',            1),


A bit more than half the time, the model will appear on the map normally. The other times,it looks like the resource is added to the map metatdata, but simply doesn't appear on the map. The resource can be improved, with the resources then showing up, but the improvement also doesn't show up on the map. It does on the SV map, though.

The behavior has been similar no matter the model used.
 
Last edited:
Spoiler Old, Incorrect Assessment :
OK - one clue: the models seem dodgy only if they're ResourceClassType of RESOURCECLASS_RUSH, if that helps any. Normal Luxury and Bonus resources appear fine.


Actually, in further testing, the "appear/disappear" issues seems to be related to resources that have a quantity of more than 1 (i.e. primarily Strategic Resources, but when I added a special quantity boost to a couple of Bonus resources, the error then occurred to those resources - even though they appeared 100% correctly when their quantity was only 1).

Deep Blue's inspired mod "Resource Generator" (https://forums.civfanatics.com/threads/resource-generator-lua-component.401894/) uses this method to place a resource on a previously-empty tile:

Code:
iPlot:SetResourceType(New_Resource_ID, N);

Is there some kind of "dirty" event or other method that could be the cause of all this?
 
Last edited:
So far as I know this method worked last time I trialed it
Code:
pPlot:SetResourceType(iDeer,1)
From what I recall "0" does not work correctly.

"-1" for the ResourceType argument removes the resource from the plot. Don't remember if "-1" will have odd results if given as the QTY argument.

I can't remember whether giving quantity values for Strategic Resources can bork the UI if the qty assigned is not a valid one from the possible amounts in the Database for that strategic resource.
 
Last edited:
@Nomad or What - This is true, as far as ASP.lua is concerned. The mod I'm using recycles Deep Blue's approach, which executes after the map is generated. It also only adds 1 copy of a resource to a tile, unless it's a "RESOURCECLASS_RUSH" or "RESOURCECLASS_MODERN" ResourceClassType, then it checks the Resource_QuantityTypes table for an amount to spawn.

All of this works like it's supposed to. The problem remains that for any resource (of any type) that plants more than 1 unit of the resource in a single tile has a ~40:60 chance of placing the resource in the map's metadata, but not on the map itself. And when the resource doesn't appear on the map, any improvement on the resource also doesn't show up on the map. A player still "gets" those resources, though.

The basic problem is sometimes the resource shows up on the map, sometimes it doesn't show - all from the same model:

upload_2020-12-6_10-55-26.jpeg
 
I can't remember whether giving quantity values for Strategic Resources can bork the UI if the qty assigned is not a valid one from the possible amounts in the Database for that strategic resource.

Interesting - Deep Blue's script builds a table of all entries in the Resource_QuantityTypes for a given resource (called "iQuantityTypes"), then randomly chooses an element in that table whose value corresponds to the "Quantity" value from the table. So, for Iron it would choose either 2 or 6 to place on a tile. It looks like it will only spawn specific quantities from the table, so this hopefully wouldn't bork up things that way.

Will experiment with this and see if that might explain what the map is sometimes broken.
 
@LeeS - If you're up on this, do you know of a limit to the number of SV files for new resources? I've seen a few posts about having too many SV files for units causes the SV UI to crap out.

I've noticed on this mod, that after I add 22 SV files for the resources, on the 23rd resource, no SV icon shows on the SV UI. I can change the order of resources, and it will always stop displaying the 23rd and beyond resource. I can still hover over the tile and see the resource on the SV map, but the large icon doesn't display.

FWIW: the number of elements in the ArtDefine_StrategicView table is 1-296 (before my new resources, the table only has 1-275 entries). On the 297th element, the UI stops displaying the SV icon on the SV UI. All of the SV files are listed in the table with their corresponding resource, they just don't show on the SV map.

I'm harping on this as I've seen often in debugging mods in Civ5 that errors often show up in code that is actually structured correctly. However, this is some obscure problem in a completely different area of the mod that shows up as an externality elsewhere. I'm wondering if that's my problem here.

I know something's lurking in my code someplace, as my game tends to CTD when I exit the game to go back to the main menu. Logs are clean, but they don't catch everything I guess.
 
Last edited:
The issue as I recall was 256 SV icons for units -- any more than that would manifest the Icons Icons Everywhere bug where in SV or in 'regular' view the game would show Unit Strategic Icon spam on every plot.
256 is a memory allocation magic binary number -- Firaxis assumed there would never be a need to handle more than 256 units at one time when assigning memory allocation space for units flags / strategic view icons.

I cannot remember whether the bug will also manifest if the total number of SV icons registered is greater than 256 in total regardless of the 'source' of the icons (ie, whether for units, improvements, etc) -- but I do know that more than 256 SV for units instantly manifests the bug.

If you are running InfoAddict that has a tendancy to CTD when exiting the game. Even returning to main menu would cause the CTD when using InfoAddict. There was supposed to be a fix mod for it since the original author was no longer active but I have never tried to run the fix mod. InfoAddict's basic problem as I recall was executing its lua code through a wrong modinfo method.
 
OK - that makes sense. There aren't toooo many resources in the game. However, for some bizarre reason, I can't get those last 6 SV icons to show up on the SV map. The entries are in the database, and you can see the resource there when hovering the mouse, but the big resource SV icons just refuse to show up for work...
 
OK, @LeeS - as usual, you're on to the problem:

I can't remember whether giving quantity values for Strategic Resources can bork the UI if the qty assigned is not a valid one from the possible amounts in the Database for that strategic resource.

There are 2 entries in the "Resource_QuantityTypes" for a new Strat Res called, "Hardwood", 5 and 2 respectively. When Deep Blue's script adds the resource with a quantity of 2, the model appears on the map properly. When it adds a quantity of 5, then the model does not appear.

If I use only 1 entry in that table, say with a value of 4, then the code fails, as it doesn't build the temporary table it uses to distribute various quantities among the eligible tiles with only 1 quantity in the database. (It looks like the code expects every strategic resource to have 2 entries in this database)

So, obviously the code is designed to have at least 2 possible quantities spawn, however, when it does, for some bizarre reason, the smaller quantity shows up on the map, while the larger does not. I've worked around this by only placing 1 entry into the database, then when it fails for each resource spawn, assign the resource tile count to a default number.

I've played around with a dozen tests, and found out that the resources place correctly if they are 3 or less. Any number 4 or greater will cause the map to fail to place them correctly. WHY??????? :wallbash:

At any rate, I'm done with this little headache. Took wayyyyy too long to work through. But, many many thanks @LeeS for pointing me in the right direction. I'll structure the mod around the low number of strategic resource spawn, probably with adding buildings that increase the amount of resources found on the map.

OK, back the dungeon with me... :crazyeye:

BTW - @LeeS : did you ever set up that PayPal account???? Something tells me you're on Santa's "Nice" list this year! :)
 
I've played around with a dozen tests, and found out that the resources place correctly if they are 3 or less. Any number 4 or greater will cause the map to fail to place them correctly. WHY??????? :wallbash:

I hate it when things like this happen. I have been so mind-bogglingly frustrated by 3D models that for all intents should perform correctly, but they just...don't. I have countless of half baked projects that I have never been able to get into game and I can't figure out why. At least you got a partial solution that you can workaround, sometimes you get lucky. :thumbsup:
 
ArtDefinesHeavy should be included in the XML for Rush Resources that need a higher number than 3 should fix the problem.
 
Top Bottom