Looking for help with a book I read maybe about 5 years ago in which humans and aliens that resemble an insect colony have been stranded on a world for hundreds of years (Not sure when it was written). Both species are stuck on the planet, and the alien hive is broken into two groups - one group that kills humans on sight, and another that is breeding humans as workers. Both hive groups are either waiting or looking for a queen.
Both humans and aliens are looking for the pieces of a 'key' that will allow them to access a ship in space. The protagonist is a young man who has one of the pieces I think, and early on he meets up with three other people, one of whom is a character called 'Cap' who was on the original ship that brought humans 300 years earlier, and who turns out to be the bad guy - killed the captain of the ship because he wanted to take over or something.
I do remember that towards the end of the book, the aliens find their queen, but she has been driven insane and murders all of them, or something like that.
Oh, and one of the weirdest parts of the book is that at the end, the protagonist and his love interest have to have sex in a control center of some kind in order to activate the key and unlock the computer/ship controls .... after which the bad guy is blown up in space by the ships laser. Talk about going out with a bang ...
Google searches with various combination of the above phrases reveal nothing, so hoping that someone can help - would like to read book again.
Thanks in advance!