/// <summary> /// Constructs a AddonProductionJob instance. /// </summary> /// <param name="ownerBuilding">The owner building of this job.</param> /// <param name="addonProduct">The type of addon to be created by this job.</param> /// <param name="jobID">The ID of this job.</param> public AddonProductionJob(Building ownerBuilding, IAddonType addonProduct, int jobID) : base(ownerBuilding.Owner, addonProduct, jobID) { this.addonProduct = addonProduct; this.ownerBuilding = this.ConstructField <Building>("ownerBuilding"); this.ownerBuilding.Write(ownerBuilding); }
/// <summary> /// Checks whether the placement constraints of this building allows it to be placed together with an addon of the given addon type /// at the given quadratic position and collects all the violating quadratic coordinates relative to the given position. /// </summary> /// <param name="position">The position to be checked.</param> /// <param name="addonType">The addon type to be checked.</param> /// <param name="entitiesToIgnore"> /// The list of entities to be ignored during the check. All entities in this list shall belong to the scenario of this entity. /// </param> /// <returns> /// The list of the quadratic coordinates (relative to the given position) violating the constraints of this building. /// </returns> public RCSet <RCIntVector> CheckPlacementConstraints(RCIntVector position, IAddonType addonType, RCSet <Entity> entitiesToIgnore) { RCSet <Entity> entitiesToIgnoreSet = new RCSet <Entity>(entitiesToIgnore) { this }; return(this.buildingType.CheckPlacementConstraints(this.Scenario, position, addonType, entitiesToIgnoreSet)); }
/// <see cref="IScenarioMetadata.GetAddonType"/> public IAddonType GetAddonType(string addonTypeName) { if (this.attachedMetadata == null) { throw new InvalidOperationException("Metadata not yet attached!"); } IAddonType attachedAddonType = this.attachedMetadata.GetAddonType(addonTypeName); return(new IAddonType(this.GetElementTypeUpgradeImpl(attachedAddonType.Name))); }
/// <see cref="CommandInputListener.TryComplete"/> public override CommandInputListener.CompletionResultEnum TryComplete() { if (this.CommandBuilder.TargetPosition == RCNumVector.Undefined) { /// No target position selected -> completion failed! return(CompletionResultEnum.FailedAndCancel); } if (this.placeSelectedBuilding) { /// Target position selected for the selected building -> validate the selected position. int[] currentSelection = this.selectionManagerBC.CurrentSelection.ToArray(); if (currentSelection.Length != 1) { throw new InvalidOperationException("The number of the currently selected entities must be 1!"); } Building selectedBuilding = this.scenarioManagerBC.ActiveScenario.GetElement <Building>(currentSelection[0]); if (selectedBuilding == null) { throw new InvalidOperationException("The currently selected entity doesn't exist or is not a building!"); } if (this.addonTypeName == null) { /// There is no additional addon type. if (this.fogOfWarBC.CheckPlacementConstraints(selectedBuilding, (RCIntVector)this.CommandBuilder.TargetPosition, new RCSet <Entity>()).Count == 0) { /// Selected position is OK. return(CommandInputListener.CompletionResultEnum.Succeeded); } else { /// Selected position is invalid -> completion failed! this.CommandBuilder.TargetPosition = RCNumVector.Undefined; return(CommandInputListener.CompletionResultEnum.FailedButContinue); } } else { /// Additional addon type has to be checked as well. IAddonType addonType = this.scenarioManagerBC.Metadata.GetAddonType(this.addonTypeName); if (addonType == null) { throw new InvalidOperationException(string.Format("Addon type '{0}' is not defined in the metadata!", this.addonTypeName)); } if (this.fogOfWarBC.CheckPlacementConstraints(selectedBuilding, (RCIntVector)this.CommandBuilder.TargetPosition, addonType, new RCSet <Entity>()).Count == 0) { /// Selected position is OK. return(CommandInputListener.CompletionResultEnum.Succeeded); } else { /// Selected position is invalid -> completion failed! this.CommandBuilder.TargetPosition = RCNumVector.Undefined; return(CommandInputListener.CompletionResultEnum.FailedButContinue); } } } else if (this.buildingTypeName != null) { /// Target position selected for a given building type -> validate the selected position. IBuildingType buildingType = this.scenarioManagerBC.Metadata.GetBuildingType(this.buildingTypeName); if (buildingType == null) { throw new InvalidOperationException(string.Format("Building type '{0}' is not defined in the metadata!", this.buildingTypeName)); } RCSet <Entity> currentSelection = new RCSet <Entity>(); foreach (int selectedEntityID in this.selectionManagerBC.CurrentSelection) { currentSelection.Add(this.scenarioManagerBC.ActiveScenario.GetElement <Entity>(selectedEntityID)); } if (this.addonTypeName == null) { if (this.fogOfWarBC.CheckPlacementConstraints(buildingType, (RCIntVector)this.CommandBuilder.TargetPosition, currentSelection).Count == 0) { /// Selected position is OK. return(CompletionResultEnum.Succeeded); } else { /// Selected position is invalid -> completion failed! this.CommandBuilder.TargetPosition = RCNumVector.Undefined; return(CompletionResultEnum.FailedButContinue); } } else { /// Additional addon type has to be checked as well. IAddonType addonType = this.scenarioManagerBC.Metadata.GetAddonType(this.addonTypeName); if (addonType == null) { throw new InvalidOperationException(string.Format("Addon type '{0}' is not defined in the metadata!", this.addonTypeName)); } if (this.fogOfWarBC.CheckPlacementConstraints(buildingType, (RCIntVector)this.CommandBuilder.TargetPosition, addonType, currentSelection).Count == 0) { /// Selected position is OK. return(CommandInputListener.CompletionResultEnum.Succeeded); } else { /// Selected position is invalid -> completion failed! this.CommandBuilder.TargetPosition = RCNumVector.Undefined; return(CommandInputListener.CompletionResultEnum.FailedButContinue); } } } else { /// A point selected on the map -> validate the selected position. return(CommandInputListener.CompletionResultEnum.Succeeded); } }
/// <see cref="IFogOfWarBC.CheckPlacementConstraints"/> public RCSet <RCIntVector> CheckPlacementConstraints(Building building, RCIntVector position, IAddonType addonType, RCSet <Entity> entitiesToIgnore) { if (this.ActiveScenario == null) { throw new InvalidOperationException("No active scenario!"); } RCIntVector objectQuadraticSize = this.ActiveScenario.Map.CellToQuadSize(building.ElementType.Area.Read().Size); RCSet <RCIntVector> violatingQuadCoords = building.CheckPlacementConstraints(position, addonType, 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); }
/// <summary> /// Updates the placement data based on the current state of the game engine. /// </summary> private void UpdatePlacementData() { Building newBuildingToBePlaced = null; IBuildingType newBuildingTypeToBePlaced = null; IAddonType newAddonTypeToBePlaced = null; if (this.commandManagerBC.IsWaitingForTargetPosition) { if (this.commandManagerBC.PlaceSelectedBuilding) { newBuildingToBePlaced = this.GetSelectedBuilding(); } else if (this.commandManagerBC.BuildingType != null) { this.RefreshCurrentSelection(); newBuildingTypeToBePlaced = this.scenarioManagerBC.Metadata.GetBuildingType(this.commandManagerBC.BuildingType); if (newBuildingTypeToBePlaced == null) { throw new InvalidOperationException(string.Format("Building type '{0}' is not defined in the metadata!", this.commandManagerBC.BuildingType)); } } if (this.commandManagerBC.AddonType != null) { newAddonTypeToBePlaced = this.scenarioManagerBC.Metadata.GetAddonType(this.commandManagerBC.AddonType); if (newAddonTypeToBePlaced == null) { throw new InvalidOperationException(string.Format("Addon type '{0}' is not defined in the metadata!", this.commandManagerBC.AddonType)); } } } /// Check if new preview animations have to be created. bool createPreviewAnimations = false; if (newBuildingToBePlaced != this.buildingToBePlaced || newBuildingTypeToBePlaced != this.buildingTypeToBePlaced || newAddonTypeToBePlaced != this.addonTypeToBePlaced) { this.buildingToBePlaced = newBuildingToBePlaced; this.buildingTypeToBePlaced = newBuildingTypeToBePlaced; this.addonTypeToBePlaced = newAddonTypeToBePlaced; createPreviewAnimations = true; } /// Create the building and addon preview animations if necessary. if (createPreviewAnimations) { this.buildingPreviewAnimation = null; this.addonPreviewAnimation = null; if (this.buildingToBePlaced != null && this.buildingToBePlaced.ElementType.AnimationPalette != null) { Animation previewAnimDef = this.buildingToBePlaced.ElementType.AnimationPalette.PreviewAnimation; if (previewAnimDef != null) { this.buildingPreviewAnimation = new AnimationPlayer(previewAnimDef, new ConstValue <MapDirection>(MapDirection.NorthEast)); } } else if (this.buildingTypeToBePlaced != null && this.buildingTypeToBePlaced.AnimationPalette != null) { Animation previewAnimDef = this.buildingTypeToBePlaced.AnimationPalette.PreviewAnimation; if (previewAnimDef != null) { this.buildingPreviewAnimation = new AnimationPlayer(previewAnimDef, new ConstValue <MapDirection>(MapDirection.NorthEast)); } } if (this.addonTypeToBePlaced != null && this.addonTypeToBePlaced.AnimationPalette != null) { Animation previewAnimDef = this.addonTypeToBePlaced.AnimationPalette.PreviewAnimation; if (previewAnimDef != null) { this.addonPreviewAnimation = new AnimationPlayer(previewAnimDef, new ConstValue <MapDirection>(MapDirection.NorthEast)); } } } }