project_files/frontlib/model/weapon.c
changeset 7320 e704706008d4
parent 7316 f7b49b2c5d84
child 7497 7e1d72fc03c7
equal deleted inserted replaced
7318:a446eafcddeb 7320:e704706008d4
   103 	}
   103 	}
   104 
   104 
   105 	return result;
   105 	return result;
   106 }
   106 }
   107 
   107 
   108 static void flib_weaponsetlist_destroy(flib_weaponsetlist *list) {
   108 void flib_weaponsetlist_destroy(flib_weaponsetlist *list) {
   109 	if(list) {
   109 	if(list) {
   110 		for(int i=0; i<list->weaponsetCount; i++) {
   110 		for(int i=0; i<list->weaponsetCount; i++) {
   111 			flib_weaponset_release(list->weaponsets[i]);
   111 			flib_weaponset_release(list->weaponsets[i]);
   112 		}
   112 		}
   113 		free(list->weaponsets);
   113 		free(list->weaponsets);
   165 		if(!ini) {
   165 		if(!ini) {
   166 			flib_log_e("Missing file %s.", filename);
   166 			flib_log_e("Missing file %s.", filename);
   167 		} else if(flib_ini_enter_section(ini, "General")) {
   167 		} else if(flib_ini_enter_section(ini, "General")) {
   168 			flib_log_e("Missing section \"General\" in file %s.", filename);
   168 			flib_log_e("Missing section \"General\" in file %s.", filename);
   169 		} else {
   169 		} else {
   170 			flib_weaponsetlist *list = flib_weaponsetlist_create();
   170 			flib_weaponsetlist *tmpList = flib_weaponsetlist_create();
   171 			if(list) {
   171 			if(tmpList && !fillWeaponsetsFromIni(tmpList, ini)) {
   172 				if(!fillWeaponsetsFromIni(list, ini)) {
   172 				result = tmpList;
   173 					result = flib_weaponsetlist_retain(list);
   173 				tmpList = NULL;
   174 				}
   174 			}
   175 			}
   175 			flib_weaponsetlist_destroy(tmpList);
   176 			flib_weaponsetlist_release(list);
       
   177 		}
   176 		}
   178 		flib_ini_destroy(ini);
   177 		flib_ini_destroy(ini);
   179 	}
   178 	}
   180 	return result;
   179 	return result;
   181 }
   180 }
   218 	}
   217 	}
   219 	return result;
   218 	return result;
   220 }
   219 }
   221 
   220 
   222 flib_weaponsetlist *flib_weaponsetlist_create() {
   221 flib_weaponsetlist *flib_weaponsetlist_create() {
   223 	return flib_weaponsetlist_retain(flib_calloc(1, sizeof(flib_weaponsetlist)));
   222 	return flib_calloc(1, sizeof(flib_weaponsetlist));
   224 }
   223 }
   225 
   224 
   226 GENERATE_STATIC_LIST_INSERT(insertWeaponset, flib_weaponset*)
   225 GENERATE_STATIC_LIST_INSERT(insertWeaponset, flib_weaponset*)
   227 GENERATE_STATIC_LIST_DELETE(deleteWeaponset, flib_weaponset*)
   226 GENERATE_STATIC_LIST_DELETE(deleteWeaponset, flib_weaponset*)
   228 
   227 
   243 			return 0;
   242 			return 0;
   244 		}
   243 		}
   245 	}
   244 	}
   246 	return -1;
   245 	return -1;
   247 }
   246 }
   248 
       
   249 flib_weaponsetlist *flib_weaponsetlist_retain(flib_weaponsetlist *list) {
       
   250 	if(list) {
       
   251 		flib_retain(&list->_referenceCount, "flib_weaponsetlist");
       
   252 	}
       
   253 	return list;
       
   254 }
       
   255 
       
   256 void flib_weaponsetlist_release(flib_weaponsetlist *list) {
       
   257 	if(list && flib_release(&list->_referenceCount, "flib_weaponsetlist")) {
       
   258 		flib_weaponsetlist_destroy(list);
       
   259 	}
       
   260 }