HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Basic inheritance & native function questions

01-29-2003, 04:42 PM#1
Heptameron
1. Do all the functions and types in Blizzard.j also work in common.j and common.ai? Also, do any functions defined in common.j and .ai work in each other?

2. I am hoping to get a list of the native functions in common.ai and what they do. Here are some of my guesses. If you know what one is, please tell me.

Code:
native DebugS               takes string str                            returns nothing
Displays string str to AI player or all players, I'm not sure.
Code:
native DebugFI              takes string str, integer val               returns nothing
Same as above, but replaces "%d" with integer val.
Code:
native DebugUnitID          takes string str, integer val               returns nothing
No idea.
Code:
native DisplayText          takes integer p, string str                 returns nothing
Displays string str for player p.
Code:
native DisplayTextI         takes integer p, string str, integer val    returns nothing
Same as above, but replaces "%d" with integer val.
Code:
native DoAiScriptDebug      takes nothing                               returns boolean
No idea.
Code:
native GetAiPlayer          takes nothing                               returns integer
Returns the player this AI script is running for.
Code:
native GetHeroId            takes nothing                               returns integer
Returns a hero ID (how does this work?)
Code:
native GetHeroLevelAI       takes nothing                               returns integer
Returns the level of a hero (how does this work?)

Thanks in advance.
- Newtfeet
01-29-2003, 10:20 PM#2
AIAndy
1. The functions in blizzard.j can be copied and work in common.ai . You can access functions in common.j from an AI script. There are some functions in common.j that do not work properly from AI scripts.

2. The debug functions seem to require a special debug mode. It is unknown how to activate it. Without the debug mode they do nothing.
DoAiScriptDebug should probably return if the script is run in debug mode.
GetHeroId and GetHeroLevelAI are only needed for skilling the hero. GetHeroId returns the type of hero that should be skilled and GetHeroLevelAI returns the current level of the hero.
01-30-2003, 02:35 AM#3
Heptameron
Quote:
GetHeroId and GetHeroLevelAI are only needed for skilling the hero. GetHeroId returns the type of hero that should be skilled and GetHeroLevelAI returns the current level of the hero.
So, if a hero has an unused skill point, then GetHeroId returns the Hero ID for that hero. However, if no hero has any skill points it returns 0. And GetHeroLevelAI returns the level of the hero with a skill point, unless there is no such hero. In that case it returns 0. Right?

-Newtfeet
01-30-2003, 06:23 AM#4
PitzerMike
if no hero has any skill points the function is'nt even called(so it cannot return 0)
normally it would look like this (for humans)

globals
integer array skillspaladin
integer array skillsking
integer array skillsmage
endglobals

function SetSkills takes nothing returns nothing // here you can define the order in which the skill points will be invested by the different types of hero
set skillspaladin[1] = DIVINE_SHIELD
set skillspaladin[2] = HOLY_LIGHT
... and so on ...
endfunction

function LevelUp takes nothing returns integer // only called when hero gains level and returns the skill defined in SetSkills() for that level
local integer hero = GetHeroId()
local integer level = GetHeroLevelAI()
if hero == PALADIN then
return skillspaladin[level]
elseif hero == MTN_KING then
return skillsking[level]
else
return skillsmage[level]
endif
endfunction

function BuildLoop takes nothing returns nothing // would build Paladins, so the comp has always one Paladin
loop
if GetUnitCountDone(PALADIN) < 1 then
call SetProduce(1,PALADIN,-1)
endif
endloop
endfunction

function main takes nothing returns nothing
call SetSkills()
call SetHeroLevels(function LevelUp) // this only calls the levelup function when a hero gains a level (points are then invested according to the list in LevelUp)
call BuildLoop()
endfunction
01-30-2003, 10:24 PM#5
Heptameron
Ok, thanks! That helps a lot. Here is another section of common.ai:

Code:
 native GetUnitCount         takes integer unitid                        returns integer
Returns amount of all units of ID unitid for all players (does it include P13 - 16?) Does not count units being built. (?)
Code:
native GetPlayerUnitTypeCount takes player p, integer unitid            returns integer
Returns amount of all units of ID unitid for player p. Counts units being built.
Code:
native GetUnitCountDone     takes integer unitid                        returns integer
Returns amount of all complete units of ID unitid for AI player.
Code:
native GetTownUnitCount     takes integer id, integer tn, boolean dn    returns integer
Returns amount of all units of ID id in town tn. Counts only done units if boolean dn is true.
How does the town system work? Could someone explain it, please?
Code:
native GetUnitGoldCost      takes integer unitid                        returns integer
Returns the Gold cost of unit unitid.
Code:
native GetUnitWoodCost      takes integer unitid                        returns integer
Returns the Wood cost of unit unitid.
Code:
native GetMinesOwned        takes nothing                               returns integer
Returns the number of Gold Mines you own (i.e. Haunted or Entangled by you, or having one of your Peons in the mine in the last 20 game seconds.)
Code:
 
native GetGoldOwned         takes nothing                               returns integer
Returns the total of all gold in gold mines that you own.
Code:
native TownWithMine         takes nothing                               returns integer
Returns the town ID of a town with a Gold Mine?
Code:
native TownHasMine          takes integer townid                        returns boolean
Returns true if town townid has a Gold Mine. (?)
Code:
native TownHasHall          takes integer townid                        returns boolean
Returns true if town townid has a Town Hall structure (i.e. Keep, Halls of the Dead, Tree of Life, etc.)

-Newtfeet
01-31-2003, 10:11 AM#6
PitzerMike
GetUnitCount - counts units of that type owned by the player for whom the script is currently running (= aiplayer) (currently produced units included)
GetPlayerUnitTypeCount - same as above but you can choose the player (ie Player(0) for Player 1)
GetTownUnitCount - counts units of type owned by aiplayer in a specific town (Townsystem: 0 = Starting Base, 1 first expansion and so on, -1 is the base where all the important buildings (Barracks) are) , if boolean is true then only done units are counted
GetMinesOwned - counts mines owned by the aiplayer (for peon assignment)
GetGoldOwned - returns the amount of Gold the aiplayer ownes
TownWithMine - returns a town of the aiplayer that has a mine

all the others were correctly guessed
:D
02-01-2003, 02:27 AM#7
Heptameron
Thanks guys! Ok, here is even more common.ai:

Code:
 native GetUpgradeLevel      takes integer id                            returns integer
Returns the current level of upgrade id.
Code:
native GetUpgradeGoldCost   takes integer id                            returns integer
Returns the amount of Gold required to research upgrade id.
Code:
native GetUpgradeWoodCost   takes integer id                            returns integer
Returns the amount of Gold required to research upgrade id.
Code:
native GetNextExpansion     takes nothing                               returns integer
Returns the town id that the next expansion would be?
Code:
native GetMegaTarget        takes nothing                               returns unit
Returns an enemy unit (what makes a unit a mega target? Some infomation about targets would be nice.)
Code:
native GetBuilding          takes player p                              returns unit
Returns a building of player p (does it favor bigger buildings?)
Code:
native GetEnemyPower        takes nothing                               returns integer
No idea.
Code:
native SetAllianceTarget    takes unit id                               returns nothing
Sets unit id as a target for allied computers. (Do reciving players have to be coallied to read the target?)
Code:
native GetAllianceTarget    takes nothing                               returns unit
Reads the alliance target.
Code:
native SetProduce           takes integer qty, integer id, integer town returns boolean
Builds qty units of type id at town town (return boolean means what?)
Code:
native Unsummon             takes unit unitid                           returns nothing
Unsummons unit unitid.
Code:
native SetExpansion         takes unit peon, integer id                 returns boolean
No idea.
Code:
native SetUpgrade           takes integer id                            returns boolean
Upgrades upgrade id (return boolean means what?)
Code:
native SetHeroLevels        takes code func                             returns nothing
Runs code func to set hero skill point.
Code:
native SetNewHeroes         takes boolean state                         returns nothing
Tells the AI not to build any more heros if state is false?
Code:
native PurchaseZeppelin     takes nothing                               returns nothing
Tells a hero to go to a Goblin Labortory and purchase a Zeppelin.
Code:
native MergeUnits           takes integer qty, integer a, integer b, integer make returns boolean
Merges qty unitid a and unitid b to make unitid make (return boolean means what?)

Thanks!
-Newtfeet
02-01-2003, 08:28 AM#8
PitzerMike
GetMegaTarget - only returns a target unit if an enemy player's defense is down in order to make an all out attack, otherwise it returns null (WatchMegaTargets must be set to true in the main function)
GetBuilding - returns a building of an enemy player which can be used as attack target
GetEnemyPower - returns the amount of food used by enemies
SetAllianceTarget - first you get an attack target with functions such as GetBuilding, then you set the alliance target to this, if there are more aiplayers in the same force the other one will receive this target with the command GetAllianceTarget() and be able to attack the same target
SetProduce - boolean means that the building of the unit/building has succeeded (normally not used), nevertheless you can call it with 'call SetProduce(1,MORTAR,-1)
SetExpansion - Sets up a new base (unit would be a peon/peasant/acolyte/... that is picked before with GetExpansionPeon(), the id would be TOWN_HALL for humans), returned boolean normally not used
SetUpgrade - same again, boolean need not to be used
MergeUnits - only used for hippo riders (would look like this: call MergeUnits(1,ARCHER,HIPPO,HIPPO_RIDER), same again with the boolean

the others are quite obvious
:D
02-01-2003, 12:06 PM#9
AIAndy
GetEnemyPower does not work, always returns 0.
02-01-2003, 02:21 PM#10
Heptameron
We're on a roll!

Code:
 native SetCampaignAI        takes nothing                               returns nothing
No idea.
Code:
native SetMeleeAI           takes nothing                               returns nothing
No idea.
Code:
native SetTargetHeroes      takes boolean state                         returns nothing
Tells you units whether or not to target heros over units.
Code:
native SetPeonsRepair       takes boolean state                         returns nothing
Tells your peons whether or not to repair damaged buildings.
Code:
native SetHeroesFlee        takes boolean state                         returns nothing
Tells your heros whether or not to flee when damaged.
Code:
native SetWatchMegaTargets  takes boolean state                         returns nothing
If state is true, watch enemies to see if they leave their guard down.
Code:
native SetIgnoreInjured     takes boolean state                         returns nothing 
No idea.
Code:
native SetHeroesTakeItems   takes boolean state                         returns nothing 
Tells you heros whether or not to take items.
Code:
native SetUnitsFlee         takes boolean state                         returns nothing
Tells your units whether or not to flee when damaged.
Code:
native SetGroupsFlee        takes boolean state                         returns nothing
Tells your groups of units whether or not to flee when damaged. (If SetUnitsFlee is true and SetGroups flee is false, will a unit in a group flee if damaged?)
Code:
native SetSlowChopping      takes boolean state                         returns nothing
No idea.
Code:
native SetCaptainChanges    takes boolean allow                         returns nothing
No idea. (How do captains work? There are a ton of functions that do something with them...)
Code:
native SetSmartArtillery    takes boolean state                         returns nothing
No idea.
Code:
native SetReplacementCount  takes integer qty                           returns nothing
No idea.
Code:
native GroupTimedLife       takes boolean allow                         returns nothing
No idea.
Code:
native RemoveInjuries       takes nothing                               returns nothing
No idea.
Code:
native RemoveSiege          takes nothing                               returns nothing
No idea.

*sigh* I have a lot of no ideas!

-Newtfeet
02-01-2003, 08:09 PM#11
PitzerMike
first of all these commands are all initials which means that they are only called once at the beginning of the script

SetCampaignAI - defines the script as campaign AI (can be used when comp has larger starting base)
SetMeleeAI - defines the script as melee AI (will often not work correctly if the comp doesn't start from the beginning)
SetIgnoreInjured - if false the comp prefers targets that are already damaged
Flee Commands: i guess a unit in a group will not flee when it's damaged as long as the group is still strong enough but the whole group will flee if enemy is stronger
SetSlowChopping - has to do something with the speed the ai reacts on events (dunno exactly but is normally not used)

----------------------------------------------
CreateCaptains - initial command needed for using all the captain-commands (don't know what SetCaptainChanges means because it is never used), for example you could use them to check battle states ( if CaptainInCombat(true) == true it would mean that the ai units are involved in an offensive battle) use this to wait until battle is over and send group home with CaptainGoHome(). There are two captains (an offensive and an defensive) which can be used to determine the behaviour in battles.
---------------------------------------------

SetSmartArtillery - helps the ai to attack targets in the right order
SetReplacementCount - integers from 1 to 3 are used, higher values make the ai stronger but dunno exactly what they do

I don't know about the last three ones but only RemoveInjuries() matters because it is normally used at the beginning of the script.
02-01-2003, 10:41 PM#12
AIAndy
SetGroupsFlee enables fleeing from combat.
SetUnitsFlee activates the behaviour that a unit will flee a short way and then return.
SetSlowChopping is used in campaign AIs to make the AI chop wood very slow, so the wood is not removed in a large way. Due to the reduced resource income by that it is required to provide the AI with wood by trigger.
I think, RemoveInjuries causes highly damaged units to stay at home to heal.
My guess for RemoveSiege is that it removes siege units from the attack group.
As for the unexplained rest, try them out and tell us what they do. They might be useful.
02-02-2003, 07:00 PM#13
Heptameron
Quote:
As for the unexplained rest, try them out and tell us what they do. They might be useful.
Sorry, but I am too lazy. I want to leech infomation off you guys, not to find it myself. But who knows? I might!

Code:
 native InitAssault          takes nothing                               returns nothing
Clears assault data?
Code:
native AddAssault           takes integer qty, integer id               returns boolean
Add qty units of unitid id to the assault group.
Code:
native AddDefenders         takes integer qty, integer id               returns boolean
Adds qty units of unitid id to the defender group.
Code:
native GetCreepCamp         takes integer min, integer max, boolean flyers_ok returns unit
Returns a creep in a group of min to max creeps. If flyers_ok is false, then it will skip camps with air creeps.

-Newtfeet
02-02-2003, 10:53 PM#14
AIAndy
GetCreepCamp 's min and max refer to the sum of the levels of the creeps in the camp. The rest is right.