Hello everyone! This is my first comment here.
Welcome!
Thank you for the excellent mod Melindil!
I'm currently working on a complete unarmed/melee combat overhaul and made a few simple extensions to FTSE. Would it be possible to include them in some future version of FTSE or functions similar in purpose? The mod is still work in progress, but other modders might also find the new methods useful.
Of course! I will gladly accept enhancements and contributions to the mod. I'll include these in the 0.50 version currently in progress. I'll also try to keep the Git repo up-to-date, in case some of the in-progress work might be helpful for you.
The first batch is about the equipped slot1, slot2 weapons and which one is active, also the punch and kick entity belonging to the actor. The address offsets: weapon slot1 - 0x1010, weapon slot2 - 0x1014, unarmed punch: 0xfa0, unarmed kick: 0xfa8 (returns weapon's
Perfect timing on this one - I have been planning to come back and add more to the Actor entity type after getting the other entity types done. It's still very incomplete, even though it was the first type I worked on decoding. I'll eventually get a full struct definition for Actor like the other entity types have (this will replace most of the "offsets" map), but the code you have for selecting the proper active weapon will still work well with only minor changes.
The second list of functions help with converting the ap field number to a more comprehensive action point value.
This one actually looks like a bug on my part. The game appears to hold the AP value as a float rather than an int type. Thinking about it, this probably makes sense, as fractional AP could be useful for both CTB recharge timing, as well as movement allowance for the turn-based modes. I'll change the definition and return type to float, and see if this gives better results.
The third ones are just some bounding box getters.
I'll add these in. While I'm at it, I'll also add something in the Entity class to get distance between two entities, both as center-to-center distance and boundingbox-to-boundingbox (different parts of the BOS code use each calculation, so both may be useful).
I'm not much of Lua coder (only started four days ago), so this is probably a rookie question: is there a reason why you do not use local variables in your Lua code?
I'm not all that experienced with Lua either
. I mainly like it for how easy it is to integrate into C/C++. In this case, it looks like I'm getting confused with Python, where function-assigned variables are by default local. I'll fix the base Lua code and the Wiki examples.
The Critical-hit-chance-and-effects states that the critical roll is between 1 and 100 (inclusive). On the other hand the OnCriticalEffect1-2 hook's roll parameter can go above 100. Does this mean it's reduced after the hook has returned?
Correct. I pass the full value of the effect roll, in case a mod wants to reduce the roll prior to applying the cap (reducing after the cap makes a 100 roll impossible even if other bonuses could allow for it), or if a mod wants to add further effects for rolls greater than 100 (e.g. by returning a table with flags set, rather than a roll value). If the script doesn't set explicit flags, the BOS code will cap the value to 1-100 after the script runs. Chance to hit and chance to crit work similarly, though chance-to-hit splits the value into pre-cap and post-cap, as BOS code actually tracks both values; e.g. to apply the location-specific adjustments for the aimed shot window.
The following formula "If attacker is using a ranged weapon, target is using melee/unarmed, and the attacker is within distance of 3: subtract 1 - (distance / 3.0) * target's melee/unarmed skill * 0.33" can be found in Chance-to-hit-calculations. Is this correct (if it is please explain)?
This one was an interesting find. The game actually grants the equivalent of an AC bonus if a melee/unarmed character gets close enough to an attacker using a ranged weapon (presumably, their experience in melee/unarmed helps them dodge or deflect the weapon?). The maximum AC bonus is equal to the character's corresponding active weapon skill (Melee Weapons or Unarmed depending on active weapon or attack type - note that it is required to actually have a melee/unarmed weapon or attack selected) multiplied by 0.33. This maximum bonus applies if the melee character is immediately adjacent to the attacker's bounding box. If the melee character is further away, the bonus reduces linearly with increasing distance, until it disappears entirely at a distance of 3 hexes. This is a big factor in the "Peoria turrets can't hit close-range attackers" observation - a 100% melee/unarmed skill (achievable by that mission) drops the turret's hit chance by 33%, which, along with armor AC, is enough to make it almost always miss. I've actually been curious to see if a high unarmed build (+ H2H evade + armor + Dodger + etc.) can give enough AC to let a character survive at close range to burst and other strong weapons. Even without that, there's still a small benefit even for normally ranged units to switch to a secondary melee/unarmed weapon near end-of-turn if an enemy is close.