public Animal(AnimalName n, int mas, int mat, string[] t, BodyPlan p, char c, Color col, double d) : base(n, mas, mat, t) { bodyplan = p; this.c = c; color = col; dimorphismConstant = d; animals.Append(this); }
public BodyPlan(AnimalName n, BodyPlan b, BodyPart[] p, string[] t) { name = n; if (b == null) { parts = p; tags = t; } else { parts = b.parts.Concat(p).ToArray(); tags = t.Concat(b.tags).ToArray(); } bodyPlans.Append(this); }
public static void ParseData() { IEnumerable <string> raw = File.ReadAllLines("data/bio_part.dat") .Concat(File.ReadAllLines("data/bio_plan.dat")) .Concat(File.ReadAllLines("data/bio.dat")) .Select(line => Regex.Replace(line.ToLower(), @"^\s+|\s+$", "") // set lowercase; remove leading/trailing whitespace ); string type = ""; // MAKE SURE TO COPY THESE TO RESET AnimalName name = AnimalName.none; int mass = 0; int maturity_time = 0; ushort relsize = 0; BodyPart parent = BodyPart.root; BodyPart[] parts = new BodyPart[0]; BodyPlan body_plan = BodyPlan.none; string[] tags = new string[0]; char c = '\0'; Color color = Color.Gray; double dimorphism = 1; Action Reset = () => { name = AnimalName.none; mass = 0; maturity_time = 0; relsize = 0; parent = BodyPart.root; parts = new BodyPart[0]; body_plan = BodyPlan.none; tags = new string[0]; c = '\0'; color = Color.Gray; dimorphism = 1; }; int partcount = 0; int plans = 0; int animals = 0; int plants = 0; foreach (string line in raw) { string[] split = line.Split(" "); string kw = split[0]; switch (kw) { case "part": case "plan": case "animal": case "plant": type = kw; continue; case "name": name = new AnimalName(split[1]); continue; case "tags": tags = split.Skip(1).ToArray(); continue; case "parent": parent = BodyPart.FromName(split[1]); continue; case "parts": parts = split.Skip(1).Select(s => BodyPart.FromName(s)).ToArray(); continue; case "icon": color = Program.ColorFromHex(split[1]); c = split[2][0]; continue; case "mass": mass = int.Parse(split[1]); continue; case "maturity_time": maturity_time = int.Parse(split[1]); continue; case "relsize": relsize = ushort.Parse(split[1]); continue; case "dimorphism": dimorphism = double.Parse(split[1]); continue; case "template": case "bodyplan": body_plan = BodyPlan.FromName(split[1]); continue; case "end": break; // handled below default: // just a comment! continue; } // handle end if (type == "part") { new BodyPart(name, parent, tags, relsize); partcount++; } else if (type == "plan") { new BodyPlan(name, body_plan, parts, tags); plans++; } else if (type == "animal") { new Animal(name, mass, maturity_time, tags, body_plan, c, color, dimorphism); animals++; } else if (type == "plant") { new Plant(name, mass, maturity_time, tags); plants++; } else { throw new NotImplementedException(); } // reset Reset(); } Program.Log(String.Format("{0} bodyparts loaded", partcount), 0); Program.Log(String.Format("{0} bodyplans loaded", plans), 0); Program.Log(String.Format("{0} plants loaded", plants), 0); Program.Log(String.Format("{0} animals loaded", animals), 0); }