Esempio n. 1
0
    public void CheckForClients(GridTile_Planet planet)
    {
        List <Client> clientsList = new List <Client>();

        // Check for clients on contracts that can be picked up, if planet is right
        foreach (var contract in _assignedContracts)
        {
            foreach (var client in contract.AllClients)
            {
                if (client.currentState == ClientState.Waiting && client.startPlanet == planet)
                {
                    clientsList.Add(client);
                }
            }
        }
        foreach (var client in clientsList)
        {
            EmbarkClient(client, planet);
        }
        clientsList.Clear();

        // Check for onboard clients that can debark
        foreach (var client in _clientsOnBoard)
        {
            if (client.CheckSuccessCondition(planet))
            {
                clientsList.Add(client);
            }
        }

        foreach (var client in clientsList)
        {
            DebarkClient(client, planet);
        }
    }
Esempio n. 2
0
    private GridTile_Planet GetClosestEndPlanet(List <GridTile_Planet> completeList, GridTile_Planet startPlanet)
    {
        int count       = completeList.Count;
        int targetIndex = int.MaxValue;
        int minRating   = int.MaxValue;

        TileCoordinates startPos = startPlanet.TileCoordinates;

        for (int i = 0; i < count; i++)
        {
            if (completeList[i] != startPlanet)
            {
                TileCoordinates planetPos      = completeList[i].TileCoordinates;
                int             distanceRating = PathFinder.instance.GetDistanceRating(startPos.tileX, startPos.tileY, planetPos.tileX, planetPos.tileY, true);
                if (distanceRating < minRating)
                {
                    minRating   = distanceRating;
                    targetIndex = i;
                }
            }
        }

        if (targetIndex < count)
        {
            //Debug.Log("CLOSEST PLANET : " + completeList[targetIndex].PlanetName);
            return(completeList[targetIndex]);
        }

        return(null);
    }
Esempio n. 3
0
    private void OnTriggerEnter2D(Collider2D col)
    {
        //When inside anomaly affected sector
        if (col.GetComponent <GridTile_Anomaly>() != null)
        {
            GridTile_Anomaly anomaly = col.GetComponent <GridTile_Anomaly>();
            ship.anomalyTile = anomaly;
            mM.ContactWithAnomalyNotif(ship, anomaly);
        }

        if (col.GetComponent <Planet_InteractionZone>() != null)
        {
            ship.planetInOrbit   = col.GetComponent <Planet_InteractionZone>().ParentPlanet;
            ship.isInPlanetOrbit = true;
        }

        if (col.GetComponent <DeployPoint>() != null)
        {
            ship.deployP         = col.GetComponent <DeployPoint>();
            ship.isInDeployPoint = true;
        }

        if (col.GetComponent <Cloud>() != null)
        {
            ship.isMoving  = false;
            ship.isInCloud = true;
            mM.ContactWithCloudNotif(ship);
        }

        GridTile_Planet planet = col.GetComponent <GridTile_Planet>();

        if (planet != null)
        {
            planet.RevealPlanet(false);
            ship.CheckForClients(planet);
        }

        GridTile_StaticAnomaly staticAnomaly = col.GetComponent <GridTile_StaticAnomaly>();

        if (staticAnomaly != null)
        {
            ship.DisableShip();
        }

        // Wormhole
        WormHole candidateWormhole = col.GetComponent <WormHole>();

        if (candidateWormhole != null)
        {
            // If collision with wormhole is NOT collision with the current RECEIVING wormhole
            if (candidateWormhole != ship.receiverWormhole)
            {
                // Assign references and call the ship function
                ship.senderWormhole   = col.GetComponent <WormHole>();
                ship.receiverWormhole = ship.senderWormhole.SisterWormHole;
                ship.EnterWormHole(ship.receiverWormhole);
                mM.ContactWithWormholeNotif(ship);
            }
        }
    }
Esempio n. 4
0
    private GridTile_Planet GetRandomPlanet(List <GridTile_Planet> targetList)
    {
        int             randomIndex = UnityEngine.Random.Range(0, targetList.Count);
        GridTile_Planet target      = targetList[randomIndex];

        return(target);
    }
Esempio n. 5
0
 public override bool CheckSuccessCondition(GridTile_Planet currentPlanet)
 {
     if (currentPlanet == endPlanet)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 6
0
    private GridTile_Planet GetRandomEndPlanet(List <GridTile_Planet> completeList, GridTile_Planet startPlanet)
    {
        List <GridTile_Planet> candidates = new List <GridTile_Planet>(completeList);

        candidates.Remove(startPlanet);

        return(candidates[UnityEngine.Random.Range(0, candidates.Count)]);
    }
Esempio n. 7
0
    private void DebarkClient(Client client, GridTile_Planet planet)
    {
        if (_clientsOnBoard.Remove(client))
        {
            client.ChangeState(ClientState.Debarked);
            currentCargo--;

            mM.ClientDebarkedNotif(this, client, planet);
        }
        linkedMarker.UpdateLights(currentCargo);
    }
Esempio n. 8
0
    private void CheckForClients()
    {
        TileCoordinates currentTile = GridCoords.FromWorldToTilePosition(transform.position);
        GridTile        tile        = GridCoords.CurrentGridInfo.gameGridTiles[currentTile.tileX, currentTile.tileY];
        GridTile_Planet planet      = tile.GetComponent <GridTile_Planet>();

        if (planet != null)
        {
            CheckForClients(planet);
        }
    }
Esempio n. 9
0
    public override bool CheckStartPlanet(GridTile_Planet currentPlanet)
    {
        if (currentState != ClientState.Waiting)
        {
            return(false);
        }

        if (currentPlanet == startPlanet)
        {
            return(true);
        }

        return(false);
    }
Esempio n. 10
0
    // Fonction appelée lorsqu'un planète spawn, qui sert à garder à jour la liste de planètes
    private void OnNewPlanetTileSpawned(GridTile_Planet planetTile)
    {
        if (_planetTemplateDB == null)
        {
            _planetTemplateDB = FindObjectOfType <PlanetTemplateDB>();
        }

        _allPlanetTiles.Add(planetTile);

        if (_planetTemplateDB != null)
        {
            PlanetInfo newInfo = new PlanetInfo(_planetTemplateDB.GetRandomPlanetName(), _planetTemplateDB.GetRandomPlanetSpriteMatch());
            planetTile.AssignPlanetInfo(newInfo);
        }
    }
Esempio n. 11
0
    private void EmbarkClient(Client client, GridTile_Planet planet)
    {
        if (!_clientsOnBoard.Contains(client))
        {
            if (currentCargo < cargoCapacity)
            {
                _clientsOnBoard.Add(client);
                client.ChangeState(ClientState.Embarked);
                currentCargo++;

                mM.ClientEmbarkedNotif(this, client, planet);
            }
        }
        linkedMarker.UpdateLights(currentCargo);
    }
Esempio n. 12
0
 private GridTile_Planet GetEndPlanet(List <GridTile_Planet> completeList, GridTile_Planet startPlanet, int travelDistanceRating)
 {
     if (_clientRules[_currentRuleIndex].specialEndCondition == SpecialConditions.ClosestPlanet)
     {
         return(GetClosestEndPlanet(completeList, startPlanet));
     }
     //else if (travelDistanceRating == 0)
     //{
     //    return GetRandomEndPlanet(completeList, startPlanet);
     //}
     else
     {
         List <GridTile_Planet> candidates = GetEndPlanetsByDistance(completeList, startPlanet, travelDistanceRating);
         return(GetRandomPlanet(candidates));
     }
 }
Esempio n. 13
0
    //private List<GridTile_Planet> GetPlanetsByDistance(List<GridTile_Planet> completeList, List<GridTile_Planet> listToModify, GridTile_Planet startPlanet)
    //{
    //    int targetDistanceRating = _clientRules[_currentRuleIndex].distanceRating;

    //    List<GridTile_Planet> shortDistancePlanets = new List<GridTile_Planet>();
    //    List<GridTile_Planet> mediumDistancePlanets = new List<GridTile_Planet>();
    //    List<GridTile_Planet> longDistancePlanets = new List<GridTile_Planet>();
    //    List<GridTile_Planet> candidates = new List<GridTile_Planet>();
    //    int shortCount = 0;
    //    int mediumCount = 0;
    //    int longCount = 0;

    //    List<int> distances = new List<int>();
    //    int count = 0;
    //    foreach (var planet in completeList)
    //    {
    //        distances.Add(planet.DistanceRating);
    //        count++;
    //    }
    //    distances.Sort();

    //    for (int i = 0; i < count; i++)
    //    {
    //        Debug.Log(distances[i]);
    //    }

    //    int third = distances[(count / 3) - 1];
    //    int twoThirds = distances[(count / 3 * 2) - 1];

    //    foreach (var planet in listToModify)
    //    {
    //        if (planet.DistanceRating <= third)
    //        {
    //            Debug.Log("SHORT DIST PLANET : " + planet.PlanetName);
    //            shortDistancePlanets.Add(planet);
    //            shortCount++;
    //        }
    //        else if (planet.DistanceRating > twoThirds)
    //        {
    //            longDistancePlanets.Add(planet);
    //            longCount++;
    //        }
    //        else
    //        {
    //            mediumDistancePlanets.Add(planet);
    //            mediumCount++;
    //        }
    //    }

    //    if (targetDistanceRating == 1)
    //    {
    //        if (shortCount > 0)
    //            candidates = shortDistancePlanets;

    //        else if (mediumCount > 0)
    //            candidates = mediumDistancePlanets;

    //        else if (longCount > 0)
    //            candidates = longDistancePlanets;

    //        else
    //        {
    //            candidates = new List<GridTile_Planet>(completeList);
    //            candidates.Remove(startPlanet);
    //        }
    //    }

    //    else if (targetDistanceRating == 2)
    //    {
    //        if (mediumCount > 0)
    //            candidates = mediumDistancePlanets;
    //        else
    //        {
    //            List<GridTile_Planet> shortLong = new List<GridTile_Planet>();
    //            int shortLongCount = 0;
    //            foreach (var planet in shortDistancePlanets)
    //            {
    //                shortLong.Add(planet);
    //                shortLongCount++;
    //            }
    //            foreach (var planet in longDistancePlanets)
    //            {
    //                shortLong.Add(planet);
    //                shortLongCount++;
    //            }

    //            if (shortLongCount > 0)
    //            {
    //                candidates = shortLong;
    //            }
    //            else
    //            {
    //                candidates = new List<GridTile_Planet>(completeList);
    //                candidates.Remove(startPlanet);
    //            }
    //        }

    //    }
    //    else if (targetDistanceRating == 3)
    //    {
    //        if (longCount > 0)
    //            candidates = longDistancePlanets;

    //        else if (mediumCount > 0)
    //            candidates = mediumDistancePlanets;

    //        else if (shortCount > 0)
    //            candidates = shortDistancePlanets;

    //        else
    //        {
    //            candidates = new List<GridTile_Planet>(completeList);
    //            candidates.Remove(startPlanet);
    //        }
    //    }
    //    return candidates;
    //}

    private Client CreateClient(GridTile_Planet startPlanet, GridTile_Planet endPlanet, int travelDistanceRating)
    {
        ChallengeType challengeType = ChallengeType.PlanetName;

        if (challengeType == ChallengeType.Random)
        {
            int randomRoll = UnityEngine.Random.Range(0, 10);
            if (randomRoll < 5)
            {
                challengeType = ChallengeType.Coords;
            }
            else
            {
                challengeType = ChallengeType.PlanetName;
            }
        }

        if (challengeType == ChallengeType.Coords)
        {
            Client_Coords client = new Client_Coords();
            client.clientFirstName      = _contractsDB.GetRandomClientFirstName();
            client.clientLastName       = _contractsDB.GetRandomClientLastName();
            client.clientSprite         = _contractsDB.GetRandomFaceSprite();
            client.startPlanet          = startPlanet;
            client.endPlanet            = endPlanet;
            client.travelDistanceRating = travelDistanceRating;
            client.challengeType        = challengeType;
            return(client);
        }
        else
        {
            Client_PlanetName client = new Client_PlanetName();
            client.clientFirstName      = _contractsDB.GetRandomClientFirstName();
            client.clientLastName       = _contractsDB.GetRandomClientLastName();
            client.clientSprite         = _contractsDB.GetRandomFaceSprite();
            client.startPlanet          = startPlanet;
            client.endPlanet            = endPlanet;
            client.travelDistanceRating = travelDistanceRating;
            client.challengeType        = challengeType;
            return(client);
        }
    }
Esempio n. 14
0
    public void AssignClients(List <Client> clients, int completionTime, bool timedContract)
    {
        if (clients[0].startPlanet != null)
        {
            startPlanetSpriteRenderer.sprite = clients[0].startPlanet.SpriteMatch.contractSprite;
            startPlanetText.text             = clients[0].startPlanet.PlanetName;
            _startPlanet = clients[0].startPlanet;
        }
        else
        {
            startPlanetText.text = "Some planet";
        }

        int candidateDistance = 0;

        for (int i = 0; i < clients.Count; i++)
        {
            if (i >= targetClientCount)
            {
                break;
            }

            if (clients[i].travelDistanceRating > candidateDistance)
            {
                candidateDistance = clients[i].travelDistanceRating;
            }

            AddClient(clients[i], i);
        }

        _travelDistanceRating = candidateDistance;
        this._timedContract   = timedContract;
        this._completionTime  = completionTime + (_travelDistanceRating * 60);
        _currentTime          = 0;

        timeSlider.color   = chillColor;
        timeSlider.enabled = _timedContract;
    }
Esempio n. 15
0
 public abstract bool CheckSuccessCondition(GridTile_Planet currentPlanet);
Esempio n. 16
0
    // TODO : Wrapper ça dans container de contrat de grosseur différente
    public void CreateNewSingleContract()
    {
        List <Client>   allClients      = new List <Client>();
        int             contractSize    = 1;
        MovableContract movableContract = null;

        // Contract object
        if (contractSize == 1)
        {
            movableContract = Instantiate(singleContractPrefab).GetComponent <MovableContract>();
        }

        //else if (contractSize == 2)
        //    movableContract = Instantiate(doubleContractPrefab).GetComponent<MovableContract>();

        Vector2 spawnPos = Vector2.zero;
        Vector2 endPos   = Vector2.zero;

        if (_belt == null)
        {
            _belt = FindObjectOfType <ConveyorBelt>();
        }

        if (_belt != null)
        {
            spawnPos    = _belt.contractsStartPos.position;
            spawnPos.x  = _belt.Bounds.center.x;
            spawnPos.x -= movableContract.ObjSpriteRenderer.bounds.extents.x;

            endPos.x  = spawnPos.x;
            endPos.y  = _belt.contractsEndPos.position.y;
            endPos.y += movableContract.ObjSpriteRenderer.bounds.size.y;
            endPos.y += 2 * (1 / 32f); // 2px offset

            movableContract.SetSortingLayer(_belt.SpriteRenderer.sortingLayerID);
            movableContract.SetOrderInLayer(_belt.SpriteRenderer.sortingOrder + 1);
        }

        movableContract.transform.position = spawnPos;
        movableContract.InitializeContract(endPos);
        movableContract.ClientAmount = contractSize;

        // Client settings
        // Start planet
        List <GridTile_Planet> allCandidatePlanets = new List <GridTile_Planet>(PlanetManager.instance.AllPlanetTiles);
        GridTile_Planet        startPlanet         = GetStartPlanet(allCandidatePlanets);

        if (startPlanet == null)
        {
            Debug.LogWarning("Could not find target start planet. Check start settings.");
            int randomIndex = UnityEngine.Random.Range(0, allCandidatePlanets.Count);
            startPlanet = allCandidatePlanets[randomIndex];
        }

        for (int i = 0; i < contractSize; i++)
        {
            int travelDistanceRating = _clientRules[_currentRuleIndex].travelDistanceRating;

            if (_clientRules[_currentRuleIndex].specialEndCondition == SpecialConditions.ClosestPlanet)
            {
                travelDistanceRating = 1;
            }

            if (travelDistanceRating == 0)
            {
                int randomDistance = UnityEngine.Random.Range(1, 4);
                travelDistanceRating = randomDistance;
            }

            // End planet
            //List<GridTile_Planet> distanceCandidates = GetPlanetsByDistance(allCandidatePlanets, candidateEndPlanets, startPlanet);
            GridTile_Planet endPlanet = GetEndPlanet(allCandidatePlanets, startPlanet, travelDistanceRating);

            allClients.Add(CreateClient(startPlanet, endPlanet, travelDistanceRating));
            allCandidatePlanets.Remove(endPlanet);
            int ruleCount = _clientRules.Count;

            if (_currentRuleIndex == _clientRules.Count - 1)
            {
                _allRulesApplied = true;
            }

            if (!_allRulesApplied)
            {
                _currentRuleIndex++;
            }
            else
            {
                _currentRuleIndex = UnityEngine.Random.Range(0, ruleCount);
            }

            startPlanet.AddContractHeat(1);
        }

        if (contractSize == 1)
        {
            Contract_Single contract = movableContract.GetComponent <Contract_Single>();
            contract.AssignClients(allClients, _completionTime, _timedContracts);
            contract.CalculatePointsReward(pointSettings);

            _allContracts.Add(contract);
        }
        //else if (contractSize == 2)
        //{
        //    Contract_Double contract = movableContract.GetComponent<Contract_Double>();
        //    contract.AssignClients(allClients);
        //    contract.CalculatePointsReward(pointSettings);
        //    _allContracts.Add(contract);
        //}

        _spawnCount++;

        if (newContractReceived != null)
        {
            newContractReceived();
        }
    }
Esempio n. 17
0
 public abstract bool CheckStartPlanet(GridTile_Planet currentPlanet);
Esempio n. 18
0
    private List <GridTile_Planet> GetEndPlanetsByDistance(List <GridTile_Planet> completeList, GridTile_Planet startPlanet, int travelDistanceRating)
    {
        List <int>  planetDistances = new List <int>();
        List <Ship> allShips        = ShipManager.instance.AllShips;
        int         count           = 0;

        foreach (var planet in completeList)
        {
            if (planet == startPlanet)
            {
                continue;
            }

            TileCoordinates planetPos      = planet.TileCoordinates;
            TileCoordinates startPos       = startPlanet.TileCoordinates;
            int             distanceRating = PathFinder.instance.GetDistanceRating(startPos.tileX, startPos.tileY, planetPos.tileX, planetPos.tileY, true);

            planet.CurrentDistanceRating = distanceRating;
            planetDistances.Add(distanceRating);
            count++;
        }
        planetDistances.Sort();

        List <GridTile_Planet> shortDistancePlanets  = new List <GridTile_Planet>();
        List <GridTile_Planet> mediumDistancePlanets = new List <GridTile_Planet>();
        List <GridTile_Planet> longDistancePlanets   = new List <GridTile_Planet>();
        List <GridTile_Planet> candidates            = new List <GridTile_Planet>();
        int shortCount  = 0;
        int mediumCount = 0;
        int longCount   = 0;

        int third     = planetDistances[(count / 3) - 1];
        int twoThirds = planetDistances[(count / 3 * 2) - 1];

        //Debug.Log("----- END PLANETS 1/3 DIST : " + third);
        //Debug.Log("----- END PLANETS 2/3 DIST : " + twoThirds);


        foreach (var planet in completeList)
        {
            if (planet == startPlanet)
            {
                continue;
            }

            if (planet.CurrentDistanceRating < third)
            {
                //Debug.Log("SHORT DIST PLANET (" + planet.CurrentDistanceRating + ") : " + planet.PlanetName);
                shortDistancePlanets.Add(planet);
                shortCount++;
            }
            else if (planet.CurrentDistanceRating >= twoThirds)
            {
                //Debug.Log("LONG DIST PLANET (" + planet.CurrentDistanceRating + ") : " + planet.PlanetName);
                longDistancePlanets.Add(planet);
                longCount++;
            }
            else
            {
                //Debug.Log("MEDIUM DIST PLANET (" + planet.CurrentDistanceRating + ") : " + planet.PlanetName);
                mediumDistancePlanets.Add(planet);
                mediumCount++;
            }
        }

        if (travelDistanceRating == 1)
        {
            if (shortCount > 0)
            {
                candidates = shortDistancePlanets;
            }

            else if (mediumCount > 0)
            {
                candidates = mediumDistancePlanets;
            }

            else if (longCount > 0)
            {
                candidates = longDistancePlanets;
            }

            else
            {
                candidates = new List <GridTile_Planet>(completeList);
                candidates.Remove(startPlanet);
            }
        }

        else if (travelDistanceRating == 2)
        {
            if (mediumCount > 0)
            {
                candidates = mediumDistancePlanets;
            }
            else
            {
                List <GridTile_Planet> shortLong = new List <GridTile_Planet>();
                int shortLongCount = 0;
                foreach (var planet in shortDistancePlanets)
                {
                    shortLong.Add(planet);
                    shortLongCount++;
                }
                foreach (var planet in longDistancePlanets)
                {
                    shortLong.Add(planet);
                    shortLongCount++;
                }

                if (shortLongCount > 0)
                {
                    candidates = shortLong;
                }
                else
                {
                    candidates = new List <GridTile_Planet>(completeList);
                    candidates.Remove(startPlanet);
                }
            }
        }
        else if (travelDistanceRating == 3)
        {
            if (longCount > 0)
            {
                candidates = longDistancePlanets;
            }

            else if (mediumCount > 0)
            {
                candidates = mediumDistancePlanets;
            }

            else if (shortCount > 0)
            {
                candidates = shortDistancePlanets;
            }

            else
            {
                candidates = new List <GridTile_Planet>(completeList);
                candidates.Remove(startPlanet);
            }
        }
        return(candidates);
    }