/** * @brief Saves the player's active events. * * @param writer XML Write to use to save events. * @return 0 on success. */ int events_saveActive( xmlTextWriterPtr writer ) { int i; Event_t *ev; xmlw_startElem(writer,"events"); for (i=0; i<event_nactive; i++) { ev = &event_active[i]; if (!ev->save) /* Only save events that want to be saved. */ continue; xmlw_startElem(writer,"event"); xmlw_attr(writer,"name","%s",event_dataName(ev->data)); xmlw_attr(writer,"id","%u",ev->id); /* Claims. */ xmlw_startElem(writer,"claims"); claim_xmlSave( writer, ev->claims ); xmlw_endElem(writer); /* "claims" */ /* Write Lua magic */ xmlw_startElem(writer,"lua"); nxml_persistLua( ev->L, writer ); xmlw_endElem(writer); /* "lua" */ xmlw_endElem(writer); /* "event" */ } xmlw_endElem(writer); /* "events" */ return 0; }
/** * @brief Saves the player's active missions. * * @param writer XML Write to use to save missions. * @return 0 on success. */ int missions_saveActive( xmlTextWriterPtr writer ) { int i,j,n; int nitems; char **items; xmlw_startElem(writer,"missions"); for (i=0; i<MISSION_MAX; i++) { if (player_missions[i]->id != 0) { xmlw_startElem(writer,"mission"); /* data and id are attributes because they must be loaded first */ xmlw_attr(writer,"data","%s",player_missions[i]->data->name); xmlw_attr(writer,"id","%u",player_missions[i]->id); xmlw_elem(writer,"title","%s",player_missions[i]->title); xmlw_elem(writer,"desc","%s",player_missions[i]->desc); xmlw_elem(writer,"reward","%s",player_missions[i]->reward); /* Markers. */ xmlw_startElem( writer, "markers" ); if (player_missions[i]->markers != NULL) { n = array_size( player_missions[i]->markers ); for (j=0; j<n; j++) { xmlw_startElem(writer,"marker"); xmlw_attr(writer,"id","%d",player_missions[i]->markers[j].id); xmlw_attr(writer,"type","%d",player_missions[i]->markers[j].type); xmlw_str(writer,"%s", system_getIndex(player_missions[i]->markers[j].sys)->name); xmlw_endElem(writer); /* "marker" */ } } xmlw_endElem( writer ); /* "markers" */ /* Cargo */ xmlw_startElem(writer,"cargos"); for (j=0; j<player_missions[i]->ncargo; j++) xmlw_elem(writer,"cargo","%u", player_missions[i]->cargo[j]); xmlw_endElem(writer); /* "cargos" */ /* OSD. */ if (player_missions[i]->osd > 0) { xmlw_startElem(writer,"osd"); /* Save attributes. */ items = osd_getItems(player_missions[i]->osd, &nitems); xmlw_attr(writer,"title","%s",osd_getTitle(player_missions[i]->osd)); xmlw_attr(writer,"nitems","%d",nitems); xmlw_attr(writer,"active","%d",osd_getActive(player_missions[i]->osd)); /* Save messages. */ for (j=0; j<nitems; j++) xmlw_elem(writer,"msg","%s",items[j]); xmlw_endElem(writer); /* "osd" */ } /* Claims. */ xmlw_startElem(writer,"claims"); claim_xmlSave( writer, player_missions[i]->claims ); xmlw_endElem(writer); /* "claims" */ /* Write Lua magic */ xmlw_startElem(writer,"lua"); nxml_persistLua( player_missions[i]->L, writer ); xmlw_endElem(writer); /* "lua" */ xmlw_endElem(writer); /* "mission" */ } } xmlw_endElem(writer); /* "missions" */ return 0; }