- Joined
- Apr 24, 2012
- Messages
- 5,113
JASS:
//! zinc
library NameGenerator /* v 1.0
*************************************************************************************
*
* Allows you to generate unique names,either male or female
*
* Names are Warcraft 3-ish.
*
*************************************************************************************
*
* */ uses /*
*
* */ Table /* hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
*
*************************************************************************************
*
* API
*
* public struct NameGenerator[]
*
* static method female() -> string
* - Retrieves a female name
*
* static method male() -> string
* - Retrieves a male name
*
* public function GenerateName(boolean male) -> string
* - returns either male or female name depending on the boolean "male"
* - if true, returns male, else, return female, obviousy.
* - Wrapper function
*
*************************************************************************************
*
* Credits
*
* Magtheridon96 - Inspiration
* Bribe - Table
*
*************************************************************************************/
{
/*
Globals
*/
/*
Name strings
*/
string femaleNames[], string maleNames[], string prefixSurnames[], string suffixSurnames[];
/*
Name max indexes
*/
integer femaleMax = 0, maleMax = 0, prefixMax = 0, suffixMax = 0;
/*
String Name Tables
*/
Table female, Table male[];;
/*
Name indexer
*/
integer fIndex = 0, mIndex = 0;
integer fIndex2 = 0, mIndex2 = 0;
/*****************************************
*
* Name Generator Funcs
*
******************************************/
function FirstMaleName (string s)
{
integer i = 0;
for ( 1 <= i < maleMax)
{
mIndex2 = mIndex2 + 1;
male.string[mIndex] = maleNames[i] + " " + s;
}
}
function FirstFemaleName (string s)
{
integer i = 0;
for ( 1 <= i < femaleMax)
{
fIndex2 = fIndex2 + 1;
female.string[fIndex] = femaleNames[i] + " " + s;
}
}
function PrefixName (string s)
(
integer i = 0;
for ( 1 <= i < prefixMax)
{
FirstMaleName(prefixNames[i] + s);
FirstFemaleName(prefixNames[i] + s);
}
}
function SuffixName ()
(
integer i = 0;
for ( 1 <= i < prefixMax)
{
PrefixName(suffixNames[i]);
}
}
/*
Name Generator Struct
*/
module InitMod
private static method onInit() { init() }
endmodule
public struct NameGenerator[]
{
static method female() -> string
{
fIndex = fIndex + 1;
return female.string[fIndex];
}
static method male() -> string
{
mIndex = mIndex + 1;
return male.string[mIndex];
}
private static method init()
{
/*
Male Names
*/
maleNames[1] = "Illidan";
maleNames[2] = "Aurius";
maleNames[3] = "Tanin";
maleNames[4] = "Kael";
maleNames[5] = "Eldin";
maleNames[6] = "Lorn";
maleNames[7] = "Aldos";
maleNames[8] = "Hale";
maleNames[9] = "Gilaras";
maleNames[10] = "Kath'ranis";
maleNames[11] = "Tyroil";
maleNames[12] = "Sylvos";
maleNames[13] = "Tenris";
maleNames[14] = "Marakanis";
maleNames[15] = "Geldor";
maleNames[16] = "Hanlendor";
maleNames[17] = "Kelen";
maleNames[18] = "Magroth";
maleNames[19] = "Granis";
maleNames[20] = "Jorn";
maleNames[21] = "Sage";
maleNames[21] = "Malak";
maleNames[22] = "Gavirad";
maleNames[23] = "Morlune";
maleNames[24] = "Agamand";
maleNames[25] = "Ballador";
maleNames[26] = "Manadar";
maleNames[27] = "Zann";
maleNames[28] = "Arius";
maleNames[29] = "Karnwield";
maleNames[30] = "Buzan";
maleMax = 30;
/*
Female Names
*/
femaleNames[1] = "Tyrande";
femaleNames[2] = "Sylvanas";
femaleNames[3] = "Maiev";
femaleNames[4] = "Jaina";
femaleNames[5] = "Serena";
femaleNames[6] = "Jennala";
femaleNames[7] = "Shandris";
femaleNames[8] = "Anna";
femaleNames[9] = "Venna";
femaleNames[10] = "Nara";
femaleNames[11] = "Anya";
femaleNames[12] = "Clea";
femaleNames[13] = "Somand";
femaleNames[14] = "Siren";
femaleNames[15] = "Cyndia";
femaleNames[16] = "Anthis";
femaleNames[17] = "Mira";
femaleNames[18] = "Amora";
femaleNames[19] = "Lady";
femaleNames[20] = "Cordana";
femaleNames[21] = "Malace";
femaleNames[22] = "Sira";
femaleNames[23] = "Adora";
femaleNames[24] = "Theta";
femaleNames[25] = "Diana";
femaleNames[26] = "Ariel";
femaleNames[27] = "Anara";
femaleNames[28] = "Lanaya";
femaleNames[29] = "Rylai";
femaleNames[30] = "Lina";
femaleMax = 30;
/*
Surname Prefixes
*/
prefixNames[1] = "Blood";
prefixNames[2] = "Path";
prefixNames[3] = "Bronze";
prefixNames[4] = "Moon";
prefixNames[5] = "Sun";
prefixNames[6] = "Silver";
prefixNames[7] = "Blade";
prefixNames[8] = "Star";
prefixNames[9] = "Whisper";
prefixNames[10] = "Chill";
prefixNames[11] = "Night";
prefixNames[12] = "White";
prefixNames[13] = "Saber";
prefixNames[14] = "Dark";
prefixNames[15] = "Crest";
prefixNames[16] = "Winter";
prefixNames[17] = "Snow";
prefixNames[18] = "Thunder";
prefixNames[19] = "Fire";
prefixNames[20] = "Grim";
prefixNames[21] = "Cold";
prefixNames[22] = "Wolf";
prefixNames[23] = "Dust";
prefixNames[24] = "Harpy";
prefixNames[25] = "Storm";
prefixNames[26] = "Rune";
prefixNames[27] = "Plain";
prefixNames[28] = "Wind";
prefixNames[29] = "Ghost";
prefixNames[30] = "Truth";
prefixNames[31] = "Flame";
prefixNames[32] = "Light";
prefixNames[33] = "Spell";
prefixNames[34] = "Dawn";
prefixNames[35] = "Stone";
prefixNames[36] = "Iron";
prefixNames[37] = "Broad";
prefixNames[38] = "Stern";
prefixNames[39] = "Hawk";
prefixNames[40] = "Earth";
prefixNames[41] = "Death";
prefixNames[42] = "Eagle";
prefixNames[43] = "Way";
prefixNames[44] = "Terror";
prefixNames[45] = "Shadow";
prefixNames[46] = "Sin";
prefixNames[47] = "Hell";
prefixNames[48] = "Rage";
prefixMax = 48;
/*
Surname Suffixes
*/
suffixNames[1] = "weaver";
suffixNames[2] = "fang";
suffixNames[3] = "horn";
suffixNames[4] = "binder";
suffixNames[5] = "beard";
suffixNames[6] = "axe";
suffixNames[7] = "breaker";
suffixNames[8] = "cliff";
suffixNames[9] = "finder";
suffixNames[10] = "seeker";
suffixNames[11] = "strider";
suffixNames[12] = "brew";
suffixNames[13] = "song";
suffixNames[14] = "stone";
suffixNames[15] = "hammer";
suffixNames[16] = "runner";
suffixNames[17] = "fury";
suffixNames[18] = "wing";
suffixNames[19] = "chaser";
suffixNames[20] = "hoof";
suffixNames[21] = "totem";
suffixNames[22] = "steer";
suffixNames[23] = "bull";
suffixNames[24] = "slayer";
suffixNames[25] = "shade";
suffixNames[26] = "wood";
suffixNames[27] = "mane";
suffixNames[28] = "dragon";
suffixNames[29] = "singer";
suffixNames[30] = "scar";
suffixNames[31] = "claw";
suffixNames[32] = "tooth";
suffixNames[33] = "eye";
suffixNames[33] = "spear";
suffixNames[34] = "hammer";
suffixNames[35] = "bow";
suffixNames[36] = "wither";
suffixNames[37] = "stalker";
suffixNames[38] = "wrath";
suffixNames[39] = "blade";
suffixNames[40] = "bringer";
suffixMax = 40;
/*
Create Tables
*/
female = Table.create();
male = Table.create();
/*
Start Name Generator
*/
SuffixName();
}
module InitMod;
}
/*
Wrapper
*/
public function GenerateName(boolean male) -> string
{
if (male) { return NameGenerator.male(); }
return NameGenerator.female();
}
}
//! endzinc
Demo:
JASS:
library Test initializer init uses NameGenerator
private function buffer takes nothing returns nothing
local boolean b = GetRandomInt(1, 100) > 50
call BJDebugMsg(GenerateName(b))
endfunction
private function init takes nothing returns nothing
call BJDebugMsg("Generating Names")
call TimerStart(CreateTimer(), 0.1, true, function buffer)
endfunction
endlibrary
Note: Haven't tested this yet if the code is reaching the op-limit.