private static void enqueueDestroyActions(IStoryAction <UintT> storyAction, CM.DomainAction domainAction,
                                           CM.Animation effectingAnimation, FireBoltActionList aaq,
                                           string parentActionId, bool implicitActorInstantiation)
 {
     foreach (CM.DestroyAction da in domainAction.DestroyActions)
     {
         float  startTick = 0;
         string actorName = null;
         foreach (CM.DomainActionParameter domainActionParameter in domainAction.Params)
         {
             if (domainActionParameter.Name == da.ActorNameParamName)
             {
                 if (!getActionParameterValue(storyAction, domainActionParameter, out actorName) ||
                     (implicitActorInstantiation && !actorWillBeInstantiated(actorName)))
                 {
                     break;
                 }
             }
         }
         startTick = getStartTick(storyAction, da, effectingAnimation);
         if (Destroy.ValidForConstruction(actorName))
         {
             aaq.Add(new Destroy(startTick, actorName)
             {
                 ParentActionId = parentActionId
             });
         }
     }
 }
Beispiel #2
0
 public static bool ValidForConstruction(string actorName, CM.Animation animation)
 {
     if (string.IsNullOrEmpty(actorName) || animation == null || string.IsNullOrEmpty(animation.FileName))
     {
         return(false);
     }
     return(true);
 }
 private static void enqueueRotateActions(IStoryAction <UintT> storyAction, CM.DomainAction domainAction,
                                          CM.Animation effectingAnimation, FireBoltActionList aaq,
                                          string parentActionId, bool implicitActorInstantiation)
 {
     foreach (CM.RotateAction ra in domainAction.RotateActions)
     {
         float   startTick     = 0;
         float   endTick       = 0;
         string  actorName     = null;
         float?  targetDegrees = null;
         Vector2?targetPoint   = null;
         foreach (CM.DomainActionParameter domainActionParameter in domainAction.Params)
         {
             if (domainActionParameter.Name == ra.ActorNameParamName)
             {
                 if (!getActionParameterValue(storyAction, domainActionParameter, out actorName) ||
                     (implicitActorInstantiation && !actorWillBeInstantiated(actorName)))
                 {
                     break;
                 }
             }
             else if (domainActionParameter.Name == ra.DestinationParamName)
             {
                 IActionProperty targetOrientation;
                 if (storyAction.TryGetProperty(domainActionParameter.Name, out targetOrientation))
                 {
                     if (targetOrientation.Value.Value is float)
                     {
                         targetDegrees = (float)targetOrientation.Value.Value;
                         if (targetOrientation.Range.Name == "x+degrees")
                         {
                             targetDegrees = targetDegrees.Value.convertSourceEngineToUnityRotation();
                         }
                     }
                     else if (targetOrientation.Value.Value is Coordinate2D)
                     {
                         targetPoint = new Vector2((float)((Coordinate2D)targetOrientation.Value.Value).X,
                                                   (float)((Coordinate2D)targetOrientation.Value.Value).Y);
                     }
                 }
                 else
                 {
                     Debug.LogError("orientation not set for stepId[" + storyAction.Name + "]");
                 }
             }
         }
         startTick = getStartTick(storyAction, ra, effectingAnimation);
         endTick   = getEndTick(storyAction, ra, effectingAnimation, startTick);
         var targetRotation = new Vector3Nullable(null, targetDegrees, null);
         if (Rotate.ValidForConstruction(actorName, targetRotation, targetPoint))
         {
             aaq.Add(new Rotate(startTick, endTick, actorName, targetRotation, targetPoint)
             {
                 ParentActionId = parentActionId
             });
         }
     }
 }
        private static CM.Animation getEffectingAnimation(IStoryAction <UintT> storyAction, CM.DomainAction domainAction)
        {
            //find effector if any
            CM.AnimateAction effectorAnimateAction = domainAction.AnimateActions.Find(x => x.Effector);
            //didn't find an effector for this domain action...move along; nothing to see here
            if (effectorAnimateAction == null)
            {
                return(null);
            }

            string effectorActorName = null;

            CM.AnimationMapping effectorAnimationMapping = null;
            CM.Animation        effectingAnimation       = null;
            foreach (CM.DomainActionParameter domainActionParameter in domainAction.Params)
            {
                if (domainActionParameter.Name == effectorAnimateAction.ActorNameParamName)
                {
                    IActionProperty actorNameProperty;
                    if (storyAction.TryGetProperty(domainActionParameter.Name, out actorNameProperty))
                    {
                        effectorActorName = actorNameProperty.Value.Name;
                    }
                    if (effectorActorName == null)
                    {
                        Debug.LogError("actorName not set for stepId[" + storyAction.Name + "]");
                        return(null);
                    }
                    string abstractEffectorActorName;
                    if (!getAbstractActorName(effectorActorName, out abstractEffectorActorName))
                    {
                        Extensions.Log("Failed to find effectorActorName[{0}] in hierarchy for stepid[{1}]", effectorActorName, storyAction.Name);
                        return(null);
                    }

                    CM.Actor effectorActor;
                    if (!cm.TryGetActor(abstractEffectorActorName, out effectorActor))
                    {
                        Extensions.Log("effector actor [{0}] undefined for step[{1}]", effectorActorName, storyAction.Name);
                        return(null);
                    }
                    if (!effectorActor.TryGetAnimationMapping(effectorAnimateAction.Name, out effectorAnimationMapping))
                    {
                        Extensions.Log("cinematic model animation instance undefined for actor[" +
                                       effectorActorName + "] action[" + domainAction.Name + "] paramName[" + domainActionParameter.Name + "]");
                        return(null);
                    }
                    effectingAnimation = cm.FindAnimation(effectorAnimationMapping.AnimationName);
                    if (effectingAnimation == null)
                    {
                        Debug.LogError(string.Format("animation name [{0}] undefined.", effectingAnimation));
                    }
                }
            }
            return(effectingAnimation);
        }
        private static float getEffectorAnimationOffset(CM.Animation effectingAnimation, CM.FireBoltAction fireBoltAction)
        {
            float offset = 0;

            if (effectingAnimation != null)
            {
                CM.AnimationIndex effectingIndex = effectingAnimation.AnimationIndices.Find(x => x.Name == fireBoltAction.EffectorOffsetIndexName);
                if (effectingIndex != null)
                {
                    offset = effectingIndex.TimeOffset;
                }
            }
            return(offset);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="storyPlanPath">path to the story plan to load</param>
        /// <param name="cinematicModelPath">path to the cinematic model to load</param>
        /// <returns></returns>
        public static FireBoltActionList CreateStoryActions(Story <UintV, UintT, IIntervalSet <UintV, UintT> > story, CM.CinematicModel cm, bool implicitActorCreation)
        {
            ActorActionFactory.cm = cm;
            FireBoltActionList aaq = new FireBoltActionList();

            ActorActionFactory.story = story;
            orderedObjectSets        = story.ObjectSetGraph.ReverseTopologicalSort().ToArray();
            //orderedActionTypes = story.ActionTypeGraph.ReverseTopologicalSort().ToArray();

            implicitActorInstantiations = new Dictionary <string, bool>();

            //buildInitialState(aaq);
            if (implicitActorCreation)
            {
                createActors(aaq);
            }

            //generate FireBolt actions for the steps
            foreach (IStoryAction <UintT> storyAction in story.Actions.Values)
            {
                CM.DomainAction domainAction = getStoryDomainAction(storyAction);
                if (domainAction == null)
                {
                    continue;
                }

                CM.Animation effectingAnimation = getEffectingAnimation(storyAction, domainAction);

                enqueueCreateActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name);
                enqueueAnimateActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name, implicitActorCreation);
                enqueueDestroyActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name, implicitActorCreation);
                enqueuetranslateActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name, implicitActorCreation);
                enqueueRotateActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name, implicitActorCreation);
                enqueueAttachActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name, implicitActorCreation);
            }
            return(aaq);
        }
 private static void enqueueAttachActions(IStoryAction <UintT> storyAction, CM.DomainAction domainAction, CM.Animation effectingAnimation,
                                          FireBoltActionList aaq, string parentActionId, bool implicitActorInstantiation)
 {
     foreach (CM.AttachAction aa in domainAction.AttachActions)
     {
         float  startTick  = 0;
         string actorName  = null;
         string parentName = null;
         bool   attach     = false;
         foreach (CM.DomainActionParameter domainActionParameter in domainAction.Params)
         {
             if (domainActionParameter.Name == aa.ActorNameParamName)
             {
                 getActionParameterValue(storyAction, domainActionParameter, out actorName);
                 //TODO fail gracefully if we don't find actor param value
             }
             else if (domainActionParameter.Name == aa.ParentParamName)
             {
                 getActionParameterValue(storyAction, domainActionParameter, out parentName);
                 //TODO fail gracefully if we don't find parent param value
             }
         }
         attach    = aa.Attach;
         startTick = getStartTick(storyAction, aa, effectingAnimation);
         if ((!implicitActorInstantiation || actorWillBeInstantiated(actorName)) &&
             Create.ValidForConstruction(actorName, parentName))
         {
             aaq.Add(new Attach(startTick, actorName, parentName, attach)
             {
                 ParentActionId = parentActionId
             });
         }
     }
 }
        private static void enqueueCreateActions(IStoryAction <UintT> storyAction, CM.DomainAction domainAction,
                                                 CM.Animation effectingAnimation, FireBoltActionList aaq, string parentActionId)
        {
            foreach (CM.CreateAction ca in domainAction.CreateActions)
            {
                float   startTick   = 0;
                string  actorName   = null;
                Vector3 destination = new Vector3();
                Vector3?orientation = null;
                float   targetDegrees;
                CinematicModelMetaData metaData = new CinematicModelMetaData();

                foreach (CM.DomainActionParameter domainActionParameter in domainAction.Params)
                {
                    if (domainActionParameter.Name == ca.ActorNameParamName)
                    {
                        if (getActionParameterValue(storyAction, domainActionParameter, out actorName))//actorName is defined, we can look up a model
                        {
                            if (!getActorMetaData(actorName, out metaData))
                            {
                                break; //we failed to find the actor within the hierarchy
                            }
                        }
                    }
                    else if (domainActionParameter.Name == ca.OriginParamName)
                    {
                        IActionProperty coord;
                        if (storyAction.TryGetProperty(domainActionParameter.Name, out coord))
                        {
                            if (coord.Value.Value is Coordinate2D)
                            {
                                destination = ((Coordinate2D)coord.Value.Value).ToVector3(cm.DomainDistancePerEngineDistanceX,
                                                                                          cm.DomainDistancePerEngineDistanceY,
                                                                                          cm.DomainDistancePerEngineDistanceZ);
                            }
                            else if (coord.Value.Value is Coordinate3D)
                            {
                                destination = ((Coordinate3D)coord.Value.Value).ToVector3(cm.DomainDistancePerEngineDistanceX,
                                                                                          cm.DomainDistancePerEngineDistanceY,
                                                                                          cm.DomainDistancePerEngineDistanceZ);
                            }
                        }
                        else
                        {
                            Debug.LogError("origin not set for stepId[" + storyAction.Name + "]");
                        }
                    }
                    else if (domainActionParameter.Name == ca.OrientationParamName)
                    {
                        IActionProperty orientationProperty;
                        if (storyAction.TryGetProperty(domainActionParameter.Name, out orientationProperty) &&
                            tryConvertOrientation(orientationProperty, out targetDegrees))
                        {
                            orientation = new Vector3(0, targetDegrees, 0);
                        }
                        else
                        {
                            Debug.LogError("origin not set for stepId[" + storyAction.Name + "]");
                        }
                    }
                }
                startTick = getStartTick(storyAction, ca, effectingAnimation);
                if (Create.ValidForConstruction(actorName, metaData.ModelName))
                {
                    aaq.Add(new Create(startTick, actorName, metaData.ModelName, destination, metaData, orientation)
                    {
                        ParentActionId = parentActionId
                    });
                }
            }
        }
        private static float getEndTick(IStoryAction <UintT> storyAction, CM.FireBoltAction fireBoltAction, CM.Animation effectingAnimation, float startTick)
        {
            float endTick = storyAction.Time.End.ToMillis(cm.MillisPerTick);

            if (fireBoltAction.MaxDuration.HasValue &&
                fireBoltAction.MaxDuration.Value < storyAction.Time.End - storyAction.Time.Start)
            {
                endTick = startTick + fireBoltAction.MaxDuration.Value;
            }
            return(endTick);
        }
Beispiel #10
0
        private static float getStartTick(IStoryAction <UintT> storyAction, CM.FireBoltAction fireBoltAction, CM.Animation effectingAnimation)
        {
            float startTick = 0;

            startTick  = storyAction.Time.Start.ToMillis(cm.MillisPerTick);
            startTick += getEffectorAnimationOffset(effectingAnimation, fireBoltAction);
            return(startTick);
        }
Beispiel #11
0
        private static void enqueueAnimateActions(IStoryAction <UintT> storyAction, CM.DomainAction domainAction,
                                                  CM.Animation effectingAnimation, FireBoltActionList aaq,
                                                  string parentActionId, bool implicitActorInstantiation)
        {
            foreach (CM.AnimateAction animateAction in domainAction.AnimateActions)
            {
                string actorName                   = null;
                string abstractActorName           = null;
                float  startTick                   = 0;
                float  endTick                     = 0;
                CM.AnimationMapping animMapping    = null;
                CM.AnimationMapping stateMapping   = null;
                CM.Animation        animation      = null;
                CM.Animation        stateAnimation = new CM.Animation();


                string endName           = !string.IsNullOrEmpty(animateAction.End) ? animateAction.End : string.Empty;
                string animateActionName = animateAction.Name;

                //PURPOSE: if domain action parameter is the name of an animateAction for that domain action as defined in the cinematic model,
                //then use the parameter value as the animateAction name.
                // Used when a domain action has a variable for accepting an action to play, handy for spawn actions that require an initial state
                foreach (CM.DomainActionParameter domainActionParameter in domainAction.Params)
                {
                    //endName = string.Empty; //The endName should not be string.Empty if the below propety is never true.
                    // Extensions.Log("beforeset: " + animateAction.Name + " " +  domainActionParameter.Name);
                    if (domainActionParameter.Name.Equals(animateAction.Name))
                    {
                        getActionParameterValue(storyAction, domainActionParameter, out animateActionName);
                        endName = animateActionName;
                        break;
                    }
                }

                foreach (CM.DomainActionParameter domainActionParameter in domainAction.Params)
                {
                    if (domainActionParameter.Name == animateAction.ActorNameParamName)
                    {
                        if (getActionParameterValue(storyAction, domainActionParameter, out actorName) &&
                            (!implicitActorInstantiation || actorWillBeInstantiated(actorName)))
                        {
                            //abstractActorName = actorName;
                            if (!getAbstractActorName(actorName, out abstractActorName))
                            {
                                //can't figure out what this actor name is supposed to be.  don't try to animate it.
                                break;
                            }
                            else
                            {
                                //this forces all levels of hierarchy to implement all animations if we want them played
                                //we can't partially look up levels above for some things
                                //iterate back and forth between finding matching hierarchical parents and looking for mappings to alleviate
                                if (!getAnimationMapping(abstractActorName, animateActionName, out animMapping))
                                {
                                    Extensions.Log("cinematic model animation instance undefined for actor[" +
                                                   abstractActorName + "] animateAction[" + animateActionName + "]");
                                    break;
                                }
                            }

                            //we have a valid mapping, let's use it to find an animation for this actor
                            animation = cm.FindAnimation(animMapping.AnimationName);
                            if (animation == null)
                            {
                                Extensions.Log("animation name [{0}] undefined", animMapping.AnimationName);
                                break;
                            }

                            //end name is optional, we don't have to do this for the animation to be valid
                            if (!string.IsNullOrEmpty(endName))
                            {
                                getAnimationMapping(abstractActorName, endName, out stateMapping);
                                if (!(stateMapping == null))
                                {
                                    stateAnimation = cm.FindAnimation(stateMapping.AnimationName);

                                    if (stateAnimation == null)
                                    {
                                        Extensions.Log("state animation name [{0}] undefined", stateMapping.AnimationName);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                startTick = getStartTick(storyAction, animateAction, effectingAnimation);
                endTick   = getEndTick(storyAction, animateAction, effectingAnimation, startTick);

                if (AnimateMecanim.ValidForConstruction(actorName, animation))
                {
                    //   Extensions.Log("actor: " + actorName + " animMappingName: " + animMapping.AnimationName + " animateActionName: " + animMapping.AnimateActionName + " loop: " + animMapping.LoopAnimation);
                    aaq.Add(new AnimateMecanim(startTick, endTick, actorName, animation.FileName,
                                               animMapping.LoopAnimation, stateAnimation.FileName)
                    {
                        ParentActionId = parentActionId
                    });
                }
            }
        }
Beispiel #12
0
 private static void enqueuetranslateActions(IStoryAction <UintT> storyAction, CM.DomainAction domainAction,
                                             CM.Animation effectingAnimation, FireBoltActionList aaq,
                                             string parentActionId, bool implicitActorInstantiation)
 {
     foreach (CM.TranslateAction ta in domainAction.TranslateActions)
     {
         float           startTick   = 0;
         float           endTick     = 0;
         string          actorName   = null;
         Vector3Nullable destination = new Vector3Nullable(null, null, null);
         Vector3         origin      = Vector3.zero;
         foreach (CM.DomainActionParameter domainActionParameter in domainAction.Params)
         {
             if (domainActionParameter.Name == ta.OriginParamName)
             {
                 IActionProperty coord;
                 if (storyAction.TryGetProperty(domainActionParameter.Name, out coord))
                 {
                     if (coord.Value.Value is Coordinate2D)
                     {
                         origin = ((Coordinate2D)coord.Value.Value).ToVector3(cm.DomainDistancePerEngineDistanceX, cm.DomainDistancePerEngineDistanceY, cm.DomainDistancePerEngineDistanceZ);
                     }
                     else if (coord.Value.Value is Coordinate3D)
                     {
                         origin = ((Coordinate3D)coord.Value.Value).ToVector3(cm.DomainDistancePerEngineDistanceX, cm.DomainDistancePerEngineDistanceY, cm.DomainDistancePerEngineDistanceZ);
                     }
                 }
                 else
                 {
                     Debug.LogError("origin not set for stepId[" + storyAction.Name + "]");
                 }
             }
             else if (domainActionParameter.Name == ta.DestinationParamName)
             {
                 IActionProperty coord;
                 if (storyAction.TryGetProperty(domainActionParameter.Name, out coord))
                 {
                     if (coord.Value.Value is Coordinate2D)
                     {
                         destination = ((Coordinate2D)coord.Value.Value).ToVector3Nullable(cm.DomainDistancePerEngineDistanceX, cm.DomainDistancePerEngineDistanceY, cm.DomainDistancePerEngineDistanceZ);
                     }
                     else if (coord.Value.Value is Coordinate3D)
                     {
                         destination = ((Coordinate3D)coord.Value.Value).ToVector3Nullable(cm.DomainDistancePerEngineDistanceX, cm.DomainDistancePerEngineDistanceY, cm.DomainDistancePerEngineDistanceZ);
                     }
                 }
                 else
                 {
                     Debug.LogError("destination not set for stepId[" + storyAction.Name + "]");
                 }
             }
             else if (domainActionParameter.Name == ta.ActorNameParamName)
             {
                 if (!getActionParameterValue(storyAction, domainActionParameter, out actorName) ||
                     (implicitActorInstantiation && !actorWillBeInstantiated(actorName)))
                 {
                     break;
                 }
             }
         }
         startTick = getStartTick(storyAction, ta, effectingAnimation);
         endTick   = getEndTick(storyAction, ta, effectingAnimation, startTick);
         if (Translate.ValidForConstruction(actorName))
         {
             aaq.Add(new Translate(startTick, endTick, actorName, origin, destination)
             {
                 ParentActionId = parentActionId
             });
         }
     }
 }