/*public static void SpawnLake(Transform lakePos) * { * NatureObject no = NatureObject.Get("Teich"); * Vector3 gpos = Grid.ToGrid(lakePos.position); * GameNatureObject go = new GameNatureObject(no, (int)gpos.x, (int)gpos.z); * go.SetPosition(lakePos.transform.position); * go.SetRotation(Quaternion.identity); * SpawnNatureObject(go); * }*/ public static void SpawnForest(int treeAm, Vector3 pos) { NatureObject no = NatureObject.Get("Birke"); GameNatureObject go; Vector3 node = Grid.ToGrid(pos); int gx = (int)node.x; int gy = (int)node.z; for (int i = 0; i < treeAm; i++) { int x = 0; int z = 0; int count = 0; do { int spread = treeAm / 10 + count + 1; x = gx + Random.Range(-spread, spread); z = gy + Random.Range(-spread, spread); } while (!Grid.ValidNode(x, z) || (Grid.GetNode(x, z).IsOccupied() || (Mathf.Abs(Grid.SpawnY - x) < 5 && Mathf.Abs(Grid.SpawnY - z) < 5)) && (++count) < 100); if (count == 100) { continue; } go = new GameNatureObject(no, x, z); go.SetPosition(Grid.ToWorld(x + no.gridWidth / 2, z + no.gridHeight / 2)); go.SetRotation(Quaternion.Euler(0, Random.Range(0, 360), 0)); SpawnNatureObject(go); } }
//ボールがブロックに衝突しているかをチェックする public void ballCollisionCheck(ref Ball ball) { bool collisionFlag = false; //trueならブロックとボールは衝突している if (NatureObject.OBJ_BLOCK == this.natureObject) { //ボールの座標がブロックの矩形に重なっていないかをチェックする //ボールのX座標がオブジェクトの矩形より大きく、ボールのX座標が矩形のX座標の幅よりも小さい場合、 //または矩形のX座標がボールのX座標よりも大きく、かつ、矩形のX座標よりもボールのX座標がボールの横幅よりも大きい場合、 //かつ、ボールのY座標が矩形のY座標よりも大きく、ボールのY座標が矩形のY座標の高さよりも大きい場合、 //または矩形のY座標がボールのY座標よりも大きく、さらに矩形のY座標よりもボールのY座標がボールの縦幅よりも大きい場合、 if (((ball.getX() > this.x) && (ball.getX() < (this.x + MapObject.mapObjectWidth)) || (this.x > ball.getX()) && (this.x < (ball.getX() + ball.getBallWidth()))) && ((ball.getY() > this.y) && (ball.getY() < (this.y + MapObject.mapObjectHeight)) || (this.y > ball.getY()) && (this.y < (ball.getY() + ball.getBallHeight())))) { //ブロックの矩形と座標が重なっていたら、ボールを反射させる double angle = ball.getAngle(); ball.setAngle(-angle); collisionFlag = true; } //ブロックを消去する if (collisionFlag == true) { natureObject = NatureObject.OBJ_SPACE; } } return; }
public static string Name(int id) { NatureObject no = Get(id); if (no == null) { return("undefined nature object id=" + id); } return(no.name); }
public override sealed bool AddObject(NatureObject obj) { if (Map[obj.PX, obj.PY] != null) { return(false); } else { Map[obj.PX, obj.PY] = obj; return(true); } }
static Brush getBrush(NatureObject obj) { if (obj == null) { return(Brushes.Black); } switch (obj) { case MyAgent a: return(Brushes.Blue); //agent case SimpleFood food: return(Brushes.Green); //food default: return(Brushes.Red); } }
public bool MoveObject(NatureObject obj, Direction dir) { int newX = obj.PX, oldX = newX, newY = obj.PY, oldY = newY; switch (dir) { case Direction.Left: newX--; break; case Direction.Right: newX++; break; case Direction.Up: newY--; break; case Direction.Down: newY++; break; default: throw new NotImplementedException(); } if (newX < 0) { newX = XS + newX; } else { newX = newX % XS; } if (newY < 0) { newY = YS + newY; } else { newY = newY % YS; } if (Map[newX, newY] != null) { return(false); } else { Map[oldX, oldY] = null; changeObjectCoors(obj, newX, newY); Map[newX, newY] = obj; return(true); } }
private void SetupRandomNature() { // If in editor, spawn less nature to speed up testing if (Application.isEditor) { Spawn(30, 5, 5, 5, 30, 5, 5, 5, 5); // Spawn(50, 80, 15, 5, 30, 40, 20); //Spawn(200,50,15,10,70,15);//Spawn(50,20,5,5,30,5); } // Spawn some random plants else { Spawn(850, 320, 45, 25, 340, 40, 20, 200, 200); for (int i = 0; i < forestParent.childCount; i++) { Forest f = forestParent.GetChild(i).GetComponent <Forest>(); SpawnForest(f.trees, f.transform.position); } } /*for (int i = 0; i < lakeParent.childCount; i++) * { * Transform lk = lakeParent.GetChild(i); * SpawnLake(lk); * }*/ int count = 0; int x, z; do { x = Random.Range(-5, 5) + Grid.SpawnX; z = Random.Range(-5, 5) + Grid.SpawnY; } while ((Grid.GetNode(x, z).IsOccupied() || Grid.GetNode(x, z).IsWater() || (Mathf.Abs(Grid.SpawnX) < 5 && Mathf.Abs(Grid.SpawnY) < 5)) && (++count) < 100); if (count < 100) { NatureObject no = NatureObject.Get("Pilzstrunk"); GameNatureObject go = new GameNatureObject(no, x, z); go.SetPosition(Grid.ToWorld(x + no.gridWidth / 2, z + no.gridHeight / 2)); go.SetRotation(Quaternion.Euler(0, Random.Range(0, 360), 0)); SpawnNatureObject(go); } }
/*private void SpawnNatureObject(NatureO int randSize) * { * Terrain terrain = Terrain.activeTerrain; * * bool invalid = false; * int species = Random.Range(0, plants[(int)type].Count); * * int x = 0; * int z = 0; * int count = 0; * if(type == NatureObjectType.Reed) * { * List<Node> sn = new List<Node>(shore); * if(sn.Count == 0) return; * Node rsn = sn[Random.Range(0, sn.Count)]; * while(rsn.nodeObject != null && (++count) < 100) * rsn = sn[Random.Range(0, sn.Count)]; * if(count == 100) return; * x = rsn.gridX; * z = rsn.gridY; * } * else * { * x = UnityEngine.Random.Range(0, Grid.WIDTH); * z = UnityEngine.Random.Range(0, Grid.HEIGHT); * while((Grid.GetNode(x,z).IsOccupied() || (Mathf.Abs(Grid.WIDTH / 2 - x) < 5 && Mathf.Abs(Grid.HEIGHT / 2 - z) < 5)) && (++count) < 100) * { * x = UnityEngine.Random.Range(0, Grid.WIDTH); * z = UnityEngine.Random.Range(0, Grid.HEIGHT); * } * if(count == 100) return; * for (int dx = 0; dx < 3; dx++) * { * if (invalid) continue; * for (int dy = 0; dy < 3; dy++) * { * if (invalid) continue; * if (!Grid.ValidNode(x + dx, z + dy)) invalid = true; * else if (Grid.GetNode(x + dx, z + dy).IsOccupied()) invalid = true; * } * } * } * if (invalid) return; * * GameNatureObject toSpawn = new GameNatureObject(NatureObject.Get(), Grid.WIDTH / 2 - 1, Grid.HEIGHT / 2 - 1, 3); * toSpawn.SetPosition(Vector3.zero); * toSpawn.SetRotation(Quaternion.Euler(0, -90, 0)); * * GameObject obj = (GameObject)Instantiate(plants[(int)type][species], Vector3.zero * ,Quaternion.Euler(0, Random.Range(0, 360), 0), * plantsParent); * NatureObjectScript nos = obj.AddComponent<NatureObjectScript>(); * nos.tag = "NatureObject"; * nos.SetNatureObject(no) * * nos.SetPos(gridX, gridY); * * if(randSize > 0) nos.SetRandSize(randSize); * * // Set correct position of NatureObjectScript in terrain * Vector3 worldPos = Grid.ToWorld(x + nos.gridWidth / 2, z + nos.gridHeight / 2); * float smph = terrain.SampleHeight(worldPos); * worldPos.y = terrain.transform.position.y + smph; * * NatureObjectScript.transform.position = worldPos; * * nature.Add(NatureObjectScript); * * for (int dx = 0; dx < NatureObjectScript.gridWidth; dx++) * { * for (int dy = 0; dy < NatureObjectScript.gridHeight; dy++) * { * Grid.GetNode(x+dx,z+dy).SetNodeObject(obj.transform); * if(type == NatureObjectType.Rock) Grid.GetNode(x+dx, z+dy).objectWalkable = false; * } * } * }*/ // Spawn the given amount of trees,mushrooms,reeds and rocks private void Spawn(int countTrees, int countMushrooms, int countMushroomStumps, int countReed, int countCorn, int countRocks, int energySpots, int countPearTree, int countFirTree) { int[] counts = new int[] { countTrees, countRocks, countCorn, countMushrooms, countMushroomStumps, countReed, energySpots, countPearTree, countFirTree }; for (int i = 0; i < counts.Length; i++) { NatureObject baseNo = NatureObject.Get(i); if (!baseNo) { continue; } if (baseNo.type == NatureObjectType.Water) { continue; } for (int j = 0; j < counts[i]; j++) { SpawnRandomPosNatureObject(baseNo, 3); } } }
void Update() { /*for(int i = 0; i < typeCount.Length; i++) * typeCount[i] = 0; * foreach(NatureObjectScript p in nature) * { * if ((int)p.Type < typeCount.Length) * { * typeCount[(int)p.Type]++; * } * }*/ // NatureObjectScript SpawningFactor //int month = GameManager.GetMonth(); /* TODO: spawn in right month */ for (int i = 0; i < natureObjectSpawningTime.Length; i++) { NatureObject no = NatureObject.Get(i); if (no.growth < float.Epsilon) { continue; } if (no.type == NatureObjectType.Water) { continue; } natureObjectSpawningTime[i] += Time.deltaTime; float gt = 60f / (floraSpawningFactor * no.spawningFactor); if (natureObjectSpawningTime[i] >= gt) { natureObjectSpawningTime[i] -= gt; // Limit splant spawning if (typeCount[i] < no.spawningLimit) { SpawnRandomPosNatureObject(no, 0); } } } }
public GameNatureObject(NatureObject natureObject, int gridX, int gridY, int size, int variation) { this.natureObjectId = natureObject.id; this.gridX = gridX; this.gridY = gridY; this.size = size; this.variation = variation; miningTimes = 0; fallSpeed = 0; breakTime = -1; broken = false; currentGrowth = natureObject.growth * Random.Range(0.8f, 1.2f); growthTime = 0; despawnTime = 0; float amount = natureObject.materialPerSize.Amount * (1 + size); amount *= Random.Range(1f - natureObject.materialVarFactor, 1f + natureObject.materialVarFactor); resourceCurrent = new GameResources(natureObject.materialPerSize.Id, (int)amount); }
// PRE: Building and game building have to be set before strat is called private void Start() { // set nr of building if not already given by game building if (gameBuilding.nr == -1) { gameBuilding.nr = allBuildingScripts.Count; BuildingScript par = Identify(ParentBuildingNr); if (par) { par.AddChildBuilding(this); } } // Update allBuildings collection allBuildingScripts.Add(this); tag = Building.Tag; // make building a clickable object //co = gameObject.AddComponent<ClickableObject>(); // co.clickable = false; if (currentModel == null) { for (int i = 0; i < MaxStages; i++) { transform.GetChild(i).gameObject.SetActive(false); } SetCurrentModel(); } audioSource = Instantiate(AudioManager.Instance.buildingAudioPrefab, transform).GetComponent <AudioSource>(); // Add and disable Campfire script if (HasFire) { campfire = gameObject.AddComponent <Campfire>(); campfire.woodAmount = gameBuilding.campFireWoodAmount; campfire.enabled = !Blueprint; if (Name == "Lagerfeuer") { campfire.SetIsBigCampfire(false); } else if (Name == "Grosse Feuerstelle") { campfire.SetIsBigCampfire(true); } audioSource.clip = AudioManager.Instance.campfire; audioSource.loop = true; //cf.maxIntensity = Mathf.Clamp(GridWidth, 1, 1.8f); } fieldPlant = NatureObject.Get("Korn"); // init blueprint UI blueprintCanvas = transform.Find("CanvasBlueprint"); panelMaterial = new List <Transform>(); textMaterial = new List <Text>(); for (int i = 0; i < blueprintCanvas.Find("Cost").childCount; i++) { Transform pm = blueprintCanvas.Find("Cost").GetChild(i); panelMaterial.Add(pm); textMaterial.Add(pm.Find("TextMat").GetComponent <Text>()); } LayoutRebuilder.ForceRebuildLayoutImmediate(blueprintCanvas.GetComponent <RectTransform>()); buildingMaterial = meshRenderer.materials; blueprintMaterial = new Material[buildingMaterial.Length]; for (int i = 0; i < buildingMaterial.Length; i++) { blueprintMaterial[i] = BuildManager.Instance.blueprintMaterial; } // Finish building if no costs if (BlueprintBuildCost.Count == 0) { FinishBuilding(); } else { ChangeTerrainGround(); } //blueprintCanvas.gameObject.SetActive(false); blueprintCanvas.gameObject.SetActive(false); // init range canvas rangeCanvas = transform.Find("CanvasRange").transform; rangeImage = rangeCanvas.Find("Image").GetComponent <Image>(); // Make selected person go build this building PersonScript ps = PersonScript.FirstSelectedPerson(); if (ps) { ps.AddTargetTransform(transform, true); } // if building has a custom collision radius, disable default collider and add a capsule collider /*if (CollisionRadius > float.Epsilon) * { * gameObject.AddComponent<CapsuleCollider>(); * myCollider.enabled = false; * }*/ if (ViewRange > 0) { /* TODO: optimize code! */ /* * foreach (NatureObjectScript p in Nature.nature) * { * p.UpdateBuildingViewRange(); * } * foreach (ItemScript p in ItemScript.allItemScripts) * { * p.UpdateBuildingViewRange(); * } * foreach (PersonScript p in PersonScript.wildPeople) * { * p.UpdateBuildingViewRange(); * } * foreach (AnimalScript a in AnimalScript.allAnimals) * { * a.UpdateBuildingViewRange(); * }*/ gameObject.AddComponent <SimpleFogOfWar.FogOfWarInfluence>().ViewDistance = ViewRange; } // start coroutine StartCoroutine(GameBuildingTransform()); //recruitingTroop = new List<Troop>(); }
public static void SpawnRandomPosNatureObject(NatureObject baseNo, int rndSize) { Terrain terrain = Terrain.activeTerrain; bool invalid = false; int x = 0; int z = 0; int count = 0; if (baseNo.type == NatureObjectType.Reed) { List <Node> sn = new List <Node>(shore); if (sn.Count == 0) { return; } Node rsn = sn[Random.Range(0, sn.Count)]; while (rsn.nodeObject != null && (++count) < 100) { rsn = sn[Random.Range(0, sn.Count)]; } if (count == 100) { return; } x = rsn.gridX; z = rsn.gridY; } else { x = UnityEngine.Random.Range(0, Grid.WIDTH); z = UnityEngine.Random.Range(0, Grid.HEIGHT); while ((Grid.GetNode(x, z).IsOccupied() || Grid.GetNode(x, z).IsWater() || (Mathf.Abs(Grid.SpawnX - x) < Mathf.Max(5, baseNo.minDistToCenter) && Mathf.Abs(Grid.SpawnY - z) < Mathf.Max(5, baseNo.minDistToCenter))) && (++count) < 100) { x = UnityEngine.Random.Range(0, Grid.WIDTH); z = UnityEngine.Random.Range(0, Grid.HEIGHT); } if (count == 100) { return; } for (int dx = 0; dx < 3; dx++) { if (invalid) { continue; } for (int dy = 0; dy < 3; dy++) { if (invalid) { continue; } if (!Grid.ValidNode(x + dx, z + dy)) { invalid = true; } else if (Grid.GetNode(x + dx, z + dy).IsOccupied()) { invalid = true; } } } } if (invalid) { return; } GameNatureObject toSpawn = new GameNatureObject(baseNo, x, z); toSpawn.SetPosition(Grid.ToWorld(x + baseNo.gridWidth / 2, z + baseNo.gridHeight / 2)); toSpawn.SetRotation(Quaternion.Euler(0, Random.Range(0, 360), 0)); NatureObjectScript nos = SpawnNatureObject(toSpawn); nos.SetRandSize(rndSize); }
public GameNatureObject(NatureObject natureObject) : this(natureObject, 0, 0) { }
public GameNatureObject(int id) : this(NatureObject.Get(id)) { }
public GameNatureObject(string name) : this(NatureObject.Get(name)) { }
public GameNatureObject(NatureObject natureObject, int gridX, int gridY) : this(natureObject, gridX, gridY, Random.Range(0, natureObject.sizes), Random.Range(0, natureObject.variations)) { }
public void setNatureObject(NatureObject natureObject) { this.natureObject = natureObject; }
public CellField(int xs, int ys) : base(xs, ys) { Map = new NatureObject[xs, ys]; }
public override sealed bool ReplaceObject(NatureObject o0, NatureObject o1) { Map[o0.PX, o0.PY] = o1; return(true); }