public void InitalSpawn(int seed)
    {
        if (!forestContainer)
        {
            forestContainer        = new GameObject("Forest Container").transform;
            forestContainer.parent = transform;
        }

        foliageObjects          = new List <FoliageObject>();
        terrainObjects          = new List <TerrainObject>();
        terrainObjectContainers = new Transform[foliageTypes.Length];

        CancelInvoke();
        Vector2 sampleOffset = new Vector2(-mapSize.x / 2f, -mapSize.z / 2f);

        for (int foliageObjectType = 0; foliageObjectType < foliageTypes.Length; foliageObjectType++)
        {
            TerrainObjectType foliageObjectSettings = foliageTypes[foliageObjectType];
            terrainObjectContainers[foliageObjectType]        = new GameObject(foliageObjectSettings.name + " Container").transform;
            terrainObjectContainers[foliageObjectType].parent = forestContainer;
            foliageObjectSettings.Initialize(terrainLayerMask, objectLayerMask, terrainObjectContainers[foliageObjectType], LevelController.Instance.yearLength);
            foreach (Vector2 sample in new PoissonDiscSampler((int)mapSize.x, (int)mapSize.z, foliageObjectSettings.initialSpawnSampleRadius, foliageObjectSettings.poissonClusterRange, seed).Samples())
            {
                Vector3 position = new Vector3(sample.x + sampleOffset.x, maxTerrainHeight + 5f, sample.y + sampleOffset.x);
                AttemptSpawn(position, foliageObjectSettings, true, foliageObjectType > 0);
            }
        }

        InvokeRepeating("UpdateScores", .1f, scoreUpdateInterval);
        if (reproduceAnnually)
        {
            InvokeRepeating("NewYear", 0.0f, LevelController.Instance.yearLength);
        }
    }
Ejemplo n.º 2
0
    public void AddTerrainObject(TerrainObjectType type, HexCoordinates coordinates)
    {
        //TODO this could be more efficient
        CellStack stack = GetCellStackFromWorldCoords(coordinates);

        if (type == TerrainObjectType.Tree)
        {
            AddTree(stack);
        }
    }
Ejemplo n.º 3
0
	public virtual void Initialize (TerrainObjectType foliageType, float spawnTime, float viablityPercent, bool annualReproduction)
	{
		viability = viablityPercent;
		selfTerrainObjectType = foliageType;
		timeOfCreation = spawnTime;
		scale = selfTerrainObjectType.dna.scale.GetValue(viability);

		objectContainer = transform.GetChild(0);
		objectContainer.localScale = baseScale = objectContainer.localScale * scale;

		baseArea = Mathf.PI * (selfTerrainObjectType.dna.radius) * (selfTerrainObjectType.dna.radius) * scale;
		baseVolume = baseArea * selfTerrainObjectType.dna.height * selfTerrainObjectType.dna.objectDensity;
	}
Ejemplo n.º 4
0
    public virtual void Initialize(TerrainObjectType foliageType, float spawnTime, float viablityPercent, bool annualReproduction)
    {
        viability             = viablityPercent;
        selfTerrainObjectType = foliageType;
        timeOfCreation        = spawnTime;
        scale = selfTerrainObjectType.dna.scale.GetValue(viability);

        objectContainer            = transform.GetChild(0);
        objectContainer.localScale = baseScale = objectContainer.localScale * scale;

        baseArea   = Mathf.PI * (selfTerrainObjectType.dna.radius) * (selfTerrainObjectType.dna.radius) * scale;
        baseVolume = baseArea * selfTerrainObjectType.dna.height * selfTerrainObjectType.dna.objectDensity;
    }
Ejemplo n.º 5
0
    public override void Initialize(TerrainObjectType foliageType, float spawnTime, float viablityPercent, bool annualReproduction)
    {
        base.Initialize(foliageType, spawnTime, viablityPercent, annualReproduction);
        reproduceAnnually = annualReproduction;

        updateSmoothingStepPercent  = 1f / (float)foliageType.dna.scaleSmoothingSteps;
        updateSmoothingStepInterval = foliageType.dna.scaleSmoothTime * updateSmoothingStepPercent;
        predictedLifetime           = selfTerrainObjectType.dna.lifetime.GetValue(viability) * foliageType.yearLength;

        objectContainer.localScale = GetAgedScale();

        maxHealth = selfTerrainObjectType.dna.healthBySize.GetValue(scale);
    }
Ejemplo n.º 6
0
	public override void Initialize (TerrainObjectType foliageType, float spawnTime, float viablityPercent, bool annualReproduction)
	{
		base.Initialize(foliageType, spawnTime, viablityPercent, annualReproduction);
		reproduceAnnually = annualReproduction;

		updateSmoothingStepPercent = 1f / (float)foliageType.dna.scaleSmoothingSteps;
		updateSmoothingStepInterval = foliageType.dna.scaleSmoothTime * updateSmoothingStepPercent;
		predictedLifetime = selfTerrainObjectType.dna.lifetime.GetValue(viability) * foliageType.yearLength;

		objectContainer.localScale = GetAgedScale();

		maxHealth = selfTerrainObjectType.dna.healthBySize.GetValue(scale);

	}
    public void AttemptSpawn(Vector3 samplePoint, TerrainObjectType terrainObjectSettings, bool randomAge, bool checkSurroundings)
    {
        float viability = terrainObjectSettings.TestViability(ref samplePoint, checkSurroundings);

        if (viability <= terrainObjectSettings.viabilitySettings.minViability)
        {
            return;
        }

        float viabilityPercentage = CustomMathf.RemapValue(viability, terrainObjectSettings.viabilitySettings.minViability, 1f, true);
        float num       = !randomAge ? 0.0f : initialAgeDistribution.GetValue(Random.value) * terrainObjectSettings.dna.lifetime.minOutputValue * LevelController.Instance.yearLength;
        var   newObject = terrainObjectSettings.SpawnFoliageObject(samplePoint, Time.time - num, viabilityPercentage, reproduceAnnually);

        if (newObject.GetType() == typeof(FoliageObject))
        {
            AddFoliageObject((FoliageObject)newObject);
        }
        else
        {
            AddTerrainObject(newObject);
        }
    }
Ejemplo n.º 8
0
 public void SetObjectType(TerrainObjectType type)
 {
     objectType = type;
 }
	public void AttemptSpawn (Vector3 samplePoint, TerrainObjectType terrainObjectSettings, bool randomAge, bool checkSurroundings)
	{
		float viability = terrainObjectSettings.TestViability(ref samplePoint, checkSurroundings);
		if (viability <= terrainObjectSettings.viabilitySettings.minViability)
		{
			return;
		}

		float viabilityPercentage = CustomMathf.RemapValue(viability, terrainObjectSettings.viabilitySettings.minViability, 1f, true);
		float num = !randomAge ? 0.0f : initialAgeDistribution.GetValue(Random.value) * terrainObjectSettings.dna.lifetime.minOutputValue * LevelController.Instance.yearLength;
		var newObject = terrainObjectSettings.SpawnFoliageObject(samplePoint, Time.time - num, viabilityPercentage, reproduceAnnually);
		if (newObject.GetType() == typeof(FoliageObject))
		{
			AddFoliageObject((FoliageObject)newObject);
		}
		else
		{
			AddTerrainObject(newObject);
		}
	}
Ejemplo n.º 10
0
        public ObjectType Load(int objTypeNum, bool noCacheOut = true, bool forceLoad = false)
        {
            if (ObjectTypeList.ContainsKey(objTypeNum))
            {
                return(ObjectTypeList[objTypeNum]);
            }

            int objectTypeNum = -1;

            var objFitData = objPakFile.GetFileInner(objTypeNum);

            if (objFitData == null)
            {
                return(null);
            }

            var objFitFile = new FITFile(objFitData);

            objFitFile.SeekSection("ObjectClass");

            objFitFile.GetInt("ObjectTypeNum", out objectTypeNum);

            ObjectType objType = new ObjectType(objectTypeNum);

            switch ((ObjectTypeClass)objectTypeNum)
            {
            case ObjectTypeClass.CRAPPY_OBJECT:
                //----------------------------------------------
                // In theory we can't ever get here.
                // Because we did our jobs correctly!!

                throw new Exception();
                break;

            case ObjectTypeClass.BATTLEMECH_TYPE:
            {
                //objType = new ObjectType(objFitFile);
                //objType.init(objFitFile);
                //objType = new BattleMechType;
                //objType->setObjTypeNum(objTypeNum);
                ////if ((objType->init(objectFile,objectFile->getPacketSize()) != NO_ERR) && (objType->init(tmp1) != NO_ERR))
                //if ((objType->init(objectFile, objectFile->getPacketSize(), tmp1) != NO_ERR))// && (objType->init(tmp1) != NO_ERR))
                //    Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init Mech type ");
            }
            break;

            case ObjectTypeClass.VEHICLE_TYPE:
            {
                //objType = new GroundVehicleType;
                //objType->setObjTypeNum(objTypeNum);
                //if ((objType->init(objectFile, objectFile->getPacketSize(), tmp1) != NO_ERR))// && (objType->init(tmp1,3) != NO_ERR))
                //    Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init Vehicle type ");
            }
            break;

            case ObjectTypeClass.TREEBUILDING_TYPE:
            case ObjectTypeClass.BUILDING_TYPE:
            {
                objType = new BuildingType(objFitFile);
                //objType->setObjTypeNum(objTypeNum);
                //if (objType->init(objectFile, objectFile->getPacketSize(), tmp1) != NO_ERR)
                //    Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init Building type ");
            }
            break;

            case ObjectTypeClass.TREE_TYPE:
            {
                objType = new TerrainObjectType(objFitFile);
                //objType->setObjTypeNum(objTypeNum);
                //if (objType->init(objectFile, objectFile->getPacketSize()) != NO_ERR)
                //    Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init TerrainObject:Tree type ");
            }
            break;

            case ObjectTypeClass.TERRAINOBJECT_TYPE:
            {
                objType = new TerrainObjectType(objFitFile);
                //objType->setObjTypeNum(objTypeNum);
                //if (isMiscTerrObj)
                //    ((TerrainObjectTypePtr)objType)->initMiscTerrObj(objTypeNum);
                //else if (objType->init(objectFile, objectFile->getPacketSize()) != NO_ERR)
                //    Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init TerrainObject type ");
            }
            break;

            case ObjectTypeClass.WEAPONBOLT_TYPE:
            {
                //objType = new WeaponBoltType;
                //objType->setObjTypeNum(objTypeNum);
                //if (objType->init(objectFile, objectFile->getPacketSize()) != NO_ERR)
                //Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init WeaponBolt type ");
            }
            break;

            case ObjectTypeClass.TURRET_TYPE:
            {
                objType = new TurretType(objFitFile);
                //objType = new TurretType;
                //objType->setObjTypeNum(objTypeNum);
                //if (objType->init(objectFile, objectFile->getPacketSize(), tmp1) != NO_ERR)
                //    Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init Turret type ");
            }
            break;

            case ObjectTypeClass.EXPLOSION_TYPE:
            {
                objType = new ExplosionType(objFitFile);
                //objType = new ExplosionType;
                //objType->setObjTypeNum(objTypeNum);
                //if (objType->init(objectFile, objectFile->getPacketSize()) != NO_ERR)
                //    Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init Explosion type ");
            }
            break;

            case ObjectTypeClass.FIRE_TYPE:
            {
                objType = new FireType(objFitFile);
                //objType = new FireType;
                //objType->setObjTypeNum(objTypeNum);
                //if (objType->init(objectFile, objectFile->getPacketSize()) != NO_ERR)
                //    Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init Fire type ");
            }
            break;

            case ObjectTypeClass.GATE_TYPE:
            {
                objType = new GateType(objFitFile);
                //objType = new GateType;
                //objType->setObjTypeNum(objTypeNum);
                //if (objType->init(objectFile, objectFile->getPacketSize(), tmp1) != NO_ERR)
                //    Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init Gate type ");
            }
            break;

            case ObjectTypeClass.ARTILLERY_TYPE:
            {
            }
            break;

            case ObjectTypeClass.MINE_TYPE:
            {
                objType             = new ObjectType(objFitFile);
                objType.objectClass = ObjectClass.MINE;
                //objType = new ArtilleryType;
                //objType->setObjTypeNum(objTypeNum);
                //if (objType->init(objectFile, objectFile->getPacketSize()) != NO_ERR)
                //    Fatal(objectTypeNum, " ObjectTypeManager.load: unable to init Artillery type ");
            }
            break;

            default:
                return(null);
            }


            if (noCacheOut)
            {
                objType.NoCacheOut();
                if (objType.ExplosionObject > 0)
                {
                    Load((int)objType.ExplosionObject, false);
                }
            }

            ObjectTypeList.Add(objTypeNum, objType);

            return(objType);
        }