예제 #1
0
파일: Map.cs 프로젝트: g5v991x/testpf
    public List<Vector3> Get_Attack(List<Vector3> center, int reach)
    {
        MapData tmpmap=new MapData(sizex, sizey); 	// this is the distance to center map

        List<Vector3> lst = new List<Vector3>(); // list of avaliable squares
        List<Vector3> atk = new List<Vector3>(); // list of attack targets
        int[] occid = new int[center.Count];
        bool noblock = true;

        // tempororaily remove the character so it wont block itself
        for (int i=0; i<center.Count; i++) {
            //save the occupy id in map in center.z
            occid[i]= occupy.Check_At(center[i]);
            occupy.Set_At(center[i],0);
            lst.Add(center[i]);
            tmpmap.Set_At(center[i],1);
        }

        // build path
        int first = 0, last=lst.Count;
        for (int step=0; step< reach; step++)
        {
            for (int i=first; i< last; i++)
            {

                for (int di=0; di<8; di++)
                {
                    Vector3 tmpv = lst[i] + dirs[di];

                    // Empty square
                    if (Check_Avi(tmpv,noblock))
                    {
                        if (tmpmap.Check_At(tmpv) == 0)
                        {
                            tmpv.z = i;
                            int dist=tmpmap.Check_At(lst[i])+length[di];

                            if (dist <= reach * 10 + 5)
                            {
                                lst.Add(tmpv);
                                tmpmap.Set_At(tmpv, dist);
                            }
                        }
                        else
                        {
                            int dist = tmpmap.Check_At(lst[i]) + length[di];
                            if (dist < tmpmap.Check_At(tmpv))
                            {
                                tmpmap.Set_At(tmpv, dist);
                            }

                        }

                    }
                    // Square with enemies
                    if (Check_Avi(tmpv,noblock) && occupy.Check_At(tmpv) > 0)
                    {
                        if (!center.Contains(tmpv) && !atk.Contains(tmpv))
                        {
                            int dist = tmpmap.Check_At(lst[i]) + length[di];
                            if (dist <= ( reach) * 10 + 5)
                            {
                                tmpv.z = -1;
                                atk.Add(tmpv);
                                tmpmap.Add_At(tmpv, 1);
                            }
                        }
                    }

                }
            }

            first = last;
            last = lst.Count;
        }

        // put the character back
        for (int i=0; i<center.Count; i++) {
            occupy.Set_At(center[i], occid[i]);
        }

        //		lst.RemoveAt (0);
        lst.AddRange(atk);
        return lst;
    }