public constant real DEFAULT_PERIOD = 1.7 // The period in which the hero AI will do actions. A very low period can cause strain.
While this makes sense in general coding, it makes more sense to use events for wc3.
public constant real MOVE_DIST = 1000. // The random amount of distance the hero will move
This should probably be different depending on the unit
public constant integer MAX_INVENTORY_SIZE = 6 // The number of items the hero can hold
This is dependent upon unit and possible custom inventories
public constant real FOUNTAIN_RNG = 500. // The range the hero should be in of the fountain.
Should probably be changed to aura and it depends on the aura >.>. This value shouldn't exist... it should go until the unit has the aura on them.
private constant integer MAX_SKILL_LVL = 10 // The level at which the hero learns all of its skills
This is just plain silly as it can be dynamically calculated
return .percentLife <= .35 or (.percentLife <= .55 and .mana / GetUnitState(.hero, UNIT_STATE_MAX_MANA) <= .3) or (.maxLife < 700 and .life <= 250.)
Naive approach. This should depend on the number of enemy units, the number of ally units, the state of the ally units vs the enemy units, and depend on if there is a healer in range or not, in which case the AI should use the healer to heal the hero or w/e.
return .percentLife >= .85 and .mana / GetUnitState(.hero, UNIT_STATE_MAX_MANA) >= .65
Same issue. The return to points should be any point under play control that provides a means of healing.
JASS:
return o == 852664 or /* Healing spray
*/ o == 852183 or /* Starfall
*/ o == 852593 or /* Stampede
*/ o == 852488 or /* Flamestrike
*/ o == 852089 or /* Blizzard
*/ o == 852238 // Rain of Fire
Very bad approach. You can easily detect whether a unit is currently channeling or not. Make a seperate resource with an IsUnitChanneling function.
JASS:
private function SetupItemTypes takes nothing returns nothing
call DefaultItemBuild.addItemId('gcel', 100)
call DefaultItemBuild.addItemId('bspd', 150)
call DefaultItemBuild.addItemId('rlif', 200)
call DefaultItemBuild.addItemId('prvt', 350)
call DefaultItemBuild.addItemId('rwiz', 400)
call DefaultItemBuild.addItemId('pmna', 500)
endfunction
This seems stupid. It should be dependent on the hero and the state of the player and team.
JASS:
private function SetupLearnset takes nothing returns nothing
// Syntax:
// set LearnsetInfo[LEVEL OF HERO][HERO UNIT-TYPE ID] = SKILL ID
// Paladin
set LearnsetInfo[1]['Hpal'] = 'AHhb' // Holy Light
set LearnsetInfo[3]['Hpal'] = 'AHhb'
set LearnsetInfo[5]['Hpal'] = 'AHhb'
set LearnsetInfo[2]['Hpal'] = 'AHds' // Divine Shield
set LearnsetInfo[4]['Hpal'] = 'AHds'
set LearnsetInfo[7]['Hpal'] = 'AHds'
set LearnsetInfo[8]['Hpal'] = 'AHad' // Devotion Aura
set LearnsetInfo[9]['Hpal'] = 'AHad'
set LearnsetInfo[10]['Hpal'] = 'AHad'
set LearnsetInfo[6]['Hpal'] = 'AHre' // Resurrection
// Blood Mage
set LearnsetInfo[1]['Hblm'] = 'AHfs' // Flame Strike
set LearnsetInfo[3]['Hblm'] = 'AHfs'
set LearnsetInfo[5]['Hblm'] = 'AHfs'
// Assassin
set LearnsetInfo[1]['E000'] = 'A001' // Backstab
set LearnsetInfo[3]['E000'] = 'A001'
set LearnsetInfo[5]['E000'] = 'A001'
set LearnsetInfo[7]['E000'] = 'A001'
endfunction
This should depend on the current state of the game >.>. Obviously, if you are fighting undead heroes, you are going to want to go for Holy Light before anything else. If you have a large army and are fighting regular units, devotion aura. If you are fighting heroes regularly Divine Shield.
struct Itemset
This needs to provide a way to interface with a custom inventory
and (IsUnitAlly(u, temp.owner) or IsUnitEnemy(u, temp.owner))
That == true..
private method buyItems takes nothing returns nothing
Hero should buy items straight from the shop, so the set player state thing is silly as is the unit add item by id..
method defaultLoopActions takes nothing returns nothing
Instead of this, a goal needs to be defined for the hero. From there, the AI can follow actions leading to that goal.
method update takes nothing returns nothing
This is rather silly as it should just be tied in with events...
Threats should depend on hero weaknesses and strengths... if a hero is weak vs a specific unit, then obviously that hero should go for that unit first.
USE_ON_ATTACKED
Should use acquisition range rather than on attack
Overall, I wouldn't recommend anyone to use this resource quite yet. It requires a lot of work and a lot of rewriting. Try again ^)^. Also keep in mind that AI actions are largely dependent on the unit and the game that the unit is in as well as the state of the game. This makes general AI pretty much impossible to do, which is why I personally haven't done one. You could sort of get away with unique AI scripts for specific units, but you'd still have to customize them to a specific game (perhaps like a core goal script that effects all of the units).
All in all, I think AI has 3 parts: core AI script that all AI uses, unit specific script, and team specific scripts. You sort of have the core AI, although it isn't that great, as well as minimal support for unit specific (again not that great). This is why I said that you should probably just rewrite the whole thing ; ).