public Quad(int LeftX, int LeftY, int RightX, int RightY)
 {
     this.L     = new Vec2int(LeftX, LeftY);
     this.R     = new Vec2int(RightX, RightY);
     Length     = R.x - L.x;
     HalfLength = Length / 2;
 }
Ejemplo n.º 2
0
 void updatePath(Vec2int[] newPath)
 {
     if (newPath == null)
     {
         if (gos != null)
         {
             foreach(GameObject go in gos)
             {
                 go.SetActive(false);
             }
         }
         return;
     }
     if(gos == null) gos = new List<GameObject>();
     int size = gos.Count;
     if(size > newPath.Length){
         for(var i = newPath.Length - 1; i < size; i++){
             gos[i].SetActive(false);
         }
     }else if (size < newPath.Length){
         for(int i = size; i < newPath.Length; i++)
         {
             gos.Add((Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject));
             gos[i].transform.parent = transform;
         }
     }
     for(int i = 0; i < newPath.Length; i++){
         gos[i].SetActive(true);
         gos[i].transform.position = WorldMapData.instance.tiles[newPath[i].x, newPath[i].y].position;
         gos[i].transform.position = new Vector3(gos[i].transform.position.x, gos[i].transform.position.y + 0.2f, gos[i].transform.position.z);
     }
 }
 //	Конструкторы
 public Quad(Vec2int L, Vec2int R)
 {
     this.L     = L;
     this.R     = R;
     Length     = R.x - L.x;
     HalfLength = Length / 2;
 }
    void GeterateMap(Vec2int Left, Vec2int Right)
    {
        //	Инициализация списка массивов квадратов
        List <Quad[]> box = new List <Quad[]> ();

        //	Добавление в список первого квадрата
        box.Add(new Quad[] {
            new Quad(Left, Right)
        });
        //Генерация Diamond-Square
        for (int l = size; l > 0; l /= 2)
        {
            box = GenerateList(ref box);
        }
        //	Запись в текстуру
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                GeneratedTexture.SetPixel(i, j, new Color(map [i, j], map [i, j], map [i, j], 0));
            }
        }
        GeneratedTexture.filterMode = FilterMode.Trilinear;
        GeneratedTexture.Apply();
        box.Clear();
    }
Ejemplo n.º 5
0
 void CollectRessources(Vec2int pos)
 {
     WorldMapData worldData = WorldMapData.instance;
     if(worldData.tiles[pos.x, pos.y].gameObjectList.Count > 0) {
         foreach(GameObject gO in worldData.tiles[pos.x, pos.y].gameObjectList) {
             if(gO.tag == "Ressource") {
                 ResourceManager.instance.ressourcesToDeregister.Add(gO);
                 switch(gO.GetComponent<Ressource>().rType) {
                 case "Food":
                     ResourceManager.instance.ResourceAS("Food", gO.GetComponent<Ressource>().rValue);
                     break;
                 case "Stone":
                     ResourceManager.instance.ResourceAS("Stone", gO.GetComponent<Ressource>().rValue);
                     break;
                 case "Wood":
                     ResourceManager.instance.ResourceAS("Wood", gO.GetComponent<Ressource>().rValue);
                     break;
                 case "Soul":
                     ResourceManager.instance.ResourceAS("Soul", gO.GetComponent<Ressource>().rValue);
                     break;
                 case "default":
                     Debug.Log("Wrong Type");
                     break;
                 }
                 gO.SetActive(false);
             }
         }
     }
 }
    void Start()
    {
        //	Задаем стартовые точки - левый нижний и правый верхний углы
        Vec2int Left  = new Vec2int(0, 0);
        Vec2int Right = new Vec2int(size - 1, size - 1);

        GeterateMap(Left, Right);

        mat.mainTexture = GeneratedTexture;
        mat.SetTexture("_BumpMap", GeneratedTexture);
    }
Ejemplo n.º 7
0
 public void setPosition(Vec2int pos)
 {
     this.pos = pos;
     WorldMapData worlddata = WorldMapData.instance;
     worlddata.tiles[data.pos.x, data.pos.y].mapObjects.Remove(data);
     data.pos = pos;
     worlddata.tiles[data.pos.x, data.pos.y].mapObjects.Add(data);
     CollectRessources(pos);
     FogOfWar.instance.CheckTiles(pos, FogOfWar.instance.visionRange);
     FogOfWar.instance.SetEntitiesToVisible();
     FogOfWar.instance.SetEntitiesToInvisible();
 }
Ejemplo n.º 8
0
 // don't know if that works bc there WAS a yield ._.
 public void followPath(Vec2int[] path, float dur)
 {
     if(moving || path == null) return;
     Messenger.instance.send(new ActionStartedMessage());
     moving = true;
     this.path = path;
     theDur = dur;
     passedTime = 0;
     index = 0;
     lastIndex = 0;
     pathWalkAStep = true;
 }
    public Quad[] Square(Quad box)
    {
        Vec2int Center = new Vec2int(box.R.x - box.HalfLength, box.R.y - box.HalfLength);

        map[Center.x, Center.y] = (map[box.L.x, box.L.y] + map[box.L.x, box.R.y] + map[box.R.x, box.R.y] + map[box.R.x, box.L.y]) / 4 + Random.Range(-box.Length * Roughnees / (size - 1), box.Length * Roughnees / (size - 1));
        return(new Quad[] {
            new Quad(box.L, Center),
            new Quad(Center, box.R),
            new Quad(new Vec2int(box.L.x, box.L.y + box.HalfLength), new Vec2int(box.R.x - box.HalfLength, box.R.y)),
            new Quad(new Vec2int(box.L.x + box.HalfLength, box.L.y), new Vec2int(box.R.x, box.L.y + box.HalfLength))
        });
    }
Ejemplo n.º 10
0
 public void HuntPlayer()
 {
     Vec2int[] path = WorldMapData.instance.findAIPath(moc.pos.x, moc.pos.y, mocOlaf.pos.x, mocOlaf.pos.x, visionRange, true);
     print(path.Length);
     Vec2int[] pathToFollow = new Vec2int[1];
     if(moveTilesPerTurnMax > path.Length)
     {
         pathToFollow = new Vec2int[moveTilesPerTurnMax];
         Array.Copy(path, pathToFollow, moveTilesPerTurnMax);
         print("pathToFollow.Length" + pathToFollow.Length);
     }
     moc.followPath(pathToFollow, 0.25f);
 }
    public void diamond(Quad box)
    {
        float   a, b, c, d;
        Vec2int Center = new Vec2int(box.L.x + box.HalfLength, box.R.y - box.HalfLength);

        Vec2int[] points = new Vec2int[] {
            new Vec2int(Center.x - box.HalfLength, Center.y),           //Left
            new Vec2int(Center.x, Center.y + box.HalfLength),           //Top
            new Vec2int(Center.x + box.HalfLength, Center.y),           //Right
            new Vec2int(Center.x, Center.y - box.HalfLength)            //Bottom
        };
        foreach (Vec2int point in points)
        {
            if (point.y - box.HalfLength >= 0)
            {
                a = map[point.x, point.y - box.HalfLength];
            }
            else
            {
                a = map[point.x, size - 1 - box.HalfLength];
            }
            if (point.x - box.HalfLength >= 0)
            {
                b = map[point.x - box.HalfLength, point.y];
            }
            else
            {
                b = map[size - 1 - box.HalfLength, point.y];
            }
            if (point.y + box.HalfLength < size - 1)
            {
                c = map[point.x, point.y + box.HalfLength];
            }
            else
            {
                c = map[point.x, box.HalfLength];
            }
            if (point.x + box.HalfLength < size - 1)
            {
                d = map[point.x + box.HalfLength, point.y];
            }
            else
            {
                d = map[box.HalfLength, point.y];
            }
            map[point.x, point.y] = (a + b + c + d) / 4 + Random.Range(-box.Length * Roughnees / (size - 1), box.Length * Roughnees / (size - 1));
        }
    }
Ejemplo n.º 12
0
    /*void Update () {
    if(Input.GetKeyDown(KeyCode.L))
        CheckTiles(gameObject.GetComponent.<MapObjectCarrier>().pos, visionRange);
    if(Input.GetKeyDown(KeyCode.K))
        SetEntitiesToVisible();
    if(Input.GetKeyDown(KeyCode.J))
        SetEntitiesToInvisible();
    }*/
    public void CheckTiles(Vec2int origin, int radius)
    {
        ClearLists();
        WorldMapData worldData = WorldMapData.instance;

        var hexCenter = worldData.tiles[origin.x, origin.y];
        adjacentTemp.Add(hexCenter);
        adjacent.Add(hexCenter);

        for(var i = 0; i <= radius; i++) {
            for(var l = 0; l < 6 * radius; l++) {
                adjacentTemp = adjacent[l].getAdjacent().ToList();
                foreach(Hexagon hex in adjacentTemp) {
                    if(!adjacent.Contains(hex))
                        adjacent.Add(hex);
                }
            }
        }
        adjacent = Enumerable.ToList(Enumerable.Distinct(adjacent));
        AddEnemysInRangeToList();
        AddRessourcesInRangeToList();
    }
Ejemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        if (sSize == null)
            return;
        switch ((int)sSize.value) {
            case 0:
                size = new Vec2int(64, 64);
                break;
            case 1:
                size = new Vec2int(96, 96);
                break;
            case 2:
                size = new Vec2int(128, 128);
                break;
        }
        temperature = sTemperature.value;
        altitude = sAltitude.value;
        humidity = sHumidity.value;

        winBuilder = tWinBuilder.isOn;
        winGlory = tWinGlory.isOn;
    }
Ejemplo n.º 14
0
 void redraw(Vec2int goal)
 {
     MapObjectCarrier target = InterfaceData.instance.selectedCarrier;
     if(!target) return;
     updatePath(WorldMapData.instance.findPath(target.pos.x, target.pos.y, goal.x, goal.y, target.movedMax - target.moved, false));
 }
Ejemplo n.º 15
0
 public MouseTileChangedMessage(Vec2int tile, Vector3 tilePos, Vector3 worldPos)
 {
     super("MouseTileChanged");
     this.tile = tile;
     this.tilePos = tilePos;
     this.worldPos = worldPos;
 }
Ejemplo n.º 16
0
 void finalizeAt(int index, Vec2int[] path, bool suspended)
 {
     Vector3 end = WorldMapData.instance.tiles[path[index].x, path[index].y].position;
     gameObject.transform.position = new Vector3(end.x, gameObject.transform.position.y, end.z);
     setPosition(path[index]);
     moving = false;
     suspend = false;
     Messenger.instance.send(new ActionEndedMessage(""));
     if(!suspended){
         moved++;
         Messenger.instance.send(new MapObjectMovedMessage(data, path[index-1]));
     }
 }
Ejemplo n.º 17
0
 public MapObjectMovedMessage(MapObjectData objData, Vec2int lastTile)
 {
     super("MapObjectMoved");
     this.objData = objData;
     this.lastTile = lastTile;
 }