Example #1
0
        public void RemoveEntities(string className)
        {
            if (this.Disposed == true)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            int count = _entities.Count;

            for (int i = 0; i < count; i++)
            {
                idMapEntity ent = _entities[i];

                if (ent.Dict.GetString("classname").Equals(className, StringComparison.OrdinalIgnoreCase) == true)
                {
                    _entities.RemoveAt(i);

                    i--;
                }
            }
        }
Example #2
0
		public static idMapEntity Parse(idLexer lexer, bool isWordSpawn = false, float version = idMapFile.CurrentMapVersion)
		{
			idToken token;

			if((token = lexer.ReadToken()) == null)
			{
				return null;
			}

			if(token.ToString() != "{")
			{
				lexer.Error("idMapEntity.Parse: {{ not found, found {0}", token.ToString());
				return null;
			}

			idMapEntity mapEnt = new idMapEntity();
			idMapBrush mapBrush = null;
			idMapPatch mapPatch = null;
			Vector3 origin = Vector3.Zero;
			bool worldEnt = false;
			string tokenValue;

			do
			{
				if((token = lexer.ReadToken()) == null)
				{
					lexer.Error("idMapEntity.Parse: EOF without closing brace");
					return null;
				}

				if(token.ToString() == "}")
				{
					break;
				}

				if(token.ToString() == "{")
				{
					// parse a brush or patch
					if((token = lexer.ReadToken()) == null)
					{
						lexer.Error("idMapEntity.Parse: unexpected EOF");
						return null;
					}

					if(worldEnt == true)
					{
						origin = Vector3.Zero;
					}

					tokenValue = token.ToString();

					// if is it a brush: brush, brushDef, brushDef2, brushDef3
					if(tokenValue.StartsWith("brush", StringComparison.OrdinalIgnoreCase) == true)
					{
						mapBrush = idMapBrush.Parse(lexer, origin, (tokenValue.Equals("brushDef2", StringComparison.OrdinalIgnoreCase) || tokenValue.Equals("brushDef3", StringComparison.OrdinalIgnoreCase)), version);

						if(mapBrush == null)
						{
							return null;
						}

						mapEnt.AddPrimitive(mapBrush);
					}
					// if is it a patch: patchDef2, patchDef3
					else if(tokenValue.StartsWith("patch", StringComparison.OrdinalIgnoreCase) == true)
					{
						mapPatch = idMapPatch.Parse(lexer, origin, tokenValue.Equals("patchDef3", StringComparison.OrdinalIgnoreCase), version);

						if(mapPatch == null)
						{
							return null;
						}

						mapEnt.AddPrimitive(mapPatch);
					}
					// assume it's a brush in Q3 or older style
					else
					{
						lexer.UnreadToken = token;

						mapBrush = idMapBrush.ParseQ3(lexer, origin);

						if(mapBrush == null)
						{
							return null;
						}

						mapEnt.AddPrimitive(mapBrush);
					}
				}
				else
				{
					// parse a key / value pair
					string key = token.ToString();
					token = lexer.ReadTokenOnLine();
					string value = token.ToString();

					// strip trailing spaces that sometimes get accidentally added in the editor
					value = value.Trim();
					key = key.Trim();

					mapEnt.Dict.Set(key, value);

					if(key.Equals("origin", StringComparison.OrdinalIgnoreCase) == true)
					{
						// scanf into doubles, then assign, so it is idVec size independent
						string[] parts = value.Split(' ');

						float.TryParse(parts[0], out origin.X);
						float.TryParse(parts[1], out origin.Y);
						float.TryParse(parts[2], out origin.Z);
					}
					else if((key.Equals("classname", StringComparison.OrdinalIgnoreCase) == true) && (value.Equals("worldspawn", StringComparison.OrdinalIgnoreCase) == true))
					{
						worldEnt = true;
					}
				}
			}
			while(true);

			return mapEnt;
		}
Example #3
0
        public static idMapEntity Parse(idLexer lexer, bool isWordSpawn = false, float version = idMapFile.CurrentMapVersion)
        {
            idToken token;

            if ((token = lexer.ReadToken()) == null)
            {
                return(null);
            }

            if (token.ToString() != "{")
            {
                lexer.Error("idMapEntity.Parse: {{ not found, found {0}", token.ToString());
                return(null);
            }

            idMapEntity mapEnt   = new idMapEntity();
            idMapBrush  mapBrush = null;
            idMapPatch  mapPatch = null;
            Vector3     origin   = Vector3.Zero;
            bool        worldEnt = false;
            string      tokenValue;

            do
            {
                if ((token = lexer.ReadToken()) == null)
                {
                    lexer.Error("idMapEntity.Parse: EOF without closing brace");
                    return(null);
                }

                if (token.ToString() == "}")
                {
                    break;
                }

                if (token.ToString() == "{")
                {
                    // parse a brush or patch
                    if ((token = lexer.ReadToken()) == null)
                    {
                        lexer.Error("idMapEntity.Parse: unexpected EOF");
                        return(null);
                    }

                    if (worldEnt == true)
                    {
                        origin = Vector3.Zero;
                    }

                    tokenValue = token.ToString();

                    // if is it a brush: brush, brushDef, brushDef2, brushDef3
                    if (tokenValue.StartsWith("brush", StringComparison.OrdinalIgnoreCase) == true)
                    {
                        mapBrush = idMapBrush.Parse(lexer, origin, (tokenValue.Equals("brushDef2", StringComparison.OrdinalIgnoreCase) || tokenValue.Equals("brushDef3", StringComparison.OrdinalIgnoreCase)), version);

                        if (mapBrush == null)
                        {
                            return(null);
                        }

                        mapEnt.AddPrimitive(mapBrush);
                    }
                    // if is it a patch: patchDef2, patchDef3
                    else if (tokenValue.StartsWith("patch", StringComparison.OrdinalIgnoreCase) == true)
                    {
                        mapPatch = idMapPatch.Parse(lexer, origin, tokenValue.Equals("patchDef3", StringComparison.OrdinalIgnoreCase), version);

                        if (mapPatch == null)
                        {
                            return(null);
                        }

                        mapEnt.AddPrimitive(mapPatch);
                    }
                    // assume it's a brush in Q3 or older style
                    else
                    {
                        lexer.UnreadToken = token;

                        mapBrush = idMapBrush.ParseQ3(lexer, origin);

                        if (mapBrush == null)
                        {
                            return(null);
                        }

                        mapEnt.AddPrimitive(mapBrush);
                    }
                }
                else
                {
                    // parse a key / value pair
                    string key = token.ToString();
                    token = lexer.ReadTokenOnLine();
                    string value = token.ToString();

                    // strip trailing spaces that sometimes get accidentally added in the editor
                    value = value.Trim();
                    key   = key.Trim();

                    mapEnt.Dict.Set(key, value);

                    if (key.Equals("origin", StringComparison.OrdinalIgnoreCase) == true)
                    {
                        // scanf into doubles, then assign, so it is idVec size independent
                        string[] parts = value.Split(' ');

                        float.TryParse(parts[0], out origin.X);
                        float.TryParse(parts[1], out origin.Y);
                        float.TryParse(parts[2], out origin.Z);
                    }
                    else if ((key.Equals("classname", StringComparison.OrdinalIgnoreCase) == true) && (value.Equals("worldspawn", StringComparison.OrdinalIgnoreCase) == true))
                    {
                        worldEnt = true;
                    }
                }
            }while(true);

            return(mapEnt);
        }