Exemple #1
0
    public override bool ValidateMainTask()
    {
        if (base.CurrentMainTask != null)
        {
            if (base.CurrentMainTask.CheckValidity())
            {
                return(false);
            }
            this.Unassign();
        }
        ArmyTask armyTask = null;
        float    num      = float.MaxValue;

        for (int i = 0; i < this.catspawLayer.CatspawTasks.Count; i++)
        {
            if (this.catspawLayer.CatspawTasks[i].CheckValidity() && this.catspawLayer.CatspawTasks[i].IsMinorArmyValid(this.army, 5f))
            {
                float num2 = (float)this.worldPositionningService.GetDistance(base.Garrison.WorldPosition, this.catspawLayer.CatspawTasks[i].GetTargetPosition());
                if (num > num2)
                {
                    armyTask = this.catspawLayer.CatspawTasks[i];
                    num      = num2;
                }
            }
        }
        if (base.CurrentMainTask != armyTask)
        {
            this.Assign(armyTask, new HeuristicValue(0f));
            return(true);
        }
        return(false);
    }
Exemple #2
0
 public virtual void Assign(ArmyTask task, HeuristicValue fitness)
 {
     if (this.CurrentMainTask == task)
     {
         return;
     }
     if (this.CurrentMainTask != null)
     {
         this.Unassign();
     }
     if (task != null)
     {
         if (task.AssignedArmy != null)
         {
             task.AssignedArmy.Unassign();
         }
         this.CurrentMainTask = task;
         this.CurrentMainTask.AssignedArmy = this;
         this.CurrentMainTask.CurrentAssignationFitness = fitness;
         IGameService service = Services.GetService <IGameService>();
         this.CurrentMainTask.EstimatedTurnEnd = new HeuristicValue(0f);
         this.CurrentMainTask.EstimatedTurnEnd.Add((float)(service.Game as global::Game).Turn, "current turn", new object[0]);
         this.CurrentMainTask.EstimatedTurnEnd.Add(5f, "estimated time to complete (constant)", new object[0]);
         this.CurrentMainTask.Behavior.Reset();
         this.State = TickableState.NeedTick;
     }
 }
Exemple #3
0
        private void AddTask(ArmyTask task)
        {
            lock (_tasksLock)
            {
                if (!_tasks.ContainsKey(task.Army))
                {
                    _tasks[task.Army] = new Queue <ArmyTask>();
                }

                _tasks[task.Army].Enqueue(task);
            }
        }