public DebugSightingItem(ITypeResolver resolver, Vector2 pos) : base(resolver, pos, Angle.Right) { sighting = new SightingProperty(this, 20); AddProperty(sighting); }
/// <summary> /// Default Constructor for the Type Mapper. /// </summary> /// <param name="faction">Faction</param> /// <param name="item">Item</param> /// <param name="interop">UnitInterop</param> public RecognitionInterop(Faction faction, FactionItem item, UnitInterop interop) : base(faction, item, interop) { // Get Sniffer Reference var sniffer = Item.GetProperty<SnifferProperty>(); if (sniffer == null) throw new ArgumentException("Item does not contain SnifferProperty"); // Insert sniffed Items into the List. sniffer.OnNewSmellableItem += property => { var info = property.Item.GetItemInfo(Item); if (!smellableItems.Contains(info)) smellableItems.Add(info); }; // Remove sniffed Items from List. sniffer.OnLostSmellableItem += property => { var info = property.Item.GetItemInfo(Item); if (smellableItems.Contains(info)) smellableItems.Remove(info); }; // Get Sighting Property sighting = Item.GetProperty<SightingProperty>(); if (sighting == null) throw new ArgumentException("Item does not contain SightingProperty"); // Add visible items to List. sighting.OnNewVisibleItem += property => { var info = property.Item.GetItemInfo(Item); if (!visibleItems.Contains(info)) visibleItems.Add(info); }; // Remove visible Items from List. sighting.OnLostVisibleItem += property => { var info = property.Item.GetItemInfo(Item); if (visibleItems.Contains(info)) visibleItems.Remove(info); }; // Set new Environment on Cell Switch sighting.OnEnvironmentChanged += (i, value) => { if (OnEnvironmentChanged != null) OnEnvironmentChanged(value); }; }
public void CleanupEngine() { VisibleItem = null; SightingItem = null; SmellableItem = null; SnifferItem = null; Visible = null; Sighting = null; Smellable = null; Sniffer = null; Map = null; Engine = null; }
/// <summary> /// Default Constructor for the Type Mapper. /// </summary> /// <param name="item">Related Engine Item</param> /// <param name="property">Related Engine Property</param> public SightingState(Item item, SightingProperty property) : base(item, property) { // Bind Direction to the Item Direction ViewDirection = (short)property.ViewDirection.Degree; property.OnViewDirectionChanged += (i, v) => { ViewDirection = (short)v.Degree; }; // Bind Angle to the Item Angle ViewAngle = property.ViewAngle; property.OnViewAngleChanged += (i, v) => { ViewAngle = v; }; // Bind View Range to the Item View Range ViewRange = property.ViewRange; property.OnViewRangeChanged += (i, v) => { ViewRange = v; }; }
protected override void RequestDraw() { if (_level != null) { DrawPlayground(_level.Map.GetCellCount(), _level.Map.Tiles); foreach (var item in _level.Items) { float?bodySpeed = null; float?bodyDirection = null; float?bodyRadius = null; float?smellableRadius = null; float?viewRange = null; float?viewAngle = null; float?viewDirection = null; float?attackRange = null; // Movement if (item.ContainsProperty <WalkingProperty>()) { WalkingProperty prop = item.GetProperty <WalkingProperty>(); bodySpeed = prop.Speed; bodyDirection = prop.Direction; } // Kollisionsradius if (item.ContainsProperty <CollidableProperty>()) { CollidableProperty prop = item.GetProperty <CollidableProperty>(); bodyRadius = prop.CollisionRadius; } // Sicht if (item.ContainsProperty <SightingProperty>()) { SightingProperty prop = item.GetProperty <SightingProperty>(); viewRange = prop.ViewRange; viewDirection = prop.ViewDirection.Radian; viewAngle = prop.ViewAngle; } // Attack if (item.ContainsProperty <AttackerProperty>()) { AttackerProperty prop = item.GetProperty <AttackerProperty>(); attackRange = prop.AttackRange; } // Stinkender radius if (item.ContainsProperty <SmellableProperty>()) { SmellableProperty prop = item.GetProperty <SmellableProperty>(); smellableRadius = prop.SmellableRadius; } Color color = Color.Gray; Color?borderColor = null; // Farbe if (item is AnthillItem) { color = Color.Brown; } else if (item is SugarItem) { color = Color.White; } else if (item is AppleItem) { color = Color.LightGreen; } else if (item is BugItem) { color = Color.Blue; } else if (item is AntItem) { color = Color.LightGray; AntItem ant = item as AntItem; switch (ant.PlayerIndex) { case 0: borderColor = Color.Orange; break; case 1: borderColor = Color.Red; break; case 2: borderColor = Color.Yellow; break; case 3: borderColor = Color.Green; break; case 4: borderColor = Color.Blue; break; case 5: borderColor = Color.Purple; break; case 6: borderColor = Color.White; break; case 7: borderColor = Color.Black; break; } } else if (item is MarkerItem) { color = Color.LightGray; MarkerItem marker = item as MarkerItem; switch (marker.PlayerIndex) { case 0: borderColor = Color.Orange; break; case 1: borderColor = Color.Red; break; case 2: borderColor = Color.Yellow; break; case 3: borderColor = Color.Green; break; case 4: borderColor = Color.Blue; break; case 5: borderColor = Color.Purple; break; case 6: borderColor = Color.White; break; case 7: borderColor = Color.Black; break; } } // Malen DrawItem(item.Id, item.Position, bodyRadius, bodyDirection, bodySpeed, color, viewRange, viewDirection, viewAngle, attackRange, smellableRadius, borderColor); } } }
protected override void RequestDraw() { if (_engine != null) { DrawPlayground(_engine.Map.GetCellCount(), _engine.Map.Tiles); foreach (var item in _engine.Items) { float?bodySpeed = null; float?bodyDirection = null; float?bodyRadius = null; float?smellableRadius = null; float?viewRange = null; float?viewAngle = null; float?viewDirection = null; float?attackRange = null; // Movement if (item.ContainsProperty <WalkingProperty>()) { WalkingProperty prop = item.GetProperty <WalkingProperty>(); bodySpeed = prop.Speed; bodyDirection = prop.Direction; } // Kollisionsradius if (item.ContainsProperty <CollidableProperty>()) { CollidableProperty prop = item.GetProperty <CollidableProperty>(); bodyRadius = prop.CollisionRadius; } // Sicht if (item.ContainsProperty <SightingProperty>()) { SightingProperty prop = item.GetProperty <SightingProperty>(); viewRange = prop.ViewRange; viewDirection = prop.ViewDirection.Radian; viewAngle = prop.ViewAngle; } // Attack if (item.ContainsProperty <AttackerProperty>()) { AttackerProperty prop = item.GetProperty <AttackerProperty>(); attackRange = prop.AttackRange; } // Stinkender radius if (item.ContainsProperty <SmellableProperty>()) { SmellableProperty prop = item.GetProperty <SmellableProperty>(); smellableRadius = prop.SmellableRadius; } DrawItem(item.Id, item.Position, bodyRadius, bodyDirection, bodySpeed, Color.White, viewRange, viewDirection, viewAngle, attackRange, smellableRadius, null); } } }
private void InitSightingItem(Vector2 pos) { SightingItem = new DebugSightingItem(pos); Sighting = SightingItem.GetProperty<SightingProperty>(); Engine.InsertItem(SightingItem); }
public void CleanupEngine() { VisibleItem = null; SightingItem = null; SmellableItem = null; SnifferItem = null; Visible = null; Sighting = null; Smellable = null; Sniffer = null; Map = null; Engine = null; }
/// <summary> /// Default Constructor for the Type Mapper. /// </summary> /// <param name="faction">Faction</param> /// <param name="item">Item</param> /// <param name="interop">UnitInterop</param> public RecognitionInterop(Faction faction, FactionItem item, UnitInterop interop) : base(faction, item, interop) { // Get Sniffer Reference var sniffer = Item.GetProperty <SnifferProperty>(); if (sniffer == null) { throw new ArgumentException("Item does not contain SnifferProperty"); } // Insert sniffed Items into the List. sniffer.OnNewSmellableItem += property => { var info = property.Item.GetItemInfo(Item); if (!smellableItems.Contains(info)) { smellableItems.Add(info); } }; // Remove sniffed Items from List. sniffer.OnLostSmellableItem += property => { var info = property.Item.GetItemInfo(Item); if (smellableItems.Contains(info)) { smellableItems.Remove(info); } }; // Get Sighting Property sighting = Item.GetProperty <SightingProperty>(); if (sighting == null) { throw new ArgumentException("Item does not contain SightingProperty"); } // Add visible items to List. sighting.OnNewVisibleItem += property => { var info = property.Item.GetItemInfo(Item); if (!visibleItems.Contains(info)) { visibleItems.Add(info); } }; // Remove visible Items from List. sighting.OnLostVisibleItem += property => { var info = property.Item.GetItemInfo(Item); if (visibleItems.Contains(info)) { visibleItems.Remove(info); } }; // Set new Environment on Cell Switch sighting.OnEnvironmentChanged += (i, value) => { if (OnEnvironmentChanged != null) { OnEnvironmentChanged(value); } }; }
private void InitSightingItem(Vector2 pos) { SightingItem = new DebugSightingItem(pos); Sighting = SightingItem.GetProperty <SightingProperty>(); Engine.InsertItem(SightingItem); }
/// <summary> /// Registers Ants /// </summary> /// <param name="typeMapper">Type Mapper</param> /// <param name="settings">Settings</param> private void RegisterAnt(ITypeMapper typeMapper, KeyValueStore settings) { // Ant Item settings.Set <AntItem>("ZickZackAngle", 10, "Correction Angle after Sprint"); settings.Set <AntItem>("ZickZackRange", 30f, "Distance to go every Sprint"); settings.Set <AntItem>("RotationSpeed", 20, "Maximum Rotation Angle per Round"); settings.Set <AntItem>("DropSugar", false, "Will an Ant leave a small Sugar on Drop"); settings.Set <AntItem>("MarkerDelay", 10, "Time in Rounds between Marker-Drops"); typeMapper.RegisterItem <AntItem, AntState, AntInfo>(this, "Ant"); // Walking settings.Set <AntItem>("MaxSpeed", 1f, "Maximum Speed of an Ant"); typeMapper.AttachItemProperty <AntItem, WalkingProperty>(this, "Ant Walking", (i) => { WalkingProperty property = new WalkingProperty(i); // Set Maximum Speed based on the current Settings // TODO: Check for Castes property.MaximumSpeed = i.Settings.GetFloat <AntItem>("MaxSpeed").Value; // Bind Item Orientation to Walk-Direction property.Direction = i.Orientation; i.OrientationChanged += (item, v) => { property.Direction = v; }; return(property); }); // Collision settings.Set <AntItem>("Mass", 1f, "Collision Mass of an Ant"); typeMapper.AttachItemProperty <AntItem, CollidableProperty>(this, "Ant Collidable", (i) => { CollidableProperty property = new CollidableProperty(i); // Set Mass to Settings property.CollisionFixed = false; property.CollisionMass = i.Settings.GetFloat <AntItem>("Mass").Value; // Bind Collision Radius to Item Radius property.CollisionRadius = i.Radius; i.RadiusChanged += (item, v) => { property.CollisionRadius = v; }; return(property); }); // Visibility typeMapper.AttachItemProperty <AntItem, VisibleProperty>(this, "Ant Visible", (i) => { VisibleProperty property = new VisibleProperty(i); // Bind Visibility Radius to the Item Radius property.VisibilityRadius = i.Radius; i.RadiusChanged += (item, v) => { property.VisibilityRadius = v; }; return(property); }); // Sighting settings.Set <AntItem>("ViewRange", 20f, "View Range of an Ant"); settings.Set <AntItem>("ViewAngle", 360, "View Angle of an Ant"); typeMapper.AttachItemProperty <AntItem, SightingProperty>(this, "Ant Sighting", (i) => { SightingProperty property = new SightingProperty(i); // Set View Range and Angle property.ViewRange = i.Settings.GetFloat <AntItem>("ViewRange").Value; property.ViewAngle = i.Settings.GetFloat <AntItem>("ViewAngle").Value; // Bind View Direction to the Item Orientation property.ViewDirection = i.Orientation; i.OrientationChanged += (item, v) => { property.ViewDirection = v; }; return(property); }); // Sniffer typeMapper.AttachItemProperty <AntItem, SnifferProperty>(this, "Ant Sniffer"); // Carrier settings.Set <AntItem>("CarrierStrength", 10f, "Carrier Strength of an Ant"); typeMapper.AttachItemProperty <AntItem, CarrierProperty>(this, "Ant Carrier", (i) => { CarrierProperty property = new CarrierProperty(i); property.CarrierStrength = i.Settings.GetFloat <AntItem>("CarrierStrength").Value; return(property); }); // Attackable settings.Set <AntItem>("MaxHealth", 100f, "Maximum Health for an Ant"); typeMapper.AttachItemProperty <AntItem, AttackableProperty>(this, "Ant Attackable", (i) => { AttackableProperty property = new AttackableProperty(i); // Bind Attackable Radius to Item Radius property.AttackableRadius = i.Radius; i.RadiusChanged += (item, v) => { property.AttackableRadius = v; }; // Health property.AttackableMaximumHealth = settings.GetInt <AntItem>("MaxHealth").Value; property.AttackableHealth = settings.GetInt <AntItem>("MaxHealth").Value; return(property); }); // Attacker settings.Set <AntItem>("AttackRange", 3f, "Attack Range for a Bug"); settings.Set <AntItem>("RecoveryTime", 2, "Recovery Time in Rounds for a Bug"); settings.Set <AntItem>("AttackStrength", 5, "Attach Strength for a Bug"); typeMapper.AttachItemProperty <AntItem, AttackerProperty>(this, "Ant Attacker", (i) => { AttackerProperty property = new AttackerProperty(i); property.AttackRange = i.Settings.GetFloat <AntItem>("AttackRange").Value; property.AttackRecoveryTime = i.Settings.GetInt <AntItem>("RecoveryTime").Value; property.AttackStrength = i.Settings.GetInt <AntItem>("AttackStrength").Value; return(property); }); // Collector settings.Set <AntItem>("SugarCapacity", 5, "Maximum Capacity for Sugar"); settings.Set <AntItem>("AppleCapacity", 2, "Maximum Capacity for Apple"); typeMapper.AttachItemProperty <AntItem, SugarCollectorProperty>(this, "Ant Sugar Collectable", (i) => { SugarCollectorProperty property = new SugarCollectorProperty(i); property.Capacity = i.Settings.GetInt <AntItem>("SugarCapacity").Value; return(property); }); typeMapper.AttachItemProperty <AntItem, AppleCollectorProperty>(this, "Ant Apple Collectable", (i) => { AppleCollectorProperty property = new AppleCollectorProperty(i); property.Capacity = i.Settings.GetInt <AntItem>("AppleCapacity").Value; return(property); }); // TODO: Optional, wenn _settings.ANT_APPLECOLLECT | _settings.ANT_APPLE_CAPACITY, 0); }
/// <summary> /// Registers classic Bugs /// </summary> /// <param name="typeMapper">Type Mapper</param> /// <param name="settings">Settings</param> private void RegisterClassicBug(ITypeMapper typeMapper, KeyValueStore settings) { // Classic Bug typeMapper.RegisterItem <ClassicBugItem, BugState, BugInfo>(this, "Classic Bug"); // Walking settings.Set <ClassicBugItem>("MaxSpeed", 2f, "Maximum Speed of a Classic Bug"); typeMapper.AttachItemProperty <ClassicBugItem, WalkingProperty>(this, "Classic Bug Walking", (i) => { WalkingProperty property = new WalkingProperty(i); // Set Walking Speed property.MaximumSpeed = i.Settings.GetFloat <ClassicBugItem>("MaxSpeed").Value; // Bind Direction to the Items Orientation property.Direction = i.Orientation; i.OrientationChanged += (item, v) => { property.Direction = v; }; return(property); }); // Collision settings.Set <ClassicBugItem>("Mass", 10f, "Collision Mass of a Classic Bug"); typeMapper.AttachItemProperty <ClassicBugItem, CollidableProperty>(this, "Classic Bug Collidable", (i) => { CollidableProperty property = new CollidableProperty(i); // Set Collision Mass property.CollisionFixed = false; property.CollisionMass = i.Settings.GetFloat <ClassicBugItem>("Mass").Value; // Bind Collision Radius to the Item Radius property.CollisionRadius = i.Radius; i.RadiusChanged += (item, v) => { property.CollisionRadius = v; }; return(property); }); // Visibility typeMapper.AttachItemProperty <ClassicBugItem, VisibleProperty>(this, "Classic Bug Visible", (i) => { VisibleProperty property = new VisibleProperty(i); // Bind Visibility Radius to the Item Radius property.VisibilityRadius = i.Radius; i.RadiusChanged += (item, v) => { property.VisibilityRadius = v; }; return(property); }); // Sighting settings.Set <ClassicBugItem>("ViewRange", 20f, "View Range of a Classic Bug"); settings.Set <ClassicBugItem>("ViewAngle", 360, "View Angle of a Classic Bug"); typeMapper.AttachItemProperty <ClassicBugItem, SightingProperty>(this, "Classic Bug Sighting", (i) => { SightingProperty property = new SightingProperty(i); // Set View Range and Angle property.ViewRange = i.Settings.GetFloat <ClassicBugItem>("ViewRange").Value; property.ViewAngle = i.Settings.GetFloat <ClassicBugItem>("ViewAngle").Value; // Bind View Direction to the Item Orientation property.ViewDirection = i.Orientation; i.OrientationChanged += (item, v) => { property.ViewDirection = v; }; return(property); }); // Sniffer typeMapper.AttachItemProperty <ClassicBugItem, SnifferProperty>(this, "Classic Bug Sniffer"); // Attackable settings.Set <ClassicBugItem>("MaxHealth", 1000, "Maximum Health of a Classic Bug"); typeMapper.AttachItemProperty <ClassicBugItem, AttackableProperty>(this, "Classic Bug Attackable", (i) => { AttackableProperty property = new AttackableProperty(i); // Bind Attackable Radius to Item Radius property.AttackableRadius = i.Radius; i.RadiusChanged += (item, v) => { property.AttackableRadius = v; }; // Health property.AttackableMaximumHealth = settings.GetInt <ClassicBugItem>("MaxHealth").Value; property.AttackableHealth = settings.GetInt <ClassicBugItem>("MaxHealth").Value; return(property); }); // Attacker settings.Set <ClassicBugItem>("AttackRange", 5f, "Attack Range for a Classic Bug"); settings.Set <ClassicBugItem>("RecoveryTime", 5, "Recovery Time in Rounds for a Classic Bug"); settings.Set <ClassicBugItem>("AttackStrength", 10, "Attach Strength for a Classic Bug"); typeMapper.AttachItemProperty <ClassicBugItem, AttackerProperty>(this, "Classic Bug Attacker", (i) => { AttackerProperty property = new AttackerProperty(i); property.AttackRange = i.Settings.GetFloat <ClassicBugItem>("AttackRange").Value; property.AttackRecoveryTime = i.Settings.GetInt <ClassicBugItem>("RecoveryTime").Value; property.AttackStrength = i.Settings.GetInt <ClassicBugItem>("AttackStrength").Value; return(property); }); }