Code: Show/Hide #define VOTING_TAG 6326 enum _VotePossibilities { VOTE_Obstain, // leave this one at the start // add whatever you want here VOTE_Dodgeball, // 1 VOTE_Football, // 2 VOTE_Hockey, // 3 VOTE_Count // leave this one at the end }; struct VoteResults { int results[VOTE_Count]; }; void botInfo::vote(int value, Player *p) { if (value > 0 && value < VOTE_Count); set_tag(p,VOTING_TAG,value); } void botInfo::resetVotes() { for (_listnode <Player> *parse = playerlist->head; parse; parse = parse->next) { set_tag(parse->item,VOTING_TAG,VOTE_Obstain); } } VoteResults botInfo::getResults() { VoteResults vr; for (int x = 0; x < VOTE_Count;++x) vr.results[x] = 0; for (_listnode <Player> *parse = playerlist->head; parse; parse = parse->next) { if (parse->item != me) { int vote = get_tag(parse->item,VOTING_TAG); vr.results[vote]++; } } return vr; } |
Code: Show/Hide VoteResults getResults(); |
Code: Show/Hide VoteResults* botInfo::getResults(); |
Code: Show/Hide VoteResults* botInfo::getResults()
{ VoteResults vr; for (int x = 0; x < VOTE_Count;++x) vr.results[x] = 0; for (_listnode <Player> *parse = playerlist->head; parse; parse = parse->next) { if (parse->item != me) { int vote = get_tag(parse->item,VOTING_TAG); vr.results[vote]++; } } return &vr; } |
Code: Show/Hide VoteResults *vr = getResults();
int res1 = vr->results[0]; |
Code: Show/Hide {
VoteResults vr; return &vr; } |
Quote: |
int results[VOTE_Count]; int winner = getResults(results); |
Code: Show/Hide #define VOTING_TAG 6326 enum _VotePossibilities { VOTE_Obstain, // leave this one at the start // add whatever you want here VOTE_Dodgeball, // 1 VOTE_Football, // 2 VOTE_Hockey, // 3 VOTE_Count // leave this one at the end }; void botInfo::vote(int value, Player *p) { if (value > 0 && value < VOTE_Count); set_tag(p,VOTING_TAG,value); } void botInfo::resetVotes() { for (_listnode <Player> *parse = playerlist->head; parse; parse = parse->next) { set_tag(parse->item,VOTING_TAG,VOTE_Obstain); } } // get the winner, and the results where results is an int array at least as big as VOTE_Count int botInfo::getResults(int* results) { int winner = 0; int winnerCount = 0; for (int x = 0; x < VOTE_Count;++x) (*results)[x] = 0; for (_listnode <Player> *parse = playerlist->head; parse; parse = parse->next) { if (parse->item != me) { int vote = get_tag(parse->item,VOTING_TAG); int count = (*results)[vote] + 1; if (count > winnerCount) { count = winnerCount; winner = vote; } (*results)[vote] = count; } } return winner; } |