MediaWiki:Zerospace EN.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 17: | Line 17: | ||
var dice_size = 6; | var dice_size = 6; | ||
var dice_count = 3; | var dice_count = 3; | ||
alien_type_roll = roll_dice(dice_size, dice_count); | var alien_type_roll = roll_dice(dice_size, dice_count); | ||
if (alien_type_roll <= 13) | if (alien_type_roll <= 13) | ||
Line 38: | Line 37: | ||
var alien_type = new Object(); | var alien_type = new Object(); | ||
alien_type['id'] = alien_type_id; | |||
alien_type['text'] = alien_type_text; | |||
return alien_type; | return alien_type; | ||
} | |||
function generate_alien_skin_saturation(allow_patterned) | |||
{ | |||
allow_patterned = typeof allow_patterned !== 'undefined' ? allow_patterned : true; | |||
var dice_size = 6; | |||
var dice_count = 1; | |||
if (allow_patterned == false) | |||
{ | |||
dice_size = 5; | |||
} | |||
var alien_skin_saturation_roll = roll_dice(dice_size, dice_count); | |||
switch (alien_skin_saturation_roll) | |||
{ | |||
case 1: | |||
alien_skin_saturation_text = "Pale"; | |||
break; | |||
case 2: | |||
alien_skin_saturation_text = "Light"; | |||
break; | |||
case 3: | |||
alien_skin_saturation_text = "Medium"; | |||
break; | |||
case 4: | |||
alien_skin_saturation_text = "Deep"; | |||
break; | |||
case 5: | |||
alien_skin_saturation_text = "Dark"; | |||
break; | |||
case 6: | |||
alien_skin_saturation_text = "Patterned"; | |||
} | |||
var alien_skin_saturation = new Object(); | |||
alien_skin_saturation['id'] = alien_skin_saturation_roll; | |||
alien_skin_saturation['text'] = alien_skin_saturation_text; | |||
return alien_skin_saturation; | |||
} | |||
function generate_alien_skin_colour() | |||
{ | |||
var dice_size = 6; | |||
var dice_count = 1; | |||
var alien_skin_colour_roll = roll_dice(dice_size, dice_count); | |||
switch (alien_skin_colour_roll) | |||
{ | |||
case 1: | |||
alien_skin_colour_text = "Blue"; | |||
break; | |||
case 2: | |||
alien_skin_colour_text = "Brown"; | |||
break; | |||
case 3: | |||
alien_skin_colour_text = "Green"; | |||
break; | |||
case 4: | |||
alien_skin_colour_text = "Grey"; | |||
break; | |||
case 5: | |||
alien_skin_colour_text = "Red"; | |||
break; | |||
case 6: | |||
alien_skin_colour_text = "Yellow"; | |||
} | |||
var alien_skin_colour = new Object(); | |||
alien_skin_colour['id'] = alien_skin_colour_roll; | |||
alien_skin_colour['text'] = alien_skin_colour_text; | |||
return alien_skin_colour; | |||
} | |||
function generate_alien_skin() | |||
{ | |||
var increase_contrast_roll; | |||
var increase_contrast; | |||
var dice_size = 6; | |||
var dice_count = 1; | |||
alien_skin_saturation = generate_alien_skin_saturation; | |||
alien_skin_saturation_id = alien_skin_saturation['id']; | |||
alien_skin_saturation_text = alien_skin_saturation['text']; | |||
alien_skin_colour = generate_alien_skin_colour; | |||
alien_skin_colour_id = alien_skin_colour['id']; | |||
alien_skin_colour_text = alien_skin_colour['text']; | |||
dice_size = 2; | |||
dice_count = 1; | |||
increase_contrast_roll = roll_dice(dice_size, dice_count); | |||
if (increase_contrast_roll == 1) | |||
{ | |||
increase_contrast = true; | |||
} | |||
else | |||
{ | |||
increase_contrast = false; | |||
} | |||
if (increase_contrast && alien_skin_colour_text == "Grey") | |||
{ | |||
if (alien_skin_saturation_text == "Pale") | |||
{ | |||
alien_skin_saturation_text= "Snow"; | |||
alien_skin_colour_text = "White"; | |||
} | |||
else if (alien_skin_saturation_text == "Dark") | |||
{ | |||
alien_skin_saturation_text= "Pitch"; | |||
alien_skin_colour_text = "Black"; | |||
} | |||
} | |||
var alien_skin = new Object(); | |||
alien_skin['saturation'] = alien_skin_saturation_id; | |||
alien_skin['colour'] = alien_skin_colour_id; | |||
alien_skin['text'] = alien_skin_saturation_text + " " + alien_skin_colour_text; | |||
return alien_skin; | |||
} | } | ||
function generate_alien() | function generate_alien() | ||
{ | { | ||
var random_alien | var random_alien = ''; | ||
var alien_name | var alien_name = GenPlot(); | ||
var alien_type | var alien_type = generate_alien_type(); | ||
var alien_type_id | var alien_type_id = alien_type['id']; | ||
var alien_type_text = alien_type['text']; | var alien_type_text = alien_type['text']; | ||
var alien_skin = generate_alien_skin(); | |||
var alien_skin_saturation = alien_skin['saturation']; | |||
var alien_skin_colour = alien_skin['colour']; | |||
var alien_skin_text = alien_skin['text']; | |||
random_alien = '<div id="random_alien_title" class="sidebar_title">' + alien_name + "</div>\n"; | random_alien = '<div id="random_alien_title" class="sidebar_title">' + alien_name + "</div>\n"; | ||
random_alien += '<div id="random_alien_title" class="sidebar_subtitle">' + alien_type_text + "</div>\n"; | random_alien += '<div id="random_alien_title" class="sidebar_subtitle">' + alien_type_text + "</div>\n"; | ||
random_alien += '<div><strong>Skin:<strong> ' + alien_skin_text + "</div>\n"; | |||
document.getElementById("random_alien_output").innerHTML = random_alien; | document.getElementById("random_alien_output").innerHTML = random_alien; | ||
} | } |
Revision as of 17:58, 25 April 2018
function roll_dice(dice_size, dice_count)
{
dice_size = typeof dice_size !== 'undefined' ? dice_size : 6;
dice_count = typeof dice_count !== 'undefined' ? dice_count : 1;
var dice_total = 0;
for (i = 0; i < dice_count; i++) {
dice_total += Math.floor((Math.random() * dice_size) + 1);
}
return dice_total;
}
function generate_alien_type()
{
var dice_size = 6;
var dice_count = 3;
var alien_type_roll = roll_dice(dice_size, dice_count);
if (alien_type_roll <= 13)
{
alien_type_id = 1;
alien_type_text = 'Humanoid alien';
}
else if (alien_type_roll <= 15)
{
alien_type_id = 2;
alien_type_text = 'Android';
}
else
{
alien_type_id = 3;
alien_type_text = 'Exotic alien';
}
var alien_type = new Object();
alien_type['id'] = alien_type_id;
alien_type['text'] = alien_type_text;
return alien_type;
}
function generate_alien_skin_saturation(allow_patterned)
{
allow_patterned = typeof allow_patterned !== 'undefined' ? allow_patterned : true;
var dice_size = 6;
var dice_count = 1;
if (allow_patterned == false)
{
dice_size = 5;
}
var alien_skin_saturation_roll = roll_dice(dice_size, dice_count);
switch (alien_skin_saturation_roll)
{
case 1:
alien_skin_saturation_text = "Pale";
break;
case 2:
alien_skin_saturation_text = "Light";
break;
case 3:
alien_skin_saturation_text = "Medium";
break;
case 4:
alien_skin_saturation_text = "Deep";
break;
case 5:
alien_skin_saturation_text = "Dark";
break;
case 6:
alien_skin_saturation_text = "Patterned";
}
var alien_skin_saturation = new Object();
alien_skin_saturation['id'] = alien_skin_saturation_roll;
alien_skin_saturation['text'] = alien_skin_saturation_text;
return alien_skin_saturation;
}
function generate_alien_skin_colour()
{
var dice_size = 6;
var dice_count = 1;
var alien_skin_colour_roll = roll_dice(dice_size, dice_count);
switch (alien_skin_colour_roll)
{
case 1:
alien_skin_colour_text = "Blue";
break;
case 2:
alien_skin_colour_text = "Brown";
break;
case 3:
alien_skin_colour_text = "Green";
break;
case 4:
alien_skin_colour_text = "Grey";
break;
case 5:
alien_skin_colour_text = "Red";
break;
case 6:
alien_skin_colour_text = "Yellow";
}
var alien_skin_colour = new Object();
alien_skin_colour['id'] = alien_skin_colour_roll;
alien_skin_colour['text'] = alien_skin_colour_text;
return alien_skin_colour;
}
function generate_alien_skin()
{
var increase_contrast_roll;
var increase_contrast;
var dice_size = 6;
var dice_count = 1;
alien_skin_saturation = generate_alien_skin_saturation;
alien_skin_saturation_id = alien_skin_saturation['id'];
alien_skin_saturation_text = alien_skin_saturation['text'];
alien_skin_colour = generate_alien_skin_colour;
alien_skin_colour_id = alien_skin_colour['id'];
alien_skin_colour_text = alien_skin_colour['text'];
dice_size = 2;
dice_count = 1;
increase_contrast_roll = roll_dice(dice_size, dice_count);
if (increase_contrast_roll == 1)
{
increase_contrast = true;
}
else
{
increase_contrast = false;
}
if (increase_contrast && alien_skin_colour_text == "Grey")
{
if (alien_skin_saturation_text == "Pale")
{
alien_skin_saturation_text= "Snow";
alien_skin_colour_text = "White";
}
else if (alien_skin_saturation_text == "Dark")
{
alien_skin_saturation_text= "Pitch";
alien_skin_colour_text = "Black";
}
}
var alien_skin = new Object();
alien_skin['saturation'] = alien_skin_saturation_id;
alien_skin['colour'] = alien_skin_colour_id;
alien_skin['text'] = alien_skin_saturation_text + " " + alien_skin_colour_text;
return alien_skin;
}
function generate_alien()
{
var random_alien = '';
var alien_name = GenPlot();
var alien_type = generate_alien_type();
var alien_type_id = alien_type['id'];
var alien_type_text = alien_type['text'];
var alien_skin = generate_alien_skin();
var alien_skin_saturation = alien_skin['saturation'];
var alien_skin_colour = alien_skin['colour'];
var alien_skin_text = alien_skin['text'];
random_alien = '<div id="random_alien_title" class="sidebar_title">' + alien_name + "</div>\n";
random_alien += '<div id="random_alien_title" class="sidebar_subtitle">' + alien_type_text + "</div>\n";
random_alien += '<div><strong>Skin:<strong> ' + alien_skin_text + "</div>\n";
document.getElementById("random_alien_output").innerHTML = random_alien;
}
// Retro Alien Name Generator
// http://www.springhole.net/writing_roleplaying_randomators/retroaliennames.htm
var aVocab = new Array();
var intIncr
var intCat
intCat =0
intIncr=0
//The data stored is pretty simple. It works like this:
//
// The aVocab array has sub arrays that are named lists of data.
//
//aVocab[intCat]= new Array(); - The aVocab Array actually holds other arrays.
//aVocab[intCat][0]="FIRST" - This is the name of the list of data in this sub array. The name helps the program find the data.
//aVocab[intCat][1] = new Array() - Yep, ANOTHER array - this is the array that holds the actual data.
//aVocab[intCat][1][intIncr++]="First thing <SECOND>" // See that <SECOND> tag? Anything in brackets references another list.
//aVocab[intCat][1][intIncr++]="First thing <THIRD>"
//
// Unless it's the last entry, don't forget to increment and reset the counters!
//
//intCat++
//intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="FIRST"
aVocab[intCat][1] = new Array()
//aVocab[intCat][1][intIncr++]="<options>\n<options>\n<options>\n<options>\n<options>"
aVocab[intCat][1][intIncr++]="<options>"
intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="options"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="<firstconsonant><apos><ending>"
aVocab[intCat][1][intIncr++]="<firstconsonant><apos><ending>"
aVocab[intCat][1][intIncr++]="<firstconsonant><apos><vowel><apos><ending>"
aVocab[intCat][1][intIncr++]="<firstconsonant><apos><vowel><apos><midletters><apos><ending>"
aVocab[intCat][1][intIncr++]="<firstconsonant><apos><vowel><apos><midletters><apos><ending>"
aVocab[intCat][1][intIncr++]="<firstconsonant><apos><vowel><apos><midletters><apos><ending>"
aVocab[intCat][1][intIncr++]="<firstvowel><apos><midletters><apos><vowel><apos><midletters><apos><ending>"
intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="firstvowel"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="A"
aVocab[intCat][1][intIncr++]="E"
aVocab[intCat][1][intIncr++]="I"
aVocab[intCat][1][intIncr++]="I<apos>a"
aVocab[intCat][1][intIncr++]="O"
aVocab[intCat][1][intIncr++]="U"
aVocab[intCat][1][intIncr++]="U<apos>a"
intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="firstconsonant"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="B"
aVocab[intCat][1][intIncr++]="B<apos>l"
aVocab[intCat][1][intIncr++]="B<apos>r"
aVocab[intCat][1][intIncr++]="D"
aVocab[intCat][1][intIncr++]="D<apos>r"
aVocab[intCat][1][intIncr++]="Ch"
aVocab[intCat][1][intIncr++]="F"
aVocab[intCat][1][intIncr++]="F<apos>l"
aVocab[intCat][1][intIncr++]="F<apos>r"
aVocab[intCat][1][intIncr++]="G"
aVocab[intCat][1][intIncr++]="G<apos>l"
aVocab[intCat][1][intIncr++]="G<apos>r"
aVocab[intCat][1][intIncr++]="H"
aVocab[intCat][1][intIncr++]="J"
aVocab[intCat][1][intIncr++]="K"
aVocab[intCat][1][intIncr++]="K<apos>h"
aVocab[intCat][1][intIncr++]="K<apos>l"
aVocab[intCat][1][intIncr++]="K<apos>r"
aVocab[intCat][1][intIncr++]="L"
aVocab[intCat][1][intIncr++]="M"
aVocab[intCat][1][intIncr++]="N"
aVocab[intCat][1][intIncr++]="P"
aVocab[intCat][1][intIncr++]="P<apos>l"
aVocab[intCat][1][intIncr++]="P<apos>r"
aVocab[intCat][1][intIncr++]="R"
aVocab[intCat][1][intIncr++]="S"
aVocab[intCat][1][intIncr++]="Sh"
aVocab[intCat][1][intIncr++]="S<apos>l"
aVocab[intCat][1][intIncr++]="S<apos>m"
aVocab[intCat][1][intIncr++]="S<apos>n"
aVocab[intCat][1][intIncr++]="S<apos>t"
aVocab[intCat][1][intIncr++]="T"
aVocab[intCat][1][intIncr++]="Th"
aVocab[intCat][1][intIncr++]="Th<apos>r"
aVocab[intCat][1][intIncr++]="T<apos>r"
aVocab[intCat][1][intIncr++]="V"
aVocab[intCat][1][intIncr++]="W"
aVocab[intCat][1][intIncr++]="X"
aVocab[intCat][1][intIncr++]="Y"
aVocab[intCat][1][intIncr++]="Z"
intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="vowel"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="a"
aVocab[intCat][1][intIncr++]="a<apos>a"
aVocab[intCat][1][intIncr++]="e"
aVocab[intCat][1][intIncr++]="e<apos>e"
aVocab[intCat][1][intIncr++]="i"
aVocab[intCat][1][intIncr++]="o"
aVocab[intCat][1][intIncr++]="o<apos>o"
aVocab[intCat][1][intIncr++]="u"
aVocab[intCat][1][intIncr++]="u<apos>u"
intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="midletters"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="b"
aVocab[intCat][1][intIncr++]="b<apos>l"
aVocab[intCat][1][intIncr++]="b<apos>r"
aVocab[intCat][1][intIncr++]="ch"
aVocab[intCat][1][intIncr++]="d"
aVocab[intCat][1][intIncr++]="d<apos>r"
aVocab[intCat][1][intIncr++]="f"
aVocab[intCat][1][intIncr++]="fr"
aVocab[intCat][1][intIncr++]="fl"
aVocab[intCat][1][intIncr++]="g"
aVocab[intCat][1][intIncr++]="g<apos>l"
aVocab[intCat][1][intIncr++]="g<apos>r"
aVocab[intCat][1][intIncr++]="h"
aVocab[intCat][1][intIncr++]="j"
aVocab[intCat][1][intIncr++]="k"
aVocab[intCat][1][intIncr++]="k<apos>l"
aVocab[intCat][1][intIncr++]="k<apos>s"
aVocab[intCat][1][intIncr++]="k<apos>r"
aVocab[intCat][1][intIncr++]="k<apos>t"
aVocab[intCat][1][intIncr++]="l"
aVocab[intCat][1][intIncr++]="l<apos>b"
aVocab[intCat][1][intIncr++]="l<apos>d"
aVocab[intCat][1][intIncr++]="l<apos>k"
aVocab[intCat][1][intIncr++]="l<apos>l"
aVocab[intCat][1][intIncr++]="l<apos>m"
aVocab[intCat][1][intIncr++]="l<apos>r"
aVocab[intCat][1][intIncr++]="l<apos>s"
aVocab[intCat][1][intIncr++]="l<apos>t"
aVocab[intCat][1][intIncr++]="m"
aVocab[intCat][1][intIncr++]="n"
aVocab[intCat][1][intIncr++]="n<apos>d"
aVocab[intCat][1][intIncr++]="n<apos>t"
aVocab[intCat][1][intIncr++]="p"
aVocab[intCat][1][intIncr++]="p<apos>k"
aVocab[intCat][1][intIncr++]="p<apos>l"
aVocab[intCat][1][intIncr++]="p<apos>r"
aVocab[intCat][1][intIncr++]="r"
aVocab[intCat][1][intIncr++]="r<apos>d"
aVocab[intCat][1][intIncr++]="r<apos>j"
aVocab[intCat][1][intIncr++]="r<apos>k"
aVocab[intCat][1][intIncr++]="r<apos>l"
aVocab[intCat][1][intIncr++]="r<apos>r"
aVocab[intCat][1][intIncr++]="r<apos>s"
aVocab[intCat][1][intIncr++]="r<apos>t"
aVocab[intCat][1][intIncr++]="s"
aVocab[intCat][1][intIncr++]="sh"
aVocab[intCat][1][intIncr++]="s<apos>l"
aVocab[intCat][1][intIncr++]="s<apos>n"
aVocab[intCat][1][intIncr++]="s<apos>m"
aVocab[intCat][1][intIncr++]="s<apos>t"
aVocab[intCat][1][intIncr++]="t"
aVocab[intCat][1][intIncr++]="th"
aVocab[intCat][1][intIncr++]="th<apos>r"
aVocab[intCat][1][intIncr++]="t<apos>r"
aVocab[intCat][1][intIncr++]="v"
aVocab[intCat][1][intIncr++]="x"
aVocab[intCat][1][intIncr++]="x<apos>x"
aVocab[intCat][1][intIncr++]="y"
aVocab[intCat][1][intIncr++]="z"
aVocab[intCat][1][intIncr++]="z<apos>g"
aVocab[intCat][1][intIncr++]="z<apos>l"
aVocab[intCat][1][intIncr++]="z<apos>n"
aVocab[intCat][1][intIncr++]="z<apos>m"
aVocab[intCat][1][intIncr++]="z<apos>t"
aVocab[intCat][1][intIncr++]="z<apos>z"
intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="ending"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="a"
aVocab[intCat][1][intIncr++]="ak"
aVocab[intCat][1][intIncr++]="ar"
aVocab[intCat][1][intIncr++]="ax"
aVocab[intCat][1][intIncr++]="an"
aVocab[intCat][1][intIncr++]="e<apos>a"
aVocab[intCat][1][intIncr++]="e<apos>e"
aVocab[intCat][1][intIncr++]="ek"
aVocab[intCat][1][intIncr++]="i<apos>a"
aVocab[intCat][1][intIncr++]="ik"
aVocab[intCat][1][intIncr++]="in"
aVocab[intCat][1][intIncr++]="is"
aVocab[intCat][1][intIncr++]="ix"
aVocab[intCat][1][intIncr++]="ok"
aVocab[intCat][1][intIncr++]="on"
aVocab[intCat][1][intIncr++]="o<apos>o"
aVocab[intCat][1][intIncr++]="os"
aVocab[intCat][1][intIncr++]="ox"
aVocab[intCat][1][intIncr++]="oz"
intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]="apos"
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]="'"
aVocab[intCat][1][intIncr++]=""
aVocab[intCat][1][intIncr++]=""
aVocab[intCat][1][intIncr++]=""
aVocab[intCat][1][intIncr++]=""
aVocab[intCat][1][intIncr++]=""
//Leave to Copy!
intCat++
intIncr=0
aVocab[intCat]= new Array();
aVocab[intCat][0]=""
aVocab[intCat][1] = new Array()
aVocab[intCat][1][intIncr++]=""
function GenNumber(nRange)
{
var iNumGen
iNumGen = Math.round((Math.random() * nRange));
return iNumGen;
}
function GetFrom(aArray)
{
var undefined
var sReturn
sReturn = aArray[GenNumber(aArray.length)];
if (sReturn == undefined)
{
sReturn = GetFrom(aArray)
}
return sReturn
}
function GetArray(sArrayName)
{
for (var intLooper=0;intLooper <aVocab.length;intLooper++)
{
if (aVocab[intLooper][0]==sArrayName)
{
return aVocab[intLooper][1];
break;
}
}
}
function ScanLine(sLine)
{
var iTagStart, iTagEnd
var sKey
if (sLine.indexOf("<") > -1)
{
iTagStart = sLine.indexOf("<");
iTagEnd = sLine.indexOf(">");
sKey = sLine.substr(iTagStart+1, iTagEnd-(iTagStart+1));
sKey = GetFrom(GetArray(sKey))
sLine = sLine.substr(0, iTagStart) + sKey + sLine.substr(iTagEnd+1, (sLine.length - iTagEnd))
}
if (sLine.indexOf("<") > - 1)
{
sLine = ScanLine(sLine)
}
return sLine;
}
function GenPlot()
{
sLine = GetFrom(GetArray("FIRST"));
sLine = ScanLine(sLine)
return sLine;
}
$(function () {
var random_alien_button = document.getElementById('random_alien_button');
random_alien_button.innerHTML = '<input type="button" value="Generate An Alien" onclick="generate_alien();" />';
random_alien_output.innerHTML = 'Click the button and generate a random alien.';
}());