Пример #1
0
void RankSystem::updatePos(  RankStats* rr ,  Stats* s )
{
	rr->addStats( s );

	if ( calc.code ) {
		calc.physAddr1[0] = rr->kills;
		calc.physAddr1[1] = rr->deaths;
		calc.physAddr1[2] = rr->hs;
		calc.physAddr1[3] = rr->tks;
		calc.physAddr1[4] = rr->shots;
		calc.physAddr1[5] = rr->hits;
		calc.physAddr1[6] = rr->damage;
		calc.physAddr1[7] = rr->points;
		for(int i = 1; i < 8; ++i)
			calc.physAddr2[i] = rr->bodyHits[i];
		cell result = 0;
		int err;
		MF_AmxPush(&calc.amx, calc.amxAddr2);
		MF_AmxPush(&calc.amx, calc.amxAddr1);
		if ((err = MF_AmxExec(&calc.amx,&result, calc.func)) != AMX_ERR_NONE)
			MF_LogError(&calc.amx, err, "Fatal error calculating stats");
		rr->score = result;
	}
	else rr->score = rr->kills - rr->deaths;

	RankStats* aa = rr->next;
	while ( aa && (aa->score <= rr->score) ) { // try to nominate
		rr->goUp();
		aa->goDown();
		aa = aa->next;		// go to next rank
	}
	if ( aa != rr->next )
	{
		unlink( rr );
		put_before( rr, aa );
	}
	else
	{
		aa = rr->prev;
		while ( aa && (aa->score > rr->score) ) { // go down
			rr->goDown();
			aa->goUp();
			aa = aa->prev;	// go to prev rank
		}
		if ( aa != rr->prev ){
			unlink( rr );
			put_after( rr, aa );
		}
	}

}
Пример #2
0
void RankSystem::updatePos_exec(RankStats* rr)
{
	// Enter Critical Section
	EnterCriticalSection(MUTEX);

	// Verify Pointer to RankStats
	if(rr == NULL)
	{
		MF_SyncLog("updatePos_exec: Pointer to RankStats has Expired!");

		// Leave Critical Section
		LeaveCriticalSection(MUTEX);
		return;
	}

	// Update Calc Buffer
	uint8_t i;
	calc.physAddr1[0] = rr->kills;
	calc.physAddr1[1] = rr->deaths;
	calc.physAddr1[2] = rr->hs;
	calc.physAddr1[3] = rr->tks;
	calc.physAddr1[4] = rr->shots;
	calc.physAddr1[5] = rr->hits;
	calc.physAddr1[6] = rr->damage;
	calc.physAddr1[7] = rr->bDefusions;
	calc.physAddr1[8] = rr->bDefused;
	calc.physAddr1[9] = rr->bPlants;
	calc.physAddr1[10] = rr->bExplosions;
	for(i = 1; i < 8; ++i)
		calc.physAddr2[i] = rr->bodyHits[i];

	// Result Calculation using Calc Buffer and Calc Function "get_score"
	cell result = 0;
	MF_AmxPush(&calc.amx, calc.amxAddr2);
	MF_AmxPush(&calc.amx, calc.amxAddr1);
	if((i = (uint8_t)MF_AmxExec(&calc.amx, &result, calc.func)) != AMX_ERR_NONE)
	{
		MF_SyncLog("updatePos_exec: Error in pawn function \"get_score\"");

		// Leave Critical Section
		LeaveCriticalSection(MUTEX);
		return;
	}

	rr->score = result;
	RankStats* itr = rr->prev;
	while(itr != NULL && rr->score >= itr->score)
	{
		rr->id--;
		itr->id++;
		itr = itr->prev;
	}
	if(itr != rr->prev)
	{
		unlink_ptr(rr);
		if(itr == NULL)
			put_before(rr, head);
		else
			put_after(rr, itr);	// since current "itr" has greater score
	}
	else
	{
		itr = rr->next;
		while(itr != NULL && rr->score < itr->score)
		{
			rr->id++;
			itr->id--;
			itr = itr->next;
		}
		if(itr != rr->next)
		{
			unlink_ptr(rr);
			if(itr == NULL)
				put_after(rr, tail);
			else
				put_before(rr, itr);	// since current "itr" has lower (or equal) score
		}
	}

	// Leave Critical Section
	LeaveCriticalSection(MUTEX);
}