Esempio n. 1
0
 public City(MainForm contextForm, MapWorld world, MapCity City)
 {
     InitializeComponent();
     _contextForm = contextForm;
     _world       = world;
     _city        = City;
 }
Esempio n. 2
0
    public void ActivateAdvance(MapCity mapCity)
    {
        Debug.Log("Show City info");
        // verify if there is a hero in the city
        if (mapCity.LMapHero != null)
        {
            // Get Lefto Hero Party UI
            HeroPartyUI leftHeroPartyUI = transform.root.Find("MiscUI/LeftHeroParty").GetComponent <HeroPartyUI>();
            // assign HeroParty to left hero party UI
            leftHeroPartyUI.LHeroParty = mapCity.LCity.GetHeroPartyByMode(PartyMode.Party);
            // activate left hero party UI
            leftHeroPartyUI.gameObject.SetActive(true);
            // deactivate inventory
            leftHeroPartyUI.GetComponentInChildren <PartyInventoryUI>(true).gameObject.SetActive(false);
            //// Activate placeholder to be used as background
            //transform.Find("LeftPartyInfoPlaceHolder").gameObject.SetActive(true);
        }
        else
        {
            // No hero in city
            // Display black box
            transform.Find("LeftPartyInfoPlaceHolder").gameObject.SetActive(true);
        }
        // Get Right Hero Party UI
        HeroPartyUI rightHeroPartyUI = transform.root.Find("MiscUI/RightHeroParty").GetComponent <HeroPartyUI>();

        // assign City garnizon HeroParty to right hero party UI
        rightHeroPartyUI.LHeroParty = mapCity.LCity.GetHeroPartyByMode(PartyMode.Garnizon);
        // activate right hero party UI
        rightHeroPartyUI.gameObject.SetActive(true);
        // deactivate inventory
        rightHeroPartyUI.GetComponentInChildren <PartyInventoryUI>(true).gameObject.SetActive(false);
        //// Activate placeholder to be used as background
        //transform.Find("RightPartyInfoPlaceHolder").gameObject.SetActive(true);
    }
Esempio n. 3
0
    public IEnumerator EnterCityEditMode(MapCity mapCity)
    {
        //Debug.Log("EnterCityEditMode");
        mapCity.DimmLabel();
        // Block mouse input
        // InputBlocker inputBlocker = transform.root.Find("MiscUI/InputBlocker").GetComponent<InputBlocker>();
        InputBlocker.SetActive(true);
        // Wait for all animations to finish
        // this depends on the labelDimTimeout parameter in MapObject, we add additional 0.1f just in case
        yield return(new WaitForSeconds(mapCity.GetComponent <MapObject>().LabelDimTimeout + 0.1f));

        // Unblock mouse input
        InputBlocker.SetActive(false);
        // map manager change to browse mode back
        // . - this is done by OnDisable() automatically in MapManager
        //MapManager mapManager = transform.parent.GetComponent<MapManager>();
        //mapManager.SetMode(MapManager.Mode.Browse);
        // Deactivate map manager with map
        MapManager.Instance.gameObject.SetActive(false);
        // Deactivate this map menu
        gameObject.SetActive(keepEnabledAfterStart);
        // Note: everything below related to mapManager or mapScreen will not be processed, because map manager is disabled
        // Activate city view = go to city edit mode
        transform.root.GetComponentInChildren <UIManager>().GetComponentInChildren <EditPartyScreen>(true).SetEditPartyScreenActive(mapCity.LCity);
    }
Esempio n. 4
0
    void CreateCityOnMap(City city, CityData cityData)
    {
        // Create new party on map
        MapCity newCityOnMap = Instantiate(cityOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapCity>())).GetComponent <MapCity>();
        // city to original position on map
        //newCityOnMap.GetComponent<RectTransform>().offsetMin = new Vector2(cityData.cityMapPosition.offsetMinX, cityData.cityMapPosition.offsetMinY);
        //newCityOnMap.GetComponent<RectTransform>().offsetMax = new Vector2(cityData.cityMapPosition.offsetMaxX, cityData.cityMapPosition.offsetMaxY);
        // place it to original position on map based on the tile coordinates
        Vector3 cityPositionOffset = new Vector3(8f, 8f, 0);

        newCityOnMap.transform.position = MapManager.Instance.GetWorldPositionByCoordinates(cityData.cityMapCoordinates) - cityPositionOffset;
        // create links between city on map and city
        newCityOnMap.LCity = city;
        city.LMapCity      = newCityOnMap;
        // rename it
        newCityOnMap.gameObject.name = city.CityName;
        // Create city label on map
        MapObjectLabel newCityOnMapLabel = Instantiate(cityOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapObjectLabel>())).GetComponent <MapObjectLabel>();

        // Link city to the lable and label to the city
        newCityOnMap.GetComponent <MapObject>().Label = newCityOnMapLabel;
        newCityOnMapLabel.MapObject = newCityOnMap.GetComponent <MapObject>();
        // activate city label on map
        newCityOnMapLabel.gameObject.SetActive(true);
        // set color according to the player color preference
        newCityOnMap.SetColor(GetPlayerByFaction(city.CityCurrentFaction).PlayerColor);
        // activate city on map
        newCityOnMap.gameObject.SetActive(true);
    }
Esempio n. 5
0
 public List <MapCity> GetNeighboursOf(MapCity city)
 {
     if (neighboursMap.ContainsKey(city))
     {
         return(neighboursMap[city]);
     }
     throw new System.ArgumentException("Requested information on a city that has not been registered.");
 }
Esempio n. 6
0
 void ChangeCityFocus(MapCity nextCity)
 {
     focusedObject = nextCity.gameObject;
     // set name UI
     SetCityNameUI(nextCity);
     // select city on map
     MapManager.Instance.SetSelection(MapManager.Selection.PlayerCity, nextCity);
     // reset cursor to normal, because it is changed by MapManager
     CursorController.Instance.SetNormalCursor();
     // set camera focus on a city
     Camera.main.GetComponent <CameraController>().SetCameraFocus(nextCity);
 }
Esempio n. 7
0
    private List <MapCity> AStar(MapCity start, MapCity goal, HeuristicDelegate heuristic)
    {
        //Should be min-heap or priority queue, will use List for readability
        List <MapCity> openSet = new List <MapCity>()
        {
            start
        };


        Dictionary <MapCity, MapCity> cameFrom = new Dictionary <MapCity, MapCity>();
        Dictionary <MapCity, float>   gScore   = new Dictionary <MapCity, float>();

        gScore[start] = 0;

        Dictionary <MapCity, float> fScore = new Dictionary <MapCity, float>();

        fScore[start] = heuristic(start, goal);


        while (openSet.Count > 0)
        {
            MapCity current = GetLowestFScore(openSet, fScore);

            if (current == goal)
            {
                return(ReconstructPath(cameFrom, current));
            }

            openSet.Remove(current);

            foreach (var neighbour in mapHandler.GetNeighboursOf(current))
            {
                //Here GetDistanceBetween between is used as the actual connection weigth
                float tentativeGScore = gScore[current] + mapHandler.GetDistanceBetween(current, neighbour);

                if (!gScore.ContainsKey(neighbour) || tentativeGScore < gScore[neighbour])
                {
                    cameFrom[neighbour] = current;
                    gScore[neighbour]   = tentativeGScore;
                    fScore[neighbour]   = tentativeGScore + heuristic(neighbour, goal);

                    if (!openSet.Contains(neighbour))
                    {
                        openSet.Add(neighbour);
                    }
                }
            }
        }

        return(null);
    }
Esempio n. 8
0
    public void FocusOnCity()
    {
        // get first city
        MapCity mapCity = GetFirstCityOnMap();

        // verify if mapCity is not null
        if (mapCity != null)
        {
            // activate focus on a map city
            SetActive(mapCity);
            // set camera focus on a city
            Camera.main.GetComponent <CameraController>().SetCameraFocus(mapCity);
        }
    }
Esempio n. 9
0
    private List <MapCity> ReconstructPath(Dictionary <MapCity, MapCity> cameFrom, MapCity current)
    {
        List <MapCity> totalPath = new List <MapCity>()
        {
            current
        };

        while (cameFrom.ContainsKey(current))
        {
            current = cameFrom[current];
            totalPath.Add(current);
        }

        return(totalPath);
    }
Esempio n. 10
0
    void SetAdditionalInfo(MapCity mapCity)
    {
        // initialize additional info string
        string additionalInfo = "";

        // verify cityType
        if (mapCity.LCity.CityType == CityType.Capital)
        {
            additionalInfo = "";
        }
        else
        {
            additionalInfo = mapCity.LCity.CityLevelCurrent + " Level";
        }
        // Set UI text
        focusedObjectInfoText.text = additionalInfo;
    }
Esempio n. 11
0
    void SetCityNameUI(MapCity mapCity)
    {
        // initialize additional info string
        string additionalInfo = "";

        // verify cityType
        if (mapCity.LCity.CityType == CityType.Capital)
        {
            additionalInfo = mapCity.LCity.CityCurrentFaction.ToString() + " Captial";
        }
        else
        {
            additionalInfo = "City";
        }
        // Set UI text
        SetFocusedObjectName(mapCity.LCity.CityName + "\r\n<size=12>" + additionalInfo + "</size>");
    }
Esempio n. 12
0
    public void CaptureAndEnterCity()
    {
        Debug.Log("BattleScreen: EnterCity");
        // remove dead units from city garnizon's heroParty
        enemyPartyPanel.transform.parent.GetComponent <HeroPartyUI>().LHeroParty.RemoveDeadPartyUnits();
        // Change city faction to player's faction
        enemyPartyPanel.GetCity().CityCurrentFaction = playerPartyPanel.GetHeroParty().Faction;
        // Prepare variables to be used later
        MapHero mapHero = playerPartyPanel.GetHeroParty().LMapHero;
        MapCity destinationCityOnMap = enemyPartyPanel.GetCity().LMapCity;

        //MapManager mapManager = GetMapManager();
        // execute default on battle exit function
        DefaultOnBattleExit();
        // Trigger map hero move to and enter city
        MapManager.Instance.MapHeroMoveToAndEnterCity(mapHero, destinationCityOnMap);
    }
Esempio n. 13
0
    private void OnDrawGizmos()
    {
        if (shortestRoute != null)
        {
            Gizmos.color = Color.green;

            for (int i = 0; i < shortestRoute.Count - 1; i++)
            {
                MapCity cityA = shortestRoute[i];
                MapCity cityB = shortestRoute[i + 1];

                if (cityA && cityB)
                {
                    Gizmos.DrawLine(cityA.transform.position, cityB.transform.position);
                }
            }
        }
    }
Esempio n. 14
0
    private void OnDrawGizmos()
    {
        if (!visualize)
        {
            return;
        }

        foreach (var element in neighboursMap)
        {
            MapCity key = element.Key;
            foreach (var neighbour in element.Value)
            {
                float s = 1.3f - GetDistanceBetween(key, neighbour) / maxDistance;
                Gizmos.color = new Color(s, s, s, 1);
                Gizmos.DrawLine(key.transform.position, neighbour.transform.position);
            }
        }
    }
Esempio n. 15
0
 public void SetCameraFocus(MapCity mapCity)
 {
     // Remove previous focus
     ResetFocusedObject();
     // save followed city link
     followedCityOnMap = mapCity;
     // verify if mapCity is not null
     if (mapCity != null)
     {
         Debug.Log("Set camera focus on " + mapCity.LCity.CityName + " city");
         // reset camera is focused flag
         cameraIsFocused = false;
         // set followed object position
         followedObjectTransform = mapCity.transform;
         // start set focus animation
         MapManager.Instance.Queue.Run(WaitUntilCameraIsFocused(minDistanceToTheCity));
     }
 }
Esempio n. 16
0
    // This operation can occur in O(1) time if openSet is a min-heap or a priority queue !!
    // Here: O(n)
    private MapCity GetLowestFScore(List <MapCity> openSet, Dictionary <MapCity, float> fScore)
    {
        float   min     = float.MaxValue;
        MapCity minCity = null;

        foreach (var e in openSet)
        {
            if (fScore.ContainsKey(e))
            {
                float score = fScore[e];
                if (score < min)
                {
                    min     = score;
                    minCity = e;
                }
            }
        }
        return(minCity);
    }
Esempio n. 17
0
    public void SetActive(MapCity mapCity)
    {
        // first do cleanup in case if previously were selected other object
        if (focusedObject != null)
        {
            ReleaseFocus();
        }
        // Get active player
        GamePlayer activePlayer = TurnsManager.Instance.GetActivePlayer();

        // Set focused object
        Debug.Log("Update map focus panel with " + mapCity.name);
        focusedObject = mapCity.gameObject;
        // save currently focused object id to game player it will be needed for game load and turns switch
        activePlayer.FocusedObjectID = focusedObject.gameObject.GetInstanceID();
        // transform.root.Find("Managers").GetComponent<TurnsManager>().GetActivePlayer().FocusedObjectID = focusedObject.gameObject.GetInstanceID();
        // Set city name
        SetCityNameUI(mapCity);
        // Set additional info
        SetAdditionalInfo(mapCity);
        // Set list of map cities
        mapCitiesList = new List <MapCity>();
        // Loop through all map cities
        foreach (MapCity mCity in MapManager.Instance.GetComponentsInChildren <MapCity>())
        {
            // verify if faction is the same
            if (mapCity.LCity.CityCurrentFaction == mCity.LCity.CityCurrentFaction)
            {
                mapCitiesList.Add(mCity);
            }
        }
        // verify if there is more than 1 city of the same faction
        if (mapCitiesList.Count > 1)
        {
            // activate next and previous controls
            previousButton.SetInteractable(true);
            nextButton.SetInteractable(true);
        }
        // Activate enter city control
        transform.Find("FocusedObjectControl/EnterCity").gameObject.SetActive(true);
    }
Esempio n. 18
0
    //This is not performant at all! It is done in this way soly to allow editing everything in the editor
    private void Update()
    {
        MapCity[] cities = FindObjectsOfType <MapCity>();

        for (int a = 0; a < cities.Length; a++)
        {
            MapCity        cityA      = cities[a];
            List <MapCity> neighbours = new List <MapCity>();

            for (int b = 0; b < cities.Length; b++)
            {
                MapCity cityB = cities[b];
                float   dist  = GetDistanceBetween(cityA, cityB);
                if (dist < maxDistance)
                {
                    neighbours.Add(cityB);
                }
            }
            neighboursMap[cityA] = neighbours;
        }
    }
Esempio n. 19
0
    public void EnterBattle(MapHero playerOnMap, MapCity enemyCityOnMap)
    {
        // gen enemy party, which can fight
        HeroParty enemyHeroParty = GetPartyInCityWhichCanFight(enemyCityOnMap);

        // verify if there are units in party protecting this city, which can fight
        // it is possible that city is not protected
        if (enemyHeroParty != null)
        {
            // city is protected
            // get hero's parties
            HeroParty playerHeroParty = playerOnMap.LHeroParty;
            // proceed with preparations for the battle
            EnterBattleCommon(playerHeroParty, enemyHeroParty);
        }
        else
        {
            // city is not protected
            // no need to battle
            // move to and enter city
            CaptureAndEnterCity();
        }
    }
Esempio n. 20
0
    HeroParty GetPartyInCityWhichCanFight(MapCity enemyCityOnMap)
    {
        // Firt verify if city is protected by Hero's party
        // Player cannot attack city untill there a party protecting it
        HeroParty enemyHeroParty = enemyCityOnMap.LCity.GetHeroPartyByMode(PartyMode.Party);

        if (enemyHeroParty)
        {
            // enemy hero is protecting city
            // battle place is on a city gates
            // verify if there are units which can fight, because it is possible that player left only dead units in party
            if (enemyHeroParty.HasUnitsWhichCanFight())
            {
                return(enemyHeroParty);
            }
            else
            {
                Debug.LogWarning("Party was found, but there is no unit which can fight. Checking city Garnizon.");
            }
        }
        // if we are here, then there is no enemy hero protecting city
        // get garnizon party
        // there should be garnizon in every city
        enemyHeroParty = enemyCityOnMap.LCity.GetHeroPartyByMode(PartyMode.Garnizon);
        // verify if there are units in party protecting this city, which can fight
        // it is possible that city is not protected, because all units are dead
        if (enemyHeroParty.HasUnitsWhichCanFight())
        {
            return(enemyHeroParty);
        }
        else
        {
            Debug.LogWarning("There is no unit in city Garnizon which can fight");
        }
        // if no party can fight, then return null
        return(null);
    }
Esempio n. 21
0
 public void ShowNext()
 {
     // verify focused object type
     if (focusedObject.GetComponent <MapHero>())
     {
         Debug.Log("Show next hero");
         // get next hero from the list
         MapHero nextHero = mapHeroesList[GetNextIndex(GetSelectedHeroIndex(), mapHeroesList.Count)];
         // set focused object to new hero
         ChangeHeroFocus(nextHero);
     }
     else if (focusedObject.GetComponent <MapCity>())
     {
         Debug.Log("Show next city");
         // get next city from the list
         MapCity nextCity = mapCitiesList[GetNextIndex(GetSelectedCityIndex(), mapCitiesList.Count)];
         // set focused object to new city
         ChangeCityFocus(nextCity);
     }
     else
     {
         Debug.LogError("Unknwon focused object type");
     }
 }
Esempio n. 22
0
 public void ShowPrevious()
 {
     // verify focused object type
     if (focusedObject.GetComponent <MapHero>())
     {
         Debug.Log("Show previous hero");
         // get previous hero from the list
         MapHero previousHero = mapHeroesList[GetPreviousIndex(GetSelectedHeroIndex(), GetSelectedHeroIndex())];
         // set focused object to new hero
         ChangeHeroFocus(previousHero);
     }
     else if (focusedObject.GetComponent <MapCity>())
     {
         Debug.Log("Show previous city");
         // get previous city from the list
         MapCity previousCity = mapCitiesList[GetPreviousIndex(GetSelectedCityIndex(), mapCitiesList.Count)];
         // set focused object to new city
         ChangeCityFocus(previousCity);
     }
     else
     {
         Debug.LogError("Unknwon focused object type");
     }
 }
Esempio n. 23
0
 void LateUpdate()
 {
     // verify if there is a hero which camera needs to follow
     if (followedHeroOnMap != null)
     {
         // Get destination position based on the map borders
         // Avoid that camera goes over top or bottom border
         // Get heroPosition
         Vector3 followedHeroPosition = followedHeroOnMap.transform.position;
         // Get camera position
         Vector3 point         = Camera.main.WorldToViewportPoint(followedHeroPosition);
         Vector3 cameraPostion = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z));
         // Debug.LogWarning("Hero:Camera y " + (int)followedHeroPosition.y + ":"  + (int)Camera.main.transform.position.y);
         // Get destination
         Vector3 delta       = followedHeroPosition - cameraPostion;
         Vector3 destination = transform.position + delta;
         Vector3 destinationBorderAligned = GetPositionWithScreenBordersLimits(destination);
         Vector3 destinationOYO           = new Vector3(transform.position.x, destinationBorderAligned.y, transform.position.z);
         // verify if we need to rotate
         float tileSize = 16f;
         float mapWidth = 960f;
         if (doShifMapTiles)
         {
             // get xDistance
             float xDistance = destination.x - transform.position.x;
             // get number of rotaitons required based on the distance and tile size
             int numberOfRotationsRequired = 1 + Math.Abs(Mathf.RoundToInt(xDistance / tileSize));
             // get number of rotations, which will cover whole map
             int loopRotations = Mathf.RoundToInt(mapWidth / tileSize);
             // Debug.Log("rotations reset to max when between: " + maxRotations + "-" + loopRotations);
             // make sure that number of rotaions are not higher than the number or map slices
             while (numberOfRotationsRequired >= loopRotations)
             {
                 numberOfRotationsRequired -= loopRotations;
                 // calculate them in a distance
                 rotationsCounter += loopRotations;
             }
             rotationsCounter += numberOfRotationsRequired * rotationDirection;
             // Debug.Log("Do " + numberOfRotationsRequired + " rotations, total rotaitons: " + rotationsCounter);
             if (numberOfRotationsRequired != 0)
             {
                 if (rotationDirection > 0)
                 {
                     // Rotate map
                     MapManager.Instance.RotateRight(numberOfRotationsRequired);
                 }
                 else
                 {
                     // Rotate map
                     MapManager.Instance.RotateLeft(numberOfRotationsRequired);
                 }
             }
             // reset flag
             // Debug.Log("Block rotations");
             doShifMapTiles = false;
         }
         // verify that camera has not already focused on a hero
         if (!cameraIsFocused)
         {
             // move camera to the hero
             transform.position = Vector3.SmoothDamp(transform.position, destinationOYO, ref velocity, dampTime, focusMoveSpeed);
         }
         else
         {
             // make camera follow hero on Map
             transform.position = Vector3.SmoothDamp(transform.position, destinationOYO, ref velocity, dampTime);
         }
     }
     else if (followedCityOnMap != null)
     {
         // Get destination position based on the map borders
         // Avoid that camera goes over top or bottom border
         // Get heroPosition
         Vector3 followedCityPosition = followedCityOnMap.transform.position;
         // Get camera position
         Vector3 point         = Camera.main.WorldToViewportPoint(followedCityPosition);
         Vector3 cameraPostion = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z));
         // Debug.LogWarning("Hero:Camera y " + (int)followedCityPosition.y + ":"  + (int)Camera.main.transform.position.y);
         // Get destination
         Vector3 delta       = followedCityPosition - cameraPostion;
         Vector3 destination = transform.position + delta;
         Vector3 destinationBorderAligned = GetPositionWithScreenBordersLimits(destination);
         Vector3 destinationOYO           = new Vector3(transform.position.x, destinationBorderAligned.y, transform.position.z);
         // verify if we need to rotate
         float tileSize = 16f;
         float mapWidth = 960f;
         if (doShifMapTiles)
         {
             // get xDistance
             float xDistance = destination.x - transform.position.x;
             // get number of rotaitons required based on the distance and tile size
             int numberOfRotationsRequired = 1 + Math.Abs(Mathf.RoundToInt(xDistance / tileSize));
             // get number of rotations, which will cover whole map
             int loopRotations = Mathf.RoundToInt(mapWidth / tileSize);
             // Debug.Log("rotations reset to max when between: " + maxRotations + "-" + loopRotations);
             // make sure that number of rotaions are not higher than the number or map slices
             while (numberOfRotationsRequired >= loopRotations)
             {
                 numberOfRotationsRequired -= loopRotations;
                 // calculate them in a distance
                 rotationsCounter += loopRotations;
             }
             rotationsCounter += numberOfRotationsRequired * rotationDirection;
             // Debug.Log("Do " + numberOfRotationsRequired + " rotations, total rotaitons: " + rotationsCounter);
             if (numberOfRotationsRequired != 0)
             {
                 if (rotationDirection > 0)
                 {
                     // Rotate map
                     MapManager.Instance.RotateRight(numberOfRotationsRequired);
                 }
                 else
                 {
                     // Rotate map
                     MapManager.Instance.RotateLeft(numberOfRotationsRequired);
                 }
             }
             // reset flag
             // Debug.Log("Block rotations");
             doShifMapTiles = false;
         }
         // verify that camera has not already focused on a hero
         if (!cameraIsFocused)
         {
             // move camera to the city
             transform.position = Vector3.SmoothDamp(transform.position, destinationOYO, ref velocity, dampTime, focusMoveSpeed);
         }
         else
         {
             // stop following
             followedCityOnMap = null;
         }
     }
     else if (doFollowMapDrag)
     {
         // Debug.Log("Camera before x:y " + (int)Camera.main.transform.position.x + ":" + (int)Camera.main.transform.position.y);
         float   tileSize = 16f;
         float   mapWidth = 960f;
         Vector3 newPos   = dragOrigin - Input.mousePosition;
         Vector3 delta    = newPos - Camera.main.transform.position - new Vector3(tileSize * rotationsCounter, 0, 0);
         // Debug.Log("delta x:y " + (int)delta.x + ":" + (int)delta.y);
         Vector3 destination = transform.position + delta;
         Vector3 destinationBorderAligned = GetPositionWithScreenBordersLimits(destination);
         // verify if we need to rotate (shift map slides)
         if (doShifMapTiles)
         {
             // get xDistance
             float xDistance = destination.x - transform.position.x;
             // get number of rotaitons required based on the distance and tile size
             int numberOfRotationsRequired = 1 + Math.Abs(Mathf.RoundToInt(xDistance / tileSize));
             // set max number of rotations
             // int maxRotations = (int)Mathf.Floor((mapWidth - (float)Screen.width) / tileSize) - 1;
             if (maxRotations <= 0)
             {
                 maxRotations = 1;
             }
             // get number of rotations, which will cover whole map
             int loopRotations = Mathf.RoundToInt(mapWidth / tileSize);
             // verify if number of rotations is more than max and less than loop
             //if (numberOfRotationsRequired > maxRotations && numberOfRotationsRequired < loopRotations)
             //    numberOfRotationsRequired = maxRotations;
             // Debug.Log("rotations reset to max when between: " + maxRotations + "-" + loopRotations);
             // make sure that number of rotaions are not higher than the number or map slices
             while (numberOfRotationsRequired >= loopRotations)
             {
                 numberOfRotationsRequired -= loopRotations;
                 // calculate them in a distance
                 rotationsCounter += loopRotations;
             }
             rotationsCounter += numberOfRotationsRequired * rotationDirection;
             // Debug.Log("Do " + numberOfRotationsRequired + " rotations, total rotaitons: " + rotationsCounter);
             if (numberOfRotationsRequired != 0)
             {
                 if (rotationDirection > 0)
                 {
                     // Rotate map
                     MapManager.Instance.RotateRight(numberOfRotationsRequired);
                 }
                 else
                 {
                     // Rotate map
                     MapManager.Instance.RotateLeft(numberOfRotationsRequired);
                 }
                 // shift camera to hide rotation
                 // Debug.Log("Shift camera");
                 // transform.position -= new Vector3(tileSize * rotationDirection * numberOfRotationsRequired, 0, 0);
             }
             // reset flag
             // Debug.Log("Block rotations");
             doShifMapTiles = false;
             // Debug.Break();
             // do not move camera anymore during this frame
             // activate rotation lock, until camera has reached previous rotation target
             // rotationLock = true;
             // Debug.Log("Activate rotation lock");
         }
         // move camera to simulate drag
         Vector3 destinationOYO = new Vector3(transform.position.x, destinationBorderAligned.y, transform.position.z);
         // Vector3 destinationXYO = new Vector3(destinationBorderAligned.x, destinationBorderAligned.y, transform.position.z);
         // transform.position = Vector3.SmoothDamp(transform.position, destinationXYO, ref velocity, dampTime, mapRotationSpeed);
         // do not move camera
         transform.position = Vector3.SmoothDamp(transform.position, destinationOYO, ref velocity, dampTime);
         // get distance
         float remainingDistanceX = Mathf.Abs(transform.position.x - destinationBorderAligned.x);
         // set min distance
         float minDistance = 0.5f;
         // verify if rotation lock can be unlocked
         if (remainingDistanceX <= minDistance && rotationLock == true)
         {
             // release rotation lock;
             rotationLock = false;
             // Debug.Log("Release rotation lock, remaining distance: " + (int)remainingDistanceX);
         }
         // Debug.Log("Camera after  x:y " + (int)Camera.main.transform.position.x + ":" + (int)Camera.main.transform.position.y);
         // Debug.Log("Rotations: " + rotationsCounter);
     }
 }
Esempio n. 24
0
 public float GetDistanceBetween(MapCity a, MapCity b)
 {
     return((b.transform.position - a.transform.position).magnitude);
 }
Esempio n. 25
0
        public void CreateWorld_2()
        {
            //The World
            MapWorld world = new MapWorld();
            Dictionary <string, MapIsland> Islands = new Dictionary <string, MapIsland>();

            //island 1 ------------------------------------------------------------
            MapIsland island = new MapIsland(world, "island1");

            island.PointX = 118;
            island.PointY = 31;

            //Instance for the Island
            MapInstance instance1 = new MapInstance(island, "island1_instance_1");

            instance1.PointX = 130;
            instance1.PointY = 50;

            //list zone for instance on the island
            List <MapZone> listZone_instance1 = new List <MapZone>();
            MapZone        zone1 = new MapZone(instance1, true, 1);

            zone1.PointX = 50;
            zone1.PointY = 50;

            MapZone zone2 = new MapZone(instance1, true, 2);

            zone2.PointX = 150;
            zone2.PointY = 150;

            MapZone zone3 = new MapZone(instance1, true, 3);

            zone3.PointX = 250;
            zone3.PointY = 250;

            List <MapZone> listlink = new List <MapZone>();

            listlink.Add(zone2);
            zone1.ListLink = listlink;

            listlink = new List <MapZone>();
            listlink.Add(zone1);
            listlink.Add(zone3);
            zone2.ListLink = listlink;

            listlink = new List <MapZone>();
            listlink.Add(zone2);
            zone3.ListLink = listlink;

            //Zone must be add like : first is the entry and last the exit
            listZone_instance1.Add(zone1);
            listZone_instance1.Add(zone2);
            listZone_instance1.Add(zone3);

            instance1.listZones = listZone_instance1;

            List <MapInstance> listinstances = new List <MapInstance>();

            listinstances.Add(instance1);
            island.IslandInstances = listinstances;

            //city for the island
            MapCity city = new MapCity(island, "City1");

            city.PointX = 100;
            city.PointY = 200;
            island.AddCity(city);

            //list sellable items for merchant and merch
            ListItems   listI     = new ListItems();
            List <Item> itemsSell = new List <Item>();

            itemsSell.Add(listI.Items[0]);

            Merchant merch1 = new Merchant("Vendeur général", itemsSell);

            merch1.PointX = 50;
            merch1.PointY = 325;
            merch1.Invent = world.Team.Invent;

            itemsSell.Add(listI.Items[1]);
            Merchant merch2 = new Merchant("herboriste", itemsSell);

            merch2.PointX = 250;
            merch2.PointY = 325;
            merch2.Invent = world.Team.Invent;

            //Add services
            Mortuary s1 = new Mortuary(city);

            s1.PointX = 300;
            s1.PointY = 110;

            Taverne s2 = new Taverne();

            s2.PointX = 190;
            s2.PointY = 100;

            //list merchant for city
            List <object> listservices = new List <object>();

            listservices.Add(merch1);
            listservices.Add(merch2);
            listservices.Add(s1);
            listservices.Add(s2);
            city.Services = listservices;

            //add island to world
            Islands.Add("island1", island);

            //island 2 ------------------------------------------------------------
            island        = new MapIsland(world, "island2");
            island.PointX = 118;
            island.PointY = 231;

            //Instance for the Island
            instance1        = new MapInstance(island, "island2_instance_1");
            instance1.PointX = 130;
            instance1.PointY = 250;

            //list zone for instance on the island
            listZone_instance1 = new List <MapZone>();
            zone1        = new MapZone(instance1, true, 1);
            zone1.PointX = 50;
            zone1.PointY = 50;

            zone2        = new MapZone(instance1, true, 2);
            zone2.PointX = 150;
            zone2.PointY = 150;

            zone3        = new MapZone(instance1, true, 3);
            zone3.PointX = 250;
            zone3.PointY = 250;

            listlink = new List <MapZone>();
            listlink.Add(zone2);
            zone1.ListLink = listlink;

            listlink = new List <MapZone>();
            listlink.Add(zone1);
            listlink.Add(zone3);
            zone2.ListLink = listlink;

            listlink = new List <MapZone>();
            listlink.Add(zone2);
            zone3.ListLink = listlink;

            listZone_instance1.Add(zone1);
            listZone_instance1.Add(zone2);
            listZone_instance1.Add(zone3);

            instance1.listZones = listZone_instance1;

            listinstances = new List <MapInstance>();
            listinstances.Add(instance1);
            island.IslandInstances = listinstances;

            //city for the island
            city        = new MapCity(island, "City2");
            city.PointX = 200;
            city.PointY = 200;
            island.AddCity(city);

            //list sellable items for merchant and merch
            listI     = new ListItems();
            itemsSell = new List <Item>();
            itemsSell.Add(listI.Items[1]);

            merch1        = new Merchant("Vendeur général", itemsSell);
            merch1.PointX = 50;
            merch1.PointY = 325;
            merch1.Invent = world.Team.Invent;

            //Add services
            s1        = new Mortuary(city);
            s1.PointX = 300;
            s1.PointY = 110;

            s2        = new Taverne();
            s2.PointX = 190;
            s2.PointY = 100;

            //list merchant for city
            listservices = new List <object>();
            listservices.Add(merch1);
            listservices.Add(s1);
            listservices.Add(s2);
            city.Services = listservices;

            //add island to world
            Islands.Add("island2", island);

            //End-----------------------------------------------

            //list link between island
            List <MapIsland> listlinkis = new List <MapIsland>();

            listlinkis.Add(Islands["island2"]);
            Islands["island1"].ListLink = listlinkis;

            listlinkis = new List <MapIsland>();
            listlinkis.Add(Islands["island1"]);
            Islands["island2"].ListLink = listlinkis;

            //add island to world
            world.Islands        = Islands;
            world.ActualPosition = world.Islands["island1"];

            //Serialize
            IFormatter formatter = new BinaryFormatter();

            using (Stream stream = new FileStream("../../../Ressources/NewWorld.bin", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                formatter.Serialize(stream, world);
            }
        }
Esempio n. 26
0
    public void CreateHeroParty(PartyData partyData)
    {
        // verify if there are units in party
        if (partyData.partyUnitsData.Length >= 1)
        {
            Debug.Log("Creating " + partyData.partyUnitsData[0].unitType + " party");
        }
        else
        {
            // empty can be only garnizon in non-capital city
            Debug.Log("Creating garnizon");
        }
        // define new hero party variable
        HeroParty newHeroParty;
        // define new hero party parent transform variable
        Transform newHeroPartyParentTransform;

        // create hero party from tempalte in required location: City or UI address
        // verify if party was in city
        if (partyData.linkedCityID != CityID.None)
        {
            // get parent transform by city ID
            newHeroPartyParentTransform = GetCityByID(partyData.linkedCityID).transform;
        }
        else if (partyData.partyUIAddress != null)
        {
            Debug.Log("Creating party at " + partyData.partyUIAddress);
            // get parent transform by UI address
            newHeroPartyParentTransform = transform.Find(partyData.partyUIAddress);
        }
        else
        {
            Debug.LogError("Unknown condition. Cannot find hero party parent transform");
            newHeroPartyParentTransform = transform;
        }
        newHeroParty = Instantiate(heroPartyTemplate, newHeroPartyParentTransform).GetComponent <HeroParty>();
        // set hero party data
        newHeroParty.PartyData = partyData;
        // create units
        // Note: Party leader should be created before party representation on the map is set
        foreach (PartyUnitData partyUnitData in partyData.partyUnitsData)
        {
            CreatePartyUnit(partyUnitData, newHeroParty);
        }
        // verify if party is in garnizon mode
        if (partyData.partyMode == PartyMode.Garnizon)
        {
            // skip creating party on map represetnation
            // City garnizon does not have representation on map
        }
        else
        {
            // create party on map
            MapHero newMapHero = CreatePartyOnMap(newHeroParty, partyData);
            // verify if party has linked city
            if (partyData.linkedCityID != CityID.None)
            {
                // get city by city ID
                MapCity mapCity = GetCityByID(partyData.linkedCityID).LMapCity;
                // create links between city on map and hero on map if needed (if they are on the same tile or if hero party is in city)
                mapCity.LMapHero    = newMapHero;
                newMapHero.lMapCity = mapCity;
            }
        }
        // create items for party
        foreach (InventoryItemData inventoryItemData in newHeroParty.PartyData.partyInventory)
        {
            CreateInventoryItem(inventoryItemData, newHeroParty.transform);
        }
        // rename hero party
        if (partyData.partyUnitsData.Length >= 1 && newHeroParty.PartyMode != PartyMode.Garnizon)
        {
            // Name party by the leader name
            newHeroParty.gameObject.name = newHeroParty.GetPartyLeader().GivenName + " " + newHeroParty.GetPartyLeader().UnitName + " Party";
        }
        else
        {
            // Name party "Garnizon"
            newHeroParty.gameObject.name = "Garnizon";
        }
        // activate hero party
        newHeroParty.gameObject.SetActive(true);
    }
Esempio n. 27
0
 public Militia(MapCity context)
 {
     _context = context;
 }
Esempio n. 28
0
 void ResetFocusedObject()
 {
     followedHeroOnMap = null;
     followedCityOnMap = null;
     doFollowMapDrag   = false;
 }