Debian Codegraph @

src/cdogs/map_build.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-2015, 2017-2023 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 "game_mode.h"
52 #include "map.h"
53 #include "mission.h"
54
55 typedef struct
56 {
57 Map *Map;
58 const Mission *mission;
59 GameMode mode;
60 const CharacterStore *characters;
61
62 // internal data structures to help build the map
63 CArray access; // of uint16_t
64 CArray tiles; // of TileClass
65 CArray leaveFree; // of bool
66 } MapBuilder;
67
68 void MapBuild(
69 Map *m, const Mission *mission, const bool loadDynamic, const int missionIndex, const GameMode mode, const CharacterStore *characters);
70 void MapBuilderInit(
71 MapBuilder *mb, Map *m, const Mission *mission, const GameMode mode, const CharacterStore *characters);
72 void MapBuilderTerminate(MapBuilder *mb);
73
74 void MapLoadDynamic(MapBuilder *mb);
75
76 uint16_t MapBuildGetAccess(const MapBuilder *mb, const struct vec2i pos);
77 void MapBuildSetAccess(MapBuilder *mb, struct vec2i pos, const uint16_t v);
78 const TileClass *MapBuilderGetTile(
79 const MapBuilder *mb, const struct vec2i pos);
80 void MapBuilderSetTile(MapBuilder *mb, struct vec2i pos, const TileClass *t);
81
82 // Mark a tile so that it is left free of other map objects
83 void MapBuilderSetLeaveFree(
84 MapBuilder *mb, const struct vec2i tile, const bool value);
85 bool MapBuilderIsLeaveFree(const MapBuilder *mb, const struct vec2i tile);
86
87 bool MapTryPlaceOneObject(
88 MapBuilder *mb, const struct vec2i v, const MapObject *mo,
89 const int extraFlags, const bool isStrictMode);
90 bool MapTryPlaceDestroyObject(
91 MapBuilder *mb, const Mission *m, const int objective, const struct vec2i pos, const bool strict);
92 void MapPlacePickup(
93 const PickupClass *p, const struct vec2 pos, const int flags);
94 // TODO: refactor
95 void MapPlaceCollectible(
96 const Mission *m, const int objective, const struct vec2 pos);
97 // TODO: refactor
98 void MapPlaceKey(
99 MapBuilder *mb, const struct vec2i tilePos, const int keyIndex);
100 bool MapPlaceRandomTile(
101 MapBuilder *mb, const PlacementAccessFlags paFlags,
102 bool (*tryPlaceFunc)(MapBuilder *, const struct vec2i, void *),
103 void *data);
104
105 bool MapIsAreaInside(
106 const Map *map, const struct vec2i pos, const struct vec2i size);
107 bool MapBuilderIsAreaFunc(
108 const MapBuilder *mb, const struct vec2i pos, const struct vec2i size,
109 bool (*func)(const MapBuilder *, const struct vec2i));
110 bool MapIsAreaClear(
111 const MapBuilder *mb, const struct vec2i pos, const struct vec2i size);
112 bool MapIsAreaClearOrRoom(
113 const MapBuilder *mb, const struct vec2i pos, const struct vec2i size);
114 bool MapIsAreaClearOrWall(
115 const MapBuilder *mb, struct vec2i pos, struct vec2i size);
116 bool MapGetRoomOverlapSize(
117 const MapBuilder *mb, const Rect2i r, uint16_t *overlapAccess);
118 bool MapIsLessThanTwoWallOverlaps(
119 const MapBuilder *mb, struct vec2i pos, struct vec2i size);
120 void MapFillRect(MapBuilder *mb, const Rect2i r, const TileClass *edge, const TileClass *fill);
121 struct vec2i MapGetRoomSize(const RoomParams r, const int doorMin);
122 void MapMakeRoom(
123 MapBuilder *mb, const struct vec2i pos, const struct vec2i size,
124 const bool walls, const TileClass *wall, const TileClass *room,
125 const bool removeInterRoomWalls);
126 void MapMakeRoomWalls(
127 MapBuilder *mb, const RoomParams r, const TileClass *wall, const Rect2i room);
128 bool MapTryBuildWall(
129 MapBuilder *mb, const bool isRoom, const int pad, const int wallLength,
130 const TileClass *wall, const Rect2i r);
131 void MapSetRoomAccessMask(
132 MapBuilder *mb, const Rect2i r, const uint16_t accessMask);
133 void MapSetRoomAccessMaskOverlap(
134 MapBuilder *mb, CArray *rooms, const uint16_t accessMask);
135 void MapPlaceDoors(
136 MapBuilder *mb, const Rect2i r, const bool hasDoors, const bool doors[4],
137 const int doorMin, const int doorMax, const uint16_t accessMask,
138 const bool randomPos,
139 const TileClass *door, const TileClass *floor);
140
141 void MapBuildTile(
142 MapBuilder *mb, const struct vec2i pos, const TileClass *tile);
143
144 uint16_t GenerateAccessMask(int *accessLevel);
145
146 void SetupWallTileClasses(Map *m, PicManager *pm, const TileClass *base);
147 void SetupFloorTileClasses(Map *m, PicManager *pm, const TileClass *base);
148 void SetupDoorTileClasses(Map *m, PicManager *pm, const TileClass *base);