The same people that pullled me into that game tried to get me into a new one, CivClicker. I think I’ve managed to avoid getting pulled in too far but not before noticing an issue and writing a user script to handle it, which I figured I’d share.

In the game there are several classes of job you can assign your people to. Six of them require there be enough space in a class of building to hold them. Ten soldiers for each barracks built, for example. The problem is that nothing shows how much space you have available, so you might intend to assign a bunch of soldiers only to be unable to and not realize why. My script provides that information.

In CivClicker there is a table of all of the job types. Each row has an ID matching the naming convention of <type>group. We create an array of the six types we care about, then we loop through the table rows. On the ones that match a name we’re looking for, we add a span to the sixth field (the one that shows how many you already have of that particular type). Through some string manipulation, we give that span the ID of <type>Available so we can reference it later.

// do the check every second
setInterval(function () {
update_availability();
}, 1000);

We set the update_availability() function to run every second. This means there can be some lag but I didn’t think this needed to run more often.

We see that update_availability() is what actually finds the number of each class that you can have, then subtracts what you already have and displays that in the spans we established earlier. I’d like to be able to get this down a little bit, we should be able to loop through each class, but since the game itself doesn’t have a list of all the classes available I didn’t bother to expand on that either. The prettify() function is from the game, however, as I figured I should display numbers the same way they do.