I have a strange issue with some code I'm using for a possible random creature generation program. (I'm using it to create and sort a database of sorts for an upcoming MMO project.)
Here's the code in its entirety...
EXAMPLE ONE:
Rem Project: Random Creature Generator
Rem Created: Friday, January 27, 2012
Rem ***** Main Source File *****
`=========================================
` RANDOM CREATURE GENERATOR
`=========================================
`CODER Rob P Mussell II
`DATE 27-JAN-2012
`DESC This is a demonstration of a game-based random creature generator
` not a 'random encounter generator' like other RPGs use in various
` places.
` This program will use a randomized system and certain reads of the
` Player and Party statistics, location of the Player/Party, and the
` generalized level(s) of the Player/Party to determine the number
` of creatures, the type and aggressive nature of the creatures, and
` the size of the creatures.
` Typically, I do not see any more than 20 creatures at any given time
` based on the above, and on the specific locales the Player/Party
` happens to be traversing at any time.
`===================
`= GLOBAL VARIABLES
`===================
GLOBAL DIM clr(16)
GLOBAL true AS BOOLEAN = 1
GLOBAL false AS BOOLEAN = 0
GLOBAL hitc AS INTEGER = 0
MaxNr = 5
`=====================
`= CONSTANT VARIABLES
`=====================
#CONSTANT d4 = 4
#CONSTANT d6 = 6
#CONSTANT d8 = 8
#CONSTANT d10 = 10
#CONSTANT d12 = 12
#CONSTANT d20 = 20
`=====================
`= USER-DEFINED TYPES
`=====================
TYPE Stat
a, b, c, d, e, f AS INTEGER
ENDTYPE
TYPE Attr
a, b, c, d, e, f AS INTEGER
ENDTYPE
TYPE Foe
aa AS Attr
ss AS Stat
hp AS INTEGER `hit points
hc AS INTEGER `hit chance
da AS INTEGER `minimum damage
dz AS INTEGER `maximum damage
lc$ AS STRING `location of creature (i.e. where it resides)
tm$ AS STRING `relative temperature (i.e. avg. ambient temp. of residence)
nr AS INTEGER `number of appearing creatures
nm$ AS STRING `creature's name
legs AS INTEGER `number of legs creature has
uprt AS BOOLEAN `0 = not upright (animal-style); 1 = upright (humanoid-style)
natw AS INTEGER `can be as many as legs, or at least 2
typ$ AS STRING `type of animal
`Insect-6; Inoct-8; Arachnid/Spider/Octopus-8; Squid-10; Horse/animal-4
csiz AS INTEGER `1 = miniscule; 2 = tiny; 3 = small; 4 = moderate; 5 = average;
`6 = medium; 7 = large; 8 = huge; 9 = enormous; 10 = gigantic;
`11 = gargantuan
ENDTYPE
`###########################################
`# SET UP VARIABLES NEEDED FOR DEMO PROGRAM
`###########################################
DIM Enemy(MaxNr) AS Foe
`---------------------------------------------
`- SET UP THE ENEMIES' STATS AND DESCRIPTIONS
`---------------------------------------------
FOR i = 1 TO MaxNr
Enemy(i).aa.a = SetAttribute() `M
Enemy(i).aa.b = SetAttribute() `S
Enemy(i).aa.c = SetAttribute() `T
Enemy(i).aa.d = SetAttribute() `A
Enemy(i).aa.e = SetAttribute() `I
Enemy(i).aa.f = SetAttribute() `K
Enemy(i).ss.a = CalcStatistic(Enemy(i).aa.a, Enemy(i).aa.b, Enemy(i).aa.c, Enemy(i).aa.d) `ATtacK
Enemy(i).ss.b = CalcStatistic(Enemy(i).aa.b, Enemy(i).aa.c, Enemy(i).aa.d, Enemy(i).aa.d) `DEFend
Enemy(i).ss.c = CalcStatistic(Enemy(i).aa.b, Enemy(i).aa.b, Enemy(i).aa.c, Enemy(i).aa.c) `HeaLTh
Enemy(i).ss.d = CalcStatistic(Enemy(i).aa.e, Enemy(i).aa.e, Enemy(i).aa.f, Enemy(i).aa.f) `TECnic (aggression)
Enemy(i).ss.e = CalcStatistic(Enemy(i).aa.a, Enemy(i).aa.b, Enemy(i).aa.d, Enemy(i).aa.d) `SPeeD
Enemy(i).ss.f = CalcStatistic(Enemy(i).aa.b, Enemy(i).aa.c, Enemy(i).aa.e, Enemy(i).aa.f) `PERception
Enemy(i).hp = Enemy(i).ss.c * 10
Enemy(i).uprt = CheckUpright()
Enemy(i).legs = CheckLegs()
Enemy(i).typ$ = CheckCreatureType(Enemy(i).legs)
loc$ = CheckLocale()
Enemy(i).lc$ = loc$
tmp$ = CheckTemp()
Enemy(i).tm$ = tmp$
Enemy(i).da = CheckBonus(Enemy(i).aa.a)
Enemy(i).dz = CheckBonus(Enemy(i).aa.a)
Enemy(i).csiz = CheckSize()
Enemy(i).nm$ = tmp$ + " " + loc$
Enemy(i).natw = GetNrAttacks()
REPEAT
CalcHitChance(Enemy(i).ss.a, Enemy(i).ss.e, Enemy(i).csiz)
UNTIL hitc > 0
Enemy(1).hc = hitc
`#######################################
`# EXAMPLE TO DETERMINE HIT CHANCE (HC)
`#######################################
`enemy's atk = 20 (attack)
`enemy's spd = 20 (speed )
`enemy's csiz = 11 ( size )
`---------------------------------------
`enemy's hc = ((20 / 4) + (20 / 4)) * (11 / 2)
` = (5 + 5) * 5.5
` = 10 * 5 ... remember, these are integers (no decimals)
` = 50 ... 50% chance to hit Player
`#######################################
NEXT
`===============
`= DISPLAY MODE
`===============
SET DISPLAY MODE 1024, 768, 32
SET TEXT FONT "Envy Code R"
SET TEXT SIZE 18
CLS
`=======================
`= SET UP COLOR CONTENT
`=======================
SetColor()
`====================
`= DISPLAY FIVE FOES
`====================
FOR i = 1 TO MaxNr
PRINT "ENEMY #"+ STR$(i) + ": " + Enemy(i).nm$ + " " + Enemy(i).typ$ + " " + STR$(Enemy(i).csiz)
PRINT "MGT." + STR$(Enemy(i).aa.a) + " STA." + STR$(Enemy(i).aa.b) + " TOU." + STR$(Enemy(i).aa.c) + " AGL." + STR$(Enemy(i).aa.d) + " INT." + STR$(Enemy(i).aa.e) + " KNO." + STR$(Enemy(i).aa.f)
PRINT "ATK." + STR$(Enemy(i).ss.a) + " DEF." + STR$(Enemy(i).ss.b) + " HLT." + STR$(Enemy(i).ss.c) + " TEC." + STR$(Enemy(i).ss.d) + " SPD." + STR$(Enemy(i).ss.e) + " PER." + STR$(Enemy(i).ss.f)
PRINT "HP " + STR$(Enemy(i).hp) + " HC " + STR$(Enemy(i).hc)
PRINT
NEXT i
`++++++++++++++++++++++++
`+ DISPLAY END CONDITION
`++++++++++++++++++++++++
INK clr(1), clr(0)
PRINT "Press [ANY] Key to Quit."
WAIT KEY
`**************
`* END PROGRAM
`**************
END
`============
`= FUNCTIONS
`============
FUNCTION Roller( sides AS INTEGER , addOne AS BOOLEAN )
temp = RND( sides )
IF temp < 0 THEN temp = 0
IF addOne = true THEN INC temp, 1
IF temp > sides THEN temp = sides
ENDFUNCTION temp
FUNCTION SetColor()
RESTORE _ColorData
FOR i = 0 to 15
READ f, g, h
clr(i) = RGB(f, g, h)
NEXT i
ENDFUNCTION
FUNCTION SetAttribute()
FOR i = 1 to 5
mp = mp + Roller(6, true)
NEXT i
IF mp < 12 THEN mp = 12
ENDFUNCTION mp
FUNCTION CheckBonus( valve AS INTEGER )
SELECT valve
CASE 30 : x = 10 : ENDCASE
CASE 29 : x = 9 : ENDCASE
CASE 28 : x = 8 : ENDCASE
CASE 27 : x = 7 : ENDCASE
CASE 26, 25 : x = 6 : ENDCASE
CASE 24, 23 : x = 5 : ENDCASE
CASE 22, 21 : x = 4 : ENDCASE
CASE 20, 19 : x = 3 : ENDCASE
CASE 18, 17, 16 : x = 2 : ENDCASE
CASE 15, 14, 13 : x = 1 : ENDCASE
CASE DEFAULT : x = 0 : ENDCASE
ENDSELECT
ENDFUNCTION x
FUNCTION CheckUpright()
tp = Roller(1, false)
ENDFUNCTION tp
FUNCTION CheckLegs()
mm = Roller(5, true)
IF mm < 1 THEN mm = 1
mm = mm * 2
ENDFUNCTION mm
FUNCTION Go2Legs()
gar = Roller(6, true)
SELECT gar
CASE 1 : t$ = "Undead" : ENDCASE
CASE 2 : t$ = "Gour Beast" : ENDCASE
CASE 3 : t$ = "Orcine" : ENDCASE
CASE 4 : t$ = "Pan Ram" : ENDCASE
CASE 5 : t$ = "Demonoid" : ENDCASE
CASE 6 : t$ = "Gelatin" : ENDCASE
CASE DEFAULT : t$ = "Draconite" : ENDCASE
ENDSELECT
ENDFUNCTION t$
FUNCTION Go4Legs()
yar = Roller(10, false)
SELECT yar
CASE 1 : t$ = "Bovine" : ENDCASE
CASE 2 : t$ = "Ursine" : ENDCASE
CASE 3 : t$ = "Porcine" : ENDCASE
CASE 4 : t$ = "Equine" : ENDCASE
CASE 5 : t$ = "Feline" : ENDCASE
CASE 6 : t$ = "Canine" : ENDCASE
CASE 7 : t$ = "Rodent" : ENDCASE
CASE 8 : t$ = "Lizard" : ENDCASE
CASE 9 : t$ = "Tortoise" : ENDCASE
CASE 0 : t$ = "Draco" : ENDCASE
CASE DEFAULT : t$ = "Rodent" : ENDCASE
ENDSELECT
ENDFUNCTION t$
FUNCTION Go6Legs()
man = Roller(3, true)
SELECT man
CASE 1 : t$ = "Insect" : ENDCASE
CASE 2 : t$ = "Mantid" : ENDCASE
CASE 3 : t$ = "Equuid" : ENDCASE
CASE DEFAULT : t$ = "Insect" : ENDCASE
ENDSELECT
ENDFUNCTION t$
FUNCTION Go8Legs()
kid = Roller(4, true)
SELECT kid
CASE 1 : t$ = "Inoct" : ENDCASE
CASE 2 : t$ = "Arachnid" : ENDCASE
CASE 3 : t$ = "Octopod" : ENDCASE
CASE 4 : t$ = "Tenticlar" : ENDCASE
CASE DEFAULT : t$ = "Inoct" : ENDCASE
ENDSELECT
ENDFUNCTION t$
FUNCTION Go10Legs()
orc = Roller(3, true)
SELECT orc
CASE 1 : t$ = "Tenticlar" : ENDCASE
CASE 2 : t$ = "Squid" : ENDCASE
CASE 3 : t$ = "Pseudopod" : ENDCASE
CASE DEFAULT : t$ = "Tenticlar" : ENDCASE
ENDSELECT
ENDFUNCTION t$
FUNCTION CheckCreatureType( value AS INTEGER )
IF value = 2 THEN temp$ = Go2Legs()
IF value = 4 THEN temp$ = Go4Legs()
IF value = 6 THEN temp$ = Go6Legs()
IF value = 8 THEN temp$ = Go8Legs()
IF value = 10 THEN temp$ = Go10Legs()
ENDFUNCTION temp$
FUNCTION CheckTemp()
ork = Roller(5, true)
SELECT ork
CASE 1 : t$ = "Polar" : ENDCASE
CASE 2 : t$ = "Arctic" : ENDCASE
CASE 3 : t$ = "Moderate" : ENDCASE
CASE 4 : t$ = "Temperate" : ENDCASE
CASE 5 : t$ = "Tropic" : ENDCASE
CASE DEFAULT : t$ = "Temperate" : ENDCASE
ENDSELECT
ENDFUNCTION t$
FUNCTION CheckLocale()
lip = Roller(20, false)
SELECT lip
CASE 1 : t$ = "Beach" : ENDCASE
CASE 2 : t$ = "Desert" : ENDCASE
CASE 3 : t$ = "Wasteland" : ENDCASE
CASE 4 : t$ = "Forest" : ENDCASE
CASE 5 : t$ = "Savannah" : ENDCASE
CASE 6 : t$ = "Plain" : ENDCASE
CASE 7 : t$ = "Valley" : ENDCASE
CASE 8 : t$ = "Foothill" : ENDCASE
CASE 9 : t$ = "Mountain" : ENDCASE
CASE 0 : t$ = "Cavern" : ENDCASE
CASE 10 : t$ = "Jungle" : ENDCASE
CASE 12 : t$ = "Underbrush" : ENDCASE
CASE 13 : t$ = "Burrow" : ENDCASE
CASE 14 : t$ = "Den" : ENDCASE
CASE 15 : t$ = "Grassland" : ENDCASE
CASE 16 : t$ = "Ruins" : ENDCASE
CASE 17 : t$ = "Lake" : ENDCASE
CASE 18 : t$ = "Sea" : ENDCASE
CASE 19 : t$ = "River" : ENDCASE
CASE 11 : t$ = "Ocean" : ENDCASE
CASE DEFAULT : t$ = "Plain" : ENDCASE
ENDSELECT
ENDFUNCTION t$
FUNCTION CheckSize()
old = Roller(11, true)
IF old < 1 THEN old = 1
ENDFUNCTION old
FUNCTION GetNrAttacks()
ad = Roller(Enemy(i).legs, true)
ad = ad / 2
IF ad < 2 THEN ad = 2
ENDFUNCTION ad
FUNCTION GetQuarters( over AS INTEGER )
result = INT(over / 4)
ENDFUNCTION result
FUNCTION GetHalves( number AS INTEGER )
junk = INT(number / 2)
ENDFUNCTION junk
FUNCTION CalcStatistic( za , zb , zc , zd AS INTEGER )
rest = GetQuarters(za + zb + zc + zd)
ENDFUNCTION rest
FUNCTION CalcHitChance( az , bz , cz AS INTEGER )
archie = GetHalves(cz)
chuck = GetQuarters(az)
barry = GetQuarters(bz)
hitc = chuck + barry
hitc = hitc * archie
ENDFUNCTION
`=======
`= DATA
`=======
_ColorData:
DATA 000,000,000 `BLACK
DATA 255,255,255 `WHITE
DATA 255,000,000 `RED
DATA 000,255,000 `GREEN
DATA 000,000,255 `BLUE
DATA 255,255,000 `YELLOW
DATA 255,000,255 `MAGENTA
DATA 000,255,255 `CYAN
DATA 128,128,128 `MID GRAY
DATA 064,064,064 `QTR GRAY
DATA 128,000,000 `MAROON
DATA 000,128,000 `PINE
DATA 000,000,128 `NAVY
DATA 128,128,000 `GOLD
DATA 128,000,128 `PURPLE
DATA 000,128,128 `DARK CYAN
Also, I tested another chunk of code that did the same things and IT WORKED...
EXAMPLE TWO:
Rem Project: RCG_MathTest
Rem Created: Friday, February 03, 2012
Rem ***** Main Source File *****
CLS
FOR i = 1 to 10
PRINT "FOE #:" + STR$(i)
atk = Roller(30, 1)
spd = Roller(30, 1)
siz = Roller(11, 1)
hitc = CalcHitChance(atk, spd, siz)
PRINT "((" + STR$(atk) + " / 4) + (" + STR$(spd) + " / 4)) * (" + STR$(siz) + " / 2) = " + STR$(hitc)
PRINT "(" + STR$(atk / 4) + " + " + STR$(spd / 4) + ") * (" + STR$(siz / 2) + ") = " + STR$(hitc)
PRINT "Atk " + STR$(atk) + " Spd " + STR$(spd) + " Siz " + STR$(siz) + " HC " + STR$(hitc)
PRINT
NEXT
WAIT KEY
END
FUNCTION CalcHitChance( aa, bb, cc AS FLOAT )
arby = GetQuarters(aa)
beny = GetQuarters(bb)
caly = GetHalves(cc)
IF caly < 1 THEN caly = 1
deny = (arby + beny) * caly
ENDFUNCTION deny
FUNCTION GetHalves( value AS FLOAT )
zr = INT(value / 2)
ENDFUNCTION zr
FUNCTION GetQuarters( nr AS FLOAT )
zs = INT(nr / 4)
ENDFUNCTION zs
FUNCTION Roller( sides AS INTEGER , addOne AS BOOLEAN )
zq = RND(sides)
IF addOne = 1 THEN INC zq, 1
IF zq > sides THEN zq = sides
IF zq < 12 THEN zq = 12
ENDFUNCTION zq
Can anyone explain why this is not working in my 1st Example while it works in my 2nd? The code generates all the needed stuff for Enemy(1), including HitChance, but nothing beyond that, the HitChance is not calculated beyond Enemy(1), but in the 2nd example, HitChance is calculated in all of the Foe output...
Please advise.
There's a thin line between Genius and Insanity.
Which side are you on? (Or is it more likely that you're balancing precariously on that line and struggling not to fall one way or the other?)