Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

containerbase.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           containerbase.cpp  -  description
00003                              -------------------
00004     begin                : Fri Sep 29 2000
00005     copyright            : (C) 2003 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021 
00022 #include <algorithm>
00023 #include "typen.h"
00024 #include "containerbase.h"
00025 #include "vehicletype.h"
00026 #include "vehicle.h"
00027 #include "spfst.h"
00028 #include "graphics/blitter.h"
00029 #include "graphics/ColorTransform_PlayerColor.h"
00030 #include "containercontrols.h"
00031 #include "resourcenet.h"
00032 
00033 
00034 ContainerBase ::  ContainerBase ( const ContainerBaseType* bt, GameMap* map, int player ) : gamemap ( map ), cargoParent(NULL), baseType (bt)
00035 {
00036    damage = 0;
00037    color = player*8;
00038    maxresearchpoints = baseType->defaultMaxResearchpoints;
00039    researchpoints = min ( maxresearchpoints, baseType->nominalresearchpoints );
00040    maxplus = baseType->maxplus;
00041    
00042    for ( int i = 0; i < map->getVehicleTypeNum(); ++i ) {
00043       const Vehicletype* vt = map->getvehicletype_bypos(i);
00044       if ( vt ) 
00045          for ( int j = 0; j < bt->vehiclesInternallyProduceable.size(); ++j ) 
00046             if ( vt->id >= bt->vehiclesInternallyProduceable[j].from  && vt->id <= bt->vehiclesInternallyProduceable[j].to )
00047                internalUnitProduction.push_back ( vt ); 
00048    }
00049 }
00050 
00051 SigC::Signal1<void,ContainerBase*> ContainerBase :: anyContainerDestroyed;
00052 SigC::Signal1<void,ContainerBase*> ContainerBase :: anyContainerConquered;
00053 
00054 
00055 Resources ContainerBase :: putResource ( const Resources& res, bool queryonly, int scope, int player)
00056 {
00057    Resources result;
00058    for ( int i = 0; i < resourceNum; i++ )
00059       result.resource(i) = putResource ( res.resource(i), i , queryonly, scope, player );
00060    return result;
00061 }
00062 
00063 
00064 Resources ContainerBase :: getResource ( const Resources& res, bool queryonly, int scope, int player)
00065 {
00066    Resources result;
00067    for ( int i = 0; i < resourceNum; i++ )
00068       result.resource(i) = getResource ( res.resource(i), i , queryonly, scope, player );
00069    return result;
00070 }
00071 
00072 Resources ContainerBase :: getResource ( const Resources& res ) const
00073 {
00074    Resources result;
00075    for ( int i = 0; i < resourceNum; i++ )
00076       result.resource(i) = getAvailableResource ( res.resource(i), i );
00077    return result;
00078 }
00079 
00080 
00081 int ContainerBase :: repairItem   ( ContainerBase* item, int newDamage  )
00082 {
00083    if ( !canRepair( item ) )
00084       return item->damage;
00085 
00086    if ( item == this ) 
00087       if ( damage - repairableDamage() > newDamage )
00088          newDamage = damage - repairableDamage();
00089    
00090    int orgdam = item->damage;
00091 
00092    Resources cost;
00093    newDamage = getMaxRepair ( item, newDamage, cost );
00094    item->damage = newDamage;
00095    getResource ( cost, 0 );
00096 
00097    item->postRepair( orgdam );
00098 
00099    return newDamage;
00100 }
00101 
00102 int ContainerBase :: getMaxRepair ( const ContainerBase* item )
00103 {
00104    Resources res;
00105    return getMaxRepair ( item, 0, res );
00106 }
00107 
00108 int ContainerBase :: getMaxRepair ( const ContainerBase* item, int newDamage, Resources& cost, bool ignoreCost  )
00109 {
00110    if ( !canRepair( item ) )
00111       return item->damage;
00112 
00113    int i;
00114    if ( newDamage > item->damage )
00115       newDamage = item->damage;
00116 
00117    if ( item == this )
00118       if ( damage - repairableDamage() > newDamage )
00119          newDamage = damage - repairableDamage();
00120 
00121    int toRepair = item->damage - newDamage;
00122 
00123    Resources maxNeeded = getRepairEfficiency() * item->baseType->productionCost;
00124 
00125    Resources needed;
00126    for ( i = 0; i < resourceTypeNum; i++ )
00127       needed.resource(i) = maxNeeded.resource(i) * (item->damage-newDamage) / 100;
00128 
00129    if ( !ignoreCost ) {
00130       Resources avail = getResource ( needed, 1 );
00131    
00132       for ( i = 0; i < resourceTypeNum; i++ )
00133          if ( needed.resource(i) ) {
00134             int repairable = toRepair * avail.resource(i) / needed.resource(i);
00135             if ( item->damage - repairable > newDamage )
00136                newDamage = item->damage - repairable;
00137          }
00138    }
00139 
00140    for ( i = 0; i < resourceTypeNum; i++ )
00141       cost.resource(i) = maxNeeded.resource(i) * (item->damage-newDamage) / 100;
00142 
00143    return newDamage;
00144 }
00145 
00146 int ContainerBase :: vehiclesLoaded ( void ) const
00147 {
00148    int a = 0;
00149 
00150    for ( Cargo::const_iterator i = cargo.begin(); i != cargo.end(); ++i )
00151       if ( *i )
00152          ++a;
00153 
00154    return a;
00155 }
00156 
00157 
00158 int ContainerBase::cargoWeight() const
00159 {
00160    int w = 0;
00161    for ( Cargo::const_iterator i = cargo.begin(); i != cargo.end(); ++i )
00162       if ( *i )
00163          w += (*i)->weight();
00164 
00165    return w;
00166 }
00167 
00168 
00169 int ContainerBase :: cargoNestingDepth()
00170 {
00171    ContainerBase* cb = getCarrier();
00172    if ( cb )
00173       return cb->cargoNestingDepth() +1;
00174    else
00175       return 0;
00176 }
00177 
00178 
00179 
00180 ContainerBase* ContainerBase :: getCarrier() const
00181 {
00182    return cargoParent;
00183 }
00184 
00185 
00186 bool ContainerBase::unitLoaded( int nwid )
00187 {
00188    for ( Cargo::const_iterator i = cargo.begin(); i != cargo.end(); ++i )
00189       if ( *i ) {
00190          if ( (*i)->networkid == nwid )
00191             return true;
00192          else {
00193             if ( (*i)->unitLoaded( nwid ) )
00194                return true;
00195          }
00196       }
00197 
00198    return false;
00199 
00200 }
00201 
00202 Vehicle* ContainerBase :: findUnit ( int nwid ) const
00203 {
00204    for ( Cargo::const_iterator i = cargo.begin(); i != cargo.end(); ++i )
00205       if ( *i ) {
00206          if ( (*i)->networkid == nwid )
00207             return *i;
00208          else {
00209             Vehicle* cb = (*i)->findUnit( nwid );
00210             if ( cb )
00211                return cb;
00212          }
00213       }
00214 
00215    return NULL;
00216 }
00217 
00218 
00219 template<int pixelSize>
00220 class ColorTransform_UnitGray
00221 { }
00222 ;
00223 
00224 template<>
00225 class ColorTransform_UnitGray<1> : public ColorTransform_XLAT<1>
00226 {
00227    public:
00228       ColorTransform_UnitGray( NullParamType npt  = nullParam )
00229       {
00230          setTranslationTable( *xlatpictgraytable );
00231       };
00232 };
00233 
00234 template<>
00235 class ColorTransform_UnitGray<4> : public ColorTransform_Gray<4>
00236 {
00237    public:
00238       ColorTransform_UnitGray( NullParamType npt  = nullParam )
00239       {}
00240 }
00241 ;
00242 
00243 
00244 int ContainerBase::calcShadowDist( int binaryHeight )
00245 {
00246    if ( binaryHeight <= 1 )
00247       return 0;
00248 
00249    if ( binaryHeight <= 3 )
00250       return 1;
00251 
00252    return 6 * ( binaryHeight - log2 ( chfahrend ));
00253 }
00254 
00255 
00256 void ContainerBase::paintField ( const Surface& img, Surface& dest, SPoint pos, int dir, bool shaded, int shadowDist ) const
00257 {
00258 
00259    pair<const Surface*, int> dirpair = make_pair(&img, directionangle[dir]);
00260 
00261    int height = getHeight();
00262    if ( height <= chgetaucht ) {
00263       if ( shaded ) {
00264          megaBlitter< ColorTransform_UnitGray,
00265          ColorMerger_AlphaMixer,
00266          SourcePixelSelector_CacheRotation,
00267          TargetPixelSelector_All>
00268          ( img, dest, pos, nullParam,nullParam, dirpair, nullParam);
00269       } else {
00270          if ( img.GetPixelFormat().BytesPerPixel() == 1 ) {
00271             MegaBlitter<1,gamemapPixelSize,ColorTransform_PlayerCol, ColorMerger_AlphaMixer, SourcePixelSelector_CacheRotation> blitter;
00272             blitter.setPlayer( getOwner() );
00273             blitter.setAngle( img, directionangle[dir] );
00274             blitter.blit( img, dest, pos );
00275 
00276             /*
00277             megaBlitter< ColorTransform_PlayerCol,
00278             ColorMerger_AlphaMixer,
00279             SourcePixelSelector_CacheRotation,
00280             TargetPixelSelector_All>
00281             ( img, dest, pos, getOwner(),nullParam, dirpair, nullParam);
00282             */
00283          } else {
00284             MegaBlitter<4,gamemapPixelSize,ColorTransform_PlayerTrueCol, ColorMerger_AlphaMixer, SourcePixelSelector_CacheRotation> blitter;
00285             blitter.setColor( gamemap->player[getOwner()].getColor() );
00286             blitter.setAngle( img, directionangle[dir] );
00287             blitter.blit( img, dest, pos );
00288 
00289          }
00290       }
00291    } else {
00292       if ( height >= chfahrend && shadowDist ) {
00293          if ( shadowDist == -1 )
00294             shadowDist = calcShadowDist( log2( height ));
00295 
00296          megaBlitter< ColorTransform_None,
00297          ColorMerger_AlphaShadow,
00298          SourcePixelSelector_CacheRotation,
00299          TargetPixelSelector_All>
00300          ( img, dest, SPoint(pos.x+shadowDist, pos.y+shadowDist), nullParam,nullParam, dirpair, nullParam);
00301       }
00302 
00303       if ( shaded ) {
00304          megaBlitter< ColorTransform_UnitGray,
00305          ColorMerger_AlphaOverwrite,
00306          SourcePixelSelector_CacheRotation,
00307          TargetPixelSelector_All>
00308          ( img, dest, pos, nullParam,nullParam, dirpair, nullParam);
00309       } else {
00310          if ( img.GetPixelFormat().BytesPerPixel() == 1 ) {
00311             MegaBlitter<1,gamemapPixelSize,ColorTransform_PlayerCol, ColorMerger_AlphaOverwrite, SourcePixelSelector_CacheRotation> blitter;
00312             blitter.setPlayer( getOwner() );
00313             blitter.setAngle( img, directionangle[dir] );
00314             blitter.blit( img, dest, pos );
00315          } else {
00316             MegaBlitter<4,gamemapPixelSize,ColorTransform_PlayerTrueCol, ColorMerger_AlphaMerge, SourcePixelSelector_CacheRotation> blitter;
00317             // blitter.setPlayer( getOwner() );
00318             blitter.setColor( gamemap->player[getOwner()].getColor() );
00319             blitter.setAngle( img, directionangle[dir] );
00320             blitter.blit( img, dest, pos );
00321          }
00322       }
00323    }
00324 }
00325 
00326 
00327 void ContainerBase :: clearCargo()
00328 {
00329    while ( !cargo.empty() )
00330       if ( cargo.front() )
00331          delete cargo.front();
00332       else
00333          cargo.erase( cargo.begin() );
00334 
00335    cargoChanged();
00336 }
00337 
00338 
00339 void ContainerBase :: addToCargo( Vehicle* veh )
00340 {
00341    for ( Cargo::iterator i = cargo.begin(); i != cargo.end(); ++i )
00342       if ( ! (*i) ) {
00343          *i = veh;
00344          veh->cargoParent = this;
00345          return;
00346       }
00347 
00348    cargo.push_back( veh );
00349    veh->cargoParent = this;
00350    veh->setnewposition(getPosition());
00351    cargoChanged();
00352 }
00353 
00354 bool ContainerBase :: removeUnitFromCargo( Vehicle* veh, bool recursive )
00355 {
00356    if ( !veh )
00357       return false;
00358    else {
00359       if ( removeUnitFromCargo( veh->networkid, recursive )) {
00360          cargoChanged();
00361          return true;
00362       } else
00363          return false;
00364    }
00365 }
00366 
00367 bool ContainerBase :: removeUnitFromCargo( int nwid, bool recursive )
00368 {
00369    for ( Cargo::iterator i = cargo.begin(); i != cargo.end(); ++i )
00370       if ( *i ) {
00371          if ( (*i)->networkid == nwid ) {
00372             (*i)->cargoParent = NULL;
00373             *i = NULL;
00374             cargoChanged();
00375             return true;
00376          }
00377          if ( recursive )
00378             if ( (*i)->removeUnitFromCargo( nwid, recursive ))
00379                return true;
00380       }
00381 
00382    return false;
00383 }
00384 
00385 bool ContainerBase :: canCarryWeight( int additionalWeight ) const
00386 {
00387    if ( cargoWeight() + additionalWeight > baseType->maxLoadableWeight )
00388       return false;
00389    else
00390       if ( getCarrier() )
00391          return getCarrier()->canCarryWeight( additionalWeight );
00392       else
00393          return true;
00394 }
00395 
00396 
00397 bool ContainerBase :: vehicleFit ( const Vehicle* vehicle ) const
00398 {
00399    bool isConquering = isBuilding() && getMap()->getPlayer(this).diplomacy.isHostile( vehicle) && vehicle->color != color;
00400    if ( baseType->vehicleFit ( vehicle->typ )) // checks size and type
00401       if ( vehiclesLoaded() < baseType->maxLoadableUnits || isConquering )
00402          if ( canCarryWeight( vehicle->weight() ) || findUnit ( vehicle->networkid ) || isConquering) // if the unit is already  loaded, the container already bears its weight
00403             return true;
00404 
00405    return false;
00406 }
00407 
00408 
00409 bool  ContainerBase :: vehicleLoadable ( const Vehicle* vehicle, int uheight, const bool* attacked ) const
00410 {
00411    if ( vehicle->attacked )
00412       return false;
00413 
00414    bool hasAttacked = vehicle->attacked;
00415    if ( attacked )
00416       hasAttacked = *attacked;
00417 
00418    if ( uheight == -1 )
00419       uheight = vehicle->height;
00420 
00421    if ( vehicleFit ( vehicle ))
00422       for ( ContainerBaseType::EntranceSystems::const_iterator i = baseType->entranceSystems.begin(); i != baseType->entranceSystems.end(); i++ )
00423          if ( (i->height_abs & uheight) || (i->height_abs == 0 ))
00424             if ( i->mode & ContainerBaseType::TransportationIO::In )
00425                if ( i->height_rel == -100 || i->height_rel == getheightdelta ( getPosition().getNumericalHeight(), log2(uheight)  ) )
00426                   if ( (i->container_height & getPosition().getBitmappedHeight()) || (i->container_height == 0))
00427                      if ( vehicle->typ->hasAnyFunction(i->requiresUnitFeature) || i->requiresUnitFeature.none() )
00428                         if ( i->vehicleCategoriesLoadable & (1<<vehicle->typ->movemalustyp)) {
00429                            if ( getMap()->getPlayer(this).diplomacy.isAllied( vehicle->getOwner()) ) 
00430                               return true;
00431 
00432                            if ( isBuilding() ) {
00433                               if ( !hasAttacked ) {
00434                                  if ( getOwner() == 8 )
00435                                     return true;
00436                                  if ( gamemap->getPlayer(this).diplomacy.isHostile( vehicle->getOwner())  )
00437                                     if (damage >= mingebaeudeeroberungsbeschaedigung  || vehicle->typ->hasFunction( ContainerBaseType::ConquerBuildings ) )
00438                                        return true;
00439                               }
00440                            }
00441                         }
00442    return false;
00443 }
00444 
00445 int  ContainerBase :: vehicleUnloadable ( const Vehicletype* vehicleType ) const
00446 {
00447    int height = 0;
00448 
00449    if ( baseType->vehicleFit ( vehicleType ))
00450       for ( ContainerBaseType::EntranceSystems::const_iterator i = baseType->entranceSystems.begin(); i != baseType->entranceSystems.end(); i++ )
00451          if ( i->mode & ContainerBaseType::TransportationIO::Out )
00452             if ( (i->container_height & getPosition().getBitmappedHeight()) || (i->container_height == 0))
00453                if ( i->vehicleCategoriesLoadable & (1<<vehicleType->movemalustyp))
00454                   if ( vehicleType->hasAnyFunction(i->requiresUnitFeature) || i->requiresUnitFeature.none() )
00455                      if ( i->height_abs != 0 && i->height_rel != -100 ) {
00456                         int h = 0;
00457                         for ( int hh = 0; hh < 8; ++hh)
00458                            if ( getheightdelta(getPosition().getNumericalHeight(), hh) == i->height_rel )
00459                               h += 1 << hh;
00460                         height |= i->height_abs & h;
00461                      } else
00462                         if ( i->height_rel != -100 )
00463                            height |= 1 << (getPosition().getNumericalHeight() + i->height_rel) ;
00464                         else
00465                            height |= i->height_abs ;
00466    return height & vehicleType->height;
00467 }
00468 
00469 const ContainerBaseType::TransportationIO* ContainerBase::vehicleUnloadSystem ( const Vehicletype* vehicleType, int height )
00470 {
00471    if ( baseType->vehicleFit ( vehicleType ))
00472       for ( ContainerBaseType::EntranceSystems::const_iterator i = baseType->entranceSystems.begin(); i != baseType->entranceSystems.end(); i++ )
00473          if ( i->mode & ContainerBaseType::TransportationIO::Out )
00474             if ( (i->container_height & getPosition().getBitmappedHeight()) || (i->container_height == 0))
00475                if ( i->vehicleCategoriesLoadable & (1<<vehicleType->movemalustyp))
00476                   if ( vehicleType->hasAnyFunction(i->requiresUnitFeature) || i->requiresUnitFeature.none() )
00477                      if ( i->height_abs != 0 && i->height_rel != -100 ) {
00478                         if ( height & ( i->height_abs & (1 << (getPosition().getNumericalHeight() + i->height_rel ))))
00479                            return &(*i);
00480                      } else
00481                         if ( i->height_rel != -100 ) {
00482                            if ( height & ( 1 << (getPosition().getNumericalHeight() + i->height_rel)))
00483                               return &(*i);
00484                         } else
00485                            if ( height & i->height_abs )
00486                               return &(*i);
00487    return NULL;
00488 
00489 }
00490 
00491 int  ContainerBase :: vehicleDocking ( const Vehicle* vehicle, bool out ) const
00492 {
00493    if ( vehicle == this )
00494       return 0;
00495 
00496    int height = 0;
00497 
00498    if ( baseType->vehicleFit ( vehicle->typ ) && ( vehicleFit( vehicle ) || out ) )
00499       for ( ContainerBaseType::EntranceSystems::const_iterator i = baseType->entranceSystems.begin(); i != baseType->entranceSystems.end(); i++ )
00500          if ( i->mode & ContainerBaseType::TransportationIO::Docking )
00501             if ( (i->container_height & getPosition().getBitmappedHeight()) || (i->container_height == 0))
00502                if ( i->vehicleCategoriesLoadable & (1<<vehicle->typ->movemalustyp))
00503                   if ( i->dockingHeight_abs != 0 && i->dockingHeight_rel != -100 )
00504                      height |= i->dockingHeight_abs & (1 << (getPosition().getNumericalHeight() + i->dockingHeight_rel ));
00505                   else
00506                      if ( i->dockingHeight_rel != -100 )
00507                         height |= 1 << (getPosition().getNumericalHeight() + i->dockingHeight_rel) ;
00508                      else
00509                         height |= i->dockingHeight_abs ;
00510    return height;
00511 }
00512 
00513 const ContainerBase::Production& ContainerBase::getProduction() const
00514 {
00515    if ( productionCache.empty() && !internalUnitProduction.empty() ) {
00516       for ( Production::const_iterator i = internalUnitProduction.begin(); i != internalUnitProduction.end(); ++i )
00517          if ( vehicleUnloadable( *i ) || baseType->hasFunction( ContainerBaseType::ProduceNonLeavableUnits ) )
00518             productionCache.push_back ( *i );
00519    }
00520 
00521    return productionCache;
00522 }
00523 
00524 Resources ContainerBase::getProductionCost( const Vehicletype* unit ) const
00525 {
00526    return baseType->productionEfficiency * unit->productionCost;
00527 }
00528 
00529 
00530 void ContainerBase ::deleteProductionLine( const Vehicletype* type )
00531 {
00532    internalUnitProduction.erase( remove( internalUnitProduction.begin(), internalUnitProduction.end(), type ), internalUnitProduction.end());
00533    productionCache.clear();
00534 }
00535 
00536 void ContainerBase ::deleteAllProductionLines()
00537 {
00538    internalUnitProduction.clear();
00539    productionCache.clear();
00540 }
00541 
00542 void ContainerBase :: addProductionLine( const Vehicletype* type )
00543 {
00544    if ( find ( internalUnitProduction.begin(), internalUnitProduction.end(), type ) == internalUnitProduction.end() )
00545       internalUnitProduction.push_back( type );
00546    productionCache.clear();
00547 }
00548 
00549 void ContainerBase :: setProductionLines( const Production& production  )
00550 {
00551    internalUnitProduction = production;
00552    productionCache.clear();
00553 }
00554 
00555 
00556 ContainerBase :: ~ContainerBase ( )
00557 {
00558    for ( Cargo::iterator i = cargo.begin(); i != cargo.end(); ++i )
00559       if ( *i )
00560          delete *i;
00561 
00562    if ( gamemap->state != GameMap::Destruction ) {
00563       destroyed();
00564       anyContainerDestroyed( this );
00565    }
00566 }
00567 
00568 
00569 TemporaryContainerStorage :: TemporaryContainerStorage ( ContainerBase* _cb, bool storeCargo )
00570 {
00571    cb = _cb;
00572    tmemorystream stream ( &buf, tnstream::writing );
00573    cb->write ( stream, storeCargo );
00574    _storeCargo = storeCargo;
00575 }
00576 
00577 void TemporaryContainerStorage :: restore (  )
00578 {
00579    if ( _storeCargo ) {
00580       cb->clearCargo();
00581    }
00582 
00583    tmemorystream stream ( &buf, tnstream::reading );
00584    cb->read ( stream );
00585 }
00586 
00587 
00588 
00589 
00590 
00591 
00592 void ContainerBase::endOwnTurn( void )
00593 {
00594 #ifndef karteneditor
00595    if ( baseType->hasFunction( ContainerBaseType::TrainingCenter  ) ) {
00596       for ( Cargo::iterator i = cargo.begin(); i != cargo.end(); ++i )
00597          if ( *i ) {
00598             /*
00599             bool ammoFull = true;
00600             for ( int w = 0; w < (*i)->typ->weapons.count; ++w )
00601                if ( (*i)->ammo[w] < (*i)->typ->weapons.weapon[w].count )
00602                   ammoFull = false;
00603 
00604             if ( ammoFull ) {
00605             */
00606                ContainerControls cc ( this );
00607                if ( cc.unitTrainingAvailable( *i )) {
00608                   cc.trainUnit( *i );
00609                   cc.refillAmmo ( *i );
00610                }
00611             // }
00612          }
00613    }
00614 #endif
00615 }
00616 
00617 void ContainerBase::endAnyTurn( void )
00618 {
00619 }
00620 
00621 void ContainerBase::endRound ( void )
00622 {
00623 }
00624 
00625 
00626 
00627 Resources ContainerBase ::netResourcePlus( ) const
00628 {
00629    Resources res;
00630    for ( int resourcetype = 0; resourcetype < resourceTypeNum; resourcetype++ ) {
00631       GetResourcePlus grp ( getMap() );
00632       res.resource(resourcetype) += grp.getresource ( getPosition().x, getPosition().y, resourcetype, color/8, 1 );
00633    }
00634    return res;
00635 }
00636 
00637 
00638 
00639 Player& ContainerBase :: getOwningPlayer() const 
00640 { 
00641    return getMap()->getPlayer(this); 
00642 }
00643 
00644 
00645 
00646 Resources ContainerBase :: getResourcePlus( )
00647 {
00648    Work* w = spawnWorkClasses ( true );
00649    Resources r;
00650    if ( w )
00651       r = w->getPlus();
00652    delete w;
00653 
00654    //  printf ("building %s %d / %d : plus %d %d %d \n", typ->name.c_str(), getPosition().x, getPosition().y, r.energy, r.material, r.fuel );
00655 
00656    return r;
00657 }
00658 
00659 Resources ContainerBase :: getResourceUsage( )
00660 {
00661    Work* w = spawnWorkClasses ( true );
00662    Resources r;
00663    if ( w )
00664       r = w->getUsage();
00665    delete w;
00666 
00667    if ( baseType->hasFunction( ContainerBaseType::Research ) )
00668       r += returnResourcenUseForResearch( this, researchpoints );
00669 
00670 
00671    return r;
00672 }
00673 
00674 Resources ContainerBase::getStorageCapacity() const
00675 {
00676    if ( gamemap && gamemap->_resourcemode == 1 && isBuilding() )
00677       return baseType->getStorageCapacity( 1 );
00678    else
00679       return baseType->getStorageCapacity( 0 );
00680 }
00681 
00682 
00683 
00684 
00685 bool ContainerBase::registerWorkClassFactory( WorkClassFactory* wcf, bool ASCmode )
00686 {
00687    if ( ASCmode )  {
00688       if ( !workClassFactoriesASC )
00689          workClassFactoriesASC = new WorkerClassList;
00690       
00691       workClassFactoriesASC->push_back( wcf );
00692    } else {
00693       if ( !workClassFactoriesBI )
00694          workClassFactoriesBI = new WorkerClassList;
00695       
00696       workClassFactoriesBI->push_back( wcf );
00697    }
00698    return true;
00699 }
00700 
00701 ContainerBase::WorkerClassList* ContainerBase::workClassFactoriesASC = NULL;
00702 ContainerBase::WorkerClassList* ContainerBase::workClassFactoriesBI = NULL;
00703 
00704 
00705 ContainerBase ::Work* ContainerBase ::spawnWorkClasses( bool justQuery )
00706 {
00707    if ( getMap()->_resourcemode != 1 ) {
00708       for ( WorkerClassList::iterator i = workClassFactoriesASC->begin(); i != workClassFactoriesASC->end(); ++i )
00709          if ( (*i)->available( this ) )
00710             return (*i)->produce(this, justQuery);
00711    } else {
00712       for ( WorkerClassList::iterator i = workClassFactoriesBI->begin(); i != workClassFactoriesBI->end(); ++i )
00713          if ( (*i)->available( this ) )
00714             return (*i)->produce(this, justQuery);
00715    }
00716    return NULL;
00717 }
00718 
00719 
00720 

Generated on Tue Jun 24 01:27:37 2008 for Advanced Strategic Command by  doxygen 1.4.2