// Get a new task for the specified creature using needs // public void GetNewTask(Creature creature) { Needs.NEEDTYPE highestNeed = Needs.NEEDTYPE.NONE; highestNeed = creature.getCreatureStats().getNeeds().getMostUrgent(); Tasks.CreatureTasks neededTask = Tasks.CreatureTasks.NONE; // No Needs based tasked // /*if (highestNeed == Needs.NEEDTYPE.NONE) * { * TribeJobPosting posting = creature.GetTribe().GetJobPosting(creature); * if(posting != null) * { * neededTask = posting.requestedTask; * } * } * else*/ neededTask = Tasks.GetAppropriateTask(highestNeed); if (neededTask == Tasks.CreatureTasks.SLEEP && creature.GetCurrentState() == Creature.CREATURE_STATE.SLEEP) { Debug.LogWarning("Task is sleep, already asleep"); return; } ActionStep.FailReason failReason = currentTask.GetPreviousStepsFailReason(); // DEPRECATED? Previous task was failed // if (failReason != ActionStep.FailReason.NA) { } startNewTask(neededTask); }
// EXCEPTION ACTIONS, Do these when tasks fail for a certain reason // public static ActionStep[] GetExceptionActions(Tasks.CreatureTasks task, ActionStep.FailReason failReason, Creature creature) { Tasks.CreatureTasks exceptionTask = Tasks.CreatureTasks.NONE; // Couldn't locate Sleeping spot // if (task == Tasks.CreatureTasks.SLEEP && failReason == ActionStep.FailReason.InfinityDistance) { exceptionTask = Tasks.CreatureTasks.EXPLORE; } // Don't know of any food // if (task == Tasks.CreatureTasks.EAT && failReason == ActionStep.FailReason.NoKnownFoodProducer) { exceptionTask = Tasks.CreatureTasks.EXPLORE; } else if (task == Tasks.CreatureTasks.EAT && failReason == ActionStep.FailReason.NoKnownFood) { exceptionTask = Tasks.CreatureTasks.MOVE_AND_OBSERVE; } ActionStep[] steps = GetTaskList(exceptionTask); // If we're exploring looking for food, only explore for a little bit // if (task == Tasks.CreatureTasks.EAT && failReason == ActionStep.FailReason.NoKnownFoodProducer) { //steps[1].OverrideMaxTimeAllowed(6f); } else if (task == Tasks.CreatureTasks.EAT && failReason == ActionStep.FailReason.NoKnownFood) { Thing[] foodProducers = creature.GetKnownConsumeableProducers(); List <Thing> validThings = new List <Thing>(); for (int count = 0; count < foodProducers.Length; count++) { Thing producer = foodProducers[count]; //Debug.LogWarning("Distance - " + Vector3.Distance(producer.transform.position, creature.transform.position)); if (Vector3.Distance(producer.transform.position, creature.transform.position) > 300) { validThings.Add(producer); } } Thing foodProducer = null; if (validThings.Count > 0) { foodProducer = validThings[Random.Range(0, validThings.Count)]; } if (foodProducer != null) { steps[0].SetTargetPosition(foodProducer.transform.position); creature.SetNavMeshAgentDestination(foodProducer.transform.position); } else { //Debug.LogWarning("NO valid producers"); return(GetExceptionActions(Tasks.CreatureTasks.EAT, ActionStep.FailReason.NoKnownFoodProducer, creature)); } } return(steps); }
public CreatureTaskInstance(Tasks.CreatureTasks taskType, ActionStep[] previousSteps, Thing[] targets, Creature actingCreature) { this.taskType = taskType; this._previousActionSteps = previousSteps; this.currentActionSteps = CreatureConstants.GetTaskList(taskType); this._targets = targets; this.creature = actingCreature; _currentStepNum = 0; }
private void Initialize(Actions action, Tasks.CreatureTasks task, float distanceRequiredToCompleteModifier) { maxAllowedTime = CreatureConstants.GetMaxAllowedTime(action); failReason = FailReason.NA; this.associatedTask = task; this.action = action; // No target, set to zero // _targetPosition = Vector3.zero; failReason = FailReason.NA; creatureAgentDestinationHasBeenSet = false; this.distanceRequiredToCompleteModifier = distanceRequiredToCompleteModifier; }
public static ActionStep[] GetTaskList(Tasks.CreatureTasks task) { ActionStep[] steps = null; if (task == Tasks.CreatureTasks.EAT) { steps = new ActionStep[4]; steps[0] = new ActionStep(ActionStep.Actions.Locate, task); steps[1] = new ActionStep(ActionStep.Actions.MoveTo, task); steps[2] = new ActionStep(ActionStep.Actions.Add, task); steps[3] = new ActionStep(ActionStep.Actions.Eat, task); } else if (task == Tasks.CreatureTasks.SLEEP) { steps = new ActionStep[4]; steps[0] = new ActionStep(ActionStep.Actions.Locate, task); steps[1] = new ActionStep(ActionStep.Actions.MoveTo, task, 5); steps[2] = new ActionStep(ActionStep.Actions.Land, task); steps[3] = new ActionStep(ActionStep.Actions.Sleep, task); } else if (task == Tasks.CreatureTasks.EXPLORE) { steps = new ActionStep[2]; steps[0] = new ActionStep(ActionStep.Actions.Locate, task); steps[1] = new ActionStep(ActionStep.Actions.MoveTo, task, 30); } else if (task == Tasks.CreatureTasks.GATHER) { steps = new ActionStep[2]; steps[0] = new ActionStep(ActionStep.Actions.Locate, task, Thing.Base_Types.PLANT); steps[1] = new ActionStep(ActionStep.Actions.MoveTo, task); } else if (task == Tasks.CreatureTasks.MOVE_AND_OBSERVE) { steps = new ActionStep[1]; steps[0] = new ActionStep(ActionStep.Actions.MoveTo, task, 30); } return(steps); }
private static Tasks.CreatureTasks GetExceptionTask(Tasks.CreatureTasks task, ActionStep.FailReason failReason) { return(Tasks.CreatureTasks.EXPLORE); }
public ActionStep(Actions action, Tasks.CreatureTasks task, Thing.Base_Types targetBaseType) { this.targetBaseType = targetBaseType; Initialize(action, task, 1); }
public ActionStep(Actions action, Tasks.CreatureTasks task) { Initialize(action, task, 1); }
public ActionStep(Actions action, Tasks.CreatureTasks task, float distanceRequiredToCompleteModifier) { Initialize(action, task, distanceRequiredToCompleteModifier); }
private void startNewTask(Tasks.CreatureTasks neededTask) { currentTask = new CreatureTaskInstance(neededTask, currentTask.currentActionSteps, new Thing[0], creature); busy = true; }
public TribeJobPosting(float urgency, Tasks.CreatureTasks task, TribeJob parentJob) { this.urgency = urgency; this.requestedTask = task; this.associatedJob = parentJob; }