public void NotifyManager(Event e, object o) { // Debug.Log("Event send to the manager !"); if (e == Event.BlueprintDrawn) { // Debug.Log("Blueprint Drawn event received"); EnemyManager.S.RecalculateZone(); } else if (e == Event.RoomSetType) { SubmarineManager.S.UpdateRoom((GenericRoom)o); MiningManager.S.UpdateRoom((GenericRoom)o); } AudioManager.S.ReceiveEvent(e); if (e == Event.BlueprintFinished) { ARoom room = (ARoom)o; MapManager.S.NotifyBluePrintFininshed(room); } if (e == Event.MasterBlueprintFinished) { MasterBlueprint mbp = (MasterBlueprint)o; MapManager.S.NotifyMasterBluePrintFininshed(mbp); } foreach (var agent in _agents) { agent.OnEventReceived(e, o); } }
public void MoveToRoom(ARoom target) { _currentRoom = target; transform.position = new Vector3( _currentRoom.Position.x + 0.5f, -_currentRoom.Position.y + 0.1f, 0f ); }
public void NotifyBlueprintFinished(ARoom room) { var bp = Blueprints.First(bp => bp.RoomRef == room); Blueprints.Remove(bp); if (Blueprints.Count == 0) { EventManager.S.NotifyManager(Events.Event.MasterBlueprintFinished, this); } }
public Requirement(ARoom room, ResourceInfo[] resources, bool isEndless) { _endlessMode = isEndless; _room = room; foreach (var r in resources) { int amount = r.Amount; do { var nb = amount > ConfigManager.S.Config.NbOfResourcePerTransportation ? ConfigManager.S.Config.NbOfResourcePerTransportation : amount; _waiting.Add((r.Type, nb)); amount -= nb; if (_endlessMode && !_endlessReserve.ContainsKey(r.Type)) { _endlessReserve.Add(r.Type, 0); } } while (amount > 0); } }
public static List <ARoom> FindPath(ARoom startPosition, ARoom endPosition) { if (startPosition == endPosition) { return(new List <ARoom>()); } List <Node> openSet = new List <Node>(); HashSet <Node> closedSet = new HashSet <Node>(); Node startingNode = new Node(startPosition); openSet.Add(startingNode); while (openSet.Count > 0) { Node currentNode = openSet[0]; for (int i = 1; i < openSet.Count; ++i) { Node runningNode = openSet[i]; if (runningNode.fCost < currentNode.fCost || runningNode.fCost == currentNode.fCost && runningNode.hCost < currentNode.hCost) { currentNode = openSet[i]; } } openSet.Remove(currentNode); closedSet.Add(currentNode); if (currentNode.currentNode == endPosition) { return(RetracePath(startingNode, currentNode)); } foreach (ARoom neighbor in currentNode.currentNode.GetNeighborhood()) { Node neighbour = new Node(neighbor); if (closedSet.Any(x => x.currentNode.Myid == neighbour.currentNode.Myid)) { continue; } float newMovementCostToNeighbour = currentNode.gCost + neighbour.currentNode.GetCost(); if (newMovementCostToNeighbour < neighbour.gCost || !openSet.Any(x => x.currentNode.Myid == neighbour.currentNode.Myid)) { neighbour.gCost = newMovementCostToNeighbour; neighbour.hCost = ARoom.GetDistance(neighbor, endPosition); neighbour.parent = currentNode; if (!openSet.Any(x => x.currentNode.Myid == neighbour.currentNode.Myid)) { openSet.Add(neighbour); } } } } return(new List <ARoom>()); }
private void Update() { // We want the user to click and release his mouse on the same element if (Input.GetMouseButtonDown(0)) { currInfoD = null; var mousePos = Input.mousePosition; mousePos.z = -Camera.main.transform.position.z; var pos = Camera.main.ScreenToWorldPoint(mousePos); var pos2d = (Vector2)pos; var room = MapManager.S.MapRooms.FirstOrDefault((x) => { var xSize = x.Size.x / 2f; return(pos2d.x > x.GameObject.transform.position.x - xSize && pos2d.x < x.GameObject.transform.position.x + xSize && pos2d.y > x.GameObject.transform.position.y && pos2d.y < x.GameObject.transform.position.y + x.Size.y); }); if (room != null) { if (_currentSelection != null && room.IsBuilt) // We want to change the type of a room { clicked = room as GenericRoom; if (clicked != null && !clicked.RoomType.IsEmpty()) { clicked = null; } } else // Display info about a room { _roomInfo.Name.text = room.GetName(); _roomInfo.Description.text = room.GetDescription(); if (_roomInfo.DetailPanel.transform.childCount > 0) { Destroy(_roomInfo.DetailPanel.transform.GetChild(0).gameObject); } var gRoom = room as GenericRoom; if (gRoom != null || room.IsBuilt) { var p = room.IsBuilt ? gRoom.RoomType.GetDescriptionPanel() : room.GetDescriptionPanel(); if (p != null) { var go = Instantiate(p, _roomInfo.DetailPanel.transform); var t = (RectTransform)go.transform; var pT = (RectTransform)_roomInfo.DetailPanel.transform; t.sizeDelta = Vector2.zero; t.position = pT.position; if (room.IsBuilt) { gRoom.RoomType.SetupConfigPanel(go); } else { room.SetupConfigPanel(go); } } } _roomInfo.gameObject.SetActive(true); currInfoD = gRoom; } } else if (Input.mousePosition.x < Screen.width - 200 || Input.mousePosition.y < Screen.height - 300) { _roomInfo.gameObject.SetActive(false); } } if (Input.GetMouseButtonUp(0) && clicked != null && clicked.IsBuilt) { clicked.RoomType = ModularRoomFactory.BuildModularRoom(_currentSelection.Value, clicked); int index; if (clicked.Size.x == 2) { if (clicked.Size.y == 1) { index = 0; } else { index = 1; } } else { if (clicked.Size.y == 1) { index = 2; } else { index = 3; } } GameObject go; if (_currentSelection.Value == RoomType.AIRLOCK) { go = PAirlock[index]; } else if (_currentSelection.Value == RoomType.DEFENSE) { go = PDefense[index]; } else if (_currentSelection.Value == RoomType.FACTORY) { go = PFactory[index]; } else if (_currentSelection.Value == RoomType.MINING) { go = PMining[index]; } else if (_currentSelection.Value == RoomType.STORAGE) { go = PStorage[index]; } else { go = null; } if (go != null) { var n = Instantiate(go, clicked.GameObject.transform.position, Quaternion.Euler(0f, 180f, 0f)); Destroy(clicked.GameObject); clicked.GameObject = n; } EventManager.S.NotifyManager(Events.Event.RoomSetType, clicked); clicked = null; SetCurrentBuild(-1); } if (Input.GetMouseButtonDown(1)) // Reset selection { currInfoD = null; if (_currentSelection != null) { SetCurrentBuild(-1); } SubmarineManager.S.RemoveSubmarinePlacementMode(); } }
public Node(ARoom node) { this.currentNode = node; }
public override void addRoom(string roomName) { rooms.Add(ARoom.createRoom(roomName)); }
public bool Contains(ARoom room) { return(Blueprints.Select(bp => bp.RoomRef).Contains(room)); }
public Blueprint(ARoom room) { RoomRef = room; }
private void GenerateNewMasterBlueprint() { // Choose between Expansion or Descent bool descent = Random.Range(0f, 1f) < ConfigManager.S.Config.ChangeBuildElevator; if (descent) { // choose the layer at the bottom int bottomLayer = MapManager.S.MapRooms.Select(room => room.Position.y).Max(); // try to place a lift at the right or left of each room in this layer var rrls = MapManager.S.MapRooms.Where( room => room.Position.y == bottomLayer && (room.RoomLeft == null || room.RoomRight == null) ).Select( room => (room, MapManager.S.GetZoneLiftPossibilities(room.Position + new Vector2Int(room.Size.x, 0), true, 1, 6), MapManager.S.GetZoneLiftPossibilities(room.Position, false, 1, 6)) ).Where( rrl => (rrl.Item2.Count > 0 || rrl.Item3.Count > 0) ).ToList(); if (rrls.Count > 0) { var rrl = rrls[Random.Range(0, rrls.Count)]; List <int> directionChoices = new List <int>(); if (rrl.Item2.Count > 0) { directionChoices.Add(0); } if (rrl.Item3.Count > 0) { directionChoices.Add(1); } int direction = directionChoices[Random.Range(0, directionChoices.Count)]; var blueprints = (direction == 0) ? rrl.Item2 : rrl.Item3; var blueprint = blueprints[Random.Range(0, blueprints.Count)]; ARoom runningRoom = rrl.Item1; List <ARoom> roomList = new List <ARoom>(); // Debug.Log("Direction : " + ((direction == 0) ? "Rigth" : "Left") + " ------------------------------------------------------"); if (direction == 0) { for (int corridor = 0; corridor < blueprint.Item1; ++corridor) { runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x + runningRoom.Size.x, runningRoom.Position.y), new Vector2Int(1, 1), MapManager.S.Corridor, RoomType.CORRIDOR, runningRoom, null, true ); roomList.Add( runningRoom ); } runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x + runningRoom.Size.x, runningRoom.Position.y), new Vector2Int(1, 1), MapManager.S.Elevator, RoomType.ELEVATOR, runningRoom, null, true ); roomList.Add( runningRoom ); for (int depth = 0; depth < blueprint.Item2 - 1; ++depth) { runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x, runningRoom.Position.y + 1), new Vector2Int(1, 1), MapManager.S.Corridor, RoomType.CORRIDOR, runningRoom, null, true ); roomList.Add( runningRoom ); } runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x, runningRoom.Position.y + 1), new Vector2Int(1, 1), MapManager.S.Elevator, RoomType.ELEVATOR, runningRoom, null, true ); roomList.Add( runningRoom ); } else { for (int corridor = 0; corridor < blueprint.Item1; ++corridor) { runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x - 1, runningRoom.Position.y), new Vector2Int(1, 1), MapManager.S.Corridor, RoomType.CORRIDOR, runningRoom, null, true ); roomList.Add( runningRoom ); } runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x - runningRoom.Size.x, runningRoom.Position.y), new Vector2Int(1, 1), MapManager.S.Elevator, RoomType.ELEVATOR, runningRoom, null, true ); roomList.Add( runningRoom ); for (int depth = 0; depth < blueprint.Item2 - 1; ++depth) { runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x, runningRoom.Position.y + 1), new Vector2Int(1, 1), MapManager.S.Corridor, RoomType.CORRIDOR, runningRoom, null, true ); roomList.Add( runningRoom ); } runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x, runningRoom.Position.y + 1), new Vector2Int(1, 1), MapManager.S.Elevator, RoomType.ELEVATOR, runningRoom, null, true ); roomList.Add( runningRoom ); } // Debug.Break(); MapManager.S.MapMasterBlueprints.Add(new Map.Blueprints.MasterBlueprint( roomList.Select(room => new Blueprint(room)).ToList(), _id )); EventManager.S.NotifyManager(Events.Event.BlueprintDrawn, this); return; } // if not possible, try building a classic room } { // for each room get the list of all possible expansions var rprl = MapManager.S.MapRooms.Where( room => room.RoomLeft == null || room.RoomRight == null ).Select( room => (room, (float)room.Position.x + 3 * room.Position.y, MapManager.S.GetZoneConstructionPossibilities(room.Position + new Vector2Int(room.Size.x, 0), true, 1, 6), MapManager.S.GetZoneConstructionPossibilities(room.Position, false, 1, 2)) ).Where( rprl => (rprl.Item3.Count > 0) || (rprl.Item4.Count > 0) ).ToList(); if (rprl.Count == 0) { return; } float total = 0; foreach (var rprlVal in rprl) { total += rprlVal.Item2; } int i = 0; { float choice = Random.Range(0f, total) - rprl[0].Item2; while (choice > 0f) { ++i; choice -= rprl[i].Item2; } } // for each expansion, associate a probability weigth var choosenRoom = rprl[i]; // Debug.Log("ChoosenRoom lists : " + choosenRoom.Item3.Count + ", " + choosenRoom.Item4.Count); List <int> directionChoices = new List <int>(); if (choosenRoom.Item3.Count > 0) { directionChoices.Add(0); } if (choosenRoom.Item4.Count > 0) { directionChoices.Add(1); } // Debug.Log("DirectionChoices : " + directionChoices.Count); int direction = directionChoices[Random.Range(0, directionChoices.Count)]; var blueprints = (direction == 0) ? choosenRoom.Item3 : choosenRoom.Item4; var blueprint = blueprints[Random.Range(0, blueprints.Count)]; ARoom runningRoom = choosenRoom.Item1; List <ARoom> roomList = new List <ARoom>(); // Debug.Log("Direction : " + ((direction == 0) ? "Rigth" : "Left") + " ------------------------------------------------------"); if (direction == 0) { for (int corridor = 0; corridor < blueprint.Item1; ++corridor) { runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x + runningRoom.Size.x, runningRoom.Position.y), new Vector2Int(1, 1), MapManager.S.Corridor, RoomType.CORRIDOR, runningRoom, null, true ); roomList.Add( runningRoom ); } var roominfo = MapManager.S.Rooms.First(ri => ri.Size.x == blueprint.Item2 && ri.Size.y == blueprint.Item3); runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x + runningRoom.Size.x, runningRoom.Position.y), new Vector2Int(blueprint.Item2, blueprint.Item3), roominfo.GameObject, RoomType.EMPTY, runningRoom, null, true ); roomList.Add( runningRoom ); } else { for (int corridor = 0; corridor < blueprint.Item1; ++corridor) { runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x - 1, runningRoom.Position.y), new Vector2Int(1, 1), MapManager.S.Corridor, RoomType.CORRIDOR, runningRoom, null, true ); roomList.Add( runningRoom ); } var roominfo = MapManager.S.Rooms.First(ri => ri.Size.x == blueprint.Item2 && ri.Size.y == blueprint.Item3); runningRoom = MapManager.S.AddRoom( new Vector2Int(runningRoom.Position.x - blueprint.Item2, runningRoom.Position.y), new Vector2Int(blueprint.Item2, blueprint.Item3), roominfo.GameObject, RoomType.EMPTY, runningRoom, null, true ); roomList.Add( runningRoom ); } // Debug.Break(); MapManager.S.MapMasterBlueprints.Add(new Map.Blueprints.MasterBlueprint( roomList.Select(room => new Blueprint(room)).ToList(), _id )); EventManager.S.NotifyManager(Events.Event.BlueprintDrawn, this); } }
public PCSource(ARoom room, SourceConfig config) : base(room, config, null) { TryParseMacAddressFromConfigString(config); }
public InternalBookOrderFactory(AUser user, ARoom room, AEvent thing) : base(user, room, thing) { }
public GenericSource(ARoom room, SourceConfig config, ISourceDevice device) : base(room, config, device) { }
public GenericSource(ARoom room, SourceConfig config) : base(room, config, null) { }
public ABookOrderFactory(AUser user, ARoom room, AEvent thing) { User = user; Room = room; Event = thing; }
public TVSource(ARoom room, SourceConfig config) : base(room, config, null) { _clientId = config.DeviceAddressNumber; }
private IEnumerator ChooseAction(/*??*/) { while (true) { // Debug.Log("ChooseAction begin"); // First of all, if _currentRoom is null, let's try to find where we are if (_currentRoom == null) { // Debug.Log(" Checking for room"); // Debug.Log(" My pos : " + transform.position.x + ", " + transform.position.y); foreach (var room in MapManager.S.MapRooms) { // Debug.Log(" Room pos :"); // Debug.Log(" (" + room.Position.x + ", " + room.Position.y + ") (" + (room.Position.x + room.Size.x) + ", " + (room.Position.y + room.Size.y) + ")"); if (transform.position.x >= room.Position.x && transform.position.x <= room.Position.x + room.Size.x && -transform.position.y >= room.Position.y && -transform.position.y <= room.Position.y + room.Size.y ) { _currentRoom = room; break; } } // if _currentRoom is still null ... we are in the water ! if (_currentRoom == null) { // Debug.Log(" Still no room => aborting"); yield return(new WaitForSeconds(1f)); } } if (_currentAction == Action.Idle) { // Debug.Log(" Currently Idle"); float actionChoice = Random.Range(0f, 1f); if (actionChoice < 0.9f) // 10% chance build a new room { // Debug.Log(" Will Build"); // go to building mode // 1) choose a room from where to expand List <(ARoom room, float weight)> choices = new List <(ARoom room, float weight)>(); foreach (ARoom room in MapManager.S.MapRooms) { if (room.RoomLeft == null || room.RoomRight == null) { choices.Add((room, (float)room.Position.x + 3 * room.Position.y)); } } // if there is room to expand if (choices.Count > 0) { float total = 0; foreach ((var _, var weight) in choices) { total += weight; } float choice = Random.Range(0f, total) - choices[0].weight; int i = 0; while (choice > 0f) { ++i; choice -= choices[i].weight; } // i is the choosen room _targetRoom = choices[i].room; // 2) set the path to the target room _roomPath = Astar.FindPath(_currentRoom, _targetRoom); // Debug.Log(" Going to room (" + _targetRoom.Position.x + ", " + _targetRoom.Position.y + ") to build"); _currentAction = Action.Building; } } else { // move to a random room _targetRoom = MapManager.S.MapRooms[Random.Range(0, MapManager.S.MapRooms.Count)]; _roomPath = Astar.FindPath(_currentRoom, _targetRoom); // Debug.Log(" Going to room (" + _targetRoom.Position.x + ", " + _targetRoom.Position.y + ")"); } } else if (_currentAction == Action.Building) { // Debug.Log(" Currently Building"); if (_roomPath.Count > 0) { // still moving var room = _roomPath[0]; // Debug.Log(" Still Moving to (" + room.Position.x + ", " + room.Position.y + ")"); // Go to next room MoveToRoom(room); _roomPath.RemoveAt(0); } else { // Debug.Log(" Building Room/Corridor"); // We are at the building room _targetRoom = null; // now start building if (_currentRoom is Corridor) { // Debug.Log(" In a corridor"); if (Random.Range(0f, 1f) < 0.75f) // 75% expand corridor { // Debug.Log(" Expanding corridor"); // Debug.Log(" In the same direction"); ARoom corridor = null; if (_currentRoom.RoomLeft != null) // we are going from left to right { corridor = MapManager.S.AddRoom(new Vector2Int(_currentRoom.Position.x + 1, _currentRoom.Position.y), new Vector2Int(1, 1), MapManager.S.Corridor, RoomType.CORRIDOR, _currentRoom, null, false); } else // right to left { corridor = MapManager.S.AddRoom(new Vector2Int(_currentRoom.Position.x - 1, _currentRoom.Position.y), new Vector2Int(1, 1), MapManager.S.Corridor, RoomType.CORRIDOR, _currentRoom, null, false); } _targetRoom = corridor; _roomPath = Astar.FindPath(_currentRoom, _targetRoom); } else // 25% build a room { // Debug.Log(" Build a new room"); ARoom room = null; if (_currentRoom.RoomLeft != null) // we are going from left to right { // Debug.Log(" To the right"); room = MapManager.S.AddRoom(new Vector2Int(_currentRoom.Position.x + 1, _currentRoom.Position.y), new Vector2Int(2, 1), MapManager.S.ReceptionRoom, RoomType.EMPTY, _currentRoom, null, false); } else // right to left { // Debug.Log(" To the left"); room = MapManager.S.AddRoom(new Vector2Int(_currentRoom.Position.x - 2, _currentRoom.Position.y), new Vector2Int(2, 1), MapManager.S.ReceptionRoom, RoomType.EMPTY, _currentRoom, null, false); } _currentAction = Action.Idle; _targetRoom = room; _roomPath = Astar.FindPath(_currentRoom, _targetRoom); } } else // not a corridor => we are in a room and we start a corridor { // Debug.Log(" In a room"); // Right/Left?? List <int> directions = new List <int>(); if (_currentRoom.RoomRight == null) { directions.Add(0); } if (_currentRoom.RoomLeft == null) { directions.Add(1); } if (directions.Count > 0) { // Debug.Log(" Building Corridor"); // choose one int choice = directions[Random.Range(0, directions.Count)]; if (choice == 0) // add to the right { // Debug.Log(" to the right"); var corridor = MapManager.S.AddRoom(new Vector2Int(_currentRoom.Position.x + _currentRoom.Size.x, _currentRoom.Position.y), new Vector2Int(1, 1), MapManager.S.Corridor, RoomType.CORRIDOR, _currentRoom, null, false); _targetRoom = corridor; _roomPath = Astar.FindPath(_currentRoom, _targetRoom); } else // add to the left { // Debug.Log(" to the left"); var corridor = MapManager.S.AddRoom(new Vector2Int(_currentRoom.Position.x - 1, _currentRoom.Position.y), new Vector2Int(1, 1), MapManager.S.Corridor, RoomType.CORRIDOR, _currentRoom, null, false); _targetRoom = corridor; _roomPath = Astar.FindPath(_currentRoom, _targetRoom); } } } } } else if (_roomPath.Count > 0) { // Debug.Log(" Currently Moving"); var room = _roomPath[0]; // Debug.Log(" to (" + room.Position.x + ", " + room.Position.y + ")"); // we are moving MoveToRoom(room); _roomPath.RemoveAt(0); } else { // Debug.Log(" Currently Stopped Moving"); // we stopped moving ... _targetRoom = null; _currentAction = Action.Idle; } // Debug.Log("ChooseAction End, starting anew ..."); yield return(new WaitForSeconds(0.1f)); // ChooseAction(); } }