fixed locals, fixed object+world gen
This commit is contained in:
@@ -12,7 +12,6 @@ public class Tile : MonoBehaviour
|
||||
System.Random rand = new System.Random();
|
||||
TileType tiletype;
|
||||
GameObject contentGenerator;
|
||||
|
||||
List<GameObject> aliveEnemies = new List<GameObject>();
|
||||
|
||||
public void generateTile(Vector3 pos, TileType type)
|
||||
@@ -26,7 +25,7 @@ public class Tile : MonoBehaviour
|
||||
|
||||
public void Update()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void generateContent()
|
||||
@@ -40,23 +39,41 @@ public class Tile : MonoBehaviour
|
||||
public List<Vector3> getSpawnLocations()
|
||||
{
|
||||
List<Vector3> list = new List<Vector3>();
|
||||
//Change object spawning
|
||||
int objectAmount = rand.Next(20, 101);
|
||||
Vector3 newPoint;
|
||||
while(list.Count < objectAmount){
|
||||
newPoint = new Vector3(rand.Next(-40, 40) + 100 * position.x, 50, rand.Next(-40, 40) + 100 * position.z);
|
||||
if (!list.Contains(newPoint))
|
||||
{
|
||||
list.Add(newPoint);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void spawnObject(Vector3 position)
|
||||
{
|
||||
int chance = rand.Next(1, 101);
|
||||
|
||||
if (chance >= 25)
|
||||
{
|
||||
GameObject content = contentGenerator.GetComponent<ContentGenerator>().generateContent(tiletype.ToString());
|
||||
if (content != null)
|
||||
{
|
||||
if(tiletype == TileType.CITY && (content.tag.ToLower().Contains("npc") || content.tag.ToLower().Contains("tree") || content.tag.ToLower().Contains("stone") || content.tag.ToLower().Contains("ore"))){
|
||||
position.y = 5;
|
||||
float verticeX = position.x / 10;
|
||||
float verticeZ = position.z / 10;
|
||||
|
||||
Vector3 vertice = new Vector3(Mathf.Round(verticeX), 0, Mathf.Round(verticeZ));
|
||||
Vector3[] vertices = gameObject.GetComponent<MeshFilter>().mesh.vertices;
|
||||
|
||||
foreach(Vector3 v in vertices){
|
||||
if(v.x == vertice.x && v.z == vertice.z){
|
||||
position.y = v.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
GameObject obj = Instantiate(content, position, Quaternion.identity);
|
||||
obj.transform.parent = gameObject.transform;
|
||||
|
||||
GameObject obj = Instantiate(content, position, Quaternion.identity, gameObject.transform);
|
||||
if (obj.tag.Contains("Enemy"))
|
||||
{
|
||||
aliveEnemies.Add(obj);
|
||||
@@ -103,10 +120,12 @@ public class Tile : MonoBehaviour
|
||||
{
|
||||
result = result + obj.GetComponent<Enemy>().saveEnemy() + "\r\n}";
|
||||
}
|
||||
else if(obj.name.ToLower().Contains("house")){
|
||||
else if (obj.name.ToLower().Contains("house"))
|
||||
{
|
||||
result = result + obj.transform.Find("Door").GetComponent<Door>().saveHouse() + "\r\n}";
|
||||
}
|
||||
else if(obj.name.ToLower().Contains("npc")){
|
||||
else if (obj.name.ToLower().Contains("npc"))
|
||||
{
|
||||
result = result + obj.GetComponent<NPC>().saveNPC() + "\r\n}";
|
||||
}
|
||||
else
|
||||
@@ -166,10 +185,12 @@ public class Tile : MonoBehaviour
|
||||
spawnedObject.GetComponent<Enemy>().loadEnemy(obj);
|
||||
}
|
||||
}
|
||||
else if(spawnedObject.name.ToLower().Contains("house")){
|
||||
else if (spawnedObject.name.ToLower().Contains("house"))
|
||||
{
|
||||
spawnedObject.transform.Find("Door").GetComponent<Door>().loadHouse(obj);
|
||||
}
|
||||
else if(spawnedObject.tag.ToLower().Contains("npc")){
|
||||
else if (spawnedObject.tag.ToLower().Contains("npc"))
|
||||
{
|
||||
spawnedObject.GetComponent<NPC>().loadQuest(obj["receivedQuest"].ToString());
|
||||
}
|
||||
}
|
||||
@@ -178,7 +199,8 @@ public class Tile : MonoBehaviour
|
||||
setPosition(pos);
|
||||
}
|
||||
|
||||
public List<TileType> getPossibleNeighbours(){
|
||||
public List<TileType> getPossibleNeighbours()
|
||||
{
|
||||
return TileTypeMethods.getPossibleNeighbours(tiletype);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user