/// <summary> /// Creates any combat events that will result in the launch. /// </summary> private void CreateCombatEvents() { // Create the combat event for arrival RftVector targetPosition = this._destination.GetTargetPosition(_source.GetCurrentPosition(), this._launchedSub.GetSpeed()); GameTick arrival = this._launchTime.Advance((int)Math.Floor((targetPosition - _source.GetCurrentPosition()).Magnitude() / this._launchedSub.GetSpeed())); CombatEvent arriveCombat = new CombatEvent(this._launchedSub, this._destination, arrival, targetPosition); _combatEvents.Add(arriveCombat); Game.TimeMachine.AddEvent(arriveCombat); // Determine any combat events that may exist along the way. // First determine if any subs are on the same path. // Subs will only be on the same path if it is outpost to outpost if (this._destination.GetType().Equals(typeof(Outpost)) && this._source.GetType().Equals(typeof(Outpost))) { // Interpolate to launch time to determine combats! GameTick currentTick = Game.TimeMachine.GetCurrentTick(); Game.TimeMachine.GoTo(this.GetTick()); GameState interpolatedState = Game.TimeMachine.GetState(); foreach (Sub sub in interpolatedState.getSubsOnPath((Outpost)this._source, (Outpost)this._destination)) { // Don't combat with yourself if (sub == this.GetActiveSub()) { continue; } // Determine if we combat it if (sub.GetDirection() == this.GetActiveSub().GetDirection()) { if (this.GetActiveSub().GetExpectedArrival() < sub.GetExpectedArrival()) { // We can catch it. Determine when and create a combat event. } } else { // Sub is moving towards us. if (sub.GetOwner() != this.GetActiveSub().GetOwner()) { // Combat will occur // Determine when and create a combat event. // Determine the number of ticks between the incoming sub & the launched sub. int ticksBetweenSubs = sub.GetExpectedArrival() - this._launchTime; // Determine the speed ratio as a number between 0-0.5 double speedRatio = (sub.GetSpeed() / this.GetActiveSub().GetSpeed()) - 0.5; int ticksUntilCombat = (int)Math.Floor(speedRatio * ticksBetweenSubs); // Determine collision position: RftVector combatPosition = new RftVector(RftVector.Map, this.GetActiveSub().GetDirection() * ticksUntilCombat); CombatEvent combatEvent = new CombatEvent(sub, this.GetActiveSub(), this._launchTime.Advance(ticksUntilCombat), combatPosition); _combatEvents.Add(combatEvent); Game.TimeMachine.AddEvent(combatEvent); } } } // Go back to the original point in time. Game.TimeMachine.GoTo(currentTick); } }
/// <summary> /// Generates a set of outposts for one player based on the map generation configurations. /// </summary> /// <returns>A list of a single player's outposts</returns> public List <Outpost> GeneratePlayerOutposts() { // List of a player's outposts. List <Outpost> playerOutposts = new List <Outpost>(); // setup variables double direction; double distance; bool usableLocation = true; int x, y, idx; RftVector vectorDistance; RftVector currentOutpostPosition; Outpost currentOutpost, otherOutpost; // Loop to generate outposts until the number of generated outposts is valid while (playerOutposts.Count < this.Configuration.OutpostsPerPlayer + this.Configuration.DormantsPerPlayer) { // calculate the new outposts location within allowable raidius distance = this.RandomGenerator.NextDouble() * (this.Configuration.MaxiumumOutpostDistance - this.Configuration.MinimumOutpostDistance) + this.Configuration.MinimumOutpostDistance; direction = this.RandomGenerator.NextDouble() * Math.PI * 2; // In radians // Determine the type of outpost that is generated OutpostType[] validTypes = { OutpostType.Factory, OutpostType.Generator, OutpostType.Watchtower, }; OutpostType type = validTypes[this.RandomGenerator.NextRand(0, 3)]; //convert distance & direction into vector X and Y x = Convert.ToInt32(Math.Cos(direction) * distance); y = Convert.ToInt32(Math.Sin(direction) * distance); currentOutpostPosition = new RftVector(map, x, y); usableLocation = true; // Determine if the generated location is too close to another outpost for (idx = 0; idx < playerOutposts.Count & usableLocation; idx++) { // Get the X and Y pos to find distance otherOutpost = playerOutposts[idx]; vectorDistance = otherOutpost.GetCurrentPosition() - currentOutpostPosition; //ensure that the new location is not too close to other outposts if (vectorDistance.Magnitude() < this.Configuration.MinimumOutpostDistance) { usableLocation = false; } } // If the location is not too close to another outpost, add the outpost to the list. if (usableLocation || playerOutposts.Count == 0) { currentOutpost = new Outpost(generator.GetNextId(), currentOutpostPosition, type); currentOutpost.Name = this.NameGenerator.GetRandomName(); playerOutposts.Add(currentOutpost); } } // Return list of generated outposts. return(playerOutposts); }