private void Collection_FormClosed(object sender, FormClosedEventArgs e) { FormCollection form = (FormCollection)sender; if (form.DialogResult == DialogResult.OK && form.features != null) { features = form.features; if (form.features.Count != features.Count) { MessageBox.Show("Feature collection has been heavily modified, network will be deleted!", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); nn = null; toolStripStatusLabel2.Text = "---"; toolStripStatusLabel4.Text = "0"; toolStripStatusLabel6.Text = "0"; } else { if (nn != null) { nn._state.features = features; } } PopulateListView(); } }
public virtual void Initialise() { coords = new ChunkCoords(transform.position, EntityNetwork.CHUNK_SIZE); EntityNetwork.AddEntity(this, coords); RepositionInNetwork(true); healthComponent?.SetToUpperLimit(); enabled = true; }
private void OnDestroy() { if (Singleton == this) { CustomMessagingManager.UnregisterNamedMessageHandler("NetworkInput"); CustomMessagingManager.UnregisterNamedMessageHandler("NetworkState"); Singleton = null; } }
public void SelectNetwork(EntityNetwork nn) { this.nn = nn; if (nn != null) { inputHidden = BuildEntityMatrix(nn._state._weightInputHidden, new Point(0, 0), 16, 16 * 3, 16); hiddenOutput = BuildEntityMatrix(nn._state._weightHiddenOutput, new Point(16, 0), 16, 16 * 3, 16); } }
private void Awake() { if (Singleton != null) { Destroy(gameObject); return; } Singleton = this; // TODO: DontDestroyOnLoad(gameObject); }
public void AssignUnoccupiedCoords(GatherBot b) { if (b == null) { return; } CheckEmptyMarkedCoords(); botOccupiedCoords.Clear(); botOccupiedCoords.AddRange(emptyCoords); for (int i = 0; i < childBots.Count; i++) { EntityNetwork.IterateCoordsInRange( childBots[i].GetIntendedCoords(), 1, cc => { botOccupiedCoords.Add(cc); return(false); }, false); } //find a random nearby coordinate that is not already occupied int searchRange = 1; ChunkCoords location = ChunkCoords.Invalid; while (location == ChunkCoords.Invalid) { EntityNetwork.IterateCoordsOnRangeBorder( coords, searchRange, cc => { if (botOccupiedCoords.Contains(cc)) { return(false); } if (Random.value < 0.1f) { location = cc; return(true); } return(false); }, false); searchRange++; } Vector2 pos = ChunkCoords.GetCenterCell(location, EntityNetwork.CHUNK_SIZE); b.HiveOrders(pos); }
private void Form_FormClosed(object sender, FormClosedEventArgs e) { FormCreateNetwork form = (FormCreateNetwork)sender; if (form.DialogResult == DialogResult.OK) { nn = new EntityNetwork(features, form.hiddenLayer, form.learningRate); toolStripStatusLabel2.Text = nn._state.name; toolStripStatusLabel4.Text = nn._state._weightInputHidden.GetLength(0).ToString(); toolStripStatusLabel6.Text = nn._state._learningRate.ToString("0.00"); } }
public virtual void DestroySelf(Entity destroyer, float dropModifier) { if (destroyer) { destroyer.DestroyedAnEntity(this); } if (EntityNetwork.ConfirmLocation(this, coords)) { EntityNetwork.RemoveEntity(this); } IInventoryHolder target = destroyer as IInventoryHolder; DropLoot(target, dropModifier); Destroy(gameObject); }
private void Awake() { if (instance != this && instance != null) { Destroy(gameObject); return; } instance = this; Debug.Log("Loading Entity Network"); gridIsSetUp = true; Debug.Log("Entity Network Loaded"); OnLoaded?.Invoke(); OnLoaded = null; }
private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); return; } holder.SetActive(true); AddListener(() => { holder.SetActive(false); }); if (FindObjectOfType <SceneryController>()) { int ID = loadingReady.Count; loadingReady.Add(false); SceneryController.AddListener(() => { Ready(ID); }); } if (FindObjectOfType <EntityGenerator>()) { int ID = loadingReady.Count; loadingReady.Add(false); EntityGenerator.AddListener(() => { Ready(ID); }); } if (FindObjectOfType <EntityNetwork>()) { int ID = loadingReady.Count; loadingReady.Add(false); EntityNetwork.AddListener(() => { Ready(ID); }); } }
private void CoordsChanged(ChunkCoords newCoords, ChunkCoords oldCoords) { HashSet <ChunkCoords> activeCoords = new HashSet <ChunkCoords>(); HashSet <ChunkCoords> removedCoords = new HashSet <ChunkCoords>(); //send some active objects to the transition pool for (int i = active.Count - 1; i >= 0; i--) { StarFieldMaterialPropertyManager sfmpm = active[i]; activeCoords.Add(sfmpm.coord); if (ChunkCoords.SquareDistance(sfmpm.coord, newCoords) > ViewDistance) { removedCoords.Add(sfmpm.coord); active.RemoveAt(i); transitionActive.Add(sfmpm); } } //activate or create new items to fill in the scenery EntityNetwork.IterateCoordsInRange(newCoords, ViewDistance, cc => { int dist = ChunkCoords.SquareDistance(cc, oldCoords); if (dist <= ViewDistance && dist != -1) { return(false); } ChunkCoords loopedCoords = cc; if (hasLoopPoint) { loopedCoords.x = Mathf.Abs(cc.x) % loopSize; loopedCoords.y = Mathf.Abs(cc.y) % loopSize; } FillSpace(loopedCoords); //create new cosmic items if (Chunk(loopedCoords).Count == 0) { FillChunk(loopedCoords); } SetUpScenery(cc, loopedCoords); return(false); }, true); }
public FormCoverage(Image image, EntityNetwork nn) { InitializeComponent(); /// Load source image sourceBitmap = new Bitmap(image); this.nn = nn; entityBox1.Mode = EntityMode.ImageLayer0; entityBox1.LoadImage(image); entityBox1.Mode = EntityMode.Selection; /// Fill combobox by Features for (int i = 0; i < nn._state.features.Count; i++) { comboBox1.Items.Add(nn.GetFeatureName(i)); } }
/// Disables all entities previously in view, gets a new list of entities and enables them. private void UpdateEntitiesInView(ChunkCoords newCoords, ChunkCoords oldCoords) { //keep track of coords previous in view //query the EntityNetwork for a list of coordinates in view based on camera's size int range = ENTITY_VIEW_RANGE + RangeModifier; EntityNetwork.IterateEntitiesInRange( oldCoords, range, e => { ChunkCoords eCC = e.GetCoords(); if (!IsInRange(newCoords, eCC, range) || !newCoords.IsValid() || !eCC.IsValid()) { e.RepositionInNetwork(true); } return(false); }); EntityNetwork.IterateEntitiesInRange( newCoords, range, e => { ChunkCoords eCC = e.GetCoords(); if (IsInRange(oldCoords, eCC, range) || !oldCoords.IsValid() || !eCC.IsValid()) { e.RepositionInNetwork(true); } return(false); }); CheckPhysicsRange(newCoords, oldCoords); }
public void RepositionInNetwork(bool forceUpdate) { ChunkCoords newCc = new ChunkCoords(transform.position, EntityNetwork.CHUNK_SIZE); if (newCc == coords && !forceUpdate) { return; } EntityNetwork.Reposition(this, newCc); bool foundInPhysicsRange = CheckIfInPhysicsRange(); bool foundInViewRange = CheckInCameraViewRange(); bool justEnteredPhysicsRange = !IsInPhysicsRange && foundInPhysicsRange; bool justExitedPhysicsRange = IsInPhysicsRange && !foundInPhysicsRange; bool justEnteredViewRange = !IsInViewRange && foundInViewRange; bool justExitedViewRange = IsInViewRange && !foundInViewRange; if (justEnteredPhysicsRange) { IsInPhysicsRange = true; OnEnterPhysicsRange(); } if (justExitedPhysicsRange) { IsInPhysicsRange = false; OnExitPhysicsRange(); } if (justEnteredViewRange) { IsInViewRange = true; OnEnterViewRange(); } if (justExitedViewRange) { IsInViewRange = false; OnExitViewRange(); } }
private ChunkCoords ClosestValidNonFilledChunk(SpawnableEntity se) { int minRange = Mathf.Max(0, se.rarityZoneOffset); ChunkCoords coords = ChunkCoords.Invalid; while (coords == ChunkCoords.Invalid) { EntityNetwork.IterateCoordsOnRangeBorder(ChunkCoords.Zero, minRange, cc => { if (!Chunk(cc)) { coords = cc; return(true); } return(false); }, true); minRange++; } return(ChunkCoords.Invalid); }
private void loadNetworkToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult res = openFileDialog2.ShowDialog(); if (res == DialogResult.OK) { string filename = openFileDialog2.FileName; XmlSerializer ser = new XmlSerializer(typeof(EntityNetwork.State)); using (FileStream fs = new FileStream(filename, FileMode.Open)) { EntityNetwork.State state = (EntityNetwork.State)ser.Deserialize(fs); nn = new EntityNetwork(state); features = nn._state.features; toolStripStatusLabel2.Text = state.name; toolStripStatusLabel4.Text = state._weightInputHidden.GetLength(0).ToString(); toolStripStatusLabel6.Text = state._learningRate.ToString("0.00"); } } }
private void SearchForNearestAsteroid() { int searchRange = 1; Asteroid closestAsteroid = null; float closestDistance = float.PositiveInfinity; while (closestAsteroid == null) { EntityNetwork.IterateEntitiesInRange( coords, searchRange, e => { if (e is Asteroid asteroid) { if ((hive != null && hive.VerifyGatheringTarget(this, e)) || hive == null) { float dist = Vector2.Distance(transform.position, e.transform.position); if (dist < closestDistance) { closestDistance = dist; closestAsteroid = asteroid; } } } return(false); }); searchRange++; } targetEntity = closestAsteroid; searchTimer = Pause.timeSinceOpen; }
private void CheckPhysicsRange(ChunkCoords newCoords, ChunkCoords oldCoords) { int range = Constants.MAX_PHYSICS_RANGE; EntityNetwork.IterateEntitiesInRange( oldCoords, range, e => { ChunkCoords eCC = e.GetCoords(); if (!IsInRange(newCoords, eCC, range) || !newCoords.IsValid() || !eCC.IsValid()) { e.RepositionInNetwork(true); } return(false); }); EntityNetwork.IterateEntitiesInRange( newCoords, range, e => { ChunkCoords eCC = e.GetCoords(); if (IsInRange(oldCoords, eCC, range) || !oldCoords.IsValid() || !eCC.IsValid()) { e.RepositionInNetwork(true); } return(false); }); }
protected virtual void Scanning() { if (rb.velocity.sqrMagnitude < 0.01f) { if (!scanStarted) { if (IsInViewRange) { StartCoroutine(ScanRings()); } scanStarted = true; entitiesScanned.Clear(); new Thread(() => { EntityNetwork.IterateEntitiesInRange( coords, 1, e => { if (e != this) { entitiesScanned.Add(e); } return(false); }); }).Start(); } else { scanTimer += Time.deltaTime; } if (scanTimer >= scanDuration) { scanTimer = 0f; scanStarted = false; //look for the first unusual entity in the scan for (int i = 0; i < entitiesScanned.Count; i++) { Entity e = entitiesScanned[i]; if (IsScary(e)) { hive?.MarkCoordAsEmpty(coords); SetState(AIState.Exploring); return; } ICombat threat = e.GetICombat(); if (threat != null && IsSuspicious(threat)) { nearbySuspects.Add(threat); } } if (nearbySuspects.Count > 0) { SetState(AIState.Suspicious); return; } //choose state if (entitiesScanned.Count >= 10) { SetState(AIState.Gathering); } else { hive?.MarkCoordAsEmpty(coords); SetState(AIState.Exploring); } } } }
private void OnDestroy() { EntityNetwork.RemoveEntity(this); mainCam = null; mainCamCtrl = null; }
public FormDebugger(EntityNetwork nn) { InitializeComponent(); SelectNetwork(nn); }