Improved plural processing.

This commit is contained in:
Martin Haye 2017-08-25 08:16:06 -07:00
parent ffa1bb9afe
commit 865c2fe8f2
4 changed files with 22 additions and 31 deletions

View File

@ -132,7 +132,7 @@ def rollPlayerHit(pPlayer, pWeapon, pEnemy, sAction)
roll = rollPercentileWithLuck(-(pPlayer->b_luck)) // luck can reduce roll = increase chance to hit roll = rollPercentileWithLuck(-(pPlayer->b_luck)) // luck can reduce roll = increase chance to hit
if combatDebug; displayf2("Roll=%d, need <%d\n", roll, abs(roll < chance)); getUpperKey(); fin if combatDebug; displayf2("Roll=%d, need <%d\n", roll, abs(roll < chance)); getUpperKey(); fin
if roll >= chance if roll >= chance
setPlural(0) isPlural = FALSE
displayf3("\n%s %s at %s but misses.\n", pPlayer=>s_name, sAction, pEnemy=>s_name) displayf3("\n%s %s at %s but misses.\n", pPlayer=>s_name, sAction, pEnemy=>s_name)
return FALSE return FALSE
fin fin
@ -143,7 +143,7 @@ end
def rollEnemyDodge(pPlayer, pEnemy, sAction) def rollEnemyDodge(pPlayer, pEnemy, sAction)
// Enemy chance to dodge is taken from their chance to hit divided by 2 // Enemy chance to dodge is taken from their chance to hit divided by 2
if (rand16() % 100) < (pEnemy->b_chanceToHit / 2) if (rand16() % 100) < (pEnemy->b_chanceToHit / 2)
setPlural(0) isPlural = FALSE
displayf3("\n%s %s at %s, ", pPlayer=>s_name, sAction, pEnemy=>s_name) displayf3("\n%s %s at %s, ", pPlayer=>s_name, sAction, pEnemy=>s_name)
displayf1("but %s dodges.\n", pEnemy=>s_name) displayf1("but %s dodges.\n", pEnemy=>s_name)
return TRUE return TRUE
@ -157,7 +157,7 @@ def damageEnemy(pPlayer, pEnemy, dmg, sAction)#0
displayf3("\nenemy health: %d-%d=%d\n", pEnemy=>w_health, dmg, pEnemy=>w_health-dmg) displayf3("\nenemy health: %d-%d=%d\n", pEnemy=>w_health, dmg, pEnemy=>w_health-dmg)
getUpperKey getUpperKey
fin fin
setPlural(0) isPlural = FALSE
buildString(@addToString) buildString(@addToString)
printf3("\n%s %s %s ", pPlayer=>s_name, sAction, pEnemy=>s_name) printf3("\n%s %s %s ", pPlayer=>s_name, sAction, pEnemy=>s_name)
printf1("for %d damage.", dmg) printf1("for %d damage.", dmg)
@ -290,7 +290,7 @@ def reload(pl, pWeapon, echo)#0
word item word item
byte orig, n byte orig, n
setPlural(FALSE) isPlural = FALSE
// If ammo type is null, it means weapon doesn't use ammo in traditional sense. // If ammo type is null, it means weapon doesn't use ammo in traditional sense.
if !pWeapon=>s_ammoKind if !pWeapon=>s_ammoKind
@ -366,7 +366,7 @@ def displayOpponents()#0
fin fin
first = FALSE first = FALSE
count = countListFiltered(p=>p_enemies, p_nextObj, @canFight) count = countListFiltered(p=>p_enemies, p_nextObj, @canFight)
setPlural(count <> 1) isPlural = count <> 1
if (p=>p_enemies=>r_groupSize == 0) if (p=>p_enemies=>r_groupSize == 0)
displayf2("%s at %d'", p=>p_enemies=>s_name, p->b_enemyGroupRange) displayf2("%s at %d'", p=>p_enemies=>s_name, p->b_enemyGroupRange)
else else
@ -678,7 +678,7 @@ def enemyCombatTurn(pe)#1
pl = randomFromListFiltered(global=>p_players, p_nextObj, @canFight) pl = randomFromListFiltered(global=>p_players, p_nextObj, @canFight)
if !pl; return FALSE; fin if !pl; return FALSE; fin
setPlural(FALSE) isPlural = FALSE
displayf3("\n%s %s %s ", pe=>s_name, pe=>s_attackText, pl=>s_name) displayf3("\n%s %s %s ", pe=>s_name, pe=>s_attackText, pl=>s_name)
// Roll to hit // Roll to hit
@ -887,10 +887,10 @@ def collectLootAndXP()#2
fin fin
if addItem(global=>p_players, pItem) if addItem(global=>p_players, pItem)
if pItem->t_type == TYPE_STUFF and pItem=>w_count > 1 if pItem->t_type == TYPE_STUFF and pItem=>w_count > 1
setPlural(TRUE) isPlural = TRUE
displayf2("You find %d %s! ", pItem=>w_count, pItem=>s_name) displayf2("You find %d %s! ", pItem=>w_count, pItem=>s_name)
else else
setPlural(FALSE) isPlural = FALSE
displayf2("You find %s%s! ", anOrA(pItem=>s_name), pItem=>s_name) displayf2("You find %s%s! ", anOrA(pItem=>s_name), pItem=>s_name)
fin fin
fin fin
@ -938,7 +938,7 @@ def startCombat(mapCode)#1
p = global=>p_enemyGroups p = global=>p_enemyGroups
while p while p
n = countList(p=>p_enemies) n = countList(p=>p_enemies)
setPlural(n <> 1) isPlural = n <> 1
s = callGlobalFunc(GS_ENEMY_INTRO, 0, 0, 0) s = callGlobalFunc(GS_ENEMY_INTRO, 0, 0, 0)
displayf2(s, n, p=>p_enemies=>s_name) displayf2(s, n, p=>p_enemies=>s_name)
p = p=>p_nextObj p = p=>p_nextObj

View File

@ -115,7 +115,6 @@ import gamelib
predef setMap(is3D, num, x, y, dir)#0 predef setMap(is3D, num, x, y, dir)#0
predef setMapWindow()#0 predef setMapWindow()#0
predef setBigWindow()#0 predef setBigWindow()#0
predef setPlural(flg)#0
predef setPortrait(portraitNum)#0 predef setPortrait(portraitNum)#0
predef setScriptInfo(mapName, trigTbl, wdt, hgt)#0 predef setScriptInfo(mapName, trigTbl, wdt, hgt)#0
predef setSky(num)#0 predef setSky(num)#0
@ -147,6 +146,7 @@ import gamelib
byte portraitNum byte portraitNum
word pGodModule word pGodModule
word typeHash word typeHash
byte isPlural
/////////// Shared string constants ////////////// /////////// Shared string constants //////////////

View File

@ -76,7 +76,7 @@ byte renderLoaded = FALSE
byte texturesLoaded = FALSE byte texturesLoaded = FALSE
byte textDrawn = FALSE byte textDrawn = FALSE
byte textClearCountdown = 0 byte textClearCountdown = 0
byte isPlural = 0 // valid values: 0 or $40 export byte isPlural = 0 // valid values: 0 or $40
byte inScript = FALSE byte inScript = FALSE
export word skyNum = 9 export word skyNum = 9
@ -421,8 +421,10 @@ export asm finishString(isPlural)#1
dey ; undo copy of the paren dey ; undo copy of the paren
stx tmp+1 ; save position in input stx tmp+1 ; save position in input
bit tmp ; set copy flag (V) initially to same as isPlural flag
dex ; needed for failsafe operation dex ; needed for failsafe operation
lda tmp ; set copy flag (V) initially
bne .findsl ; to same as isPlural flag
clv
.findsl ; see if there's a slash within the parens .findsl ; see if there's a slash within the parens
inx inx
cpx inbuf cpx inbuf
@ -436,7 +438,7 @@ export asm finishString(isPlural)#1
plp plp
+ cmp #")" ; scan until ending paren + cmp #")" ; scan until ending paren
beq + beq +
cpx inbuf cpx inbuf
bcc .findsl ; loop to scan next char bcc .findsl ; loop to scan next char
bcs .done ; failsafe: handle missing end-paren (always taken) bcs .done ; failsafe: handle missing end-paren (always taken)
+ ldx tmp+1 ; get back to start of parens + ldx tmp+1 ; get back to start of parens
@ -454,17 +456,15 @@ export asm finishString(isPlural)#1
plp plp
bcs .plup ; always taken bcs .plup ; always taken
+ cmp #")" + cmp #")"
beq + ; stop at closing paren beq .notpar ; stop at closing paren
bvc .plup ; if not in copy mode, skip copy bvc .plup ; if not in copy mode, skip copy
iny iny
sta inbuf,y ; else do copy sta inbuf,y ; else do copy
bne .plup ; always taken bne .plup ; always taken
+ dey ; to offset upcoming iny, since we already copied
.notpar .notpar
bit fixedRTS; set prev-is-alpha flag bit fixedRTS; set prev-is-alpha flag
cmp #"A" ; if >= ASCII "A", consider it alpha cmp #"A" ; if >= ASCII "A", consider it alpha
bcc .next bcs .next
clv ; clear prev-is-alpha flag clv ; clear prev-is-alpha flag
.next .next
@ -1071,16 +1071,6 @@ export def getStringResponse()#1
return mmgr(HEAP_INTERN, $200) return mmgr(HEAP_INTERN, $200)
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Setter functions for library use
export def setPlural(flg)#0
if flg
isPlural = $40
else
isPlural = 0
fin
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Convert signed decimal to string in decimalBuf (@decimalBuf returned) // Convert signed decimal to string in decimalBuf (@decimalBuf returned)
def convertDec(n)#1 def convertDec(n)#1

View File

@ -888,13 +888,14 @@ end
// For non-countable items, display singular name. // For non-countable items, display singular name.
// For countable "stuff" (e.g. ammo), display the count and appropriate singular or plural name. // For countable "stuff" (e.g. ammo), display the count and appropriate singular or plural name.
def _displayItemName(pItem)#1 def _displayItemName(pItem)#1
isPlural = FALSE
if pItem->t_type == TYPE_STUFF if pItem->t_type == TYPE_STUFF
setPlural(pItem=>w_count <> 1) isPlural = pItem=>w_count <> 1
rawDisplayf1("%d ", pItem=>w_count) rawDisplayf1("%d ", pItem=>w_count)
else
setPlural(FALSE)
fin fin
rawDisplayf1("%s", pItem=>s_name) // use displayf to get proper plural processing buildString(@addToString)
printf1("%s", pItem=>s_name) // need proper plural processing
rawDisplayStr(finishString(isPlural))
return 0 return 0
end end