| 06-11-2003, 06:50 PM | #1 |
I've recently begun AI scripting (in AI files, not using triggers in WE). I'm having some troubles understanding how this whole AI concept works. This is a snippet from human.ai: Code:
local integer T
loop
call ClearHarvestAI()
set T = TownWithMine()
call HarvestGold(T,5)
call HarvestWood(0,2)
if TownCountDone(TOWN_HALL)>1 then
call HarvestGold(T+1,4)
endif
call HarvestWood(0,15)
call build_sequence()
call Sleep(3)
endloop1) What does ClearHarvestAI do? It sounds like it aborts the commands every peon is doing. 2) What does TownWithMine return? The latest constructed town hall? 3) What is the second parameter in the Harvest***() functions? 4) All these functions are placed in a loop. Why are all commands issued again and again? (like harvest*** and build_sequence)? Wouldn't it be enough if they were issued once? 5) in build_sequence there is a long queue of build commands. When this is run, are they added to a building queue or does the script "halt" until a structure is complete then moves on to the next? 6) For further (stupid?) questions like these, is there some tutorial somewhere? The FAQ didn't help much, it was basically teaching the syntax which I don't have any problems with. |
| 06-11-2003, 07:57 PM | #2 |
1) Successive calls to the harvest functions add up and ClearHarvestAI resets that. 2) It returns the id of a town with a mine. I think it usually returns that with the lowest id. 3) The first parameter is the id of the town and the second parameter says how many peasants should go harvesting. 4) The harvest functions are called so often because after the AI uses one peasant to build it does not automatically return to harvesting. It also allows to adapt to a new town hall and such things. The build sequence stuff is repeated to put things in the build queue as needed like the upgrades that are only put in the queue if a condition is true. 5) They are added to a build queue that is processed in a separate thread. 6) There has been a thread some time back in this forum where many of the built-in functions are explained. |
| 06-11-2003, 08:11 PM | #3 | |
Thank you Quote:
I know this is not the case but this is how I would explain the works of it. Perhaps I'm getting stuck on too much details here, but I'd really like to understand exactly how things works. Makes it easier to write new scripts instead of doing a few changes in existing ones. Another question, in most of the bilding functions there is an integer value as the first parameter (looking in common.ai it is named qty). What does this do? I'll try to find that thread. I searched for some good threads before but couldn't find it. Have a link to it? Thanks! |
| 06-11-2003, 08:47 PM | #4 |
The first parameter of the building functions is the quantity but in fact that is not the quantity that he should build but the total amount of that unit type he should have after building. And that is the reason that he does not build more and more of the first unit in the queue. |
| 06-11-2003, 09:06 PM | #5 |
If someone knows the link to the tread explaining all the functions I would be happy as well. :gsmile: What about trying to put together some document explaining all the functions. Maybe I'll start compiling a list with those functions I know, then those more experienced could just check for correctness. |
| 06-12-2003, 12:31 AM | #6 | |
Quote:
Ahhhh, and that the computer will rebuild structures if someone destroys them (and rebuild the army if it gets killed instead of making it just once). Thank you! |
| 06-12-2003, 05:53 AM | #7 |
http://www.wc3campaigns.com/forums/s...threadid=10748 That is the thread with the natives (the most basic things you can access). |
| 06-12-2003, 02:22 PM | #8 |
I have a few other questions: 1) In the sleep function, is the argument expressed in seconds or milliseconds? 2) I'm trying to get the amount of food the player (computer) has free. I think I should use (FoodAvail(int) - FoodUsed()) but I have no idea what the integer argument stands for. It is called base. 3) While testing my scripts I've found that sometimes the AI places 2 workers to speed build a building (often the barracks). Is there any way to prevent this? This usually screws up my building orders, since I get a lack of resources (mainly wood). 4) What does the MeleeTownHall() function do? It seems lke it creates (builds) a town hall if one is missing, but in that caase why is there a SetBuildUnit(1, TOWN_HALL) directly afterwards (in humans.ai)? |
| 06-12-2003, 04:42 PM | #9 | ||
Quote:
Seconds. Quote:
All functions in common.ai are probably not written in the most obvious way IMHO. emote_sweat |
| 06-13-2003, 06:24 AM | #10 |
The human AI speed build is probably no feature but a hardcoded bug. There is no good way to prevent it that I know of. maybe slowing down the build_seqence loop can fix it. |
