public void CanLaunchSubs() { List <Player> players = new List <Player>(); players.Add(new Player("1")); Game game = new Game(_testUtils.GetDefaultGameConfiguration(players)); game.TimeMachine.GetState().GetOutposts().Add(_outpost); game.TimeMachine.GetState().GetOutposts().Add(_outpost2); int initialDrillers = _outpost.GetComponent <DrillerCarrier>().GetDrillerCount(); _outpost.GetComponent <SubLauncher>().LaunchSub(game.TimeMachine.GetState(), new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = _outpost.GetComponent <IdentityManager>().GetId(), DrillerCount = 10, SourceId = _outpost2.GetComponent <IdentityManager>().GetId(), }.ToByteString(), Id = "123", EventType = EventType.LaunchEvent, OccursAtTick = 10, })); Assert.AreEqual(initialDrillers - 10, _outpost.GetComponent <DrillerCarrier>().GetDrillerCount()); Assert.AreEqual(1, game.TimeMachine.GetState().GetSubList().Count); }
public void DrillFirstMine() { _o1.GetComponent <DrillerCarrier>().AddDrillers(50); DrillMineEvent drillMine = new DrillMineEvent(_model1); _tm.AddEvent(drillMine); _tm.Advance(10); Assert.IsTrue(drillMine.WasEventSuccessful()); Assert.IsFalse(_tm.GetState().GetOutposts().Contains(_o1)); }
/// <summary> /// Undoes the sub's arrival /// </summary> /// <returns>If the event was undone</returns> public override bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (EventSuccess) { _outpost.GetComponent <DrillerCarrier>().RemoveDrillers(_arrivingSub.GetComponent <DrillerCarrier>().GetDrillerCount()); _outpost.GetComponent <SpecialistManager>() .RemoveSpecialists(_arrivingSub.GetComponent <SpecialistManager>().GetSpecialists()); state.AddSub(this._arrivingSub); return(true); } return(false); }
public void MinimumOutpostDistanceRespected() { List <Player> players = new List <Player> { new Player("1") }; GameConfiguration config = _testUtils.GetDefaultGameConfiguration(players); Assert.IsNotNull(config); Random rand = new Random(DateTime.Now.Millisecond); config.MapConfiguration.Seed = rand.Next(); config.MapConfiguration.DormantsPerPlayer = 0; config.MapConfiguration.MaximumOutpostDistance = 2; config.MapConfiguration.MinimumOutpostDistance = 1; config.MapConfiguration.OutpostsPerPlayer = 2; MapGenerator generator = new MapGenerator(config.MapConfiguration, players); List <Outpost> generatedOutposts = generator.GenerateMap(); // Ensure the distance between outposts is over 199. Assert.AreEqual(2, generatedOutposts.Count); // Ensure the distance between the two is respected. Outpost outpost1 = generatedOutposts[0]; Outpost outpost2 = generatedOutposts[1]; float distance = (outpost1.GetComponent <PositionManager>().GetPositionAt(new GameTick(0)) - outpost2.GetComponent <PositionManager>().GetPositionAt(new GameTick(0))).Magnitude(); Assert.IsTrue(distance >= config.MapConfiguration.MinimumOutpostDistance); }
public void Setup() { _p = new Player("Player 1"); List <Player> playerlist = new List <Player>(); playerlist.Add(_p); GameConfiguration config = testUtils.GetDefaultGameConfiguration(playerlist); config.MapConfiguration.OutpostsPerPlayer = 12; _game = new Game(config); _tm = _game.TimeMachine; _o1 = _tm.GetState().GetPlayerOutposts(_p)[0]; _o2 = _tm.GetState().GetPlayerOutposts(_p)[1]; _model1 = new GameEventModel() { EventData = new DrillMineEventData() { SourceId = _o1.GetComponent <IdentityManager>().GetId() }.ToByteString(), Id = Guid.NewGuid().ToString(), EventType = EventType.DrillMineEvent, OccursAtTick = 10 }; _model2 = new GameEventModel() { EventData = new DrillMineEventData() { SourceId = _o2.GetComponent <IdentityManager>().GetId() }.ToByteString(), Id = Guid.NewGuid().ToString(), EventType = EventType.DrillMineEvent, OccursAtTick = 20 }; }
/// <summary> /// Translates a given set of outposts by a set amount, duplicating the outposts at a different coordinate location. /// Result from this function is a newly generated set of outposts offset by the specified translation. /// </summary> /// <param name="outposts">A list of outposts to translate</param> /// <param name="translation">The translation to apply</param> /// <returns>A list of translated outposts</returns> private List <Outpost> TranslateOutposts(List <Outpost> outposts, RftVector translation) { // Generate a random rotation of 0/90/180/270 so the map doesn't appear to be tiled. double rotation = _randomGenerator.NextRand(0, 3) * Math.PI / 2; // List to store the newly translated outposts List <Outpost> translatedOutposts = new List <Outpost>(); // Loop through the original outposts. foreach (Outpost outpost in outposts) { // Get original outpost location RftVector position = outpost.GetComponent <PositionManager>().GetPositionAt(new GameTick(0)); // New vector for the copied location RftVector newPosition = new RftVector(RftVector.Map, position.X, position.Y); // Undo the rotation and apply a new rotation. // https://stackoverflow.com/questions/620745/c-rotating-a-vector-around-a-certain-point double cs = Math.Cos(rotation); double sn = Math.Sin(rotation); double translatedX = position.X; double translatedY = position.Y; double resultX = translatedX * cs - translatedY * sn; double resultY = translatedY * cs - translatedX * sn; resultX += _mapConfiguration.MaximumOutpostDistance; resultY += _mapConfiguration.MaximumOutpostDistance; newPosition.X = (float)resultX; newPosition.Y = (float)resultY; // Apply the translation to offset the outpost. newPosition += translation; // Add a new outpost to the translated outposts list Outpost newOutpost = CreateOutpost(newPosition, outpost.GetOutpostType()); newOutpost.GetComponent <DrillerCarrier>().SetOwner(outpost.GetComponent <DrillerCarrier>().GetOwner()); newOutpost.GetComponent <IdentityManager>().SetName(_nameGenerator.GetRandomName()); translatedOutposts.Add(newOutpost); } // Return the translated outposts. return(translatedOutposts); }
/// <summary> /// Validates an outpost /// </summary> /// <param name="state">The game state</param> /// <param name="outpost">The outpost to validate</param> /// <returns>If the outpost is valid</returns> public static bool ValidateOutpost(GameState.GameState state, Outpost outpost) { if (outpost == null) { return(false); } if (!state.OutpostExists(outpost)) { return(false); } if (outpost.GetComponent <DrillerCarrier>().GetDrillerCount() < 0) { return(false); } if (outpost.GetComponent <SpecialistManager>() == null) { return(false); } if (outpost.GetComponent <SpecialistManager>().GetSpecialistCount() < 0) { return(false); } if (outpost.GetComponent <SpecialistManager>().GetSpecialistCount() > outpost.GetComponent <SpecialistManager>().GetCapacity()) { return(false); } if (outpost.GetComponent <DrillerCarrier>().GetOwner() != null && !state.PlayerExists(outpost.GetComponent <DrillerCarrier>().GetOwner())) { return(false); } return(true); }
public void Setup() { _player1 = new Player("1"); List <Player> players = new List <Player>(); GameConfiguration config = testUtils.GetDefaultGameConfiguration(players); Assert.IsNotNull(config); _state = new GameState(config); _map = new Rft(300, 300); _outpost = new Generator("0", new RftVector(_map, 0, 0), _player1); _outpost.GetComponent <DrillerCarrier>().AddDrillers(10); _tempSub = new Sub("1", _outpost, _outpost, new GameTick(), 10, _player1); }
/// <summary> /// Determine all subs that are on a path between two outpost desinations /// </summary> /// <param name="source">The source outpost</param> /// <param name="destination">The destination outpost</param> /// <returns>A list of all subs sailing between the source and destination</returns> public List <Sub> getSubsOnPath(Outpost source, Outpost destination) { List <Sub> subsOnPath = new List <Sub>(); // Check if a sub is on that path // This logic is not nessicarily true.. // If a sub has a navigator this logic kind of falls apart. foreach (Sub sub in this._activeSubs) { if ( sub.GetComponent <PositionManager>().GetExpectedDestination() == destination.GetComponent <PositionManager>().GetPositionAt(CurrentTick) || sub.GetComponent <PositionManager>().GetPositionAt(CurrentTick) == source.GetComponent <PositionManager>().GetPositionAt(CurrentTick)) { // TODO: // if (sub.GetComponent<PositionManager>().GetSource() == source || sub.GetComponent<PositionManager>().GetSource() == destination) // { // // Sub is on the path. // subsOnPath.Add(sub); // } } } return(subsOnPath); }
public void HasDrillerCarrier() { Assert.IsNotNull(_outpost.GetComponent <DrillerCarrier>()); }