Example #1
0
        public bool RemoveCharacter(string instancename)
        {
            GroundMap map = ZoneManager.Instance.CurrentGround;

            if (map == null)
            {
                DiagManager.Instance.LogInfo(String.Format("ScriptGround.RemoveObject({0}) : No ground map loaded!", instancename));
                return(false);
            }

            //Removal by instance name, since lua can't do via .NET pointer reliably, and pointers to .NET aren't practical in lua
            GroundChar charToRemove = map.GetMapChar(instancename);

            if (charToRemove != null)
            {
                map.RemoveMapChar(charToRemove);
                return(true);
            }
            charToRemove = map.GetTempChar(instancename);
            if (charToRemove != null)
            {
                map.RemoveTempChar(charToRemove);
                return(true);
            }

            return(false);
        }
Example #2
0
        public object CreateCharacter(string chartype, string instancename, int x, int y, string actionfun, string thinkfun)
        {
            GroundMap map = ZoneManager.Instance.CurrentGround;

            if (map == null)
            {
                DiagManager.Instance.LogInfo(String.Format("ScriptGround.CreateCharacter({0},{1},{2},{3})", chartype, instancename, x, y));
                return(null);
            }

            GroundChar groundchar = null;


            //Ideally this is how we'd create characters :

            /*
             *  GroundCharTemplate template = CharacterTemplates.Find(chartype); //Templates are created by the modders, and stored as data (This is handy, because its pretty certain a lot of characters and entities will be repeated throughout the maps)
             *  if (template == null)
             *      return null;
             *
             *  groundchar = template.create(instancename, x, y);
             *
             *  groundchar.SetRoutine(thinkfun); //Aka the code that makes the npc wander, or do stuff over and over again
             *  groundchar.SetAction(actionfun);
             *
             *  map.AddMapChar(groundChar);
             *  return groundchar; //Object's properties can be tweaked later on
             */
            return(groundchar);
        }
Example #3
0
    private void CreateDoors(Rectangle room)
    {
        int xMin = room.Left;
        int xMax = room.Right;
        int yMin = room.Top;
        int yMax = room.Bottom;

        List <Cell> borderCells = ItemsMap.GetCellsAlongLine(xMin, yMin, xMax, yMin).ToList();

        borderCells.AddRange(ItemsMap.GetCellsAlongLine(xMin, yMin, xMin, yMax));
        borderCells.AddRange(ItemsMap.GetCellsAlongLine(xMin, yMax, xMax, yMax));
        borderCells.AddRange(ItemsMap.GetCellsAlongLine(xMax, yMin, xMax, yMax));

        foreach (Cell cell in borderCells)
        {
            if (IsPotentialDoor(cell))
            {
                GroundMap.SetCellProperties(cell.X, cell.Y, false, true);
                ItemsMap.SetCellProperties(cell.X, cell.Y, false, true);
                var door     = new Item();
                var instance = Instantiate <GameObject>(_door, new Vector2(cell.X, cell.Y), Quaternion.identity);
                door.Stat = "close";
                door.go   = instance;
                instance.transform.SetParent(itemsHolder);
                instance.GetComponent <Renderer>().enabled = false;
                ItemsTiles[cell.X, cell.Y] = door;
                Doors.Add(door);
            }
        }
    }
Example #4
0
        /// <summary>
        /// Loads a new ground map of the specified name into the current zone (temporarily) for dev usage.
        /// </summary>
        /// <param name="mapname"></param>
        public void DevLoadGround(string mapname)
        {
            exitMap();

            CurrentGround = DataManager.Instance.GetGround(mapname);
            CurrentMapID  = new SegLoc(-1, 0);
        }
Example #5
0
    public Room(Rect rect, GroundMap map)
    {
        this.rect = rect;
        this.map  = map;

        this.center = CalculateCenter();
    }
Example #6
0
    public EntityMap Init(Tilemap map, GroundMap groundMap)
    {
        this.map       = map;
        this.groundMap = groundMap;

        return(this);
    }
Example #7
0
    bool IsPotentialDoor(Cell cell)
    {
        if (!cell.IsWalkable)
        {
            return(false);
        }

        Cell right  = GroundMap.GetCell(cell.X + 1, cell.Y);
        Cell left   = GroundMap.GetCell(cell.X - 1, cell.Y);
        Cell top    = GroundMap.GetCell(cell.X, cell.Y - 1);
        Cell bottom = GroundMap.GetCell(cell.X, cell.Y + 1);

        if (GetDoor(cell.X, cell.Y) != null ||
            GetDoor(right.X, right.Y) != null ||
            GetDoor(left.X, left.Y) != null ||
            GetDoor(top.X, top.Y) != null ||
            GetDoor(bottom.X, bottom.Y) != null)
        {
            return(false);
        }

        if (right.IsWalkable && left.IsWalkable && !top.IsWalkable && !bottom.IsWalkable)
        {
            return(true);
        }
        if (!right.IsWalkable && !left.IsWalkable && top.IsWalkable && bottom.IsWalkable)
        {
            return(true);
        }
        return(false);
    }
Example #8
0
    void GenerateGroundTexture()
    {
        groundHeightMapPreview            = new Texture2D(300, 300);
        groundHeightMapPreview.filterMode = FilterMode.Point;
        groundHeightMapPreview.wrapMode   = TextureWrapMode.Clamp;

        GroundMap groundMap = Utility.GetTargetObjectOfProperty(groundMapProperty) as GroundMap;

        var nbXPixel = groundHeightMapPreview.width / (Chunk.ChunkSize * 5);
        var nbYPixel = groundHeightMapPreview.height / (Chunk.ChunkSize * 5);

        for (int j = 0; j < Chunk.ChunkSize * 5; j++)
        {
            for (int i = 0; i < Chunk.ChunkSize * 5; i++)
            {
                var height = groundMap.GetHeightUnscale(i - Chunk.ChunkRadius, j - Chunk.ChunkRadius);
                var color  = Color.Lerp(Color.black, Color.white, height);

                var colors = Enumerable.Repeat <Color>(color, nbXPixel * nbYPixel).ToArray();
                groundHeightMapPreview.SetPixels(i * nbXPixel, j * nbYPixel, nbXPixel, nbYPixel, colors);
            }
        }

        groundHeightMapPreview.Apply();
    }
Example #9
0
 private void CreateVerticalTunnel(int yStart, int yEnd, int xPosition)
 {
     for (int y = Math.Min(yStart, yEnd); y <= Math.Max(yStart, yEnd); y++)
     {
         GroundMap.SetCellProperties(xPosition, y, true, true);
         ItemsMap.SetCellProperties(xPosition, y, true, true);
     }
 }
Example #10
0
 private void CreateHorizontalTunnel(int xStart, int xEnd, int yPosition)
 {
     for (int x = Math.Min(xStart, xEnd); x <= Math.Max(xStart, xEnd); x++)
     {
         GroundMap.SetCellProperties(x, yPosition, true, true);
         ItemsMap.SetCellProperties(x, yPosition, true, true);
     }
 }
Example #11
0
        /// <summary>
        /// Creates a new ground map of the specified name into the current zone (temporarily) for dev usage.
        /// </summary>
        public void DevNewGround()
        {
            exitMap();

            CurrentGround = new GroundMap();
            CurrentGround.CreateNew(16, 16, Content.GraphicsManager.DungeonTexSize);
            CurrentMapID = new SegLoc(-1, 0);
        }
Example #12
0
        private Ground BuildFromMap(GroundMap groundMap)
        {
            Ground ground = GameObjectsFactory.getInstance().Create <Ground>();

            ground.BuildFromMap(groundMap);
            ground.transform.parent = transform;
            return(ground);
        }
Example #13
0
 private void exitMap()
 {
     CurrentMap = null;
     if (CurrentGround != null && CurrentMapID.IsValid())//only clean up maps that are valid (aka, not from editor mode)
     {
         CurrentGround.DoCleanup();
     }
     CurrentGround = null;
 }
Example #14
0
 public void BuildFromMap(GroundMap map)
 {
     foreach (GroundBlockMap blockMap in map)
     {
         GroundBlock newBlock = GameObjectsFactory.getInstance().Create <GroundBlock>();
         newBlock.BuildFromMap(blockMap);
         AddBlock(newBlock);
     }
 }
 public ReimersBillboards(
     VisionContent vContent,
     Matrix world,
     GroundMap groundMap,
     ColorSurface normals,
     Texture2D texture)
     : base(vContent, world, texture, generateTreePositions(vContent.Load<Texture2D>("treeMap"), groundMap, normals), 6, 7)
 {
 }
Example #16
0
 public void AddMap(int node, Vector2 start, int num, Ground groundKind, Vector3 rotation)
 {
     if(maps == null) maps = new List<GroundMap>();
     GroundMap map = new GroundMap();
     map.start = start;
     map.num = num;
     map.groundKind = groundKind;
     map.rotation = rotation;
     maps.Insert(node, map);
 }
Example #17
0
    public GroundMap MakeMap(int maxRooms, IntRange roomSizeRange, int mapWidth, int mapHeight, Tilemap tileMap)
    {
        map = ScriptableObject.CreateInstance <GroundMap>().Init(mapWidth, mapHeight, tileMap);

        var rooms = MakeRooms(maxRooms, roomSizeRange, mapWidth, mapHeight, tileMap);

        map.rooms = rooms.ToList();
        map.UpdateNavigationMasks();
        Debug.Log("Rooms: " + rooms.Count());
        return(map);
    }
Example #18
0
 void CreateRoom(Rectangle room)
 {
     for (int x = room.Left + 1; x < room.Right; x++)
     {
         for (int y = room.Top + 1; y < room.Bottom; y++)
         {
             GroundMap.SetCellProperties(x, y, true, true);
             ItemsMap.SetCellProperties(x, y, true, true);
         }
     }
 }
Example #19
0
    public Action GetAction(EntityMap entityMap, GroundMap groundMap)
    {
        Action action;
        var    aStar        = new AStar(groundMap, entityMap);
        var    target       = entityMap.GetPlayer();
        var    actionResult = new ActionResult();

        if (target == null)
        {
            // If no target, the pathfinding doesn't know what to do, so wait instead and send a message up
            action = BuildWaitAction(actionResult, entityMap, groundMap);
        }

        // Right now enemies will only act if the player can see them
        else if (groundMap.isTileVisible(owner.position))
        {
            // Attempt to move towards the AIs target (this doesn't have to be the player!)
            if (owner.DistanceTo(target) >= 2)
            {
                var moveTile = aStar.FindPathToTarget((owner.position.x, owner.position.y), (target.position.x, target.position.y));
                if (moveTile == null)
                {
                    // No path found I guess
                    action = BuildWaitAction(actionResult, entityMap, groundMap);
                }
                else
                {
                    action = new WalkAction(owner.actor, new CellPosition(moveTile.x, moveTile.y));
                }
            }
            else
            {
                // If we're in melee range, attack instead of move
                if (owner.GetComponent <Fighter>() == null)
                {
                    // Can't fight though... ha
                    action = BuildWaitAction(actionResult, entityMap, groundMap);
                }
                else
                {
                    action = new MeleeAttackAction(owner.actor, target.position);
                }
            }
        }
        else
        {
            // Nothing to do, not visible, just wait
            action = BuildWaitAction(actionResult, entityMap, groundMap, logMessage: false);
        }

        return(action);
    }
Example #20
0
    public Action GetAction(EntityMap eMap, GroundMap gMap)
    {
        if (entity.GetComponent <BasicMonsterAi>() is BasicMonsterAi ai)
        {
            nextAction = ai.GetAction(eMap, gMap);
        }

        var action = nextAction;

        nextAction = null;

        return(action);
    }
Example #21
0
    void DrawGround()
    {
        foreach (var cell in GroundMap.GetAllCells())
        {
            if (!cell.IsExplored)
            {
                continue;
            }

            GameObject tileType;
            if (GroundMap.IsInFov(cell.X, cell.Y))
            {
                if (cell.IsWalkable)
                {
                    tileType = Floor;
                }
                else
                {
                    tileType = Wall;
                }
                if (groundTiles[cell.X, cell.Y] == null)
                {
                    GameObject instance = GameObject.Instantiate <GameObject>(tileType, new Vector2(cell.X, cell.Y),
                                                                              Quaternion.identity);
                    instance.transform.SetParent(boardHolder);
                    groundTiles[cell.X, cell.Y] = instance;
                }
                groundTiles[cell.X, cell.Y].GetComponent <Renderer>().material.color = Color.white;
            }
            else
            {
                if (cell.IsWalkable)
                {
                    tileType = Floor;
                }
                else
                {
                    tileType = Wall;
                }
                if (groundTiles[cell.X, cell.Y] == null)
                {
                    GameObject instance = GameObject.Instantiate <GameObject>(tileType, new Vector2(cell.X, cell.Y),
                                                                              Quaternion.identity);
                    instance.transform.SetParent(boardHolder);
                    groundTiles[cell.X, cell.Y] = instance;
                }
                groundTiles[cell.X, cell.Y].GetComponent <Renderer>().material.color = Color.gray;
            }
        }
    }
Example #22
0
    void OpenDoor(GameObject actor, int x, int y)
    {
        var door = GetDoor(x, y);

        if (door != null && door.Stat == "close")
        {
            Debug.Log("cat");
            door.Stat = "open";
            var ItemCell   = ItemsMap.GetCell(x, y);
            var GroundCell = ItemsMap.GetCell(x, y);
            GroundMap.SetCellProperties(x, y, true, true, GroundCell.IsExplored);
            ItemsMap.SetCellProperties(x, y, true, true, ItemCell.IsExplored);
            door.go.GetComponent <Animator>().SetTrigger("Open");
        }
    }
Example #23
0
        /// <summary>
        /// Finds the mapname in this zone's map list, and loads it.
        /// </summary>
        /// <param name="mapname"></param>
        public void SetCurrentGround(string mapname)
        {
            exitMap();

            int index = GroundMaps.FindIndex((str) => (str == mapname));

            if (index > -1)
            {
                CurrentGround = GetGround(new SegLoc(-1, index));
            }
            else
            {
                throw new Exception(String.Format("Cannot find ground map of name {0} in {1}.", mapname, Name.DefaultText));
            }

            CurrentMapID = new SegLoc(-1, index);
        }
Example #24
0
        public bool RemoveObject(string instancename)
        {
            GroundMap map = ZoneManager.Instance.CurrentGround;

            if (map == null)
            {
                DiagManager.Instance.LogInfo(String.Format("ScriptGround.RemoveObject({0}) : No ground map loaded!", instancename));
                return(false);
            }

            DiagManager.Instance.LogInfo("ScriptGround.RemoveObject():FIXME"); //!#FIXME

            /*
             * map.RemoveObject(instancename); //Removal by instance name, since lua can't do via .NET pointer reliably, and pointers to .NET aren't practical in lua
             */
            return(true);
        }
Example #25
0
        public void SetCurrentMap(SegLoc map)
        {
            exitMap();

            if (map.IsValid())
            {
                if (map.Segment > -1)
                {
                    CurrentMap = GetMap(map);
                }
                else
                {
                    CurrentGround = GetGround(map);
                }
            }
            CurrentMapID = map;
        }
Example #26
0
    public bool MoveTorwards(CellPosition target, EntityMap map, GroundMap groundMap)
    {
        var dx       = target.x - actor.entity.position.x;
        var dy       = target.y - actor.entity.position.y;
        var distance = (int)Mathf.Sqrt(dx * dx + dy * dy);

        dx = dx / distance;
        dy = dy / distance;

        var newX = actor.entity.position.x + dx;
        var newY = actor.entity.position.y + dy;

        if (!groundMap.IsBlocked(newX, newY) && map.GetBlockingEntityAtPosition(newX, newY) == null)
        {
            Move(dx, dy);
            return(true);
        }

        return(false);
    }
Example #27
0
    void UpdatePlayerFieldOfView()
    {
        GroundMap.ComputeFov((int)Player.transform.position.x, (int)Player.transform.position.y, 8, true);
        ItemsMap.ComputeFov((int)Player.transform.position.x, (int)Player.transform.position.y, 8, true);

        foreach (var cell in GroundMap.GetAllCells())
        {
            if (GroundMap.IsInFov(cell.X, cell.Y))
            {
                GroundMap.SetCellProperties(cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, true);
            }
        }

        foreach (var cell in ItemsMap.GetAllCells())
        {
            if (ItemsMap.IsInFov(cell.X, cell.Y))
            {
                ItemsMap.SetCellProperties(cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, true);
            }
        }
    }
Example #28
0
        //===================================
        //  Custscene stuff
        //===================================


        //===================================
        // Objects and Characters
        //===================================
        public object CreateObject(string objtype, string instancename, int x, int y, int w, int h)
        {
            GroundMap map = ZoneManager.Instance.CurrentGround;

            if (map == null)
            {
                DiagManager.Instance.LogInfo(String.Format("ScriptGround.CreateObject({0}, {1}, {2}, {3}, {4}, {5}) : No ground map loaded!", objtype, instancename, x, y, w, h));
                return(null);
            }

            GroundObject groundobject = null;
            var          template     = TemplateManager.Instance.FindTemplate(objtype); //Templates are created by the modders, and stored as data (This is handy, because its pretty certain a lot of characters and entities will be repeated throughout the maps)

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

            groundobject        = (GroundObject)template.create(instancename);
            groundobject.Bounds = new Rect(x, y, w, h);
            groundobject.AddScriptEvent(LuaEngine.EEntLuaEventTypes.Action);
            map.AddObject(groundobject);
            return(groundobject); //Object's properties can be tweaked later on
        }
Example #29
0
 public void GenerateTreePositions(GroundMap groundMap, ColorSurface normals)
 {
     var treeList = generateTreePositions(groundMap, normals);
     CreateBillboardVerticesFromList(treeList);
 }
Example #30
0
        private List<Tuple<Vector3, Vector3>> generateTreePositions(GroundMap groundMap, ColorSurface normals)
        {
            var treeList = new List<Tuple<Vector3,Vector3>>();
            var random = new Random();

            for (var y = normals.Height - 2; y > 0; y--)
                for (var x = normals.Width - 2; x > 0; x--)
                {
                    var height = groundMap[x, y];
                    if ( height <3 || height > 5)
                        continue;
                    for (var currDetail = 0; currDetail < 5; currDetail++)
                    {
                        var rand1 = (float) random.NextDouble();
                        var rand2 = (float) random.NextDouble();
                        treeList.Add(new Tuple<Vector3, Vector3>(
                                         new Vector3(
                                             x + rand1,
                                             groundMap.GetExactHeight(x, y, rand1, rand2),
                                             y + rand2),
                                         normals.AsVector3(x, y)));
                    }
                }

            return treeList;
        }
Example #31
0
 public FieldOfViewSystem(GroundMap map)
 {
     this.map    = map;
     fovComputer = new FieldOfViewComputer(BlocksLight, SetVisible, GetDistance);
 }
Example #32
0
        public void Generate(int difficulty)
        {
            int maxGroundPines = difficulty + 1;

            GroundMap groundMap = GroundMap.GenerateRandom(30 + 20 * difficulty);

            groundMap.AddSpots(5);
            groundMap.GrowPines(maxGroundPines);

            GroundMap leftWMap = groundMap.GetLeftMould();

            leftWMap.AddSpots(4);
            leftWMap.GrowPines(4);

            GroundMap rightWMap = groundMap.GetRightMould();

            rightWMap.AddSpots(4);
            rightWMap.GrowPines(4);

            GroundMap leftW1Map = leftWMap.GetLeftMould();

            leftW1Map.AddSpots(2);
            leftW1Map.GrowPines(10);

            GroundMap rightW1Map = rightWMap.GetRightMould();

            rightW1Map.AddSpots(2);
            rightW1Map.GrowPines(10);

            groundMap.SetDepth(2);
            leftWMap.SetDepth(1);
            rightWMap.SetDepth(1);
            leftW1Map.SetDepth(0);
            rightW1Map.SetDepth(0);

            //create nice ending ground
            GroundMap endingMap = GroundMap.BuildEndingMap(leftWMap.GetLastBlock(), rightWMap.GetLastBlock(), groundMap.GetLastBlock());

            endingMap.SetDepth(1);

            GroundMap endingMap1 = GroundMap.BuildEndingMap(leftW1Map.GetLastBlock(), rightW1Map.GetLastBlock(), endingMap.GetLastBlock());

            endingMap1.SetDepth(0);

            GroundMap barMap = GroundMap.BuildBarMap(endingMap1);

            barMap.SetDepth(0);

            //build from maps
            List <GameObject> objects = new List <GameObject>();

            Ground ground = BuildFromMap(groundMap);

            enterPoint = ground.GetEnterPoint();
            exitPoint  = ground.GetExitPoint();
            objects.AddRange(ground.GetGameObjects());

            Ground leftW = BuildFromMap(leftWMap);

            leftW.AddColliders();
            objects.AddRange(leftW.GetGameObjects());

            Ground rightW = BuildFromMap(rightWMap);

            rightW.AddColliders();
            objects.AddRange(rightW.GetGameObjects());

            Ground leftW1 = BuildFromMap(leftW1Map);

            leftW1.AddColliders();
            objects.AddRange(leftW1.GetGameObjects());

            Ground rightW1 = BuildFromMap(rightW1Map);

            rightW1.AddColliders();
            objects.AddRange(rightW1.GetGameObjects());

            Ground ending = BuildFromMap(endingMap);

            ending.AddColliders();
            objects.AddRange(ending.GetGameObjects());

            Ground ending1 = BuildFromMap(endingMap1);

            ending1.AddColliders();
            objects.AddRange(ending1.GetGameObjects());

            Ground bar = BuildFromMap(barMap);

            objects.AddRange(bar.GetGameObjects());

            //sort objects
            objects = objects.OrderByDescending(p => p.transform.position.y).ToList();
            int objOrder = 0;

            foreach (GameObject obj in objects)
            {
                obj.GetComponent <SpriteRenderer>().sortingOrder = objOrder;
                objOrder++;
            }
        }
Example #33
0
 public void GenerateTreePositions(GroundMap groundMap, ColorSurface normals)
 {
     generateTreePositions(groundMap, normals);
     CreateVertices();
 }
Example #34
0
        protected void initialize(GroundMap groundMap, WeightsMap weights, ColorSurface normals)
        {
            GroundMap = groundMap;

            Debug.Assert((groundMap.Width%TerrainPlane.SquareSize) == 0 && (groundMap.Height%TerrainPlane.SquareSize) == 0);

            _position = World.TranslationVector;

            Textures[0] = Textures[0] ?? VContent.Load<Texture2D>("terraintextures/sand");
            Textures[1] = Textures[1] ?? VContent.Load<Texture2D>("terraintextures/sahara");
            Textures[2] = Textures[2] ?? VContent.Load<Texture2D>("terraintextures/grass");
            Textures[3] = Textures[3] ?? VContent.Load<Texture2D>("terraintextures/rock");
            Textures[4] = Textures[4] ?? VContent.Load<Texture2D>("terraintextures/snow");
            Textures[5] = Textures[5] ?? VContent.Load<Texture2D>("terraintextures/stones");
            Textures[6] = Textures[6] ?? VContent.Load<Texture2D>("terraintextures/dirtground");
            Textures[7] = Textures[7] ?? VContent.Load<Texture2D>("terraintextures/path");
            Textures[8] = Textures[8] ?? VContent.Load<Texture2D>("terraintextures/wheatfield");

            HeightsMap = groundMap.CreateHeightsTexture(Effect.GraphicsDevice);
            WeightsMap = weights.CreateTexture2D(Effect.GraphicsDevice);
            NormalsMap = normals.CreateTexture2D(Effect.GraphicsDevice);

            var slicesW = groundMap.Width/Side;
            var slicesH = groundMap.Height/Side;
            //TODO - this is wrong - I guess...
            var sliceFracX = 1f/slicesW;
            var sliceFracY = 1f/slicesH;
            _slices = new TerrainSlice[slicesW*slicesH];

            var gurka = Vector3.TransformNormal(new Vector3(HalfSide, 0, HalfSide), World);
            var radius = Math.Max(gurka.X, gurka.Z) * (float)Math.Sqrt(2);

            var i = 0;
            for (var y = 0; y < slicesH; y++)
                for (var x = 0; x < slicesW; x++)
                {
                    var world = Matrix.Translation(Side*x, 0, Side*y)*World;
                    _slices[i++] = new TerrainSlice
                    {
                        TexOffsetAndScale = new Vector4(x*sliceFracX, y*sliceFracY, sliceFracX, sliceFracY),
                        World = world,
                        BoundingSphere = new BoundingSphere(world.TranslationVector + gurka, radius)
                    };
                }
            BoundingSphere = new BoundingSphere(
                _position + new Vector3(groundMap.Width, 0, groundMap.Height)/2,
                (float) Math.Sqrt(groundMap.Width*groundMap.Width + groundMap.Height*groundMap.Height)/2);

            GroundExtentX = slicesW;
            GroundExtentZ = slicesH;
        }
Example #35
0
 protected void initialize(GroundMap groundMap)
 {
     initialize(groundMap, groundMap.CreateWeigthsMap(), groundMap.CreateNormalsMap(ref World));
 }
Example #36
0
    private WaitAction BuildWaitAction(ActionResult actionResult, EntityMap entityMap, GroundMap groundMap, bool logMessage = true)
    {
        if (logMessage)
        {
            actionResult.AppendMessage(new Message($"The {owner.name} is confused.  What should it do?", null));
        }
        var action = new WaitAction(owner.actor);

        actionResult.Success = true;
        action.SetActionResult(actionResult);
        return(action);
    }
Example #37
0
    void Start()
    {
        roomSizeRange     = IntRange.CreateInstance <IntRange>();
        roomSizeRange.min = 6;
        roomSizeRange.max = 10;

        Application.targetFrameRate = 120;
        QualitySettings.vSyncCount  = 0;

        var groundTileMap = GameObject.Find(TileMapType.GroundMap.Name()).GetComponent <Tilemap>();
        var levelBuilder  = new LevelBuilder();

        _groundMap = levelBuilder.MakeMap(maxRooms, roomSizeRange, mapWidth, mapHeight, groundTileMap);
        var startLocation = levelBuilder.GetStartPosition();

        var entityTileMap = GameObject.Find(TileMapType.EntityMap.Name()).GetComponent <Tilemap>();

        _entityMap = ScriptableObject.CreateInstance <EntityMap>().Init(entityTileMap, _groundMap);

        var entityBackgroundTileMap = GameObject.Find(TileMapType.EntityMap_Background.Name()).GetComponent <Tilemap>();

        _entityMapBackground = ScriptableObject.CreateInstance <EntityMap>().Init(entityBackgroundTileMap, _groundMap);

        _actors = new List <Actor>();

        // Build Player
        _player = Entity.CreateEntity().Init(startLocation.Clone(), spriteType: SpriteType.Soldier_Sword, color: Color.green, name: "player");
        _player.gameObject.AddComponent <Player>().owner = _player;
        _player.gameObject.AddComponent <Fighter>().Init(30, 2, 5).owner       = _player;
        _player.gameObject.AddComponent <Inventory>().Init(capacity: 10).owner = _player;
        _actors.Add(new Actor(_player));

        SetDesiredScreenSize();
        Camera.main.transform.position = new Vector3(_player.position.x + CalculateCameraAdjustment(), _player.position.y, Camera.main.transform.position.z);

        // Build Enemies
        var newEntities = levelBuilder.FillRoomsWithEntityActors(_entityMap.GetEntities(), maxEnemiesInRoom, maxItemsInRoom);

        foreach (var enemy in newEntities)
        {
            _actors.Add(new Actor(enemy));
            _entityMap.AddEntity(enemy);
        }

        var passiveEntities = levelBuilder.FillRoomsWithPassiveEntities(_entityMapBackground.GetEntities(), maxEnemiesInRoom, maxItemsInRoom);

        foreach (var passiveEntity in passiveEntities)
        {
            _entityMapBackground.AddEntity(passiveEntity);
        }

        _entityMap.AddEntity(_player);

        // Setup Systems
        fovSystem = new FieldOfViewSystem(_groundMap);
        fovSystem.Run(new Vector2Int(_player.position.x, _player.position.y), playerViewDistance);

        RunVisibilitySystem();

        // Final Setup
        _groundMap.UpdateTiles();

        statText.SetPlayer(_player);
        inventoryInterface.SetInventory(_player.GetComponent <Inventory>());
        _gameState = GameState.Global_LevelScene;

        _log = FindObjectOfType <MessageLog>();
    }
Example #38
0
        public CodeIsland(
            VisionContent vContent,
            Archipelag archipelag,
            Matrix world,
            VAssembly vassembly)
            : base(vContent)
        {
            Archipelag = archipelag;
            VAssembly = vassembly;
            World = world;

            if (VAssembly.Is3DParty)
            {
                DrawableBox = new DrawableBox(vContent, World, new Vector3(50, 20, 50), 0.01f);
                foreach (var vclass in vassembly.VClasses)
                {
                    var vc = new VisionClass(this, vclass, 75, 75, 5) {Height = 10};
                    Classes.Add(vclass.FullName, vc);
                }
                return;
            }

            var rnd = new Random();

            var interfaceClasses = new List<VClass>();
            var implementationClasses = new List<VClass>();
            foreach (var vclass in vassembly.VClasses)
                if (vclass.IsInterface)
                    interfaceClasses.Add(vclass);
                else
                    implementationClasses.Add(vclass);

            var circleMaster = new CircleMaster<VClass>();
            var q = 0;
            foreach (var vclass in interfaceClasses)
                circleMaster.Drop(q += 10, 0, 10, vclass);

            foreach (var vclass in implementationClasses)
                circleMaster.Drop(q += 5, 0, 4 + (int) Math.Sqrt(vclass.InstructionCount), vclass);

            int left, top, right, bottom;
            circleMaster.GetBounds(out left, out top, out right, out bottom);
            foreach (var c in circleMaster.Circles)
            {
                var vc = new VisionClass(this, c.Tag, ClassSide/2 + c.X - left, ClassSide/2 + c.Y - top, c.R);
                Classes.Add(c.Tag.FullName, vc);
            }

            var surfaceWidth = 1 << (1 + (int) (Math.Log(right - left)/Math.Log(2)));
            var surfaceHeight = 1 << (1 + (int) (Math.Log(bottom - top)/Math.Log(2)));

            System.Diagnostics.Debug.Print("{0}: {1} {2}", vassembly.Name, surfaceWidth, surfaceHeight);

            //var qq = Math.Max(surfaceWidth, surfaceHeight);
            var ground = new GroundMap(surfaceWidth, surfaceHeight);

            BoundingSphere = new BoundingSphere(new Vector3(
                world.TranslationVector.X + ground.Width / 2f,
                world.TranslationVector.Y,
                world.TranslationVector.Z + ground.Height / 2f),
                (float)Math.Sqrt(ground.Width * ground.Width + ground.Height * ground.Height) / 2);

            foreach (var vc in Classes.Values)
            {
                var instructHeight = (vc.VClass.IsInterface ? 40 : 10) + (float) Math.Pow(vc.VClass.InstructionCount, 0.3);
                var maintainabilityFactor = 3*(10 - vc.MaintainabilityIndex/10);
                var radius = vc.R;
                var middleX = vc.X - radius;
                var middleY = vc.Y - radius;
                var bellShapeFactor = 2f/(radius*1.7f);
                ground.AlterValues(
                    middleX, middleY,
                    radius*2, radius*2,
                    (px, py,  h) =>
                    {
                        var dx = px - radius;
                        var dy = py - radius;
                        var d = (dx*dx + dy*dy)*bellShapeFactor*bellShapeFactor;
                        var sharpness = (px & 1) != (py & 1) ? maintainabilityFactor : 0;
                        return h + instructHeight*(float) Math.Exp(-d*d) + sharpness*(float) rnd.NextDouble();
                    });

                var height = ground[vc.X, vc.Y];
                vc.Height = height;
            }

            // raise the point where the sign is
            foreach (var vc in Classes.Values)
                ground[vc.X, vc.Y] += 6;

            //...and lower it...
            ground.Soften(2);

            //make GroundMap slices seamless
            for (var x = 64; x < surfaceWidth; x += TerrainPlane.SquareSize)
                for (var y = 0; y < surfaceHeight; y++)
                    ground[x, y] = ground[x - 1, y] = (ground[x, y] + ground[x - 1, y])/2;
            for (var y = 64; y < surfaceHeight; y += TerrainPlane.SquareSize)
                for (var x = 0; x < surfaceWidth; x++)
                    ground[x, y] = ground[x, y - 1] = (ground[x, y] + ground[x, y - 1])/2;

            foreach (var vc in Classes.Values)
                vc.Height = ground[vc.X, vc.Y];

            var normals = ground.CreateNormalsMap(ref world);

            var signs = new Signs(
                vContent,
                world*Matrix.Translation(0, -0.1f, 0),
                vContent.Load<Texture2D>("billboards/woodensign"),
                Classes.Values.ToList(),
                16,
                4);
            Children.Add(signs);

            var qqq = world; //*Matrix.Translation(0, 0.05f, 0);
            var ms = new CxBillboard(vContent, Matrix.Identity, vContent.Load<Texture2D>("billboards/grass"), 1, 1, 0.5f);
            foreach (var vc in Classes.Values)
            {
                for (var i = (vc.CyclomaticComplexity - 1)*2; i > 0; i--)
                {
                    var gx = vc.X + ((float) rnd.NextDouble() - 0.5f)*(ClassSide - 3);
                    var gy = vc.Y + ((float) rnd.NextDouble() - 0.5f)*(ClassSide - 3);
                    ms.Add(
                        Vector3.TransformCoordinate(new Vector3(gx, ground.GetExactHeight(gx, gy), gy), qqq),
                        normals.AsVector3(vc.X, vc.Y));
                }
            }
            ms.CreateVertices();
            Children.Add(ms);

            var weights = ground.CreateWeigthsMap(new[] {0, 0.40f, 0.60f, 0.9f});
            //weights.DrawLine(0, 0, 20, 20, 1, (_, mt) => new Mt9Surface.Mt9 { I = 100 });
            //weights.AlterValues(20, 20, 20, 20, (x, y, mt) =>
            //{
            //    mt.B = 1;
            //    return mt;
            //});
            //weights.AlterValues(40, 40, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { C = 100 });
            //weights.AlterValues(60, 60, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { D = 10 });
            //weights.AlterValues(80, 80, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { E = 10 });
            //weights.AlterValues(100, 100, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { F = 10 });
            //weights.AlterValues(120, 120, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { G = 10 });
            //weights.AlterValues(140, 140, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { H = 10 });
            //weights.AlterValues(160, 160, 20, 20, (x, y, mt) => new Mt9Surface.Mt9 { I = 100, A = (float)Math.Sqrt(x * x + y * y) });

            //foreach (var vc in Classes.Values.Where(_ => !_.CalledClasses.Any()))
            //{
            //    weights.AlterValues(vc.X - vc.R, vc.Y - vc.R, vc.R*2, vc.R*2, (x, y, mt) => new Mt9Surface.Mt9 {I = 100});
            //}

            initialize(ground, weights, normals);
        }
Example #39
-1
        private static List<Vector3> generateTreePositions(Texture2D treeMap, GroundMap groundMap, ColorSurface normals)
        {
            var treeMapColors = new Color[treeMap.Description.Width*treeMap.Description.Height];
            treeMap. GetData(treeMapColors);

            var sz = new Size2(treeMap.Description.Width, treeMap.Description.Height);
            var noiseData = new int[sz.Width,sz.Height];
            for (var x = 0; x < sz.Width; x++)
                for (var y = 0; y < sz.Height; y++)
                    noiseData[x, y] = treeMapColors[y + x*sz.Height].R;

            var treeList = new List<Vector3>();
            var random = new Random();

            var minFlatness = (float) Math.Cos(MathUtil.DegreesToRadians(15));
            for (var y = normals.Height - 2; y > 0; y--)
                for (var x = normals.Width - 2; x > 0; x--)
                {
                    var terrainHeight = groundMap[x, y];
                    if ((terrainHeight <= 8) || (terrainHeight >= 14))
                        continue;
                    var flatness1 = Vector3.Dot(normals.AsVector3(x, y), Vector3.Up);
                    var flatness2 = Vector3.Dot(normals.AsVector3(x + 1, y + 1), Vector3.Up);
                    if (flatness1 <= minFlatness || flatness2 <= minFlatness)
                        continue;
                    var relx = (float) x/normals.Width;
                    var rely = (float) y/normals.Height;

                    float noiseValueAtCurrentPosition = noiseData[(int) (relx*sz.Width), (int) (rely*sz.Height)];
                    float treeDensity;
                    if (noiseValueAtCurrentPosition > 200)
                        treeDensity = 3;
                    else if (noiseValueAtCurrentPosition > 150)
                        treeDensity = 2;
                    else if (noiseValueAtCurrentPosition > 100)
                        treeDensity = 1;
                    else
                        treeDensity = 0;

                    for (var currDetail = 0; currDetail < treeDensity; currDetail++)
                    {
                        var rand1 = (float) random.NextDouble();
                        var rand2 = (float) random.NextDouble();
                        treeList.Add(new Vector3(
                                         x + rand1,
                                         groundMap.GetExactHeight(x, y, rand1, rand2),
                                         y + rand2));
                    }
                }

            return treeList;
        }