Frustrated

So today was like the first frustrating day of this for sure. I ran into some shit with Rails associations that were really really tedious, and I’m a little angry about it, but I think I got to a good solution.

Some background basics of a 4X (at least ones set in Space), you send ships to star systems, where they either fight other ships, or land folks on the planet to grow a new Outpost, but at the same time, ships belonging to other players are also going about their business, and how do you know if you can see them or not? Star ships ostensibly all have sensors baked in, on the lookout for hostiles (or even allies…?) and new stars to expand our starcharts as we explore outward.

But here’s the deal. We have a database table full of Ships, another full of Stars, and another full of Empires. We need to know which other things those things are aware of, so we use what’s called a “join table” that connects the two.

For Ships, we have a radar_blips table, which connects Ship to itself because what are ships scanning for? Other ships.

RadarBlips have a Ship, and a Target(which is another ship). I have also included a field called “range” RadarBlip so as to avoid re-calculating the distance on every load, since Ships don’t move between Game Updates. The naming and dereferencing of these things in the code gets complicated though, and because of a quirk of rails associations, it’s hard to grab that range value at the same time as I’m grabbing the object representing the target/ship, and I spent approximately… the entire f*ing morning trying to do so.

The “Empires knowing about Stars” thing is a little bit simpler, since it’s two different database tables storing those objects, and the only bit of information we might need to know about about the state of the relationship is whether or not the Empire has actually been to the Star in question. Obviously here on earth we’ve recorded a whole lot of stars in the sky, but do we actually know what, if any, alien space ships are there? Decidedly not. So we keep track of “observed” v. “visited” for game purposes.

And for some reason (ADHD? Lack of sleep? Being a proficient Rails developer but not fully an expert?) the act of naming of this table gave me a shitload of trouble today… it needs to have a reasonable name, so the code communicates clearly to any hypothetical future employees, but Rails has some baked-in default conventions around then naming of these types of tables, and for some reason all this kinda broke my brain this morning.

Reminded me a little bit about a Twitter hashtag that made the rounds where Senior Engineers™ (whatever the f that even means) posted the random bullshit they didn’t know/didn’t understand/had to look up, to demonstrate for engineers just starting out that it’s definitely OK not to know everything about software, and to proactively Google/Stack Overflow when challenges arise. I composed the tweet in my head but didn’t end up posting:

I’ve been a Software Engineer for 20 years, and developing in Rails for 10. Today I learned what a “Proxy Association” is, and spent four hours grinding my gears on how to set it up, only to find out I STILL didn’t understand them, even after I thought I did.

Thank goodness Twitter increased their character limit to 240.

But! If you read this far and you’re not here for the Developer deep-dives, here’s the takeaway: I finally managed to finish implementing “fog of war” for User accounts, so they can discover the galaxy one bit at a time, and so a player’s ships will only reveal for them the other ships they can currently see, based to their sensor readings. Good stuff, and super important features of a 4X, as “Explore” is literally one of the Xs.

Leave a Comment

Your email address will not be published.