mob/proc/New()
--> Purpose: When a newly created Mob appears on the map, it checks if that mob is an AI / Player, and if it is the former, it then proceeds into the AI_StartUp() and AI_Wander()
mob/proc/AI_StartUp()
--> Purpose: Performs various "house-keeping" on the AI (clothing it, giving it a random name and age, generating its shop, giving it hair and possible skin-tone and eye-color, and generating an AI Family for it should it not have any Family Members).
mob/proc/AI_Wander()
--> Purpose: Basic AI Movement around a general area.
mob/proc/Fill_In(var/mob/M)
--> Purpose: Called by the AI_StartUp(), to fill in the information of a newly created AI Mob, based upon the var/mob/M passed through the procedure as an argument / parameter.
Note:
The AI_StartUp() is quite a bulky piece of code as it is very repetitive, and unfortunately, where the issue probably occurs. As such, I've labelled the sections of it to help with navigation.Code:
mob/proc/AI_Wander()
while(src.Player == "AI")
var/Dir = rand(1,4)
sleep(2)
if(Dir == 1)
step(src, NORTH)
if(Dir == 2)
step(src, EAST)
if(Dir == 3)
step(src, SOUTH)
if(Dir == 4)
step(src, WEST)
mob/proc/AI_StartUp()
// ----- Assorting Genders and Age ----- //
if(src.icon == 'MaleBase.dmi')
src.Gender = "Male"
else if(src.icon == 'FemaleBase.dmi')
src.Gender = "Female"
if(src.Age == 0)
var/Num = rand(1,3)
if(Num == 1)
src.Age = rand(15, 30)
else
src.Age = rand(30, 70)
// ----- Generate Random Names ----- //
if(src.Name != "None" && src.House != "None")
if(FirstNames.Find(src.Name) == 0)
FirstNames.Add(src.Name)
if(HouseNames.Find(src.House) == 0)
HouseNames.Add(src.House)
else if(src.Name == "None")
if(src.icon == 'MaleBase.dmi')
src.Name = Male_RNG.Create()
else if(src.icon == 'FemaleBase.dmi')
src.Name = Female_RNG.Create()
else if(src.House == "None" && src.Liege != "None")
src.House = House_RNG.Create()
// ----- Clothe the AI ----- //
if(src.Clothing.len == 0)
if(src.Gender == "Male")
var/Num = rand(1,3)
if(Num == 1)
var/obj/Clothing/Shirt/SH = new(src)
src.contents += SH
else if(Num == 2)
var/obj/Clothing/SleevelessShirt/SH = new(src)
src.contents += SH
else if(Num == 3)
var/obj/Clothing/LongSleeveShirt/SH = new(src)
src.contents += SH
var/obj/Clothing/Pants/P = new(src)
src.contents += P
if(src.Gender == "Female")
var/Num = rand(1,2)
if(Num == 1)
var/obj/Clothing/Dress/D = new(src)
src.contents += D
else
Num = rand(1,3)
if(Num == 1)
var/obj/Clothing/Shirt/SH = new(src)
src.contents += SH
else if(Num == 2)
var/obj/Clothing/SleevelessShirt/SH = new(src)
src.contents += SH
else if(Num == 3)
var/obj/Clothing/LongSleeveShirt/SH = new(src)
src.contents += SH
var/obj/Clothing/Pants/P = new(src)
src.contents += P
var/Num = rand(1,3)
if(Num == 1)
var/obj/Clothing/Coat/SH = new(src)
src.contents += SH
else if(Num == 2)
var/obj/Clothing/Cape/SH = new(src)
src.contents += SH
else if(Num == 3)
var/obj/Clothing/Scarf/SH = new(src)
src.contents += SH
var/obj/Clothing/Shoes/S = new(src)
src.contents += S
for(var/obj/Clothing/C in src.contents)
if(C.Stackable == 0 && C.Quantity == 1)
src.overlays.Add(C)
src.Clothing.Add(C)
// ----- Populate the AI Store ----- //
for(var/atom/A in src.contents)
if(istype(A,/obj/Clothing))
var/obj/Clothing/O = A
if(O.Stackable == 1 && O.Quantity > 1)
src.Selling.Add(O)
if(istype(A,/obj/Armour))
var/obj/Armour/O = A
if(O.Stackable == 1 && O.Quantity > 1)
src.Selling.Add(O)
if(istype(A,/obj/Weapon))
var/obj/Weapon/O = A
if(O.Stackable == 1 && O.Quantity > 1)
src.Selling.Add(O)
if(istype(A,/obj/Potion))
var/obj/Potion/O = A
if(O.Stackable == 1 && O.Quantity > 1)
src.Selling.Add(O)
if(istype(A,/obj/Item))
var/obj/Item/O = A
if(O.Stackable == 1 && O.Quantity > 1)
src.Selling.Add(O)
if(istype(A,/obj/Material))
var/obj/Material/O = A
if(O.Stackable == 1 && O.Quantity > 1)
src.Selling.Add(O)
// ----- Giving AIs Hair + Skin Tone ----- //
if(src.Hair == "")
var/Num = rand(1,5)
if(src.Gender == "Male")
if(Num == 1)
var/obj/Hair/I = new()
I.icon = 'Short Curly Hair.dmi'
src.Hair = "Short Curly Hair"
src.overlays.Add(I)
if(Num == 2)
var/obj/Hair/I = new()
I.icon = 'Short Combed Hair.dmi'
src.Hair = "Short Combed Hair"
src.overlays.Add(I)
if(Num == 3)
var/obj/Hair/I = new()
I.icon = 'Long Curly Hair.dmi'
src.Hair = "Long Curly Hair"
src.overlays.Add(I)
if(Num == 4)
var/obj/Hair/I = new()
I.icon = 'Long Combed Hair.dmi'
src.Hair = "Long Combed Hair"
src.overlays.Add(I)
if(Num == 5)
var/obj/Hair/I = new()
I.icon = 'Low Cut Hair.dmi'
src.Hair = "Low Cut Hair"
src.overlays.Add(I)
if(src.Gender == "Female")
if(Num == 1)
var/obj/Hair/I = new()
I.icon = 'Short Curly Hair with Bangs.dmi'
src.Hair = "Short Curly Hair with Bangs"
src.overlays.Add(I)
if(Num == 2)
var/obj/Hair/I = new()
I.icon = 'Short Ponytail Hair.dmi'
src.Hair = "Short Ponytail Hair"
src.overlays.Add(I)
if(Num == 3)
var/obj/Hair/I = new()
I.icon = 'Long Hair with Bangs.dmi'
src.Hair = "Long Hair with Bangs"
src.overlays.Add(I)
if(Num == 4)
var/obj/Hair/I = new()
I.icon = 'Long Ponytail Hair.dmi'
src.Hair = "Long Ponytail Hair"
src.overlays.Add(I)
if(Num == 5)
var/obj/Hair/I = new()
I.icon = 'Free-Flowing Long Hair.dmi'
src.Hair = "Free-Flowing Long Hair"
src.overlays.Add(I)
if(src.Capital == "Garoh")
if(src.Gender == "Female")
src.icon = 'Nomad MaleBase.dmi'
else if(src.Gender == "Male")
src.icon = 'Nomad FemaleBase.dmi'
// ----- Create Family for the AI ----- //
if(src.House != "None")
if(src.Family.len == 0)
src.Family.Add(src)
var/Num = rand(1,5)
var/Mem = 0
for(var/x = 1; x <= Num; x++)
Mem = rand(1,5)
src.State = "Amnt: [Num] | Mem: [Mem] | Cycle: [x]"
if(Mem == 1)
if(src.Gender == "Male")
if(src.Misc[0] == 0)
var/mob/Lady_Wife/A = new(src.loc)
A.Name = Male_RNG.Create()
A.Age = src.Age + rand(-5,5)
A.Fill_In(src)
src.Family.Add(A)
src.Misc[0] = 1
if(src.Gender == "Female")
if(src.Misc[1] == 0)
var/mob/Lord_Husband/A = new(src.loc)
A.Name = Female_RNG.Create()
A.Age = src.Age + rand(-5,5)
A.Fill_In(src)
src.Family.Add(A)
src.Misc[1] = 1
if(Mem == 2)
var/mob/Lady_Daughter/A = new(src.loc)
A.Name = Female_RNG.Create()
A.Age = rand(5, src.Age/2)
A.Fill_In(src)
src.Family.Add(A)
if(Mem == 3)
var/mob/Lord_Son/A = new(src.loc)
A.Name = Male_RNG.Create()
A.Age = rand(5, src.Age/2)
A.Fill_In(src)
src.Family.Add(A)
if(Mem == 4)
if(src.Misc[2] == 0)
var/mob/Lady_Mother/A = new(src.loc)
A.Name = Female_RNG.Create()
A.Age = src.Age + rand(18,25)
A.Fill_In(src)
src.Family.Add(A)
src.Misc[2] = 1
if(Mem == 5)
if(src.Misc[3] == 0)
var/mob/Lord_Father/A = new(src.loc)
A.Name = Male_RNG.Create()
A.Age = src.Age + rand(18,25)
A.Fill_In(src)
src.Family.Add(A)
src.Misc[3] = 1
if(x == Num)
src.State = "Cycle Break | Cycle: [x]"
break
for(var/mob/A in src.Family)
if(A != src)
A.Family = src.Family
return
mob/proc/Fill_In(var/mob/M)
src.House = M.House
src.Sigil = M.Sigil
src.Words = M.Words
src.Capital = M.Capital
src.Liege = M
src.x += rand(3,5)
src.y += rand(3,5)
mob/New()
if(src.Player == "AI")
src.AI_StartUp()
src.AI_Wander()
Note:
Any statements concerning "src.Misc[x]" is simply a miscellaneous list variable I created to handle miscellaneous code bugs (in this case, avoiding an AI-Mob from having 2 wives, 2 husbands, 2 mothers, and 2 fathers).
Problem description:
Finally, the issue that I am getting here is that only the first Family-Created AI-Mob (FC-AM) is being created, despite the random variables within the "Family Creation Section" of the AI_StartUp() may be more than 1 (I've verified this through the statement "src.State = Amnt: [Num] | Mem: [Mem] | Cycle: [x]" and looking at the values). Furthermore, the FC-AM does not go through the the Fill_In(), the for-loop statement terminates at the first Cycle, the Original AI-Mob (O-AM) on which all of this procedure is based upon does not go through to AI_Wander() while the FC-AM does, and finally, the FC-AM does not gain its "Family Members" in its Family-List.
My Belief:
I believe the issue lies in the fact that upon the creation of the FC-AM, it too will be subject to go through the AI_StartUp() (as was intended, as it allows for the newly created FC-AM to go through the other "house-cleaning" sections of the code). I think this somehow creates the problem, though what it is? I am uncertain... (An endless loop? Though, I think it'd be a different type of reaction...)
Any form of guidance on this matter would be greatly appreciated.
P.S.
I cannot go through the process of creating pre-defined AIs for everything as the list of AIs I've pre-defined are already around 50+, some of which actually requires Family Members; hence why I've developed this code. I am also aware that depending on the amount of Mobs created through this, I could very well be looking at intense server issues related to lag and/or bugs, but, I'll deal with that when the time comes.