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 "Thing" sections in dehacked files
16 //
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 
21 #include "doomtype.h"
22 #include "m_misc.h"
23 
24 #include "deh_defs.h"
25 #include "deh_main.h"
26 #include "deh_mapping.h"
27 #include "deh_htic.h"
28 
29 #include "info.h"
30 
DEH_BEGIN_MAPPING(thing_mapping,mobjinfo_t)31 DEH_BEGIN_MAPPING(thing_mapping, mobjinfo_t)
32   DEH_MAPPING("ID #",                doomednum)
33   DEH_MAPPING("Initial frame",       spawnstate)
34   DEH_MAPPING("Hit points",          spawnhealth)
35   DEH_MAPPING("First moving frame",  seestate)
36   DEH_MAPPING("Alert sound",         seesound)
37   DEH_MAPPING("Reaction time",       reactiontime)
38   DEH_MAPPING("Attack sound",        attacksound)
39   DEH_MAPPING("Injury frame",        painstate)
40   DEH_MAPPING("Pain chance",         painchance)
41   DEH_MAPPING("Pain sound",          painsound)
42   DEH_MAPPING("Close attack frame",  meleestate)
43   DEH_MAPPING("Far attack frame",    missilestate)
44   DEH_MAPPING("Burning frame",       crashstate)
45   DEH_MAPPING("Death frame",         deathstate)
46   DEH_MAPPING("Exploding frame",     xdeathstate)
47   DEH_MAPPING("Death sound",         deathsound)
48   DEH_MAPPING("Speed",               speed)
49   DEH_MAPPING("Width",               radius)
50   DEH_MAPPING("Height",              height)
51   DEH_MAPPING("Mass",                mass)
52   DEH_MAPPING("Missile damage",      damage)
53   DEH_MAPPING("Action sound",        activesound)
54   DEH_MAPPING("Bits 1",              flags)
55   DEH_MAPPING("Bits 2",              flags2)
56 DEH_END_MAPPING
57 
58 static void *DEH_ThingStart(deh_context_t *context, char *line)
59 {
60     int orig_thing_number = 0, thing_number = 0;
61     mobjinfo_t *mobj;
62 
63     if (sscanf(line, "Thing %i", &orig_thing_number) != 1)
64     {
65         DEH_Warning(context, "Parse error on section start");
66         return NULL;
67     }
68 
69     // Translate to the correct thing number based on the exe version this
70     // patch was made for. Subtract one because HHE thing numbers are
71     // indexed from 1.
72 
73     thing_number = DEH_MapHereticThingType(orig_thing_number - 1);
74 
75     if (thing_number < 0 || thing_number >= DEH_HERETIC_NUMMOBJTYPES)
76     {
77         DEH_Warning(context, "Invalid thing number: %i", orig_thing_number);
78         return NULL;
79     }
80 
81     mobj = &mobjinfo[thing_number];
82 
83     return mobj;
84 }
85 
DEH_ThingParseLine(deh_context_t * context,char * line,void * tag)86 static void DEH_ThingParseLine(deh_context_t *context, char *line, void *tag)
87 {
88     mobjinfo_t *mobj;
89     char *variable_name, *value;
90     int ivalue;
91 
92     if (tag == NULL)
93        return;
94 
95     mobj = (mobjinfo_t *) tag;
96 
97     // Parse the assignment
98 
99     if (!DEH_ParseAssignment(line, &variable_name, &value))
100     {
101         // Failed to parse
102 
103         DEH_Warning(context, "Failed to parse assignment");
104         return;
105     }
106 
107     // all values are integers
108 
109     ivalue = atoi(value);
110 
111     // If the value to be set is a frame, the frame number must
112     // undergo transformation from a Heretic 1.0 index to a
113     // Heretic 1.3 index.
114 
115     if (M_StrCaseStr(variable_name, "frame") != NULL)
116     {
117         ivalue = DEH_MapHereticFrameNumber(ivalue);
118     }
119 
120     // Set the field value
121 
122     DEH_SetMapping(context, &thing_mapping, mobj, variable_name, ivalue);
123 }
124 
DEH_ThingSHA1Sum(sha1_context_t * context)125 static void DEH_ThingSHA1Sum(sha1_context_t *context)
126 {
127     int i;
128 
129     for (i=0; i<NUMMOBJTYPES; ++i)
130     {
131         DEH_StructSHA1Sum(context, &thing_mapping, &mobjinfo[i]);
132     }
133 }
134 
135 deh_section_t deh_section_thing =
136 {
137     "Thing",
138     NULL,
139     DEH_ThingStart,
140     DEH_ThingParseLine,
141     NULL,
142     DEH_ThingSHA1Sum,
143 };
144 
145