Mostly implemented ability to add/remove players, but got some debugging to do.

This commit is contained in:
Martin Haye 2016-08-17 08:09:14 -07:00
parent db41d2289f
commit ecf76efde2
6 changed files with 148 additions and 34 deletions

View File

@ -119,6 +119,9 @@
<block type="interaction_give_item"></block> <block type="interaction_give_item"></block>
<block type="interaction_take_item"></block> <block type="interaction_take_item"></block>
<block type="interaction_has_item"></block> <block type="interaction_has_item"></block>
<block type="interaction_add_player"></block>
<block type="interaction_remove_player"></block>
<block type="interaction_has_player"></block>
<block type="interaction_get_stat"></block> <block type="interaction_get_stat"></block>
<block type="interaction_increase_stat"></block> <block type="interaction_increase_stat"></block>
<block type="interaction_decrease_stat"></block> <block type="interaction_decrease_stat"></block>

View File

@ -660,6 +660,45 @@ if (typeof Mythos === "undefined") {
this.setTooltip('Check if player has a given item'); this.setTooltip('Check if player has a given item');
} }
}; };
Blockly.Blocks['interaction_add_player'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField("Add player")
.appendField(new Blockly.FieldTextInput(""), "NAME")
.appendField("to party");
this.setOutput(false);
this.setTooltip('Add a player to the party');
}
};
Blockly.Blocks['interaction_remove_player'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField("Remove player")
.appendField(new Blockly.FieldTextInput(""), "NAME")
.appendField("from party");
this.setOutput(false);
this.setTooltip('Remove a player from the party (if possible)');
}
};
Blockly.Blocks['interaction_has_player'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(Blockly.Blocks.logic.HUE);
this.appendDummyInput()
.appendField("party has player")
.appendField(new Blockly.FieldTextInput(""), "NAME");
this.setOutput(true, "Boolean");
this.setTooltip('Check if party has a given player');
}
};
Blockly.Blocks['interaction_get_stat'] = { Blockly.Blocks['interaction_get_stat'] = {
init: function () { init: function () {
this.setHelpUrl(Mythos.helpUrl); this.setHelpUrl(Mythos.helpUrl);

View File

@ -61,6 +61,7 @@ class A2PackPartitions
def fixups = [:] // module name to fixup.num, fixup.buf def fixups = [:] // module name to fixup.num, fixup.buf
def itemNameToFunc = [:] def itemNameToFunc = [:]
def playerNameToFunc = [:]
def lastSysModule def lastSysModule
@ -1752,8 +1753,10 @@ class A2PackPartitions
// Number all the maps and record them with names // Number all the maps and record them with names
numberMaps(dataIn) numberMaps(dataIn)
// Form the translation from item name to function name // Form the translation from item name to function name (and ditto
// for players)
allItemFuncs(dataIn.global.sheets.sheet) allItemFuncs(dataIn.global.sheets.sheet)
allPlayerFuncs(dataIn.global.sheets.sheet)
// Pack each map This uses the image and tile maps filled earlier. // Pack each map This uses the image and tile maps filled earlier.
println "Packing maps." println "Packing maps."
@ -2100,7 +2103,7 @@ end
"${parseByteAttr(row, name)}))") "${parseByteAttr(row, name)}))")
} }
else if (name =~ /^item-/) { else if (name =~ /^item-/) {
def itemFunc = itemNameToFunc[val] def itemFunc = itemNameToFunc[val.trim().toLowerCase()]
assert itemFunc : "Can't locate item '$val'" assert itemFunc : "Can't locate item '$val'"
out.println(" addToList(@p=>p_items, itemScripts()=>$itemFunc())") out.println(" addToList(@p=>p_items, itemScripts()=>$itemFunc())")
} }
@ -2157,9 +2160,9 @@ end
sheets.find { it?.@name.equalsIgnoreCase("items") }.rows.row.findAll{it.@name}.each { row -> sheets.find { it?.@name.equalsIgnoreCase("items") }.rows.row.findAll{it.@name}.each { row ->
funcs << ["item", "NIt_${humanNameToSymbol(row.@name, false)}", funcs.size, row] } funcs << ["item", "NIt_${humanNameToSymbol(row.@name, false)}", funcs.size, row] }
// Global mapping of item name to function, so that Players can create items. // Global mapping of item name to function, so that give/take functions can create items.
funcs.each { typeName, func, index, row -> funcs.each { typeName, func, index, row ->
itemNameToFunc[row.@name.trim()] = func itemNameToFunc[row.@name.trim().toLowerCase()] = func
} }
// And return the funcs. // And return the funcs.
@ -2301,7 +2304,7 @@ end
replaceIfDiff("build/src/plasma/gen_items.pla") replaceIfDiff("build/src/plasma/gen_items.pla")
} }
def genAllPlayers(sheets) def allPlayerFuncs(sheets)
{ {
// Grab all the raw data // Grab all the raw data
def funcs = [] def funcs = []
@ -2309,6 +2312,17 @@ end
funcs << ["NPl_${humanNameToSymbol(row.@name, false)}", funcs.size, row] funcs << ["NPl_${humanNameToSymbol(row.@name, false)}", funcs.size, row]
} }
// Global mapping of player name to function, so that add/remove functions can work.
funcs.each { func, index, row ->
playerNameToFunc[row.@name.trim().toLowerCase()] = func
}
}
def genAllPlayers(sheets)
{
// Grab all the raw data
def funcs = allPlayerFuncs(sheets)
// Make constants for the function table // Make constants for the function table
new File("build/src/plasma/gen_players.plh.new").withWriter { out -> new File("build/src/plasma/gen_players.plh.new").withWriter { out ->
out.println("// Generated code - DO NOT MODIFY BY HAND\n") out.println("// Generated code - DO NOT MODIFY BY HAND\n")
@ -2679,6 +2693,7 @@ end
out << "include \"../plasma/playtype.plh\"\n" out << "include \"../plasma/playtype.plh\"\n"
out << "include \"../plasma/gen_images.plh\"\n\n" out << "include \"../plasma/gen_images.plh\"\n\n"
out << "include \"../plasma/gen_items.plh\"\n\n" out << "include \"../plasma/gen_items.plh\"\n\n"
out << "include \"../plasma/gen_players.plh\"\n\n"
out << "word global\n" out << "word global\n"
} }
@ -2871,6 +2886,10 @@ end
packGiveItem(blk); break packGiveItem(blk); break
case 'interaction_take_item': case 'interaction_take_item':
packTakeItem(blk); break packTakeItem(blk); break
case 'interaction_add_player':
packAddPlayer(blk); break
case 'interaction_remove_player':
packRemovePlayer(blk); break
case 'interaction_increase_stat': case 'interaction_increase_stat':
case 'interaction_decrease_stat': case 'interaction_decrease_stat':
packChangeStat(blk); break packChangeStat(blk); break
@ -2942,7 +2961,7 @@ end
def packGiveItem(blk) def packGiveItem(blk)
{ {
def name = getSingle(blk.field, 'NAME').text().trim() def name = getSingle(blk.field, 'NAME').text().trim()
def itemFunc = itemNameToFunc[name] def itemFunc = itemNameToFunc[name.toLowerCase()]
assert itemFunc : "Can't locate item '$name'" assert itemFunc : "Can't locate item '$name'"
outIndented("giveItemToPlayer($itemFunc)\n") outIndented("giveItemToPlayer($itemFunc)\n")
} }
@ -2950,11 +2969,25 @@ end
def packTakeItem(blk) def packTakeItem(blk)
{ {
def name = getSingle(blk.field, 'NAME').text().trim() def name = getSingle(blk.field, 'NAME').text().trim()
def itemFunc = itemNameToFunc[name] assert itemNameToFunc.containsKey(name.toLowerCase()) : "Can't locate item '$name'"
assert itemFunc : "Can't locate item '$name'"
outIndented("takeItemFromPlayer(${escapeString(name)})\n") outIndented("takeItemFromPlayer(${escapeString(name)})\n")
} }
def packAddPlayer(blk)
{
def name = getSingle(blk.field, 'NAME').text().trim()
def playerFunc = playerNameToFunc[name.toLowerCase()]
assert playerFunc : "Can't locate player '$name'"
outIndented("addPlayerToParty($playerFunc)\n")
}
def packRemovePlayer(blk)
{
def name = getSingle(blk.field, 'NAME').text().trim()
assert playerNameToFunc.containsKey(name.toLowerCase()) : "Can't locate player '$name'"
outIndented("removePlayerFromParty(${escapeString(name)})\n")
}
def nameToStat(name) { def nameToStat(name) {
switch (name.toLowerCase().trim()) { switch (name.toLowerCase().trim()) {
case "intelligence": return "@S_INTELLIGENCE"; return case "intelligence": return "@S_INTELLIGENCE"; return
@ -3055,10 +3088,18 @@ end
def packHasItem(blk) def packHasItem(blk)
{ {
def name = getSingle(blk.field, "NAME").text() def name = getSingle(blk.field, "NAME").text().trim()
assert itemNameToFunc.containsKey(name.toLowerCase()) : "Can't locate item '$name': $itemNameToFunc"
out << "playerHasItem(${escapeString(name)})" out << "playerHasItem(${escapeString(name)})"
} }
def packHasPlayer(blk)
{
def name = getSingle(blk.field, "NAME").text().trim()
assert playerNameToFunc.containsKey(name.toLowerCase()) : "Can't locate player '$name'"
out << "partyHasPlayer(${escapeString(name)})"
}
def packExpr(blk) def packExpr(blk)
{ {
switch (blk.@type) { switch (blk.@type) {
@ -3083,6 +3124,9 @@ end
case 'interaction_has_item': case 'interaction_has_item':
packHasItem(blk) packHasItem(blk)
break break
case 'interaction_has_player':
packHasPlayer(blk)
break
case 'interaction_get_stat': case 'interaction_get_stat':
packGetStat(blk) packGetStat(blk)
break break

View File

@ -29,8 +29,8 @@ MAX_SEGS = 96
DO_COMP_CHECKSUMS = 0 ; during compression debugging DO_COMP_CHECKSUMS = 0 ; during compression debugging
DEBUG_DECOMP = 0 DEBUG_DECOMP = 0
DEBUG = 0 DEBUG = 1
SANITY_CHECK = 0 ; also prints out request data SANITY_CHECK = 1 ; also prints out request data
; Zero page temporary variables ; Zero page temporary variables
tmp = $2 ; len 2 tmp = $2 ; len 2
@ -1512,14 +1512,15 @@ saneCheck: !zone {
} }
saneEnd: !zone { saneEnd: !zone {
+prStr : !text "->",0
+prYX
pha pha
tya tya
pha pha
txa txa
pha pha
jsr saneCheck jsr saneCheck
+prChr 'm' +prStr : !text "m.",0
+crout
pla pla
tax tax
pla pla

View File

@ -16,7 +16,7 @@ import gamelib
predef getUpperKey, clearWindow, getGlobals, rand16, printf1, printf2, printf3 predef getUpperKey, clearWindow, getGlobals, rand16, printf1, printf2, printf3
predef displayf1, displayf2, displayf3, buildString, addToString, finishString predef displayf1, displayf2, displayf3, buildString, addToString, finishString
predef displayChar, rawDisplayStr, displayStr, rightJustifyStr, rightJustifyNum, puts predef displayChar, rawDisplayStr, displayStr, rightJustifyStr, rightJustifyNum, puts
predef min, max, randomFromListFiltered, randomFromArray predef min, max, randomFromListFiltered, randomFromArray, scanForNamedObj
predef countList, countListFiltered, addToList, removeFromList predef countList, countListFiltered, addToList, removeFromList
predef beep, showParty, mmgr, setWindow1, setWindow2, setWindow3, reboot, brk predef beep, showParty, mmgr, setWindow1, setWindow2, setWindow3, reboot, brk
predef encodeDice, rollDice, setPlural, getStringResponse predef encodeDice, rollDice, setPlural, getStringResponse
@ -26,6 +26,7 @@ import gamelib
predef calcPlayerArmor, diskActivity, rdkey, initHeap, scriptCombat, makeModifier predef calcPlayerArmor, diskActivity, rdkey, initHeap, scriptCombat, makeModifier
predef giveItemToPlayer, takeItemFromPlayer, playerHasItem, getStat, setStat predef giveItemToPlayer, takeItemFromPlayer, playerHasItem, getStat, setStat
predef setGameFlag, getGameFlag, scriptSetAvatar predef setGameFlag, getGameFlag, scriptSetAvatar
predef addPlayerToParty, removePlayerFromParty, partyHasPlayer
// Shared string constants // Shared string constants

View File

@ -2340,7 +2340,7 @@ export def payGold(amount)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def scanForNamedObj(p_obj, name) export def scanForNamedObj(p_obj, name)
while p_obj while p_obj
if streqi(p_obj=>s_name, name); return p_obj; fin if streqi(p_obj=>s_name, name); return p_obj; fin
p_obj = p_obj=>p_nextObj p_obj = p_obj=>p_nextObj
@ -2349,46 +2349,72 @@ def scanForNamedObj(p_obj, name)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
export def giveItemToPlayer(itemFunc) export def createAndAddUnique(moduleID, creationFuncNum, pList)
word p_module, funcTbl, func, p_item word p_module, funcTbl, func, p_thing
// Load the module that is capable of creating items // Load the module that is capable of creating the thing
mmgr(FINISH_LOAD, WITH_CLOSE)
mmgr(START_LOAD, 1) // code is in partition 1 mmgr(START_LOAD, 1) // code is in partition 1
p_module = mmgr(QUEUE_LOAD, MODULE_GEN_ITEMS<<8 | RES_TYPE_MODULE) p_module = mmgr(QUEUE_LOAD, moduleID<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, WITH_CLOSE) mmgr(FINISH_LOAD, WITH_CLOSE)
// Figure out which item function to call there, and create the item // Figure out which creation function to call there, and create the thing
funcTbl = p_module() funcTbl = p_module()
func = *(funcTbl + itemFunc) func = *(funcTbl + creationFuncNum)
p_item = func() printf1("func=$%x\n", func)
p_thing = func()
printf1("p_thing=$%x\n", p_thing)
// Avoid giving duplicate items. // Avoid giving duplicate things.
if !scanForNamedObj(global=>p_players=>p_items, p_item=>s_name) if !scanForNamedObj(*pList, p_thing=>s_name)
addToList(@global=>p_players=>p_items, p_item) addToList(pList, p_thing)
fin fin
// Finished with the item module now. // Finished with the module now.
mmgr(FREE_MEMORY, p_module) mmgr(FREE_MEMORY, p_module)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
export def takeItemFromPlayer(itemName) export def giveItemToPlayer(itemFuncNum)
word p_player createAndAddUnique(MODULE_GEN_ITEMS, itemFuncNum, @global=>p_players=>p_items) // def: 1st player
word p_item end
p_player = global=>p_players // default to first player
p_item = scanForNamedObj(p_player=>p_items, itemName) ///////////////////////////////////////////////////////////////////////////////////////////////////
if p_item export def addPlayerToParty(playerFuncNum)
removeFromList(@p_player=>p_items, p_item) createAndAddUnique(MODULE_GEN_PLAYERS, playerFuncNum, @global=>p_players)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def removeNamed(name, pList)
word p_thing
p_thing = scanForNamedObj(*pList, name)
if p_thing
removeFromList(pList, p_thing)
else else
printf1("Warning: couldn't find item '%s' to take.\n", itemName) printf1("Warning: couldn't find '%s' to remove.\n", name)
fin fin
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def takeItemFromPlayer(itemName)
removeNamed(itemName, @global=>p_players=>p_items) // default to first player
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def removePlayerFromParty(playerName)
removeNamed(playerName, @global=>p_players)
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
export def playerHasItem(itemName) export def playerHasItem(itemName)
return scanForNamedObj(global=>p_players=>p_items, itemName) <> NULL return scanForNamedObj(global=>p_players=>p_items, itemName) <> NULL
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def partyHasPlayer(playerName)
return scanForNamedObj(global=>p_players, playerName) <> NULL
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
export def getStat(statName) export def getStat(statName)
word player word player