1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/***************************************************************************
cargodialog.cpp - description
-------------------
begin : Tue Oct 24 2000
copyright : (C) 2000 by Martin Bickel
email : bickel@asc-hq.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "containercontrols.h"
#include "gamemap.h"
#include "mapdisplayinterface.h"
#include "itemrepository.h"
const GameMap* ContainerConstControls::getMap() const
{
return container->getMap();
}
GameMap* ContainerControls::getMap()
{
return container->getMap();
}
const Player& ContainerConstControls::getPlayer() const
{
return getMap()->player[ getMap()->actplayer ];
}
Player& ContainerControls::getPlayer()
{
return getMap()->player[ getMap()->actplayer ];
}
int ContainerControls::getPlayerNum()
{
return getMap()->actplayer;
}
bool ContainerConstControls::unitProductionAvailable() const
{
if ( container->getOwner() == container->getMap()->actplayer )
if ( container->vehiclesLoaded() < container->baseType->maxLoadableUnits )
if ( container->baseType->hasFunction( ContainerBaseType::InternalVehicleProduction ))
return true;
return false;
}
int ContainerConstControls::unitProductionPrerequisites( const Vehicletype* type, bool internally ) const
{
int l = 0;
Resources cost = container->getProductionCost( type );
for ( int r = 0; r < resourceTypeNum; r++ )
if ( container->getAvailableResource( cost.resource(r), r ) < cost.resource(r) )
l |= 1 << r;
if ( internally ) {
if ( !type->techDependency.available( getPlayer().research ) && getMap()->getgameparameter( cgp_produceOnlyResearchedStuffInternally ) )
l |= 1 << 10;
if ( !container->vehicleUnloadable( type ) && !container->baseType->hasFunction( ContainerBaseType::ProduceNonLeavableUnits ))
l |= 1 << 11;
} else {
if ( !type->techDependency.available( getPlayer().research ) && getMap()->getgameparameter( cgp_produceOnlyResearchedStuffExternally ) )
l |= 1 << 10;
}
return l;
}
Vehicle* ContainerControls::produceUnitHypothetically( const Vehicletype* type )
{
if ( !unitProductionAvailable() )
return NULL;
if ( unitProductionPrerequisites( type, true ))
return NULL;
Vehicle* vehicle = new Vehicle ( type, getMap(), getPlayerNum() );
vehicle->setnewposition( container->getPosition() );
if ( getMap()->getgameparameter(cgp_bi3_training) >= 1 ) {
int cnt = 0;
for ( Player::BuildingList::iterator bi = getMap()->player[getMap()->actplayer].buildingList.begin(); bi != getMap()->player[getMap()->actplayer].buildingList.end(); bi++ )
if ( (*bi)->typ->hasFunction( ContainerBaseType::TrainingCenter ) )
cnt++;
vehicle->experience += cnt * getMap()->getgameparameter(cgp_bi3_training);
if ( vehicle->experience > maxunitexperience )
vehicle->experience = maxunitexperience;
}
return vehicle;
}
|