src/ai/ai_factory.hpp
branchnoai
changeset 9467 730cae121ae3
parent 9443 c29c91993080
child 9468 e3eb6d371fbb
equal deleted inserted replaced
9466:ce783f899b3c 9467:730cae121ae3
    93 			if (first_it == it) return NULL;
    93 			if (first_it == it) return NULL;
    94 		}
    94 		}
    95 		return f->CreateInstance();
    95 		return f->CreateInstance();
    96 	}
    96 	}
    97 
    97 
       
    98 	/**
       
    99 	 * Select the AI with the given name.
       
   100 	 * @param name the AI to select.
       
   101 	 */
       
   102 	static AIController *SelectAI(const char *name)
       
   103 	{
       
   104 		if (GetFactories().size() == 0) return NULL;
       
   105 
       
   106 		Factories::iterator it = GetFactories().begin();
       
   107 		for (; it != GetFactories().end(); it++) {
       
   108 			AIFactoryBase *f = (*it).second;
       
   109 
       
   110 			if (strcasecmp(name, f->name) == 0 && f->AllowStartup()) {
       
   111 				return f->CreateInstance();
       
   112 			}
       
   113 		}
       
   114 
       
   115 		return NULL;
       
   116 	}
       
   117 
       
   118 	/**
       
   119 	 * Fills the given buffer with the AIs we know.
       
   120 	 * @param p    start of the buffer.
       
   121 	 * @param last till were we may write.
       
   122 	 * @return till were we have written.
       
   123 	 */
       
   124 	static char *GetAIConsoleList(char *p, const char *last)
       
   125 	{
       
   126 		printf("%d\n", GetFactories().size());
       
   127 		p += snprintf(p, last - p, "List of AIs:\n");
       
   128 		Factories::iterator it = GetFactories().begin();
       
   129 		for (; it != GetFactories().end(); it++) {
       
   130 			AIFactoryBase *f = (*it).second;
       
   131 			if (!f->AllowStartup()) continue;
       
   132 			p += snprintf(p, last - p, "%10s: %s\n", f->name, f->GetDescription());
       
   133 		}
       
   134 		p += snprintf(p, last - p, "\n");
       
   135 
       
   136 		return p;
       
   137 	}
       
   138 
    98 
   139 
    99 
   140 
   100 	/**
   141 	/**
   101 	 * Get the author of the AI.
   142 	 * Get the author of the AI.
   102 	 */
   143 	 */