....The entanglement will automatically disappear on the 256th round after being applied. =)
In practice, this fact will, of course, not affect the outcome of the battle, but for the record... =)
Posts from The intricacies of game mechanics
I'm testing it right now: round 1134 - they're still shooting... =)
Round 1433 - everything's fine! =)
1645... I'm already falling asleep... And I'm ending the test...
Lider1, I can imagine how long that battle lasted in real time, if I've already been sitting here on auto-battle for 2 hours! )))
Unfortunately, I couldn't find any information on the forum about the AI's battle algorithm when fighting neutral creatures (I consider battles with heroes as a special case of battles with neutral creatures, which is less interesting for online play).
I have a few questions:
- What is the AI's objective in a battle at the algorithm level? To inflict maximum damage, or to eliminate the maximum number of creatures, taking into account their level? Or something else?
This is particularly interesting when the AI knows that the battle is a guaranteed loss, i.e., there is no scenario in which it can still win (3 behemoths vs. 1 behemoth, or 1 angel in a mini-dungeon).
Based on the answer, it will be possible to test several strategies for typical battles, different formations, etc. For example, a standard capture of a resource with a group stack of an army, with the main attacking ranged unit in the 6th stack. Well, almost always, the group stack of griffins flies to block the ranged unit, without attacking the ranged units themselves. Although it is precisely the ranged units that pose a threat and ultimately bring victory.
- What principle does the AI use to determine whether to attack a single unit/tank or to attack the main stack if it can reach both in one turn? I have some observations on this, but without details. For example, if the AI sees that it can kill an angel in 1-2 rounds, it will not rush to kill a "tasty" stack of spearmen, which, in terms of total HP, may be greater than the angel's HP. In the case of a main stack and a single unit, if the AI can reach both and has one stack (1 + 70 troglodytes vs. 25 centaurs), then in some cases it will attack the single unit, and in another case, it will attack the main stack (probably when it knows that it will not die in return).
- How does the AI choose its target to attack?
Sometimes you attack a ranged unit, run single units of centaurs towards the ranged units, and the computer starts attacking them instead of your ranged unit. And in another case, exactly the opposite, no matter how many single units you put in front, it shoots at the ranged units until the last one. There is definitely some pattern here, and I would like to know it. Similar situations occur with melee units, but I can't remember all of them.
- Sometimes the AI does not attack, even when it has the opportunity. Are there any rules that, if followed, will prevent the AI from attacking?
That is, magic or other obstacles are not involved. We are not talking about dragons that are afraid to expose themselves or breathe on their own, or about the first-second round of the battle "hydra vs. hive," where the little snakes scatter in different directions, fearing a simultaneous attack; in this case, the pattern is clear (although a description of all such cases would also be useful).
--
It may be difficult to get the answers from the code, but I would be glad to hear observations on this from experienced players.
Dealing maximum damage, or eliminating the maximum number of creatures while considering their level? Or something else?
1. We attack 50-99 skeletons guarding the prison.
2. 61 skeletons, including an upgraded stack of 12 skeletons.
3. We kill all stacks except for the upgraded one.
4. The upgraded stack kills our Knight, and the hero leaves us.
5. The prison guards also disappear along with our hero.
This is how SOD works.
P.S. If you run away from the upgraded stack with your hero, the story will repeat – the guards will disappear.
A story in pictures:
Many people weaken their units this way; it's a well-known trick.
For quite some time now, I have been analyzing the exe file of Heroes 3 (SoD 3.2), and I am finding quite a few interesting gameplay subtleties that seemingly no one knew about. Previously, I wrote some things in the FizMiG thread on the df2 forum, but it later became clear that FizMiG isn't going to be updated anyway, and few players visit it. I think this information will be more in demand here.
To start with, I will gradually (not all at once) go through FizMiG and write about the errors and inaccuracies in it that I know of, as well as clarify descriptions (I will only paraphrase what is already there if it is necessary for the clarity of the text). Perhaps some of the information is already known to some (including some things I posted elsewhere), but the sufficient condition for its inclusion here will be the absence, incorrectness, or insufficient accuracy of its description in FizMiG.
If anyone has specific questions—feel free to ask—I will be able to find answers to many of them.
If something seems wrong—we can discuss it; I could certainly be mistaken.
1. Starting armies and hero movement points.
A hero's starting army consists of 3 stacks: first, second, and third in the order they are listed in FizMiG. The war machine is always considered the second stack and appears according to the same rules, except that it does not disappear when the army is zeroed out or replaced by a single unit.
The first stack is always given to the hero.
The second stack is given to the hero with an 88% probability.
The third stack is given to the hero with a 25% probability.
At the start of the game, all heroes are assigned a starting army in the specified form, and movement points are calculated based on it. An army of one unit is set only after placing the hero in the tavern, and movement points are not recalculated. Because of this, for example, a Barbarian hero bought with one unit will have 1630 movement points with a 75% probability (Orcs did not arrive at the map start, minimum speed 5), and 1560 movement points with a 25% probability (Orcs arrived at the map start, minimum speed 4), while the tavern will show he has one goblin in either case.
When a hero is lost in battle, his army is first zeroed out, then his movement points are recalculated, and then he is given a standard starting army. As a result, when calculating movement points, the minimum speed of the hero's creatures is considered to be 20, and the hero is given 2000 movement points (excluding other modifiers).
Upon retreating, the army is immediately set to 1 creature, and movement points are not recalculated.
At the beginning of a new day, movement points are recalculated only for heroes belonging to players, as well as for heroes in the tavern. Consequently, if, for example, a Ranger hero had Dwarves arrive at the map start and he entered the tavern with one Centaur—if you buy him on the same day he arrives, he will have 1500 movement points, but if you make him spend the night in the tavern and buy him the next day—he will have 1700. If this hero arrived, spent the night in the tavern, was not bought, and was overwritten—he will still have 1700 movement points by the time he arrives again.
In online play, information that a hero has been bought is transmitted to inactive players immediately, while changes to heroes' armies are transmitted only during the turn handover. This includes the fact that information about replacing a hero's starting (or post-death) army with one unit upon entering the tavern is not transmitted. Because of this, inactive players see which army was generated at the start for the active player's bought heroes before the replacement by one unit. This is also taken into account in the tavern information (where the hero with the strongest value of this number is always shown: sqrt((1.0 + 0.05*(hero attack))*(1.0 + 0.05*(hero defense)))*(sum of AI Value of all creatures in the hero's army)): for example, if Galtran arrived in the tavern on the first day with 1 Skeleton and the player bought him, other players will see his starting army before the replacement by one unit, and since it is likely to be stronger than the starting armies of other heroes, other players may see him in the tavern.
At the start of the map, heroes are given a random amount of experience ranging from 40 to 90.
2. Hero Specializations.
Generally, almost everything in the specializations section of FizMiG is described well and accurately; I will only describe some points more clearly.
No secondary skill specializations work if the hero lacks the corresponding secondary skill (however, the First Aid specialization is considered a skill specialization and does not work without it, while the Ballista specialization is a creature specialization and works without the Artillery skill). If a Necromancy specialist hero does not have Necromancy but has the Cloak of the Undead King, which allows raising skeletons regardless, the specialization effect will still not be taken into account.
The specialization for the Luck spell (both Melody and Daremith) works simply: the Luck spell always gives +3 luck to target stacks, without the possibility of exceeding the maximum (3).
The Eagle Eye specialization actually adds +5% of the skill effect per hero level to the skill effect.
The Navigation specialization adds +5% to the hero's base water walking reserve (1500) per level. That is, the specialization effect does not depend on the navigation skill level (except for the fact that if the hero has no navigation skill at all, the specialization does not work) and is always equal to +75*(hero level) movement points. In FizMiG, they apparently checked only for expert navigation, which is why they wrote 2%.
3. Impossibility of learning certain secondary skills in the University.
FizMiG provides a table, but it is not entirely correct. In reality, it is simpler: a hero cannot learn those and only those secondary skills in the University where the drop chance for their class is 0. Meanwhile, in the Witch Hut and from the Scholar, a hero can learn any offered skills.
4. Spells.
- Blood for the Blood God (Bloodlust).
Bloodlust increases the attack of creatures only in melee: although the spell is cast on ranged units, its bonus is not taken into account when shooting. In the original, the attack bonus for ranged units was always displayed in the stack info window; in HD+, only when it is active, i.e., if the ranged unit can only fight in melee.
- Minefield.
The player always sees their own mines. If the hero had creatures at the start of the battle for whom the battlefield is native terrain, the player also sees enemy mines. If the player sees a mine, their creatures will not take damage when passing through it.
- Fire Shield.
Fire shield damage is calculated after all attack bonuses are calculated, but before all penalties.
That is, fire shield damage will correspond to the required percentage of damage taking into account the attack and defense bonus (if attack exceeds defense), luck, cavalry bonus, hatreds, Offense secondary skill (and specialization), Blessing specialization, and the double damage of Death Knights.
But fire shield damage is calculated without considering the attack and defense penalty (if defense exceeds attack), Psychic or Magic Elemental strikes against creatures with corresponding magic defenses, the melee penalty, the counterattack penalty after removing Blind or Paralysis, the strike against a petrified creature, the penalty for the Shield spell, and the hero's Defense secondary skill (and specialization).
After taking the required percentage of damage, it is processed by a function that modifies magic damage. Thus, fire shield damage is affected by: the hero possessing the Sphere of Raging Fire, the Wizard secondary skill and specialization, partial damage ignorance by Stone, Steel, Gold, and Diamond Golems, and the presence of the Protection from Fire spell on the stack receiving the fire shield damage.
Meanwhile, anything that affects the chance of casting the spell: resistances, immunities, cursed ground, anti-magic garrison, artifacts that forbid casting—does not affect receiving damage from the fire shield. The only exception is that the fire shield does not work on creatures immune to fire (Ifrits, Fire Elementals, Fire Birds, and upgraded versions of these entities).
Fire shield damage is calculated and dealt identically for a creature under the corresponding spell and for Ifrit Sultans. If the Fire Shield spell is cast on Ifrit Sultans (for example, via the Medal of Vulnerability), the modifier used is the percentage of damage corresponding to the spell (20% - 20% - 25% - 30%); otherwise, it is always 20%.
- Clone.
Order of hex checking when summoning a clone (hexes are checked in increasing order of their numbers; the clone is placed on the first free one).
For a single-cell unit:
https://www.dropbox.com/s/45dxj8e8geudsm2/clone1.jpg
For a 2-cell unit (cells with numbers are the rear part of the summoned clone):
https://www.dropbox.com/s/dl8cxnvm3xl9427/clone2.jpg
If the stack is facing the opposite direction of the arrow, the diagram is mirrored horizontally.
If the clone cannot be placed on any of the marked hexes, it is not summoned at all (and a corresponding message is shown).
Additionally, two-cell units have peculiarities that are game bugs (fixed in HD+):
If hex 11 on the diagram is free, then check 11, as well as intermediate checks between 21 and 22; 31 and 32; 41 and 42; 51 and 52; 61 and 62; 71 and 72; 81 and 82; 91 and 92 pass, and the clone is "summoned" to cell 11 (partially overlapping the cloned stack). In this case, the clone itself is invisible and non-interactive, does not participate in battle, and the cloned stack becomes invisible until the first action.
Regardless of occupied hexes, if the check reaches 28, 38, 48, 58, 68, 78, 88, or 98, the clone immediately attempts to summon onto the cell of the cloned stack; it is not summoned, but the cloned stack will disappear after the spell duration expires or after the battle.
- Quicksand.
Quicksand does not affect flying creatures.
Once a non-flying creature steps on quicksand, its turn ends immediately, and it cannot move further or attack.
The player always sees their own quicksand. If the hero had creatures at the start of the battle for whom the battlefield is native terrain, the player also sees enemy quicksand. If a player moves a non-flying creature onto quicksand that was previously invisible to them—that quicksand becomes visible. If the player sees quicksand, their creatures will always route their movement to avoid it (meaning you don't have to worry about a creature passing through visible quicksand—if a hex is marked as available by the movement shadow, the stack will reach it, bypassing all visible quicksand).
During a castle siege, the AI evaluates quicksand the same way as a moat (even if the castle has no moat): if the AI believes the moat would deal too much damage to the stack, it will similarly fear stepping on quicksand.
- Hypnosis.
In many battle calculations, a hypnotized creature is considered friendly: for example, the Offense, Archery, and Defense secondary skills of the controlling player apply to it, rather than the owner's. I won't compile a full list of modifiers yet, as it's tedious and not necessarily needed.
- Magic Mirror.
Magic Mirror only works with spells cast by human heroes. Spells cast by AI stacks or heroes cannot be redirected by the Magic Mirror. However, when calculating the value of a hero's spellcasting (but not stacks), the AI takes into account the Magic Mirror on the target, and its desire to cast on a stack protected by a Magic Mirror drops significantly (specifically, if the reflection chance is 50%, the AI equates the value of casting on such a stack to 0), despite the fact that the mirror never triggers when an AI hero casts.
The stack to which the spell is reflected is chosen randomly from all non-killed stacks of the casting side that are not shooting towers. If casting this spell on that stack is impossible, it will have no effect.
Fairy Dragons have a Magic Mirror effect identical to a spell cast without the elemental skill (i.e., 20%). If Magic Mirror is cast on a Fairy Dragon, the maximum of the effects is taken (i.e., effectively the spell effect will always override the innate mirror, which in this case ceases to provide any effect). If no external Magic Mirror is cast on Fairy Dragons, the AI does not consider their innate mirror when calculating the value of a hero's spellcasting.
5. Creatures.
- Pegasus, Silver Pegasus.
If the hero had Pegasi or Silver Pegasi in their army at the start of the battle, opponent spells will cost 2 more until the end of the battle.
- Unicorn, War Unicorn.
The magic resistance aura does not add 20% to the chance to reflect a spell, but multiplies the chance of the spell being cast by 0.8. The number of unicorn stacks nearby does not matter—the aura is either present or not.
- Mage, Archmage.
Does not suffer a penalty for shooting over fortress walls.
If the hero had mages or archmages in their army at the start of the battle, their spells will cost 2 less until the end of the battle.
- Master Djinn, Sorcerer.
The Master Djinn chooses a spell from all existing long-term spells intended for a friendly stack, plus healing (flag 0x00000008). Spells that cannot be cast (at all or due to stack immunity), those already cast on the stack, and those the djinn doesn't deem right to cast (see below) are not considered. A spell is chosen randomly from all eligible ones, with equal chances for each. For casting, the AI calculates average utility across all possible spells. Casts at advanced level with 6 spell power.
The Sorcerer chooses a spell from the following list with the specified weights, excluding those that cannot be cast on each stack, are already cast, or are deemed useless by the Sorcerer (same logic as the master djinn).
Haste: 15
Air Shield: 10
Slow: 10
Stone Skin: 15
Bloodlust: 5
Blessing: 15
Healing: 10
Weakness: 4
The specified weight values are not percentages, but indicators. Calculate the chance as: (spell indicator)/(sum of indicators of all possible spells for casting). For example, the chance for Haste when all spells are available would be 15/84.
Casts with spell power 3 at expert level.
Now regarding the determination of casting appropriateness:
Elemental Protections, Anti-Magic, and Magic Mirror: only if the enemy has a hero and that hero has a Spellbook.
Healing: only if the target has lost health.
Prayer: only if the target has not yet acted in this round (waiting is not considered an action).
Executioner: only if the enemy has creatures susceptible to basic Executioner (including already dead)—this is a game bug, because Master Djinn casting occurs at advanced level (Sorcerers do not cast Executioner).
Shield and Fire Shield: only if the enemy has stacks that are not killed, blinded, petrified, paralyzed, and currently cannot shoot (blocked shooters etc. are also counted).
Air Shield: only if the enemy has stacks that are not killed, blinded, petrified, paralyzed, and currently can shoot (blocked shooters etc. are not counted).
Precision: only if the target stack can currently shoot (a blocked shooter etc. is not counted).
Bloodlust: only if the target stack currently cannot shoot (a blocked shooter etc. is also counted).
Other spells (including all spells cast on opponents for Sorcerers) are, in the opinion of mage creatures, always worth casting if they are not already on the stack and can generally be cast on it.
- Black Knight, Death Knight, Mummy.
Upon striking, they cast basic Curse on the attacked unit with a 25% chance.
- Troglodyte, Hell Troglodyte.
Immune not only to Blindness, but also to Petrify (from Medusas and Basilisks).
- Scorpikora.
Scorpikora's paralysis works like advanced Blindness: the counterattack damage of a paralyzed creature is reduced 4 times. If the creature is also blinded, the effects multiply.
- Ifrit Sultan.
Fire shield damage for Ifrit Sultans is calculated and dealt the same as for a creature under the corresponding spell. See details in the Fire Shield spell description.
- Ogre Mage.
Casts advanced Bloodlust for 6 rounds.
- Mighty Gorgon.
After a strike, the deadly gaze triggers: each creature from the attacking squad has a 10% chance to kill a creature in the attacked squad, but the total number of killed creatures cannot exceed (number of creatures in the attacking squad)/10 (rounded up).
- Monarch Wyvern.
After a strike, there is a 30% probability that poison will be applied for 3 rounds to the attacked stack, provided it is a living creature, in playfortuna casino. Immediately upon application, as well as at the start of each round, the poison removes 10% of the stack's maximum health until the end of the battle, but totaling no more than 50% for all poison throughout the battle. If poison is applied to a creature already poisoned, its duration is extended, but no additional health reduction occurs upon application. Poison and Old Age effects multiply.
- Phoenix.
Resurrects once per battle immediately after death. Number of resurrected Phoenixes in a stack: (number of creatures at the start of battle)/5 + X, where X is calculated as follows: take the number of phoenixes equal to the remainder of dividing the number of creatures in the stack at the start of battle by 5, and each of them has a 20% chance to resurrect. For example, if there were 19 phoenixes, 3 phoenixes will definitely resurrect, and among the remaining 4, each has a 20% chance to resurrect. With great luck, all 7 could resurrect.
- Sorcerer.
Regarding cast spells—see the section on Master Djinn and Sorcerer.
Does not suffer a penalty for shooting over fortress walls.
- Fairy Dragon.
When receiving a turn (at the start of a round or after waiting), a spell that the Fairy Dragon can cast is generated.
Drop chances for various spells for the fairy dragon in the original:It is easy to notice that spell IDs are used as chances. This is a game bug—correct chances are programmed in, but they aren't used. The bug is fixed in HD+.
- Ice Bolt: 16/153
- Lightning Bolt: 17/153
- Fireball: 21/153
- Magic Arrow: 15/153
- Ring of Frost: 20/153
- Chain Lightning: 19/153
- Meteor Shower: 23/153
- Inferno: 22/153
Drop chances for various spells for the fairy dragon in HD+:Fairy Dragons have a Magic Mirror effect identical to a spell cast without the elemental skill (i.e., 20%). See details in the Magic Mirror spell description.
- Ice Bolt: 22%
- Lightning Bolt: 22%
- Fireball: 21%
- Magic Arrow: 10%
- Ring of Frost: 10%
- Chain Lightning: 5%
- Meteor Shower: 5%
- Inferno: 5%
- Rust Dragon.
Acid breath consists of 2 parts: the first is cast on the attacked stack with non-zero defense upon any hit and reduces its defense by 3. The second part is cast after the first with a 20% probability and deals damage equal to (number of attacking creatures)*(random number from the creature's minimum damage to maximum)/2. Since the Rust Dragon's damage is 50, the second part of acid breath always deals 25*(number of attacking creatures) damage. This damage affects all creatures, and no modifiers influence it.
- Azure Dragon.
Fear: every creature, except those immune to morale and Azure Dragons themselves, has a 10% chance to skip its turn (chance is calculated separately from negative morale) if there is at least 1 Azure Dragon in the enemy army. If all Azure Dragons in the army are destroyed, the fear effect stops.
Azure Dragons are actually subject to morale—there is an error in FizMiG.
6. Weeks and months of creatures and plagues.
When generating a new week, in 25% of cases, +5 monster units occur, and in 75%—nothing (anteaters etc. are not equivalent to monsters and are generated separately during these 75%).
Only monsters belonging to the town can appear.
When generating a new month, in 50% of cases nothing happens (earthworms etc.), in 40% a monster is generated, and in 10%—a plague.
Difficulty level has no effect. The only thing is that in tutorials, monsters and plagues cannot appear at all.
Monsters are indeed taken from the 12 specified in FizMiG. Drop chances for each are equal.
Number of monsters = (random number from the minimum number of monsters on the map at the start of the game to the maximum number of monsters on the map at the start of the game) * 2; if it is greater than 4095, it is capped at 4095.
Minimum and maximum quantities can be seen in crtraits.txt. They are common for all city creatures of the same levels. For example, 1st upgrade: 20-50, 1st grade: 20-30, 7th grade: 3-8.
The aggressiveness of appearing monsters is random—from 1 to 10 with equal chances; these monsters can always increase in number and retreat.
The number of monsters appearing on the map is not fixed; every available (non-water etc.) map cell has a 0.5% chance that a monster will appear on it. Thus, theoretically, monsters could appear on all cells at once or on none.
Excellent breakdown of mechanics; it's always interesting to find such nuances in old games that few people knew about. Regarding the recalculation of hero movement points—that really is a subtle point that introduces a certain strategy into planning the first moves.
Another interesting detail related to this is the influence of native terrain. If a hero starts on their native terrain, the movement bonus can produce unexpected results. For example, a barbarian on sand or snow receives a penalty, whereas a knight in grass gets a slight advantage instead. This is especially important on templates with diverse terrain, where a situation can arise where a hero "loses" movement simply due to a change in terrain type after losing their army.
Regarding clones—I once encountered a bug where the clone disappeared immediately after being summoned if there were obstacles nearby. Apparently, this is exactly related to the cell checking order you described. Have you noticed any patterns in how exactly the clone chooses a spot if there are several possible options?