DEBUG_AI_WEAP =========================================================================== Parameter: - Returns: - Changes Globals: - ===========================================================================
| 201 | // Changes Globals: - |
| 202 | //=========================================================================== |
| 203 | weaponconfig_t *LoadWeaponConfig(char *filename) |
| 204 | { |
| 205 | int max_weaponinfo, max_projectileinfo; |
| 206 | token_t token; |
| 207 | char path[MAX_PATH]; |
| 208 | int i, j; |
| 209 | source_t *source; |
| 210 | weaponconfig_t *wc; |
| 211 | weaponinfo_t weaponinfo; |
| 212 | |
| 213 | max_weaponinfo = (int) LibVarValue("max_weaponinfo", "32"); |
| 214 | if (max_weaponinfo < 0) |
| 215 | { |
| 216 | botimport.Print(PRT_ERROR, "max_weaponinfo = %d\n", max_weaponinfo); |
| 217 | max_weaponinfo = 32; |
| 218 | LibVarSet("max_weaponinfo", "32"); |
| 219 | } //end if |
| 220 | max_projectileinfo = (int) LibVarValue("max_projectileinfo", "32"); |
| 221 | if (max_projectileinfo < 0) |
| 222 | { |
| 223 | botimport.Print(PRT_ERROR, "max_projectileinfo = %d\n", max_projectileinfo); |
| 224 | max_projectileinfo = 32; |
| 225 | LibVarSet("max_projectileinfo", "32"); |
| 226 | } //end if |
| 227 | strncpy(path, filename, MAX_PATH); |
| 228 | PC_SetBaseFolder(BOTFILESBASEFOLDER); |
| 229 | source = LoadSourceFile(path); |
| 230 | if (!source) |
| 231 | { |
| 232 | botimport.Print(PRT_ERROR, "counldn't load %s\n", path); |
| 233 | return NULL; |
| 234 | } //end if |
| 235 | //initialize weapon config |
| 236 | wc = (weaponconfig_t *) GetClearedHunkMemory(sizeof(weaponconfig_t) + |
| 237 | max_weaponinfo * sizeof(weaponinfo_t) + |
| 238 | max_projectileinfo * sizeof(projectileinfo_t)); |
| 239 | wc->weaponinfo = (weaponinfo_t *) ((char *) wc + sizeof(weaponconfig_t)); |
| 240 | wc->projectileinfo = (projectileinfo_t *) ((char *) wc->weaponinfo + |
| 241 | max_weaponinfo * sizeof(weaponinfo_t)); |
| 242 | wc->numweapons = max_weaponinfo; |
| 243 | wc->numprojectiles = 0; |
| 244 | //parse the source file |
| 245 | while(PC_ReadToken(source, &token)) |
| 246 | { |
| 247 | if (!strcmp(token.string, "weaponinfo")) |
| 248 | { |
| 249 | Com_Memset(&weaponinfo, 0, sizeof(weaponinfo_t)); |
| 250 | if (!ReadStructure(source, &weaponinfo_struct, (char *) &weaponinfo)) |
| 251 | { |
| 252 | FreeMemory(wc); |
| 253 | FreeSource(source); |
| 254 | return NULL; |
| 255 | } //end if |
| 256 | if (weaponinfo.number < 0 || weaponinfo.number >= max_weaponinfo) |
| 257 | { |
| 258 | botimport.Print(PRT_ERROR, "weapon info number %d out of range in %s\n", weaponinfo.number, path); |
| 259 | FreeMemory(wc); |
| 260 | FreeSource(source); |
no test coverage detected