• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

New Feature type not showing in maps

ScythianBeastie

Chieftain
Joined
Oct 26, 2005
Messages
22
Location
Pantałonia
Merry Christmas to those who celebrate! :)

I'm currently working on my first ever real mod (I'll provide details if anyone's interested. :) )

I need to add a Feature to all Desert terrain tiles that don't already have Flood Plains or Oases.

I'm using ModBuddy to build my mod. I've already copied FeatureGenerator.lua and added it to my mod in Solution Explorer, and I set it to import into VFS. I've tested it, and Civ is building maps with my version of the LUA script.

However, my Feature never appears in even a single tile of my map -- and the oceans fill with ice, which is even stranger. :crazyeye: Something very odd is going on, and I'm not sure what.

This "spoiler" contains the code I'm using to set up the Feature:
Spoiler :

<GameData>
<Features>
<Row>
<Type>FEATURE_SAGEBRUSH</Type>
<Description>TXT_KEY_FEATURE_SAGEBRUSH</Description>
<Civilopedia>TXT_KEY_CIV5_FEATURES_SAGEBRUSH_TEXT</Civilopedia>
<ArtDefineTag>ART_DEF_TERRAIN_DESERT</ArtDefineTag>
<Movement>1</Movement>
<InfluenceCost>2</InfluenceCost>
<AppearanceProbability>10000</AppearanceProbability>
<PortraitIndex>1</PortraitIndex>
<IconAtlas>TERRAIN_ATLAS</IconAtlas>
</Row>
</Features>
<Feature_TerrainBooleans>
<Row>
<FeatureType>FEATURE_SAGEBRUSH</FeatureType>
<TerrainType>TERRAIN_DESERT</TerrainType>
</Row>
</Feature_TerrainBooleans>
</GameData>


And this "spoiler" contains my text strings (just in case they're relevant somehow):
Spoiler :

<Language_en_US>

<!-- Terrains and Features-->

<Row Tag="TXT_KEY_FEATURE_SAGEBRUSH">
<Text>Sagebrush</Text>
</Row>
<Row Tag="TXT_KEY_CIV5_FEATURES_SAGEBRUSH_TEXT">
<Text>Sagebrush is a near-ubiquitous component of eastern Oregon's deserts.</Text>
</Row>
</Language_en_US>


And this "spoiler" contains the changes I've made to FeatureGenerator.lua (changes should appear in red):
Spoiler :

------------------------------------------------------------------------------
function FeatureGenerator:__initFeatureTypes()

self.featureSagebrush = FeatureTypes.FEATURE_SAGEBRUSH;
self.featureFloodPlains = FeatureTypes.FEATURE_FLOOD_PLAINS;
self.featureIce = FeatureTypes.FEATURE_ICE;
self.featureJungle = FeatureTypes.FEATURE_JUNGLE;
self.featureForest = FeatureTypes.FEATURE_FOREST;
self.featureOasis = FeatureTypes.FEATURE_OASIS;
self.featureMarsh = FeatureTypes.FEATURE_MARSH;

self.terrainIce = TerrainTypes.TERRAIN_SNOW;
self.terrainTundra = TerrainTypes.TERRAIN_TUNDRA;
self.terrainPlains = TerrainTypes.TERRAIN_PLAINS;
end
------------------------------------------------------------------------------
(... and then skip down to ... )
------------------------------------------------------------------------------
function FeatureGenerator:AddFeaturesAtPlot(iX, iY)
-- adds any appropriate features at the plot (iX, iY) where (0,0) is in the SW
local lat = self:GetLatitudeAtPlot(iX, iY);
local plot = Map.GetPlot(iX, iY);

if plot:CanHaveFeature(self.featureFloodPlains) then
-- All desert plots along river are set to flood plains.
plot:SetFeatureType(self.featureFloodPlains, -1)
end

if (plot:GetFeatureType() == FeatureTypes.NO_FEATURE) then
if plot:CanHaveFeature(self.featureSagebrush) then
plot:SetFeatureType(self.featureSagebrush, -1)
end
end


if (plot:GetFeatureType() == FeatureTypes.NO_FEATURE) then
self:AddOasisAtPlot(plot, iX, iY, lat);
end

if (plot:GetFeatureType() == FeatureTypes.NO_FEATURE) then
self:AddIceAtPlot(plot, iX, iY, lat);
end

if (plot:GetFeatureType() == FeatureTypes.NO_FEATURE) then
self:AddMarshAtPlot(plot, iX, iY, lat);
end

if (plot:GetFeatureType() == FeatureTypes.NO_FEATURE) then
self:AddJunglesAtPlot(plot, iX, iY, lat);
end

if (plot:GetFeatureType() == FeatureTypes.NO_FEATURE) then
self:AddForestsAtPlot(plot, iX, iY, lat);
end

end
------------------------------------------------------------------------------



I've fiddled with this for several hours now (experimenting with the order of UpdateDatabase entries, etc., etc.), but have had no luck. :eek:

Thank you for any assistance you can provide! :)
 
UPDATE:
I just made an exact copy of Flood Plains (called "TestPlains"), and made two tiny changes in the LUA script:

Spoiler :

self.featureTestPlains = FeatureTypes.FEATURE_TESTPLAINS;


Spoiler :

if plot:CanHaveFeature(self.featureFloodPlains) then
-- All desert plots along river are set to flood plains.
-- plot:SetFeatureType(self.featureFloodPlains, -1)

plot:SetFeatureType(self.featureTestPlains, -1)
end


I also commented out my earlier LUA edits.

... and when I did that, it puts ice in desert river squares in place of the Flood Plains -- actual ice, not just something that looks like ice -- instead of the feature I want.

Is there some other script or place where I need to define my feature in order to be able to get FeatureGenerator.lua to use it?
 
The mistake you made is a pretty simple one: just because you added a new Feature to the game doesn't mean it gets added to the FeatureTypes table. It might seem obvious that it'd just add a new entry, but unfortunately, it just doesn't work that way. So, FeatureTypes.FEATURE_SAGEBRUSH equals zero... which happens to be the ID code for Ice, hence the effect you're seeing.

This same problem applies to a LOT of different tables: ResourceTypes, YieldTypes, et cetera. While the new entries are added to the database, they're not added to the corresponding tables that most of the Lua functions use. In some cases you can use GameInfoTypes.FEATURE_SAGEBRUSH instead (which DOES accept new entries), but depending on which Lua is being used, it might not work. For instance, if you add a new Yield type, none of the Lua functions for yields will use it correctly no matter how you index it. It's just a bad design, and unfortunately you're seeing the downside.
 
Spatzimaus, thank you very much for your clear and thorough reply! :)

FYI, your posts and responses to other folks have done a tremendous amount to help me with the Civ5 mod-building process. I really appreciate your work here! :goodjob:
 
FYI, your posts and responses to other folks have done a tremendous amount to help me with the Civ5 mod-building process.

Well, my posts would be even more helpful if they actually included a solution to the problem. Unfortunately, there are an awful lot of things that just don't work in the core game, so it's hard not to come across as too negative.

Thankfully, though, this isn't one of those times; while using the FeatureType index doesn't work, you CAN use the GameInfoTypes index instead to add a Feature, because it looks like the Lua code in question only cares about the ID code, not an explicit entry in the FeatureTypes table. In my own mod, I'd added a new great person type (the Empath), and the Great Empath can place a Monolith improvement, which then places a special Feature on the same plot to add Happiness (since that's not something an improvement can do). It definitely works, so you shouldn't have a problem with placing your custom feature.

You WILL have a problem graphically, in that your new feature can't have a unique model, but I've found that the game's actually surprisingly robust at cross-table art definition sharing. That is, using a Resource graphic (say, Wheat) for a Feature or Improvement, or vice versa. In my own mod I do this, with the intermediate stages in my tree-planting process (which use a temporary Improvement) using Sugar and Cotton graphics. The only issue I've run into is that if you use a resource art definition, it won't remove the graphic if the Feature/Improvement is later removed (at least, until you save and reload), but depending on what you're doing with it, this may or may not be an issue for you. (In my case, you get forests that also have the sugar/cotton graphic mostly hidden by the trees.) I'm assuming this is because resources don't ever turn off, and so their art definition doesn't include that return-to-null state that the normal Features need.
 
Back
Top Bottom