From 865c2fe8f246ddff0724d6df5313d347cd4d1115 Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Fri, 25 Aug 2017 08:16:06 -0700 Subject: [PATCH] Improved plural processing. --- Platform/Apple/virtual/src/plasma/combat.pla | 18 +++++++------- Platform/Apple/virtual/src/plasma/gamelib.plh | 2 +- .../Apple/virtual/src/plasma/gameloop.pla | 24 ++++++------------- Platform/Apple/virtual/src/plasma/party.pla | 9 +++---- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/Platform/Apple/virtual/src/plasma/combat.pla b/Platform/Apple/virtual/src/plasma/combat.pla index 83ab59a2..e0b8a604 100644 --- a/Platform/Apple/virtual/src/plasma/combat.pla +++ b/Platform/Apple/virtual/src/plasma/combat.pla @@ -132,7 +132,7 @@ def rollPlayerHit(pPlayer, pWeapon, pEnemy, sAction) 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 roll >= chance - setPlural(0) + isPlural = FALSE displayf3("\n%s %s at %s but misses.\n", pPlayer=>s_name, sAction, pEnemy=>s_name) return FALSE fin @@ -143,7 +143,7 @@ end def rollEnemyDodge(pPlayer, pEnemy, sAction) // Enemy chance to dodge is taken from their chance to hit divided by 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) displayf1("but %s dodges.\n", pEnemy=>s_name) 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) getUpperKey fin - setPlural(0) + isPlural = FALSE buildString(@addToString) printf3("\n%s %s %s ", pPlayer=>s_name, sAction, pEnemy=>s_name) printf1("for %d damage.", dmg) @@ -290,7 +290,7 @@ def reload(pl, pWeapon, echo)#0 word item byte orig, n - setPlural(FALSE) + isPlural = FALSE // If ammo type is null, it means weapon doesn't use ammo in traditional sense. if !pWeapon=>s_ammoKind @@ -366,7 +366,7 @@ def displayOpponents()#0 fin first = FALSE count = countListFiltered(p=>p_enemies, p_nextObj, @canFight) - setPlural(count <> 1) + isPlural = count <> 1 if (p=>p_enemies=>r_groupSize == 0) displayf2("%s at %d'", p=>p_enemies=>s_name, p->b_enemyGroupRange) else @@ -678,7 +678,7 @@ def enemyCombatTurn(pe)#1 pl = randomFromListFiltered(global=>p_players, p_nextObj, @canFight) if !pl; return FALSE; fin - setPlural(FALSE) + isPlural = FALSE displayf3("\n%s %s %s ", pe=>s_name, pe=>s_attackText, pl=>s_name) // Roll to hit @@ -887,10 +887,10 @@ def collectLootAndXP()#2 fin if addItem(global=>p_players, pItem) 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) else - setPlural(FALSE) + isPlural = FALSE displayf2("You find %s%s! ", anOrA(pItem=>s_name), pItem=>s_name) fin fin @@ -938,7 +938,7 @@ def startCombat(mapCode)#1 p = global=>p_enemyGroups while p n = countList(p=>p_enemies) - setPlural(n <> 1) + isPlural = n <> 1 s = callGlobalFunc(GS_ENEMY_INTRO, 0, 0, 0) displayf2(s, n, p=>p_enemies=>s_name) p = p=>p_nextObj diff --git a/Platform/Apple/virtual/src/plasma/gamelib.plh b/Platform/Apple/virtual/src/plasma/gamelib.plh index ed241439..b1860042 100644 --- a/Platform/Apple/virtual/src/plasma/gamelib.plh +++ b/Platform/Apple/virtual/src/plasma/gamelib.plh @@ -115,7 +115,6 @@ import gamelib predef setMap(is3D, num, x, y, dir)#0 predef setMapWindow()#0 predef setBigWindow()#0 - predef setPlural(flg)#0 predef setPortrait(portraitNum)#0 predef setScriptInfo(mapName, trigTbl, wdt, hgt)#0 predef setSky(num)#0 @@ -147,6 +146,7 @@ import gamelib byte portraitNum word pGodModule word typeHash + byte isPlural /////////// Shared string constants ////////////// diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index 8a22cbf1..646cc833 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -76,7 +76,7 @@ byte renderLoaded = FALSE byte texturesLoaded = FALSE byte textDrawn = FALSE byte textClearCountdown = 0 -byte isPlural = 0 // valid values: 0 or $40 +export byte isPlural = 0 // valid values: 0 or $40 byte inScript = FALSE export word skyNum = 9 @@ -421,8 +421,10 @@ export asm finishString(isPlural)#1 dey ; undo copy of the paren stx tmp+1 ; save position in input - bit tmp ; set copy flag (V) initially to same as isPlural flag 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 inx cpx inbuf @@ -436,7 +438,7 @@ export asm finishString(isPlural)#1 plp + cmp #")" ; scan until ending paren beq + - cpx inbuf + cpx inbuf bcc .findsl ; loop to scan next char bcs .done ; failsafe: handle missing end-paren (always taken) + ldx tmp+1 ; get back to start of parens @@ -454,17 +456,15 @@ export asm finishString(isPlural)#1 plp bcs .plup ; always taken + cmp #")" - beq + ; stop at closing paren + beq .notpar ; stop at closing paren bvc .plup ; if not in copy mode, skip copy iny sta inbuf,y ; else do copy bne .plup ; always taken -+ dey ; to offset upcoming iny, since we already copied - .notpar bit fixedRTS; set prev-is-alpha flag cmp #"A" ; if >= ASCII "A", consider it alpha - bcc .next + bcs .next clv ; clear prev-is-alpha flag .next @@ -1071,16 +1071,6 @@ export def getStringResponse()#1 return mmgr(HEAP_INTERN, $200) 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) def convertDec(n)#1 diff --git a/Platform/Apple/virtual/src/plasma/party.pla b/Platform/Apple/virtual/src/plasma/party.pla index 3a1571eb..ed554e35 100644 --- a/Platform/Apple/virtual/src/plasma/party.pla +++ b/Platform/Apple/virtual/src/plasma/party.pla @@ -888,13 +888,14 @@ end // For non-countable items, display singular name. // For countable "stuff" (e.g. ammo), display the count and appropriate singular or plural name. def _displayItemName(pItem)#1 + isPlural = FALSE if pItem->t_type == TYPE_STUFF - setPlural(pItem=>w_count <> 1) + isPlural = pItem=>w_count <> 1 rawDisplayf1("%d ", pItem=>w_count) - else - setPlural(FALSE) 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 end