Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

movementmanager.cpp

00001 /***************************************************************************
00002                           movementmanager.cpp  -  description
00003                              -------------------
00004     begin                : dim mai 16 2004
00005     modified             : sam jun 5  2004
00006     copyright            : (C) 2004 by Duong-Khang NGUYEN
00007     email                : neoneurone @ users sourceforge net
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   any later version.                                                    *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #include "movement.h"
00020 #include "movementmanager.h"
00021 
00022 #include "graphicmanager.h"
00023 
00024    /*=====================================================================*/
00025 MovementManager::MovementManager(
00026     const GraphicManager* gm,
00027     const Map* map):
00028 pcGraphicMgr( gm ),
00029 pcMap( map )
00030 {
00031     OPENCITY_DEBUG("ctor");
00032 
00033    // tab movement initialization
00034     for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
00035         tabmvt[ i ] = NULL;
00036     }
00037 }
00038 
00039 
00040    /*=====================================================================*/
00041 MovementManager::~MovementManager()
00042 {
00043     OPENCITY_DEBUG("dtor");
00044 
00045     for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
00046         delete tabmvt[ i ];
00047     }
00048 }
00049 
00050 
00051    /*=====================================================================*/
00052 const int
00053 MovementManager::Add(
00054     Movement* const pNew )
00055 {
00056     for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
00057         if (tabmvt[ i ] == NULL) {
00058             tabmvt[ i ] = pNew;
00059             return i;
00060         }
00061     }
00062 
00063     return -1;
00064 }
00065 
00066 
00067    /*=====================================================================*/
00068 void
00069 MovementManager::Remove(
00070     const int ciIndex )
00071 {
00072 // IF the user has specified the index of the element
00073 // THEN only remove that element
00074     if ((ciIndex > -1) && (ciIndex < OC_MOVEMENT_MAX )) {
00075         if (tabmvt[ ciIndex ] != NULL) {
00076             delete tabmvt[ ciIndex ];
00077             tabmvt[ ciIndex ] = NULL;
00078         }
00079         return;
00080     }
00081 
00082 // ELSE remove all the contained movement
00083     for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
00084         if (tabmvt[ i ] != NULL) {
00085             delete tabmvt[ i ];
00086             tabmvt[ i ] = NULL;
00087         }
00088     }
00089 }
00090 
00091 
00092    /*=====================================================================*/
00093 void
00094 MovementManager::Move(
00095     const int ciIndex )
00096 {
00097 // IF the user has specified the index of the element
00098 // THEN only call that element
00099     if ((ciIndex > -1) && (ciIndex < OC_MOVEMENT_MAX )) {
00100         if (tabmvt[ ciIndex ] != NULL)
00101         if (tabmvt[ ciIndex ]->Move() == false) {
00102             delete tabmvt[ ciIndex ];
00103             tabmvt[ ciIndex ] = NULL;
00104         }
00105         return;
00106     }
00107 
00108 // ELSE move all the contained movement
00109     for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
00110         if (tabmvt[ i ] != NULL)
00111         if (tabmvt[ i ]->Move() == false) {
00112             delete tabmvt[ i ];
00113             tabmvt[ i ] = NULL;
00114         }
00115     }
00116 }
00117 
00118 
00119    /*=====================================================================*/
00120 void
00121 MovementManager::Display(
00122     const int ciIndex )
00123 {
00124 // IF the user has specified the index of the element
00125 // THEN only call that element
00126     if ((ciIndex > -1) && (ciIndex < OC_MOVEMENT_MAX )) {
00127         if (tabmvt[ ciIndex ] != NULL)
00128             this->pcGraphicMgr->Display(
00129                 tabmvt[ ciIndex ]->_fCurrentW,
00130                 tabmvt[ ciIndex ]->_fCurrentL,
00131                 tabmvt[ ciIndex ]->_fCurrentH,
00132                 tabmvt[ ciIndex ] );
00133         return;
00134     }
00135 
00136 // ELSE display all the contained movement
00137     for (uint i = 0; i < OC_MOVEMENT_MAX; i++) {
00138         if (tabmvt[ i ] != NULL)
00139             this->pcGraphicMgr->Display(
00140                 tabmvt[ i ]->_fCurrentW,
00141                 tabmvt[ i ]->_fCurrentL,
00142                 tabmvt[ i ]->_fCurrentH,
00143                 tabmvt[ i ] );
00144     }
00145 }
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 

Generated on Sat Nov 11 10:21:10 2006 for OpenCity by  doxygen 1.4.2