示例#1
0
 void ExecuteOrder(UnitTask.TaskType t, SelectionData SD)
 {
     if (SD.IsWorker())
     {
         WorkerExecute(t, SD);
     }
     else if (SD.IsVehicle())
     {
         VehicleExecute(t, SD);
     }
 }
示例#2
0
    bool TryAddOrder(Tile tile, UnitTask.TaskType type)
    {
        if (type == UnitTask.TaskType.none)
        {
            tile.CancelTilesTasks();
            return(true);
        }
        UnitTask task = TaskLibrary.Get().CreateTask(type, tile.transform.position, tile.gameObject);

        if (task == null || !task.IsValid())
        {
            return(false);
        }
        TaskList.AddTaskToGlobalTaskList(task);
        return(true);
    }
示例#3
0
 public static OrderVisualType ConvertTaskToOrderType(UnitTask.TaskType t)
 {
     if (t == UnitTask.TaskType.Mine)
     {
         return(OrderVisualType.Mine);
     }
     if (t == UnitTask.TaskType.ClearRubble)
     {
         return(OrderVisualType.Clear);
     }
     if (t == UnitTask.TaskType.Build)
     {
         return(OrderVisualType.Build);
     }
     return(OrderVisualType.None);
 }
示例#4
0
    void WorkerExecute(UnitTask.TaskType t, SelectionData SD)
    {
        bool ShouldSet = !QueueModDown;

        if (t == UnitTask.TaskType.Walk)
        {
            AddTaskToWorker(t, SD._Worker, GetMousePosition(), null, ShouldSet);
            return;
        }
        else if (t == UnitTask.TaskType.ClearRubble)
        {
            if (!AddTaskToWorker(t, SD._Worker, _hit.point, _hit.collider.gameObject, ShouldSet))
            {
                AddTaskToWorker(UnitTask.TaskType.Walk, SD._Worker, GetMousePosition(), null, ShouldSet);
            }
            return;
        }
        AddTaskToWorker(t, SD._Worker, _hit.point, _hit.collider.gameObject, ShouldSet);
    }
示例#5
0
    void UpdateOrderPaintMode()
    {
        if (MenuScript.GamePaused)
        {
            return;
        }
        if (ControlScript.instance.GetControl(ControlScript.ORDERBRUSH_MINE).InputDown)
        {
            if (Mode == CurrentSelectionMode.PlaceOrders && CurrentBrush == UnitTask.TaskType.Mine)
            {
                CurrentBrush = UnitTask.TaskType.none;
                SetMode(CurrentSelectionMode.Select);
            }
            else
            {
                CurrentBrush = UnitTask.TaskType.Mine;
                SetMode(CurrentSelectionMode.PlaceOrders);
            }
        }
        if (ControlScript.instance.GetControl(ControlScript.ORDERBRUSH_CANCEL).InputDown)
        {
            if (Mode == CurrentSelectionMode.PlaceOrders && CurrentBrush == UnitTask.TaskType.none)
            {
                SetMode(CurrentSelectionMode.Select);
            }
            else
            {
                CurrentBrush = UnitTask.TaskType.none;
                SetMode(CurrentSelectionMode.PlaceOrders);
            }
        }
        if (Mode != CurrentSelectionMode.PlaceOrders)
        {
            return;
        }

        if (LeftMouseHold)
        {
            ApplyOrderToTargetTile();
        }
    }
示例#6
0
    bool AddTaskToVehicle(UnitTask.TaskType t, Vehicle V, Vector3 Pos, GameObject OBJ, bool set = false)
    {
        UnitTask newTask = TaskLibrary.Get().CreateTask(t, Pos, OBJ);

        if (newTask == null)
        {
            return(false);
        }
        if (!TaskLibrary.CanVehicleExecuteTask(t, V))
        {
            return(false);
        }
        if (set)
        {
            V.SetTask(newTask);
        }
        else
        {
            V.AddTask(newTask);
        }
        return(true);
    }
示例#7
0
    bool AddTaskToWorker(UnitTask.TaskType t, Worker W, Vector3 Pos, GameObject OBJ, bool set = false)
    {
        UnitTask newTask = TaskLibrary.Get().CreateTask(t, Pos, OBJ);

        if (newTask == null)
        {
            return(false);
        }
        if (!TaskLibrary.CanWorkerExecuteTask(t, W))
        {
            return(false);
        }
        if (set)
        {
            W.SetTask(newTask, ShouldPlaySound());
        }
        else
        {
            W.AddTask(newTask);
        }
        return(true);
    }
示例#8
0
    public static bool CanWorkerExecuteTask(UnitTask.TaskType t, Worker w)
    {
        switch (t)
        {
        case UnitTask.TaskType.ClearRubble:
            return(w._currentTool == Unit.UnitTool.Shovel);

        case UnitTask.TaskType.Mine:
            return(w._currentTool == Unit.UnitTool.MiningTool);

        case UnitTask.TaskType.Attack:
            return(w._currentTool == Unit.UnitTool.Weapon);

        case UnitTask.TaskType.Reinforce:
        case UnitTask.TaskType.Build:
            return(w._currentTool == Unit.UnitTool.Hammer);

        case UnitTask.TaskType.flameTarget:
            return(w._currentTool == Unit.UnitTool.FlameThrower);
        }
        return(true);
    }
示例#9
0
    public UnitTask CreateTask(UnitTask.TaskType t, Vector3 pos, GameObject Data)
    {
        UnitTask newTask = null;

        switch (t)
        {
        case UnitTask.TaskType.Mine:
            RockScript Rock = Data.GetComponentInParent <RockScript>();
            if (CanMineTarget(Rock))
            {
                newTask = new UnitTask
                {
                    _location        = pos,
                    _taskType        = UnitTask.TaskType.Mine,
                    _targetRock      = Rock,
                    _requiredTool    = Unit.UnitTool.MiningTool,
                    _taskDescription = "Mining " + Rock.RockType
                };
            }
            break;

        case UnitTask.TaskType.Pickup:
            Ore O = Data.GetComponent <Ore>();
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.Pickup,
                _itemToPickUp    = Data,
                _itemType        = (O != null) ? UnitTask.ItemType.Ore : UnitTask.ItemType.EnergyCrystal,
                _taskDescription = (O != null) ? "Transporting an Ore" : "Transporting an Energy crystal",
                _requiredTool    = Unit.UnitTool.none
            };
            break;

        case UnitTask.TaskType.Walk:
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.Walk,
                _taskDescription = "Walking to location",
                _requiredTool    = Unit.UnitTool.none
            };
            break;

        case UnitTask.TaskType.Attack:
            Monster tempMonster = Data.GetComponent <Monster>();
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.Attack,
                _requiredTool    = Unit.UnitTool.Weapon,
                _taskDescription = "Attacking " + tempMonster._type,
                _targetMonster   = Data.GetComponent <Monster>()
            };
            break;

        case UnitTask.TaskType.flameTarget:
            MushroomCluster mushroom = Data.GetComponentInParent <MushroomCluster>();
            if (mushroom == null)
            {
                return(null);
            }
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.flameTarget,
                _requiredTool    = Unit.UnitTool.FlameThrower,
                _taskDescription = "Burning things",
                _targetMushroom  = mushroom
            };
            break;

        case UnitTask.TaskType.Reinforce:
            break;

        case UnitTask.TaskType.Build:
            Building tempBuilding = Data.GetComponentInParent <Building>();
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.Build,
                _targetBuilding  = Data.GetComponentInParent <Building>(),
                _requiredTool    = Unit.UnitTool.Hammer,
                _taskDescription = "Building a " + tempBuilding.name
            };
            break;

        case UnitTask.TaskType.GetTool:
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.GetTool,
                _taskDescription = "Getting " + RadialMenuScript.instance.NewTool.ToString(),
                _requiredTool    = RadialMenuScript.instance.NewTool
            };
            break;

        case UnitTask.TaskType.RefillOxygen:
            Building closestOxyGen = null;
            foreach (Building building in WorldController.GetWorldController._buildings)
            {
                if (building.tag == TagLibrary.GEN_TAG && building._Built)
                {
                    if (closestOxyGen == null || Vector3.Distance(Data.transform.position, building.transform.position) < Vector3.Distance(Data.transform.position, closestOxyGen.transform.position))
                    {
                        closestOxyGen = building;
                    }
                }
            }
            if (closestOxyGen == null)
            {
                return(null);
            }
            newTask = new UnitTask
            {
                _location        = closestOxyGen.transform.position,
                _taskType        = UnitTask.TaskType.RefillOxygen,
                _taskDescription = "Refilling Oxygen",
                _targetBuilding  = closestOxyGen
            };
            break;

        case UnitTask.TaskType.RefillEnergy:
            Building tempBuidling = Data.GetComponent <Building>();
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.RefillEnergy,
                _targetBuilding  = tempBuidling,
                _taskDescription = "Refilling " + tempBuidling.name + " energy"
            };
            break;

        case UnitTask.TaskType.ClearRubble:
            RubbleScript tempRubble = Data.GetComponentInParent <RubbleScript>();
            if (tempRubble == null)
            {
                return(null);
            }
            newTask = new UnitTask
            {
                _location        = tempRubble.transform.position,
                _taskType        = UnitTask.TaskType.ClearRubble,
                _targetRubble    = tempRubble,
                _requiredTool    = Unit.UnitTool.Shovel,
                _taskDescription = "Clearing rubble"
            };
            break;

        case UnitTask.TaskType.GetInVehicle:
            Vehicle tempVehicle = Data.GetComponent <Vehicle>();
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.GetInVehicle,
                _targetVehicle   = tempVehicle,
                _taskDescription = "Entering vehicle"
            };
            break;

        case UnitTask.TaskType.RechargeVehicle:
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.RechargeVehicle,
                _taskDescription = "Recharging vehicle"
            };
            break;

        case UnitTask.TaskType.Idle:
        case UnitTask.TaskType.none:
        default:
            Debug.LogError("Invalid Task for Create Task: " + t.ToString());
            break;
        }
        if (newTask == null || !newTask.IsValid())
        {
            return(null);
        }
        return(newTask);
    }