Beispiel #1
0
        /// <summary>
        /// Constructs a new ProductionJob instance with the given ID for the given product.
        /// </summary>
        /// <param name="ownerPlayer">The owner player of this job.</param>
        /// <param name="product">The product to be created by this job.</param>
        /// <param name="jobID">The ID of this job.</param>
        protected ProductionJob(Player ownerPlayer, IScenarioElementType product, int jobID)
        {
            if (ownerPlayer == null)
            {
                throw new ArgumentNullException("ownerPlayer");
            }
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }
            if (jobID < 0)
            {
                throw new ArgumentOutOfRangeException("jobID", "Job identifier cannot be negative!");
            }

            this.elementFactory = ComponentManager.GetInterface <IElementFactory>();

            this.ownerPlayer      = this.ConstructField <Player>("ownerPlayer");
            this.jobID            = this.ConstructField <int>("jobID");
            this.progress         = this.ConstructField <int>("progress");
            this.lockedMinerals   = this.ConstructField <int>("lockedMinerals");
            this.lockedVespeneGas = this.ConstructField <int>("lockedVespeneGas");
            this.lockedSupplies   = this.ConstructField <int>("lockedSupplies");
            this.ownerPlayer.Write(ownerPlayer);
            this.jobID.Write(jobID);
            this.progress.Write(-1);
            this.lockedMinerals.Write(0);
            this.lockedVespeneGas.Write(0);
            this.lockedSupplies.Write(0);
            this.product = product;
        }
Beispiel #2
0
        /// <see cref="IMapEditorService.PlaceVespeneGeyser"/>
        public bool PlaceVespeneGeyser(RCIntVector position)
        {
            if (this.scenarioManager.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (position == RCIntVector.Undefined)
            {
                throw new ArgumentNullException("position");
            }

            RCIntVector navCellCoords = this.mapWindowBC.AttachedWindow.WindowToMapCoords(position).Round();
            IQuadTile   quadTileAtPos = this.scenarioManager.ActiveScenario.Map.GetCell(navCellCoords).ParentQuadTile;

            IScenarioElementType objectType        = this.scenarioManager.Metadata.GetElementType(VespeneGeyser.VESPENEGEYSER_TYPE_NAME);
            RCIntVector          objQuadSize       = this.scenarioManager.ActiveScenario.Map.CellToQuadSize(objectType.Area.Read().Size);
            RCIntVector          topLeftQuadCoords = quadTileAtPos.MapCoords - objQuadSize / 2;

            if (objectType.CheckPlacementConstraints(this.scenarioManager.ActiveScenario, topLeftQuadCoords, new RCSet <Entity>()).Count != 0)
            {
                return(false);
            }

            VespeneGeyser placedVespeneGeyser = new VespeneGeyser();

            this.scenarioManager.ActiveScenario.AddElementToScenario(placedVespeneGeyser);
            placedVespeneGeyser.AttachToMap(this.scenarioManager.ActiveScenario.Map.GetQuadTile(topLeftQuadCoords));
            return(true);
        }
Beispiel #3
0
        /// <see cref="IFogOfWarBC.CheckPlacementConstraints"/>
        public RCSet <RCIntVector> CheckPlacementConstraints(IScenarioElementType elementType, RCIntVector position, RCSet <Entity> entitiesToIgnore)
        {
            if (this.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }

            RCIntVector         objectQuadraticSize = this.ActiveScenario.Map.CellToQuadSize(elementType.Area.Read().Size);
            RCSet <RCIntVector> violatingQuadCoords = elementType.CheckPlacementConstraints(this.ActiveScenario, position, entitiesToIgnore);

            for (int x = 0; x < objectQuadraticSize.X; x++)
            {
                for (int y = 0; y < objectQuadraticSize.Y; y++)
                {
                    RCIntVector relativeQuadCoords = new RCIntVector(x, y);
                    RCIntVector absQuadCoords      = position + relativeQuadCoords;
                    if (absQuadCoords.X < 0 || absQuadCoords.X >= this.ActiveScenario.Map.Size.X ||
                        absQuadCoords.Y < 0 || absQuadCoords.Y >= this.ActiveScenario.Map.Size.Y ||
                        this.GetFullFowTileFlags(absQuadCoords).HasFlag(FOWTileFlagsEnum.Current))
                    {
                        violatingQuadCoords.Add(relativeQuadCoords);
                    }
                }
            }
            return(violatingQuadCoords);
        }
Beispiel #4
0
        /// <see cref="IScenarioMetadata.GetElementType"/>
        public IScenarioElementType GetElementType(string typeName)
        {
            if (this.attachedMetadata == null)
            {
                throw new InvalidOperationException("Metadata not yet attached!");
            }

            IScenarioElementType attachedElementType = this.attachedMetadata.GetElementType(typeName);

            return(new IScenarioElementType(this.GetElementTypeUpgradeImpl(attachedElementType.Name)));
        }
Beispiel #5
0
 /// <summary>
 /// Sets the entity type that this constraint belongs to.
 /// </summary>
 /// <param name="entityType">The entity type that this constraint belongs to.</param>
 /// <exception cref="SimulatorException">If a corresponding entity type has already been set for this constraint.</exception>
 public void SetEntityType(IScenarioElementType entityType)
 {
     if (entityType == null)
     {
         throw new ArgumentNullException("entityType");
     }
     if (this.entityType != null)
     {
         throw new SimulatorException("Entity type has already been set for this constraint!");
     }
     this.entityType = entityType;
 }
Beispiel #6
0
        /// <see cref="IScenarioMetadata.this[]"/>
        public IScenarioElementType this[int typeID]
        {
            get
            {
                if (this.attachedMetadata == null)
                {
                    throw new InvalidOperationException("Metadata not yet attached!");
                }

                IScenarioElementType attachedType = this.attachedMetadata[typeID];
                return(new IScenarioElementType(this.GetElementTypeUpgradeImpl(attachedType.Name)));
            }
        }
Beispiel #7
0
        /// <see cref="IMapEditorService.PlaceStartLocation"/>
        public bool PlaceStartLocation(RCIntVector position, int playerIndex)
        {
            if (this.scenarioManager.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (position == RCIntVector.Undefined)
            {
                throw new ArgumentNullException("position");
            }

            RCIntVector navCellCoords = this.mapWindowBC.AttachedWindow.WindowToMapCoords(position).Round();
            IQuadTile   quadTileAtPos = this.scenarioManager.ActiveScenario.Map.GetCell(navCellCoords).ParentQuadTile;

            IScenarioElementType objectType        = this.scenarioManager.Metadata.GetElementType(StartLocation.STARTLOCATION_TYPE_NAME);
            RCIntVector          objQuadSize       = this.scenarioManager.ActiveScenario.Map.CellToQuadSize(objectType.Area.Read().Size);
            RCIntVector          topLeftQuadCoords = quadTileAtPos.MapCoords - objQuadSize / 2;

            if (objectType.CheckPlacementConstraints(this.scenarioManager.ActiveScenario, topLeftQuadCoords, new RCSet <Entity>()).Count != 0)
            {
                return(false);
            }

            /// Check if a start location with the given player index already exists.
            RCSet <StartLocation> startLocations = this.scenarioManager.ActiveScenario.GetAllElements <StartLocation>();
            StartLocation         startLocation  = null;

            foreach (StartLocation sl in startLocations)
            {
                if (sl.PlayerIndex == playerIndex)
                {
                    startLocation = sl;
                    break;
                }
            }

            /// If a start location with the given player index already exists, change its quadratic coordinates,
            /// otherwise create a new start location.
            if (startLocation != null)
            {
                startLocation.DetachFromMap();
            }
            else
            {
                startLocation = new StartLocation(playerIndex);
                this.scenarioManager.ActiveScenario.AddElementToScenario(startLocation);
            }
            startLocation.AttachToMap(this.scenarioManager.ActiveScenario.Map.GetQuadTile(topLeftQuadCoords));
            return(true);
        }
        /// <see cref="IProductionDetailsView.GetProductionJobIcon"/>
        public SpriteRenderInfo GetProductionJobIcon(int itemIndex)
        {
            ProductionLine activeProductionLine = this.GetActiveProductionLine();

            if (activeProductionLine == null)
            {
                throw new InvalidOperationException("Active production line of the current selection cannot be accessed!");
            }

            IScenarioElementType job = activeProductionLine.GetProduct(itemIndex);

            if (job == null)
            {
                throw new InvalidOperationException(string.Format("There is no production job at index {0} int the active production line of the current selection!", itemIndex));
            }

            /// Retrieve the icon of the job from the CommandManagerBC!
            return(this.commandManager.GetProductButtonSprite(job.Name));
        }
Beispiel #9
0
        /// <see cref="CommandInputListener.TryComplete"/>
        public override CommandInputListener.CompletionResultEnum TryComplete()
        {
            /// First we have to check the resources of the local player.
            Player localPlayer = this.scenarioManagerBC.ActiveScenario.GetPlayer((int)this.selectionManagerBC.LocalPlayer);
            IScenarioElementType selectedProductType = localPlayer.Metadata.GetElementType(this.selectedProductTypeName);
            int mineralsNeeded = selectedProductType.MineralCost != null?selectedProductType.MineralCost.Read() : 0;

            int vespeneGasNeeded = selectedProductType.GasCost != null?selectedProductType.GasCost.Read() : 0;

            int supplyNeeded = selectedProductType.SupplyUsed != null?selectedProductType.SupplyUsed.Read() : 0;

            if (mineralsNeeded > localPlayer.Minerals || vespeneGasNeeded > localPlayer.VespeneGas)// || (supplyNeeded > 0 && localPlayer.UsedSupply + supplyNeeded > localPlayer.TotalSupply))
            {
                /// Insufficient resources or supply (TODO: send and error message up to the user!)
                return(CommandInputListener.CompletionResultEnum.FailedButContinue);
            }

            /// Resources are OK.
            this.CommandBuilder.CommandType = COMMAND_TYPE;
            this.CommandBuilder.Parameter   = this.selectedProductTypeName;
            return(CommandInputListener.CompletionResultEnum.Succeeded);
        }
        /// <summary>
        /// Constructs a command execution instance.
        /// </summary>
        /// <param name="recipientEntities">The recipient entities of this command execution.</param>
        protected CmdExecutionBase(RCSet <Entity> recipientEntities)
        {
            if (recipientEntities == null)
            {
                throw new ArgumentNullException("recipientEntities");
            }
            if (recipientEntities.Count == 0)
            {
                throw new ArgumentException("No recipient entities for command execution!", "recipientEntities");
            }

            this.scenario        = this.ConstructField <Scenario>("scenario");
            this.owner           = this.ConstructField <Player>("owner");
            this.parentExecution = this.ConstructField <CmdExecutionBase>("parentExecution");
            this.subExecution    = this.ConstructField <CmdExecutionBase>("subExecution");
            this.isInitialized   = this.ConstructField <byte>("isInitialized");
            this.scenario.Write(null);
            this.owner.Write(null);
            this.parentExecution.Write(null);
            this.subExecution.Write(null);
            this.isInitialized.Write(0x00);
            this.recipientEntities = new RCSet <Entity>();

            IScenarioElementType typeOfRecipientEntities = null;

            foreach (Entity entity in recipientEntities)
            {
                /// Check whether the entity is added to a scenario and a player.
                if (entity.Scenario == null)
                {
                    throw new InvalidOperationException("One of the recipient entities does not belong to a scenario!");
                }
                if (entity.Owner == null)
                {
                    throw new InvalidOperationException("One of the recipient entities does not belong to a player!");
                }

                /// Check whether every recipient entities are added to the same scenario.
                if (this.scenario.Read() == null)
                {
                    this.scenario.Write(entity.Scenario);
                }
                else if (this.scenario.Read() != entity.Scenario)
                {
                    throw new InvalidOperationException("All of the recipient entities must belong to the same scenario!");
                }

                /// Check whether every recipient entities are owned by the same player.
                if (this.owner.Read() == null)
                {
                    this.owner.Write(entity.Owner);
                }
                else if (this.owner.Read() != entity.Owner)
                {
                    throw new InvalidOperationException("All of the recipient entities must be owned by the same player!");
                }

                /// Check whether every recipient entities has the same type.
                if (typeOfRecipientEntities == null)
                {
                    typeOfRecipientEntities = entity.ElementType;
                }
                else if (typeOfRecipientEntities != entity.ElementType)
                {
                    throw new InvalidOperationException("All of the recipient entities must have the same type!");
                }

                /// Register the recipient entity to this command execution.
                this.recipientEntities.Add(entity);
            }
        }