Jump to content

Formulas


NKF

Recommended Posts

First of all, this is meant to be an informative thread rather than for discussion - though discussion is not discouraged if it can clarify any errors. The purpose of this thread is to collect various mathematical equations used in the game.

 

WARNING: The contents of thread may very well spoil the game for you. If you don't want to ruin the game's 'magic', stop reading now! It's far too late for me. Save yourself now while you still can.

 

I'm warning you. It's dull. It's boring. It's unnecessarily wordy. It's got numbers!! Read at your own risk. For those who wish to understand the game better, then read on:

 

Disclaimer: I'm not going to say any of these are 100% accurate. But after gathering some statistics and doing some sums, the formulas I'm listing appear to be fairly accurate. But as always, I may be wrong.

 

Thanks to a thread on the XCommand forum, and a bit of experimenting, the first formula I'm presenting will give you an idea why some aliens are such tough buggers (like lobstermen vs almost everything, or chryssalids vs AP).

 

 

 

 

Damage vs. Armour

Or, how much damage can a weapon do to a unit with so much armour.

 

Formula:

damage to unit = (weapon damage * damage modifier) - armour

 

If the bullet does negative or zero damage, then the bullet is ignored. If the bullet does damage, then there's a chance that the armour plate that it struck will deteriorate by a few points.

 

 

 

That's the basic idea. Let's expand on the variables a bit.

 

armour: Is simply the value of the armour section the bullet hit.

 

damage modifier: 0.5 if the unit resists and 2.0 if the unit is weak against the weapon's damage type. I'm not sure, but there's probably also a 1.0 for units that neither resist nor are weak against the bullet type.

 

weapon damage: Weapon damage will be a random number between 0 and the damage level of the weapon. In reality, all weapons do half their listed damages on average (something to do with the distribution of random numbers leaning more towards the middle of the normal distribution curve).

 

A critical hit is therefore anything above 50% to 100% of the listed damage (or 100% to 200% for double damage, 25% - 50% for units that take half damage).

 

 

 

 

It's interesting to note that X-Com units take double damage from practically every major weapon type. I know for sure that they take double damage from AP, Plasma and laser (I tested: rifle bullets were doing up to ranges of 60 points of damage to X-Com units when they're only supposed to do 30). No wonder your units drop like flies. At least this is true for unarmoured soldiers. I'm not too sure if armour helps reduce this to normal damage.

 

Coming up next (when I feel like it, or if anyone would care to put it in before me):

  • The accuracy formula (everyone probably knows this one by now)
  • The TU penalty for carrying more than you can carry.

The one formula I cannot work out is the one that relates throwing distance with item weight and the strength of the soldier. What's for sure is that the stronger you are, the greater the distance you can throw an object of a certain weight.

 

- NKF

Link to comment
Share on other sites

  • Replies 92
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Speaking of damage vs. armour. I think that it should be posted here, though I don't sure, maybe you all know about it. Anyway.

 

High Explosive types (all of them, not just grenades and HE packs) affect the Under armour always. And, as this part is the most weak, it is more effective early in the game. So, it is the only effective way to battle Lobsterman, if you still haven't Sonic weaponry.

Link to comment
Share on other sites

NKF, are the "critical hits" you mention (50% or better of max damage) the ones that affect armor?

 

Also, a pure random single variable will be evenly distributed (flatline graph) among all its possible values, and the average of all those values will be in the middle. The average is no more likely to occur than any other, it's just what the damage would average out to over several shots. Is this what is happening in X-COM or does the average damage actually occur more often than, say, minimum damage?

 

Pedantic note: You only get bell curves when you start multiplying variables together. 1D6 (one six sided die) has a flat distribution, 2D6 have a triangle distribution peaking on 7, 3D6 distribution starts to look like a bell curve centered on 10.5. (You have a 25% chance of rolling a 10 or 11, according to a little table I did up once. On a D16 you would only have a 12.5% chance.)

Link to comment
Share on other sites

I do not know, which distribution is modelled in X-COM, but I think that it is an even distribution with equal probability of all values, and not normal or Gauss distribution. The reason is, that most pseudo random generators implemented use that sort of distribution, and modelling normal distribution is more difficult.
Link to comment
Share on other sites

Well, I'm just taking the general assumption that with the greater number of random number samples that you take, you'll find that the average will creep closer to about 50% - the middle of the normal curve. (you'd normally expect your weapons to do between 15% - 85% most of the time, with the end bits being rare cases).

 

Of course, in reality, I notice that the pseudo-random numbers used in X-Com tend to be quite wild. It seems that way mostly because the usual sample size for a given combat session is actually quite small (well, you do shoot at a lot, but it's still not a large enough sample to get a better picture of the actual average).

 

 

Re armour damage: No, as long as +ve amount of damage is done to the unit, then armour is damaged. If, after deducting the armour, and weapon damage is a negative number or zero, then no damage is done and armour is intact.

 

I'm not sure how much armour is lost, but I think it's somewhere between 0 - 3 points.

 

You know, they should've modelled the game so that your armour is damaged anyway. It would have meant that really tough units, like sectopods or lobstermen, would have to have their armour breached first before you can kill them with low-tech weapons.

 

- NKF

Link to comment
Share on other sites

And about accuracy. Is it merely

 

chance to hit = soldier accuracy * weapon accuracy

 

or does it include some sort of distance modifier?

 

In the above formula

 

soldier accuracy is just what it is - current soldier accuracy rating

 

weapon accuracy is the accuracy rating of the weapon's particular firing mode (aimed, snap or auto).

 

After that chance is calculated, it is increased by 15%, if your soldier is kneeling, or decreased by 20% if his second hand is occupied while firing two-handed weapon. I think that this chance is decreased, if the target is kneeling, but I'm not sure by which percent (maybe also 15%). Let's call this a final chance to hit.

 

To calculate the chance to hit in a burst mode it is better to find the chance to miss in all three shots. It is

 

chance to miss 3 times=(1 - final chance to hit)*(1 - final chance to hit)*(1 - final chance to hit)

 

And the chance to hit at least one time is: 1 - chance to miss 3 times

Link to comment
Share on other sites

I had a fairly accurate formula listing in one of the older threads, but that's close enough.

 

I think the handedness penalty for using a two handed weapon while the other hand's carrying something else actually reduces your overall accuracy to 78%. 80% of base accuracy is good enough, I suppose.

 

To make it simpler, kneeling multiplies current firing accuracy by 1.15. If you are carrying an item in one hand while trying to fire a two-handed weapon, you multiply your base accuracy by 0.78 - 0.80 (one of these is the actual multiplier).

 

 

The only thing you missed is the health percentage modifier. I'll cover it in the following.

 

How Health Influences Accuracy and Throwing Accuracy

 

Current Accuracy = (current health / max health) * firing accuracy

 

So if you're at 50% of your health, then you'll only be able to use 50% of your firing accuracy. If, miraculously, you have more health than your maximum health bar, then you actually get an accuracy boost.

 

The same goes for throwing accuracy.

 

Note: the accuracy formula for HWPs and alien terror units work slightly differently. They do not take into account the kneeling and item handedness bonuses.

 

- NKF

Link to comment
Share on other sites

Well, it's yes and no.

 

Let's just say that formula is to determine accuracy of the shot before the bullet leaves the gun - this is not affected by distance. You can hit just as well from one side of the map to the other with no trouble.

 

When it leaves the gun, well, because computers fudge some values a bit to optimise processing speeds, it can cause the bullet to drift a bit. Say, after so many tiles, the bullet's deviated at least one or two points away from its original trajectory. With greater distances, this builds up and whoosh, the bullet just misses its mark.

 

But of course, until we see the source code, this is just a lot of guesswork based off of a lot of observation.

 

- NKF

Link to comment
Share on other sites

Maybe the weapons have some deviation. I mean that not only the calculated accuracy determines is the shot successfull or not. Maybe each weapon has some angle of deviation from the ideal trajectory. This could explain, why it is harder to shot distant targets. Or, maybe the angle of deviation includes calculated accuracy. For example:

 

deviation = standard deviation - accuracy * standard deviation

 

where

 

standard deviation is some basic deviation, maybe weapon specific

 

accuracy is the accuracy, calculated above and

 

deviation is the final angle that the trajectory of the shot will deviate.

 

This formula may also include some random component.

 

But I don't know, what to do with the accuracies greater than 100%

Link to comment
Share on other sites

I think there is a distance relationship in the accuracy somewhere, and not because of fudged-up values in the computer.

 

Think about it: A soldier standing right next to the target has a nigh-impossible chance of missing, even if said soldier has an modified accuracy of 20%.

 

And of course, my sniper's aimed shots with a modified accuracy of 85% seem to hit a lot less than that. (But that could just be me, of course.)

 

 

And if the accuracy is >100%? Maybe they become more accurate the farther away something is. It'd be funny to see that person.

 

"So you're the one who can hit a fly on a wall from a field away?"

 

"Yep."

 

"So then why do you always miss the toilet?"

Link to comment
Share on other sites

Heh, a soldier with 0 accuracy (i.e. a chryssalid) can hit a target one tile away too. But in that case, it's more a matter of the bullet having little to no chance of missing its intended target and collides with it no matter what.

 

Whether it's the computer 'optimising' numbers or not, I think it's safe to say that the better the accuracy, the smaller the margin of error. Accuracies over 100% mean an even tighter margin of error (i.e. less bullet drift).

 

The less drift, the more accurate the shot. The greater the distance, the higher chance drift will impact the chance of the bullet colliding with its intended target.

 

I suppose this is one way you can think about it. When you fire a bullet at a certain target, the game does a bit magic and obtains the angle to fire the bullet. Now imagine that a bullet can be fired within a certain wedge in front of you with 0 degrees pointing right at the target and there's also 45 degrees arcs (less, I think) to either side which the bullet can travel along (and consequently miss if the target is far enough). The higher your accuracy score, the closer to 0 degrees your shot will be. The less accuracy, the more it'll angle to either side.

 

When the bullet leaves the gun, it will then travel along the path set for it until it collides with something (a wall, an object, a unit). As long as the bullet touches something (or at least as long as the collision detection function detects something), it damages it. This explains the 0% accurate units hitting something a few tiles away.

 

Or there's always the chance that the game introduces error. Of course, we mustn't forget that the game's a little simplistic in its approach to quite a lot of things, so determining the accuracy of a shot needn't be too complex.

 

 

 

Now if only I could find that formula for encumberance. It's a simple enough formula... this is why you should keep a good filing system for your notes. :D

 

I found some raw data I gathered for throwing distances of items of certain weights and for soldiers of strength levels. Should I post them? I'm a bit stumped on where to start to working out a formula for it. If anyone would care to take a shot at it, I'll post it some time.

 

- NKF

Link to comment
Share on other sites

  • 2 weeks later...

Bumpity bump -

 

Since this is the Formulas (oh the agony!) thread, I'll just dump the bed rest formula in here too.

 

Calculating Hospital Bed Time

 

Bed rest = Amount of HP lost -/+ (a random number up to 50% of Amount of HP lost)

 

or:

 

Bed rest = Half of Lost HP + (A random number between 0 and Lost HP)

 

Finally, ignore any fractions - just round it down to the nearest integer.

 

Example

Jungo Okabe, squad leader, was severely wounded in battle for 59 of his 60 health points. The possible amount of days he will be forced, by the crazy doctors in the med-lab, to stay in bed will be between:

 

50% of 59 is 29 (really it's 29.5).

 

So 59 - 29 = 30 and 59 + 29 = 88

 

30 and 88 days.

 

It may even be as low as 29 days, depending on how the fraction was rounded.

 

---

 

Now, an illegally modified soldier with hitpoints that go through the roof, who was wounded for 100 hit-points:

 

50% of 100 is 50

 

100 - 50 = 50

100 + 50 = 150

 

This sad case will be stuck in bed anywhere between 50 and 150 days.

 

---

 

The Encumberance Penalty

 

Every object that can be picked up has a weight. Every point of weight represents one point of strength that the soldier needs to have in order to carry the item. A grenade has a weight of 3, so to carry 10 grenades without being encumbered, the soldier must have 30 strength.

 

If the amount of weight being carried is under the strength level, there is no penalty.

 

Encumberance penalty = Strength / Total Carried Weight

 

If it's 1 or greater, then treat the encumberance penalty as 1 (values over 1 would actually boost your max TUs above the norm. We cannot have that!).

 

The encumberance penalty is applied at the start of each turn.

 

 

Examples

We have Joe Bloggs with 30 Strength, he's currently the mule for the squad's leading rocket soldier. He's currently carrying four large rockets in his inventory, and nothing else. Each large rocket should be 8 weight units each for a total of 32 weight. He's 2 points over his allowed weight.

 

So, 30 / 32 = 0.93 

 

Therefore: Joe Blogg's TUs will only be able to use 93% of his total TUs every turn thereafter. So if he has 64 maximum TUs, he starts with 60 TUs.

 

One more example: Richard Roe, the scout/grenadier, is a weakling with only 25 strength. He carries a pistol (5), two clips (3 x 2) and two grenades (3 x 2). That's 17 weight in total.

 

So 25 / 17 = 1.47  (or 147% - but we only use 100%)

 

Since it's over 100%, Richard Roe gets to use 100% of his maximum TUs at the start of the next turn.

 

 

Note: Object weights are hidden. Their weights are listed in the Official Strategy Guide, by Dave Ellis, if I'm not mistaken. I can probably put together a table sometime and list them here.

 

Note, clips and partial clips are always the same weight (3). When loaded in a gun, they still count towards your total weight, but when determining throwing distances for the gun itself, the clip is ignored.

 

- NKF

Link to comment
Share on other sites

Just a quick tip... intentionally overencumberring your soldiers before hitting the enemy is a great way to maximise your strength pts increase with each kill.

 

I typically intentionally load a bunch of heavy stuff on my soldiers and find that in one or two battles a guy that started low to mid-20s strength can get up to high-30s to low-40s... of course he would actually have to get those hits in and survive... which doesn't often happen if you are so low in TUs that you can't move to the front of the action.

Link to comment
Share on other sites

First of all - Actually, being encumbered does not increase how much additional strength is earned at the end of the mission. Encumberance is not recorded by the game at all. The only way to raise strength is by successful psi attacks and successfully 'hitting' enemy units. The more times you perform these actions, the better the chance of a strength increase. The actual increase is random, but the maximum size of the bonus may be influenced by the total number of the actions.

 

--

 

Stamina recovery is a fixed value for every unit, and it's not affected by encumberance - it's set at the start of the battle. The tank, for example, has it set so that it will always regain slightly more stamina than it will ever lose in any given turn - thus the illusion that they never get tired. Your soldiers vary in levels of stamina recovery levels. Say, a soldier has a stamina recovery of 20. That soldier will always regain 20 points of stamina every turn.

 

I'll probably give this one a look. There might be some formula that determines how the stamina regain value is calculated.

 

EDIT: I've checked - and it's still the same. Encumberance doesn't reduce energy recovery.

 

I haven't got any clues as to how the recovery rate is calculated yet, but I have noticed a few other things of note.

 

Addendum: Calculating Firing Accuracy

 

In addition to the usual accuracy formula, there is also a penalty for critical wounds.

 

So for the penalty size based on the number of wounds:

 

0 wounds = 0%

1 wounds = -10%

2 wounds = -20%

3 wounds = -30%

4 wounds = -40%

5 wounds = -50%

6 wounds = -60%

7 wounds = -70%

8 wounds = -80%

9 wounds = -90%

10+ wounds = -90% (the penalty doesn't go any farther than 90%)

 

Example:

Jane Doe has 4 critical wounds. She has 64 accuracy, 50% of her current health, is kneeling and is attempting a snapshot with a laser rifle (50% accuracy). She is carrying the rifle with both hands.

 

0.64 (accuracy) * 0.5 (health) * 1.15 (kneeling) * 0.5 (l-rifle snap acc.) * 1 (using two handed weapon properly) * 0.4 (the wound penalty) = 0.07

 

Jane Doe's hit probability for this shot is only 7%. Aborting the shot and seeking a medic would be the best course of action.

 

The above does not apply to throwing accuracy. Only firing accuracy.

 

- NKF

Link to comment
Share on other sites

Actually I'd disagree on the encumberrance not matterring as to str gained. I had a saved game from a few minutes prior to a battle that I had tested it with. Guy with 22 str goes into combat in two different ways... packed with 10 grenades or going with only a pistol and 2 pistol clips. In both cases I used him to fight exactly 2 aliens. With the overencumberred version he gained 6 str, with the pistol version he gained 3.

 

Now, even taking into account the randomness of the exp gain counters doesn't allow for that big of a gap. If that's not caused by the encumberrance I'd sure like to know what it comes from... and considerring that consistently my soldiers that are overencumberred get str gains faster than any other category, whereas in versions of the game where I leave them underequpped and they don't... *shrugs* I usually agree with you, NKF, but on this one I am not going to give in on.

Link to comment
Share on other sites

You're right. Encumberance does have an effect. But not necessarily on strength gain.

 

I made two identical twins and sent them into combat. They both had 27 strength to start with. One was heavily encumbered.

 

I ran fifteen tests (at the time of typing this). Of almost half of these tests, the soldiers had 45 'hits' each. For the rest of the tests, the soldiers had 100 'hits' each. For all the tests, the light soldier had between 0 - 6 point strength gains (27 - 33). The one that was encumbered also had results between 0 - 6 point strength gains (27 - 33).

 

There's apparently a limit to the size of the strength gains, as the tests with 45 'hits' made no different to the ones with 100 'hits'. I think I should try this again with a more reasonable number of hits. 45 - 100 hits is a tad too much for a regular mission. :D

 

Encumberance did have one major effect. Even though the two units were exact duplicates, the encumbered clone became a sergeant when the other one just became a squaddie (I even switched them at one point, and the heavier one got the extra bars). The game must consider encumberance at the end of the mission in addition to weighting all the experience a soldier gains in order to determine what ranks to hand out. I mean, you will have to agree that the encumbered soldier being able to pull off identical hits as the light soldier is quite a major feat in and of itself! I guess it's also a great equaliser in the event of two soldiers having equal experience.

 

 

 

 

Major edit:

 

Alright, so I wasted most of the afternoon on the game figuring out just how you earn experience. I'll list my findings.

 

First of all, I'll list what actions help raise what stats:

 

Melee attacks

  • TU
  • Stamina
  • Health
  • Strength

Successful Psi attacks

  • TU
  • Stamina
  • Health
  • Psi Skill

Number of Thrown items

  • Throwing skill

Successful hits (bullets, explosives, etc)

  • TU
  • Stamina
  • Health
  • Strength
  • Firing Accuracy

And finally, this one came as a bit of a shock to me.

 

Number of times reaction fire was used

  • TU
  • Stamina
  • Health
  • Strength
  • Reactions

It seems that with enough reaction fire attempts, even if you don't hit anything, you can actually raise your stats just as well as hitting an enemy target can.

 

I don't know if the chances of raising the listed stats are cumulative, or whether only the highest one counts.

 

Hah, just when I think I've figured out the game, it springs more surprises on me.

 

Anyway, most of the stat gains vary in size depending on how much current experience you have. For example, if you have 0 stamina (hypothetically speaking, of course), you get 0 - 8 possible improvement points. With 60 stamina, you can get 0 - 4, With 100, you get 0 - 0.

 

It's easy to get stat increases at first, but as your stats get higher, you need to do more in order to get the maximum possible stat increase.

 

For firing accuracy, however, it always seems to be 0 - 6, no matter what level you are (of course, you still have to hit more targets if you want to get up to 6 as you increase in accuracy levels). The maximum possible points for firing accuracy is 120. But if you can get it to 119 and score a 6 point improvement, you can get 125 firing accuracy. (I had the idea it was 130, but 120's good enough, I guess)

 

For health, At 0 health, you get 0 - 8 health bonus points. Around 30 or so, you have 0 - 4 health bonus points. By 60 (the maximum health), bonus health is 0.

 

Strength seems to go from Str 0 (0 - 9/10), 20 ( 0 - 7), 35 ( 0 - 5), 60 ( 0 - 2) and finally 70 (0).

 

For, argh, .. I think I'll just list the stat caps, since it seems that bonus stat points are influenced by percentages. X-Com UFO loves percentages, by the look of it. :D

 

TU: 80

Stamina: 100

Health: 60

I'm not counting bravery (it moves in 10 point increments)

Reactions: 80 (I'm not sure about this one, I'll have to doublecheck my notes later)

Firing accuracy: 120

Throwing Accuracy: 120

Strength: 70

Psi Strength: Fixed (the legal maximum for this is 100)

Psi Skill: 100

 

- NKF

Link to comment
Share on other sites

Sometimes you can increase the accuracy even more. For example, in one mission one of my soldiers killed 9 aliens and received 8 increase in firing accuracy from 72 to 80; another one killed 7 aliens and received 7 pts increase (from 84 to 91). So the maximum may be 8 or even more.

 

Oh, that was in TFTD, but I don't think this really matters.

Link to comment
Share on other sites

NKF, You've mentioned earlier, that you have raw data for throwing distances of items. I've found in the manual for Laser Squad, that throwing distance is equal to the strength of the soldier divided by the weight of the object. I know, that LS is a different game, but made by the same people and it influenced X-Com greatly. So, does this formula fit in your data?
Link to comment
Share on other sites

On that same note, you can get most of the stats 1 point beyond the maximum. I often see health go up to 61. And as mentioned earlier, for accuracy, if you can roll some bonus points greater than the 120 cap but with current accuracy under that, you can get something like 121 - 125 accuracy. That really does wonders for the standard pistol... :D

 

---

 

Cyrus: I'll have look into that. There are all sorts of factors that need to be taken into account. The game just doesn't have enough vertical space to allow really high throwing arcs (when the game complains 'unable to throw here' instead of 'out of range'). This is very noticeable when there's a low ceiling above you (such as inside bases).

 

Speaking of which, hey JFG: Did you get the distance data I sent? I can't seem to find anything in my PM sent folder... Nevermind, I'll just gather some fresh new data later.

 

- NKF

Link to comment
Share on other sites

Right about now, tables would be a blessing. :D

 

Anyway, here's the raw data, dig in:

 

I'll list the numbers like this 9 + 1F + 3. The first number is the first field where the subject is standing (I'm not counting the tile the soldier is on), the next number will represent the number of fields the item was able to pass over (1F = 10 tiles), and the last number will be the number of tiles was able to enter the last field. (I know, it's a bit crazy - I'll put the total at the end of the line in brackets)

 

I'll list two of these, the first one representing the number where the game stops saying 'out of range', and the other representing when the game allowed the soldier to throw the object.

 

There are four test subjects. Each with strength ratings of 10, 20, 35 and 70. (Note the 10 strength soldier is a special case - done specifically for this test).

 

At the moment, there are three test objects to be thrown.

 

Object A = grenade/weapon clip/plasma pistol weighing in at 3 points.

Object B = A pistol, at 5 points;

Object C = A rifle/heavy plasma, at 8 points.

 

Soldier 1 (10 str)

  • A = 8, 8 (8, 8)
  • B = 6, 6 (6, 6)
  • C = 4, 4 (4, 4)

Soldier 2 (20 str)

  • A = 9 + 7, 9 +7 (16, 16)
  • B = 9 + 1, 9 (10, 9)
  • C = 7, 7 (7, 7)

Soldier 3 (35 str)

  • A = 9 + 1F + 8, 9 + 1F, + 5 (27, 24)
  • B = 9 + 7, 9 + 7 (16, 16)
  • C = 9 + 2, 9 + 2 (11, 11)

Soldier 4 (70 str)

  • A = 9 + >4F, 9 + 2F + 4 ( >49, 33) (I need a larger test field... :hmmm: )
  • B = 9 + 2F + 6, 9 + 1F + 8 (35, 27)
  • C = 9 + 1F + 3, 9 + 1F + 2 (22, 21)

As you can see, Solder 4 really has quite a good hurling arm! :ninja:

 

Note, the throwing accuracy stat merely helps your soldier get the object into the right spot - it doesn't affect how far the object can be thrown.

 

- NKF

 

edit:, I just realised that I spent the whole afternoon gathering inconsequential data on my old PC when I should've been playing as much Icewind Dale as I can before my current harddrive fails completely... My priorities are really messed up. :D

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...