Esempio n. 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.SoundSpatial);

                default:
                    throw new NotImplementedException();
                }
            }
            return(ThnTypes.Convert <ThnObjectFlags>(val));
        }
Esempio n. 2
0
 protected static bool GetValue <T>(LuaTable table, string key, out T result, T def = default(T))
 {
     result = default;
     if (table.TryGetValue(key, out var tmp))
     {
         result = ThnTypes.Convert <T>(tmp);
         return(true);
     }
     return(false);
 }
Esempio n. 3
0
        static ThnObjectFlags ConvertFlags(EntityTypes type, LuaTable table)
        {
            if (!(table["flags"] is float))
            {
                return((ThnObjectFlags)table["flags"]);
            }
            var val = (int)(float)table["flags"];

            return(ThnTypes.Convert <ThnObjectFlags>(val));
        }
Esempio n. 4
0
 static void ProcessEvents(LuaTable t)
 {
     for (int ti = 0; ti < t.Capacity; ti++)
     {
         var ev = (LuaTable)t[ti];
         ev[1] = ThnTypes.Convert <EventTypes>(ev[1]);
         if (ev.Capacity >= 4)
         {
             var props = (LuaTable)ev[3];
             //TODO: Property flags
         }
     }
 }
Esempio n. 5
0
        protected ThnEvent(LuaTable table)
        {
            Time = (float)table[0];
            Type = ThnTypes.Convert <EventTypes>(table[1]);
            if (GetProps(table, out var props))
            {
                if (GetValue(props, "param_curve", out LuaTable pcurve))
                {
                    ParamCurve = new ParameterCurve(pcurve);
                    GetValue(props, "pcurve_period", out ParamCurve.Period);
                }
                GetValue(props, "duration", out Duration);
            }
            var targetTable = (LuaTable)table[2];

            Targets = new string[targetTable.Count];
            for (int i = 0; i < Targets.Length; i++)
            {
                Targets[i] = (string)targetTable[i];
            }
        }
Esempio n. 6
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"] = ThnTypes.Convert <EntityTypes>(ent["type"]);
                if (ent.TryGetValue("lightprops", out o))
                {
                    var lp = (LuaTable)o;
                    if (lp.ContainsKey("type"))
                    {
                        lp["type"] = ThnTypes.Convert <LightTypes>(lp["type"]);
                    }
                }
                if (ent.ContainsKey("flags"))
                {
                    ent["flags"] = ConvertFlags((EntityTypes)ent["type"], ent);
                }
            }
        }
Esempio n. 7
0
        ThnEntity GetEntity(LuaTable table)
        {
            object o;

            var e = new ThnEntity();

            e.Name = (string)table["entity_name"];
            e.Type = ThnTypes.Convert <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 = ThnTypes.Convert <bool>(o);
                }
                if (usrprops.TryGetValue("Actor", out o))
                {
                    e.Actor = o.ToString();
                }
                if (usrprops.TryGetValue("TextString", out o))
                {
                    e.DisplayText         = new ThnDisplayText();
                    e.DisplayText.TextIDS = FuzzyInt(o);
                    if (usrprops.TryGetValue("TextStart", out o))
                    {
                        e.DisplayText.Start = FuzzyFloat(o);
                    }
                }

                if (usrprops.TryGetValue("main_object", out o))
                {
                    e.MainObject = true;
                }
            }
            if (table.TryGetValue("audioprops", out o))
            {
                var aprops = (LuaTable)o;
                e.AudioProps = new ThnAudioProps();
                if (aprops.TryGetValue("rmix", out o))
                {
                    e.AudioProps.Rmix = (float)o;
                }
                if (aprops.TryGetValue("ain", out o))
                {
                    e.AudioProps.Ain = (float)o;
                }
                if (aprops.TryGetValue("dmax", out o))
                {
                    e.AudioProps.Dmax = (float)o;
                }
                if (aprops.TryGetValue("atout", out o))
                {
                    e.AudioProps.Atout = (float)o;
                }
                if (aprops.TryGetValue("pan", out o))
                {
                    e.AudioProps.Pan = (float)o;
                }
                if (aprops.TryGetValue("dmin", out o))
                {
                    e.AudioProps.Dmin = (float)o;
                }
                if (aprops.TryGetValue("aout", out o))
                {
                    e.AudioProps.Aout = (float)o;
                }
                if (aprops.TryGetValue("attenuation", out o))
                {
                    e.AudioProps.Attenuation = (float)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 (cameraprops.TryGetValue("nearplane", out o))
                {
                    e.NearPlane = (float)o;
                }
                if (cameraprops.TryGetValue("farplane", out o))
                {
                    e.FarPlane = (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 = ThnTypes.Convert <bool>(o);
                }
                else
                {
                    e.LightProps.On = true;
                }
                var r = new RenderLight();
                r.Position = e.Position.Value;
                if (lightprops.TryGetValue("type", out o))
                {
                    var tp = ThnTypes.Convert <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 Color3f(tmp.X, tmp.Y, tmp.Z);
                }
                if (lightprops.TryGetVector3("ambient", out tmp))
                {
                    r.Ambient = new Color3f(tmp.X, tmp.Y, tmp.Z);
                }
                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 = tmp;
                }
                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);
        }
Esempio n. 8
0
        ThnEvent GetEvent(LuaTable table)
        {
            var t = ThnTypes.Convert <EventTypes>(table[1]);

            switch (t)
            {
            case EventTypes.SetCamera:
                return(new SetCameraEvent(table));

            case EventTypes.StartSound:
                return(new StartSoundEvent(table));

            case EventTypes.StartAudioPropAnim:
                return(new StartAudioPropAnimEvent(table));

            case EventTypes.StartLightPropAnim:
                return(new StartLightPropAnimEvent(table));

            case EventTypes.StartCameraPropAnim:
                return(new StartCameraPropAnimEvent(table));

            case EventTypes.StartPathAnimation:
                return(new StartPathAnimationEvent(table));

            case EventTypes.StartSpatialPropAnim:
                return(new StartSpatialPropAnimEvent(table));

            case EventTypes.AttachEntity:
                return(new AttachEntityEvent(table));

            case EventTypes.ConnectHardpoints:
                return(new ConnectHardpointsEvent(table));

            case EventTypes.StartMotion:
                return(new StartMotionEvent(table));

            case EventTypes.StartIK:
                return(new StartIKEvent(table));

            case EventTypes.StartSubScene:
                return(new StartSubSceneEvent(table));

            case EventTypes.StartPSys:
                return(new StartPSysEvent(table));

            case EventTypes.StartPSysPropAnim:
                return(new StartPSysPropAnimEvent(table));

            case EventTypes.StartFogPropAnim:
                return(new StartFogPropAnimEvent(table));

            case EventTypes.StartReverbPropAnim:
                return(new StartReverbPropAnim(table));

            case EventTypes.StartFloorHeightAnim:
                return(new StartFloorHeightAnimEvent(table));

            case EventTypes.Subtitle:
                return(new SubtitleEvent(table));
            }
            throw new ArgumentException($"event type {t}");
        }