private void Generator_Simulate() { Vector3 offset = (0.5f * Vector3.right) + (0.5f * Vector3.up); foreach (var generator in generator_dictionary) { // If the generator has a wire under it if (energy_dictionary.ContainsKey(generator.Key)) { Energy_Tile new_tile = new Energy_Tile(); new_tile.energy_level = energy_dictionary[generator.Key].energy_level + 1; new_tile.tiletype = energy_dictionary[generator.Key].tiletype; new_tile.energy_origin = DIRECTION.NULL; new_tile.has_changed_this_step = false; if (energy_buffer.ContainsKey(generator.Key)) { energy_buffer[generator.Key] = new_tile; } else { energy_buffer.Add(generator.Key, new_tile); } } } }
private void Initiate_Transfer(Dictionary <Vector3Int, Energy_Tile> i_buffer, Vector3Int i_transfer_pos, DIRECTION i_origin_dir, DIRECTION i_transfer_direction, int i_delta, bool is_cumulative) { Energy_Tile new_tile = new Energy_Tile(); if (is_cumulative) { new_tile.energy_level = energy_dictionary[i_transfer_pos].energy_level + i_delta; } else { new_tile.energy_level = i_delta; } new_tile.energy_origin = i_origin_dir; new_tile.tiletype = energy_dictionary[i_transfer_pos].tiletype; new_tile.has_changed_this_step = false; new_tile.transfer_direction = energy_dictionary[i_transfer_pos].transfer_direction; if (i_buffer.ContainsKey(i_transfer_pos)) { i_buffer[i_transfer_pos].energy_level += i_delta; i_buffer[i_transfer_pos].transfer_direction = energy_dictionary[i_transfer_pos].transfer_direction; i_buffer[i_transfer_pos].energy_origin = i_origin_dir; } else { i_buffer.Add(i_transfer_pos, new_tile); } }
private Energy_Tile Create_Energy_Tile(TileBase i_tile) { Energy_Tile temp_energy = new Energy_Tile(); temp_energy.tiletype = i_tile; temp_energy.energy_level = 0; temp_energy.energy_origin = DIRECTION.NULL; temp_energy.transfer_direction = DIRECTION.NULL; temp_energy.has_changed_this_step = false; return(temp_energy); }
private DIRECTION Check_Valid_Directions(Vector3Int i_pos, Energy_Tile i_tile) { DIRECTION return_dir = new DIRECTION(); if (energy_dictionary.ContainsKey(i_pos)) { if (energy_dictionary.ContainsKey(i_pos + Vector3Int.up)) { return_dir |= DIRECTION.UP; } if (energy_dictionary.ContainsKey(i_pos + Vector3Int.right)) { return_dir |= DIRECTION.RIGHT; } if (energy_dictionary.ContainsKey(i_pos - Vector3Int.up)) { return_dir |= DIRECTION.DOWN; } if (energy_dictionary.ContainsKey(i_pos - Vector3Int.right)) { return_dir |= DIRECTION.LEFT; } DIRECTION change_dir = i_tile.transfer_direction; if (change_dir == DIRECTION.NULL) { change_dir = DIRECTION.UP; } int counter = 0; bool has_completed = false; while (counter < 4) { change_dir = (DIRECTION)((int)(change_dir) << 1); if (change_dir == DIRECTION.OVER) { change_dir = DIRECTION.UP; } if (((change_dir & return_dir) == change_dir) && (((change_dir & i_tile.energy_origin) != i_tile.energy_origin) || (i_tile.energy_origin == DIRECTION.NULL))) { i_tile.transfer_direction = change_dir; has_completed = true; counter = 4; } counter++; } if (has_completed) { // do transfer Transfer_Energy(i_pos, i_tile.energy_level, change_dir); } else { Transfer_Energy(i_pos, i_tile.energy_level, DIRECTION.OVER); // Send energy to the receptor or dissipate it if (!Send_To_Receptor(i_pos, i_tile.energy_level)) { //Debug.Log("Energy Dissipated: " + i_tile.energy_level); } } } return(return_dir); }