Major updates to the crafting algo.

* Update crafting algo. to favor highest output recipes for making
  items, and to be more flexible about trying a variety of recipes if
  some one recipe doesn't work.
* Modify crafting algo. to allow crafting of "gatherable" items.
* Update logger to support indent/outdent for clearer formatting
* Convert IC2 Forge Hammer / Cutter recipes to treat them as tools
This commit is contained in:
Andrew Miner
2015-02-18 21:29:21 -08:00
parent aab3baec1a
commit b1a6637005
6 changed files with 148 additions and 111 deletions
+22 -3
View File
@@ -5,8 +5,9 @@ Copyright (c) 2014-2015 by Redwood Labs
All rights reserved.
###
BaseModel = require './base_model'
Stack = require './stack'
BaseModel = require './base_model'
Stack = require './stack'
StringBuilder = require './string_builder'
########################################################################################################################
@@ -43,7 +44,7 @@ module.exports = class Recipe extends BaseModel
aValue = a.getQuantityProducedOf itemSlug
bValue = b.getQuantityProducedOf itemSlug
if aValue isnt bValue
return if aValue < bValue then -1 else +1
return if aValue > bValue then -1 else +1
aValue = a.getInputCount()
bValue = b.getInputCount()
@@ -102,6 +103,24 @@ module.exports = class Recipe extends BaseModel
return true
return false
# Property Methods #############################################################################
getSlug: ->
if not @_slug?
builder = new StringBuilder
builder
.loop(@input, delimiter:',', onEach:(b, stack)-> b.push stack.itemSlug.qualified)
.onlyIf @tools.length > 0, (b)=>
b.push(' + ').loop(@tools, delimiter:',', onEach:(b, stack)-> b.push stack.itemSlug.qualified)
.push(' => ')
.loop(@output, delimiter:',', onEach:(b, stack)-> b.push stack.itemSlug.qualified)
@_slug = builder.toString()
return @_slug
Object.defineProperties @prototype,
slug: {get:@prototype.getSlug}
# Object Overrides #############################################################################
toString: ->