Home » MODDING HQ 1.13 » v1.13 Modding, Customising, Editing » v1.13 Time Capsule (How-to Library) » "How does it work?" Part 11: Enemy Gun Selection
"How does it work?" Part 11: Enemy Gun Selection[message #244880]
|
Sun, 21 February 2010 05:55
|
|
Headrock |
 |
Messages:1757
Registered:March 2006 Location: Jerusalem |
|
|
"How Does It Work?" series: [/b]</font>Enemy Gun Choices
There have been no less than two occasions in the past year where this question has come up:
"How do enemies pick which gun to carry?"
Speculations were rife, and both times I had to step in to clear things up. I do this by looking at the game's source code and trying to figure out, well, "how does it work".
Since I'm really not looking to do the research again a third time, I figured I'd just write it all down, once and for all, so that I could point people to it.
Disclaimer: The game is written in C++, and while fairly simple to read, it may confuse many players. Therefore, "How Does It Work" guides are written in Pseudo-Code, which is basically a translation into plain English.
This chapter does not explore the entire item generation system. It is focused primarily on the enemy decisions about which GUNS to carry. However, the majority of the item choice system works the same way.
Also note that the same formula is used for MILITIA equipment. However, it works slightly differently for them, they generally get worse equipment than Soldiers of similar level.
In the future, I may or may not expand this article with those missing details. No promises.
Basic process overview
When do enemies get randomized equipment?
Enemies come in two major flavours - Pre-generated and Randomly-Generated.
Pre-Generated enemies are the ones that are explicitly placed on maps with the JA2 Map Editor. Modders normally give these enemies a specific gun, but sometimes allow the game to make its own, random choice about which guns to give them.
Randomly-Generated enemies generally come from enemy units that move around the Strategy Map. Sometimes these may wander into city sectors and become stationary. Regardless of whether they are moving on the map or not, they come with no pre-made data, and so whatever they are carrying had to has to be randomly generated.
Note that in both cases, if randomization is involved, it happens when the sector is LOADED. If an enemy manages to survive a battle (esp. by running away), the next time you meet the SAME enemy, he will have new randomized equipment. For instance, an enemy that drops its weapon and runs will have a new weapon when you meet him again. He'll have a new weapon even if he didn't drop his last one.
Only pre-made, hand-placed enemies will carry the same weapon every time. Examples include a sniper in Alma carrying a Dragunov. He'll carry that same weapon every game, because he was hand-placed by the SirTech level designers when they made JA2.
What influences weapon choice?
There are several misconceptions about this, which this article is supposed to clear up. Let's see a list of all factors that influence weapon choice:
- The soldier's class (ADMIN / TROOP / ELITE).
- The Difficulty Level of the game you're playing.
- The highest Progress you've achieved so far in the game (even if it has dropped since).
- The customizable file (DATAFolder)\TableData\EnemyGunChoices.XML.
- Distance from the queen's palace (Sector P3).
- Several randomized variables.
- The JA2_Options.INI setting called "SLOW_PROGRESS_FOR_ENEMY_ITEMS_CHOICE".
Contrary to... common belief... the weapons your men are carrying have absolutely no effect on this formula. Only the above-listed values have any effect.
In addition, a gun's COOLNESS has no bearing on when it will appear in game. What DOES matter is where this gun is listed in EnemyGunChoices.XML, as you will see shortly.
Formula Outline
Let's get a quick overview of how the formula goes. This section explains it briefly. The next section will explain it with greater detail (including pseudo-code).
- Step 1. Calculate the distance from the palace. This is called a "Distance Modifier".
- Step 2. Use the Distance Modifier to calculate a simple "Equipment Modifier".
- Step 3. Calculate the difficulty of the game compared to your highest progress. This is called a "Difficulty Modifier"
- Step 4. Compare the Difficulty Modifier and Equipment Modifier, coming up with a "Basic Weapon Level".
- Step 5. Add a modifier based on Soldier's Class to the Basic Weapon Level.
- Step 6. A random chance to add or subtract a point from the Basic Weapon Level, giving us a Final Weapon Level.
- Step 7. Choose a random weapon from EnemyGunChoices.XML, from a category corresponding to the Final Weapon Level.
Confusing? It is. Let's get down and dirty.
<font size="]Formula
We'll now go step by step, following the exact formula used by the game. Try to stay familiar with the different modifiers, because they can get pretty confusing.
Ready? Go.
STEP 1: CALCULATE DISTANCE MODIFIER
If the Current Sector is in Alma, then
Distance = 10
If the Current Sector is in Orta, then
Distance = 4
Else,
Distance = The distance between the Current Sector and the Queen's Palace (sector P3)
Distance is capped at 20, although it can't get over 21.213 anyway.
Distance is calculated using the Pythagorean Theorem. If you've studied any maths in school, you should know what this means.
It is rounded down.
Note that the Current Sector is the sector where the soldier is at the time you meet him. If you meet the same soldier in different sectors, the changed distance from the palace may have a serious influence on his weapon choice, assuming he's moved far enough between encounters.
Also note that in Alma and Orta, the distance is artificially reduced to make these randomly-generated enemies more dangerous than they would normally be.
Distance Modifier = (( 20 - Distance ) * 30) / 20
This produces a range of 0 to 30. The result is the Distance Modifier which will be used twice, later in this formula. Remember it!
STEP 2: CALCULATE EQUIPMENT MODIFIER
We're now going to use the Distance Modifier to get an Equipment Modifier.
Temporary Value = (Distance Modifier / 3) - 5
Given that the Distance Modifier's range is between 0 and 30 (see previous step), we now have a value of between -5 and 5.
RandomNum = Roll a random number between 0 and 9.
Temporary Value is increased by RandomNum.
If Temporary Value is smaller than 0, then
Temporary Value = 0.
If Temporary Value is greater than 9, then
Temporary Value = 9.
We applied a random modifier, and then limited the result to between 0 and 9.
If we're in Autoresolve mode, then
Temporary Value is decreased by 1.
For Autoresolve battles, enemies are actually given worse weapons and equipment. Militia, on the other hand, get a +1 bonus. This is supposed to make battles between them more fair, since Militia get crappier weapons on the whole. But who cares about Autoresolve anyway.
Now, let's find out the Equipment Modifier based on the Temporary Value we have.
If Temporary Value = 0, then
Equipment Modifier = 0.
If Temporary Value = 1 or 2, then
Equipment Modifier = +1.
If Temporary Value = 3, 4, 5 or 6, then
Equipment Modifier = +2.
If Temporary Value = 7 or 8, then
Equipment Modifier = +3.
If Temporary Value = 9, then
Equipment Modifier = +4.
Ah, the Equipment Modifier is what we were aiming for, really.
We now dump the Temporary Value, it's of no use to us any longer.
We keep the Equipment Modifier for later use though! It is very important!
STEP 3: CALCULATE DIFFICULTY MODIFIER
Now let's find out what the difficulty modifier is. It's based on the game's difficulty level, but also on our highest Progress level.
If Game Difficulty is NOVICE, then
Difficulty Modifier = 0.
If Game Difficulty is EXPERIENCED, then
Difficulty Modifier = 10.
If Game Difficulty is EXPERT, then
Difficulty Modifier = 20.
If Game Difficulty is INSANE, then
Difficulty Modifier = 30.
Very simple, this is our starting point for the Difficulty Modifier calculation.
If our Highest Progress Level is more than 0, then
Difficulty Modifier is increased by 5.
Note that the Highest Progress Level is the highest we've achieved in this campaign. It's possible for progress to go down if we mess up, but this formula only cares about our "best" progress so far, not about the "current" progress.
If Daily Mine Income = 0, then
Difficulty Modifier is decreased by 5.
The game makes life a little easier on us if we don't control any mines.
Difficulty Modifier is increased by Distance Modifier.
Remember the Distance Modifier from Step 1? We now add it to the Difficulty Modifier.
Make sure that the Difficulty Modifier is no less than 0 and no more than 100.
Simple enough, capping the Difficulty Modifier to correspond to a range of 0 to 100.
And we're through with this. We have to remember the Difficulty Modifier of course, because we're going to use it in the next step.
STEP 4: CALCULATE BASIC WEAPON LEVEL
In this step, we calculate the important modifiers we got from the previous steps together.
Depending on the SLOW_PROGRESS_FOR_ENEMY_ITEMS_CHOICE setting from JA2_Options.INI, we may get completely different results here.
If SLOW_PROGRESS_FOR_ENEMY_ITEMS_CHOICE is set to FALSE, then
Basic Weapon Level = (Equipment Modifier - 5) + (Difficulty Modifier / 10).
If SLOW_PROGRESS_FOR_ENEMY_ITEMS_CHOICE is set to TRUE, then
Basic Weapon Level = Difficulty Modifier / 10.
As you can see, SLOW_PROGRESS_FOR_ENEMY_ITEMS_CHOICE=TRUE ignores the Equipment Modifier completely.
At this point, SLOW_PROGRESS_FOR_ENEMY_ITEMS_CHOICE=TRUE actually produces a HIGHER Basic Weapon Level, but as you'll soon see, the end result will be quite different.
STEP 5: ADD SOLDIER CLASS MODIFIER
We now add yet ANOTHER modifier, which is based on the soldier's "rank" - ADMIN (YellowShirt), TROOP (RedShirt) or ELITE (BlackShirt).
If SLOW_PROGRESS_FOR_ENEMY_ITEMS_CHOICE = FALSE, then
If Soldier's Class = ADMIN, then
Basic Weapon Level is increased by 1.
If Soldier's Class = TROOP, then
Basic Weapon Level is increased by 3.
If Soldier's Class = ELITE, then
Basic Weapon Level is increased by 5.
Obviously, soldier class is a MAJOR modifier, and Blackshirts get a massive advantage here. Their weapon level is boosted up by a whopping 5 points.
Note, of course, that if SLOW_PROGRESS_FOR_ENEMY_ITEMS_CHOICE is set to TRUE, this modifier is completely ignored!
STEP 6: ADD RANDOM MODIFIER
Now, depending on the soldier's class, we have some chance to get either a +1 or -1 to our weapon level. Most often, however, we get nothing.
If Soldier's Class = ADMIN, then
RandomNum = Roll a random number between 0 and 4.
If RandomNum = 0, then
Random Modifier = +1.
If RandomNum = 1, then
Random Modifier = -1.
If Soldier's Class = TROOP, then
RandomNum = Roll a random number between 0 and 6.
If RandomNum = 3, then
Random Modifier = +1.
If RandomNum = 4, then
Random Modifier = -1.
If Soldier's Class = ELITE, then
RandomNum = Roll a random number between 0 and 10 (or 0 and 11, if using NIV)
If RandomNum = 4 or 10, then
Random Modifier = +1.
If RandomNum = 5, then
Random Modifier = -1.
This roll is actually much more important than what's shown above, because various roll results can alter the level of all equipment this soldier might be carrying, including armor and grenades etc. However, we are only interested in guns right now.
Final Weapon Level = Basic Weapon Level + Random Modifier.
Aha! This is the Final Weapon Level!
At this point, the Final Weapon Level is anywhere between 0 and 10. Excellent, this represents the number of categories in EnemyGunChoices.XML.
Note that I'm skipping a serious part about soldiers randomly rolling up RPGs and other launcher-type equipment. That's a bit beyond the scope of this article. I might add that bit in, sometime in the future. Or not.
STEP 7: CHOOSE A RANDOM GUN
Now that we have a Final Weapon Level, we go and have a look at EnemyGunChoices.XML.
The file is divided into 11 sections, numbered 0 to 10. Each section holds a list of index number, each representing a single gun from Items.XML.
All we have to do now is to find the section corresponding to our Final Weapon Level, and randomly choose one of the guns listed.
Again, the gun's Coolness Level is completely irrelevant. If a gun with coolness 10 is listed in section 0, it will probably be available at the start of the game from ADMIN-level enemies, on NOVICE difficulty.
And that's all there is to it. Hope the modifiers haven't blown your head off, and see you next time in "How does it work"!
[Updated on: Mon, 27 April 2015 23:46] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: "How does it work?" Part 11: Enemy Gun Selection[message #254260]
|
Fri, 18 June 2010 18:43 
|
|
BallerDave |
 |
Messages:71
Registered:April 2008 Location: Ze land of ze sheep, Dubl... |

|
|
Thanks Dieter
this should provide a way for users who do not contribute to the game directly to at least try and sponsor all of you good people who keep the game alive and in a state of constant evolution.
[Updated on: Fri, 18 June 2010 18:51] by Moderator Report message to a moderator
|
Corporal
|
|
|
|
|
|
|
Re: "How does it work?" Part 11: Enemy Gun Selection[message #269530]
|
Fri, 07 January 2011 12:34
|
|
Buns |
 |
Messages:655
Registered:September 2010 |
|
|
Ah yes, thank you. I had been setting up a mod that makes weapon progress by technology levels and was noticing that it didn't work as it should. Such as WWII still being dropped at progress level 70 (what should give 1970s weaponary) in case the battle took place somewhere north of Cambria. Now I know the reason: progress doesn't play a role.
OK, I'll wait for the new version and meanwhile make a different approach to Arulcan Army outfit.
Report message to a moderator
|
First Sergeant
|
|
|
Goto Forum:
Current Time: Wed Jul 09 19:54:15 GMT+3 2025
Total time taken to generate the page: 0.06022 seconds
|