// GET RESOURCER FOR AREA public float AreaResources(Global.areaTypes type, bool food, bool familiar) { float value = 0.0f; for (int i = 0; i < Global.system.travel.Count; i++) { if (Global.system.travel[i].area == type) { if (food) { if (familiar) { value = Global.system.travel[i].foodFamiliar; } else { value = Global.system.travel[i].foodForeign; } } else { if (familiar) { value = Global.system.travel[i].waterFamiliar; } else { value = Global.system.travel[i].waterForeign; } } } } return(value); }
// TRAVELLING INFO void TravelNeed() { meatNeed = 0; plantsNeed = 0; waterNeed = 0; // Planned path for (int p = 0; p < pathPlanned.Count; p++) { currentArea = pathPlanned[p].GetComponent <MapTile>().areaType; foodMultiply = AreaResources(currentArea, true, false); waterMultiply = AreaResources(currentArea, true, false); TamerResources(); PetResources(); } // Final path for (int f = 0; f < pathFinal.Count; f++) { currentArea = pathFinal[f].GetComponent <MapTile>().areaType; foodMultiply = AreaResources(currentArea, true, false); waterMultiply = AreaResources(currentArea, true, false); TamerResources(); PetResources(); } // Time timeNeed = (1 + pathPlanned.Count + pathFinal.Count) / 2; }
// CREATE NEW ENCOUNTER public void CreateEncounter() { distanceTiles.Clear(); //encounterTiles[i].GetComponent<MapTile>().Indicate(MapTile.indicators.dist1); for (int i = 0; i < encounterTiles.Count; i++) { float distance = Vector3.Distance(player.position, encounterTiles[i].transform.position); if (distance < 2) { distanceTiles.Add(new EncounterTile(encounterTiles[i], 1)); } else if (distance < 4) { distanceTiles.Add(new EncounterTile(encounterTiles[i], 2)); } else if (distance < 6) { distanceTiles.Add(new EncounterTile(encounterTiles[i], 3)); } else if (distance < 8) { distanceTiles.Add(new EncounterTile(encounterTiles[i], 4)); } else if (distance < 10) { distanceTiles.Add(new EncounterTile(encounterTiles[i], 5)); } } //Sorting list and check it count if (distanceTiles.Count > 0) { distanceTiles.Sort(delegate(EncounterTile a, EncounterTile b) { return((a.distance).CompareTo(b.distance)); }); } // Create encounter int forceExit = distanceTiles.Count * 10; int tileCount = 0; int currentDistance = 1; while (tileCount < distanceTiles.Count) { // Check tiles that are at current distance for (int d = 0; d < distanceTiles.Count; d++) { if (distanceTiles[d].distance == currentDistance) { // Check whether tile is empty bool create = true; for (int e = 0; e < Global.system.encounters.Count; e++) { if (Global.system.encounters[e].coords == distanceTiles[d].tile.GetComponent <MapTile>().coords) { create = false; } } // If allowed to create if (create) { // Check area type for (int t = 0; t < Global.system.travel.Count; t++) { if (distanceTiles[d].tile.GetComponent <MapTile>().areaType == Global.system.travel[t].area) { // Detection distance if (distanceTiles[d].distance == Global.system.travel[t].detectionDistance) { if (pathPos < pathFinal.Count && pathPos > 0) { if (distanceTiles[d].tile.GetComponent <MapTile>().coords != pathFinal[pathPos].coords) { // Encounter chance float chance = Random.Range(0, 100.0f); if (chance <= Global.system.travel[t].encounterChance) { int count = Random.Range(0, 3); Vector3 pos = distanceTiles[d].tile.transform.position; pos.y += playerOffset; Global.areaTypes type = distanceTiles[d].tile.GetComponent <MapTile>().areaType; // If area is not city: create monster if (type != Global.areaTypes.city) { Vector2 coords = distanceTiles[d].tile.GetComponent <MapTile>().coords; Transform spawned = Instantiate(Global.system.MapEnemy(type, -1), pos, Quaternion.identity) as Transform; int id = spawned.GetComponent <Stats>().id; Encounter newEncounter = new Encounter(spawned, id, count, pos, coords); Global.system.encounters.Add(newEncounter); } } } } } } } } tileCount++; } } currentDistance++; // Force exit forceExit--; if (forceExit < 0) { Debug.LogWarning("Forced exit"); break; } } }