Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- This script has been tested with Ironfist version 1.3.0
-- Script Name: _MapName.MX2.lua (temp)
-- Script version: v0.314 - 20181208 (temp)
-- Map Name: _MapName.MX2 (temp)
-- Author: Unknown_Hero (LeHerosInconnu on GitHub)
-- Description:
-- This script is designed to work in a global way with any scenario. Since Project Ironfist does not yet support global scripts, you will have to rename this script with the name of the scenario each time
-- you want to play another scenario, for example, rename "_MapName.MX2.lua" to "ENROTH.MP2.lua" to use the script with ENROTH scenario.
-- I suggest you play on small maps at the moment because the autosave time is too long and hard to bear.
-- Also, due to the bug of unloaded tables from a save file (or autosave file) in Ironfist version 1.3.0, you have to play the scenario in one go or problems will occur. So if the program crashes, the game is dead.
-- What it does:
-- ***** Changes in general.
-- Set the spell points to maximum for all heroes at start of scenario, this only works for the 54 heroes in pool for now.
-- The hero without Magic Book can buy one at any shrine.
-- Once a day, the hero recovers some spell points when he visits a shrine.
-- The hero can choose whether or not to keep the secondary skill he learns at any witch's hut when he leaves it.
-- The hero can upgrade his archers, orcs, dwarves, trolls, liches, green dragons, red dragons at the corresponding creature generator on the adventure map for a cost when he leaves it.
-- Initially, for the trolls, liches and dragons, I wanted the ability to upgrade creatures to be possible only if creatures defending creature generators are defeated, but it works without this condition for now.
-- The hero can train his peasants at the hill fort for a cost (disabled).
-- ***** Changes to Heroes.
-- At the beginning of each combat, the hero with a magic book recovers a number of spell points corresponding to 5 spell points multiplied by the initial value of the knowledge of his class
-- (Knowledge 1 for Knight and Barbarian, Knowledge 2 for Warlock, Wizard and Necromancer, Knowledge 3 for Sorceress).
-- Knight Hero:
-- Recovers 5 spell points at start of combat (only with magic book).
-- Barbarian Hero:
-- Recovers 5 spell points at start of combat (only with magic book).
-- Sorceress Hero:
-- Recovers 15 spell points at start of combat (only with magic book).
-- Warlock Hero:
-- Recovers 10 spell points at start of combat (only with magic book).
-- Wizard Hero:
-- Recovers 10 spell points at start of combat (only with magic book).
-- Wizard Hero special bonus: Wizard Hero recovers 2 extra spell points per day on the adventure map.
-- Wizard Hero special bonus: Wizard Hero recovers 5 extra spell points at start of combat.
-- Necromancer Hero:
-- Recovers 10 spell points at start of combat (only with magic book).
-- ***** Tweaks to Secondary Skills.
-- Tweaks: Mysticism gives additional spell points each day on the adventure map (this only works for the 54 heroes in pool for now) and at the start of each combat.
-- Tweaks: Navigation also generates gold every turn.
-- Tweaks: Basic Estates, small adjustment to stay better than Basic Navigation.
-- ***** Changes to creatures.
-- Each peasant generates 1 gold per day (only in the hero's army for now)(disabled).
-- ***** Tweaks for Artifacts.
-- Tweaks: Some artifacts give extra point(s) for Spell Power and Knowledge.
-- +1 Spell Power: Evil Eye, Enchanted Hourglass, Skullcap, Evercold Icicle, Everhot Lava Rock, Lighting Rod, Snake Ring, Elemental Ring.
-- +1 Knowledge: Gold Watch, Ice Cloak, Fire Cloak, Lightning Helm, Ankh, Book of Elements, Holy Pendant, Pendant of Free Will, Pendant of Life, Serenity Pendant, Seeing-eye Pendant, Kinetic Pendant, Pendant of Death,
-- Wand of Negation, Broach of Shielding, Crystal Ball, Spade of Necromancy.
-- +2 Spell Power: Wizard's Hat, Power Ring.
-- +2 Knowledge: Heart of Fire, Heart of Ice, Sphere of Negation.
-- This only works for the 54 heroes in pool for now.
-- Spell power and Knowledge values are updated only when any heroes move.
-- This modifies the disposition of the artifacts in the hero's inventory made by the player.
-- A complete artifacts.xml file to directly modify the values is necessary to avoid this and would be much simpler.
-- In addition, the bug linked to the artesian spring effect is activated as soon as a hero moves after a visit by a hero to the artesian spring (any "moved" artifact in the inventory removes spell points above the maximum).
-- Fixed the activation of the bug linked to the artesian spring effect for this case.
-- Tweaks: The Power Ring artifact gives 2 extra spell points per day on the adventure map (total of 4 spell points with the original effect).
-- Tweaks: The Power Ring artifact gives 10 extra spell points at start of combat.
-- ***** Spoilers - Start. *****
-- ***** Do not read this if you want to have some surprises during the game. ;-) *****
-- ***** Spoilers - Start. *****
-- ***** Tweaks for artifacts, effects according to the class of the hero.
-- Necromancer Hero:
-- Once per city of dead, the Necromancer hero with the Power Ring artifact gets +1 Spell Power and +1 Knowledge when he is the first to visit the city of dead.
-- Once a day, the Necromancer hero with the Power Ring artifact recovers all his spell points when he visits certain locations on the adventure map (excavation, graveyard, pyramid, barrow mounds, daemon cave, city of dead).
-- For now, it only works for the 54 heroes in pool (or specified names)(disabled for barrow mounds).
-- The Necromancer hero with the Pendant of Death artifact can upgrade his zombies at the graveyard, his mummies at the pyramid, his vampires at the daemon cave, all undead creatures at the city of dead
-- on the adventure map for free.
-- Once per certain locations on the adventure map (excavation, graveyard, pyramid, barrow mounds, daemon cave, city of dead), the Necromancer hero with the Spade of Necromancy artifact can raise undead creatures
-- when he is the first to visit the location, skeletons when he visits an excavation, mutant zombies or zombies when he visits a graveyard, royal mummies or mummies when he visits a pyramid,
-- vampire lords or vampires when he visits a daemon cave, ghosts when he visits a barrow mounds and power liches or liches when he visits the city of dead.
-- For now, it only works for the 54 heroes in pool (or specified names)(disabled for barrow mounds).
-- The Necromancer hero with the Ankh artifact can transform the living creatures of the same type present in his army into the corresponding undead creatures when he visits a creature generator on the adventure map,
-- living creatures of level 1 when he visits an excavation, living creatures of level 1 and 2 when he visits a graveyard, living creatures of level 1 to 3 when he visits a pyramid,
-- living creatures of level 1 to 4 when he visits a daemon cave and living creatures of all levels when he visits the city of dead, when he leaves the location.
-- For now, it only works for the 54 heroes in pool (or specified names).
-- ***** Spoilers - End. *****
-- ***** Spoilers - End. *****
-- All is not perfect, for example, the hero must leave the square where the witch's hut is located to decide whether or not to keep the secondary skill he has just learned, but it is not possible to do otherwise
-- with what is available for now with the Project Ironfist tool, here GetLocationSecondarySkill() would have allowed to avoid this.
-- Similar problem for the possibility to upgrade creatures at the corresponding creature generators on the adventure map (the hero must get the free troops before he can upgrade them),
-- or when a hero must leave a square to proceed a verification, here, the instruction "WaitEndOfEvent()" would have been perfect to avoid this.
-- Problems encountered:
-- Bug with tables in 1.3.0!!! The tables are ignored when loading a save file!!!
-- The table "shrineVisitedDay" is not filled by the heroes controlled by the AI player (if the two players are controlled by human players, it works fine).
-- The table "secondarySkillLevel" is not filled by the heroes controlled by the AI player (if the two players are controlled by human players, it works fine), in this case it is less important.
-- The table "creatureGeneratorMapVisited" is not filled by the heroes controlled by the AI player (if the two players are controlled by human players, it works fine).
-- Generally speaking, AI-controlled heroes do not trigger the function OnLocationVisit(type, x, y) when they visit a location on the map.
-- I would like them to do it and I wish I could control the effects for AI-controlled heroes with a function like IsHeroControlledByAI(hero).
-- CREATURE_PEASANT or 0 do not work in 1.3.0!!! (fixed for the next version).
-- Barrow Mounds, Earth Summoning Altar, Air Summoning Altar, Fire Summoning Altar and Water Summoning Altar locations are still missing in the locations list for 1.3.0!!!
-- Questions:
-- How to make "Advanced Message Box" work like "Question Box"?
-- Do heroes controlled by the AI player get the same bonuses (they don't fill the table)?
-- Settings:
-- All options are enabled by default and can be turned off individually, set to "0" to turn the option off.
-- You can also change the values at your convenience.
-- Limitations:
-- The hero loses the ability to choose whether or not to keep the secondary skill he learns at a witch's hut when he uses the "Town Gate", "Dimension Door" or "Town Portal" spell
-- and he is still on the square where is located the witch's hut, or when he is teleported to another square by a script instruction, or if he disappears from the map (loses a combat, retreats during combat, etc.).
-- A hero with the same name as the hero located on the square of the witch's hut will trigger the choice window if he moves to a hexagon adjacent to the witch's hut.
-- To my knowledge, only the french scenario "Faux Semblants" offers two heroes with the same name.
-- The same when a hero must leave a square to proceed a verification.
-- ToDo:
-- The hero can train his peasants to archers or rangers or pikemen or veteran pikemen at the hill fort. --> Replace CREATURE_GOBLIN, numberPeasant) by CREATURE_PEASANT.
-- Each peasant generates 1 gold per day (only in the hero's army for now). --> Replace CREATURE_GOBLIN, numberPeasant) by CREATURE_PEASANT.
-- AdvMessageBox = require("scripts.modules.AdvMessageBox").
-- Voir nécro et ankh demeures undead demeures living (enters, leaves).
-- Déplacer automatiquement le magic book dans le slot 1. ????
-- Tweaks: Mysticism gives additional spell points each day on the adventure map and at the start of each combat. -- This only works for the 54 heroes in pool for now, add hired heroes with different portraits.
-- Change name by heroNumberPool where possible.
-- Remplacer les valeurs de longueur de table par numEntries.
-- Note:
-- Ramasser un artefact ou obtenir un artefact après un combat ne déclenche pas the bug linked to the Artesian Spring effect (any "moved" artifact in the inventory removes spell points above the maximum).
-- Set the spell points to maximum for all heroes at start of scenario, this only works for the 54 heroes in pool for now.
setMaxSpellPointsStartOn = 1;
-- The hero without Magic Book can buy one at any shrine.
magicBookOn = 1;
costMagicBook = 500;
-- Once a day, the hero recovers some spell points when he visits a shrine.
shrineOn = 1;
shrineFirstPoints = 10;
shrineSecondPoints = 20;
shrineThirdPoints = 30;
shrineVisitedDay = {};
-- The hero can choose whether or not to keep the secondary skill he learns at any witch's hut when he leaves it.
choiceWitchHutOn = 1;
secondarySkillLevel = {};
-- The hero can upgrade his archers, orcs, dwarves, trolls, liches, green dragons, red dragons at the corresponding creature generator on the adventure map for a cost when he leaves it.
upgradeCreatureLocationOn = 1;
upgradeArcherArchersHouse = 1;
upgradeOrcWatchTower = 1;
upgradeDwarfDwarfCottage = 1;
upgradeTrollTrollBridge = 1;
upgradeLichCityOfDead = 1;
upgradeDragonDragonCity = 1;
costMultiplier = 2;
creatureGeneratorMapVisited = {};
-- The hero can train his peasants at the hill fort for a cost (disabled). -- CREATURE_PEASANT or 0 do not work in 1.3.0!!!
peasantTrainingOn = 0; -- CREATURE_PEASANT is broken in 1.3.0!!!!
costTrainingMultiplier = 1;
captainsFees = 0.1;
crudeCaptainOn = 1;
crudeCaptainFrequency = 100;
-- At the beginning of each combat, the hero with a magic book recovers a number of spell points corresponding to 5 spell points multiplied by the initial value of the knowledge of his class
-- (Knowledge 1 for Knight and Barbarian, Knowledge 2 for Warlock, Wizard and Necromancer, Knowledge 3 for Sorceress).
startCombatSpellPointOn = 1;
startCombatSpellPointKnight = 1;
startCombatSpellPointBarbarian = 1;
startCombatSpellPointSorceress = 1;
startCombatSpellPointWarlock = 1;
startCombatSpellPointWizard = 1;
startCombatSpellPointNecromancer = 1;
startCombatSpellPointBonus = 5;
isBattle = 0;
-- Wizard Hero special bonus: Wizard Hero recovers 2 extra spell points per day on the adventure map.
-- Wizard Hero special bonus: Wizard Hero recovers 5 extra spell points at start of combat.
specialBonusSpellPointWizardOn = 1;
specialBonusSpellPointAdventureWizard = 2; -- or 4 points?
specialBonusSpellPointCombatWizard = 5; -- or 10 points?
isHeroInPool = 0;
-- Tweaks: Mysticism gives additional spell points each day on the adventure map (this only works for the 54 heroes in pool for now) and at the start of each combat.
mysticismAdventureOn = 1;
mysticismAdventureBasic = 1;
mysticismAdventureAdvanced = 2;
mysticismAdventureExpert = 3;
mysticismCombatOn = 1;
mysticismCombatBasic = 5;
mysticismCombatAdvanced = 10;
mysticismCombatExpert = 15;
-- Tweaks: Navigation also generates gold every turn.
navigationGoldOn = 1;
navigationGoldBasic = 100;
navigationGoldAdvanced = 200;
navigationGoldExpert = 300;
-- Tweaks: Basic Estates, small adjustment to stay better than Basic Navigation.
estatesAdjustmentOn = 1;
estatesAdjustmentBasic = 25;
-- Each peasant generates 1 gold per day (only in the hero's army for now)(disabled). -- CREATURE_PEASANT or 0 do not work in 1.3.0!!!
peasantGoldOn = 0; -- CREATURE_PEASANT is broken in 1.3.0!!!!
peasantGoldDay = 1;
-- Tweaks: Some artifacts give extra point(s) for Spell Power and Knowledge.
-- This only works for the 54 heroes in pool for now.
-- Spell power and Knowledge values are updated only when any heroes move.
-- This modifies the disposition of the artifacts in the hero's inventory made by the player.
-- A complete artifacts.xml file to directly modify the values is necessary to avoid this and would be much simpler.
-- In addition, the bug linked to the artesian spring effect is activated as soon as a hero moves after a visit by a hero to the artesian spring (any "moved" artifact in the inventory removes spell points above the maximum).
-- Fixed the activation of the bug linked to the artesian spring effect for this case.
tweaksArtifactSpellPowerKnowledgeOn = 1;
heroSpellPowerKnowledgeGiven = {};
tweaksArtifactSpellPower1 = {ARTIFACT_EVIL_EYE, ARTIFACT_ENCHANTED_HOURGLASS, ARTIFACT_SKULLCAP, ARTIFACT_EVERCOLD_ICICLE, ARTIFACT_EVERHOT_LAVA_ROCK, ARTIFACT_LIGHTNING_ROD, ARTIFACT_SNAKE_RING, ARTIFACT_ELEMENTAL_RING};
tweaksArtifactKnowledge1 = {ARTIFACT_GOLD_WATCH, ARTIFACT_ICE_CLOAK, ARTIFACT_FIRE_CLOAK, ARTIFACT_LIGHTNING_HELM, ARTIFACT_ANKH, ARTIFACT_BOOK_OF_ELEMENTS, ARTIFACT_HOLY_PENDANT, ARTIFACT_PENDANT_OF_FREE_WILL,
ARTIFACT_PENDANT_OF_LIFE, ARTIFACT_SERENITY_PENDANT, ARTIFACT_SEEING_EYE_PENDANT, ARTIFACT_KINETIC_PENDANT, ARTIFACT_PENDANT_OF_DEATH, ARTIFACT_WAND_OF_NEGATION,
ARTIFACT_BROACH_OF_SHIELDING, ARTIFACT_CRYSTAL_BALL, ARTIFACT_SPADE_OF_NECROMANCY};
tweaksArtifactSpellPower2 = {ARTIFACT_WIZARDS_HAT, ARTIFACT_POWER_RING};
tweaksArtifactKnowledge2 = {ARTIFACT_HEART_OF_FIRE, ARTIFACT_HEART_OF_ICE, ARTIFACT_SPHERE_OF_NEGATION};
-- Tweaks: The Power Ring artifact gives 2 extra spell points per day on the adventure map (total of 4 spell points with the original effect).
tweaksSpellPointAdventurePowerRingOn = 1;
tweaksSpellPointAdventurePowerRing = 2;
-- Tweaks: The Power Ring artifact gives 10 extra spell points at start of combat.
tweaksSpellPointCombatPowerRingOn = 1;
tweaksSpellPointCombatPowerRing = 10;
-- Once per city of dead, the Necromancer hero with the Power Ring artifact gets +1 Spell Power and +1 Knowledge when he is the first to visit the city of dead.
necromancerCityOfDeadPowerRingOn = 1;
necromancerCityOfDeadVisitedPowerRing = {};
-- Once a day, the Necromancer hero with the Power Ring artifact recovers all his spell points when he visits certain locations on the adventure map (excavation, graveyard, pyramid, barrow mounds, daemon cave, city of dead).
necromancerLocationPowerRingOn = 1;
necromancerExcavationPowerRing = 1;
necromancerGraveyardPowerRing = 1;
necromancerPyramidPowerRing = 1;
necromancerBarrowMoundsPowerRing = 1; -- Barrow Mounds is still missing in the locations list for 1.3.0!!!
necromancerDaemonCavePowerRing = 1;
necromancerCityOfDeadPowerRing = 1;
locationVisitedPowerRing = {};
-- The Necromancer hero with the Pendant of Death artifact can upgrade his zombies at the graveyard, his mummies at the pyramid, his vampires at the daemon cave, all undead creatures at the city of dead
-- on the adventure map for free.
necromancerUndeadUpgradePendantOfDeathOn = 1;
necromancerZombieUpgradePendantOfDeath = 1;
necromancerMummyUpgradePendantOfDeath = 1;
necromancerVampireUpgradePendantOfDeath = 1;
necromancerLichUpgradePendantOfDeath = 1;
-- Once per certain locations on the adventure map (excavation, graveyard, pyramid, barrow mounds, daemon cave, city of dead), the Necromancer hero with the Spade of Necromancy artifact can raise undead creatures
-- when he is the first to visit the location, skeletons when he visits an excavation, mutant zombies or zombies when he visits a graveyard, royal mummies or mummies when he visits a pyramid,
-- vampire lords or vampires when he visits a daemon cave, ghosts when he visits a barrow mounds and power liches or liches when he visits the city of dead.
-- For now, it only works for the 54 heroes in pool (or specified names)(disabled for barrow mounds).
necromancerLocationSpadeOfNecromancyOn = 1;
necromancerExcavationSpadeOfNecromancy = 1;
necromancerGraveyardSpadeOfNecromancy = 1;
necromancerPyramidSpadeOfNecromancy = 1;
necromancerBarrowMoundsSpadeOfNecromancy = 1; -- Barrow Mounds is still missing in the locations list for 1.3.0!!!
necromancerDaemonCaveSpadeOfNecromancy = 1;
necromancerCityOfDeadSpadeOfNecromancy = 1;
-- quantityTroopBoneDragon = 1;----
quantityTroopPowerLich = 2;
quantityTroopLich = 2;
quantityTroopVampireLord = 3;
quantityTroopVampire = 3;
quantityTroopRoyalMummy = 4;
quantityTroopMummy = 4;
quantityTroopMutantZombie = 6;
quantityTroopZombie = 6;
quantityTroopSkeleton = 10;
quantityTroopGhost = 3;
multiplierBonusSpadeOfNecromancy = 3;
locationVisitedSpadeOfNecromancy = {};
-- The Necromancer hero with the Ankh artifact can transform the living creatures of the same type present in his army into the corresponding undead creatures when he visits a creature generator on the adventure map,
-- living creatures of level 1 when he visits an excavation, living creatures of level 1 and 2 when he visits a graveyard, living creatures of level 1 to 3 when he visits a pyramid,
-- living creatures of level 1 to 4 when he visits a daemon cave and living creatures of all levels when he visits the city of dead, when he leaves the location.
-- Add Barrow Mounds (special only when adjustment for ghost applied), Earth Summoning Altar, Air Summoning Altar, Fire Summoning Altar and Water Summoning Altar,
-- these locations are still missing in the locations list for 1.3.0!!!
necromancerLocationAnkhOn = 1;
necromancerArchersHouseAnkh = 1;
necromancerWatchTowerAnkh = 1;
necromancerDwarfCottageAnkh = 1;
necromancerTrollBridgeAnkh = 1;
necromancerCityOfDeadAnkh = 1;
necromancerDragonCityAnkh = 1;
necromancerPeasantHutAnkh = 1;
necromancerGoblinHutAnkh = 1;
necromancerTreeHouseAnkh = 1;
necromancerTreeCityAnkh = 1;
necromancerCaveAnkh = 1;
necromancerHalflingHoleAnkh = 1;
necromancerWagonCampAnkh = 1;
necromancerDesertTentAnkh = 1;
necromancerAncientLampAnkh = 1;
necromancerRuinsAnkh = 1;
-- necromancerEarthSummoningAltarAnkh = 1;
-- necromancerAirSummoningAltarAnkh = 1;
-- necromancerFireSummoningAltarAnkh = 1;
-- necromancerWaterSummoningAltarAnkh = 1;
necromancerExcavationAnkh = 1;
necromancerGraveyardAnkh = 1;
necromancerPyramidAnkh = 1;
necromancerDaemonCaveAnkh = 1;
necromancerBarrowMoundsAnkh = 0; -- (special only when adjustment for ghost applied) -- and Barrow Mounds is still missing in the locations list for 1.3.0!!!
locationVisitedAnkh = {};
--MessageBox("Script loaded.");----
levelCreatureReference = {1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 1, 2, 2, 3, 4, 4, 5, 5, 6, 1, 2, 2, 3, 3, 4, 4, 5, 6, 1, 2, 3, 4, 4 ,5, 6, 6, 6, 1, 2, 3, 3, 4, 5, 5, 6, 6, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 1, 2, 4, 6, 3, 5, 5, 5, 5};
-- Palliative for lack of built-in function, GetHeroClass(hero) or GetHeroFaction(hero) would be nice - start.
-- It only works with the 54 heroes in pool for now and names in the various hero name tables, the list is not exhaustive.
nameHeroKnight = {"Corlagon", "Lord Halton", "Roland", "Lord Alberon", "Ceallach", "Gallavant", "Lord Kraeger"};
nameHeroBarbarian = {"Uncle Ivan", "Ivan II", "Ivan III", "Ivan IV", "Jarkonas"};
nameHeroSorceress = {"Sister Eliza", "Drakonia", "Iciria", "Druid Queen"};
nameHeroWarlock = {"Archibald", "Dainwin", "Elderian", "Martine", "Zaggath", "DragonMaster"};
nameHeroWizard = {"Roland", "Jarkonas VI", "Joseph", "Solmyr"};
nameHeroNecromancer = {"Brother Brax", "Drakonia", "Ibn Fadlan", "Mog"};
for i = 0, 53 do
hero = GetHeroInPool(i);
name = hero.name;
if i >= 0 and i <= 8 then
table.insert(nameHeroKnight, 1, name);
elseif i >= 9 and i <= 17 then
table.insert(nameHeroBarbarian, 1, name);
elseif i >= 18 and i <= 26 then
table.insert(nameHeroSorceress, 1, name);
elseif i >= 27 and i <= 35 then
table.insert(nameHeroWarlock, 1, name);
elseif i >= 36 and i <= 44 then
table.insert(nameHeroWizard, 1, name);
elseif i >= 45 and i <= 53 then
table.insert(nameHeroNecromancer, 1, name);
end;
end;
function HeroClass()
if isBattle == 0 and isHeroInPool == 0 then
hero = GetCurrentHero();
name = hero.name;
end;
for i = 1, #nameHeroKnight do
if name == nameHeroKnight[i] then
return "knight";
end;
end;
for i = 1, #nameHeroBarbarian do
if name == nameHeroBarbarian[i] then
return "barbarian";
end;
end;
for i = 1, #nameHeroSorceress do
if name == nameHeroSorceress[i] then
return "sorceress";
end;
end;
for i = 1, #nameHeroWarlock do
if name == nameHeroWarlock[i] then
return "warlock";
end;
end;
for i = 1, #nameHeroWizard do
if name == nameHeroWizard[i] then
return "wizard";
end;
end;
for i = 1, #nameHeroNecromancer do
if name == nameHeroNecromancer[i] then
return "necromancer";
end;
end;
end
-- Palliative for lack of built-in function, GetHeroClass(hero) or GetHeroFaction(hero) would be nice - end.
-- The table of heroes who visited an artesian spring and got the bonus.
heroArtesianSpringVisited = {};
-- This fills the table of heroes who visited an artesian spring and got the bonus.
function HeroOverMaxSpellPointsArtesianSpring()
for i = 0, 53 do
hero = GetHeroInPool(i);
heroNumberPool = i;
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
points = hero.spellpoints;
alreadyVisited = 0;
numEntries = 2;
if points == maxPoints * 2 then
if #heroArtesianSpringVisited > 0 then
for j = 1, (#heroArtesianSpringVisited / numEntries) do
k = (j * numEntries) - numEntries;
if heroArtesianSpringVisited[1 + k] == heroNumberPool then
alreadyVisited = 1;
break;
end;
end;
end;
if alreadyVisited == 0 then
table.insert(heroArtesianSpringVisited, heroNumberPool);
table.insert(heroArtesianSpringVisited, maxPoints);
end;
end;
if #heroArtesianSpringVisited > 0 then
for j = 1, (#heroArtesianSpringVisited / numEntries) do
k = (j * numEntries) - numEntries;
if heroArtesianSpringVisited[1 + k] == heroNumberPool then
if points <= heroArtesianSpringVisited[2 + k] then
for l = 1, numEntries do
table.remove(heroArtesianSpringVisited, (1 + k));
end;
end;
end;
end;
end;
end;
end
-- Tweaks: Some artifacts give extra point(s) for Spell Power and Knowledge.
-- This only works for the 54 heroes in pool for now.
-- Spell power and Knowledge values are updated only when any heroes move.
-- This modifies the disposition of the artifacts in the hero's inventory made by the player.
-- A complete artifacts.xml file to directly modify the values is necessary to avoid this and would be much simpler.
-- In addition, the bug linked to the artesian spring effect is activated as soon as a hero moves after a visit by a hero to the artesian spring (any "moved" artifact in the inventory removes spell points above the maximum).
-- Fixed the activation of the bug linked to the artesian spring effect for this case.
function TweaksArtifactSpellPowerKnowledge()
if #heroSpellPowerKnowledgeGiven > 0 then
for i = 0, 53 do
hero = GetHeroInPool(i);
heroNumberPool = i;
spellPower = GetPrimarySkill(hero, PRIMARY_SKILL_SPELLPOWER);
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
for j = 1, (#heroSpellPowerKnowledgeGiven / 3) do
k = (j * 3) - 3;
if heroSpellPowerKnowledgeGiven[1 + k] == heroNumberPool then
SetPrimarySkill(hero, PRIMARY_SKILL_SPELLPOWER, spellPower - heroSpellPowerKnowledgeGiven[2 + k]);
SetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE, knowledge - heroSpellPowerKnowledgeGiven[3 + k]);
break;
end;
end;
end;
heroSpellPowerKnowledgeGiven = {};
end;
for i = 0, 53 do
hero = GetHeroInPool(i);
heroNumberPool = i;
givenSpellPower = 0;
givenKnowledge = 0;
freeSlots = CountEmptyArtifactSlots(hero);
numberArtifacts = 14 - freeSlots;
spellPower = GetPrimarySkill(hero, PRIMARY_SKILL_SPELLPOWER);
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
artifactSpellPowerKnowledge = {};
initialPoints = hero.spellpoints;
for j = 1, numberArtifacts do
for k = 1, #tweaksArtifactSpellPower1 do
if HasArtifact(hero, tweaksArtifactSpellPower1[k]) == true then
givenSpellPower = givenSpellPower + 1;
TakeArtifact(hero, tweaksArtifactSpellPower1[k]);
table.insert(artifactSpellPowerKnowledge, tweaksArtifactSpellPower1[k]);
end;
end;
for l = 1, #tweaksArtifactSpellPower2 do
if HasArtifact(hero, tweaksArtifactSpellPower2[l]) == true then
givenSpellPower = givenSpellPower + 2;
TakeArtifact(hero, tweaksArtifactSpellPower2[l]);
table.insert(artifactSpellPowerKnowledge, tweaksArtifactSpellPower2[l]);
end;
end;
for m = 1, #tweaksArtifactKnowledge1 do
if HasArtifact(hero, tweaksArtifactKnowledge1[m]) == true then
givenKnowledge = givenKnowledge + 1;
TakeArtifact(hero, tweaksArtifactKnowledge1[m]);
table.insert(artifactSpellPowerKnowledge, tweaksArtifactKnowledge1[m]);
end;
end;
for n = 1, #tweaksArtifactKnowledge2 do
if HasArtifact(hero, tweaksArtifactKnowledge2[n]) == true then
givenKnowledge = givenKnowledge + 2;
TakeArtifact(hero, tweaksArtifactKnowledge2[n]);
table.insert(artifactSpellPowerKnowledge, tweaksArtifactKnowledge2[n]);
end;
end;
end;
for o = 1, #artifactSpellPowerKnowledge do
GrantArtifact(hero, artifactSpellPowerKnowledge[o]);
end;
if givenSpellPower > 0 then
SetPrimarySkill(hero, PRIMARY_SKILL_SPELLPOWER, spellPower + givenSpellPower);
end;
if givenKnowledge > 0 then
SetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE, knowledge + givenKnowledge);
maxTotalPoints = (knowledge + givenKnowledge) * 10;
if initialPoints <= maxTotalPoints then
hero.spellpoints = initialPoints;
else
hero.spellpoints = maxTotalPoints;
end;
end;
if givenSpellPower > 0 or givenKnowledge > 0 then
table.insert(heroSpellPowerKnowledgeGiven, heroNumberPool);
table.insert(heroSpellPowerKnowledgeGiven, givenSpellPower);
table.insert(heroSpellPowerKnowledgeGiven, givenKnowledge);
-- Fix for the activation of the bug linked to the Artesian Spring effect - Start.
if #heroArtesianSpringVisited > 0 then
for j = 1, (#heroArtesianSpringVisited / numEntries) do
k = (j * numEntries) - numEntries;
if heroArtesianSpringVisited[1 + k] == heroNumberPool then
if initialPoints > maxTotalPoints then
hero.spellpoints = initialPoints;
end;
end;
end;
end;
-- Fix for the activation of the bug linked to the Artesian Spring effect - End.
end;
end;
end
-- Set the spell points to maximum for all heroes at start of scenario.
-- This only works for the 54 heroes in pool for now.
function SetMaxSpellPoints()
for i = 0, 53 do
hero = GetHeroInPool(i);
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
SetSpellpoints(hero, maxPoints);
end;
end
-- Palliative for lack of built-in function, IsPlayerControlledByAI(player) would be nice - start.
-- It only works for solo game!!!
function AiPlayer()
hero = GetCurrentHero();
owner = GetHeroOwner(hero);
if owner ~= 0 then
return true;
end;
end
-- Palliative for lack of built-in function, IsPlayerControlledByAI(player) would be nice - end.
-- Table undeadReference:
-- First entry in the table, the number of data to ignore before the entry of possible choice for creature.
-- Entry of possible choice, number of possibilities, references of undead creatures.
-- Entry of possible choice for creature.
undeadReference = {
68, "C0", 1, 47, "C1", 3, 47, 48, 49, "C2", 5, 47, 48, 49, 50, 51, "C3", 7, 47, 48, 49, 50, 51, 54, 55, "C4", 2, 47, 56, "C5", 7, 47, 48, 49, 50, 51, 52, 53,
"C6", 1, 48, "C7", 1, 49, "C8", 1, 50, "C9", 1, 51, "C10", 1, 52, "C11", 1, 53, "C12", 1, 54, "C13", 1, 55, "C14", 1, 56, "C15", 1, 59,
"C0", "C1", "C1", "C2", "C2", "C2", "C2", "C2", "C2", "C2", "C2",
"C0", "C1", "C1", "C0", "C2", "C2", "C3", "C3", "C2",
"C0", "C1", "C1", "C2", "C2", "C3", "C3", "C0", "C4",
"C0", "C0", "C0", "C2", "C2", "C4", "C4", "C4", "C4",
"C0", "C0", "C0", "C0", "C0", "C3", "C3", "C0", "C0",
"C0", "C6", "C7", "C8", "C9", "C10", "C11", "C12", "C13", "C14",
"C0", "C1", "C15", "C5", "C2", "C0", "C0", "C0", "C0"};
nameSingPlurCreature = {
"Peasant", "Peasants", "Archer", "Archers", "Ranger", "Rangers", "Pikeman", "Pikemen", "Veteran Pikeman", "Veteran Pikemen", "Swordsman", "Swordsmen", "Master Swordsman", "Master Swordsmen", "Cavalry", "Cavalries", "Champion", "Champions", "Paladin", "Paladins", "Crusader", "Crusaders",
"Goblin", "Goblins", "Orc", "Orcs", "Orc Chief", "Orc Chiefs", "Wolf", "Wolves", "Ogre", "Ogres", "Ogre Lord", "Ogre Lords", "Troll", "Trolls", "War Troll", "War Trolls", "Cyclops", "Cyclopes",
"Sprite", "Sprites", "Dwarf", "Dwarves", "Battle Dwarf", "Battle Dwarves", "Elf", "Elves", "Grand Elf", "Grand Elves", "Druid", "Druids", "Greater Druid", "Greater Druids", "Unicorn", "Unicorns", "Phoenix", "Phoenixes",
"Centaur", "Centaurs", "Gargoyle", "Gargoyles", "Griffin", "Griffins", "Minotaur", "Minotaurs", "Minotaur King", "Minotaur Kings", "Hydra", "Hydras", "Green Dragon", "Green Dragons", "Red Dragon", "Red Dragons", "Black Dragon", "Black Dragons",
"Halfling", "Halflings", "Boar", "Boars", "Iron Golem", "Iron Golems", "Steel Golem", "Steel Golems", "Roc", "Rocs", "Mage", "Magi", "Archmage", "Archmagi", "Giant", "Giants", "Titan", "Titans",
"Skeleton", "Skeletons", "Zombie", "Zombies", "Mutant Zombie", "Mutant Zombies", "Mummy", "Mummies", "Royal Mummy", "Royal Mummies", "Vampire", "Vampires", "Vampire Lord", "Vampire Lords", "Lich", "Liches", "Power Lich", "Power Liches", "Bone Dragon", "Bone Dragons",
"Rogue", "Rogues", "Nomad", "Nomads", "Ghost", "Ghosts", "Genie", "Genies", "Medusa", "Medusas", "Earth Elemental", "Earth Elementals", "Air Elemental", "Air Elementals", "Fire Elemental", "Fire Elementals", "Water elemental", "Water elementals"};
-- Bug with tables in 1.3.0!!! The tables are ignored when loading a save file!!!
mapVariables = {"heroArtesianSpringVisited", "heroSpellPowerKnowledgeGiven", "shrineVisitedDay", "secondarySkillLevel", "creatureGeneratorMapVisited",
"locationVisitedPowerRing", "locationVisitedSpadeOfNecromancy", "locationVisitedAnkh", "necromancerCityOfDeadVisitedPowerRing"};
function OnMapStart()
-- Tweaks: Some artifacts give extra point(s) for Spell Power and Knowledge.
-- This only works for the 54 heroes in pool for now.
-- Spell power and Knowledge values are updated only when any heroes move.
-- This modifies the disposition of the artifacts in the hero's inventory made by the player.
-- A complete artifacts.xml file to directly modify the values is necessary to avoid this and would be much simpler.
-- In addition, the bug linked to the artesian spring effect is activated as soon as a hero moves after a visit by a hero to the artesian spring (any "moved" artifact in the inventory removes spell points above the maximum).
-- Fixed the activation of the bug linked to the artesian spring effect for this case.
if tweaksArtifactSpellPowerKnowledgeOn == 1 then
TweaksArtifactSpellPowerKnowledge();
end;
-- Set the spell points to maximum for all heroes at start of scenario, this only works for the 54 heroes in pool for now.
if setMaxSpellPointsStartOn == 1 then
SetMaxSpellPoints();
end;
--MessageBox("OnMapStart.");----
end
function OnLocationVisit(type, x, y)
-- The hero without Magic Book can buy one at any shrine.
if magicBookOn == 1 then
if type == LOCATION_SHRINE_FIRST or type == LOCATION_SHRINE_SECOND_ORDER or type == LOCATION_SHRINE_THIRD_ORDER then
hero = GetCurrentHero();
name = hero.name;
player = GetCurrentPlayer();
gold = GetResource(player, RESOURCE_GOLD);
if HasArtifact(hero, ARTIFACT_MAGIC_BOOK) == false and CountEmptyArtifactSlots(hero) >= 1 and gold >= 500 then
result = QuestionBox("{Shrine of Magic}\n\n"..name..", I see you do not have a Magic Book.\nYou can buy one here for "..costMagicBook.." gold. Do you wish to buy a Magic Book?");
if result then
gold = gold - costMagicBook;
SetResource(player, RESOURCE_GOLD, gold);
GrantArtifact(hero, ARTIFACT_MAGIC_BOOK);
end;
elseif HasArtifact(hero, ARTIFACT_MAGIC_BOOK) == false and CountEmptyArtifactSlots(hero) >= 1 and gold < 500 then
MessageBox("{Shrine of Magic}\n\n"..name..", I see you do not have a Magic Book. You can buy one here for 500 gold. Unfortunately, you seem to be a little short on cash at the moment.");
end;
end;
end;
-- Once a day, the hero recovers some spell points when he visits a shrine.
if shrineOn == 1 then
if type == LOCATION_SHRINE_FIRST or type == LOCATION_SHRINE_SECOND_ORDER or type == LOCATION_SHRINE_THIRD_ORDER then
hero = GetCurrentHero();
name = hero.name;
points = hero.spellpoints;
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
restorePoints = 0;
alreadyVisited = 0;
initialPoints = points;
if #shrineVisitedDay > 0 then
for i = 1, (#shrineVisitedDay / 4) do
j = (i * 4) - 4;
if shrineVisitedDay[1 + j] == x and shrineVisitedDay[2 + j] == y and shrineVisitedDay[3 + j] == name and shrineVisitedDay[4 + j] > 0 then
if points >= maxPoints then
MessageBox("{Shrine of Magic}\n\nA visit to the shrine is supposed to restore some of your spell points, but you have already visited this shrine this day and you are already at maximum.");
elseif points < maxPoints then
MessageBox("{Shrine of Magic}\n\nA visit to the shrine is supposed to restore some of your spell points, but you have already visited this shrine this day.");
end;
alreadyVisited = 1;
break;
end;
end;
end;
if alreadyVisited == 0 then
if type == LOCATION_SHRINE_FIRST then
restorePoints = shrineFirstPoints;
elseif type == LOCATION_SHRINE_SECOND_ORDER then
restorePoints = shrineSecondPoints;
elseif type == LOCATION_SHRINE_THIRD_ORDER then
restorePoints = shrineThirdPoints;
end;
if points >= maxPoints then
MessageBox("{Shrine of Magic}\n\nA visit to the shrine is supposed to restore some of your spell points, but you are already at maximum.");
elseif points < maxPoints then
points = points + restorePoints;
if points > maxPoints then
points = maxPoints;
end;
givenPoints = points - initialPoints;
MessageBox("{Shrine of Magic}\n\nA visit to the shrine restored "..givenPoints.." of your spell points.");
hero.spellpoints = points;
table.insert(shrineVisitedDay, x);
table.insert(shrineVisitedDay, y);
table.insert(shrineVisitedDay, name);
table.insert(shrineVisitedDay, givenPoints);
end;
end;
end;
end;
-- The hero can choose whether or not to keep the secondary skill he learns at any witch's hut when he leaves it.
-- This is for when the hero enters the witch's hut.
if choiceWitchHutOn == 1 then
if type == LOCATION_WITCH_HUT then
hero = GetCurrentHero();
name = hero.name;
numberSkills = 0;
for i = 0, 13 do
level = GetSecondarySkill(hero, i);
if level > 0 then
numberSkills = numberSkills + 1;
end;
end;
if numberSkills < 8 then
for i = 0, 13 do
level = GetSecondarySkill(hero, i);
table.insert(secondarySkillLevel, level);
end;
table.insert(secondarySkillLevel, x);
table.insert(secondarySkillLevel, y);
table.insert(secondarySkillLevel, name);
end;
end;
end;
-- The hero can train his peasants at the hill fort for a cost.
if peasantTrainingOn == 1 then
if type == LOCATION_HILL_FORT then
hero = GetCurrentHero();
name = hero.name;
player = GetCurrentPlayer();
gold = GetResource(player, RESOURCE_GOLD);
costArcher = 150; -- is GetCreatureCost(creature) available in 1.3.0? No!!!!
costRanger = 200; -- is GetCreatureCost(creature) available in 1.3.0?
costPikeman = 200; -- is GetCreatureCost(creature) available in 1.3.0?
costVeteranPikeman = 250; -- is GetCreatureCost(creature) available in 1.3.0?
if HasTroop(hero, CREATURE_GOBLIN, 1) == true then -- CREATURE_PEASANT or 0 do not work!!!
numberPeasant = GetCreatureAmount(hero, CREATURE_GOBLIN); -- CREATURE_PEASANT
costTrainToArcher = math.floor(costArcher * numberPeasant * (costTrainingMultiplier + captainsFees));
costTrainToRanger = math.floor(costRanger * numberPeasant * (costTrainingMultiplier + captainsFees));
costTrainToPikeman = math.floor(costPikeman * numberPeasant * (costTrainingMultiplier + captainsFees));
costTrainToVeteranPikeman = math.floor(costVeteranPikeman * numberPeasant * (costTrainingMultiplier + captainsFees));
if numberPeasant == 1 then
textPeasant = "Peasant";
textNumberPeasant = "";
textArcher = "Archer";
textRanger = "Ranger";
textPikeman = "Pikeman";
textVeteranPikeman = "Veteran Pikeman";
else
textPeasant = "Peasants";
textNumberPeasant = ""..numberPeasant.." ";
textArcher = "Archers";
textRanger = "Rangers";
textPikeman = "Pikemen";
textVeteranPikeman = "Veteran Pikemen";
end;
if gold == 0 then
textNotEnoughGoldLeft = "no";
else
textNotEnoughGoldLeft = "only "..gold.."";
end;
if gold >= costTrainToVeteranPikeman then
textDressed = "in dazzling armor inlaid with gold and precious stones";
choice = 4;
textChoice = "{Dwarves' Captain}\n\nYou have the choice between ";
textTroop1 = ""..textArcher..", ";
textTroop2 = ""..textRanger..", ";
textTroop3 = ""..textPikeman.." and ";
textTroop4 = textVeteranPikeman;
elseif gold >= costTrainToPikeman then
textDressed = "in worn and shriveled armor";
choice = 3;
textChoice = "{Dwarves' Captain}\n\nYou have the choice between ";
textTroop1 = ""..textArcher..", ";
textTroop2 = ""..textRanger.." and ";
textTroop3 = textPikeman;
textTroop4 = "";
elseif gold >= costTrainToRanger then
textDressed = "in a shabby armor pierced everywhere";
choice = 2;
textChoice = "{Dwarves' Captain}\n\nYou have the choice between ";
textTroop1 = ""..textArcher.." and ";
textTroop2 = textRanger;
textTroop3 = "";
textTroop4 = "";
elseif gold >= costTrainToArcher then
textDressed = "in ageless armor, all bumpy and rusty";
choice = 1;
textChoice = "{Dwarves' Captain}\n\nYour "..textPeasant.." can only be trained to ";
textTroop1 = textArcher;
textTroop2 = "";
textTroop3 = "";
textTroop4 = "";
end;
if gold >= costTrainToArcher then
result = QuestionBox("{Dwarves' Captain}\n\nThe Dwarves' Captain, dressed "..textDressed..", looks at your troops and offers to train your "..textPeasant.." for a cost. He can train ranged troops or close combat troops. It may seem expensive, but the Dwarves' Captain has his fees as he likes to repeat it. Do you want him to train your "..textNumberPeasant..""..textPeasant.."?");
if result then
for i = choice, 1, -1 do
if i == 1 then
textChoiceTroop = textArcher;
elseif i == 2 then
textChoiceTroop = textRanger;
elseif i == 3 then
textChoiceTroop = textPikeman;
elseif i == 4 then
textChoiceTroop = textVeteranPikeman;
end;
crudeCaptain = math.random(crudeCaptainFrequency);
result = QuestionBox(""..textChoice..""..textTroop1..""..textTroop2..""..textTroop3..""..textTroop4..". Do you want "..textChoiceTroop.."?");
if result then
if i == 4 then
trainCreature = CREATURE_VETERAN_PIKEMAN;
costTrainCreature = costTrainToVeteranPikeman;
elseif i == 3 then
trainCreature = CREATURE_PIKEMAN;
costTrainCreature = costTrainToPikeman;
elseif i == 2 then
trainCreature = CREATURE_RANGER;
costTrainCreature = costTrainToRanger;
elseif i == 1 then
trainCreature = CREATURE_ARCHER;
costTrainCreature = costTrainToArcher;
end;
textGoldLeft = gold;
result = QuestionBox("{Dwarves' Captain}\n\nYour "..textPeasant.." will be trained as "..textChoiceTroop..". You have "..textGoldLeft.." gold left. Do you accept the training of your "..textNumberPeasant..""..textPeasant.." for "..costTrainCreature.." gold?");
if result then
gold = gold - costTrainCreature;
SetResource(player, RESOURCE_GOLD, gold);
TakeTroop(hero, CREATURE_GOBLIN, numberPeasant); -- CREATURE_PEASANT
GrantArmy(hero, trainCreature, numberPeasant);
text = "{Dwarves' Captain}\n\nYour troops have been trained. The Dwarves' Captain thanks you and remains at your disposal for future training.";
dialogtype = 1;
img1type = 18;
img1arg = trainCreature;
AdvancedMessageBox(text, dialogtype, -1, -1, img1type, img1arg, -1, 0, -1, 0);
else
if crudeCaptainOn == 1 and crudeCaptain == 1 then
MessageBox("{Dwarves' Captain}\n\nThe Dwarves' Captain pulls out his tongue. He moves away from you showing you his big hairy buttocks.");
else
MessageBox("{Dwarves' Captain}\n\nThe Dwarves' Captain seems disappointed with your answer. He walks away from you, mumbling.");
end;
end;
break;
else;
if i == 1 then
if crudeCaptainOn == 1 and crudeCaptain == 1 then
MessageBox("{Dwarves' Captain}\n\nGo away, shabby, you're wasting my time for nothing!!!");
else
MessageBox("{Dwarves' Captain}\n\nAt your pleasure, my lord. I remain at your disposal if you need my services.");
end;
end;
end;
end;
else
MessageBox("{Dwarves' Captain}\n\nMaybe another time, my lord.");
end;
elseif gold < costTrainToArcher then
MessageBox("{Dwarves' Captain}\n\n"..name..", your "..textPeasant.." can be trained here, but you need at least "..costTrainToArcher.." gold. Unfortunately, you seem to be a little short on cash at the moment, you have "..textNotEnoughGoldLeft.." gold left.");
end;
end;
end;
end;
-- Once per city of dead, the Necromancer hero with the Power Ring artifact gets +1 Spell Power and +1 Knowledge when he is the first to visit the city of dead.
if necromancerCityOfDeadPowerRingOn == 1 then
if type == LOCATION_CITY_OF_DEAD then
hero = GetCurrentHero();
if HasArtifact(hero, ARTIFACT_POWER_RING) == true and HeroClass() == "necromancer" then
alreadyVisited = 0;
if #necromancerCityOfDeadVisitedPowerRing > 0 then
for i = 1, (#necromancerCityOfDeadVisitedPowerRing / 2) do
j = (i * 2) - 2;
if necromancerCityOfDeadVisitedPowerRing[1 + j] == x and necromancerCityOfDeadVisitedPowerRing[2 + j] == y then
alreadyVisited = 1;
break;
end;
end;
end;
if alreadyVisited == 0 then
heroSpellPower = GetPrimarySkill(hero, PRIMARY_SKILL_SPELLPOWER);
heroKnowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
SetPrimarySkill(hero, PRIMARY_SKILL_SPELLPOWER, heroSpellPower + 1);
SetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE, heroKnowledge + 1);
text = "{Sacred Ritual of the\nPower Ring}\n\nThe Sacred Ritual of the Power Ring has improved your Spell Power and your Knowledge. You can no longer practice the Sacred Ritual of the Power Ring at this city of dead.";
dialogtype = 1;
img1type = 25;
img1arg = 102; -- why "2" to "102" only for this?
img2type = 25;
img2arg = 3; -- and not for this? "103" will crash the program!!!
AdvancedMessageBox(text, dialogtype, -1, -1, img1type, img1arg, img2type, img2arg, -1, 0);
table.insert(necromancerCityOfDeadVisitedPowerRing, x);
table.insert(necromancerCityOfDeadVisitedPowerRing, y);
else
MessageBox("{Sacred Ritual of the\nPower Ring}\n\nThe Sacred Ritual of the Power Ring to improve your Spell Power and your Knowledge has already been achieved at this city of dead. Unfortunately, the Sacred Ritual of the Power Ring can only be accomplished once per city of dead.");
end;
end;
end;
end;
-- Once a day, the Necromancer hero with the Power Ring artifact recovers all his spell points when he visits certain locations on the adventure map (excavation, graveyard, pyramid, barrow mounds, daemon cave, city of dead).
if necromancerLocationPowerRingOn == 1 then
if necromancerExcavationPowerRing == 1 or necromancerGraveyardPowerRing == 1 or necromancerPyramidPowerRing == 1
or necromancerBarrowMoundsPowerRing == 1 or necromancerDaemonCavePowerRing == 1 or necromancerCityOfDeadPowerRing == 1 then
if (type == LOCATION_EXCAVATION and necromancerExcavationPowerRing == 1) or (type == LOCATION_GRAVEYARD and necromancerGraveyardPowerRing == 1) or (type == LOCATION_PYRAMID and necromancerPyramidPowerRing == 1)
or (type == LOCATION_BARROW_MOUNDS and necromancerBarrowMoundsPowerRing == 1) or (type == LOCATION_DAEMON_CAVE and necromancerDaemonCavePowerRing == 1) -- Barrow Mounds is still missing in the locations list for 1.3.0!!!
or (type == LOCATION_CITY_OF_DEAD and necromancerCityOfDeadPowerRing == 1) then
hero = GetCurrentHero();
name = hero.name;
alreadyVisited = 0;
points = hero.spellpoints;
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
restorePoints = 0;
initialPoints = points;
if HasArtifact(hero, ARTIFACT_POWER_RING) == true and HeroClass() == "necromancer" then
if #locationVisitedPowerRing > 0 then
for i = 1, (#locationVisitedPowerRing / 4) do
j = (i * 4) - 4;
if locationVisitedPowerRing[1 + j] == x and locationVisitedPowerRing[2 + j] == y and locationVisitedPowerRing[3 + j] == name and locationVisitedPowerRing[4 + j] > 0 then
if points >= maxPoints then
MessageBox("{Sacred Ritual of the\nPower Ring}\n\nThe Sacred Ritual of the Power Ring to restore all of your spell points can not be accomplished. You have already visited this location this day and you are already at maximum.");
elseif points < maxPoints then
MessageBox("{Sacred Ritual of the\nPower Ring}\n\nThe Sacred Ritual of the Power Ring to restore all of your spell points can not be accomplished. You have already visited this location this day.");
end;
alreadyVisited = 1;
break;
end;
end;
end;
if alreadyVisited == 0 then
restorePoints = maxPoints;
if points >= maxPoints then
MessageBox("{Sacred Ritual of the\nPower Ring}\n\nThe Sacred Ritual of the Power Ring to restore all of your spell points can not be accomplished. You are already at maximum.");
elseif points < maxPoints then
points = points + restorePoints;
if points > maxPoints then
points = maxPoints;
end;
givenPoints = points - initialPoints;
MessageBox("{Sacred Ritual of the\nPower Ring}\n\nThe Sacred Ritual of the Power Ring restored "..givenPoints.." of your spell points.");
hero.spellpoints = points;
table.insert(locationVisitedPowerRing, x);
table.insert(locationVisitedPowerRing, y);
table.insert(locationVisitedPowerRing, name);
table.insert(locationVisitedPowerRing, givenPoints);
end;
end;
end;
end;
end;
end;
-- The Necromancer hero with the Pendant of Death artifact can upgrade his zombies at the graveyard, his mummies at the pyramid, his vampires at the daemon cave, all undead creatures at the city of dead
-- on the adventure map for free.
if necromancerUndeadUpgradePendantOfDeathOn == 1 then
if necromancerZombieUpgradePendantOfDeath == 1 or necromancerMummyUpgradePendantOfDeath ==1 or necromancerVampireUpgradePendantOfDeath == 1 or necromancerLichUpgradePendantOfDeath == 1 then
if (type == LOCATION_GRAVEYARD and necromancerZombieUpgradePendantOfDeath == 1) or (type == LOCATION_PYRAMID and necromancerMummyUpgradePendantOfDeath == 1)
or (type == LOCATION_DAEMON_CAVE and necromancerVampireUpgradePendantOfDeath == 1) or (type == LOCATION_CITY_OF_DEAD and necromancerZombieUpgradePendantOfDeath == 1)
or (type == LOCATION_CITY_OF_DEAD and necromancerMummyUpgradePendantOfDeath == 1) or (type == LOCATION_CITY_OF_DEAD and necromancerVampireUpgradePendantOfDeath == 1)
or (type == LOCATION_CITY_OF_DEAD and necromancerLichUpgradePendantOfDeath == 1) then
hero = GetCurrentHero();
name = hero.name;
if HasArtifact(hero, ARTIFACT_PENDANT_OF_DEATH) == true and HeroClass() == "necromancer" then
if type == LOCATION_GRAVEYARD and necromancerZombieUpgradePendantOfDeath == 1 then
baseCreature = {CREATURE_ZOMBIE};
upgradedCreature = {CREATURE_MUTANT_ZOMBIE};
singularCreature = {"Zombie"};
pluralCreature = {"Zombies"};
elseif type == LOCATION_PYRAMID and necromancerMummyUpgradePendantOfDeath == 1 then
baseCreature = {CREATURE_MUMMY};
upgradedCreature = {CREATURE_ROYAL_MUMMY};
singularCreature = {"Mummy"};
pluralCreature = {"Mummies"};
elseif type == LOCATION_DAEMON_CAVE and necromancerVampireUpgradePendantOfDeath == 1 then
baseCreature = {CREATURE_VAMPIRE};
upgradedCreature = {CREATURE_VAMPIRE_LORD};
singularCreature = {"Vampire"};
pluralCreature = {"Vampires"};
elseif type == LOCATION_CITY_OF_DEAD
and (necromancerZombieUpgradePendantOfDeath == 1 or necromancerMummyUpgradePendantOfDeath == 1 or necromancerVampireUpgradePendantOfDeath == 1 or necromancerLichUpgradePendantOfDeath == 1) then
baseCreature = {CREATURE_ZOMBIE, CREATURE_MUMMY, CREATURE_VAMPIRE, CREATURE_LICH};
upgradedCreature = {CREATURE_MUTANT_ZOMBIE, CREATURE_ROYAL_MUMMY, CREATURE_VAMPIRE_LORD, CREATURE_POWER_LICH};
singularCreature = {"Zombie", "Mummy", "Vampire", "Lich"};
pluralCreature = {"Zombies", "Mummies", "Vampires", "Liches"};
end;
for i = #baseCreature, 1, -1 do
if HasTroop(hero, baseCreature[i], 1) == true then
numberCreature = GetCreatureAmount(hero, baseCreature[i]);
if numberCreature == 1 then
textCreature = singularCreature[i];
textNumberCreature = "";
else
textCreature = pluralCreature[i];
textNumberCreature = ""..numberCreature.." ";
end;
result = QuestionBox("{Sacred Ritual of the\nPendant of Death}\n\nThe Sacred Ritual of the Pendant of Death allows you to upgrade the "..textCreature.." of your army. Do you want to accomplish the Sacred Ritual of the Pendant of Death on your "..textNumberCreature..""..textCreature.."?");
if result then
TakeTroop(hero, baseCreature[i], numberCreature);
GrantArmy(hero, upgradedCreature[i], numberCreature);
if numberCreature == 1 then
textCreature = ""..singularCreature[i].."";
textCreature2 = " has";
else
textCreature = ""..pluralCreature[i].."";
textCreature2 = " have";
end;
text = "{Sacred Ritual of the\nPendant of Death}\n\nYour "..textCreature..""..textCreature2.." been upgraded.";
dialogtype = 1;
img1type = 18;
img1arg = upgradedCreature[i];
AdvancedMessageBox(text, dialogtype, -1, -1, img1type, img1arg, -1, 0, -1, 0);
else
if i == 1 then
MessageBox("{Sacred Ritual of the\nPendant of Death}\n\nAt your wish my lord.");
end;
end;
end;
end;
end;
end;
end;
end;
-- Once per certain locations on the adventure map (excavation, graveyard, pyramid, barrow mounds, daemon cave, city of dead), the Necromancer hero with the Spade of Necromancy artifact can raise undead creatures
-- when he is the first to visit the location, skeletons when he visits an excavation, mutant zombies or zombies when he visits a graveyard, royal mummies or mummies when he visits a pyramid,
-- vampire lords or vampires when he visits a daemon cave, ghosts when he visits a barrow mounds and power liches or liches when he visits the city of dead.
-- For now, it only works for the 54 heroes in pool (or specified names)(disabled for barrow mounds).
if necromancerLocationSpadeOfNecromancyOn == 1 then
if (type == LOCATION_EXCAVATION and necromancerExcavationSpadeOfNecromancy == 1) or (type == LOCATION_GRAVEYARD and necromancerGraveyardSpadeOfNecromancy == 1)
or (type == LOCATION_PYRAMID and necromancerPyramidSpadeOfNecromancy == 1) or (type == LOCATION_BARROW_MOUNDS and necromancerBarrowMoundsSpadeOfNecromancy == 1) -- Barrow Mounds is still missing in the locations list for 1.3.0!!!
or (type == LOCATION_DAEMON_CAVE and necromancerDaemonCaveSpadeOfNecromancy == 1) or (type == LOCATION_CITY_OF_DEAD and necromancerCityOfDeadSpadeOfNecromancy == 1) then
hero = GetCurrentHero();
name = hero.name;
if HasArtifact(hero, ARTIFACT_SPADE_OF_NECROMANCY) == true and HeroClass() == "necromancer" then
alreadyVisited = 0;
if #locationVisitedSpadeOfNecromancy > 0 then
for i = 1, (#locationVisitedSpadeOfNecromancy / 2) do
j = (i * 2) - 2;
if locationVisitedSpadeOfNecromancy[1 + j] == x and locationVisitedSpadeOfNecromancy[2 + j] == y then
alreadyVisited = 1;
break;
end;
end;
end;
if type == LOCATION_EXCAVATION and necromancerExcavationSpadeOfNecromancy == 1 then
raiseCreature = {CREATURE_SKELETON};
quantityCreature = {quantityTroopSkeleton};
textCreature = {"Skeleton", "Skeletons"};
locationCreature = "Skeletons";
location = "excavation";
elseif type == LOCATION_GRAVEYARD and necromancerGraveyardSpadeOfNecromancy == 1 then
raiseCreature = {CREATURE_ZOMBIE, CREATURE_MUTANT_ZOMBIE};
quantityCreature = {quantityTroopZombie, quantityTroopMutantZombie};
textCreature = {"Zombie", "Zombies", "Mutant Zombie", "Mutant Zombies"};
locationCreature = "Zombies or Mutant Zombies";
location = "graveyard";
elseif type == LOCATION_PYRAMID and necromancerPyramidSpadeOfNecromancy == 1 then
raiseCreature = {CREATURE_MUMMY, CREATURE_ROYAL_MUMMY};
quantityCreature = {quantityTroopMummy, quantityTroopRoyalMummy};
textCreature = {"Mummy", "Mummies", "Royal Mummy", "Royal Mummies"};
locationCreature = "Mummies or Royal Mummies";
location = "pyramid";
elseif type == LOCATION_BARROW_MOUNDS and necromancerBarrowMoundsSpadeOfNecromancy == 1 then -- Barrow Mounds is still missing in the locations list for 1.3.0!!!
raiseCreature = {CREATURE_GHOST};
quantityCreature = {quantityTroopGhost};
textCreature = {"Ghost", "Ghosts"};
locationCreature = "Ghosts";
location = "barrow mounds";
elseif type == LOCATION_DAEMON_CAVE and necromancerDaemonCaveSpadeOfNecromancy == 1 then
raiseCreature = {CREATURE_VAMPIRE, CREATURE_VAMPIRE_LORD};
quantityCreature = {quantityTroopVampire, quantityTroopVampireLord};
textCreature = {"Vampire", "Vampires", "Vampire Lord", "Vampire Lords"};
locationCreature = "Vampires or Vampire Lords";
location = "daemon cave";
elseif type == LOCATION_CITY_OF_DEAD and necromancerCityOfDeadSpadeOfNecromancy == 1 then
raiseCreature = {CREATURE_LICH, CREATURE_POWER_LICH};
quantityCreature = {quantityTroopLich, quantityTroopPowerLich};
textCreature = {"Lich", "Liches", "Power Lich", "Power Liches"};
locationCreature = "Liches or Power Liches";
location = "city of death";
end;
if alreadyVisited == 0 then
result = QuestionBox("{Sacred Ritual of the\nSpade of Necromancy}\n\nThe Sacred Ritual of the Spade of Necromancy allows you to raise "..locationCreature.." once per "..location..". Do you want to accomplish the Sacred Ritual of the Spade of Necromancy?");
if result then
-- There is no way to check and set individually the troops present in the different slots of the hero's army, so this will change the disposition of the troops in the hero's army made by the player.
-- Here, the functions GetArmyInSlot(hero, slot, creature, quantity) and SetArmyInSlot(hero, slot, creature, quantity) would be useful to set back the original arrangement of the troops.
for i = 1, #levelCreatureReference do
if HasTroop(hero, i - 1, 1) == true then
numberCreature = GetCreatureAmount(hero, i - 1);
TakeTroop(hero, i - 1, numberCreature);
GrantArmy(hero, i - 1, numberCreature);
end;
end;
emptyCreatureSlots = CountEmptyCreatureSlots(hero);
ranksFull = 0;
choiceRaiseCreature = {};
choiceQuantityCreature = {};
choiceTextCreature = {};
for i = 1, #raiseCreature do
if HasTroop(hero, raiseCreature[i], 1) == true then
table.insert(choiceRaiseCreature, raiseCreature[i]);
table.insert(choiceQuantityCreature, quantityCreature[i]);
table.insert(choiceTextCreature, textCreature[i - 1 + i]);
table.insert(choiceTextCreature, textCreature[(i - 1 + i) + 1]);
end;
end;
if #choiceRaiseCreature == 0 and emptyCreatureSlots == 0 then
ranksFull = 1;
elseif #choiceRaiseCreature > 0 and emptyCreatureSlots == 0 then
raiseCreature = choiceRaiseCreature;
quantityCreature = choiceQuantityCreature;
textCreature = choiceTextCreature;
end;
if ranksFull == 1 then
MessageBox("{Sacred Ritual of the\nSpade of Necromancy}\n\nThe Sacred Ritual of the Spade of Necromancy to raise "..locationCreature.." can not be accomplished. Your ranks are full.");
else
for i = #raiseCreature, 1, -1 do
if HasTroop(hero, raiseCreature[i], 1) == true or emptyCreatureSlots >= 1 then
numberCreature = quantityCreature[i] * multiplierBonusSpadeOfNecromancy;
if numberCreature > 1 then
textRaiseTroop = textCreature[i * 2];
else
textRaiseTroop = textCreature[(i * 2) - 1];
end;
result = QuestionBox("{Sacred Ritual of the\nSpade of Necromancy}\n\nDo you want to accomplish the Sacred Ritual of the Spade of Necromancy to raise "..numberCreature.." "..textRaiseTroop.."?");
if result then
GrantArmy(hero, raiseCreature[i], numberCreature);
text = "{Sacred Ritual of the\nSpade of Necromancy}\n\nThe Sacred Ritual of the Spade of Necromancy has raised "..numberCreature.." "..textRaiseTroop..". You can no longer practice the Sacred Ritual of the Spade of Necromancy at this "..location..".";
dialogtype = 1;
img1type = 18;
img1arg = raiseCreature[i];
AdvancedMessageBox(text, dialogtype, -1, -1, img1type, img1arg, -1, 0, -1, 0);
table.insert(locationVisitedSpadeOfNecromancy, x);
table.insert(locationVisitedSpadeOfNecromancy, y);
break;
else
if i == 1 then
MessageBox("{Sacred Ritual of the\nSpade of Necromancy}\n\nAt your wish my lord. You can come back to your convenience to accomplish the Sacred Ritual of the Spade of Necromancy. But remember my lord, this can only be done once per "..location.." and only by the first Necromancer hero to achieve it.");
end;
end;
end;
end;
end;
else
MessageBox("{Sacred Ritual of the\nSpade of Necromancy}\n\nMaybe another time my lord. You can come back to your convenience to accomplish the Sacred Ritual of the Spade of Necromancy. But remember my lord, this can only be done once per "..location.." and only by the first Necromancer hero to achieve it.");
end;
else
MessageBox("{Sacred Ritual of the\nSpade of Necromancy}\n\nThe Sacred Ritual of the Spade of Necromancy has already been achieved at this "..location..". Unfortunately, the Sacred Ritual of the Spade of Necromancy can only be accomplished once per "..location..".");
end;
end;
end;
end;
-- The Necromancer hero with the Ankh artifact can transform the living creatures of the same type present in his army into the corresponding undead creatures when he visits a creature generator on the adventure map,
-- living creatures of level 1 when he visits an excavation, living creatures of level 1 and 2 when he visits a graveyard, living creatures of level 1 to 3 when he visits a pyramid,
-- living creatures of level 1 to 4 when he visits a daemon cave and living creatures of all levels when he visits the city of dead, when he leaves the location.
-- This is for when the hero enters the location.
if necromancerLocationAnkhOn == 1 then
if (type == LOCATION_ARCHERS_HOUSE and necromancerArchersHouseAnkh == 1) or (type == LOCATION_WATCH_TOWER and necromancerWatchTowerAnkh == 1) or (type == LOCATION_DWARF_COTTAGE and necromancerDwarfCottageAnkh == 1)
or (type == LOCATION_TROLL_BRIDGE and necromancerTrollBridgeAnkh == 1) or (type == LOCATION_CITY_OF_DEAD and necromancerCityOfDeadAnkh == 1) or (type == LOCATION_DRAGON_CITY and necromancerDragonCityAnkh == 1)
or (type == LOCATION_PEASANT_HUT and necromancerPeasantHutAnkh == 1) or (type == LOCATION_GOBLIN_HUT and necromancerGoblinHutAnkh == 1) or (type == LOCATION_TREE_HOUSE and necromancerTreeHouseAnkh == 1)
or (type == LOCATION_TREE_CITY and necromancerTreeCityAnkh == 1) or (type == LOCATION_CAVE and necromancerCaveAnkh == 1) or (type == LOCATION_HALFLING_HOLE and necromancerHalflingHoleAnkh == 1)
or (type == LOCATION_WAGON_CAMP and necromancerWagonCampAnkh == 1) or (type == LOCATION_DESRT_TENT and necromancerDesertTentAnkh == 1) or (type == LOCATION_ANCIENT_LAMP and necromancerAncientLampAnkh == 1)
-- see for LOCATION_DESRT_TENT is changed in 1.3.0!!! No!!!
or (type == LOCATION_RUINS and necromancerRuinsAnkh == 1)
-- Barrow Mounds, Earth Summoning Altar, Air Summoning Altar, Fire Summoning Altar and Water Summoning Altar locations are still missing in the locations list for 1.3.0!!!
-- or (type == LOCATION_EARTH_SUMMONING_ALTAR and necromancerEarthSummoningAltarAnkh == 1) or (type == LOCATION_AIR_SUMMONING_ALTAR and necromancerAirSummoningAltarAnkh == 1)
-- or (type == LOCATION_FIRE_SUMMONING_ALTAR and necromancerFireSummoningAltarAnkh == 1) or (type == LOCATION_WATER_SUMMONING_ALTAR and necromancerWaterSummoningAltarAnkh == 1)
-- or (type == LOCATION_BARROW_MOUNDS and necromancerBarrowMoundsAnkh == 1) ---- (special only when adjustment for ghosts applied)
or (type == LOCATION_EXCAVATION and necromancerExcavationAnkh == 1) or (type == LOCATION_GRAVEYARD and necromancerGraveyardAnkh == 1) or (type == LOCATION_PYRAMID and necromancerPyramidAnkh == 1)
or (type == LOCATION_DAEMON_CAVE and necromancerDaemonCaveAnkh == 1) then
hero = GetCurrentHero();
name = hero.name;
if HasArtifact(hero, ARTIFACT_ANKH) == true and HeroClass() == "necromancer" then
table.insert(locationVisitedAnkh, x);
table.insert(locationVisitedAnkh, y);
table.insert(locationVisitedAnkh, name);
table.insert(locationVisitedAnkh, type);
end;
end;
end;
-- The hero can upgrade his archers, orcs, dwarves, trolls, liches, green dragons, red dragons at the corresponding creature generator on the adventure map for a cost when he leaves it.
-- This is for when the hero enters the creature generator.
if upgradeCreatureLocationOn == 1 then
if upgradeArcherArchersHouse == 1 or upgradeOrcWatchTower == 1 or upgradeDwarfDwarfCottage == 1 or upgradeTrollTrollBridge == 1 or upgradeLichCityOfDead == 1 or upgradeDragonDragonCity == 1 then
if (type == LOCATION_ARCHERS_HOUSE and upgradeArcherArchersHouse == 1) or (type == LOCATION_WATCH_TOWER and upgradeOrcWatchTower == 1) or (type == LOCATION_DWARF_COTTAGE and upgradeDwarfDwarfCottage == 1)
or (type == LOCATION_TROLL_BRIDGE and upgradeTrollTrollBridge == 1) or (type == LOCATION_CITY_OF_DEAD and upgradeLichCityOfDead == 1) or (type == LOCATION_DRAGON_CITY and upgradeDragonDragonCity == 1) then
hero = GetCurrentHero();
name = hero.name;
table.insert(creatureGeneratorMapVisited, x);
table.insert(creatureGeneratorMapVisited, y);
table.insert(creatureGeneratorMapVisited, name);
table.insert(creatureGeneratorMapVisited, type);
end;
end;
end;
end
--MessageBox("");
function OnHeroMove(x, y)
-- This fills the table of heroes who visited an artesian spring and got the bonus.
HeroOverMaxSpellPointsArtesianSpring();
-- Tweaks: Some artifacts give extra point(s) for Spell Power and Knowledge.
-- This only works for the 54 heroes in pool for now.
-- Spell power and Knowledge values are updated only when any heroes move.
-- This modifies the disposition of the artifacts in the hero's inventory made by the player.
-- A complete artifacts.xml file to directly modify the values is necessary to avoid this and would be much simpler.
-- In addition, the bug linked to the artesian spring effect is activated as soon as a hero moves after a visit by a hero to the artesian spring (any "moved" artifact in the inventory removes spell points above the maximum).
-- Fixed the activation of the bug linked to the artesian spring effect for this case.
if tweaksArtifactSpellPowerKnowledgeOn == 1 then
TweaksArtifactSpellPowerKnowledge();
end;
-- The hero can choose whether or not to keep the secondary skill he learns at any witch's hut when he leaves it.
-- This is for when the hero leaves the witch's hut.
if choiceWitchHutOn == 1 then
if #secondarySkillLevel > 0 then
hero = GetCurrentHero();
name = hero.name;
givenSkill = -1;
for i = 1, (#secondarySkillLevel / 17) do
j = (i * 17) - 17;
if (((secondarySkillLevel[15 + j] == x + 1 or secondarySkillLevel[15 + j] == x - 1) and secondarySkillLevel[16 + j] == y)
or ((secondarySkillLevel[15 + j] == x or secondarySkillLevel[15 + j] == x + 1 or secondarySkillLevel[15 + j] == x - 1) and secondarySkillLevel[16 + j] == y - 1))
and secondarySkillLevel[17 + j] == name then
for k = 0, 13 do
level = GetSecondarySkill(hero, k);
if secondarySkillLevel[k + 1 + j] ~= level then
givenSkill = k;
break;
end;
end;
for l = 1, 17 do
table.remove(secondarySkillLevel, j + 1);
end;
if givenSkill ~= -1 then
if givenSkill == 0 then
textSkill = "Pathfinding";
elseif givenSkill == 1 then
textSkill = "Archery";
elseif givenSkill == 2 then
textSkill = "Logistics";
elseif givenSkill == 3 then
textSkill = "Scouting";
elseif givenSkill == 4 then
textSkill = "Diplomacy";
elseif givenSkill == 5 then
textSkill = "Navigation";
elseif givenSkill == 6 then
textSkill = "Leadership";
elseif givenSkill == 7 then
textSkill = "Wisdom";
elseif givenSkill == 8 then
textSkill = "Mysticism";
elseif givenSkill == 9 then
textSkill = "Luck";
elseif givenSkill == 10 then
textSkill = "Ballistics";
elseif givenSkill == 11 then
textSkill = "Eagle Eye";
elseif givenSkill == 12 then
textSkill = "Necromancy";
elseif givenSkill == 13 then
textSkill = "Estates";
end;
result = QuestionBox("{Witch's Hut}\n\n"..name..", you have just learned "..textSkill..". You can choose not to keep it.\nWould you like to keep "..textSkill.."?");
if not result then
SetSecondarySkill(hero, givenSkill, 0);
end;
end;
end;
end;
end;
end;
-- The Necromancer hero with the Ankh artifact can transform the living creatures of the same type present in his army into the corresponding undead creatures when he visits a creature generator on the adventure map,
-- living creatures of level 1 when he visits an excavation, living creatures of level 1 and 2 when he visits a graveyard, living creatures of level 1 to 3 when he visits a pyramid,
-- living creatures of level 1 to 4 when he visits a daemon cave and living creatures of all levels when he visits the city of dead, when he leaves the location.
-- This is for when the hero leaves the location.
if necromancerLocationAnkhOn == 1 then
if #locationVisitedAnkh > 0 then
hero = GetCurrentHero();
name = hero.name;
if HasArtifact(hero, ARTIFACT_ANKH) == true and HeroClass() == "necromancer" then
for i = 1, (#locationVisitedAnkh / 4) do
j = (i * 4) - 4;
if (((locationVisitedAnkh[1 + j] == x + 1 or locationVisitedAnkh[1 + j] == x - 1) and locationVisitedAnkh[2 + j] == y)
or ((locationVisitedAnkh[1 + j] == x or locationVisitedAnkh[1 + j] == x + 1 or locationVisitedAnkh[1 + j] == x - 1) and locationVisitedAnkh[2 + j] == y - 1)
-- specific squares to test for the ancient lamp - start.
or ((locationVisitedAnkh[1 + j] == x or locationVisitedAnkh[1 + j] == x + 1 or locationVisitedAnkh[1 + j] == x - 1) and locationVisitedAnkh[2 + j] == y - 2)
or (locationVisitedAnkh[1 + j] == x and locationVisitedAnkh[2 + j] == y)
or ((locationVisitedAnkh[1 + j] == x + 2 or locationVisitedAnkh[1 + j] == x - 2) and ((locationVisitedAnkh[2 + j] == y) or (locationVisitedAnkh[2 + j] == y + 1)
or (locationVisitedAnkh[2 + j] == y + 2) or (locationVisitedAnkh[2 + j] == y - 1) or (locationVisitedAnkh[2 + j] == y - 2)))
or ((locationVisitedAnkh[1 + j] == x or locationVisitedAnkh[1 + j] == x + 1 or locationVisitedAnkh[1 + j] == x - 1) and locationVisitedAnkh[2 + j] == y + 1)
or ((locationVisitedAnkh[1 + j] == x or locationVisitedAnkh[1 + j] == x + 1 or locationVisitedAnkh[1 + j] == x - 1) and locationVisitedAnkh[2 + j] == y + 2))
-- specific squares to test for the ancient lamp - end.
and locationVisitedAnkh[3 + j] == name then
if locationVisitedAnkh[4 + j] == LOCATION_ARCHERS_HOUSE and necromancerArchersHouseAnkh == 1 then
baseCreature = {CREATURE_ARCHER, CREATURE_RANGER};
elseif locationVisitedAnkh[4 + j] == LOCATION_WATCH_TOWER and necromancerWatchTowerAnkh == 1 then
baseCreature = {CREATURE_ORC, CREATURE_ORC_CHIEF};
elseif locationVisitedAnkh[4 + j] == LOCATION_DWARF_COTTAGE and necromancerDwarfCottageAnkh == 1 then
baseCreature = {CREATURE_DWARF, CREATURE_BATTLE_DWARF};
elseif locationVisitedAnkh[4 + j] == LOCATION_TROLL_BRIDGE and necromancerTrollBridgeAnkh == 1 then
baseCreature = {CREATURE_TROLL, CREATURE_WAR_TROLL};
elseif (locationVisitedAnkh[4 + j] == LOCATION_CITY_OF_DEAD and necromancerCityOfDeadAnkh == 1) then -- or (locationVisitedAnkh[4 + j] == LOCATION_BARROW_MOUNDS and necromancerBarrowMoundsAnkh == 1) then --
baseCreature = {};
for i = 1, #levelCreatureReference do
table.insert(baseCreature, i - 1);
end;
elseif locationVisitedAnkh[4 + j] == LOCATION_DRAGON_CITY and necromancerDragonCityAnkh == 1 then
baseCreature = {CREATURE_GREEN_DRAGON, CREATURE_RED_DRAGON, CREATURE_BLACK_DRAGON};
-- elseif locationVisitedAnkh[4 + j] == LOCATION_PEASANT_HUT and necromancerPeasantHutAnkh == 1 then
-- baseCreature = {CREATURE_PEASANT}; -- CREATURE_PEASANT or 0 do not work in 1.3.0!!!
elseif locationVisitedAnkh[4 + j] == LOCATION_GOBLIN_HUT and necromancerGoblinHutAnkh == 1 then
baseCreature = {CREATURE_GOBLIN};
elseif (locationVisitedAnkh[4 + j] == LOCATION_TREE_HOUSE and necromancerTreeHouseAnkh == 1) or (locationVisitedAnkh[4 + j] == LOCATION_TREE_CITY and necromancerTreeCityAnkh == 1) then
baseCreature = {CREATURE_SPRITE};
elseif locationVisitedAnkh[4 + j] == LOCATION_CAVE and necromancerCaveAnkh == 1 then
baseCreature = {CREATURE_CENTAUR};
elseif locationVisitedAnkh[4 + j] == LOCATION_HALFLING_HOLE and necromancerHalflingHoleAnkh == 1 then
baseCreature = {CREATURE_HALFLING};
elseif locationVisitedAnkh[4 + j] == LOCATION_WAGON_CAMP and necromancerWagonCampAnkh == 1 then
baseCreature = {CREATURE_ROGUE};
elseif locationVisitedAnkh[4 + j] == LOCATION_DESRT_TENT and necromancerDesertTentAnkh == 1 then -- see for LOCATION_DESRT_TENT is changed in 1.3.0!!! No!!!
baseCreature = {CREATURE_NOMAD};
elseif locationVisitedAnkh[4 + j] == LOCATION_ANCIENT_LAMP and necromancerAncientLampAnkh == 1 then
baseCreature = {CREATURE_GENIE};
elseif locationVisitedAnkh[4 + j] == LOCATION_RUINS and necromancerRuinsAnkh == 1 then
baseCreature = {CREATURE_MEDUSA};
-- Earth Summoning Altar, Air Summoning Altar, Fire Summoning Altar and Water Summoning Altar locations are still missing in the locations list for 1.3.0!!!
-- elseif locationVisitedAnkh[4 + j] == LOCATION_EARTH_SUMMONING_ALTAR and necromancerEarthSummoningAltarAnkh == 1 then
-- baseCreature = {CREATURE_EARTH_ELEMENTAL};
-- elseif locationVisitedAnkh[4 + j] == LOCATION_AIR_SUMMONING_ALTAR and necromancerAirSummoningAltarAnkh == 1 then
-- baseCreature = {CREATURE_AIR_ELEMENTAL};
-- elseif locationVisitedAnkh[4 + j] == LOCATION_FIRE_SUMMONING_ALTAR and necromancerFireSummoningAltarAnkh == 1 then
-- baseCreature = {CREATURE_FIRE_ELEMENTAL};
-- elseif locationVisitedAnkh[4 + j] == LOCATION_WATER_SUMMONING_ALTAR and necromancerWaterSummoningAltarAnkh == 1 then
-- baseCreature = {CREATURE_WATER_ELEMENTAL};
elseif locationVisitedAnkh[4 + j] == LOCATION_EXCAVATION and necromancerExcavationAnkh == 1 then
baseCreature = {};
for i = 1, #levelCreatureReference do
if levelCreatureReference[i] == 1 then
table.insert(baseCreature, i - 1);
end;
end;
elseif locationVisitedAnkh[4 + j] == LOCATION_GRAVEYARD and necromancerGraveyardAnkh == 1 then
baseCreature = {};
for i = 1, #levelCreatureReference do
if levelCreatureReference[i] == 1 or levelCreatureReference[i] == 2 then
table.insert(baseCreature, i - 1);
end;
end;
elseif locationVisitedAnkh[4 + j] == LOCATION_PYRAMID and necromancerPyramidAnkh == 1 then
baseCreature = {};
for i = 1, #levelCreatureReference do
if levelCreatureReference[i] == 1 or levelCreatureReference[i] == 2 or levelCreatureReference[i] == 3 then
table.insert(baseCreature, i - 1);
end;
end;
elseif locationVisitedAnkh[4 + j] == LOCATION_DAEMON_CAVE and necromancerDaemonCaveAnkh == 1 then
baseCreature = {};
for i = 1, #levelCreatureReference do
if levelCreatureReference[i] == 1 or levelCreatureReference[i] == 2 or levelCreatureReference[i] == 3 or levelCreatureReference[i] == 4 then
table.insert(baseCreature, i - 1);
end;
end;
end;
for i = 1, #baseCreature do
turnCreature = baseCreature[1 + (i - 1)];
if (turnCreature >= 47 and turnCreature <= 56) or turnCreature == 59 then
else
if HasTroop(hero, turnCreature, 1) == true then
numberCreature = GetCreatureAmount(hero, turnCreature);
if numberCreature == 1 then
sp = 1;
textCreature = nameSingPlurCreature[(turnCreature * 2) + sp];
textNumberCreature = "";
textPeasant = "Peasant";
textPeasant2 = "thanks";
textSkeleton = "Skeleton";
textSkeleton2 = " is";
-- (special only when adjustment for ghosts applied)
textGhost = "Ghost";
textGhost2 = " is";
else
sp = 2;
textCreature = nameSingPlurCreature[(turnCreature * 2) + sp];
textNumberCreature = ""..numberCreature.." ";
textPeasant = "Peasants";
textPeasant2 = "thank";
textSkeleton = "Skeletons";
textSkeleton2 = " are";
-- (special only when adjustment for ghosts applied)
textGhost = "Ghosts";
textGhost2 = " are";
end;
result = QuestionBox("{Sacred Ritual of the\nAnhk}\n\nThe Sacred Ritual of the Anhk allows you to turn the living creatures of your army into undead. Do you want to accomplish the Sacred Ritual of the Anhk on your "..textNumberCreature..""..textCreature.."?");
if result then
-- (special only when adjustment for ghosts applied)
if locationVisitedAnkh[4 + j] == LOCATION_BARROW_MOUNDS and necromancerBarrowMoundsAnkh == 1 then
possibleChoice = "C15";
else
possibleChoice = undeadReference[(undeadReference[1] + turnCreature) + 1];
end;
for j = 2, undeadReference[1] do
if undeadReference[j] == possibleChoice then
numberPossibilities = undeadReference[j + 1];
mj = j;
break;
end;
end;
if possibleChoice == "C0" then
textChoice = "{Sacred Ritual of the\nAnhk}\n\nYou can only turn this troop of living creatures of your army into ";
textTroop1 = nameSingPlurCreature[(undeadReference[mj + 2] * 2) + sp];
textInter1 = "";
textTroop2 = "";
textInter2 = "";
textTroop3 = "";
textInter3 = "";
textTroop4 = "";
textInter4 = "";
textTroop5 = "";
textInter5 = "";
textTroop6 = "";
textInter6 = "";
textTroop7 = "";
elseif possibleChoice == "C1" then
textChoice = "{Sacred Ritual of the\nAnhk}\n\nYou have the choice between ";
textTroop1 = nameSingPlurCreature[(undeadReference[mj + 2] * 2) + sp];
textInter1 = ", ";
textTroop2 = nameSingPlurCreature[(undeadReference[mj + 3] * 2) + sp];
textInter2 = " or ";
textTroop3 = nameSingPlurCreature[(undeadReference[mj + 4] * 2) + sp];
textInter3 = "";
textTroop4 = "";
textInter4 = "";
textTroop5 = "";
textInter5 = "";
textTroop6 = "";
textInter6 = "";
textTroop7 = "";
elseif possibleChoice == "C2" then
textChoice = "{Sacred Ritual of the\nAnhk}\n\nYou have the choice between ";
textTroop1 = nameSingPlurCreature[(undeadReference[mj + 2] * 2) + sp];
textInter1 = ", ";
textTroop2 = nameSingPlurCreature[(undeadReference[mj + 3] * 2) + sp];
textInter2 = ", ";
textTroop3 = nameSingPlurCreature[(undeadReference[mj + 4] * 2) + sp];
textInter3 = ", ";
textTroop4 = nameSingPlurCreature[(undeadReference[mj + 5] * 2) + sp];
textInter4 = " or ";
textTroop5 = nameSingPlurCreature[(undeadReference[mj + 6] * 2) + sp];
textInter5 = "";
textTroop6 = "";
textInter6 = "";
textTroop7 = "";
elseif possibleChoice == "C3" then
textChoice = "{Sacred Ritual of the\nAnhk}\n\nYou have the choice between ";
textTroop1 = nameSingPlurCreature[(undeadReference[mj + 2] * 2) + sp];
textInter1 = ", ";
textTroop2 = nameSingPlurCreature[(undeadReference[mj + 3] * 2) + sp];
textInter2 = ", ";
textTroop3 = nameSingPlurCreature[(undeadReference[mj + 4] * 2) + sp];
textInter3 = ", ";
textTroop4 = nameSingPlurCreature[(undeadReference[mj + 5] * 2) + sp];
textInter4 = ", ";
textTroop5 = nameSingPlurCreature[(undeadReference[mj + 6] * 2) + sp];
textInter5 = ", ";
textTroop6 = nameSingPlurCreature[(undeadReference[mj + 7] * 2) + sp];
textInter6 = " or ";
textTroop7 = nameSingPlurCreature[(undeadReference[mj + 8] * 2) + sp];
elseif possibleChoice == "C4" then
textChoice = "{Sacred Ritual of the\nAnhk}\n\nYou have the choice between ";
textTroop1 = nameSingPlurCreature[(undeadReference[mj + 2] * 2) + sp];
textInter1 = " or ";
textTroop2 = nameSingPlurCreature[(undeadReference[mj + 3] * 2) + sp];
textInter2 = "";
textTroop3 = "";
textInter3 = "";
textTroop4 = "";
textInter4 = "";
textTroop5 = "";
textInter5 = "";
textTroop6 = "";
textInter6 = "";
textTroop7 = "";
elseif possibleChoice == "C5" then
textChoice = "{Sacred Ritual of the\nAnhk}\n\nYou have the choice between ";
textTroop1 = nameSingPlurCreature[(undeadReference[mj + 2] * 2) + sp];
textInter1 = ", ";
textTroop2 = nameSingPlurCreature[(undeadReference[mj + 3] * 2) + sp];
textInter2 = ", ";
textTroop3 = nameSingPlurCreature[(undeadReference[mj + 4] * 2) + sp];
textInter3 = ", ";
textTroop4 = nameSingPlurCreature[(undeadReference[mj + 5] * 2) + sp];
textInter4 = ", ";
textTroop5 = nameSingPlurCreature[(undeadReference[mj + 6] * 2) + sp];
textInter5 = ", ";
textTroop6 = nameSingPlurCreature[(undeadReference[mj + 7] * 2) + sp];
textInter6 = " or ";
textTroop7 = nameSingPlurCreature[(undeadReference[mj + 8] * 2) + sp];
-- (special only when adjustment for ghosts applied)
elseif possibleChoice == "C15" then
textChoice = "{Sacred Ritual of the\nAnhk}\n\nYou can only turn this troop of living creatures of your army into ";
textTroop1 = nameSingPlurCreature[(undeadReference[mj + 2] * 2) + sp];
textInter1 = "";
textTroop2 = "";
textInter2 = "";
textTroop3 = "";
textInter3 = "";
textTroop4 = "";
textInter4 = "";
textTroop5 = "";
textInter5 = "";
textTroop6 = "";
textInter6 = "";
textTroop7 = "";
end;
for l = numberPossibilities, 1, -1 do
textChoiceTroop = nameSingPlurCreature[(undeadReference[mj + 2 + (l - 1)] * 2) + sp];
result = QuestionBox(""..textChoice..""..textTroop1..""..textInter1..""..textTroop2..""..textInter2..""..textTroop3..""..textInter3..""..textTroop4..""..textInter4..""..textTroop5..""..textInter5..""..textTroop6..""..textInter6..""..textTroop7..". Do you want to turn the "..textNumberCreature..""..textCreature.." of your army into "..numberCreature.." "..textChoiceTroop.."?");
if result then
choiceTroop = undeadReference[mj + 2 + (l - 1)];
TakeTroop(hero, turnCreature, numberCreature);
GrantArmy(hero, choiceTroop, numberCreature);
if turnCreature == CREATURE_GOBLIN then -- CREATURE_PEASANT
-- (special only when adjustment for ghost applied)
if possibleChoice == "C15" then
text = "{Sacred Ritual of the\nAnhk}\n\nArgll! Arrgh! Aaarrgh...\nThe "..textGhost..""..textGhost2.." ready to serve you... or not.";
else
text = "{Sacred Ritual of the\nAnhk}\n\nArgll! Arrgh! Aaarrgh...\nThe "..textSkeleton..""..textSkeleton2.." ready to serve you.";
end;
else
text = "{Sacred Ritual of the\nAnhk}\n\nCrash! Ouch! Craaak!\nYour troops have been turned into undead in accordance with your wish my lord.";
end;
dialogtype = 1;
img1type = 18;
img1arg = choiceTroop;
AdvancedMessageBox(text, dialogtype, -1, -1, img1type, img1arg, -1, 0, -1, 0);
break;
else
if l == 1 then
if turnCreature == CREATURE_GOBLIN then -- CREATURE_PEASANT
text = "{Sacred Ritual of the\nAnhk}\n\nHo! Waouh! Hipipihourra!\nThe relieved "..textPeasant.." overflowing with joy "..textPeasant2.." you very much for your benevolence.";
dialogtype = 1;
img1type = 18;
img1arg = CREATURE_PEASANT;
AdvancedMessageBox(text, dialogtype, -1, -1, img1type, img1arg, -1, 0, -1, 0);
else
MessageBox("{Sacred Ritual of the\nAnkh}\n\nAt your wish my lord.");
end;
end;
end;
end;
else
if turnCreature == CREATURE_GOBLIN then -- CREATURE_PEASANT
text = "{Sacred Ritual of the\nAnhk}\n\nHo! Waouh! Hourra!\nThe "..textPeasant.." full of joy "..textPeasant2.." you for your benevolence.";
dialogtype = 1;
img1type = 18;
img1arg = CREATURE_PEASANT;
AdvancedMessageBox(text, dialogtype, -1, -1, img1type, img1arg, -1, 0, -1, 0);
else
MessageBox("{Sacred Ritual of the\nAnkh}\n\nMaybe another time my lord.");
end;
end;
end;
end;
end;
for k = 1, 4 do
table.remove(locationVisitedAnkh, j + 1);
end;
end;
end;
end;
end;
end;
-- The hero can upgrade his archers, orcs, dwarves, trolls, liches, green dragons, red dragons at the corresponding creature generator on the adventure map for a cost when he leaves it.
-- This is for when the hero leaves the creature generator.
if upgradeCreatureLocationOn == 1 then
if upgradeArcherArchersHouse == 1 or upgradeOrcWatchTower == 1 or upgradeDwarfDwarfCottage == 1 or upgradeTrollTrollBridge == 1 or upgradeLichCityOfDead == 1 or upgradeDragonDragonCity == 1 then
if #creatureGeneratorMapVisited > 0 then
hero = GetCurrentHero();
name = hero.name;
player = GetCurrentPlayer();
gold = GetResource(player, RESOURCE_GOLD);
for i = 1, (#creatureGeneratorMapVisited / 4) do
j = (i * 4) - 4;
if (((creatureGeneratorMapVisited[1 + j] == x + 1 or creatureGeneratorMapVisited[1 + j] == x - 1) and creatureGeneratorMapVisited[2 + j] == y)
or ((creatureGeneratorMapVisited[1 + j] == x or creatureGeneratorMapVisited[1 + j] == x + 1 or creatureGeneratorMapVisited[1 + j] == x - 1) and creatureGeneratorMapVisited[2 + j] == y - 1))
and creatureGeneratorMapVisited[3 + j] == name then
if creatureGeneratorMapVisited[4 + j] == LOCATION_ARCHERS_HOUSE and upgradeArcherArchersHouse == 1 then
baseCreature = CREATURE_ARCHER;
upgradedCreature = CREATURE_RANGER;
costBaseCreature = 150; -- GetCreatureCost(baseCreature);-- is GetCreatureCost(creature) available in 1.3.0? No!
costUpgradedCreature = 200; -- GetCreatureCost(upgradedCreature);
singularCreature = "Archer";
pluralCreature = "Archers";
nameGenerator = "{Archer's House}";
elseif creatureGeneratorMapVisited[4 + j] == LOCATION_WATCH_TOWER and upgradeOrcWatchTower == 1 then
baseCreature = CREATURE_ORC;
upgradedCreature = CREATURE_ORC_CHIEF;
costBaseCreature = 140; -- GetCreatureCost(baseCreature);
costUpgradedCreature = 175; -- GetCreatureCost(upgradedCreature);
singularCreature = "Orc";
pluralCreature = "Orcs";
nameGenerator = "{Watch Tower}";
elseif creatureGeneratorMapVisited[4 + j] == LOCATION_DWARF_COTTAGE and upgradeDwarfDwarfCottage == 1 then
baseCreature = CREATURE_DWARF;
upgradedCreature = CREATURE_BATTLE_DWARF;
costBaseCreature = 200; -- GetCreatureCost(baseCreature);
costUpgradedCreature = 250; -- GetCreatureCost(upgradedCreature);
singularCreature = "Dwarf";
pluralCreature = "Dwarves";
nameGenerator = "{Dwarf Cottage}";
elseif creatureGeneratorMapVisited[4 + j] == LOCATION_TROLL_BRIDGE and upgradeTrollTrollBridge == 1 then
baseCreature = CREATURE_TROLL;
upgradedCreature = CREATURE_WAR_TROLL;
costBaseCreature = 600; -- GetCreatureCost(baseCreature);
costUpgradedCreature = 700; -- GetCreatureCost(upgradedCreature);
singularCreature = "Troll";
pluralCreature = "Trolls";
nameGenerator = "{Troll Bridge}";
elseif creatureGeneratorMapVisited[4 + j] == LOCATION_CITY_OF_DEAD and upgradeLichCityOfDead == 1 then
baseCreature = CREATURE_LICH;
upgradedCreature = CREATURE_POWER_LICH;
costBaseCreature = 750; -- GetCreatureCost(baseCreature);
costUpgradedCreature = 900; -- GetCreatureCost(upgradedCreature);
singularCreature = "Lich";
pluralCreature = "Liches";
nameGenerator = "{City of the Dead}";
elseif creatureGeneratorMapVisited[4 + j] == LOCATION_DRAGON_CITY and upgradeDragonDragonCity == 1 then
baseCreature = CREATURE_GREEN_DRAGON;
baseCreature2 = CREATURE_RED_DRAGON;
upgradedCreature = CREATURE_BLACK_DRAGON;
costBaseCreature = 3000; -- GetCreatureCost(baseCreature);
costBaseCreature2 = 3500; -- GetCreatureCost(baseCreature2);
costUpgradedCreature = 4000; -- GetCreatureCost(upgradedCreature);
costBaseCreatureSulfur = 1; -- GetCreatureResource(creature) would be nice!!!!
costBaseCreature2Sulfur = 1;
costUpgradedCreatureSulfur = 2;
singularCreature = "Green Dragon";
pluralCreature = "Green Dragons";
singularCreature2 = "Red Dragon";
pluralCreature2 = "Red Dragons";
nameGenerator = "{Dragon City}";
end;
if HasTroop(hero, baseCreature, 1) == true then
numberCreature = GetCreatureAmount(hero, baseCreature);
costUpgradeCreature = (costUpgradedCreature - costBaseCreature) * numberCreature * costMultiplier;
if baseCreature == CREATURE_GREEN_DRAGON then
sulfur = GetResource(player, RESOURCE_SULFUR);
costUpgradeCreatureSulfur = (costUpgradedCreatureSulfur - costBaseCreatureSulfur) * numberCreature * costMultiplier;
textCostSulfur = " and "..costUpgradeCreatureSulfur.." sulfur";
if sulfur >= costUpgradeCreatureSulfur then
checkSulfur = 1;
else
checkSulfur = 0;
end;
if sulfur == 0 then
textSulfurLeft = " and no sulfur left";
elseif sulfur < costUpgradeCreatureSulfur and sulfur ~= 0 then
textSulfurLeft = " and only "..sulfur.." sulfur left";
elseif sulfur >= costUpgradeCreatureSulfur then
textSulfurLeft = " and "..sulfur.." sulfur left";
end;
else
textCostSulfur = "";
checkSulfur = 1;
textSulfurLeft = "";
end;
if numberCreature == 1 then
textCreature = singularCreature;
textNumberCreature = "";
else
textCreature = pluralCreature;
textNumberCreature = ""..numberCreature.." ";
end;
if gold == 0 then
textGoldLeft = "no";
elseif gold < costUpgradeCreature and gold ~= 0 then
textGoldLeft = "only "..gold.."";
elseif gold >= costUpgradeCreature then
textGoldLeft = ""..gold.."";
end;
if gold >= costUpgradeCreature and checkSulfur == 1 then
result = QuestionBox(""..nameGenerator.."\n\n"..name..", your "..textCreature.." can be upgraded, but it will cost you dearly. You have "..textGoldLeft.." gold left"..textSulfurLeft..". Do you wish to upgrade your "..textNumberCreature..""..textCreature.." for "..costUpgradeCreature.." gold"..textCostSulfur.."?");
if result then
gold = gold - costUpgradeCreature;
SetResource(player, RESOURCE_GOLD, gold);
if baseCreature == CREATURE_GREEN_DRAGON then
sulfur = sulfur - costUpgradeCreatureSulfur;
SetResource(player, RESOURCE_SULFUR, sulfur);
end;
TakeTroop(hero, baseCreature, numberCreature);
GrantArmy(hero, upgradedCreature, numberCreature);
if numberCreature == 1 then
textCreature = ""..singularCreature.." has";
else
textCreature = ""..pluralCreature.." have";
end;
text = ""..nameGenerator.."\n\nYour "..textCreature.." been upgraded.";
dialogtype = 1;
img1type = 18;
img1arg = upgradedCreature;
AdvancedMessageBox(text, dialogtype, -1, -1, img1type, img1arg, -1, 0, -1, 0);
end;
elseif gold < costUpgradeCreature or checkSulfur == 0 then
if baseCreature == CREATURE_GREEN_DRAGON then
textShort = "resources";
else
textShort = "cash";
end;
MessageBox(""..nameGenerator.."\n\n"..name..", your "..textCreature.." can be upgraded here for "..costUpgradeCreature.." gold"..textCostSulfur..". Unfortunately, you seem to be a little short on "..textShort.." at the moment, you have "..textGoldLeft.." gold left"..textSulfurLeft..".");
end;
end;
if HasTroop(hero, CREATURE_RED_DRAGON, 1) == true and creatureGeneratorMapVisited[4 + j] == LOCATION_DRAGON_CITY then
numberCreature = GetCreatureAmount(hero, baseCreature2);
costUpgradeCreature = (costUpgradedCreature - costBaseCreature2) * numberCreature * costMultiplier;
if baseCreature2 == CREATURE_RED_DRAGON then
sulfur = GetResource(player, RESOURCE_SULFUR);
costUpgradeCreatureSulfur = (costUpgradedCreatureSulfur - costBaseCreature2Sulfur) * numberCreature * costMultiplier;
textCostSulfur = " and "..costUpgradeCreatureSulfur.." sulfur";
if sulfur >= costUpgradeCreatureSulfur then
checkSulfur = 1;
else
checkSulfur = 0;
end;
if sulfur == 0 then
textSulfurLeft = " and no sulfur left";
elseif sulfur < costUpgradeCreatureSulfur and sulfur ~= 0 then
textSulfurLeft = " and only "..sulfur.." sulfur left";
elseif sulfur >= costUpgradeCreatureSulfur then
textSulfurLeft = " and "..sulfur.." sulfur left";
end;
else
textCostSulfur = "";
checkSulfur = 1;
textSulfurLeft = "";
end;
if numberCreature == 1 then
textCreature = singularCreature2;
textNumberCreature = "";
else
textCreature = pluralCreature2;
textNumberCreature = ""..numberCreature.." ";
end;
if gold == 0 then
textGoldLeft = "no";
elseif gold < costUpgradeCreature and gold ~= 0 then
textGoldLeft = "only "..gold.."";
elseif gold >= costUpgradeCreature then
textGoldLeft = ""..gold.."";
end;
if gold >= costUpgradeCreature and checkSulfur == 1 then
result = QuestionBox(""..nameGenerator.."\n\n"..name..", your "..textCreature.." can be upgraded, but it will cost you dearly. You have "..textGoldLeft.." gold left"..textSulfurLeft..". Do you wish to upgrade your "..textNumberCreature..""..textCreature.." for "..costUpgradeCreature.." gold"..textCostSulfur.."?");
if result then
gold = gold - costUpgradeCreature;
SetResource(player, RESOURCE_GOLD, gold);
if baseCreature2 == CREATURE_RED_DRAGON then
sulfur = sulfur - costUpgradeCreatureSulfur;
SetResource(player, RESOURCE_SULFUR, sulfur);
end;
TakeTroop(hero, baseCreature2, numberCreature);
GrantArmy(hero, upgradedCreature, numberCreature);
if numberCreature == 1 then
textCreature = ""..singularCreature2.." has";
else
textCreature = ""..pluralCreature2.." have";
end;
text = ""..nameGenerator.."\n\nYour "..textCreature.." been upgraded.";
dialogtype = 1;
img1type = 18;
img1arg = upgradedCreature;
AdvancedMessageBox(text, dialogtype, -1, -1, img1type, img1arg, -1, 0, -1, 0);
end;
elseif gold < costUpgradeCreature or checkSulfur == 0 then
if baseCreature2 == CREATURE_RED_DRAGON then
textShort = "resources";
else
textShort = "cash";
end;
MessageBox(""..nameGenerator.."\n\n"..name..", your "..textCreature.." can be upgraded here for "..costUpgradeCreature.." gold"..textCostSulfur..". Unfortunately, you seem to be a little short on "..textShort.." at the moment, you have "..textGoldLeft.." gold left"..textSulfurLeft..".");
end;
end;
for k = 1, 4 do
table.remove(creatureGeneratorMapVisited, j + 1);
end;
end;
end;
end;
end;
end;
end
function OnNewDay(month, week, day)
-- Once a day, the hero recovers some spell points when he visits a shrine.
-- This clears the table.
if shrineOn == 1 then
if not (month == 1 and week == 1 and day == 1) then
shrineVisitedDay = {};
end;
end;
-- Wizard Hero special bonus: Wizard Hero recovers 2 extra spell points per day on the adventure map.
if specialBonusSpellPointWizardOn == 1 then
if not (month == 1 and week == 1 and day == 1) then
for i = 0, 53 do
hero = GetHeroInPool(i);
name = hero.name;
points = hero.spellpoints;
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
isHeroInPool = 1;
heroClass = HeroClass();
if heroClass == "wizard" then
if points < maxPoints then
points = points + specialBonusSpellPointAdventureWizard;
if points > maxPoints then
points = maxPoints;
end;
hero.spellpoints = points;
end;
end;
end;
isHeroInPool = 0;
end;
end;
-- Tweaks: Mysticism gives additional spell points each day on the adventure map (this only works for the 54 heroes in pool for now) and at the start of each combat.
-- This is for adventure map.
if mysticismAdventureOn == 1 then
if not (month == 1 and week == 1 and day == 1) then
for i = 0, 53 do
hero = GetHeroInPool(i);
mysticism = GetSecondarySkill(hero, SECONDARY_SKILL_MYSTICISM);
points = hero.spellpoints;
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
mysticismPoints = 0;
if mysticism == 1 then
mysticismPoints = mysticismAdventureBasic;
elseif mysticism == 2 then
mysticismPoints = mysticismAdventureAdvanced;
elseif mysticism == 3 then
mysticismPoints = mysticismAdventureExpert;
end;
if points < maxPoints then
points = points + mysticismPoints;
if points > maxPoints then
points = maxPoints;
end;
hero.spellpoints = points;
end;
end;
end;
end;
-- Tweaks: Navigation also generates gold every turn.
if navigationGoldOn == 1 then
if not (month == 1 and week == 1 and day == 1) then
for i = 0, 5 do
player = GetPlayer(i);
for j = 0, GetNumHeroes(player) - 1 do
hero = GetHero(player, j);
navigation = GetSecondarySkill(hero, SECONDARY_SKILL_NAVIGATION);
if navigation == 1 then
GiveResource(player, RESOURCE_GOLD, navigationGoldBasic);
elseif navigation == 2 then
GiveResource(player, RESOURCE_GOLD, navigationGoldAdvanced);
elseif navigation == 3 then
GiveResource(player, RESOURCE_GOLD, navigationGoldExpert);
end;
end;
end;
end;
end;
-- Tweaks: Basic Estates, small adjustment to stay better than Basic Navigation.
if estatesAdjustmentOn == 1 then
if not (month == 1 and week == 1 and day == 1) then
for i = 0, 5 do
player = GetPlayer(i);
for j = 0, GetNumHeroes(player) - 1 do
hero = GetHero(player, j);
estates = GetSecondarySkill(hero, SECONDARY_SKILL_ESTATES);
if estates == 1 then
GiveResource(player, RESOURCE_GOLD, estatesAdjustmentBasic);
end;
end;
end;
end;
end;
-- Each peasant generates 1 gold per day (only in the hero's army for now).
if peasantGoldOn == 1 then
if not (month == 1 and week == 1 and day == 1) then
for i = 0, 5 do
player = GetPlayer(i);
for j = 0, GetNumHeroes(player) - 1 do
hero = GetHero(player, j);
if HasTroop(hero, CREATURE_GOBLIN, 1) == true then -- CREATURE_PEASANT or 0 do not work!!!
numberPeasant = GetCreatureAmount(hero, CREATURE_GOBLIN); -- CREATURE_PEASANT
goldGain = numberPeasant * peasantGoldDay;
GiveResource(player, RESOURCE_GOLD, goldGain);
end;
end;
end;
end;
end;
-- Tweaks: The Power Ring artifact gives 2 extra spell points per day on the adventure map (total of 4 spell points with the original effect).
if tweaksSpellPointAdventurePowerRingOn == 1 then
if not (month == 1 and week == 1 and day == 1) then
for i = 0, 53 do
hero = GetHeroInPool(i);
points = hero.spellpoints;
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
if HasArtifact(hero, ARTIFACT_POWER_RING) == true then
if points < maxPoints then
points = points + tweaksSpellPointAdventurePowerRing;
if points > maxPoints then
points = maxPoints;
end;
hero.spellpoints = points;
end;
end;
end;
end;
end;
-- Once a day, the Necromancer hero with the Power Ring artifact recovers all his spell points when he visits certain locations on the adventure map (excavation, graveyard, pyramid, barrow mounds, daemon cave, city of dead).
-- This clears the table.
if necromancerLocationPowerRingOn == 1 then
if necromancerExcavationPowerRing == 1 or necromancerGraveyardPowerRing == 1 or necromancerPyramidPowerRing == 1
or necromancerBarrowMoundsPowerRing == 1 or necromancerDaemonCavePowerRing == 1 or necromancerCityOfDeadPowerRing == 1 then
if not (month == 1 and week == 1 and day == 1) then
locationVisitedPowerRing = {};
end;
end;
end;
end
function OnBattleStart()
-- At the beginning of each combat, the hero with a magic book recovers a number of spell points corresponding to 5 spell points multiplied by the initial value of the knowledge of his class
-- (Knowledge 1 for Knight and Barbarian, Knowledge 2 for Warlock, Wizard and Necromancer, Knowledge 3 for Sorceress).
if startCombatSpellPointOn == 1 then
if BattleHasHero(1) == true then
j = 1;
else
j = 0;
end;
for i = 0, j do
hero = BattleGetHero(i);
name = hero.name;
points = hero.spellpoints;
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
startCombatSpellPoint = 0;
isBattle = 1;
if HasArtifact(hero, ARTIFACT_MAGIC_BOOK) == true then
heroClass = HeroClass();
if heroClass == "knight" and startCombatSpellPointKnight == 1 then
startCombatSpellPoint = 1 * startCombatSpellPointBonus;
elseif heroClass == "barbarian" and startCombatSpellPointBarbarian == 1 then
startCombatSpellPoint = 1 * startCombatSpellPointBonus;
elseif heroClass == "sorceress" and startCombatSpellPointSorceress == 1 then
startCombatSpellPoint = 3 * startCombatSpellPointBonus;
elseif heroClass == "warlock" and startCombatSpellPointWarlock == 1 then
startCombatSpellPoint = 2 * startCombatSpellPointBonus;
elseif heroClass == "wizard" and startCombatSpellPointWizard == 1 then
startCombatSpellPoint = 2 * startCombatSpellPointBonus;
elseif heroClass == "necromancer" and startCombatSpellPointNecromancer == 1 then
startCombatSpellPoint = 2 * startCombatSpellPointBonus;
end;
end;
if points < maxPoints then
points = points + startCombatSpellPoint;
if points > maxPoints then
points = maxPoints;
end;
hero.spellpoints = points;
end;
end;
isBattle = 0;
end;
-- Wizard Hero special bonus: Wizard Hero recovers 5 extra spell points at start of combat.
if specialBonusSpellPointWizardOn == 1 then
if BattleHasHero(1) == true then
j = 1;
else
j = 0;
end;
for i = 0, j do
hero = BattleGetHero(i);
name = hero.name;
points = hero.spellpoints;
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
isBattle = 1;
heroClass = HeroClass();
if heroClass == "wizard" then
if points < maxPoints then
points = points + specialBonusSpellPointCombatWizard;
if points > maxPoints then
points = maxPoints;
end;
hero.spellpoints = points;
end;
end;
end;
isBattle = 0;
end;
-- Tweaks: Mysticism gives additional spell points each day on the adventure map and at the start of each combat.
-- This is for combat.
if mysticismCombatOn == 1 then
if BattleHasHero(1) == true then
j = 1;
else
j = 0;
end;
for i = 0, j do
hero = BattleGetHero(i);
mysticism = GetSecondarySkill(hero, SECONDARY_SKILL_MYSTICISM);
points = hero.spellpoints;
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
mysticismPoints = 0;
if mysticism == 1 then
mysticismPoints = mysticismCombatBasic;
elseif mysticism == 2 then
mysticismPoints = mysticismCombatAdvanced;
elseif mysticism == 3 then
mysticismPoints = mysticismCombatExpert;
end;
if points < maxPoints then
points = points + mysticismPoints;
if points > maxPoints then
points = maxPoints;
end;
hero.spellpoints = points;
end;
end;
end;
-- Tweaks: The Power Ring artifact gives 10 extra spell points at start of combat.
if tweaksSpellPointCombatPowerRingOn == 1 then
if BattleHasHero(1) == true then
j = 1;
else
j = 0;
end;
for i = 0, j do
hero = BattleGetHero(i);
points = hero.spellpoints;
knowledge = GetPrimarySkill(hero, PRIMARY_SKILL_KNOWLEDGE);
maxPoints = knowledge * 10;
if HasArtifact(hero, ARTIFACT_POWER_RING) == true then
if points < maxPoints then
points = points + tweaksSpellPointCombatPowerRing;
if points > maxPoints then
points = maxPoints;
end;
hero.spellpoints = points;
end;
end;
end;
end;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.