Gain is relative, so you have to understand the reference against which the gain is measured. Also, gain and antenna patterns tend to go hand in hand in that one affects the other.
Antenna gain is measured against a theoretical antenna referred to as an isotropic radiator. Imagine an antenna that consists of a single point which radiates equally in all directions. As a result, the antenna pattern is a sphere with the antenna, remember that it's a single point, at the center of the sphere. That's an isotropic radiator. But this is just theoretical--you can't really build an isotropic radiator.
The most basic antenna that you can build is a dipole which consists of two elements, each a quarter wavelength long, placed end to end and fed in the middle. If you oriented your dipole vertically and tested the antenna pattern, you'd find that it's a horizontal dough-nut with the antenna running through the center of the dough-nut. Remember the isotropic radiator? It's pattern is a sphere, but your dipole's pattern is a dough-nut. Because the pattern's different, your dipole antenna has gain, about 2.14 dBi, relative to the isotropic radiator. But you only get that gain in the horizontal plane of the dough-nut. If you measure from directly above or below the antenna, you'd find nearly zero gain. By changing the pattern, relative to the isotropic radiator, you have also gotten some gain, relative to the isotropic radiator.
Dipoles are not real practical for use on a vehicle, so quarter-wave antennas were developed. They only work if they have a suitable ground plane below the antenna. That's because your quarter-wave antenna's element becomes one element of the dipole and the ground plane becomes the other element. Your antenna pattern is now very similar to the dipole, but the dough-nut has been sliced horizontally by the ground plane. And your gain out at the edges of the dough-nut is the same as if you were using a dipole.
As you lengthen your quarter-wave vertical, you'll find a few more critical lengths where the antenna is resonant. Some of those resonant lengths are half-wave, 5/8's wave, and 3/4 wave. You can even stack resonant lengths end to end. (Note that each of those lengths typically require some sort of matching transformer in order to bring the feedpoint impedance in line with the 50 ohms that your antenna is expecting.) Each time you hit one of those resonant lengths, you'll find that your antenna has more gain. But you get that gain by flattening out the dough-nut.
So, your comment about lower gain antennas working better in hilly terrain has some theoretical merit. Imagine yourself at the bottom of a valley and the radio station or repeater you want to reach is at the top of a mountain next to the valley. If you had a high gain antenna, it's pattern will be flat out to the horizon. More of the energy from your radio will be radiated into the side of the mountain instead of up to the top of the mountain. If you had a low gain antenna, your pattern will be more like a puffed-out dough-nut which means more of the energy from your radio will reach the mountaintop.