Example #1
0
        public void AddTemplateToMap(ObjectTemplate template, Map map, MapInfo info, TileInfo blockedTileInfo, Point position, float?rotation, string roadType)
        {
            if (template.IsInstantiated)
            {
                throw new InvalidOperationException("A template can only be added to a map once. Consider cloning it before adding it to the map.");
            }

            Point origin = template.CalculateOrigin();

            foreach (var obj in template.Objects)
            {
                obj.Properties["uniqueID"].Value = objectId.ToString();
                Point point = new Point(position.X + obj.X - origin.X, position.Y + obj.Y - origin.Y);
                if (rotation.HasValue)
                {
                    point         = point.Rotate(position, rotation.Value);
                    obj.Rotation += rotation.Value;
                }

                obj.X = point.X;
                obj.Y = point.Y;

                map.Objects.Add(obj);
                objectId++;
            }

            AddFlattenedArea(template, info);

            AddTextures(template, map, info, blockedTileInfo, position, rotation, origin);

            AddRoadsFromTemplateToMap(template, map, info, roadType);

            template.IsInstantiated = true;
        }
Example #2
0
        private static void AddFlattenedArea(ObjectTemplate template, MapInfo info)
        {
            Point origin = template.CalculateOrigin();

            float squaredRadius = template.Objects /*.Where(o => o.RoadOptions == RoadOptions.None)*/.Max(o => (new Point(o.X, o.Y) - origin).VectorLengthSquared());

            info.FlattenedAreas.Add(new Math.Circle(origin, System.Math.Max((float)System.Math.Sqrt(squaredRadius), Map.TileWidth * 5)));
        }