Condition Triggers Done, Trying JSON Format

Hey Folks! Hope everyone had a good weekend. Our Canadian Thanksgiving was sort of a fizzle. Our dinner plans fell through, and our back-up plan was closed for the holidays. Rochelle at least made a pumpkin pie, but then the local store was out of whipping cream. So we just bought ice cream and went to town on pie and ice cream. Still kinda missed our turkey, but leftover chili and pie wasn't bad!

I finally finished up the condition trigger portion of the editor, and it seems to be dealing well with the data. I added a few event handlers to it today so it would automatically update the game data any time fields were edited. This, of course, meant a bit more time was needed adding clean-up code for the handlers. But all-told, it was not too bad.

Before tackling the condition portion of the editor, I thought I'd see about writing the data out to files again. And since a lot of folks have recommended JSON instead of XML format, I decided to give that a shot. For those wondering what JSON looks like, here's an example condition trigger in JSON:

{ "strName": "TDcAltruism", "strCondName": "DcAltruism", "fChance": 1, "nCount": 1, "fThresholdMin": 25, "fThresholdMax": null, "aReqs": [], "aForbids": [] }

It's quite a bit easier to use than NEO Scavenger's XML data. I can avoid writing a lot of XML parsing/formatting code. And for modders, it should be easier to navigate and edit this format. Though to be fair, XML can be made similarly easy to read. NEO Scavenger just used the default mySQL XML export, which is a bit more bloated than needed.

Anyway, Haxe conveniently provides some built-in JSON parsing and "stringifying" code. Basically, I can just feed Haxe an object from the game, say Json.stringify(TDcAltruism), and I'll get text output like what you see above. And reading that object in from a text file is just as easy: Json.parse(txt) (assuming one has already read a file into the txt variable, which is similarly easy in Haxe/OpenFL).

The only complication I ran into was my own fault (as usual). I assumed Json would automatically cast the data it was reading into the correct format for the container I provided, which it didn't. This caused some strange memory referencing errors that confused me for a while before I figured it out. Once I wrote some code to manually transfer the Dynamic object's values over to the container's fields, it seemed to work smoothly. (That, and I needed to add some special handling code for default values that needed to be +/- Infinity instead of a finite number.)

As of now, I'm able to write out all CondTriggers to JSON and read them back in again, and I'm thinking I'll just covert all my XML data to JSON. And when that's done, I'll probably go back to tackling the editor for Conditions, and then start authoring some data!

Oh! And I had another sort of brainstorm over the weekend, regarding AI getting food from fridges. Basically, I can probably just create a new type of interaction that fridges have, which gives an item instead of a condition to the petitioner.

AI uses "SeekFood" on a food item: interaction response is "GrantFood" which decreases AI's hunger directly.
AI uses "SeekFood" on a fridge: interaction response is "GrantFoodItem" which transfers a food item to AI. The AI can then use "SeekFood" on the food item on their next turn.

The above case can make use of interactions' built-in "aCondTrigsNext" field, which describes what the petitioner expects to get next from this interaction. Both "GrantFood" and "GrantFoodItem" can be set to yield "Food" to the AI, so it will seek them equally.

The only changes needed to support this are to add which items "us" and "them" get in an interaction (and code to transfer said items), as well as AI code to check one's inventory first before seeking other AI or furniture to fulfill a need.

Seems pretty doable, and requires little reworking of existing systems. Might be a good full-scale test of the editor once it's done!


Toupz's picture

Nice work and i love reading your blog i visit this website a lot :D Thoroughly enjoy Neo Scavenger and can't wait to see a space sim from you. i'm a big sci-fi fan aswell as space sims/post-apocalyptic/zombie/Survival games.

dcfedor's picture

Thanks! I'm hoping I can pull off even half of the things I'm picturing in my head. I've been waiting a long time to make a space game :)

Dan Fedor - Founder, Blue Bottle Games