aliens

Author Topic: Understanding Game Mechanics  (Read 5106 times)

Offline Coincident

  • Captain
  • ***
  • Posts: 54
    • View Profile
Understanding Game Mechanics
« on: October 30, 2015, 05:40:26 pm »
Hello everyone. This is my first post here, so I'd like to begin by congratulating the devs & community on the splendid job you did with OpenXcom :)

I decided to start this thread after searching around - I didn't find any similar discussion.
The idea is to share/discuss information about the game mechanics and trying to understand the more complex calculations.
The goal is to help people get the right information, so modders can (hopefully) make better game-design decisions.

I will start with two questions of my own:



1 - Base defense damage mechanics:

My base is attacked 2 times by alien Battleships:
The first time, 3 Plasma Defenses hit the UFO, and it is destroyed.
The second time, 4 Plasma Defenses hit the UFO, and it is destroyed.

Is the damage from base defenses subject to a random interval - like the battlescape damage that is randomly chosen from 0% to 200%?
If so, what is the random interval?
From what I've searched, https://ufopaedia.org mentions nothing of the sort: https://www.ufopaedia.org/index.php?title=Plasma_Defences



2 - Stun rod damage mechanics:

The stun rod damage type is Stun, but it is also a melee weapon.
Does melee resistance affect the stun rod damage?
If so - in what order do multiple resistances apply?

To simplify, imagine the stun rod deals 100 Stun Damage.
Now imagine that it hits an alien with 20% melee resist, and -20% stun resist.
Which scenario is correct?
100 -> -20% stun resist -> 120 -> 20% melee resist -> 96 avg damage
OR
100 -> 20% melee resist -> 80 -> -20% stun resist -> 96 avg damage (same as above)
OR
100 -> 20%-20% melee+stun resist  -> 100 avg damage
OR
100-> -20% stun resist -> 120 avg damage

https://ufopaedia.org also mentions nothing about the relationship between the stun rod and melee resistance (maybe that means there is no relationship...?): https://www.ufopaedia.org/index.php?title=Stun_Rod
« Last Edit: October 30, 2015, 09:05:48 pm by Coincident »

Offline Hobbes

  • Commander
  • *****
  • Posts: 2101
  • Infiltration subroutine in progress
    • View Profile
Re: Understanding Game Mechanics
« Reply #1 on: October 30, 2015, 07:45:51 pm »
1 - Base defense damage mechanics:

My base is attacked 2 times by alien Battleships:
The first time, 3 Plasma Defenses hit the UFO, and it is destroyed.
The second time, 4 Plasma Defenses hit the UFO, and it is destroyed.

Is the damage from base defenses subject to a random interval - like the battlescape damage that is randomly chosen from 0% to 200%?
If so, what is the random interval?
From what I've searched, ufopeadia.org mentions nothing of the sort: https://www.ufopaedia.org/index.php?title=Plasma_Defences

This is the OXC code that calculates damage on Base Defense:

Code: [Select]
_ufo->getdamage() + (dmg / 2 + RNG::generate(0, dmg)
If I'm reading this correctly, then it would be 900 + (900/(2 + number between 0 and 900). This means that the damage range of Base Defenses can vary between roughly 100-150%.

Quote
2 - Stun rod damage mechanics:

The stun rod damage type is Stun, but it is also a melee weapon.
Does melee resistance affect the stun rod damage?
If so - in what order do multiple resistances apply?

To simplify, imagine the stun rod deals 100 Stun Damage.
Now imagine that it hits an alien with 20% melee resist, and -20% stun resist.
Which scenario is correct?
100 -> -20% stun resist -> 120 -> 20% melee resist -> 96 avg damage
OR
100 -> 20% melee resist -> 80 -> -20% stun resist -> 96 avg damage (same as above)
OR
100 -> 20%-20% melee+stun resist  -> 100 avg damage
OR
100-> -20% stun resist -> 120 avg damage

ufopeadia.org also mentions nothing about the relationship between the stun rod and melee resistance (maybe that means there is no relationship...?): https://www.ufopaedia.org/index.php?title=Stun_Rod

What counts is the DamageType, which on this case it is Stun. The melee definition of the Stun Rod only applies to its BattleType, which defines the behavior of the item on Battlescape.

Offline Coincident

  • Captain
  • ***
  • Posts: 54
    • View Profile
Re: Understanding Game Mechanics
« Reply #2 on: October 30, 2015, 08:10:29 pm »
Thanks Hobbes, that was exactly what I was looking for. :)

However, from the formula you posted, it looks like the defense damage multiplier is from 50% to 150% (there are no parenthesis after the division)
It looks like: ufo's previous damage + 450 + random(0, 900)


Offline Hobbes

  • Commander
  • *****
  • Posts: 2101
  • Infiltration subroutine in progress
    • View Profile
Re: Understanding Game Mechanics
« Reply #3 on: October 30, 2015, 09:02:56 pm »
Thanks Hobbes, that was exactly what I was looking for. :)

However, from the formula you posted, it looks like the defense damage multiplier is from 50% to 150% (there are no parenthesis after the division)
It looks like: ufo's previous damage + 450 + random(0, 900)

Ah, you're right! That makes more sense (I'm not a coder, so these formulas can be like magic to me :))

Anyways, if you want to check the formula yourself, here's the link:
https://github.com/SupSuper/OpenXcom/blob/67500926e461a6aac7a61d64fdaebebbf9a766f0/src/Geoscape/BaseDefenseState.cpp
« Last Edit: October 30, 2015, 09:07:49 pm by Hobbes »

Offline Coincident

  • Captain
  • ***
  • Posts: 54
    • View Profile
Re: Understanding Game Mechanics
« Reply #4 on: November 07, 2015, 10:30:07 pm »
In what .cpp file are the Battlescape final screen scores being calculated?
I've used GitHub file finder to search for any file named "*Battlescape*", and I've browsed throught BattlescapeState.cpp, BattlescapeGame.cpp, etc. but I can't seem to find anything related to scoring.

Thing is... I have so many questions related to battlescape scoring, that I'd rather just take a look at the code myself.



My goal is to mod a few things related to scoring, but I'm not sure if these are even possible, namely:

 - Reduce Alien Alloys recovery points to less than 1 (not sure how to do this though, does the recoveryPoints ruleset var accept decimals?)
 - Change Elerium 115 recovery points (the ruleset item has no recoveryPoints set... how does it currently work?)
 - Change  points lost for X-COM soldier MIA (can't find any rule for this)
 - See / Change points lost for X-COM soldiers killed, depending on rank (can't find any rule for this)
 - Change the points for successfully destroying an Alien Base (can't find any rule for this)
 - Lose points for leaving abandoning a terror site with live aliens (probably not supported)
 - Lose points for losing an X-COM base after an alien retaliation (probably not supported)

Offline Arthanor

  • Commander
  • *****
  • Posts: 2488
  • XCom Armoury Quartermaster
    • View Profile
Re: Understanding Game Mechanics
« Reply #5 on: November 08, 2015, 12:21:52 am »
I don't think you can do fractions of points, but you can tweak the values of most (probably all) items through the ruleset. MIA soldier points are maybe linked to KIA? But I'm pretty sure there is no way to link rank with points or the other things.

You want to check DebriefingState.cpp for the code, in the Battlescape folder.

Offline Coincident

  • Captain
  • ***
  • Posts: 54
    • View Profile
Re: Understanding Game Mechanics
« Reply #6 on: November 08, 2015, 12:49:08 pm »
You want to check DebriefingState.cpp for the code, in the Battlescape folder.
Thanks Arthanor. That was exactly what I was looking for.

But I'm pretty sure there is no way to link rank with points or the other things.
According to ufopaedia, the original X-COM has the player loose more points for getting higher-ranked soldiers killed. This must have been implemented in OpenXCom for sure. Maybe it's not in the debriefing calculation stuff, but it's associated to the actual unit.


Anyway, I'm going to look around and try to answer my owns questions here, in case someone sees this thread in the future:


- Reduce Alien Alloys recovery points to less than 1 (not sure how to do this though, does the recoveryPoints ruleset var accept decimals?)
The recoveryPoints ruleset is an int - no decimals are accepted.
https://github.com/SupSuper/OpenXcom/blob/master/src/Mod/RuleItem.cpp#L600

- Change Elerium 115 recovery points (the ruleset item has no recoveryPoints set... how does it currently work?)
Recovering an elerium item (=50 units) is a special case, and always gives 5 points. This is hard-coded and unfortunately cannot be changed with rulesets.
https://github.com/SupSuper/OpenXcom/blob/master/src/Battlescape/DebriefingState.cpp#L1119

- See / Change points lost for X-COM soldiers killed, depending on rank (can't find any rule for this)
The value of an X-COM soldier is hard-coded to 20 + Num of missions the soldier has been to + rankBonus.
Where rankBonus = 1 for sergeant, 3 for captain, 6 for colonel, 10 for commander.
This cannot be changed with rulesets.
https://github.com/SupSuper/OpenXcom/blob/master/src/Savegame/BattleUnit.cpp#L116

- Change  points lost for X-COM soldier MIA (can't find any rule for this)
Soldiers MIA make you lose the same amount of points as if they were killed, this cannot be changed with rulesets.
https://github.com/SupSuper/OpenXcom/blob/master/src/Battlescape/DebriefingState.cpp#L750

- Change the points for successfully destroying an Alien Base (can't find any rule for this)
Points for destroying an Alien Base can be easily changed in the deployment ruleset (objectiveComplete)
https://github.com/SupSuper/OpenXcom/blob/master/src/Battlescape/DebriefingState.cpp#L396

This also works for custom mission deployments.
https://github.com/SupSuper/OpenXcom/blob/master/src/Battlescape/DebriefingState.cpp#L847

- Lose points for leaving abandoning a terror site with live aliens (probably not supported)
 - Lose points for losing an X-COM base after an alien retaliation (probably not supported)
Points for losing a certain mission can be easily changed in the deployment ruleset (objectiveFailed)
However, this only works for terror / custom mission. Losing an X-COM base does not go through that code.
https://github.com/SupSuper/OpenXcom/blob/master/src/Battlescape/DebriefingState.cpp#L904


Extra findings:

Score lost for Civilians killed by X-COM is calculated by adding 2 thirds to the value of the civilian unit, this cannot be changed with rulesets.
https://github.com/SupSuper/OpenXcom/blob/master/src/Battlescape/DebriefingState.cpp#L692

Offline Arthanor

  • Commander
  • *****
  • Posts: 2488
  • XCom Armoury Quartermaster
    • View Profile
Re: Understanding Game Mechanics
« Reply #7 on: November 08, 2015, 03:20:46 pm »
Cool stuff! I guess you can change more things than I expected. I really have to get into the mission stuff...