Code:
obj
Unit/var
ID = 0 // To make sure each Unit has its own unique ID upon creation
Name = "" // Name of the Unit
Desc = "" // Brief description on the Unit
Type = "" // Whether the Unit is a Land, Air, or Sea Type
Time = 0 // The Amount of Time to Create a Unit
Owner = "" // What Player owns which Unit
Level = 0 // The Level of a Unit
Power = 0 // The Power of a Unit
Health = 0 // The Current Health of the Unit
MaxHealth = 0 // The Max Health the Unit Starts With
list/Costs = list() // The Resources Cost necessary to create a Unit
list/Targets = list() // Unit-Types which a Unit can attack
list/Vulnerable = list() // Unit-Types which a Unit cannot attack
list/Requirements = list() // The Research Requirements needed to create a Unit
obj/Unit
Infantry
icon = 'Infantry.dmi'
icon_state = "Infantry"
Name = "Infantry" // Name of the Unit
Desc = "A foot soldier armed with a automatic machine gun, trained and used for military purposes"
Type = "Land" // Whether the Unit is a Land, Air, or Sea Type
Time = 30
Power = 3
Health = 10 // The Health of the Unit
MaxHealth = 10
Costs = list("Populace", 1, "Steel", 10, "Oil", 10)
Targets = list("Land") // Unit-Types which a Unit can attack
Vulnerable = list("Air","Sea") // Unit-Types which a Unit cannot attack
Requirements = list(/obj/Research/CodeOfArms, /obj/Research/Gunpowder) // The Research Requirements needed to create a Unit
Click()
if(usr.Action != src)
usr << "Unit Clicked"
usr.Unit_Info(src)
else
usr << "Unit Unselected"
usr.Action = ""
New(var/Location, var/ID)
src.Owner = usr
src.ID = ID
src.loc = locate(Location)
usr.Units.Add(src)
usr << "Unit Created!"
mob/proc
Unit_Info(var/obj/Unit/U)
sd_Alert(src,"Level: [U.Level] | Health: [U.Health]/[U.MaxHealth] || [U.Desc]","[U.Name]: [U.ID]")
src.Action = U
Create_Unit(var/obj/Unit/U, var/obj/Building/B)
usr << "Computations for Creating Unit"
var/idNum = 0
var/String = ""
var/Flag = 0
usr << "Prompting for Surety"
for(var/C in U.Costs)
if(istext(C))
String += "[C] "
else if(isnum(C))
String += "[C] Units, "
var/Response = sd_Alert(src,"Create Unit: [U.Name]? || Requirements: [String]","Create Unit",list("Yes","No"))
if(Response == "No")
return
else
usr << "Ensuring Resources for Unit Cost"
for(var/C=1, C<=U.Costs.len, C++)
if(istext(C))
if(C == "Populace")
if(B.Workers >= U.Costs[C+1])
Flag = 1
else
Flag = 0
sd_Alert(src,"You Do Not Have Enough Workers withinn Building, [B.Name]: [B.ID]","Inadequate Workers to Create Unit")
return
else if(Resources[U.Costs[C]] >= U.Costs[C+1])
Flag = 1
else
Flag = 0
sd_Alert(src,"You Do Not Have Enough Resources","Inadequate Resources to Create Unit")
return
usr << "Deducting Resources for Unit Cost"
if(Flag == 1)
for(var/C=1, C<=U.Costs.len, C++)
if(istext(C))
if(C == "Populace")
B.Workers -= U.Costs[C+1]
else
Resources[U.Costs[C]] -= U.Costs[C+1]
usr << "Delay for Spawning Unit"
spawn(U.Time)
for(var/obj/Unit/T in usr.Units)
if(U.Name == T.Name)
idNum++
usr << "Creating unit..."
var/TypePath = "/obj/Unit/[U.icon_state]"
new TypePath (B.Spawn, idNum)
Problem description:
I'm at a stump concerned where when I try to create a Unit, it is not being created. If you may need more information in trying to understand what is happening, I'm willing to give more, but I'm grateful for any input on how to make this work as intended [which is to say, the Unit is to be created]