MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Structure_ConnectWall

Function Structure_ConnectWall

src/structure.c:1136–1193  ·  view source on GitHub ↗

* Connect walls around the given position. * * @param position The packed position. * @param recurse Wether to recurse. * @return True if and only if a change happened. */

Source from the content-addressed store, hash-verified

1134 * @return True if and only if a change happened.
1135 */
1136bool Structure_ConnectWall(uint16 position, bool recurse)
1137{
1138 static const uint8 wall[] = {
1139 0, 3, 1, 2, 3, 3, 4, 5, 1, 6, 1, 7, 8, 9, 10, 11,
1140 1, 12, 1, 19, 1, 16, 1, 31, 1, 28, 1, 52, 1, 45, 1, 59,
1141 3, 3, 13, 20, 3, 3, 22, 32, 3, 3, 13, 53, 3, 3, 38, 60,
1142 5, 6, 7, 21, 5, 6, 7, 33, 5, 6, 7, 54, 5, 6, 7, 61,
1143 9, 9, 9, 9, 17, 17, 23, 34, 9, 9, 9, 9, 25, 46, 39, 62,
1144 11, 12, 11, 12, 13, 18, 13, 35, 11, 12, 11, 12, 13, 47, 13, 63,
1145 15, 15, 16, 16, 17, 17, 24, 36, 15, 15, 16, 16, 17, 17, 40, 64,
1146 19, 20, 21, 22, 23, 24, 25, 37, 19, 20, 21, 22, 23, 24, 25, 65,
1147 27, 27, 27, 27, 27, 27, 27, 27, 14, 29, 14, 55, 26, 48, 41, 66,
1148 29, 30, 29, 30, 29, 30, 29, 30, 31, 30, 31, 56, 31, 49, 31, 67,
1149 33, 33, 34, 34, 33, 33, 34, 34, 35, 35, 15, 57, 35, 35, 42, 68,
1150 37, 38, 39, 40, 37, 38, 39, 40, 41, 42, 43, 58, 41, 42, 43, 69,
1151 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 27, 50, 43, 70,
1152 49, 50, 49, 50, 51, 52, 51, 52, 53, 54, 53, 54, 55, 51, 55, 71,
1153 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 63, 63, 44, 72,
1154 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 73
1155 };
1156
1157 uint16 bits = 0;
1158 uint16 tileID;
1159 bool isDestroyedWall;
1160 uint8 i;
1161 Tile *tile;
1162
1163 isDestroyedWall = Map_GetLandscapeType(position) == LST_DESTROYED_WALL;
1164
1165 for (i = 0; i < 4; i++) {
1166 const uint16 curPos = position + g_table_mapDiff[i];
1167
1168 if (recurse && Map_GetLandscapeType(curPos) == LST_WALL) Structure_ConnectWall(curPos, false);
1169
1170 if (isDestroyedWall) continue;
1171
1172 switch (Map_GetLandscapeType(curPos)) {
1173 case LST_DESTROYED_WALL: bits |= (1 << (i + 4));
1174 /* FALL-THROUGH */
1175 case LST_WALL: bits |= (1 << i);
1176 /* FALL-THROUGH */
1177 default: break;
1178 }
1179 }
1180
1181 if (isDestroyedWall) return false;
1182
1183 tileID = g_wallTileID + wall[bits] + 1;
1184
1185 tile = &g_map[position];
1186 if (tile->groundTileID == tileID) return false;
1187
1188 tile->groundTileID = tileID;
1189 g_mapTileID[position] |= 0x8000;
1190 Map_Update(position, 0, false);
1191
1192 return true;
1193}

Callers 2

Structure_PlaceFunction · 0.85
Map_UpdateWallFunction · 0.85

Calls 2

Map_GetLandscapeTypeFunction · 0.85
Map_UpdateFunction · 0.85

Tested by

no test coverage detected