MediaWiki:Zerospace EN.js

From OGC
Revision as of 18:32, 25 April 2018 by Admin (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
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_color()
{
	var dice_size = 6;
	var dice_count = 1;

	var alien_skin_color_roll = roll_dice(dice_size, dice_count);

	switch (alien_skin_color_roll)
	{
		case 1:
			alien_skin_color_text = "blue";
			break;
		case 2:
			alien_skin_color_text = "brown";
			break;
		case 3:
			alien_skin_color_text = "green";
			break;
		case 4:
			alien_skin_color_text = "grey";
			break;
		case 5:
			alien_skin_color_text = "red";
			break;
		case 6:
			alien_skin_color_text = "yellow";
	}

	var alien_skin_color = new Object();
	alien_skin_color['id']   = alien_skin_color_roll;
	alien_skin_color['text'] = alien_skin_color_text;

	return alien_skin_color;
}

function generate_alien_skin_combo()
{
	var increase_contrast_roll;
	var increase_contrast;

	alien_skin_saturation = generate_alien_skin_saturation(false);
	alien_skin_saturation_id = alien_skin_saturation['id'];
	alien_skin_saturation_text = alien_skin_saturation['text'];

	alien_skin_color = generate_alien_skin_color();
	alien_skin_color_id = alien_skin_color['id'];
	alien_skin_color_text = alien_skin_color['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_color_text == "grey")
	{
		if (alien_skin_saturation_text == "pale")
		{
			alien_skin_saturation_text= "snow";
			alien_skin_color_text = "white";
		}
		else if (alien_skin_saturation_text == "dark")
		{
			alien_skin_saturation_text= "pitch";
			alien_skin_color_text = "black";
		}
	}

	var alien_skin_combo = new Object();
	alien_skin_combo['saturation'] = alien_skin_saturation_id;
	alien_skin_combo['color']     = alien_skin_color_id;
	alien_skin_combo['text']       = alien_skin_saturation_text + " " + alien_skin_color_text;

	return alien_skin_combo;
}

function generate_alien_skin()
{
	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'];

	if (alien_skin_saturation_text == "patterned")
	{
		alien_skin_combo_1 = generate_alien_skin_combo();
		alien_skin_id_1 = (alien_skin_combo_1['saturation'] * 1000) + (alien_skin_combo_1['color'] * 100);
		alien_skin_text_1 = alien_skin_combo_1['text'];

		alien_skin_combo_2 = generate_alien_skin_combo();
		alien_skin_id_2 = (alien_skin_combo_2['saturation'] * 10) + alien_skin_combo_2['color'];
		alien_skin_text_2 = alien_skin_combo_2['text'];

		alien_skin_id = alien_skin_id_1 + alien_skin_id_2;
		alien_skin_text = alien_skin_text_1 + " and " + alien_skin_text_2 + "patterns";
	}
	else
	{
		alien_skin_combo = generate_alien_skin_combo();
		alien_skin_id = (alien_skin_combo['saturation'] * 10) + alien_skin_combo['color'];
		alien_skin_text = alien_skin_combo['text'];
	}

	var alien_skin = new Object();
	alien_skin['id']     = alien_skin_id;
	alien_skin['text']       = alien_skin_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_text       = alien_skin['text'];

	random_alien = '<div id="random_alien_title" class="sidebar_title"><strong>Species:</strong> ' + 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.';
}());