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

Function Map_FindLocationTile

src/map.c:917–1016  ·  view source on GitHub ↗

* Find a tile close the a LocationID described position (North, Enemy Base, ..). * * @param locationID Value between 0 and 7 to indicate where the tile should be. * @param houseID The HouseID looking for a tile (to get an idea of Enemy Base). * @return The tile requested. */

Source from the content-addressed store, hash-verified

915 * @return The tile requested.
916 */
917uint16 Map_FindLocationTile(uint16 locationID, uint8 houseID)
918{
919 static const int16 mapBase[3] = {1, -2, -2};
920 const MapInfo *mapInfo = &g_mapInfos[g_scenario.mapScale];
921 const uint16 mapOffset = mapBase[g_scenario.mapScale];
922
923 uint16 ret = 0;
924
925 if (locationID == 6) { /* Enemy Base */
926 PoolFindStruct find;
927
928 find.houseID = HOUSE_INVALID;
929 find.index = 0xFFFF;
930 find.type = 0xFFFF;
931
932 /* Find the house of an enemy */
933 while (true) {
934 Structure *s;
935
936 s = Structure_Find(&find);
937 if (s == NULL) break;
938 if (s->o.type == STRUCTURE_SLAB_1x1 || s->o.type == STRUCTURE_SLAB_2x2 || s->o.type == STRUCTURE_WALL) continue;
939
940 if (s->o.houseID == houseID) continue;
941
942 houseID = s->o.houseID;
943 break;
944 }
945 }
946
947 while (ret == 0) {
948 switch (locationID) {
949 case 0: /* North */
950 ret = Tile_PackXY(mapInfo->minX + Tools_RandomLCG_Range(0, mapInfo->sizeX - 2), mapInfo->minY + mapOffset);
951 break;
952
953 case 1: /* East */
954 ret = Tile_PackXY(mapInfo->minX + mapInfo->sizeX - mapOffset, mapInfo->minY + Tools_RandomLCG_Range(0, mapInfo->sizeY - 2));
955 break;
956
957 case 2: /* South */
958 ret = Tile_PackXY(mapInfo->minX + Tools_RandomLCG_Range(0, mapInfo->sizeX - 2), mapInfo->minY + mapInfo->sizeY - mapOffset);
959 break;
960
961 case 3: /* West */
962 ret = Tile_PackXY(mapInfo->minX + mapOffset, mapInfo->minY + Tools_RandomLCG_Range(0, mapInfo->sizeY - 2));
963 break;
964
965 case 4: /* Air */
966 ret = Tile_PackXY(mapInfo->minX + Tools_RandomLCG_Range(0, mapInfo->sizeX), mapInfo->minY + Tools_RandomLCG_Range(0, mapInfo->sizeY));
967 if (houseID == g_playerHouseID && !Map_IsValidPosition(ret)) ret = 0;
968 break;
969
970 case 5: /* Visible */
971 ret = Tile_PackXY(Tile_GetPackedX(g_minimapPosition) + Tools_RandomLCG_Range(0, 14), Tile_GetPackedY(g_minimapPosition) + Tools_RandomLCG_Range(0, 9));
972 if (houseID == g_playerHouseID && !Map_IsValidPosition(ret)) ret = 0;
973 break;
974

Callers 3

GameLoop_HouseFunction · 0.85
Unit_CreateWrapperFunction · 0.85

Calls 6

Structure_FindFunction · 0.85
Tools_RandomLCG_RangeFunction · 0.85
Map_IsValidPositionFunction · 0.85
Tile_MoveByRandomFunction · 0.85
Unit_FindFunction · 0.85
Object_GetByPackedTileFunction · 0.85

Tested by

no test coverage detected