| 1797 | -------------------------------------------------------------------------------*/ |
| 1798 | |
| 1799 | Entity* findEntityInLine( Entity* my, real_t x1, real_t y1, real_t angle, int entities, Entity* target, list_t* entityListToUse) |
| 1800 | { |
| 1801 | Entity* result = NULL; |
| 1802 | node_t* node; |
| 1803 | real_t lowestDist = 9999; |
| 1804 | int quadrant = 0; |
| 1805 | |
| 1806 | while ( angle >= PI * 2 ) |
| 1807 | { |
| 1808 | angle -= PI * 2; |
| 1809 | } |
| 1810 | while ( angle < 0 ) |
| 1811 | { |
| 1812 | angle += PI * 2; |
| 1813 | } |
| 1814 | |
| 1815 | if ( !my ) |
| 1816 | { |
| 1817 | return nullptr; |
| 1818 | } |
| 1819 | int originx = static_cast<int>(my->x) >> 4; |
| 1820 | int originy = static_cast<int>(my->y) >> 4; |
| 1821 | std::vector<list_t*> entLists; // stores the possible entities to look through depending on the quadrant. |
| 1822 | // start search from 1 tile behind facing direction in x/y position, extending to the edge of the map in the facing direction. |
| 1823 | |
| 1824 | if ( multiplayer == CLIENT ) |
| 1825 | { |
| 1826 | entLists.push_back(map.entities); // default to old map.entities if client (if they ever call this function...) |
| 1827 | } |
| 1828 | |
| 1829 | Stat* myStats = my->getStats(); |
| 1830 | |
| 1831 | if ( angle >= PI / 2 && angle < PI ) // -x, +y |
| 1832 | { |
| 1833 | quadrant = 1; |
| 1834 | /*messagePlayer(0, "drawing from x: %d - %d, y: %d- %d", |
| 1835 | 0, std::min(static_cast<int>(map.width) - 1, originx + 1), |
| 1836 | std::max(0, originy - 1), map.height - 1);*/ |
| 1837 | |
| 1838 | if ( multiplayer != CLIENT ) |
| 1839 | { |
| 1840 | for ( int ix = std::min(static_cast<int>(map.width) - 1, originx + 1); ix >= 0; --ix ) |
| 1841 | { |
| 1842 | for ( int iy = std::max(0, originy - 1); iy < map.height; ++iy ) |
| 1843 | { |
| 1844 | entLists.push_back(&TileEntityList.gridEntities[ix][iy]); |
| 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | } |
| 1849 | else if ( angle >= 0 && angle < PI / 2 ) // +x, +y |
| 1850 | { |
| 1851 | quadrant = 2; |
| 1852 | /*messagePlayer(0, "drawing from x: %d - %d, y: %d- %d", |
| 1853 | std::max(0, originx - 1), map.width - 1, |
| 1854 | std::max(0, originy - 1), map.height - 1);*/ |
| 1855 | |
| 1856 | if ( multiplayer != CLIENT ) |
no test coverage detected