1 /* 2 C-Dogs SDL 3 A port of the legendary (and fun) action/arcade cdogs. 4 Copyright (c) 2013-2019, 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 #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_GRENADE, 61 GUNTYPE_MULTI 62 } GunType; 63 64 // Gun states 65 typedef enum 66 { 67 GUNSTATE_READY, 68 GUNSTATE_FIRING, 69 GUNSTATE_RECOIL, 70 GUNSTATE_COUNT 71 } gunstate_e; 72 73 typedef struct 74 { 75 const Pic *Icon; 76 GunType Type; 77 union { 78 struct 79 { 80 char *Sprites; 81 int Grips; 82 CArray Bullets; // of const BulletClass * 83 int AmmoId; // -1 if the gun does not consume ammo 84 int Cost; // Cost in score to fire weapon 85 int ReloadLead; 86 Mix_Chunk *Sound; 87 Mix_Chunk *ReloadSound; 88 int SoundLockLength; 89 float Recoil; // Random recoil for inaccurate weapons, in radians 90 struct 91 { 92 int Count; // Number of bullets in spread 93 float Width; // Width of individual spread, in radians 94 } Spread; 95 float AngleOffset; 96 int MuzzleHeight; 97 int ElevationLow; 98 int ElevationHigh; 99 const ParticleClass *MuzzleFlash; 100 const ParticleClass *Brass; 101 bool CanShoot; 102 struct 103 { 104 int Amount; // Amount of screen shake to produce 105 bool CameraSubjectOnly; // Only shake if gun held by camera 106 // subject 107 } Shake; 108 } Normal; 109 char *Guns[MAX_BARRELS]; 110 } u; 111 char *name; 112 char *Description; 113 int Lock; 114 Mix_Chunk *SwitchSound; 115 bool CanDrop; // whether this gun can be dropped to be picked up 116 char *DropGun; // Gun to drop if an actor with this gun dies 117 bool IsRealGun; // whether this gun can be used as is by players 118 } WeaponClass; 119 typedef struct 120 { 121 CArray Guns; // of WeaponClass 122 CArray CustomGuns; // of WeaponClass 123 } WeaponClasses; 124 125 extern WeaponClasses gWeaponClasses; 126 127 void WeaponClassesInitialize(WeaponClasses *wcs); 128 void WeaponClassesLoadJSON(WeaponClasses *wcs, CArray *classes, json_t *root); 129 void WeaponClassesClear(CArray *classes); 130 void WeaponClassesTerminate(WeaponClasses *wcs); 131 const WeaponClass *StrWeaponClass(const char *s); 132 WeaponClass *IdWeaponClass(const int i); 133 int WeaponClassId(const WeaponClass *wc); 134 struct vec2 WeaponClassGetBarrelMuzzleOffset( 135 const WeaponClass *wc, const CharSprites *cs, const int barrel, 136 direction_e dir, const gunstate_e state); 137 float WeaponClassGetMuzzleHeight( 138 const WeaponClass *wc, const gunstate_e state, const int barrel); 139 140 void WeaponClassFire( 141 const WeaponClass *wc, const struct vec2 pos, const float z, 142 const double radians, const int flags, const int actorUID, 143 const bool playSound, const bool isGun); 144 void WeaponClassAddBrass( 145 const WeaponClass *wc, const direction_e d, const struct vec2 pos); 146 147 float WeaponClassGetRange(const WeaponClass *wc); 148 bool WeaponClassHasMuzzle(const WeaponClass *wc); 149 bool WeaponClassIsHighDPS(const WeaponClass *wc); 150 bool WeaponClassIsLongRange(const WeaponClass *wc); 151 bool WeaponClassIsShortRange(const WeaponClass *wc); 152 bool WeaponClassCanShoot(const WeaponClass *wc); 153 int WeaponClassNumBarrels(const WeaponClass *wc); 154 const WeaponClass *WeaponClassGetBarrel( 155 const WeaponClass *wc, const int barrel); 156 const BulletClass *WeaponClassGetBullet( 157 const WeaponClass *wc, const int barrel); 158 159 #define WC_BARREL_ATTR(_wc, _attr, _barrel) \ 160 ((_wc).Type == GUNTYPE_MULTI \ 161 ? StrWeaponClass((_wc).u.Guns[_barrel])->u.Normal._attr \ 162 : (_wc).u.Normal._attr) 163 164 // Initialise bullets and weapons in one go 165 void BulletAndWeaponInitialize( 166 BulletClasses *b, WeaponClasses *wcs, const char *bpath, 167 const char *gpath); 168