Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
writing basic AI
#6
    C-Code:
bool is_attacking(int j){
   if( !is_object(j) || target.id == 999 ){ return false; }
 
   int x = target.state;
   int i = 0;
   do{ x /= 10; i++; }while( x > 0);
   x = 1;
   for( i; i > 1; --i ){ x *= 10; }
 
   return ( target.team != self.team && ( ( target.type == 0 && frame(j,60,99) ) || target.state/x == 3 || target.state == 18 || target.state == 19 || target.state == 1002 || target.state == 2000 ) ) ? true : false;
}
So this function is supposed to return true if the target is attacking. With the first line I return false whenever this object does not exist or is just a broken weapon piece.

If that's not the case, in the last line I return true if the object is attacking. The easiest option is: return true if the target is on a different team and in state 3, the attacking state. But this will only recognize characters doing basic attacks because all projectiles use attacking states like 3000, 3005 and 3006. Also some character attacks use state 301. I did not want to check for all of these separately, so I simply checked whether the state begins with a 3. For that the code in between determines the length of the state and creates a 1 with trailing zeros to have the same amount of digits (1 for state 3, 100 for 301, 1000 for 3000/3001/etc). If dividing the target state by this number equals 3 then the state starts off with 3. There are also other attacking states such as the light and heavy throwing weapon states and the fire states 19 and 18 (I now notice I did not take into consideration that team mates with state 18 are attacking you too).

Now this function is anything but perfect, because there was no way to truly check for itrs yet. Version 3.0 will allow me to simply check whether the target is on a different team and has a damaging itr in its current frame. That will be a lot simpler and much more efficient than this.

    C-Code:
int square_distance(int s, int t){
 
   loadTarget(s);
   int sx = target.x;
   int sy = target.y;
   int sz = target.z;
 
   loadTarget(t);
   int tx = target.x;
   int ty = target.y;
   int tz = target.z;
 
   return (sx-tx)*(sx-tx) + (sy-ty)*(sy-ty) + (sz-tz)*(sz-tz);
}
The square distance function loads the coordinates of two objects and returns their absolute squared distance (Pythagoras shall guide you). As I don't want to waste space and resources with a square root function to turn this into a real distance it is only ever possible to compare two squared distances with each other. If there ever is a need to compare a real distance with this one it can simply be squared as well.

next: the hit time function and an updated is attacking function
Reply
Thanks given by: John Fighterli


Messages In This Thread
writing basic AI - by YinYin - 08-19-2012, 12:19 PM
RE: writing basic AI - by Alblaka - 08-19-2012, 03:34 PM
RE: writing basic AI - by Boop - 08-19-2012, 04:08 PM
RE: writing basic AI - by YinYin - 08-19-2012, 09:29 PM
RE: writing basic AI - by YinYin - 08-21-2012, 03:39 PM
RE: writing basic AI - by YinYin - 08-25-2012, 07:38 AM
RE: writing basic AI - by YinYin - 06-04-2013, 07:40 PM



Users browsing this thread: 1 Guest(s)