| 1 | /* |
| 2 | C-Dogs SDL |
| 3 | A port of the legendary (and fun) action/arcade cdogs. |
| 4 | Copyright (C) 1995 Ronny Wester |
| 5 | Copyright (C) 2003 Jeremy Chin |
| 6 | Copyright (C) 2003-2007 Lucas Martin-King |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | |
| 22 | This file incorporates work covered by the following copyright and |
| 23 | permission notice: |
| 24 | |
| 25 | Copyright (c) 2013-2015, 2018-2019, 2021 Cong Xu |
| 26 | All rights reserved. |
| 27 | |
| 28 | Redistribution and use in source and binary forms, with or without |
| 29 | modification, are permitted provided that the following conditions are met: |
| 30 | |
| 31 | Redistributions of source code must retain the above copyright notice, this |
| 32 | list of conditions and the following disclaimer. |
| 33 | Redistributions in binary form must reproduce the above copyright notice, |
| 34 | this list of conditions and the following disclaimer in the documentation |
| 35 | and/or other materials provided with the distribution. |
| 36 | |
| 37 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 38 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 39 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 40 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 41 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 42 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 43 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 44 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 45 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 46 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 47 | POSSIBILITY OF SUCH DAMAGE. |
| 48 | */ |
| 49 | #pragma once |
| 50 | |
| 51 | #include <json/json.h> |
| 52 | |
| 53 | #include "proto/msg.pb.h" |
| 54 | |
| 55 | #include "particle.h" |
| 56 | #include "sounds.h" |
| 57 | #include "tile.h" |
| 58 | |
| 59 | typedef struct |
| 60 | { |
| 61 | bool Hit; |
| 62 | char *Sound; |
| 63 | } HitProps; |
| 64 | |
| 65 | struct MobileObject; |
| 66 | typedef struct |
| 67 | { |
| 68 | char *Name; |
| 69 | CPic CPic; |
| 70 | struct |
| 71 | { |
| 72 | const ParticleClass *P; |
| 73 | float Width; |
| 74 | int TicksPerEmit; |
| 75 | } Trail; |
| 76 | struct vec2i ShadowSize; |
| 77 | int Delay; // number of frames before moving |
| 78 | float SpeedLow; |
| 79 | float SpeedHigh; |
| 80 | bool SpeedScale; // whether to scale X/Y speed based on perspective |
| 81 | float Friction; // Amount to subtract from velocity per tick |
| 82 | // -1 is infinite range |
| 83 | int RangeLow; |
| 84 | int RangeHigh; |
| 85 | int Power; |
| 86 | float Mass; |
| 87 | struct vec2i Size; |
| 88 | struct |
| 89 | { |
| 90 | special_damage_e Effect; |
| 91 | int Ticks; |
| 92 | } Special; |
| 93 | bool HurtAlways; |
| 94 | bool Persists; // remains even after hitting walls/items |
| 95 | const ParticleClass *Spark; |
| 96 | const ParticleClass *OutOfRangeSpark; |
| 97 | const ParticleClass *WallMark; |
| 98 | bool WallBounces; |
| 99 | struct |
| 100 | { |
| 101 | HitProps Object; |
| 102 | HitProps Flesh; |
| 103 | HitProps Wall; |
| 104 | // TODO: haven't defined what hit wall false means |
| 105 | } Hit; |
| 106 | struct |
| 107 | { |
| 108 | float GravityFactor; // 0 for non-falling bullets |
| 109 | bool FallsDown; // if false, DZ is never negative |
| 110 | bool DestroyOnDrop; |
| 111 | bool Bounces; |
| 112 | CArray DropGuns; // of const WeaponClass * |
| 113 | } Falling; |
| 114 | int SeekFactor; // -1 to disable; higher = less seeking |
| 115 | bool Erratic; |
| 116 | |
| 117 | // Special weapons to fire if certain events occur |
| 118 | CArray OutOfRangeGuns; // of const WeaponClass * |
| 119 | CArray HitGuns; // of const WeaponClass * |
| 120 | CArray ProximityGuns; // of const WeaponClass * |
| 121 | |
| 122 | // Temporary JSON object for two-step bullet loading |
| 123 | json_t *node; |
| 124 | } BulletClass; |
| 125 | typedef struct |
| 126 | { |
| 127 | CArray Classes; // of BulletClass |
| 128 | BulletClass Default; |
| 129 | CArray CustomClasses; // of BulletClass |
| 130 | json_t *root; |
| 131 | } BulletClasses; |
| 132 | extern BulletClasses gBulletClasses; |
| 133 | |
| 134 | int BulletClassesCount(const BulletClasses *classes); |
| 135 | |
| 136 | BulletClass *StrBulletClass(const char *s); |
| 137 | |
| 138 | void BulletInitialize(BulletClasses *bullets); |
| 139 | void BulletLoadJSON( |
| 140 | BulletClasses *bullets, CArray *classes, json_t *bulletNode); |
| 141 | // 2-step initialisation since bullet and weapon reference each other |
| 142 | void BulletLoadWeapons(BulletClasses *bullets); |
| 143 | void BulletClassesClear(CArray *classes); |
| 144 | void BulletTerminate(BulletClasses *bullets); |
| 145 | |
| 146 | void BulletAdd(const NAddBullet add); |
| 147 | void BulletDestroy(struct MobileObject *obj); |
| 148 | |
| 149 | bool BulletUpdate(struct MobileObject *obj, const int ticks); |
| 150 | void BulletBounce(const NBulletBounce bb); |
| 151 | |
| 152 | // Type of material that the bullet hit |
| 153 | typedef enum |
| 154 | { |
| 155 | HIT_NONE, |
| 156 | HIT_WALL, |
| 157 | HIT_OBJECT, |
| 158 | HIT_FLESH |
| 159 | } HitType; |
| 160 | void PlayHitSound(const BulletClass *b, const HitType t, const struct vec2 pos); |