On Earthquake Safety

A conversation on twitter today turned to earthquakes and earthquake safety. It’s a bit much of a topic to fit into tweets, so I thought I’d write a blog post about it.

1. The first rule of earthquake safety is you do not talk about earthquake safety run outside.

2. The second rule of earthquake safety is you DO NOT TALK ABOUT EARTHQUAKE SAFETY RUN OUTSIDE. Seriously. The type of motion in an earthquake is most likely to throw the roof off the building. Inside tends to be safer than the distance you would get running. Speaking of which…

3. Don’t run around. The ground is moving! It’s going to mess with your balance, just a bit. I’m told the best thing is to drop to your knees and…

4. Crawl under a table or desk or something of the sort. Your biggest risk is actually getting hit by objects falling from shelves.

5. Curl up like an armadillo, hold on to a leg of your cover with one hand, protect your neck with the other.

6. When it’s over, feel free to (carefully) go outside. Don’t drink tap water, turn off your gas, etc.

7. Turn on the news. They’ll probably be giving you good emergency info.

 

A few other notes:

If in an adobe building, cowering in a doorway is a good idea, that’s the strong point of the architecture. If not in an adobe building, stay out of the doorways, those are the weak parts of the architecture!

If you’ve read about the ‘triangle of life’, ignore it completely. The self-titled expert behind that doesn’t know what he’s talking about.

If you’re currently in a country without building codes (or that doesn’t adhere to them), it may be a good idea to ignore rules one and two. Those are predicated on a bit of standards in construction.

 

Links:

USGS FAQ

Red Cross Safety Sheet

Emergency Survival Program Safety Sheet

Converter Series: A Question of Structure

Since this is where I started defining it, I should explain the overall structure of my code at this stage.

Both CK2 and EU3 data are stored in their own classes. The top level ones are called CK2World and EU3World, respectively. Each will contain pointers to appropriate classes for titles, nations, provinces, characters, and whatever else is necessary. Pointers allow me to easily establish complex relationships among all the data (at this point, I already had a notion of the complexity of relationships just among the characters: everyone needs to know who their parents, children, spouses, lieges, and vassals are. At least).

The CK2 classes will generally know how to set all their own data if you give them the correct portion of the parsed save. Part of setting that data will be creating all instances of their sub-objects, and passing the correct part of the save to that piece, which will figure out its own details. It will be a straightforward application of object-oriented programming, and the structured nature of the save file will make it easy to determine all the right classes.

The EU3 classes will be a little more complex. It many cases, handing them a pointer to the corresponding CK2 items will be enough. But other cases will involve analyzing lots of data. It’s hard to plan too much in advance. What will be clever about the EU3 classes is each knows how to output itself. Part of that will involve telling any sub-structures to output themselves. So the overall structure of the EU3 classes will be defined by the structure of the outputted save (itself constrained by what EU3 will successfully input).

At this point, I create the EU3World class and program its output() function. This function just calls a temporary function (helpfully placed in temp.h and temp.cpp) that outputs the header that makes for a minimal working save. We’ll eventually have to figure out the details of this header, as it has all kinds of id numbers, but for now there’s no need. The main() function of the converter creates an instance of the EU3World class and tells it to output itself to a save.

And testing shows that we get a working save. A very boring working save:

Relevant repository links:
Output a minimal yet functional EU3 save

Converter Series: Stealing My Own Code (Useful Utilities) and Also Outputting Something Useful

I decided at this point to start borrowing some useful utilities. I started with a windows batch file that would build my whole project and put it in a zip file, ready for the users to enjoy. I had to edit a little to work with the new project (new names, things in slightly different places), but it was easy enough to do.

Then I added another batch file that would copy important data files during the build. The converter won’t run very well without those.

Then I added some automated test batch files. Those are clever, and there’s three that get called in order and repeatedly. But they allow me to test a whole bunch of saves at once, which is a time saver down the line. Of course, all I get at this point is a log file that tells me it’s parsing the save. But I’m setting myself up for future success.

After that, I spend some time on the forums writing up some instructions for potential volunteers. Someone’s uploaded a save for me to test with, so I put in the repository. And in the course of writing instructions for volunteers, I create the first of our data files, so I save that to the repository too.

One of the volunteers gets back with some useful analysis rather quickly. It seems you need very little to have an EU3 save that won’t crash the game. So I make the converter spit out what little we need (more on that next post). It’s still nothing terribly exciting, but we can see what we’re doing as we’re doing it.

Relevant repository links:
Automated build batch file
Copy data files on build
Automated Test and Build_and_Test batch files
Added Ostergotland save
Add initial province mapping with Iceland mapped

Converter Series: Errors and Kinda Starting Over

I half-hoped the problems with my repository would just go away, so I took the time to tell everyone on the forums what I was up to. But apparently time does not fix all errors, so I did some research. It seems that fixing my repository would involving opening a trouble ticket on SourceForge, waiting for them to diagnose things, and then roll back my repository to a time before it broke. Which would destroy my changes.

I hadn’t done much work yet, so I just deleted it and created a new one. But then I couldn’t log in correctly. So I deleted it and made a third. With the same result. So I deleted it and switched from SVN to Mercurial. The details between them aren’t important, but there’s a bit of a blurb about them here.

That completed, I took the copy of everything on my computer and put it in the repository. But I restarted the changelog so it’s numbers would match the repository numbers (kind of, Mecurial is complex that way). Back to work!

Relevant repository links:
Initial commit
Initial Parser

Converter Series: Stealing My Own Code (Parsing)

After getting the logger working, I stole some more interesting code from my old project: the save file parser.

Remember when I mentioned that C++’s lack of good string parsing would bring a near-impossiblity around? This is the issue. The save files have a pretty simple nested structure:

something =
{
   something_else
   another_thing
   more_things =
   {
      thing1
      thing2
   }
}

But C++ is not good at handling that kind of stuff. At least not without tons of specialized code that’s difficult to write well. Seriously. One of the scarier classes in a Computer Science major is the compiler class (well, depending on the university. MIT grads probably eat it for lunch, and many colleges likely don’t challenge their students that much), where you learn to write that code.

One of the cool things about C++, though, is that there are all kinds of useful tools and libraries that people write and freely share. Boost is a collection of such libraries, and Boost::Spirit is designed to handle this kind of work.

But it still requires lots of coding and clever rules. Fortunately, my old project had to parse these saves. And we had made many improvements to the parser over time. So, I just took the source and added it to this project, then had it parse a CK2 save game. It didn’t choke on the save, which means that it must be more-or-less the same format inside (I hadn’t looked yet, as they’re somewhere on the order of 50MB in size, which is a bit much to just examine by eye).

For the record, the code to parse everything is about 650 lines: 300 to parse it (not including all the code in Boost::Spirit, which is leaving out a lot), and 350 to put it in some kind of format we can play with. Much more complex than the logger. And to be honest, largely incomprehensible to me.

But when I go to check in this code, I get an error. It seems my repository has been corrupted.