1 registered members (TipmyPip),
18,449
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
AI states
#69906
04/06/06 20:40
04/06/06 20:40
|
Joined: Apr 2004
Posts: 516 USA
Trooper119
OP
User
|
OP
User
Joined: Apr 2004
Posts: 516
USA
|
I'm trying to take the next step so I was reading up the manuel and studying example code all over the place but I really don't understand (Beside programming in strings as indicators) how to program in states for example in war.wdl you have this Code:
if((EVENT_TYPE == EVENT_SCAN && indicator == _EXPLODE) || (EVENT_TYPE == EVENT_SHOOT && indicator == _GUNFIRE)) { MY._SIGNAL = _DETECTED; // by shooting, player gives away his position
if (indicator == _EXPLODE) {
You notice indicator == _explode as well as My.signal these very much seem to be conveniant indicators for states that the entity is in and they obviously use no strings to do it, these may be functions of some kind but I can't figure them out, so can anyone clarify a bit on how to program these or better types of states for my AI? Now that I think about it they may just be returns from the engine functions, regardless can anyone tell my what they are and how to program in states the best way possible (Is my string way the best or not) P.S. Please prove me wrong on my string idea
A clever person solves a problem. A wise person avoids it. --Einstein
Currently Codeing: Free Lite-C
|
|
|
Re: AI states
[Re: Trooper119]
#69907
04/06/06 20:44
04/06/06 20:44
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
Well I think these are just defined names. Like variables you can define names and attach a certain value to it. So you can use the name and not the value in your code to make it better to read. Example: Code:
define _running, 2; define _walking, 1; define _jumping, 3;
define walk_mode,skill21;
action test_actor { while(me) { if(my.walk_mode == _jumping) { //do this } if(my.walk_mode != _running) { //do that } //... wait(1); } }
I guess you get the idea  If this is not the way the templates are working, just correct me  Haven't ever really worked with the templates.
|
|
|
Re: AI states
[Re: Xarthor]
#69908
04/06/06 21:37
04/06/06 21:37
|
Joined: Apr 2004
Posts: 516 USA
Trooper119
OP
User
|
OP
User
Joined: Apr 2004
Posts: 516
USA
|
I edited this post but this is what I found in war.wdl P.S. There were no definitions or variables in any part of war.wdl to be found so they were imported from somewhere else, aka I really can't tell you what these where ment to do Code:
MY._SIGNAL = 0; // reset the _signal skill MY._SIGNAL = 0; MY._SIGNAL = _DETECTED; MY._SIGNAL = _DETECTED; // by shooting, player gives away his position indicator = _WATCH; indicator == _EXPLODE indicator == _GUNFIRE
I gave it some thought and defining these variables would work perfectly to define states for your players, NPC's, and enemies all you would do is do somthing like Code:
define idle,0; //do these need _ in front of them? what does that do? define search,1; define attack,2; define destroy_box,3; var bot_state; //later in action code ... action xyz { ent_create(bot, temp, bot_event); ... } ... //again later in newly created bot_event ... bot_event { bot_state = idle; //bot_state in the computer is now 0 but //it makes it nicer to our eyes like this ... } //then you would go on turning on scans and such //which would trigger states to search, attack, and destroy //at appropriate times give certain contraints //also then repetative code could be avoided by only going to //code labeled by the given states, if need be
How do you guys code your AI, do you bother with these types of technicalities, do you like it more programmer friendly (if your friend came over he would be able to edit the code with miniel amounts of comments and NO input from you), do you go for just make it work and make it effecient (who cares about anything else), or is there another method that I haven't mentioned?
Last edited by Trooper119; 04/06/06 23:42.
|
|
|
Re: AI states
[Re: Trooper119]
#69909
04/07/06 04:33
04/07/06 04:33
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
This is one method I've used: 1. Define a series of string constants for move, animation and general states.
2. Define a null string constant which actually contains the word "null".
3. If you have three different state types, define six string pointers, ...one each for the old states for three state types = 3...+ and once again one each for the new states for three state types = 3
4. Define a function (actorA0()) invoked at the beginning of a frame for every actor, which retrieves the old states for the 3 state types from the actor's skills and dumps them into the 3 old states string pointers. In the same function, simply assign the new states string pointers the values of the old states string pointers (which might have been assigned the null string constant mentioned above, if the handles in the skills were 0 or the string constants retrieved (via ptr_for_handle) from the values of handles in the skills of the actor).
5. Throughout the execution of the actors action, you can compare the string pointers with string constants directly, draw the strings (using the font height to make multiple lines of text) on the actor indicating the various states quite easily, modify the new states string pointers to point to some other string constants when certain conditions are met, and compare the old states and new states string pointers with each other to handle transitions, ie. like modifying the bounding box and/or hull of the actor, if the old move state string pointer contains the word "crouch" and the new move state string doesn't or visa versa.
6. Define a function (actorZ0()) invoked at the very end of a frame for every actor which transfers the new states string pointers into the skills for the actor, which allows them to be retrieved again from actorA0() as the new old states.
As far as the old templates are concerned: If the indicator was _WATCH the trace or scan was probably a "look" trace or scan. If the indicator was _EXPLODE the trace or scan was probably an "explosion" trace or scan. If the indicator was _GUNFIRE the trace probably wasn't a "look" trace, it was probably a "shot fired" trace. Essentially, an indicator can be used to differentiate between events with the same type when the purpose behind the event differs. In other words, if an event type isn't specific enough, a tag or indicator might be used.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|