BWAPI
|
00001 /* 00002 * Manager.cpp - Managers 00003 */ 00004 #include "Manager.h" 00005 #include "Common.h" 00006 #include "Agent.h" 00007 #include "Tasks/Task.h" 00008 00009 #include <BWAPI.h> 00010 00011 using namespace BWAPI; 00012 00013 00014 /* getAgentsOfType - Gets an AgentSet containing all owned Agents of the specified type, from this Manager's AgentSet */ 00015 AgentSet Manager::getAgentsOfType(UnitType type) 00016 { 00017 return getAgentsOfType(type, agents); 00018 } 00019 00020 /* getAgentsOfType - Gets an AgentSet containing all owned Agents of the specified type from the specified AgentSet */ 00021 AgentSet Manager::getAgentsOfType(UnitType type, AgentSet& agentSet) 00022 { 00023 AgentSet resultSet; 00024 AgentSetIter it = agentSet.begin(); 00025 AgentSetIter end = agentSet.end(); 00026 for(; it != end; ++it) 00027 { 00028 Agent* agent = *it; 00029 if( agent->getUnit().getType() == type ) 00030 resultSet.insert(agent); 00031 } 00032 return resultSet; 00033 } 00034 00035 /* update - Called on each frame */ 00036 void Manager::update() 00037 { 00038 // Tell agents to update 00039 AgentSetIter agent; 00040 for (agent = agents.begin(); agent != agents.end(); agent++) 00041 { 00042 (*agent)->update(); 00043 } 00044 } 00045 00046 /* draw */ 00047 void Manager::draw() 00048 { 00049 for (AgentSetIter agent = agents.begin(); agent != agents.end(); agent++) 00050 (*agent)->draw(); 00051 } 00052 00053 /* addAgent - Add an Agent to the Managers Agent set */ 00054 void Manager::addAgent(Agent &t) 00055 { 00056 agents.insert(&t); 00057 } 00058 00059 /* removeAgent - Remove an Agent of @ut from the Managers Agent set */ 00060 Agent* Manager::removeAgent(UnitType ut) 00061 { 00062 Agent *agent = NULL; 00063 AgentSetIter it; 00064 for (it = agents.begin(); it != agents.end(); it++) 00065 { 00066 if ((*it)->getUnit().getType().getID() == ut.getID()) 00067 { 00068 agent = *it; 00069 agents.erase(agent); 00070 break; 00071 } 00072 } 00073 return agent; 00074 } 00075 00076 /* removeAllAgents - Remove all agents 00077 * Note: this doesn't free memory allocated for each Agent, 00078 * it just dumps the pointers 00079 */ 00080 void Manager::removeAllAgents() 00081 { 00082 agents.clear(); 00083 } 00084 00085 /* addTask - Add this task to the task queue */ 00086 void Manager::addTask(Task &t) 00087 { 00088 tasks.push(&t); 00089 } 00090 00091 /* doTask - Do this task without entering the queue */ 00092 void Manager::doTask(Task &t) 00093 { 00094 00095 } 00096 00097 /* mwtpNext - Value currently placed on accepting one more of this unit type */ 00098 int Manager::mwtpNext(UnitType &ut) 00099 { 00100 return 0; 00101 } 00102 00103 /* mwtpLast - Value currently placed on the last of this unit type */ 00104 int Manager::mwtpLast(UnitType &t) 00105 { 00106 return 0; 00107 } 00108 00109 /* estimateCost - best estimate at the cost of completing this task */ 00110 int Manager::estimateCost(Task &t) 00111 { 00112 return 0; 00113 } 00114 00115 /* numAgents - Find out how many Agents of any unit type this Manager owns */ 00116 int Manager::numAgents() const { return agents.size(); } 00117 00118 /* numAgents - Find out how many Agents of @type this Manager owns */ 00119 int Manager::numAgents(UnitType type) 00120 { 00121 return getAgentsOfType(type).size(); 00122 }