Пример #1
0
        //Flags are stored differently internally between Freelancer and Librelancer
        ThnObjectFlags ConvertFlags(EntityTypes type, LuaTable table)
        {
            var val = (int)(float)table["flags"];

            if (val == 0)
            {
                return(ThnObjectFlags.None);
            }
            if (val == 1)
            {
                return(ThnObjectFlags.Reference);                      //Should be for all types
            }
            if (type == EntityTypes.Sound)
            {
                switch (val)
                {
                case 2:
                    return(ThnObjectFlags.Spatial);

                default:
                    throw new NotImplementedException();
                }
            }
            return(ThnEnum.FlagsReflected <ThnObjectFlags>(val));
        }
Пример #2
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
                });
            }
        }
Пример #3
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);
        }
Пример #4
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");
                }
            }
        }
Пример #5
0
        static ThnObjectFlags ConvertFlags(EntityTypes type, LuaTable table)
        {
            if (!(table["flags"] is float))
            {
                return((ThnObjectFlags)table["flags"]);
            }
            var val = (int)(float)table["flags"];

            return(ThnEnum.Check <ThnObjectFlags>(val));
        }
Пример #6
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)
            });
        }
Пример #7
0
 static void ProcessEvents(LuaTable t)
 {
     for (int ti = 0; ti < t.Capacity; ti++)
     {
         var ev = (LuaTable)t[ti];
         ev[1] = ThnEnum.Check <EventTypes>(ev[1]);
         if (ev.Capacity >= 4)
         {
             var props = (LuaTable)ev[3];
             //TODO: Property flags
         }
     }
 }
        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
                });
            }
        }
Пример #10
0
        static void ProcessEntities(LuaTable t)
        {
            //Make sure flags aren't integers
            object o;

            for (int ti = 0; ti < t.Capacity; ti++)
            {
                var ent = (LuaTable)t[ti];
                ent["type"] = ThnEnum.Check <EntityTypes>(ent["type"]);
                if (ent.TryGetValue("lightprops", out o))
                {
                    var lp = (LuaTable)o;
                    if (lp.ContainsKey("type"))
                    {
                        lp["type"] = ThnEnum.Check <LightTypes>(lp["type"]);
                    }
                }
                if (ent.ContainsKey("flags"))
                {
                    ent["flags"] = ConvertFlags((EntityTypes)ent["type"], ent);
                }
            }
        }
Пример #11
0
        ThnEntity GetEntity(LuaTable table)
        {
            object o;

            var e = new ThnEntity();

            e.Name = (string)table["entity_name"];
            e.Type = ThnEnum.Check <EntityTypes>(table["type"]);
            if (table.TryGetValue("srt_grp", out o))
            {
                e.SortGroup = (int)(float)table["srt_grp"];
            }
            if (table.TryGetValue("usr_flg", out o))
            {
                e.UserFlag = (int)(float)table["usr_flg"];
            }
            if (table.TryGetValue("lt_grp", out o))
            {
                e.LightGroup = (int)(float)table["lt_grp"];
            }

            Vector3 tmp;

            if (table.TryGetVector3("ambient", out tmp))
            {
                e.Ambient = tmp;
            }
            if (table.TryGetVector3("up", out tmp))
            {
                e.Up = tmp;
            }
            if (table.TryGetVector3("front", out tmp))
            {
                e.Front = tmp;
            }

            if (table.TryGetValue("template_name", out o))
            {
                e.Template = (string)o;
            }
            if (table.TryGetValue("flags", out o))
            {
                if (o is float)
                {
                    e.ObjectFlags = ConvertFlags(e.Type, table);
                }
                else
                {
                    e.ObjectFlags = (ThnObjectFlags)o;
                }
            }
            if (table.TryGetValue("userprops", out o))
            {
                var usrprops = (LuaTable)o;
                if (usrprops.TryGetValue("category", out o))
                {
                    e.MeshCategory = (string)o;
                }
                if (usrprops.TryGetValue("nofog", out o))
                {
                    e.NoFog = ThnEnum.Check <bool>(o);
                }
            }

            if (table.TryGetValue("spatialprops", out o))
            {
                var spatialprops = (LuaTable)o;
                if (spatialprops.TryGetVector3("pos", out tmp))
                {
                    e.Position = tmp;
                }
                if (spatialprops.TryGetValue("orient", out o))
                {
                    e.RotationMatrix = GetMatrix((LuaTable)o);
                }
            }

            if (table.TryGetValue("cameraprops", out o))
            {
                var cameraprops = (LuaTable)o;
                if (cameraprops.TryGetValue("fovh", out o))
                {
                    e.FovH = (float)o;
                }
                if (cameraprops.TryGetValue("hvaspect", out o))
                {
                    e.HVAspect = (float)o;
                }
            }
            if (table.TryGetValue("lightprops", out o))
            {
                var lightprops = (LuaTable)o;
                e.LightProps = new ThnLightProps();
                if (lightprops.TryGetValue("on", out o))
                {
                    e.LightProps.On = ThnEnum.Check <bool>(o);
                }
                else
                {
                    e.LightProps.On = true;
                }
                var r = new RenderLight();
                r.Position = e.Position.Value;
                if (lightprops.TryGetValue("type", out o))
                {
                    var tp = ThnEnum.Check <LightTypes>(o);
                    if (tp == LightTypes.Point)
                    {
                        r.Kind = LightKind.Point;
                    }
                    if (tp == LightTypes.Direct)
                    {
                        r.Kind = LightKind.Directional;
                    }
                    if (tp == LightTypes.Spotlight)
                    {
                        r.Kind    = LightKind.Spotlight;
                        r.Falloff = 1f;
                    }
                }
                else
                {
                    throw new Exception("Light without type");
                }
                if (lightprops.TryGetVector3("diffuse", out tmp))
                {
                    r.Color = new Color4(tmp.X, tmp.Y, tmp.Z, 1);
                }
                if (lightprops.TryGetVector3("direction", out tmp))
                {
                    r.Direction = tmp;
                }
                if (lightprops.TryGetValue("range", out o))
                {
                    r.Range = (int)(float)o;
                }
                if (lightprops.TryGetValue("theta", out o))
                {
                    r.Theta = r.Phi = (float)o;
                }
                if (lightprops.TryGetVector3("atten", out tmp))
                {
                    r.Attenuation = new Vector4(tmp, 0);
                }
                e.LightProps.Render = r;
            }
            if (table.TryGetValue("pathprops", out o))
            {
                var pathprops = (LuaTable)o;
                if (pathprops.TryGetValue("path_data", out o))
                {
                    e.Path = new MotionPath((string)o);
                }
            }
            return(e);
        }
Пример #12
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
                });
            }
        }
Пример #13
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)
                });
            }
        }
Пример #14
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
            });
        }
Пример #15
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
                });
            }
        }