in reply to Creating a random generator
Here is an update to what I posted previously in this thread. With all the changes made, this is hopefully more understandable. Because of the length of the script, I have broken it down into several code blocks. Notes are at the end on areas where work still needs to be done. Comments from within the code will be pointing to those notes.
This first code block is the head of the script.
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; use CGI; use CGI::Carp qw(fatalsToBrowser); use Games::Dice qw(roll); use HTML::Template; use Lingua::EN::Inflect qw(PL PL_N PL_V PL_ADJ NO NUM PL_eq PL_N_eq PL +_V_eq PL_ADJ_eq A AN PART_PRES ORD NUMWORDS inflect classical def_nou +n def_verb def_adj def_a def_an); use B; =pod =head1 NAME F<rg_mutate.pl> =head1 AUTHOR Lady_Aleena =head1 ACKNOWLEDGEMENTS Perl Monks: Anno, bradenshep, Corion, ikegami, Limbic~Region, Petruchi +o, shmem, Sidhekin, wfsp, ysth and the rest of the community that has + been so kind to me. =head1 SYNOPSIS This script randomly generates mutations of player characters. =cut print "content-type: text/html \n\n"; my %Data; sub random { my ($name) = @_; my $array = $Data{$name}; my $pick = $array->[rand @$array]; if (ref($pick) eq 'CODE') {return $pick->();} else {return $pick;} }
This next code block is all the static arrays with the arrays in alphabetical order.
#Static# $Data{AbNm} = [qw(strength dexterity constitution intelligence wisdom +charisma)]; $Data{Algn} = [qw(lawful chaotic good evil neutral)]; $Data{BdPt} = ['eye','lip','nail','nose','hair','skin','entire body']; $Data{ClSp} = [qw(Air All Animal Astral Chaos Charm Combat Creation Di +vination Earth Fire Guardian Healing Law Necromatic Numbers Plant Pro +tection Summoning Sun Thought Time Travelers War Wards Water Weather) +]; $Data{Clss} = [qw(Warrior Rogue Priest Wizard Psionisist)]; $Data{Dice} = [qw(1d4 1d6 1d8 1d10 1d12 1d20)]; $Data{Divn} = ['Demi-','Lesser ','Intermediate ','Greater ']; $Data{Eff1} = [qw(Acid Cold Electricity Fire Gas Sonic)]; $Data{Eff2} = ['Acid','Cold','Electricity','Fire','Poison','Energy Dra +in']; $Data{Eff3} = ['Acid','Cold','Electricity','Fire','Energy Drain','Gas' +,'Poison','Sonic']; $Data{Emtn} = [qw(joy sorrow trust fear love hate indifference)]; $Data{Fail} = ['all crtical misses','failed backstabs','failed saving +throws']; $Data{Gaze} = [qw(Paralysis Stone Stun Death)]; $Data{Gems} = [qw(diamond ruby sapphire emerald amethyst garnet spinel + zircon crystal quartz)]; $Data{ImDm} = ['immune to','takes ×2 dmg from']; $Data{LNWp} = ['language','non-weapon proficiency','weapon']; $Data{MITp} = ['Magical Liquids','Scrolls','Rings','Rods','Staves','Wa +nds','Books','Gems & Jewelry','Clothing','Boots & Gloves','Girdles & +Helms','Bags & Bottles','Dust & Stones','Household Items','Musical In +struments','Weird Stuff','Humorous Items','Armor and Shields','Weapon +s','Artifacts']; $Data{Mtls} = [qw(platinum gold silver copper nickel bronze tin iron s +teel lead aluminum)]; $Data{PlMi} = [qw(+ -)]; $Data{Radi} = ["1' or Touch","5'","10'","20'","50'","100'"]; $Data{Siz1} = [qw(taller shorter)]; $Data{Siz2} = [qw(longer shorter)]; $Data{SpFr} = ['common','uncommon','rare','very rare']; $Data{SvTr} = ['Paralyzation','Poison','Death Magic','Rods','Staves',' +Wands','Petrifaction','Polymorph','Breath Weapon','Spells']; $Data{Thng} = ['animals','plants','constructs','dragons','lycenthropes +','undead','inanimate objects']; $Data{Time} = [qw(round turn hour day week month year)]; $Data{Toch} = ['befouls','purifies','nullifies holy water','nullifies +unholy water']; $Data{Vocl} = [qw(Deafen Fear Terror Flight)]; $Data{WpMg} = ['non-','']; $Data{WpMt} = [qw(bone metal stone wooden)]; $Data{WpTp} = [qw(bludgeoning piercing slashing missile)]; $Data{WzSc} = [qw(Abjuration Air Alteration Conjuration/Summoning Divi +nation Earth Enchantment/Charm Fire Illusion/Phantasm Invocation/Evoc +ation Necromancy Water)];
This code block is all of the arrays that do things with the above and amongst themselves.
#Dynamic# sub radius {"in a ".random("Radi")." radius"} sub tdice { my $tdice = roll(random("Dice")); return "$tdice ".PL_N("time",$tdice)." ".A(random("Time")); } $Data{SpellsT} = [ sub {random("WzSc")." school"}, sub {random("ClSp")." sphere"} ]; $Data{Resist} = [ "immune", sub {"is ".roll('1d100')."% magic resistant"}, "has no resistance" ]; $Data{Spells} = [ "all spells", "all Wizard spells", "all Priest spells", sub {"the ".random("WzSc")." school of wizard spells"}, sub {"the ".random("ClSp")." sphere of priest spells"}, sub {random("Eff3")." spells and spell-like effects"} ]; $Data{MIGp} = [ sub {"magic items in the ".random("MITp")." group"}, "all magic items" ]; $Data{MagicItems} = [ "can use all magic items", "can not use any magic items", sub {"can only use magic items in the ".random("MITp")." group"}, sub {"can not use magic items in the ".random("MITp")." group"}, sub {"causes ".random("MIGp")." to dysfunction ".radius}, sub {"causes ".random("MIGp")." to loose their power ".radius}, sub {"attracts ".random("MIGp")." ".radius}, sub {"repels ".random("MIGp")." ".radius}, sub {"destroys ".random("MIGp")." ".radius} ]; $Data{OtherMagic} = [ "magic dead", sub {"a ".random("Radi")." radius Wild Magic zone"}, "a magic attracter", "addicted to magic energies" ]; $Data{Weapon} = [ sub {random("WpTp")}, sub {random("WpMt")}, sub {random("WpMg")."magical"}, "all" ]; $Data{NWPlearn} = [ sub {random("AbNm")." based"}, sub {random("Clss")." specific"} ]; $Data{SATS} = [ sub {"to saving throws vs. ".random("SvTr")}, "Armor Class", "THAC0 modifier", "to Surprise" ]; $Data{Attack} = [ sub {"Breath Weapon - ".random("Eff1")." for ".random("Dice")." damage +"}, sub {"Gaze Attack - ".random("Gaze")}, sub {"Touch Attack - ".random("Eff2")." for ".random("Dice")." damage" +}, sub {"Vocal Attack - ".random("Vocl")} ]; my %color_info = (red=>'f00',yellow=>'ff0',green=>'0f0',cyan=>'0ff',bl +ue=>'00f',magenta=>'f0f',white=>'fff',black=>'000'); $Data{Color} = [map {"<span class=\"bo\" style=\"color:#$color_info{$_ +};\">$_</span>"} keys %color_info]; $Data{Aura} = [ sub {"visible ".random("Color")}, sub {random("Emtn")}, sub {random("Algn")} ];
This block belongs to the last array in this block, @Body.
my %mammal_info = (bovine=>'cattle', canine =>'dog', caprine =>'goat', + equine=>'horse', feline =>'cat', leporine=>'rabbit', lupine=>'wolf', + ovine =>'sheep', porcine =>'pig', ursine=>'bear', vulpine=>'fox') +; $Data{Mammal} = [map {"<a title=\"$mammal_info{$_}\">$_</a>"} keys %ma +mmal_info]; $Data{Animal} = [ "amphibian", "insetoid", sub {random("Mammal")}, "reptilian" ]; $Data{Animal2} = [qw(amphibian insetoid mammallian reptilian)]; $Data{Head} = [ "an enlarged head", "a shrunken head", "horns" ]; $Data{Eyes} = [ "glowing eyes", "the appearance of no eyes", sub {random("Color")." eyes"}, "eyes in an odd position", "only one eye", sub {roll('1d4+2')." eyes"}, "infravision<p>† ultravision if infravision is already present</ +p>", sub {my $clrbld = (roll('1d100')>80?'green':'red'); "$clrbld-weakness +color blindness"}, "photo-sensitivity" ]; $Data{Ears} = [ "lobeless ears", "only ear holes", "no ears", "extra-sensitive hearing", sub {roll('1d10*10')."% deafness"}, sub {roll('1d4+2')." ears"} ]; $Data{Nose} = [ "an oversized nose", "only nose holes", "no nose", sub {"a nose with an ".random("Animal")." appearance"}, "an extra-sensitive nose", "no sense of smell" ]; $Data{Mouth} = [ sub {random("Color")." lips"}, "no lips", "an oversized mouth", sub {roll('1d2+1')." mouths"}, ]; $Data{Arms} = [ sub {"arms that are ".roll('1d50')."% ".random("Siz2")." than average" +}, "no elbow joint", "no wrist joint", sub {roll('1d4+2')." arms (all arms above triple the normal amount are + vestigial)"}, sub {random("Animal")."-like arms"} ]; $Data{Hands} = [ "elongated fingers", "one less finger on each hand", "double jointed fingers", "animal claws", "snake fingers", "webbed fingers" ]; $Data{Legs} = [ sub {"legs that are ".roll('1d50')."% ".random("Siz2")." than average" +}, "no knee joint", "no ankle joint", sub {roll('1d4+2')." legs (all legs above double the normal amount are + vestigial)"}, sub {random("Animal")." legs"} ]; $Data{Feet} = [ "elongated toes", "one less toe on each foot", "no toes", "animal paws", "claws for toes", "webbed toes" ]; $Data{Skin} = [ "fur covered skin", sub {random("Animal")." skin"}, "fish scales", "feathers", "invisible skin", sub {random("Color")." skin"}, "ultra-sensitive skin" ]; $Data{Bones} = [ "wooden bones", sub {random("Gems")." bones"}, sub {random("Mtls")." bones"}, "fragile bones", "unbreakable bones" ]; $Data{Teeth} = [ "enlarged teeth", "fangs", "fangs with venom", sub {random("Gems")." teeth"}, sub {random("Mtls")." teeth"}, "two sets of teeth" ]; $Data{Hair} = [ sub {random("Color")." hair"}, "odd textured hair", "uncuttable hair", "no hair anywhere", "invisible hair", sub {random("Mtls")." hair"} ]; $Data{Nails} = [ sub {random("Gems")." nails"}, sub {random("Mtls")." nails"}, "no nails", "unbreakable nails" ]; $Data{Blood} = [ "icor for blood", "poisonous blood", sub {random("Color")." blood"} ]; $Data{Body} = [ sub {random("Skin")}, sub {random("Bones")}, sub {random("Blood")}, sub {random("Head")}, sub {random("Hair")}, sub {random("Eyes")}, sub {random("Ears")}, sub {random("Nose")}, sub {random("Mouth")}, sub {random("Teeth")}, sub {random("Arms")}, sub {random("Hands")}, sub {random("Legs")}, sub {random("Feet")}, sub {random("Nails")}, sub {random("Animal2")." wings"}, sub {random("Animal")." tail"}, "gills" ];
This block belongs to the last array in this block, @SED, which is short for SleepEatDrink.
$Data{Sleep} = [ 'hardly ever wakes up', 'needs twice as much sleep', 'needs half as much sleep', 'does not need sleep', 'is an insomniac', 'is a narcoleptic', 'is unable to remember the past after sleeping' ]; $Data{Eat} = [ 'can not stop eating', 'needs twice as much food', 'needs half as much food', 'does not need to eat', 'is carnivorous', 'is herbivorous', 'is lethargic after eating any amount of food' ]; $Data{Drink} = [ 'can not stop drinking', 'needs twice as much liquid', 'needs half as much liquid', 'does not need liquids', 'is an alcoholic', 'can not get drunk', 'is intoxicated after injesting any liquid' ]; $Data{SED} = [ sub {random("Sleep")}, sub {random("Eat")}, sub {random("Drink")}, sub {random("Sleep")." and ".random("Eat")}, sub {random("Sleep")." and ".random("Drink")}, sub {random("Eat")." and ".random("Drink")}, sub {random("Sleep").", ".random("Eat").", and ".random("Drink")} ];
This is where everything comes together, in this vla.
$Data{Mutation} = [ "no unusual effect", "General ability", #See note 1 "Sub-ability", #See note 2 sub {"casts up to ".random("SpFr")." ".random("SpellsT")." spells as a + natural ability ".tdice." (See the spell progession for maximum spel +l level.)"}, sub {random("Resist")." to ".random("Spells")}, sub {random("MagicItems")}, sub {"is ".random("OtherMagic")}, sub {random("ImDm")." ".random("Weapon")." weapons"}, "takes only magical damage", sub {"knows one ".random("LNWp")." that parent knows"}, sub {"knows all ".PL_N(random("LNWp"))." that parent knows"}, sub {"unable to learn ".PL_N(random("LNWp"))." that parent knows"}, "unable to learn any language other than racial language", sub {random("PlMi").roll('1d4')." on all non-weapon proficiency checks +"}, sub {"unable to learn ".random("NWPlearn")." non-weapon proficiencies" +}, sub {"unable to learn ".random("WpTp")." weapons"}, sub {"can not use ".random("WpMt")." weapons"}, sub {"born already at ".ORD(roll(random("Dice")))." level"}, sub {"unable to advance past ".ORD(roll('5d6'))." level"}, sub {random("PlMi").roll('1d10')." ".random("SATS")}, sub {"a Wild Magic Surge accompanies ".random("Fail")}, "attacks as a warrior of the same level. If already a warrior, attacks + at 1 level higher.", "can not make a Critical Hit", "attracts these followers: <ul>(RangerFollowers.pl)</ul>", # See note +5 sub {"repels all animals ".radius}, "backstabs as a thief of the same level. If already a thief, backstabs + at 1 level higher.", "turns undead as a priest of the same level. If already a priest, turn +s at 1 level higher.", "Wild Psionic Talent: (Psionics.pl)", ## See note 5 "unable to use Psionics", sub {"Special Attack: ".random("Attack")." ".tdice}, sub {"is ".roll('1d50')."% ".random("Siz1")." than average"}, sub {"has ".random("Body")}, sub {"can change ".random("BdPt")." color at will to ".random("Color") +}, sub {$Data{BdPt}[roll('1d3-1')]."s turn ".random("Color")." when magic + is used ".radius}, sub {$Data{BdPt}[roll('3d2+1')]." turns ".random("Color")." when magic + is used ".radius}, sub {"has ".A(random("Aura"))." aura"}, sub {"communicates with ".random("Thng")." ".radius}, sub {"knows history of ".random("Thng")." ".radius}, "is blessed", "is cursed", sub {"touch ".random("Toch")}, sub {random("SED")}, sub {do 'rg_ins.pl'}, ####****This is where rg_ins.pl goes.****#### "has characteristics of (AAn-AllMonsters.pl)", # See note 5 "has lycanthropy as a (Lycanthrope.pl)", #See note 5 sub {random("SED")." after seeing (AAn-AllMonsters.pl) for a ".$Data{T +ime}[roll('1d4+2')]}, # See note 5 sub {"is ".random("Divn")."power - character should be retired"} ];
After all of that, it has to do something, so here is the beginnings of what I would like to see happen.
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http: +//www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">'; print '<html><head><title>Character Mutations</title><link rel="styles +heet" type="text/css" href="../../main.css"/></head><body><h1>Charact +er Mutations Generator</h1><p>All effects are cumulative, and one can + be cancelled out by another.</p><ol>'; for(1..roll(random("Dice"))){print "<li>".random("Mutation")."</li>\n" +}; print "</ol></body></html>";
This is the file that is called by the 5th to the last line in the VLA.
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; use CGI; use CGI::Carp qw(fatalsToBrowser); use HTML::Template; sub Disorder { my @Disorder = ('amnesia','catatonia','dementia','hallucinatory insani +ty','manic despression','paranoia','schizophrenia'); return $Disorder[rand @Disorder] } my %InsDesc = ( abluto=>'washing or bathing', acaro=>'ticks and mites, and the diseases they transmit', aero=>'air, atmosphere, weather, or gas', agro=>'agricultural soils, or open spaces', ailuro=>'cats', xeno=>'foreigners, strangers, foreign things, or outside causes', xero=>'dry conditions or dryness', xylo=>'wood, wooden objects, or forests', zoo=>'animals', zym=>'fermentation' ); sub Ins { my @InsKeys = keys %InsDesc; my $InsRand = $InsKeys[rand @InsKeys]; my @InsType = ( $InsRand."phobia (fear of ".$InsDesc{$InsRand}.")", $InsRand."mania (obsession of or with ".$InsDesc{$InsRand}.")", $InsRand."philia (insatiable desire for ".$InsDesc{$InsRand}.")" ); } sub Insanity { my @InsGen = (Disorder,Ins); return $InsGen[rand @InsGen]; } print Insanity; if (!caller) { print "This will only show up when run directly" };
I hope that this is little clearer than the last time I posted this script. I know that it is still a mess.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating a random generator
by shmem (Chancellor) on Oct 03, 2007 at 17:11 UTC | |
by Lady_Aleena (Priest) on Oct 05, 2007 at 07:08 UTC | |
|
Re^2: Creating a random generator
by graff (Chancellor) on Oct 01, 2007 at 13:24 UTC | |
by Lady_Aleena (Priest) on Oct 03, 2007 at 17:25 UTC | |
by Lady_Aleena (Priest) on Oct 09, 2007 at 21:21 UTC | |
by graff (Chancellor) on Oct 10, 2007 at 05:54 UTC | |
|
Re^2: Creating a random generator
by Lady_Aleena (Priest) on Oct 08, 2007 at 10:23 UTC |