[Change] Cleaned up some code.
This commit is contained in:
		
							parent
							
								
									2e65fb94a1
								
							
						
					
					
						commit
						6769b024b3
					
				
							
								
								
									
										6
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								TODO
									
									
									
									
									
								
							| @ -4,11 +4,11 @@ Vital: | |||||||
|     -- Interference |     -- Interference | ||||||
|     -- Asteroids. |     -- Asteroids. | ||||||
|   -- Real news. |   -- Real news. | ||||||
|  |   -- Event System. | ||||||
|  |     -- Like mission system, but they occur naturally/randomly. | ||||||
|  |     -- Has similar power to mission system. | ||||||
| 
 | 
 | ||||||
| Major: | Major: | ||||||
|   -- Event System. |  | ||||||
|     -- Like mission system, but they accur naturally/randomly. |  | ||||||
|     -- Had similar power to mission system |  | ||||||
|   -- Unique pilot system (besides mission uniques). |   -- Unique pilot system (besides mission uniques). | ||||||
|   -- Escorts available for hire. |   -- Escorts available for hire. | ||||||
| 	-- Nicer AI. | 	-- Nicer AI. | ||||||
|  | |||||||
| @ -23,6 +23,8 @@ | |||||||
| 
 | 
 | ||||||
| #define PLAYER_ALLY   70. /**< Above this, player is considered ally. */ | #define PLAYER_ALLY   70. /**< Above this, player is considered ally. */ | ||||||
| 
 | 
 | ||||||
|  | #define CHUNK_SIZE    32  /**< Size of chunk for allocation. */ | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * @struct Faction. |  * @struct Faction. | ||||||
|  * |  * | ||||||
| @ -53,15 +55,13 @@ static int faction_nstack = 0;          /**< Number of factions in the faction s | |||||||
| /* Static. */ | /* Static. */ | ||||||
| static int faction_isFaction(int f); | static int faction_isFaction(int f); | ||||||
| static void faction_sanitizePlayer(Faction* faction); | static void faction_sanitizePlayer(Faction* faction); | ||||||
| static Faction* faction_parse(xmlNodePtr parent); | static int  faction_parse(Faction* tmp, xmlNodePtr parent); | ||||||
| static void faction_parseSocial(xmlNodePtr parent); | static void faction_parseSocial(xmlNodePtr parent); | ||||||
| /* Extern. */ | /* Extern. */ | ||||||
| int pfaction_save(xmlTextWriterPtr writer); | int pfaction_save(xmlTextWriterPtr writer); | ||||||
| int pfaction_load(xmlNodePtr parent); | int pfaction_load(xmlNodePtr parent); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * @fn int faction_get(const char* name) |  | ||||||
|  * |  | ||||||
|  * @brief Get a faction ID by name. |  * @brief Get a faction ID by name. | ||||||
|  *    @param name Name of the faction to seek. |  *    @param name Name of the faction to seek. | ||||||
|  *    @return ID of the faction. |  *    @return ID of the faction. | ||||||
| @ -437,13 +437,13 @@ static int faction_isFaction(int f) { | |||||||
|  *    @param parent Parent node to extract faction from. |  *    @param parent Parent node to extract faction from. | ||||||
|  *    @return Faction created from parent node. |  *    @return Faction created from parent node. | ||||||
|  */ |  */ | ||||||
| static Faction* faction_parse(xmlNodePtr parent) { | static int faction_parse(Faction* tmp, xmlNodePtr parent) { | ||||||
|   xmlNodePtr node; |   xmlNodePtr node; | ||||||
|   int player; |   int player; | ||||||
|   Faction* tmp; |  | ||||||
|   char buf[PATH_MAX]; |   char buf[PATH_MAX]; | ||||||
| 
 | 
 | ||||||
|   tmp = CALLOC_L(Faction); |   /* Clear memory. */ | ||||||
|  |   memset(tmp, 0, sizeof(Faction)); | ||||||
| 
 | 
 | ||||||
|   tmp->name = xml_nodeProp(parent, "name"); |   tmp->name = xml_nodeProp(parent, "name"); | ||||||
|   if(tmp->name == NULL) |   if(tmp->name == NULL) | ||||||
| @ -470,7 +470,7 @@ static Faction* faction_parse(xmlNodePtr parent) { | |||||||
| 
 | 
 | ||||||
|   if(player == 0) WARN("Faction '%s' missing player tag", tmp->name); |   if(player == 0) WARN("Faction '%s' missing player tag", tmp->name); | ||||||
| 
 | 
 | ||||||
|   return tmp; |   return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Parse the social tidbits: Allies and enemies. */ | /* Parse the social tidbits: Allies and enemies. */ | ||||||
| @ -531,14 +531,13 @@ void factions_reset(void) { | |||||||
|  *    @return 0 on success. |  *    @return 0 on success. | ||||||
|  */ |  */ | ||||||
| int factions_load(void) { | int factions_load(void) { | ||||||
|  |   int mem; | ||||||
|   uint32_t bufsize; |   uint32_t bufsize; | ||||||
|   char* buf = pack_readfile(DATA, FACTION_DATA, &bufsize); |   char* buf = pack_readfile(DATA, FACTION_DATA, &bufsize); | ||||||
| 
 | 
 | ||||||
|   xmlNodePtr factions, node; |   xmlNodePtr factions, node; | ||||||
|   xmlDocPtr doc = xmlParseMemory(buf, bufsize); |   xmlDocPtr doc = xmlParseMemory(buf, bufsize); | ||||||
| 
 | 
 | ||||||
|   Faction* tmp = NULL; |  | ||||||
| 
 |  | ||||||
|   node = doc->xmlChildrenNode; /* Faction node. */ |   node = doc->xmlChildrenNode; /* Faction node. */ | ||||||
|   if(!xml_isNode(node, XML_FACTION_ID)) { |   if(!xml_isNode(node, XML_FACTION_ID)) { | ||||||
|     ERR("Malformed "FACTION_DATA" file: missing root element '"XML_FACTION_ID"'"); |     ERR("Malformed "FACTION_DATA" file: missing root element '"XML_FACTION_ID"'"); | ||||||
| @ -559,15 +558,24 @@ int factions_load(void) { | |||||||
| 
 | 
 | ||||||
|   /* First pass. */ |   /* First pass. */ | ||||||
|   node = factions; |   node = factions; | ||||||
|  |   mem = 0; | ||||||
|   do { |   do { | ||||||
|     if(xml_isNode(node, XML_FACTION_TAG)) { |     if(xml_isNode(node, XML_FACTION_TAG)) { | ||||||
|       tmp = faction_parse(node); |       /* See if stack needs to grow. */ | ||||||
|       faction_stack = realloc(faction_stack, sizeof(Faction)*(++faction_nstack)); |       faction_nstack++; | ||||||
|       memcpy(faction_stack + faction_nstack - 1, tmp, sizeof(Faction)); |       if(faction_nstack > mem) { | ||||||
|       free(tmp); |         mem += CHUNK_SIZE; | ||||||
|  |         faction_stack = realloc(faction_stack, sizeof(Faction)*mem); | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       /* Load faction. */ | ||||||
|  |       faction_parse(&faction_stack[faction_nstack-1], node); | ||||||
|     } |     } | ||||||
|   } while(xml_nextNode(node)); |   } while(xml_nextNode(node)); | ||||||
| 
 | 
 | ||||||
|  |   /* Shrink stack to minimum size. */ | ||||||
|  |   faction_stack = realloc(faction_stack, sizeof(Faction)*faction_nstack); | ||||||
|  | 
 | ||||||
|   /* Second pass - Set allies and enemies. */ |   /* Second pass - Set allies and enemies. */ | ||||||
|   node = factions; |   node = factions; | ||||||
|   do { |   do { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Allanis
						Allanis