It does end after the first if statement if the returnvalue is false, from what I can tell. Note the "if (retval) then".
From what I can see of the code, there doesn't appear to be anything immediately wrong.
Could there be something else triggering it? The empires in stock seem pretty messed up at any rate; they work far better in Kwok.
I believe the AI also keeps an explorer ship or two even in the other states, though?
Code:
AI_STATE_EXPLORE_AND_EXPAND:
set lng_Max_Explorers := 3
AI_STATE_INFRASTRUCTURE:
set lng_Max_Explorers := 1
AI_STATE_ATTACK:
set lng_Max_Explorers := 1
AI_STATE_DEFEND:
set lng_Max_Explorers := 1
AI_STATE_NOT_CONNECTED:
set lng_Max_Explorers := 2