Advanced Strategic Command
containercontrols.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  cargodialog.cpp - description
3  -------------------
4  begin : Tue Oct 24 2000
5  copyright : (C) 2000 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "containercontrols.h"
19 #include "gamemap.h"
20 #include "mapdisplayinterface.h"
21 #include "itemrepository.h"
22 
23 
24 const GameMap* ContainerConstControls::getMap() const
25 {
26  return container->getMap();
27 }
28 
29 
30 const Player& ContainerConstControls::getPlayer() const
31 {
32  return getMap()->player[ getMap()->actplayer ];
33 }
34 
35 
37 {
38  if ( container->getOwner() == container->getMap()->actplayer )
39  if ( container->vehiclesLoaded() < container->baseType->maxLoadableUnits )
41  return true;
42 
43  return false;
44 }
45 
46 int ContainerConstControls::unitProductionPrerequisites( const VehicleType* type, bool internally ) const
47 {
48  int l = 0;
49  Resources cost = container->getProductionCost( type );
50  for ( int r = 0; r < resourceTypeNum; r++ )
51  if ( container->getAvailableResource( cost.resource(r), r ) < cost.resource(r) )
52  l |= 1 << r;
53 
54  if ( internally ) {
55  if ( !type->techDependency.available( getPlayer().research ) && getMap()->getgameparameter( cgp_produceOnlyResearchedStuffInternally ) )
56  l |= 1 << 10;
57 
58  if ( !container->vehicleUnloadable( type ) && !container->baseType->hasFunction( ContainerBaseType::ProduceNonLeavableUnits ))
59  l |= 1 << 11;
60  } else {
61  if ( !type->techDependency.available( getPlayer().research ) && getMap()->getgameparameter( cgp_produceOnlyResearchedStuffExternally ) )
62  l |= 1 << 10;
63  }
64 
65  return l;
66 }
67 
68 
int maxLoadableUnits
the maximum number of units that can be loaded
TechAdapterDependency techDependency
bool hasFunction(ContainerFunctions function) const
int getOwner() const
returns the number of the player this vehicle/building belongs to
virtual int getAvailableResource(int amount, int resourcetype, int scope=1) const =0
int unitProductionPrerequisites(const VehicleType *type, bool internally) const
returns 0 if the unit is producable and != 0 otherwise.
bool unitProductionAvailable() const
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
int vehicleUnloadable(const VehicleType *vehicleType, int carrierHeight=-1) const
checks the unloading of a unit type
const int resourceTypeNum
The number of different resources that ASC uses.
Definition: typen.h:77
Resources getProductionCost(const VehicleType *unit) const
Definition of THE central asc class: GameMap.
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
Player player[9]
Definition: gamemap.h:253
int vehiclesLoaded(void) const
returns the number of loaded units
int getgameparameter(GameParameter num) const
Definition: gamemap.cpp:1047
int & resource(int type)
Definition: typen.h:105
const ContainerBaseType * baseType
the type descriping all non-instance specific properties of the container
Definition: containerbase.h:80
GameMap * getMap() const
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
Resources are basically the currency of ASC.
Definition: typen.h:97
bool available(const Research &research) const
Definition: research.cpp:412
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182