Pikes can be useful, but they're not the be-all end-all of medieval weapons.
I mean, they kinda were. The end of the medieval era had, essentially, Tercios and various forms of cavalry. Only Italian condottieri really break for the mold by any great degree, and it is generally accepted that they lagged behind the rest of Europe as far as military technology goes.
Get close enough (using heavily armored infantry with heavy weapons that can smash the pikes aside or destroy them, for example)
If this is a reference to Zweihanders, they were generally a part of a pike unit and were there to break deadlocks between themselves and other pike units. If it isn't a reference to that, the issue becomes just how many pikes they can knock aside. If it's a ten-footer, then, sure, I can see them batting away the three or four pikes they need to to get at the front row of guys. But a 25-footer makes that sort of tactic impossible on a practical level, as you have to bat your way past up to eight pikes and thus you have to resort to your second point.
fight in the right terrain (like, say, a swamp, or jungle, like the area we're living in) and the long reach becomes a liability instead
Which is good if you are fighting on defense, as you get to decide where the battles take place and thus can avoid the plains or mountains which allow pikes to either maneuver well enough or remove the necessity of maneuver, but, then, that's an issue with every weapon and war. All melee war is about supply and maneuver. Guns simply remove a good degree of importance off of the second requirement.
Alas, I do believe we're getting off topic, slightly, so I will close with this. You can develop bayonets. If you use a plug bayonet (bearing further research), gunners will act as a regular melee unit against humans and other, non-tough units, but will act as militia against tougher units. This is an improvement, as it will reduce costs to recruit a gunner unit (as you no longer need to equip them with swords that they are not skilled in) as well as remove the disadvantage to melee rolls they currently have. It is a liability, as it will, like normal plug bayonets, remove the ability of gunners to participate in any upcoming fallback, retreat, or skirmish actions until the end of that battle. Further research will allow for the creation of ring, and then socket bayonets, which will be the final evolution. Ring bayonets will improve on plug bayonets by allowing for the gunner unit to still take part in the various ranged combats. Socket bayonets will improve upon ring bayonets by making the gunners regulars in all melee combat, no matter the enemy.
Researching ring bayonets can take place after the first combat action with plug bayonets.
Researching Socket bayonets can take place after handguns are refined to a yet-undecided degree.
Now then, would you guys like to continue on this argument or would you like for me to get back to writing up your combat?