Ejemplo n.º 1
0
        public void bViewVotes()
        {
            Person p = null;

            if (state == uiState.SOCIETY && GraphicalSociety.focus != null)
            {
                p = GraphicalSociety.focus;
            }
            else
            {
                Hex hex = GraphicalMap.selectedHex;
                if (hex != null && hex.settlement != null && hex.settlement.title != null && hex.settlement.title.heldBy != null)
                {
                    p = hex.settlement.title.heldBy;
                }
            }

            if (p == null)
            {
                return;
            }

            VoteSession vs = p.society.voteSession;

            if (vs == null)
            {
                return;
            }

            world.audioStore.playClick();

            vs.assignVoters();
            addBlocker(world.prefabStore.getScrollSetVotes(p, vs.issue).gameObject);
        }
Ejemplo n.º 2
0
        public void checkData()
        {
            sess.assignVoters();
            textVoterName.text = "Voter: " + voterBars[0].voter.getFullName();
            textVPower.text    = "" + (int)(world.map.overmind.power);
            if (agent != null)
            {
                textVLiking.text = "" + (int)voterBars[0].voter.getRelation(agent).getLiking();
            }
            else
            {
                textVLiking.text = "N/A";
            }
            double uSel  = sess.issue.computeUtility(voterBars[0].voter, voteOptBars[0].opt, new List <ReasonMsg>());
            double uCurr = sess.issue.computeUtility(voterBars[0].voter, voterBars[0].voter.getVote(sess), new List <ReasonMsg>());

            textVoterUtility.text     = "Opinion of selected option: " + (int)uSel;
            textVoterCurrUtility.text = "Opinion of their current option: " + (int)uCurr;

            if (voterBars[0].voter.state != Person.personState.enthralled && voterBars[0].voter.getVote(sess) != voteOptBars[0].opt)
            {
                double utilityDelta = uCurr - uSel;
                if (utilityDelta < 0)
                {
                    utilityDelta = 0;
                }
                textSwitchCostPower.text  = "" + (int)((utilityDelta * world.map.param.voting_powerToSwitchPerU) + world.map.param.voting_powerToSwitchMin);
                textSwitchCostLiking.text = "" + (int)((utilityDelta * world.map.param.voting_likingToSwitchPerU) + world.map.param.voting_likingToSwitchMin);
                switchLiking.gameObject.SetActive(true);
                switchPower.gameObject.SetActive(true);
            }
            else
            {
                textSwitchCostPower.text  = "N/A";
                textSwitchCostLiking.text = "N/A";
                switchLiking.gameObject.SetActive(false);
                switchPower.gameObject.SetActive(false);
            }

            foreach (PopVoterBar bar in voterBars)
            {
                bar.checkData();
            }

            double     highest = voteOptBars[0].opt.votingWeight;
            VoteOption winner  = voteOptBars[0].opt;

            for (int i = 1; i < voteOptBars.Count; i++)
            {
                if (voteOptBars[i].opt.votingWeight > highest)
                {
                    highest = voteOptBars[i].opt.votingWeight;
                    winner  = voteOptBars[i].opt;
                }
            }
            textWinningOpt.text = winner.info(sess.issue);
        }
        public PopupScrollSet getScrollSet(VoteSession sess, List <VoteOption> votes)
        {
            PopupScrollSet specific = getInnerScrollSet();

            sess.assignVoters();
            foreach (VoteOption b in votes)
            {
                PopupBoxVote box = getVoteBox(sess, b);
                box.gameObject.transform.SetParent(specific.gameObject.transform);
                specific.scrollables.Add(box);
            }

            return(specific);
        }
        public void processVoting()
        {
            if (voteSession == null)
            {
                if (voteCooldown > 0)
                {
                    voteCooldown -= 1; return;
                }

                Person proposer = null;
                foreach (Person p in people)
                {
                    if (p.state == Person.personState.enthralled)
                    {
                        continue;
                    }
                    if (proposer == null)
                    {
                        proposer = p;
                    }
                    else
                    {
                        int myDelta    = map.turn - p.lastVoteProposalTurn;
                        int theirDelta = map.turn - proposer.lastVoteProposalTurn;
                        if (myDelta > theirDelta)
                        {
                            proposer = p;
                        }
                    }
                }
                if (proposer != null)
                {
                    proposer.lastVoteProposalTurn = map.turn;
                    VoteIssue issue = proposer.proposeVotingIssue();
                    if (issue == null)
                    {
                        return;
                    }

                    bool   positive = true;
                    int    priority = (this.hasEnthralled()) ? 1 : 3;
                    string msg      = this.getName() + " now voting on " + issue.ToString();

                    World.staticMap.addMessage(msg, priority, positive);

                    //Otherwise, on with voting for this new thing
                    voteSession               = new VoteSession();
                    voteSession.issue         = issue;
                    voteSession.timeRemaining = map.param.society_votingDuration;
                    if (World.logging && logbox != null)
                    {
                        logbox.takeLine("Starting voting on " + voteSession.issue.ToString());
                    }

                    if (this.hasEnthralled())
                    {
                        voteSession.assignVoters();
                        VoteOption optionChoice = null;
                        foreach (VoteOption opt in voteSession.issue.options)
                        {
                            if (opt.votesFor.Contains(proposer))
                            {
                                optionChoice = opt;
                                break;
                            }
                        }
                        string str = proposer.getFullName() + " has proposed a measure to be voted on by the nobles of "
                                     + this.getName() + ".\nThey are voting " +
                                     optionChoice.info(issue);

                        map.world.prefabStore.popImgMsg(str, "Voting issue: " + issue.getLargeDesc());
                    }
                }
            }
            else
            {
                if (voteSession.issue.stillValid(map) == false)
                {
                    voteSession = null;
                    World.log("Vote session no longer valid");
                    return;
                }
                if (voteSession.timeRemaining > 0)
                {
                    voteSession.timeRemaining -= 1; return;
                }

                voteSession.assignVoters();

                double     topVote = 0;
                VoteOption winner  = null;
                foreach (VoteOption option in voteSession.issue.options)
                {
                    if (option.votingWeight > topVote || winner == null)
                    {
                        winner  = option;
                        topVote = option.votingWeight;
                    }

                    voteSession.issue.changeLikingForVotes(option, voteSession.issue);
                }

                if (World.logging && logbox != null)
                {
                    logbox.takeLine("End voting on " + voteSession.issue.ToString());
                }
                if (World.logging && logbox != null)
                {
                    logbox.takeLine("    Winning option: " + winner.info());
                }

                if (this.hasEnthralled())
                {
                    string str = "Chosen outcome: " + winner.info(voteSession.issue);
                    str += "\nVotes for: ";
                    foreach (Person p in winner.votesFor)
                    {
                        str += p.getFullName() + ", ";
                    }
                    str = str.Substring(0, str.Length - 2);

                    map.world.prefabStore.popImgMsg(str, "Voting concluded. Issue: " + voteSession.issue.getLargeDesc());
                }

                voteSession.issue.implement(winner);
                if (voteSession.issue is VoteIssue_AssignLandedTitle == false)
                {
                    billsSinceLastSettlementAssignment += 1;
                }
                else
                {
                    billsSinceLastSettlementAssignment = 0;
                }
                voteSession = null;
            }
        }
Ejemplo n.º 5
0
        public void setTo(Person p)
        {
            if (p == null)
            {
                setToNull(); return;
            }

            profileBack.enabled     = true;
            profileMid.enabled      = true;
            profileFore.enabled     = true;
            profileBorder.enabled   = true;
            profileAdvEyes.enabled  = true;
            profileAdvMouth.enabled = true;
            profileAdvHair.enabled  = true;
            profileAdvJewel.enabled = true;
            profileBorder.sprite    = null;
            if (p.society.getSovereign() == p)
            {
                profileBorder.sprite = p.map.world.textureStore.slotKing;
            }
            else if (p.titles.Count > 0)
            {
                profileBorder.sprite = p.map.world.textureStore.slotDuke;
            }
            else
            {
                profileBorder.sprite = p.map.world.textureStore.slotCount;
            }

            if (World.staticMap.param.option_useAdvancedGraphics == 1)
            {
                //Null setting done to unfuck the distortion of images which periodically occurs
                profileBack.sprite     = null;
                profileMid.sprite      = null;
                profileAdvEyes.sprite  = null;
                profileAdvMouth.sprite = null;
                profileAdvHair.sprite  = null;
                profileAdvJewel.sprite = null;
                profileFore.sprite     = null;
                profileBack.sprite     = p.getImageBack();
                if (p.isMale)
                {
                    profileMid.sprite      = p.map.world.textureStore.cultures[p.culture.graphicsIndex].m_faces[p.imgAdvFace];
                    profileAdvEyes.sprite  = p.map.world.textureStore.cultures[p.culture.graphicsIndex].m_eyes[p.imgAdvEyes];
                    profileAdvMouth.sprite = p.map.world.textureStore.cultures[p.culture.graphicsIndex].m_mouths[p.imgAdvMouth];
                    profileAdvHair.sprite  = p.map.world.textureStore.cultures[p.culture.graphicsIndex].m_hair[p.imgAdvHair];
                    profileAdvJewel.sprite = p.map.world.textureStore.cultures[p.culture.graphicsIndex].m_jewels[p.imgAdvJewel];
                }
                else
                {
                    profileMid.sprite      = p.map.world.textureStore.cultures[p.culture.graphicsIndex].f_faces[p.imgAdvFace];
                    profileAdvEyes.sprite  = p.map.world.textureStore.cultures[p.culture.graphicsIndex].f_eyes[p.imgAdvEyes];
                    profileAdvMouth.sprite = p.map.world.textureStore.cultures[p.culture.graphicsIndex].f_mouths[p.imgAdvMouth];
                    profileAdvHair.sprite  = p.map.world.textureStore.cultures[p.culture.graphicsIndex].f_hair[p.imgAdvHair];
                    profileAdvJewel.sprite = p.map.world.textureStore.cultures[p.culture.graphicsIndex].f_jewels[p.imgAdvJewel];
                }
                profileFore.sprite = p.getImageFore();
            }
            else
            {
                profileAdvEyes.enabled  = false;
                profileAdvMouth.enabled = false;
                profileAdvJewel.enabled = false;
                profileAdvHair.enabled  = false;
                //Null setting done to unfuck the distortion of images which periodically occurs
                profileBack.sprite = null;
                profileMid.sprite  = null;
                profileFore.sprite = null;
                profileBack.sprite = p.getImageBack();
                profileMid.sprite  = p.getImageMid();
                profileFore.sprite = p.getImageFore();
            }


            personTitle.text = p.getFullName();
            TitleLanded title = p.title_land;

            if (title == null)
            {
                locText.text = "No Landed Title";
            }
            else
            {
                locText.text = "of " + title.settlement.name;
            }

            Society     soc  = p.society;
            VoteSession vote = (soc != null) ? soc.voteSession : null;

            if (vote != null)
            {
                personVoting.text = "Voting: " + p.getVote(vote).info(vote.issue);
            }
            else
            {
                personVoting.text = "Not voting";
            }

            voteSharePrediction.text = "";
            if (p.society.socType.periodicElection())
            {
                Title possibleOpt = null;
                foreach (Title t in soc.titles)
                {
                    if (t is Title_Sovereign)
                    {
                        if (t.getEligibleHolders(p.society).Contains(p))
                        {
                            possibleOpt = t;
                        }
                    }
                    else if (t is Title_ProvinceRuler && possibleOpt == null)
                    {
                        if (t.getEligibleHolders(p.society).Contains(p))
                        {
                            possibleOpt = t;
                        }
                    }
                }
                if (possibleOpt != null)
                {
                    VoteIssue_AssignTitle hypothetical = new VoteIssue_AssignTitle(p.society, p, possibleOpt);
                    foreach (Person p2 in possibleOpt.getEligibleHolders(p.society))
                    {
                        VoteOption opt = new VoteOption();
                        opt.person = p2;
                        hypothetical.options.Add(opt);
                    }
                    VoteSession sess = new VoteSession();
                    sess.issue = hypothetical;
                    sess.assignVoters();
                    double total   = 0;
                    double mine    = 0;
                    double highest = 0;
                    foreach (VoteOption opt in hypothetical.options)
                    {
                        total += opt.votingWeight;
                        if (opt.person == p)
                        {
                            mine = opt.votingWeight;
                        }
                        if (opt.votingWeight > highest)
                        {
                            highest = opt.votingWeight;
                        }
                    }
                    if (total > 0)
                    {
                        if (mine == highest)
                        {
                            voteSharePrediction.color = new Color(0, 0.75f, 0);
                        }
                        else
                        {
                            voteSharePrediction.color = new Color(1, 0.5f, 0.5f);
                        }
                        voteSharePrediction.text = possibleOpt.getName() + "\nPredicted Vote Share: " + (int)(100 * mine / total) + "%";
                    }
                }
            }
        }
        public void processVoting()
        {
            if (voteSession == null)
            {
                if (voteCooldown > 0)
                {
                    voteCooldown -= 1; return;
                }

                Person proposer = null;
                foreach (Person p in people)
                {
                    if (p.state == Person.personState.enthralled)
                    {
                        continue;
                    }
                    if (proposer == null)
                    {
                        proposer = p;
                    }
                    else
                    {
                        int myDelta    = map.turn - p.lastVoteProposalTurn;
                        int theirDelta = map.turn - proposer.lastVoteProposalTurn;
                        if (myDelta > theirDelta)
                        {
                            proposer = p;
                        }
                    }
                }
                if (proposer != null)
                {
                    proposer.lastVoteProposalTurn = map.turn;
                    VoteIssue issue = proposer.proposeVotingIssue();
                    if (issue == null)
                    {
                        return;
                    }

                    bool   positive = true;
                    int    priority = (this.hasEnthralled()) ? 1 : 3;
                    string msg      = this.getName() + " now voting on " + issue.ToString();

                    World.staticMap.addMessage(msg, priority, positive);

                    //Otherwise, on with voting for this new thing
                    voteSession               = new VoteSession();
                    voteSession.issue         = issue;
                    voteSession.timeRemaining = map.param.society_votingDuration;
                }
            }
            else
            {
                if (voteSession.issue.stillValid(map) == false)
                {
                    voteSession = null;
                    World.log("Vote session no longer valid");
                    return;
                }
                if (voteSession.timeRemaining > 0)
                {
                    voteSession.timeRemaining -= 1; return;
                }

                voteSession.assignVoters();

                double     topVote = 0;
                VoteOption winner  = null;
                foreach (VoteOption option in voteSession.issue.options)
                {
                    if (option.votingWeight > topVote || winner == null)
                    {
                        winner  = option;
                        topVote = option.votingWeight;
                    }

                    voteSession.issue.changeLikingForVotes(option);
                }

                voteSession.issue.implement(winner);
                voteSession = null;
            }
        }