Beispiel #1
0
        public void UpdateInProgressTasks(TaskLauncher taskLauncher)
        {
            if (taskLauncher == null || taskLauncher.GetTaskQueueCount() == 0) //if the task launcher is invalid or there are no tasks in the queue
            {
                return;
            }

            for (int progressTaskID = 0; progressTaskID < taskLauncher.GetTaskQueueCount(); progressTaskID++)
            {
                Add(new TaskUIAttributes
                {
                    ID           = progressTaskID,
                    type         = TaskTypes.cancelPendingTask,
                    taskLauncher = taskLauncher,
                    source       = taskLauncher.FactionEntity,
                    icon         = taskLauncher.GetPendingTaskIcon(progressTaskID)
                }, 0, TaskUI.Types.inProgress);
            }
        }
Beispiel #2
0
        //checks whether a task can be added or not and if not, provide the reason in the return value
        public ErrorMessage CanAddTaskToLauncher(TaskLauncher taskLauncher, FactionEntityTask task)
        {
            if (Status.IsTaskEnabled(task.GetCode(), taskLauncher.FactionEntity.FactionID, task.IsAvailable) == false) //if the task is disabled
            {
                return(ErrorMessage.componentDisabled);
            }

            if (taskLauncher.FactionEntity.EntityHealthComp.CurrHealth < taskLauncher.GetMinHealth()) //if the task holder does not have enough health to launch task
            {
                return(ErrorMessage.sourceLowHealth);
            }

            if (taskLauncher.GetMaxTasksAmount() <= taskLauncher.GetTaskQueueCount()) //if the maximum amount of pending tasks has been reached
            {
                return(ErrorMessage.sourceMaxCapacityReached);
            }

            if (task.HasRequiredResources() == false)
            {
                return(ErrorMessage.lowResources);
            }

            if (task.GetTaskType() == TaskTypes.createUnit) //if this is a unit creation task..
            {
                int nextPopulation = task.UnitPopulationSlots + gameMgr.GetFaction(taskLauncher.FactionEntity.FactionID).GetCurrentPopulation();
                if (nextPopulation > gameMgr.GetFaction(taskLauncher.FactionEntity.FactionID).GetMaxPopulation()) //check the population slots
                {
                    return(ErrorMessage.maxPopulationReached);
                }

                if (taskLauncher.FactionEntity.FactionMgr.HasReachedLimit(task.UnitCode, task.UnitCode)) //did the unit type to create reach its limit,
                {
                    return(ErrorMessage.factionLimitReached);
                }
            }

            return(CanAddTask(taskLauncher.FactionEntity));
        }