* 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. */
| 1867 | * @return True if and only if the position of the unit is already occupied. |
| 1868 | */ |
| 1869 | bool 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. |
no test coverage detected