Ejemplo n.º 1
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            var obj = cs.Objects[(string)ev.Targets[0]];

            if (obj.Sound != null)
            {
                var    flags = (SoundFlags)0;
                object tmp;
                if (ev.Properties.TryGetValue("flags", out tmp))
                {
                    flags = ThnEnum.Check <SoundFlags>(tmp);
                }
                float start_time = 0;
                if (ev.Properties.TryGetValue("start_time", out tmp))
                {
                    start_time = (float)tmp;
                }
                var i = obj.Sound.CreateInstance(false);
                if (i != null)
                {
                    i.Start((flags & SoundFlags.Loop) == SoundFlags.Loop, start_time);
                    cs.Coroutines.Add(new SoundRoutine()
                    {
                        Sound = i, Duration = ev.Duration
                    });
                }
                else
                {
                    FLLog.Error("Thn", "Sfx overflow");
                }
            }
        }
Ejemplo n.º 2
0
        void ProcessStartSpatialPropAnim(ThnEvent ev)
        {
            var obj = Objects[(string)ev.Targets[0]];

            var     props  = (LuaTable)ev.Properties["spatialprops"];
            Matrix4?orient = null;
            object  tmp;

            if (ev.Properties.TryGetValue("orient", out tmp))
            {
                orient = ThnScript.GetMatrix((LuaTable)tmp);
            }
            if (obj.Camera != null)
            {
                if (orient != null)
                {
                    obj.Camera.Orientation = orient.Value;
                }
                if (ev.Duration > 0)
                {
                    FLLog.Error("Thn", "spatialpropanim.duration > 0 - unimplemented");
                    //return;
                }
            }
            if (obj.Camera == null)
            {
                FLLog.Error("Thn", "StartSpatialPropAnim unimplemented");
            }
        }
Ejemplo n.º 3
0
 void ProcessEvent(ThnEvent ev)
 {
     if (ev.CustomAction != null)
     {
         ev.CustomAction();
         return;
     }
     if (ev.Type == EventTypes.SetCamera)
     {
         ProcessSetCamera(ev);
     }
     else if (ev.Type == EventTypes.StartPSys)
     {
         ProcessStartPSys(ev);
     }
     else
     {
         IThnEventRunner er;
         if (eventRunners.TryGetValue(ev.Type, out er))
         {
             er.Process(ev, this);
         }
         else
         {
             FLLog.Error("Thn", "Unimplemented event: " + ev.Type.ToString());
         }
     }
 }
Ejemplo n.º 4
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            if (!cs.Objects.ContainsKey((string)ev.Targets[0]))
            {
                FLLog.Error("Thn", $"Entity {ev.Targets[0]} does not exist");
                return;
            }
            var obj   = cs.Objects[(string)ev.Targets[0]];
            var ren   = ((ParticleEffectRenderer)obj.Object.RenderComponent);
            var props = (LuaTable)ev.Properties["psysprops"];

            if (props.Capacity == 0)
            {
                return;
            }
            var targetSparam = (float)props["sparam"];

            if (ev.Duration == 0)
            {
                ren.SParam = targetSparam;
            }
            else
            {
                cs.Coroutines.Add(new SParamAnimation()
                {
                    Renderer    = ren,
                    StartSParam = ren.SParam,
                    EndSParam   = targetSparam,
                    Duration    = ev.Duration,
                });
            }
        }
Ejemplo n.º 5
0
        void ProcessStartPathAnimation(ThnEvent ev)
        {
            var obj   = Objects[(string)ev.Targets[0]];
            var path  = Objects[(string)ev.Targets[1]];
            var start = (float)ev.Properties["start_percent"];
            var stop  = (float)ev.Properties["stop_percent"];
            var flags = ThnEnum.Check <AttachFlags>(ev.Properties["flags"]);

            if (obj.Object != null)
            {
                coroutines.Add(new ObjectPathAnimation()
                {
                    Duration     = ev.Duration,
                    StartPercent = start,
                    StopPercent  = stop,
                    Flags        = flags,
                    Curve        = ev.ParamCurve,
                    Path         = path,
                    Object       = obj.Object
                });
            }
            if (obj.Camera != null)
            {
                coroutines.Add(new CameraPathAnimation()
                {
                    Duration     = ev.Duration,
                    StartPercent = start,
                    StopPercent  = stop,
                    Flags        = flags,
                    Curve        = ev.ParamCurve,
                    Path         = path,
                    Camera       = obj.Camera
                });
            }
        }
Ejemplo n.º 6
0
        ThnEvent GetEvent(LuaTable table)
        {
            var e = new ThnEvent();

            e.Time    = (float)table[0];
            e.Type    = ThnEnum.Check <EventTypes>(table[1]);
            e.Targets = (LuaTable)table[2];
            if (table.Capacity >= 4)
            {
                e.Properties = (LuaTable)table[3];
                //Get properties common to most events
                object tmp;
                if (e.Properties.TryGetValue("param_curve", out tmp))
                {
                    e.ParamCurve = new ParameterCurve((LuaTable)tmp);
                    if (e.Properties.TryGetValue("pcurve_period", out tmp))
                    {
                        e.ParamCurve.Period = (float)tmp;
                    }
                }
                if (e.Properties.TryGetValue("duration", out tmp))
                {
                    e.Duration = (float)tmp;
                }
            }
            return(e);
        }
Ejemplo n.º 7
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            ThnObject objA;
            ThnObject objB;

            if (!cs.Objects.TryGetValue((string)ev.Targets[0], out objA))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[0]);
                return;
            }
            if (!cs.Objects.TryGetValue((string)ev.Targets[1], out objB))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[1]);
                return;
            }
            var     targetType = ThnEnum.Check <TargetTypes>(ev.Properties["target_type"]);
            var     flags      = AttachFlags.Position | AttachFlags.Orientation;
            Vector3 offset;
            object  tmp;

            if (ev.Properties.TryGetValue("flags", out tmp))
            {
                flags = ThnEnum.Check <AttachFlags>(tmp);
            }
            ev.Properties.TryGetVector3("offset", out offset);
            //Attach GameObjects to eachother
            GameObject part = null;
            string     tgt_part;

            ev.Properties.TryGetValue("target_part", out tmp);
            tgt_part = (tmp as string);
            if (targetType == TargetTypes.Hardpoint && !string.IsNullOrEmpty(tgt_part))
            {
                part            = new GameObject();
                part.Parent     = objB.Object;
                part.Attachment = objB.Object.GetHardpoint(ev.Properties["target_part"].ToString());
            }
            if (targetType == TargetTypes.Part && !string.IsNullOrEmpty(tgt_part))
            {
                var hp = new Hardpoint(null, objB.Object.CmpConstructs.Find(ev.Properties["target_part"].ToString())); //Create a dummy hardpoint to attach to
                part            = new GameObject();
                part.Parent     = objB.Object;
                part.Attachment = hp;
            }
            cs.Coroutines.Add(new AttachRoutine()
            {
                Duration    = ev.Duration,
                Child       = objA,
                Parent      = objB,
                Part        = part,
                Position    = ((flags & AttachFlags.Position) == AttachFlags.Position),
                Orientation = ((flags & AttachFlags.Orientation) == AttachFlags.Orientation),
                LookAt      = ((flags & AttachFlags.LookAt) == AttachFlags.LookAt)
            });
        }
Ejemplo n.º 8
0
        void ProcessStartPSys(ThnEvent ev)
        {
            var obj = Objects[(string)ev.Targets[0]];
            var r   = (ParticleEffectRenderer)obj.Object.RenderComponent;

            r.Active = true;
            Coroutines.Add(new StopPSys()
            {
                Duration = ev.Duration, Fx = r
            });
        }
Ejemplo n.º 9
0
        void ProcessStartPSys(ThnEvent ev)
        {
            if (!Objects.ContainsKey((string)ev.Targets[0]))
            {
                FLLog.Error("Thn", "Entity " + ev.Targets[0].ToString() + " does not exist");
                return;
            }
            var obj = Objects[(string)ev.Targets[0]];
            var r   = (ParticleEffectRenderer)obj.Object.RenderComponent;

            r.Active = true;
            Coroutines.Add(new StopPSys()
            {
                Duration = ev.Duration, Fx = r
            });
        }
Ejemplo n.º 10
0
        void ProcessEvent(ThnEvent ev)
        {
            switch (ev.Type)
            {
            case EventTypes.SetCamera:
                ProcessSetCamera(ev);
                break;

            case EventTypes.AttachEntity:
                ProcessAttachEntity(ev);
                break;

            case EventTypes.StartPSys:
                ProcessStartPSys(ev);
                break;

            case EventTypes.StartMotion:
                ProcessStartMotion(ev);
                break;

            case EventTypes.StartFogPropAnim:
                ProcessStartFogPropAnim(ev);
                break;

            case EventTypes.StartPathAnimation:
                ProcessStartPathAnimation(ev);
                break;

            case EventTypes.StartSpatialPropAnim:
                ProcessStartSpatialPropAnim(ev);
                break;

            case EventTypes.StartPSysPropAnim:
                ProcessStartPSysPropAnim(ev);
                break;

            case EventTypes.StartLightPropAnim:
                ProcessStartLightPropAnim(ev);
                break;

            default:
                FLLog.Error("Thn", "Unimplemented event: " + ev.Type.ToString());
                break;
            }
        }
Ejemplo n.º 11
0
        void ProcessStartMotion(ThnEvent ev)
        {
            //How to tie this in with .anm files?
            var obj = Objects[(string)ev.Targets[0]];

            if (obj.Object != null && obj.Object.AnimationComponent != null)             //Check if object has Cmp animation
            {
                object o;
                bool   loop = true;
                if (ev.Properties.TryGetValue("event_flags", out o))
                {
                    if (((int)(float)o) == 3)
                    {
                        loop = false;                         //Play once?
                    }
                }
                obj.Object.AnimationComponent.StartAnimation((string)ev.Properties["animation"], loop);
            }
        }
        public void Process(ThnEvent ev, Cutscene cs)
        {
            var obj   = cs.Objects[(string)ev.Targets[0]];
            var path  = cs.Objects[(string)ev.Targets[1]];
            var start = (float)ev.Properties["start_percent"];
            var stop  = (float)ev.Properties["stop_percent"];
            var flags = ThnEnum.Check <AttachFlags>(ev.Properties["flags"]);

            cs.Coroutines.Add(new ObjectPathAnimation()
            {
                Duration     = ev.Duration,
                StartPercent = start,
                StopPercent  = stop,
                Flags        = flags,
                Curve        = ev.ParamCurve,
                Path         = path,
                Object       = obj
            });
        }
        public void Process(ThnEvent ev, Cutscene cs)
        {
            var obj = cs.Objects[(string)ev.Targets[0]];

            if (obj.Sound != null)
            {
                var    flags = (SoundFlags)0;
                object tmp;
                if (ev.Properties.TryGetValue("flags", out tmp))
                {
                    flags = ThnEnum.Check <SoundFlags>(tmp);
                }
                obj.Sound.Play(flags == SoundFlags.Loop);
                cs.Coroutines.Add(new SoundRoutine()
                {
                    Sound = obj.Sound, Duration = ev.Duration
                });
            }
        }
        public void Process(ThnEvent ev, Cutscene cs)
        {
            //How to tie this in with .anm files?
            float start_time = 0;
            float duration   = 0;
            float time_scale = 1;

            if (ev.Properties.TryGetValue("start_time", out object of))
            {
                start_time = (float)of;
            }
            if (ev.Properties.TryGetValue("time_scale", out of))
            {
                time_scale = (float)of;
            }
            if (ev.Properties.TryGetValue("duration", out of))
            {
                duration = (float)of;
            }

            var obj = cs.Objects[(string)ev.Targets[0]];

            if (obj.Object != null && obj.Object.AnimationComponent != null) //Check if object has Cmp animation
            {
                object o;
                bool   loop = false;
                if (ev.Properties.TryGetValue("event_flags", out o))
                {
                    if (((int)(float)o) == 2)
                    {
                        loop = true; //Play once?
                    }
                }
                obj.Object.AnimationComponent.StartAnimation(
                    (string)ev.Properties["animation"],
                    loop,
                    start_time,
                    time_scale,
                    duration);
            }
        }
Ejemplo n.º 15
0
        void ProcessStartPSysPropAnim(ThnEvent ev)
        {
            var obj          = Objects[(string)ev.Targets[0]];
            var ren          = ((ParticleEffectRenderer)obj.Object.RenderComponent);
            var props        = (LuaTable)ev.Properties["psysprops"];
            var targetSparam = (float)props["sparam"];

            if (ev.Duration == 0)
            {
                ren.SParam = targetSparam;
            }
            else
            {
                coroutines.Add(new SParamAnimation()
                {
                    Renderer    = ren,
                    StartSParam = ren.SParam,
                    EndSParam   = targetSparam,
                    Duration    = ev.Duration,
                });
            }
        }
Ejemplo n.º 16
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            ThnObject objA;
            ThnObject objB;

            if (!cs.Objects.TryGetValue((string)ev.Targets[0], out objA))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[0]);
                return;
            }
            if (!cs.Objects.TryGetValue((string)ev.Targets[1], out objB))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[1]);
                return;
            }
            var    targetType = ThnEnum.Check <TargetTypes>(ev.Properties["target_type"]);
            var    flags      = AttachFlags.Position | AttachFlags.Orientation;
            object tmp;

            if (ev.Properties.TryGetValue("flags", out tmp))
            {
                flags = ThnEnum.Check <AttachFlags>(tmp);
            }
            //Attach GameObjects to eachother
            GameObject part = null;
            string     tgt_part;

            ev.Properties.TryGetValue("target_part", out tmp);
            tgt_part = (tmp as string);
            if (targetType == TargetTypes.Hardpoint && !string.IsNullOrEmpty(tgt_part))
            {
                if (objB.Object == null)
                {
                    FLLog.Error("Thn", "Could not get hardpoints on " + objB.Name);
                }
                else
                {
                    part            = new GameObject();
                    part.Parent     = objB.Object;
                    part.Attachment = objB.Object.GetHardpoint(ev.Properties["target_part"].ToString());
                }
            }
            if (targetType == TargetTypes.Part && !string.IsNullOrEmpty(tgt_part))
            {
                if (objB.Object == null || objB.Object.RigidModel == null || objB.Object.RigidModel.Parts == null)
                {
                    FLLog.Error("Thn", "Could not get parts on " + objB.Name);
                }
                else
                {
                    if (objB.Object.RigidModel.Parts.TryGetValue((string)ev.Properties["target_part"], out var tgtpart))
                    {
                        var hp = new Hardpoint(null, tgtpart);
                        part            = new GameObject();
                        part.Parent     = objB.Object;
                        part.Attachment = hp;
                    }
                }
            }
            Vector3 offset = Vector3.Zero;

            if (ev.Properties.TryGetValue("offset", out tmp))
            {
                offset = ((LuaTable)tmp).ToVector3();
            }
            Quaternion lastRotate = Quaternion.Identity;

            if ((flags & AttachFlags.Orientation) == AttachFlags.Orientation &&
                (flags & AttachFlags.OrientationRelative) == AttachFlags.OrientationRelative)
            {
                if (part != null)
                {
                    lastRotate = part.GetTransform().ExtractRotation();
                }
                else
                {
                    lastRotate = objB.Rotate.ExtractRotation();
                }
            }
            cs.Coroutines.Add(new AttachRoutine()
            {
                Duration            = ev.Duration,
                Child               = objA,
                Parent              = objB,
                Part                = part,
                Position            = ((flags & AttachFlags.Position) == AttachFlags.Position),
                Orientation         = ((flags & AttachFlags.Orientation) == AttachFlags.Orientation),
                OrientationRelative = ((flags & AttachFlags.OrientationRelative) == AttachFlags.OrientationRelative),
                EntityRelative      = ((flags & AttachFlags.EntityRelative) == AttachFlags.EntityRelative),
                LookAt              = ((flags & AttachFlags.LookAt) == AttachFlags.LookAt),
                LastRotate          = lastRotate,
                Offset              = offset
            });
        }
Ejemplo n.º 17
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            if (ev.Targets.Capacity == 0)
            {
                return;
            }
            ThnObject objA;

            if (!cs.Objects.TryGetValue((string)ev.Targets[0], out objA))
            {
                FLLog.Error("Thn", "Object does not exist " + (string)ev.Targets[0]);
                return;
            }

            bool       hasPos   = false;
            Quaternion?q_orient = null;

            if (ev.Targets.Capacity >= 1)
            {
                var     props = (LuaTable)ev.Properties["spatialprops"];
                Vector3 pos;
                object  tmp;
                if (props.TryGetValue("q_orient", out tmp))
                {
                    var tb = (LuaTable)tmp;
                    q_orient = new Quaternion((float)tb[1], (float)tb[2], (float)tb[3], (float)tb[0]);
                }

                if (props.TryGetValue("orient", out tmp))
                {
                    var orient = ThnScript.GetMatrix((LuaTable)tmp);
                    q_orient = orient.ExtractRotation();
                }

                AxisRotation axisRotation = null;
                if (props.TryGetValue("axisrot", out tmp))
                {
                    var axisRot_Table = (LuaTable)tmp;
                    axisRotation = new AxisRotation();
                    if (!axisRot_Table.TryGetVector3(1, out axisRotation.Axis))
                    {
                        FLLog.Error("Thn", "invalid axisrot");
                        return;
                    }
                    axisRotation.Axis           = Vector3.TransformNormal(axisRotation.Axis, objA.Rotate);
                    axisRotation.Degrees        = (float)axisRot_Table[0];
                    axisRotation.OriginalRotate = objA.Rotate;
                }

                hasPos = props.TryGetVector3("pos", out pos);
                if (ev.Targets.Capacity > 1)
                {
                    ThnObject objB;
                    if (!cs.Objects.TryGetValue((string)ev.Targets[1], out objB))
                    {
                        FLLog.Error("Thn", "Object does not exist " + (string)ev.Targets[1]);
                        return;
                    }
                    if (ev.Duration < float.Epsilon)
                    {
                        objA.Translate = objB.Translate;
                        objA.Rotate    = objB.Rotate;
                    }
                    else
                    {
                        cs.Coroutines.Add(new FollowSpatialRoutine()
                        {
                            Duration = ev.Duration,
                            HasPos   = hasPos,
                            HasQuat  = q_orient != null,
                            This     = objA,
                            Follow   = objB
                        });
                    }
                }
                else
                {
                    if (ev.Duration < float.Epsilon)
                    {
                        if (hasPos)
                        {
                            objA.Translate = pos;
                        }
                        if (q_orient != null)
                        {
                            objA.Rotate = Matrix4x4.CreateFromQuaternion(q_orient.Value);
                        }
                    }
                    else
                    {
                        cs.Coroutines.Add(new StaticSpatialRoutine()
                        {
                            Duration = ev.Duration,
                            HasPos   = hasPos,
                            HasQuat  = q_orient != null,
                            EndPos   = pos,
                            EndQuat  = q_orient ?? Quaternion.Identity,
                            This     = objA,
                            AxisRot  = axisRotation
                        });
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            if (!cs.Objects.ContainsKey((string)ev.Targets[0]))
            {
                FLLog.Error("Thn", $"Entity {ev.Targets[0]} does not exist");
                return;
            }
            var obj = cs.Objects[(string)ev.Targets[0]];

            if (obj.Light == null)
            {
                FLLog.Error("Thn", $"Entity {ev.Targets[0]} is not a light");
                return;
            }

            object   tmp;
            LuaTable lightprops;

            if (ev.Properties.TryGetValue("lightprops", out tmp))
            {
                lightprops = (LuaTable)tmp;
            }
            else
            {
                FLLog.Warning("Thn", "Light prop animation with no properties");
                return;
            }

            Vector3 vtmp;
            Color3f?targetDiffuse = null;
            Color3f?targetAmbient = null;

            if (lightprops.TryGetValue("on", out tmp))
            {
                obj.Light.Active = ThnEnum.Check <bool>(tmp);
            }
            if (lightprops.TryGetVector3("diffuse", out vtmp))
            {
                targetDiffuse = new Color3f(vtmp);
                if (ev.Duration <= 0)
                {
                    obj.Light.Light.Color = new Color3f(vtmp);
                }
            }
            if (lightprops.TryGetVector3("ambient", out vtmp))
            {
                targetAmbient = new Color3f(vtmp);
                if (ev.Duration <= 0)
                {
                    obj.Light.Light.Ambient = new Color3f(vtmp);
                }
            }
            if (ev.Duration > 0)
            {
                cs.Coroutines.Add(new AnimLightProp()
                {
                    Source        = obj.Light.Light,
                    Target        = obj.Light,
                    TargetDiffuse = targetDiffuse,
                    TargetAmbient = targetAmbient,
                    Duration      = ev.Duration,
                    ParamCurve    = ev.ParamCurve
                });
            }
        }
Ejemplo n.º 19
0
        void ProcessStartPSys(ThnEvent ev)
        {
            var obj = Objects[(string)ev.Targets[0]];

            ((ParticleEffectRenderer)obj.Object.RenderComponent).Active = true;
        }
        public void Process(ThnEvent ev, Cutscene cs)
        {
            if (ev.Targets.Capacity == 0)
            {
                return;
            }
            ThnObject objA;

            if (!cs.Objects.TryGetValue((string)ev.Targets[0], out objA))
            {
                FLLog.Error("Thn", "Object does not exist " + (string)ev.Targets[0]);
                return;
            }
            if (ev.Targets.Capacity == 1)
            {
                var        props    = (LuaTable)ev.Properties["spatialprops"];
                Quaternion?q_orient = null;
                Vector3    pos;
                object     tmp;
                if (props.TryGetValue("q_orient", out tmp))
                {
                    var tb = (LuaTable)tmp;
                    q_orient = new Quaternion((float)tb[1], (float)tb[2], (float)tb[3], (float)tb[0]);
                }
                if (props.TryGetValue("orient", out tmp))
                {
                    var orient = ThnScript.GetMatrix((LuaTable)tmp);
                    q_orient = orient.ExtractRotation();
                }
                bool hasPos = props.TryGetVector3("pos", out pos);
                if (ev.Duration < float.Epsilon)
                {
                    if (hasPos)
                    {
                        objA.Translate = pos;
                    }
                    if (q_orient != null)
                    {
                        objA.Rotate = Matrix4.CreateFromQuaternion(q_orient.Value);
                    }
                }
                else
                {
                    cs.Coroutines.Add(new StaticSpatialRoutine()
                    {
                        Duration = ev.Duration,
                        HasPos   = hasPos,
                        HasQuat  = q_orient != null,
                        EndPos   = pos,
                        EndQuat  = q_orient ?? Quaternion.Identity,
                        This     = objA
                    });
                }
            }
            else
            {
                ThnObject objB;
                if (!cs.Objects.TryGetValue((string)ev.Targets[1], out objB))
                {
                    FLLog.Error("Thn", "Object does not exist " + (string)ev.Targets[1]);
                    return;
                }
                if (ev.Duration < float.Epsilon)
                {
                    objA.Translate = objB.Translate;
                    objA.Rotate    = objB.Rotate;
                }
                else
                {
                    cs.Coroutines.Add(new FollowSpatialRoutine()
                    {
                        Duration = ev.Duration,
                        HasPos   = true,
                        HasQuat  = true,
                        This     = objA,
                        Follow   = objB
                    });
                }
            }
        }
Ejemplo n.º 21
0
        void ProcessStartFogPropAnim(ThnEvent ev)
        {
            //fogmode is ignored.
            //fogdensity is ignored.
            var fogprops = (LuaTable)ev.Properties["fogprops"];

            object  tmp;
            Vector3 tmp2;

            //Nullable since we are animating
            bool?    fogon      = null;
            Vector3? fogColor   = null;
            float?   fogstart   = null;
            float?   fogend     = null;
            float?   fogDensity = null;
            FogModes fogMode    = FogModes.Linear;

            //Get values
            if (fogprops.TryGetValue("fogon", out tmp))
            {
                fogon = ThnEnum.Check <bool>(tmp);
            }
            if (fogprops.TryGetValue("fogmode", out tmp))
            {
                fogMode = ThnEnum.Check <FogModes>(tmp);
            }
            if (fogprops.TryGetValue("fogdensity", out tmp))
            {
                fogDensity = (float)tmp;
            }
            if (fogprops.TryGetVector3("fogcolor", out tmp2))
            {
                fogColor = tmp2;
            }
            if (fogprops.TryGetValue("fogstart", out tmp))
            {
                fogstart = (float)tmp;
            }
            if (fogprops.TryGetValue("fogend", out tmp))
            {
                fogend = (float)tmp;
            }

            if (fogon.HasValue)             //i'm pretty sure this can't be animated
            {
                Renderer.SystemLighting.FogMode = fogon.Value ? fogMode : FogModes.None;
            }

            //Set fog
            if (Math.Abs(ev.Duration) < float.Epsilon)             //just set it
            {
                if (fogColor.HasValue)
                {
                    var v = fogColor.Value;
                    v *= (1 / 255f);
                    Renderer.SystemLighting.FogColor = new Color4(v.X, v.Y, v.Z, 1);
                }
                if (fogstart.HasValue)
                {
                    Renderer.SystemLighting.FogRange.X = fogstart.Value;
                }
                if (fogend.HasValue)
                {
                    Renderer.SystemLighting.FogRange.Y = fogend.Value;
                }
                if (fogDensity.HasValue)
                {
                    Renderer.SystemLighting.FogDensity = fogDensity.Value;
                }
            }
            else
            {
                coroutines.Add(new FogPropAnimRoutine()                 //animate it!
                {
                    Event          = ev,
                    FogDensity     = fogDensity,
                    FogColor       = fogColor,
                    FogStart       = fogstart,
                    FogEnd         = fogend,
                    OrigFogColor   = Renderer.SystemLighting.FogColor,
                    OrigFogStart   = Renderer.SystemLighting.FogRange.X,
                    OrigFogEnd     = Renderer.SystemLighting.FogRange.Y,
                    OrigFogDensity = Renderer.SystemLighting.FogDensity
                });
            }
        }
Ejemplo n.º 22
0
        void ProcessAttachEntity(ThnEvent ev)
        {
            object tmp;

            if (!Objects.ContainsKey((string)ev.Targets[0]))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[0]);
                return;
            }
            var     objA       = Objects[(string)ev.Targets[0]];
            var     objB       = Objects[(string)ev.Targets[1]];
            var     targetType = ThnEnum.Check <TargetTypes>(ev.Properties["target_type"]);
            var     flags      = AttachFlags.Position | AttachFlags.Orientation;
            Vector3 offset;

            if (ev.Properties.TryGetValue("flags", out tmp))
            {
                flags = ThnEnum.Check <AttachFlags>(tmp);
            }
            ev.Properties.TryGetVector3("offset", out offset);
            //Attach GameObjects to eachother
            if (objA.Object != null && objB.Object != null)
            {
                if (targetType == TargetTypes.Hardpoint)
                {
                    var targetHp = ev.Properties["target_part"].ToString();
                    if (!objB.Object.HardpointExists(targetHp))
                    {
                        FLLog.Error("Thn", "object " + objB.Name + " does not have hardpoint " + targetHp);
                        return;
                    }
                    var hp = objB.Object.GetHardpoint(targetHp);
                    objA.Object.Attachment = hp;
                    objA.Object.Parent     = objB.Object;
                    objA.Object.Transform  = Matrix4.CreateTranslation(offset);
                }
                else if (targetType == TargetTypes.Root)
                {
                    objA.Object.Transform = Matrix4.CreateTranslation(offset);
                    objA.Object.Parent    = objB.Object;
                }
            }
            //Attach GameObjects and Cameras to eachother
            if (objA.Object != null && objB.Camera != null)
            {
            }
            if (objA.Camera != null && objB.Object != null)
            {
                if ((flags & AttachFlags.LookAt) == AttachFlags.LookAt)
                {
                    objA.Camera.LookAt = objB.Object;
                }
                GameObject part = null;
                if (targetType == TargetTypes.Hardpoint)
                {
                    part            = new GameObject();
                    part.Parent     = objB.Object;
                    part.Attachment = objB.Object.GetHardpoint(ev.Properties["target_part"].ToString());
                }
                if (targetType == TargetTypes.Part)
                {
                    var hp = new Hardpoint(null, part.CmpConstructs.Find(ev.Properties["target_part"].ToString()));                     //Create a dummy hardpoint to attach to
                    part            = new GameObject();
                    part.Parent     = objB.Object;
                    part.Attachment = hp;
                }
                coroutines.Add(new AttachCameraToObject()
                {
                    Duration    = ev.Duration,
                    Camera      = objA.Camera,
                    Object      = objB.Object,
                    Part        = part,
                    Position    = ((flags & AttachFlags.Position) == AttachFlags.Position),
                    Orientation = ((flags & AttachFlags.Orientation) == AttachFlags.Orientation),
                    LookAt      = ((flags & AttachFlags.LookAt) == AttachFlags.LookAt)
                });
            }
        }
Ejemplo n.º 23
0
 void ProcessStartLightPropAnim(ThnEvent ev)
 {
     FLLog.Error("Thn", "Unimplemented event StartLightPropAnim");
 }
Ejemplo n.º 24
0
 void ProcessSetCamera(ThnEvent ev)
 {
     SetCamera((string)ev.Targets[1]);
 }