[Add] First commit of Lephisto save stuff.
This commit is contained in:
		
							parent
							
								
									c609780acc
								
							
						
					
					
						commit
						e5620f86eb
					
				
							
								
								
									
										55
									
								
								src/player.c
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								src/player.c
									
									
									
									
									
								
							| @ -138,9 +138,11 @@ static void rect_parse(const xmlNodePtr parent, | ||||
| static int gui_parse(const xmlNodePtr parent, const char* name); | ||||
| static void gui_renderPilot(const Pilot* p); | ||||
| static void gui_renderBar(const glColour* c, const Rect* r, const double w); | ||||
| static int player_saveShip(xmlTextWriterPtr writer, Pilot* ship, char* loc); | ||||
| // Externed.
 | ||||
| void player_dead(void); | ||||
| void player_destroyed(void); | ||||
| int player_save(xmlTextWriterPtr writer); | ||||
| 
 | ||||
| // Prompt player name.
 | ||||
| void player_new(void) { | ||||
| @ -1436,3 +1438,56 @@ int player_missionAlreadyDone(int id) { | ||||
|   return 0; | ||||
| } | ||||
| 
 | ||||
| // Save the player in a freaking xmlfile.
 | ||||
| int player_save(xmlTextWriterPtr writer) { | ||||
|   int i; | ||||
| 
 | ||||
|   xmlw_startElem(writer, "player"); | ||||
|   xmlw_attr(writer, "name", player_name); | ||||
| 
 | ||||
|   xmlw_elem(writer, "rating", "%d", player_crating); | ||||
|   xmlw_elem(writer, "scred", "%d", player->credits); | ||||
| 
 | ||||
|   player_saveShip(writer, player, NULL); // Current ship.
 | ||||
| 
 | ||||
|   xmlw_startElem(writer, "ships"); | ||||
|   for(i = 0; i < player_nstack; i++) | ||||
|     player_saveShip(writer, player_stack[i], player_lstack[i]); | ||||
|   xmlw_endElem(writer); // Ships.
 | ||||
| 
 | ||||
|   xmlw_endElem(writer); // Player.
 | ||||
| 
 | ||||
|   return 0; | ||||
| } | ||||
| 
 | ||||
| static int player_saveShip(xmlTextWriterPtr writer, Pilot* ship, char* loc) { | ||||
|   int i; | ||||
| 
 | ||||
|   xmlw_startElem(writer, "ship"); | ||||
|   xmlw_attr(writer, "name", ship->name); | ||||
| 
 | ||||
|   xmlw_elem(writer, "shipname", ship->ship->name); | ||||
|   xmlw_elem(writer, "location", loc); | ||||
| 
 | ||||
|   // Save the outfits.
 | ||||
|   xmlw_startElem(writer, "outfits"); | ||||
|   for(i = 0; i < ship->noutfits; i++) { | ||||
|     xmlw_elem(writer, "outfit", ship->outfits[i].outfit->name); | ||||
|     xmlw_attr(writer, "quantity", "%d", ship->outfits[i].quantity); | ||||
|   } | ||||
|   xmlw_endElem(writer); // Outfits.
 | ||||
| 
 | ||||
|   // Save the commodities.
 | ||||
|   xmlw_startElem(writer, "commodities"); | ||||
|   for(i = 0; i < ship->noutfits; i++) { | ||||
|     xmlw_elem(writer, "outfit", ship->commodities[i].commodity->name); | ||||
|     xmlw_attr(writer, "quantity", "%d", ship->commodities[i].quantity); | ||||
|     if(ship->commodities[i].id > 0) | ||||
|       xmlw_attr(writer, "id", "%d", ship->commodities[i].id); | ||||
|   } | ||||
|   xmlw_endElem(writer); // Commodities.
 | ||||
|   xmlw_endElem(writer); // Ship.
 | ||||
| 
 | ||||
|   return 0; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -33,7 +33,7 @@ | ||||
| 
 | ||||
| // Encompassing element.
 | ||||
| #define xmlw_startElem(w, str) \ | ||||
|   if(xmlTextWriterStartElement(w, str) < 0) { \ | ||||
|   if(xmlTextWriterStartElement(w, (xmlChar*)str) < 0) { \ | ||||
|     ERR("xmlw: Unable to create start element"); return -1; } | ||||
| 
 | ||||
| #define xmlw_endElem(w) \ | ||||
| @ -42,11 +42,11 @@ | ||||
| 
 | ||||
| // Other stuff.
 | ||||
| #define xmlw_elem(w, n, str, args...) \ | ||||
|   if(xmlTextWriteFormatElement(w, n, str, ## args) < 0) { \ | ||||
|   if(xmlTextWriterWriteFormatElement(w, (xmlChar*)n, str, ## args) < 0) { \ | ||||
|     ERR("xmlw: Unable to write format element"); return -1; } | ||||
| 
 | ||||
| #define xmlw_attr(w, str, val) \ | ||||
|   if(xmlTextWriteAttribute(w, str, val) < 0) { \ | ||||
| #define xmlw_attr(w, str, val...) \ | ||||
|   if(xmlTextWriterWriteFormatAttribute(w, (xmlChar*)str, ## val) < 0) { \ | ||||
|     ERR("xmlw: Unable to write element attribute"); return -1; } | ||||
| 
 | ||||
| // Document level.
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Allanis
						Allanis