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::SellUpgradeOperation Class Reference
Inheritance diagram for BaseComputer::SellUpgradeOperation:
BaseComputer::UpgradeOperation ModalDialogCallback

Public Member Functions

void start (void)
 
 SellUpgradeOperation (BaseComputer &p)
 

Protected Member Functions

virtual bool checkTransaction (void)
 
virtual void concludeTransaction (void)
 
virtual void selectMount (void)
 
virtual ~SellUpgradeOperation (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_downgradeLimiter
 
- 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 3453 of file basecomputer.cpp.

Constructor & Destructor Documentation

BaseComputer::SellUpgradeOperation::SellUpgradeOperation ( BaseComputer p)
inline

Definition at line 3458 of file basecomputer.cpp.

3458  : UpgradeOperation( p )
3459  , m_downgradeLimiter( NULL ) {};
virtual BaseComputer::SellUpgradeOperation::~SellUpgradeOperation ( void  )
inlineprotectedvirtual

Definition at line 3465 of file basecomputer.cpp.

3465 {}

Member Function Documentation

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

Implements BaseComputer::UpgradeOperation.

Definition at line 3902 of file basecomputer.cpp.

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

3903 {
3904  Unit *playerUnit = m_parent.m_player.GetUnit();
3905  if (!playerUnit) {
3906  finish();
3907  return false; //We want the window to die to avoid accessing of deleted memory.
3908  }
3909  double percent; //Temp. Not used.
3910  if ( playerUnit->canDowngrade( m_newPart, m_selectedMount, m_selectedTurret, percent, m_downgradeLimiter ) ) {
3911  //We can sell the upgrade.
3913  return false;
3914  } else {
3915  showYesNoQuestion( "You don't have exactly what you wish to sell. Continue?",
3916  this, CONFIRM_ID );
3917  return true;
3918  }
3919 }
void BaseComputer::SellUpgradeOperation::concludeTransaction ( void  )
protectedvirtual

Implements BaseComputer::UpgradeOperation.

Definition at line 3922 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), Unit::AddCargo(), Unit::canDowngrade(), Cockpit::credits, Unit::Downgrade(), Network, Unit::PriceCargo(), and usedValue().

3923 {
3924  Unit *playerUnit = m_parent.m_player.GetUnit();
3925  Unit *baseUnit = m_parent.m_base.GetUnit();
3926  if ( !(playerUnit && baseUnit) ) {
3927  finish();
3928  return;
3929  }
3930  //Get the upgrade percentage to calculate the full price.
3931  double percent;
3933  const float price = m_part.price*usedValue( percent );
3934  //Adjust the money.
3935  if (!Network)
3936  _Universe->AccessCockpit()->credits += price;
3937  //Change the ship.
3938  if ( playerUnit->Downgrade( m_newPart, m_selectedMount, m_selectedTurret, percent, m_downgradeLimiter ) ) {
3939  //Remove the item from the ship, since we sold it, and add it to the base.
3940  m_part.quantity = 1;
3941  m_part.price = baseUnit->PriceCargo( m_part.content );
3942  baseUnit->AddCargo( m_part );
3943  }
3944  updateUI();
3945 
3946  finish();
3947 }
void BaseComputer::SellUpgradeOperation::selectMount ( void  )
protectedvirtual

Implements BaseComputer::UpgradeOperation.

Definition at line 3831 of file basecomputer.cpp.

References Mount::ACTIVE, SimplePicker::addCell(), Window::findControlById(), ClassCache< Typ, Key >::getCachedConst(), Unit::GetNumMounts(), FactionUtil::GetUpgradeFaction(), i, Mount::INACTIVE, QuestionDialog::init(), lookupMountSize(), matchCargoToWeapon(), MOUNT_POINT_FULL(), MOUNT_POINT_NO_SELECT(), Unit::mounts, QuestionDialog::run(), ModalDialog::setCallback(), tostring(), and WindowController::window().

3832 {
3833  if (m_newPart->GetNumMounts() <= 0) {
3834  //Part doesn't need a mount point.
3835  gotSelectedMount( 0 );
3836  return;
3837  }
3838  Unit *playerUnit = m_parent.m_player.GetUnit();
3839  if (!playerUnit) {
3840  finish();
3841  return;
3842  }
3843  //Create a custom list dialog to get the mount point.
3845  dialog->init( "Select mount for your item:" );
3846  dialog->setCallback( this, GOT_MOUNT_ID );
3847 
3848  //Fill the dialog picker with the mount points.
3849  SimplePicker *picker = static_cast< SimplePicker* > ( dialog->window()->findControlById( "Picker" ) );
3850  assert( picker != NULL );
3851  int mount = -1; //The mount if there was only one.
3852  int selectableCount = 0;
3853  for (int i = 0; i < playerUnit->GetNumMounts(); i++) {
3854  //Whether or not the entry is selectable -- the same as the thing we are selling.
3855  bool selectable = false;
3856 
3857  //Get the name.
3858  string mountName;
3859  if (playerUnit->mounts[i].status == Mount::ACTIVE || playerUnit->mounts[i].status == Mount::INACTIVE) {
3860  //Something is mounted here.
3861  const std::string unitName = playerUnit->mounts[i].type->weapon_name;
3863  string ammoexp;
3864  mountName = tostring( i+1 )+" "+unitName.c_str();
3865  ammoexp =
3866  (playerUnit->mounts[i].ammo == -1) ? string( "" ) : string( ( " ammo: "+tostring( playerUnit->mounts[i].ammo ) ) );
3867  mountName += ammoexp;
3868  if (partUnit) {
3869  if ( partUnit->GetNumMounts() ) {
3870  if (partUnit->mounts[0].type == playerUnit->mounts[i].type) {
3871  selectable = true;
3872  selectableCount++;
3873  mount = i;
3874  }
3875  }
3876  } else if ( matchCargoToWeapon( m_part.content, unitName ) ) {
3877  selectable = true;
3878  selectableCount++;
3879  mount = i;
3880  }
3881  } else {
3882  //Nothing at this mount point.
3883  const std::string temp = lookupMountSize( playerUnit->mounts[i].size );
3884  mountName = tostring( i+1 )+" (Empty) "+temp.c_str();
3885  }
3886  //Now we add the cell. Note that "selectable" is stored in the tag property.
3887  const GFXColor mountColor = ( selectable ? MOUNT_POINT_FULL() : MOUNT_POINT_NO_SELECT() );
3888  picker->addCell( new SimplePickerCell( mountName, "", mountColor, (selectable ? 1 : 0) ) );
3889  }
3890  assert( selectableCount > 0 ); //We should have found at least one unit mounted.
3891  if (selectableCount > 1) {
3892  //Need to have the user choose.
3893  dialog->run();
3894  } else {
3895  //Get rid of the dialog -- we only have one choice.
3896  delete dialog;
3897  gotSelectedMount( mount );
3898  }
3899 }
void BaseComputer::SellUpgradeOperation::start ( void  )

Definition at line 3770 of file basecomputer.cpp.

References StarSystemGent::faction, Unit::faction, GetMasterPartList(), GetUnitDir(), makeFinalBlankUpgrade(), and Unit::name.

Referenced by BaseComputer::sellUpgrade().

3771 {
3772  Unit *playerUnit = m_parent.m_player.GetUnit();
3773  if ( !( playerUnit && commonInit() ) ) {
3774  finish();
3775  return;
3776  }
3777  const string unitDir = GetUnitDir( playerUnit->name.get().c_str() );
3778  const string limiterName = unitDir+".blank";
3779  const int faction = playerUnit->faction;
3780 
3781  //Get the "limiter" for this operation. Stats can't decrease more than the blank ship.
3782  m_downgradeLimiter = makeFinalBlankUpgrade( playerUnit->name, faction );
3783 
3784  //If its limiter is not available, just assume that there are no limits.
3785 
3786  Cargo *part = GetMasterPartList( m_selectedItem.GetContent().c_str() );
3787  if (part) {
3788  m_part = *part;
3789  endInit();
3790  } else {
3791  finish();
3792  //The object may be deleted now. Be careful here.
3793  }
3794 }

Member Data Documentation

const Unit* BaseComputer::SellUpgradeOperation::m_downgradeLimiter
protected

Definition at line 3467 of file basecomputer.cpp.


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