public void GenerateSomeCityTestNetAddressAndVerifyPrefix() { Network network = new CityTest(); for (int i = 0; i < 10; i++) { var privateKey = new Key(); BitcoinPubKeyAddress address = privateKey.PubKey.GetAddress(network); Assert.StartsWith("T", address.ToString()); var witnessAddress = privateKey.PubKey.WitHash.ToString(); var test = address.ScriptPubKey.ToString(); BitcoinSecret secret = privateKey.GetWif(network); var wif = secret.ToWif(); Assert.StartsWith("V", wif.ToString()); } for (int i = 0; i < 10; i++) { var privateKey = new Key(false); BitcoinPubKeyAddress address = privateKey.PubKey.GetAddress(network); Assert.StartsWith("T", address.ToString()); var witnessAddress = privateKey.PubKey.WitHash.ToString(); var test = address.ScriptPubKey.ToString(); BitcoinSecret secret = privateKey.GetWif(network); var wif = secret.ToWif(); Assert.StartsWith("7", wif.ToString()); } }
public void NewCity() { CityTest cityScript = FindObjectOfType <CityTest>(); if (!cityScript) { return; } int seed = 0; int.TryParse(gameObject.GetComponentInChildren <InputField>().text, out seed); if (cityScript.myCity != null) { Destroy(cityScript.myCity.thisCity); cityScript.myCity = null; } cityScript.citySeed = seed; if (cityScript.citySeed != 0) { cityScript.GenerateCity(); } }
public static void SendInstructions(LORD_INSTRUCTIONS instructions, CityTest city, CityTest targetCity) { if (onInstruct != null) { onInstruct(instructions, city, targetCity); } }
void BuildLots(ref LotType _lot) { //shrink poly List <Vector2> lotPoly = CityTest.Shrink(borders, footPathSize + roadSize); //for each edge in poly for (int currEdge = 0; currEdge < lotPoly.Count; currEdge++) { //find its width and height float depth = _lot.maxDepth; int nextEdge = currEdge + 1 == lotPoly.Count ? 0 : currEdge + 1; int nextNextEdge = nextEdge + 1 == lotPoly.Count ? 0 : nextEdge + 1; int prevEdge = currEdge - 1 < 0 ? lotPoly.Count - 1 : currEdge - 1; //get cross point in from the edge direction Vector2 cross = GK.Geom.RotateRightAngle(lotPoly[nextEdge] - lotPoly[currEdge]).normalized *depth; Vector2 nextEdgeDirection = (lotPoly[nextEdge] - lotPoly[currEdge]).normalized; Vector2 prevEdgeDirection = lotPoly[prevEdge] - lotPoly[currEdge]; Vector2 nextNextEdgeDirection = lotPoly[nextEdge] - lotPoly[nextNextEdge]; float angleBetweenPrevNext = Vector2.Angle(nextEdgeDirection, prevEdgeDirection); float angleBetweenNextNextNext = Vector2.Angle(nextEdgeDirection, nextNextEdgeDirection); //find starting lenght (sin tan) along the original edge float startLenght = Mathf.Tan((90 - angleBetweenPrevNext) * Mathf.Deg2Rad) * depth; //find the hypotinues of the previous end lenght startLenght += depth / Mathf.Sin(angleBetweenPrevNext * Mathf.Deg2Rad); //hypot //find ending lenght (sin tan) along the original edge starting from the back normal edge float endLenght = Vector3.Distance(lotPoly[currEdge], lotPoly[nextEdge]) + (Mathf.Tan((90 - angleBetweenPrevNext) * Mathf.Deg2Rad) * depth); for (float currentLenght = startLenght; currentLenght < endLenght;) { //randomly get a building int buildingIndex = Random.Range(0, _lot.buildings.Count); GameObject building = _lot.buildings[buildingIndex]; float width = _lot.buildingSizes[buildingIndex].x; if (currentLenght + width < endLenght)// check if pointing can fit { //add building between points; Vector2 bottomLeft = lotPoly[currEdge] + nextEdgeDirection * currentLenght; Vector2 bottomRight = bottomLeft + nextEdgeDirection * width; Vector2 topRight = bottomRight + cross; Vector2 topLeft = bottomLeft + cross; currentLenght += width; Vector2 centerLot = (bottomLeft + bottomRight + topRight + topLeft) / 4; //crete the building in the lot GameObject newBuilding = GameObject.Instantiate(building, new Vector3(centerLot.x, 0, centerLot.y), Quaternion.LookRotation(Vector3.Cross(new Vector3(nextEdgeDirection.x, 0, nextEdgeDirection.y), -Vector3.up), Vector3.up), thisBlock.transform); newBuilding.name = "Building: " + currentLenght.ToString(); } else { break; } } } }
public void DevelopNewCity(KingdomTileTest conqueror, List <General> visitingGenerals) { this.cityAttributes = new CityTest(this.hexTile, conqueror); this.cityAttributes.OccupyCity(); this.GetComponent <SpriteRenderer> ().color = this.cityAttributes.kingdomTile.kingdom.tileColor; this.cityAttributes.visitingGenerals.AddRange(visitingGenerals); GameManager.Instance.UpdateAllMilitaryData(); }
public Army(CityTest city) { // this.id = GetID () + 1; // this.name = "GENERAL" + this.id; this.armyCount = city.kingdomTile.kingdom.armyBaseUnits; this.armyLevel = 1; this.armyExperience = 0; this.armyStats = new ArmyStats(city.kingdomTile.kingdom.armyBaseStats.hp, city.kingdomTile.kingdom.armyBaseStats.attack); }
public Merchant() { this._jobType = JOB_TYPE.MERCHANT; this._residence = RESIDENCE.OUTSIDE; this.tradeGoods = new List <Resource>(); this.pathToTargetCity = null; this.targetCity = null; this.isOutsideCity = false; }
public Citizen(JOB_TYPE jobType, CityTest city) { this._id = GetID() + 1; this.name = "CITIZEN" + this._id; this._job = GetJob(jobType); // this._job = new Job(); // this._job.CopyData(GetJob (jobType)); this._city = city; this._level = 1; AssignJobToCitizen(); SetLastID(this._id); }
// public bool isResolved; public MilitaryData(CityTest enemyCity, General enemyGeneral, int yourArmyStrength, BATTLE_MOVE battleMove) { this.id = GetID() + 1; this.enemyCity = enemyCity; this.enemyGeneral = enemyGeneral; this.battleMove = battleMove; this.yourArmyStrength = yourArmyStrength; this.isAllowedAttack = false; SetLastID(this.id); // this.isResolved = false; }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Tab)) { CityTest cityScript = FindObjectOfType <CityTest>(); if (cityScript.myCity != null) { Destroy(cityScript.myCity.thisCity); cityScript.myCity = null; } cityScript.citySeed = Random.Range(int.MinValue, int.MaxValue); gameObject.GetComponentInChildren <InputField>().text = cityScript.citySeed.ToString(); cityScript.GenerateCity(); } }
internal void CheckForWars() { if (this.cities.Count <= 0) { PoliticsPrototypeManager.Instance.turnEnded -= CheckForWars; PoliticsPrototypeManager.Instance.MakeKingdomDead(this); } if (this.kingdomsAtWarWith.Count <= 0) { return; } for (int i = 0; i < this.cities.Count; i++) { for (int j = 0; j < this.cities[i].cityAttributes.connectedCities.Count; j++) { CityTest connectedCity = this.cities[i].cityAttributes.connectedCities[j].cityAttributes; if (connectedCity.kingdomTile.kingdom.id != this.id && SearchRelationshipKingdomsById(connectedCity.kingdomTile.kingdom.id).isAtWar) { KingdomTest kingdomAtWarWith = connectedCity.kingdomTile.kingdom; int chanceOfWar = Random.Range(0, 100); // Debug.LogError(this.kingdomName + " is attempting to invade city " + connectedCity.cityName + " of kingdom " + connectedCity.kingdomTile.kingdom.kingdomName); if (chanceOfWar < 5) { //Invade City Debug.LogError(this.kingdomName + " has invaded city " + connectedCity.cityName + " of kingdom " + connectedCity.kingdomTile.kingdom.kingdomName); this.AddCityToKingdom(connectedCity.hexTile.GetCityTileTest()); kingdomAtWarWith.RemoveCitiesFromKingdom(new List <CityTileTest>() { connectedCity.hexTile.GetCityTileTest() }); int chanceOfPeace = Random.Range(0, 100); if (chanceOfPeace < 15) { Debug.LogError(this.kingdomName + " has declared peace with " + connectedCity.kingdomTile.kingdom.kingdomName); this.SearchRelationshipKingdomsById(kingdomAtWarWith.id).isAtWar = false; kingdomAtWarWith.SearchRelationshipKingdomsById(this.id).isAtWar = false; } break; } } } } }
public General(CityTest city) { this.id = GetID() + 1; this.name = "GENERAL" + this.id; this.city = city; this.location = city.hexTile; this.targetLocation = null; this.targetCity = null; this.army = new Army(city); this.taskID = 0; this.task = GENERAL_TASK.NONE; this.isOnTheWay = false; this.daysBeforeArrival = 0; this.daysBeforeReleaseTask = 0; this.roads = new List <Tile> (); GeneralAI.onMove += Move; GeneralAI.onCheckTask += CheckTask; SetLastID(this.id); }
public void GetCitiesCompletionListTest() { CityTest _ct = new CityTest(); _ct.SetUp(); WebLocationService.TransitState t_state = _ct.EndPoint.GetStateById(GetAdminTicket(), _ct._state_id); string key = string.Format("{0};{1}", t_state.Country, t_state.Name); Console.WriteLine("Key: {0}", key); WebLocationService.TransitCity t_instance = _ct.GetTransitInstance(); int id = _ct.EndPoint.CreateOrUpdateCity(GetAdminTicket(), t_instance); string[] cities = EndPoint.GetCitiesCompletionList( t_instance.Name.Substring(0, 3), 100, key); Assert.AreEqual(1, cities.Length); Assert.AreEqual(t_instance.Name, cities[0]); Console.WriteLine(cities[0]); _ct.EndPoint.DeleteCity(GetAdminTicket(), id); _ct.TearDown(); }
//generate our block public void Initilize(LotType lotType) { //set the bolock seed Random.State currentRNGState = Random.state; Random.InitState(seed); _lotType = lotType; MeshRenderer renderer = thisBlock.AddComponent <MeshRenderer>(); renderer.material = Resources.Load <Material>("CityMat"); renderer.material.color = lotType.groundColour; MeshFilter filter = thisBlock.AddComponent <MeshFilter>(); filter.mesh = new Mesh(); List <Vector2> blockGroundPoly; //generate our block ground and foot paths if (_lotType.footPath) { blockGroundPoly = CityTest.Shrink(borders, roadSize + footPathSize); BuildFootPath(_lotType.footPath); } else { blockGroundPoly = CityTest.Shrink(borders, roadSize); } //generate our buildings BuildLots(ref lotType); //generate our roads BuildRoads(); Vector3[] verticies = new Vector3[blockGroundPoly.Count]; int[] triangles = new int[blockGroundPoly.Count * 3]; Color[] vertColours = new Color[verticies.Length]; for (int i = 0; i < blockGroundPoly.Count; i++) // create our ground mesh { verticies[i] = new Vector3(blockGroundPoly[i].x, 0, blockGroundPoly[i].y) - thisBlock.transform.position; triangles[i * 3] = 0; if (i + 1 > verticies.Length - 1) { triangles[i * 3 + 1] = 0; } else { triangles[i * 3 + 1] = i + 1; } triangles[i * 3 + 2] = i; } filter.mesh.vertices = verticies; filter.mesh.triangles = triangles; Random.state = currentRNGState; }
public void CityTestnetIsInitializedCorrectly() { Network network = new CityTest(); Assert.Equal(0, network.Checkpoints.Count); Assert.Equal(1, network.DNSSeeds.Count); Assert.Equal(3, network.SeedNodes.Count); Assert.Equal("CityTest", network.Name); Assert.Equal(CityMain.CityRootFolderName, network.RootFolderName); Assert.Equal(CityMain.CityDefaultConfigFilename, network.DefaultConfigFilename); Assert.Equal(0x26898467.ToString(), network.Magic.ToString()); Assert.Equal(24333, network.DefaultPort); Assert.Equal(24334, network.RPCPort); Assert.Equal(CityMain.CityMaxTimeOffsetSeconds, network.MaxTimeOffsetSeconds); Assert.Equal(CityMain.CityDefaultMaxTipAgeInSeconds, network.MaxTipAge); Assert.Equal(10000, network.MinTxFee); Assert.Equal(60000, network.FallbackFee); Assert.Equal(10000, network.MinRelayTxFee); Assert.Equal("TCITY", network.CoinTicker); Assert.Equal(2, network.Bech32Encoders.Length); //Assert.Equal(new Bech32Encoder("bc").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS].ToString()); //Assert.Equal(new Bech32Encoder("bc").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS].ToString()); Assert.Equal(12, network.Base58Prefixes.Length); Assert.Equal(new byte[] { (66) }, network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS]); Assert.Equal(new byte[] { (196) }, network.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS]); Assert.Equal(new byte[] { (66 + 128) }, network.Base58Prefixes[(int)Base58Type.SECRET_KEY]); Assert.Equal(new byte[] { 0x01, 0x42 }, network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC]); Assert.Equal(new byte[] { 0x01, 0x43 }, network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC]); Assert.Equal(new byte[] { (0x04), (0x88), (0xB2), (0x1E) }, network.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY]); Assert.Equal(new byte[] { (0x04), (0x88), (0xAD), (0xE4) }, network.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY]); Assert.Equal(new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 }, network.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE]); Assert.Equal(new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A }, network.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE]); Assert.Equal(new byte[] { 0x2a }, network.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS]); Assert.Equal(new byte[] { 23 }, network.Base58Prefixes[(int)Base58Type.ASSET_ID]); Assert.Equal(new byte[] { 0x13 }, network.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS]); Assert.Equal(210000, network.Consensus.SubsidyHalvingInterval); Assert.Equal(750, network.Consensus.MajorityEnforceBlockUpgrade); Assert.Equal(950, network.Consensus.MajorityRejectBlockOutdated); Assert.Equal(1000, network.Consensus.MajorityWindow); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP34]); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP65]); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP66]); Assert.Equal(new uint256("0x000fd5ab3150ba1f57dbbfb449b67f4d4a30a634d997b269eccb0a48dd7cd3d9"), network.Consensus.BIP34Hash); Assert.Equal(new Target(new uint256("0000ffff00000000000000000000000000000000000000000000000000000000")), network.Consensus.PowLimit); Assert.Null(network.Consensus.MinimumChainWork); Assert.Equal(TimeSpan.FromSeconds(14 * 24 * 60 * 60), network.Consensus.PowTargetTimespan); Assert.Equal(TimeSpan.FromSeconds(10 * 60), network.Consensus.PowTargetSpacing); Assert.False(network.Consensus.PowAllowMinDifficultyBlocks); Assert.False(network.Consensus.PowNoRetargeting); Assert.Equal(1916, network.Consensus.RuleChangeActivationThreshold); Assert.Equal(2016, network.Consensus.MinerConfirmationWindow); Assert.Null(network.Consensus.BIP9Deployments[BIP9Deployments.TestDummy]); Assert.Null(network.Consensus.BIP9Deployments[BIP9Deployments.CSV]); Assert.Null(network.Consensus.BIP9Deployments[BIP9Deployments.Segwit]); Assert.Equal(125000, network.Consensus.LastPOWBlock); Assert.True(network.Consensus.IsProofOfStake); Assert.Equal(4535, network.Consensus.CoinType); Assert.Equal(new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)), network.Consensus.ProofOfStakeLimit); Assert.Equal(new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)), network.Consensus.ProofOfStakeLimitV2); Assert.Equal(new uint256("0x000fd5ab3150ba1f57dbbfb449b67f4d4a30a634d997b269eccb0a48dd7cd3d9"), network.Consensus.DefaultAssumeValid); Assert.Equal(10, network.Consensus.CoinbaseMaturity); Assert.Equal(Money.Coins(13736000000), network.Consensus.PremineReward); Assert.Equal(2, network.Consensus.PremineHeight); Assert.Equal(Money.Coins(1), network.Consensus.ProofOfWorkReward); Assert.Equal(Money.Coins(100), network.Consensus.ProofOfStakeReward); Assert.Equal((uint)500, network.Consensus.MaxReorgLength); Assert.Equal(long.MaxValue, network.Consensus.MaxMoney); Block genesis = network.GetGenesis(); Assert.Equal(uint256.Parse("0x000fd5ab3150ba1f57dbbfb449b67f4d4a30a634d997b269eccb0a48dd7cd3d9"), genesis.GetHash()); Assert.Equal(uint256.Parse("0xc83d0753a8826119c898cc23828356b760f0042ff8e9d67b3a03edfce5824a74"), genesis.Header.HashMerkleRoot); }
void ChooseTargetCity() { List <CityTest> elligibleCitiesForTrade = new List <CityTest>(); for (int i = 0; i < this.currentTile.GetCityTileTest().cityAttributes.connectedCities.Count; i++) { if (this.currentTile.GetCityTileTest().cityAttributes.connectedCities[i].cityAttributes.id == this.citizen.city.id || !this.currentTile.GetCityTileTest().cityAttributes.connectedCities[i].cityAttributes.hexTile.isOccupied) { //Skip cities already in trade with or own city or unoccupiedCities continue; } CityTest currentConnectedCity = this.currentTile.GetCityTileTest().cityAttributes.connectedCities[i].cityAttributes; for (int j = 0; j < this.tradeGoods.Count; j++) { RESOURCE currentTradeGood = this.tradeGoods[j].resourceType; if (currentConnectedCity.GetResourceStatusByType(currentTradeGood).status == RESOURCE_STATUS.SCARCE) { if (!elligibleCitiesForTrade.Contains(currentConnectedCity)) { elligibleCitiesForTrade.Add(currentConnectedCity); } } } } // if (elligibleCitiesForTrade.Count > 0) { // this.targetCity = elligibleCitiesForTrade [UnityEngine.Random.Range(0, elligibleCitiesForTrade.Count)]; // this.pathToTargetCity = GameManager.Instance.GetPath(this.citizen.city.hexTile.tile, this.targetCity.hexTile.tile, PATHFINDING_MODE.NORMAL).ToList(); // this.pathToTargetCity.Reverse(); // // this.citizenAvatar = GameObject.Instantiate(Resources.Load ("CitizenAvatar", typeof(GameObject)), this.citizen.city.hexTile.transform) as GameObject; // this.citizenAvatar.transform.localPosition = Vector3.zero; if (elligibleCitiesForTrade.Count <= 0) { for (int i = 0; i < this.currentTile.GetCityTileTest().cityAttributes.connectedCities.Count; i++) { if (!this.currentTile.GetCityTileTest().cityAttributes.connectedCities[i].cityAttributes.hexTile.isOccupied) { continue; } elligibleCitiesForTrade.Add(this.currentTile.GetCityTileTest().cityAttributes.connectedCities[i].cityAttributes); } } elligibleCitiesForTrade.OrderByDescending(x => x.GetScarcityValue()); if (elligibleCitiesForTrade [0].id == this.citizen.city.id) { elligibleCitiesForTrade.RemoveAt(0); List <CityTileTest> connectedCities = elligibleCitiesForTrade [0].connectedCities; for (int i = 0; i < connectedCities.Count; i++) { if (!this.currentTile.GetCityTileTest().cityAttributes.connectedCities [i].cityAttributes.hexTile.isOccupied) { continue; } elligibleCitiesForTrade.Add(connectedCities[i].cityAttributes); } } this.targetCity = elligibleCitiesForTrade[0]; this.pathToTargetCity = GameManager.Instance.GetPath(this.currentTile.tile, this.targetCity.hexTile.tile, PATHFINDING_MODE.NORMAL).Reverse().ToList(); this.citizen.city.cityLogs += GameManager.Instance.currentDay.ToString() + ": Merchant will go to [FF0000]" + this.targetCity.cityName + "[-]. The Merchant been to " + this.numOfCitiesVisited.ToString() + " cities\n\n"; GameManager.Instance.turnEnded += GoToDestination; }
public CityMilitaryData(CityTest city, int armyStrength) { this.city = city; this.armyStrength = armyStrength; }
//subdivide our suburb into blocks public void GenerateBlocks(float spacing, float deviation = 0, float alignmentRotation = 0) { //set our seed for the suburb Random.State currentRNGState = Random.state; Random.InitState(seed); float minX = float.MaxValue, maxX = float.MinValue, minY = float.MaxValue, maxY = float.MinValue; Vector2 rotationPivot = new Vector2(0, 0); List <Vector2> shrunkBorders = new List <Vector2>(borders); List <Vector2> sites = new List <Vector2>(); // shrink our borders so our points arnt created to close to the edge, this will result in blocks that are to small shrunkBorders = CityTest.Shrink(shrunkBorders, spacing / 2); if (shrunkBorders.Count >= 3) { for (int i = 0; i < shrunkBorders.Count; i++)//find anchorPoint { if (shrunkBorders[i].x < rotationPivot.x) { rotationPivot.x = shrunkBorders[i].x; } if (shrunkBorders[i].y < rotationPivot.y) { rotationPivot.y = shrunkBorders[i].y; } } //find rotate boarders for alignment and find bounding volume for (int i = 0; i < shrunkBorders.Count; i++) { shrunkBorders[i] = shrunkBorders[i].RotateAroundPoint(rotationPivot, alignmentRotation);// Vector2.MoveTowards(shrunkBorders[i].RotateAroundPoint(rotationPivot, alignmentRotation), borderCenter, spacing/2);// spacing/2); if (shrunkBorders[i].x > maxX) { maxX = shrunkBorders[i].x; } else if (shrunkBorders[i].x < minX) { minX = shrunkBorders[i].x; } if (shrunkBorders[i].y > maxY) { maxY = shrunkBorders[i].y; } else if (shrunkBorders[i].y < minY) { minY = shrunkBorders[i].y; } } //triangulate out polygon so we can check if created points are within our poly GK.DelaunayTriangulation triangulation = new GK.DelaunayCalculator().CalculateTriangulation(shrunkBorders); float xCenterOffset = ((maxX - minX) % spacing) / 2; float yCenterOffset = ((maxY - minY) % spacing) / 2; for (float x = minX - xCenterOffset; x < maxX; x += spacing) { for (float y = minY - yCenterOffset; y < maxY; y += spacing) { Vector2 newPoint = new Vector2(x + Random.Range(-deviation, deviation), y + Random.Range(-deviation, deviation)); // generate a points i a grid for (int i = 0; i < triangulation.Triangles.Count; i += 3) // if the point is contained within our polygon { if (GK.Geom.PointInTriangle(newPoint, triangulation.Vertices[triangulation.Triangles[i]], triangulation.Vertices[triangulation.Triangles[i + 1]], triangulation.Vertices[triangulation.Triangles[i + 2]])) { Vector2 rotatedPoint = newPoint.RotateAroundPoint(rotationPivot, -alignmentRotation); sites.Add(rotatedPoint);// rotate our aligned point to its original rotation and add it to the block site list break; } } } } } if (sites.Count >= 3) // we can only create a diagram if we have more then 2 verts { GK.VoronoiDiagram blockVoronoiDiagram = new GK.VoronoiCalculator().CalculateDiagram(sites); // generate our streets and blocks in our suburb for (int i = 0; i < blockVoronoiDiagram.Sites.Count; i++) { List <Vector2> clippedSite = null; if (blockVoronoiDiagram.FirstEdgeBySite.Count > 0) ////THIS IS NEEDED BECAUSE THE DIAGRAM CAN BE INVALID SOMETIMES { new GK.VoronoiClipper().ClipSite(blockVoronoiDiagram, borders, i, ref clippedSite); // clip our block by our suburb if (clippedSite.Count > 0) { Block newBlock = new Block();// create and assign the block newBlock.borders = new List <Vector2>(clippedSite); newBlock.parentSuburb = this; newBlock.seed = Random.Range(int.MinValue, int.MaxValue); newBlock.blockPosition = blockVoronoiDiagram.Sites[i]; newBlock.thisBlock = new GameObject("Block"); newBlock.thisBlock.transform.SetParent(thisSuburb.transform); newBlock.thisBlock.transform.localPosition = new Vector3(newBlock.blockPosition.x, 0, newBlock.blockPosition.y); myBlocks.Add(newBlock); } else { Debug.LogError("SUBURB SITE AFTER CLIPPED WASNT VALID"); } } else////THIS IS NEEDED BECAUSE THE DIAGRAM CAN BE INVALID SOMETIMES if its not valid make the entire subrb a block { Debug.LogWarning("SITE COULTNT BE CREATED BECASUE DIAGRAM DOESNT HAVE STARTING EDGES"); Block newBlock = new Block(); newBlock.borders = new List <Vector2>(borders); newBlock.parentSuburb = this; newBlock.seed = Random.Range(int.MinValue, int.MaxValue); newBlock.blockPosition = sitePosition; newBlock.thisBlock = new GameObject("Block"); newBlock.thisBlock.transform.SetParent(thisSuburb.transform); newBlock.thisBlock.transform.localPosition = new Vector3(newBlock.blockPosition.x, 0, newBlock.blockPosition.y); myBlocks.Add(newBlock); break; } } } else// if the suburb has less then 3 verts it cant be split so we make the entire suburb a block { Block newBlock = new Block(); newBlock.borders = new List <Vector2>(borders); newBlock.parentSuburb = this; newBlock.seed = Random.Range(int.MinValue, int.MaxValue); newBlock.blockPosition = sitePosition; newBlock.thisBlock = new GameObject("Block"); newBlock.thisBlock.transform.SetParent(thisSuburb.transform); newBlock.thisBlock.transform.localPosition = new Vector3(newBlock.blockPosition.x, 0, newBlock.blockPosition.y); myBlocks.Add(newBlock); } Random.state = currentRNGState; }
public void CityTestnetIsInitializedCorrectly() { Network network = new CityTest(); Assert.Equal(3, network.Checkpoints.Count); Assert.Equal(3, network.DNSSeeds.Count); Assert.Equal(3, network.SeedNodes.Count); Assert.Equal("CityTest", network.Name); Assert.Equal(CityMain.CityRootFolderName, network.RootFolderName); Assert.Equal(CityMain.CityDefaultConfigFilename, network.DefaultConfigFilename); Assert.Equal(0x43545401.ToString(), network.Magic.ToString()); Assert.Equal(24333, network.DefaultPort); Assert.Equal(24334, network.DefaultRPCPort); Assert.Equal(24335, network.DefaultAPIPort); Assert.Equal(CityMain.CityMaxTimeOffsetSeconds, network.MaxTimeOffsetSeconds); Assert.Equal(CityMain.CityDefaultMaxTipAgeInSeconds, network.MaxTipAge); Assert.Equal(10000, network.MinTxFee); Assert.Equal(10000, network.FallbackFee); Assert.Equal(10000, network.MinRelayTxFee); Assert.Equal("TCITY", network.CoinTicker); Assert.Equal(2, network.Bech32Encoders.Length); //Assert.Equal(new Bech32Encoder("bc").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS].ToString()); //Assert.Equal(new Bech32Encoder("bc").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS].ToString()); Assert.Equal(12, network.Base58Prefixes.Length); Assert.Equal(new byte[] { (66) }, network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS]); Assert.Equal(new byte[] { (196) }, network.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS]); Assert.Equal(new byte[] { (66 + 128) }, network.Base58Prefixes[(int)Base58Type.SECRET_KEY]); Assert.Equal(new byte[] { 0x01, 0x42 }, network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC]); Assert.Equal(new byte[] { 0x01, 0x43 }, network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC]); Assert.Equal(new byte[] { (0x04), (0x88), (0xB2), (0x1E) }, network.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY]); Assert.Equal(new byte[] { (0x04), (0x88), (0xAD), (0xE4) }, network.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY]); Assert.Equal(new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 }, network.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE]); Assert.Equal(new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A }, network.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE]); Assert.Equal(new byte[] { 0x2a }, network.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS]); Assert.Equal(new byte[] { 23 }, network.Base58Prefixes[(int)Base58Type.ASSET_ID]); Assert.Equal(new byte[] { 0x13 }, network.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS]); Assert.Equal(210000, network.Consensus.SubsidyHalvingInterval); Assert.Equal(750, network.Consensus.MajorityEnforceBlockUpgrade); Assert.Equal(950, network.Consensus.MajorityRejectBlockOutdated); Assert.Equal(1000, network.Consensus.MajorityWindow); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP34]); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP65]); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP66]); Assert.Equal(new uint256("0x00077765f625cc2cb6266544ff7d5a462f25be14ea1116dc2bd2fec17e40a5e3"), network.Consensus.BIP34Hash); Assert.Equal(new Target(new uint256("0000ffff00000000000000000000000000000000000000000000000000000000")), network.Consensus.PowLimit); Assert.Null(network.Consensus.MinimumChainWork); Assert.Equal(TimeSpan.FromSeconds(14 * 24 * 60 * 60), network.Consensus.PowTargetTimespan); Assert.Equal(TimeSpan.FromSeconds(10 * 60), network.Consensus.PowTargetSpacing); Assert.False(network.Consensus.PowAllowMinDifficultyBlocks); Assert.False(network.Consensus.PowNoRetargeting); Assert.Equal(2016, network.Consensus.MinerConfirmationWindow); Assert.Equal(125000, network.Consensus.LastPOWBlock); Assert.True(network.Consensus.IsProofOfStake); Assert.Equal(1926, network.Consensus.CoinType); Assert.Equal(new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)), network.Consensus.ProofOfStakeLimit); Assert.Equal(new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)), network.Consensus.ProofOfStakeLimitV2); Assert.Equal(new uint256("0x00077765f625cc2cb6266544ff7d5a462f25be14ea1116dc2bd2fec17e40a5e3"), network.Consensus.DefaultAssumeValid); Assert.Equal(10, network.Consensus.CoinbaseMaturity); Assert.Equal(Money.Coins(13736000000), network.Consensus.PremineReward); Assert.Equal(2, network.Consensus.PremineHeight); Assert.Equal(Money.Coins(2), network.Consensus.ProofOfWorkReward); Assert.Equal(Money.Coins(20), network.Consensus.ProofOfStakeReward); Assert.Equal((uint)500, network.Consensus.MaxReorgLength); Assert.Equal(long.MaxValue, network.Consensus.MaxMoney); Block genesis = network.GetGenesis(); Assert.Equal(uint256.Parse("0x00077765f625cc2cb6266544ff7d5a462f25be14ea1116dc2bd2fec17e40a5e3"), genesis.GetHash()); Assert.Equal(uint256.Parse("0x034aaae9ca8e297078a2fed80cdaaf72ffad8aa1b1988c7b6edd8f01d69312ca"), genesis.Header.HashMerkleRoot); }
void BuildFootPath(GameObject footPathPrefab) { List <Vector2> footPathPoly = CityTest.Shrink(borders, roadSize); //GameObject footPathPrefab = Resources.Load<GameObject>("FootPath"); float footPathSegmentLenght = footPathSize; for (int currBorderIndex = 0; currBorderIndex < footPathPoly.Count; currBorderIndex++) { GameObject footPath = new GameObject("FootPath: " + currBorderIndex.ToString()); footPath.transform.position = new Vector3(footPathPoly[currBorderIndex].x, 0, footPathPoly[currBorderIndex].y) + thisBlock.transform.position; footPath.transform.SetParent(thisBlock.transform); // this works the same as the roads for the most part, referance that int nextBorderIndex = currBorderIndex + 1; if (nextBorderIndex >= footPathPoly.Count) { nextBorderIndex = 0; } int prevBorderIndex = currBorderIndex - 1; if (prevBorderIndex < 0) { prevBorderIndex = footPathPoly.Count - 1; } int nextNextBorderIndex = nextBorderIndex + 1; if (nextNextBorderIndex >= footPathPoly.Count) { nextNextBorderIndex = 0; } Vector3 FrontWorldPosition = new Vector3(footPathPoly[currBorderIndex].x, 0, footPathPoly[currBorderIndex].y); Vector3 EndWorldPosition = new Vector3(footPathPoly[nextBorderIndex].x, 0, footPathPoly[nextBorderIndex].y); Vector3 nextPosition = new Vector3(footPathPoly[nextNextBorderIndex].x, 0, footPathPoly[nextNextBorderIndex].y); Vector3 prevPosition = new Vector3(footPathPoly[prevBorderIndex].x, 0, footPathPoly[prevBorderIndex].y); Vector3 thisDir = (EndWorldPosition - FrontWorldPosition).normalized; Vector3 nextDir = (nextPosition - EndWorldPosition).normalized; Vector3 prevDir = (FrontWorldPosition - prevPosition).normalized; Vector3 frontSliceDirection = (thisDir + prevDir) * 0.5f; Vector3 endSliceDirection = -(thisDir + nextDir) * 0.5f; float endRoadLenght = Vector3.Distance(EndWorldPosition, FrontWorldPosition); for (float lenght = 0; lenght < endRoadLenght; lenght += footPathSegmentLenght) { GameObject footPathObj = GameObject.Instantiate(footPathPrefab, FrontWorldPosition + thisDir * lenght + Vector3.up * 0.001f, Quaternion.LookRotation(thisDir, Vector3.up)); EzySlice.SlicedHull hull = footPathObj.Slice(FrontWorldPosition, frontSliceDirection); if (hull != null && hull.upperHull) { MonoBehaviour.Destroy(footPathObj); footPathObj = hull.CreateUpperHull(footPathObj); } hull = footPathObj.Slice(EndWorldPosition, endSliceDirection); if (hull != null && hull.upperHull) { MonoBehaviour.Destroy(footPathObj); footPathObj = hull.CreateUpperHull(footPathObj); } //THis is required to remove the empty material array elements the slicer leave there for some reason, bug with ezyslice Material[] newShared = new Material[1]; newShared[0] = footPathObj.GetComponent <Renderer>().sharedMaterials[0]; footPathObj.GetComponent <Renderer>().sharedMaterials = newShared; footPathObj.name = "Foot Path"; footPathObj.transform.SetParent(footPath.transform); } } }