Added player generation.

This commit is contained in:
Martin Haye 2016-06-16 17:42:18 -07:00
parent 4e57da0d53
commit 7e758be30e
7 changed files with 178 additions and 35 deletions

View File

@ -59,6 +59,8 @@ class PackPartitions
def bytecodes = [:] // module name to bytecode.num, bytecode.buf
def fixups = [:] // module name to fixup.num, fixup.buf
def itemNameToFunc = [:]
def compressor = LZ4Factory.fastestInstance().highCompressor()
def ADD_COMP_CHECKSUMS = false
@ -1516,6 +1518,7 @@ class PackPartitions
compileModule("party", "src/plasma/")
compileModule("gen_enemies", "src/plasma/")
compileModule("gen_items", "src/plasma/")
compileModule("gen_players", "src/plasma/")
}
/**
@ -1902,6 +1905,39 @@ class PackPartitions
out.println " //item name=${row.@name}"
}
def genPlayer(func, row, out)
{
out.println(" word p")
out.println(\
" p = makePlayer_pt2(makePlayer_pt1(" +
"${escapeString(parseStringAttr(row, "name"))}, " +
"${parseByteAttr(row, "intelligence")}, " +
"${parseByteAttr(row, "strength")}, " +
"${parseByteAttr(row, "agility")}, " +
"${parseByteAttr(row, "stamina")}, " +
"${parseByteAttr(row, "charisma")}, " +
"${parseByteAttr(row, "spirit")}, " +
"${parseByteAttr(row, "luck")}), " +
"${parseWordAttr(row, "health")}, " +
"${parseByteAttr(row, "aiming")}, " +
"${parseByteAttr(row, "hand-to-hand")}, " +
"${parseByteAttr(row, "dodging")})")
row.attributes().each { name, val ->
if (name =~ /^skill-(.*)/) {
out.println(" addToList(@p=>p_skills, " +
"makeModifier(${escapeString(name.replace("skill-", ""))}, " +
"${parseByteAttr(row, name)}))")
}
else if (name =~ /^item-/) {
def itemFunc = itemNameToFunc[val]
assert itemFunc : "Can't locate item 'val'"
out.println(" addToList(@p=>p_items, itemScripts()=>$itemFunc())")
}
}
out.println(" calcPlayerArmor(p)")
out.println " return p"
}
def addCodeToFunc(funcName, codesString, addTo)
{
if (codesString == null || codesString.length() == 0)
@ -1950,6 +1986,11 @@ class PackPartitions
sheets.find { it?.@name.equalsIgnoreCase("items") }.rows.row.each { row ->
funcs << ["item", "NIt_${humanNameToSymbol(row.@name, false)}", funcs.size, row] }
// Global mapping of item name to function, so that Players can create items.
funcs.each { typeName, func, index, row ->
itemNameToFunc[row.@name] = func
}
// Build up the mappings from loot codes and store codes to creation functions
def lootCodeToFuncs = [:]
def storeCodeToFuncs = [:]
@ -1998,7 +2039,7 @@ class PackPartitions
// Generate all the functions themselves
funcs.each { typeName, func, index, row ->
withContext(func)
withContext("$typeName '${row.@name}'")
{
out.println("def _$func()")
switch (typeName) {
@ -2024,6 +2065,81 @@ class PackPartitions
replaceIfDiff("build/src/plasma/gen_items.pla")
}
def genAllPlayers(sheets)
{
// Grab all the raw data
def funcs = []
sheets.find { it?.@name.equalsIgnoreCase("players") }.rows.row.each { row ->
funcs << ["NPl_${humanNameToSymbol(row.@name, false)}", funcs.size, row]
}
// Make constants for the function table
new File("build/src/plasma/gen_players.plh.new").withWriter { out ->
out.println("// Generated code - DO NOT MODIFY BY HAND\n")
out.println("const makeInitialParty = 0")
funcs.each { func, index, row ->
out.println("const ${func} = ${(index+1)*2}")
}
}
replaceIfDiff("build/src/plasma/gen_players.plh")
// Generate code
new File("build/src/plasma/gen_players.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_modules.plh\"")
out.println("include \"gen_items.plh\"")
out.println("include \"gen_players.plh\"")
out.println()
out.println("word global, itemScripts")
out.println()
// Pre-define all the creation functions
out.println("predef _makeInitialParty")
funcs.each { func, index, row ->
out.println("predef _$func")
}
out.println("")
// Next, output the function table
out.println("word[] funcTbl = @_makeInitialParty")
funcs.each { func, index, row ->
out.println("word = @_$func")
}
out.println("")
// Generate all the functions themselves
funcs.each { func, index, row ->
withContext("player '${row.@name}'") {
out.println("def _$func()")
genPlayer(func, row, out)
out.println("end\n")
}
}
// Code for initial party creation
out.println("def _makeInitialParty()")
out.println(" itemScripts = mmgr(QUEUE_LOAD, MODULE_GEN_ITEMS<<8 | RES_TYPE_MODULE)")
out.println(" mmgr(FINISH_LOAD, 1) // 1 = keep open")
funcs.each { func, index, row ->
if (row.@"starting-party" == "yes")
out.println(" addToList(@global=>p_players, _$func())")
}
out.println(" mmgr(FREE_MEMORY, itemScripts)")
out.println(" itemScripts = NULL")
out.println("end\n")
// Lastly, the outer module-level code
out.println("global = getGlobals()")
out.println("return @funcTbl")
out.println("done")
}
replaceIfDiff("build/src/plasma/gen_players.pla")
}
def replaceIfDiff(oldFile)
{
def newFile = new File(oldFile + ".new")
@ -2094,6 +2210,7 @@ class PackPartitions
// Translate enemies, weapons, etc. to code
genAllEnemies(dataIn.global.sheets.sheet.find { it?.@name.equalsIgnoreCase("enemies") }, portraitNames)
genAllItems(dataIn.global.sheets.sheet)
genAllPlayers(dataIn.global.sheets.sheet)
// Produce a list of assembly and PLASMA code segments
binaryStubsOnly = true

View File

@ -115,9 +115,9 @@ const makeArmor = gameLibVecs + 3*54
const makeWeapon_pt1 = gameLibVecs + 3*55
const makeWeapon_pt2 = gameLibVecs + 3*56
const randomFromArray = gameLibVecs + 3*57
const UNUSED_FN_58 = gameLibVecs + 3*58
const UNUSED_FN_59 = gameLibVecs + 3*59
const UNUSED_FN_60 = gameLibVecs + 3*60
const makePlayer_pt1 = gameLibVecs + 3*58
const makePlayer_pt2 = gameLibVecs + 3*59
const calcPlayerArmor = gameLibVecs + 3*60
const UNUSED_FN_61 = gameLibVecs + 3*61
const UNUSED_FN_62 = gameLibVecs + 3*62
const UNUSED_FN_63 = gameLibVecs + 3*63

View File

@ -38,8 +38,8 @@ include "playtype.plh"
include "gen_images.plh"
include "gen_modules.plh"
include "gen_enemies.plh"
include "globalScripts.plh" // old-style
include "gen_globalScripts.plh" // new-style
include "gen_globalScripts.plh"
include "gen_players.plh"
include "combat.plh"
include "party.plh"
@ -111,6 +111,7 @@ predef _reboot, _brk, _encodeDice, _rollDice
predef _setPlural, _makeEnemy, _getStringResponse, _strcmpi, _addEncounterZone, _fatal
predef _pause, _tossStrings, _showMapName, _setMapWindow
predef _makeModifier, _makeArmor, _makeWeapon_pt1, _makeWeapon_pt2, _randomFromArray
predef _makePlayer_pt1, _makePlayer_pt2, _calcPlayerArmor
word gameLib_addrs = @_setScriptInfo, @_scriptDisplayStr, @_scriptDisplayStrNL, @_getYN
word = @_queue_setMap, @_setSky, @_setGround, @_queue_teleport, @_setPortrait, @_clearPortrait
@ -126,6 +127,7 @@ word = @_reboot, @_brk, @_encodeDice, @_rollDice
word = @_setPlural, @_makeEnemy, @_getStringResponse, @_strcmpi, @_addEncounterZone, @_fatal
word = @_pause, @_tossStrings, @_showMapName, @_setMapWindow
word = @_makeModifier, @_makeArmor, @_makeWeapon_pt1, @_makeWeapon_pt2, @_randomFromArray
word = @_makePlayer_pt1, @_makePlayer_pt2, @_calcPlayerArmor
word = 0 // end of library functions
@ -2190,19 +2192,56 @@ def _makeWeapon_pt2(p, attack0, attack1, attack2, weaponRange, combatText)
return p
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def _makePlayer_pt1(name, intelligence, strength, agility, stamina, charisma, spirit, luck)
word p
p = mmgr(HEAP_ALLOC, TYPE_PLAYER)
p=>s_name = mmgr(HEAP_INTERN, name)
p->b_intelligence = intelligence
p->b_strength = strength
p->b_agility = agility
p->b_stamina = stamina
p->b_charisma = charisma
p->b_spirit = spirit
p->b_luck = luck
return p
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def _makePlayer_pt2(p, health, aiming, handToHand, dodging)
p=>w_health = health
p=>w_maxHealth = health
p->b_aiming = aiming
p->b_handToHand = handToHand
p->b_dodging = dodging
return p
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def _calcPlayerArmor(player)
word pItem
player->b_armor = 0
pItem = player=>p_items
while pItem
if pItem->t_type == TYPE_ARMOR
player->b_armor = player->b_armor + pItem->b_armorValue
fin
pItem = pItem=>p_nextObj
loop
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Create the party
def initParty()
word globalScripts
word playerScripts, itemScripts, globalScripts
// Old-style
globalScripts = mmgr(QUEUE_LOAD, MODULE_GLOBAL_SCRIPTS<<8 | RES_TYPE_MODULE)
// Create the initial party
playerScripts = mmgr(QUEUE_LOAD, MODULE_GEN_PLAYERS<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, 1) // 1 = keep open
addToList(@global=>p_players, globalScripts()=>script_new_Player_Hue_Hauser())
addToList(@global=>p_players, globalScripts()=>script_new_Player_Mokahnu())
mmgr(FREE_MEMORY, globalScripts)
playerScripts()=>makeInitialParty()
mmgr(FREE_MEMORY, playerScripts)
// New-style
// And run the new-game script
globalScripts = mmgr(QUEUE_LOAD, MODULE_GEN_GLOBAL_SCRIPTS<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, 1) // 1 = keep open
globalScripts()=>sc_newGame()

View File

@ -13,11 +13,11 @@ include "playtype.plh"
include "gen_images.plh"
predef new_Armor_Chaps, new_Armor_ShamanHeaddress, new_Armor_TahnkuPants, new_Armor_TahnkuVest
predef new_Weapon_Handgun, new_Weapon_SpiritBow, new_Weapon_SpiritBlade, calcPlayerArmor
predef new_Weapon_Handgun, new_Weapon_SpiritBow, new_Weapon_SpiritBlade
predef new_Player_Hue_Hauser, new_Player_Mokahnu
word[] funcTbl = @new_Armor_Chaps, @new_Armor_ShamanHeaddress, @new_Armor_TahnkuPants, @new_Armor_TahnkuVest
word = @new_Weapon_Handgun, @new_Weapon_SpiritBow, @new_Weapon_SpiritBlade, @calcPlayerArmor
word = @new_Weapon_Handgun, @new_Weapon_SpiritBow, @new_Weapon_SpiritBlade
word = @new_Player_Hue_Hauser, @new_Player_Mokahnu
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -126,19 +126,6 @@ def new_Weapon_SpiritBlade
return p
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def calcPlayerArmor(player)
word pItem
player->b_armor = 0
pItem = player=>p_items
while pItem
if pItem->t_type == TYPE_ARMOR
player->b_armor = player->b_armor + pItem->b_armorValue
fin
pItem = pItem=>p_nextObj
loop
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Player_Hue_Hauser
word p, pItem
@ -147,10 +134,10 @@ def new_Player_Hue_Hauser
p->b_intelligence = 5
p->b_strength = 6
p->b_agility = 3
p->b_bravery = 6
p->b_stamina = 4
p->b_charisma = 7
p->b_spirit = 5
p->b_luck = 5
p=>w_maxHealth = 12
p=>w_health = 12
@ -184,10 +171,10 @@ def new_Player_Mokahnu
p->b_intelligence = 7
p->b_strength = 4
p->b_agility = 6
p->b_bravery = 7
p->b_stamina = 6
p->b_charisma = 7
p->b_spirit = 10
p->b_luck = 5
p=>w_maxHealth = 40
p=>w_health = 40

View File

@ -15,6 +15,5 @@ const script_new_Armor_TahnkuVest = 6
const script_new_Weapon_Handgun = 8
const script_new_Weapon_SpiritBow = 10
const script_new_Weapon_SpiritBlade = 12
const script_calcPlayerArmor = 14
const script_new_Player_Hue_Hauser = 16
const script_new_Player_Mokahnu = 18
const script_new_Player_Hue_Hauser = 14
const script_new_Player_Mokahnu = 16

View File

@ -42,16 +42,17 @@ struc Player
byte b_intelligence
byte b_strength
byte b_agility
byte b_bravery
byte b_stamina
byte b_charisma
byte b_spirit
byte b_luck
// Calculated attributes
byte b_armor
// Basic skills (much like attributes)
byte b_aiming
byte b_handToHand
byte b_dodging
// Status

View File

@ -13,7 +13,7 @@ open(ARGV[0], "r").readlines.each_with_index { |line, idx|
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+/, "-")
outField = inField.downcase.gsub("xd6", "").gsub("#", "num").gsub(/[^-a-zA-Z0-9 ]/, "").strip.gsub(/\s+/, "-")
colNames << outField
columnsEl.add_child out.create_element("column", :name => outField)
}