Example #1
0
        public GameData.StarSystem GetSystem(string id)
        {
            var legacy = fldata.Universe.FindSystem(id);

            if (fldata.Stars != null)
            {
                foreach (var txmfile in fldata.Stars.TextureFiles)
                {
                    resource.LoadTxm(Compatibility.VFS.GetPath(fldata.Freelancer.DataPath + txmfile));
                }
            }
            var sys = new GameData.StarSystem();

            sys.AmbientColor    = legacy.AmbientColor ?? Color4.White;
            sys.Name            = legacy.StridName;
            sys.Id              = legacy.Nickname;
            sys.BackgroundColor = legacy.SpaceColor ?? Color4.Black;
            sys.MusicSpace      = legacy.MusicSpace;
            sys.FarClip         = legacy.SpaceFarClip ?? 20000f;
            if (legacy.BackgroundBasicStarsPath != null)
            {
                try {
                    sys.StarsBasic = resource.GetDrawable(legacy.BackgroundBasicStarsPath);
                } catch (Exception) {
                    sys.StarsBasic = null;
                    FLLog.Error("System", "Failed to load starsphere " + legacy.BackgroundBasicStarsPath);
                }
            }

            if (legacy.BackgroundComplexStarsPath != null)
            {
                try {
                    sys.StarsComplex = resource.GetDrawable(legacy.BackgroundComplexStarsPath);
                } catch (Exception) {
                    sys.StarsComplex = null;
                    FLLog.Error("System", "Failed to load starsphere " + legacy.BackgroundComplexStarsPath);
                }
            }

            if (legacy.BackgroundNebulaePath != null)
            {
                try {
                    sys.StarsNebula = resource.GetDrawable(legacy.BackgroundNebulaePath);
                } catch (Exception) {
                    sys.StarsNebula = null;
                    FLLog.Error("System", "Failed to load starsphere " + legacy.BackgroundNebulaePath);
                }
            }

            if (legacy.LightSources != null)
            {
                foreach (var src in legacy.LightSources)
                {
                    var lt = new RenderLight();
                    lt.Color       = src.Color.Value;
                    lt.Position    = src.Pos.Value;
                    lt.Range       = src.Range.Value;
                    lt.Direction   = src.Direction ?? new Vector3(0, 0, 1);
                    lt.Kind        = ((src.Type ?? Legacy.Universe.LightType.Point) == Legacy.Universe.LightType.Point) ? LightKind.Point : LightKind.Directional;
                    lt.Attenuation = new Vector4(src.Attenuation ?? Vector3.UnitY, 0);
                    if (src.AttenCurve != null)
                    {
                        lt.Kind        = LightKind.PointAttenCurve;
                        lt.Attenuation = ApproximateCurve.GetCubicFunction(
                            fldata.Graphs.FindFloatGraph(src.AttenCurve).Points.ToArray()
                            );
                    }
                    sys.LightSources.Add(lt);
                }
            }
            foreach (var obj in legacy.Objects)
            {
                sys.Objects.Add(GetSystemObject(obj));
            }
            if (legacy.Zones != null)
            {
                foreach (var zne in legacy.Zones)
                {
                    var z = new GameData.Zone();
                    z.Nickname     = zne.Nickname;
                    z.EdgeFraction = zne.EdgeFraction ?? 0.25f;
                    z.Position     = zne.Pos.Value;
                    if (zne.Rotate != null)
                    {
                        var r = zne.Rotate.Value;

                        var qx = Quaternion.FromEulerAngles(
                            MathHelper.DegreesToRadians(r.X),
                            MathHelper.DegreesToRadians(r.Y),
                            MathHelper.DegreesToRadians(r.Z)
                            );
                        z.RotationMatrix = Matrix4.CreateFromQuaternion(qx);
                        z.RotationAngles = new Vector3(
                            MathHelper.DegreesToRadians(r.X),
                            MathHelper.DegreesToRadians(r.Y),
                            MathHelper.DegreesToRadians(r.Z)
                            );
                    }
                    else
                    {
                        z.RotationMatrix = Matrix4.Identity;
                        z.RotationAngles = Vector3.Zero;
                    }
                    switch (zne.Shape.Value)
                    {
                    case Legacy.Universe.ZoneShape.ELLIPSOID:
                        z.Shape = new GameData.ZoneEllipsoid(z,
                                                             zne.Size.Value.X,
                                                             zne.Size.Value.Y,
                                                             zne.Size.Value.Z
                                                             );
                        break;

                    case Legacy.Universe.ZoneShape.SPHERE:
                        z.Shape = new GameData.ZoneSphere(z,
                                                          zne.Size.Value.X
                                                          );
                        break;

                    case Legacy.Universe.ZoneShape.BOX:
                        z.Shape = new GameData.ZoneBox(z,
                                                       zne.Size.Value.X,
                                                       zne.Size.Value.Y,
                                                       zne.Size.Value.Z
                                                       );
                        break;

                    case Legacy.Universe.ZoneShape.CYLINDER:
                        z.Shape = new GameData.ZoneCylinder(z,
                                                            zne.Size.Value.X,
                                                            zne.Size.Value.Y
                                                            );
                        break;

                    case Legacy.Universe.ZoneShape.RING:
                        z.Shape = new GameData.ZoneRing(z,
                                                        zne.Size.Value.X,
                                                        zne.Size.Value.Y,
                                                        zne.Size.Value.Z
                                                        );
                        break;

                    default:
                        Console.WriteLine(zne.Nickname);
                        Console.WriteLine(zne.Shape.Value);
                        throw new NotImplementedException();
                    }
                    sys.Zones.Add(z);
                }
            }
            if (legacy.Asteroids != null)
            {
                foreach (var ast in legacy.Asteroids)
                {
                    sys.AsteroidFields.Add(GetAsteroidField(sys, ast));
                }
            }

            if (legacy.Nebulae != null)
            {
                foreach (var nbl in legacy.Nebulae)
                {
                    sys.Nebulae.Add(GetNebula(sys, nbl));
                }
            }
            return(sys);
        }
 protected ZoneShape(Zone zn)
 {
     Zone = zn;
 }