예제 #1
0
    public static Vector3 GetDynamicNativeSinglePoint(VArtifactTown vat, System.Random randSeed)
    {
        VArtifactUnit vau         = vat.VAUnits[randSeed.Next(vat.VAUnits.Count)];
        Vector3       posBeforRot = vau.npcPos[randSeed.Next(vau.npcPos.Count)];

        return(GetPosAfterRotation(vau, posBeforRot));
    }
예제 #2
0
 public static bool CheckTownAvailable(VArtifactTown vaTowndata)
 {
     if (!IsContained(vaTowndata))
     {
         for (int i = 0; i < vaTowndata.VAUnits.Count; i++)
         {
             VArtifactUnit vau = vaTowndata.VAUnits[i];
             vau.worldPos = new Vector3(vau.PosCenter.x, -1, vau.PosCenter.y);
         }
         return(true);
     }
     return(false);
 }
예제 #3
0
    public static Vector3 GetPosAfterRotation(VArtifactUnit vau, Vector3 relativePos)
    {
        Quaternion q = new Quaternion();

        q.eulerAngles = new Vector3(0, vau.rot, 0);
        Vector3 ofs = relativePos - vau.worldPos;

        ofs.x += vau.isoStartPos.x;
        ofs.y += vau.worldPos.y;
        ofs.z += vau.isoStartPos.y;
        Vector3 rezultPos = vau.worldPos + q * ofs;

        return(rezultPos);
    }
예제 #4
0
    public static List <IntVector2> LinkedChunkIndex(VArtifactUnit townInfo)
    {
        IntVector2 startPos = townInfo.PosStart;
        IntVector2 endPos   = townInfo.PosEnd;

        List <IntVector2> startIndexList = Link1PointToChunk(startPos);
        List <IntVector2> endIndexList   = Link1PointToChunk(endPos);

        IntVector2 startIndex = GetMinChunkIndex(startIndexList);
        IntVector2 endIndex   = GetMaxChunkIndex(endIndexList);

        List <IntVector2> chunkIndexList = GetChunkIndexListFromStartEnd(startIndex, endIndex);

        return(chunkIndexList);
    }
예제 #5
0
    public static void OutputTownVoxel(int x, int y, int z, VCVoxel voxel, VArtifactUnit town)
    {
        IntVector3 pos     = new IntVector3(x, y, z);
        VFVoxel    vfvoxel = new VFVoxel();

        vfvoxel.Type   = voxel.Type;
        vfvoxel.Volume = voxel.Volume;
        if (town.townVoxel.ContainsKey(pos))
        {
            VFVoxel originVoxel = town.townVoxel[pos];
            vfvoxel.Volume = (byte)Mathf.Clamp(vfvoxel.Volume + originVoxel.Volume, 0, 255);
        }
        town.townVoxel[pos] = vfvoxel;
        //Debug.LogError("addarttown:"+pos);
    }
예제 #6
0
 public static DynamicNative[] GetAllDynamicNativePoint(int townId, out List <Vector3> posList)
 {
     DynamicNative[] result = null;
     posList = new List <Vector3> ();
     if (VArtifactTownManager.Instance != null)
     {
         VArtifactTown vat = VArtifactTownManager.Instance.GetTownByID(townId);
         if (vat != null)
         {
             if (vat.nativeTower != null)
             {
                 result = vat.nativeTower.dynamicNatives;
                 if (vat.VAUnits != null && vat.VAUnits.Count > 0)
                 {
                     VArtifactUnit  vau         = vat.VAUnits[0];
                     List <Vector3> posBeforRot = vau.npcPos;
                     foreach (Vector3 p in posBeforRot)
                     {
                         posList.Add(GetPosAfterRotation(vau, p));
                     }
                 }
                 else
                 {
                     Debug.LogError("GetAllDynamicNativePoint: " + "vat.VAUnits==null||vat.VAUnits.Count=0");
                 }
             }
             else
             {
                 Debug.LogError("GetAllDynamicNativePoint: " + "vat.nativeTower==null");
             }
         }
         else
         {
             Debug.LogError("GetAllDynamicNativePoint: " + "vat==null");
         }
     }
     else
     {
         Debug.LogError("GetAllDynamicNativePoint: " + "ArtifactTownManager.Instance==null");
     }
     return(result);
 }
예제 #7
0
    public VABuildingInfo(Vector3 pos, float rot, int id, BuildingID buildingId, VABuildingType type, VArtifactUnit vau, Vector2 size)
    {
        this.pos      = pos;
        this.id       = id;
        this.rotation = rot;
        buildingType  = type;

        center   = new IntVector2();
        center.x = Mathf.FloorToInt(this.pos.x);
        center.y = Mathf.FloorToInt(this.pos.z);

        root      = pos;
        this.size = size;
//        int length = Mathf.CeilToInt(size.x);
        int width    = Mathf.CeilToInt(size.y);
        int distance = width / 2 + 3;

        //--to do:get front door pos
        frontDoorPos = root + new Vector3(distance * Mathf.Sin(rot * Mathf.PI / 180), 0, distance * Mathf.Cos(rot * Mathf.PI / 180));

        this.buildingId = buildingId;
        this.vau        = vau;
    }
예제 #8
0
    public static void GetArtifactUnit(VArtifactTown townData, ArtifactUnit[] artifactUnitArray, System.Random myRand)
    {
        int townPosXMin = townData.PosGen.x;
        int townPosZMin = townData.PosGen.y;
        int townPosXMax = townData.PosGen.x;
        int townPosZMax = townData.PosGen.y;

        int unitIndex = 0;

        for (int m = 0; m < artifactUnitArray.Count(); m++)
        {
            IntVector2 posXZ = VArtifactUtil.GetIntVector2FromStr(artifactUnitArray[m].pos);
            int        unitID;
            if (artifactUnitArray[m].id.Equals("-1"))
            {
                List <int> idList = VArtifactUtil.townArtifactsData.Keys.ToList();
                unitID = idList[myRand.Next(idList.Count)];
            }
            else
            {
                unitID = VArtifactUtil.RandIntFromStr(artifactUnitArray[m].id, myRand);
            }
            //Debug.Log("unitID:" + unitID);
            Town_artifacts townDataFromDataBase = VArtifactUtil.townArtifactsData[unitID];
            string         isoName = townDataFromDataBase.isoName;
            float          rot;
            if (artifactUnitArray[m].rot.Equals("-1"))
            {
                //--to do: "type" is not used
                rot = (float)(myRand.NextDouble() * 360);
            }
            else
            {
                rot = VArtifactUtil.RandFloatFromStr(artifactUnitArray[m].rot, myRand);
            }

            //--to do: get the isoData  from id;
            ulong guid;
            //townData.isodataList.Add(posXZ,GetIsoData(isoName,out guid));
            VArtifactUnit vau     = new VArtifactUnit();
            VArtifactData isoData = VArtifactUtil.GetIsoData(isoName, out guid);
            if (isoData == null)
            {
                Debug.LogError("unitID:" + unitID + " isoName not found! IsoName: " + isoName);
                continue;
            }
            vau.isoName   = isoName;
            vau.unitIndex = unitIndex++;
            vau.isoId     = unitID;
            vau.isoGuId   = guid;
            vau.vat       = townData;
            vau.rot       = rot;
            vau.PosCenter = posXZ + townData.PosGen;
            int xIsoSize = isoData.m_HeadInfo.xSize;
            int zIsoSize = isoData.m_HeadInfo.zSize;
            vau.isoStartPos = new IntVector2(posXZ.x - xIsoSize / 2, posXZ.y - zIsoSize / 2) + townData.PosGen;
            vau.isoEndPos   = new IntVector2(posXZ.x + xIsoSize / 2, posXZ.y + zIsoSize / 2) + townData.PosGen;
            int xSize = townDataFromDataBase.vaSize.x;
            int zSize = townDataFromDataBase.vaSize.y;
            vau.PosStart      = new IntVector2(posXZ.x - xSize / 2, posXZ.y - zSize / 2) + townData.PosGen;
            vau.PosEnd        = new IntVector2(posXZ.x + xSize / 2, posXZ.y + zSize / 2) + townData.PosGen;
            vau.level         = townData.level;
            vau.type          = townData.type;
            vau.buildingIdNum = artifactUnitArray[m].buildingIdNum.ToList();
            vau.npcIdNum      = artifactUnitArray[m].npcIdNum.ToList();
            vau.buildingCell  = townDataFromDataBase.buildingCell;
            vau.npcPos        = townDataFromDataBase.npcPos;
            vau.vaSize        = townDataFromDataBase.vaSize;
            vau.towerPos      = townDataFromDataBase.towerPos;
            if (vau.PosStart.x < townPosXMin)
            {
                townPosXMin = vau.PosStart.x;
            }
            if (vau.PosStart.y < townPosZMin)
            {
                townPosZMin = vau.PosStart.y;
            }
            if (vau.PosEnd.x > townPosXMax)
            {
                townPosXMax = vau.PosEnd.x;
            }
            if (vau.PosEnd.y > townPosZMax)
            {
                townPosZMax = vau.PosEnd.y;
            }
            townData.VAUnits.Add(vau);
        }
        townData.PosStart  = new IntVector2(townPosXMin, townPosZMin);
        townData.PosEnd    = new IntVector2(townPosXMax, townPosZMax);
        townData.PosCenter = new IntVector2((townPosXMin + townPosXMax) / 2, (townPosZMin + townPosZMax) / 2);
//        townData.height = Mathf.CeilToInt(townData.VAUnits[0].worldPos.y + townData.VAUnits[0].vaSize.z);
//        townData.TransPos = new Vector3(townData.PosCenter.x, townData.height, townData.PosCenter.y);
        townData.radius = (int)Mathf.Sqrt(Mathf.Pow((townPosXMax - townPosXMin) / 2, 2) + Mathf.Pow((townPosZMax - townPosZMin) / 2, 2));
    }
예제 #9
0
    //public static void OutputVoxels(Vector3 worldPos, ulong guid, VArtifactTown newTown)
    //{
    //    ISO = isos[guid];
    //    OutputVoxels(worldPos,newTown);
    //}

    //public static void OutputVoxels(Vector3 worldPos, int townId, VArtifactTown newTown)
    //{
    //    ulong guid = townIdIso[townId];
    //    ISO = isos[guid];
    //    OutputVoxels(worldPos,newTown);
    //}


    public static void OutputVoxels(Vector3 worldPos, VArtifactUnit newTown, float rotation = 0)
    {
        if (!isos.ContainsKey(newTown.isoGuId))
        {
            LoadIso(GetISONameFullPath(newTown.isoName));
        }
        if (!isos.ContainsKey(newTown.isoGuId))
        {
            Debug.LogError("isoGuId error: " + newTown.isoGuId + "isoName: " + newTown.isoName);
            return;
        }
        VArtifactData isoData = isos[newTown.isoGuId];
        //long tick = System.DateTime.Now.Ticks;
        Quaternion q = new Quaternion();

        q.eulerAngles = new Vector3(0, rotation, 0);
        Vector3 XDir = (q * Vector3.right).normalized;
        Vector3 YDir = (q * Vector3.up).normalized;
        Vector3 ZDir = (q * Vector3.forward).normalized;
        //Vector3 XDir = Vector3.right;
        //Vector3 YDir = Vector3.up;
        //Vector3 ZDir = Vector3.forward;
        Vector3 ofs     = new Vector3(isoData.m_HeadInfo.xSize, 0, isoData.m_HeadInfo.zSize) * (-0.5f);
        Vector3 new_pos = worldPos + q * ofs;

        foreach (KeyValuePair <int, VCVoxel> kvp in isoData.m_Voxels)
        {
            Vector3 lpos = new Vector3(kvp.Key & 0x3ff, kvp.Key >> 20, (kvp.Key >> 10) & 0x3ff);
            Vector3 wpos = new_pos
                           + lpos.x * XDir
                           + lpos.y * YDir
                           + lpos.z * ZDir;

            INTVECTOR3 wpos_floor = new INTVECTOR3(Mathf.FloorToInt(wpos.x), Mathf.FloorToInt(wpos.y), Mathf.FloorToInt(wpos.z));
            INTVECTOR3 wpos_ceil  = new INTVECTOR3(Mathf.CeilToInt(wpos.x), Mathf.CeilToInt(wpos.y), Mathf.CeilToInt(wpos.z));

            if (wpos_floor == wpos_ceil)
            {
                OutputTownVoxel(wpos_floor.x, wpos_floor.y, wpos_floor.z, kvp.Value, newTown);
            }
            else
            {
                for (int x = wpos_floor.x; x <= wpos_ceil.x; ++x)
                {
                    for (int y = wpos_floor.y; y <= wpos_ceil.y; ++y)
                    {
                        for (int z = wpos_floor.z; z <= wpos_ceil.z; ++z)
                        {
                            float deltax = 1 - Mathf.Abs(wpos.x - x);
                            float deltay = 1 - Mathf.Abs(wpos.y - y);
                            float deltaz = 1 - Mathf.Abs(wpos.z - z);
                            float u      = deltax * deltay * deltaz;
                            if (u < 0.5f)
                            {
                                u = u / (0.5f + u);
                            }
                            else
                            {
                                u = 0.5f / (1.5f - u);
                            }
                            VCVoxel voxel = kvp.Value;
                            voxel.Volume = (byte)Mathf.CeilToInt(voxel.Volume * u);
                            if (voxel.Volume > 1)
                            {
                                OutputTownVoxel(x, y, z, voxel, newTown);
                            }
                        }
                    }
                }
            }
        }
        // Debug.LogError("Output Time: " + (System.DateTime.Now.Ticks - tick) + " townCount:" + (++townCount));
    }