Wednesday, October 2, 2013

XML and Scrolling

Cultura has a lot of different resources. And it might be overwhelming to a player who isn't all the rage into Dwarf Fortress or Anno 1404. So, in Cultura, the concept is simplified a bit. There are "items". You can see below in the list those are things like "grain", "fruit", "meat". Within an item category are "materials". So there are different types of grain such as "wheat" or "oats".

What this means is that all goods will require "items" (not materials). So when you want to make "flour", you use "grain". It doesn't matter what kind of grain. But using more types of materials creates higher quality items. Higher quality items last longer or give better bonuses.

The current list of items and materials are:

  • Grain: wheat, oats, rye, barley, stone grass, green brome, silk rye, bluestem
  • Fruit/Vegetable: juniper berries, crab apple, blackberry, strawberry, glowing mushroom, crab plum, yellow berry, tiger nut
  • Dairy: none for now
  • Meat: gazelle, seal, mammoth, sabertooth cat, unicorn, ice crab, dragon, direwolf
  • Stone: granite, limestone, flint, chert, stonewood, rune rock, aquaferra, dark granite
  • Wood: pine, oak, cypress, sycamore, silverleaf, ironwood, amberbark, goldwood
  • Earth: clay, sand, kaolin, silt, bright clay, dark shale, fire sand, frost silt
  • Metal: tin, iron, nickel, zinc, viper stone, cold iron, frost ore, amber nickel
  • Bone: gazelle, seal, mammoth, sabertooth cat, unicorn, ice crab, dragon, direwolf
  • Fur/Skin: gazelle, seal, mammoth, sabertooth cat, unicorn, ice crab, dragon, direwolf
  • Fibre: silk, cotton, ramie, hemp, giant spider silk, thread mushroom, rock string, yarn bush
  • Filler: papyrus, ryegrass, leadtree, burclover, hollow weed, elf blade, grey shrub, goldclover
  • Herb: tea, ginger, basil, cinnamon, glowing nettle, ember flowers, comfrey root, mandrake
  • Precious Metal: gold, silver, copper, platinum, mithril, adamantium, snow silver, null iron
  • Precious Stone: turquoise, diamond, jade, sapphire, mana crystal, moonstone, sky pearl, power stone

In terms of code the only trickiness surrounds meat, bone and skin. For those items they are refined from animal (or sentient) carcasses. Your hunters will go out, kill a gazelle and then harvest "carcass" type goods. These are then turned into meat, bone and skin. This means for the game purposes, meat/bone/skin count as non-raw goods! Instead "animal parts" is what you collect and then based on the material of the animal part you get different meat, bone and skin. You can then use those to craft further items. The xml that has been written looks something like:


<good>
 <name>Meat</name>
 <id>10000</id>
 <prereq>
  <req>
   <id>100</id>
   <amount>1</amount>
  </req>
 </prereq> 
 <category>
  <id>100001</id>
 </category>
 <graphic>
  <meshname>meat</meshname>
  <texture>meat.png</texture>
 </graphic>  
</good>

This gives a quick way to add in new stuff into the game. How do we parse it? Using rapidxml :) I'm not going to write a poopy xml parser when there's a million out there. Those aren't particularly interesting or hard problems to solve versus making Cultura. The intent is, afterall, to make an awesome game.

Using xml, the units, structures, goods and materials are all loaded at initialization. Then they are saved in the "gameEntityCreator". This class holds all the definitions. Whenever some components needs to make a new unit or structure or resource node etc, they call the gameEntityCreator to do so.

Next for the xml loading is to change the UI to make use of the gameEntityCreator and its list of definitions. The goal is modularity and moddability. While I don't have an intent in making the game mod-able, I do intend to have as little "one-shot" code in the game as possible through better design.

Some additional awesome fixes by a friend:

  • Game starts with the camera properly centered on your cave
  • No more scrolling unto infinity, it stops at the edge of the map