src/team/results.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2006 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Manage the end of game results of a team
00020  *****************************************************************************/
00021 
00022 #include <sstream>
00023 #include "../include/app.h"
00024 #include "../include/constant.h"
00025 #include "results.h"
00026 #include "../character/character.h"
00027 #include "team.h"
00028 #include "macro.h"
00029 #include "../tool/i18n.h"
00030 
00031 TeamResults::TeamResults(const std::string& name,
00032                          const Surface* logo,
00033                          const Character* MV,
00034                          const Character* MUl,
00035                          const Character* MUs,
00036                          const Character* BT)
00037   : teamName(name),
00038     team_logo(logo),
00039     mostViolent(MV),
00040     mostUsefull(MUl),
00041     mostUseless(MUs),
00042     biggestTraitor(BT)
00043 {
00044 }
00045 
00046 TeamResults* TeamResults::createTeamResults(Team* team)
00047 {
00048   int         most_violent    = 0;
00049   int         most_useless    = 0x0FFFFFFF;
00050   int         most_usefull    = 0;
00051   int         most_traitor    = 0;
00052   const Character* MostViolent = NULL;
00053   const Character* MostUsefull = NULL;
00054   const Character* MostUseless = NULL;
00055   const Character* BiggestTraitor = NULL;
00056 
00057   // Search best/worst performers
00058   for (Team::const_iterator player = team->begin(),
00059        last_player = team->end();
00060        player != last_player;
00061        ++player) 
00062     //FOR_EACH_CHARACTER(team, player)
00063   {
00064     // Most damage in one shot
00065     if (player->GetMostDamage() > most_violent)
00066     {
00067       most_violent = player->GetMostDamage();
00068       MostViolent  = &(*(player));
00069     }
00070     // Most damage oplayerall to other teams
00071     if (player->GetOtherDamage() > most_usefull)
00072     {
00073       most_usefull = player->GetOtherDamage();
00074       MostUsefull  = &(*(player));
00075     }
00076     // Least damage oplayerall to other teams
00077     if (player->GetOtherDamage() < most_useless)
00078     {
00079       most_useless = player->GetOtherDamage();
00080       MostUseless  = &(*(player));
00081     }
00082     // Most damage oplayerall to his own team
00083     if (player->GetOwnDamage() > most_traitor)
00084     {
00085       most_traitor = player->GetOwnDamage();
00086       BiggestTraitor  = &(*(player));
00087     }
00088   }
00089 
00090   return new TeamResults(team->GetName()+" - "+team->GetPlayerName(),
00091                          &team->flag,
00092                          MostViolent,
00093                          MostUsefull,
00094                          MostUseless,
00095                          BiggestTraitor);
00096 }
00097 
00098 TeamResults* TeamResults::createGlobalResults(std::vector<TeamResults*>* list)
00099 {
00100   int         most_violent    = 0;
00101   int         most_useless    = 0x0FFFFFFF;
00102   int         most_usefull    = 0;
00103   int         most_traitor    = 0;
00104   const Character* MostViolent = NULL;
00105   const Character* MostUsefull = NULL;
00106   const Character* MostUseless = NULL;
00107   const Character* BiggestTraitor = NULL;
00108 
00109   for (res_iterator result=list->begin(), last_result=list->end();
00110        result != last_result;
00111        ++result)
00112   {
00113     const Character* player;
00114     // Most damage in one shot
00115     player = (*(result))->getMostViolent();
00116     if(player == NULL) continue;
00117     if (player->GetMostDamage() > most_violent)
00118     {
00119       most_violent = player->GetMostDamage();
00120       MostViolent  = player;
00121     }
00122     // Most damage oplayerall to other teams
00123     if (player->GetOtherDamage() > most_usefull)
00124     {
00125       most_usefull = player->GetOtherDamage();
00126       MostUsefull  = player;
00127     }
00128     // Least damage oplayerall to other teams
00129     if (player->GetOtherDamage() < most_useless)
00130     {
00131       most_useless = player->GetOtherDamage();
00132       MostUseless  = player;
00133     }
00134     // Most damage oplayerall to his own team
00135     if (player->GetOwnDamage() > most_traitor)
00136     {
00137       most_traitor = player->GetOwnDamage();
00138       BiggestTraitor  = player;
00139     }
00140   }
00141 
00142   // We'll do as if NULL is for all teams
00143   return new TeamResults(_("All teams"),
00144                          NULL,
00145                          MostViolent,
00146                          MostUsefull,
00147                          MostUseless,
00148                          BiggestTraitor);
00149 }
00150 
00151 std::vector<TeamResults*>* TeamResults::createAllResults(void)
00152 {
00153   TeamResults* results;
00154   std::vector<TeamResults*>* results_list = new std::vector<TeamResults*>;
00155 
00156   // Build results list
00157   FOR_EACH_TEAM(team)
00158   {
00159     results = TeamResults::createTeamResults(*team);
00160 
00161     results_list->push_back(results);
00162   }
00163  
00164   // Add overall results to list
00165   results = TeamResults::createGlobalResults(results_list);
00166   results_list->push_back(results);
00167 
00168   return results_list;
00169 }
00170 
00171 void TeamResults::deleteAllResults(std::vector<TeamResults*>* results_list)
00172 {
00173   // Build results list
00174   for (int i=results_list->size()-1; i==0; i--)
00175     delete ((*results_list)[i]);
00176  
00177   // Add overall results to list
00178   delete results_list;
00179 }

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7