11-09-2022, 07:18 AM
I've found SGN to frequently be quite useful. One of my better success stories in the use of SGN was this little snippet from a role playing character generator.
While it doesn't look like much to a casual observer, those two equations essentially replaced 16 lines of SELECT CASE block. Oh yes, and _CEIL was new to me when this was written too.
Code: (Select All)
FUNCTION Bonus% (mode AS INTEGER, stat AS INTEGER, PCin AS INTEGER)
' Returns the multiplier for characteristic based attributes.
' as per the following table.
' Characteristic Value {char(stat, PCin).value}
' 1-4 5-8 9-12 13-16 17-20 each +4
'Mode
'Pri [ 1] -2 -1 0 1 2 +1
'Pri-[-1] 2 1 0 -1 -2 -1
'Sec [ 2] -1 0 0 0 1 +1
'Sec-[-2] 1 0 0 0 -1 -1
' Use straight for hit points and multiply by 5 for skill category modifiers.
' mode: 1= primary 2= secondary -1= negative primary -2= negative secondary
' stat passes the index number of the characteristic in question
' PCin passes the PC index usually ActPC but also a loop control from
' Delete_PC removal routine
v% = (_CEIL(char(stat, PCin).value / 4) - 3) * SGN(mode)
Bonus% = v% - (ABS(mode) - 1) * SGN(v%)
END FUNCTION 'Bonus%
While it doesn't look like much to a casual observer, those two equations essentially replaced 16 lines of SELECT CASE block. Oh yes, and _CEIL was new to me when this was written too.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
sha_na_na_na_na_na_na_na_na_na: