Debian Codegraph @

src/cdogs/weapon_class.h

raw symbols SCIP
1 /*
2 C-Dogs SDL
3 A port of the legendary (and fun) action/arcade cdogs.
4 Copyright (c) 2013-2019, 2021-2024 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 #pragma once
29
30 #include "bullet_class.h"
31 #include "draw/char_sprites.h"
32
33 // WARNING: used for old-style maps, do not touch
34 typedef enum
35 {
36 GUN_KNIFE,
37 GUN_MG,
38 GUN_GRENADE,
39 GUN_FLAMER,
40 GUN_SHOTGUN,
41 GUN_POWERGUN,
42 GUN_FRAGGRENADE,
43 GUN_MOLOTOV,
44 GUN_SNIPER,
45 GUN_MINE,
46 GUN_DYNAMITE,
47 GUN_GASBOMB,
48 GUN_PETRIFY,
49 GUN_BROWN,
50 GUN_CONFUSEBOMB,
51 GUN_GASGUN,
52 GUN_PULSERIFLE,
53 GUN_HEATSEEKER,
54 GUN_COUNT
55 } gun_e;
56
57 typedef enum
58 {
59 GUNTYPE_NORMAL,
60 GUNTYPE_MELEE,
61 GUNTYPE_GRENADE,
62 GUNTYPE_MULTI,
63 GUNTYPE_COUNT
64 } GunType;
65
66 // Gun states
67 typedef enum
68 {
69 GUNSTATE_READY,
70 GUNSTATE_FIRING,
71 GUNSTATE_RECOIL,
72 GUNSTATE_COUNT
73 } gunstate_e;
74
75 typedef struct
76 {
77 const Pic *Icon;
78 GunType Type;
79 union {
80 struct
81 {
82 char *Sprites;
83 int Grips;
84 CArray Bullets; // of const BulletClass *
85 int AmmoId; // -1 if the gun does not consume ammo
86 int Cost; // Cost in score to fire weapon
87 int ReloadLead;
88 Mix_Chunk *Sound;
89 Mix_Chunk *ReloadSound;
90 int SoundLockLength;
91 float Recoil; // Random recoil for inaccurate weapons, in radians
92 struct
93 {
94 int Count; // Number of bullets in spread
95 float Width; // Width of individual spread, in radians
96 } Spread;
97 float AngleOffset;
98 int MuzzleHeight;
99 int ElevationLow;
100 int ElevationHigh;
101 const ParticleClass *MuzzleFlash;
102 const ParticleClass *Brass;
103 struct
104 {
105 int Amount; // Amount of screen shake to produce
106 bool CameraSubjectOnly; // Only shake if gun held by camera
107 // subject
108 } Shake;
109 bool Auto; // Auto melee
110 } Normal;
111 char *Guns[MAX_BARRELS];
112 } u;
113 char *name;
114 char *Description;
115 char *Prerequisite; // WeaponClass
116 int Lock;
117 Mix_Chunk *SwitchSound;
118 bool CanDrop; // whether this gun can be dropped to be picked up
119 char *DropGun; // Gun to drop if an actor with this gun dies
120 bool IsRealGun; // whether this gun can be used as is by players
121 int Price; // Price to purchase gun
122 int OverheatTicks; // Number of ticks required to overheat the barrel and start smoking
123 } WeaponClass;
124 typedef struct
125 {
126 CArray Guns; // of WeaponClass
127 CArray CustomGuns; // of WeaponClass
128 } WeaponClasses;
129
130 extern WeaponClasses gWeaponClasses;
131
132 const char *GunTypeStr(const GunType t);
133 void GunTypeGetSlotStartEnd(const GunType gt, int *start, int *end);
134
135 void WeaponClassesInitialize(WeaponClasses *wcs);
136 void WeaponClassesLoadJSON(WeaponClasses *wcs, CArray *classes, json_t *root);
137 void WeaponClassesClear(CArray *classes);
138 void WeaponClassesTerminate(WeaponClasses *wcs);
139 const WeaponClass *StrWeaponClass(const char *s);
140 WeaponClass *IdWeaponClass(const int i);
141 int WeaponClassId(const WeaponClass *wc);
142 struct vec2 WeaponClassGetBarrelMuzzleOffset(
143 const WeaponClass *wc, const CharSprites *cs, const int barrel,
144 direction_e dir, const gunstate_e state);
145 float WeaponClassGetMuzzleHeight(
146 const WeaponClass *wc, const gunstate_e state, const int barrel);
147
148 void WeaponClassFire(
149 const WeaponClass *wc, const struct vec2 pos, const float z,
150 const double radians, const int flags, const int actorUID,
151 const bool playSound, const bool isGun);
152 void WeaponClassAddBrass(
153 const WeaponClass *wc, const direction_e d, const struct vec2 pos);
154
155 float WeaponClassGetRange(const WeaponClass *wc);
156 bool WeaponClassHasMuzzle(const WeaponClass *wc);
157 bool WeaponClassIsHighDPS(const WeaponClass *wc);
158 bool WeaponClassIsLongRange(const WeaponClass *wc);
159 bool WeaponClassIsShortRange(const WeaponClass *wc);
160 bool WeaponClassCanShoot(const WeaponClass *wc);
161 int WeaponClassNumBarrels(const WeaponClass *wc);
162 const WeaponClass *WeaponClassGetBarrel(
163 const WeaponClass *wc, const int barrel);
164 const BulletClass *WeaponClassGetBullet(
165 const WeaponClass *wc, const int barrel);
166 const WeaponClass *WeaponClassGetPrerequisite(const WeaponClass *wc);
167 bool WeaponClassesAreRelated(const WeaponClass *wc1, const WeaponClass *wc2);
168 int WeaponClassFullPrice(const WeaponClass *wc);
169
170 #define WC_BARREL_ATTR(_wc, _attr, _barrel) \
171 ((_wc).Type == GUNTYPE_MULTI \
172 ? StrWeaponClass((_wc).u.Guns[_barrel])->u.Normal._attr \
173 : (_wc).u.Normal._attr)
174
175 // Initialise bullets and weapons in one go
176 void BulletAndWeaponInitialize(
177 BulletClasses *b, WeaponClasses *wcs, const char *bpath,
178 const char *gpath);