Exemple #1
0
        // Add new factory in the game arena if conditions for adding them satisty
        // Research Facility: Only one
        // Uses class variables factories, researchFacility, HydroBot
        private bool addNewBuilding(BuildingType buildingType, Vector3 position)
        {
            bool status = false;
            float orientation; // 0, PI/2, PI, 3*PI/2
            Factory oneFactory;

            bool notEnoughResource = false;
            switch (buildingType)
            {
                case BuildingType.researchlab:
                    if (HydroBot.numResources < GameConstants.numResourcesForResearchCenter)
                        notEnoughResource = true;
                    break;
                case BuildingType.biodegradable:
                    if (HydroBot.numResources < GameConstants.numResourcesForBioFactory)
                        notEnoughResource = true;
                    break;
                case BuildingType.plastic:
                    if (HydroBot.numResources < GameConstants.numResourcesForPlasticFactory)
                        notEnoughResource = true;
                    break;
                case BuildingType.radioactive:
                    if (HydroBot.numResources < GameConstants.numResourcesForRadioFactory)
                        notEnoughResource = true;
                    break;
            }
            // Check if hydrobot has sufficient resources for building a factory
            if (notEnoughResource)
            {
                // Play some sound hinting no sufficient resource
                audio.MenuScroll.Play();
                Point point = new Point();
                String point_string = "Not enough\nresources";
                point.LoadContent(PoseidonGame.contentManager, point_string, position, Color.Red);
                PlayGameScene.points.Add(point);
                return false;
            }
            if (HydroBot.currentEnergy < GameConstants.EnergyLostPerBuild)
            {
                audio.MenuScroll.Play();
                Point point = new Point();
                String point_string = "Not enough\nenergy";
                point.LoadContent(PoseidonGame.contentManager, point_string, position, Color.Red);
                PlayGameScene.points.Add(point);
                return false;
            }
            int radius = 60; // need to revise this based on the model for each building
            BoundingSphere buildingBoundingSphere;
            if (factoryAnchor != null)
            {
                buildingBoundingSphere = factoryAnchor.BoundingSphere;
                radius = (int)buildingBoundingSphere.Radius;
            }
            else if (researchAnchor != null)
            {
                buildingBoundingSphere = researchAnchor.BoundingSphere;
                radius = (int)buildingBoundingSphere.Radius;
            }

            // Check if position selected for building is within game arena.. The game area is within -MaxRange to +MaxRange for both X and Z axis
            // Give a lax of 40 units so that if a click happened at the edge of the arena, building is not allowed. This is to prevent the case
            // that power packs might appear above the end of the factory whose edge is just beyond the game arena.
            if (Math.Abs(position.X) > (float)(GameConstants.MainGameMaxRangeX - 40) || Math.Abs(position.Z) > (float)(GameConstants.MainGameMaxRangeZ - 40))
            {
                // Play some sound hinting position selected is outside game arena
                audio.MenuScroll.Play();
                Point point = new Point();
                String point_string = "Can not\nbuild here";
                point.LoadContent(PoseidonGame.contentManager, point_string, position, Color.Red);
                points.Add(point);
                return false;
            }

            //Verify that current location is available for adding the building

            int heightValue = GameConstants.MainGameFloatHeight;//(int)terrain.heightMapInfo.GetHeight(new Vector3(position.X, 0, position.Z));
            if (AddingObjects.IsSeaBedPlaceOccupied((int)position.X, heightValue, (int)position.Z, radius, null, null, trashes, factories, researchFacility))
            {
                // Play some sound hinting seabed place is occupied
                audio.MenuScroll.Play();
                Point point = new Point();
                String point_string = "Can not\nbuild here";
                point.LoadContent(PoseidonGame.contentManager, point_string, position, Color.Red);
                points.Add(point);
                return false;
            }

            switch (buildingType)
            {
                case BuildingType.researchlab:
                    if (researchFacility != null)
                    {
                        // do not allow addition of more than one research facility
                        Point point = new Point();
                        String point_string = "Can only build\n1 research center";
                        point.LoadContent(PoseidonGame.contentManager, point_string, position, Color.Red);
                        points.Add(point);
                        audio.MenuScroll.Play();
                        status = false;
                    }
                    else
                    {
                        //create research facility.. Only one is allowed, hence using a separate variable for this purpose.
                        researchFacility = new ResearchFacility(particleManager);
                        position.Y = terrain.heightMapInfo.GetHeight(new Vector3(position.X, 0, position.Z));
                        //orientation = (float)(Math.PI/2) * random.Next(4);
                        orientation = researchAnchor.orientation;
                        researchFacility.Model = researchBuildingModel;
                        researchFacility.ModelStates = researchBuildingModelStates;
                        researchFacility.LoadContent(game, position, orientation);
                        HydroBot.numResources -= GameConstants.numResourcesForResearchCenter;
                        status = true;
                    }
                    break;

                case BuildingType.biodegradable:
                    oneFactory = new Factory(FactoryType.biodegradable, particleManager, GraphicsDevice);
                    position.Y = terrain.heightMapInfo.GetHeight(new Vector3(position.X, 0, position.Z));
                    orientation = factoryAnchor.orientation;
                    oneFactory.Model = biodegradableFactoryModel;
                    oneFactory.ModelStates = biodegradableFactoryModelStates;
                    oneFactory.LevelTextures = biodegradableFactoryLevelTextures;
                    oneFactory.LoadContent(game, position, orientation, ref IngamePresentation.factoryFont, ref IngamePresentation.factoryBackground, biofactoryAnimationTextures);
                    HydroBot.numResources -= GameConstants.numResourcesForBioFactory;
                    factories.Add(oneFactory);
                    status = true;

                    break;

                case BuildingType.plastic:
                    oneFactory = new Factory(FactoryType.plastic, particleManager, GraphicDevice);
                    position.Y = terrain.heightMapInfo.GetHeight(new Vector3(position.X, 0, position.Z));
                    orientation = factoryAnchor.orientation;
                    oneFactory.Model = plasticFactoryModel;                 // set the model so that bounding sphere calculation happens based on fully blown model
                    oneFactory.ModelStates = plasticFactoryModelStates;     // set different model states so that under construction states are handled
                    oneFactory.LevelTextures = plasticFactoryLevelTextures;
                    oneFactory.LoadContent(game, position, orientation, ref IngamePresentation.factoryFont, ref IngamePresentation.factoryBackground, nuclearFactoryAnimationTextures); // for time being reuse nuclear factory animation texture
                    HydroBot.numResources -= GameConstants.numResourcesForPlasticFactory;
                    factories.Add(oneFactory);
                    status = true;

                    break;
                case BuildingType.radioactive:
                    oneFactory = new Factory(FactoryType.radioactive, particleManager, GraphicDevice);
                    position.Y = terrain.heightMapInfo.GetHeight(new Vector3(position.X, 0, position.Z));
                    orientation = factoryAnchor.orientation;
                    oneFactory.Model = radioactiveFactoryModel;
                    oneFactory.ModelStates = radioactiveFactoryModelStates;
                    oneFactory.LoadContent(game, position, orientation, ref IngamePresentation.factoryFont, ref IngamePresentation.factoryBackground, nuclearFactoryAnimationTextures);
                    HydroBot.numResources -= GameConstants.numResourcesForRadioFactory;
                    factories.Add(oneFactory);
                    status = true;

                    break;
            }
            if (status)
            {
                // Play sound for successful addition of a building
                audio.OpenChest.Play();
                HydroBot.currentEnergy -= GameConstants.EnergyLostPerBuild;
                //env loss for building factory
                if (GameConstants.envLossPerFactoryBuilt > 0)
                {
                    HydroBot.currentEnvPoint -= GameConstants.envLossPerFactoryBuilt;
                    Point lossPoint = new Point();
                    lossPoint.LoadContent(Content, "-" + GameConstants.envLossPerFactoryBuilt + "ENV", position, Color.Red);
                    points.Add(lossPoint);
                }
            }

            return status;
        }
Exemple #2
0
        private void UpdateAnchor()
        {
            // check if anchor need to be instantiated or updated
            if (factoryButtonPanel.AnchoredIndex != factoryButtonPanel.PreviousAnchoredIndex)
            {
                factoryAnchor = null;
                researchAnchor = null;

                Vector3 anchorPosition = CursorManager.IntersectPointWithPlane(cursor, gameCamera, GameConstants.MainGameFloatHeight);
                float orientation;
                if (factoryButtonPanel.anchorIndexToBuildingType() == BuildingType.researchlab)
                {
                    researchAnchor = new ResearchFacility(particleManager);
                    anchorPosition.Y = terrain.heightMapInfo.GetHeight(new Vector3(anchorPosition.X, 0, anchorPosition.Z));
                    orientation = (float)(Math.PI / 2) * random.Next(4);
                    researchAnchor.Model = researchBuildingModel;
                    researchAnchor.LoadContent(game, anchorPosition, orientation);
                }
                else
                {
                    FactoryType typeOfFactory = factoryButtonPanel.anchorIndexToFactoryType(factoryButtonPanel.AnchoredIndex);
                    factoryAnchor = new Factory(typeOfFactory, particleManager, GraphicDevice);
                    anchorPosition.Y = terrain.heightMapInfo.GetHeight(new Vector3(anchorPosition.X, 0, anchorPosition.Z));
                    orientation = (float)(Math.PI / 2) * random.Next(4);
                    switch (typeOfFactory)
                    {
                        case FactoryType.biodegradable:
                            factoryAnchor.Model = biodegradableFactoryModel; // need to make it different for each type
                            break;
                        case FactoryType.plastic:
                            factoryAnchor.Model = plasticFactoryModel;
                            break;
                        case FactoryType.radioactive:
                            factoryAnchor.Model = radioactiveFactoryModel;
                            break;
                    }
                    factoryAnchor.LoadContent(game, anchorPosition, orientation, ref IngamePresentation.factoryFont, ref IngamePresentation.dummyTexture, null);
                }
            }
            else
            {
                if (factoryAnchor != null)
                {
                    factoryAnchor.Position = CursorManager.IntersectPointWithPlane(cursor, gameCamera, GameConstants.MainGameFloatHeight);
                    factoryAnchor.Position.Y = terrain.heightMapInfo.GetHeight(new Vector3(factoryAnchor.Position.X, 0, factoryAnchor.Position.Z));
                }
                else if (researchAnchor != null)
                {
                    researchAnchor.Position = CursorManager.IntersectPointWithPlane(cursor, gameCamera, GameConstants.MainGameFloatHeight);
                    researchAnchor.Position.Y = terrain.heightMapInfo.GetHeight(new Vector3(researchAnchor.Position.X, 0, researchAnchor.Position.Z));
                }
            }
        }