Welcome to the experience of working on any kind of moderately complicated project.
Something I've found, which can be kind of painful, is that I often come up with a prototype that has entirely un-salvageable code. Usually, the best thing to do at that point is start over and build again. Kind of like a 'second draft' in writing parlance.
But, before that, I take notes. A lot of notes. Mainly, I try to work out how to structure my code on the second go around.
What logic should be encapsulated as functions, should I transition those global vars into a dictionary or array, should this logic go into this group, can I make life simpler by using this third-party behavior, should I combine these objects into one object or make a family for them, etc, etc, ad infinitum...
C2 has an odd sort of curve, where it's very easy to build a prototype, but takes a lot of discipline to build a functional, efficient, and maintainable project, with enough comments and organization that you can make sense of it later on.
Here's three specific bits of advice I've found useful:
1. Functions. Use them wherever possible. They are more work to set up, but they make managing a complex project worlds easier. Plus, in many cases they are modular enough that you can reuse them across projects.
2. Groups. Use them. And decide on a way to name or sort them so that you can easily tell which are purely organizational (never activated/deactivated during the game) and which are being use programmatically.
3. Constant variables for logical values used in multiple places. Simple example: Global TRUE = 1, Global FALSE = 0. I like these because it makes code easier to read, takes advantage of C2's auto-change and auto-fill capability, and is more efficient and less error prone than using string comparators (though const strings can come in handy too...for example, as a reference to a function name).