示例#1
0
文件: BodyPart.cs 项目: bilwis/SH2RL
 public void ConnectToBody(Body body, BodyPart parent=null)
 {
     cleanup();
     IsSevered = false;
     initialized = false;
     this.body = body;
     this.parent = parent;
 }
示例#2
0
文件: BodyPart.cs 项目: bilwis/SH2RL
        public BodyPart Sever(int x, int y, int z, MessageHandler msg)
        {
            this.x = x;
            this.y = y;
            this.z = z;
            Init(Util.DecodeRGB(rgb), msg);
            this._desc = "A severed " + Name.ToLower() + " lies here.";
            IsSevered = true;
            parent = null;

            return this;
        }
示例#3
0
文件: Body.cs 项目: bilwis/SH2RL
        public void ParseBodyDefinition(string filename)
        {
            Random rand = new Random();
            XmlTextReader reader = new XmlTextReader(filename);
            string name;
            float var = 1.0f;

            List<Organ> organ_defs = new List<Organ>();
            List<OrganConstructor> bp_organs = new List<OrganConstructor>();
            Dictionary<string, string> bp_parents = new Dictionary<string,string>();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        switch (reader.Name)
                        {
                            case "name":
                                name = reader.ReadElementContentAsString();
                                break;
                            case "height":
                                height = reader.ReadElementContentAsFloat();
                                break;
                            case "width":
                                width = reader.ReadElementContentAsFloat();
                                break;
                            case "depth":
                                depth = reader.ReadElementContentAsFloat();
                                break;
                            case "variation":
                                var = reader.ReadElementContentAsFloat();
                                break;

                            case "organ_def":
                                Organ o = parseOrganDefinition(reader);
                                if (o == null)
                                    throw new Exception("Error while parsing body definition XML: Organ above line " + reader.LineNumber + " not correctly parsed.");
                                organ_defs.Add(o);
                                break;

                            case "body_part":
                                string guid = System.Guid.NewGuid().ToString();

                                string bp_name = "ERROR";
                                float surface = 0.0f;
                                float weight = 0.0f;
                                bool essential = false;

                                int rgb = 0;
                                string display_char = " ";

                                bool symetrical = false;
                                string parent_name = null;

                                bool readingOrgan = false;
                                OrganConstructor temp = new OrganConstructor();

                                bool bp_done = false;

                                while (reader.Read() && !bp_done)
                                {

                                    switch (reader.NodeType)
                                    {
                                        case XmlNodeType.Element:
                                            switch (reader.Name)
                                            {
                                                case "name":
                                                    if (!readingOrgan)
                                                        bp_name = reader.ReadElementContentAsString();
                                                    else
                                                        temp.alias = reader.ReadElementContentAsString();
                                                    break;
                                                case "surface":
                                                    surface = reader.ReadElementContentAsFloat();
                                                    break;
                                                case "weight":
                                                    weight = reader.ReadElementContentAsFloat();
                                                    break;
                                                case "essential":
                                                    essential = reader.ReadElementContentAsBoolean();
                                                    break;
                                                case "parent":
                                                    parent_name = reader.ReadElementContentAsString();
                                                    break;
                                                case "display_char":
                                                    display_char = reader.ReadElementContentAsString();
                                                    break;
                                                case "color":
                                                    string[] temp_col_arr = reader.ReadElementContentAsString().Split(',');
                                                    rgb = Util.EncodeRGB(Int32.Parse(temp_col_arr[0]), Int32.Parse(temp_col_arr[1]), Int32.Parse(temp_col_arr[2]));
                                                    break;
                                                case "symetrical":
                                                    symetrical = reader.ReadElementContentAsBoolean();
                                                    break;
                                                case "organ":
                                                    if (readingOrgan)
                                                        throw new Exception("Error while parsing body definition XML: Organ element not closed before line " + reader.LineNumber + ".");
                                                    readingOrgan = true;
                                                    temp = new OrganConstructor();
                                                    //set default
                                                    temp.hit_prob = 1.0f;
                                                    break;
                                                case "type":
                                                    temp.name = reader.ReadElementContentAsString();
                                                    break;
                                                case "thickness":
                                                    temp.thickness = reader.ReadElementContentAsFloat();
                                                    break;
                                                case "hit_prob":
                                                    temp.hit_prob = reader.ReadElementContentAsFloat();
                                                    break;
                                            }
                                            break;
                                        case XmlNodeType.EndElement:
                                            switch (reader.Name)
                                            {
                                                case "organ":
                                                    readingOrgan = false;
                                                    temp.bp_guid = guid;
                                                    bp_organs.Add(temp);
                                                    break;
                                                case "body_part":
                                                    BodyPart new_bp = new BodyPart(guid, bp_name, surface, weight, essential, symetrical, display_char[0], rgb);
                                                    bp_parents.Add(new_bp.GUID, parent_name);
                                                    parts.Add(new_bp.GUID, new_bp);
                                                    bp_done = true;
                                                    break;
                                            }
                                            break;
                                    }
                                }

                                break;
                        }
                        break;
                    case XmlNodeType.EndElement:
                        switch (reader.Name)
                        {

                        }
                        break;
                }
            }

            //load bp_organs into bodyparts, attach bodyparts to Body
            foreach (BodyPart p in parts.Values)
            {
                foreach (OrganConstructor oc in bp_organs)
                {
                    if (p.GUID == oc.bp_guid)
                    {
                        foreach (Organ o in organ_defs)
                        {
                            if (o.name == oc.name)
                            {
                                p.AddOrgan(new Organ(o, oc.thickness, oc.hit_prob, oc.alias));
                            }
                        }
                    }
                }
                if (bp_parents[p.GUID] != null)
                {
                    foreach (BodyPart par in parts.Values)
                    {
                        if (par.Name == bp_parents[p.GUID])
                            p.ConnectToBody(this, par);
                    }
                }
                else
                {
                    p.ConnectToBody(this);
                }
            }

            this.height = (float)(height + (var * (rand.NextDouble() - 0.5)));
            this.width = (float)(width + (var * (rand.NextDouble() - 0.5)));
            this.depth = (float)(depth + (var * (rand.NextDouble() - 0.5)));
            loaded = true;
        }
示例#4
0
文件: Body.cs 项目: bilwis/SH2RL
 public void AddBodyPart(BodyPart bp, BodyPart parent=null)
 {
     parts.Add(bp.GUID, bp);
     bp.ConnectToBody(this, parent);
 }