[Fix] Couple bugs with saving.

This commit is contained in:
Allanis 2013-05-08 20:11:38 +01:00
parent bb48d5ac23
commit fa7138f907
4 changed files with 32 additions and 7 deletions

View File

@ -8,6 +8,7 @@
#include "hook.h" #include "hook.h"
#include "mission.h" #include "mission.h"
#include "ltime.h" #include "ltime.h"
#include "save.h"
#include "land.h" #include "land.h"
// Global/main window. // Global/main window.
@ -969,6 +970,7 @@ void land(Planet* p) {
// TODO: mission check. // TODO: mission check.
visited(VISITED_LAND); visited(VISITED_LAND);
} }
save_all();
} }
// Takeoff from the planet. // Takeoff from the planet.

View File

@ -1467,19 +1467,23 @@ static int player_saveShip(xmlTextWriterPtr writer, Pilot* ship, char* loc) {
xmlw_attr(writer, "name", ship->name); xmlw_attr(writer, "name", ship->name);
xmlw_elem(writer, "shipname", ship->ship->name); xmlw_elem(writer, "shipname", ship->ship->name);
xmlw_elem(writer, "location", loc); if(loc != NULL) xmlw_elem(writer, "location", loc);
// Save the outfits. // Save the outfits.
xmlw_startElem(writer, "outfits"); xmlw_startElem(writer, "outfits");
for(i = 0; i < ship->noutfits; i++) { for(i = 0; i < ship->noutfits; i++) {
xmlw_elem(writer, "outfit", ship->outfits[i].outfit->name); xmlw_startElem(writer, "outfit");
xmlw_attr(writer, "quantity", "%d", ship->outfits[i].quantity); xmlw_attr(writer, "quantity", "%d", ship->outfits[i].quantity);
xmlw_str(writer, ship->outfits[i].outfit->name);
xmlw_endElem(writer); // Outfit.
} }
xmlw_endElem(writer); // Outfits. xmlw_endElem(writer); // Outfits.
// Save the commodities. // Save the commodities.
xmlw_startElem(writer, "commodities"); xmlw_startElem(writer, "commodities");
for(i = 0; i < ship->noutfits; i++) { for(i = 0; i < ship->ncommodities; i++) {
xmlw_elem(writer, "outfit", ship->commodities[i].commodity->name); xmlw_elem(writer, "outfit", ship->commodities[i].commodity->name);
xmlw_attr(writer, "quantity", "%d", ship->commodities[i].quantity); xmlw_attr(writer, "quantity", "%d", ship->commodities[i].quantity);
if(ship->commodities[i].id > 0) if(ship->commodities[i].id > 0)

View File

@ -6,6 +6,16 @@
// Externs. // Externs.
extern int player_save(xmlTextWriterPtr writer); extern int player_save(xmlTextWriterPtr writer);
extern int missions_save(xmlTextWriterPtr writer); extern int missions_save(xmlTextWriterPtr writer);
// Static.
static int save_data(xmlTextWriterPtr writer);
static int save_data(xmlTextWriterPtr writer) {
// The data itself.
if(player_save(writer) < 0) return -1;
if(missions_save(writer) < 0) return -1;
return 0;
}
int save_all(void) { int save_all(void) {
char* file; char* file;
@ -19,17 +29,22 @@ int save_all(void) {
} }
xmlw_start(writer); xmlw_start(writer);
xmlw_startElem(writer, "lephisto_save");
// The data itself. if(save_data(writer) < 0) {
player_save(writer); ERR("Trying to save game data");
missions_save(writer); xmlFreeTextWriter(writer);
xmlFreeDoc(doc);
return -1;
}
xmlw_endElem(writer); // lephisto_save.
xmlw_done(writer); xmlw_done(writer);
file = "test.xml"; file = "test.xml";
xmlFreeTextWriter(writer); xmlFreeTextWriter(writer);
xmlSaveFileEnc(file, doc, "UTF-8"); //xmlSaveFileEnc(file, doc, "UTF-8");
xmlFreeDoc(doc); xmlFreeDoc(doc);
return 0; return 0;

View File

@ -49,6 +49,10 @@
if(xmlTextWriterWriteFormatAttribute(w, (xmlChar*)str, ## val) < 0) { \ if(xmlTextWriterWriteFormatAttribute(w, (xmlChar*)str, ## val) < 0) { \
ERR("xmlw: Unable to write element attribute"); return -1; } ERR("xmlw: Unable to write element attribute"); return -1; }
#define xmlw_str(w, str, val...) \
if(xmlTextWriterWriteFormatString(w, str, ## val) < 0) { \
ERR("xmlw: Unable to write element data"); return -1; }
// Document level. // Document level.
#define xmlw_start(w) \ #define xmlw_start(w) \
if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) { \ if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) { \