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

Function Unit_IsTileOccupied

src/unit.c:1869–1894  ·  view source on GitHub ↗

* Check if the position the unit is on is already occupied. * * @param unit The Unit to operate on. * @return True if and only if the position of the unit is already occupied. */

Source from the content-addressed store, hash-verified

1867 * @return True if and only if the position of the unit is already occupied.
1868 */
1869bool Unit_IsTileOccupied(Unit *unit)
1870{
1871 const UnitInfo *ui;
1872 uint16 packed;
1873 Unit *unit2;
1874 uint16 speed;
1875
1876 if (unit == NULL) return true;
1877
1878 ui = &g_table_unitInfo[unit->o.type];
1879 packed = Tile_PackTile(unit->o.position);
1880
1881 speed = g_table_landscapeInfo[Map_GetLandscapeType(packed)].movementSpeed[ui->movementType];
1882 if (speed == 0) return true;
1883
1884 if (unit->o.type == UNIT_SANDWORM || ui->movementType == MOVEMENT_WINGER) return false;
1885
1886 unit2 = Unit_Get_ByPackedTile(packed);
1887 if (unit2 != NULL && unit2 != unit) {
1888 if (House_AreAllied(Unit_GetHouseID(unit2), Unit_GetHouseID(unit))) return true;
1889 if (ui->movementType != MOVEMENT_TRACKED) return true;
1890 if (g_table_unitInfo[unit2->o.type].movementType != MOVEMENT_FOOT) return true;
1891 }
1892
1893 return (Structure_Get_ByPackedTile(packed) != NULL);
1894}
1895
1896/**
1897 * Set the speed of a Unit.

Callers 3

Unit_CreateFunction · 0.85
Unit_SetPositionFunction · 0.85

Calls 5

Map_GetLandscapeTypeFunction · 0.85
Unit_Get_ByPackedTileFunction · 0.85
House_AreAlliedFunction · 0.85
Unit_GetHouseIDFunction · 0.85

Tested by

no test coverage detected