public void Init(Transform _target, string beatType, PlayerDirection _direction) { beat = BeatFactory.GetBeat(beatType); currentSection = MapUtil.getCurrentSection(); KeyToPress = BeatUtil.GetKeyCodeFromDirection(_direction); canBePresssed = false; target = _target; direction = _direction; lifeTime = 0f; transform.rotation = _target.rotation; SpriteRenderer spr = GetComponent <SpriteRenderer>(); spr.color = _target.GetComponent <SpriteRenderer>().color; }
private void InitializeStructures() { MapSection section = GetSection("Structures"); if (section != null) { structures = new List <Structure>(); foreach (KeyValuePair <string, string> entry in section.Entries) { string[] parts = entry.Value.Split(','); if (parts.Length >= 17) { try { string owner = parts[0].Trim(); string structureID = parts[1].Trim(); int health = int.Parse(parts[2], NumberStyles.Integer); int x = int.Parse(parts[3], NumberStyles.Integer); int y = int.Parse(parts[4], NumberStyles.Integer); int facing = int.Parse(parts[5], NumberStyles.Integer); string tag = parts[6].Trim(); int sellable = int.Parse(parts[7], NumberStyles.Integer); int rebuildable = int.Parse(parts[8], NumberStyles.Integer); int poweredOn = int.Parse(parts[9], NumberStyles.Integer); int upgradesCount = int.Parse(parts[10], NumberStyles.Integer); int spotlight = int.Parse(parts[11], NumberStyles.Integer); string upgrade1 = parts[12].Trim(); string upgrade2 = parts[13].Trim(); string upgrade3 = parts[14].Trim(); int repairable = int.Parse(parts[15], NumberStyles.Integer); int nominal = int.Parse(parts[16], NumberStyles.Integer); structures.Add(new Structure(owner, structureID, health, x, y, facing, tag, sellable, rebuildable, poweredOn, upgradesCount, spotlight, upgrade1, upgrade2, upgrade3, repairable, nominal)); } catch (Exception) { log.Error("Error reading Structures entry with index: " + entry.Key); } } else { log.Error("Error reading Structures entry having less parameters with index: " + entry.Key); } } } }
private MapSection GetSection(string sectionName) { MapSection mapSection = null; if (MapSections != null && !String.IsNullOrEmpty(sectionName)) { try { mapSection = MapSections.Find(section => section.Name.Equals(sectionName)); } catch (Exception) { log.Info("Section not found: [" + sectionName + "]"); } } return(mapSection); }
private void InitializeUnits() { MapSection section = GetSection("Units"); if (section != null) { units = new List <Unit>(); foreach (KeyValuePair <string, string> entry in section.Entries) { string[] parts = entry.Value.Split(','); if (parts.Length >= 14) { try { string index = entry.Key; string owner = parts[0].Trim(); string unitID = parts[1].Trim(); int health = int.Parse(parts[2], NumberStyles.Integer); int x = int.Parse(parts[3], NumberStyles.Integer); int y = int.Parse(parts[4], NumberStyles.Integer); int facing = int.Parse(parts[5], NumberStyles.Integer); string mission = parts[6].Trim(); string tag = parts[7].Trim(); int veterancy = int.Parse(parts[8], NumberStyles.Integer); int group = int.Parse(parts[9], NumberStyles.Integer); int highOnBridge = int.Parse(parts[10], NumberStyles.Integer); string followerIndex = parts[11].Trim(); int acNoRecruitable = int.Parse(parts[12], NumberStyles.Integer); int acYesRecruitable = int.Parse(parts[13], NumberStyles.Integer); units.Add(new Unit(index, owner, unitID, health, x, y, facing, mission, tag, veterancy, group, highOnBridge, followerIndex, acNoRecruitable, acYesRecruitable)); } catch (Exception) { log.Error("Error reading Unit entry with index: " + entry.Key); } } else { log.Error("Error reading Unit entry having less parameters with index: " + entry.Key); } } } }
public void TestRequiresQuadPrecision() { string connectionId = "dummy"; int maxIterations = 100; CanvasSize canvasSize = new CanvasSize(1000, 1000); //DPoint leftBot = new DPoint(-0.7764118407199196, 0.13437492059936854); //DPoint rightTop = new DPoint(-0.7764117329761986, 0.13437499747905846); SPoint leftBot = new SPoint("-0.7764118407199196", "0.13437492059936854"); SPoint rightTop = new SPoint("-0.7764118407199300", "0.13437499747905846"); SCoords coords = new SCoords(leftBot, rightTop); MapSection area = new MapSection(new Point(0, 0), canvasSize.GetWholeUnits(Engine.BLOCK_SIZE)); SMapWorkRequest mapWorkRequest = new SMapWorkRequest("FET2", coords, canvasSize, area, maxIterations, connectionId); bool requiresQuadPrecision = mapWorkRequest.RequiresQuadPrecision(); }
void PlaceEnemy(MapSection s) { if (s.m_room == null) { return; } if (s.m_room.m_type == RoomType.ENTRANCE) { return; } float rnd_x = Mathf.Floor(s.GetMidpoint().x + Random.Range(1 - s.m_room.m_size, s.m_room.m_size - 1)) * m_map_square_size; float rnd_y = Mathf.Floor(s.GetMidpoint().y + Random.Range(1 - s.m_room.m_size, s.m_room.m_size - 1)) * m_map_square_size; Vector3 pos = new Vector3(rnd_x, 0, rnd_y); Instantiate(GetRandomSpawn(), pos, Quaternion.identity); }
private FJobRequest CreateFJobRequest(SCoordsWorkRequest sCoordsWorkRequest, int jobId) { SCoords sCoords = sCoordsWorkRequest.SCoords; MqMessages.Coords coords = new MqMessages.Coords(sCoords.LeftBot.X, sCoords.RightTop.X, sCoords.LeftBot.Y, sCoords.RightTop.Y); CanvasSize cs = sCoordsWorkRequest.CanvasSize; SizeInt samplePoints = new SizeInt(cs.Width, cs.Height); MapSection ms = sCoordsWorkRequest.MapSection; RectangleInt area = new RectangleInt(new PointInt(ms.SectionAnchor.X, ms.SectionAnchor.Y), new SizeInt(ms.CanvasSize.Width, ms.CanvasSize.Height)); string name = "CoordsRequest"; FJobRequest fJobRequest = new FJobRequest(jobId, name, FJobRequestType.TransformCoords, coords, area, samplePoints, 0, sCoordsWorkRequest.TransformType); return(fJobRequest); }
static SMapWorkRequest CreateWorkRequest(int jobId) { CanvasSize canvasSize = new CanvasSize(300, 200); DPoint leftBot = new DPoint(-2, -1); DPoint rightTop = new DPoint(1, 1); SCoords coords = new SCoords(new SPoint(leftBot), new SPoint(rightTop)); MapSection area = new MapSection(new Point(0, 0), canvasSize.GetWholeUnits(Engine.BLOCK_SIZE)); int maxIterations = 100; string connectionId = "dummy"; SMapWorkRequest mapWorkRequest = new SMapWorkRequest("FEngRunner", coords, canvasSize, area, maxIterations, connectionId) { JobId = jobId }; return(mapWorkRequest); }
public Zombie(MapSection section) : base(EnemyTypes.Zombie, EnemyConstants.GetZombieProperties(), "Entities/Zombie.png", section) { _ai = new MeleeAI(this, EnemyConstants.ZombieAggroRange, new Melee(this, EnemyConstants.ZombieMinDamage, EnemyConstants.ZombieMaxDamage), EnemyConstants.ZombieWanderLength); HitboxSize = 0.8f; Width = 64; Height = 64; AttackRange = EnemyConstants.ZombieAttackRange; Animations = new AnimationList(); var spawnAnimation = new Animation(AnimationTypes.Spawn); spawnAnimation.AddFrame(new Rectangle(TextureSize * 13, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.5)); spawnAnimation.AddFrame(new Rectangle(TextureSize * 14, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.5)); spawnAnimation.AddFrame(new Rectangle(TextureSize * 14, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.05), SpawnedFunc); Animations.Add(spawnAnimation); var walkAnimation = new Animation(AnimationTypes.Move); walkAnimation.AddFrame(new Rectangle(TextureSize * 9, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.4)); walkAnimation.AddFrame(new Rectangle(TextureSize * 10, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.4)); walkAnimation.AddFrame(new Rectangle(TextureSize * 11, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.4)); walkAnimation.AddFrame(new Rectangle(TextureSize * 12, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.4)); Animations.Add(walkAnimation); var attackAnimation = new Animation(AnimationTypes.Attack); attackAnimation.AddFrame(new Rectangle(TextureSize * 7, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.35)); attackAnimation.AddFrame(new Rectangle(TextureSize * 8, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.4), AttackedFunc); attackAnimation.AddFrame(new Rectangle(TextureSize * 8, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1), DoneAttackingFunc); Animations.Add(attackAnimation); var dieAnimation = new Animation(AnimationTypes.Death); dieAnimation.AddFrame(new Rectangle(TextureSize * 0, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1), OnDeath); dieAnimation.AddFrame(new Rectangle(TextureSize * 0, 1, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1)); dieAnimation.AddFrame(new Rectangle(TextureSize * 0, 2, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1)); dieAnimation.AddFrame(new Rectangle(TextureSize * 0, 3, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1)); dieAnimation.AddFrame(new Rectangle(TextureSize * 0, 4, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1)); dieAnimation.AddFrame(new Rectangle(TextureSize * 0, 5, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1)); dieAnimation.AddFrame(new Rectangle(TextureSize * 0, 6, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1)); dieAnimation.AddFrame(new Rectangle(TextureSize * 6, 6, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1), OnDeathFinished); Animations.Add(dieAnimation); }
void PlaceRandomFeature(MapSection s) { if (s.m_room == null) { return; } if (m_map_features.Length == 0) { return; } float rnd_x = Mathf.Floor(s.GetMidpoint().x + Random.Range(1 - s.m_room.m_size, s.m_room.m_size - 1)) * m_map_square_size; float rnd_y = Mathf.Floor(s.GetMidpoint().y + Random.Range(1 - s.m_room.m_size, s.m_room.m_size - 1)) * m_map_square_size; Vector3 pos = new Vector3(rnd_x, 0, rnd_y); GameObject rnd_feature = m_map_features[Random.Range(0, m_map_features.Length)]; Instantiate(rnd_feature, pos, Quaternion.identity); }
private void UpdateOverlaySections() { MapSection overlaySection = GetSection("OverlayPack"); MapSection overlayDataSection = GetSection("OverlayDataPack"); if (overlaySection != null && overlayDataSection != null) { byte[] overlayPack = new byte[1 << 18]; byte[] overlayDataPack = new byte[1 << 18]; for (int i = 0; i < 262144; i++) { overlayPack[i] = 0xFF; overlayDataPack[i] = 0; } if (overlays != null && overlays.Count > 0) { foreach (Overlay entry in overlays) { int location = (entry.MapY * 512) + entry.MapX; overlayPack[location] = (byte)entry.OverlayIndex; overlayDataPack[location] = (byte)entry.OverlayFrame; } } string oPackEncoded = Convert.ToBase64String(Format5.Encode(overlayPack, 80), Base64FormattingOptions.None); string oDataPackEncoded = Convert.ToBase64String(Format5.Encode(overlayDataPack, 80), Base64FormattingOptions.None); overlaySection.Entries.Clear(); overlayDataSection.Entries.Clear(); for (int i = 0, j = 1; i < oPackEncoded.Length; i += 70) { overlaySection.Entries.Add(j++.ToString(CultureInfo.InvariantCulture), oPackEncoded.Substring(i, Math.Min(70, oPackEncoded.Length - i))); } for (int i = 0, j = 1; i < oDataPackEncoded.Length; i += 70) { overlayDataSection.Entries.Add(j++.ToString(CultureInfo.InvariantCulture), oDataPackEncoded.Substring(i, Math.Min(70, oDataPackEncoded.Length - i))); } } }
public Archer(MapSection section) : base(EnemyTypes.Archer, EnemyConstants.GetArcherProperties(), "Entities/Archer.png", section) { _ai = new RangeAI(this, EnemyConstants.ArcherAggroRange, EnemyConstants.ArcherWanderLength, new RangeAttack(this, 12, 18, MissileTypes.Arrow, EnemyConstants.ArcherArrowCooldown)); HitboxSize = 0.93f; Width = 64; Height = 64; AttackRange = 625; Animations = new AnimationList(); var spawnAnimation = new Animation(AnimationTypes.Spawn); spawnAnimation.AddFrame(new Rectangle(0, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.05), SpawnedFunc); Animations.Add(spawnAnimation); var walkAnimation = new Animation(AnimationTypes.Move); walkAnimation.AddFrame(new Rectangle(TextureSize * 0, TextureSize * 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.25)); walkAnimation.AddFrame(new Rectangle(TextureSize * 1, TextureSize * 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.25)); walkAnimation.AddFrame(new Rectangle(TextureSize * 2, TextureSize * 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.25)); walkAnimation.AddFrame(new Rectangle(TextureSize * 3, TextureSize * 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.25)); Animations.Add(walkAnimation); var attackAnimation = new Animation(AnimationTypes.Attack); attackAnimation.AddFrame(new Rectangle(TextureSize * 0, TextureSize * 1, TextureSize, TextureSize), TimeSpan.FromSeconds(0.25)); attackAnimation.AddFrame(new Rectangle(TextureSize * 1, TextureSize * 1, TextureSize, TextureSize), TimeSpan.FromSeconds(0.25)); attackAnimation.AddFrame(new Rectangle(TextureSize * 2, TextureSize * 1, TextureSize, TextureSize), TimeSpan.FromSeconds(0.25), AttackedFunc); attackAnimation.AddFrame(new Rectangle(TextureSize * 2, TextureSize * 1, TextureSize, TextureSize), TimeSpan.FromSeconds(0.05), DoneAttackingFunc); Animations.Add(attackAnimation); var hitAnimation = new Animation(AnimationTypes.Damaged); hitAnimation.AddFrame(new Rectangle(TextureSize * 3, TextureSize * 1, TextureSize, TextureSize), TimeSpan.FromSeconds(0.25)); Animations.Add(hitAnimation); var dieAnimation = new Animation(AnimationTypes.Death); dieAnimation.AddFrame(new Rectangle(TextureSize * 3, TextureSize * 1, TextureSize, TextureSize), TimeSpan.FromSeconds(0.35), OnDeath); dieAnimation.AddFrame(new Rectangle(TextureSize * 3, TextureSize * 1, TextureSize, TextureSize), TimeSpan.FromSeconds(0.25), OnDeathFinished); Animations.Add(dieAnimation); }
private void InitializeAircrafts() { MapSection section = GetSection("Aircraft"); if (section != null) { aircrafts = new List <Aircraft>(); foreach (KeyValuePair <string, string> entry in section.Entries) { string[] parts = entry.Value.Split(','); if (parts.Length >= 12) { try { string owner = parts[0].Trim(); string aircraftID = parts[1].Trim(); int health = int.Parse(parts[2], NumberStyles.Integer); int x = int.Parse(parts[3], NumberStyles.Integer); int y = int.Parse(parts[4], NumberStyles.Integer); int facing = int.Parse(parts[5], NumberStyles.Integer); string mission = parts[6].Trim(); string tag = parts[7].Trim(); int veterancy = int.Parse(parts[8], NumberStyles.Integer); int group = int.Parse(parts[9], NumberStyles.Integer); int acNoRecruitable = int.Parse(parts[10], NumberStyles.Integer); int acYesRecruitable = int.Parse(parts[11], NumberStyles.Integer); aircrafts.Add(new Aircraft(owner, aircraftID, health, x, y, facing, mission, tag, veterancy, group, acNoRecruitable, acYesRecruitable)); } catch (Exception) { log.Error("Error reading Aircraft entry with index: " + entry.Key); } } else { log.Error("Error reading Aircraft entry having less parameters with index: " + entry.Key); } } } }
public void LoadRoadMap() { for (int i = 0; i < sizeMap.x; i++) { for (int j = 0; j < sizeMap.y; j++) { currentLocation = new Vector2(i, j); idLocation = (int)(currentLocation.x * sizeMap.x + currentLocation.y); MapSection mapSection = Instantiate(MapSection, new Vector3(i * 25, 0, j * 25), Quaternion.Euler(0, road.road[idLocation].rotation, 0), MapContainer.transform); map.Add(mapSection); idSection = road.road[idLocation].id; CreateSectionMap(i, j); //RoadSection section = Road.road[(int)(i * sizeMap.x + j)]; //MapSection section = Instantiate(MapSection, new Vector3(i * 25, 0, j * 25), Quaternion.identity, MapContainer.transform); //Road.road.Add(new RoadSection()); } } }
public Vector3 GetAdjacentRoomPosition(Vector3 position) { //Vector2 pos = new Vector2(Mathf.FloorToInt(position.x/m_map_square_size),Mathf.FloorToInt(position.z/m_map_square_size)); //MapSection current_section = GetSectionAtCoords(pos); MapSection current_section = GetSectionAtPosition(position); List <MapSection> rnd_sections = new List <MapSection>(); Vector3 section_pos; if (current_section.m_corridors.east) { section_pos = new Vector3(current_section.GetMidpoint().x + m_section_size.x, current_section.GetMidpoint().y); rnd_sections.Add(GetSectionAtCoords(section_pos)); } if (current_section.m_corridors.west) { section_pos = new Vector3(current_section.GetMidpoint().x - m_section_size.x, current_section.GetMidpoint().y); rnd_sections.Add(GetSectionAtCoords(section_pos)); } if (current_section.m_corridors.north) { section_pos = new Vector3(current_section.GetMidpoint().x, current_section.GetMidpoint().y + m_section_size.y); rnd_sections.Add(GetSectionAtCoords(section_pos)); } if (current_section.m_corridors.south) { section_pos = new Vector3(current_section.GetMidpoint().x, current_section.GetMidpoint().y - m_section_size.y); rnd_sections.Add(GetSectionAtCoords(section_pos)); } //rnd_sections.Shuffle(); MapSection rnd_sec = rnd_sections[Random.Range(0, rnd_sections.Count - 1)]; if (rnd_sections.Count == 0) { return(Vector3.zero); } return(new Vector3(rnd_sec.GetMidpoint().x *m_map_square_size, 0, rnd_sec.GetMidpoint().y *m_map_square_size)); }
public Dog(MapSection section) : base(EnemyTypes.Dog, EnemyConstants.GetDogProperties(), "Entities/Dog.png", section) { _ai = new MeleeAI(this, EnemyConstants.DogAggroRange, new Melee(this, 6, 8), EnemyConstants.DogWanderLength); HitboxSize = 0.8f; Width = 64; Height = 64; AttackRange = 48; Animations = new AnimationList(); var spawnAnimation = new Animation(AnimationTypes.Spawn); spawnAnimation.AddFrame(new Rectangle(TextureSize * 6, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.5)); spawnAnimation.AddFrame(new Rectangle(TextureSize * 7, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.5)); spawnAnimation.AddFrame(new Rectangle(TextureSize * 7, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.05), SpawnedFunc); Animations.Add(spawnAnimation); var walkAnimation = new Animation(AnimationTypes.Move); walkAnimation.AddFrame(new Rectangle(TextureSize * 2, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.4)); walkAnimation.AddFrame(new Rectangle(TextureSize * 3, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.4)); walkAnimation.AddFrame(new Rectangle(TextureSize * 4, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.4)); walkAnimation.AddFrame(new Rectangle(TextureSize * 5, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.4)); Animations.Add(walkAnimation); var attackAnimation = new Animation(AnimationTypes.Attack); attackAnimation.AddFrame(new Rectangle(TextureSize * 0, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.35)); attackAnimation.AddFrame(new Rectangle(TextureSize * 1, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.4), AttackedFunc); attackAnimation.AddFrame(new Rectangle(TextureSize * 1, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1), DoneAttackingFunc); Animations.Add(attackAnimation); var dieAnimation = new Animation(AnimationTypes.Death); dieAnimation.AddFrame(new Rectangle(TextureSize * 7, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.5), OnDeath); dieAnimation.AddFrame(new Rectangle(TextureSize * 6, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.5)); dieAnimation.AddFrame(new Rectangle(TextureSize * 6, 0, TextureSize, TextureSize), TimeSpan.FromSeconds(0.1), OnDeathFinished); Animations.Add(dieAnimation); }
private void InitializeOverlays() { MapSection overlaySection = GetSection("OverlayPack"); MapSection overlayDataSection = GetSection("OverlayDataPack"); if (overlaySection != null && overlayDataSection != null) { overlays = new List <Overlay>(); StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> entry in overlaySection.Entries) { sb.Append(entry.Value); } byte[] format80Data = Convert.FromBase64String(sb.ToString()); byte[] overlayPack = new byte[1 << 18]; Format5.DecodeInto(format80Data, overlayPack, 80); sb.Clear(); foreach (KeyValuePair <string, string> entry in overlayDataSection.Entries) { sb.Append(entry.Value); } format80Data = Convert.FromBase64String(sb.ToString()); byte[] overlayDataPack = new byte[1 << 18]; Format5.DecodeInto(format80Data, overlayDataPack, 80); foreach (Tuple <int, int> cellCoordinate in coordList) { int location = cellCoordinate.Item1 + 512 * cellCoordinate.Item2; byte overlayIndex = overlayPack[location]; if (overlayIndex != 0xFF) { overlays.Add(new Overlay(overlayIndex, (int)overlayDataPack[location], cellCoordinate.Item1, cellCoordinate.Item2)); } } } }
private void AddMapSectionBeamDisableIntoList(MapSectionBeamDisable oneRow) { try { if (!Vehicle.MapInfo.sectionMap.ContainsKey(oneRow.SectionId)) { mirleLogger.Log(new LogFormat("Error", "5", GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, "Device", "CarrierID" , $"Section[{oneRow.SectionId}]加入Beam Sensor Disable清單失敗, 圖資不包含Section[{oneRow.SectionId}]")); return; } MapSection mapSection = Vehicle.MapInfo.sectionMap[oneRow.SectionId]; if (oneRow.Min < -30) { mirleLogger.Log(new LogFormat("Error", "5", GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, "Device", "CarrierID" , $"Min < 0. [SectionId={oneRow.SectionId}][Min={oneRow.Min}]")); return; } if (oneRow.Max > mapSection.HeadToTailDistance + 31) { mirleLogger.Log(new LogFormat("Error", "5", GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, "Device", "CarrierID" , $"Max > Distance. [SectionId={oneRow.SectionId}][Max={oneRow.Max}][Distance={mapSection.HeadToTailDistance}]")); return; } if (oneRow.Min == 0 && oneRow.Max == 0) { oneRow.Min = -30; oneRow.Max = mapSection.HeadToTailDistance + 30; } mapSection.BeamSensorDisables.Add(oneRow); } catch (Exception ex) { LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, ex.Message); } }
void AIWander() { //Clear target if it has been reached. if (m_has_wander_target) { if (Vector3.Distance(transform.position, m_wander_target) < 1) { m_has_wander_target = false; return; } } //Move towards target. if (m_has_wander_target) { Vector3 dir = m_wander_target - transform.position; Vector2 dir2d = new Vector3(dir.x, dir.z); m_entity.m_mobile.Move(m_entity.m_move_speed * m_wander_speed_mod, dir2d); return; } //Get a new target. MapSection current_section = Game.map.GetSectionAtPosition(transform.position); if (current_section.m_room == null) { return; } Vector2 rnd_tile = new Vector2( current_section.GetMidpoint().x + Random.Range(-current_section.m_room.m_size + 1, current_section.m_room.m_size), current_section.GetMidpoint().y + Random.Range(-current_section.m_room.m_size + 1, current_section.m_room.m_size) ); Vector3 rnd_position = new Vector3(rnd_tile.x * Game.map.GetMapSquareSize(), 0, rnd_tile.y * Game.map.GetMapSquareSize()); m_wander_target = rnd_position; m_has_wander_target = true; }
private void InitializeTunnelLines() { MapSection section = GetSection("Tubes"); if (section != null) { tunnelLines = new List <TunnelLine>(); foreach (KeyValuePair <string, string> entry in section.Entries) { string[] parts = entry.Value.Split(','); if (parts.Length > 5) { try { int sx = int.Parse(parts[0], NumberStyles.Integer); int sy = int.Parse(parts[1], NumberStyles.Integer); int facing = int.Parse(parts[2], NumberStyles.Integer); int ex = int.Parse(parts[3], NumberStyles.Integer); int ey = int.Parse(parts[4], NumberStyles.Integer); List <int> ds = new List <int>(); for (int i = 5; i < parts.Length; i++) { ds.Add(int.Parse(parts[i], NumberStyles.Integer)); } tunnelLines.Add(new TunnelLine(sx, sy, facing, ex, ey, ds)); } catch (Exception) { log.Error("Error reading Tubes (Tunnel) entry with index: " + entry.Key); } } } } }
private void InitializeTerrains() { MapSection section = GetSection("Terrain"); if (section != null) { terrains = new List <Terrain>(); foreach (KeyValuePair <string, string> entry in section.Entries) { try { int coord = int.Parse(entry.Key, NumberStyles.Integer); int x = coord % 1000; int y = coord / 1000; terrains.Add(new Terrain(entry.Value, x, y)); } catch (Exception) { log.Error("Error reading Terrain entry with index: " + entry.Key); } } } }
private void InitializeCellTags() { MapSection section = GetSection("CellTags"); if (section != null) { cellTags = new List <CellTag>(); foreach (KeyValuePair <string, string> entry in section.Entries) { try { int coord = int.Parse(entry.Key, NumberStyles.Integer); int x = coord % 1000; int y = coord / 1000; cellTags.Add(new CellTag(entry.Value, x, y)); } catch (Exception) { log.Error("Error reading CellTags entry with index: " + entry.Key); } } } }
public void Update(GameTime gameTime) { Cursor.Type = CursorType.Crosshair; #region Moving Camera if (Keyboard.GetState().IsKeyDown(Keys.Left)) { camera.MoveLeft(CAMERA_SPEED); } if (Keyboard.GetState().IsKeyDown(Keys.Right)) { camera.MoveRight(CAMERA_SPEED); } if (Keyboard.GetState().IsKeyDown(Keys.Up)) { camera.MoveUp(CAMERA_SPEED); } if (Keyboard.GetState().IsKeyDown(Keys.Down)) { camera.MoveDown(CAMERA_SPEED); } #endregion #region Add section if (!isKeyAddPressed && Keyboard.GetState().IsKeyDown(Keys.Add)) { isKeyAddPressed = true; var bounds = new Rectangle( (int)(Cursor.InGamePosition.X * SCALE), (int)(Cursor.InGamePosition.Y * SCALE), (int)Map.Game.InternalSize.Width, (int)Map.Game.InternalSize.Height ); int nextSectionIndex = Map.Sections.Count; MapSectionContainers.Add(nextSectionIndex, new MapSectionContainer(Map, this, nextSectionIndex, bounds)); var defaultSpawnPoint = new SpawnPoint(Map, "spawn01"); var mapSection = new MapSection(Map, bounds, defaultSpawnPoint.Name); mapSection.Entities.Add(defaultSpawnPoint.Name, defaultSpawnPoint); Map.Sections.Add(nextSectionIndex, mapSection); } if (Keyboard.GetState().IsKeyUp(Keys.Add)) { isKeyAddPressed = false; } #endregion foreach (var section in MapSectionContainers) { section.Value.Update(new Vector2( Cursor.InGamePosition.X * SCALE, Cursor.InGamePosition.Y * SCALE )); } cursorPosition.Text = (int)Cursor.InGamePosition.X * SCALE + ";" + (int)Cursor.InGamePosition.Y * SCALE; camera.Update(gameTime); frame.Update(); Cursor.Update(); }
public void UpdateMapSections() { int index = 0; MapSection section = GetSection("Aircraft"); if (section != null) { section.Entries.Clear(); if (aircrafts != null && aircrafts.Count > 0) { foreach (Aircraft entry in aircrafts) { section.Entries.Add(Convert.ToString(index++), entry.ToString()); } } } index = 0; section = GetSection("Infantry"); if (section != null) { section.Entries.Clear(); if (infantries != null && infantries.Count > 0) { foreach (Infantry entry in infantries) { section.Entries.Add(Convert.ToString(index++), entry.ToString()); } } } section = GetSection("Units"); if (section != null) { section.Entries.Clear(); if (units != null && units.Count > 0) { foreach (Unit entry in units) { section.Entries.Add(entry.Index, entry.ToString()); } } } index = 0; section = GetSection("Structures"); if (section != null) { section.Entries.Clear(); if (structures != null && structures.Count > 0) { foreach (Structure entry in structures) { section.Entries.Add(Convert.ToString(index++), entry.ToString()); } } } section = GetSection("CellTags"); if (section != null) { section.Entries.Clear(); if (cellTags != null && cellTags.Count > 0) { foreach (CellTag entry in cellTags) { section.Entries.Add(Convert.ToString(entry.MapY * 1000 + entry.MapX), entry.ToString()); } } } index = 0; section = GetSection("Smudge"); if (section != null) { section.Entries.Clear(); if (smudges != null && smudges.Count > 0) { foreach (Smudge entry in smudges) { section.Entries.Add(Convert.ToString(index++), entry.ToString()); } } } section = GetSection("Terrain"); if (section != null) { section.Entries.Clear(); if (terrains != null && terrains.Count > 0) { foreach (Terrain entry in terrains) { section.Entries.Add(Convert.ToString(entry.MapY * 1000 + entry.MapX), entry.ToString()); } } } index = 0; section = GetSection("Tubes"); if (section != null) { section.Entries.Clear(); if (tunnelLines != null && tunnelLines.Count > 0) { foreach (TunnelLine entry in tunnelLines) { section.Entries.Add(Convert.ToString(index++), entry.ToString()); } } } section = GetSection("Waypoints"); if (section != null) { section.Entries.Clear(); if (waypoints != null && waypoints.Count > 0) { foreach (Waypoint entry in waypoints) { section.Entries.Add(entry.ToString(), Convert.ToString(entry.MapY * 1000 + entry.MapX)); } } } UpdateOverlaySections(); UpdateTileSection(); if (sectionsWithNodes != null && sectionsWithNodes.Count > 0) { foreach (string sectionName in sectionsWithNodes) { section = GetSection(sectionName); if (section != null) { string nodeCount; if (section.Entries.TryGetValue("NodeCount", out nodeCount)) { int count = 0; int.TryParse(nodeCount, out count); if (count > 0) { for (int i = 0; i < count; i++) { string countStr = i.ToString("000"); if (section.Entries.ContainsKey(countStr)) { section.Entries.Remove(countStr); } } } List <BaseNode> baseNodesInSection = baseNodes.FindAll(bn => bn.SectionName.Equals(sectionName)); Dictionary <string, string> sectionEntries = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> entry in section.Entries) { sectionEntries.Add(entry.Key, entry.Value); } nodeCount = "0"; if (baseNodesInSection != null && baseNodesInSection.Count > 0) { for (int bnCount = 0; bnCount < baseNodesInSection.Count; bnCount++) { sectionEntries.Add(bnCount.ToString("000"), baseNodesInSection[bnCount].ToString()); } nodeCount = baseNodesInSection.Count.ToString(); } if (sectionEntries.ContainsKey("NodeCount")) { sectionEntries["NodeCount"] = nodeCount; } else { sectionEntries.Add("NodeCount", nodeCount); } section.Entries = sectionEntries; } } } } Dictionary <string, string> sizeEntries = new Dictionary <string, string>(); section = GetSection("Map"); if (section != null) { int localX = localSize[0]; int localY = localSize[1]; int localWidth = newMapWidth - localSize[4]; int localHeight = newMapHeight - localSize[5]; sizeEntries.Add("Size", "0,0," + newMapWidth + "," + newMapHeight); if (left >= 0 && top >= 0 && right >= 0 && bottom >= 0 && options.MaintainLocalSize) { localX = localSize[0] + left; localY = localSize[1] + top; localWidth = newMapWidth - localSize[4] - right - left; localHeight = newMapHeight - localSize[5] - bottom - top; } if (localX < 1) { localX = 1; } if (localY < 2) { localY = 2; } if (localWidth < 1) { localWidth = 1; } if (localHeight < 2) { localHeight = 2; } string mapLocalSize = Convert.ToString(localX) + "," + Convert.ToString(localY) + "," + Convert.ToString(localWidth) + "," + Convert.ToString(localHeight); sizeEntries.Add("LocalSize", mapLocalSize); section.Merge(sizeEntries); } if (!String.IsNullOrEmpty(options.MapName)) { section = GetSection("Basic"); if (section != null) { Dictionary <string, string> basicEntries = new Dictionary <string, string>(); basicEntries.Add("Name", options.MapName); section.Merge(basicEntries); } } }
private void InitializeTiles() { MapSection section = GetSection("IsoMapPack5"); if (section != null) { tiles = new List <Tile>(); StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> entry in section.Entries) { sb.Append(entry.Value); } byte[] lzoData = Convert.FromBase64String(sb.ToString()); int cells = (MapWidth * 2 - 1) * MapHeight; int lzoPackSize = cells * 11 + 4; // last 4 bytes used for termination byte[] isoMapPack = new byte[lzoPackSize]; int j = 0; for (int i = 0; i < cells; i++) { isoMapPack[j] = 0x88; isoMapPack[j + 1] = 0x40; isoMapPack[j + 2] = 0x88; isoMapPack[j + 3] = 0x40; j += 11; } Format5.DecodeInto(lzoData, isoMapPack); foreach (Tuple <int, int> cellCoordinate in coordList) { tiles.Add(new Tile(0, 0, 0, 0, cellCoordinate.Item1, cellCoordinate.Item2)); } MemoryFile mf = new MemoryFile(isoMapPack); for (int i = 0; i < cells; i++) { int rx = (int)mf.ReadUInt16(); int ry = (int)mf.ReadUInt16(); int tileIndex = mf.ReadInt32(); byte subIndex = mf.ReadByte(); byte heightLevel = mf.ReadByte(); byte iceGrowth = mf.ReadByte(); if (tileIndex >= 65535) { tileIndex = 0; // Tile 0xFFFF used as empty/clear } if (rx < 512 && ry < 512) { int index = tiles.FindIndex(tile => tile.MapX == rx && tile.MapY == ry); if (index >= 0) { tiles[index].TileIndex = tileIndex; tiles[index].SubIndex = subIndex; tiles[index].Level = heightLevel; tiles[index].IceGrowth = iceGrowth; } } } } }
private void UpdateTileSection() { MapSection tileSection = GetSection("IsoMapPack5"); if (tileSection != null) { byte[] encoded; List <Tile> tileSetStage = new List <Tile>(); List <byte[]> sortedTiles = new List <byte[]>(); if (!options.KeepL0ClearTiles) { foreach (Tile t in tiles) { if (t.TileIndex > 0 || t.SubIndex > 0 || t.Level > 0 || t.IceGrowth > 0) { tileSetStage.Add(t); } } } else { tileSetStage.AddRange(tiles); } if (tileSetStage.Count == 0) { tileSetStage.Add(tiles.First()); encoded = GetEncoded(tileSetStage); } else { sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.MapX).ThenBy(x => x.TileIndex).ThenBy(x => x.SubIndex).ThenBy(x => x.Level).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileIndex).ThenBy(x => x.MapX).ThenBy(x => x.SubIndex).ThenBy(x => x.Level).ToList())); if (options.BetterTilesPackCompression) { sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.MapX).ThenBy(x => x.SubIndex).ThenBy(x => x.TileIndex).ThenBy(x => x.Level).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.SubIndex).ThenBy(x => x.TileIndex).ThenBy(x => x.MapX).ThenBy(x => x.Level).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.SubIndex).ThenBy(x => x.TileIndex).ThenBy(x => x.Level).ThenBy(x => x.MapX).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.SubIndex).ThenBy(x => x.TileIndex).ThenBy(x => x.Level).ThenBy(x => x.MapY).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.SubIndex).ThenBy(x => x.Level).ThenBy(x => x.TileIndex).ThenBy(x => x.MapX).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.SubIndex).ThenBy(x => x.Level).ThenBy(x => x.TileIndex).ThenBy(x => x.MapY).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileIndex).ThenBy(x => x.SubIndex).ThenBy(x => x.MapY).ThenBy(x => x.Level).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileIndex).ThenBy(x => x.SubIndex).ThenBy(x => x.Level).ThenBy(x => x.MapX).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileIndex).ThenBy(x => x.SubIndex).ThenBy(x => x.Level).ThenBy(x => x.MapY).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileIndex).ThenBy(x => x.Level).ThenBy(x => x.SubIndex).ThenBy(x => x.MapX).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.TileIndex).ThenBy(x => x.Level).ThenBy(x => x.SubIndex).ThenBy(x => x.MapY).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Level).ThenBy(x => x.SubIndex).ThenBy(x => x.TileIndex).ThenBy(x => x.MapX).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Level).ThenBy(x => x.SubIndex).ThenBy(x => x.TileIndex).ThenBy(x => x.MapY).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Level).ThenBy(x => x.TileIndex).ThenBy(x => x.MapX).ThenBy(x => x.SubIndex).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Level).ThenBy(x => x.TileIndex).ThenBy(x => x.MapY).ThenBy(x => x.SubIndex).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Level).ThenBy(x => x.TileIndex).ThenBy(x => x.SubIndex).ThenBy(x => x.MapX).ToList())); sortedTiles.Add(GetEncoded(tileSetStage.OrderBy(x => x.Level).ThenBy(x => x.TileIndex).ThenBy(x => x.SubIndex).ThenBy(x => x.MapY).ToList())); } int smallest = sortedTiles[0].Length; int smallestIndex = 0; for (int index = 0; index < sortedTiles.Count; index++) { if (sortedTiles[index].Length < smallest) { smallest = sortedTiles[index].Length; smallestIndex = index; } } encoded = sortedTiles[smallestIndex]; } string compressed64 = Convert.ToBase64String(encoded, Base64FormattingOptions.None); tileSection.Entries.Clear(); for (int i = 0, j = 1; i < compressed64.Length; i += 74) { tileSection.Entries.Add(j++.ToString(CultureInfo.InvariantCulture), compressed64.Substring(i, Math.Min(74, compressed64.Length - i))); } } }
private void FindSectionThread() { VehicleLocation newVehicleLocation = new VehicleLocation(); string sectionID = localData.Location.NowSection; string addressID = localData.Location.LastAddress; MapAGVPosition now = localData.Real; MapPosition temp; MapSection section; double distanceToHead; double distanceToTail; if (now == null) { return; } if (localData.TheMapInfo.AllSection.ContainsKey(sectionID)) { #region 是否還在目前Section內 (判斷條件 : 頭尾不能超出,寬度為MoveControlConfig.SectionRange 預設是50mm, 非RTurn且 角度誤差在MoveControlConfig.SectionAllowDeltaTheta 預設是5度). section = localData.TheMapInfo.AllSection[sectionID]; temp = computeFunction.GetTransferPosition(section, now.Position); if (0 <= temp.X && temp.X <= section.Distance && Math.Abs(temp.Y) <= localData.MoveControlData.MoveControlConfig.SectionRange && Math.Abs(computeFunction.GetCurrectAngle(section.FromVehicleAngle - now.Angle)) <= localData.MoveControlData.MoveControlConfig.SectionAllowDeltaTheta) { if (section.FromVehicleAngle == section.ToVehicleAngle) { if (Math.Abs(computeFunction.GetCurrectAngle(section.FromVehicleAngle - now.Angle)) <= localData.MoveControlData.MoveControlConfig.SectionAllowDeltaTheta) { localData.Location.DistanceFormSectionHead = temp.X; distanceToHead = temp.X; distanceToTail = section.Distance - temp.X; if (distanceToHead <= localData.MoveControlData.MoveControlConfig.InPositionRange && distanceToHead <= distanceToTail) { localData.Location.InAddress = true; localData.Location.LastAddress = section.FromAddress.Id; } else if (distanceToTail <= localData.MoveControlData.MoveControlConfig.InPositionRange && distanceToTail <= distanceToHead) { localData.Location.InAddress = true; localData.Location.LastAddress = section.ToAddress.Id; } else { localData.Location.InAddress = false; } WriteLog(7, "", String.Concat("Section不變更 : ", sectionID)); localData.LastAGVPosition = now; return; } } } #endregion #region 搜尋是否在相鄰Section內 (判斷條件 : 頭尾不能超出,寬度為MoveControlConfig.SectionRange 預設是50mm, 非RTurn且 角度誤差在MoveControlConfig.SectionAllowDeltaTheta 預設是5度). for (int i = 0; i < localData.TheMapInfo.AllSection[sectionID].NearbySection.Count; i++) { section = localData.TheMapInfo.AllSection[sectionID].NearbySection[i]; if (section.FromVehicleAngle == section.ToVehicleAngle) { temp = computeFunction.GetTransferPosition(section, now.Position); if (0 <= temp.X && temp.X <= section.Distance && Math.Abs(temp.Y) <= localData.MoveControlData.MoveControlConfig.SectionRange && Math.Abs(computeFunction.GetCurrectAngle(section.FromVehicleAngle - now.Angle)) <= localData.MoveControlData.MoveControlConfig.SectionAllowDeltaTheta) { if (Math.Abs(computeFunction.GetCurrectAngle(section.FromVehicleAngle - now.Angle)) <= localData.MoveControlData.MoveControlConfig.SectionAllowDeltaTheta) { newVehicleLocation.DistanceFormSectionHead = temp.X; newVehicleLocation.NowSection = section.Id; distanceToHead = temp.X; distanceToTail = section.Distance - temp.X; if (distanceToHead <= localData.MoveControlData.MoveControlConfig.InPositionRange && distanceToHead <= distanceToTail) { newVehicleLocation.InAddress = true; newVehicleLocation.LastAddress = section.FromAddress.Id; } else if (distanceToTail <= localData.MoveControlData.MoveControlConfig.InPositionRange && distanceToTail <= distanceToHead) { newVehicleLocation.InAddress = true; newVehicleLocation.LastAddress = section.ToAddress.Id; } else { newVehicleLocation.InAddress = false; if (section.FromAddress == localData.TheMapInfo.AllSection[sectionID].FromAddress || section.FromAddress == localData.TheMapInfo.AllSection[sectionID].ToAddress) { newVehicleLocation.LastAddress = section.FromAddress.Id; } else { newVehicleLocation.LastAddress = section.ToAddress.Id; } } localData.Location = newVehicleLocation; WriteLog(7, "", String.Concat("切換Section(相鄰) : ", newVehicleLocation.NowSection)); localData.LastAGVPosition = now; return; } } } } #endregion } #region Find All (條件 : 頭尾可超出 MoveControlConfig.SectionRange 預設是50mm, 寬度在MoveControlConfig.SectionWidthRange 預設是500mm, 非RTurn且 角度誤差在MoveControlConfig.SectionAllowDeltaTheta 預設是5度 中 找尋數值最接近的) MapSection minSection = null; MapPosition minPosition = null; double min = -1; double tempMin; double deltaAngle; foreach (MapSection tempSection in localData.TheMapInfo.AllSection.Values) { if (tempSection.FromVehicleAngle == tempSection.ToVehicleAngle) { temp = computeFunction.GetTransferPosition(tempSection, now.Position); if (-localData.MoveControlData.MoveControlConfig.SectionRange <= temp.X && temp.X <= (tempSection.Distance + localData.MoveControlData.MoveControlConfig.SectionRange) && Math.Abs(temp.Y) <= localData.MoveControlData.MoveControlConfig.SectionWidthRange) { deltaAngle = Math.Abs(computeFunction.GetCurrectAngle(tempSection.FromVehicleAngle - now.Angle)); tempMin = Math.Abs(temp.Y) + deltaAngle * 50; if (temp.X < 0) { tempMin = tempMin - temp.X; } else if (temp.X > tempSection.Distance) { tempMin = tempMin + temp.X - tempSection.Distance; } if (min == -1 || tempMin < min) { min = tempMin; minSection = tempSection; minPosition = temp; } } } } if (min == -1) { if (localData.MoveControlData.MoveControlConfig.LosePositionSetNullAddressSection) { newVehicleLocation.DistanceFormSectionHead = 0; newVehicleLocation.LastAddress = ""; newVehicleLocation.NowSection = ""; newVehicleLocation.InAddress = false; localData.Location = newVehicleLocation; } WriteLog(3, "", String.Concat("目前位置 : ", computeFunction.GetMapAGVPositionStringWithAngle(now), " 搜尋不到所在Section")); localData.LastAGVPosition = now; } else { newVehicleLocation.NowSection = minSection.Id; if (minPosition.X < 0) { newVehicleLocation.DistanceFormSectionHead = 0; } else if (minPosition.X > minSection.Distance) { newVehicleLocation.DistanceFormSectionHead = minSection.Distance; } else { newVehicleLocation.DistanceFormSectionHead = minPosition.X; } distanceToHead = Math.Abs(minPosition.X); distanceToTail = Math.Abs(minSection.Distance - minPosition.X); if (distanceToHead <= localData.MoveControlData.MoveControlConfig.InPositionRange && distanceToHead <= distanceToTail) { newVehicleLocation.LastAddress = minSection.FromAddress.Id; newVehicleLocation.InAddress = true; } else if (distanceToTail < localData.MoveControlData.MoveControlConfig.InPositionRange && distanceToTail < distanceToHead) { newVehicleLocation.LastAddress = minSection.ToAddress.Id; newVehicleLocation.InAddress = true; } else { if (distanceToHead <= distanceToTail) { newVehicleLocation.LastAddress = minSection.FromAddress.Id; } else { newVehicleLocation.LastAddress = minSection.ToAddress.Id; } newVehicleLocation.InAddress = false; } localData.Location = newVehicleLocation; WriteLog(7, "", String.Concat("切換Section(All) : ", newVehicleLocation.NowSection)); localData.LastAGVPosition = now; } #endregion }
public void ReleaseMapSection(MapSection sect) { sectionCache.Release(sect); }
public MapSection(int apiVersion, EventHandler handler, MapSection basis) : base(apiVersion, handler, basis) { }
public void ReadSectionCsv() { try { if (string.IsNullOrWhiteSpace(SectionPath)) { LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, $"IsSectionPathNull={string.IsNullOrWhiteSpace(SectionPath)}"); return; } Vehicle.MapInfo.sectionMap.Clear(); string[] allRows = File.ReadAllLines(SectionPath); if (allRows == null || allRows.Length < 2) { LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, $"There are no section in file"); return; } string[] titleRow = allRows[0].Split(','); allRows = allRows.Skip(1).ToArray(); int nRows = allRows.Length; int nColumns = titleRow.Length; Dictionary <string, int> dicHeaderIndexes = new Dictionary <string, int>(); //Id, FromAddress, ToAddress, Speed, Type, PermitDirection for (int i = 0; i < nColumns; i++) { var keyword = titleRow[i].Trim(); if (!string.IsNullOrWhiteSpace(keyword)) { dicHeaderIndexes.Add(keyword, i); } } for (int i = 0; i < nRows; i++) { string[] getThisRow = allRows[i].Split(','); MapSection oneRow = new MapSection(); try { oneRow.Id = getThisRow[dicHeaderIndexes["Id"]]; if (!Vehicle.MapInfo.addressMap.ContainsKey(getThisRow[dicHeaderIndexes["FromAddress"]])) { LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, $"LoadSectionCsv read oneRow fail, headAddress is not in the map : [secId={oneRow.Id}][headAddress={getThisRow[dicHeaderIndexes["FromAddress"]]}]"); } oneRow.HeadAddress = Vehicle.MapInfo.addressMap[getThisRow[dicHeaderIndexes["FromAddress"]]]; oneRow.InsideAddresses.Add(oneRow.HeadAddress); if (!Vehicle.MapInfo.addressMap.ContainsKey(getThisRow[dicHeaderIndexes["ToAddress"]])) { LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, $"LoadSectionCsv read oneRow fail, tailAddress is not in the map : [secId={oneRow.Id}][tailAddress={getThisRow[dicHeaderIndexes["ToAddress"]]}]"); } oneRow.TailAddress = Vehicle.MapInfo.addressMap[getThisRow[dicHeaderIndexes["ToAddress"]]]; oneRow.InsideAddresses.Add(oneRow.TailAddress); oneRow.HeadToTailDistance = GetDistance(oneRow.HeadAddress.Position, oneRow.TailAddress.Position); oneRow.Speed = double.Parse(getThisRow[dicHeaderIndexes["Speed"]]); oneRow.Type = oneRow.SectionTypeParse(getThisRow[dicHeaderIndexes["Type"]]); } catch (Exception ex) { LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, $"LoadSectionCsv read oneRow fail : [lastReadSecId={lastReadSecId}]"); LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, ex.Message); } lastReadSecId = oneRow.Id; Vehicle.MapInfo.sectionMap.Add(oneRow.Id, oneRow); } //LoadBeamSensorDisable(); AddInsideAddresses(); LogDebug(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, $"Load Section File Ok. [lastReadSecId={lastReadSecId}]"); } catch (Exception ex) { LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, $"LoadSectionCsv : [lastReadSecId={lastReadSecId}]"); LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, ex.Message); } }