Advanced Strategic Command
autotraining.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  autotraining.cpp - description
3  -------------------
4  copyright : (C) 2009 by Martin Bickel
5  email : bickel@asc-hq.org
6  ***************************************************************************/
7 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  ***************************************************************************/
20 
21 
22 #include "player.h"
23 #include "gamemap.h"
24 
26 #include "actions/servicecommand.h"
27 
28 static void autoTrainer( ContainerBase* container )
29 {
30  for ( ContainerBase::Cargo::const_iterator i = container->getCargo().begin(); i != container->getCargo().end(); ++i ) {
31  if ( TrainUnitCommand::avail( container, *i )) {
32  Context context;
33  context.gamemap = container->getMap();
34  context.actingPlayer = & (container->getMap()->getPlayer( container ));
35  context.parentAction = NULL;
36  context.display = NULL;
37  context.viewingPlayer = container->getOwner();
38  context.actionContainer = &container->getMap()->actions;
39 
40  auto_ptr<TrainUnitCommand> tuc ( new TrainUnitCommand( container ));
41  tuc->setUnit( *i );
42  ActionResult res = tuc->execute( context );
43 
44  if ( res.successful())
45  tuc.release();
46 
47 
48  if ( ServiceCommand::avail( container, *i )) {
49  auto_ptr<ServiceCommand> sc ( new ServiceCommand( container ));
50  sc->setDestination( *i );
51  TransferHandler& tc = sc->getTransferHandler();
52  tc.fillDestAmmo();
53  sc->saveTransfers();
54  res = sc->execute( context );
55  if ( res.successful())
56  sc.release();
57  }
58  }
59  }
60 }
61 
62 void automaticTrainig( GameMap* gamemap, Player& player )
63 {
64  for ( Player::BuildingList::iterator b = player.buildingList.begin(); b != player.buildingList.end(); ++b )
65  autoTrainer( *b );
66 
67  for ( Player::VehicleList::iterator v= player.vehicleList.begin(); v != player.vehicleList.end(); ++v )
68  autoTrainer( *v );
69 
70 }
void fillDestAmmo()
Definition: servicing.cpp:852
Player * actingPlayer
Definition: context.h:37
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
void automaticTrainig(GameMap *gamemap, Player &player)
trains all units that are in training centers, which increases their experience at the cost of time (...
static void autoTrainer(ContainerBase *container)
int getOwner() const
returns the number of the player this vehicle/building belongs to
VehicleList vehicleList
a list of all units
Definition: player.h:135
GameAction * parentAction
Definition: context.h:38
Definition of THE central asc class: GameMap.
int viewingPlayer
Definition: context.h:40
bool successful() const
MapDisplayInterface * display
Definition: context.h:39
GameMap * gamemap
Definition: context.h:36
ActionContainer * actionContainer
Definition: context.h:41
static bool avail(ContainerBase *source, ContainerBase *target)
BuildingList buildingList
a list of all units
Definition: player.h:139
ActionContainer actions
Records all action that have been done for undo/redo purposes.
Definition: gamemap.h:390
static bool avail(const ContainerBase *carrier, const Vehicle *unit)
GameMap * getMap() const
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
const Cargo & getCargo() const
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182