Пример #1
0
        private bool readConfig()
        {
            KourageousTouristsAddOn.printDebug("reading config");
            ConfigNode config = GameDatabase.Instance.GetConfigNodes(KourageousTouristsAddOn.cfgRoot).FirstOrDefault();

            if (config == null)
            {
                KourageousTouristsAddOn.printDebug("no config found in game database");
                return(false);
            }

            // TODO: Remove this coupling
            String dbg = config.GetValue(KourageousTouristsAddOn.debugLog);

            if (dbg != null)
            {
                KourageousTouristsAddOn.debug = dbg.ToLower().Equals("true");
            }

            ConfigNode[] nodes = config.GetNodes(KourageousTouristsAddOn.cfgLevel);
            foreach (ConfigNode cfg in nodes)
            {
                String tLvl = cfg.GetValue("touristlevel");
                if (tLvl == null)
                {
                    KourageousTouristsAddOn.printDebug("tourist config entry has no attribute 'level'");
                    return(false);
                }

                KourageousTouristsAddOn.printDebug("lvl=" + tLvl);
                ProtoTourist t = new ProtoTourist();
                int          lvl;
                if (!Int32.TryParse(tLvl, out lvl))
                {
                    KourageousTouristsAddOn.printDebug("Can't parse tourist level as int: " + tLvl);
                    return(false);
                }
                t.level = lvl;

                if (cfg.HasValue("situations"))
                {
                    t.situations.AddRange(
                        cfg.GetValue("situations").Replace(" ", "").Split(','));
                }
                t.situations.RemoveAll(str => String.IsNullOrEmpty(str));
                if (cfg.HasValue("bodies"))
                {
                    t.celestialBodies.AddRange(
                        cfg.GetValue("bodies").Replace(" ", "").Split(','));
                }
                t.celestialBodies.RemoveAll(str => String.IsNullOrEmpty(str));
                if (cfg.HasValue("abilities"))
                {
                    t.abilities.AddRange(
                        cfg.GetValue("abilities").Replace(" ", "").Split(','));
                }
                t.abilities.RemoveAll(str => String.IsNullOrEmpty(str));
                if (cfg.HasValue("srfspeed"))
                {
                    String srfSpeed = cfg.GetValue("srfspeed");
                    KourageousTouristsAddOn.printDebug("srfspeed = " + srfSpeed);
                    double spd = 0.0;
                    if (Double.TryParse(srfSpeed, out spd))
                    {
                        t.srfspeed = spd;
                    }
                    else
                    {
                        t.srfspeed = Double.NaN;
                    }
                }

                KourageousTouristsAddOn.printDebug("Adding cfg: " + t.ToString());
                this.touristConfig.Add(lvl, t);
            }
            return(true);
        }
Пример #2
0
        private bool readConfig()
        {
            Log.dbg("reading config");
            ConfigNode config = Settings.Read();

            if (config == null)
            {
                Log.dbg("no config found in game database");
                return(false);
            }

            ConfigNode[] nodes = config.GetNodes(KourageousTouristsAddOn.cfgLevel);
            foreach (ConfigNode cfg in nodes)
            {
                String tLvl = cfg.GetValue("touristlevel");
                if (tLvl == null)
                {
                    Log.dbg("tourist config entry has no attribute 'level'");
                    return(false);
                }

                Log.dbg("lvl={0}", tLvl);
                ProtoTourist t = new ProtoTourist();
                int          lvl;
                if (!Int32.TryParse(tLvl, out lvl))
                {
                    Log.dbg("Can't parse tourist level as int: {0}", tLvl);
                    return(false);
                }
                t.level = lvl;

                if (cfg.HasValue("situations"))
                {
                    t.situations.AddRange(
                        cfg.GetValue("situations").Replace(" ", "").Split(','));
                }
                t.situations.RemoveAll(str => String.IsNullOrEmpty(str));
                if (cfg.HasValue("bodies"))
                {
                    t.celestialBodies.AddRange(
                        cfg.GetValue("bodies").Replace(" ", "").Split(','));
                }
                t.celestialBodies.RemoveAll(str => String.IsNullOrEmpty(str));
                if (cfg.HasValue("abilities"))
                {
                    t.abilities.AddRange(
                        cfg.GetValue("abilities").Replace(" ", "").Split(','));
                }
                t.abilities.RemoveAll(str => String.IsNullOrEmpty(str));
                if (cfg.HasValue("srfspeed"))
                {
                    String srfSpeed = cfg.GetValue("srfspeed");
                    Log.dbg("srfspeed = {0}", srfSpeed);
                    double spd = 0.0;
                    if (Double.TryParse(srfSpeed, out spd))
                    {
                        t.srfspeed = spd;
                    }
                    else
                    {
                        t.srfspeed = Double.NaN;
                    }
                }

                Log.dbg("Adding cfg: {0}", t);
                this.touristConfig.Add(lvl, t);
            }
            return(true);
        }