The Magic behind Random Missions and Difficulty
-
Table of Contents:
[olist]- Difficulty
- Difficulty Calculation for Job Offers (mBase.ini)
- Amount of NPCs created by Difficulty and NPC Level (npcranktodiff.ini)
- Requirements to have Missions offered on a Base
- Payment by Difficulty (diff2money.ini)
[/olist]
Difficulty
A basic requirement and variable for random missions is the Difficulty. It is an arbitrary decimal number in a range of [0, 100] (meaning 0 and 100 are included).
If needed the maximum difficulty can be adjusted by those offsets:
content.dll, 1143D4, 100f = maximum value of misn difficulty content.dll, 1175F0, 100f = maximum value of DestroyMission difficulty (I think; it's part of the StateMachine) content.dll, 11B22C, 100f = maximum value of rank_diff and generated mission difficulty ```([Source, adoxa](https://the-starport.net/freelancer/forum/viewtopic.php?post_id=44542#forumpost44542)) Difficulty Calculation for Job Offers (_mBase.ini_) A key to understand how Difficulty works is the way how it is used and calculated. This is unfortunately not very easy to understand at first. The main use is within mBase.ini where the values are set which difficulty a player can get from a base or NPC. The difficulty number displayed in-game when reading a mission offer has a somewhat direct connection to the chosen technical difficulty behind. Apparently those in-game numbers are hard-coded somewhere for specific difficulty values. Commonly the mission_type parameter can be understood as:
mission_type = DestroyMission, <mindiff>, <maxdiff>,</maxdiff></mindiff>
**minDiff** and **maxDiff** are important for the calculation of the real Difficulty that will be available for the player. Especially important is to note that **maxDiff is not necessarily really the maximum**. The calculations are as follows: Single Player
rank_diff = based on internal MissionNum and DATA\MISSIONS\rankdiff.ini
factor = 1.3689^3 = 2.565164201769
diff = rank_diff * factor, where diff is in range of [0, 100]If diff <= minDiff, then the player gets the message on the job-board to become a better pilot.
If diff >= maxDiff:
d = maxDiff / factor, where d becomes >= minDiff
finalDifficulty = maxDiff - cos(rnd * pi/2) * (maxDiff - d), where rnd is a random value in range of [0, 1)
else
diff = rank_diff / factor, where diff1 is in range of [minDiff, 100]
finalDifficulty = maxDiff - cos(rnd * pi/2) * (maxDiff - diff), where rnd is a random value in range of [0, 1)[/code][size]Multi Player[/size]
[code]rnd is a random value in range of [0, 3)
If rnd is 0:
diff = maxDiff
else
diff = maxDiff * 1.3689^(rnd * 2 + 2)
diff is limited to a range of [0, 100]
finalDifficulty = diff - cos(rnd * pi/2) * (diff - minDiff), where rnd is a random value in range of [0, 1)[/code]([url]Source, adoxa[/url])Looking especially on the first part of the multiplayer-specific calculation shows that [b]maxDiff is not a constant value[/b], but is getting multiplied by a random factor. This can make multiplayer missions go beyond the naively intended levels.
To understand the influence of the minDiff and maxDiff values in those calculations I do recommend to look on a graph plot for some simple values.
As an example in multiplayer when minDiff is 0 and maxDiff is 1 in the final calculation, the graph looks [url]like this[/url]
If minDiff and maxDiff are swapped interesting results [url]like this[/url] can be achieved. In those plots the left axis shows the probability to get the mission, whereas the lower axis shows the difficulty level to get.To limit the difficulty in multiplayer between the minDiff and maxDiff value, the following patch can be applied on Content.dll using [url]bwpatchw[/url].
[code]# Make MP job difficulty exactly between min and max difficulty in mbases.ini.Jason Hood (adoxa), 22 February, 2010.
Fixed 3 June, 2010.
File: content.dll # v1.1
0AAD7A: 89 44 E4 04 D9 44 E4 20 D8 64 E4 [ 99 B9 03 00 00 00 F7 F9 85 D2 74 ]
1C EB 04 66 B8 FB 06 DB 44 E4 04 [ 33 D9 05 30 B2 FB 06 DD 5C 24 04 ]
D8 0D D0 97 39 06 DE C9 D8 44 E4 [ FF D6 99 DD 44 24 04 B9 03 00 00 ]
1C 5E 83 C4 10 C3 [ 00 F7 F9 8D 54 12 ]
[/code]([url]Source, adoxa[/url])[size]Amount of NPCs created by Difficulty and NPC Level ([i]npcranktodiff.ini[/i])[/size]
It is possible to define exactly how many NPCs of a specific level are being created for a specific Difficulty. This is handled within the [i]npcranktodiff.ini[/i].
A line looks as follows:
[code]NpcRank = <npc level=“”>, <difficulty 1=“” for=“” ship=“”>, <difficulty 2=“” for=“” ships=“”>, <difficulty 3=“” for=“” ships=“”>, …[/code]Important to note:
[list]
[li]Only exactly one line of NpcRank is picked for the spawn per wave in a job.[/li]
[li]The amount of spawned ships is determined by the highest Difficulty in that line (e.g. if Difficulty is 5 and the 3rd ship column is 5, then 3 ships get spawned).[/li]
[li]By default the game can handle up to 8 ships per line. To allow for more, see the following.[/li]
[/list]
The game uses a table of weights to define a preference for the amount of ships being spawned. It is as follows:
[code]Ships SP MP
1 0 0
2 3 2
3 9 3
4 6 9
5 2 6
6 1 4
7 1 2
8 1 1
[/code]([url]Source, adoxa[/url])
The weights here are again relative to their sum. E.g. in multiplayer the sum is 27, so 4 ships get spawned in 9 out of 27 cases (33.3%). As you can see, 1 ship has weight of 0. This means the game never will pick an NpcRank where the Difficulty for only the first ship would match.
This table is very important to keep in mind. At any Difficulty picked, there always should be NpcRanks defined that cover all those ship counts.
If you notice your job-board being more empty than it should be, it could be that the game tries to pick a ship count which is not provided for the current Difficulty.This table can be adjusted at the offset 11CC58 in Content.dll. First are the weights for singleplayer (starting for 0 ships, 1 ship, 2 ships, etc.) and after that for multiplayer (also starting for 0 ships, 1 ship, …).
If you want to allow NpcRanks with more than 8 ships being spawned, you must create your own weight-table.
[code]content.dll 0F8A4B 58CCFB->00CBFC = use 30-float array at 12CB08 (created manually!) for SP ship weighting vector ~adoxa
content.dll 0F8A54 7CCCFB->80CBFC = use 30-float array at 12CB88 (created manually!) for MP ship weighting vector ~adoxa
[/code]([url]Source, adoxa[/url])[size]Requirements to have Missions offered on a Base[/size]
There are 4 requirements that must be met to have a mission of a specific Difficulty being offered to a player:
[list]
[li]The enemy faction must have an NPC spawn of any unrelated level/difficulty within at least one mission vignette zone in the system.[/li]
[li]The enemy faction must have at least one [i]NpcShip[/i] from [i]npcships.ini[/i] assigned via [i]faction_prop.ini[/i] that must have the [b]same[/b] [i]level[/i] as any Difficulty-matching [i]NpcRank[/i], and have [i]npc_class class_fighter[/i].[/li]
[li]The enemy faction must have at least one [i]NpcShip[/i] from [i]npcships.ini[/i] assigned via [i]faction_prop.ini[/i] that must have the [b]matching[/b] [i]npc_class diff-label + class_fighter[/i] for the matching [i]NpcRank[/i]. And this [i]NpcShip[/i] must have a [i]level[/i] matching ±1.[/li]
[li]There must be at least one [i]NpcRank[/i] that can spawn ships within the picked Difficulty range.[/li]
[/list]
This sounds quite daunting, so let’s explain this on an example:We want to have some faction offer missions against fc_lr_grp in our system. For this we at first need a mission zone:
[code][Zone]
nickname = Zone_destroy_vignette_01
pos = 0, 0, 0
shape = SPHERE
size = 10000
mission_type = unlawful, lawful
sort = 99.500000
vignette_type = open[/code]
Now we must make sure the enemy spawns within this zone, so it will get selected by the game to be associated with this enemy faction.
[code][Zone]
nickname = Zone_destroy_vignette_01_pop
pos = 0, 0, 0
shape = SPHERE
size = 100000
sort = 1
toughness = 19
density = 1
repop_time = 25
max_battle_size = 4
relief_time = 35
encounter = area_scout, 1, 1
faction = fc_lr_grp, 1[/code]
Now we must find out which Difficulty our mission may have. For this we check in our mBase.ini:
[code]mission_type = DestroyMission, 0, 0.112387, 100[/code]
With this value we now go into our npcranktodiff.ini file and look which line might match. Keep in mind the game has certain weights on how many ships it prefers to spawn (see above chapter). One of the possible NpcRanks might be:
[code]NpcRank = 1, 0.00985, 0.03569, 0.07754, 0.13539, 0.20923, 0.29908, 0.40493, 0.52677[/code]
With this we know that we want to spawn level 1 NPCs.
Now we must make sure fc_lr_grp has at least one ship matching this with an npc_class of class_fighter:
[code][NPCShipArch]
nickname = fc_lr_pi_fighter_d1
loadout = fc_lr_pi_fighter_loadout01
level = d1
ship_archetype = pi_fighter
pilot = pilot_pirate_med
state_graph = FIGHTER
npc_class = unlawful, class_fighter, d1[/code]We see that the level=d1, matching our NpcRank. And we see the npc_class contains d1 and class_fighter, so it also can spawn the ship.
Important to know is that one ship with the required level must exist. But it does not need to be the same ship that is being spawned.
The ships that will be spawned are determined by their matching npc_class label. Meaning that if your ship has d1, but npc_class d100, it will not be spawned.
You can and must have at least one (but it can be another) ship with a matching npc_class diff-label for d1, and class_fighter. Important here is that whatever ship has the matching npc_class must match the level +1.
So we could say we have a level d2 ship with npc_class=diff1, class_fighter, it would be able to be spawned. But only if there is another ship defined somewhere that has level=d1. This may look like this and still get spawned in our d1 mission:
[code][NPCShipArch]
nickname = fc_lr_pi_fighter_d1-d2
loadout = fc_lr_pi_fighter_loadout01
level = d2
ship_archetype = pi_fighter
pilot = pilot_pirate_med
state_graph = FIGHTER
npc_class = unlawful, class_fighter, d1, d2[/code][size]Payment by Difficulty ([i]diff2money.ini[/i])[/size]
Defining payments for specific Difficulties is very easy and straight-forward to be done in [i]diff2money.ini[/i].
A line looks as follows:
[code]Diff2Money = <start difficulty=“”>, <payment>[/code]You can add as many or as few of those lines as you like. The payments between each defined Difficulty are linearly interpolated. You should at least provide a line for Difficulty 0 and 100 to allow the game to compute any payments between.[/code]</payment></start></difficulty></difficulty></difficulty></npc> -
This is great, thanks for sharing! Will find this really useful.
-
The weight is an arbitrary value, usually chosen between 0 and including 100, in a way that the sum of all mission_types of a base are 100. This may not be necessary however.
It’s relative to the sum. Seemingly Freelancer devs chose to express it as a percentage, but any value can be used. E.g. three missions each with a weight of 1 means any is equally likely (one in three); three missions with weights of 1, 2 and 3 means the first is unlikely (one in six), the second is less likely (one in three [2/6]) and the third is likely (half [3/6]).
-
Thanks for the clarification, I edited the post.
-
Thanks for clarifying that. Also, hello from a fellow QLDer, haha. Small world (universe?).
3/5