MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / unitOpensDoor

Method unitOpensDoor

src/Battlescape/TileEngine.cpp:1797–1945  ·  view source on GitHub ↗

* Opens a door (if any) by rightclick, or by walking through it. The unit has to face in the right direction. * @param unit Unit. * @param rClick Whether the player right clicked. * @param dir Direction. * @return -1 there is no door, you can walk through; * 0 normal door opened, make a squeaky sound and you can walk through; * 1 ufo door is starting to open, make a whoosh sound, don't

Source from the content-addressed store, hash-verified

1795 * 5 would contravene fire reserve
1796 */
1797int TileEngine::unitOpensDoor(BattleUnit *unit, bool rClick, int dir)
1798{
1799 int door = -1;
1800 int TUCost = 0;
1801 int size = unit->getArmor()->getSize();
1802 int z = unit->getTile()->getTerrainLevel() < -12 ? 1 : 0; // if we're standing on stairs, check the tile above instead.
1803 if (size > 1 && rClick)
1804 return door;
1805 if (dir == -1)
1806 {
1807 dir = unit->getDirection();
1808 }
1809 for (int x = 0; x < size && door == -1; x++)
1810 {
1811 for (int y = 0; y < size && door == -1; y++)
1812 {
1813 std::vector<std::pair<Position, int> > checkPositions;
1814 Tile *tile = _save->getTile(unit->getPosition() + Position(x,y,z));
1815 if (!tile) continue;
1816
1817 switch (dir)
1818 {
1819 case 0: // north
1820 checkPositions.push_back(std::make_pair(Position(0, 0, 0), MapData::O_NORTHWALL)); // origin
1821 if (x != 0)
1822 {
1823 checkPositions.push_back(std::make_pair(Position(0, -1, 0), MapData::O_WESTWALL)); // one tile north
1824 }
1825 break;
1826 case 1: // north east
1827 checkPositions.push_back(std::make_pair(Position(0, 0, 0), MapData::O_NORTHWALL)); // origin
1828 checkPositions.push_back(std::make_pair(Position(1, -1, 0), MapData::O_WESTWALL)); // one tile north-east
1829 if (rClick)
1830 {
1831 checkPositions.push_back(std::make_pair(Position(1, 0, 0), MapData::O_WESTWALL)); // one tile east
1832 checkPositions.push_back(std::make_pair(Position(1, 0, 0), MapData::O_NORTHWALL)); // one tile east
1833 }
1834 break;
1835 case 2: // east
1836 checkPositions.push_back(std::make_pair(Position(1, 0, 0), MapData::O_WESTWALL)); // one tile east
1837 break;
1838 case 3: // south-east
1839 if (!y)
1840 checkPositions.push_back(std::make_pair(Position(1, 1, 0), MapData::O_WESTWALL)); // one tile south-east
1841 if (!x)
1842 checkPositions.push_back(std::make_pair(Position(1, 1, 0), MapData::O_NORTHWALL)); // one tile south-east
1843 if (rClick)
1844 {
1845 checkPositions.push_back(std::make_pair(Position(1, 0, 0), MapData::O_WESTWALL)); // one tile east
1846 checkPositions.push_back(std::make_pair(Position(0, 1, 0), MapData::O_NORTHWALL)); // one tile south
1847 }
1848 break;
1849 case 4: // south
1850 checkPositions.push_back(std::make_pair(Position(0, 1, 0), MapData::O_NORTHWALL)); // one tile south
1851 break;
1852 case 5: // south-west
1853 checkPositions.push_back(std::make_pair(Position(0, 0, 0), MapData::O_WESTWALL)); // origin
1854 checkPositions.push_back(std::make_pair(Position(-1, 1, 0), MapData::O_NORTHWALL)); // one tile south-west

Callers 2

thinkMethod · 0.80
initMethod · 0.80

Calls 15

openDoorMethod · 0.80
getReservedActionMethod · 0.80
getMovementTypeMethod · 0.80
checkReservedTUMethod · 0.80
spendTimeUnitsMethod · 0.80
getVisibleUnitsMethod · 0.80
PositionClass · 0.70
getSizeMethod · 0.45
getArmorMethod · 0.45
getTerrainLevelMethod · 0.45
getTileMethod · 0.45
getDirectionMethod · 0.45

Tested by

no test coverage detected