public ServerWorld(GameData.StarSystem system, GameServer server) { Server = server; System = system; GameWorld = new GameWorld(null); GameWorld.PhysicsUpdate += GameWorld_PhysicsUpdate; GameWorld.LoadSystem(system, server.Resources); }
public ServerWorld(GameData.StarSystem system, GameServer server) { Server = server; System = system; GameWorld = new GameWorld(null); GameWorld.Server = this; GameWorld.LoadSystem(system, server.Resources, true); NPCs = new NPCManager(this); }
public SpaceGameplay(FreelancerGame g, GameSession session) : base(g) { FLLog.Info("Game", "Entering system " + session.PlayerSystem); g.ResourceManager.ClearTextures(); //Do before loading things this.session = session; font = Game.Fonts.GetSystemFont("Agency FB"); sys = g.GameData.GetSystem(session.PlayerSystem); loader = new LoadingScreen(g, g.GameData.LoadSystemResources(sys)); }
public GameData.StarSystem GetSystem(string id) { var sys = new GameData.StarSystem(); var iterator = FillSystem(id, sys); while (iterator.MoveNext()) { } return(sys); }
public SpaceGameplay(FreelancerGame g, CGameSession session) : base(g) { FLLog.Info("Game", "Entering system " + session.PlayerSystem); g.ResourceManager.ClearTextures(); //Do before loading things this.session = session; sys = g.GameData.GetSystem(session.PlayerSystem); ui = Game.Ui; ui.GameApi = uiApi = new LuaAPI(this); loader = new LoadingScreen(g, g.GameData.LoadSystemResources(sys)); loader.Init(); }
public DemoSystemView(FreelancerGame g) : base(g) { FLLog.Info("Game", "Starting System Viewer Demo"); sys = g.GameData.GetSystem("li01"); camera = new DebugCamera(g.Viewport); camera.Zoom = 5000; sysrender = new SystemRenderer(camera, g.GameData, g.ResourceManager, g); world = new GameWorld(sysrender); world.LoadSystem(sys, g.ResourceManager); g.Sound.PlayMusic(sys.MusicSpace); camera.UpdateProjection(); trender = new Renderer2D(Game.RenderState); font = g.Fonts.GetSystemFont("Agency FB"); g.Keyboard.KeyDown += G_Keyboard_KeyDown; g.Keyboard.TextInput += G_Keyboard_TextInput; }
public override void Update(TimeSpan delta) { if (current_msg != "") { msg_current_time -= delta.TotalSeconds; if (msg_current_time < 0) { current_msg = ""; } } if (!textEntry) { ProcessInput(delta); } else { if (Game.Keyboard.IsKeyDown(Keys.Enter)) { textEntry = false; Game.DisableTextInput(); if (Game.GameData.SystemExists(currentText.Trim())) { sys = Game.GameData.GetSystem(currentText.Trim()); world.LoadSystem(sys, Game.ResourceManager); camera.Free = false; camera.Update(TimeSpan.FromSeconds(1)); camera.Free = true; Game.Sound.PlayMusic(sys.MusicSpace); } else { msg_current_time = MSG_TIMER; current_msg = string.Format("{0} is not a valid system", currentText.Trim()); } } if (Game.Keyboard.IsKeyDown(Keys.Escape)) { textEntry = false; } } camera.Update(delta); camera.Free = true; world.Update(delta); }
public SpaceGameplay(FreelancerGame g, GameSession session) : base(g) { FLLog.Info("Game", "Entering system " + session.PlayerSystem); g.ResourceManager.ClearTextures(); //Do before loading things this.session = session; font = Game.Fonts.GetSystemFont("Agency FB"); #if false pyw = new DebugGraph(); pyw.AddLine(Color4.Red, 240, -1, 1); pyw.AddLine(Color4.Green, 240, -1, 1); pyw.AddLine(Color4.Blue, 240, -1, 1); pyw.X = 850; pyw.Y = 10; pyw.Width = 170; pyw.Height = 124; #endif sys = g.GameData.GetSystem(session.PlayerSystem); loader = new LoadingScreen(g, g.GameData.LoadSystemResources(sys)); }
public void RequestWorld(GameData.StarSystem system, Action <ServerWorld> spunUp) { lock (availableWorlds) { if (availableWorlds.Contains(system)) { spunUp(worlds[system]); return; } } worldRequests.Enqueue(() => { var world = new ServerWorld(system, this); FLLog.Info("Server", "Spun up " + system.Nickname + " (" + system.Name + ")"); worlds.Add(system, world); lock (availableWorlds) { availableWorlds.Add(system); } spunUp(world); }); }
public SpaceGameplay(FreelancerGame g, GameSession session) : base(g) { FLLog.Info("Game", "Entering system " + session.PlayerSystem); g.ResourceManager.ClearTextures(); //Do before loading things this.session = session; #if false pyw = new DebugGraph(); pyw.AddLine(Color4.Red, 240, -1, 1); pyw.AddLine(Color4.Green, 240, -1, 1); pyw.AddLine(Color4.Blue, 240, -1, 1); pyw.X = 850; pyw.Y = 10; pyw.Width = 170; pyw.Height = 124; #endif sys = g.GameData.GetSystem(session.PlayerSystem); loader = new LoadingScreen(g, g.GameData.LoadSystemResources(sys)); ui = new UiContext(g); ui.GameApi = uiApi = new LuaAPI(this); widget = ui.CreateAll("hud.xml"); }
public SpaceGameplay(FreelancerGame g, GameSession session) : base(g) { FLLog.Info("Game", "Starting Gameplay Demo"); sys = g.GameData.GetSystem(session.PlayerSystem); var shp = g.GameData.GetShip(session.PlayerShip); //Set up player object + camera this.session = session; player = new GameObject(shp.Drawable, g.ResourceManager, false); control = new ShipControlComponent(player); control.Ship = shp; player.Components.Add(control); powerCore = new PowerCoreComponent(player) { ThrustCapacity = 1000, ThrustChargeRate = 100 }; player.Components.Add(powerCore); player.PhysicsComponent.Position = session.PlayerPosition; player.PhysicsComponent.Orientation = session.PlayerOrientation; player.PhysicsComponent.Material.Restitution = 1; player.PhysicsComponent.Mass = shp.Mass; player.Nickname = "player"; foreach (var equipment in session.MountedEquipment) { var equip = g.GameData.GetEquipment(equipment.Value); var obj = new GameObject(equip, player.GetHardpoint(equipment.Key), player); player.Children.Add(obj); } camera = new ChaseCamera(Game.Viewport); camera.ChasePosition = session.PlayerPosition; camera.ChaseOrientation = new Matrix4(player.PhysicsComponent.Orientation); camera.Reset(); sysrender = new SystemRenderer(camera, g.GameData, g.ResourceManager, g); world = new GameWorld(sysrender); world.LoadSystem(sys, g.ResourceManager); world.Objects.Add(player); world.Physics.SetDampingFactors(0.01f, 1f); world.RenderUpdate += World_RenderUpdate; world.PhysicsUpdate += World_PhysicsUpdate; var eng = new GameData.Items.Engine() { FireEffect = "gf_li_smallengine02_fire", LinearDrag = 600, MaxForce = 48000 }; player.Components.Add((ecpt = new EngineComponent(player, eng, g))); ecpt.Speed = 0; player.Register(sysrender, world.Physics); g.Sound.PlayMusic(sys.MusicSpace); trender = new Renderer2D(Game.RenderState); font = g.Fonts.GetSystemFont("Agency FB"); g.Keyboard.TextInput += G_Keyboard_TextInput; debugphysics = new PhysicsDebugRenderer(); cur_arrow = g.ResourceManager.GetCursor("cross"); cur_reticle = g.ResourceManager.GetCursor("fire_neutral"); current_cur = cur_arrow; hud = new Hud(g); hud.SetManeuver("FreeFlight"); Game.Keyboard.TextInput += Game_TextInput; g.Keyboard.KeyDown += Keyboard_KeyDown; input = new InputManager(Game); input.ToggleActivated += Input_ToggleActivated; input.ToggleUp += Input_ToggleUp; hud.OnManeuverSelected += Hud_OnManeuverSelected; hud.OnEntered += Hud_OnTextEntry; pilotcomponent = new AutopilotComponent(player); pilotcomponent.DockComplete += Pilotcomponent_DockComplete; player.Components.Add(pilotcomponent); player.World = world; world.MessageBroadcasted += World_MessageBroadcasted; }
public GameData.Nebula GetNebula(GameData.StarSystem sys, Legacy.Universe.Nebula nbl) { var n = new GameData.Nebula(); n.Zone = sys.Zones.Where((z) => z.Nickname.ToLower() == nbl.ZoneName.ToLower()).First(); var panels = new Legacy.Universe.TexturePanels(nbl.TexturePanels.Files[0]); foreach (var txmfile in panels.Files) { resource.LoadTxm(Compatibility.VFS.GetPath(fldata.Freelancer.DataPath + txmfile)); } n.ExteriorFill = nbl.ExteriorFillShape; n.ExteriorColor = nbl.ExteriorColor ?? Color4.White; n.FogColor = nbl.FogColor ?? Color4.Black; n.FogEnabled = (nbl.FogEnabled ?? 0) != 0; n.FogRange = new Vector2(nbl.FogNear ?? 0, nbl.FogDistance ?? 0); n.SunBurnthroughScale = n.SunBurnthroughIntensity = 1f; if (nbl.NebulaLights != null && nbl.NebulaLights.Count > 0) { n.AmbientColor = nbl.NebulaLights[0].Ambient; n.SunBurnthroughScale = nbl.NebulaLights[0].SunBurnthroughScaler ?? 1f; n.SunBurnthroughIntensity = nbl.NebulaLights[0].SunBurnthroughIntensity ?? 1f; } if (nbl.CloudsPuffShape != null) { n.HasInteriorClouds = true; GameData.CloudShape[] shapes = new GameData.CloudShape[nbl.CloudsPuffShape.Count]; for (int i = 0; i < shapes.Length; i++) { var name = nbl.CloudsPuffShape[i]; if (!panels.Shapes.ContainsKey(name)) { FLLog.Error("Nebula", "Shape " + name + " does not exist in " + nbl.TexturePanels.Files[0]); shapes[i].Texture = ResourceManager.NullTextureName; shapes[i].Dimensions = new RectangleF(0, 0, 1, 1); } else { shapes[i].Texture = panels.Shapes[name].TextureName; shapes[i].Dimensions = panels.Shapes[name].Dimensions; } } n.InteriorCloudShapes = new WeightedRandomCollection <GameData.CloudShape>( shapes, nbl.CloudsPuffWeights.ToArray() ); n.InteriorCloudColorA = nbl.CloudsPuffColorA.Value; n.InteriorCloudColorB = nbl.CloudsPuffColorB.Value; n.InteriorCloudRadius = nbl.CloudsPuffRadius.Value; n.InteriorCloudCount = nbl.CloudsPuffCount.Value; n.InteriorCloudMaxDistance = nbl.CloudsMaxDistance.Value; n.InteriorCloudMaxAlpha = nbl.CloudsPuffMaxAlpha ?? 1f; n.InteriorCloudFadeDistance = nbl.CloudsNearFadeDistance.Value; n.InteriorCloudDrift = nbl.CloudsPuffDrift.Value; } if (nbl.ExteriorShape != null) { n.HasExteriorBits = true; GameData.CloudShape[] shapes = new GameData.CloudShape[nbl.ExteriorShape.Count]; for (int i = 0; i < shapes.Length; i++) { var name = nbl.ExteriorShape[i]; if (!panels.Shapes.ContainsKey(name)) { FLLog.Error("Nebula", "Shape " + name + " does not exist in " + nbl.TexturePanels.Files[0]); shapes[i].Texture = ResourceManager.NullTextureName; shapes[i].Dimensions = new RectangleF(0, 0, 1, 1); } else { shapes[i].Texture = panels.Shapes[name].TextureName; shapes[i].Dimensions = panels.Shapes[name].Dimensions; } } n.ExteriorCloudShapes = new WeightedRandomCollection <GameData.CloudShape>( shapes, nbl.ExteriorShapeWeights.ToArray() ); n.ExteriorMinBits = nbl.ExteriorMinBits.Value; n.ExteriorMaxBits = nbl.ExteriorMaxBits.Value; n.ExteriorBitRadius = nbl.ExteriorBitRadius.Value; n.ExteriorBitRandomVariation = nbl.ExteriorBitRadiusRandomVariation ?? 0; n.ExteriorMoveBitPercent = nbl.ExteriorMoveBitPercent ?? 0; } if (nbl.ExclusionZones != null) { n.ExclusionZones = new List <GameData.ExclusionZone>(); foreach (var excz in nbl.ExclusionZones) { if (excz.Exclusion == null) { continue; } var e = new GameData.ExclusionZone(); e.Zone = sys.Zones.Where((z) => z.Nickname.ToLower() == excz.Exclusion.Nickname.ToLower()).First(); e.FogFar = excz.FogFar ?? n.FogRange.Y; if (excz.ZoneShellPath != null) { var pth = Compatibility.VFS.GetPath(fldata.Freelancer.DataPath + excz.ZoneShellPath); e.Shell = resource.GetDrawable(pth); e.ShellTint = excz.Tint ?? Color3f.White; e.ShellScalar = excz.ShellScalar ?? 1f; e.ShellMaxAlpha = excz.MaxAlpha ?? 1f; } n.ExclusionZones.Add(e); } } if (nbl.BackgroundLightningDuration != null) { n.BackgroundLightning = true; n.BackgroundLightningDuration = nbl.BackgroundLightningDuration.Value; n.BackgroundLightningColor = nbl.BackgroundLightningColor.Value; n.BackgroundLightningGap = nbl.BackgroundLightningGap.Value; } if (nbl.DynamicLightningDuration != null) { n.DynamicLightning = true; n.DynamicLightningGap = nbl.DynamicLightningGap.Value; n.DynamicLightningColor = nbl.DynamicLightningColor.Value; n.DynamicLightningDuration = nbl.DynamicLightningDuration.Value; } if (nbl.CloudsLightningDuration != null) { n.CloudLightning = true; n.CloudLightningDuration = nbl.CloudsLightningDuration.Value; n.CloudLightningColor = nbl.CloudsLightningColor.Value; n.CloudLightningGap = nbl.CloudsLightningGap.Value; n.CloudLightningIntensity = nbl.CloudsLightningIntensity.Value; } return(n); }
GameData.AsteroidField GetAsteroidField(GameData.StarSystem sys, Legacy.Universe.AsteroidField ast) { var a = new GameData.AsteroidField(); a.Zone = sys.Zones.Where((z) => z.Nickname.ToLower() == ast.ZoneName.ToLower()).First(); Legacy.Universe.TexturePanels panels = null; if (ast.TexturePanels != null) { foreach (var f in ast.TexturePanels.Files) { panels = new Legacy.Universe.TexturePanels(f); foreach (var txmfile in panels.Files) { resource.LoadTxm(Compatibility.VFS.GetPath(fldata.Freelancer.DataPath + txmfile)); } } } if (ast.Band != null) { a.Band = new GameData.AsteroidBand(); a.Band.RenderParts = ast.Band.RenderParts.Value; a.Band.Height = ast.Band.Height.Value; a.Band.Shape = panels.Shapes [ast.Band.Shape].TextureName; a.Band.Fade = new Vector4(ast.Band.Fade [0], ast.Band.Fade [1], ast.Band.Fade [2], ast.Band.Fade [3]); var cs = ast.Band.ColorShift ?? Vector3.One; a.Band.ColorShift = new Color4(cs.X, cs.Y, cs.Z, 1f); a.Band.TextureAspect = ast.Band.TextureAspect ?? 1f; a.Band.OffsetDistance = ast.Band.OffsetDist ?? 0f; } a.Cube = new List <GameData.StaticAsteroid> (); a.CubeRotation = new GameData.AsteroidCubeRotation(); a.CubeRotation.AxisX = ast.Cube_RotationX ?? GameData.AsteroidCubeRotation.Default_AxisX; a.CubeRotation.AxisY = ast.Cube_RotationY ?? GameData.AsteroidCubeRotation.Default_AxisY; a.CubeRotation.AxisZ = ast.Cube_RotationZ ?? GameData.AsteroidCubeRotation.Default_AxisZ; a.CubeSize = ast.Field.CubeSize ?? 100; //HACK: Actually handle null cube correctly a.SetFillDist(ast.Field.FillDist.Value); a.EmptyCubeFrequency = ast.Field.EmptyCubeFrequency ?? 0f; foreach (var c in ast.Cube) { var sta = new GameData.StaticAsteroid() { Rotation = c.Rotation, Position = c.Position, Info = c.Info }; sta.RotationMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(c.Rotation.X)) * Matrix4.CreateRotationY(MathHelper.DegreesToRadians(c.Rotation.Y)) * Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(c.Rotation.Z)); var n = c.Name; var arch = fldata.Asteroids.FindAsteroid(c.Name); resource.LoadMat(Compatibility.VFS.GetPath(fldata.Freelancer.DataPath + arch.MaterialLibrary)); sta.Drawable = resource.GetDrawable(Compatibility.VFS.GetPath(fldata.Freelancer.DataPath + arch.DaArchetype)); a.Cube.Add(sta); } a.ExclusionZones = new List <GameData.ExclusionZone>(); if (ast.ExclusionZones != null) { foreach (var excz in ast.ExclusionZones) { var e = new GameData.ExclusionZone(); e.Zone = sys.Zones.Where((z) => z.Nickname.ToLower() == excz.Exclusion.Nickname.ToLower()).First(); //e.FogFar = excz.FogFar ?? n.FogRange.Y; if (excz.ZoneShellPath != null) { var pth = Compatibility.VFS.GetPath(fldata.Freelancer.DataPath + excz.ZoneShellPath); e.Shell = resource.GetDrawable(pth); e.ShellTint = excz.Tint ?? Color3f.White; e.ShellScalar = excz.ShellScalar ?? 1f; e.ShellMaxAlpha = excz.MaxAlpha ?? 1f; } a.ExclusionZones.Add(e); } } a.BillboardCount = ast.AsteroidBillboards == null ? -1 : ast.AsteroidBillboards.Count.Value; if (a.BillboardCount != -1) { a.BillboardDistance = ast.AsteroidBillboards.StartDist.Value; a.BillboardFadePercentage = ast.AsteroidBillboards.FadeDistPercent.Value; Compatibility.GameData.Universe.TextureShape sh = null; if (panels != null) { sh = panels.Shapes [ast.AsteroidBillboards.Shape]; } else { sh = new Legacy.Universe.TextureShape(ast.AsteroidBillboards.Shape, ast.AsteroidBillboards.Shape, new RectangleF(0, 0, 1, 1)); } a.BillboardShape = new TextureShape() { Texture = sh.TextureName, Dimensions = sh.Dimensions, Nickname = ast.AsteroidBillboards.Shape }; a.BillboardSize = ast.AsteroidBillboards.Size.Value; a.BillboardTint = new Color3f(ast.AsteroidBillboards.ColorShift ?? Vector3.One); } return(a); }
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); }