Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BaseComputer::BuyUpgradeOperation Class Reference
Inheritance diagram for BaseComputer::BuyUpgradeOperation:
BaseComputer::UpgradeOperation ModalDialogCallback

Public Member Functions

void start (void)
 
 BuyUpgradeOperation (BaseComputer &p)
 

Protected Member Functions

virtual bool checkTransaction (void)
 
virtual void concludeTransaction (void)
 
virtual void selectMount (void)
 
virtual ~BuyUpgradeOperation (void)
 
- Protected Member Functions inherited from BaseComputer::UpgradeOperation
 UpgradeOperation (BaseComputer &p)
 
virtual ~UpgradeOperation (void)
 
bool commonInit (void)
 
void finish (void)
 
bool endInit (void)
 
bool gotSelectedMount (int index)
 
bool gotSelectedTurret (int index)
 
void updateUI (void)
 
virtual void showTurretPicker (void)
 
virtual void modalDialogResult (const std::string &id, int result, WindowController &controller)
 

Protected Attributes

const Unitm_theTemplate
 
int m_addMultMode
 
- Protected Attributes inherited from BaseComputer::UpgradeOperation
BaseComputerm_parent
 
const Unitm_newPart
 
Cargo m_part
 
int m_selectedMount
 
int m_selectedTurret
 
Cargo m_selectedItem
 

Detailed Description

Definition at line 3433 of file basecomputer.cpp.

Constructor & Destructor Documentation

BaseComputer::BuyUpgradeOperation::BuyUpgradeOperation ( BaseComputer p)
inline

Definition at line 3438 of file basecomputer.cpp.

3438  : UpgradeOperation( p )
3439  , m_theTemplate( NULL )
3440  , m_addMultMode( 0 ) {};
virtual BaseComputer::BuyUpgradeOperation::~BuyUpgradeOperation ( void  )
inlineprotectedvirtual

Definition at line 3446 of file basecomputer.cpp.

3446 {}

Member Function Documentation

bool BaseComputer::BuyUpgradeOperation::checkTransaction ( void  )
protectedvirtual

Implements BaseComputer::UpgradeOperation.

Definition at line 3692 of file basecomputer.cpp.

References Unit::canUpgrade(), and showYesNoQuestion().

3693 {
3694  Unit *playerUnit = m_parent.m_player.GetUnit();
3695  if (!playerUnit) {
3696  finish();
3697  return false; //We want the window to die to avoid accessing of deleted memory.
3698  }
3699  double percent; //Temp. Not used.
3700  if ( playerUnit->canUpgrade( m_newPart, m_selectedMount, m_selectedTurret, m_addMultMode, false, percent,
3701  m_theTemplate ) ) {
3702  //We can buy the upgrade.
3704  return false;
3705  } else {
3706  showYesNoQuestion( "The item cannot fit the frame of your starship. Do you want to buy it anyway?",
3707  this, CONFIRM_ID );
3708  return true;
3709  }
3710 }
void BaseComputer::BuyUpgradeOperation::concludeTransaction ( void  )
protectedvirtual

Implements BaseComputer::UpgradeOperation.

Definition at line 3713 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), basecargoassets(), Unit::canUpgrade(), Cockpit::credits, Unit::GetCargo(), VegaConfig::getVariable(), index, Network, XMLSupport::parse_bool(), Unit::RemoveCargo(), Unit::ToggleWeapon(), Unit::Upgrade(), and vs_config.

3714 {
3715  Unit *playerUnit = m_parent.m_player.GetUnit();
3716  Unit *baseUnit = m_parent.m_base.GetUnit();
3717  if ( !(playerUnit && baseUnit) ) {
3718  finish();
3719  return;
3720  }
3721  //Get the upgrade percentage to calculate the full price.
3722  double percent;
3723  int numleft = basecargoassets( baseUnit, m_part.content );
3724  while ( numleft > 0
3725  && playerUnit->canUpgrade( m_newPart, m_selectedMount, m_selectedTurret, m_addMultMode, true, percent,
3726  m_theTemplate ) ) {
3727  const float price = m_part.price; //* (1-usedValue(percent));
3728  if (_Universe->AccessCockpit()->credits >= price) {
3729  //Have enough money. Buy it.
3730  _Universe->AccessCockpit()->credits -= price;
3731  if (Network)
3733  //Upgrade the ship.
3735  static bool allow_special_with_weapons =
3736  XMLSupport::parse_bool( vs_config->getVariable( "physics", "special_and_normal_gun_combo", "true" ) );
3737  if (!allow_special_with_weapons) {
3738  playerUnit->ToggleWeapon( false, /*backwards*/ true );
3739  playerUnit->ToggleWeapon( false, /*backwards*/ false );
3740  }
3741  //Remove the item from the base, since we bought it.
3742  unsigned int index;
3743  baseUnit->GetCargo( m_part.content, index );
3744  baseUnit->RemoveCargo( index, 1, false );
3745  } else {
3746  break;
3747  }
3748  if (m_newPart->mounts.size() == 0)
3749  break;
3750  else if (m_newPart->mounts[0].ammo <= 0)
3751  break;
3752  numleft = basecargoassets( baseUnit, m_part.content );
3753  }
3754  updateUI();
3755 
3756  finish();
3757 }
void BaseComputer::BuyUpgradeOperation::selectMount ( void  )
protectedvirtual

Implements BaseComputer::UpgradeOperation.

Definition at line 3637 of file basecomputer.cpp.

References Mount::ACTIVE, SimplePicker::addCell(), Unit::canUpgrade(), Window::findControlById(), Unit::GetNumMounts(), i, Mount::INACTIVE, QuestionDialog::init(), lookupMountSize(), MOUNT_POINT_EMPTY(), MOUNT_POINT_FULL(), MOUNT_POINT_NO_SELECT(), Unit::mounts, QuestionDialog::run(), ModalDialog::setCallback(), tostring(), and WindowController::window().

3638 {
3639  if (m_newPart->GetNumMounts() <= 0) {
3640  //Part doesn't need a mount point.
3641  gotSelectedMount( 0 );
3642  return;
3643  }
3644  Unit *playerUnit = m_parent.m_player.GetUnit();
3645  if (!playerUnit) {
3646  finish();
3647  return;
3648  }
3649  //Create a custom list dialog to get the mount point.
3651  dialog->init( "Select mount for your item:" );
3652  dialog->setCallback( this, GOT_MOUNT_ID );
3653 
3654  //Fill the dialog picker with the mount points.
3655  SimplePicker *picker = static_cast< SimplePicker* > ( dialog->window()->findControlById( "Picker" ) );
3656  assert( picker != NULL );
3657  for (int i = 0; i < playerUnit->GetNumMounts(); i++) {
3658  //Mount is selectable if we can upgrade with the new part using that mount.
3659  double percent; //Temp. Not used.
3660  const bool selectable = playerUnit->canUpgrade( m_newPart,
3661  i,
3663  m_addMultMode,
3664  false,
3665  percent,
3666  m_theTemplate );
3667 
3668  //Figure color and label based on weapon that is in the slot.
3669  GFXColor mountColor = MOUNT_POINT_NO_SELECT();
3670  string mountName;
3671  string ammoexp;
3672  if (playerUnit->mounts[i].status == Mount::ACTIVE || playerUnit->mounts[i].status == Mount::INACTIVE) {
3673  mountName = tostring( i+1 )+" "+playerUnit->mounts[i].type->weapon_name;
3674  ammoexp =
3675  (playerUnit->mounts[i].ammo == -1) ? string( "" ) : string( ( " ammo: "+tostring( playerUnit->mounts[i].ammo ) ) );
3676  mountName += ammoexp;
3677  mountColor = MOUNT_POINT_FULL();
3678  } else {
3679  const std::string temp = lookupMountSize( playerUnit->mounts[i].size );
3680  mountName = tostring( i+1 )+" (Empty) "+temp.c_str();
3681  mountColor = MOUNT_POINT_EMPTY();
3682  }
3683  //If the mount point won't work with the weapon, don't let user select it.
3684  if (!selectable) mountColor = MOUNT_POINT_NO_SELECT();
3685  //Now we add the cell. Note that "selectable" is stored in the tag property.
3686  picker->addCell( new SimplePickerCell( mountName, "", mountColor, (selectable ? 1 : 0) ) );
3687  }
3688  dialog->run();
3689 }
void BaseComputer::BuyUpgradeOperation::start ( void  )

Definition at line 3590 of file basecomputer.cpp.

References Unit::faction, Unit::GetCargo(), GetModeFromName(), makeTemplateUpgrade(), Unit::name, and Cargo::quantity.

Referenced by BaseComputer::buyUpgrade().

3591 {
3592  Unit *playerUnit = m_parent.m_player.GetUnit();
3593  Unit *baseUnit = m_parent.m_base.GetUnit();
3594  if ( !( playerUnit && baseUnit && commonInit() ) ) {
3595  finish();
3596  return;
3597  }
3598  m_theTemplate = makeTemplateUpgrade( playerUnit->name.get(), playerUnit->faction );
3599 
3600  m_addMultMode = GetModeFromName( m_selectedItem.GetContent().c_str() ); //Whether the price is linear or geometric.
3601  unsigned int offset; //Temp. Not used.
3602  Cargo *part = baseUnit->GetCargo( m_selectedItem.content, offset ); //Whether the base has any of these.
3603  if (part && part->quantity > 0) {
3604  m_part = *part;
3605  endInit();
3606  } else {
3607  finish();
3608  //The object may be deleted now. Be careful here.
3609  }
3610 }

Member Data Documentation

int BaseComputer::BuyUpgradeOperation::m_addMultMode
protected

Definition at line 3449 of file basecomputer.cpp.

const Unit* BaseComputer::BuyUpgradeOperation::m_theTemplate
protected

Definition at line 3448 of file basecomputer.cpp.


The documentation for this class was generated from the following file: