Beispiel #1
0
        public StarSystem(UniverseIni universe, Section section, FreelancerData data)
            : base(data)
        {
            if (universe == null)
            {
                throw new ArgumentNullException("universe");
            }
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }
            string file = null;

            foreach (Entry e in section)
            {
                switch (e.Name.ToLowerInvariant())
                {
                case "nickname":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (Nickname != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    Nickname = e[0].ToString();
                    break;

                case "file":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (file != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    file = e[0].ToString();
                    break;

                case "pos":
                    if (e.Count != 2)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (Pos != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    Pos = new Vector2(e[0].ToSingle(), e[1].ToSingle());
                    break;

                case "msg_id_prefix":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (MsgIdPrefix != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    MsgIdPrefix = e[0].ToString();
                    break;

                case "visit":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (Visit != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    Visit = e[0].ToInt32();
                    break;

                case "strid_name":
                    if (e.Count == 0)
                    {
                        break;
                    }
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (StridName != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    StridName = GameData.Infocards.GetStringResource(e[0].ToInt32());
                    break;

                case "ids_info":
                    if (e.Count == 0)
                    {
                        break;
                    }
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (IdsInfo != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    IdsInfo = GameData.Infocards.GetXmlResource(e[0].ToInt32());
                    break;

                case "navmapscale":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (NavMapScale != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    NavMapScale = e[0].ToSingle();
                    break;

                default:
                    throw new Exception("Invalid Entry in " + section.Name + ": " + e.Name);
                }
            }

            if (file == null)               //TODO: MultiUniverse
            {
                FLLog.Warning("Ini", "Unimplemented: Possible MultiUniverse system " + Nickname);
                return;
            }

            foreach (Section s in ParseFile(GameData.Freelancer.DataPath + "universe\\" + file))
            {
                switch (s.Name.ToLowerInvariant())
                {
                case "systeminfo":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "name":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (Name != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            Name = e[0].ToString();
                            break;

                        case "space_color":
                            if (e.Count != 3)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (SpaceColor != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            SpaceColor = new Color4(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f, 1f);
                            break;

                        case "local_faction":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (LocalFaction != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            LocalFaction = e[0].ToString();
                            break;

                        case "rpop_solar_detection":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (RpopSolarDetection != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            RpopSolarDetection = e[0].ToBoolean();
                            break;

                        case "space_farclip":
                            if (SpaceFarClip != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            SpaceFarClip = e[0].ToSingle();
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + section.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "music":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "space":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (MusicSpace != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            MusicSpace = e[0].ToString();
                            break;

                        case "danger":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (MusicDanger != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            MusicDanger = e[0].ToString();
                            break;

                        case "battle":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (MusicBattle != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            MusicBattle = e[0].ToString();
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + section.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "archetype":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "ship":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (ArchetypeShip == null)
                            {
                                ArchetypeShip = new List <string>();
                            }
                            ArchetypeShip.Add(e[0].ToString());
                            break;

                        case "simple":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (ArchetypeSimple == null)
                            {
                                ArchetypeSimple = new List <string>();
                            }
                            ArchetypeSimple.Add(e[0].ToString());
                            break;

                        case "solar":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (ArchetypeSolar == null)
                            {
                                ArchetypeSolar = new List <Archetype>();
                            }
                            ArchetypeSolar.Add(GameData.Solar.FindSolar(e[0].ToString()));
                            break;

                        case "equipment":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (ArchetypeEquipment == null)
                            {
                                ArchetypeEquipment = new List <string>();
                            }
                            ArchetypeEquipment.Add(e[0].ToString());
                            break;

                        case "snd":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (ArchetypeSnd == null)
                            {
                                ArchetypeSnd = new List <string>();
                            }
                            ArchetypeSnd.Add(e[0].ToString());
                            break;

                        case "voice":
                            if (ArchetypeVoice == null)
                            {
                                ArchetypeVoice = new List <List <string> >();
                            }
                            ArchetypeVoice.Add(new List <string>());
                            foreach (IValue i in e)
                            {
                                ArchetypeVoice[ArchetypeVoice.Count - 1].Add(i.ToString());
                            }
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + s.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "dust":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "spacedust":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (Spacedust != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            Spacedust = e[0].ToString();
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + s.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "nebula":
                    if (Nebulae == null)
                    {
                        Nebulae = new List <Nebula>();
                    }
                    Nebulae.Add(new Nebula(this, s, GameData));
                    break;

                case "asteroids":
                    if (Asteroids == null)
                    {
                        Asteroids = new List <AsteroidField>();
                    }
                    Asteroids.Add(new AsteroidField(this, s, GameData));
                    break;

                case "ambient":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "color":
                            if (e.Count != 3)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (AmbientColor != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            AmbientColor = new Color4(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f, 1f);
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + s.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "lightsource":
                    if (LightSources == null)
                    {
                        LightSources = new List <LightSource>();
                    }
                    LightSources.Add(new LightSource(s, GameData));
                    break;

                case "object":
                    if (Objects == null)
                    {
                        Objects = new List <SystemObject>();
                    }
                    Objects.Add(new SystemObject(universe, this, s, GameData));
                    break;

                case "encounterparameters":
                    if (EncounterParameters == null)
                    {
                        EncounterParameters = new List <EncounterParameter>();
                    }
                    EncounterParameters.Add(new EncounterParameter(s));
                    break;

                case "texturepanels":
                    TexturePanels = new TexturePanelsRef(s, GameData);
                    break;

                case "background":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "basic_stars":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (BackgroundBasicStarsPath != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            BackgroundBasicStarsPath = VFS.GetPath(GameData.Freelancer.DataPath + e [0].ToString());
                            break;

                        case "complex_stars":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (BackgroundComplexStarsPath != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            BackgroundComplexStarsPath = VFS.GetPath(GameData.Freelancer.DataPath + e [0].ToString());
                            break;

                        case "nebulae":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            string temp = VFS.GetPath(GameData.Freelancer.DataPath + e[0].ToString(), false);
                            if (BackgroundNebulaePath != null && BackgroundNebulaePath != temp)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            BackgroundNebulaePath = temp;
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + s.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "zone":
                    if (Zones == null)
                    {
                        Zones = new List <Zone>();
                    }
                    Zones.Add(new Zone(s, GameData));
                    break;

                case "field":
                    Field = new Field(s);
                    break;

                case "asteroidbillboards":
                    AsteroidBillboards = new AsteroidBillboards(s);
                    break;

                default:
                    throw new Exception("Invalid Section in " + file + ": " + s.Name);
                }
            }
        }
Beispiel #2
0
        public SystemObject(UniverseIni universe, StarSystem system, Section section, FreelancerData freelancerIni)
            : base(section, freelancerIni)
        {
            if (universe == null)
            {
                throw new ArgumentNullException("universe");
            }
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }

            this.universe      = universe;
            this.system        = system;
            TradelaneSpaceName = new List <string>();

            foreach (Entry e in section)
            {
                if (!parentEntry(e))
                {
                    switch (e.Name.ToLowerInvariant())
                    {
                    case "ambient_color":
                    case "ambient":
                        if (e.Count != 3)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (AmbientColor != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        AmbientColor = new Color4(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f, 1f);
                        break;

                    case "archetype":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (archetypeName != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        archetypeName = e[0].ToString();
                        break;

                    case "star":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (Star != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        Star = e[0].ToString();
                        break;

                    case "atmosphere_range":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (AtmosphereRange != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        AtmosphereRange = e[0].ToInt32();
                        break;

                    case "burn_color":
                        if (e.Count != 3)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (BurnColor != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        BurnColor = new Color4(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f, 1f);
                        break;

                    case "base":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (baseName != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        baseName = e[0].ToString();
                        break;

                    case "msg_id_prefix":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (MsgIdPrefix != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        MsgIdPrefix = e[0].ToString();
                        break;

                    case "jump_effect":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (JumpEffect != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        JumpEffect = e[0].ToString();
                        break;

                    case "behavior":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (Behavior != null && Behavior != e[0].ToString())
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        Behavior = e[0].ToString();
                        break;

                    case "difficulty_level":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (DifficultyLevel != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        DifficultyLevel = e[0].ToInt32();
                        break;

                    case "goto":
                        if (e.Count != 3)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (Goto != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        Goto = new JumpReference(e[0].ToString(), e[1].ToString(), e[2].ToString());
                        break;

                    case "loadout":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (loadoutName != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        loadoutName = e[0].ToString();
                        break;

                    case "pilot":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (Pilot != null && Pilot != e[0].ToString())
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        Pilot = e[0].ToString();
                        break;

                    case "dock_with":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (dockWithName != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        dockWithName = e[0].ToString();
                        break;

                    case "voice":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (Voice != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        Voice = e[0].ToString();
                        break;

                    case "space_costume":
                        if (e.Count < 1 /*|| e.Count > 3*/)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (SpaceCostume != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        SpaceCostume = new Costume(e[0].ToString(), e[1].ToString(), e.Count >= 3 ? e[2].ToString() : string.Empty, freelancerIni);
                        break;

                    case "faction":
                        if (e.Count != 1)
                        {
                            FLLog.Warning("Ini", "Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (Faction != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        Faction = e[0].ToString();
                        break;

                    case "prev_ring":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (PrevRing != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        PrevRing = e[0].ToString();
                        break;

                    case "next_ring":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (nextRingName != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        nextRingName = e[0].ToString();
                        break;

                    case "tradelane_space_name":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        TradelaneSpaceName.Add(GameData.Infocards.GetStringResource(e[0].ToInt32()));
                        break;

                    case "parent":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (parentName != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        parentName = e[0].ToString();
                        break;

                    case "info_card_ids":
                    case "info_card":
                    case "info_ids":
                        if (e.Count != 1)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        if (InfoCardIds != null)
                        {
                            throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        }
                        InfoCardIds = GameData.Infocards.GetStringResource(e[0].ToInt32());
                        break;

                    case "ring":
                        if (e.Count != 2)
                        {
                            throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                        }
                        //if ( != null) throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                        //TODO
                        break;

                    case "260800":                     // Strange error
                        break;

                    case "rot":
                        FLLog.Warning("SystemObject", "unimplemented: rot");
                        break;

                    default:
                        throw new Exception("Invalid Entry in " + section.Name + ": " + e.Name);
                    }
                }
            }
        }