/// <summary> /// Constructs a ScenarioElement instance. /// </summary> /// <param name="elementTypeName">The name of the type of this element.</param> protected ScenarioElement(string elementTypeName) { ScenarioMetadataUpgrade instanceLevelMetadata = new ScenarioMetadataUpgrade(); this.metadata = instanceLevelMetadata; this.metadataUpgrade = instanceLevelMetadata; this.metadataUpgrade.AttachMetadata(ComponentManager.GetInterface <IScenarioLoader>().Metadata); this.elementType = this.metadata.GetElementType(elementTypeName); this.elementTypeUpgrade = this.metadataUpgrade.GetElementTypeUpgrade(elementTypeName); this.typeID = this.ConstructField <int>("typeID"); this.id = this.ConstructField <int>("id"); this.owner = this.ConstructField <Player>("owner"); this.lastOwnerIndex = this.ConstructField <int>("lastOwnerIndex"); this.scenario = this.ConstructField <Scenario>("scenario"); this.mapObjectsOfThisElementByLayer = new Dictionary <MapObjectLayerEnum, RCSet <MapObject> > { { MapObjectLayerEnum.GroundObjects, new RCSet <MapObject>() }, { MapObjectLayerEnum.GroundMissiles, new RCSet <MapObject>() }, { MapObjectLayerEnum.AirObjects, new RCSet <MapObject>() }, { MapObjectLayerEnum.AirMissiles, new RCSet <MapObject>() } }; this.mapObjectsOfThisElement = new Dictionary <MapObject, MapObjectLayerEnum>(); this.typeID.Write(this.elementType.ID); this.id.Write(-1); this.owner.Write(null); this.lastOwnerIndex.Write(-1); this.scenario.Write(null); this.mapContext = null; }
/// <summary> /// Constructs a new player instance. /// </summary> /// <param name="playerIndex">The index of the player.</param> /// <param name="startLocation">The start location of the player.</param> internal Player(int playerIndex, StartLocation startLocation) { if (playerIndex < 0 || playerIndex >= Player.MAX_PLAYERS) { throw new ArgumentOutOfRangeException("playerIndex"); } if (startLocation == null) { throw new ArgumentNullException("startLocation"); } if (startLocation.Scenario == null) { throw new SimulatorException("The given start location doesn't belong to a scenario!"); } if (!startLocation.HasMapObject(MapObjectLayerEnum.GroundObjects)) { throw new SimulatorException("The given start location has already been initialized!"); } ScenarioMetadataUpgrade metadata = new ScenarioMetadataUpgrade(); metadata.AttachMetadata(ComponentManager.GetInterface <IScenarioLoader>().Metadata); this.metadata = metadata; this.metadataUpgrade = metadata; this.playerIndex = this.ConstructField <int>("playerIndex"); this.startLocation = this.ConstructField <StartLocation>("startLocation"); this.startPosition = this.ConstructField <RCNumVector>("startPosition"); this.quadraticStartPosition = this.ConstructField <RCIntRectangle>("quadraticStartPosition"); this.minerals = this.ConstructField <RCNumber>("minerals"); this.vespeneGas = this.ConstructField <RCNumber>("vespeneGas"); this.lockedSupplies = this.ConstructField <int>("lockedSupplies"); this.usedSupplyCache = new CachedValue <int>(this.CalculateUsedSupply); this.totalSupplyCache = new CachedValue <int>(this.CalculateTotalSupply); this.playerIndex.Write(playerIndex); this.startLocation.Write(startLocation); this.startPosition.Write(startLocation.MotionControl.PositionVector.Read()); this.quadraticStartPosition.Write(startLocation.MapObject.QuadraticPosition); this.buildings = new Dictionary <string, RCSet <Building> >(); this.addons = new Dictionary <string, RCSet <Addon> >(); this.units = new Dictionary <string, RCSet <Unit> >(); this.upgrades = new Dictionary <string, Upgrade>(); this.minerals.Write(INITIAL_MINERALS); this.vespeneGas.Write(INITIAL_VESPENE_GAS); this.lockedSupplies.Write(0); }