/*******************/
/**SPAWN COMBAT AI**/
/*******************/
New(/**/)
..(/**/)
while(src)
sleep(rand(15,18))
var/mob/target
src.stable=1
target=locate(/mob/player) in oview(7,src)
while(target && !src.aggressive && !src.blastable)
sleep(rand(15,18))
step(src,pick(NORTH,SOUTH,EAST,WEST))
while(target && src.aggressive && !src.blastable)
sleep(rand(10,12))
if(get_dist(src,target)<=1)
var/next_dir = get_dir(src,target)
switch(next_dir)
if(NORTHEAST){step(src,NORTH);sleep(2);step(src,EAST)}
if(NORTHWEST){step(src,NORTH);sleep(2);step(src,WEST)}
if(SOUTHEAST){step(src,SOUTH);sleep(2);step(src,EAST)}
if(SOUTHWEST){step(src,SOUTH);sleep(2);step(src,WEST)}
src.dir=get_dir(src,target)
if(prob(src.throwchanse))
src.AIThrow(target)
else if(src.dir==get_dir(src,target))
src.AIAttack(/**/)
else
step_towards(src,target)
while(target && get_dist(src,target)<=7 && !src.aggressive && src.blastable)
sleep(rand(10,18))
if(get_dist(src,target)>1)
var/next_dir = get_dir(src,target)
switch(next_dir)
if(NORTHEAST){step(src,NORTH);sleep(2);step(src,EAST)}
if(NORTHWEST){step(src,NORTH);sleep(2);step(src,WEST)}
if(SOUTHEAST){step(src,SOUTH);sleep(2);step(src,EAST)}
if(SOUTHWEST){step(src,SOUTH);sleep(2);step(src,WEST)}
if(prob(src.newspecialmovechanse2))
src.MonsterZanzoke(/**/)
src.x = target.x+1
src.y = target.y
src.z = target.z
if(src.dir==get_dir(src,target))
if(prob(src.newspecialmovechanse1))
src.SpecialMove(/**/)
else
src.AIBlast(/**/)
else
step_towards(src,target)
else
if(get_dist(src,target)<=1)
var/next_dir = get_dir(src,target)
switch(next_dir)
if(NORTHEAST){step(src,NORTH);sleep(2);step(src,EAST)}
if(NORTHWEST){step(src,NORTH);sleep(2);step(src,WEST)}
if(SOUTHEAST){step(src,SOUTH);sleep(2);step(src,EAST)}
if(SOUTHWEST){step(src,SOUTH);sleep(2);step(src,WEST)}
src.dir=get_dir(src,target)
if(prob(src.throwchanse))
src.AIThrow(target)
else if(src.dir==get_dir(src,target))
src.AIAttack(/**/)
else
step_towards(src,target)
Problem description:
Hello there... I`ve been trying to create ai system for my game and I could really need some advice:
- How to reduce this game
- Is it even ok to make it like that
- How to detect while no target so they would go back to spawn ( allready have spawn system)
Okay, here's how I would handle AI if I weren't using my own insanely complicated techniques to keep CPU occupancy down to a minimum:
In this example, we actually define a number of states that the AI can enter based upon the position of its target.
In our case, we are using the following states:
Chase
Attack
Reset
In the Chase state, the mob attempts to get within range of the player.
In the Attack state, the mob ensures it is within the correct range of the player, and attempts to attack until that mob is dead.
In the reset state, it tries to make it home, and after a certain period of time, if it's not back home, it gives up on trying and just teleports back to home.
The reason I've split out the AI like this, is so that you can change AI behavior later easily. Your approach will not allow you to make changes to how things operate at all, so your AI will all act the same. Plus, my approach doesn't make any conditional checks that aren't necessary.
On top of that, players trigger AI aggro, rather than all monsters in the world looking for players all the time. It might be in your interests to turn it off in safezones, for instance, so players in towns don't trigger AI aggro, and it saves you some CPU.