Beispiel #1
0
 public Worker(Unit u, Commander c)
 {
     unitID = u.ID;
     commander = c;
     unit = u;
     unitResources = new Dictionary<int, int>();
     currentState = State.IDLE;
 }
Beispiel #2
0
 public static IUnitAgent AttachAgent(Unit u, Commander c)
 {
     IUnitAgent agent = null;
     if (u.Type.Worker)
     {
         agent = new Worker(u, c);
     }
     return agent;
 }
Beispiel #3
0
        public virtual void Start(ProxyBot pProxy)
        {
            this.proxyBot = pProxy;

            int playerID = proxyBot.PlayerID;

            //AI List
            Dictionary<int, IUnitAgent> agents = new Dictionary<int, IUnitAgent>();

            //Create the commander
            Commander commander = new Commander();

            while (true)
            {
                try
                {
                    //System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 250));
                    System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64)10000 * 500));
                }
                catch (System.Exception)
                {
                }

                foreach(Unit unit in proxyBot.Units)
                {
                    //Attach an AI to any new unit
                    foreach (Unit u in proxyBot.Units)
                    {
                        if (u.PlayerID == playerID)
                        {
                            if (!agents.Keys.Contains(u.ID))
                            {
                                agents.Add(u.ID, AgentFactory.AttachAgent(u, commander));
                            }
                        }
                    }

                    //Update from command centre
                    commander.Update(proxyBot, agents);

                    //Update the unit agents
                    foreach (KeyValuePair<int, IUnitAgent> kvp in agents)
                    {
                        if (kvp.Value != null)
                        {
                            kvp.Value.Update(proxyBot);
                        }
                    }
                }
            }
        }