예제 #1
0
파일: a_vote.c 프로젝트: Raptor007/aq2-tng
qboolean _iCheckMapVotes (void)
{
	static qboolean enough = false;
	float p;
	votelist_t *tmp;

	if (!map_need_to_check_votes)
		return (enough);

	tmp = MapWithMostVotes (&p);

	enough = (tmp != NULL && p >= mapvote_pass->value / 100.0f);
	if (map_num_clients < mapvote_min->value)
		enough = false;
	if (mapvote_need->value)
	{
		if ((float)((float) map_num_votes / (float) map_num_clients) <
			(float)(mapvote_need->value / 100.0f))
			enough = false;
	}

	map_need_to_check_votes = false;

	return (enough);
}
예제 #2
0
파일: a_vote.c 프로젝트: Raptor007/aq2-tng
qboolean _MostVotesStr (char *buf)
{
	float p_most = 0.0f;
	votelist_t *most;

	most = MapWithMostVotes(&p_most);
	if (most != NULL)
	{
		sprintf (buf, "%s (%.2f%%)", most->mapname, p_most * 100.0f);
		return true;
	}
	else
		strcpy (buf, "(no map)");

	return false;
}
예제 #3
0
파일: a_vote.c 프로젝트: Raptor007/aq2-tng
void Cmd_Maplist_f(edict_t *ent)
{
	//go through the votelist and list out all the maps and % votes
	int lines, chars_on_line, len_mr;
	float p_test = 0.0f, p_most = 0.0f;
	votelist_t *search, *most;
	char msg_buf[MAX_STRING_CHARS], tmp_buf[128];	//only 40 are used

	if (!use_mapvote->value) {
		gi.cprintf(ent, PRINT_HIGH, "Map voting is disabled.\n");
		return;
	}

	most = MapWithMostVotes (&p_most);

	sprintf (msg_buf,
		"List of maps that can be voted on:\nRequire more than %d%% votes (%.2f)\n\n",
		(int)mapvote_pass->value, mapvote_pass->value / 100.0f);

	lines = chars_on_line = 0;
	for (search = map_votes; search != NULL; search = search->next)
	{

		if (map_num_clients > 0)
			p_test = (float) ((float) search->num_votes / (float) map_num_clients);

		if (p_test >= 10.0)
			len_mr = 11;
		else
			len_mr = 10;

		len_mr += strlen (search->mapname);
		//Igor[Rock] begin
		//    if (num_allvotes && vrot->value)
		//       len_mr += 4;
		//Igor[Rock] end
		if ((chars_on_line + len_mr + 2) > 39)
		{
			Q_strncatz (msg_buf, "\n", sizeof(msg_buf));
			lines++;
			chars_on_line = 0;
			if (lines > 25)
				break;
		}

		Com_sprintf (tmp_buf, sizeof(tmp_buf), "%s (%.2f)  ", search->mapname, p_test);
		Q_strncatz(msg_buf, tmp_buf, sizeof(msg_buf));
		chars_on_line += len_mr;
	}

	if (map_votes == NULL)
		Q_strncatz(msg_buf, "None!", sizeof(msg_buf));
	else if (most != NULL)
	{
		Com_sprintf (tmp_buf, sizeof(tmp_buf), "\n\nMost votes: %s (%.2f)", most->mapname, p_most);
		Q_strncatz(msg_buf, tmp_buf, sizeof(msg_buf));
	}

	Q_strncatz(msg_buf, "\n\n", sizeof(msg_buf));
	Com_sprintf (tmp_buf, sizeof(tmp_buf),
		"%d/%d (%.2f%%) clients voted\n%d client%s minimum (%d%% required)",
		map_num_votes, map_num_clients,
		(float)( (float)map_num_votes /
		(float)(map_num_clients > 0 ? map_num_clients : 1) * 100.0f),	// TempFile changed to percentual display
		(int)mapvote_min->value, (mapvote_min->value > 1 ? "s" : ""),
		(int)mapvote_need->value);

	Q_strncatz(msg_buf, tmp_buf, sizeof(msg_buf));

	gi.centerprintf (ent, "%s", msg_buf);

	return;
}
예제 #4
0
파일: a_vote.c 프로젝트: Raptor007/aq2-tng
void _MapExitLevel (char *NextMap)
{
	votelist_t *votemap = NULL;
	//Igor[Rock] BEGIN
	FILE *votefile;
	char buf[MAX_STR_LEN];
	//Igor[Rock] END

	// If mapvote_next=1 and level has ended, ignore minimums required for mapvote.
	if( _iCheckMapVotes() || ((map_num_votes > 0) && mapvote_next && mapvote_next->value) )
	{
		votemap = MapWithMostVotes (NULL);
		Q_strncpyz (NextMap, votemap->mapname, MAX_QPATH);
		gi.bprintf (PRINT_HIGH, "Next map was voted on and is %s.\n", NextMap);
	}

	//clear stats
	for (votemap = map_votes; votemap != NULL; votemap = votemap->next)
	{
		//Igor[Rock] BEGIN
		if (votemap->num_votes)
		{
			votemap->num_allvotes += votemap->num_votes;
			num_allvotes += votemap->num_votes;
		}
		if (Q_stricmp (level.mapname, votemap->mapname) == 0)
		{
			if (map_num_clients > 1)
			{
				if (votemap->num_allvotes < (map_num_clients / 2))
				{
					num_allvotes -= votemap->num_allvotes;
					votemap->num_allvotes = 0;
				}
				else
				{
					num_allvotes -= (map_num_clients / 2);
					votemap->num_allvotes -= (map_num_clients / 2);
				}
			}
			else
			{
				if (votemap->num_allvotes)
				{
					num_allvotes--;
					votemap->num_allvotes--;
				}
			}
		}
		//Igor[Rock] END
		votemap->num_votes = 0;
	}

	//Igor[Rock] BEGIN
	// Save the actual votes to a file
	votefile = fopen (maplistpath, "w");
	if (votefile != NULL)
	{
		sprintf (buf, "%d\n", num_allvotes);
		fputs (buf, votefile);

		for (votemap = map_votes; votemap != NULL; votemap = votemap->next)
		{
			sprintf (buf, "%s,%d\n", votemap->mapname, votemap->num_allvotes);
			fputs (buf, votefile);
		}

		fclose (votefile);
	}
	//Igor[Rock] END
	map_num_votes = 0;
	map_num_clients = 0;
	map_need_to_check_votes = true;
}
예제 #5
0
void
Cmd_Maplist_f (edict_t * ent, char *dummy)
{
  //go through the votelist and list out all the maps and % votes
  int lines, chars_on_line, len_mr;
  float p_test, p_most;
  votelist_t *search, *most;
  char msg_buf[16384], tmp_buf[400];	//only 40 are used

  p_test = p_most = 0.0;

  most = MapWithMostVotes (&p_most);

  sprintf (msg_buf,
	   "List of maps that can be voted on:\nRequire more than %d%%%% votes (%.2f)\n\n",
	   (int) mapvote_pass->value,
	   (float) ((float) mapvote_pass->value / 100.0));

  lines = chars_on_line = 0;
  for (search = map_votes; search != NULL; search = search->next)
    {

      if (map_num_clients > 0)
	p_test =
	  (float) ((float) search->num_votes / (float) map_num_clients);

      if (p_test >= 10.0)
	len_mr = 11;
      else
	len_mr = 10;

      len_mr += strlen (search->mapname);
//Igor[Rock] begin
      //    if (num_allvotes && vrot->value)
      //       len_mr += 4;
      //Igor[Rock] end
      if ((chars_on_line + len_mr + 2) > 39)
	{
	  strcat (msg_buf, "\n");
	  lines++;
	  chars_on_line = 0;
	  if (lines > 25)
	    break;
	}
//Igor[Rock] begin
      //    if (num_allvotes && vrot->value) {
      //       sprintf(tmp_buf, "%s (%.2f,%2d%%%%)  ",
      //             search->mapname, p_test,
      //          (search->num_allvotes * 100) / num_allvotes);
      //    }
      //    else {
      sprintf (tmp_buf, "%s (%.2f)  ", search->mapname, p_test);
//    }
      //Igor[Rock] End
      strcat (msg_buf, tmp_buf);
      chars_on_line += len_mr;

    }

  if (map_votes == NULL)
    strcat (msg_buf, "None!");
  else if (most != NULL)
    {
      sprintf (tmp_buf, "\n\nMost votes: %s (%.2f)", most->mapname, p_most);
      strcat (msg_buf, tmp_buf);
    }

  strcat (msg_buf, "\n\n");
  sprintf (tmp_buf,
	   "%d/%d (%.2f%%%%) clients voted\n%d client%s minimum (%d%%%% required)",
	   map_num_votes, map_num_clients,
	   (float) ((float) map_num_votes /
		    (float) (map_num_clients > 0 ? map_num_clients : 1) * 100),	// TempFile changed to percentual display
	   (int) mapvote_min->value, (mapvote_min->value > 1 ? "s" : ""),
	   (int) mapvote_need->value);
  strcat (msg_buf, tmp_buf);

  gi.centerprintf (ent, msg_buf);

  return;
}