User Tools

Site Tools


user:loggy:misc

Loggy's Misc reverse engineering notes

(gray items have already been incorporated into proper wiki pages)

  • Hell power is 20% + 2% per mark to spawn a horror. It spawns in a random square in a 5x5 grid around you
  • CATEGORY Check to Win Things:
    • web is str + DRN vs 22, win means you break free
    • Affliction 2^50 (netted?) is str + DRN vs 20
    • False fetters is MR + DRN vs 20, win to escape
    • Slime is 22
    • size/strength negate: 5+6 always immune, 4 is 66% to ignore, 3 is 33% to ignore, otherwise roll strength vs 14 + d20 (no DRN or openended). If strength wins (not ties) it is negated
    • Having the blink unit effect means you always successfully escape entangle, web, net, earth grip (but not bonds of fire or false fetters)
  • CATEGORY Decompiler Nerd Things:
    • Effect modifier 4611686018427387904 is 1/3 strength added
    • Spec 0x100000000000000 or 72057594037927936 readds magic damage
    • 0x4000000000000000 or 4611686018427387904 adds 1/3 strength
    • 0x800000000 or 34359738368 is added to all effects with aoe > 0
    • 0x40000000 or 1073741824 is simply added to all spells
    • 144115188075855872 makes projectiles stick to the ground rather than fly normally
    • 0x400000000 or 17179869184 is weapon #range050
    • 0x8000000000000 or 2251799813685248 may be for flaming projectiles
    • 141837069189120 is not construct immune, it actually prevents the user hitting themselves (but doesn't work on x% field AoEs)
  • CATEGORY Behavior Afflictions:
    • Rage: 50% chance to attack a random adjacent square
    • Dementia: 25% to make units do nothing for 3650 ticks
    • Confusion: 30% to stand and do nothing, 20% to attack a random adjacent square
    • Stupid: 10% chance to do nothing (and wait for half a round), 10% to attack something adjacent at random.
  • Unknown affliction 2^38 is cleared every combat round and doesn't do anything when that happens
  • affliction 2^40 makes you take 1 AN internal damage. Being undead makes it go up to 2. If you are taking 1, it has a 20% chance to end
  • Commanders have a 50% chance to smart retreat. If they don't, they have make a morale check vs 10 to smart retreat. If they fail that and have appropriate survivals there's a 50% chance to still be smart
    • This is likely where "pretenders never die on retreat" comes from because the safe retreat odds for any commander with 30 morale is going to be 99.92%!
  • Items on death either go into the anyone-pool or the owner's pool. The chance of going into the anyone pool is 90% for cursed items, and then ((constrlevel/2)+1) * 15% after that. The victor then rolls for each nofind item in their own and anyone pools, picking a commander at random to try to pick up the stuff. This fails only if the commander in question has no free slots for the item it was allocated.
  • BoT does something with scales and then has a (41 + death*4)% to add 1d4 nonexploding years to each unit.
  • Lanka's blood hunting bonus is +1 per turmoil
  • Blood popkill is 10*floor((slaves + 4)/5)
  • Manifestation checks at most 8 random commanders. It has a 50% chance to skip any that are not horror marked
  • There is a 20% chance that each side in an assassination gets to pull 1d4+ blood slaves into the fight
  • Looming Hell has a 5% chance per candle in the affected unit's province to not use one of its 5 "charges".
  • Picus/Procas axes give +2 MR, +5 strength and +10 fear if used together
    • Picus's Axe of Rulership and Procas's Axe of Rulership
  • Despite having the gender changing effect set at -1, the Bear Claw Talisman does not function. Cat Charm however, does.
  • The chance to spawn a guardian spirit in percent is (10 * holy level) + innate guardian spirit modifier + (1 * number of candles, negative if hostile).
  • There is a 15% chance per cold scale for a battle to take place in a snowstorm. If temp is between neutral and heat 2 inclusive, there is a (5 + growth*5)% chance for the battle to take place in a regular rain storm. UW, in the Void and in caves, there is always no natural weather.
  • Fatigue from flying is (flight distance * enc)/20, doubled in rain or snow (but only if you don't have storm immunity or storm power). Curse of stones is a flat 2d6 nonexploding every time you fly. Flight distance is simply dx + dy, capped to a maximum of 20 for this calculation.
  • Blood Vortex: remembers where you cast it. Makes 3 remote checks, the first of which will always be an adjacent province to where it was cast. Further checks are provinces picked at random, that have nonzero population and are not UW. (Population here refers to /10 from the displayed game values)
    • Remote checks contribute (pop/20) + d50+, capped to the province's pop. This is halved if order 2 or 3, and doubled if turmoil 2 or 3. Affected provinces gain 1d10 nonexploding unrest and have their population reduced appropriately. Final population contribution to the vortex is half of what is drained.
    • Local province: pop/10 + d100+, capped to pop. Population is drained, but scales have no impact.
    • Final slave total = (local contribution + remote contribution + d10 nonexploding - 1)/9
  • Fires from Afar hit rate is 20% or (number of units in province*25)/number of effects, whichever is higher. The same unit cannot be hit more than once.
  • Lingering effects technically do (x + 2)/3 rounded down damage
  • Spy unrest is d20 exploding
  • Pretender awakening: Every turn these things are rolled again, and if less than the current turn number, you awaken. Dice here are exploding.
    • Dormant: 9 + d4
    • Imprisoned: 27 + d20
    • Dormant disciple: 4 + d4
    • Imprisoned disciple: 13 + d20
  • AoE spread: get anything adjacent (including diagonal) to the last square hit. If you already hit the square, get another one adjacent to the square you just checked and try again. Upon finding an empty square, hit that, and then start again at the origin. Repeat until the desired number of squares are hit.
  • Gifts from Heaven deviates at most 1 square in any direction, including diagonals. (This is due to spell attrib 579 and is done once for each point of the attrib)
  • Blood slave usage range looks to be 8 squares along either axis so the total usage area is square and not circular
  • Transformation's yellow text is nearly right. The checks really are 20% + misfortune scale to fail. Succeeding the first gives a good result. Upon failing the first check there is then a second identical check, succeeding this gives you a bad result (and feebleminds you if the new form is not mindless). Failing both checks kills you.
  • A bad result that is mindless lowers your paths to F4A4W4E4S3D4N3B4 if any of them were higher than that
  • Even when you fail both and die, you still get transformed into something, which feebleminds you or applies the path limiting above anyway.
  • The chance of getting a pathboost in percent is (can't push you above X10) is ((10 - drain scale) * attuned percentage * 10)/100. Magic scales count for negative drain. Attuned values are a chassis attribute, for instance cave drakes have 50% earth attuned.
  • Spell interruption chance in percent is interruptdamage + 25 + (damage*100)/maxhp. Interruptdamage is from effect 129 only. Combat casters and mindless/slave vessels are halved, both conditions will half twice, rounding down after each.
  • Effect order notes:
    • Mirror image is bypassed by the following spec values: 131072 (no effect on mindless), 1073741824, 34359738368, 18014398509481984 (likely "true" damage, inflicted by BV and blood bond), 36028797018963968 (internal damage), or the damage being 900+
    • Prot force is bypassed by only true, internal and AN, or if the damage is 900+
    • Mistform and mossbody are bypassed if the damage is 900+, or is true/internal
    • Ethereal seems to have no such checks, but all the special damage things it might want to ignore are magical anyway
    • Twist fate comes next, applying to damage less than 900, without the true damage modifier. Twist fate also won't apply to 1 damage, so long as you have more than 2hp.
    • If the time is appropriate, fools luck will negate damage that is less than 900 and not true damage, but only if the damage is greater than 1 or your hitpoints are less than 3
    • If the time is appropriate, fools luck will double damage that is less than 900 and not true damage, but only if the damage is greater than 1
    • Luck negates damage if the amount is less than 900, the damage is not true damage, the damage would be fatal, cursed luck is not active, the unit is not inanimate or undead, and a 75% random chance is passed.
    • Damage reversal activates if the damage is less than 9000, the damage is not true damage, the attacker and victim are different creatures, there is an attacker for this damage that is alive, and the attacker's current province is positive (IE not in another plane)
    • Blood vengeance activates if the damage is less than 9000, the damage is not true damage, the attacker and victim are different creatures, there is an attacker for this damage that is alive, and the attacker's current province is positive
    • Blood bond shares damage if the damage is not true damage, one of the unit's coordinates on the battlefield is greater than -1, there is an attacker for this damage that is alive, and the attacker's current province is positive
    • Holy avenger adds one strike on any nonzero damage that is not true damage
    • Limb damage cap (and presumably severing) is applied to non-true damage now
    • Spellcasting interrupting is checked
    • If damage is nonzero at this point and the damage is not true damage, mirror image is removed
    • If damage is nonzero and not poison damage, remove unknown (affliction 1024)
    • Unseen pops if the unit survives and if affliction 2048 not suffered: (add mirror image and affliction 2048)
    • If damage less than 9000, roll for afflictions
    • Returning on damage triggers if the unit survives. Note that being knocked into a secondshape doesn't count here, because you're technically dead until the shapechange code below "heals" you. The same thing likely happens with ppyre and simiilar effects.
    • Something I don't understand happens, it has to do with putting units on a list to make morale checks but may be more involved
    • Eligible berserkers roll 3d6 exploding. If this is less than their max morale, they get angry
    • Shrink/growshapes occur
    • Various secondshape things occur
    • some things I don't understand
    • If the target does not have positive hp at this point and spec 256, add the soul slayed affliction
    • Phoenix pyre, if the damage was less than 9000, explode. If your fatigue is less than 100 and you weren't soul slayed, reappear.
    • Inner fire, if the damage was less than 9000 and fatal.
    • Death explosion bless, if the damage was less than 9000 and fatal.
    • Deathfire, if damage was less than 9000 and fatal.
    • Disease explosion, if damage less than 9000 and fatal.
    • Deathwail (accepts pen bonus), if damage less than 9000 and fatal
    • Extra life, if damage less than 9000, fatal, and not soul slayed
    • Spawn a horror if dying with a horror seed value of greater than 1 and damage less than 9000
    • Reforming, if damage less than 9000, fatigue less than 100, and not soul slayed: adds 1d6 exploding + 6 fatigue when it happens
    • Swarm body, if damage less than 9000 and not soul slayed: a bit involved
      • Gain (openended d6) + 6 fatigue
      • Turn into your soul vessel type: bug on land, shrimp if underwater
      • Heal to the soul vessel form's max health
      • Lose all items if you are a commander
      • Set effect 339 in slots with value = your old unit type
      • Become feebleminded.
      • Pick a random square in a 3x3 box around where you died. If belonging to the nation on the left, move 2 squares left. If belonging to the nation on the right, move 2 squares right instead.
      • Spawn a number of normal bugs equal to your swarm body ability value, in addition to your soul vessel
      • After battle, you should get unfeebleminded and return to your normal body
      • Otherwise, there is a 20% chance per turn that a soul vessel turns back to its normal body, so long as its fatigue < 100. This also unfeebleminds it
    • At this point, if you are alive, in a province > 0 (not in another plane), and have lost your head, you die unless you're one of the types of creatures that can survive that.
    • Some preparations for immortal/twiceborn/reincarnation/mummify. None of these happen unless the fatal damage was less than 9000
    • If the unit died, it adds one to the province's armed corpse count if it is not an animal, undead, need not eat, naturally ethereal, or inanimate
    • If the unit was not undead and not inanimate, and haunted forest is active, and the battle is taking place in the relevant dominion, you get a manikin for someone (probably the enchantment owner)
  • Communion fatigue calc
    • (Take spell fatigue * 10)/(num slaves + 1). If the casting master was innate, double this
      • If slave's path level < half master's path, rounded down, you get this x4
      • If slave path level < master's path x0.75 rounded down, you get x3
      • If slave path level < master's path, you get x2
      • If slave path level > master's path, you get x0.5 rounded down
      • If slave path level == master's path, you get x1
    • The final fatigue added to the slave is (the above value + a random number between 0-9 inclusive) / 10, rounded down, to a minimum of 1
  • Acid damage:
    • Chance of rust is 4% per damage
    • The manual's description of rust on armour/weapons seems to be correct
  • Looks like death by homesickness, landdamage, uwdamage, disease, and such things will drop items into a lab. So will damage caster rituals.
  • Precision (all distance/range calcs here use pythagorean distance rounded down to integer):
    • Roll a d100.
    • If 1 or 2, divide effective prec by 3
    • If 3-6 inclusive, divide effective prec by 2
    • The above is done before prec over 10 is doubled
    • Final prec does not go below 0
    • Deviation only occurs if prec/2 - 2 < the range.
      • The deviation in number of squares is ([a random number between 0 and (prec - 1)] + ((5 * distance)/4, rounded down)/prec, rounded down. For the purposes of the division, the minimum possible prec value is 1.
      • For each number of squares to deviate, offset each coordinate by a random number between -1 and 1
      • Continue this process up to 100 times if the projectile would be landing more than 2 units out of the original range of the attack or spell
  • Spells have their number of effects subtracted from their effective precision, to a maximum of -5 at 5+ effects.
  • Tartarians are 50% to feeblemind, 20% to be a commander. Then, 50% to add extra afflictions (equal odds of major and minor). Continue rolling 50%s until an affliction was not added.
  • Imprint Souls:
    • Fails if targeted province has no population
    • Final damage is (spell damage) or (province pop/10 * 5), whichever is less
    • Target province loses (final damage/5)*10 pop
    • Conversion rate is: [item pen bonus] * 3 + Astral level, capped at a max value of 30
    • The number of sacred units you make is (conversion rate * final damage)/(30 + [a random number 0-5])
    • The number of nonsacred units is [final dmg] - [sacred units]
    • Guaranteed one commander, if [random number 0-9] + 5 < Astral + [item pen bonus] you get another
    • Units depend on terrain:
      • Land gives you Madmen, Flagellants and Mad Priests
      • Water gives Mad Deep One, Fanatic Deep One, Holy Deep One
  • Event req_minpd and req_maxpd variance is indeed ±25% as per the mod manual
    • req_mintroops and maxtroops also get this
  • Being set on fire from fire damage is 4% per point of initial damage, but you cannot burn if you are ethereal, have unknown unit flag 0x10, fire immunity, chill aura by buff, mistform, or underwater, or have 5+ FR. Fatigue damage is 1% per point instead
  • Being frozen by cold damage is 4% per point of initial damage, and you cannot be frozen if ethereal, undead, chill aura by buff, mistform, fire shield, or 5+ CR. Fatigue damage is 1% per point instead.
    • The manual is also lying about the thaw rate, it is actually 25% + cold res + (cold scale*6), NOT 5x cold res, to a minimum of 25% thawing rate
  • stun chance on salt vuln is (dmg * 500)/(max hp + 10) percent. This is done before salt vuln caps damage
  • stun chance on shock hp damage is (dmg * 200)/(max hp + 5) percent. This is done before any capped damage
  • stun chance of shock fatigue damage is (dmg * 100)/(max hp + 5)
    • … so this is why tweaps stuns everything it touches (1 AN capped shock, 3 AN fatigue)
  • Movement collisions:
    • Calc chassis value for commanders and squads MOVING into each other. Units standing still don't count.
    • Compare each to a random number 0-349. If BOTH sides' values were less than their random rolls, there is no interruption and presumably they keep moving normally
    • For each side, roll an openended d(total chassis value on this side). Divide the original number by 10 and add the die result to it.
    • Compare this value. The loser gets stopped and the fight happens where they are. In the very unlikely event of a tie, the one starting in the highest province ID wins and pushes the other.
  • Special province IDs
    • -18 - dead twiceborned commanders
    • -17 - dead reincarnation candidates
    • -16 - dead mummify candidates
    • -15 - returning on damage
    • -13 to -11 - other planes
    • -10 - "there were X leaderless units in the province…"
    • -9 - retreated province
    • -8 - creatures "removed from combat" (as per the debug log)
    • -7 - fallen or imprisoned pretenders, and hall of fame heroes
    • -6 - dead immortals
    • -2 - special merc home province
  • Poison fatigue damage on size 3+ is reduced to (dmg*2)/size [or 2/<size> of the original damage]
  • Life after Death fails on Undead, immortals, demons, inanimate beings, creatures that are inherently ethereal, pretenders, most kinds of animals (unknown checks)
    • Sea fathers turn into soulless#197
    • Cyclops#156 turn into tartarian cyclops (!)
    • 160-173 and 177 [ctissians] turn into 922 if their res cost is 15+, otherwise 921
    • 127-132 [caelians] and some other things that hurt my head to work out exactly what they are turn into [debug console shows this is 202-205, 215] 918 [caelian soulless]
    • Centaur 27 turn into nothing
    • mother of monsters turns into nothing
    • various kinds of demonbred turn into nothing
    • dagon turn into nothing
    • gorgon turn into nothing
    • war elephants turn into nothing
    • freaks turn into nothing
    • frost dragon turns into nothing
    • nature dragon turns into nothing
    • wyrm turns into nothing
    • wolf turns into nothing
    • nerids turn into nothing
    • sacred serpent turn into nothing
    • wight mage#299 turns into nothing, even though it's already excluded by being undead
    • dark vines turn into nothing
    • queen of the sea turns into nothing
    • undines turn into nothing
    • eternal knights turn into nothing
    • illithid soldier 407 turn into nothing
    • black harpy 430
    • (all these things turn into nothing unless otherwise mentioned)
    • 438
    • 445
    • 464
    • 465
    • 466
    • 467
    • 469
    • 470
    • 487
    • 490
    • 514
    • 516
    • 517
    • 521
    • 525
    • 540
    • 543
    • 560
    • 561
    • 562
    • 563
    • 592
    • 609
    • 610
    • 611
    • 614
    • 627
    • 640
    • 660
    • 750
    • 751
    • 752
    • 753
    • 754
    • 755
    • 756
    • 757
    • 758
    • 768
    • 769
    • 779
    • 786
    • 901 black dryad
    • 902
    • 903
    • 904
    • 1885
    • 1887
    • 1897
    • any plant
    • any size 6
    • If size 4-5 and not mounted:
      • if 25+ res, 917
      • if 10+ res, 916
      • otherwise 315
    • if size 1, 3075
    • if amphibian or aquatic, 918. If you cost more than 15 res, 919
    • if cold blood, act as if you were a ctissian above
    • If flying and size 3, 918 like a caelian
    • if some kind of resource cost is 0-2, 197
    • if that kind of resource cost is 3-14, 914
    • otherwise, 915
  • Cross Breeding:
    • You get (nreff + crossbreeding bonus) creatures.
    • Quality is (Luck * 5) + 17 + crossbreeding bonus.
    • There is a (quality/10)% chance that you get one of the strong crossbreeds, otherwise you get weak ones
  • Hero arrival: chance is 3% + luck scale
    • First roll for normal heroes, if that misses you roll for multihero; if a normal hero is blocked by minimum arrival turn the roll is ignored as if it never succeeded
  • Strands of Arcane Power:
    • First, the site searching.
      • Check each province that you own and has friendly dominion.
        • Check each of the caster's magic paths in turn, and roll an exploding d10. Don't do this if the caster has no level in the respective path
          • If path level + die is 21+, you site search that path at level 3
          • If path level + die is 16+, you site search that path at level 2
          • If path level + die is 11+, you site search that path at level 1
    • Then, the attacking:
      • This is done on a nation by nation basis, attacking low nation IDs first
      • A valid target is any hostile mage (with nonholy paths), that is not mindless, and is in the global owner's dominion.
      • First, they get a MR check of MR + DRN vs 10 + DRN, the DEFENDER wins ties [making this equivalent to normal MR]. If they succeed this, nothing else happens to them. Pen boosters don't work here.
      • If the victim is not an astral mage, the victim takes 10 AN magical damage, with an additional (normal) MR check to negate it. This damage is not attributed to the caster so will not add to the kills stat, trigger blood vengeance etc. Pen boosters DO work, and (astral level/2) of the caster is added to the pen here.
      • If the victim is an astral mage, both sides roll current Astral level (this will include boosters) + closed d6. The global caster wins ties, and the loser is feebleminded. Unlike magic duel, a tie only feebleminds the victim and leaves the caster intact.
      • If the global caster got feebleminded, don't attack anyone else
  • It looks like The Ravenous Swarm will attack every 5120 ticks. It first aims for undead, then accept any target. Its damage is AN, ignores shields, nonmagical, and has no source for the sake of damage reversal.
  • Special AoE values:
    • 666 all squares
    • 665 25%
    • 664 10%
    • 663 50%
    • 662 5%
  • Raid order:
    • Get the lowest combat speed of all the raiders/raiding commanders. Flyers are considered to have 50 for this
    • If the province's patrol strength is greater than 0, and (closed d(lowest combat speed) - 1 + patrolstrength)/lowest combat speed > 0, you might get caught. This is the number of catch attempts the defenders have, each has a 50% chance of success.
    • If (summed pillager value * 10) + exploding d100 < (ingame display of province's population/100)…
      • Roll an open ended d((summed pillager value * 10)/3, rounded down). This x10 is the popkill value.
      • Unrest caused = popkill value/10 or exploding 2d25, whichever is lower
      • Message for the raider: "%s tried to raid %s. %d people were killed before they managed to put up defences and repel the pillagers."
      • Message for the raided: "A small enemy force tried to raid %s but were repelled by the inhabitants. %d people were killed."
    • Otherwise:
      • Take (total pillager value * 750)/100 or d50+300, whichever is smaller.
      • Take ((ingame displayed population amount / 10) * (the above value))/2500. This is the popkill value [real popkill ingame may be 10x this]
      • Gain gold equal to popkill value/2
      • Unrest added is exploding 2d50 or 10x popkill value, whichever is lower
      • Message for the raider: "%s has raided in %s. %d people were killed and %d gold were confiscated."
      • Message for the raided: "An enemy force has raided %s. %d people were killed."
  • Upkeep and desertion:
    • Calc your upkeep for everything (units banished to other planes don't count). If your final gold total is negative and your upkeep was nonzero, it's desertion time. The "gold per year" displayed under the morale section on a unit card is actually (actual upkeep per turn*12 + 7)/15 rounded down
      • Calculate (negative gold total * -25) / (total upkeep). This is the desertion chance in %
      • If that was was 11+, set it to 10.
      • If the desertion percent is less than 1, you simply get "Upkeep cost for the troops was %d gold this season. You couldn't afford this and the troops are getting angry."
      • Otherwise:
        • For each owned, noncommander, not in another plane, nonmerc, nonsacred/prophet/god unit with nonzero upkeep, roll closed d100 - 1. If this value is less than the desertion percent, the unit "deserts" (it's actually death).
        • Report the number of deserters in the message.
      • Set your gold count to 0 from whatever negative value it was.
  • Pathfinding, AKA why bozmos2 is a lagfest:
    • When you click a commander, seemingly for each province on the map (some may be skipped, it's unclear what the criteria are for this though as the disassembler can't tell me what writes to the variable that is checked)
      • Calculate movement scores, to everywhere on the map. This function takes a "depth" value which is the maximum number of times this is iterated over. First the game runs this at 10, and if that fails it runs it again (starting over) with a depth of 20.
      • Set the cost to get to all provinces to 9999 (unreachable)
      • Set the cost of the current province to 0.
      • For each province on the map:
        • If the province had cost to reach of less than 9999, skip it as we already checked this.
        • For each "new" province in the province's connections:
          • If the cost to reach the new province is lower than the current province, skip it (this would be going backwards)
          • If the movement crosses a water boundary, check for sea of ice
          • Iterate over each of the new province's connections, twice, to first determine that the two provinces are adjacent and then to get the connection type
          • If some conditions about the province terrains and army map move capabilities are not met (which stops this movement), check cold scales twice (once for each province) and for a global storm (two more enchant checks)
          • Some more stuff that may involve up to 2 scales checks and one sea of ice check
          • Calculate the half steps out of each provinces. In practice, this means doing the following twice:
            • Iterating over the connections again
            • Potentially checking cold scales once
            • Potentially checking for global storm once
        • Continue this process "depth" times
    • Side note, checking for cold scales iterates over the enchantment arrays twice, once for illwinter and again for second sun
  • "Adds AN lingering heat" creates a cloud that lasts only two pulses, dealing the listed amount of AN heat fatigue damage.
  • Lifedrain does 1/4 damage (rounded down) to inanimates
  • Bleeding inflicts 10 fatigue and ((max hp + closed d20 - 1)/20, rounded down) HP damage per tick, the chance of it stopping really is (10 + regen percentage)%, halved (and rounded down) if underwater. The manual is close to correct on the damage
  • Therodos spectre reanimation is 4/9 for hoplites, 2/9 for archers, 2/9 for peltasts, 1/9 for kouretes
  • Target rear:
    • For each unit in the game (in ascending ID order):
      • If the unit is dead, is not in the current battle, is not owned by a hostile nation, or has an invalid forward/backward coordinate (negative), skip this unit.
      • Get its forward/backward coordinate. If the owner of the considered unit started on the left, multiply the coordinate by -1. If it belongs to neither of the two sides of the battle (say, is an uncontrolled horror or lammashta), consider its coordinate to be -99999.
      • If the unit is routing, subtract 50 from its coordinate value.
      • A unit is taken to be the "current best rearmost unit" if all of the following bullet points are satisfied:
        • Either no unit has been picked, or a random number 0-99 is less than or equal to (15 + (400 / ((number of enemy units in the battle / 3, rounded down) + 10)))
        • The calculated forward/backward coordinate is greater than or equal to the old best one (defaults to -9999)
        • Either you do not have a ranged weapon, your ranged weapon can affect mindless beings, or the target is not mindless
        • Either <something I don't understand> or there are more squares containing allies than enemies in a 3x3 box around the unit being considered
  • Popkill by events (eg, black death) generates 1 unarmed corpse per 10 pop killed
  • Summon animals rituals (in order of priority, so swamp/mountain acts as swamp):
    • Swamp: 2/3 giant spider, 1/3 horned serpent
    • Any UW:
      • 3/12 for sea stag
      • 2/12 for hippocampus
      • 1/12 for leocampus
      • 2/12 for sea dog
      • 1/12 for shark#816
      • 2/12 for small shark
      • 1/12 for kraken
    • Waste:
      • 1/3: If terrain is also highland, black hawk, otherwise giant spider
      • 1/3: giant spider
      • 1/3: goat
    • Highland:
      • 1/3: wolf
      • 1/3: black hawk
      • 1/3: great bear#694
    • Forest:
      • 1/6: boar
      • 1/6: giant spider
      • 1/6: great bear#694
      • 1/6: wolf
      • 1/6: moose
      • 1/6: deer
    • Any other terrain
      • 1/6: great lion
      • 1/6: giant spider
      • 1/6: black hawk
      • 1/6: wolf
      • 1/6: goat
      • 1/6: deer
  • MA ctis miasma is <candles>/75 to disease things. It doesn't affect pretenders/disciples, sacreds, prophets, underwater provinces, units with swamp survival, coldblooded, or inanimates.
  • Supplies and starvation: This stuff is rolled independently for each non-commander that has to eat
    • Chance of bad things = min(90, ((supp usage - supplies) * 100)/supplies)
    • If you have appropriate terrain survivals, chance of bad things is essentially divided by 4, without rounding
    • If you rolled and bad things are to happen to you:
      • If you are not starving, you start starving. There is a flat 10% chance that you also get diseased
      • If you were already starving, there is a flat 50% chance that you get diseased.
      • If you were already diseased, take (maxhp + random 0-9)/10 points of True damage (without DRN rolls)
    • Messages, in priority order:
      • If 5+ new starvers, and nobody is being hurt due to being starved+diseased, and (total number of eaters) ⇐ (new starvers + 2): "Your troops in %s are starving badly due to lack of supplies. The troops must get more supplies or they will surely die."
      • If any new starvers and nobody was hurt due to being starved+diseased:
        • If nobody was starving before, "Your troops in %s are starting to starve due to lack of supplies."
        • Otherwise, "Your troops in %s are starving due to lack of supplies."
      • If 5+ hurt due to already having diseases, and (total number of eaters) < (number hurt due to already having diseases + 2), "There is a severe lack of supplies in %s. All kind of diseases are flourishing among the troops and it is probably too late to save them from dying."
      • If anyone was hurt due to already having disease, or someone started starving (and the above messages didn't trigger), "There is a lack of supplies in %s. Diseases are afflicting the troops."
      • Otherwise, no message
  • Precision:
    • First add together all modifiers except experience stars.
    • Divide by two and round down for each of the following points that are met:
      • Being in the void without void sanity
      • Storm and no storm power/immunity
      • Mist or mist of deception or both (don't do this twice for both)
    • Add experience modifier
  • Innate Flyers (not by buff etc) can only be charged by other flyers (that can fly for any reason, incl buffs). Everyone else "uses" their charge but gets no bonus
  • Pebbleskin suit is 2% per turn to transform you, but not if you're inanimate
  • Vengeful Water:
    • UW always gets 409 = size 5 water
    • Cold 2 gets 833 = size 4 ice
    • Cold 3 gets 832 = size 5 ice
    • Coastal gets 408 = size 6 water
    • Swamp also gets 408 = size 6 water
    • If the victim is inanimate or not in a freshwater province, you get 412 = size 2 water
    • Otherwise, 411 = size 3 water
  • Targeting for Flames from the Sky/Murdering Winter:
    • Total up the number of nonsneaking commanders of all nations in the target province, except those that are on the same team as the caster
    • Each nation rolls (closed d100 + 49) * number of commanders, the highest value "wins" and eats ffts to the face
    • In the event of a tie, the lower nation ID takes precedence
    • If you have no nonsneaking commanders you cannot be hit
  • Turmoil summon is an exploding d((turmoil * 3) + 5) every turn
  • Enchanted Forests: All forests under neutral or enemy dominion act as if they were temples of the caster's pretender. When the dominion has become friendly it stops spreading. Each forest under friendly dominion picks make up to three attempts to pick a random adjacent province, each with a ((candles + 4) * growth * 5)% chance of succeeding. Upon success, the province is attacked if it is a hostile non-wasteland non-sea province.
  • Ghost Ship Armada:
    • For each unlocked armada…
      • Pick a random province.
      • If any of the following, it gets discarded, and try again (and keep count of number of tries)
        • The picked province is on the same team as the caster
        • The owner of the besieged fort in the pricked province is on the same team as the caster
        • The province is not coastal
        • The province is forted, and the number of attempts < (provinces on map / 5)
        • Province's population is less than 10 * (closed d25 + 24), and number of attempts < provinces on map
        • The province is not directly adjacent to the province hit by the main armada, and is not directly adjacent to the province hit by the last armada
      • Make up to 5000 attempts to satisfy the above before giving up.
      • On the first success, spawn…
        • 20 Damned Buccaneer#3351 under command of Damned Admiral "Torgrin", equipped with Shield of the Accursed, Amulet of Antimagic, The Admiral's Sword, Burning Pearl, scripted to Attack
        • 16 Damned Buccaneer#3352 under command of Damned Captain "Soulplunder", equipped with Star of Heroes, Dancing Trident, Dancing Shield, scripted Attack Rear
        • 16 Damned Buccaneer#3352 under command of Damned Captain "Unjust", equipped with Flesh Eater, Enchanted Shield, Ring of Fire, Pendant of Luck, scripted Attack Rear
        • 12 Damned Buccaneer#3351 under command of Damned Captain "Wornhem Helmsman", equipped with Ice Pebble Staff, scripted Spells
        • 12 Damned Buccaneer#3352 under command of Damned Captain "Leperbone", equipped with Knife of the Damned, Eye Shield, Cat Charm, Ring of the Warrior, scripted Attack
        • Damned Boatswain "Ashbreath", equipped with Fire Plate, Lightning Rod, Amulet of Antimagic, forced F2, 2 fire gems, scripted Spells
        • Damned Boatswain "Plaguesky", equipped with Lightning Spear, Weightless Scale Mail, forced A2, 1 air gem, scripted Spells
      • On the further successes, spawn…
        • 12 Damned Buccaneer#3351 under command of Damned Captain, scripted Attack
        • 12 Damned Buccaneer#3352 under command of Damned Captain, scripted Attack
        • 6 Damned Buccaneer#3351 under command of Damned Boatswain, undefined orders
      • If you failed, kill off that armada.
      • If you succeeded:
        • Set the province owner to independents
        • Roll 2d100 exploding. Kill 10x this population, to a max of half the province's population
        • If there is a fort, popkill reduced to 75% of what it would have been
        • Unarmed corpses increases by (popkill/20)
        • Gold generated is (popkill/10 - (closed d(popkill/100) - 1))
        • Unrest generated is (popkill/5) or 50, whichever is smaller
        • Possible bug: it seems like only the gold generated by the last armada counts… also the message only reports the last popkill value…
    • Every 350 gold unlocks another armada, up to the max of 5
  • Each step the AI goes from normal modifies the amount of design points they get by ±50
  • Global enchantment dispelling/overcast is an exploding d20, not a d6 as stated by the manual
  • Wild Hunt - all attackers belong to the casting nation and the casting nation sees all reports
    • Start with 10 attempts remaining
    • If attempts remaining & 1 == 0, look at province ID 1. Otherwise, look at a random province ID
    • A province is invalid if:
      • It is UW
      • It isn't a forest
      • Random 50% chance to be invalid
    • Once valid, check for hostile commanders in the picked province, in ascending commander ID order. A commander is valid if:
      • It is not owned by the caster or their team
      • Attempts remaining / 2 > the commander's holy level
      • The picked commander is attacked in an assassination setting by:
        • Herne the Lord of the Hunt, e1n5, 2n1e gems, Enchanted Spear, Wall Shaker, Amulet of Resilience; scripted spells; 12 Barghests, 17 Wolves
      • Herne can only go after one commander per turn. Once this happens move onto the next phase of lesser hunts
      • If the main hunt falls, the global drops
    • Lesser hunts:
      • Makes up to 210 attempts.
      • Each picks a random province. Provinces are only invalid if UW or not forests
      • Commanders are checked in ascending ID order again.
      • They are considered invalid if:
        • They are owned by the caster or his allies
        • They are sneaking
        • They have no holy levels
        • They are not sacred, a prophet, pretender, or disciple
        • Successful triggers subtract 51 attempts, unsuccessful subtract 1. So the highest possible number is five per turn.
        • There are equal chances for the attacks to be (all die rolls are open ended):
          • Barghest commander, 1d6 + 4 Black Dogs
          • Cu Sidhe#1770 commander, 1d4 + 2 Cu Sidhe
          • Dire Wolf commander, 1d10 + 10 Wolves
        • If these lesser attacks fail, nothing happens to the global enchantment.
  • Illwinter attacks:
    • 2 spawn chances. Pick a random province, it fails if provinces is UW, not cold, or owned by the caster or his team. Equal chances for:
      • Niefel Giant commander with closed d4 - 1 Niefel Giant troops
      • Niefel Shaman commander with open ended 2d8 Winter Wolf troops
      • Werewolf commander with open ended 2d20 Wolf troops
      • Jotun Wolf commander with open ended 2d6 Dire Wolf troops
  • Infernal Breeding:
    • Roll closed 2d6, add the game era [a range 1-3] and subtract 1. Going to call this the era value for now
    • Roll open 1d4, subtract 2, add the number of effects, and half your adept crossbreeder value rounded down. This value can't be lower than 1. This turns out to be the number of units made
    • The era value determines what you get:
      • If < 3, you get Hellbred Giants with a Hellbred Giant commander, troop quantity is half the value calculated above
      • If exactly 3, you get Hellbred Horites with no commander, quantity is as calculated above
      • If exactly 4, you also get Hellbred Giants, with no commander, quantity is value above / 3
      • If exactly 5, you get Hell Spawn#3061 with a commander, quantity is as calculated above / 2
      • If exactly 6, you get Hell Spawn#2967 with no commander, and quantity / 2
      • If exactly 7, you get Hell Spawn#2971-2974, chosen randomly at equal weighting, quantity as above
      • If 8+ you get Hell Spawn#2968+2970, chosen randomly at equal weighting, quantity as above, with commander
  • UW flight needs:
    • the innate chassis ability to fly, not via buff or item, AND…
    • either innate chassis aquatic or amphibiousness, NOT poor amphibian
  • Effects that trigger magic phase battles on the targeted province:
    • 37 remote summon permanent units
    • 38 remote summon temp units
    • 77 astral travel
    • 79 faery trod (on targeted province only)
    • 80 gateway
    • 92 imprint souls
    • 95 cloud trapeze
    • 19 teleport
    • 114 treelord
  • Vafur Flames will only affect things that can be set on fire. Rain gives a 50% chance to avoid its effects. Creatures can only be affected by the damage component once per battle, but will be set on fire every time they enter the flames (if they can be set on fire).
  • Hidden in Snow:
    • Always 1 unfrozen lord
    • You get (8 - drain) + turmoil + closed d8 unfrozen warriors
    • You get closed 2d25 unfrozen, to a max of (50 - the number of unfrozen warriors you created)
    • There is a (3 * (25 - misfortune))% chance to get a mage
    • There is a second, independent (3*misfortune + 25)% chance to get a mage
  • Hidden in Sand/Hidden Underneath:
    • Always 1 leader
    • ((8 - drain) - turmoil) + closed d8 good troops
    • Closed 2d25 lesser, to a max of (50 - good you got)
    • (-3 * misfortune + 85)% chance for a mage
    • second (-2 * misfortune + 15)% chance for a mage
  • Dome order:
    • Celestial rainbow
    • Flaming death
    • Frost
    • Corruption
    • Astral
    • Air
    • Forest
  • Ritual of Rebirth:
    • Get first valid hero in HoF that is dead and owned by the caster's nation. Can't be inanimate (unless it is one of the three mummy types this spell makes).
    • Get resource size, if set. Otherwise, use "normal" size.
    • If size < 4 and innately flying: mummy caelian#743
    • If size 4+: giant mummy#742
    • Otherwise: become the spell's damage attribute (which is normal mummy for ritual of rebirth)
    • Prophet status is removed if you made another prophet, but not H3.
  • Beckoning:
    • Final nreff = min(spell nreff, the number of units in the province belonging to the fort owner)
    • Forest survival does provide immunity
    • Otherwise, affected units roll morale + DRN vs 10 + DRN, victim wins ties
    • If they fail that, they suffer the damage/spec of the spell as effect 2 (so for vanilla it's 999 damage, MRN, uses caster's pen bonus etc)
  • Beckoning targeting: goes for the main province owner. If that is the same as the caster's nation, it will target the fort's owner instead in the case of sieged provinces
  • Stygian Paths
    • Stygian Guide value = the highest value of stygian guide of the commander and all troops under their leadership
    • All units take 1 AN magic damage
    • The stygian guide value offers a % chance to avoid the MR or die effect
    • If any given unit is stealthy, it has a (stealthy)% chance to avoid the MR or die effect, to a maximum of 90% evasion at 90+ stealth.
  • Twiceborn shape logic
    • Units with base twiceborn shapes defined use that
    • If you have a #firstshape, consider that instead of whatever shape you are in currently
    • Use resource size over regular size if you have it set
    • If the firstshape has a twiceborn shape defined, use that
    • If the unit is associated with Ur or Uruk, it becomes a Wight Shaman
    • If the unit is associated with Ashdod and is size 4+, it becomes a Wight Murmurer
    • If the unit is associated with EA or MA Agartha and is size 4, it becomes a Wight Oracle
    • If the unit is a Panic Apostate, it becomes a Carrion Lord#710
    • If the unit is associated with Asphodel and is size 2, it becomes a Carrion Lady
    • If the unit is associated with Asphodel and is size 3, it becomes a Carrion Centaur
    • If the unit is size 2, is cold blooded and has swamp survival, it becomes a Wight Mage#3181 [ctissian]
    • If the unit is size 6 and female, it becomes a Wight Mage#3446 [female titan]
    • If the unit is size 6 and male, it becomes a Wight Mage#3445 [male titan]
    • If the unit is size 4+ and an innate full (not poor) amphibian, it becomes a Wight Mage#3195 [atlantian/angakok]
    • If the unit is size 4+ and is aquatic, it also becomes a Wight Mage#3195 [atlantian/angakok]
    • If the unit is size 2 and innately flying, it becomes a Wight Mage#3180 [caelian]
    • If the unit is size 5+ and female, it becomes a Wight Mage#3446 [female titan]
    • If the unit is size 5+ and male, it becomes a Wight Mage#3445 [male titan]
    • If the unit is size 4+ and female, it becomes a Wight Hag#3444 [size 4, gygja]
    • If the unit is size 4+ and male, it becomes a Wight Mage#3450 [size 4, skratti]
    • If the unit is size 2+, it becomes a Wight Mage#299 [size 2, human]
    • If the unit is size 1, not innately flying, and male, it becomes a Wight Mage#3448 [size 1 vaetti]
    • If the unit is size 1, not innately flying, and female, it becomes a Wight Mage#3449 [size 1 vaetti female]
    • Otherwise (the unit is size 1 and innately flying) it becomes a Wight Mage#3447 [zotz]
  • Non-permenant affliction notes:
    • Slime
      • att/def: -2
    • Frozen
      • -3 att
      • -3 def
    • Webbed: -75% def
    • Netted: -75% def
    • Entangled: -75% def
    • Earth grip: -75% def
    • Fire bonds: -75% def
    • False fetters: -75% def
    • Stunned: -75% def
    • Paralysis: set to 0
    • Petrify: set to 0
    • Encase in ice: set to 0
    • Sleep: set to 0
  • Defence modifiers on action rate:
    • quickness x2
    • slowed /2
    • slimed /2
    • If final action rate > 1, +2 def
    • If final action rate < 1, -2 def
  • Disease damage/afflictions: Non-regenerating creatures suffer (closed d10 - 1 + max hp)/10 damage per turn, rounded down, and have a base affliction chance of 15%. Regenerating creatures suffer no damage and have a base affliction chance of 10%. Holding a cursed item increases affliction chance by a flat +50%. If an affliction is rolled, there is the same chance again that it is a major affliction, otherwise a minor affliction is added.
  • Chain lightning spread:
    • A new jump happens every 120 ticks
    • Cannot hit the same victim twice in a row
    • Will prefer to jump to a random target within 1 square reach, but can travel up to 2 squares (using pythagorus, rounding down)
  • Independent gem regeneration:
    • Occurs immediately after player incomes are calculated. Happens for every alive commander with an owning nation of less than 5 (so will include special monsters) that has a positive province ID (so not commanders in other planes).
    • For each non-holy path the commander has:
      • If [path level * 3] - [owned gems of this type] ⇐ [a random number 0-19 inclusive], stop filling gems
      • Otherwise, add 1 gem, and repeat the above step again, EXCEPT deduct one from their path level.
  • Example: a F3 mage has no gems. The first gem is added if 9 - 0 > a random number 0-19. If this happens, the check for the second gem is 6 [F3, minus one as one gem was added this turn] - 1 [one fire gem now owned]
  • Projectiles and hitzones:
    • This is for spells and ranged weapons with AoE: one person
    • no effect on mindless → always hits the head (so mind burn, mind blasters…)
    • true or internal damage, with hitlocation of one person → always hits the chest
    • 20% to hit leg, if no legs then hit body
    • 50% to hit body
    • 20% to hit arms, if no arms then hit body
    • 10% to hit head, if no head then hit body
  • Melee hitzones:
    • Reduced weapon length = (length of weapon - 1), to a minimum of 0
    • "Reach value" = (target size - reduced weapon length) - attacker size - "lower head" value (shown when clicking size on the unit card)
    • Roll a ranged hitzone result, and remember it.
    • If weapon "more likely to hit head", 75% chance to change the ranged hitzone result to be the head, so long as the target's bodytype has a head
    • If trying to hit head:
      • If target still has a head (IE: they have more than one head, or started with one head and it hasn't been cut off already):
        • If reach value is 0 or negative, you succesfully hit the head.
        • Otherwise, pretende your ranged hitzone roll was a leg hit
      • If target has lost their only head, pretend your ranged hitzone roll was a body hit
    • If trying to hit body:
      • If reach value is 1 or lower, you successfully hit the body.
      • Otherwise, pretend your ranged hitzone roll was a leg hit
    • If trying to hit arms:
      • If reach value is 2 or lower, you successfully hit the arms.
      • Otherwise, pretender your ranged hitzone roll was a leg hit
    • If trying to hit legs:
      • If victim doesn't have hittable legs (eg Jinn or Misc bodyshapes), you successfully hit the body instead.
      • Otherwise, you successfully hit the legs.
  • Defence negates rolls an openended 3d6. If this is less than the unit's defence skill, not including fatigue or modifiers from weapons, with shields subtracting their encumbrance value from the score (and not adding their parry value), the effect is negated. Trample's defence calculation also works this way (so shields are an active detriment to being trampled)
  • Retreating and death:
    • For my benefit only because this is really confusing: flags initially set are 8, 9, c, d, e, f, 16, 17, 18… 12 can be set later, all others are not relevant for this
    • If connection is impassible, and no teleport type movement, you die if you take it
    • If connection is mountainpass:
      • If you have any of the following flags: flying/teleport/mountain survival/floating; you can take the mountain pass and not die
      • Otherwise, if either side of the pass is in neutral/cold scales, or perpetual storm is active, you die
    • If connection is river:
      • If you have can't pass rivers (eg vampires), you die
      • If you die when taken underwater, can't teleport, can't fly, lack the swimming tag, Sea of Ice is not active, or either side of the river is not cold 1+, you die
  • Ind's poptypes:
    • The "random determinant" for a province is calculated as (province id / 3) + (province id / 23) + a random number 0-4294967295 that is fixed and generated on world creation. Only the even/oddness of this value matters at all. This is rounding down after all of the divisions.
    • (The first one of the following that applies determines what you get)
      • If it's your capital, underwater, or lacks fort, you don't get any of your specials.
      • If cave (with or without mixed terrains), always cyno type
      • If swamp (with or without mixed terrains), always nothing
      • If waste (with or without mixed terrains), always lost tribe giants
      • If forest (with or without mixed terrains), always orionde
      • If highland (with or without mixed terrains), always cyno type
      • If mountain (without mixed terrains of highland/swamp/waste/forest/cave), and random determinant is even, you get cynos
      • In other cases, you get feminie if random determinant is even, or piconye if random determinant is odd
    • This means that you should in theory, after one piconye, feminie or mountain cyno fort, identify if the random component itself is even or odd, and be able to predict all randomness after that
  • Mapmove function (IE: what the inspector needs to implement to show correct mapmoves)
    • If 0 or negative, it isn't changed
    • If <100:
      • If <6:
        • Multiply by 6
        • If flying, add 8, otherwise add 2
        • If slave, subtract 2
      • If commander, add 2
      • If >40:
        • Set to ((value + 2)/5) * 5, round down after division
    • If >0 and <100:
      • Add 2 * size difference between natural chassis and actual unit (due to enlarge/shrink)
      • Subtract 2 * old age penalty, to a maximum penalty of -6
    • If the unit lacks the nomovepen tag (on chariots mostly):
      • Calculate total armour mapmove penalty (sum of all armour pieces with type 5 → body)
        • If the armour data has a movement penalty flag set (attrib 0x246) and its value is not -99, use that
        • Take the armour's encumbrance.
        • If armour is magical (attrib 0x22d) subtract 1
        • Mapmove penalty is (encumbrance, maybe reduced by 1 as above) * 2, to a maximum penalty of 6 from a single piece of armour.
      • If the unit chassis has encumbrance 0, half this (rounded down)
      • Subtract from mapmove
    • If the unit is commander:
      • If limp, -4
      • If cripple, /4 and round down
    • Add mapspeed bonuses (eg from items), if any
    • If you can fly, and have a value for unit effect 0xe6 (which seems to be only used for "flyingmapmove" for the flying carpet item), use this in place of your normal map move
  • "Startage" (for, presumably, noncommanders only - commanders go a bit differently)
    • This is seemingly identical (I have not looked TOO hard) to the function below for commanders, except it doesn't do the stuff involving provincial age rates and action/age rate modifiers
    • TODO check more carefully. I don't really know where my adventures in writing the below took me
  • "Startagemagic" (for commanders only, has a lot in common with the above… but is a different function!?):
    • Get base max age. If one isn't set on the chassis data:
      • Default: 50. Otherwise, take the first one of these that applies
        • If demon, 1000
        • If innately ethereal undead, 1000
        • If other undead, 500
        • If inanimate, chassis size * 400
        • If innately ethereal, 150
        • If recuperating, 90
        • If animal and base MR is 5 or lower, chassis size * 7
        • If animal and base MR is 6+, chassis size * 15
      • If cold blooded, add 50% to whatever the above result was
      • If this is a pretender chassis (startdom or pathcost set):
        • If startdom is 1 (or somehow lower):
          • If size is 4 or lower, max age is set to 500 if below that
          • If size is 5 or 6, max age is set to 1000 if below that
        • If startdom is 2+, max age is set to 5000 if below that
    • If your maxage is 10 or lower, something2 = 1, otherwise it is 4
    • Base startage = maxage/3 + something2
    • The following is used only when not used in "newunit", which is just about everything except making brand new units and commanders…
      • Stuff I don't understand
    • If good leader (80 base leadership), add 10 or (base max age/10), whichever is larger
    • If expert leader (120 base leadership), add 20 or (base max age/5), whichever is larger
    • If superior leader (160 base leadership), add 50 or (base max age/2), whichever is larger
    • If startage modifier tag is set, add that now
    • If no startage modifier, and base RP cost is 500+:
      • Get the unit's base gold cost. If it is 15000+, subtract 10000 from it. Calling this the reduced gold cost, I guess?
      • Get the unit's base recpoint cost, add 500 then divide it by 1000. Calling this the reduced recpoint cost
      • Something4 = ((reduced goldcost - reduced recpoints)*10)/reduced recpoints [what happens if this divides by zero?]
      • If the result is beyond the range -5 to 5, move it to the closest value
      • Add to base start age.
    • If startage is set on this chassis, throw out everything done so far and use that instead
    • If the chassis has undocumented 0x2a1 (this is on two Hag heroes with a value of 350), and this is MA or LA, add ((closed d50 + 74)*attribute's value)/100. Multiply this by 2 if this is LA.
    • If the chassis has add random age:
      • In [what context? it's some, but not newunit calls] some contexts, this always adds attribute value/3. [This includes the recpoint autocalc algorithm]
      • Otherwise, add an openended d(value)
    • If you are a commander, and startage is not set:
      • If base max age < 200:
        • If base max age < 40, consider it to be 40
        • Nonholy path modifier = (base max age * total nonholy paths)/7
        • Holy path modifier = (base max age * total nonholypaths)/5
      • If base max age is 200-399:
        • Nonholy path modifier = (base max age * total nonholy paths)/9
        • Holy path modifier = (base max age * total nonholy paths)/6
      • If base max age is 400+:
        • If base max age is 750+, consider it to be 750
        • Nonholy path modifier = (base max age * total nonholy paths)/12
        • Holy path modifier = (base max age * total nonholy paths)/8
      • Take whichever path modifier is higher, and this is your base additional max age from magic paths.
      • If the chassis has undocumented 0x280 (Erythreian princes and princess of the setting sun have this at 20), set the path modifier to (old path modifier * attribute value + 50)/100
      • Calculate a multiplier for the addition:
        • If normal action speed (as a percentage), start with 100. If quickened (or somehow slowed/slimed) use the appropriate multiplied value here.
        • Calculate total age rate modifier, by adding the following:
          • Slow aging percent, attached to the unit (eg items, unaging bless)
          • Slow aging percent, from a site in the current province
          • Slow aging in province (percent), from noaging land (modded units, or the fountain of youth item)
        • If the sum of these is greater than zero, subtract it from the action speed percentage
        • Final variance = (base additional max age * final action speed/age rate percentage)/100, rounded down
        • If the commander is not being viewed in a UI preview window, add (variance) + closed d(variance/5) - 1
        • If this is a UI preview window, add variance + (variance/10)
  • The arena is always Order0Productivity0Heat1Death3Luck0Drain2
  • The arena is technically a wasteland, but I don't know any reason why this is important
  • Arena fights always proceed like:
    • Pick a random nation that entered
    • Pick a random nation that entered and that isn't the first nation
    • Repeat until there's 0 or 1 nations left, then crown the winner or exit and say nothing
  • Field sizes:
    • The Void, Inferno, Kokytos, Arenas, are always 40x20
    • Otherwise, for each unit in battle, add up the unit's size. If it was 4+, take it to be 6 instead.
    • If this has the assassination terrain flag, and the total size is 199 or less:
      • One dimension (width?) = 16
      • Other dimension (length?) = 21 + closed d12
    • All other cases
      • If the total size calculated above is 4800 or lower, you get the standard 80x40
      • Otherwise…
        • Length = 80 + (total size - 4800)/260
        • Width = 40 + (total size - 4400)/260
        • Neither dimension may exceed 198
  • Both kinds of corpses decay to 80% of their values every turn
  • Growth/death scale pop changes:
    • The scale growth mod (which is 20 by default but can be modded) is multiplied by the province's scale value, and is then divided by 2 if you have the half growth/death thing Abysia has
    • the amount subtracted from the displayed ingame province's population is 10*((closed d10000 - 1) * (province current population/10 * the scale growth mod) / 10000), rounded towards zero
  • Burning mountain eruption is 25% per turn at turn 30, +1% per turn until it happens
  • Recpoint autocalc - applies to non-commanders, or commanders with a set RP cost of <7. Those with 7+ use different rules I don't understand yet
    • If set RP is less than 500, use that and don't do any more of this.
    • A = (RPcost + 500)/1000, rounded down, to a minimum of 1.
    • A2 = A, unless it is less than 1, in which case A2 = 1.
    • B = (unit's base gold cost, not autocalced) - 10000
    • if unit's base gold cost ⇐ 5000, B = the base gold cost instead
    • C = ((B - A2)*100)/A2, to a maximum value of 100
    • If the unit has the Standard ability, C instead has a maximum value of 50
    • D = sqrt(unit's start age, modified by unknown stuff * 4)
    • E = 1 + D + base RP cost - (A * 1000) + (C * 20)/100
    • If the unit is undisciplined, divide E by 2.
    • If the unit is a slave (but not also undisciplined), subtract E/4 rounded down.
    • If the unit is mounted, add 15 to E.
    • If the unit is slow to recruit, multiply E by 2.
    • If E is less than 2, set it to 2.
    • E is the final RP cost.
  • Innate casters:
    • Operate on a clock that starts at 0, and goes up by 1 every 1880 ticks.
    • Instead of hitting 4, it goes back to 0.
    • All innates first try to cast instantly, but this might be delayed a bit (see below)
    • Innate 4s cast whenever it changes, so at 0 and then every 1880 ticks after
    • Innate 3s cast whenever it is not 1, so 0, 3760, 5640 ticks (and all multiples of 7520 + these values)
    • Innate 2s cast whenever it is 0 or 2, so 0 and 3760 (and all multiplies of 7520 + these)
    • Innate 1s cast whenever it is 0, so 0 and all multiples of 7520
    • https://imgur.com/a/8anyRIU This might help with visuals, and shows the earliest possible cast times for innates
    • Additionally, units are staggered slightly based on their unit ID. The base offset for a unit is ((its unit ID % 188) - 1) * 10 ticks
    • … so a commander with a unit ID of 3014 would have a delay of 3014 mod 188 = 6; 6 - 1 * 10 = 50 ticks from the above
    • Timestop changes all this, not looked at that yet
  • The delay for a normal guy going from preparing to actually casting a spell is (75 * spell's cast time in percent, modified by fast cast modifiers)/2 + closed d1000 - 501
  • Initial delay:
    • Units roll a (closed d1000 - 1) for each squad member, and get the lowest result
    • Commanders just get one swing on a d1000-1
  • Magic Duel baiting:
    • Spellcasting AI scans squares in lines going down the length of the battlefield. It starts at the top left corner, goes all the way right, then moves down a line, and repeats.
    • This is relevant because in the case of a TIED score, the first square checked is always retained, making magic duel somewhat biased towards things on rows closer to the top of the battlefield (and to a lesser extent, things on the left of these rows).
    • For all intents and purposes, magic duel's score will almost always be 10 - this technically is min(10, target max hp + 5 + strength - 10). Non-astral mages score 0.
    • Add up the scores of all units in the target square, then divide by the number of units in the square (so stacking non-astral mages in the same square should make you less likely to be targeted)
    • Add a random number between 1 and 10 to this, then subtract 5.
    • Multiply score by 15, then divide by 15 or the distance to the target, whichever is greater, then round down.
    • Being close to the caster and/or closer to the top of the screen will make you more likely to be the target of a magic duel.
  • Tartarian/shattered soul orders:
    • This affects all types of order 63, which are: "Build mausoleum" "Call the dead" "All will be ashes" "Whisper to the dead" "Mutter" "Festival for the dead" "Open tomb" "All will end" "Attend funeral"
    • Get some kind of "unholy" nation ID for later. This is nation attribute 36, which is currently only MA ermor, but if multiple nations had this then the highest ID one would always "win"
    • If the shattered souler is in a province with no candles owned by anybody, and an unholy nation is in the game:
      • If (number of candles) < (shattered souler's Death path + 3), there is a ((death path + 3)*15)% chance to:
        • If the unholy nation is in the game, give them dominion ownership and +1 candle in the province, to a max of 10
    • Otherwise, if the shattered souler's province has candles already:
      • If the province has the unholy nation's candles in and (number of candles) < (shattered souler's Death path + 3), there is a ((death path + 3)*15)% chance to add +1 candle to a max of 10
      • Otherwise, there is a (((death path + 3) - candles) * 5)% chance to subtract 1 candle from the dominion strength of the province.
    • If the shattered souler was in a candleless province and there was no unholy nation, nothing happens.
  • "Fhtagn" - insanity order
    • This is all varieties of (regular insanity) order 62: "Heretic Preaching", "The stars are right" "Hear the void" "Hear my dreams of R'lyeh" "See the signs of R'lyeh" "R'lyeh is rising" "See the signs in the sky" "Fhtagn"
    • The unholy nation this time is LA rlyeh/attrib 167
    • This is the same as the above, except ((holy path * 2) + 2) is used to replace all instances of (death path + 3)
  • Ice fort melting:
    • Roll a random number -2 to 0 inclusive.
    • If the cold scales in the province is greater than or equal to this number, the fort melts a bit.
    • If the fort was previously undamaged, and is being melted: "The %s in %s has started to melt. It might be damaged unless the province gets colder."
    • If the fort has been damaged 15 times and is not sieged, it melts fully to nothingness: "The %s in %s has completely melted away due to the prolonged heat"
    • If the fort has been damaged 5 to 9 times inclusive: "The %s in %s is melting badly. It might be permanently destroyed unless the province gets colder."
    • If the fort has been damaged 10+ times, it permenantly becomes a half melted fort: "The %s in %s has mostly melted away due to the prolonged heat. The damage is now beyond repair and the half melted fort has to be destroyed so a new and better fort can be built."
    • In cold 1+, a fort at any level of destruction instead gets (3 * cold scale) subtracted from its damage count. This cannot lower the damage count below 0. If this lowers the damage progress to zero and the fort is not half melted: "The %s in %s has fully recovered from the earlier melting."
  • Mirror image and exact chances
    • Num images = max(1, 2 * air level), as would be expected
    • There is a (100/(images + 1))% chance to NOT negate the damage:
      • 1 image: 50%
      • 2 images: 33%
      • 9 images: 10%
      • 21 images: 4% [unrounded values would have you say 4.76%]
    • So I guess Really Stupid Large numbers of images get the most out of the slight rounding error…
  • Assassinations and bodyguards:
    • The chance of each bodyguard showing up in percent is 50, +10 per bodyguard point the unit has, -10 per patience point the assassin has. The chance can't fall below 5% or exceed 95%. This is rolled individually per unit bodyguarding the commander.
    • Warning doesn't do anything here except increase the number of bodyguards a commander is allowed to have.
  • Reaper/Leper/BVC/Plague doctor
    • Add up the total reaper/active plague doctors in the province.
    • For diseasing units
      • Each unit in the province that is friendly to the province's owner has a (total reaper/plague doctor in the province - total reaper ability on units friendly to the province owner)% to become diseased if it isn't already.
      • Note that friendly plague doctoring is not subtracted.
      • "Province owner" here refers to the sieging party in the case of a besieged fort.
      • → this means that BVC in your own fort under siege will only disease siegers, and BVC in a fort you are sieging diseases nobody.
    • Popkill:
      • Roll an openended d(total reaper and active plague doctors). Friendly reaper is not subtracted here.
      • Add the die result to province unrest.
      • Kill (total reaper and active plague doctors/2)% of the province population.
      • Add ((killed population/10) - (((killed population/10) * 50) / 100)) unarmed corpses to the province
  • Marignon innate dompushing (nation attribute 41, MA/LA Marignon both have this with a value of 1)
    • Only in owned provinces in hostile (not neutral) dominion, also applies to friendly forts under siege
    • Chance to deduct a hostile dominion candle is 30%, or 60% if a temple is present. If there's only one red candle, it is removed leaving neutral dominion
    • This can also spread dominion to a max of 1 white candle (or 2 if a temple is present). The chance of adding one is 20%, or 40% if a temple is present.
  • On dominion spreading:
    • If the province has hostile dominion, there is a (50 + (5* dom conflict bonus) + (5 * pretender's effective dom score, capped at 20) - (5 * hostile dominion level in province))% chance that the dominion level is decreased by one point.
      • (The wiki didn't mention how conflict bonus fits into this until now…)
    • The chance to add to dominion in the province where the check originated is ((10 - candles) * 3)%. This cannot happen if the province is already up to your current dominion strength.
    • Otherwise, pick an adjacent province and repeat up to 1500 times per temple check.
  • Capital starting population (before the adjustment some nation like popkillers get) is 10 * (2950 + closed d100)
  • Capital starting resources is 78 + closed d5
  • Path loss on recall
    • This whole section doesn't apply for nations with attribute 0x10c (Ur/Uruk). They also can't gain any paths from dying either.
    • Your chance to lose paths (not candles) in percent is:
      • (nature path + 5) * 10%
      • If you're a trinity, add ((nature + 5) * -10 + 100)/2 rounded down.
      • If you are a disciple, or have a dominion strength of 1 already, you cannot lose candles and always lose paths instead.
    • If you're losing paths:
      • Make up to 1000 attempts to successfully do this. If that fails for some reason, you get the rolls to gain paths, but then fall back to losing a candle instead of a path:
        • There is a 50% chance that you try to lose Nature.
        • Otherwise, roll a random path to try to lose. If you happened to roll death, roll again. If the second roll also lands on death, death can be lost.
        • If you don't have any (base) skill in the path you're trying to lose, use up one of the 1000 attempts and start again.
        • If you are trying to lose death, there is a chance to get away without losing anything. This happens if (a random number 0-11 inclusive) < (10 or your base death path, whichever is lower).
        • Otherwise, you lose one point in the path you picked.
      • Regardless of what path you tried to lose or whether you actually lost any now you roll to gain paths.
        • If you are D3 or lower and you didn't lose death, there is a 15% chance that you gain 1 death level
        • If you are S3 or lower and you didn't lose astral, and didn't gain death, there is a 1% chance that you gain 1 astral level
        • If you are B3 or lower and you didn't lose blood, and didn't gain either death or astral, there is a 1% chance you gain 1 blood level
    • If losing candles, you do NOT roll to gain paths unless the above loop of 1000 attempts failed to find a path to remove from you and had to resort to taking a candle instead.
  • Passive unrest reduction due to dom/order/turmoil
    • First, PD does its thing: Reduces unrest by ((pd / 10) - 15), the amount shown on the PD UI ingame
    • Dominion unrest modifier. (Number of candles + 1)/2 rounded down. If the dominion is hostile, this is added to the unrest instead of subtracted
    • If hostile dominion:
      • Get turmoil scale. If it was negative (order) make it positive (as if it was the same amount of turmoil).
      • Unrest divisor = (10 + abs(turmoil))
    • If friendly/neutral dominion, unrest divisor = (10 + order)
    • Subtract from the unrest total: (remaining unrest/divisor) rounded down
    • Patrolling happens next.
  • The mod command domunrest (both Phlegras have this at 5) adds (closed d10 - 1 + candles * value)/10 rounded down unrest per turn.
  • Spec 70368744177664 (no effect on flyers/floaters) stops effects applying to
    • Units that are innately flying all the time
    • Units that are floating by any means
    • Units with the flight buff
    • It does NOT care about flying by other means such as fly-when-blessed (eagle warriors)
  • Casters and deciding how many gems to use
    • The conservative gem usage setting is ignored and assumed to be off for the attacking side, in assassinations, and when on other planes
    • Calculate fatigue after casting. Notably this does not include communion fatigue dispersion.
      • Spell base fatigue is divided by 2 if the caster is a spellsinger
      • The fatigue divisor is (1 + (caster's primary path level including communion boost) - (spell's primary path level requirement)), and is set to 1 if it turns out lower than that
      • Final = (caster's current fatigue) + (caster's spellcasting encumbrance) + (spell base fatigue/fatigue divisor)
    • In all cases, calculate bare minimum number of gems required to cast the spell, including +1 gem to boost the path level as required.
    • If conservative gem usage is in effect:
      • Add an extra gem if all of these are true:
        • The caster would be over 100 fatigue
        • The fatigue divisor is less than 10
        • Casting this spell would add 30 or more fatigue
      • Upon adding an extra gem, recalculate the fatigue after casting (each extra gem increases the fatigue divisor by 1)
      • Keep adding gems until one of the above three conditions are not met. If the number of total gems spent exceeds the caster's path level (including communion boost), they spend only the bare minimum, otherwise they spend the amount that resulted from the process above.
    • If no conservative gem usage is in effect:
      • Add additional gems, one at a time (increasing fatigue divisor by 1 after each addition), while…
        • The caster would have 3 or more of the gem type left after casting the spell
        • And either:
          • (Spell's fatigue cost/fatigue divisor) is 25+ and fatigue divisor is less than 2
          • (Spell's fatigue cost/fatigue divisor) is 40+ and fatigue divisor is less than 3
      • Then add an extra gem if all of these are true:
        • The caster would be over 85 fatigue
        • The fatigue divisor is less than 10
        • Casting this spell would add 20 or more fatigue
      • Upon adding an extra gem, recalculate the fatigue after casting (each extra gem increases the fatigue divisor by 1)
      • Keep adding gems until one of the above three conditions are not met. If the number of total gems spent exceeds the caster's path level (including communion boost), they spend only the bare minimum, otherwise they spend the amount that resulted from the process above.
  • Pillage
    • A unit's pillage strength is:
      • (Strength + combat speed + fear * 10)/2, rounded down. Combat speed for flying units (flying from any source) is considered to be 25, even if their actual CS is higher
    • Sum up the commander's pillage strength and all units under their command.
    • If province population/150 >= pillage strength, you fail to pillage, and don't get any gold.
    • If there's an enemy fort present (or, I think if you're somehow trying to pillage your own fort under siege!), your pillage fails. "%s tried to pillage %s, but failed due to an enemy fort being present."
    • If you failed the population check above, stuff still happens…
      • Roll an exploding d(pillage strength/2, rounded down). The attempt kills 10x this number of population, resulting in 1 unarmed corpse per population killed.
      • Add exploding 2d20 unrest to the province.
      • Message: "%s tried to pillage %s. %d people were killed before they managed to put up defences and repel the pillagers."
    • If you pillaged successfully…
      • Set the province flag which presumably shows the burning torch icon.
      • Final pillage strength = (province population/10 * min(total pillage strength, closed d50 + 400))/3000
      • Kill (final pillage strength*10) population, to a max of the province's current population. This generates 1 unarmed corpse per 50 population killed
      • Unrest die size = min(50, final pillage strength * 2)
      • The unrest generated is 4d(this size)
      • The gold generated is (final pillage strength - closed d(final pillage strength/2, rounded down))
  • FIXME Does the pillage bonus trait just not do what the game says it does? I can't find anywhere where it's checked here
  • Unit id allocation:
    • If the highest unit ID is less than 25000, simply increase highest unit ID by 1 and assign the next new unit the old highest value
    • Otherwise, go through all existing IDs in order until you find one for a unit that is dead and removable, then take that old unit's ID
  • Pretenders at game creation are given consecutive unit IDs. These go in ascending order of nation IDs in the game. They are not the first things to be created though, so for the purposes of innate spellcasting offsets, a clean multiple of 188 might happen to fall in the middle of this process. It still very very heavily biases two innate pretenders' offsets towards the lower nation ID though…

Undocumented hotkeys

  • Many many not-really useful things, like "h" on the "pick a nation to play" will host if not multiplayer, tohfx will sort the in battle f1 display like clicking on the columns does, many alternative ways to close windows…
  • $ with -d or higher on the strategic map desplays your "kingdom value". Don't really know what this is useful for
  • C on the "Rejoice! X has ascended → view scores/history" screen will host a new turn!
  • F9 on strategic map displays thrones
  • T on player setup tries to force teams of 4, with nations assigned by internal ID
  • d on send messages retracts all messages
  • i on the army setup screen will invert the selection of units in the selected squad
  • ctrl-p on army setup writes something to the blind log
  • r, s, m, l on the map selection screen for a new game do something. I'm not certain what, might be selecting random map sizes

Armor defeating ("critical" hits)

  • Looks a bit different to the dom4 stuff.
  • Applies only if:
    • Trying to do more than -900 damage (this likely has some internal significance)
    • The attack is not AN
    • One of the following:
      • Final prot DRN is 0-2 inclusive
      • Final prot DRN is 0-3 inclusive AND the victim's fatigue is 50+
      • Final prot DRN is 0-4 inclusive AND the victim is immobilised, but is not inherently an immobile unit type
    • The result is the victim's protection is reduced by (victim's protection+2)/4, rounded down

Graphs. I am not too confident on these…

  • Army size graph looks to plot (total size of all units you own)/4 to a max of 65000. This counts base unit type size, so enlarge/shrinking units has no effect.
  • Dominion graph looks to plot (total of all candles, +10 for each province that has your candles)/2 to a max of 65000.

Melee weapons and items:

  • the first weapon is skipped if you have 2+ shields from items and the weapon is nonintrinsic
  • the second weapon is skipped if you have any shields from items and the weapon is nonintrinsic
  • the third weapon is skipped if you have 3+ shields from items and the weapon is nonintrinsic
  • the fourth weapon is skipped if you have 4+ shields from items the weapon is nonintrinsic
  • This looks backwards, but if you swapped 1st and 2nd consider that any human with a sword and shield would lose their shield if given a magic shield, it's weird but is what it is
  • Weapon attribute 657 seems to be "needs accessible horns to use" and weapons with this are removed if a crown is equipped

It looks like moving off the field simulates 100 rounds of affliction and regen processing, this specifically includes poison, decay, That Mystery Affliction that Does More To Undead, uwdamage, landdamage, burning, bleeding, freezing, desiccation, plague, regen

Assassinations:

  • This function processes all commanders in ascending commander ID order.
  • Infiltration for graphs: is just 50% to succeed
  • Cause unrest: creates openended d20 unrest
  • Seduction: two map commander orders (72, seduction; 58: corruptor) do this.
    • Get a commander to target. This looks properly randomised (builds a list on the stack and then picks one randomly). This respects Scale Walls. Sneaking commanders are not valid targets, as many players probably know from experience.
    • If dream seduction, penbase = 13 + (pen bonus from items, bless etc), moralebase = <value of dream seduction>
    • If nondream seduction (overwrites dream if you give a unit both), penbase = 99, moralebase = <value of seduction ability>
    • If the unit is female (including via cat charm):
      • Add the amount of the gender changing effect to the morale base
    • If action is corrupt: penbase=99, moralebase=<value of corruptor ability>, which will overwrite anything earlier
    • Make 1000 attempts to pick an adjacent province you can retreat to. I could look into this in more detail if required.
    • If no province found, you get "With nowhere to run with the victim afterwards, %s aborted the seduction attempt."
    • The MR check is always rolled, even for corruption and non-dream seduction (though with a base pen of 99 they probably can't really ever fail). Specifically, if MR + DRN >= penbase + DRN then it fails (result=0, result2=0) and you get "%s tried to project %s wonderful dreams at %s, but the target resisted and no real seduction could be done."
    • If you have nowhere to walk to, but can fly and your size is less than your target's, you fail (result=-3, result2=0).
    • If the seducer and victim are the same gender, you head towards a fail state that presumably corruption will undo later (result=-1, result2=1)
    • If the victim is something that can't be converted (ie is a god or prophet), result1=-1, result2=0
    • If the victim is immobile result=-3, result2=0
    • Otherwise you pass (result=1, result2=0)
    • Roll the morale check: if moralebase + DRN > victim's morale + DRN, you keep the result1 from above.
      • Otherwise, result1 becomes -1 if any of the following are true: this is corruption (not seduction), or the seducer's morale roll < (the victim's morale roll - 2), or result2 != 0. If none of that was true result1 becomes -2 instead
    • If result1 == 1: The seduction succeeded: "%s disappeared one night and was never seen again." etc.
    • If result1 == 0: The (dream) seduction failed. "%s tried to project %s wonderful dreams at %s, but the target resisted and no real seduction could be done." The victim's nation does NOT get a message for this one.
    • If result1 == -2: "%s tried to seduce %s, but %s could not shy away from %s duties. However %s did not want %s to get caught and did not give %s away.". But nothing else happens, and the victim's nation doesn't get told anything.
    • If result1 == -3: You failed due to "logistical reasons" and fight anyway.
    • If result1 is anything else, and result2==0, and the victim has less than 20 morale: "%s failed to %s %s and a battle ensued."
    • Any other case: "%s failed to %s %s and a battle ensued. In fact %s wasn't even remotely interested in the offer."
  • Order 61 (I think this is "Lure", the Siren/Jorogomu ability)
    • Pick a commander to assassinate.
    • This also requires mixed genders.
    • MR: attempt fails if 16 + DRN < victim MR + DRN
    • Morale: attempt fails if <lure ability value> + DRN < victim morale + DRN
    • Also fails if victim is prophet or god
    • If you succeeded this far:
      • If this attempt is using Jorogumo's 0x2a7 ability…
        • If victim's strength + DRN ⇐ 15 + DRN, you end up fighting later.
      • If the victim does not die when taken underwater, you end up fighting later.
    • All fights take place underwater (add terrain mask 4) but seemingly without setting the assassination flag and the 50% chance of darkness. This looks like it includes the Jorogumo fight if you pass the strength check, which is probably a bug
    • Much like seduction, there's a range of messages:
      • MR/Morale checks passed:
        • Jorogumo type:
          • "%s encountered an alluring woman that tried to seduce %s. But %s did not leave %s post." - Victim gets this
          • "%s failed to lure %s into her trap." - user gets this if victim has <20 morale
          • "%s failed to lure an enemy called %s into her trap. In fact %s wasn't attracted at all to this most beautiful song." - victim has 20+ morale
        • Normal type:
          • "%s managed to resist a magically alluring song that was heard from the water."
          • "%s failed to lure %s into the sea."
      • Complete Success:
        • Jorogumo type:
          • "%s successfully lured %s into the her webs and dragged him into the water where he drowned." - User
          • The victim can get two messages, with a coin flip between them: "%s disappeared one night and was never seen again. This night some people say they saw a glimpse of an extraordinarily beautiful woman." and your normal boring "%s disappeared one night and was never seen again."
        • Normal lure:
          • "%s successfully lured %s into the sea where he drowned." - User
          • Victim can have two messages:
            • 75%: "%s disappeared one night and was never seen again. This night some people heard the most beautiful song."
            • 25%: "%s disappeared one night and was never seen again."
      • Other failures:
        • Jorogumo type:
          • "%s disappeared one night when he followed an enticing young woman. He suddenly found himself trapped in spider webs, but no web is strong enough to hold %s for long. After breaking free he attacked the woman that lured him into this trap." - Victim, passed strength check
          • "%s successfully lured an enemy commander called %s into her web. Unfortunately he broke free from the web and a battle ensued." - User, passed strength check
          • "%s successfully lured an enemy commander called %s into her web. All seemed well as she dragged the helpless victim into the nearby pool of water. Unfortunately the victim later emerged unharmed from the water and attacked her." - User, victim does not die underwater
          • "%s disappeared one night when he followed an enticing young woman. He suddenly found himself trapped in spider webs and dragged into a pool of water. Unable to drown, %s could free himself as the web started to dissolve. After breaking free he emerged from the water and attacked the woman that lured him into this trap." - Victim, if does not die underwater
        • Regular lure:
          • "%s successfully lured an enemy commander called %s into the sea. Unfortunately he didn't drown and a battle ensued." - User, victim does not die underwater
          • "%s disappeared one night and entered the sea. This night some people heard the most beautiful song. %s was disappointed to find a fish being instead of the beautiful female he had envisioned. He attacked her in rage and disappointment." - Victim, when not dying underwater
  • Regular assassination: does what it says. I can't see any surprises here.
  • Seduction/regular assassinations are 50% to add what I assume is the the nighttime darkness terrain flag.
  • Looks like Jorogumo's lure can be used anywhere that isn't a waste.
  • A side's "max" hp calc (this is only for adjusting the saved value of "how much hp did my side start with", the actual work just does the hp calcs with modifications as below for slaves/pd) goes like this:
  • Get real total
  • Get tempflag1 total - I added a note saying retinue gets this flag, but pd does NOT (it's tempflag3)
  • "Permanent" total = real - tempflag1
  • if "permanent" total ⇐ tempflag1 total, templflag1 total = "permanent" total
  • Actual total of the calc = permanent + tempflag1 total
  • This is really confusing, but it's maybe the basis of the one commander and their retinue line?
  • 1x 10hp guy, 100hp of retinue
    • real=110
    • tempflag1 = 100
    • permanent = 10
    • The conditionis true, so tempflag1=10
    • actual total = 20
  • pd (temp flag=3) contribute hp/4 rounded up
  • slaves contribute hp/2 rounded up

Blastsquare (and the apostasy bug)

  • A = size points in square + open 2d6
  • A gets 999 added if battle enchant/timestop or the spell has ignore shields spec value
  • If spell doesn't have the nonmagical spec, add 2 more to A
  • B = (2 - victim fatigue/20 rounded down) + open 2d6
  • Get your shield defence/parry value, and double it.
  • If spec has either "flail spec" 4 or AN 128, shield defence/parry value = 0.
  • Calc effective shield prot: fetch the value, if spec has AP, halve it, if spell is AN or ignores shields then this is zero.
  • If spec has neither flail spec 4 or AN 128, and the victim is standing on a fort wall
    • If shield defence/parry was less than 10, set it to 10.
    • If shield prot was less than 30, set it to 30. Then, if the effect was AP, half it. (this seemingly introduces an order of operations bug - if you have a prot 36 shield vs AP, you'll use the wall bonus instead despite it being worse)
  • If you have air shield, there's a value% chance to add 100 to B.
  • If A < B, the victim avoids all damage.
  • If A < (B + the shield's parry value), you hit the shield.

FIXME look at what sets the assassination flag, very likely there is a bug in the spells that don't use it (which will cause casting AI to not have the reduced buff preference)

user/loggy/misc.txt · Last modified: 2023/12/12 13:05 by loggy