private void cboMineral_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (!_initialized) { return; } if (_mineralVisual != null) { _viewport.Children.Remove(_mineralVisual); } MineralType mineralType = (MineralType)cboMineral.SelectedValue; // Create visual ModelVisual3D visual = new ModelVisual3D(); visual.Content = Mineral.GetNewVisual(mineralType); //visual.Transform = new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation())); _mineralVisual = visual; _viewport.Children.Add(_mineralVisual); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
private void AddFood(Mineral mineral) { var quantity = base.CargoBays.CargoVolume; if (quantity.Item2 - quantity.Item1 < mineral.VolumeInCubicMeters) { // The cargo bays are too full return; } // Try to pop this out of the map if (!_map.RemoveItem(mineral, true, false)) { // It's already gone return; } // Convert it to cargo Cargo_Mineral cargo = new Cargo_Mineral(mineral.MineralType, mineral.Density, mineral.VolumeInCubicMeters); // Try to add this to the cargo bays - the total volume may be enough, but the mineral may be too large for any // one cargo bay if (base.CargoBays.Add(cargo)) { // Finish removing it from the real world mineral.PhysicsBody.Dispose(); this.ShouldRecalcMass_Large = true; } else { // It didn't fit, give it back to the map _map.AddItem(mineral); } }
private void Start() { //Debug.Log(worldNames[0]); //world.Print(); mineral = Resources.Load <Mineral>("ScriptableObj/Minerals/" + mineralName[0]); minerals.Add(mineral); for (int i = 1; i < mineralName.Length; i++) { //#if UNITY_EDITOR // mineral = (Mineral)AssetDatabase.LoadAssetAtPath("Assets/ScriptableObj/Minerals/" + mineralName[i] + ".asset", typeof(Mineral)); //#endif mineral = Resources.Load <Mineral>("ScriptableObj/Minerals/" + mineralName[i]); //print(mineral); minerals.Add(mineral); //print(mineral); //minerals[i].Print(); prefabTool.GetComponent <SumNumOfMinerals>().numOfMineral = minerals[i].numOfMineral; prefabTool.GetComponent <SumNumOfMinerals>().id = minerals[i].id; //prefabTool.GetComponent<Image>().sprite = minerals[i].imageMineralSprite; imgPF = prefabTool.transform.GetChild(0).GetComponent <Image>(); nameMineral = prefabTool.transform.GetChild(1).GetComponent <Text>(); numOfMineral = prefabTool.transform.GetChild(2).GetComponent <Text>(); imgPF.sprite = minerals[i].imageMineralIcon; nameMineral.text = minerals[i].mineralname; numOfMineral.text = minerals[i].numOfMineral.ToString(); Instantiate(prefabTool, content.transform); } mineral = minerals[0]; }
/** * Make this planet a homeworld planet for a race */ public void makeHomeworld(Player player, int year) { owner = player; ownerID = owner.getID(); Race race = player.getRace(); System.Random random = new System.Random(); int min = Consts.minHWMineralConc; int max = Consts.maxStartingConc; concMinerals = new Mineral(random.Next(max) + min, random.Next(max) + min, random.Next(max) + min); hab = new Hab(); hab.setGrav(((race.getHabHigh().getGrav() - race.getHabLow().getGrav()) / 2) + race.getHabLow().getGrav()); hab.setTemp(((race.getHabHigh().getTemp() - race.getHabLow().getTemp()) / 2) + race.getHabLow().getTemp()); hab.setRad(((race.getHabHigh().getRad() - race.getHabLow().getRad()) / 2) + race.getHabLow().getRad()); min = Consts.minStartingSurf; max = Consts.maxStartingSurf; setCargo(new Cargo(random.Next(max) + min, random.Next(max) + min, random.Next(max) + min, 0, 0)); setPopulation(Consts.startingPopulation); if (race.hasLRT(LRT.LSP)) { setPopulation((int)(getPopulation() * Consts.lowStartingPopFactor)); } mines = Consts.startingMines; factories = Consts.startingFactories; defenses = Consts.startingDefenses; homeworld = true; contributesToResearch = true; scanner = true; }
private void Collision_BotFood(object sender, MaterialCollisionArgs e) { try { Body shipBody = e.GetBody(_material_Bot); Body mineralBody = e.GetBody(_material_Food); Swimbot bot = _bots.Where(o => o.PhysicsBody.Equals(shipBody)).FirstOrDefault(); if (bot == null) { return; } Mineral mineral = _map.GetItem <Mineral>(mineralBody); if (mineral == null) { return; } bot.CollidedMineral(mineral); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
private Dictionary <Mineral.Type, Vector3[]> calculateMinerals(int y) { Dictionary <Mineral.Type, Vector3[]> minerals = new Dictionary <Mineral.Type, Vector3[]> (); //Debug.Log (y); // Generate coal if (y < Mineral.getSpawnLayer(Mineral.Type.Coal)) { if (Mineral.hasSpawnChance(Mineral.Type.Coal)) { Vector3[] positions = this.generateMineralPositions(Mineral.getRandomSize(Mineral.Type.Coal)); minerals.Add(Mineral.Type.Coal, positions); } } if (y < Mineral.getSpawnLayer(Mineral.Type.Iron)) { if (Mineral.hasSpawnChance(Mineral.Type.Iron)) { Vector3[] positions = this.generateMineralPositions(Mineral.getRandomSize(Mineral.Type.Iron)); minerals.Add(Mineral.Type.Iron, positions); } } return(minerals); }
private void AddMineralToViewport(Viewport3D viewport, Mineral mineral) { #region Add lights Model3DGroup lightGroup = new Model3DGroup(); lightGroup.Children.Add(new AmbientLight(Colors.DimGray)); lightGroup.Children.Add(new DirectionalLight(Colors.Silver, new Vector3D(1, -1, -1))); ModelVisual3D lights = new ModelVisual3D(); lights.Content = lightGroup; viewport.Children.Add(lights); #endregion //NOTE: This relies on the fact that the mineral was removed from the main screen (the visuals can only belong to // one viewport at a time) foreach (ModelVisual3D visual in mineral.Visuals3D) { // I can't use this one, because the rixium rings will get screwed up //visual.Transform = new RotateTransform3D(new AxisAngleRotation3D(Math3D.GetRandomVectorSpherical(_rand, 10d), Math3D.GetNearZeroValue(_rand, 360d))); visual.Transform = new TranslateTransform3D(); viewport.Children.Add(visual); } }
public AddEditMineralsViewModel() : base(-1) { ValidInanimateTemplates = TemplateCache.GetAll <IInanimateTemplate>(); ValidMaterials = TemplateCache.GetAll <IMaterial>(); ValidMinerals = TemplateCache.GetAll <IMineral>(); DataObject = new Mineral(); }
public AddEditMineralsViewModel(long templateId) : base(templateId) { ValidInanimateTemplates = TemplateCache.GetAll <IInanimateTemplate>(); ValidMaterials = TemplateCache.GetAll <IMaterial>(); ValidMinerals = TemplateCache.GetAll <IMineral>(); DataObject = new Mineral(); //apply template if (DataTemplate != null) { DataObject.AmountMultiplier = DataTemplate.AmountMultiplier; DataObject.CanSpawnInSystemAreas = DataTemplate.CanSpawnInSystemAreas; DataObject.ElevationRange = DataTemplate.ElevationRange; DataObject.HumidityRange = DataTemplate.HumidityRange; DataObject.OccursIn = DataTemplate.OccursIn; DataObject.PuissanceVariance = DataTemplate.PuissanceVariance; DataObject.Rarity = DataTemplate.Rarity; DataObject.TemperatureRange = DataTemplate.TemperatureRange; DataObject.Dirt = DataTemplate.Dirt; DataObject.Fertility = DataTemplate.Fertility; DataObject.Ores = DataTemplate.Ores; DataObject.Rock = DataTemplate.Rock; DataObject.Solubility = DataObject.Solubility; } }
private void Collect() { mineral = target.GetComponent <Mineral> (); if (mineral.amount > 0) { var amounttocollect = speedCollector * Time.deltaTime; if (amounttocollect + collected <= capacity) { collected += mineral.Extract(amounttocollect); } else { collected += mineral.Extract(capacity - collected); } //print (collected + " - " + capacity + " - " + float.Equals(collected, capacity) + " - " + (collected >= capacity)); if (float.Equals(collected, capacity) || collected >= capacity) { target = null; } } else { target = null; } }
/// <summary> /// When the drill hits a mineral item, then it collects it. /// </summary> /// <param name="min">Mineral that the drill is colliding with.</param> public void CollectMinerals(Mineral min) { double minX = this.gameModel.Drill.Location[0] - 10; double maxX = minX + this.gameModel.TileSize; double minY = this.gameModel.Drill.Location[1] - 10; double maxY = minY + this.gameModel.TileSize; Random r = new Random(); if (minX <= min.Location[0] && maxX >= min.Location[0] && minY <= min.Location[1] && maxY >= min.Location[1] && this.gameModel.Drill.StorageFullness < this.gameModel.Drill.StorageCapacity) { switch (min.Type) { case MineralsType.Gold: this.gameModel.ActualPoints += CONFIG.GoldPrice; this.gameModel.Drill.StorageFullness++; break; case MineralsType.Silver: this.gameModel.ActualPoints += CONFIG.SilverPrice; this.gameModel.Drill.StorageFullness++; break; case MineralsType.Bronze: this.gameModel.ActualPoints += CONFIG.BronzePrice; this.gameModel.Drill.StorageFullness++; break; } min.Location[0] = r.Next(0, CONFIG.MapWidth * 2) * this.gameModel.TileSize; min.Location[1] = r.Next((CONFIG.MapHeight / 3) + 2, CONFIG.MapHeight) * this.gameModel.TileSize; } }
private void Collision_Ship_Mineral(object sender, CollisionEndEventArgs e) { // They all return 0's //Point3D contactPoint = e.ContactPositionWorld; //Vector3D contactNormal = e.ContactNormalWorld; //Vector3D contactForce = e.ContactForceWorld; Ship ship = null; Mineral mineral = null; if (e.Body1 is Ship) { ship = (Ship)e.Body1; mineral = (Mineral)e.Body2; } else { ship = (Ship)e.Body2; mineral = (Mineral)e.Body1; } if (ship.CollideWithMineral(mineral)) { // The ship is taking the mineral e.AllowCollision = false; _map.RemoveItem(mineral); } }
/// <summary> /// Called when [mouse enter]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void OnMouseEnter(object sender, EventArgs e) { Control ctrl = sender as Control; if (!toolTipInfo.Active && ctrl != null) { string tooltip = ""; if (ctrl is PictureBox && ctrl.Tag is Ore) { toolTipInfo.ToolTipTitle = "Ore"; Ore ore = (Ore)ctrl.Tag; tooltip = ore.Name; try { double netYield = Convert.ToDouble(textBoxNetYield.Text) / 100; tooltip += string.Format(Environment.NewLine + "Efficiency: {0}", ore.GetEfficiency(netYield)); } catch (FormatException) {} } else if (ctrl is PictureBox && ctrl.Tag is Mineral) { toolTipInfo.ToolTipTitle = "Mineral"; Mineral m = ctrl.Tag as Mineral; tooltip = m.Name + Environment.NewLine + "price: " + m.Price.ToString("F3"); } if (tooltip.Length > 0) { toolTipInfo.SetToolTip(ctrl, tooltip); } toolTipInfo.Active = true; } }
private void textBoxPrice_TextChanged(object sender, EventArgs e) { TextBox box = sender as TextBox; double price = 0.0; if (box == null) return; try { price = Convert.ToDouble(box.Text); } catch (FormatException) { } Mineral m = box.Tag as Mineral; if (m != null) m.Price = price; if (sender == textBoxPriceTritanium) Config<Settings>.Instance.PriceTritanium = price; else if (sender == textBoxPricePyerite) Config<Settings>.Instance.PricePyerite = price; else if (sender == textBoxPriceMexallon) Config<Settings>.Instance.PriceMexallon = price; else if (sender == textBoxPriceIsogen) Config<Settings>.Instance.PriceIsogen = price; else if (sender == textBoxPriceNocxium) Config<Settings>.Instance.PriceNocxium = price; else if (sender == textBoxPriceZydrine) Config<Settings>.Instance.PriceZydrine = price; else if (sender == textBoxPriceMegacyte) Config<Settings>.Instance.PriceMegacyte = price; else if (sender == textBoxPriceMorphite) Config<Settings>.Instance.PriceMorphite = price; }
public static Mineral GetMineralEarly(Vector3 position) { float distance = float.MaxValue; Mineral target = null; foreach (var mineral in minerals) { if (mineral.amount > 0 && mineral.currentCollectors < mineral.capacityCollectors && Vector3.Distance(mineral.transform.position, position) < distance) { target = mineral; distance = Vector3.Distance(mineral.transform.position, position); } } if (target == null) { foreach (var mineral in minerals) { if (mineral.amount > 0 && Vector3.Distance(mineral.transform.position, position) < distance) { target = mineral; distance = Vector3.Distance(mineral.transform.position, position); } } } target.currentCollectors++; return(target); }
public void RemoveMineral(Mineral m) { m.Hide(); mineralList.Remove(m); mineralPool.Add(m); }
public void Remove(Mineral mineral, float amount) { if (cargo.ContainsKey(mineral)) { cargo[mineral] -= amount; } }
public IActionResult DisplayMineral(int mineralId) { Mineral mineralFound = _context.minerals.Include(mineral => mineral.ChemicalFormula).SingleOrDefault(mineral => mineral.MineralId == mineralId); ViewBag.mineral = mineralFound; ViewBag.error = TempData["notLoggedIn"]; return(View("DisplayMineral")); }
public override void Die() { Destroy(gameObject, 0); if (chunk != null) { if (!flagged) { chunk.FlagAsteroid(this); flagged = true; } chunk.RemoveAsteroid(this); } if (sizeClass > 0 && gen != null) { if (chunk != null) { Random.seed = chunk.chunkSeed + id; } float numAsteroids = Random.Range(sizeClass, sizeClass + 3); float angleStep = 360 / numAsteroids; float startAngle = Random.Range(0, 360); for (int i = 0; i < numAsteroids; i++) { gen.transform.position = transform.position + (Vector3) new Vector2(Mathf.Cos(Mathf.Deg2Rad * (startAngle + angleStep * i)), Mathf.Sin(Mathf.Deg2Rad * (startAngle + angleStep * i))) * (sizeClass + 1) * 2; Asteroid clone = gen.GenerateAsteroid(mineral, sizeClass - 1, Random.Range(int.MinValue, int.MaxValue) + id); clone.chunk = chunk; if (chunk != null) { chunk.AddAsteroid(clone); } else { clone.gameObject.SetActive(true); } clone.rigidbody2D.AddForce(((Vector2)gen.transform.position - lastColPoint).normalized * 10 * sizeClass, ForceMode2D.Impulse); } } if (mineral != MineralType.Blank) { Mineral drop = gen.GenerateMineral(mineral); drop.transform.position = transform.position; } if (deathFX.Length > 0) { Instantiate(deathFX[(int)Mathf.Clamp(sizeClass, 0, deathFX.Length - 1)], transform.position + new Vector3(0, 0, -5), transform.rotation); } }
private void FixedUpdate() { if (blockBeingMined != null) { rb.velocity = new Vector3(0.0f, 0.0f, 0.0f); rb.isKinematic = true; if (System.DateTimeOffset.Now.ToUnixTimeMilliseconds() - timer > mineTimer) { Mine(); } if (mineCount == mineCountMax) { AddInventory(blockBeingMined); spawn.RemoveBlock(blockBeingMined); blockBeingMined.gameObject.SetActive(false); blockBeingMined = null; mineCount = 0; rb.isKinematic = false; } } else { if (Input.anyKey) { if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.UpArrow)) { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(0.0f, moveVertical * verticalSpeed, moveHorizontal * horisontalSpeed); player.Move(); rb.AddForce(movement * player.speedMultiplier); } if (Input.GetKeyDown(KeyCode.W)) { if (weapon.activeSelf) { weapon.SetActive(false); } else { weapon.SetActive(true); } } else if (Input.GetKeyDown(KeyCode.D) && weapon.activeSelf) { GameObject bulletInstance = Instantiate(bullet); bulletInstance.transform.position = weapon.transform.position + new Vector3(0.0f, 0.0f, 0.225f); bulletInstance.GetComponent <Rigidbody>().AddForce(new Vector3(0.0f, 0.0f, 1000.0f)); } else if (Input.GetKeyDown(KeyCode.A) && weapon.activeSelf) { GameObject bulletInstance = Instantiate(bullet); bulletInstance.transform.position = weapon.transform.position + new Vector3(0.0f, 0.0f, -0.225f); bulletInstance.GetComponent <Rigidbody>().AddForce(new Vector3(0.0f, 0.0f, -1000.0f)); } } } }
public Mineral GenerateMineral(MineralType t) { Mineral clone = Instantiate(baseMineral, new Vector3(0, 0, 0), baseMineral.transform.rotation) as Mineral; DeformMesh(clone.GetComponent <MeshFilter>().mesh, clone.GetComponent <PolygonCollider2D>(), 4, Random.Range(int.MinValue, int.MaxValue)); clone.renderer.material.SetColor("_OffColor", Asteroid.MineralToColor(t)); clone.renderer.material.SetColor("_Color", Asteroid.MineralToColor(t)); return(clone); }
private void AddMineral(ChangeInstruction instr) { Mineral mineral = new Mineral(instr.Mineral.MineralType, instr.Add_Position, instr.Mineral.Volume, _world, _material_Mineral, _sharedVisuals, ItemOptionsAstMin2D.MINERAL_DENSITYMULT, instr.Mineral.Volume / ItemOptionsAstMin2D.MINERAL_AVGVOLUME); mineral.PhysicsBody.AngularVelocity = instr.Add_AngVel; mineral.PhysicsBody.Velocity = instr.Add_Velocity; _map.AddItem(mineral); }
public void discover(int year, Planet planet) { this.reportYear = year; this.population = planet.getPopulation(); this.hab = new Hab(planet.getHab()); this.owner = planet.getOwner(); this.ownerID = planet.getOwnerID(); this.concMinerals = new Mineral(planet.getConcMinerals()); }
public void SetUp() { this.gameModel = new GameModel(500, 500); this.logic = new GameLogic(this.gameModel); this.logic.InitialMap(); this.logic.StartGame(); this.min = new Mineral(5, 5, MineralsType.Gold); this.enemy = new Enemy(10, 10); this.bomb = new Bomb(10, 10); }
private bool PlaceMineral(Mineral m, Stack<Mineral> parent_chain) { // Check if there is a free spot or another mineral in each horizontal direction Vector2[] dir_list = new Vector2[] { Vector2.right, -Vector2.right, Vector2.up, -Vector2.up }; dir_list = GeneralHelpers.ShuffleArray(dir_list); bool prefer_chaining = true; for (int i = 0; i < 4; ++i) { Vector2 point = (Vector2)parent_chain.Peek().transform.position + dir_list[i] * Mineral.WidthHeight; Collider2D col = Physics2D.OverlapPoint(point); if (col == null) { if (prefer_chaining) continue; // try another direction to find a mineral to chain onto else { // place mineral here (base case) m.transform.position = point; return true; } } // is there another mineral in the way? (that was not previously a parent in this recursion) Mineral new_parent = col.GetComponent<Mineral>(); if (new_parent != null && !parent_chain.Contains(new_parent)) { // try to place mineral further down the chain Stack<Mineral> new_chain = new Stack<Mineral>(parent_chain); new_chain.Push(new_parent); if (PlaceMineral(m, new_chain)) return true; } } // we tried to find a spot further down the chain, but couldn't find one // now look at the immediatly open spots again if (prefer_chaining) { for (int i = 0; i < 4; ++i) { Vector2 point = (Vector2)parent_chain.Peek().transform.position + dir_list[i] * Mineral.WidthHeight; Collider2D col = Physics2D.OverlapPoint(point); if (col == null) { // place mineral here m.transform.position = point; return true; } } } // no free locations, and we are as far down the chain as possible (unusual) return false; }
public Mineral GetActivatedMineralUsingIndex(int _mineralDataIndex) { if (_mineralDataIndex < 0 || _mineralDataIndex >= mineralList.Count) { throw new Exception(); } Mineral m = mineralList[_mineralDataIndex]; return(m); }
private void CreateMineralsSprtBuild(MineralType mineralType, Vector3D position) { Mineral mineral = new Mineral(); mineral.MineralType = mineralType; mineral.InitialVelocity = Math3D.GetRandomVector_Circular(8); mineral.CreateMineral(_materialManager, _map, _sharedVisuals, position, true, .0005); mineral.PhysicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce); }
public bool Add(Mineral mineral) { if (this.UsedVolume + MINERALVOLUME > this.MaxVolume) { return(false); } _contents.Add(mineral); return(true); }
private void Mine(Mineral mineral) { switch (mineral.Type) { case MineralType.Copper: mineral.Amount--; resourcesCarried.Copper++; break; case MineralType.Iron: mineral.Amount--; resourcesCarried.Iron++; break; case MineralType.Unknown: throw new NotImplementedException("Impossible!"); } }
public void AddMineral(Mineral mineral) { mineral.person_id = Constants.PERSON_ID; string theObject = JsonUtility.ToJson(mineral); //Debug.Log (theObject); UnityWebRequest www = UnityWebRequest.Put(baseURL + "mineral/" + mineral.id.ToString() + "/", theObject); www.SetRequestHeader("Content-Type", "application/json"); www.SendWebRequest(); this.Ownedminerals.Add(mineral); }
private void RenderMineral() { ModelVisual3D visual = new ModelVisual3D(); visual.Content = Mineral.GetNewVisual(this.MineralType); _rotateTransform = new QuaternionRotation3D(Math3D.GetRandomRotation()); visual.Transform = new RotateTransform3D(_rotateTransform); _viewport.Children.Add(visual); _camera.Position = (_camera.Position.ToVector().ToUnit() * 2.5d).ToPoint(); }
private void SpawnMineral() { Mineral m = Instantiate<Mineral>(mineral_prefab); if (root_mineral == null) { m.transform.position = transform.position; root_mineral = m; } else { Stack<Mineral> parent_chain = new Stack<Mineral>(); parent_chain.Push(root_mineral); PlaceMineral(m, parent_chain); } }
private void CreateMinerals_LINE() { List<MineralType> mineralTypes = new List<MineralType>(); mineralTypes.AddRange((MineralType[])Enum.GetValues(typeof(MineralType))); mineralTypes.Remove(MineralType.Custom); double x = -15; foreach (MineralType mineralType in mineralTypes) { Mineral mineral = new Mineral(); mineral.MineralType = mineralType; mineral.InitialVelocity = Math3D.GetRandomVector_Circular(.25); mineral.CreateMineral(_materialManager, _map, _sharedVisuals, new Vector3D(x, 10, 0), true, .0005); mineral.PhysicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce); x += 2; } }
public void Remove(Mineral mineral) { _contents.Remove(mineral); }
public bool Add(Mineral mineral) { if (this.UsedVolume + MINERALVOLUME > this.MaxVolume) { return false; } _contents.Add(mineral); return true; }
// fills a whole depth with minerals of a specific type. air/ramps/liquids are replaced with dirt private void _worker_InsertOres(object sender, DoWorkEventArgs e) { int depth = 25 - ((Tuple<int, int>)e.Argument).Item1; int mineral = ((Tuple<int, int>)e.Argument).Item2; List<KeyValuePair<int, int>> depthMineralList = new List<KeyValuePair<int, int>>(); if (mineral == -1) { depthMineralList.Add(new KeyValuePair<int, int>(depth, 19)); depthMineralList.Add(new KeyValuePair<int, int>(depth + 1, 21)); depthMineralList.Add(new KeyValuePair<int, int>(depth + 2, 20)); depthMineralList.Add(new KeyValuePair<int, int>(depth + 3, 18)); depthMineralList.Add(new KeyValuePair<int, int>(depth + 4, 31)); depthMineralList.Add(new KeyValuePair<int, int>(depth + 5, 30)); depthMineralList.Add(new KeyValuePair<int, int>(depth + 6, 23)); depthMineralList.Add(new KeyValuePair<int, int>(depth + 7, 25)); depthMineralList.Add(new KeyValuePair<int, int>(depth + 8, 26)); depthMineralList.Add(new KeyValuePair<int, int>(depth + 9, 27)); depthMineralList.Add(new KeyValuePair<int, int>(depth + 10, 29)); } else { depthMineralList.Add(new KeyValuePair<int, int>(depth, mineral)); } Map map = _empire.Map; int currentCells = 0; int currentPercentage = 0; //depth, height, width foreach (KeyValuePair<int, int> kvp in depthMineralList) { for (int height = 0; height < map.MapHeight; ++height) { for (int width = 0; width < map.MapWidth; ++width) { Game.MapCell currentCell = map.GetCell(kvp.Key, height, width); currentCell.RemoveRamp(); currentCell.RemoveLiquid(); if (!currentCell.HasWall()) { currentCell.Wall = (int)GameLibrary.Material.Dirt; } Mineral mineralToAdd = new Mineral(new Vector3(height, width, kvp.Key), kvp.Value); if(mineralToAdd.Cell() != null) _empire.EntityManager.SpawnEntityImmediate(mineralToAdd); } } ++currentCells; int tempPercentage = (int)((currentCells / (double)depthMineralList.Count) * 100); if (tempPercentage > currentPercentage) { currentPercentage = tempPercentage; _worker.ReportProgress(currentPercentage); } } _worker.ReportProgress(0); }
void ShootRaycast(string direction) { if(direction.Equals("left")) { rcLeft = new Vector2(transform.position.x - 0.16f, transform.position.y); hitLeft = Physics2D.Raycast(rcLeft, Vector2.left, rcDist); if (hitLeft.collider != null) { if(hitLeft.transform.tag.Equals("Mineral") && Vector2.Distance(transform.position, hitLeft.point) < 0.25f) { if(!hitLeft.transform.gameObject.Equals(selectedMineralLeft)) { selectedMineralLeft = hitLeft.transform.gameObject.GetComponent<Mineral>(); } } else { selectedMineralLeft = null; } } if(selectedMineralLeft != null) { if (Vector2.Distance(rcLeft, new Vector2(selectedMineralLeft.transform.position.x, selectedMineralLeft.transform.position.y)) > nullDist) { selectedMineralLeft = null; } } } else if(direction.Equals("right")) { rcRight = new Vector2(transform.position.x + 0.16f, transform.position.y); hitRight = Physics2D.Raycast(rcRight, Vector2.right, rcDist); if (hitRight.collider != null) { /* Debug.Log(hitRight.transform.tag.Equals("Mineral")); Debug.Log(Vector2.Distance(transform.position, hitRight.point)); Debug.Log(!hitRight.transform.gameObject.Equals(selectedMineralRight)); */ if (hitRight.transform.tag.Equals("Mineral") && Vector2.Distance(transform.position, hitRight.point) < 0.32f) { if (!hitRight.transform.gameObject.Equals(selectedMineralRight)) { selectedMineralRight = hitRight.transform.gameObject.GetComponent<Mineral>(); } } else { selectedMineralRight = null; } //Debug.Log(Vector2.Distance(rcRight, new Vector2(selectedMineralRight.transform.position.x, selectedMineralRight.transform.position.y))); } if(selectedMineralRight != null) { //Debug.Log(Vector2.Distance(rcRight, new Vector2(selectedMineralRight.transform.position.x, selectedMineralRight.transform.position.y))); if (Vector2.Distance(rcRight, new Vector2(selectedMineralRight.transform.position.x, selectedMineralRight.transform.position.y)) > nullDist) { selectedMineralRight = null; } } } else if(direction.Equals("bottom")) { rcBottom = new Vector2(transform.position.x, transform.position.y - 0.32f); hitBottom = Physics2D.Raycast(rcBottom, -Vector2.up, rcDist); if (hitBottom.collider != null) { if (hitBottom.transform.tag.Equals("Mineral") && Vector2.Distance(rcBottom, hitBottom.point) < 0.005f) { if (!hitBottom.transform.gameObject.Equals(selectedMineralBottom)) { selectedMineralBottom = hitBottom.transform.gameObject.GetComponent<Mineral>(); } } else { selectedMineralBottom = null; } } if(selectedMineralBottom != null) { if (Vector2.Distance(rcBottom, new Vector2(selectedMineralBottom.transform.position.x, selectedMineralBottom.transform.position.y)) > nullDist) { selectedMineralBottom = null; } } } }