AC Blog-ish
#7
So, I don't know if anyone actually cares about my "blog", but if anyone is reading this... can someone explain why this is a struct instead of a class?

Code:
struct voteinfo { int boot; int owner, callmillis, result, num1, num2, type; char text[MAXTRANS]; serveraction *action; bool gonext; enet_uint32 host; voteinfo() : boot(0), owner(0), callmillis(0), result(VOTE_NEUTRAL), action(NULL), gonext(false), host(0) {} ~voteinfo() { delete action; } void end(int result) { if(action && !action->isvalid()) result = VOTE_NO; // don't perform() invalid votes sendf(-1, 1, "ri2", SV_VOTERESULT, result); this->result = result; if(result == VOTE_YES) { if(valid_client(owner)) clients[owner]->lastvotecall = 0; if(action) action->perform(); } loopv(clients) clients[i]->vote = VOTE_NEUTRAL; } bool isvalid() { return valid_client(owner) && action != NULL && action->isvalid(); } bool isalive() { return servmillis - callmillis < 30*1000; } void evaluate(bool forceend = false) { if(result!=VOTE_NEUTRAL) return; // block double action if(action && !action->isvalid()) end(VOTE_NO); int stats[VOTE_NUM] = {0}; int adminvote = VOTE_NEUTRAL; loopv(clients) if(clients[i]->type!=ST_EMPTY /*&& clients[i]->connectmillis < callmillis*/) // new connected people will vote now { stats[clients[i]->vote]++; if(clients[i]->role==CR_ADMIN) adminvote = clients[i]->vote; }; bool admin = clients[owner]->role==CR_ADMIN || (!isdedicated && clients[owner]->type==ST_LOCAL); int total = stats[VOTE_NO]+stats[VOTE_YES]+stats[VOTE_NEUTRAL]; const float requiredcount = 0.51f; bool min_time = servmillis - callmillis > 10*1000; #define yes_condition ((min_time && stats[VOTE_YES] - stats[VOTE_NO] > 0.34f*total && totalclients > 4) || stats[VOTE_YES] > requiredcount*total) #define no_condition (forceend || !valid_client(owner) || stats[VOTE_NO] >= stats[VOTE_YES]+stats[VOTE_NEUTRAL] || adminvote == VOTE_NO) #define boot_condition (!boot || (boot && valid_client(num1) && clients[num1]->peer->address.host == host)) if( (yes_condition || admin || adminvote == VOTE_YES) && boot_condition ) end(VOTE_YES); else if( no_condition || (min_time && !boot_condition)) end(VOTE_NO); else return; #undef boot_condition #undef no_condition #undef yes_condition } };
Thanks given by:


Messages In This Thread
AC Blog-ish - by Mousikos - 29 May 15, 12:14AM
RE: AC Blog-ish - by Mousikos - 29 May 15, 06:06AM
RE: AC Blog-ish - by Mousikos - 29 May 15, 08:07AM
RE: AC Blog-ish - by Mr.Floppy - 29 May 15, 09:51AM
RE: AC Blog-ish - by Mousikos - 29 May 15, 11:16AM
RE: AC Blog-ish - by Mr.Floppy - 29 May 15, 11:55AM
RE: AC Blog-ish - by Mousikos - 29 May 15, 06:30PM
RE: AC Blog-ish - by MathiasB - 29 May 15, 06:51PM
RE: AC Blog-ish - by Luc@s - 29 May 15, 06:34PM
RE: AC Blog-ish - by Mousikos - 29 May 15, 06:40PM
RE: AC Blog-ish - by TheNihilanth - 29 May 15, 06:58PM
RE: AC Blog-ish - by Mousikos - 29 May 15, 10:47PM
RE: AC Blog-ish - by MathiasB - 01 Jun 15, 09:28AM
RE: AC Blog-ish - by Mr.Floppy - 01 Jun 15, 11:58AM
RE: AC Blog-ish - by Ronald_Reagan - 29 May 15, 11:20PM
RE: AC Blog-ish - by Mousikos - 29 May 15, 11:27PM
RE: AC Blog-ish - by Mousikos - 31 May 15, 08:26PM
RE: AC Blog-ish - by 1Cap - 01 Jun 15, 01:29PM
RE: AC Blog-ish - by Mousikos - 04 Jun 15, 06:07AM
RE: AC Blog-ish - by MathiasB - 04 Jun 15, 07:37AM
RE: AC Blog-ish - by Thrawn - 04 Jun 15, 11:35PM