73 /* Find the Nth item from the array */ |
73 /* Find the Nth item from the array */ |
74 Factories::iterator it = GetFactories().begin(); |
74 Factories::iterator it = GetFactories().begin(); |
75 Factories::iterator first_it; |
75 Factories::iterator first_it; |
76 for (; i > 0; i--) it++; |
76 for (; i > 0; i--) it++; |
77 first_it = it; |
77 first_it = it; |
78 AIFactoryBase *f = (*it).second; |
78 AIFactoryBase *f = it->second; |
79 |
79 |
80 if (!f->AllowStartup()) { |
80 if (!f->AllowStartup()) { |
81 /* We can't start this AI, try to find the next best */ |
81 /* We can't start this AI, try to find the next best */ |
82 do { |
82 do { |
|
83 it++; |
83 if (it == GetFactories().end()) it = GetFactories().begin(); |
84 if (it == GetFactories().end()) it = GetFactories().begin(); |
84 else it++; |
|
85 /* Back at the beginning? Drop out! */ |
85 /* Back at the beginning? Drop out! */ |
86 if (first_it == it) break; |
86 if (first_it == it) break; |
87 f = (*it).second; |
87 f = it->second; |
88 } while (!f->AllowStartup()); |
88 } while (!f->AllowStartup()); |
89 /* Unable to start any AI */ |
89 /* Unable to start any AI */ |
90 if (first_it == it) return NULL; |
90 if (first_it == it) return NULL; |
91 } |
91 } |
92 return f->CreateInstance(); |
92 return f->CreateInstance(); |