Fixed portrait confusion, and moved enemy selection code to combat module.

This commit is contained in:
Martin Haye 2016-01-01 10:18:33 -08:00
parent 7e9bcabcc1
commit ecc9cc2016
3 changed files with 49 additions and 48 deletions

View File

@ -1529,8 +1529,8 @@ class PackPartitions
out.println(" return makeEnemy(" + out.println(" return makeEnemy(" +
"\"$name\", " + "\"$name\", " +
"${parseDice(hitPoints)}, " + "${parseDice(hitPoints)}, " +
"PORTRAIT_${humanNameToSymbol(image1, true)}, " + "PO${humanNameToSymbol(image1, false)}, " +
(image2.size() > 0 ? "PORTRAIT_${humanNameToSymbol(image2, true)}, " : "0, ") + (image2.size() > 0 ? "PO${humanNameToSymbol(image2, false)}, " : "0, ") +
"$attackTypeCode, " + "$attackTypeCode, " +
"\"$attackText\", " + "\"$attackText\", " +
"${range.replace("'", "").toInteger()}, " + "${range.replace("'", "").toInteger()}, " +
@ -1562,7 +1562,7 @@ class PackPartitions
} }
if (animFrameNum <= 1) { if (animFrameNum <= 1) {
++portraitNum ++portraitNum
out.println "const PORTRAIT_${humanNameToSymbol(name, true)} = $portraitNum" out.println "const PO${humanNameToSymbol(name, false)} = $portraitNum"
} }
} }
} }

View File

@ -11,6 +11,8 @@
include "gamelib.plh" include "gamelib.plh"
include "playtype.plh" include "playtype.plh"
include "gen_images.plh" include "gen_images.plh"
include "gen_enemies.plh"
include "gen_modules.plh"
word global word global
@ -171,7 +173,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def displayOption(key, str) def displayOption(key, str)
buildString(@addToString) buildString(@addToString)
printf2(" (%c)^T033%s\n", key, str) printf2("\n (%c)^T033%s ", key, str)
rawDisplayStr(finishString(0)) rawDisplayStr(finishString(0))
end end
@ -217,7 +219,6 @@ def playerCombatChoose(pl)
otherwise otherwise
displayStr("Decisions, decisions..."); break displayStr("Decisions, decisions..."); break
wend wend
displayStr("\n")
displayOption('M', "Melee") displayOption('M', "Melee")
if pWeapon if pWeapon
@ -240,6 +241,7 @@ def playerCombatChoose(pl)
while TRUE while TRUE
pl->b_combatChoice = getUpperKey() pl->b_combatChoice = getUpperKey()
displayStr("\n")
when pl->b_combatChoice when pl->b_combatChoice
is 'M' is 'M'
return return
@ -385,19 +387,54 @@ def determineCombatOrder()
loop loop
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
def makeEnemyGroup(enemyFunc)
word p, enem, groupSize
p = mmgr(HEAP_ALLOC, TYPE_ENEMY_GROUP)
enem = enemyFunc()
p->b_enemyGroupRange = max(1, rand16() % (enem->b_enemyAttackRange))
if enem=>r_groupSize == 0 // handle unique enemies
groupSize = 1
else
groupSize = rollDice(enem=>r_groupSize)
fin
addToList(p + p_enemies, enem)
while groupSize > 1
addToList(p + p_enemies, enemyFunc())
groupSize = groupSize - 1
loop
return p
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def makeAllEnemies()
word enemiesModule
word enemyNum, enemyTbl, enemyFunc
enemiesModule = mmgr(QUEUE_LOAD, MODULE_GEN_ENEMIES<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, 1) // 1 = keep open
global=>p_enemyGroups = NULL
enemyNum = rand16() % NUM_ENEMIES
enemyTbl = enemiesModule()
enemyFunc = *((enemyNum<<1) + enemyTbl)
addToList(@global=>p_enemyGroups, makeEnemyGroup(enemyFunc))
mmgr(FREE_MEMORY, enemiesModule)
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def startCombat() def startCombat()
word p, p2, n, s word p, p2, n, s
// Setup // Setup
isFleeing = FALSE isFleeing = FALSE
makeAllEnemies()
// Display portrait of first group // Display portrait of first group
setPortrait(global=>p_enemyGroups=>p_enemies->b_image) setPortrait(global=>p_enemyGroups=>p_enemies->b_image)
// If portrait was already in memory, the memory mgr load might still be open. Close it.
mmgr(FINISH_LOAD, 0)
// We're going to do all our text drawing in window 2. Also, might as well // We're going to do all our text drawing in window 2. Also, might as well
// set everything up so that the map gets redrawn when combat finishes. // set everything up so that the map gets redrawn when combat finishes.
setWindow2() setWindow2()
@ -447,10 +484,10 @@ def startCombat()
while TRUE while TRUE
n = getUpperKey() n = getUpperKey()
if n == 'B' if n == 'B'
displayStr("\nBattle!\n") displayStr("\n\nBattle! \n")
return TRUE return TRUE
elsif n == 'F' elsif n == 'F'
displayStr("\nCoward.") displayStr("\n\nCoward. ")
return FALSE return FALSE
fin fin
beep() beep()
@ -481,7 +518,7 @@ def doCombat()
p = global=>p_combatFirst p = global=>p_combatFirst
while p while p
if !nPlayersFighting if !nPlayersFighting
setPortrait(PORTRAIT_DEATH) setPortrait(POdeath)
when rand16() % 2 when rand16() % 2
is 0 is 0
displayStr("\nYou bought the farm, with your life! Thanks for playing! Reload last save?\n"); break displayStr("\nYou bought the farm, with your life! Thanks for playing! Reload last save?\n"); break
@ -495,7 +532,7 @@ def doCombat()
fin fin
reboot() reboot()
elsif !nEnemiesFighting elsif !nEnemiesFighting
setPortrait(PORTRAIT_COMBATWIN) setPortrait(POcombatwin)
when rand16() % 3 when rand16() % 3
is 0 is 0
displayStr("\nYou survive the ordeal and rifle through the carnage.\n"); break displayStr("\nYou survive the ordeal and rifle through the carnage.\n"); break

View File

@ -1869,31 +1869,8 @@ def _makeEnemy(name, healthDice, image0, image1, attackType, attackText, attackR
return p return p
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
def makeEnemyGroup(enemyFunc)
word p, enem, groupSize
p = mmgr(HEAP_ALLOC, TYPE_ENEMY_GROUP)
enem = enemyFunc()
p->b_enemyGroupRange = max(1, rand16() % (enem->b_enemyAttackRange))
if enem=>r_groupSize == 0 // handle unique enemies
groupSize = 1
else
groupSize = rollDice(enem=>r_groupSize)
fin
addToList(p + p_enemies, enem)
while groupSize > 1
addToList(p + p_enemies, enemyFunc())
groupSize = groupSize - 1
loop
return p
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def testCombat() def testCombat()
word globalScripts
word enemiesModule
word enemyNum, enemyTbl, enemyFunc
word combatEngine word combatEngine
word x, y word x, y
byte dir byte dir
@ -1905,21 +1882,8 @@ def testCombat()
mmgr(RESET_MEMORY, 0) mmgr(RESET_MEMORY, 0)
renderLoaded = FALSE renderLoaded = FALSE
combatEngine = mmgr(QUEUE_LOAD, MODULE_COMBAT<<8 | RES_TYPE_MODULE) combatEngine = mmgr(QUEUE_LOAD, MODULE_COMBAT<<8 | RES_TYPE_MODULE)
globalScripts = mmgr(QUEUE_LOAD, MODULE_GLOBAL_SCRIPTS<<8 | RES_TYPE_MODULE)
enemiesModule = mmgr(QUEUE_LOAD, MODULE_GEN_ENEMIES<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, 1) // 1 = keep open mmgr(FINISH_LOAD, 1) // 1 = keep open
// Create the enemy group(s).
global=>p_enemyGroups = NULL
enemyNum = rand16() % NUM_ENEMIES
enemyTbl = enemiesModule()
enemyFunc = *((enemyNum<<1) + enemyTbl)
addToList(@global=>p_enemyGroups, makeEnemyGroup(enemyFunc))
// No need for the global scripts now that everything has been created
mmgr(FREE_MEMORY, globalScripts)
mmgr(FREE_MEMORY, enemiesModule)
// Run the combat engine // Run the combat engine
combatEngine() combatEngine()