Ejemplo n.º 1
0
Archivo: save.c Proyecto: isfos/naev
/**
 * @brief Actually loads a new game based on file.
 *
 *    @param file File that contains the new game.
 *    @return 0 on success.
 */
static int load_game( const char* file )
{
   xmlNodePtr node;
   xmlDocPtr doc;

   /* Make sure it exists. */
   if (!nfile_fileExists(file)) {
      dialogue_alert("Savegame file seems to have been deleted.");
      return -1;
   }

   /* Load the XML. */
   doc   = xmlParseFile(file);
   if (doc == NULL)
      goto err;
   node  = doc->xmlChildrenNode; /* base node */
   if (node == NULL)
      goto err_doc;

   /* Clean up possible stuff that should be cleaned. */
   player_cleanup();
   diff_clear();
   var_cleanup();
   missions_cleanup();
   events_cleanup();

   /* Welcome message - must be before space_init. */
   player_message( "\egWelcome to "APPNAME"!" );
   player_message( "\eg v%d.%d.%d", VMAJOR, VMINOR, VREV );

   /* Now begin to load. */
   diff_load(node); /* Must load first to work properly. */
   pfaction_load(node); /* Must be loaded before player so the messages show up properly. */
   player_load(node);
   var_load(node);
   missions_loadActive(node);
   hook_load(node);
   space_sysLoad(node);

   /* Initialize the economy. */
   economy_init();

   /* Need to run takeoff hooks since player just "took off" */
   hooks_run("takeoff");
   player_addEscorts();
   hooks_run("enter");
   events_trigger( EVENT_TRIGGER_ENTER );

   xmlFreeDoc(doc);
   xmlCleanupParser();
   
   return 0;

err_doc:
   xmlFreeDoc(doc);
   xmlCleanupParser();
err:
   WARN("Savegame '%s' invalid!", file);
   return -1;
}
Ejemplo n.º 2
0
Archivo: naev.c Proyecto: ekrumme/naev
/**
 * @brief Unloads all data, simplifies main().
 */
void unload_all (void)
{
   /* data unloading - inverse load_all is a good order */
   economy_destroy(); /* must be called before space_exit */
   space_exit(); /* cleans up the universe itself */
   fleet_free();
   ships_free();
   outfit_free();
   spfx_free(); /* gets rid of the special effect */
   missions_free();
   factions_free();
   commodity_free();
   var_cleanup(); /* cleans up mission variables */
}