Skip to main content

Posts

Showing posts from May, 2014

Hoardomatic Code: Doing Something With It

Clever readers will have realized that everything I've posted up to this point doesn't actually do anything. There's a bundle of classes and data representing everything from a pile of treasure down to details of decor, but what to do with it? Ultimately, all one needs to randomly generate a hoard is something like the code below, which generates a hoard of random items worth $2,000. For a bigger or smaller hoard, just change the value of hoard_val. package hoardomatic; public class goMonkeygo {     public static void main(String[] args) {         Double hoard_val = 2000.0;         Hoard avarice = new Hoard(hoard_val);         System.out.println(avarice.hoardReport() );     } }

Hoardomatic Code: Sample Data

And finally, data. Without the XML files, this is all, in the words of Han Solo, a really short trip. These (redundant, poorly structured) batches of XML are representative of the nature and structure of data required. Here's what they contain. BulkGoods.xml: Detailed breakdowns of additional properties of bulk goods, notably the unit of measurement and containment type. These include W for wet goods like wines and pickles which must be stored in waterproof containers, D for dry goods like spices which can go in boxes and bags, and N for things like hides and raw fibers which are measured by bulk quantities but don't require containment. Containers.xml: Detailed breakdowns of additional properties of containers, notably containment type and storage capacity. Curses.xml: Curses are like lightweight enchantments or embellishments, with a name and a CF, which Items use to modify the cost of enchantments. Embellishments.xml: Properties of mundane embellishments, including nam

Hoardomatic Code: Gem Class

Last class. Gems have their own bundle of properties, so they get their own class. Gem String gem_name: Name of the gem. Double val_constant: The value constant for the stone, the V in the(C^2 + C*4) * V value formula. Double carats: Weight of the gem in carats. This one is similar to the previous two, but it takes on itself the task of randomly selecting a node from Gems.xml to turn into an object.    package hoardomatic; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.Random; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Gem {     private String gem_name;     private Double val_constant;     private Double carats;         public Gem() {         // TODO Auto-generated constructor stub         Node gemnode = getRandomNodeFromTable("Gems.xml");       

Hoardomatic Code: Enchantment Class

Enchantments are structurally very similar to Embellishments. The big difference is how costs are accounted for by the Item containing them. Enchantment String Enchantment_name: The name of the enchantment, usually just the name of a spell, though it may include a degree (Accuracy 3) or notation about which version of an enchantment the item has (Bravery (Cast only)). Double cf: The embellishment's CF value. Not actually used, but it's there because I started enchantments by copying the embellishment class. Double flat_cost: The base cost of the enchantment. Double wt_mod: Weight adjustment, if any, which spells generally don't have. String motif_option: Not used. String ench_code: A code similar to the embellishment codes, indicating what kind of item the enchantment can be on. Most are generally applicable, but a few are limited to weapons or armor. This class works very much like the Embellishments class: it takes a node provided to it and populates the encha

Hoardomatic Code: Embellishment Class

This represents an individual decorative or functional embellishment on an item. Embellishment String embellishment_name: Name of the embellishment (for example, "Fine material" or "Tassels"). Double cf: The embellishment's CF value. Double wt_mod: Weight adjustment, if any. This defaults to 1 and is expressed as a decimal multiplier to the base item's weight. For example, 0.9 for an embellishment which reduces the weight of the item by 10%. String motif_option: Some options don't lead to item having a particular decorative motif (for example, improved materials). Some do (for example, relief carving). Some could go either way (for example, painting; an item could simply be painted, say, entirely green, or have figures painted on it in green). This defaults to "N". String emb_code: A single string corresponding to the range of attributes which items may have. The constructor I'm using takes a node (from Embelishments.xml) handed

Hoardomatic Code: Item Class

Here's where most of the work happens. It also contains lots of untidy code which is a consequence of making it up as I go along: stub functions which are unimplemented, implemented but unused functions which don't do anything useful, and references to libraries that don't actually get used. No matter; the bits which do get used do what I need them to. Item String item_name: The name of the base item (broadsword, Dwarven theodolite, arrow, etc.) Double base_cost: The cost of the unembellished item, used as the basis for CF-related price calculations. Double base_weight: The unembellished weight of the item. Integer quantity: Usually 1, but ammunition and bulk goods often have a larger quantity String curse_name: Defaults to an empty string. An item may have no more than one curse. Double curse_cf: The CF of the curse, which applies to the cost of enchantments. String unit. The unit of measurement. Defaults to "each," but may be a unit of weight, length, etc. S