Debian Codegraph @

src/cdogs/tile.c

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-2014, 2016-2020, 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 #include "tile.h"
50
51 #include "thing.h"
52 #include "triggers.h"
53
54 void DoorStateInit(DoorState *d, const bool isOpen)
55 {
56 d->Count = DOORSTATE_COUNT;
57 d->IsOpen = isOpen;
58 }
59
60 Tile TileNone(void)
61 {
62 Tile t;
63 TileInit(&t);
64 t.Class = &gTileNothing;
65 return t;
66 }
67 void TileInit(Tile *t)
68 {
69 memset(t, 0, sizeof *t);
70 CArrayInit(&t->triggers, sizeof(Trigger *));
71 CArrayInit(&t->things, sizeof(ThingId));
72 }
73 void TileDestroy(Tile *t)
74 {
75 CArrayTerminate(&t->triggers);
76 CArrayTerminate(&t->things);
77 }
78
79 void TileUpdate(Tile *t)
80 {
81 if (t->Door.Count > 0)
82 {
83 t->Door.Count--;
84 }
85 }
86
87 // t->ClassAlt->Name == NULL for nothing tiles
88 bool TileIsOpaque(const Tile *t)
89 {
90 return t != NULL && ((t->Class->Type == TILE_CLASS_DOOR && t->Door.Class &&
91 !t->Door.IsOpen && t->Door.Class->Name)
92 ? t->Door.Class->isOpaque
93 : t->Class->isOpaque);
94 }
95
96 bool TileIsShootable(const Tile *t)
97 {
98 return (t->Class->Type == TILE_CLASS_DOOR && t->Door.Class &&
99 !t->Door.IsOpen && t->Door.Class->Name)
100 ? t->Door.Class->shootable
101 : t->Class->shootable;
102 }
103
104 bool TileCanWalk(const Tile *t)
105 {
106 if (t == NULL)
107 {
108 return false;
109 }
110 return (t->Class->Type == TILE_CLASS_DOOR && t->Door.Class &&
111 !t->Door.IsOpen && t->Door.Class->Name)
112 ? t->Door.Class->canWalk
113 : t->Class->canWalk;
114 }
115
116 bool TileIsClear(const Tile *t)
117 {
118 if (t == NULL)
119 {
120 return false;
121 }
122 if (!TileCanWalk(t))
123 {
124 return false;
125 }
126 // Check if tile has no things on it, excluding particles and pickups
127 CA_FOREACH(const ThingId, tid, t->things)
128 if (tid->Kind != KIND_PARTICLE && tid->Kind != KIND_PICKUP)
129 return false;
130 CA_FOREACH_END()
131 return true;
132 }
133
134 bool TileHasCharacter(Tile *t)
135 {
136 CA_FOREACH(const ThingId, tid, t->things)
137 if (tid->Kind == KIND_CHARACTER)
138 {
139 return true;
140 }
141 CA_FOREACH_END()
142 return false;
143 }