Need help Modding Strategic Resources

grimey

Chieftain
Joined
Oct 5, 2010
Messages
13
I want to make a mod that adds a strategic resource requirement to some units.

For example make all the modern ships and tanks require Iron as well as Oil. And one of the examples is to make a Knight require iron as well. There is one problem with compatibility so far and that is the R.E.D. Modpack which adds Extra U.U. of a unit to add new models for the flavor units is there a way to change something like the resource requirement for an entire unit class instead?

It has seemed a simple enough of a task but every different attempt just ends in failure

I also have deleted the requirement for iron on early siege weapons which is the only thing that has worked so far but I don't know if that is messing up anything. Here is what I've got so far.

<GameData>
<Unit_ResourceQuantityRequirements>
<Delete UnitType="UNIT_CATAPULT" />
<Delete UnitType="UNIT_ROMAN_BALLISTA" />
<Delete UnitType="UNIT_TREBUCHET" />

<update>
<Where UnitType="UNIT_IRONCLAD" />
<Set ResourceType="RESOURCE_IRON" />
</update>
<update>
<Where UnitType="UNIT_KNIGHT" />
<Set ResourceType="RESOURCE_IRON" />
</update>
<update>
<Where UnitType="UNIT_KNIGHT" />
<Set ResourceType="RESOURCE_HORSE" />
</update>
<update>
<Where UnitType="UNIT_CANNON" />
<Set ResourceType="RESOURCE_IRON" />
</update>
</Unit_ResourceQuantityRequirements>
</GameData>

Any advice is greatly appreciated.
 
R.E.D. copy the requirement of the base units to the new ones (ex: if your mod add iron as a needed resource for tank, then all tanks added by R.E.D. will need iron too), but this will work ONLY if R.E.D. is loaded after the mod(s) that change the units requirement.

We can't yet use mods association in modbuddy to set the load order, but Mentos has posted a workaround in his Unity Mod thread (see end of first post)
 
That's great to know but what i really need the most help on is fixing my code so the new requirements will work in the first place
 
your code is replacing coal by iron for ironclad, replacing horse by iron for knight (then re-replacing iron by horse), and update an entry (cannon) that is not existing.

if you want to add a resource requirement, use the add syntax:


Code:
		<Row>
			<UnitType>UNIT_KNIGHT</UnitType>
			<ResourceType>RESOURCE_IRON</ResourceType>
		</Row>

If you plan to change one requirement then add another for a unit, the order is important, maybe you should then simply remove all requirements (like the syntax for early siege unit) first, then add or (re-add) those you want.
 
Wow....

I can't believe it was that simple...

I tried to set it up like that when i first started this but I think I had some extra stuff in there like an update bracket around the whole thing or something like that and well yeah It feels like the face palm I gave myself hit me with enough force to knock out Mike Tyson.

Thanks for the help and I love your Mod BTW.
 
Gedemon explained it well. The thing to remember is that each Row in a secondary table (like Units_ResourceQuantityRequirements; basically the ones without an ID line) is independent. So if you want to change a unit that requires Horses to require Horses AND Iron, then you don't Update anything, you just add a new Row so that there are now two rows for the unit (and not use the Update syntax). The game, when assembling the database, will simply apply both to the unit in question.

And no, you can't do it by unit class. In XML, you have to declare the resources explicitly for each unit, including UU variants, which means that your mod will not work well combined with mods that add new units (including DLC). You can get around this a bit using SQL, but then mod load order becomes crucial.

In my own mod (technically within the Balance half of my 2-part mod), I've done almost exactly what you described: Knights require both Iron and Horses (including the Camel Archer and Songhai Muslim Cavalry), as do Lancers (including the Sipahi). Tanks (including the Panzer) require both Iron and Oil. Battleships require Iron as well. Modern Armor and Stealth Bombers require both Oil and Aluminum. I also made a few other changes, like having Missile Cruisers require Oil, and Nuclear Submarines require Uranium instead of Aluminum.

It's worked very well in practice; the "primary" combat units of the later eras are harder to mass-produce since it's likely you'll be short on one resource or the other, and it encourages use of the "support" units.
The one major headache that it requires altering the resource rarities and quantities for most of the late-game strategics, especially Oil, because the default game won't put enough on the map for this to work well. And unfortunately, that's not an XML change; editing AssignStartingPlots.lua is NOT for the faint of heart, and causes compatibility issues with most major content mods out there (especially any that add new resources to the game).
 
Thanks for all the great info especially the part at the end about the lua modification that would be needed.

About the scarcity of oil with these kind of changes would it be possible to make a building that gives oil like an oil refinery and make it limited by making oil be a nearby resource is it possible to do that??
 
There's no way in the core game to create new units of a resource. However, there's a VERY handy mod component that does exactly that: Whys' Building Resources mod from back in November. It works well; the only real downside is that you won't get the resource until the start of the next turn, but that's a minor issue. I heavily use this functionality in my own mod, including doing exactly what you describe: having a building that requires the presence of a local resource, and creates more of that resource. (I did it with one of my custom resources, not oil, though. But yes, it works.)

Note that Building Resources isn't really a complete mod in itself, it's better used as a component within your own mod. But it works just fine; I use it heavily within my own mod.

Doing what you describe will have a few minor headaches. For one thing, that XML stub for local resources would have no way of distinguishing land-based oil from sea-based. Also, you can't have the added amount depend on the number of oil deposits near this city; if the building adds 1 Oil and requires a local deposit, then having three oil deposits near this city won't add +3, so it's not quite the same as making the deposits 1 unit larger.

In the long term you're better off modifying the actual resource allocation, but that has several issues. As I said before, it'd be incompatible with many mods, but it'd ALSO be incompatible with the Great Plains, Lakes, and Highlands map scripts. (It wouldn't crash those maps, but they override the resource amounts with custom values that would negate your changes.)
 
Thanks for the all the great info. I will use this building resource mod. I will make it so the building simply gives an extra amount of oil for cities with oil just to give an option for civs to use their extra money and production to get some extra oil.

The overall idea of this mod is that I find it weird that most modern day armies have a large core of infantry that is augmented with tanks, air force, helicopters, navy, artillery, ect. and it just seems like regular infantry units are not the majority of the military built. Plus It also makes things more realistic I mean really a battleship takes no iron to build???

I just hope it isn't too hard to make the ai use this new building. I probably won't try to mess with lua I'm too much of a noob to even try that and the problems you told me about really make me not want to try it. Plus a shortage of oil is kinda what I'm looking for to give a real reason for a war and a good reason to get autocracy for the +100% strategic resources.

Thanks again
 
The overall idea of this mod is that I find it weird that most modern day armies have a large core of infantry that is augmented with tanks, air force, helicopters, navy, artillery, ect. and it just seems like regular infantry units are not the majority of the military built.

If that's all you want then you could also get the same effect simply by reducing the number of resources. Play on Sparse resources instead of Standard or Abundant, and you'll have fewer resources placed on the map in the first place, which means you'll run out more quickly. This'll force you to use resourceless units (i.e., infantry) as a larger part of your army. Just don't take it too far, or you'll look like a City-State, with tons of artillery and SAMs.

The problem with doing what you're talking about is mainly the building-vs-unit balance. There are a few resources that are used both by buildings and units, so if you use this method and make a building that creates, say, Aluminum, then it's not easy to make sure the AI builds roughly the same number of Hydro Plants and Spaceship Factories as before. It's especially problematic if you make more units require Uranium.

I just hope it isn't too hard to make the ai use this new building.

Very easy, although the fine-tuning might take some time. The AI, when choosing which buildings to make at any moment, simply looks at the Flavor values, which you have full control over. AIs don't actually know what each building DOES, though, so it can't work through the logic chain of "hmm, I'm running low on Oil, maybe I'd better build a Refinery". It's more like "Production is good, and hey, that building over there has a high Production Flavor, so I'll build that." followed by "Okay, it's complete, and I just gained a unit of Oil by coincidence."

Since this building will only be in cities that have local Oil supplies (not many), you can set its Flavor values very high (total 100+), so that the AI will always consider the building to be a high priority.

I probably won't try to mess with lua I'm too much of a noob to even try that and the problems you told me about really make me not want to try it.

Lua is a programming language. If you've done any major programming, then it's really not hard to get the hang of. The only headache is that the devs turned off the debugging tools (FireTuner and the log files) by default, so you have to turn them back on. Frankly I'd suggest turning them all on even if you have no intention of doing Lua, because they're just so useful...

AssignStartingPlots.lua is just notable because of how badly it's laid out. It's HUGE, it covers tons of different things all at once (instead of being split into multiple files), and since Maps take precedence over Mods (stupid) any changes you make to it will not be compatible with the three map scripts I listed, OR any Scenario maps. It's also so large that ModBuddy won't work well for it, but any text editor will work just fine.

There's also a question of old-vs-new. Modifying an existing game Lua function file (like AssignStartingPlots) requires replacing the file in its entirety, which is automatically incompatible with any other mod that modifies the same file. NEW Lua functions work just fine, though, without any sort of compatibility issues.

Plus a shortage of oil is kinda what I'm looking for to give a real reason for a war and a good reason to get autocracy for the +100% strategic resources.

While I can understand the sentiment, be VERY careful using something like this. Both this and your proposed building have the same basic limitation: you have to HAVE the Oil to GET the Oil. Oil is by far the most terrain-limited resource, basically limited to the worst terrains (Desert, Tundra, offshore), so depending on the map it's easily possible that you'll have none at all.

At the same time, you're increasing the number of units that require the Oil, so you're widening the window where a shortage would cripple you. If Modern Armor requires both Oil and Aluminum, then a player with no Oil who's reached Tanks can't just play defensively for a few techs until his Tanks get replaced.
Generally I think this is still a good thing, which is why I made a similar change in my mod, but it's something to watch out for. This is why I mentioned AssignStartingPlots... you can increase the number of Oil deposits slightly, to make it less likely that any one civ goes without, while lowering the number of units per deposit to keep the total balanced.

And be very careful with the "shortage" concept. Shortages are far more damaging to the AI than to a human player; the Human will unlock Oil, look around and see that he has none, and immediately look to see where there's some available Oil. Maybe an unclaimed island, maybe a city-state that needs bribing. So even if the geographic distribution didn't favor him, a human player won't be entirely without Oil. An AI, on the other hand, has no similar logic, so if he's got no local Oil and he hasn't made friends with a city-state that does, he's out of luck.

It's made worse by the fact that all resources are purely probabilistic in the vanilla game. For instance, here's the logic the game uses, as it applies to Oil:
1> Go through every land hex in the game and see if it should get a Large deposit.
If it's a Marsh, there's a 1 in 9 chance it has a strategic resource.
If it's Tundra, there's a 1 in 16.
Snow: 1 in 17
Hills: 1 in 22
Jungle: 1 in 33
Forest: 1 in 39
Grassland or Plains (no Features): 1 in 33.
2> If the random draw above succeeded, do a new randomization depending on the terrain type.
If it's a Marsh, there's a 35% chance of a Uranium and a 65% chance of an Oil. (These are Large deposits: 7 units for Oil, 4 for Uranium, and so on.)
Oil also has a 40% chance on Tundra, 60% chance on Snow, and 65% chance on Desert.
3> Add extra strategics to the locations of City States.
4> Add 23 Small deposits of resources; for Oil, Small means 3 units per deposit. It'll pick a random unused hex on the map, and depending on terrain type will look up a slightly different table. The odds on this are a bit simpler; a Marsh is a 2 in 4 chance (50%), non-hills Jungles are 1 in 4, and so on. With 23 total deposits across 6 resources and depending on terrain types, it's easily possible that no Oils will be added this way. (Aluminum is especially rare to see in Small deposits; you almost always only see the big 8-unit deposits.)
5> Place Oil in the Sea. The number of total units (not deposits) placed in the ocean will be half what's placed on land, barring rounding errors. These will be 4-unit deposits unless you're playing on Abundant.
6> If there's NO Oil on the map at all after the above logic, add one Large deposit.

The bottom line is that there's no guarantee there'll be nearly enough Oil anywhere in the world, and the AI's inability to perceive a need for a resource could cripple them if you start increasing the number of units that require it.
Iron's fairly safe, because it's so common, so feel free to add it to the Battleship, Tank, etc., but watch out for doing the same for Oil or Uranium.
 
Back
Top Bottom