commands.cpp

Go to the documentation of this file.
00001 
00007 /*
00008      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00009      Copyright (C) 1994-2010  Martin Bickel  
00010 
00011      This program is free software; you can redistribute it and/or modify
00012      it under the terms of the GNU General Public License as published by
00013      the Free Software Foundation; either version 2 of the License, or
00014      (at your option) any later version.
00015 
00016      This program is distributed in the hope that it will be useful,
00017      but WITHOUT ANY WARRANTY; without even the implied warranty of
00018      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019      GNU General Public License for more details.
00020 
00021      You should have received a copy of the GNU General Public License
00022      along with this program; see the file COPYING. If not, write to the
00023      Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00024      Boston, MA  02111-1307  USA
00025 */
00026 
00027 
00028 #include "../sg.h"
00029 #include "../ascstring.h"
00030 #include "../vehicle.h"
00031 #include "../gamemap.h"
00032 #include "../spfst.h"
00033 #include "../spfst-legacy.h"
00034 #include "../itemrepository.h"
00035 
00036 #include "../turncontrol.h"
00037 #include "../pg_mapdisplay.h"
00038                
00039 #include "../actions/attackcommand.h"
00040 #include "../actions/moveunitcommand.h"
00041 #include "../actions/putminecommand.h"
00042 #include "../actions/putobjectcommand.h"
00043 #include "../actions/destructbuildingcommand.h"
00044 #include "../actions/transfercontrolcommand.h"
00045 #include "../actions/trainunitcommand.h"
00046 #include "../actions/constructunitcommand.h"
00047 #include "../actions/constructbuildingcommand.h"
00048 #include "../actions/servicecommand.h"
00049 #include "../actions/repairunitcommand.h"
00050 #include "../actions/reactionfireswitchcommand.h"
00051 #include "../actions/jumpdrivecommand.h"
00052 #include "../actions/destructunitcommand.h"
00053 #include "../actions/recycleunitcommand.h"
00054 #include "../actions/buildproductionlinecommand.h"
00055 #include "../actions/removeproductionlinecommand.h"
00056 #include "../actions/powergenerationswitchcommand.h"
00057 #include "../actions/repairbuildingcommand.h"
00058 #include "../actions/setresourceprocessingratecommand.h"
00059 #include "../actions/cargomovecommand.h"
00060 #include "../actions/diplomacycommand.h"
00061 #include "../actions/cancelresearchcommand.h"
00062 #include "../actions/directresearchcommand.h"
00063 #include "../actions/renamecontainercommand.h"
00064 
00065 GameMap* loadGameLua( const char* filename )
00066 {
00067    loadGameFromFile( filename );  
00068    repaintMap();
00069    return actmap;
00070 }
00071          
00072 ActionResult unitAttack( GameMap* actmap, int veh, const MapCoordinate& target, int weapon )
00073 {
00074    if ( !actmap )
00075       return ActionResult( 23500 );
00076    
00077    Vehicle* unit = actmap->getUnit( veh );
00078    if ( !unit  )
00079       return ActionResult(120);
00080    
00081    if ( !AttackCommand::avail( unit ))   
00082       return ActionResult(202);
00083    
00084    auto_ptr<AttackCommand> ac( new AttackCommand(unit) );
00085    ac->setTarget( target, weapon);
00086    ActionResult res = ac->execute( createContext( actmap ) );
00087    if ( res.successful() ) 
00088       ac.release();
00089       
00090    return res;
00091 }
00092          
00093          
00094 ActionResult unitMovement( GameMap* actmap, int unitID, const MapCoordinate& destination, int destinationHeigth )
00095 {
00096    if ( !actmap )
00097       return ActionResult( 23500 );
00098    
00099    Vehicle* unit = actmap->getUnit( unitID );
00100    if ( !unit )
00101       return ActionResult(120);
00102    
00103    if ( !MoveUnitCommand::avail( unit ))   
00104       return ActionResult(23411);
00105    
00106    auto_ptr<MoveUnitCommand> ac( new MoveUnitCommand(unit) );
00107    if ( destinationHeigth < 0 )
00108       ac->setDestination( destination );
00109    else
00110       ac->setDestination( MapCoordinate3D( destination, 1 << destinationHeigth ));
00111    ActionResult res = ac->execute( createContext( actmap ) );
00112    if ( res.successful() ) 
00113       ac.release();
00114    
00115    return res;
00116 }
00117          
00118 ActionResult unitMovement( GameMap* actmap, int unitID, const MapCoordinate& destination )
00119 {
00120    return unitMovement( actmap, unitID, destination, -1 );
00121 }
00122 
00123 ActionResult putMineFunc( GameMap* actmap, int veh, const MapCoordinate& destination, int mineType )
00124 {
00125    if ( !actmap )
00126       return ActionResult( 23500 );
00127    
00128    Vehicle* unit = actmap->getUnit( veh );
00129    if ( !unit )
00130       return ActionResult(120);
00131    
00132    if ( !PutMineCommand::avail( unit ))   
00133       return ActionResult(23411);
00134    
00135    auto_ptr<PutMineCommand> ac( new PutMineCommand(unit) );
00136    ac->setCreationTarget( destination, (MineTypes)mineType );
00137    ActionResult res = ac->execute( createContext( actmap ) );
00138    if ( res.successful() ) 
00139       ac.release();
00140    
00141    return res;
00142 }
00143 
00144 ActionResult removeMineFunc( GameMap* actmap, int veh, const MapCoordinate& destination )
00145 {
00146    if ( !actmap )
00147       return ActionResult( 23500 );
00148    
00149    Vehicle* unit = actmap->getUnit( veh );
00150    if ( !unit )
00151       return ActionResult(120);
00152    
00153    if ( !PutMineCommand::avail( unit ))   
00154       return ActionResult(23411);
00155    
00156    auto_ptr<PutMineCommand> ac( new PutMineCommand(unit) );
00157    ac->setRemovalTarget( destination );
00158    ActionResult res = ac->execute( createContext( actmap ) );
00159    if ( res.successful() ) 
00160       ac.release();
00161    
00162    return res;
00163 }
00164 
00165 
00166 
00167 ActionResult unitPutObject( GameMap* actmap, int veh, const MapCoordinate& destination, int objectID )
00168 {
00169    if ( !actmap )
00170       return ActionResult( 23500 );
00171    
00172    Vehicle* unit = actmap->getUnit( veh );
00173    if ( !unit )
00174       return ActionResult(120);
00175    
00176    if ( !PutObjectCommand::avail( unit ))   
00177       return ActionResult(23411);
00178    
00179    auto_ptr<PutObjectCommand> ac( new PutObjectCommand(unit) );
00180    ac->setTarget( destination, objectID );
00181    ActionResult res = ac->execute( createContext( actmap ) );
00182    if ( res.successful() ) 
00183       ac.release();
00184    
00185    return res;
00186 }
00187 
00188 ActionResult unitRemoveObject( GameMap* actmap, int veh, const MapCoordinate& destination, int objectID )
00189 {
00190    return unitPutObject( actmap, veh, destination, objectID );
00191 }
00192 
00193 
00194 ActionResult unitDestructBuilding( GameMap* actmap, int veh, const MapCoordinate& destination )
00195 {
00196    if ( !actmap )
00197       return ActionResult( 23500 );
00198    
00199    Vehicle* unit = actmap->getUnit( veh );
00200    if ( !unit )
00201       return ActionResult(120);
00202    
00203    if ( !DestructBuildingCommand::avail( unit ))   
00204       return ActionResult(23411);
00205    
00206    auto_ptr<DestructBuildingCommand> ac( new DestructBuildingCommand(unit) );
00207    ac->setTargetPosition( destination );
00208    ActionResult res = ac->execute( createContext( actmap ) );
00209    if ( res.successful() ) 
00210       ac.release();
00211    
00212    return res;
00213 }
00214 
00215 ActionResult transferControl( GameMap* actmap, int containerID, int newOwner )
00216 {
00217    if ( !actmap )
00218       return ActionResult( 23500 );
00219    
00220    ContainerBase* c = actmap->getContainer( containerID);
00221    if ( !c )
00222       return ActionResult(23410);
00223    
00224    if ( !TransferControlCommand::avail( c ))   
00225       return ActionResult(23411);
00226    
00227    if ( newOwner < 0 || newOwner > 7 )
00228       return ActionResult(22801);
00229    
00230    
00231    auto_ptr<TransferControlCommand> ac( new TransferControlCommand(c) );
00232    ac->setReceiver( &actmap->getPlayer( newOwner) );
00233    ActionResult res = ac->execute( createContext( actmap ) );
00234    if ( res.successful() ) 
00235       ac.release();
00236    
00237    return res;
00238 }
00239 
00240 ActionResult trainUnit( GameMap* actmap, int containerID, int unitID )
00241 {
00242    if ( !actmap )
00243       return ActionResult( 23500 );
00244    
00245    ContainerBase* c = actmap->getContainer( containerID);
00246    if ( !c )
00247       return ActionResult(23410);
00248      
00249    Vehicle* v = actmap->getUnit( unitID );
00250    if ( !v )
00251       return ActionResult( 21001 );
00252    
00253    if ( !TrainUnitCommand::avail( c, v ))   
00254       return ActionResult(23411);
00255    
00256    
00257    auto_ptr<TrainUnitCommand> ac( new TrainUnitCommand(c) );
00258    ac->setUnit( v );
00259    ActionResult res = ac->execute( createContext( actmap ) );
00260    if ( res.successful() ) 
00261       ac.release();
00262    
00263    return res;
00264 }
00265 
00266 ActionResult constructUnit( GameMap* actmap, int containerID, const MapCoordinate& position, int unitID )
00267 {
00268    if ( !actmap )
00269       return ActionResult( 23500 );
00270    
00271    ContainerBase* c = actmap->getContainer( containerID );
00272    if ( !c )
00273       return ActionResult(23410);
00274      
00275    VehicleType* v = vehicleTypeRepository.getObject_byID( unitID );
00276    if ( !v )
00277       return ActionResult( 21701 );
00278    
00279    if ( !ConstructUnitCommand::avail( c ))   
00280       return ActionResult(23411);
00281    
00282    
00283    auto_ptr<ConstructUnitCommand> ac( new ConstructUnitCommand(c) );
00284    ac->setVehicleType( v );
00285    
00286    if ( position.valid() ) {
00287       if ( position != c->getPosition())
00288          ac->setMode( ConstructUnitCommand::external );
00289       else
00290          ac->setMode( ConstructUnitCommand::internal );
00291       
00292       ac->setTargetPosition( position );
00293    } else
00294       ac->setMode( ConstructUnitCommand::internal );
00295    
00296    ActionResult res = ac->execute( createContext( actmap ) );
00297    if ( res.successful() ) 
00298       ac.release();
00299    
00300    return res;
00301 }
00302 
00303 
00304 ActionResult constructBuilding( GameMap* actmap, int unitID, const MapCoordinate& position, int buildingTypeID )
00305 {
00306    if ( !actmap )
00307       return ActionResult( 23500 );
00308    
00309    Vehicle* unit = actmap->getUnit( unitID );
00310    if ( !unit )
00311       return ActionResult(120);
00312    
00313    if ( !ConstructBuildingCommand::avail( unit ))   
00314       return ActionResult(23411);
00315      
00316    BuildingType* v = buildingTypeRepository.getObject_byID( buildingTypeID );
00317    if ( !v )
00318       return ActionResult( 21701 );
00319    
00320   
00321    auto_ptr<ConstructBuildingCommand> ac( new ConstructBuildingCommand(unit) );
00322    ac->setBuildingType( v );
00323    ac->setTargetPosition( position );
00324 
00325    ActionResult res = ac->execute( createContext( actmap ) );
00326    if ( res.successful() ) 
00327       ac.release();
00328 
00329    return res;
00330 }
00331 
00332 ActionResult serviceCommand( GameMap* actmap, int providingContainerID, int receivingContainerID, int type, int amount )
00333 {
00334    if ( !actmap )
00335       return ActionResult( 23500 );
00336    
00337    ContainerBase* pro = actmap->getContainer( providingContainerID );
00338    ContainerBase* rec = actmap->getContainer( receivingContainerID );
00339    if ( !pro || !rec )
00340       return ActionResult(23410);
00341    
00342    auto_ptr<ServiceCommand> ac( new ServiceCommand(pro) );
00343    ac->setDestination( rec );
00344    
00345    TransferHandler::Transfers& transfers = ac->getTransferHandler().getTransfers();
00346    
00347    for ( TransferHandler::Transfers::iterator i = transfers.begin(); i != transfers.end(); ++i )
00348       if ( (*i)->getID() == type )
00349          (*i)->setAmount( rec, amount );
00350    
00351    if ( transfers.size() > 0 ) {
00352       ac->saveTransfers();
00353       ActionResult res = ac->execute( createContext( actmap ) );
00354       if ( res.successful() ) 
00355          ac.release();
00356    
00357       return res;
00358    } else {
00359       return ActionResult(23301);  
00360    }
00361 }
00362 
00363 ActionResult repairUnit( GameMap* actmap, int repairerID, int damagedUnitID )
00364 {
00365    if ( !actmap )
00366       return ActionResult( 23500 );
00367    
00368    ContainerBase* c = actmap->getContainer( repairerID);
00369    if ( !c )
00370       return ActionResult(23410);
00371      
00372    Vehicle* v = actmap->getUnit( damagedUnitID );
00373    if ( !v )
00374       return ActionResult( 21001 );
00375    
00376    if ( !RepairUnitCommand::avail( c ))   
00377       return ActionResult(23411);
00378    
00379    
00380    auto_ptr<RepairUnitCommand> ac( new RepairUnitCommand(c) );
00381    ac->setTarget( v );
00382    ActionResult res = ac->execute( createContext( actmap ) );
00383    if ( res.successful() ) 
00384       ac.release();
00385    
00386    return res;
00387 }
00388 
00389 ActionResult unitReactionFireEnable( GameMap* actmap, int unitID, bool enabled )
00390 {
00391    if ( !actmap )
00392       return ActionResult( 23500 );
00393    
00394    Vehicle* unit = actmap->getUnit( unitID );
00395    if ( !unit )
00396       return ActionResult(120);
00397    
00398    if ( !ReactionFireSwitchCommand::avail( unit, enabled ))   
00399       return ActionResult(23411);
00400    
00401    auto_ptr<ReactionFireSwitchCommand> ac( new ReactionFireSwitchCommand(unit) );
00402    ac->setNewState( enabled );
00403    ActionResult res = ac->execute( createContext( actmap ) );
00404    if ( res.successful() ) 
00405       ac.release();
00406    
00407    return res;
00408 }
00409 
00410 ActionResult unitPowerGenerationEnable( GameMap* actmap, int unitID, int enabled )
00411 {
00412    if ( !actmap )
00413       return ActionResult( 23500 );
00414    
00415    Vehicle* unit = actmap->getUnit( unitID );
00416    if ( !unit )
00417       return ActionResult(120);
00418 
00419    if ( !PowerGenerationSwitchCommand::avail( unit, enabled ))   
00420       return ActionResult(23411);
00421 
00422    auto_ptr<PowerGenerationSwitchCommand> ac( new PowerGenerationSwitchCommand(unit) );
00423    ac->setNewState( enabled );
00424    ActionResult res = ac->execute( createContext( actmap ) );
00425    if ( res.successful() ) 
00426       ac.release();
00427 
00428    return res;
00429 }
00430 
00431 ActionResult unitJump( GameMap* actmap, int veh, const MapCoordinate& destination )
00432 {
00433    if ( !actmap )
00434       return ActionResult( 23500 );
00435    
00436    Vehicle* unit = actmap->getUnit( veh );
00437    if ( !unit )
00438       return ActionResult(120);
00439    
00440    ActionAvailability aa = JumpDriveCommand::available( unit );
00441    if ( !aa.ready())   
00442       return ActionResult(23411, aa.getMessage() );
00443    
00444    auto_ptr<JumpDriveCommand> ac( new JumpDriveCommand(unit) );
00445    ac->setDestination( destination );
00446    ActionResult res = ac->execute( createContext( actmap ) );
00447    if ( res.successful() ) 
00448       ac.release();
00449    
00450    return res;
00451 }
00452 
00453 ActionResult selfDestruct( GameMap* actmap, int containerID )
00454 {
00455    if ( !actmap )
00456       return ActionResult( 23500 );
00457    
00458    ContainerBase* c = actmap->getContainer( containerID );
00459    if ( !c )
00460       return ActionResult(23410);
00461      
00462    if ( !DestructUnitCommand::avail( c ))   
00463       return ActionResult(23411);
00464    
00465    auto_ptr<DestructUnitCommand> ac( new DestructUnitCommand(c) );
00466    ActionResult res = ac->execute( createContext( actmap ) );
00467    if ( res.successful() ) 
00468       ac.release();
00469    
00470    return res;
00471 }
00472 
00473 ActionResult recycleUnit( GameMap* actmap, int containerID, int unitID )
00474 {
00475    if ( !actmap )
00476       return ActionResult( 23500 );
00477    
00478    ContainerBase* c = actmap->getContainer( containerID );
00479    if ( !c )
00480       return ActionResult(23410);
00481      
00482    Vehicle* v = actmap->getUnit( unitID );
00483    if ( !v )
00484       return ActionResult( 21001 );
00485    
00486    if ( !RecycleUnitCommand::avail( c, v ))   
00487       return ActionResult(23411);
00488    
00489    
00490    auto_ptr<RecycleUnitCommand> ac( new RecycleUnitCommand(c) );
00491    ac->setUnit( v );
00492    ActionResult res = ac->execute( createContext( actmap ) );
00493    if ( res.successful() ) 
00494       ac.release();
00495    
00496    return res;
00497 }
00498 
00499 ActionResult buildProductionLine( GameMap* actmap, int containerID, int vehicleTypeID )
00500 {
00501    if ( !actmap )
00502       return ActionResult( 23500 );
00503    
00504    ContainerBase* c = actmap->getContainer( containerID );
00505    if ( !c )
00506       return ActionResult(23410);
00507      
00508    VehicleType* v = vehicleTypeRepository.getObject_byID( vehicleTypeID );
00509    if ( !v )
00510       return ActionResult( 21701 );
00511    
00512    if ( !BuildProductionLineCommand::avail( c ))   
00513       return ActionResult(23411);
00514    
00515    
00516    auto_ptr<BuildProductionLineCommand> ac( new BuildProductionLineCommand(c) );
00517    ac->setProduction( v );
00518    ActionResult res = ac->execute( createContext( actmap ) );
00519    if ( res.successful() ) 
00520       ac.release();
00521    
00522    return res;
00523 }
00524 
00525 ActionResult removeProductionLine( GameMap* actmap, int containerID, int vehicleTypeID )
00526 {
00527    if ( !actmap )
00528       return ActionResult( 23500 );
00529    
00530    ContainerBase* c = actmap->getContainer( containerID );
00531    if ( !c )
00532       return ActionResult(23410);
00533      
00534    VehicleType* v = vehicleTypeRepository.getObject_byID( vehicleTypeID );
00535    if ( !v )
00536       return ActionResult( 21701 );
00537    
00538    if ( !RemoveProductionLineCommand::avail( c ))   
00539       return ActionResult(23411);
00540    
00541    auto_ptr<RemoveProductionLineCommand> ac( new RemoveProductionLineCommand(c) );
00542    ac->setRemoval( v );
00543    ActionResult res = ac->execute( createContext( actmap ) );
00544    if ( res.successful() ) 
00545       ac.release();
00546    
00547    return res;
00548 }
00549 
00550 ActionResult repairBuilding( GameMap* actmap, int buildingID )
00551 {
00552    if ( !actmap )
00553       return ActionResult( 23500 );
00554    
00555    ContainerBase* c = actmap->getContainer( buildingID );
00556    if ( !c )
00557       return ActionResult(23410);
00558    
00559    Building* b = dynamic_cast<Building*>(c);
00560    if ( !b )
00561       return ActionResult(23410);
00562      
00563    if ( !RepairBuildingCommand::avail( b ))   
00564       return ActionResult(23411);
00565    
00566    auto_ptr<RepairBuildingCommand> ac( new RepairBuildingCommand(b) );
00567    ActionResult res = ac->execute( createContext( actmap ) );
00568    if ( res.successful() ) 
00569       ac.release();
00570    
00571    return res;
00572 }
00573 
00574 ActionResult setResourceProcessingRate( GameMap* actmap, int containerID, int amount )
00575 {
00576    if ( !actmap )
00577       return ActionResult( 23500 );
00578    
00579    ContainerBase* c = actmap->getContainer( containerID );
00580    if ( !c )
00581       return ActionResult(23410);
00582      
00583    if ( !SetResourceProcessingRateCommand::avail( c ))   
00584       return ActionResult(23411);
00585    
00586    auto_ptr<SetResourceProcessingRateCommand> ac( new SetResourceProcessingRateCommand(c, amount ) );
00587    ActionResult res = ac->execute( createContext( actmap ) );
00588    if ( res.successful() ) 
00589       ac.release();
00590    
00591    return res;
00592 }
00593 
00594 ActionResult cargoUnitMove( GameMap* actmap, int unitID, int targetContainerID )
00595 {
00596    if ( !actmap )
00597       return ActionResult( 23500 );
00598    
00599    Vehicle* unit = actmap->getUnit( unitID );
00600    if ( !unit )
00601       return ActionResult(120);
00602    
00603    auto_ptr<CargoMoveCommand> ac( new CargoMoveCommand(unit) );
00604    
00605    Vehicle* target = NULL;
00606    if ( targetContainerID != -1 ) {
00607       target = actmap->getUnit( targetContainerID );
00608       if ( !target )
00609          return ActionResult(23410);
00610       
00611       if ( !CargoMoveCommand::moveInAvail( unit, target ))   
00612          return ActionResult(23411);
00613       
00614       ac->setMode( CargoMoveCommand::moveInwards );
00615       ac->setTargetCarrier( target );
00616       
00617    } else {
00618       if ( !CargoMoveCommand::moveOutAvail( unit ))   
00619          return ActionResult(23411);
00620       
00621       ac->setMode( CargoMoveCommand::moveOutwards );
00622    }
00623    
00624    ActionResult res = ac->execute( createContext( actmap ) );
00625    if ( res.successful() ) 
00626       ac.release();
00627    
00628    return res;
00629 }
00630 
00631 ActionResult setDiplomacy( GameMap* actmap, int actingPlayer, int towardsPlayer, bool sneak, int newState )
00632 {
00633    if ( !actmap )
00634       return ActionResult( 23500 );
00635    
00636    if ( actingPlayer < 0 || actingPlayer >= actmap->getPlayerCount() )
00637       return ActionResult( 23100 );
00638    
00639    if ( towardsPlayer < 0 || towardsPlayer >= actmap->getPlayerCount() )
00640       return ActionResult( 23100 );
00641    
00642    
00643    
00644    auto_ptr<DiplomacyCommand> ac( new DiplomacyCommand(actmap->getPlayer(actingPlayer)) );
00645    if ( sneak )
00646       ac->sneakAttack( actmap->getPlayer(towardsPlayer) );
00647    else {
00648       if ( newState < 0 || newState >= diplomaticStateNum )
00649          return ActionResult( 23501 );
00650       
00651       DiplomaticStates state = (DiplomaticStates) newState;
00652       ac->newstate( state, actmap->getPlayer(towardsPlayer));
00653    }
00654    ActionResult res = ac->execute( createContext( actmap ) );
00655    if ( res.successful() ) 
00656       ac.release();
00657    
00658    return res;
00659 }
00660 
00661 ActionResult cancelResearch( GameMap* actmap, int actingPlayer )
00662 {
00663    if ( !actmap )
00664       return ActionResult( 23500 );
00665    
00666    if ( actingPlayer < 0 || actingPlayer >= actmap->getPlayerCount() )
00667       return ActionResult( 23100 );
00668    
00669    auto_ptr<CancelResearchCommand> ac( new CancelResearchCommand( actmap ) );
00670    ac->setPlayer( actmap->getPlayer( actingPlayer ));
00671    ActionResult res = ac->execute( createContext( actmap ) );
00672    if ( res.successful() ) 
00673       ac.release();
00674    
00675    return res;
00676 
00677 }
00678 
00679 ActionResult setResearchGoal( GameMap* actmap, int actingPlayer, int techID )
00680 {
00681    if ( !actmap )
00682       return ActionResult( 23500 );
00683    
00684    if ( actingPlayer < 0 || actingPlayer >= actmap->getPlayerCount() )
00685       return ActionResult( 23100 );
00686    
00687    Player& p = actmap->getPlayer( actingPlayer );
00688    
00689    if ( !DirectResearchCommand::available( p ) )
00690       return ActionResult(23411);
00691    
00692    Technology* t = technologyRepository.getObject_byID( techID );
00693    if ( !t )
00694       return ActionResult( 23205 );
00695    
00696    auto_ptr<DirectResearchCommand> ac( new DirectResearchCommand( p ) );
00697    ac->setTechnology( t );
00698    ActionResult res = ac->execute( createContext( actmap ) );
00699    if ( res.successful() ) 
00700       ac.release();
00701    
00702    return res;
00703 
00704 }
00705 
00706 class NextTurnStrategy_OnlyCampaign : public NextTurnStrategy {
00707    public:
00708       bool continueWhenLastPlayer() const {
00709          return false;     
00710       }
00711       
00712       bool authenticate( GameMap* actmap  ) const {
00713          int humanCount = 0;
00714          for ( int p = 0; p < actmap->getPlayerCount(); ++p )
00715             if ( actmap->getPlayer(p).isHuman() )
00716                ++humanCount;
00717          
00718          return humanCount <= 1;
00719       }
00720 } ;
00721 
00722 
00723 void endTurn()
00724 {
00725    next_turn( actmap, NextTurnStrategy_OnlyCampaign(), &getDefaultMapDisplay() );
00726 }
00727 
00728 void endTurn_headLess( GameMap* gamemap )
00729 {
00730    next_turn( gamemap, NextTurnStrategy_Abort(), NULL, -1 );
00731 }
00732 
00733 Vehicle* getSelectedUnit( GameMap* map )
00734 {
00735    MapField* fld = map->getField( map->getCursor() );
00736    if ( !fld )
00737       return NULL;
00738     
00739    if ( fld->vehicle && fld->vehicle->getOwner() == map->actplayer )
00740       return fld->vehicle;
00741    else
00742       return NULL;
00743 }
00744 
00745 ActionResult renameContainer( GameMap* actmap, int unitID, const ASCString& publicName, const ASCString& privateName )
00746 {
00747    if ( !actmap )
00748       return ActionResult( 23500 );
00749    
00750    Vehicle* v = actmap->getUnit( unitID );
00751    if ( !v )
00752       return ActionResult(23410);
00753    
00754    
00755    auto_ptr<RenameContainerCommand> rcc ( new RenameContainerCommand(v) );
00756    rcc->setName( publicName, privateName );
00757    ActionResult res = rcc->execute( createContext( actmap ) );
00758    if ( res.successful() ) 
00759       rcc.release();
00760    
00761    return res;
00762 }
00763 
00764 

Generated on Mon May 21 01:26:30 2012 for Advanced Strategic Command by  doxygen 1.5.1