public FrameStructure GetShema(short[,] map, TileInfoStructure info, Vector2 pos) { currentTileInfo = info; FrameStructure rez; short[,] mapTemplate; rez = new FrameStructure(0, 0); // rez.TileCollection = LayerData.LightLayer.TexrureName; // Debug.Log(map[1, 1]); if (map[1, 1] != 0) { rez.FrameX = Settings.LIGHT_SIZE / 2 - 2; rez.FrameY = Settings.LIGHT_SIZE / 2 - 2; } mapTemplate = new short[, ] { { -2, 0, -2 }, { -2, -2, -2 }, { -2, 1, -2 } }; if (ChackMap(mapTemplate, map, info)) { // return GetTop(); } return(rez); }
public FrameStructure GetShema(short[,] map, TileInfoStructure info) { var rez = new FrameStructure(0, 0); // rez.TileCollection = LayerData.LightLayer.TexrureName; return(rez); }
public FrameStructure GetShemaStructure(TileInfoStructure[,] map, TileInfoStructure info) { //throw new System.NotImplementedException(); FrameStructure rez; /* * int shift = 0;//200; * float radius = Settings.LIGHT_SIZE/2f;//6.0f; * * float min = shift - ((radius) - 1); * float max = shift + ((radius) - 1); * * var alpha = Mathf.Lerp(0, Settings.LIGHT_SIZE/2 , map[1, 1].lightAlpha); * * * * var val = (int)Mathf.Clamp((alpha) + shift, min, max); * // Debug.LogError(val); */ // Debug.LogError(map[1, 1].lightAlpha); // map[1, 1].lightAlpha = 1; //var alpha = (int)Mathf.Lerp(0, 255, map[1, 1].lightAlpha); var alpha = 255 - map[1, 1].lightAlpha2; //if (alpha != 0) //Debug.LogError(alpha); if (map[1, 1].type == 0 && map[1, 1].typeBG == 0) { alpha = 0; } rez = new FrameStructure(alpha, alpha); rez.TileCollection = "LightTiles";//LayerData.LightLayer.TexrureName; return(rez); }
void PrintMap(short[,] map) { string rez = ""; for (int y = 0; y < map.GetLength(0); y++) { for (int x = 0; x < map.GetLength(1); x++) { rez += ", " + map[x, y]; } rez += "\n"; } Debug.LogError(rez); }
public FrameStructure GetShema(short[,] map, TileInfoStructure info) { if (info.type == 0) { return(FrameStructure.Empty()); } //MapGenerator.surface FrameStructure rez = new FrameStructure(1, 1); rez.TileCollection = "LightTiles"; return(rez); }
public FrameStructure GetShema(short[,] map, TileInfoStructure info, Vector2Int pos) { /*if (info.type == 0) { * return FrameStructure.Empty(); * }*/ //if (info.IsWater()) { if (info.IsWater() || pos.y > MapGenerator.surface[pos.x].y) { return(FrameStructure.Empty()); } //} FrameStructure rez = new FrameStructure(1, 1); rez.TileCollection = "LightTiles"; return(rez); }
public FrameStructure GetShema(short[,] map, TileInfoStructure info) { FrameStructure rez = new FrameStructure(); currentTileInfo = info; // GetTop(); if (mapTop == null) { mapTop = new short[, ] { { -2, -1, -2 }, { -2, -2, -2 }, { -2, -2, -2 } } } ; if (ChackMap(mapTop, map, info)) { return(GetTop()); } // GetBottom(); if (mapBottom == null) { mapBottom = new short[, ] { { -2, -2, -2 }, { -2, -2, -2 }, { -2, -1, -2 } } } ; if (ChackMap(mapBottom, map, info)) { return(GetBottom()); } return(rez); } }
public FrameStructure GetShema(short[,] map, TileInfoStructure info) { // return new FrameStructure(1, 0, "Liquid_000"); // topRez.FrameX = currentTileInfo.randomTile; // topRez.DeltaHeight = 0;//CountToDeltaHeight(currentTileInfo.count); // return topRez; currentTileInfo = info; var rez = new FrameStructure(0, 0); rez.TileCollection = "Liquid_000"; //return GetTop(); // 0 пусто // 1 тогоже типа // -1 не тогоже типа // -2 не рассматриваем // 2 не пусто // GetCenter(); if (mapCenter == null) { mapCenter = new short[, ] { { -2, 1, -2 }, { 1, -2, 1 }, { -2, 1, -2 } }; } if (ChackMap(mapCenter, map, info)) { return(GetCenter()); } //GetLeftCorner(); if (mapLeftCorner == null) { mapLeftCorner = new short[, ] { { -2, -1, -2 }, { -1, -2, 1 }, { -2, 1, -2 } }; } if (ChackMap(mapLeftCorner, map, info)) { return(GetLeftTopCorner()); } //GetRightCorner(); if (mapRightCorner == null) { mapRightCorner = new short[, ] { { -2, -1, -2 }, { 1, -2, -1 }, { -2, 1, -2 } }; } if (ChackMap(mapRightCorner, map, info)) { return(GetRightTopCorner()); } //GetOneHorizontalCenter(); if (mapOneHorizontalCenter == null) { mapOneHorizontalCenter = new short[, ] { { -2, -1, -2 }, { 1, -2, 1 }, { -2, -1, -2 } }; } if (ChackMap(mapOneHorizontalCenter, map, info)) { return(GetTop()); } //GetOneVerticalCenter(); if (mapOneVerticalCenter == null) { mapOneVerticalCenter = new short[, ] { { -2, 1, -2 }, { -1, -2, -1 }, { -2, 1, -2 } }; } if (ChackMap(mapOneVerticalCenter, map, info)) { return(GetOneVerticalCenter()); } //GetOneRight(); if (mapOneRight == null) { mapOneRight = new short[, ] { { -2, -1, -2 }, { -1, -2, 1 }, { -2, -1, -2 } }; } if (ChackMap(mapOneRight, map, info)) { return(GetTop()); } //GetOneLeft(); if (mapOneLeft == null) { mapOneLeft = new short[, ] { { -2, -1, -2 }, { 1, -2, -1 }, { -2, -1, -2 } }; } if (ChackMap(mapOneLeft, map, info)) { return(GetTop()); } //GetOneTop(); if (mapOneTop == null) { mapOneTop = new short[, ] { { -2, -1, -2 }, { -1, -2, -1 }, { -2, 1, -2 } }; } if (ChackMap(mapOneTop, map, info)) { return(GetOneTop()); } //GetOneBottom(); if (mapOneBottom == null) { mapOneBottom = new short[, ] { { -2, 1, -2 }, { -1, -2, -1 }, { -2, -1, -2 } }; } if (ChackMap(mapOneBottom, map, info)) { return(GetOneBottom()); } //GetTop(); if (mapTop == null) { mapTop = new short[, ] { { -2, -1, -2 }, { 1, -2, 1 }, { -2, 1, -2 } }; } if (ChackMap(mapTop, map, info)) { return(GetTop()); } //GetBottom(); if (mapBottom == null) { mapBottom = new short[, ] { { -2, 1, -2 }, { 1, -2, 1 }, { -2, -1, -2 } }; } if (ChackMap(mapBottom, map, info)) { return(GetBottom()); } //GetLeft(); if (mapLeft == null) { mapLeft = new short[, ] { { -2, 1, -2 }, { -1, -2, 1 }, { -2, 1, -2 } }; } if (ChackMap(mapLeft, map, info)) { return(GetLeft()); } //GetRight(); if (mapRight == null) { mapRight = new short[, ] { { -2, 1, -2 }, { 1, -2, -1 }, { -2, 1, -2 } }; } if (ChackMap(mapRight, map, info)) { return(GetRight()); } //GetLeftBottomCorner(); if (mapLeftBottomCorner == null) { mapLeftBottomCorner = new short[, ] { { -2, 1, -2 }, { -1, -2, 1 }, { -2, -1, -2 } }; } if (ChackMap(mapLeftBottomCorner, map, info)) { return(GetLeftBottomCorner()); } //GetRightBottomCorner(); if (mapmapLeftBottomCorner == null) { mapmapLeftBottomCorner = new short[, ] { { -2, 1, -2 }, { 1, -2, -1 }, { -2, -1, -2 } }; } if (ChackMap(mapmapLeftBottomCorner, map, info)) { return(GetRightBottomCorner()); } return(GetOne()); }
internal bool Parse(ModeldefParser parser) { // Read modeldef structure contents bool parsingfinished = false; while (!parsingfinished && parser.SkipWhitespace(true)) { string token = parser.ReadToken().ToLowerInvariant(); if (string.IsNullOrEmpty(token)) { continue; } switch (token) { case "path": parser.SkipWhitespace(true); path = parser.StripTokenQuotes(parser.ReadToken(false)).Replace("\\", "/"); // Don't skip newline if (string.IsNullOrEmpty(path)) { parser.ReportError("Expected model path"); return(false); } break; case "model": parser.SkipWhitespace(true); // Model index int index = 0; token = parser.ReadToken(); if (!parser.ReadSignedInt(token, ref index)) { // Not numeric! parser.ReportError("Expected model index, but got \"" + token + "\""); return(false); } if (index < 0) { // Out of bounds parser.ReportError("Model index must not be in negative"); return(false); } parser.SkipWhitespace(true); // Model path token = parser.StripTokenQuotes(parser.ReadToken(false)).ToLowerInvariant(); // Don't skip newline if (string.IsNullOrEmpty(token)) { parser.ReportError("Expected model name"); return(false); } // Check invalid path chars if (!parser.CheckInvalidPathChars(token)) { return(false); } // Check extension string modelext = Path.GetExtension(token); if (string.IsNullOrEmpty(modelext)) { parser.ReportError("Model \"" + token + "\" won't be loaded. Models without extension are not supported by GZDoom"); return(false); } if (modelext != ".md3" && modelext != ".md2" && modelext != ".3d" && modelext != ".obj") { parser.ReportError("Model \"" + token + "\" won't be loaded. Only Unreal 3D, MD2, MD3, and OBJ models are supported"); return(false); } // GZDoom allows models with identical index, it uses the last one encountered modelnames[index] = Path.Combine(path, token).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); break; case "skin": parser.SkipWhitespace(true); // Skin index int skinindex = 0; token = parser.ReadToken(); if (!parser.ReadSignedInt(token, ref skinindex)) { // Not numeric! parser.ReportError("Expected skin index, but got \"" + token + "\""); return(false); } if (skinindex < 0) { // Out of bounds parser.ReportError("Skin index must not be negative"); return(false); } parser.SkipWhitespace(true); // Skin path token = parser.StripTokenQuotes(parser.ReadToken(false)).ToLowerInvariant(); // Don't skip newline if (string.IsNullOrEmpty(token)) { parser.ReportError("Expected skin path"); return(false); } // Check invalid path chars if (!parser.CheckInvalidPathChars(token)) { return(false); } // GZDoom allows skins with identical index, it uses the last one encountered skinnames[skinindex] = Path.Combine(path, token); break; // SurfaceSkin <int modelindex> <int surfaceindex> <string skinfile> case "surfaceskin": parser.SkipWhitespace(true); // Model index int modelindex = 0; token = parser.ReadToken(); if (!parser.ReadSignedInt(token, ref modelindex)) { // Not numeric! parser.ReportError("Expected model index, but got \"" + token + "\""); return(false); } if (modelindex < 0) { // Out of bounds parser.ReportError("Model index must not be negative"); return(false); } parser.SkipWhitespace(true); // Surfaceindex index int surfaceindex = 0; token = parser.ReadToken(); if (!parser.ReadSignedInt(token, ref surfaceindex)) { // Not numeric! parser.ReportError("Expected surface index, but got \"" + token + "\""); return(false); } if (surfaceindex < 0) { // Out of bounds parser.ReportError("Surface index must be positive integer"); return(false); } parser.SkipWhitespace(true); // Skin path token = parser.StripTokenQuotes(parser.ReadToken(false)).ToLowerInvariant(); // Don't skip newline if (string.IsNullOrEmpty(token)) { parser.ReportError("Expected skin path"); return(false); } // Check invalid path chars if (!parser.CheckInvalidPathChars(token)) { return(false); } // Store if (!surfaceskinenames.ContainsKey(modelindex)) { surfaceskinenames[modelindex] = new Dictionary <int, string>(); } surfaceskinenames[modelindex][surfaceindex] = Path.Combine(path, token).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); break; case "scale": parser.SkipWhitespace(true); token = parser.ReadToken(); if (!parser.ReadSignedFloat(token, ref scale.Y)) { // Not numeric! parser.ReportError("Expected Scale X value, but got \"" + token + "\""); return(false); } parser.SkipWhitespace(true); token = parser.ReadToken(); if (!parser.ReadSignedFloat(token, ref scale.X)) { // Not numeric! parser.ReportError("Expected Scale Y value, but got \"" + token + "\""); return(false); } parser.SkipWhitespace(true); token = parser.ReadToken(); if (!parser.ReadSignedFloat(token, ref scale.Z)) { // Not numeric! parser.ReportError("Expected Scale Z value, but got \"" + token + "\""); return(false); } break; case "offset": parser.SkipWhitespace(true); token = parser.ReadToken(); if (!parser.ReadSignedFloat(token, ref offset.X)) { // Not numeric! parser.ReportError("Expected Offset X value, but got \"" + token + "\""); return(false); } parser.SkipWhitespace(true); token = parser.ReadToken(); if (!parser.ReadSignedFloat(token, ref offset.Y)) { // Not numeric! parser.ReportError("Expected Offset Y value, but got \"" + token + "\""); return(false); } parser.SkipWhitespace(true); token = parser.ReadToken(); if (!parser.ReadSignedFloat(token, ref offset.Z)) { // Not numeric! parser.ReportError("Expected Offset Z value, but got \"" + token + "\""); return(false); } break; case "zoffset": parser.SkipWhitespace(true); token = parser.ReadToken(); if (!parser.ReadSignedFloat(token, ref offset.Z)) { // Not numeric! parser.ReportError("Expected ZOffset value, but got \"" + token + "\""); return(false); } break; case "angleoffset": parser.SkipWhitespace(true); token = parser.ReadToken(); if (!parser.ReadSignedFloat(token, ref angleoffset)) { // Not numeric! parser.ReportError("Expected AngleOffset value, but got \"" + token + "\""); return(false); } break; case "pitchoffset": parser.SkipWhitespace(true); token = parser.ReadToken(); if (!parser.ReadSignedFloat(token, ref pitchoffset)) { // Not numeric! parser.ReportError("Expected PitchOffset value, but got \"" + token + "\""); return(false); } break; case "rolloffset": parser.SkipWhitespace(true); token = parser.ReadToken(); if (!parser.ReadSignedFloat(token, ref rolloffset)) { // Not numeric! parser.ReportError("Expected RollOffset value, but got \"" + token + "\""); return(false); } break; case "useactorpitch": inheritactorpitch = false; useactorpitch = true; break; case "useactorroll": useactorroll = true; break; case "inheritactorpitch": inheritactorpitch = true; useactorpitch = false; parser.LogWarning("INHERITACTORPITCH flag is deprecated. Consider using USEACTORPITCH flag instead"); break; case "inheritactorroll": useactorroll = true; parser.LogWarning("INHERITACTORROLL flag is deprecated. Consider using USEACTORROLL flag instead"); break; //FrameIndex <XXXX> <X> <model index> <frame number> case "frameindex": // Sprite name parser.SkipWhitespace(true); string fispritename = parser.ReadToken(); if (string.IsNullOrEmpty(fispritename)) { parser.ReportError("Expected sprite name"); return(false); } if (fispritename.Length != 4) { parser.ReportError("Sprite name must be 4 characters long"); return(false); } // Sprite frame parser.SkipWhitespace(true); token = parser.ReadToken(); if (string.IsNullOrEmpty(token)) { parser.ReportError("Expected sprite frame"); return(false); } if (token.Length != 1) { parser.ReportError("Sprite frame must be 1 character long"); return(false); } // Make full name fispritename += token; // Model index parser.SkipWhitespace(true); int fimodelindnex = 0; token = parser.ReadToken(); if (!parser.ReadSignedInt(token, ref fimodelindnex)) { // Not numeric! parser.ReportError("Expected model index, but got \"" + token + "\""); return(false); } if (fimodelindnex < 0) { // Out of bounds parser.ReportError("Model index must not be negative"); return(false); } // Frame number parser.SkipWhitespace(true); int fiframeindnex = 0; token = parser.ReadToken(); //INFO: setting frame index to a negative number disables model rendering in GZDoom if (!parser.ReadSignedInt(token, ref fiframeindnex)) { // Not numeric! parser.ReportError("Expected frame index, but got \"" + token + "\""); return(false); } // Add to collection FrameStructure fifs = new FrameStructure { FrameIndex = fiframeindnex, ModelIndex = fimodelindnex, SpriteName = fispritename }; if (!frames.ContainsKey(fispritename)) { frames.Add(fispritename, new HashSet <FrameStructure>()); frames[fispritename].Add(fifs); } else if (frames[fispritename].Contains(fifs)) { parser.LogWarning("Duplicate FrameIndex definition"); } else { frames[fispritename].Add(fifs); } break; //Frame <XXXX> <X> <model index> <"frame name"> case "frame": // Sprite name parser.SkipWhitespace(true); string spritename = parser.ReadToken(); if (string.IsNullOrEmpty(spritename)) { parser.ReportError("Expected sprite name"); return(false); } if (spritename.Length != 4) { parser.ReportError("Sprite name must be 4 characters long"); return(false); } // Sprite frame parser.SkipWhitespace(true); token = parser.ReadToken(); if (string.IsNullOrEmpty(token)) { parser.ReportError("Expected sprite frame"); return(false); } if (token.Length != 1) { parser.ReportError("Sprite frame must be 1 character long"); return(false); } // Make full name spritename += token; // Model index parser.SkipWhitespace(true); int modelindnex = 0; token = parser.ReadToken(); if (!parser.ReadSignedInt(token, ref modelindnex)) { // Not numeric! parser.ReportError("Expected model index, but got \"" + token + "\""); return(false); } if (modelindnex < 0) { // Out of bounds parser.ReportError("Model index must not be negative"); return(false); } // Frame name parser.SkipWhitespace(true); string framename = parser.StripTokenQuotes(parser.ReadToken()); if (string.IsNullOrEmpty(framename)) { parser.ReportError("Expected frame name"); return(false); } // Add to collection FrameStructure fs = new FrameStructure { FrameName = framename, ModelIndex = modelindnex, SpriteName = spritename }; if (!frames.ContainsKey(spritename)) { frames.Add(spritename, new HashSet <FrameStructure>()); frames[spritename].Add(fs); } else if (frames[spritename].Contains(fs)) { parser.LogWarning("Duplicate Frame definition"); } else { frames[spritename].Add(fs); } break; case "{": parser.ReportError("Unexpected scope start"); return(false); // Structure ends here case "}": parsingfinished = true; break; } } // Perform some integrity checks if (!parsingfinished) { parser.ReportError("Unclosed structure scope"); return(false); } // Any models defined? if (modelnames.Count == 0) { parser.ReportError("Structure doesn't define any models"); return(false); } foreach (int i in skinnames.Keys.OrderBy(k => k)) { if (!string.IsNullOrEmpty(skinnames[i]) && !modelnames.ContainsKey(i)) { parser.ReportError("No model is defined for skin " + i + ":\"" + skinnames[i] + "\""); return(false); } } foreach (int i in surfaceskinenames.Keys.OrderBy(k => k)) { if (surfaceskinenames[i].Count > 0 && !modelnames.ContainsKey(i)) { parser.ReportError("No model is defined for surface skin " + i); return(false); } } return(true); }
public FrameStructure GetFrameStructure(float x, float y, TileInfoStructure tileStructure, LayerData layerData) { FrameStructure rez = FrameStructure.Empty(); var pos = new Vector2(x, y); if (layerData.IsShowWater) { if (tileStructure.IsWater()) { var rectWater = GetRect(3, pos, 3, layerData); rez = SpriteData.Liquid_0.Shema.GetShema(rectWater, tileStructure); return(rez); } } if (layerData.IsShowLight) { var rectLight = GetRectStructure(3, pos, 0); rez = LightShema.GetShemaStructure(rectLight, tileStructure); return(rez); } if (tileStructure.type == 0 && tileStructure.typeBG == 0) { return(rez); } if (layerData == LayerData.TerrainBgLayer) { if (tileStructure.typeBG == 0) { return(rez); } if (IsAllNeighborsIsNotEmpty(x, y)) { return(rez); } var rectBg = GetRect(3, pos, 3, layerData); rez = SpriteData.Tiles_bg.Shema.GetShema(rectBg, tileStructure); rez.TileCollection = SpriteData.Tiles_bg.Name; return(rez); } if (tileStructure.type == 0) { return(rez); } if (!layerData.IsContainsTileType(tileStructure.type)) { return(rez); } var data = SpriteData.SpritesByTypeId[tileStructure.type]; var rect = GetRect(data.SquareSizeByShema, pos, tileStructure.layer, layerData); rez = data.Shema.GetShema(rect, tileStructure); rez.TileCollection = data.Name; return(rez); }
public FrameStructure GetShema(short[,] map, TileInfoStructure info) { currentTileInfo = info; // return GetCenter(); //new FrameStructure(7, 0); if (info.randomTile >= 100) { int y = info.randomTile % 100; int x = (info.randomTile - y) / 100 - 2; if (!buffer.ContainsKey(x) || !buffer[x].ContainsKey(y)) { buffer[x] = new Dictionary <int, FrameStructure>(); buffer[x][y] = new FrameStructure(x, y); } return(buffer[x][y]); } // return GetCenter(); //GetRootBottomCenter(); if (mapRootBottomCenter == null) { mapRootBottomCenter = new short[, ] { { -2, 1, -2 }, { -2, 1, -2 }, { -1, -1, -1 } }; } if (ChackMap(mapRootBottomCenter, map, info)) { return(GetRootBottomCenter()); } //GetRootBottomLeft(); if (mapRootBottomLeft == null) { mapRootBottomLeft = new short[, ] { { -1, -1, 1 }, { -1, 1, 1 }, { -1, -1, -1 } }; } if (ChackMap(mapRootBottomLeft, map, info)) { return(GetRootBottomLeft()); } //GetRootBottomRight(); if (mapRootBottomRight == null) { mapRootBottomRight = new short[, ] { { 1, -1, -1 }, { 1, 1, -1 }, { -1, -1, -1 } }; } if (ChackMap(mapRootBottomRight, map, info)) { return(GetRootBottomRight()); } return(GetCenter()); //GetCenter(); if (mapCenter == null) { mapCenter = new short[, ] { { -2, 2, -2 }, { 0, -2, 0 }, { -2, 2, -2 } }; } if (ChackMap(mapCenter, map, info)) { return(GetCenter()); } //GetTop(); if (mapTop == null) { mapTop = new short[, ] { { 0, 0, 0 }, { -2, -2, -2 }, { -2, 1, -2 } }; } if (ChackMap(mapTop, map, info)) { return(GetTop()); } //GetBranchLeft(); if (mapBranchLeft == null) { mapBranchLeft = new short[, ] { { -2, -1, -2 }, { -1, -2, 1 }, { -2, -1, 1 } }; } if (ChackMap(mapBranchLeft, map, info)) { return(GetBranchLeft()); } //GetBranchRight(); if (mapBranchRight == null) { mapBranchRight = new short[, ] { { -2, -1, -2 }, { 1, -2, -2 }, { 1, -1, -2 } }; } if (ChackMap(mapBranchRight, map, info)) { return(GetBranchRight()); } //GetBranchLeftCenter(); if (mapBranchLeftCenter == null) { mapBranchLeftCenter = new short[, ] { { -2, -2, -2 }, { 1, -2, -1 }, { -2, -2, -2 } }; } if (ChackMap(mapBranchLeftCenter, map, info)) { return(GetBranchLeftCenter()); } //GetBranchRightCenter(); if (mapBranchRightCenter == null) { mapBranchRightCenter = new short[, ] { { -2, -2, -2 }, { -1, -2, 1 }, { -2, -2, -2 } }; } if (ChackMap(mapBranchRightCenter, map, info)) { return(GetBranchRightCenter()); } return(GetRootBottomRight()); }