1 //
2 // Copyright(C) 2005-2014 Simon Howard
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 //
15 // Parses "Weapon" sections in dehacked files
16 //
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 
22 #include "doomtype.h"
23 
24 #include "d_items.h"
25 
26 #include "deh_defs.h"
27 #include "deh_main.h"
28 #include "deh_mapping.h"
29 
DEH_BEGIN_MAPPING(weapon_mapping,weaponinfo_t)30 DEH_BEGIN_MAPPING(weapon_mapping, weaponinfo_t)
31   DEH_MAPPING("Ammo type",        ammo)
32   DEH_MAPPING("Deselect frame",   upstate)
33   DEH_MAPPING("Select frame",     downstate)
34   DEH_MAPPING("Bobbing frame",    readystate)
35   DEH_MAPPING("Shooting frame",   atkstate)
36   DEH_MAPPING("Firing frame",     flashstate)
37 DEH_END_MAPPING
38 
39 static void *DEH_WeaponStart(deh_context_t *context, char *line)
40 {
41     int weapon_number = 0;
42 
43     if (sscanf(line, "Weapon %i", &weapon_number) != 1)
44     {
45         DEH_Warning(context, "Parse error on section start");
46         return NULL;
47     }
48 
49     if (weapon_number < 0 || weapon_number >= NUMWEAPONS)
50     {
51         DEH_Warning(context, "Invalid weapon number: %i", weapon_number);
52         return NULL;
53     }
54 
55     return &weaponinfo[weapon_number];
56 }
57 
DEH_WeaponParseLine(deh_context_t * context,char * line,void * tag)58 static void DEH_WeaponParseLine(deh_context_t *context, char *line, void *tag)
59 {
60     char *variable_name, *value;
61     weaponinfo_t *weapon;
62     int ivalue;
63 
64     if (tag == NULL)
65         return;
66 
67     weapon = (weaponinfo_t *) tag;
68 
69     if (!DEH_ParseAssignment(line, &variable_name, &value))
70     {
71         // Failed to parse
72 
73         DEH_Warning(context, "Failed to parse assignment");
74         return;
75     }
76 
77     ivalue = atoi(value);
78 
79     DEH_SetMapping(context, &weapon_mapping, weapon, variable_name, ivalue);
80 }
81 
DEH_WeaponSHA1Sum(sha1_context_t * context)82 static void DEH_WeaponSHA1Sum(sha1_context_t *context)
83 {
84     int i;
85 
86     for (i=0; i<NUMWEAPONS ;++i)
87     {
88         DEH_StructSHA1Sum(context, &weapon_mapping, &weaponinfo[i]);
89     }
90 }
91 
92 deh_section_t deh_section_weapon =
93 {
94     "Weapon",
95     NULL,
96     DEH_WeaponStart,
97     DEH_WeaponParseLine,
98     NULL,
99     DEH_WeaponSHA1Sum,
100 };
101 
102