コード例 #1
0
  // called every frame
  public void OnGUI()
  {
    // avoid case when DB isn't ready for whatever reason
    if (!DB.Ready()) return;

    // check only when at the space center
    if (HighLogic.LoadedScene != GameScenes.SPACECENTER) return;

    // check once in a while
    float time = Time.realtimeSinceStartup;
    if (last_check + check_interval > time) return;
    last_check = time;

    // get notification data
    notification_data nd = DB.NotificationData();

    // if there are tutorials left to show
    if (nd.next_tutorial < tutorials.Length)
    {
      // check tutorial condition
      if (tutorial_condition(nd.next_tutorial))
      {
        // check if the relative feature is enabled
        if (tutorial_feature(nd.next_tutorial))
        {
          // show notification
          Entry e = tutorials[nd.next_tutorial];
          Notification(e.title, e.msg, "INFO");
        }

        // move to next tutorial
        ++nd.next_tutorial;
      }
    }

    // if there is one or more new deaths
    if (nd.death_counter > nd.last_death_counter)
    {
      // show notification
      Entry e = death_report[nd.next_death_report];
      Notification(e.title, e.msg, "ALERT");

      // move to next tutorial, cycle throwgh all of them repetatedly
      // note: done this way because modulo didn't work...
      ++nd.next_death_report;
      if (nd.next_death_report >= death_report.Length) nd.next_death_report -= (uint)death_report.Length;
    }

    // remember number of death kerbals
    nd.last_death_counter = nd.death_counter;
  }
コード例 #2
0
ファイル: DB.cs プロジェクト: speedwaystar/Kerbalism
  public override void OnLoad(ConfigNode node)
  {
    // get version of the savegame
    // note: if there isn't a version this is either a new game, or the first public release (that didn't have versioning)
    string version = node.HasValue("version") ? node.GetValue("version") : node.HasNode("kerbals") ? "0.9.9.0" : current_version;


    kerbals.Clear();
    if (node.HasNode("kerbals"))
    {
      ConfigNode kerbals_node = node.GetNode("kerbals");
      foreach(ConfigNode kerbal_node in kerbals_node.GetNodes())
      {
        kerbal_data kd = new kerbal_data();
        kd.temperature     = Convert.ToDouble( kerbal_node.GetValue("temperature") );
        kd.starved         = Convert.ToDouble( kerbal_node.GetValue("starved") );
        kd.deprived        = Convert.ToDouble( kerbal_node.GetValue("deprived") );
        kd.stressed        = Convert.ToDouble( kerbal_node.GetValue("stressed") );
        kd.radiation       = Convert.ToDouble( kerbal_node.GetValue("radiation") );
        kd.time_since_food = Convert.ToDouble( kerbal_node.GetValue("time_since_food") );
        kd.msg_freezing    = Convert.ToUInt32( kerbal_node.GetValue("msg_freezing") );
        kd.msg_burning     = Convert.ToUInt32( kerbal_node.GetValue("msg_burning") );
        kd.msg_starved     = Convert.ToUInt32( kerbal_node.GetValue("msg_starved") );
        kd.msg_deprived    = Convert.ToUInt32( kerbal_node.GetValue("msg_deprived") );
        kd.msg_stressed    = Convert.ToUInt32( kerbal_node.GetValue("msg_stressed") );
        kd.msg_radiation   = Convert.ToUInt32( kerbal_node.GetValue("msg_radiation") );
        kd.resque          = Convert.ToUInt32( kerbal_node.GetValue("resque") );
        kd.disabled        = Convert.ToUInt32( kerbal_node.GetValue("disabled") );
        kerbals.Add(kerbal_node.name.Replace("___", " "), kd);
      }
    }

    vessels.Clear();
    if (node.HasNode("vessels"))
    {
      ConfigNode vessels_node = node.GetNode("vessels");
      foreach(ConfigNode vessel_node in vessels_node.GetNodes())
      {
        vessel_data vd = new vessel_data();
        vd.msg_ec          = Convert.ToUInt32( vessel_node.GetValue("msg_ec") );
        vd.msg_food        = Convert.ToUInt32( vessel_node.GetValue("msg_food") );
        vd.msg_oxygen      = Convert.ToUInt32( vessel_node.GetValue("msg_oxygen") );
        vd.msg_signal      = Convert.ToUInt32( vessel_node.GetValue("msg_signal") );
        vd.msg_belt        = Convert.ToUInt32( vessel_node.GetValue("msg_belt") );
        vd.cfg_ec          = Convert.ToUInt32( vessel_node.GetValue("cfg_ec") );
        vd.cfg_supply      = Convert.ToUInt32( vessel_node.GetValue("cfg_supply") );
        vd.cfg_malfunction = Convert.ToUInt32( vessel_node.GetValue("cfg_malfunction") );
        vd.cfg_signal      = Convert.ToUInt32( vessel_node.GetValue("cfg_signal") );
        vd.notes           = vessel_node.GetValue("notes").Replace("$NEWLINE", "\n");
        vd.group           = string.CompareOrdinal(version, "0.9.9.0") > 0 ? vessel_node.GetValue("group") : "NONE";
        vessels.Add(new Guid(vessel_node.name), vd);
      }
    }

    bodies.Clear();
    if (node.HasNode("bodies"))
    {
      ConfigNode bodies_node = node.GetNode("bodies");
      foreach(ConfigNode body_node in bodies_node.GetNodes())
      {
        body_data bd = new body_data();
        bd.storm_time  = Convert.ToDouble( body_node.GetValue("storm_time") );
        bd.storm_age   = Convert.ToDouble( body_node.GetValue("storm_age") );
        bd.storm_state = Convert.ToUInt32( body_node.GetValue("storm_state") );
        bd.msg_storm   = Convert.ToUInt32( body_node.GetValue("msg_storm") );
        bodies.Add(body_node.name.Replace("___", " "), bd);
      }
    }

    notifications = new notification_data();
    if (node.HasNode("notifications"))
    {
      ConfigNode notifications_node = node.GetNode("notifications");
      notifications.next_death_report   = Convert.ToUInt32( notifications_node.GetValue("next_death_report") );
      notifications.next_tutorial       = Convert.ToUInt32( notifications_node.GetValue("next_tutorial") );
      notifications.death_counter       = Convert.ToUInt32( notifications_node.GetValue("death_counter") );
      notifications.last_death_counter  = Convert.ToUInt32( notifications_node.GetValue("last_death_counter") );
      notifications.first_belt_crossing = Convert.ToUInt32( notifications_node.GetValue("first_belt_crossing") );
      notifications.first_signal_loss   = Convert.ToUInt32( notifications_node.GetValue("first_signal_loss") );
      notifications.first_malfunction   = Convert.ToUInt32( notifications_node.GetValue("first_malfunction") );
    }


    // if an old savegame was imported, log some debug info
    if (version != current_version) Lib.Log("savegame converted from version " + version);
  }
コード例 #3
0
ファイル: DB.cs プロジェクト: BrodigganGale/Kerbalism
  public override void OnLoad(ConfigNode node)
  {
    // get version of the savegame
    // note: if there isn't a version this is either a new game, or the first public release (that didn't have versioning)
    string version = node.HasValue("version") ? node.GetValue("version") : node.HasNode("kerbals") ? "0.9.9.0" : current_version;

    // this is an unsupported version, attempt a total clean up and pray
    // note: currently unused
    if (string.CompareOrdinal(version, "0.9.9.0") < 0)
    {
      Lib.Log("loading save from unsupported version " + version);
      kerbals.Clear();
      vessels.Clear();
      bodies.Clear();
      notifications = new notification_data();
      return;
    }


    kerbals.Clear();
    if (node.HasNode("kerbals"))
    {
      ConfigNode kerbals_node = node.GetNode("kerbals");
      foreach(ConfigNode kerbal_node in kerbals_node.GetNodes())
      {
        kerbal_data kd = new kerbal_data();
        kd.resque          = Lib.ConfigValue(kerbal_node, "resque", 1u);
        kd.disabled        = Lib.ConfigValue(kerbal_node, "disabled", 0u);
        kd.living_space    = Lib.ConfigValue(kerbal_node, "living_space", 1.0); // since 0.9.9.4
        kd.entertainment   = Lib.ConfigValue(kerbal_node, "entertainment", 1.0); // since 0.9.9.4
        kd.shielding       = Lib.ConfigValue(kerbal_node, "shielding", 0.0); // since 0.9.9.4
        kd.space_name      = Lib.ConfigValue(kerbal_node, "space_name", ""); // since 0.9.9.4
        kd.kmon = new Dictionary<string, kmon_data>();
        if (kerbal_node.HasNode("kmon")) // since 0.9.9.5
        {
          foreach(var cfg in kerbal_node.GetNode("kmon").GetNodes())
          {
            kmon_data kmon = new kmon_data();
            kmon.problem = Lib.ConfigValue(cfg, "problem", 0.0);
            kmon.message = Lib.ConfigValue(cfg, "message", 0u);
            kmon.time_since = Lib.ConfigValue(cfg, "time_since", 0.0);
            kd.kmon.Add(cfg.name, kmon);
          }
        }
        kerbals.Add(kerbal_node.name.Replace("___", " "), kd);
      }
    }

    vessels.Clear();
    if (node.HasNode("vessels"))
    {
      ConfigNode vessels_node = node.GetNode("vessels");
      foreach(ConfigNode vessel_node in vessels_node.GetNodes())
      {
        vessel_data vd = new vessel_data();
        vd.msg_signal      = Lib.ConfigValue(vessel_node, "msg_signal", 0u);
        vd.msg_belt        = Lib.ConfigValue(vessel_node, "msg_belt", 0u);
        vd.cfg_ec          = Lib.ConfigValue(vessel_node, "cfg_ec", 1u);
        vd.cfg_supply      = Lib.ConfigValue(vessel_node, "cfg_supply", 1u);
        vd.cfg_signal      = Lib.ConfigValue(vessel_node, "cfg_signal", 1u);
        vd.cfg_malfunction = Lib.ConfigValue(vessel_node, "cfg_malfunction", 1u);
        vd.cfg_storm       = Lib.ConfigValue(vessel_node, "cfg_storm", 1u); // since 0.9.9.5
        vd.cfg_highlights  = Lib.ConfigValue(vessel_node, "cfg_highlights", 1u); // since 0.9.9.5
        vd.cfg_showlink    = Lib.ConfigValue(vessel_node, "cfg_showlink", 0u); // since 0.9.9.8
        vd.notes           = Lib.ConfigValue(vessel_node, "notes", "").Replace("$NEWLINE", "\n"); // since 0.9.9.1
        vd.group           = Lib.ConfigValue(vessel_node, "group", "NONE"); // since 0.9.9.1
        vd.vmon = new Dictionary<string, vmon_data>();
        if (vessel_node.HasNode("vmon")) // since 0.9.9.5
        {
          foreach(var cfg in vessel_node.GetNode("vmon").GetNodes())
          {
            vmon_data vmon = new vmon_data();
            vmon.message = Lib.ConfigValue(cfg, "message", 0u);
            vd.vmon.Add(cfg.name, vmon);
          }
        }
        vd.scansat_id = new List<uint>();
        foreach(string s in vessel_node.GetValues("scansat_id")) // since 0.9.9.5
        {
          vd.scansat_id.Add(Convert.ToUInt32(s));
        }
        vessels.Add(new Guid(vessel_node.name), vd);
      }
    }

    bodies.Clear();
    if (node.HasNode("bodies"))
    {
      ConfigNode bodies_node = node.GetNode("bodies");
      foreach(ConfigNode body_node in bodies_node.GetNodes())
      {
        body_data bd = new body_data();
        bd.storm_time  = Lib.ConfigValue(body_node, "storm_time", 0.0);
        bd.storm_age   = Lib.ConfigValue(body_node, "storm_age", 0.0);
        bd.storm_state = Lib.ConfigValue(body_node, "storm_state", 0u);
        bd.msg_storm   = Lib.ConfigValue(body_node, "msg_storm", 0u);
        bodies.Add(body_node.name.Replace("___", " "), bd);
      }
    }

    notifications = new notification_data();
    if (node.HasNode("notifications"))
    {
      ConfigNode n_node = node.GetNode("notifications");
      notifications.next_death_report   = Lib.ConfigValue(n_node, "next_death_report", 0u);
      notifications.next_tutorial       = Lib.ConfigValue(n_node, "next_tutorial", 0u);
      notifications.death_counter       = Lib.ConfigValue(n_node, "death_counter", 0u);
      notifications.last_death_counter  = Lib.ConfigValue(n_node, "last_death_counter", 0u);
      notifications.first_belt_crossing = Lib.ConfigValue(n_node, "first_belt_crossing", 0u);
      notifications.first_signal_loss   = Lib.ConfigValue(n_node, "first_signal_loss", 0u);
      notifications.first_malfunction   = Lib.ConfigValue(n_node, "first_malfunction", 0u);
    }


    // versions before 0.9.9.5 used a different structure to remember message sent
    // mute the message system for a few seconds to avoid the user being bombarded by messages
    if (string.CompareOrdinal(version, "0.9.9.5") < 0)
    {
      Message.MuteInternal();
      base.StartCoroutine(CallbackUtil.DelayedCallback(10.0f, Message.UnmuteInternal));
    }


    // versions before 0.9.9.5 didn't have profiles, and didn't use CRP food/oxygen values
    // scale all amounts of them in existing vessels, to not break savegames
    if (string.CompareOrdinal(version, "0.9.9.5") < 0)
    {
      foreach(Vessel v in FlightGlobals.Vessels.FindAll(k => !k.loaded))
      {
        foreach(var part in v.protoVessel.protoPartSnapshots)
        {
          var food = part.resources.Find(k => k.resourceName == "Food");
          if (food != null)
          {
            food.resourceValues.SetValue("amount", (Lib.ConfigValue(food.resourceValues, "amount", 0.0f) * 10.0f).ToString());
            food.resourceValues.SetValue("maxAmount", (Lib.ConfigValue(food.resourceValues, "maxAmount", 0.0f) * 10.0f).ToString());
          }

          var oxygen = part.resources.Find(k => k.resourceName == "Oxygen");
          if (oxygen != null)
          {
            oxygen.resourceValues.SetValue("amount", (Lib.ConfigValue(oxygen.resourceValues, "amount", 0.0f) * 1000.0f).ToString());
            oxygen.resourceValues.SetValue("maxAmount", (Lib.ConfigValue(oxygen.resourceValues, "maxAmount", 0.0f) * 1000.0f).ToString());
          }
        }
      }
    }


    // if an old savegame was imported, log some debug info
    if (version != current_version) Lib.Log("savegame converted from version " + version);
  }