src/object/objects_list.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 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  * Liste des objets qui sont sur le plateau de jeu.
00020  *****************************************************************************/
00021 
00022 #include "../object/objects_list.h"
00023 //-----------------------------------------------------------------------------
00024 #include "barrel.h"
00025 #include "../include/app.h"
00026 #include "../game/game_loop.h"
00027 #include "../map/map.h"
00028 #include "../map/maps_list.h"
00029 #include "../map/camera.h"
00030 #include "../tool/debug.h"
00031 #include "../tool/random.h"
00032 #include "../tool/rectangle.h"
00033 #include "../game/time.h"
00034 #include "../weapon/mine.h"
00035 #include <vector>
00036 #include <iostream>
00037 
00038 //-----------------------------------------------------------------------------
00039 ObjectsList lst_objects;
00040 //-----------------------------------------------------------------------------
00041 
00042 // Initialise la liste des objets standards
00043 void ObjectsList::PlaceMines()
00044 {
00045   MSG_DEBUG("lst_objects","Placing mines");
00046   for (uint i=0; i<ActiveMap().GetNbMine(); ++i)
00047   {
00048     ObjMine *obj = new ObjMine(*MineConfig::GetInstance());
00049 
00050     if (obj->PutRandomly(false, MineConfig::GetInstance()->detection_range * PIXEL_PER_METER *1.5 ))
00051       // detection range is in meter
00052       push_back(obj);
00053     else
00054       delete obj;
00055   }
00056 }
00057 
00058 void ObjectsList::PlaceBarrels()
00059 {
00060   MSG_DEBUG("lst_objects","Placing barrels");
00061   for (uint i= 0; i<ActiveMap().GetNbBarrel(); ++i)
00062   {
00063     PetrolBarrel *obj = new PetrolBarrel();
00064 
00065     if (obj->PutRandomly(false, 20.0))
00066       push_back(obj);
00067     else
00068       delete obj;
00069   }
00070 }
00071 
00072 
00073 ObjectsList::~ObjectsList()
00074 {
00075   FreeMem();
00076 }
00077 
00078 //-----------------------------------------------------------------------------
00079 void ObjectsList::Refresh()
00080 {
00081   ObjectsList::iterator object=begin();
00082 
00083   while(object != end())
00084   {
00085     (*object)->UpdatePosition();
00086     (*object)->Refresh();
00087     if((*object)->IsGhost())
00088       object = lst_objects.erase(object);
00089     else
00090       object++;
00091   }
00092 }
00093 
00094 //-----------------------------------------------------------------------------
00095 void ObjectsList::Draw()
00096 {
00097   for (ObjectsList::iterator it = begin();
00098        it != end();
00099        ++it)
00100   {
00101     assert((*it) != NULL);
00102     if(Time::GetInstance()->IsGamePaused())
00103     {
00104       MSG_DEBUG("lst_objects","Displaying %s",(*it)->GetName().c_str());
00105     }
00106     if (!(*it)->IsGhost())
00107       (*it)->Draw();
00108   }
00109 }
00110 
00111 //-----------------------------------------------------------------------------
00112 bool ObjectsList::AllReady()
00113 {
00114   FOR_EACH_OBJECT(object)
00115   {
00116     if (!(*object)->IsImmobile())
00117     {
00118       MSG_DEBUG("lst_objects", "\"%s\" is not ready ( IsImmobile()==fasle )", (*object)->GetName().c_str());
00119       return false;
00120     }
00121   }
00122   return true;
00123 }
00124 
00125 //-----------------------------------------------------------------------------
00126 
00127 void ObjectsList::FreeMem()
00128 {
00129   MSG_DEBUG("lst_objects", "Erasing object list");
00130   ObjectsList::iterator object;
00131   for (object = begin();
00132        object != end();
00133        ++object) {
00134     if((*object))
00135       delete (*object);
00136   }
00137   clear();
00138 }
00139 

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