| 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-2016, 2018-2019, 2021, 2025 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 "actors.h" |
| 52 | #include "bullet_class.h" |
| 53 | #include "map.h" |
| 54 | #include "pics.h" |
| 55 | #include "vector.h" |
| 56 | |
| 57 | // Bullet "height" |
| 58 | #define BULLET_Z 10 |
| 59 | |
| 60 | #define AMMO_SPAWNER_RESPAWN_TICKS (FPS_FRAMELIMIT * 30) |
| 61 | |
| 62 | #define SHOT_IMPULSE_FACTOR 0.04f |
| 63 | |
| 64 | typedef struct |
| 65 | { |
| 66 | int uid; |
| 67 | const MapObject *Class; |
| 68 | int Health; |
| 69 | int counter; |
| 70 | Thing thing; |
| 71 | Emitter damageSmoke; |
| 72 | bool isInUse; |
| 73 | } TObject; |
| 74 | |
| 75 | typedef struct MobileObject |
| 76 | { |
| 77 | int UID; |
| 78 | int ActorUID; // unique ID of actor that owns this object |
| 79 | // (prevent self collision) |
| 80 | const BulletClass *bulletClass; |
| 81 | float z; |
| 82 | float dz; |
| 83 | int count; |
| 84 | int range; |
| 85 | int flags; |
| 86 | Thing thing; |
| 87 | Emitter trail; |
| 88 | const WeaponClass *weapon; // Weapon that fired this |
| 89 | bool isInUse; |
| 90 | } TMobileObject; |
| 91 | typedef int (*MobObjUpdateFunc)(TMobileObject *, int); |
| 92 | extern CArray gMobObjs; // of TMobileObject |
| 93 | extern CArray gObjs; // of TObject |
| 94 | |
| 95 | bool CanHit( |
| 96 | const BulletClass *b, const int flags, const int uid, const Thing *target); |
| 97 | bool HasHitSound( |
| 98 | const ThingKind targetKind, const int targetUID, |
| 99 | const special_damage_e special, const bool allowFriendlyHitSound); |
| 100 | void Damage( |
| 101 | const struct vec2 hitVector, const BulletClass *bullet, |
| 102 | const WeaponClass *weapon, const int flags, const TActor *source, |
| 103 | const ThingKind targetKind, const int targetUID); |
| 104 | |
| 105 | void ObjsInit(void); |
| 106 | void ObjsTerminate(void); |
| 107 | int ObjsGetNextUID(void); |
| 108 | void ObjAdd(const NMapObjectAdd amo); |
| 109 | void ObjRemove(const NMapObjectRemove mor); |
| 110 | void ObjDestroy(TObject *o); |
| 111 | |
| 112 | // Check if this object is dangerous; i.e. on destruction will explode |
| 113 | bool ObjIsDangerous(const TObject *o); |
| 114 | |
| 115 | void UpdateObjects(const int ticks); |
| 116 | |
| 117 | TObject *ObjGetByUID(const int uid); |
| 118 | |
| 119 | void DamageObject(const NThingDamage d); |
| 120 | |
| 121 | void BulletToDamageEvent(const BulletClass *b, GameEvent *e); |
| 122 | |
| 123 | void UpdateMobileObjects(int ticks); |
| 124 | void MobObjsInit(void); |
| 125 | void MobObjsTerminate(void); |
| 126 | int MobObjsObjsGetNextUID(void); |
| 127 | TMobileObject *MobObjGetByUID(const int uid); |