00001 /*************************************************************************** 00002 autotraining.cpp - description 00003 ------------------- 00004 copyright : (C) 2009 by Martin Bickel 00005 email : bickel@asc-hq.org 00006 ***************************************************************************/ 00007 00012 /*************************************************************************** 00013 * * 00014 * This program is free software; you can redistribute it and/or modify * 00015 * it under the terms of the GNU General Public License as published by * 00016 * the Free Software Foundation; either version 2 of the License, or * 00017 * (at your option) any later version. * 00018 * * 00019 ***************************************************************************/ 00020 00021 00022 #include "player.h" 00023 #include "gamemap.h" 00024 00025 #include "actions/trainunitcommand.h" 00026 #include "actions/servicecommand.h" 00027 00028 static void autoTrainer( ContainerBase* container ) 00029 { 00030 for ( ContainerBase::Cargo::const_iterator i = container->getCargo().begin(); i != container->getCargo().end(); ++i ) { 00031 if ( TrainUnitCommand::avail( container, *i )) { 00032 Context context; 00033 context.gamemap = container->getMap(); 00034 context.actingPlayer = & (container->getMap()->getPlayer( container )); 00035 context.parentAction = NULL; 00036 context.display = NULL; 00037 context.viewingPlayer = container->getOwner(); 00038 context.actionContainer = &container->getMap()->actions; 00039 00040 auto_ptr<TrainUnitCommand> tuc ( new TrainUnitCommand( container )); 00041 tuc->setUnit( *i ); 00042 ActionResult res = tuc->execute( context ); 00043 00044 if ( res.successful()) 00045 tuc.release(); 00046 00047 00048 if ( ServiceCommand::avail( container, *i )) { 00049 auto_ptr<ServiceCommand> sc ( new ServiceCommand( container )); 00050 sc->setDestination( *i ); 00051 TransferHandler& tc = sc->getTransferHandler(); 00052 tc.fillDestAmmo(); 00053 sc->saveTransfers(); 00054 res = sc->execute( context ); 00055 if ( res.successful()) 00056 sc.release(); 00057 } 00058 } 00059 } 00060 } 00061 00062 void automaticTrainig( GameMap* gamemap, Player& player ) 00063 { 00064 for ( Player::BuildingList::iterator b = player.buildingList.begin(); b != player.buildingList.end(); ++b ) 00065 autoTrainer( *b ); 00066 00067 for ( Player::VehicleList::iterator v= player.vehicleList.begin(); v != player.vehicleList.end(); ++v ) 00068 autoTrainer( *v ); 00069 00070 }
1.5.1