| 759 | } |
| 760 | |
| 761 | void Map::ProcessPlayerPosition( |
| 762 | const Time current_time, |
| 763 | const EntityId player_monster_id, |
| 764 | MessagesSender& messages_sender ) |
| 765 | { |
| 766 | const auto player_it= monsters_.find( player_monster_id ); |
| 767 | PC_ASSERT( player_it != monsters_.end() ); |
| 768 | Player& player= static_cast<Player&>( *(player_it->second) ); |
| 769 | |
| 770 | const int player_x= static_cast<int>( std::floor( player.Position().x ) ); |
| 771 | const int player_y= static_cast<int>( std::floor( player.Position().y ) ); |
| 772 | if( player_x < 0 || player_y < 0 || |
| 773 | player_x >= int(MapData::c_map_size) || |
| 774 | player_y >= int(MapData::c_map_size) ) |
| 775 | return; |
| 776 | |
| 777 | // Process floors |
| 778 | for( int x= std::max( 0, int(player_x) - 2); x < std::min( int(MapData::c_map_size), int(player_x) + 2 ); x++ ) |
| 779 | for( int y= std::max( 0, int(player_y) - 2); y < std::min( int(MapData::c_map_size), int(player_y) + 2 ); y++ ) |
| 780 | { |
| 781 | // TODO - select correct player radius for floor collisions. |
| 782 | if( !CircleIntersectsWithSquare( |
| 783 | player.Position().xy(), GameConstants::player_radius, x, y ) ) |
| 784 | continue; |
| 785 | |
| 786 | for( const MapData::Link& link : map_data_->links ) |
| 787 | { |
| 788 | if( link.type == MapData::Link::Floor && link.x == x && link.y == y ) |
| 789 | TryActivateProcedure( link.proc_id, current_time, player, messages_sender ); |
| 790 | else if( link.type == MapData::Link::ReturnFloor && link.x == x && link.y == y ) |
| 791 | ReturnProcedure( link.proc_id, current_time ); |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | const m_Vec2 pos= player.Position().xy(); |
| 796 | const float z_bottom= player.Position().z; |
| 797 | const float z_top= player.Position().z + GameConstants::player_height; |
| 798 | |
| 799 | // Static walls links. |
| 800 | for( const MapData::Wall& wall : map_data_->static_walls ) |
| 801 | { |
| 802 | if( wall.vert_pos[0] == wall.vert_pos[1] ) |
| 803 | continue; |
| 804 | |
| 805 | const MapData::WallTextureDescription& tex= map_data_->walls_textures[ wall.texture_id ]; |
| 806 | if( tex.gso[0] ) |
| 807 | continue; |
| 808 | |
| 809 | m_Vec2 new_pos; |
| 810 | if( CollideCircleWithLineSegment( |
| 811 | wall.vert_pos[0], wall.vert_pos[1], |
| 812 | pos, GameConstants::player_interact_radius, |
| 813 | new_pos ) ) |
| 814 | { |
| 815 | ProcessElementLinks( |
| 816 | MapData::IndexElement::StaticWall, |
| 817 | &wall - map_data_->static_walls.data(), |
| 818 | [&]( const MapData::Link& link ) |
no test coverage detected