I have made several new upgrades via the data editor. Now I am trying to teach the standard AI how to use them. The upgrades are mostly improvements for unit stats or can be used with auto cast turned on. So there is no need to micro new abilities. I only need to order the AI to research the upgrades.
What I have done so far.
Preset definition
ENUM Research Status
Value Type: Integer
Values
No Reserach Strcuture
Not enough resources
Queued or in progress
Completed
Trigger
Advanced Zerg Tech
Events
Timer - Every 10.0 seconds of Game Time
Local Variables
ZergPlayer = 15 <Integer>
ResearchResult <ENUM Research Status>
Conditions
Actions
Variable - Set ResearchResult = (Check and Order Research for Player ZergPlayer at any Spawning Pool using Spawning Pool - Zerg - Creep Tumor Enhancements 1, Zerg - EnhanceCreepTumor1 and keep at least 0 of Gas and Minerals)
General - If (Conditions) then do (Actions) else do (Actions)
If
ResearchResult == No Reserach Structure
Then
Debug - Debug - Print String("Status", "no reserach structure")
General - Skip remaining actions
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
ResearchResult == Not enough resources
Then
Debug - Debug - Print String("Status", "not enough resources")
General - Skip remaining actions
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
ResearchResult == Queued or in progress
Then
Debug - Debug - Print String("Status", "queued or better")
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
ResearchResult == Completed
Then
Debug - Debug - Print String("Status", "completed")
Else
-------
------- Next "build order" can follow below this line
( The if clauses "no reserach structure" and "Not enough resources" will be combined and the other will be removed later. Here they are splitted for debug reasons. )
Function
Check and Order Research
Options: Function
Return Type: ENUM Research Status
Parameters
ResourceReserve = 0 <Integer>
ZergPlayer = 0 <Integer>
ResearchStructrure = No Game Link <Game Link - Unit>
Tech Order = No Ability Command <Ability Command>
Tech Upgrade = No Game Link <Game Link - Upgrade>
Grammar Text: Check and Order Research for Player ZergPlayer at any ResearchStructrure using Tech Order, Tech Upgrade and keep at least ResourceReserve of Gas and Minerals
Hint Text: (None)
Custom Script Code
Local Variables
ResourceReserve = ResourceReserve <Integer>
Tech Order = Tech Order <Ability Command>
iPlayer = ZergPlayer <Integer>
utResearchStructrureType = ResearchStructrure <Game Link - Unit>
Tech Upgrade = Tech Upgrade <Game Link - Upgrade>
uResearchStructrure = No Unit <Unit>
Actions
Variable - Set uResearchStructrure = (Random Living unit from (utResearchStructrureType units in (Entire map) owned by player iPlayer matching Excluded: Missile, Dead, Hidden, with at most Any Amount))
General - If (Conditions) then do (Actions) else do (Actions)
If
(Tech Upgrade count for player iPlayer, counting Complete) > 0
Then
General - Return Completed
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
Or
Conditions
(Tech Upgrade count for player iPlayer, counting In Progress) > 0
(Tech Upgrade count for player iPlayer, counting Queued) > 0
Then
General - Return Queued or in progress
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
uResearchStructrure == No Unit
Then
General - Return No Reserach Strcuture
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
(Player iPlayer Minerals) < (ResourceReserve + (Integer((Minerals cost of (Ability of Tech Order)))))
(Player iPlayer Vespene) < (ResourceReserve + (Integer((Gas cost of (Ability of Tech Order)))))
Then
General - Return Not enough resources
Else
Unit - Order uResearchStructrure to (Tech Order) (After Existing Orders)
General - Return Queued or in progress
Almost all parts are working. Only the resource check throws an error message.
Quote:
Trigger Error in 'gt_AdvancedZergTech_Func': Catalog field 'Cost.Minerals' could not be read (Core: a required object could not be found)
Trigger Error in 'gt_AdvancedZergTech_Func': Could not get 'str' from parameter in 'StringToFixed' (value: 0)
If the resources are available, the CPU player will already start the research. If the resouces are not available, it ignores the check tries to start the research. That fails without any response. And the function incorrectly returns Queued or in progress
Is there a way to inquire the resource costs of a research ability?
@JanChris: Go
( Talking to myself, but maybe some else can get a bit of useful information out of it later ... in case he/she stumbles upon the same problem )
What I have found out so far:
String( <Game Link - Ability> )
ID of ability ... e.g. "SpawningPoolResearch"
Value: Convert Game Link To String
Value: <Game Link - Ability> ... "Spawning Pool - Research (Spawning Pool)"
String( <Game Link - Upgrade> )
ID of upgrade ... e.g. "zerglingmovementspeed" for "Metabolic Boost"
Value: Convert Game Link To String
Value: <Game Link - Upgrade> ... "Zergling - Metabolic Boost"
Value of <Catalog Type> (String((Ability of <Ability Command>))) <string> for player <integer>)
ID of upgrade "zerglingmovementspeed", too
Value: Catalog Field Value Get
Catalog: Abilities
Entry: Convert Game Link To String
Value: <Game Link - Ability> ... "Spawning Pool - Research (Spawning Pool)"
Field Path: <string> ... "InfoArray[Research2].Upgrade" ... but I could ask here for other research topics, depends on this index
Player: <integer> ... 1
There seems to be no way to get from an upgrade to its costs. There is only a one way direction link and not a bi-directional link.
Judging it from a more distant, detached vantage point: This is logical !
upgrade costs are stored in the abilities. These bundle upgrades.
An upgrade could be used multiple times by abilities offering a research at different costs
This could be used to offer a normal speed research with normal costs
and a fast speed research with higher resource costs.
Or an upgrade is "lost" if the research building is destroyed.
but you can recover it by researching the same topic again with reduced time / resource costs
To get the costs of a research order, I can use this:
Value: Catalog Field Value Get
Catalog: Abilities
Entry: Convert Game Link To String
Value: <Game Link - Ability> ... "Spawning Pool - Research (Spawning Pool)"
Field Path: <string> ... "InfoArray[Research2].Resource[Vespene]"
Player: <integer> ... 1
or Resource[Minerals] respectively
For my function means that, I need to know the <Ability Command> of the research ability and the index of the research topic within this research ability.
Set Variable
Variable: iResearchIndex
Value: Arithmetic (Integer)
Value 1: Index Of Ability Command
Ability Command: abilcmdResearchOrder
Operator: +
Value 2: 1
This returns the correct Index.
Preset definition
ENUM Research Status
Value Type: Integer
Values
ERROR - Upgrade mismatch research index
No reserach structure
Not enough resources
No idle research structure
Queued or in progress
Research delayed (Queue full or requirements are not fulfilled)
Completed
Trigger
Advanced Zerg Tech
Events
Timer - Every 10.0 seconds of Game Time
Local Variables
iZergPlayer = 15 <Integer>
eResearchResult <ENUM Research Status>
Conditions
Actions
Variable - Set eResearchResult = (Check Zerg - EnhanceCreepTumor1 and if needed order Spawning Pool - Zerg - Creep Tumor Enhancements 1 for player iZergPlayer at any Spawning Pool keep at least 0 and 0 and Don't Wait for an idle unit )
General - If (Conditions) then do (Actions) else do (Actions)
If
Or
Conditions
eResearchResult == No Reserach Structure
eResearchResult == Not enough resources
Then
General - Skip remaining actions
Else
------- Next "build order" can follow
Function
Check and Order Research
Options: Function
Return Type: ENUM Research Status
Parameters
Upgrade = No Game Link <Game Link - Upgrade>
Research Order = No Ability Command <Ability Command - No Target>
Research Unit = No Game Link <Game Link - Unit>
Player = 1 <Integer>
Minerals = 0 <Integer>
Vespene = 0 <Integer>
Wait / Don't Wait = Wait <Wait Option>
Grammar Text: Check Upgrade and if needed order Research Order for player Player at any Research Unit keep at least Minerals and Vespene and Wait / Don't Wait for an idle unit
Hint Text: (None)
Custom Script Code
Local Variables
glUpgrade = Upgrade <Game Link - Upgrade>
abilcmdResearchOrder = Research Order <Ability Command>
utResearchStructrureType = Research Unit <Game Link - Unit>
uResearchStructrure = No Unit <Unit>
iPlayer = Player <Integer>
iResourceReserveMinerals = Minerals <Integer>
iResourceReserveVespene = Vespene <Integer>
eWaitOption = Wait / Don't Wait <Wait Option>
-------
iResearchIndex = 0 <Integer>
glResearchAbility <Game Link - Ability>
ugAllResearchStructures = (Empty unit group) <Unit Group>
iResourceAmount = 0 <Integer>
Actions
Variable - Set glResearchAbility = (Ability of abilcmdResearchOrder)
Variable - Set iResearchIndex = ((Index of abilcmdResearchOrder) + 1)
General - If (Conditions) then do (Actions) else do (Actions)
If
(glUpgrade count for player iPlayer, counting Complete) > 0
Then
Debug - Debug - Print String("Status", "completed")
General - Return Completed
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
Or
Conditions
(glUpgrade count for player iPlayer, counting In Progress) > 0
(glUpgrade count for player iPlayer, counting Queued) > 0
Then
Debug - Debug - Print String("Status", "queued or better")
General - Return Queued or in progress
Else
Variable - Set uResearchStructrure = (Random Living unit from (utResearchStructrureType units in (Entire map) owned by player iPlayer matching Excluded: Missile, Under Construction, Dead, Hidden, with at most Any Amount))
General - If (Conditions) then do (Actions) else do (Actions)
If
uResearchStructrure == No Unit
Then
Debug - Debug - Print String("Status", "no reserach structure")
General - Return No reserach structure
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
Or
Conditions
(Player iPlayer Minerals) < (iResourceReserveMinerals + (Value of Abilities (String(glResearchAbility)) ("InfoArray[Research%1].Resource[Minerals]" with up to All "%1" replaced by (String(iResearchIndex)) (Sensitive to case)) for player Any Player as an integer))
(Player iPlayer Vespene) < (iResourceReserveVespene + (Value of Abilities (String(glResearchAbility)) ("InfoArray[Research%1].Resource[Vespene]" with up to All "%1" replaced by (String(iResearchIndex)) (Sensitive to case)) for player Any Player as an integer))
Then
Debug - Debug - Print String("Status", "not enough resources")
General - Return Not enough resources
Else
Unit Group - Add all units in (utResearchStructrureType units in (Entire map) owned by player iPlayer matching Excluded: Missile, Under Construction, Dead, Hidden, with at most Any Amount) to ugAllResearchStructures
Unit Group - Remove all units in (Idle Units for player iPlayer) from ugAllResearchStructures
General - If (Conditions) then do (Actions) else do (Actions)
If
(Number of Any units in ugAllResearchStructures) == 0
eWaitOption == Wait
Then
Debug - Debug - Print String("Status", "no idle research structure")
General - Return No idle research structure
Else
Variable - Set uResearchStructrure = (Random Any unit from ugAllResearchStructures)
General - If (Conditions) then do (Actions) else do (Actions)
If
uResearchStructrure == No Unit
Then
Variable - Set uResearchStructrure = (Random Living unit from (utResearchStructrureType units in (Entire map) owned by player iPlayer matching Excluded: Missile, Under Construction, Dead, Hidden, with at most Any Amount))
Else
Variable - Set iResourceAmount = ((Player iPlayer Minerals) + (Player iPlayer Vespene))
Unit - Order uResearchStructrure to (abilcmdResearchOrder) (After Existing Orders)
General - If (Conditions) then do (Actions) else do (Actions)
If
iResourceAmount == ((Player iPlayer Minerals) + (Player iPlayer Vespene))
Then
Debug - Debug - Print String("Research delayed", (String(glUpgrade)))
General - Return Research delayed (Queue full or requirements are not fulfilled)
Else
Debug - Debug - Print String("New research started", (String(glUpgrade)))
General - Return Queued or in progress
I have made several new upgrades via the data editor. Now I am trying to teach the standard AI how to use them. The upgrades are mostly improvements for unit stats or can be used with auto cast turned on. So there is no need to micro new abilities. I only need to order the AI to research the upgrades.
What I have done so far.
Preset definition
Trigger
( The if clauses "no reserach structure" and "Not enough resources" will be combined and the other will be removed later. Here they are splitted for debug reasons. )
Function
Almost all parts are working. Only the resource check throws an error message.
If the resources are available, the CPU player will already start the research. If the resouces are not available, it ignores the check tries to start the research. That fails without any response. And the function incorrectly returns Queued or in progress
Is there a way to inquire the resource costs of a research ability?
@JanChris: Go
( Talking to myself, but maybe some else can get a bit of useful information out of it later ... in case he/she stumbles upon the same problem )
What I have found out so far:
String( <Game Link - Ability> )
ID of ability ... e.g. "SpawningPoolResearch"
String( <Game Link - Upgrade> )
ID of upgrade ... e.g. "zerglingmovementspeed" for "Metabolic Boost"
Value of <Catalog Type> (String((Ability of <Ability Command>))) <string> for player <integer>)
ID of upgrade "zerglingmovementspeed", too
but I could ask here for other research topics, depends on this index
There seems to be no way to get from an upgrade to its costs. There is only a one way direction link and not a bi-directional link.
Judging it from a more distant, detached vantage point: This is logical !
To get the costs of a research order, I can use this:
or Resource[Minerals] respectively
For my function means that, I need to know the <Ability Command> of the research ability and the index of the research topic within this research ability.
EDIT: I found another usefull built-in function:
This returns the correct Index.
Preset definition
Trigger
Function