Generating stubs for all item types (weapons, armor, ammo, and items).

This commit is contained in:
Martin Haye 2016-06-11 10:58:33 -07:00
parent a4eaeb5cf1
commit de33ab3b21
5 changed files with 189 additions and 12 deletions

View File

@ -1181,7 +1181,7 @@ class PackPartitions
def compressedLen = compressor.compress(uncompressedData, 0, uncompressedLen, def compressedLen = compressor.compress(uncompressedData, 0, uncompressedLen,
compressedData, 0, maxCompressedLen) compressedData, 0, maxCompressedLen)
assert compressedLen > 0 assert compressedLen > 0
// Then recompress to LZ4M (pretty much always smaller) // Then recompress to LZ4M (pretty much always smaller)
def recompressedLen = recompress(compressedData, compressedLen, uncompressedData, uncompressedLen) def recompressedLen = recompress(compressedData, compressedLen, uncompressedData, uncompressedLen)
@ -1479,6 +1479,7 @@ class PackPartitions
compileModule("combat", "src/plasma/") compileModule("combat", "src/plasma/")
compileModule("party", "src/plasma/") compileModule("party", "src/plasma/")
compileModule("gen_enemies", "src/plasma/") compileModule("gen_enemies", "src/plasma/")
compileModule("gen_items", "src/plasma/")
} }
/** /**
@ -1814,6 +1815,114 @@ class PackPartitions
} }
def genWeapon(out, row)
{
out.println " //weapon name=${row.@name}"
}
def genArmor(out, row)
{
out.println " //armor name=${row.@name}"
}
def genAmmo(out, row)
{
out.println " //ammo name=${row.@name}"
}
def genItem(out, row)
{
out.println " //item name=${row.@name}"
}
def addCodeToFunc(func, codesString, addTo)
{
if (codesString == null)
return
codesString.replace("\"", "").split(",").collect{it.trim()}.grep{it!=""}.each { code ->
if (!addTo.containsKey(code))
addTo[code] = []
addTo[code] << func
}
}
def genAllItems(sheets)
{
// Grab all the raw data
def funcs = []
sheets.find { it?.@name.equalsIgnoreCase("weapons") }.rows.row.each { row ->
funcs << ["weapon", "new_weapon_${humanNameToSymbol(row.@name, false)}", funcs.size, row] }
sheets.find { it?.@name.equalsIgnoreCase("armor") }.rows.row.each { row ->
funcs << ["armor", "new_armor_${humanNameToSymbol(row.@name, false)}", funcs.size, row] }
sheets.find { it?.@name.equalsIgnoreCase("ammo") }.rows.row.each { row ->
funcs << ["ammo", "new_ammo_${humanNameToSymbol(row.@name, false)}", funcs.size, row] }
sheets.find { it?.@name.equalsIgnoreCase("items") }.rows.row.each { row ->
funcs << ["item", "new_item_${humanNameToSymbol(row.@name, false)}", funcs.size, row] }
// Build up the mappings from loot codes and store codes to creation functions
def lootCodeToFuncs = [:]
def storeCodeToFuncs = [:]
funcs.each { typeName, func, index, row ->
addCodeToFunc(func, row.@"loot-code", lootCodeToFuncs)
addCodeToFunc(func, row.@"store-code", storeCodeToFuncs)
}
// Make constants for the function table
new File("build/src/plasma/gen_items.plh.new").withWriter { out ->
out.println("// Generated code - DO NOT MODIFY BY HAND\n")
funcs.each { typeName, func, index, row ->
out.println("const ${func} = ${index*2}")
}
}
replaceIfDiff("build/src/plasma/gen_items.plh")
// Generate code
new File("build/src/plasma/gen_items.pla.new").withWriter { out ->
out.println("// Generated code - DO NOT MODIFY BY HAND")
out.println()
out.println("include \"gamelib.plh\"")
out.println("include \"playtype.plh\"")
out.println("include \"gen_items.plh\"")
out.println()
// Pre-define all the creation functions
funcs.each { typeName, func, index, row ->
out.println("predef _$func")
}
out.println("")
// Next, output the function table
funcs.each { typeName, func, index, row ->
out.println("${index==0 ? "word[] funcTbl =" : "word ="} @_$func")
}
out.println("")
// Generate all the functions themselves
funcs.each { typeName, func, index, row ->
withContext(func)
{
out.println("def _$func()")
switch (typeName) {
case "weapon": genWeapon(out, row); break
case "armor": genArmor(out, row); break
case "ammo": genAmmo(out, row); break
case "item": genItem(out, row); break
default: assert false
}
out.println("end\n")
}
}
out.println()
// Lastly, the outer module-level code
out.println("return @funcTbl")
out.println("done")
}
replaceIfDiff("build/src/plasma/gen_items.pla")
}
def replaceIfDiff(oldFile) def replaceIfDiff(oldFile)
{ {
def newFile = new File(oldFile + ".new") def newFile = new File(oldFile + ".new")
@ -1881,8 +1990,9 @@ class PackPartitions
gsmod.packGlobalScripts(new File("build/src/plasma/gen_globalScripts.pla.new"), dataIn.global.scripts) gsmod.packGlobalScripts(new File("build/src/plasma/gen_globalScripts.pla.new"), dataIn.global.scripts)
replaceIfDiff("build/src/plasma/gen_globalScripts.pla") replaceIfDiff("build/src/plasma/gen_globalScripts.pla")
// Translate enemies to code // Translate enemies, weapons, etc. to code
genAllEnemies(dataIn.global.sheets.sheet.find { it?.@name == "enemies" }, portraitNames) genAllEnemies(dataIn.global.sheets.sheet.find { it?.@name.equalsIgnoreCase("enemies") }, portraitNames)
genAllItems(dataIn.global.sheets.sheet)
// Produce a list of assembly and PLASMA code segments // Produce a list of assembly and PLASMA code segments
binaryStubsOnly = true binaryStubsOnly = true

View File

@ -58,6 +58,7 @@ def playerMelee(pPlayer, pWeapon)
fin fin
// TODO: Add extra melee damage for skills, strength, etc. // TODO: Add extra melee damage for skills, strength, etc.
// TODO: consider enemy dodge // TODO: consider enemy dodge
// TODO: consider enemy armor and bonuses
pEnemy=>w_health = pEnemy=>w_health - dmg pEnemy=>w_health = pEnemy=>w_health - dmg
buildString(@addToString) buildString(@addToString)
@ -82,6 +83,7 @@ def playerShoot(pPlayer, pWeapon)
if !pEnemy; return FALSE; fin if !pEnemy; return FALSE; fin
// Figure out chance to hit. First come agility and aim. // Figure out chance to hit. First come agility and aim.
// TODO: check for and add weapon bonuses for agility and aiming
chance = (pPlayer->b_agility * 4) + pPlayer->b_aiming chance = (pPlayer->b_agility * 4) + pPlayer->b_aiming
// Add in skill modifier, if any // Add in skill modifier, if any
@ -108,6 +110,7 @@ def playerShoot(pPlayer, pWeapon)
dmg = rollDice(pWeapon=>r_projectileDmg) dmg = rollDice(pWeapon=>r_projectileDmg)
// TODO: Add extra melee damage for skills, strength, etc. // TODO: Add extra melee damage for skills, strength, etc.
// TODO: consider enemy dodge // TODO: consider enemy dodge
// TODO: consider enemy armor, and armor bonuses
pEnemy=>w_health = pEnemy=>w_health - dmg pEnemy=>w_health = pEnemy=>w_health - dmg
buildString(@addToString) buildString(@addToString)

View File

@ -2137,6 +2137,52 @@ def setLibVecs()
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
def makeModifier(kind, value)
word p
p = mmgr(HEAP_ALLOC, TYPE_MODIFIER)
p->b_modKind = kind
p->b_modValue = value
return p
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def makeArmor(name, kind, cost, armorValue, modifier)
word p
p = mmgr(HEAP_ALLOC, TYPE_ARMOR)
p=>s_name = mmgr(HEAP_INTERN, name)
p->b_itemKind = kind
p=>w_cost = cost
p->b_armorValue = armorValue
p=>p_modifiers = modifier
return p
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def makeWeapon(name, kind, cost, ammoKind, clipSize, meleeDmg, projectileDmg)
word p
p = mmgr(HEAP_ALLOC, TYPE_WEAPON)
p=>s_name = mmgr(HEAP_INTERN, name)
p->b_itemKind = kind
p=>w_cost = cost
p->b_ammoKind = ammoKind
p->b_clipSize = clipSize
p->b_clipCurrent = clipSize
p=>r_meleeDmg = meleeDmg
p=>r_projectileDmg = projectileDmg
return p
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def finishWeapon(p, modifier, attack0, attack1, attack2, weaponRange, combatText)
p->ba_attacks[0] = attack0
p->ba_attacks[1] = attack1
p->ba_attacks[2] = attack2
p->b_weaponRange = weaponRange
p=>s_combatText = mmgr(HEAP_INTERN, combatText)
return p
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Create the party // Create the party
def initParty() def initParty()

View File

@ -20,15 +20,6 @@ word[] funcTbl = @new_Modifier, @new_Armor_Chaps, @new_Armor_ShamanHeaddress, @n
word = @new_Weapon_Handgun, @new_Weapon_SpiritBow, @new_Weapon_SpiritBlade, @calcPlayerArmor word = @new_Weapon_Handgun, @new_Weapon_SpiritBow, @new_Weapon_SpiritBlade, @calcPlayerArmor
word = @new_Player_Hue_Hauser, @new_Player_Mokahnu word = @new_Player_Hue_Hauser, @new_Player_Mokahnu
///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Modifier(kind, value)
word p
p = mmgr(HEAP_ALLOC, TYPE_MODIFIER)
p->b_modKind = kind
p->b_modValue = value
return p
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Armor_Chaps def new_Armor_Chaps
word p word p

View File

@ -0,0 +1,27 @@
#!/opt/local/bin/ruby
require 'nokogiri'
require 'pp'
colNames = []
out = Nokogiri::XML::Document.new
out.add_child(sheet = out.create_element("sheet"))
sheet["name"] = ARGV[0].sub(/.*\//, "").sub(/\..*$/, "").sub(/.* - /, "").capitalize
rowsEl = nil
open(ARGV[0], "r").readlines.each_with_index { |line, idx|
fields = line.chomp.split("\t")
if idx == 0
sheet.add_child(columnsEl = out.create_element("columns"))
fields.each { |inField|
outField = inField.downcase.gsub("xd6", "").gsub(/:.*/, "").gsub("#", "num").gsub(/[^-a-zA-Z0-9 ]/, "").strip.gsub(/\s+/, "-")
colNames << outField
columnsEl.add_child out.create_element("column", :name => outField)
}
sheet.add_child(rowsEl = out.create_element("rows"))
else
rowsEl.add_child(rowEl = out.create_element("row"))
fields.each_with_index { |val, idx| rowEl[colNames[idx]] = val }
end
}
puts sheet