ID:272700
 
Okay, my goal is to make the AI's turn end whenever all of it's units have attacked. It works, but rarely. Is there another way to do this so that it works ALL the time?

mob/proc/AImove()
Wincheck()
if(gamestarted==1)
Endcheck()
var/mob/Pl=P[2]
if(Pl.isturn==1)
if(turns>=1)
ai_Select()

mob/proc/Endcheck()
var/A=0
var/C=0
for(var/mob/soldier/blue/B in world)
A++
if(B.attacked==1)
C++
if(A==C)
var/mob/AI=P[2]
AI.isturn=0
Playerturn()
Your AI could track two vars: units_left, and waiting_to_attack. Then, the units themselves could pass that info to the AI directly, instead of having to check each unit every round.

After a unit attacks, have it tell the AI that it did, so the AI can reduce the waiting_to_attack variable by one. When it loses a unit, subtract one from the units_left. Then your end check would just need to see if its waiting_to_attack is bigger than 0.
In response to Xooxer
I see. Thanks.