Debian Codegraph @

src/cdogs/material.c

raw symbols SCIP
1 /*
2 C-Dogs SDL
3 A port of the legendary (and fun) action/arcade cdogs.
4 Copyright (c) 2021 Cong Xu
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12 Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
27 */
28 #include "material.h"
29
30 #include "objs.h"
31 #include "thing.h"
32
33 static bool IsTileFloor(const Tile *t)
34 {
35 return t != NULL && t->Class != NULL && t->Class->Type == TILE_CLASS_FLOOR;
36 }
37
38 void MatGetFootstepSound(const CharacterClass *c, const Tile *t, char *out)
39 {
40 if (c->Footsteps)
41 {
42 sprintf(out, "footsteps/%s", c->Footsteps);
43 return;
44 }
45
46 if (IsTileFloor(t) && t->Class->Style != NULL)
47 {
48 // Custom footstep sounds for objects that are stepped on
49 CA_FOREACH(const ThingId, tid, t->things)
50 if (tid->Kind == KIND_OBJECT)
51 {
52 const TObject *obj = CArrayGet(&gObjs, tid->Id);
53 if (obj && obj->Class->DrawBelow && obj->Class->FootstepSound)
54 {
55 strcpy(out, obj->Class->FootstepSound);
56 return;
57 }
58 }
59 CA_FOREACH_END()
60
61 // Determine material type based on tile
62 if (StrStartsWith(t->Class->Style, "checker") ||
63 StrStartsWith(t->Class->Style, "tile"))
64 {
65 strcpy(out, "footsteps/tile");
66 return;
67 }
68 if (StrStartsWith(t->Class->Style, "cobble"))
69 {
70 strcpy(out, "footsteps/gravel");
71 return;
72 }
73 if (StrStartsWith(t->Class->Style, "dirt"))
74 {
75 strcpy(out, "footsteps/grass");
76 return;
77 }
78 if (StrStartsWith(t->Class->Style, "grate"))
79 {
80 strcpy(out, "footsteps/metal");
81 return;
82 }
83 if (StrStartsWith(t->Class->Style, "water"))
84 {
85 strcpy(out, "footsteps/water");
86 return;
87 }
88 if (StrStartsWith(t->Class->Style, "wood"))
89 {
90 strcpy(out, "footsteps/wood");
91 return;
92 }
93 }
94
95 // Default footstep sound
96 strcpy(out, "footsteps/boots");
97 }
98
99 color_t MatGetFootprintMask(const Tile *t)
100 {
101 if (IsTileFloor(t))
102 {
103 // Custom footstep sounds for objects that are stepped on
104 CA_FOREACH(const ThingId, tid, t->things)
105 if (tid->Kind == KIND_OBJECT)
106 {
107 const TObject *obj = CArrayGet(&gObjs, tid->Id);
108 if (obj && obj->Class->DrawBelow)
109 {
110 // For blood pools, which could have a custom color based on
111 // the character
112 color_t mask = obj->Class->FootprintMask;
113 if (!ColorEquals(obj->thing.CPic.Mask, colorWhite))
114 {
115 mask = obj->thing.CPic.Mask;
116 const color_t darken = {33, 33, 33, 255};
117 mask = ColorMult(mask, darken);
118 }
119 if (mask.a != 0)
120 {
121 return mask;
122 }
123 }
124 }
125 CA_FOREACH_END()
126
127 // Determine material type based on tile
128 if (StrStartsWith(t->Class->Style, "water"))
129 {
130 color_t mask = colorBlack;
131 mask.a = 0x99;
132 return mask;
133 }
134 }
135 return colorTransparent;
136 }
137
138 BulletClass *MatGetDamageBullet(const Tile *t)
139 {
140 return IsTileFloor(t) ? StrBulletClass(t->Class->DamageBullet) : NULL;
141 }