Example #1
0
        private List <FireNode> findNearFirePoints(FireNode point)
        {
            int             height     = FloorPlanManager.getInstance().getHeight();
            int             width      = FloorPlanManager.getInstance().getWidth();
            List <FireNode> pointNodes = new List <FireNode>();

            //up
            if (!nodes[point.x, Math.Max(point.y - 1, 0)].isGoingToFire())
            {
                pointNodes.Add(new FireNode(point.x, Math.Max(point.y - 1, 0)));
            }
            //down
            if (!nodes[point.x, Math.Min(point.y + 1, height - 1)].isGoingToFire())
            {
                pointNodes.Add(new FireNode(point.x, Math.Min(point.y + 1, height - 1)));
            }
            //left
            if (!nodes[Math.Max(point.x - 1, 0), point.y].isGoingToFire())
            {
                pointNodes.Add(new FireNode(Math.Max(point.x - 1, 0), point.y));
            }
            //right
            if (!nodes[Math.Min(point.x + 1, width - 1), point.y].isGoingToFire())
            {
                pointNodes.Add(new FireNode(Math.Min(point.x + 1, width - 1), point.y));
            }

            return(pointNodes);
        }
        public void startOnUpdate()
        {
            nodes = FloorPlanManager.getInstance().getNodes();
            exits = FloorPlanManager.getInstance().getExits();

            //绘制人物
            UpdateMap();
        }
Example #3
0
 public void setFireSource(List <FireNode> points)
 {
     nodes = FloorPlanManager.getInstance().getNodes();
     //clear fire points
     firingPoints.Clear();
     //set fire source
     addPoints(points);
     for (int i = 0; i < firingPoints.Count; ++i)
     {
         setNodeFired(firingPoints[i]);
         nodes[firingPoints[i].x, firingPoints[i].y].type = PlaceNode.TYPE_BLOCK;
     }
 }
        private int getNeighborNum(PersonNode node)
        {
            int sum = 0;

            PlaceNode[,] nodes = FloorPlanManager.getInstance().getNodes();
            List <Point> neighborPoints = GlobalController.getInstance().findNeighborsWithoutBlock(node.getPosition(), 3);

            foreach (Point point in neighborPoints)
            {
                sum += nodes[point.x, point.y].getPersonNum();
            }
            return(sum);
        }
        public bool isPersonAlone(Point node)
        {
            PlaceNode[,] nodes = FloorPlanManager.getInstance().getNodes();
            List <Point> neighborPoints = GlobalController.getInstance().findNeighborsWithoutBlock(node, 3);

            foreach (Point point in neighborPoints)
            {
                if (nodes[point.x, point.y].getPersonNum() != 0)
                {
                    return(false);
                }
            }
            return(true);
        }
        public bool isNearFire()
        {
            PlaceNode[,] nodes = FloorPlanManager.getInstance().getNodes();
            List <Point> neighborPoints = GlobalController.getInstance().findNeighborsWithoutBlock(getPosition(), 3);

            foreach (Point point in neighborPoints)
            {
                if (nodes[point.x, point.y].isFired())
                {
                    return(true);
                }
            }
            return(false);
        }
        //return a bool value indicate if the scare factor should affect person's behavior
        //depends by a random number and scare value
        public bool isAffected(Point position)
        {
            List <Point> exits  = FloorPlanManager.getInstance().getExits();
            double       ranNum = random.NextDouble();

            foreach (Point exit in exits)
            {
                if (distanceBetweenTwoPoint(exit, position) < 5)
                {
                    reset();
                    return(false);
                }
            }
            return(scareValue * ranNum >= 40);
        }
        public void ReStart()
        {
            count = 1;
            int length = width * height;

            first    = new int[length];
            next     = new int[length * 4];
            value    = new int[length * 4];
            v        = new int[length * 4];
            preOdd   = preEven = new int[length];//最大路径长度为所有节点遍历
            pre      = new int[FloorPlanManager.getInstance().getExits().Count, length * 4];
            distance = new int[length];
            visit    = new bool[length];
            queue    = new FastPriorityQueue <PathNode>(length);
        }
        //进行相关变量初始化操作
        private void initVar()
        {
            nextFirePoints = FireController.getInstance().findAllNearFirePoints();
            nodes          = FloorPlanManager.getInstance().getNodes();
            queue.Clear();
            int length = width * height;

            for (int i = 0; i < length; ++i)
            {
                distance[i] = INF;
                visit[i]    = false;
                first[i]    = -1;
            }
            caculateValue();
        }
        public void moveNext()
        {
            bool isMove = true;

            if (callTimes == 0 || callTimes % CALLPERCOUNT >= CALLPERCOUNT - 1)
            {
                FireController.getInstance().handleFireNodes(callTimes);
                int i = 0;
                foreach (Point exit in exits)
                {
                    MoveController.getInstance().DijkstraShortestPath(exit.x * FloorPlanManager.getInstance().getHeight() + exit.y, i);
                    i++;
                }
                for (int j = 0; j < personList.Count; j++)
                {
                    personList[j].setExitIndex(getNearestExitIndex(personList[j].getPosition()));
                }
            }
            for (int i = 0; i < personList.Count; i++)
            {
                handleAloneScare(personList[i]);
                //if person's scare value > 80, then he will random a avaliable direction
                if (personList[i].isAffectedByScare())
                {
                    isMove = personList[i].moveNextRandom(i);
                    personList[i].decreaseScareValue();
                }
                else
                {
                    if (getNeighborNum(personList[i]) > 30)
                    {
                        //寻找别的道路
                        personList[i].changeExitIndex();
                        isMove = personList[i].moveNext(i);
                    }
                    else
                    {
                        isMove = personList[i].moveNext(i);
                    }
                }
                if (isMove)
                {
                    updateContainerNum(new Point(personList[i].getOriginX(), personList[i].getOriginY()), personList[i].getPosition());
                }
            }
            ++callTimes;
            UpdateMap();
        }
        // Update is called once per frame
        void FixedUpdate()
        {
            nodes = FloorPlanManager.getInstance().getNodes();
            if (x != -1 && y != -1)
            {
                nodes [x, y].type = t;
            }
            x     = (int)this.transform.position.x;
            y     = (int)this.transform.position.z;
            t     = nodes [x, y].type;
            life -= 1;

            if (nodes [x, y].type == PlaceNode.TYPE_EXIT && !WinButton)
            {
                Debug.Log("Win!");
                Debug.Log(index);
                if (Network.peerType == NetworkPeerType.Server)
                {
                    MainRoom.GetComponent <NetworkView>().RPC("PersonIsEscaped", RPCMode.All, index);
                }

                WinButton = true;
                return;
            }
            Debug.Log("fire XXX " + nodes[x, y].isFired());
            if (nodes [x, y].isFired())
            {
                life -= 50;
            }
            nodes[x, y].type = PlaceNode.TYPE_BLOCK;
            if (life <= 0)
            {
                Debug.Log("Died!");
                if (Network.peerType == NetworkPeerType.Server)
                {
                    MainRoom.GetComponent <NetworkView>().RPC("PersonDie", RPCMode.All, index);
                }
            }

            if (Network.peerType == NetworkPeerType.Server)
            {
                MainRoom.GetComponent <NetworkView>().RPC("LifeControl", RPCMode.All, index, life);
            }
        }
        public int moveRules()
        {
            //get neighbor points
            int          oldX           = getX();
            int          oldY           = getY();
            List <Point> neighborPoints = GlobalController.getInstance().findNeighborsWithoutBlock(new Controller.Point(oldX, oldY), step);

            //get neighbor place nodes info
            PlaceNode[,] nodes = FloorPlanManager.getInstance().getNodes();
            List <NeighborNode> neighbors = new List <NeighborNode>();

            for (int i = 0; i < neighborPoints.Count(); ++i)
            {
                neighbors.Add(new NeighborNode(nodes[neighborPoints[i].x, neighborPoints[i].y],
                                               getNodeDirection(new Point(oldX, oldY), neighborPoints[i])));
            }
            //get next direction
            return(decideMoveDirection(neighbors));
        }
        public Vector3 setHuman()
        {
            PlaceNode[,] nodes = FloorPlanManager.getInstance().getNodes();
            System.Random random = new System.Random();
            int           maxY   = FloorPlanManager.getInstance().getHeight();
            int           maxX   = FloorPlanManager.getInstance().getWidth();
            int           randomX;
            int           randomY;

            for (int i = 0; i < Config.PERSON_NUM;)
            {
                randomX = random.Next(maxX);
                randomY = random.Next(maxY);
                if (nodes[randomX, randomY].type != PlaceNode.TYPE_BLOCK && nodes[randomX, randomY].type != PlaceNode.TYPE_BLOCK &&
                    nodes[randomX, randomY].getPersonNum() == 0)
                {
                    return(new Vector3(randomX + 0.5f, 0, randomY + 0.5f));
                }
            }
            return(new Vector3(-1, 0, -1));
        }
 public void changeExitIndex()
 {
     if (!changeExitFlag)
     {
         List <Point> exits = FloorPlanManager.getInstance().getExits();
         changeExitFlag = true;
         int minIndex = 0;
         int tmpVal;
         int minVal = (exits[0].x - getPosition().x) * (exits[0].x - getPosition().x) + (exits[0].y - getPosition().y) * (exits[0].y - getPosition().y);
         for (int i = 1; i < exits.Count; ++i)
         {
             tmpVal = (exits[i].x - getPosition().x) * (exits[i].x - getPosition().x) + (exits[i].y - getPosition().y) * (exits[i].y - getPosition().y);
             if (minVal > tmpVal && minIndex != exitIndex)
             {
                 minVal   = tmpVal;
                 minIndex = i;
             }
         }
         exitIndex = minIndex;
     }
 }
        public bool directionEnable(NeighborNode node)
        {
            int nextDirection = node.getDirection();

            PlaceNode[,] nodes = FloorPlanManager.getInstance().getNodes();

            switch (nextDirection)
            {
            case PersonLocationManager.MOVE_LEFT:
                return(nodes[getX() - 1, getY()].isEnable());

            case PersonLocationManager.MOVE_RIGHT:
                return(nodes[getX() + 1, getY()].isEnable());

            case PersonLocationManager.MOVE_UP:
                return(nodes[getX(), getY() + 1].isEnable());

            case PersonLocationManager.MOVE_DOWN:
                return(nodes[getX(), getY() - 1].isEnable());
            }
            return(true);
        }
        public bool moveNextRandom(int index)
        {
            Point originPosition = getOriginPosition();
            Point nextMove       = new Point();
            //get neighbor points
            Point        oldPoint       = getPosition();
            List <Point> neighborPoints = GlobalController.getInstance().findNeighborsWithoutBlock(new Controller.Point(oldPoint.x, oldPoint.y), step);

            //get neighbor place nodes info
            PlaceNode[,] nodes = FloorPlanManager.getInstance().getNodes();
            List <NeighborNode> neighbors = new List <NeighborNode>();

            for (int i = 0; i < neighborPoints.Count(); ++i)
            {
                neighbors.Add(new NeighborNode(nodes[neighborPoints[i].x, neighborPoints[i].y],
                                               getNodeDirection(new Point(oldPoint.x, oldPoint.y), neighborPoints[i])));
            }
            locationManager.setDirection(locationManager.randomDirection(neighbors));
            switch (locationManager.getDirection())
            {
            case PersonLocationManager.MOVE_DOWN:
                nextMove = new Point(getX(), getY() - 1);
                break;

            case PersonLocationManager.MOVE_UP:
                nextMove = new Point(getX(), getY() + 1);
                break;

            case PersonLocationManager.MOVE_LEFT:
                nextMove = new Point(getX() - 1, getY());
                break;

            case PersonLocationManager.MOVE_RIGHT:
                nextMove = new Point(getX() + 1, getY());
                break;
            }
            return(reverseOrMove(nextMove, originPosition, index));
        }
        public void setRandomNum()
        {
            StartTime = Time.time;
            ifseted   = 1;
            System.Random random = new System.Random();
            int           maxY   = FloorPlanManager.getInstance().getHeight();
            int           maxX   = FloorPlanManager.getInstance().getWidth();
            int           randomX;
            int           randomY;

            for (int i = 0; i < Config.PERSON_NUM;)
            {
                randomX = random.Next(maxX);
                randomY = random.Next(maxY);
                if (nodes[randomX, randomY].type != PlaceNode.TYPE_BLOCK && nodes[randomX, randomY].type != PlaceNode.TYPE_BLOCK &&
                    nodes[randomX, randomY].getPersonNum() == 0)
                {
                    nodes[randomX, randomY].setPersonNum(nodes[randomX, randomY].getPersonNum() + 1);
                    string     randomgetedMan = getARandomMan();
                    GameObject tmp            = (GameObject)Instantiate(Resources.Load(randomgetedMan), new Vector3(0.5f + (float)randomX, 0, 0.5f + (float)randomY), Quaternion.identity);
                    tmp.transform.Rotate(Vector3.up * UnityEngine.Random.value * 360);
                    tmp.GetComponent <PersonBehavior>().init(randomX, randomY);
                    //		tmp.AddComponent<PersonBehavior>();
                    personList.Add(new PersonNode(randomX, randomY, tmp, getNearestExitIndex(new Point(randomX, randomY))));
                    UnityEngine.Debug.Log("this is" + Network.peerType);
                    if (Network.peerType == NetworkPeerType.Server)
                    {
                        MainRoom.GetComponent <NetworkView>().RPC("RequestCreate", RPCMode.All, randomgetedMan, randomX, randomY, tmp.transform.rotation);
                    }
                    i++;
                    AllNPC += 1;
                }
            }
            UpdateMap();
            set = false;
        }
Example #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="inCanvas"></param>
 /// <param name="inLocation"></param>
 LocationInfoCanvasManager(Control inCanvas, FloorPlanManager inFloorPlanManager) : base(inCanvas)
 {
     FPManager = inFloorPlanManager;
 }
Example #19
0
 public override void Awake()
 {
     base.Awake();
     Instance = this;
 }