Esempio n. 1
0
    private void ExecuteFindResources(Player p, GameEngineValues values)
    {
        p.Resources[(int)ResourceType.Food, 1]        *= 2;
        p.Resources[(int)ResourceType.Iron, 1]        *= 2;
        p.Resources[(int)ResourceType.Aluminum, 1]    *= 2;
        p.Resources[(int)ResourceType.Uranium, 1]     *= 2;
        p.Resources[(int)ResourceType.Plutonium, 1]   *= 2;
        p.Resources[(int)ResourceType.Hydrogen, 1]    *= 2;
        p.Resources[(int)ResourceType.Plastic, 1]     *= 2;
        p.Resources[(int)ResourceType.Electronics, 1] *= 2;
        p.Resources[(int)ResourceType.Composite, 1]   *= 2;
        p.Resources[(int)ResourceType.FossilFuels, 1] *= 2;

        int population = 0;

        foreach (int cityIndex in p.cities)
        {
            population += cityVals[cityIndex].population;
        }

        p.Resources[(int)ResourceType.Food, 1]        += (short)GD.GetRandom(0, population);
        p.Resources[(int)ResourceType.Iron, 1]        += (short)GD.GetRandom(0, 2 * population / 3);
        p.Resources[(int)ResourceType.Aluminum, 1]    += (short)GD.GetRandom(0, population / 3);
        p.Resources[(int)ResourceType.Uranium, 1]     += (short)GD.GetRandom(0, population / 4);
        p.Resources[(int)ResourceType.Plutonium, 1]   += (short)GD.GetRandom(0, population / 8);
        p.Resources[(int)ResourceType.Hydrogen, 1]    += (short)GD.GetRandom(0, population / 10);
        p.Resources[(int)ResourceType.Plastic, 1]     += (short)GD.GetRandom(0, population / 5);
        p.Resources[(int)ResourceType.Electronics, 1] += (short)GD.GetRandom(0, population / 7);
        p.Resources[(int)ResourceType.Composite, 1]   += (short)GD.GetRandom(0, population / 20);
        p.Resources[(int)ResourceType.FossilFuels, 1] += (short)GD.GetRandom(0, population / 9);
    }
Esempio n. 2
0
    public GameEngineValues CalculateNextTurn()
    {
        GameEngineValues values = new GameEngineValues(this);

        foreach (Player p in players)
        {
            if (p == null || p.def.type == PlayerDef.Type.Defeated)
            {
                continue;
            }
            CalculateResources(p, values);
            CalculatePopulation(p, values);
        }
        CalculateOrder(values);
        for (int i = 0; i < nump; i++)
        {
            if (values.order[i] == 255)
            {
                continue;
            }
            Player p = players[values.order[i]];
            if (p == null || p.def.type == PlayerDef.Type.Defeated)
            {
                continue;
            }
            CalculateActions(p, values); // Actions are computed after order is defined
        }

        return(values);
    }
Esempio n. 3
0
    private void ExecuteBuildImprovement(Player p, GameEngineValues values)
    {
        long imp = cityVals[p.val1].improvementsBF;

        imp |= values.cities[p.val1].improvementsBF;
        imp  = (imp) | ((long)(1 << p.val2));
        values.cities[p.val1].improvementsBF = imp;
    }
Esempio n. 4
0
    private void CalculateActions(Player p, GameEngineValues values)
    {
        // Depending on the action we may need to do something
        switch (p.action)
        {
        case ActionType.Nothing: break;

        case ActionType.FindResources: // Double the production of resources and add some extra random resource based on the population size
            ExecuteFindResources(p, values);
            break;

        case ActionType.ResearchTechnology:
            ExecuteResearchTechnology(p);
            break;

        case ActionType.BuildImprovement:
            ExecuteBuildImprovement(p, values);
            break;

        case ActionType.Social:
            ExecuteSocialActivities(p);
            break;

        case ActionType.BuildWeapons: break;

        case ActionType.DeployWeapons: break;

        case ActionType.UseWeapons: break;

        case ActionType.Propaganda: break;

        case ActionType.Diplomacy: break;

        case ActionType.SettleCity: break;

        case ActionType.Denucrlearize: break;

        case ActionType.Defend: break;
        }
    }
Esempio n. 5
0
    private void HandleGameTurnUpdate(byte[] data)
    {
        ulong gameid = BitConverter.ToUInt64(data, 0);

        GD.DebugLog("Received GameTurn for game " + gameid, GD.LT.Log);
        if (currentGameID != gameid)
        {
            OnGame?.Invoke(this, new NetworkManager.GameMessage {
                type = GameMsgType.Error, text = "Wrong game received: " + gameid
            });
            OnServerMessage?.Invoke(this, new NetworkManager.ServerMessage {
                type = ServerMessages.Error, message = "Wrong game received: " + gameid
            });
            return;
        }

        GameEngineValues gev = new GameEngineValues(data);

        OnGame?.Invoke(this, new NetworkManager.GameMessage {
            type = GameMsgType.GameTurn, engineValues = gev
        });
    }
Esempio n. 6
0
    private void Update()
    {
        DDDebug.text = "plaAct = " + playerAction.ToString() + "\nwtf = " + wtf.ToString();

        if (GD.fullScreen == FullScreenMode.Windowed && (Screen.width != lastWidth || Screen.height != lastHeight))
        {
            lastResize -= Time.deltaTime;
            if (lastResize < 0)
            {
                lastResize = 1f;
                lastWidth  = Screen.width;
                lastHeight = (int)(lastWidth * 1080f / 1920f);
                Screen.SetResolution(lastWidth, lastHeight, GD.fullscreen);
            }
        }

        SkipButton.gameObject.SetActive(timeToWait > 0 && timeToWait < waitTime - 1f);
        if (timeToWait > 0)
        {
            timeToWait -= Time.deltaTime;
            return;
        }

        if (wtf == WhatTheFuckStatus.PlayReceivedActions)
        {
            DisableButtons.gameObject.SetActive(true);
            ProcessTurnAction();
            return;
        }

        // Process the messages
        if (engine == null || engine.messages == null || engine.messages.Count == 0)
        {
            return;
        }
        NetworkManager.GameMessage msg = engine.messages[0];
        engine.messages.RemoveAt(0);

        switch (msg.type)
        {
        case GameMsgType.PlayerDeath: // Remove the player (And have all his cities to be destroyed, and use all remaining weapons
            ShowMessage("Received player death: " + msg.id);
            for (int i = 0; i < engine.nump; i++)
            {
                if (engine.players[i].def.id == msg.id)
                {
                    playersGOs[i].transform.Find("DeadEyeL").GetComponent <Image>().enabled = true;
                    return;

                    // FIXME add a message
                    // FIXME do some destruction
                }
            }
            break;

        case GameMsgType.GameProgressUpdate:
            // Find the player in the top bar, and show a green checkmark over it
            foreach (Transform pt in Players)
            {
                if (pt.GetComponent <Enemy>().player.def.id == msg.id)
                {
                    pt.Find("TurnCompleted").GetComponent <Image>().color = ColorVisible;
                }
            }
            break;

        case GameMsgType.Error:
            ShowMessage(msg.text, true);
            break;

        case GameMsgType.GameTurn:
            turn = msg.engineValues;
            PlayEndTurn();
            break;
        }
    }
Esempio n. 7
0
 private void ExecuteSettleCity(Player p, GameEngineValues values)
 {
     // Pick the closest city with max population, halve the population of the src city and send people to the target city
     // Do we need to do it here? I suppose the action will be the same on all clients. The problem is that we need to run the actions if we are server side. Or we will not be able to process the AI
 }
Esempio n. 8
0
    private void CalculateOrder(GameEngineValues values)
    {
        // The order is a byte[6] with the index of each player in order of action
        byte[] order = new byte[6];
        for (int i = 0; i < 6; i++)
        {
            order[i]        = 255;
            values.order[i] = 255;
        }

        // Pick all players that are defending or doing social, randomize them and place them at the begin
        // Pick all other players, randomize, and place after the first ones
        List <int> list = new List <int>();

        for (int i = 0; i < nump; i++)
        {
            if (players[i].def.type == PlayerDef.Type.Defeated)
            {
                continue;
            }
            if (players[i].action == ActionType.Defend || players[i].action == ActionType.Diplomacy || players[i].action == ActionType.Social)
            {
                list.Add(i);
            }
        }
        int pos = list.Count;

        if (pos > 0)
        {
            for (int i = 0; i < 100; i++)
            {
                int a   = GD.GetRandom(0, pos);
                int b   = GD.GetRandom(0, pos);
                int tmp = list[a];
                list[a] = list[b];
                list[b] = tmp;
            }
        }
        for (int i = 0; i < pos; i++)
        {
            order[i] = (byte)list[i];
        }

        list.Clear();
        for (int i = 0; i < nump; i++)
        {
            if (players[i].def.type == PlayerDef.Type.Defeated)
            {
                continue;
            }
            if (players[i].action != ActionType.Defend && players[i].action != ActionType.Diplomacy && players[i].action != ActionType.Social)
            {
                list.Add(i);
            }
        }
        if (list.Count > 0)
        {
            for (int i = 0; i < 100; i++)
            {
                int a   = GD.GetRandom(0, list.Count);
                int b   = GD.GetRandom(0, list.Count);
                int tmp = list[a];
                list[a] = list[b];
                list[b] = tmp;
            }
        }
        for (int i = 0; i < list.Count; i++)
        {
            order[i + pos] = (byte)list[i];
        }

        // Now use the oder array to define the order of the players
        byte min;
        int  index = 0;

        pos = 0;
        while (index != -1)
        {
            index = -1;
            min   = 255;
            for (int i = 0; i < 6; i++)
            {
                if (min > order[i])
                {
                    min   = order[i];
                    index = i;
                }
            }
            if (index != -1)
            {
                values.order[pos] = (byte)index;
                order[index]      = 255;
                pos++;
            }
        }
    }
Esempio n. 9
0
    public void CalculatePopulation(Player p, GameEngineValues values)
    {
        // Find the place for the current player
        int pindex = -1;

        for (int i = 0; i < players.Length; i++)
        {
            if (players[i].def.id == p.def.id)
            {
                pindex = i;
                break;
            }
        }
        if (pindex == -1)
        {
            GD.DebugLog("CalculateResources: Cannot find the specified player id=" + p, GD.LT.Debug);
            return;
        }
        // FIXME
        // Increase the population in case there is enough food, in case the food is zero and the consumption is high, let people starve
        // The increase should be about *1.05 with at least 1 of increase

        if (players[pindex].Resources[(int)ResourceType.Food, 0] > 0 || players[pindex].Resources[(int)ResourceType.Food, 1] == players[pindex].Resources[(int)ResourceType.Food, 2])
        {
            foreach (int cityIndex in p.cities)
            {
                CityVals src = cityVals[cityIndex];
                CityVals dst = values.cities[cityIndex];
                if (dst == null)
                {
                    dst = new CityVals(src);
                    values.cities[cityIndex] = dst;
                }

                int increase = (int)(src.population * 0.05f);
                if (increase == 0)
                {
                    increase = 1;
                }
                if (src.status == CityStatus.Radioactive)
                {
                    increase = -1;
                }
                else if (src.population + increase > 25 && !src.HasImprovement((int)ItemType.IHOUS - (int)ProductionType.Improvement))
                {
                    increase = 25 - src.population;
                    if (increase < 0)
                    {
                        increase = 0;
                    }
                }
                if (src.population != 0 && increase != 0)
                {
                    dst.population += increase;
                }
                if (dst.population <= 0)
                {
                    dst.population = 0;
                    dst.status     = src.status == CityStatus.Radioactive ? CityStatus.RadioWaste : CityStatus.Destroyed;
                }
            }
        }
    }
Esempio n. 10
0
    public void CalculateResources(Player p, GameEngineValues values)
    {
        // Find the place for the current player
        int pindex = -1;

        for (int i = 0; i < players.Length; i++)
        {
            if (players[i].def.id == p.def.id)
            {
                pindex = i;
                break;
            }
        }
        if (pindex == -1)
        {
            GD.DebugLog("CalculateResources: Cannot find the specified player id=" + p, GD.LT.Debug);
            return;
        }
        // Food ************************************************************************************************************************************************************
        // Food +1 per city, +10 per farm, city_production*2 per hydrofarm
        short produced = (short)p.cities.Count;

        foreach (int cityIndex in p.cities)
        {
            if (cityVals[cityIndex].HasImprovement((int)ItemType.IFARM - (int)ProductionType.Improvement))
            {
                produced += 10;
            }
            if (cityVals[cityIndex].HasImprovement((int)ItemType.IHFRM - (int)ProductionType.Improvement))
            {
                produced += 15;
            }
        }
        players[pindex].Resources[(int)ResourceType.Food, 1] = produced;
        // Consume the food, 1 unit for each 10 millions population, but use floor to allow basic production
        int population = 0;

        foreach (int cityIndex in p.cities)
        {
            population += cityVals[cityIndex].population;
        }
        // FIXME here we want to set the vals to a new spot
        players[pindex].Resources[(int)ResourceType.Food, 2] = (short)(population / 10);
        players[pindex].Resources[(int)ResourceType.Food, 0] = (short)(players[pindex].Resources[(int)ResourceType.Food, 0] + players[pindex].Resources[(int)ResourceType.Food, 1] - players[pindex].Resources[(int)ResourceType.Food, 2]);
        if (players[pindex].Resources[(int)ResourceType.Food, 0] < 0)
        {
            players[pindex].Resources[(int)ResourceType.Food, 0] = 0;                                                       // FIXME add some problem for the enemy, do a message to the player to show there is not enough food
        }
        // Iron ************************************************************************************************************************************************************

        // Aluminum ************************************************************************************************************************************************************
        // Uranium ************************************************************************************************************************************************************
        // Plutonium ************************************************************************************************************************************************************
        // Hydrogen ************************************************************************************************************************************************************
        // Plastic ************************************************************************************************************************************************************
        // Electronic ************************************************************************************************************************************************************
        // Composite ************************************************************************************************************************************************************
        // FossilFuel ************************************************************************************************************************************************************

        // FIXME
    }
Esempio n. 11
0
    public void EndTurn(bool multiplayer, ulong playerID, GameAction gameAction)
    {
        if (GD.IsStatus(LoaderStatus.Server, LoaderStatus.ServerBackground)) // We are on the server
        // This call comes from the client listner
        // Find the player in the player list
        {
            for (int i = 0; i < nump; i++)
            {
                if (players[i].def.id == playerID)
                {
                    completed[i]      = true;
                    players[i].action = gameAction.action;
                    players[i].val1   = gameAction.val1;
                    players[i].val2   = gameAction.val2;
                    break;
                }
            }

            // Auto-complete AI and defeated
            for (int i = 0; i < nump; i++)
            {
                if (players[i].def.type == PlayerDef.Type.AI)
                {
                    completed[i] = true;
                }
                else if (players[i].def.type == PlayerDef.Type.Defeated)
                {
                    completed[i]      = true;
                    players[i].action = ActionType.Nothing;
                }
            }

            // All human players completed?
            bool allCompleted = true;
            for (int i = 0; i < nump; i++)
            {
                if (players[i].def.type != PlayerDef.Type.Defeated && players[i].def.type != PlayerDef.Type.AI && !completed[i])
                {
                    allCompleted = false;
                    break;
                }
            }
            if (allCompleted)
            {
                GameEngineValues values = CalculateNextTurn();
                // Send the result to all the clients
                GD.instance.networkManager.SendGameTurn(players, values);
                // And reset the completed
                for (int i = 0; i < nump; i++)
                {
                    completed[i] = false;
                }
            }
        }
        else if (multiplayer) // Multiplayer mode and we are the client
        // This call comes from the Renderer, Send the message to the server
        {
            GD.instance.networkManager.SendGameAction(GD.thePlayer, gameAction);
        }
        else // Single player mode
        // This call comes from the Renderer, so we can process it right now: CalculateNextTurn
        {
            for (int i = 0; i < nump; i++)
            {
                if (players[i].def.id == playerID)
                {
                    completed[i]      = true;
                    players[i].action = gameAction.action;
                    players[i].val1   = gameAction.val1;
                    players[i].val2   = gameAction.val2;
                    break;
                }
            }
            GameEngineValues values = CalculateNextTurn();
            GD.thePlayer.OnGame?.Invoke(this, new NetworkManager.GameMessage {
                type = GameMsgType.GameTurn, engineValues = values
            });
        }
    }