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 
23 #include "deh_defs.h"
24 #include "deh_main.h"
25 #include "deh_mapping.h"
26 
27 #include "info.h"
28 
DEH_BEGIN_MAPPING(thing_mapping,mobjinfo_t)29 DEH_BEGIN_MAPPING(thing_mapping, mobjinfo_t)
30   DEH_MAPPING("ID #",                doomednum)
31   DEH_MAPPING("Initial frame",       spawnstate)
32   DEH_MAPPING("Hit points",          spawnhealth)
33   DEH_MAPPING("First moving frame",  seestate)
34   DEH_MAPPING("Alert sound",         seesound)
35   DEH_MAPPING("Reaction time",       reactiontime)
36   DEH_MAPPING("Attack sound",        attacksound)
37   DEH_MAPPING("Injury frame",        painstate)
38   DEH_MAPPING("Pain chance",         painchance)
39   DEH_MAPPING("Pain sound",          painsound)
40   DEH_MAPPING("Close attack frame",  meleestate)
41   DEH_MAPPING("Far attack frame",    missilestate)
42   DEH_MAPPING("Death frame",         deathstate)
43   DEH_MAPPING("Exploding frame",     xdeathstate)
44   DEH_MAPPING("Death sound",         deathsound)
45   DEH_MAPPING("Speed",               speed)
46   DEH_MAPPING("Width",               radius)
47   DEH_MAPPING("Height",              height)
48   DEH_MAPPING("Mass",                mass)
49   DEH_MAPPING("Missile damage",      damage)
50   DEH_MAPPING("Action sound",        activesound)
51   DEH_MAPPING("Bits",                flags)
52   DEH_MAPPING("Respawn frame",       raisestate)
53 DEH_END_MAPPING
54 
55 static void *DEH_ThingStart(deh_context_t *context, char *line)
56 {
57     int thing_number = 0;
58     mobjinfo_t *mobj;
59 
60     if (sscanf(line, "Thing %i", &thing_number) != 1)
61     {
62         DEH_Warning(context, "Parse error on section start");
63         return NULL;
64     }
65 
66     // dehacked files are indexed from 1
67     --thing_number;
68 
69     if (thing_number < 0 || thing_number >= NUMMOBJTYPES)
70     {
71         DEH_Warning(context, "Invalid thing number: %i", thing_number);
72         return NULL;
73     }
74 
75     mobj = &mobjinfo[thing_number];
76 
77     return mobj;
78 }
79 
DEH_ThingParseLine(deh_context_t * context,char * line,void * tag)80 static void DEH_ThingParseLine(deh_context_t *context, char *line, void *tag)
81 {
82     mobjinfo_t *mobj;
83     char *variable_name, *value;
84     int ivalue;
85 
86     if (tag == NULL)
87        return;
88 
89     mobj = (mobjinfo_t *) tag;
90 
91     // Parse the assignment
92 
93     if (!DEH_ParseAssignment(line, &variable_name, &value))
94     {
95         // Failed to parse
96 
97         DEH_Warning(context, "Failed to parse assignment");
98         return;
99     }
100 
101 //    printf("Set %s to %s for mobj\n", variable_name, value);
102 
103     // all values are integers
104 
105     ivalue = atoi(value);
106 
107     // Set the field value
108 
109     DEH_SetMapping(context, &thing_mapping, mobj, variable_name, ivalue);
110 }
111 
DEH_ThingSHA1Sum(sha1_context_t * context)112 static void DEH_ThingSHA1Sum(sha1_context_t *context)
113 {
114     int i;
115 
116     for (i=0; i<NUMMOBJTYPES; ++i)
117     {
118         DEH_StructSHA1Sum(context, &thing_mapping, &mobjinfo[i]);
119     }
120 }
121 
122 deh_section_t deh_section_thing =
123 {
124     "Thing",
125     NULL,
126     DEH_ThingStart,
127     DEH_ThingParseLine,
128     NULL,
129     DEH_ThingSHA1Sum,
130 };
131 
132