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_take_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_increase_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');
}
};
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'] = {
init: function () {
this.setHelpUrl(Mythos.helpUrl);

View File

@ -61,6 +61,7 @@ class A2PackPartitions
def fixups = [:] // module name to fixup.num, fixup.buf
def itemNameToFunc = [:]
def playerNameToFunc = [:]
def lastSysModule
@ -1752,8 +1753,10 @@ class A2PackPartitions
// Number all the maps and record them with names
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)
allPlayerFuncs(dataIn.global.sheets.sheet)
// Pack each map This uses the image and tile maps filled earlier.
println "Packing maps."
@ -2100,7 +2103,7 @@ end
"${parseByteAttr(row, name)}))")
}
else if (name =~ /^item-/) {
def itemFunc = itemNameToFunc[val]
def itemFunc = itemNameToFunc[val.trim().toLowerCase()]
assert itemFunc : "Can't locate item '$val'"
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 ->
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 ->
itemNameToFunc[row.@name.trim()] = func
itemNameToFunc[row.@name.trim().toLowerCase()] = func
}
// And return the funcs.
@ -2301,7 +2304,7 @@ end
replaceIfDiff("build/src/plasma/gen_items.pla")
}
def genAllPlayers(sheets)
def allPlayerFuncs(sheets)
{
// Grab all the raw data
def funcs = []
@ -2309,6 +2312,17 @@ end
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
new File("build/src/plasma/gen_players.plh.new").withWriter { out ->
out.println("// Generated code - DO NOT MODIFY BY HAND\n")
@ -2679,6 +2693,7 @@ end
out << "include \"../plasma/playtype.plh\"\n"
out << "include \"../plasma/gen_images.plh\"\n\n"
out << "include \"../plasma/gen_items.plh\"\n\n"
out << "include \"../plasma/gen_players.plh\"\n\n"
out << "word global\n"
}
@ -2871,6 +2886,10 @@ end
packGiveItem(blk); break
case 'interaction_take_item':
packTakeItem(blk); break
case 'interaction_add_player':
packAddPlayer(blk); break
case 'interaction_remove_player':
packRemovePlayer(blk); break
case 'interaction_increase_stat':
case 'interaction_decrease_stat':
packChangeStat(blk); break
@ -2942,7 +2961,7 @@ end
def packGiveItem(blk)
{
def name = getSingle(blk.field, 'NAME').text().trim()
def itemFunc = itemNameToFunc[name]
def itemFunc = itemNameToFunc[name.toLowerCase()]
assert itemFunc : "Can't locate item '$name'"
outIndented("giveItemToPlayer($itemFunc)\n")
}
@ -2950,11 +2969,25 @@ end
def packTakeItem(blk)
{
def name = getSingle(blk.field, 'NAME').text().trim()
def itemFunc = itemNameToFunc[name]
assert itemFunc : "Can't locate item '$name'"
assert itemNameToFunc.containsKey(name.toLowerCase()) : "Can't locate item '$name'"
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) {
switch (name.toLowerCase().trim()) {
case "intelligence": return "@S_INTELLIGENCE"; return
@ -3055,10 +3088,18 @@ end
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)})"
}
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)
{
switch (blk.@type) {
@ -3083,6 +3124,9 @@ end
case 'interaction_has_item':
packHasItem(blk)
break
case 'interaction_has_player':
packHasPlayer(blk)
break
case 'interaction_get_stat':
packGetStat(blk)
break

View File

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

View File

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

View File

@ -2340,7 +2340,7 @@ export def payGold(amount)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def scanForNamedObj(p_obj, name)
export def scanForNamedObj(p_obj, name)
while p_obj
if streqi(p_obj=>s_name, name); return p_obj; fin
p_obj = p_obj=>p_nextObj
@ -2349,46 +2349,72 @@ def scanForNamedObj(p_obj, name)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def giveItemToPlayer(itemFunc)
word p_module, funcTbl, func, p_item
export def createAndAddUnique(moduleID, creationFuncNum, pList)
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
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)
// 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()
func = *(funcTbl + itemFunc)
p_item = func()
func = *(funcTbl + creationFuncNum)
printf1("func=$%x\n", func)
p_thing = func()
printf1("p_thing=$%x\n", p_thing)
// Avoid giving duplicate items.
if !scanForNamedObj(global=>p_players=>p_items, p_item=>s_name)
addToList(@global=>p_players=>p_items, p_item)
// Avoid giving duplicate things.
if !scanForNamedObj(*pList, p_thing=>s_name)
addToList(pList, p_thing)
fin
// Finished with the item module now.
// Finished with the module now.
mmgr(FREE_MEMORY, p_module)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def takeItemFromPlayer(itemName)
word p_player
word p_item
p_player = global=>p_players // default to first player
p_item = scanForNamedObj(p_player=>p_items, itemName)
if p_item
removeFromList(@p_player=>p_items, p_item)
export def giveItemToPlayer(itemFuncNum)
createAndAddUnique(MODULE_GEN_ITEMS, itemFuncNum, @global=>p_players=>p_items) // def: 1st player
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def addPlayerToParty(playerFuncNum)
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
printf1("Warning: couldn't find item '%s' to take.\n", itemName)
printf1("Warning: couldn't find '%s' to remove.\n", name)
fin
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)
return scanForNamedObj(global=>p_players=>p_items, itemName) <> NULL
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def partyHasPlayer(playerName)
return scanForNamedObj(global=>p_players, playerName) <> NULL
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def getStat(statName)
word player