Don't need no stinkin' factories!?

Ambreville

Deity
Joined
Sep 28, 2006
Messages
2,255
Location
Windy City USA
OK, here's the situation -- a specific building type is needed as a pre-req to train critical combat units. Yet the AI fails to understand it needs to build these facilities or rebuild them after they are destroyed. Is there something that can be done to induce the AI in constructing these buildings, at least in XML?
 
Adjusting the flavors might be one means of doing this.

That's the sticky problem. I've already done that and made sure they matched the leaders' traits, but the AI still insists in constructing every other shade of buildings... except the gosh darn Messerschmitt, Focke-Wulf, and other factories of that ilk.
 
I've listed the following in the buildings xml file for these factories:

Code:
	<Flavors>		
		<Flavor>	
			<FlavorType>[COLOR="Blue"]FLAVOR_MILITARY[/COLOR]</FlavorType>
			<iFlavor>[COLOR="Blue"]5[/COLOR]</iFlavor>
		</Flavor>
		<Flavor>
			<FlavorType>[COLOR="Blue"]FLAVOR_PRODUCTION[/COLOR]</FlavorType>
			<iFlavor>[COLOR="Blue"]10[/COLOR]</iFlavor>
		</Flavor>	
	</Flavors>

I tried switching the ratings between Military and Production, but it doesn't seem to have any effect either.

Is there another file I need to contend with which would help coax the AI into constructing these factories?
 
I've listed the following in the buildings xml file for these factories:

Code:
	<Flavors>		
		<Flavor>	
			<FlavorType>[COLOR="Blue"]FLAVOR_MILITARY[/COLOR]</FlavorType>
			<iFlavor>[COLOR="Blue"]5[/COLOR]</iFlavor>
		</Flavor>
		<Flavor>
			<FlavorType>[COLOR="Blue"]FLAVOR_PRODUCTION[/COLOR]</FlavorType>
			<iFlavor>[COLOR="Blue"]10[/COLOR]</iFlavor>
		</Flavor>	
	</Flavors>

I tried switching the ratings between Military and Production, but it doesn't seem to have any effect either.

Is there another file I need to contend with which would help coax the AI into constructing these factories?

Smack the AI with a stick and loudly say "Bad!".

In seriousness, I had this same problem with one of my small mods... Ended up just making a building that already exists into what is needed for my unit... Which kinda sucked.
 
What is strange is that the aircraft assembly plants are basically copies of the factory building. The difference is that I had to reduce the number of hammers generated by all factory type buildings across the board to avoid "over producing". So there's not too much special going on here.
 
yes, this has been a serious issue in many mods. Heck even in FFH2, theres an option to make the AI not require those type of buildings to build units, because they generally do so bad with that type of thing... Probably best you can do is adjust some flavors, maybe a couple other small things.
 
Ok, here's a quick & dirty explanation of what the AI is doing and why it won't do what you want... the key to your problem is '...the aircraft assembly plants are basically copies of the factory building. The difference is that I had to reduce the number of hammers generated by all factory type buildings...' :)

When evaluating what to build the AI defines a value of each building based on what the building provides as bonuses, so if it provides no bonus the AI won't build it, ever. Pretty slick really, and it works very well as you can see by making two buildings that are nearly identical with one have some extra bonus, the AI will always build the one with the extra bonus first.

The existing code is very 'relgion focused' because the base game only uses it for missionaries so if a building is a prereq for a unit it only considers the value of the unit if they have none of that 'unitAI type' in the area and even then the resulting value doesn't take any units stats into consideration.

So your quick fix is to make the building more attractive, domain production modifiers are a great way to accomplish that, just increase the hammer costs of your air units and then give the factories a modifier to get those costs back down to where you wanted them. You can also add experience modifiers but for a factories... probably not the best choice. Giving them a +1 or 2 research would also help. And increase your flavors substantially, if you took the regualr factory bonus and cut it in half, double the flavor values. Also, make sure the advisor is set appropriately since that has an impact on the building's value, probably military for this case.

Now, if you plan on doing some SDK work it wouldn't be hard to impliment a propper value for buildings used as prereqs for units that don't have anything to do with religions.
 
Ok, here's a quick & dirty explanation of what the AI is doing and why it won't do what you want... the key to your problem is '...the aircraft assembly plants are basically copies of the factory building. The difference is that I had to reduce the number of hammers generated by all factory type buildings...' :)

When evaluating what to build the AI defines a value of each building based on what the building provides as bonuses, so if it provides no bonus the AI won't build it, ever. Pretty slick really, and it works very well as you can see by making two buildings that are nearly identical with one have some extra bonus, the AI will always build the one with the extra bonus first.

Wow -- thanks for the guidelines. I kinda was getting there. You just made it all clearer. I had already reduced the hammer benefits in the basic factory, perhaps not enough. I'll ratchet that up. I think your idea off inflating the cost of airplanes, and then adding a big air unit production bonus in these assembly plants seems to make a lot of sense.

So your quick fix is to make the building more attractive, domain production modifiers are a great way to accomplish that, just increase the hammer costs of your air units and then give the factories a modifier to get those costs back down to where you wanted them. You can also add experience modifiers but for a factories... probably not the best choice. Giving them a +1 or 2 research would also help. And increase your flavors substantially, if you took the regualr factory bonus and cut it in half, double the flavor values. Also, make sure the advisor is set appropriately since that has an impact on the building's value, probably military for this case.

What is the maximum flavor value I should use? In the unit info file, it seems the highest value = 10. Could/should it be higher, and by how much? How do I set up "appropriately" the advisor??

Now, if you plan on doing some SDK work it wouldn't be hard to impliment a propper value for buildings used as prereqs for units that don't have anything to do with religions.

Unfortunately, I'm not literate with either Python or SDK. That'll have to wait until I can figure out what to in that arena.

Thanks again for your help here!
 
<<Seven05>>

I think a big part f the problem is that the AI does not think it needs to build aircraft. It's got a core number of aircraft assembly plants at the start of the scenario. It's just not building airplanes -- therefore it probably thinks it does not need additional assembly plants either, despite the additional incentives we talked about earlier. Does it help at all if I add "military flavor" tag line in the unit infos xml file?

Maybe it's a combination of things. Because, once I'm done blowing up the AI's assembly plants it does look like it's trying to replace them... go figure. When a lot of its bombers and fighters have been shot down, the AI tries to build just a tiny handful of new fighters, and merrily goes back to building granaries, and so forth.
 
iAIWeight is your friend. Use it wisely and it shall repay you well.

Remember that this tag can be found in almost anything: Buildings, units, civics, religions, techs, you name it. That is the best way to make the AI do things any intelligent human would do in a certain scenario. For example in war scenarios, the AI insists on building aqueducts even though his cities are being rampaged through. Solution? iAIWeight!
 
iAIWeight is your friend. Use it wisely and it shall repay you well.

Remember that this tag can be found in almost anything: Buildings, units, civics, religions, techs, you name it. That is the best way to make the AI do things any intelligent human would do in a certain scenario. For example in war scenarios, the AI insists on building aqueducts even though his cities are being rampaged through. Solution? iAIWeight!

Thanks. This might just be what I need. What's the range of numbers expected with this tag? 0-10, 0-100, 0-1000?
 
Are you only using XML, or are you also doing some python/SDK work?

In XML alone you have to cheat a bit with AI Weights & flavors (they both do almost the exact same thing anyway). The problem you're running into is that air units aren't as important as ground units due to the way the AI was coded, there are numerous hard-coded weights by UNITAI_??? types in the DLL and modifiers of when to build them per city.

You can go pretty high with the flavor values, to avoid overflows I think the safe upper limit would be somewhere around 400-500. Flovors (and the AI Weight setting) are used as multipliers when the AI determines the value of a unit/building/tech. In a normal game 10 is a good upper limit as it doesn't force things on the AI and lets the AI adapt a little.

To get the AI to build more air units either increase the AIWeight for each unit, add flavors for them (a little more control here), or adjust the UNITAI weights per leader (even more control).

For instance you could get Churchill to build a ton of fighters by increasing his preference for UNITAI_DEFENSE_AIR like this (in Civ4LeaderheadInfos.xml):

<UnitAIWeightModifiers>
<UnitAIWeightModifier>
<UnitAIType>UNITAI_DEFENSE_AIR</UnitAIType>
<iWeightModifier>150</iWeightModifier>
</UnitAIWeightModifier>
</UnitAIWeightModifiers>
With some fine-tuning you could get him to build fewer bombers at the same time if you wanted. As long as you have the UNITAI's defined properly per unit you're all set. This modifier, BTW, is a percentage on the final value I believe it's been a while since I played with it.
 
I think I've got the problem licked, at last!

I had to ratchet up weight modifiers to a 200-400 range in the Leaderheads, Units, and Buildings info files. And even then in the test I ran, the AI really didn't bother with new factories and new aircraft until I started knocking out a significant number of its armada out of the sky. In the past, even that wouldn't coax the AI into building what it needed.

The actual situation is this. I was running the RAF with a relatively small defense force. The AI was running the Luftwaffe with a large number of air units. This may have been one of the reasons why the AI wasn't adding more. It probably concluded it had "enough". The other issue may also be that this mod has no ground units except ack-ack, which probably throws the AI into a "loop" that only very big weight modifiers seem to counter-act.

I'll have to run a second test with roles reversed, to see if the AI scrambles earlier in the game to build new factories and fighters in the face of a much larger enemy force.
 
You can try higher numbers and they may work, the problme would be when you exceed a value of 65535 you'll 'flip' the counter and start again at -65535 or 0 depending on the data type (I don't have the source in front of me to look, sorry). Anyway, if a unit has a base value of 65 and you give it a weight of 1000 you'll be fine, but if the unit's base value is 130 your weight of 1000 would break it.

The shame is that to get them to do what you want would only involve changes to maybe 5-10 lines of code in the SDK rather than tweaking weights and flavors on every unit and leader :)

Here's another question for you, what else can the AI build? Do you have wealth/research processes for them to convert production? Do you have a bunch of 'filler' buildings and units that aren't absolutely necessary? You may want to considering removing the research/wealth/culture processes and as many buildings as you can pull out. If your AA units have the city defense unitAI setting (and only that unitAI) there is already code in place to limit how many they'll build based on a preferred number of defenders per city although there is no guarantee that they won't just build a ton of those if they have nothing other than AA or air units to build.
 
In fact, the SDK change is even easier for your case, just need to tell the AI it needs more aircraft when it chooses what to produce. Want a compiled version of the dll?

Code:
/*** Seven05 Begin ***/
			//if (iAircraftHave * 2 < iAircraftNeed) <- Old Firaxis code
			if (iAircraftHave < iAircraftNeed * 2)
			{
				if (AI_chooseLeastRepresentedUnit(airUnitTypes))
				{
					return;
				}
			}
/*** Seven05 End ***/
 
Back
Top Bottom