示例#1
0
  //
  // SaveObjectFile
  //
  // Save all objects, false if unable to create file
  //
  Bool SaveObjectFile(const char *name)
  {
    PTree pTree;
    FilePath path;

    // Get the global scope of the parse tree
    FScope *gScope = pTree.GetGlobalScope();

    // Save every game object
    for (NList<GameObj>::Iterator i(&GameObjCtrl::listAll); *i; i++)
    {
      SaveCreateObject(gScope, *i);
    }

    // Work out save path
    Dir::PathMake(path, Missions::GetWritePath(), name);
  
    // Write the file
    if (!CoreGame::WriteTree(pTree, path.str))
    {
      LOG_WARN(("Unable to write to file [%s]", path.str));
      return (FALSE);
    }

    // Success
    return (TRUE);
  }
示例#2
0
  //
  // LoadObjectFile
  //
  // Load a object definition file into current state, false if not found
  //
  Bool LoadObjectFile(const char *name)
  {
    ASSERT(name);

    PTree pTree;
    Bool safe = Missions::GetSafeLoad();

    // Parse the file
    GameGod::Loader::SubSystem("#game.loader.createobjects", 1);

    if (pTree.AddFile(name))
    {
      // Get the global scope
      FScope *gScope = pTree.GetGlobalScope();
      FScope *sScope;

      // Process each function
      GameGod::Loader::SubSystem("#game.loader.createobjects", gScope->GetBodyCount());

      while ((sScope = gScope->NextFunction()) != NULL)
      {
        switch (sScope->NameCrc())
        {
          case 0xCAE286FA: // "CreateObject"
            LoadCreateObject(sScope, safe);
            GameGod::Loader::Advance();
            break;
        }
      }

      if (GameGod::CheckObjects())
      {
        FSCOPE_CHECK(gScope)
      }

      // Call each existing game object
      GameGod::Loader::SubSystem("#game.loader.configureobjects", GameObjCtrl::listAll.GetCount());

      for (NList<GameObj>::Iterator i(&GameObjCtrl::listAll); *i; i++)
      {
        // Are we in safe-mode and this is a map object
        if (safe && Promote::Object<MapObjType, MapObj>(*i))
        {
        }
        else
        {
          // Call virtual post-load function
          (*i)->PostLoad();
        }

        GameGod::Loader::Advance();
      }

      return (TRUE);
    }
示例#3
0
  //
  // Export
  //
  // Export this footprint to the given file name
  //
  Bool Type::Export(const char *fileName)
  {
    PTree tree;
    FScope *root, *cellInfo;
  
    // Add the top level scope
    root = tree.GetGlobalScope()->AddFunction("ConfigureFootPrint");

    // Get the layer used for zipping
    Layer &layer = GetLayer(LAYER_LOWER);

    // Save out the grid
    for (S32 z = 0; z <= size.z; z++)
    {
      for (S32 x = 0; x <= size.x; x++)
      {
        // Write out cell info
        cellInfo = root->AddFunction("SetupCell");
        cellInfo->AddArgInteger(x);
        cellInfo->AddArgInteger(z);

        // Is this cell on the footprint
        if (x < size.x && z < size.z)
        {
          Cell &cell = GetCell(x, z);
          StdSave::TypeU32(cellInfo, "Hide", cell.GetFlag(HIDE));
          StdSave::TypeU32(cellInfo, "SetBase", cell.GetFlag(SETBASE));
          StdSave::TypeU32(cellInfo, "Second", cell.GetFlag(SECOND));
          StdSave::TypeU32(cellInfo, "Dirs", cell.dirs);
          StdSave::TypeU32(cellInfo, "ClaimLo", cell.GetFlag(CLAIMLO));
          StdSave::TypeU32(cellInfo, "ClaimHi", cell.GetFlag(CLAIMHI));
          StdSave::TypeU32(cellInfo, "BlockLOS", cell.GetFlag(BLOCKLOS));

          if (cell.GetFlag(SURFACE))
          {
            MoveTable::KeyInfo *info = MoveTable::FindSurfaceInfo(cell.surface);

            if (info)
            {
              StdSave::TypeString(cellInfo, "Surface", info->ident.str);
            }
          }
        }

        Layer::Cell &cell = layer.GetCell(x, z);
        StdSave::TypeU32(cellInfo, "Zip", cell.GetFlag(Layer::ZIP));
      }
    }
  
    // Save out to disk
    return (tree.WriteTreeText(fileName));
  }
示例#4
0
  //
  // LoadConfig
  //
  // Load the configured difficulty settings
  //
  static void LoadConfig()
  {
    PTree pTree;
    GameIdent defaultName;

    // Clear any current settings
    ClearSettings();

    // Open the configuration file
    if (pTree.AddFile(configName))
    {
      FScope *gScope = pTree.GetGlobalScope();
      FScope *sScope;

      // Parse each function
      while ((sScope = gScope->NextFunction()) != NULL)
      {
        switch (sScope->NameCrc())
        {
          case 0x12AFF0D8: // "CreateSetting"
            ProcessCreateSetting(sScope);
            break;

          case 0x733C1EB5: // "DefaultSetting"
            defaultName = StdLoad::TypeString(sScope);
            break;
        }
      }

      // Ensure at least one setting is configured
      if (settings.GetCount())
      {
        // Setup the default setting
        if ((defaultSetting = FindSetting(defaultName)) == NULL)
        {
          defaultSetting = settings.GetHead();
        }

        // Set the current from the default
        currentSetting = defaultSetting;
      }
      else
      {
        ERR_CONFIG(("At least one difficulty setting must be supplied in [%s]", configName));
      }
    }
    else
    {
      ERR_CONFIG(("Unable to load difficulty settings configuration [%s]", configName));
    }
  }
示例#5
0
  //
  // ExecInitialConfig
  //
  // Executes the config file for this application
  //
  void ExecInitialConfig()
  {
    PTree pTree;

    // Attempt to open the file
    if (pTree.AddFile(APPLICATION_CONFIGFILE))
    {
      // Find our startup scope
      FScope *fScope = pTree.GetGlobalScope()->GetFunction("StartupConfig", FALSE);

      // Config is not required
      if (fScope)
      {
        Main::ProcessCmdScope(fScope);
      }
    }
    else
    {
      ERR_FATAL(("Unable to execute the required file '%s'", APPLICATION_CONFIGFILE));    
    }
  }
示例#6
0
  //
  // LoadConfig
  //
  // Load the group configuration file
  //
  void Group::LoadConfig()
  {
    FilePath configPath;
    PTree pTree;

    // Generate the config name
    Dir::PathMake(configPath, GetPath().str, MISSIONS_FILE_GROUP);
 
    // Add the campaign config
    if (pTree.AddFile(configPath.str))
    {
      FScope *gScope = pTree.GetGlobalScope();
      FScope *sScope;

      // Process each function
      while ((sScope = gScope->NextFunction()) != NULL)
      {
        switch (sScope->NameCrc())
        {
          case 0x47CB37F2: // "Description"
            description = StdLoad::TypeString(sScope);
            break;

          case 0xF81D1051: // "System"
            system = StdLoad::TypeU32(sScope);
            break;

          case 0xC2B3BE7B: // "InstantAction"
            instantAction = StdLoad::TypeU32(sScope);
            break;

          case 0x7BB50683: // "Campaign"
            Campaigns::CreateCampaign(*this, sScope);
            break;
        }
      }
    }
  }
示例#7
0
  //
  // Init
  //
  // Initialize system
  //
  void Init()
  {
    ASSERT(!initialized)
    ASSERT(!items.GetCount())

    PTree pTree;

    // Process the configuration
    if (pTree.AddFile(configName))
    {
      FScope *fScope = pTree.GetGlobalScope();
      FScope *sScope;

      while ((sScope = fScope->NextFunction()) != NULL)
      {
        switch (sScope->NameCrc())
        {
          case 0x64FFFFD7: // "Place"
          {
            // Load the data
            const char *type = StdLoad::TypeString(sScope);
            F32 direction = StdLoad::TypeCompassAngle(sScope);
            F32 distance = StdLoad::TypeF32(sScope);
            F32 orientation = StdLoad::TypeCompassAngle(sScope);

            // Create the item
            items.Append(new Item(type, direction, distance, orientation));
            break;
          }
        }
      }
    }

    // System now initialized
    initialized = TRUE;
  }
示例#8
0
  //
  // Preview::Preview
  //
  Preview::Preview(const Missions::Mission *missionIn) 
  : teams(&TeamInfo::node),
    terrain(NULL),
    ruleSetFixed(FALSE)
  {
    if (missionIn)
    {
      name = missionIn->GetName().str;
      path = missionIn->GetGroup().GetPath().str;
    }
    else
    {
      name = "";
      path = "";
    }

    // Open mission stream
    const char *oldStream = OpenMissionStream();

    // Open the game configuration file
    PTree pTree;

    // Parse the file
    if (pTree.AddFile(FILENAME_MISSION_CONFIG))
    {
      // Get the global scope
      FScope *gScope = pTree.GetGlobalScope();
      FScope *sScope;

      // Process each function
      while ((sScope = gScope->NextFunction()) != NULL)
      {
        switch (sScope->NameCrc())
        {
          case 0xEDF7E07D: // "DefaultRule"
            ruleSet = StdLoad::TypeString(sScope);
            break;

          case 0x7F6A7C11: // "FixedRule"
            ruleSetFixed = StdLoad::TypeU32(sScope);
            break;

          case 0x1D4A8250: // "WorldInfo"
            // Load map size
            size = StdLoad::TypeU32(sScope, "CellMapX");
            break;

          case 0xCA519158: // "DefineTeams"
          {
            ASSERT(!teams.GetCount())

            // Count the number of teams we find
            FScope *fScope;

            // Process each function
            while ((fScope = sScope->NextFunction()) != NULL)
            {
              switch (fScope->NameCrc())
              {
                case 0xB884B9E8: // "CreateTeam"
                {
                  // Is this team available for play
                  if (StdLoad::TypeU32(fScope, "AvailablePlay", 1))
                  {
                    // Create new team info
                    TeamInfo *info = new TeamInfo(fScope);

                    // Add to the tree
                    teams.Add(info->GetName().crc, info);
                  }
                  break;
                }
              }
            }

            break;
          }
        }
      }
    }
    else
    {
      size = 0;
    }

    // Load preview texture
    ReloadTextures();

    // Restore old stuff
    if (oldStream)
    {
      CloseMissionStream(oldStream);
    }
  }