private void CreateLocalLists() { foreach (Robot robot in BaseFile.Robots) { Robots.Add(robot); } foreach (Weapon weapon in BaseFile.Weapons) { Weapons.Add(weapon); } foreach (Polymodel model in BaseFile.Models) { Models.Add(model); } foreach (JointPos joint in BaseFile.Joints) { Joints.Add(joint); } foreach (ushort bm in BaseFile.ObjBitmaps) { ObjBitmaps.Add(bm); } foreach (ushort bm in BaseFile.ObjBitmapPointers) { ObjBitmapPointers.Add(bm); } }
public override void DoService(IRobot robot, int procedureTime) { base.DoService(robot, procedureTime); robot.Happiness -= 3; robot.Energy += 10; Robots.Add(robot); }
public override void DoService(IRobot robot, int procedureTime) { base.DoService(robot, procedureTime); robot.ProcedureTime -= procedureTime; robot.Happiness -= 7; Robots.Add(robot); }
void NXT_RobotAdded(object sender, AvailableDevicesChangedEventArgs args) { // Modification to the observable collection must take place on the ui thread uiDispatcher.BeginInvoke(new ThreadStart(() => { Robots.Add(new NXTViewModel(args.AffectedDevice)); })); }
public override void DoService(IRobot robot, int procedureTime) { if (procedureTime > robot.ProcedureTime) { throw new ArgumentException("Robot doesn't have enough procedure time"); } robot.Happiness -= 3; robot.Energy += 10; robot.ProcedureTime -= procedureTime; Robots.Add(robot); }
private void CreateRobot(params Capability[] capabilities) { var robot = new Robot(capabilities.OfType <ProcessCapability>().ToArray()); var agent = new RobotAgent(capabilities, robot); Robots.Add(robot); RobotAgents.Add(agent); robot.SetNames(Robots.Count - 1); agent.Name = $"R{Robots.Count - 1}"; agent.ConfigurationUpdateFailed.Name = agent.Name + ".ConfigUpdateFailed"; }
public override void DoService(IRobot robot, int procedureTime) { base.DoService(robot, procedureTime); if (robot.IsChipped) { throw new ArgumentException (String.Format(ExceptionMessages.AlreadyChipped, robot.Name)); } robot.Happiness -= 5; robot.IsChipped = true; Robots.Add(robot); }
public override void DoService(IRobot robot, int procedureTime) { base.DoService(robot, procedureTime); robot.Energy -= 8; if (robot.IsChecked) { robot.Energy -= 8; } robot.ProcedureTime -= procedureTime; robot.IsChecked = true; Robots.Add(robot); }
public void RandomizeStartOrder() { var tempRobots = Robots.Select(r => r).ToList(); Robots.Clear(); var random = new Random(); while (tempRobots.Count > 0) { var min = 0; var max = tempRobots.Count; var index = random.Next(min, max); Robots.Add(tempRobots[index]); tempRobots.Remove(tempRobots[index]); } }
public override void DoService(IRobot robot, int procedureTime) { if (procedureTime > robot.ProcedureTime) { throw new ArgumentException("Robot doesn't have enough procedure time"); } if (robot.IsChecked) { robot.Energy -= 16; return; } robot.Energy -= 8; robot.IsChecked = true; robot.ProcedureTime -= procedureTime; Robots.Add(robot); }
public void RegisterRobot(string robotId, PlayType playType) { var reader = new RobotReader(); Robot robot = reader.GetRobotInfo(robotId); robot.PlayType = playType; robot.Status = new RobotStatus(); Robots.Add(robot); if (Robots.Count == BattleFieldCapacity) { SetRobotsEnemies(); } robot.Ready = true; }
/// <summary>place a robot with a given id and direction on the board </summary> /// <exception cref="System.Exception">Throws when allowed robot limit is reached </exception> /// <exception cref="System.Exception">Throws when x and y position are invalid </exception> public void Place(Guid robotId, int x, int y, Direction direction) { var robot = Robots.FirstOrDefault(r => r.RobotId == robotId); if (robot == null) { if (Robots.Count >= NumberOfRobotsAllowed) { throw new Exception("Unable to place any more robots on the board as you have reached the allowed limit"); } robot = new Robot.Robot(direction, robotId); Robots.Add(robot); } else { robot.Direction = direction; } _board.Place(robotId, x, y); }
public virtual void Execute() { while (true) { Write1stLineOfOutput(); var cordsAndOrientation = ReadPlaneCordinates(); string[] RobotLocations = GetLocationArray(cordsAndOrientation); if (RobotLocations.Length != 3) { throw new ArgumentException("Robot Locations should be valid"); } var x = -1; var y = -1; Int32.TryParse(RobotLocations[0], out x); Int32.TryParse(RobotLocations[1], out y); var orientation = RobotLocations[2].Substring(0, 1).ToUpper(); var robot1 = new Robot(Plane); OrientationPosition.Orientation actualOrientation = OrientationPosition.Orientation.N; Enum.TryParse(orientation, out actualOrientation); robot1.Orientation = actualOrientation; robot1.Location = new Location { X = x, Y = y }; Robots.Add(robot1); Write2ndLineOfOutput(); var controlSequence = ReadControlSequence(); MoveRobotSequence(controlSequence, Controller, robot1); Write3rdLineOfOutput(); var anotherRobot = ReadToAddAnotherRobot(); if (!anotherRobot.ToLower().StartsWith("y", StringComparison.OrdinalIgnoreCase)) { break; } } Controller.Robots = Robots.ToArray(); Write4thLineOfOutput(); foreach (var Robot in Controller.Robots) { WriteResults(Robot.Location.X, Robot.Location.Y, Robot.Orientation.ToString()); } }
//– removes 5 happiness and chips current robot.Robot can be chipped once.If robot is already chipped throw an ArgumentException with message "{robot name} is already chipped" public override void DoService(IRobot robot, int procedureTime) { if (procedureTime > robot.ProcedureTime) { throw new ArgumentException("Robot doesn't have enough procedure time"); } robot.Happiness -= 5; if (robot.IsChipped) { throw new ArgumentException($"{robot.Name} is already chipped"); } robot.IsChipped = true; robot.ProcedureTime -= procedureTime; Robots.Add(robot); }
public void CreateRobot(Robot protoRobot, Tile tile, float charge = 0) { if (protoRobot == null || tile == null || protoRobot.Cost > Resources && charge == 0) { return; } var robotToCreate = new Robot(protoRobot); Robots.Add(robotToCreate); robotToCreate.Tile = robotToCreate.Destination = robotToCreate.NextTile = tile; if (charge == 0) { Resources -= robotToCreate.Cost; } if (charge > 0) { robotToCreate.Charge = charge; } OnChange(); }
public void Init(SimulationParameters parameters) { Medium ether = new Medium(); PassedTime = 0; TimeOfDay = 0; Buildings = parameters.buildings; NotAdministratedBuildings = parameters.buildings; Warehouses = parameters.warehouses; Vector3 offset = new Vector3(); foreach (var item in parameters.robots) { item.robot.Init(1000, ether); var soft = Activator.CreateInstance(item.soft) as RobotOperatingSystem; soft.Init(item.robot); Robots.Add(item.robot); Debug.Log(string.Format("Installed {0} on {1}", item.soft.Name, item.robot.GetType().Name)); if (soft.GetType() == typeof(TransporterSoftware)) { Vector3 pos = (soft as TransporterSoftware).FindClosestWarehouse(); item.robot.MoveOrder(pos + offset); offset.x += 0.5F; } } foreach (var warehouse in parameters.warehouses) { warehouse.SetPreview(false); warehouse.FillWithMaterials(); } foreach (var building in parameters.buildings) { building.ClearMaterials(); building.SetFrame(0); building.SetActual(); } CycleActive = true; }
private void OnDetectedRobotChanged(object sender, NotifyCollectionChangedEventArgs e) { //実装側がそういうシステムなので基本的にAdd/Removeのどちらか片方しか生じない if (e.Action == NotifyCollectionChangedAction.Add) { foreach (var robot in e.NewItems.OfType <DetectedRobot>()) { Robots.Add(CreateDetectedRobotViewModel(robot)); } } else if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (var robot in e.NewItems.OfType <DetectedRobot>()) { var target = Robots.FirstOrDefault(r => r.HasRobot(robot)); if (target != null) { Robots.Remove(target); } } } }
public void Read(Stream stream) { BinaryReader br; br = new BinaryReader(stream); HAMDataReader bm = new HAMDataReader(); int sig = br.ReadInt32(); if (sig != 0x214D4148) { br.Dispose(); throw new InvalidDataException("HAMFile::Read: HAM file has bad header."); } Version = br.ReadInt32(); if (Version < 2 || Version > 3) { br.Dispose(); throw new InvalidDataException(string.Format("HAMFile::Read: HAM file has bad version. Got {0}, but expected \"2\" or \"3\"", Version)); } int sndptr = 0; if (Version == 2) { sndptr = br.ReadInt32(); } int NumBitmaps = br.ReadInt32(); for (int x = 0; x < NumBitmaps; x++) { Textures.Add(br.ReadUInt16()); } for (int x = 0; x < NumBitmaps; x++) { TMapInfo.Add(bm.ReadTMAPInfo(br)); TMapInfo[x].ID = x; } int NumSounds = br.ReadInt32(); if (NumSounds > 254) { throw new InvalidDataException("HAM file specifies more than 254 sounds."); } for (int x = 0; x < NumSounds; x++) { Sounds[x] = br.ReadByte(); } for (int x = 0; x < NumSounds; x++) { AltSounds[x] = br.ReadByte(); } int NumVClips = br.ReadInt32(); for (int x = 0; x < NumVClips; x++) { VClips.Add(bm.ReadVClip(br)); VClips[x].ID = x; } int NumEClips = br.ReadInt32(); for (int x = 0; x < NumEClips; x++) { EClips.Add(bm.ReadEClip(br)); EClips[x].ID = x; } int NumWallAnims = br.ReadInt32(); for (int x = 0; x < NumWallAnims; x++) { WClips.Add(bm.ReadWClip(br)); } int NumRobots = br.ReadInt32(); for (int x = 0; x < NumRobots; x++) { Robots.Add(bm.ReadRobot(br)); Robots[x].ID = x; } int NumLoadJoints = br.ReadInt32(); for (int x = 0; x < NumLoadJoints; x++) { JointPos joint = new JointPos(); joint.JointNum = br.ReadInt16(); joint.Angles.P = br.ReadInt16(); joint.Angles.B = br.ReadInt16(); joint.Angles.H = br.ReadInt16(); Joints.Add(joint); } int NumWeaponTypes = br.ReadInt32(); for (int x = 0; x < NumWeaponTypes; x++) { if (Version >= 3) { Weapons.Add(bm.ReadWeapon(br)); } else { Weapons.Add(bm.ReadWeaponInfoVersion2(br)); } Weapons[x].ID = x; } int NumPowerups = br.ReadInt32(); for (int x = 0; x < NumPowerups; x++) { Powerup powerup = new Powerup(); powerup.VClipNum = br.ReadInt32(); powerup.HitSound = br.ReadInt32(); powerup.Size = new Fix(br.ReadInt32()); powerup.Light = new Fix(br.ReadInt32()); powerup.ID = x; Powerups.Add(powerup); } int NumPolygonModels = br.ReadInt32(); for (int x = 0; x < NumPolygonModels; x++) { Models.Add(bm.ReadPolymodelInfo(br)); Models[x].ID = x; } for (int x = 0; x < NumPolygonModels; x++) { Models[x].InterpreterData = br.ReadBytes(Models[x].ModelIDTASize); //PolymodelData.Add(modeldata); } for (int x = 0; x < NumPolygonModels; x++) { Models[x].DyingModelnum = br.ReadInt32(); } for (int x = 0; x < NumPolygonModels; x++) { Models[x].DeadModelnum = br.ReadInt32(); } int gagueCount = br.ReadInt32(); for (int x = 0; x < gagueCount; x++) { Gauges.Add(br.ReadUInt16()); } for (int x = 0; x < gagueCount; x++) { GaugesHires.Add(br.ReadUInt16()); } int bitmapCount = br.ReadInt32(); for (int x = 0; x < bitmapCount; x++) { ObjBitmaps.Add(br.ReadUInt16()); } ushort value; for (int x = 0; x < bitmapCount; x++) { value = br.ReadUInt16(); if ((value + 1) > NumObjBitmaps) { NumObjBitmaps = (value + 1); } ObjBitmapPointers.Add(value); } PlayerShip = new Ship(); PlayerShip.ModelNum = br.ReadInt32(); PlayerShip.DeathVClipNum = br.ReadInt32(); PlayerShip.Mass = new Fix(br.ReadInt32()); PlayerShip.Drag = new Fix(br.ReadInt32()); PlayerShip.MaxThrust = new Fix(br.ReadInt32()); PlayerShip.ReverseThrust = new Fix(br.ReadInt32()); PlayerShip.Brakes = new Fix(br.ReadInt32()); PlayerShip.Wiggle = new Fix(br.ReadInt32()); PlayerShip.MaxRotationThrust = new Fix(br.ReadInt32()); for (int x = 0; x < 8; x++) { PlayerShip.GunPoints[x] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); } int NumCockpits = br.ReadInt32(); for (int x = 0; x < NumCockpits; x++) { Cockpits.Add(br.ReadUInt16()); } //Build a table of all multiplayer bitmaps, to inject into the object bitmap table FirstMultiBitmapNum = br.ReadInt32(); int NumReactors = br.ReadInt32(); for (int x = 0; x < NumReactors; x++) { Reactor reactor = new Reactor(); reactor.ModelNum = br.ReadInt32(); reactor.NumGuns = br.ReadInt32(); for (int y = 0; y < 8; y++) { reactor.GunPoints[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); } for (int y = 0; y < 8; y++) { reactor.GunDirs[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); } Reactors.Add(reactor); } PlayerShip.MarkerModel = br.ReadInt32(); //2620 if (Version < 3) { ExitModelnum = br.ReadInt32(); DestroyedExitModelnum = br.ReadInt32(); } for (int x = 0; x < 2620; x++) { try { BitmapXLATData[x] = br.ReadUInt16(); } catch (EndOfStreamException) //Descent 2's official HAM files have only 2600 XLAT entries, but later versions of the game attempt to read 2620. { break; } } if (Version < 3) { br.BaseStream.Seek(sndptr, SeekOrigin.Begin); int dataToRead = (int)(br.BaseStream.Length - br.BaseStream.Position); sounddata = br.ReadBytes(dataToRead); } hasRead = true; //br.Dispose(); }
private void FillWithTestData() { // создали по одной сущности в каждый из списков var user = new User { Login = MoqDataGenerator.GetRandomString(10), Password = MoqDataGenerator.GetRandomString(10), UserID = 1 }; var robot = new Robot { RobotID = MoqDataGenerator.GetRandomNumber(1, 100), Configurations = new List <Configuration>(), ProgramRobots = new List <ProgramRobot>(), ActivationCode = MoqDataGenerator.GetRandomNumber(1, 100) }; var program = CreateProgram(id: 1); var configuration = new Configuration { ConfigurationID = MoqDataGenerator.GetRandomNumber(10, 100), Port = MoqDataGenerator.GetRandomNumber(10, 11111) }; var programRobot = new ProgramRobot { ProgramRobotID = MoqDataGenerator.GetRandomNumber(10, 100) }; var image = new Image { ImageMimeType = MoqDataGenerator.GetRandomString(10), ImageData = MoqDataGenerator.GetSomeBytes(), ImageID = 1, Name = MoqDataGenerator.GetRandomString(10) }; var robotCommand = new RobotCommand { RobotCommandID = MoqDataGenerator.GetRandomNumber(10, 100), Type = 0 }; // добавили связи между сущностями robot.Configurations.Add(configuration); robot.ProgramRobots.Add(programRobot); robot.User = user; robot.UserID = user.UserID; configuration.Robot = robot; configuration.RobotID = robot.RobotID; program.ProgramRobots.Add(programRobot); program.Image = image; program.ImageID = image.ImageID; programRobot.Robot = robot; programRobot.Program = program; programRobot.RobotID = robot.RobotID; programRobot.ProgramID = program.ProgramID; programRobot.CurrentVersion = program.ActualVersion - 1; robotCommand.Argument = program.ProgramID; robotCommand.Robot = robot; robotCommand.RobotID = robot.RobotID; // добавили сущности в списки сущностей Robots.Add(robot); Programs.Add(program); Configurations.Add(configuration); ProgramRobots.Add(programRobot); Users.Add(user); RobotCommands.Add(robotCommand); Images.Add(image); // добавили еще 4 программы для теста pagination for (var i = 0; i < 4; i++) { Programs.Add(CreateProgram(i + 2)); } }
//--------------------------------------------------------------------- // READING //--------------------------------------------------------------------- /// <summary> /// Converts all the base file's data classes into the editor class for that type. /// </summary> public void CreateLocalLists() { //TODO: This is just passthrough for now, need "editor" classes foreach (ushort texture in BaseFile.Textures) { Textures.Add(texture); } foreach (TMAPInfo tmapInfo in BaseFile.TMapInfo) { TMapInfo.Add(tmapInfo); } Array.Copy(BaseFile.Sounds, Sounds, 254); Array.Copy(BaseFile.AltSounds, AltSounds, 254); foreach (VClip clip in BaseFile.VClips) { VClips.Add(clip); } foreach (EClip clip in BaseFile.EClips) { EClips.Add(clip); } foreach (WClip clip in BaseFile.WClips) { WClips.Add(clip); } foreach (Robot robot in BaseFile.Robots) { Robots.Add(robot); } foreach (JointPos joint in BaseFile.Joints) { Joints.Add(joint); } foreach (Weapon weapon in BaseFile.Weapons) { Weapons.Add(weapon); } foreach (Polymodel model in BaseFile.Models) { Models.Add(model); } foreach (ushort gauge in BaseFile.Gauges) { Gauges.Add(gauge); } foreach (ushort gauge in BaseFile.GaugesHires) { GaugesHires.Add(gauge); } PlayerShip = BaseFile.PlayerShip; foreach (ushort cockpit in BaseFile.Cockpits) { Cockpits.Add(cockpit); } foreach (Reactor reactor in BaseFile.Reactors) { Reactors.Add(reactor); } foreach (Powerup powerup in BaseFile.Powerups) { Powerups.Add(powerup); } FirstMultiBitmapNum = BaseFile.FirstMultiBitmapNum; for (int i = 0; i < 2620; i++) { BitmapXLATData[i] = BaseFile.BitmapXLATData[i]; } foreach (ushort bm in BaseFile.ObjBitmaps) { ObjBitmaps.Add(bm); } foreach (ushort bm in BaseFile.ObjBitmapPointers) { ObjBitmapPointers.Add(bm); } }
public void Read(Stream stream) { BinaryReader br; br = new BinaryReader(stream); HAMDataReader bm = new HAMDataReader(); uint sig = br.ReadUInt32(); if (sig != Util.MakeSig('M', 'A', 'H', 'X')) { br.Dispose(); throw new InvalidDataException("VHAMFile::Read: V-HAM file has bad header."); } int version = br.ReadInt32(); if (version != 1) { br.Dispose(); throw new InvalidDataException(string.Format("VHAMFile::Read: V-HAM file has bad version. Got {0}, but expected 1.", version)); } int numWeapons = br.ReadInt32(); for (int i = 0; i < numWeapons; i++) { Weapons.Add(bm.ReadWeapon(br)); Weapons[i].ID = i + NumDescent2WeaponTypes; } int numRobots = br.ReadInt32(); for (int i = 0; i < numRobots; i++) { Robots.Add(bm.ReadRobot(br)); Robots[i].ID = i + NumDescent2RobotTypes; } int numJoints = br.ReadInt32(); for (int i = 0; i < numJoints; i++) { JointPos joint = new JointPos(); joint.JointNum = br.ReadInt16(); joint.Angles.P = br.ReadInt16(); joint.Angles.B = br.ReadInt16(); joint.Angles.H = br.ReadInt16(); Joints.Add(joint); } int numModels = br.ReadInt32(); for (int i = 0; i < numModels; i++) { Models.Add(bm.ReadPolymodelInfo(br)); Models[i].ID = i + NumDescent2Polymodels; } for (int x = 0; x < numModels; x++) { Models[x].InterpreterData = br.ReadBytes(Models[x].ModelIDTASize); } for (int i = 0; i < numModels; i++) { Models[i].DyingModelnum = br.ReadInt32(); } for (int i = 0; i < numModels; i++) { Models[i].DeadModelnum = br.ReadInt32(); } int numObjBitmaps = br.ReadInt32(); for (int i = 0; i < numObjBitmaps; i++) { ObjBitmaps.Add(br.ReadUInt16()); } int numObjBitmapPointers = br.ReadInt32(); for (int i = 0; i < numObjBitmapPointers; i++) { ObjBitmapPointers.Add(br.ReadUInt16()); } br.Dispose(); }
void AddRobot(RobotConnectionInfo conn) { Robots.Add(CreateRobot(conn)); }