protected override void InstanceSetTaskPlan(TaskPlan2 taskPlan) { base.InstanceSetTaskPlan(taskPlan); if (taskPlan != null) { UpdateFormationFacing(unit, GetTaskMarker().GetWorldPosition()); unit.GetFormation().FormTest(); foreach (var subg in actorGroupAsUG.GetSubGroupsAsUG()) { Vector3 wpos; wpos = subg.GetActorsAsUnits()[0].GetFormation().GetAcceptableMovementTargetPosition(GetTaskMarker().GetWorldPosition()); MoveTaskMarker tm = TaskMarker.CreateInstanceAtWorldPosition <MoveTaskMarker>(wpos); tm.AddWaypointMarker(WaypointMarker.CreateWaypointMarker(wpos)); MoveTask chmvt = tm.GetTask() as MoveTask; chmvt.parentActorMoveTask = this; subActorsMoveTasks.Add(subg, chmvt); chmvt.SubscribeOnDestruction("removeparentssubactorsmovetasks", () => subActorsMoveTasks.Remove(subg)); subg.SubscribeOnParentGroupChange("onchangeparentgroup", () => { chmvt.parentActorMoveTask = null; subActorsMoveTasks.Remove(subg); subg.UnsubscribeOnParentGroupChange("onchangeparentgroup"); }); var prevtask = GetTaskPlan().GetTaskInPlanBefore(this) as MoveTask; TaskMarker chprevtm; if (prevtask != null && prevtask.subActorsMoveTasks.ContainsKey(subg)) { chprevtm = prevtask.subActorsMoveTasks[subg].GetTaskMarker(); } else { chprevtm = null; } TaskPlan2 chtp = tm.InsertAssociatedTaskIntoPlan(subg, chprevtm); } /*SubscribeOnDestruction("parentactormovetaskchange", () => * { * foreach (var chmvt in new List<MoveTask>(subActorsMoveTasks.Values)) * { * chmvt.EndExecution(); * chmvt.parentActorMoveTask = null; * } * subActorsMoveTasks.Clear(); * });*/ SetPhase(TaskPhase.Staging); } else { foreach (var chmvt in new List <MoveTask>(subActorsMoveTasks.Values)) { chmvt.EndExecution(); chmvt.parentActorMoveTask = null; } subActorsMoveTasks.Clear(); } }
/*private bool CompatibilityPerActor(IActor actor, Task task) { bool b = true; if (task is MoveTask2) { var mvtsk = task as MoveTask2; var subut = (actor as UnitGroup); //b = !((task.GetAgent() as UnitTeam).GetUnit() == subut.GetUnit() // || mvtsk.agentAsTeam.GetUnits().Where(_ => (_ as UnitTeam).GetUnit() == subut.GetUnit()).Count() > 0); } return b; }*/ protected override void InstanceSetTaskPlan(TaskPlan2 taskPlan) { base.InstanceSetTaskPlan(taskPlan); if (taskPlan != null) { Debug.Log("setting task plan to task"); SubscribeOnDestruction("clearchildrenmovetaskmarkers", () => subActorsMoveTaskMarkers.Clear()); foreach (var u in units) { /*actorGroupAsUG.SubscribeOnUnitRemovalFromGroup(u, _ => { subActorsMoveTaskMarkers.Remove(u); actorGroupAsUG.UnsubscribeOnUnitRemovalFromGroup(_); });*/ //UpdateFormationFacing(u, GetTaskMarker().GetWorldPosition()); //u.GetFormation().FormTest(); } foreach (var subg in actorGroupAsUG.GetSubGroupsAsUG()) { Vector3 wpos; wpos = subg.GetActorsAsUnits()[0].GetFormation().GetParentFormation().GetAcceptableMovementTargetPosition(GetTaskMarker().GetWorldPosition()); var prevtm = GetTaskMarker().GetPreviousTaskMarker()?.GetTask() as MoveTask2; TaskMarker chprevtm; if (prevtm != null) chprevtm = prevtm.subActorsMoveTaskMarkers.FirstOrDefault(_ => (UnitGroup)_.GetTask().GetActorGroup() == subg); else chprevtm = null; MoveTaskMarker tm = TaskMarker.CreateInstanceAtWorldPosition<MoveTaskMarker>(wpos); tm.AddWaypointMarker(WaypointMarker.CreateWaypointMarker(wpos)); TaskPlan2 chtp = tm.InsertAssociatedTaskIntoPlan(subg, chprevtm); tm.SubscribeOnDestruction("removefromparentmovetaskmarkerslist",() => subActorsMoveTaskMarkers.Remove(tm)); subActorsMoveTaskMarkers.Add(tm); } SetPhase(TaskPhase.Staging); } else { subActorsMoveTaskMarkers.Clear(); } if (taskPlan != null) { //AddSubjectAgent(GetAgent()); /*foreach (var sbt in agentAsTeam.GetAllSubTeamsBFS()) { AddSubjectAgent(sbt); }*/ /*foreach (var subAgent in GetSubjectAgents()) { var sbt = subAgent as UnitTeam; if (!sbt.IsVirtualTeam()) sbt.GetUnit().GetFormation().FormTest(); } foreach (var subAgent in GetSubjectAgents()) { Vector3 wpos; wpos = (subAgent as UnitTeam).GetUnit().GetFormation().GetAcceptableMovementTargetPosition(GetTaskMarker().GetWorldPosition()); }*/ //SetPhase(TaskPhase.Staging); } }