コード例 #1
0
ファイル: StarSystem.cs プロジェクト: Friendly0Fire/flos
        public void CalculatePathfinding()
        {
            foreach (var s in Solars)
            {
                if (s.Value.Arch.Type == Archetype.ObjectType.TRADELANE_RING &&
                    (s.Value.PrevRing == 0 || s.Value.NextRing == 0))
                {
                    _pathfinding.Add(s.Key, new PathfindingNode(s.Key));
                }
            }

            foreach (var node1 in _pathfinding)
            {
                foreach (var node2 in _pathfinding)
                {
                    Solar s1 = Solars[node1.Key], s2 = Solars[node2.Key];

                    var d = s1.Position.DistanceTo(s2.Position);

                    if (s1.Arch.Type == Archetype.ObjectType.TRADELANE_RING &&
                        s2.Arch.Type == Archetype.ObjectType.TRADELANE_RING)
                    {
                        var temp = s1;
                        if (temp.PrevRing != 0)
                        {
                            while (temp.PrevRing != 0)
                            {
                                temp = Solars[temp.PrevRing];
                            }
                        }
                        else
                        {
                            while (temp.NextRing != 0)
                            {
                                temp = Solars[temp.NextRing];
                            }
                        }

                        if (temp.Objid == s2.Objid)
                        {
                            _tradelanes[node1.Key] = node2.Key;
                            _tradelanes[node2.Key] = node1.Key;

                            d /= UniverseDB.TradelaneSpeed;
                        }
                        else
                        {
                            d /= UniverseDB.CruiseSpeed;
                        }
                    }
                    else
                    {
                        d /= UniverseDB.CruiseSpeed;
                    }

                    node1.Value.Connections.Add(new PathfindingConnection(node1.Value, node2.Value, d));
                    node2.Value.Connections.Add(new PathfindingConnection(node2.Value, node1.Value, d));
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     Load a single system
        /// </summary>
        /// <param name="path"></param>
        /// <param name="system"></param>
        /// <param name="log"></param>
        private static void LoadSystem(string path, StarSystem system, ILogController log)
        {
            try
            {
                var ini = new FLDataFile(path, true);
                foreach (FLDataFile.Section sec in ini.Sections)
                {
                    string sectionName = sec.SectionName.ToLowerInvariant();
                    if (sectionName == "zone")
                    {
                        var zone = new Zone {
                            shape = null, nickname = sec.GetSetting("nickname").Str(0)
                        };
                        zone.zoneid = FLUtility.CreateID(zone.nickname);

                        Vector position    = sec.GetSetting("pos").Vector();
                        var    orientation = new Matrix();

                        double[] size = null;

                        string shape = sec.GetSetting("shape").Str(0).ToLowerInvariant();

                        foreach (FLDataFile.Setting set in sec.Settings)
                        {
                            string settingName = set.SettingName.ToLowerInvariant();
                            switch (settingName)
                            {
                            case "rotation":
                                orientation = Matrix.EulerDegToMatrix(set.Vector());
                                break;

                            case "size":
                                size = new double[set.NumValues()];
                                for (int a = 0; a < size.Length; a++)
                                {
                                    size[a] = set.Float(a);
                                }
                                break;

                            case "damage":
                                zone.damage = set.Float(0);
                                break;

                            case "interference":
                                zone.interference = set.Float(0);
                                break;

                            case "encounter":
                                break;

                            case "faction":
                                break;

                            case "density":
                                zone.density = set.Float(0);
                                break;
                            }
                        }

                        if (size != null)
                        {
                            if (shape == "sphere" && size.Length == 1)
                            {
                                zone.shape = new Sphere(position, orientation, size[0]);
                            }
                            else if (shape == "cylinder" && size.Length == 2)
                            {
                                zone.shape = new Cylinder(position, orientation, size[0], size[1]);
                            }
                            else if (shape == "ellipsoid" && size.Length == 3)
                            {
                                zone.shape = new Ellipsoid(position, orientation, new Vector(size[0], size[1], size[2]));
                            }
                            else if (shape == "box" && size.Length == 3)
                            {
                                zone.shape = new Box(position, orientation, new Vector(size[0], size[1], size[2]));
                            }
                            else if (shape == "ring" && size.Length == 3)
                            {
                                zone.shape = new Ring(position, orientation, size[0], size[1], size[2]);
                            }
                        }

                        system.Zones.Add(zone);
                    }
                    else if (sectionName == "object")
                    {
                        var solar = new Object.Solar.Solar(system, sec.GetSetting("nickname").Str(0));

                        if (sec.SettingExists("pos"))
                        {
                            solar.Position = sec.GetSetting("pos").Vector();
                        }

                        if (sec.SettingExists("rotate"))
                        {
                            Vector euler = sec.GetSetting("rotate").Vector();
                            solar.Orientation = Matrix.EulerDegToMatrix(euler);
                        }

                        if (sec.SettingExists("base"))
                        {
                            // When a ship undocks, it undocks from the solar specified by baseid.
                            // uint baseid = FLUtility.CreateID(sec.GetSetting("base").Str(0));
                            // FIXME: check base exists
                            // solar.base_data = bases[baseid];
                            // bases[baseid].solar = solar;
                        }

                        if (sec.SettingExists("archetype"))
                        {
                            uint archetypeid = FLUtility.CreateID(sec.GetSetting("archetype").Str(0));
                            solar.Arch = ArchetypeDB.Find(archetypeid);
                            solar.GetLoadout();
                            // FIXME: check archetype exists
                        }

                        if (sec.SettingExists("dock_with"))
                        {
                            uint baseid = FLUtility.CreateID(sec.GetSetting("dock_with").Str(0));
                            solar.BaseData = Bases[baseid];
                        }

                        if (sec.SettingExists("goto"))
                        {
                            solar.DestinationObjid    = FLUtility.CreateID(sec.GetSetting("goto").Str(1));
                            solar.DestinationSystemid = FLUtility.CreateID(sec.GetSetting("goto").Str(0));
                        }

                        if (sec.SettingExists("prev_ring"))
                        {
                            solar.PrevRing = FLUtility.CreateID(sec.GetSetting("prev_ring").Str(0));
                        }

                        if (sec.SettingExists("next_ring"))
                        {
                            solar.NextRing = FLUtility.CreateID(sec.GetSetting("next_ring").Str(0));
                        }

                        if (sec.SettingExists("reputation"))
                        {
                            Faction faction = FindFaction(sec.GetSetting("reputation").Str(0));
                            if (faction == null)
                            {
                                log.AddLog(LogType.ERROR, "error: not valid faction={0}",
                                           sec.GetSetting("reputation").Str(0));
                            }
                            else
                            {
                                solar.Faction = faction;
                            }
                        }

                        // Rebuild the docking points from the archetype
                        // to the solar position and rotation.
                        foreach (DockingPoint dockingPoint in solar.Arch.DockingPoints)
                        {
                            var dockingObj = new DockingObject
                            {
                                Type          = dockingPoint.Type,
                                Solar         = solar,
                                Index         = (uint)solar.Arch.DockingPoints.IndexOf(dockingPoint),
                                DockingRadius = dockingPoint.DockingRadius,
                                Position      = solar.Orientation * dockingPoint.Position
                            };

                            // rotate the hardpoint by the base orientation and then
                            dockingObj.Position += solar.Position;

                            // the ship launch rotation is the base rotation rotated by the hardpoint rotation
                            dockingObj.Rotation = dockingPoint.Rotation * solar.Orientation;

                            if (solar.BaseData != null)
                            {
                                solar.BaseData.LaunchObjs.Add(dockingObj);
                            }

                            solar.DockingObjs.Add(dockingObj);
                        }


                        // Store the solar.
                        system.Solars[solar.Objid] = solar;
                        Solars[solar.Objid]        = solar;

                        if (solar.Arch.Type == Archetype.ObjectType.JUMP_GATE ||
                            solar.Arch.Type == Archetype.ObjectType.JUMP_HOLE)
                        {
                            system.Gates.Add(solar);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.AddLog(LogType.ERROR, "error: '" + e.Message + "' when parsing '" + path);
                if (e.InnerException != null)
                {
                    log.AddLog(LogType.ERROR, "error: '" + e.InnerException.Message + "' when parsing '" + path);
                }
            }
        }