Esempio n. 1
0
        private static void GroupCitiesInSegment(MapSegment segment)
        {
            Console.WriteLine(segment.name);

            // Filter groups
            List <int> [] groups = Utils
                                   .GroupTowers(segment, Constants.city_group_distance_threshold)
                                   .Where(g => g.Count >= Constants.city_population_threshold)
                                   .ToArray();

            // Debug print
            Console.WriteLine(groups.Length);
            foreach (List <int> group in groups)
            {
                Console.WriteLine(" >> " + string.Join(", ", group.Select(x => segment.towers [x].place)));
            }

            // Remove towers from the segment and add them to their own city segments
            List <int> towers_to_remove = new List <int> ();

            foreach (List <int> g in groups)
            {
                segment.cities.Add(new City(g.Select(x => segment.towers [x]).ToList()));

                towers_to_remove.AddRange(g);
            }

            segment.RemoveTowers(towers_to_remove);
        }
Esempio n. 2
0
    protected void UpdateCollider()
    {
        try {
            var resultPathing = MapSegment.GetMapSegmentPathing();
            resultPathing.UpdateInternalBoundries();

            var edgeColliders = MapSegment.GetComponentsInChildren <EdgeCollider2D>();
            foreach (var edgeCollider in edgeColliders)
            {
                GameObject.DestroyImmediate(edgeCollider.gameObject);
            }

            var edgesGroups = resultPathing.GetColliderPoints();

            foreach (var edgeGroup in edgesGroups)
            {
                var edgeGameObject = new GameObject("Collider2D");
                edgeGameObject.hideFlags = HideFlags.HideInHierarchy;

                var edgeCollider = edgeGameObject.AddComponent <EdgeCollider2D>();
                edgeCollider.points = edgeGroup.ToArray();

                edgeGameObject.transform.parent        = MapSegment.transform;
                edgeGameObject.transform.localPosition = Vector3.zero;
                edgeGameObject.transform.localRotation = Quaternion.identity;
                edgeGameObject.transform.localScale    = Vector3.one;
            }

            Debug.Log(string.Format("MapSegment {0}'s colliders has been updated", MapSegment.name));
        }catch (System.Exception e) {
            Debug.Log(e);

            Debug.LogError("Could not generate a collider. Mapsegment might not be up-to-date with some changes to the tileset. Apply the tileset again.");
        }
    }
Esempio n. 3
0
 public void Replace(MapSegment segment)
 {
     if (SegmentGameObject != null)
         GameObject.Destroy (SegmentGameObject);
     this.SegmentGameObject = segment.SegmentGameObject;
     this.State = segment.State;
 }
Esempio n. 4
0
 public void AddMapSegment(MapSegment mapSegment)
 {
     if (!MapSegments.Contains(mapSegment))
     {
         MapSegments.Add(mapSegment);
     }
 }
Esempio n. 5
0
 public ISA(MapSegment definition,
            string ISA05_SenderQual,
            string ISA06_SenderId,
            string ISA07_ReceiverQual,
            string ISA08_ReceiverId,
            string ISA12_VersionlNumber,
            int ISA13_ControlNumber,
            string ISA15_UsageIndicator
            ) : base(definition)
 {
     Content.AddRange(new[] {
         new EdiDataElement(definition.Content[0], "00"),
         new EdiDataElement(definition.Content[1], string.Empty.PadRight(10, ' ')),
         new EdiDataElement(definition.Content[2], "00"),
         new EdiDataElement(definition.Content[3], string.Empty.PadRight(10, ' ')),
         new EdiDataElement(definition.Content[4], ISA05_SenderQual),
         new EdiDataElement(definition.Content[5], ISA06_SenderId.PadRight(15)),
         new EdiDataElement(definition.Content[6], ISA07_ReceiverQual),
         new EdiDataElement(definition.Content[7], ISA08_ReceiverId.PadRight(15)),
         new EdiDataElement(definition.Content[8], DateTime.Now.ToString("yyMMdd")),
         new EdiDataElement(definition.Content[9], DateTime.Now.ToString("hhmm")),
         new EdiDataElement(definition.Content[10], "U"),
         new EdiDataElement(definition.Content[11], ISA12_VersionlNumber),
         new EdiDataElement(definition.Content[12], ISA13_ControlNumber.ToString().PadLeft(9, '0')),
         new EdiDataElement(definition.Content[12], "0"),
         new EdiDataElement(definition.Content[14], ISA15_UsageIndicator),
         new EdiDataElement(definition.Content[15], ">")
     });
 }
Esempio n. 6
0
    void OnEnabled()
    {
        MapSegment   = (MapSegment)target;
        MainFoldout  = true;
        Width        = MapSegment.Width;
        Height       = MapSegment.Height;
        TileSet      = MapSegment.TileSet;
        GridTileSize = MapSegment.GridTileSize;

        TileSetFoldout = true;

        var layers = MapSegment.GetComponentsInChildren <MapSegmentLayer>();

        CurrentLayerIndex = 0;
        for (int i = 0; i < layers.Length; i++)
        {
            if (MapSegment.CurrentLayer == layers[i])
            {
                CurrentLayerIndex = i;
            }
        }

        // Create the invisbile style used for the tiles
        m_internalTileStyle           = new GUIStyle();
        m_internalTileStyle.alignment = TextAnchor.MiddleCenter;
        m_internalTileStyle.fontSize  = 18;
        m_internalTileStyle.fontStyle = FontStyle.Bold;
    }
Esempio n. 7
0
        public void ComputeNames(MapSegment segment)
        {
            if (Constants.naming_distance_threshold > Chunk.chunk_size.y)
            {
                throw new Exception();
            }

            float threshold_squared = Constants.naming_distance_threshold * Constants.naming_distance_threshold;

            foreach (Chunk chunk in segment.chunks)
            {
                foreach (Tower tower_2 in chunk.towers_to_compare)
                {
                    foreach (Tower tower_1 in chunk.towers)
                    {
                        if (tower_1 == tower_2)
                        {
                            continue;
                        }

                        if (tower_1.place == tower_2.place)
                        {
                            if ((tower_1.map_position - tower_2.map_position).square_length <= threshold_squared)
                            {
                                tower_1.name_by_dedication = true;
                                tower_2.name_by_dedication = true;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 8
0
 public IEA(MapSegment definition,
            int IEA01_IncludedGroupsCount,
            int IEA02_ControlNumber) : base(definition)
 {
     Content.AddRange(new[] {
         new EdiDataElement(definition.Content[0], IEA01_IncludedGroupsCount.ToString()),
         new EdiDataElement(definition.Content[1], IEA02_ControlNumber.ToString().PadLeft(9, '0'))
     });
 }
Esempio n. 9
0
 public static void DoubleSegmentResolution(MapSegment seg)
 {
     for (int j = 0; j < seg.targetLocalPositions.Count - 1; j++)
     {
         var mid = (seg.targetLocalPositions[j] + seg.targetLocalPositions[j + 1]) / 2f;
         seg.targetLocalPositions.Insert(j + 1, mid);
         ++j;
     }
 }
Esempio n. 10
0
 public GE(MapSegment definition,
           int GE01_IncludedTransCount,
           int GE02_ControlNumber) : base(definition)
 {
     Content.AddRange(new[] {
         new EdiDataElement(definition.Content[0], GE01_IncludedTransCount.ToString()),
         new EdiDataElement(definition.Content[1], GE02_ControlNumber.ToString())
     });
 }
Esempio n. 11
0
    protected void HandleBlockBrush(MapSegment mapSegment)
    {
        if (!AltPress)
        {
            // Find the tile to paint
            RaycastHit raycastHit;
            var        isMouseOver = Physics.Raycast(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), out raycastHit);

            if (isMouseOver)
            {
                // Find the cordinates of the selected tile
                var tilePosition = mapSegment.GetTilePosition(raycastHit.point);

                // Use this to create the preview
                if (BlockStart != null)
                {
                    IntVector2 endBlock = new IntVector2(tilePosition);

                    TileSetPreview.SetPreviewZoneBlock(MapSegment.CurrentTileSelection, BlockStart.ToPoint(), endBlock.ToPoint());
                }

                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    BlockStart = new IntVector2(tilePosition);
                }
                else if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                {
                    if (BlockStart != null)
                    {
                        IntVector2 endBlock = new IntVector2(tilePosition);

                        var uvs = MapSegment.StartPaint();
                        for (int y = Mathf.Min(BlockStart.Y, endBlock.Y); y <= Mathf.Max(BlockStart.Y, endBlock.Y); y++)
                        {
                            for (int x = Mathf.Min(BlockStart.X, endBlock.X); x <= Mathf.Max(BlockStart.X, endBlock.X); x++)
                            {
                                mapSegment.Paint(new Point(x, y), MapSegment.CurrentTileSelection, uvs);
                            }
                        }

                        FinalizePaint(uvs);

                        // Set dirty so the editor serializes it
                        EditorUtility.SetDirty(mapSegment.CurrentLayer);
                        BlockStart = null;
                    }
                }
            }
            else
            {
                BlockStart = null;
                TileSetPreview.Clear();
            }
        }
    }
Esempio n. 12
0
    public override void OnInspectorGUI()
    {
        if (TileSetPreview == null)
        {
            if (!MapSegment.HasPreviewObject())
            {
                TileSetPreview = MapSegment.CreatePreviewObject();
            }
            else
            {
                TileSetPreview = MapSegment.GetComponentInChildren <MapSegmentPreview>();
            }
        }

        SetDefaults();
        UpdateMouseClick();

        if (Event.current.type == EventType.ValidateCommand)
        {
            if (Event.current.commandName == UNDO_REDO_COMMAND_NAME)
            {
                OnUndoRedo();
            }
        }

        if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Space)
        {
            MapSegment.CurrentTileSelection.Clear();
        }

        if (MapSegment.CurrentTileSelection == null)
        {
            MapSegment.CurrentTileSelection = new MapSegmentPaletteSelection();
        }

        MainFoldout = EditorGUILayout.Foldout(MainFoldout, "Main data");
        if (MainFoldout)
        {
            DrawMainDataSegment();
        }

        TileSetFoldout = EditorGUILayout.Foldout(TileSetFoldout, "Tile set");
        if (TileSetFoldout)
        {
            DrawTileSetSegment();
        }

        if (GUILayout.Button("Update collider"))
        {
            UpdateCollider();
        }

        Repaint();
    }
Esempio n. 13
0
    public void SetTileTypeToTile(int x, int y, Tile tile, int tileType, MapSegment mapSegment, Vector2[] meshUvs)
    {
        int uvOffset = ((y * mapSegment.Width) + x) * 4;

        for (int i = 0; i < 4; i++)
        {
            meshUvs[uvOffset + i] = tile.UvCords[i];
        }

        TilesCollection.SetTileType(x, y, tileType);
    }
 public void GenerateConstant(MapSegment mapSegment, double speed, int numberOfLines)
 {
     this.linearBezierSplineList = new List <LinearBezierSpline>();
     for (int ii = 0; ii < numberOfLines; ii++)
     {
         LinearBezierSpline speedProfileLinearBezierSpline = new LinearBezierSpline(1); // 1 = number of dimensions.
         speedProfileLinearBezierSpline.P0.CoordinateList[0] = speed;
         speedProfileLinearBezierSpline.P1.CoordinateList[0] = speed;
         this.linearBezierSplineList.Add(speedProfileLinearBezierSpline);
     }
 }
Esempio n. 15
0
    protected bool LayerIndexExists(int layerIndex)
    {
        var layers = MapSegment.GetComponentsInChildren <MapSegmentLayer>();

        if (layers.Length >= layerIndex)
        {
            return(false);
        }

        return(true);
    }
Esempio n. 16
0
 public void OnUndoRedo()
 {
     foreach (var layer in MapSegment.GetOrderedLayerList())
     {
         var uvs      = MapSegment.StartPaint(layer);
         var tileType = layer.TilesCollection.GetTileType(Point.Zero);
         layer.Paint(Point.Zero, tileType, uvs);
         FinalizeNoUndoRedo(uvs, layer);
         TileSetPreview.Clear();
     }
 }
Esempio n. 17
0
    public List <byte> FilterSegments(List <byte> segments, MapSegment.Direction direction, byte neighbor)
    {
        foreach (byte b in segments.ToList())
        {
            if (!MapSegment.EdgesMatch(direction, b, neighbor))
            {
                segments.Remove(b);
            }
        }

        return(segments);
    }
Esempio n. 18
0
    public List <string> GetGuidsForLayers()
    {
        var           layers = MapSegment.GetComponentsInChildren <MapSegmentLayer>();
        List <string> result = new List <string>();

        for (int i = 0; i < layers.Length; i++)
        {
            result.Add(layers[i].TileSetLayer.Guid);
        }

        return(result);
    }
Esempio n. 19
0
    public GameObject GetObjectFromLayer(TileSetLayer tileSetLayer)
    {
        foreach (var tmpLayer in MapSegment.GetComponentsInChildren <MapSegmentLayer>())
        {
            if (tmpLayer.TileSetLayer.Guid == tileSetLayer.Guid)
            {
                return(tmpLayer.gameObject);
            }
        }

        // This should really never happen
        Debug.LogError("Could not find the correct GameObject to alter");
        return(null);
    }
Esempio n. 20
0
        public static bool HalfSubsegmentResolution(MapSegment seg)
        {
            if (seg.targetLocalPositions.Count < 3)
            {
                Debug.Log($"A {nameof(MapSegment)} contains less than 3 waypoints, can not half subsegment resolution");
                return(false);
            }

            for (int j = seg.targetLocalPositions.Count - 2; j > 0; j -= 2)
            {
                seg.targetLocalPositions.RemoveAt(j);
            }

            return(true);
        }
Esempio n. 21
0
    protected void SetDefaults()
    {
        if (MapSegment.CurrentLayer == null)
        {
            var layers = MapSegment.GetComponentsInChildren <MapSegmentLayer>();

            // No layers exists, so nothing can be set as default (duh!)
            if (layers.Length == 0)
            {
                return;
            }

            MapSegment.CurrentLayer = layers[CurrentLayerIndex];
        }
    }
Esempio n. 22
0
        public static bool DoubleSubsegmentResolution(MapSegment seg)
        {
            if (seg.targetLocalPositions.Count < 2)
            {
                Debug.Log($"A {nameof(MapSegment)} contains less than 2 waypoints, can not double subsegment resolution");
                return(false);
            }

            for (int j = seg.targetLocalPositions.Count - 1; j > 0; --j)
            {
                var mid = (seg.targetLocalPositions[j] + seg.targetLocalPositions[j - 1]) / 2f;
                seg.targetLocalPositions.Insert(j, mid);
            }

            return(true);
        }
Esempio n. 23
0
    protected void UpdateMouse(MapSegment mapSegment)
    {
        RaycastHit raycastHit;

        IsMouseOver = Physics.Raycast(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), out raycastHit);
        RaycastHit  = raycastHit;

        if (IsMouseOver)
        {
            CurrentlyHoverPoint = mapSegment.GetTilePosition(raycastHit.point);
        }
        else
        {
            CurrentlyHoverPoint = null;
        }
    }
Esempio n. 24
0
        public async Task <IActionResult> MapSegmentAdd(MapSegmentModel model)
        {
            if (ModelState.IsValid)
            {
                var mapSegment = new MapSegment();
                mapSegment.Name = new MultiLangString(model.Name);

                await _bll.MapSegments.AddAsync(mapSegment);

                await _bll.SaveChangesAsync();

                return(RedirectToAction(nameof(MapSegment), new { id = mapSegment.Id }));
            }

            return(View(nameof(MapSegmentAdd)));
        }
Esempio n. 25
0
    public void ApplyTilsetChanges()
    {
        // Find any layers that is in the map segment but not in the tileset
        foreach (var layer in MapSegment.GetComponentsInChildren <MapSegmentLayer>())
        {
            if (!TileSet.HasLayer(layer.TileSetLayer))
            {
                GameObject.DestroyImmediate(layer.gameObject);
            }
        }

        // ALter or create new layers for the ones found in the
        for (int i = 0; i < TileSet.Layers.Count; i++)
        {
            var layer = TileSet.Layers[i];

            if (MapSegment.HasLayerOfType(layer))
            {
                AlterLayer(layer, i);
            }
            else
            {
                CreateNewLayer(layer, i);
            }
        }

        // Now sort the layers according to type
        var index = 0;

        foreach (var tileSetLayer in MapSegment.GetComponentsInChildren <MapSegmentLayer>())
        {
            var layerType = tileSetLayer.TileSetLayer.LayerType;
            if (layerType == TileSetLayerType.BaseLayer)
            {
                tileSetLayer.transform.localPosition = GetBaseLayerPosition(tileSetLayer.transform.position);
            }
            else if (layerType == TileSetLayerType.Overlay)
            {
                tileSetLayer.transform.localPosition = GetOverlayPosition(tileSetLayer.transform.position, index);
            }
            else if (layerType == TileSetLayerType.OnTopOverlay)
            {
                tileSetLayer.transform.localPosition = GetOnTopOverlayPosition(tileSetLayer.transform.position, index);
            }
            index++;
        }
    }
Esempio n. 26
0
        public SE(MapSegment definition,
                  int SE01_IncludedSegCount,
                  int SE02_ControlNumber
                  ) : base(definition)
        {
            string tcn = SE02_ControlNumber.ToString();

            if (tcn.Length < 4)
            {
                tcn = tcn.PadLeft(4, '0');
            }

            Content.AddRange(new[] {
                new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[0], SE01_IncludedSegCount.ToString()),
                new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[1], tcn),
            });
        }
Esempio n. 27
0
        public ST(MapSegment definition,
                  string ST01_TransactionId,
                  int ST02_ControlNumber
                  ) : base(definition)
        {
            string tcn = ST02_ControlNumber.ToString();

            if (tcn.Length < 4)
            {
                tcn = tcn.PadLeft(4, '0');
            }

            Content.AddRange(new[] {
                new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[0], ST01_TransactionId),
                new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[1], tcn),
            });
        }
Esempio n. 28
0
        public static EdiSegment ProcessSegment(MapBaseEntity definition, string[] content, int rowPos, IValidatedEntity validationScope)
        {
            MapSegment segDef = (MapSegment)definition;
            EdiSegment seg    = new EdiSegment(segDef);

            int i = 0;

            foreach (string val in content.Skip(1))
            {
                MapDataElement elDef = null;
                if (i < segDef.Content.Count)
                {
                    elDef = segDef.Content[i];
                }

                if (elDef == null)
                {
                    ValidationError err = new ValidationError()
                    {
                        SegmentPos  = rowPos,
                        SegmentName = content[0],
                        ElementPos  = i + 1,
                        Message     = $"Unexpected element '{val}'"
                    };
                    validationScope.ValidationErrors.Add(err);
                }

                EdiDataElement el = new EdiDataElement(elDef, val);
                if (elDef != null && !el.IsValid(elDef))
                {
                    ValidationError err = new ValidationError()
                    {
                        SegmentPos  = rowPos,
                        SegmentName = content[0],
                        ElementPos  = i + 1,
                        Message     = $"Invalid value '{val}'"
                    };
                    validationScope.ValidationErrors.Add(err);
                }

                i++;
                seg.Content.Add(el);
            }
            return(seg);
        }
Esempio n. 29
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.

            /*spriteBatch = new SpriteBatch(GraphicsDevice);
             * camera = new Camera2D(this);*/
            map = new Map();

            // TODO: use this.Content to load your game content here
            map.AddSpritesSheet(Content.Load <SpritesSheet>("test1"));
            map.AddLayer(new MapLayer(1, Color.White, 0.1f));
            map.AddSegment(0, 0, 1, new Point(10, 10));
            map.AddSegment(0, 0, 5, new Point(500, 300));
            map.AddSegment(0, 0, 2, new Point(1000, 1000));
            MapSegment test = map.AddSegment(0, 0, 3, new Point(200, 400));

            test.Location = new Point(100, 100);
        }
Esempio n. 30
0
        public static EdiSegment ProcessSegment(MapBaseEntity definition, string[] content, int rowPos, string compositeSeparator, IValidatedEntity validationScope)
        {
            MapSegment segDef = (MapSegment)definition;
            EdiSegment seg    = new EdiSegment(segDef);

            int i = 0;

            foreach (string val in content.Skip(1))
            {
                MapSimpleDataElement    elDef = null;
                MapCompositeDataElement cDef  = null;
                if (i < segDef.Content.Count)
                {
                    if (segDef.Content[i] is MapSimpleDataElement)
                    {
                        elDef = (MapSimpleDataElement)segDef.Content[i];
                    }
                    else if (segDef.Content[i] is MapCompositeDataElement)
                    {
                        cDef = (MapCompositeDataElement)segDef.Content[i];
                    }
                }

                //if cDef is null - create simple element. Even if elDef is null
                // validation will add error of unknown element later on
                if (cDef == null)
                {
                    EdiSimpleDataElement el = new EdiSimpleDataElement(elDef, val);
                    seg.Content.Add(el);
                }
                else
                {
                    EdiCompositeDataElement composite = new EdiCompositeDataElement(cDef);
                    string[] compositeContent         = val.Split(new[] { compositeSeparator }, StringSplitOptions.None);
                    ProcessComposite(composite, compositeContent);
                    seg.Content.Add(composite);
                }

                i++;
            }

            SegmentValidator.ValidateSegment(seg, rowPos, validationScope);
            return(seg);
        }
Esempio n. 31
0
 public GS(MapSegment definition,
           string GS01_GroupName,
           string GS02_SenderId,
           string GS03_ReceiverId,
           int GS06_ControlNumber,
           string GS08_VersionlNumber
           ) : base(definition)
 {
     Content.AddRange(new[] {
         new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[0], GS01_GroupName),
         new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[1], GS02_SenderId),
         new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[2], GS03_ReceiverId),
         new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[3], DateTime.Now.ToString("yyyyMMdd")),
         new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[4], DateTime.Now.ToString("hhmm")),
         new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[5], GS06_ControlNumber.ToString()),
         new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[6], "X"),
         new EdiSimpleDataElement((MapSimpleDataElement)definition.Content[7], GS08_VersionlNumber)
     });
 }
Esempio n. 32
0
 void HandleSegmentAt(MapSegment segment, float x, float z)
 {
     if (segment.State == SegmentState.Destroyed)
     {
         this.mapLoader.StartAsyncMethod(WaitUntilSegmentLoadAt(segment, x, z));
     }
 }
Esempio n. 33
0
    IEnumerator WaitUntilSegmentLoadAt(MapSegment segment, float x, float z)
    {
        var segmentCoordPosition = this.GetSegmentCoorsForPosition(x, z);
        if (segmentCoordPosition.x > mapSettings.xMax || segmentCoordPosition.x < mapSettings.xMin ||
            segmentCoordPosition.y > mapSettings.zMax || segmentCoordPosition.y < mapSettings.zMin)
        {
            yield break;
        }
        segment.State = SegmentState.Loading;
        var asyncRequest = this.LoadSegmentAsyncAt((int)segmentCoordPosition.x, (int)segmentCoordPosition.y);

        yield return asyncRequest;

        segment.SegmentGameObject = CreateSegmentAt(segmentCoordPosition, asyncRequest.asset as GameObject);
        segment.State = SegmentState.Active;
    }