project_files/frontlib/model/weapon.c
changeset 7271 5608ac657362
parent 7269 5b0aeef8ba2a
child 7275 15f722e0b96f
equal deleted inserted replaced
7269:5b0aeef8ba2a 7271:5608ac657362
    79 		}
    79 		}
    80 		free(list);
    80 		free(list);
    81 	}
    81 	}
    82 }
    82 }
    83 
    83 
       
    84 flib_weaponset *flib_weaponset_from_ammostring(const char *name, const char *ammostring) {
       
    85 	flib_weaponset *result = NULL;
       
    86 	if(!name || !ammostring) {
       
    87 		flib_log_e("null parameter in flib_weaponset_from_ammostring");
       
    88 	} else {
       
    89 		result = flib_weaponset_create(name);
       
    90 		if(result) {
       
    91 			int fieldlen = strlen(ammostring)/4;
       
    92 			setField(result->loadout, ammostring, fieldlen, false);
       
    93 			setField(result->crateprob, ammostring + fieldlen, fieldlen, true);
       
    94 			setField(result->delay, ammostring + 2*fieldlen, fieldlen, true);
       
    95 			setField(result->crateammo, ammostring + 3*fieldlen, fieldlen, true);
       
    96 		}
       
    97 	}
       
    98 	return result;
       
    99 }
       
   100 
    84 static int fillWeaponsetFromIni(flib_weaponsetlist *list, flib_ini *ini, int index) {
   101 static int fillWeaponsetFromIni(flib_weaponsetlist *list, flib_ini *ini, int index) {
    85 	int result = -1;
   102 	int result = -1;
    86 	char *keyname = flib_ini_get_keyname(ini, index);
   103 	char *keyname = flib_ini_get_keyname(ini, index);
    87 	char *decodedKeyname = flib_urldecode(keyname);
   104 	char *decodedKeyname = flib_urldecode(keyname);
    88 
   105 	char *ammostring = NULL;
    89 	if(decodedKeyname) {
   106 	if(decodedKeyname && !flib_ini_get_str(ini, &ammostring, keyname)) {
    90 		flib_weaponset *set = flib_weaponset_create(decodedKeyname);
   107 		flib_weaponset *set = flib_weaponset_from_ammostring(decodedKeyname, ammostring);
    91 		if(set) {
   108 		if(set) {
    92 			char *value = NULL;
   109 			result = flib_weaponsetlist_insert(list, set, list->weaponsetCount);
    93 			if(!flib_ini_get_str(ini, &value, keyname)) {
       
    94 				int fieldlen = strlen(value)/4;
       
    95 				setField(set->loadout, value, fieldlen, false);
       
    96 				setField(set->crateprob, value+1*fieldlen, fieldlen, true);
       
    97 				setField(set->delay, value+2*fieldlen, fieldlen, true);
       
    98 				setField(set->crateammo, value+3*fieldlen, fieldlen, true);
       
    99 				result = flib_weaponsetlist_insert(list, set, list->weaponsetCount);
       
   100 			}
       
   101 			free(value);
       
   102 		}
   110 		}
   103 		flib_weaponset_release(set);
   111 		flib_weaponset_release(set);
   104 	}
   112 	}
   105 
   113 	free(ammostring);
       
   114 	free(decodedKeyname);
   106 	free(keyname);
   115 	free(keyname);
   107 	free(decodedKeyname);
       
   108 	return result;
   116 	return result;
   109 }
   117 }
   110 
   118 
   111 static int fillWeaponsetsFromIni(flib_weaponsetlist *list, flib_ini *ini) {
   119 static int fillWeaponsetsFromIni(flib_weaponsetlist *list, flib_ini *ini) {
   112 	bool error = false;
   120 	bool error = false;