Beispiel #1
0
    private int numTilesHigh;           // how many tiles high in a quadrant


    // Initialization
    // = = = = = = = = = = = = = = = = = = = = >
    void Awake()
    {
        // Establish Singleton
        if (Master == null)
        {
            Master = this;
        }
        else
        {
            if (Master != this)
            {
                Destroy(this.gameObject);
            }
        }

        // Setup all starter variables
        numQuadWide  = 3;
        numQuadHigh  = 3;
        QuadWidth    = 10.0f;
        QuadHeight   = 10.0f;
        numTilesWide = 16;
        numTilesHigh = 16;

        // Build a new map data
        Map = new mapData(numTilesWide * numQuadWide, numTilesHigh * numQuadHigh);
        BuildDefaultShip();

        BuildMap();
    }
        public InstallMapOfflineDialogue(mapData editmap, string mapname = "")
        {
            InitializeComponent();

            if (editmap.image_radar != null) //If the map file already exists
            {
                insmap = editmap;

                target_displayimage.Source = editmap.image_radar.toBitMapImage();

                input_offset_x.Value = editmap.radar.pos_x;
                input_offset_y.Value = editmap.radar.pos_y;
                input_radar_scale.Value = (decimal)editmap.radar.scale;

                this.Title = "Editing " + mapname;
            }
            else //If it doesn't
            {
                this.Title = "Setting up new map";
            }

            if (mapname != "")
            {
                input_mapname.Text = mapname; //Should usually receive a stripped filename
                input_mapname.IsEnabled = false; //Disable the mapname box so it doest break
            }

        }
Beispiel #3
0
    /*private void Awake()
     * {
     *  instance = this;
     * }*/

    public void saveMap(mapData mData)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.dataPath + "/mapData/" + mData.mName + ".dat");

        bf.Serialize(file, mData);
    }
    public void initiate()
    {
        poolmanager.instance.initiate();
        elementaryAffection.instance.initiate();

        if (_map == null)
        {
            _map = new GameObject("(" + mapSize + "x" + mapSize + ") map");
            mapData      data      = _map.AddComponent <mapData>();
            mapGfx       gfx       = _map.AddComponent <mapGfx>();
            mapGenerator generator = _map.AddComponent <mapGenerator>();

            List <string> layerNames = new List <string>()
            {
                "ground", "path", "decoration", "tower"
            };

            data.mapSize = mapSize;
            data.layers  = layerNames;
            data.initiate();

            layerNames.Add("waypoint");

            gfx.prefixIdentifier = new List <string>()
            {
                "basis",
                "ground",
                "spawn",
                "bottomLeftPath",
                "bottomRightPath",
                "horizontalPath",
                "upperLeftPath",
                "upperRightPath",
                "verticalPath"
            };

            gfx.initiate(layerNames);

            generator.buildBoardFoundation(data, gfx);
            generator.buildRandomBoard(data, gfx);

            gfx.instantiateBoard(data.getBoard(), data.mapSize);

            createWavesystem(generator.startWaypoint);
        }
        else
        {
            Destroy(_map);
            _map = null;

            Destroy(_wavesystem);
            _wavesystem = null;

            elementaryAffection.instance.reset();

            initiate();
        }
    }
Beispiel #5
0
    public void buildBoardFoundationOnLayer(mapData mapData, mapGfx mapGfx, string layerName)
    {
        if (mapData == null || mapGfx == null)
        {
            if (gamemanager.instance.debug)
            {
                Debug.LogWarning("(mapGenerator:buildBoardFoundation) Could not build foundation because the mapData/Gfx is a nullptr.");
            }

            return;
        }

        for (int positionX = 0; positionX < mapData.mapSize; ++positionX)
        {
            for (int positionY = 0; positionY < mapData.mapSize; ++positionY)
            {
                switch (layerName)
                {
                case "ground":
                    rangeHelper range = mapGfx.getPrefixedObjectRange("ground");
                    if (range != null)
                    {
                        mapData.setTileOnLayer(positionX, positionY, layerName, Random.Range(range.begin, range.end + 1));
                    }
                    else
                    {
                        if (gamemanager.instance.debug)
                        {
                            Debug.LogError("(mapGenerator:buildBoardFoundation) Ground ID range is null.");
                        }
                        mapData.setTileOnLayer(positionX, positionY, layerName, 0);
                    }
                    break;

                case "path":
                    if (positionX == 0 || positionY == 0 || positionY == mapData.mapSize - 1 || positionX == mapData.mapSize - 1)
                    {
                        mapData.setTileOnLayer(positionX, positionY, layerName, 1);
                    }
                    else
                    {
                        mapData.setTileOnLayer(positionX, positionY, layerName, 0);
                    }
                    break;

                case "waypoint":
                    break;

                default:
                    mapData.setTileOnLayer(positionX, positionY, layerName, 0);
                    break;
                }
            }
        }
    }
    public void SaveData()
    {
        mapData md = new mapData();

        GameObject[] gbPaths  = GameObject.FindGameObjectsWithTag("path");
        GameObject[] gbPlaces = GameObject.FindGameObjectsWithTag("place");
        GameObject[] gbtags   = GameObject.FindGameObjectsWithTag("product");

        md.noOfPaths  = gbPaths.Length;
        md.noOfPlaces = gbPlaces.Length;
        md.noOftags   = gbtags.Length;
        foreach (GameObject gb in gbPaths)
        {
            paths p = new paths();

            p.name              = gb.name;
            p.position          = gb.transform.position;
            p.noOfPositions     = gb.GetComponent <LineRenderer>().positionCount;
            p.lineRendPositions = new Vector3[p.noOfPositions];

            gb.GetComponent <LineRenderer>().GetPositions(p.lineRendPositions);

            md.pathsList.Add(p);
        }

        foreach (GameObject gb in gbPlaces)
        {
            places p = new places();

            p.name     = gb.name;
            p.position = gb.transform.position;

            md.placesList.Add(p);
        }
        foreach (GameObject gb in gbtags)
        {
            tags p = new tags();

            p.name     = gb.name;
            p.position = gb.transform.position;

            md.tagsList.Add(p);
        }

        //xml saving script

        XmlSerializer serializer = new XmlSerializer(typeof(mapData));
        FileStream    stream     = new FileStream(Application.persistentDataPath + "/mapdata.xml", FileMode.Create);

        serializer.Serialize(stream, md);
        Debug.Log("File created");
        stream.Close();

        DataManagerCreator.ins.UploadeFile();
    }
Beispiel #7
0
    public mapData getMap(string mapName, string dataPath)
    {
        BinaryFormatter bf = new BinaryFormatter();
        //FileStream file = File.Open(Application.dataPath + "/mapData/" + mapName + ".dat", FileMode.Open);
        //Debug.Log("Data path: " + dataPath);
        FileStream file = File.Open(dataPath + "/mapData/" + mapName + ".dat", FileMode.Open);
        mapData    temp = (mapData)bf.Deserialize(file);

        file.Close();
        return(temp);
    }
Beispiel #8
0
        public void Create(mapData md)
        {
            if (m_build == null)
            {
                m_build = new GameObject();
            }
            m_build.name = "buildMap";

            m_buildManager = new BuildManager(m_build, m_giList, m_gtdList);

            drawFloor(md.srcMap);
            drawLine(md.srcRaw, md.srcCol);
            drawHouse();
        }
Beispiel #9
0
    IEnumerator saveMap()
    {
        int walkable    = 0;
        int nonWalkable = 0;

        Debug.Log("Saving map");
        //UnityEngine.Debug.Log("Nodes: " + nodes.Length);
        mapData mData = new mapData();

        nodeData[,] data = new nodeData[(int)(xSize * (1 / length)), (int)(zSize * (1 / length))];
        for (int i = 0; i < (xSize * (1 / length)); i++)
        {
            for (int j = 0; j < (zSize * (1 / length)); j++)
            {
                nodeData n = new nodeData();
                if (nodes[i, j].walkable)
                {
                    walkable++;
                }
                else
                {
                    nonWalkable++;
                }
                n.populate(nodes[i, j]);
                data[i, j] = n;
            }
            yield return(null);
        }
        mData.mName      = mapName;
        mData.mapNodes   = data;
        mData.xSize      = xSize;
        mData.zSize      = zSize;
        mData.nodeLength = length;

        //DataSaver.instance.saveMap(mData);
        if (File.Exists(dataPath + "/mapData/" + mData.mName + ".dat"))
        {
            File.Delete(dataPath + "/mapData/" + mData.mName + ".dat");
            Debug.Log("Deleted file");
        }
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(dataPath + "/mapData/" + mData.mName + ".dat");

        bf.Serialize(file, mData);
        file.Close();

        //Debug.Log("Walkable: " + walkable + ", non walkable: " + nonWalkable);
        mapIsReady = true;
        //Debug.Log("Finished making and saving map");
    }
Beispiel #10
0
        public SavedMapControl(mapData mapdat, string mapname)
        {
            InitializeComponent();

            dat  = mapdat;
            name = mapname;

            //Sets all the params respectively
            target_mapname.Header      = mapname;
            target_offset_x.Content    = "Offset X: " + mapdat.radar.pos_x;
            target_offset_y.Content    = "Offset Y: " + mapdat.radar.pos_y;
            target_scale.Content       = "Radar Scale: " + mapdat.radar.scale;
            target_radarpreview.Source = mapdat.image_radar.toBitMapImage();
        }
    void initData(mapData md)
    {
        if (md.GTDList.Count == 0)
        {
            List <GoodsTempData> gtdList = MapBasicData.ReadHouseData();
            for (int i = 0; i < gtdList.Count; i++)
            {
                md.GTDList.Add(gtdList[i]);
            }
        }

        if (md.m_ftList.Count == 0)
        {
            MapBasicData.ReadFloorFile(md.m_ftList);
        }
    }
Beispiel #12
0
    private bool isPossiblePath(int positionX, int positionY, int direction, mapData data)
    {
        if (data.getTileOnLayer(positionX, positionY, "path") == 1 || data.getTileOnLayer(positionX, positionY, "path") == 2)
        {
            return(false);
        }
        /**/
        if (direction == 0 || direction == 1)
        {
            if (data.getTileOnLayer(positionX - 1, positionY, "path") == 2 ||
                data.getTileOnLayer(positionX + 1, positionY, "path") == 2)
            {
                return(false);
            }

            if (direction == 0 && data.getTileOnLayer(positionX, positionY + 1, "path") == 2)
            {
                return(false);
            }

            if (direction == 1 && data.getTileOnLayer(positionX, positionY - 1, "path") == 2)
            {
                return(false);
            }
        }

        if (direction == 2 || direction == 3)
        {
            if (data.getTileOnLayer(positionX, positionY - 1, "path") == 2 ||
                data.getTileOnLayer(positionX, positionY + 1, "path") == 2)
            {
                return(false);
            }

            if (direction == 2 && data.getTileOnLayer(positionX + 1, positionY, "path") == 2)
            {
                return(false);
            }

            if (direction == 3 && data.getTileOnLayer(positionX - 1, positionY, "path") == 2)
            {
                return(false);
            }
        }

        return(true);
    }
Beispiel #13
0
        /// <summary>
        /// This method handles all the sequencing required to generate data from the mapData file
        /// </summary>
        /// <param name="mapfile">The mapfile to process</param>
        static void doProcessing(mapData mapfile, DemoParser parser)
        {
            Debug.Success("Starting processing");

            //First step: Make a grey dark version of the radar.
            Bitmap backgroundRadar = bitmapfilters.brightness(bitmapfilters.greyScaleAverage(mapfile.image_radar), 0.3f);

            //Second step: Load the demo into a demodatainstance, so that it parses into different lists.
            demodatainstance demo = new demodatainstance(parser);

            //Third step: Start making heatmaps
            densitymap density_shotsfired = new densitymap();

            //Legacy, Make the camera object
            camera cam = new camera();

            cam.offset = new vector2(mapfile.radar.pos_x, mapfile.radar.pos_y);
            cam.scale  = mapfile.radar.scale;


            foreach (p_Player plyr in demo.players.Values.ToList())
            {
                foreach (p_Round rnd in plyr.rounds)
                {
                    foreach (vector3 shot in rnd.shotsFired)
                    {
                        vector2 screenPos = transforms.worldToScreenSpace(shot, cam);
                        density_shotsfired.createHeatMapSplodge((int)screenPos.x, (int)screenPos.y, 20);
                    }
                }
            }

            density_shotsfired.averageBlur3x3();
            density_shotsfired.normalise(0.4f);

            Bitmap output = density_shotsfired.toBitMap();

            output = gradients.fire.applyToImage(output);

            output = bitmapfilters.alphaOver(backgroundRadar, output);

            output.Save("test_shotsfired.png");
        }
    public List <mapData> ReadMapData()
    {
        mapdata = new List <mapData>();
        //读取csv二进制文件
        TextAsset binAsset = Resources.Load("地图", typeof(TextAsset)) as TextAsset;

        //读取每一行的内容
        string[] lineArray = binAsset.text.Split("\r"[0]);
        Debug.Log(lineArray.Length + "长度");
        for (int i = 1; i < lineArray.Length - 1; i++)
        {
            string[] lineArray1 = lineArray[i].Split(","[0]);
            mapData  tempData   = new mapData();
            tempData.ID           = int.Parse(lineArray1[0]);
            tempData.mapName      = lineArray1[1];
            tempData.mixLev       = int.Parse(lineArray1[2]);
            tempData.mixMonsterID = int.Parse(lineArray1[3]);
            tempData.maxMonsterID = int.Parse(lineArray1[4]);
            mapdata.Add(tempData);
        }
        return(mapdata);
    }
Beispiel #15
0
    public void saveMap(Node[,] nodes, string mapName, int length, int xSize, int zSize)
    {
        mapData mData = new mapData();

        nodeData[,] nData = new nodeData[nodes.GetLength(0), nodes.GetLength(nodes.Rank - 1)];
        Debug.Log("Rank: " + (nodes.Rank - 1));

        for (int i = 0; i < nodes.GetLength(0); i++)
        {
            for (int j = 0; j < nodes.GetLength(nodes.Rank - 1); j++)
            {
                nodeData n = new nodeData();
                n.populate(nodes[i, j]);
                nData[i, j] = n;
            }
        }
        mData.mName      = mapName;
        mData.mapNodes   = nData;
        mData.xSize      = xSize;
        mData.zSize      = zSize;
        mData.nodeLength = length;
        saveMap(mData);
    }
Beispiel #16
0
    public void buildRandomBoard(mapData mapData, mapGfx mapGfx)
    {
        int pathBuildTryCount = 1;

        do
        {
            if (gamemanager.instance.debug)
            {
                Debug.LogWarning("(mapGenerator:buildRandomBoard) " + pathBuildTryCount + ". try to build path.");
            }

            buildBoardFoundationOnLayer(mapData, mapGfx, "path");
            buildBoardFoundationOnLayer(mapData, mapGfx, "tower");
            initiate(mapData.mapSize, _pathLengthReduktion);

            mapData.setTileOnLayer(_baseX, _baseY, "path", 2);

            ++pathBuildTryCount;
            _pathLengthReduktion += 5;
        }while (!buildPath(_baseX, _baseY, 1, -1, mapData));

        setupBuiltPath(mapData, mapGfx);
    }
Beispiel #17
0
    private void loadMap()
    {
        print("Starting load map");
        mapData mData = DataSaver.instance.getMap(mapName, dataPath);

        print("Read in mData");

        length = mData.nodeLength;
        xSize  = mData.xSize;
        zSize  = mData.zSize;

        maxNodes = (xSize * (1 / length)) * (zSize * (1 / length));

        nodes = new Node[(int)(xSize * (1 / length)), (int)(zSize * (1 / length))];
        for (int i = 0; i < xSize * (1 / length); i++)
        {
            for (int j = 0; j < zSize * (1 / length); j++)
            {
                createdNodes++;
                nodes[i, j] = new Node(mData.mapNodes[i, j]);
            }
        }
        mapIsReady = true;
    }
Beispiel #18
0
    void loadMap()
    {
        //Debug.Log("Load map");
        mapData mData = DataSaver.instance.getMap(mapName, dataPath);

        length = mData.nodeLength;
        xSize  = mData.xSize;
        zSize  = mData.zSize;

        totalNodes   = xSize * (1 / length) * (zSize * (1 / length));
        createdNodes = 0;

        nodes = new Node[(int)(xSize * (1 / length)), (int)(zSize * (1 / length))];
        for (int i = 0; i < xSize * (1 / length); i++)
        {
            for (int j = 0; j < zSize * (1 / length); j++)
            {
                createdNodes++;
                nodes[i, j] = new Node(mData.mapNodes[i, j]);
            }
        }
        mapIsReady = true;
        //Debug.Log("Nodes: " + nodes.Length);
    }
Beispiel #19
0
	// For folder to show up
	public void Save(String saveName)
	{
		BinaryFormatter bf = new BinaryFormatter();
		FileStream file = File.Create(Application.dataPath + "/SavedGames/" + saveName + ".dat");
		
		mapArray mData = new mapArray();
		
		for (int i = 0; i < GridSize.x; i++)
		{
			for (int j = 0; j < GridSize.y; j++)
			{
				mapData data = new mapData();
				
				Transform tile = GridArray[i, j];
				Tile t = tile.GetComponent<Tile>();
				Color col = tile.GetComponent<Renderer>().material.color;
				if (col == Color.gray)
					data.color = 0;
				else if (col == Color.blue)
					data.color = 1;
				else if (col == Color.green)
					data.color = 2;
				else if (col == Color.yellow)
					data.color = 3;
				else if (col == Color.red)
					data.color = 4;
				
				data.HasHovel = t.HasHovel;
				data.HasTown = t.HasTown;
				data.HasFort = t.HasFort;
				data.HasCastle = t.HasCastle;
				data.HasTree = t.HasTree;
				data.HasMeadow = t.HasMeadow;
				data.HasTomb = t.HasTomb;
				data.HasRoad = t.HasRoad;
				data.HasPeasant = t.HasPeasant;
				data.HasInfantry = t.HasInfantry;
				data.HasSoldier = t.HasSoldier;
				data.HasKnight = t.HasKnight;
				data.HasCannon = t.HasCannon;
				data.HasWatchTower = t.HasWatchTower;
				data.HasVillage = t.HasVillage;
				data.HasUnit = t.HasUnit;
				data.IsEmpty = t.IsEmpty;
				
				if (t.HasVillage)
				{
					data.gold = t.Village.GetComponent<Village>().Gold;
					data.wood = t.Village.GetComponent<Village>().Wood;
					data.shots = t.Village.GetComponent<Village>().CannonballShotsTaken;
				}
				
				mData.mArray[i, j] = data;
				
			}
		}
		
		bf.Serialize(file, mData);
		file.Close();
	}
Beispiel #20
0
    public void MapToDistance()
    {
        dataBase = new Dictionary <string, mapData>();
        if (File.Exists(fullPath + "distance.txt"))
        {
            File.Delete(fullPath + "distance.txt");
        }
        if (File.Exists(fullPath + "nearistNode.txt"))
        {
            File.Delete(fullPath + "nearistNode.txt");
        }
        curlongitude = GPS.Instance.longitude;
        curlatitude  = GPS.Instance.latitude;
        //curlongitude = 120.267313f;
        //curlatitude = 22.627271f;

        //讀取map.txt存放入dataBase
        using (StreamReader sreader = new StreamReader(fullPath + "map.txt", Encoding.UTF8)) {
            string[] lineSplite;
            string   line;
            while ((line = sreader.ReadLine()) != null)
            {
                if (line == "")
                {
                    break;
                }

                lineSplite = line.Split(' ');
                mapData temp = new mapData();
                temp.nodeLat  = lineSplite[1];
                temp.nodeLong = lineSplite[2];
                for (int i = 3; i < lineSplite.Length; ++i)
                {
                    temp.canGoTo.Add(lineSplite[i]);
                }
                dataBase.Add(lineSplite[0], temp);
            }
            sreader.Close();
        }
        float  shortest    = 1000000000;
        string nearestNode = "NodeNotFound";

        foreach (KeyValuePair <string, mapData> temp in dataBase)
        {
            float tempDis = Calc(curlatitude, curlongitude, float.Parse(temp.Value.nodeLat), float.Parse(temp.Value.nodeLong));
            nearestNode = (shortest > tempDis) ? temp.Key : nearestNode;
            shortest    = (shortest > tempDis) ? tempDis : shortest;

            if (temp.Value.canGoTo.Count > 0)
            {
                using (StreamWriter swriter = new StreamWriter(fullPath + "distance.txt", true, Encoding.UTF8))
                {
                    foreach (string arrivable in temp.Value.canGoTo)
                    {
                        //swriter.Write(dataBase[temp.Key].nodeLat + " " + dataBase[temp.Key].nodeLong + " " + dataBase[arrivable].nodeLat.ToString() + " " + dataBase[arrivable].nodeLong.ToString() + Environment.NewLine);
                        swriter.Write(temp.Key + " " + arrivable + " " + Calc(float.Parse(dataBase[temp.Key].nodeLat), float.Parse(dataBase[temp.Key].nodeLong), float.Parse(dataBase[arrivable].nodeLat), float.Parse(dataBase[arrivable].nodeLong)) + Environment.NewLine);
                    }
                    swriter.Close();
                }
            }
        }
        using (StreamWriter swriter = new StreamWriter(fullPath + "nearistNode.txt", true, Encoding.UTF8)) {
            swriter.Write("目前位置 " + nearestNode + " " + shortest + Environment.NewLine);
            swriter.Close();
        }
    }
Beispiel #21
0
    void Update()
    {
        Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (mousePosition.x < -0.5f || mousePosition.y < -0.5f)
        {
            mousePosition.x = -2;
            mousePosition.y = -2;
        }

        int mousePositionX = (int)(mousePosition.x + 0.5f);
        int mousePositionY = (int)(mousePosition.y + 0.5f);

        mapData mapData = gamemanager.instance.mapData;
        mapGfx  mapGfx  = gamemanager.instance.mapGfx;

        if (mapData == null || mapGfx == null)
        {
            return;
        }

        int tileOnMousePosition = mapData.getTileOnLayer(mousePositionX, mousePositionY, "tower");

        if (_buildTower == true && tileOnMousePosition != -1 && tileOnMousePosition != 1)
        {
            _mouseOverObject.SetActive(true);
            _mouseOverObject.transform.position = new Vector2(mousePositionX, mousePositionY);

            if (Input.GetMouseButtonDown(0) && _towers.ContainsKey(_towerTag))
            {
                mapData.setTileOnLayer(mousePositionX, mousePositionY, "tower", 1);
                GameObject newTower = Instantiate(_towers[_towerTag], new Vector2(mousePositionX, mousePositionY), Quaternion.identity) as GameObject;
                mapGfx.addGameObject(newTower, "tower");

                switch (_towerTag)
                {
                case "waterTower":
                    elementaryAffection.instance.waterLevel++;
                    break;

                case "fireTower":
                    elementaryAffection.instance.fireLevel++;
                    break;

                case "airTower":
                    elementaryAffection.instance.airLevel++;
                    break;

                case "earthTower":
                    elementaryAffection.instance.earthLevel++;
                    break;
                }

                elementaryAffection.instance.updateOnChange();
            }
        }
        else
        {
            _mouseOverObject.SetActive(false);
        }

        if (Input.GetMouseButtonDown(1))
        {
            _buildTower = false;
        }
    }
Beispiel #22
0
    /*(random generation)path functions*/
    private bool buildPath(int positionX, int positionY, int pathLength, int oppositeDirection, mapData mapData)
    {
        randomHelper directionRandomness = new randomHelper();

        /*Initialise all possible direction for the next path tile.*/
        /*Sort out the opposite direction of the previous pathtile to reduce unnecessary checks.*/
        directionRandomness.setupValues(new List <int>()
        {
            0, 1, 2, 3
        });
        directionRandomness.sortoutRandomValue(oppositeDirection);

        /*While there is still a possible direction to check.*/
        while (!directionRandomness.isEmpty())
        {
            /*Get a random direction.*/
            int direction = directionRandomness.getRandom();

            /*Set the next tile position to the previous one.*/
            int nextPositionX = positionX;
            int nextPositionY = positionY;

            /*Calculate the opposite direction and the next tile position with the set random direction
             *           - no diagonal moves possible.*/
            switch (direction)
            {
            case 0:
                oppositeDirection = 1;
                ++nextPositionY;
                break;

            case 1:
                oppositeDirection = 0;
                --nextPositionY;
                break;

            case 2:
                oppositeDirection = 3;
                ++nextPositionX;
                break;

            case 3:
                oppositeDirection = 2;
                --nextPositionX;
                break;

            default:
                return(false);
            }

            /*Is the next tile not a possible path...*/
            if (!isPossiblePath(nextPositionX, nextPositionY, direction, mapData))
            {
                /*The random direction will be sorted out of the possible directions.*/
                directionRandomness.sortoutRandomValue(direction);

                /*New try with a new direction.*/
                continue;
            }

            /*Is the current path length equal to the target pathlength...*/
            if (pathLength == _targetPathLength)
            {
                /*Create a spawn.*/
                mapData.setTileOnLayer(nextPositionX, nextPositionY, "path", 2);

                /*Set spawn position.*/
                _spawnX = nextPositionX;
                _spawnY = nextPositionY;

                /*Set the pathlength.*/
                //_actualPathLength = _targetPathLength;

                /*Reset the target pathlength back to the maximum path length.*/
                _targetPathLength = _maxPathLength;

                _pathList.Add(new path(direction, nextPositionX, nextPositionY));

                return(true);
            }

            /*If it is a possible path create a path tile on that position.*/
            mapData.setTileOnLayer(nextPositionX, nextPositionY, "path", 2);

            /*If the path generation finds a valid path it returns true.*/
            if (buildPath(nextPositionX, nextPositionY, pathLength + 1, oppositeDirection, mapData))
            {
                _pathList.Add(new path(direction, nextPositionX, nextPositionY));

                return(true);
            }
            else
            {
                /*If somewhere the path generation got stucked - the path generation will go back to
                 * the previous tile and tries out another direction till he found a valid way. The direction
                 * that does not work will be sorted out and the path tile that has been created will be destroyed
                 * and a wall will be placed there to symbolize the path generation there is no way in that direction.*/
                directionRandomness.sortoutRandomValue(direction);
                mapData.setTileOnLayer(nextPositionX, nextPositionY, "path", 1);
            }
        }

        /*If all possible direction do not include a possible path the target path length will be reduced
         * - to avoid that the path generation gets stucked but it will never go lower than the minimum pathlength
         * to generate maps that are worth playing.*/
        if (_targetPathLength > _minPathLength)
        {
            _targetPathLength--;
        }

        return(false);
    }
Beispiel #23
0
    private void setupBuiltPath(mapData mapData, mapGfx mapGfx)
    {
        triggerWaypoint lastWaypoint  = null;
        int             waypointCount = 0;

        mapData.setTileOnLayer(_spawnX, _spawnY, "path", mapGfx.getPrefixedObjectRange("spawn").getRandom());
        mapData.setTileOnLayer(_baseX, _baseY, "path", mapGfx.getPrefixedObjectRange("basis").getRandom());

        lastWaypoint = createWaypoint(_baseX, _baseY, mapGfx, lastWaypoint, waypointCount++);

        mapData.setTileOnLayer(_baseX, _baseY, "tower", 1);

        for (int pathtileIndex = _pathList.Count - 1; pathtileIndex >= 1; pathtileIndex--)
        {
            int positionX        = _pathList[pathtileIndex].positionX;
            int positionY        = _pathList[pathtileIndex].positionY;
            int currentDirection = _pathList[pathtileIndex].direction;
            int nextDirection    = _pathList[pathtileIndex - 1].direction;

            if (gamemanager.instance.debug)
            {
                Debug.Log("(mapGenerator:setupBuiltPath) Pathtile on " + positionX + "|" + positionY + ".");
            }

            if (currentDirection != nextDirection)
            {
                if ((currentDirection == 0 && nextDirection == 2) || (currentDirection == 3 && nextDirection == 1))
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("upperLeftPath").getRandom());
                }
                else if ((currentDirection == 1 && nextDirection == 2) || (currentDirection == 3 && nextDirection == 0))
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("bottomLeftPath").getRandom());
                }
                else if ((currentDirection == 0 && nextDirection == 3) || (currentDirection == 2 && nextDirection == 1))
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("upperRightPath").getRandom());
                }
                else if ((currentDirection == 1 && nextDirection == 3) || (currentDirection == 2 && nextDirection == 0))
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("bottomRightPath").getRandom());
                }

                lastWaypoint = createWaypoint(positionX, positionY, mapGfx, lastWaypoint, waypointCount++);
            }
            else
            {
                if (currentDirection == 0 || currentDirection == 1)
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("verticalPath").getRandom());
                }
                else if (currentDirection == 2 || currentDirection == 3)
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("horizontalPath").getRandom());
                }
            }

            mapData.setTileOnLayer(positionX, positionY, "tower", 1);
        }

        lastWaypoint   = createWaypoint(_spawnX, _spawnY, mapGfx, lastWaypoint, waypointCount++);
        _startWaypoint = lastWaypoint;

        mapData.setTileOnLayer(_spawnX, _spawnY, "tower", 1);
    }
Beispiel #24
0
    IEnumerator setUpMap()
    {
        if (DataSaver.instance.mapExists(mapName) && !makeNewMap)
        {
            CreateMap create = new CreateMap(false, length, xSize, zSize, mapName);
            while (create.totalNodes == 0)
            {
                yield return(null);
            }
            //Debug.Log("Total nodes: " + create.totalNodes);
            //Debug.Log("Created nodes: " + create.createdNodes);
            while (!create.mapIsReady)
            {
                CameraUI.instance.progressText.text = create.createdNodes + "/" + create.totalNodes;
                CameraUI.instance.progressBar.value = create.createdNodes / create.totalNodes;
                yield return(null);
            }
            CameraUI.instance.progressText.text = create.createdNodes + "/" + create.totalNodes;
            CameraUI.instance.progressBar.value = create.createdNodes / create.totalNodes;

            nodes = create.nodes;
            xSize = create.xSize;
            zSize = create.zSize;
            //print("Node count: " + nodes.Length);

            GameObject g = Instantiate((GameObject)Resources.Load(mapName));
            g.transform.position = new Vector3(xSize / 2, 0, zSize / 2);

            g = Instantiate(nodeMarker);
            g.transform.position   = nodes[0, 0].position;
            g.transform.localScale = vLength;

            g = Instantiate(nodeMarker2);
            g.transform.position   = nodes[0, nodes.GetLength(0) - 1].position;
            g.transform.localScale = vLength;

            g = Instantiate(nodeMarker3);
            g.transform.position   = nodes[nodes.GetLength(0) - 1, 0].position;
            g.transform.localScale = vLength;

            g = Instantiate(nodeMarker2);
            g.transform.position   = nodes[nodes.GetLength(0) - 1, nodes.GetLength(nodes.Rank - 1) - 1].position;
            g.transform.localScale = vLength;

            print("Finished loading map");
            mapIsReady = true;
        }
        else
        {
            print("Making new map");
            //print("Length: " + length + ", x size: " + xSize + ", Z size: " + zSize);
            if (xSize == 0 || zSize == 0)
            {
                xSize = 2000;
                zSize = 2000;
            }
            CreateMap m = new CreateMap(makeNewMap, length, xSize, zSize, mapName);
            while (m.totalNodes == 0)
            {
                yield return(null);
            }
            while (!m.mapIsReady)
            {
                CameraUI.instance.progressText.text = m.touchedNodes + "/" + m.totalNodes;
                CameraUI.instance.progressBar.value = m.touchedNodes / m.totalNodes;
                yield return(null);
            }
            CameraUI.instance.progressText.text = m.touchedNodes + "/" + m.totalNodes;
            CameraUI.instance.progressBar.value = m.touchedNodes / m.totalNodes;
            nodes = m.nodes;
            //print("Node count: " + nodes.Length);

            GameObject g = Instantiate(nodeMarker);
            g.transform.position   = nodes[0, 0].position;
            g.transform.localScale = vLength;

            g = Instantiate(nodeMarker2);
            g.transform.position   = nodes[0, nodes.GetLength(0) - 1].position;
            g.transform.localScale = vLength;

            g = Instantiate(nodeMarker3);
            g.transform.position   = nodes[nodes.GetLength(0) - 1, 0].position;
            g.transform.localScale = vLength;

            g = Instantiate(nodeMarker2);
            g.transform.position   = nodes[nodes.GetLength(0) - 1, nodes.GetLength(nodes.Rank - 1) - 1].position;
            g.transform.localScale = vLength;


            //Save map
            mapData mData = new mapData();
            nodeData[,] data = new nodeData[(int)(xSize * (1 / length)), (int)(zSize * (1 / length))];
            for (int i = 0; i < (xSize * (1 / length)); i++)
            {
                for (int j = 0; j < (zSize * (1 / length)); j++)
                {
                    nodeData n = new nodeData();
                    n.populate(nodes[i, j]);
                    data[i, j] = n;
                }
                yield return(null);
            }
            mData.mName      = mapName;
            mData.mapNodes   = data;
            mData.xSize      = xSize;
            mData.zSize      = zSize;
            mData.nodeLength = length;

            //DataSaver.instance.saveMap(mData);

            mapIsReady = true;
            print("Finished making and saving map");
        }
    }
        private void btn_Generate_Click(object sender, RoutedEventArgs e)
        {
            mapData mapfile = demoreading.loadMapFromDisk(refInstance.info.mapname);
            //First step: Make a grey dark version of the radar.
            Bitmap backgroundRadar = bitmapfilters.brightness(bitmapfilters.greyScaleAverage(mapfile.image_radar), 0.3f);
            Bitmap outputImage     = backgroundRadar;

            //Third step: Start making heatmaps
            densitymap density_shotsfired = new densitymap();

            //Legacy, Make the camera object
            camera cam = new camera();

            cam.offset = new vector2(mapfile.radar.pos_x, mapfile.radar.pos_y);
            cam.scale  = mapfile.radar.scale;

            #region shotsfired
            if (toggle_shotsfired.IsChecked.Value)
            {
                foreach (p_Player plyr in refInstance.players.Values.ToList())
                {
                    if (enabledSteamIDS[plyr.steamID]) //Check if that player was enabled
                    {
                        foreach (p_Round rnd in plyr.rounds)
                        {
                            foreach (vector3 shot in rnd.shotsFired)
                            {
                                vector2 screenPos = transforms.worldToScreenSpace(shot, cam);
                                density_shotsfired.createHeatMapSplodgeAccelerated((int)screenPos.x, (int)screenPos.y, (int)val_dialation_slider.Value);
                            }
                        }
                    }
                }


                //If blur is enabled, use the 3x3 blur filter
                if (toggle_blur.IsChecked.Value)
                {
                    density_shotsfired.averageBlur3x3();
                }


                density_shotsfired.normalise((float)val_samplemidpoint_slider.Value / (float)val_samplemidpoint_slider.Maximum);

                Bitmap output = density_shotsfired.toBitMap();
                output = gradients.fire.applyToImage(output);

                outputImage = bitmapfilters.alphaOver(backgroundRadar, output);
            }
            #endregion

            #region playerpaths
            //If draw player paths is enabled
            if (toggle_playerpaths.IsChecked.Value)
            {
                Pen CTpen = new Pen(Color.FromArgb(32, 242, 139, 4), 1);
                Pen Tpen  = new Pen(Color.FromArgb(32, 50, 178, 201), 1);


                foreach (p_Player plyr in refInstance.players.Values.ToList())
                {
                    if (enabledSteamIDS[plyr.steamID])
                    {
                        foreach (p_Round rnd in plyr.rounds)
                        {
                            using (var graphics = Graphics.FromImage(outputImage))
                            {
                                Pen pen;
                                if (rnd.teamPlayedOnRound == p_Team_Identifier.terrorist)
                                {
                                    pen = CTpen;
                                }
                                else
                                {
                                    pen = Tpen;
                                }

                                for (int i = 0; i < rnd.positions.Count(); i++)
                                {
                                    vector2 pa = transforms.worldToScreenSpace(rnd.positions[i], cam);
                                    vector2 pb = transforms.worldToScreenSpace(rnd.positions[(i - 1).Clamp(0, rnd.positions.Count() - 1)], cam);

                                    //F*****g weird shit, I dont know why its recording big jumps like this
                                    if (Math.Abs(pa.x - pb.x) + Math.Abs(pa.y - pb.y) < 128)
                                    {
                                        graphics.DrawLine(pen, pa.x, pa.y.remapF(1024, 0, 0, 1024) - 1024, pb.x, pb.y.remapF(1024, 0, 0, 1024) - 1024);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            #endregion

            target_currentview.set_image(outputImage);
        }