//bool occupiesSpace=true; public Agent(AGENTTYPE inType, string inName, Location inLocation) { agenttype=inType; agentName=inName; agentLocation=inLocation; inLocation.addOccupant(this); if (!(userinterfaceHolder)) userinterfaceHolder=GameObject.Find("UserInterface"); }
/// <summary> /// Returns a sequence of newly created agents using the given behaviour /// library. /// /// The type of agents are determined by their plan type, using the /// getPlanType() function. If a world object is given, it is given to the /// agent upon initialisation. /// /// The function must be given either a plan file of an agents_init structure, /// but not both. If a plan is given, then a single agent is created and /// returned as a sequence of one element. agents_init is a structure as /// returned by the agentinitparser module and allows creating and /// initialisation of several agents. The agents are created one by one /// and returned as a sequence. If both a plan and agents_init are given, /// then the plan is ignored. /// </summary> /// <param name="assemblyName">name of the library</param> /// <param name="plan">name of the plan (without path and file ending)</param> /// <param name="agentsInit">data structure for agent initialisation /// as returned by AgentInitParser.initAgentFile. The first element is the plan file name the second element is an attribute dictionary</param> /// <param name="world">world object, given to agents at construction</param> /// <returns>List of Agents</returns> public static AgentBase[] CreateAgents(string assemblyName, string plan, List <Tuple <string, object> > agentsInit, World world) { // build initialisation structure if (agentsInit == null) { if (plan == string.Empty) { throw new TypeLoadException("create_agent() requires either plan or agents_init to be specified"); } agentsInit = new List <Tuple <string, object> >(); /// string for the plan and a dictionary for the /// (behaviour, attribute) -> value assignment. agentsInit.Add(new Tuple <string, object>(plan, new Dictionary <Tuple <string, string>, object>())); } // create the agents List <AgentBase> agents = new List <AgentBase>(); foreach (Tuple <string, object> pair in agentsInit) { string agentPlan = pair.First; Dictionary <Tuple <string, string>, object> agentAttributes = (Dictionary <Tuple <string, string>, object>)pair.Second; // determine agent type from plan PLANTYPE planType = getPlanType(AssemblyControl.GetControl().GetPlanFile(assemblyName, agentPlan)); if (planType == PLANTYPE.NONE) { throw new KeyNotFoundException(string.Format("plan type of plan {0} not recognised", agentPlan)); } Type agentType = AGENTTYPE.getType(planType); // create agent and append to sequence Type[] constructorTypes = new Type[4]; constructorTypes[0] = assemblyName.GetType(); constructorTypes[1] = agentPlan.GetType(); constructorTypes[2] = agentAttributes.GetType(); constructorTypes[3] = (world != null) ? world.GetType() : typeof(World); System.Reflection.ConstructorInfo constructor = agentType.GetConstructor(constructorTypes); agents.Add((AgentBase)constructor.Invoke(new object[] { assemblyName, agentPlan, agentAttributes, world })); } return(agents.ToArray()); }
public void Spawn(AGENTTYPE agentToSpawn, Location locationToSpawn) { switch (agentToSpawn) { case AGENTTYPE.PLAYER: //add the player to the front of the heartbeat queue Agents.Insert(0,new Agent_Player(agentToSpawn, "player", locationToSpawn)); break; case AGENTTYPE.MONSTER: //add the player to the front of the heartbeat queue Agents.Insert(0,new Agent_Monster(agentToSpawn, "monster", locationToSpawn)); break; } }
public Agent_Player(AGENTTYPE inType, string inName, Location inLocation) : base(inType,inName,inLocation) { }
public void Spawn(int level, AGENTTYPE agentToSpawn, Location spawnLocation) { Levels[level].Spawn(agentToSpawn,spawnLocation); }
public Agent(AGENTTYPE inType, string inName) { agenttype=inType; agentName=inName; }
public GameObject getDisplayObject(AGENTTYPE agent) { GameObject tempGameObject=null; switch (agent) { case AGENTTYPE.PLAYER: tempGameObject=(GameObject) Instantiate(player); break; case AGENTTYPE.MONSTER: tempGameObject=(GameObject) Instantiate(monster); break; } return tempGameObject; }