src/tron/gArena.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 
00026 */
00027 
00028 #include "tMemManager.h"
00029 
00030 #include "nConfig.h"
00031 
00032 #include "eGrid.h"
00033 #include "gArena.h"
00034 #include "gSpawn.h"
00035 #include "gWall.h"
00036 #include "gParser.h"
00037 #include "tRandom.h"
00038 #include "eRectangle.h"
00039 
00040 static float sizeMultiplier = .5f;
00041 static nSettingItem<float> conf_mult ("REAL_ARENA_SIZE_FACTOR", sizeMultiplier);
00042 
00043 static int axes = 4;
00044 static nSettingItemWatched<int> conf_axes ("ARENA_AXES", axes,  nConfItemVersionWatcher::Group_Breaking, 6 );
00045 
00046 gArena::gArena():spawnPoints()
00047 {
00048 }
00049 
00050 void gArena::NewSpawnPoint(const eCoord &loc,const eCoord &dir){
00051     gSpawnPoint *s=tNEW(gSpawnPoint) (loc,dir);
00052     spawnPoints.Add(s,s->id);
00053 }
00054 
00055 
00056 void gArena::RemoveAllSpawn() {
00057     while (spawnPoints.Len()){
00058         gSpawnPoint *s=spawnPoints(0);
00059         spawnPoints.Remove(s,s->id);
00060         delete s;
00061     }
00062 }
00063 
00064 gArena::~gArena()
00065 {
00066     // usually, we would write this:
00067     // RemoveAllSpawn();
00068 
00069     // but because of a bug in GCC version 3.3.5 to 3.4.x (4.0 is unaffected),
00070     // we have to dublicate the code of the function.
00071     while (spawnPoints.Len())
00072     {
00073         gSpawnPoint *s=spawnPoints(0);
00074         spawnPoints.Remove(s,s->id);
00075         delete s;
00076     }
00077 }
00078 
00079 bool init_grid_in_process;
00080 
00081 // from gGame.cpp
00082 void exit_game_objects(eGrid *grid);
00083 
00084 eCoord gArena::GetRandomPos(REAL factor) const
00085 {
00086     tRandomizer & randomizer = tReproducibleRandomizer::GetInstance();
00087     REAL x = randomizer.Get();
00088     REAL y = randomizer.Get();
00089     //  REAL x = REAL(rand())/RAND_MAX;
00090     //  REAL y = REAL(rand())/RAND_MAX;
00091 
00092     //    return eCoord( sizeMultiplier * 500.0 * ( x * factor + .5f * ( 1 - factor ) ), sizeMultiplier * 500.0 * ( y * factor + .5f * ( 1 - factor ) ) );
00093     return eWallRim::GetBounds().GetPoint( eCoord( x * factor + .5f * ( 1 - factor ), y * factor + .5f * ( 1 - factor ) ) );
00094 }
00095 
00096 void gArena::PrepareGrid(eGrid *grid, gParser *aParser)
00097 {
00098     RemoveAllSpawn();
00099 
00100     init_grid_in_process=true;
00101     grid->Create();
00102     grid->SetWinding(axes);
00103 
00104     aParser->setSizeMultiplier(sizeMultiplier);
00105     aParser->Parse();
00106 
00107     init_grid_in_process=false;
00108 
00109     int i;
00110     for(i=0;i<spawnPoints.Len();i++)
00111         spawnPoints(i)->Clear();
00112 
00113     // update arena bounds
00114     eWallRim::UpdateBounds();
00115 }
00116 
00117 // find the best gSpawnPoint
00118 gSpawnPoint * gArena::LeastDangerousSpawnPoint()
00119 {
00120     REAL mindanger=1E+30;
00121     gSpawnPoint *ret=NULL;
00122 
00123     for(int i=0;i<spawnPoints.Len();i++)
00124     {
00125         REAL newDanger = spawnPoints(i)->Danger();
00126         if (newDanger < mindanger - EPS )
00127         {
00128             ret = spawnPoints(i);
00129             mindanger = newDanger;
00130         }
00131     }
00132 
00133     if (!ret)
00134         tERR_ERROR("No spawnpoint available!");
00135 
00136 #ifdef DEBUG
00137     //  std::cout << "Spawn at " << ret->location << "\n";
00138 #endif
00139 
00140     return ret;
00141 }
00142 
00143 float gArena::SizeMultiplier()
00144 {
00145     return sizeMultiplier;
00146 }
00147 
00148 void gArena::SetSizeMultiplier(float mult)
00149 {
00150     conf_mult.Set( mult );
00151 }
00152 
00153 float gArena::GetSizeMultiplier()
00154 {
00155     return sizeMultiplier;
00156 }

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