src/tron/gStatList.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 file by guru3/tank program
00026 
00027 */
00028 
00029 #include "gStatList.h"
00030 //#include "gStatistics.h"
00031 #include <iostream>
00032 
00033 gStatList::gStatList(const char* name, int oType)
00034 {
00035     myName = name;
00036     outputType = oType;
00037 
00038     if (outputType == 0)
00039     {
00040         myFile = new tStatFile(myName, &entries);
00041         myFile->read();
00042     }
00043 
00044     //  std::cout << "i am " << name << " and i have " << entries.Len() << " values\n";
00045     //  int c = getPlaceInList(tString("tank program"));
00046     //  std::cout << "i am " << name << " and i have " << entries.Len() << " values\n";
00047     //  add(tString("Tank Program"), 8);
00048     //  add(tString("guru3"), 2);
00049     //  add(tString("insaneo"), 5);
00050     //  add(tString("randman"), 1);
00051     //  add(tString("aguy"), 7);
00052     //  std::cout << "we have " << entries[c]->getName() << " with " << entries[c]->getValue() << "!\n";
00053 
00054     //  std::cout << entries.Len() << " entries\n";
00055 
00056     //  for (int c = 0; c < entries.Len(); c++)
00057     //  {
00058     //          std::cout << getName() << ": " << entries[c]->getName() << " has score " << entries[c]->getValue() << " (" << c << ")\n";
00059     //  }
00060 
00061     //  std::cout << "constructed!\n";
00062 }
00063 
00064 //adds value to the existing one
00065 void gStatList::add(tString name, REAL value)
00066 {
00067     int c = getPlaceInList(name);
00068     entries[c]->addValue(value);
00069     output(c);
00070 }
00071 
00072 //replaces the existing value with value
00073 void gStatList::update(tString name, REAL value)
00074 {
00075     int c = getPlaceInList(name);
00076     entries[c]->setValue(value);
00077     output(c);
00078 }
00079 
00080 //if the new value is greated, replace
00081 void gStatList::greater(tString name, REAL value)
00082 {
00083     int c = getPlaceInList(name);
00084     if (entries[c]->getValue() < value)
00085     {
00086         update(name, value);
00087     }
00088 }
00089 
00090 //who am i?
00091 tString gStatList::getName()
00092 {
00093     return myName;
00094 }
00095 
00096 //return the value for person of name
00097 REAL gStatList::getValue(tString name)
00098 {
00099     return entries[getPlaceInList(name)]->getValue();
00100 }
00101 
00102 int gStatList::getPlaceInList(tString name)
00103 {
00104     //  std::cout << myName << ": getting place\n";
00105 
00106     for (int c = 0; c < entries.Len(); c++)
00107     {
00108         if (entries[c]->getName() == name)
00109         {
00110             return c;
00111         }
00112     }
00113 
00114     //  std::cout << myName << ": adding place\n";
00115 
00116     //didn't find it, add it
00117     tStatEntry *newone = new tStatEntry(name);
00118     entries.Add(newone, newone->id);
00119     return getPlaceInList(name);
00120 }
00121 
00122 void gStatList::output(int c)
00123 {
00124     entries[c]->toWrite = true;
00125 
00126     if (outputType == 0)
00127     {
00128         myFile->write();
00129     }
00130 }
00131 
00132 gStatList::~gStatList()
00133 {
00134     if (outputType == 0)
00135     {
00136         delete myFile;
00137     }
00138 
00139     for (int c = 0; c < entries.Len(); c++)
00140     {
00141         entries.Remove(entries[c], entries[c]->id);
00142     }
00143 }

Generated on Sat Mar 15 22:56:10 2008 for Armagetron Advanced by  doxygen 1.5.4