Debian Codegraph @

src/cdogs/map.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-2022 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 <stdbool.h>
52
53 #include "map_object.h"
54 #include "pic.h"
55 #include "thing.h"
56 #include "tile.h"
57 #include "triggers.h"
58 #include "vector.h"
59
60 // Values for internal map
61 typedef enum
62 {
63 MAP_FLOOR,
64 MAP_WALL,
65 MAP_DOOR,
66 MAP_ROOM,
67 MAP_NOTHING,
68 MAP_SQUARE
69 } IMapType;
70 const char *IMapTypeStr(IMapType t);
71 IMapType StrIMapType(const char *s);
72
73 #define MAP_ACCESS_RED 0x800
74 #define MAP_ACCESS_BLUE 0x400
75 #define MAP_ACCESS_GREEN 0x200
76 #define MAP_ACCESS_YELLOW 0x100
77
78 #define MAP_MASKACCESS 0xFF
79 #define MAP_ACCESSBITS 0x0F00
80
81 typedef struct
82 {
83 // Array of bools to set lines of sight
84 CArray LOS; // of bool
85
86 // Array of bools for tracking new tiles in line of sight, for delayed
87 // messaging
88 CArray Explored; // of bool
89 } LineOfSight;
90
91 typedef struct
92 {
93 Rect2i R;
94 int Mission;
95 bool Hidden;
96 } Exit;
97
98 typedef struct
99 {
100 map_t TileClasses;
101 CArray Tiles; // of Tile
102 struct vec2i Size;
103
104 LineOfSight LOS;
105 CArray access; // of uint16_t
106
107 CArray triggers; // of Trigger *; owner
108 int triggerId;
109
110 int tilesSeen;
111 int keyAccessCount;
112
113 struct vec2i start;
114 CArray exits; // of Exit
115
116 int NumExplorableTiles;
117 } Map;
118
119 extern Map gMap;
120
121 uint16_t GetAccessMask(const int k);
122
123 Tile *MapGetTile(const Map *map, const struct vec2i pos);
124 bool MapIsTileIn(const Map *map, const struct vec2i pos);
125 int MapIsTileInExit(const Map *map, const Thing *ti, const int exit);
126
127 // TODO: remove this function
128 uint16_t MapGetAccessLevel(const Map *map, const struct vec2i pos);
129 uint16_t AccessCodeToFlags(const uint16_t code);
130 bool MapHasLockedRooms(const Map *map);
131 bool MapPosIsInLockedRoom(const Map *map, const struct vec2 pos);
132 int MapGetDoorKeycardFlag(Map *map, struct vec2i pos);
133
134 // Return false if cannot move to new position
135 bool MapTryMoveThing(Map *map, Thing *t, const struct vec2 pos);
136 void MapRemoveThing(Map *map, Thing *t);
137
138 void MapTerminate(Map *map);
139 void MapInit(Map *map, const struct vec2i size);
140 void MapPrintDebug(const Map *m);
141 bool MapIsPosOKForPlayer(
142 const Map *map, const struct vec2 pos, const bool allowAllTiles);
143 bool MapIsTileAreaClear(
144 const Map *map, const struct vec2 pos, const struct vec2i size);
145 bool MapHasExits(const Map *m);
146 void MapShowExitArea(Map *map, const int i);
147 // Returns the center of the tile that's the middle of the exit area
148 struct vec2 MapGetExitPos(const Map *m, const int i);
149 struct vec2i MapGetRandomTile(const Map *map);
150 struct vec2 MapGetRandomPos(const Map *map);
151 bool MapPlaceRandomPos(
152 const Map *map, const PlacementAccessFlags paFlags,
153 bool (*tryPlaceFunc)(const Map *, const struct vec2, void *), void *data);
154
155 void MapMarkAsVisited(Map *map, struct vec2i pos);
156 void MapMarkAllAsVisited(Map *map);
157 int MapGetExploredPercentage(Map *map);
158 void MapUpdate(Map *map);
159
160 typedef bool (*TileSelectFunc)(Map *, struct vec2i);
161 // Find a tile around the start that satisfies a condition
162 struct vec2i MapSearchTileAround(
163 Map *map, struct vec2i start, TileSelectFunc func);
164 bool MapTileIsUnexplored(Map *map, struct vec2i tile);
165
166 // Map construction functions
167 struct vec2 MapGenerateFreePosition(Map *map, const struct vec2i size);
168
169 Trigger *MapNewTrigger(Map *map);