private static void createAgentsInCatalog ( AObjectCatalog agents , AgentType atype , Class < ? > aclass , int num ) { int added = 0 ; try { for ( int i = 0 ; i < num ; i ++ ) { // Create a new instance (name prefix 'a' for agents) Agent agent = ( Agent ) ( aclass . getConstructor ( String . class ) . newInstance ( "a" + Integer . toString ( i ) ) ) ; // Assign the static goal plan tree hierarchy to this instance agent . setGoals ( atype . getGoals ( ) ) ; // Add this instance to the catalog of agent instances agents . push ( agent ) ; added ++ ; } logger . info ( "Finished loading {} agents" , added ) ; } catch ( NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) { logger . error ( "Could not create instance of class " + aclass . getName ( ) ) ; } }
Creates the specified number of agent instances of the given type and adds them to the catalog .