Debian Codegraph @

src/cdogs/map_object.h

raw symbols SCIP
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-2019, 2021, 2024-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 "ammo.h"
52 #include "character.h"
53 #include "pic_manager.h"
54 #include "pickup_class.h"
55 #include <json/json.h>
56
57 typedef enum
58 {
59 PLACEMENT_NONE = 0,
60 PLACEMENT_OUTSIDE,
61 PLACEMENT_INSIDE,
62 PLACEMENT_NO_WALLS,
63 PLACEMENT_ONE_WALL,
64 PLACEMENT_ONE_OR_MORE_WALLS,
65 PLACEMENT_FREE_IN_FRONT,
66 PLACEMENT_ON_WALL,
67
68 PLACEMENT_COUNT
69 } PlacementFlags;
70 const char *PlacementFlagStr(const int i);
71
72 typedef enum
73 {
74 MAP_OBJECT_TYPE_NORMAL,
75 MAP_OBJECT_TYPE_PICKUP_SPAWNER,
76 MAP_OBJECT_TYPE_ACTOR_SPAWNER
77 } MapObjectType;
78
79 // Pickups to spawn when map objects are destroyed
80 typedef struct
81 {
82 PickupType Type;
83 double SpawnChance;
84 } MapObjectDestroySpawn;
85
86 // A static map object, taking up an entire tile
87 typedef struct
88 {
89 char *Name;
90 CPic Pic;
91 struct vec2i Offset;
92 struct
93 {
94 char *MO;
95 Mix_Chunk *Sound;
96 char *Bullet;
97 } Wreck;
98 struct vec2i Size;
99 struct vec2 PosOffset;
100 int Health;
101 // Guns that are fired when this map object is destroyed
102 // i.e. explosion on destruction
103 CArray DestroyGuns; // of const WeaponClass *
104 // Bit field composed of bits shifted by PlacementFlags
105 int Flags;
106 bool DrawBelow;
107 bool DrawAbove;
108 char *FootstepSound;
109 color_t FootprintMask;
110 MapObjectType Type;
111 union {
112 const PickupClass *PickupClass;
113 struct
114 {
115 int CharId;
116 int Counter;
117 } Character;
118 } u;
119 CArray DestroySpawn; // of MapObjectDestroySpawn
120 struct
121 {
122 char *ParticleClass;
123 float HealthThreshold; // Smoke if map object damaged below this ratio
124 float Z;
125 int Ticks;
126 } DamageSmoke;
127 } MapObject;
128 typedef struct
129 {
130 CArray Classes; // of MapObject
131 CArray CustomClasses; // of MapObject
132 // Names of special types of map objects; for editor support
133 // Reset on load
134 CArray Destructibles; // of char *
135 // Map objects that match "blood%d" - left over when actors die
136 CArray Bloods; // of char *
137 } MapObjects;
138 extern MapObjects gMapObjects;
139
140 MapObject *StrMapObject(const char *s);
141 // Legacy map objects, integer based
142 MapObject *IntMapObject(const int m);
143 // Get map object by index; used by editor
144 MapObject *IndexMapObject(const int i);
145 // Get index of destructible map object; used by editor
146 int DestructibleMapObjectIndex(const MapObject *mo);
147 const MapObject *GetRandomBloodPool(void);
148 int MapObjectGetFlags(const MapObject *mo);
149
150 void MapObjectsInit(
151 MapObjects *classes, const char *filename, const AmmoClasses *ammo,
152 const WeaponClasses *guns);
153 void MapObjectsLoadJSON(CArray *classes, json_t *root);
154 void MapObjectsLoadAmmoAndGunSpawners(
155 MapObjects *classes, const AmmoClasses *ammo, const WeaponClasses *guns,
156 const bool isCustom);
157 void MapObjectsClear(CArray *classes);
158 void MapObjectsTerminate(MapObjects *classes);
159 int MapObjectsCount(const MapObjects *classes);
160
161 const Pic *MapObjectGetPic(const MapObject *mo, struct vec2i *offset);
162
163 bool MapObjectIsTileOK(
164 const MapObject *obj, const Tile *tile, const Tile *tileAbove);
165 struct vec2 MapObjectGetPlacementPos(
166 const MapObject *mo, const struct vec2i tilePos);
167 bool MapObjectIsOnWall(const MapObject *mo);