From de33ab3b2161fbeacb06ae6cd9ddac86945ab994 Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Sat, 11 Jun 2016 10:58:33 -0700 Subject: [PATCH] Generating stubs for all item types (weapons, armor, ammo, and items). --- .../src/org/demo/PackPartitions.groovy | 116 +++++++++++++++++- Platform/Apple/virtual/src/plasma/combat.pla | 3 + .../Apple/virtual/src/plasma/gameloop.pla | 46 +++++++ .../virtual/src/plasma/globalScripts.pla | 9 -- Platform/Apple/virtual/tsv2xml.rb | 27 ++++ 5 files changed, 189 insertions(+), 12 deletions(-) create mode 100755 Platform/Apple/virtual/tsv2xml.rb diff --git a/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy b/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy index a00087dd..a1ce739c 100644 --- a/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy +++ b/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy @@ -1181,7 +1181,7 @@ class PackPartitions def compressedLen = compressor.compress(uncompressedData, 0, uncompressedLen, compressedData, 0, maxCompressedLen) assert compressedLen > 0 - + // Then recompress to LZ4M (pretty much always smaller) def recompressedLen = recompress(compressedData, compressedLen, uncompressedData, uncompressedLen) @@ -1479,6 +1479,7 @@ class PackPartitions compileModule("combat", "src/plasma/") compileModule("party", "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 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) replaceIfDiff("build/src/plasma/gen_globalScripts.pla") - // Translate enemies to code - genAllEnemies(dataIn.global.sheets.sheet.find { it?.@name == "enemies" }, portraitNames) + // Translate enemies, weapons, etc. to code + 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 binaryStubsOnly = true diff --git a/Platform/Apple/virtual/src/plasma/combat.pla b/Platform/Apple/virtual/src/plasma/combat.pla index e56a3291..a01cacb5 100644 --- a/Platform/Apple/virtual/src/plasma/combat.pla +++ b/Platform/Apple/virtual/src/plasma/combat.pla @@ -58,6 +58,7 @@ def playerMelee(pPlayer, pWeapon) fin // TODO: Add extra melee damage for skills, strength, etc. // TODO: consider enemy dodge + // TODO: consider enemy armor and bonuses pEnemy=>w_health = pEnemy=>w_health - dmg buildString(@addToString) @@ -82,6 +83,7 @@ def playerShoot(pPlayer, pWeapon) if !pEnemy; return FALSE; fin // 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 // Add in skill modifier, if any @@ -108,6 +110,7 @@ def playerShoot(pPlayer, pWeapon) dmg = rollDice(pWeapon=>r_projectileDmg) // TODO: Add extra melee damage for skills, strength, etc. // TODO: consider enemy dodge + // TODO: consider enemy armor, and armor bonuses pEnemy=>w_health = pEnemy=>w_health - dmg buildString(@addToString) diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index 7d71a0cf..29765464 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -2137,6 +2137,52 @@ def setLibVecs() 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 def initParty() diff --git a/Platform/Apple/virtual/src/plasma/globalScripts.pla b/Platform/Apple/virtual/src/plasma/globalScripts.pla index ffb99720..cce52098 100644 --- a/Platform/Apple/virtual/src/plasma/globalScripts.pla +++ b/Platform/Apple/virtual/src/plasma/globalScripts.pla @@ -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_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 word p diff --git a/Platform/Apple/virtual/tsv2xml.rb b/Platform/Apple/virtual/tsv2xml.rb new file mode 100755 index 00000000..11713784 --- /dev/null +++ b/Platform/Apple/virtual/tsv2xml.rb @@ -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 \ No newline at end of file