/** * @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; }
/** * @brief Frees all the mission data. */ void missions_free (void) { int i; /* Free all the player missions. */ missions_cleanup(); /* Free the mission data. */ for (i=0; i<mission_nstack; i++) mission_freeData( &mission_stack[i] ); free( mission_stack ); mission_stack = NULL; mission_nstack = 0; }
/** * @brief Loads the player's active missions from a save. * * @param parent Node containing the player's active missions. * @return 0 on success. */ int missions_loadActive( xmlNodePtr parent ) { xmlNodePtr node; /* cleanup old missions */ missions_cleanup(); node = parent->xmlChildrenNode; do { if (xml_isNode(node,"missions")) if (missions_parseActive( node ) < 0) return -1; } while (xml_nextNode(node)); return 0; }