Handle singular/plural and singular(s) forms in display strings.

This commit is contained in:
Martin Haye 2015-11-19 08:27:04 -08:00
parent ddaca82733
commit 87cd0c3fd0

View File

@ -114,6 +114,7 @@ byte q_dir
// For decimal conversion and display tabbing
byte decimalBuf[7]
byte tabBuf[5]
byte isPlural
///////////////////////////////////////////////////////////////////////////////////////////////////
// Definitions used by assembly code
@ -134,6 +135,7 @@ DEBUG = 0
; General use
tmp = $2
pTmp = $4
ysav = $34
ysav1 = $35
; 16-bit random number seed - incremented by ROM kbd routine
@ -250,6 +252,8 @@ asm pushAuxStr // params: none; ret: $200 (inbuf)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// String building for display with the font engine. Includes plurality processing to handily
// handle things like "Dirt bag(s)" and "his/their"
asm buildString
+asmPlasm 1
sta cswl
@ -269,12 +273,78 @@ asm addToString
end
asm finishString
+asmPlasm 0
jsr setvid
!zone {
+asmPlasm 1
sta tmp ; save isPlural flag
jsr setvid ; put the cout vector back to default
bit monrts ; V flag for prev-is-punctuation
ldy #1 ; dest offset in Y
ldx #1 ; source offset in X
cpx inbuf
beq + ; only process if string has at least 1 char
bcs .done
+ sty tmp+1 ; offset of last punctuation
.fetch lda inbuf,x
cmp #"("
bne .notpar
bvs .notpar ; skip paren processing right punctuation
lda tmp ; check isPlural flag
bne .plurpr
- lda inbuf,x ; it's singular, so skip everything in parens
cmp #")"
beq .next
inx
cpx inbuf
bne -
beq .done ; handle missing trailing paren
.plurpr inx ; it's plural, so copy everything within the parens
lda inbuf,x ; copy characters
cpx inbuf ; handle missing trailing paren
beq .store
cmp #")" ; go until we reach ending paren
beq .next
sta inbuf,y
iny
bne .plurpr ; always taken
.notpar cmp #"/"
bne .notsl
bvs .notsl ; skip slash processing right after punctuation
lda tmp ; check isPlural flag
bne .plursl
- inx ; loop that skips plural form
cpx inbuf
beq +
bcs .done ; handle end of string
+ lda inbuf,x
cmp #"A" ; eat letters (and stop when we hit punctuation)
bcs -
bcc .store ; copy the ending punctuation and continue normal processing
.plursl ldy tmp+1 ; erase singular form by backing up to prev punc
iny ; plus 1 to retain prev punc
bne .next ; resume regular copying of the plural form
.notsl cmp #"A" ; if <= ASCII "A", consider it punctuation
bcc +
clv ; clear last-is-punc flag
bvc .store ; always taken
+ bit monrts ; set prev-is-punc flag
sty tmp+1 ; save dest offset of last punctuation
.store sta inbuf,y ; save to dest
iny
.next inx
cpx inbuf ; compare src offset to length
bcc .fetch ; loop while less than
beq .fetch ; or equal
.done dey
sty inbuf ; save new length
lda #<inbuf
ldy #>inbuf
ldx inbuf
rts
}
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -782,7 +852,7 @@ def printf3(str, arg1, arg2, arg3); printf4(str, arg1, arg2, arg3, 0); end
def displayf4(str, arg1, arg2, arg3, arg4)
buildString(@addToString)
printf4(str, arg1, arg2, arg3, arg4)
displayStr(finishString())
displayStr(finishString(isPlural))
end
def displayf1(str, arg1); displayf4(str, arg1, 0, 0, 0); end
@ -1463,15 +1533,13 @@ include "playtype.pla"
///////////////////////////////////////////////////////////////////////////////////////////////////
def combat()
word p, p2
word p, p2, n, s
// Create the enemy group(s).
global=>p_enemyGroups = NULL
addToList(global + p_enemyGroups, new_EnemyGroup_Dirt_Bags())
// Display portrait of first group
printf1("enemy: $%x\n", global=>p_enemyGroups=>p_enemies)
printf1("portrait: %d\n", global=>p_enemyGroups=>p_enemies=>ba_images[0])
setPortrait(global=>p_enemyGroups=>p_enemies=>ba_images[0])
// Say who we're fighting
@ -1480,7 +1548,21 @@ def combat()
displayStr("Uh oh, it's gunna' be one of THOSE days.\n")
p = global=>p_enemyGroups
while p
displayf2("%d %s draw their weapons on you!\n", countList(p=>p_enemies), p=>p_enemies=>s_name)
n = countList(p=>p_enemies)
isPlural = (n <> 1)
when rand16() % 5
is 0
s = "From out of nowhere comes/come %d %s to have their way with you!\n"; break
is 1
s = "%d nasty %s comes/come to stake their claim on you!\n"; break
is 2
s = "It's gone from bad to worse, %d %s is/are looking for trouble!\n"; break
is 3
s = "%d %s is/are sniffing you out, shoulda' bathed last week!\n"; break
otherwise
s = "You mutter a curse under your breath as you see %d %s approach you with malice!\n"; break
wend
displayf2(s, n, p=>p_enemies=>s_name)
p = p=>p_nextObj
loop