[LUA] Bonus Resources Appearing on Mountains

JeBuS27

Heretic
Joined
Sep 21, 2005
Messages
321
So, let me start off by saying that I've been modifying AssignStartingPlots.lua in an attempt to make things more modular. The amount of changes I've made is ridiculous, so I won't post it here. But that's also the problem, as I've changed so much, I can't narrow down where this bug is occurring. Now the reason for this post.

I have been noticing that Wheat and Deer are appearing on Mountain plots. I haven't noticed any other bonus resources appearing on them, but I may just not have seen it yet.

Now, I know what you're thinking: I must have goofed something up to allow the resources to be placed on Mountains. And I'd agree with you, it's the assumption I've been working under for hours now. Eventually I got sick of looking for the bug, and I started printing out debug info about the terrain that resources were being placed on. Nowhere did Mountain show up.

So, I stuck this bit of code at the end of AssignStartingPlots:PlaceResourcesAndCityStates
Code:
local iW, iH = Map.GetGridSize();

for y = 0, iH - 1 do
    for x = 0, iW - 1 do
        local plot = Map.GetPlot(x, y);
        local resourceType = plot:GetResourceType();
        local terrainType = plot:GetTerrainType();

        if resourceType ~= -1 then
            print("Placed "..GameInfo.Resources[resourceType].Type.." on "..GameInfo.Terrains[terrainType].Type..".");
        end
    end
end
What that does is loop through every plot on the map, and if it has a resource, it prints the resource and the terrain type of the plot.

The problem is, nowhere does TERRAIN_MOUNTAIN show up in that list. And yet, if I explore the map, I'll usually find wheat or deer sitting on a mountain.

I'm out of ideas.


Additional info:
I added x,y coordinates to the printout, and have found that when wheat appears on mountains, they're printed out as plains. When deer appear on mountains, they're printed as tundra. If Lua sees them that way, why do they appear as mountains (and get labeled as such on mouseover)?
 
Are mountains and hills terrain types? In Civ 4 they weren't, the terrain type was grasslands, plains, desert, tundra or snow but mountains and hills were handled differently. Now I remember reading through the map script code and saw comments that plot types were used differently in Civ 5 (and I'm at work so I can't check) so I guess the first question that you should try to answer is what are mountains and hills defined as? I'm guessing it's not a terrain type and if you check your debug output you probably don't see TERRAIN_HILL in there anywhere either.

I'll check again when I get home tonight to see if I can help you figure out how to work it out, but if you're doing something while I'm still at work (or I forget to check back) hopefully this at least gives you somewhere to start :)
 
Seven05, it's entirely possible that's the case. TERRAIN_MOUNTAIN is listed in the Terrains database as #7, and TERRAIN_HILL is #8. I assumed they worked that way, but they may not, now that you mention it.

Yep, that was it. Once I put in a check for PlotTypes.PLOT_MOUNTAIN, they stopped appearing there. But that kind of sucks for modularity, because now mountains need to be specially checked for.
 
Check the bonus infos and see if there is a value in there to allow them on mountains (I'm guessing not). If there is you can just add the check in and apply the rule just like you would for terrain and feature limitations.

This is really annoying because I was so familiar with all of this for Civ 4 but I'm not quite at the point where I'm ready to work on changes to the world or maps just yet so I'm stuck with old info in my head :)

If you want, send me a PM with you'r steam ID and I'll dig around through the files with you in about 3 hours after I get home and see if there is an elegant solution. I know I'm going to run into all of this soon enough anyway so I may as well look now.
 
The Resource_FeatureBooleans and Resource_TerrainBooleans is what I was basing my work on. But because TERRAIN_MOUNTAIN isn't reported, and there's no Resource_PlotTypeBooleans table, it ends up being a special edge-case.
 
Well, for almost every mod out there not allowing resources on mountains will be the correct rule. For mods that do allow that, they'll probably use custom versions of resource placement anyway. So for now I think it would be very safe to not allow any bonus types to be placed on mountains. Just note it in the file :)
 
Actually, at the moment I'm testing adding a new xml file "CIV5Plots.xml" and adding a Plots table and a Resource_PlotsBooleans table to the database. Any resource mods based off of it would need to add their resources to the list, but that should work.

Edit:

And it wasn't just about resource placement. It was also about making terrain modular. If Mountains were hard-coded into the resource placement, that's one terrain type that isn't modular at all.
 
Ok, I might not be helping, but are you sure you are using the right coordinates for each function?
The game uses both the grid and the hex position coordinates and Ive noticed that while most functions return the hex pos. you usually have to add the grid as input. I for one am always confused which one to use. :)
GetPlot() uses grid for sure. And the coords you see in debug mode are the grid ones.

So you could try this:
Code:
for y = 0, iH - 1 do
    for x = 0, iW - 1 do
	local gX, gY = ToGridFromHex(x, y);
	local plot = Map.GetPlot(gX, gY);
 
The problem was definitely that TERRAIN_MOUNTAIN isn't used. Apparently PlotType.PLOT_MOUNTAIN is instead.
 
A bit of an update:

I have created a few new SQL tables via XML to further define the relationships between Terrain, Features, and Resources. The tables I added so far are: Plots, Feature_PlotBooleans, Resource_PlotBooleans. Through Lua via "GameInfo.Feature_PlotBooleans" for example, I can now test the relationships in a data-driven manner, rather than the way Firaxis handled it, by "hard-coding" the checks in the script. It's actually making for cleaner code because functions are smaller, and can be reused, rather than having a specific function for adding a bonus on a hill plains, and another for adding a bonus on the coast.
 
And you didn't even need the DLL to do it :)

I'm liking the SQL database for that reason myself, hopefully more people will catch on to it.
 
I think my strategy for doing exactly-the-same-thing to AssignStartingPlots will avoid this (I hope), because I'm taking a minimal-modification approach. This limits my modification to only work with the same range of terrain as the base game, of course... however, it sounds like you're further along then I am. Perhaps I may as well not bother?

Sam, not happy to now be discovering he's wasted his time because someone else more well-known was working on it faster and better anyway. Not that it's anyone's fault, anyway...
 
I think my strategy for doing exactly-the-same-thing to AssignStartingPlots will avoid this (I hope), because I'm taking a minimal-modification approach. This limits my modification to only work with the same range of terrain as the base game, of course... however, it sounds like you're further along then I am. Perhaps I may as well not bother?

Sam, not happy to now be discovering he's wasted his time because someone else more well-known was working on it faster and better anyway. Not that it's anyone's fault, anyway...
A couple of days ago I may have been a bit further along, but I haven't touched it since then. Been poking the WorldBuilder, instead. There's just so much to look at, you may as well keep going. If only because I know there will be things you have better solutions to than I do. That's just the way things go.

As for being more well-known... :lol: I don't think anyone knows me. :P
 
Back
Top Bottom