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.h
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2003 Mike Byron
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef __BASECOMPUTER_H__
23 #define __BASECOMPUTER_H__
24 
25 #include "gui/windowcontroller.h"
26 #include "cmd/unit_generic.h"
27 #include "gui/simplepicker.h"
28 
29 //The BaseComputer class displays an interactive screen that supports a
30 //number of functions in a base.
31 //Current list:
32 //Buying and selling cargo.
33 //Upgrading and downgrading your ship.
34 //Replacing your current ship with a new one.
35 //News articles.
36 //Mission bulletin board.
37 //Player info.
38 
39 class BaseComputer : public WctlBase< BaseComputer >
40 {
41  friend class WctlBase< BaseComputer >;
42 public:
43 
44  static int dirty;
45 
46 //The Computer displays that are possible.
48  {
49  CARGO=0, //Buy and sell cargo.
50  UPGRADE, //Buy and sell ship upgrades.
51  SHIP_DEALER, //Replace current ship.
52  MISSIONS, //Show available missions.
53  NEWS, //Show news items.
54  INFO, //Show basic info.
55  LOADSAVE, //LOAD SAVE
56  NETWORK, //Network submenu of Loadsave.
57  DISPLAY_MODE_COUNT, //Number of display modes.
59  };
60 
61 //Set up the window and get everything ready.
62  virtual void init( void );
63 
64 //Start it up!
65  virtual void run( void );
66 
67 //Check if we are dirty.
68  virtual void draw( void );
69 
70 //Process a command event from the window. Handled in parent class's WctlCommandTable.
71 //virtual bool processWindowCommand(const EventCommandId& command, Control* control);
72 
73 //CONSTRUCTION
74  BaseComputer( Unit *player, Unit *base, const vector< DisplayMode > &modes );
75  virtual ~BaseComputer( void );
76 
77 //These are the transactions that can happen using this object.
78 //Transactions are operations that modify the player's state. Reading news isn't
79 //a transaction.
81  {
82  BUY_CARGO, //Buy item and put in ship.
83  SELL_CARGO, //Sell item to base.
84  BUY_UPGRADE, //Buy an improvement for current ship.
85  SELL_UPGRADE, //Sell an improvement on current ship.
86  BUY_SHIP, //Replace our current ship with a new one.
87  ACCEPT_MISSION, //Accept a mission.
88  NULL_TRANSACTION, //Not initialized yet.
89  };
90 
91 protected:
92 
93 //Association between CargoColor list, picker, and transaction type.
95  {
96  vector< CargoColor >masterList; //All the items that could be in the picker.
97  Picker *picker; //The picker loaded with the list.
98  TransactionType transaction; //The kind of transaction these items will generate.
99  TransactionList() : picker( NULL )
101  };
102 
104  {
105  BaseComputer *m_parent;
106  std::string type;
107  std::string text;
108  std::string savefile;
109 public:
110 //CONSTRUCTION.
111  LoadSaveQuitConfirm( BaseComputer *player, std::string confirmtype, std::string text ) : m_parent( player )
112  , type( confirmtype )
113  , text( text ) {}
114  virtual ~LoadSaveQuitConfirm( void ) {}
115 
116 //Set up the window and get everything ready.
117  virtual void init( void );
118 
119 //Process a command event from the window.
120  virtual bool processWindowCommand( const EventCommandId &command, Control *control );
121  };
122  friend class LoadSaveQuitConfirm;
123 //HANDLERS
124 //The selection in the News picker changed.
125  bool newsPickerChangedSelection( const EventCommandId &command, Control *control );
126 //The selection in the News picker changed.
127  bool loadSavePickerChangedSelection( const EventCommandId &command, Control *control );
128 //Something in a Picker was selected.
129  bool pickerChangedSelection( const EventCommandId &command, Control *control );
130 //Buy an item from the cargo list.
131  bool buyCargo( const EventCommandId &command, Control *control );
132 //Buy an item (quantity 10) from the cargo list.
133  bool buy10Cargo( const EventCommandId &command, Control *control );
134 //Buy all of an item from the cargo list.
135  bool buyAllCargo( const EventCommandId &command, Control *control );
136 //Sell an item from ship's cargo.
137  bool sellCargo( const EventCommandId &command, Control *control );
138 //Sell an item (quantity 10) from ship's cargo.
139  bool sell10Cargo( const EventCommandId &command, Control *control );
140 //Sell all of an item from ship's cargo.
141  bool sellAllCargo( const EventCommandId &command, Control *control );
142 //Buy a ship upgrade.
143  bool buyUpgrade( const EventCommandId &command, Control *control );
144 //Sell an upgrade on your ship.
145  bool sellUpgrade( const EventCommandId &command, Control *control );
146 //Fix an upgrade on your ship.
147  bool fixUpgrade( const EventCommandId &command, Control *control );
148 //Buy ship from the base.
149  bool buyShip( const EventCommandId &command, Control *control );
150 //Sell ship from your stock
151  bool sellShip( const EventCommandId &command, Control *control );
152 //Accept a mission.
153  bool acceptMission( const EventCommandId &command, Control *control );
154 //Quit Game
156  bool actionLoadGame( const EventCommandId &command, Control *control );
157 //Save Game
159  bool actionSaveGame( const EventCommandId &command, Control *control );
160  bool actionNewGame( const EventCommandId &command, Control *control );
161 //Load Game
163  bool actionQuitGame( const EventCommandId &command, Control *control );
164 
165  bool actionNetSaveGame( const EventCommandId &command, Control *control );
166  bool actionNetDie( const EventCommandId &command, Control *control );
167  bool actionJoinGame( const EventCommandId &command, Control *control );
168  bool actionShowAccountMenu( const EventCommandId &command, Control *control );
169  bool actionShowServerMenu( const EventCommandId &command, Control *control );
170 
171  bool actionDone( const EventCommandId &command, Control *control );
172 
173 //Show the player's basic information.
174  bool showPlayerInfo( const EventCommandId &command, Control *control );
175 //Show the stats on the player's current ship.
176  bool showShipStats( const EventCommandId &command, Control *control );
177 //Change display mode to CARGO.
178  bool changeToCargoMode( const EventCommandId &command, Control *control );
179 //Change display mode to UPGRADE.
180  bool changeToUpgradeMode( const EventCommandId &command, Control *control );
181 //Change display mode to SHIP_DEALER.
182  bool changeToShipDealerMode( const EventCommandId &command, Control *control );
183 //Change display mode to NEWS.
184  bool changeToNewsMode( const EventCommandId &command, Control *control );
185 //Change display mode to MISSIONS.
186  bool changeToMissionsMode( const EventCommandId &command, Control *control );
187 //Change display mode to INFO.
188  bool changeToInfoMode( const EventCommandId &command, Control *control );
189 //Change display mode to LOAD/SAVE
190  bool changeToLoadSaveMode( const EventCommandId &command, Control *control );
191 //Change display mode to NETWORK.
192  bool changeToNetworkMode( const EventCommandId &command, Control *control );
193  void showNetworkStatus( bool show = true );
194  bool hideNetworkStatus( const EventCommandId &command, Control *control );
195 
196 //Redo the title string.
197  void recalcTitle( void );
198 
199 //Refresh both picker lists and the title.
200  void refresh( void );
201 
202 //Return whether or not this transaction is possible for the player now.
203  bool isTransactionOK( const Cargo &originalItem, TransactionType transType, int quantity = 1 );
204 
205 //Create whatever cells are needed to add a category to the picker.
206  SimplePickerCell * createCategoryCell( SimplePickerCells &cells, const string &category, bool skipFirstCategory );
207 
208 //Load a picker with a list of items.
209  void loadListPicker( TransactionList &list, SimplePicker &picker, TransactionType transType, bool skipFirstCategory = false );
210 
211 //Scroll to a specific item in a picker, and optionally select it.
212 //Returns true if the specified item is found.
213  bool scrollToItem( Picker *picker, const Cargo &item, bool select, bool skipFirstCategory );
214 
215 public:
216 //Update the transaction controls after a transaction.
217  void updateTransactionControls( const Cargo &item, bool skipFirstCategory = false );
218 
219 //Update the controls when the selection for a transaction changes.
221 //Load the controls for the MISSIONS display.
222  void loadShipDealerControls( void );
223 
224  void secondStageJoinGame( void );
225  void finalizeJoinGame( int launchShip = 0 );
226  void finalizeNetSaveGame( void );
227 protected:
228 
229 //Hide the controls that commit transactions.
230  void hideCommitControls( void );
231 
232 //Update the commit controls in the Cargo screen, since we have three of them.
233  void configureCargoCommitControls( const Cargo &item, TransactionType trans );
234 
235 //Update the commit controls in the Cargo screen, since we have three of them.
236 //returns the state of whether the description should have a warning.
237  bool configureUpgradeCommitControls( const Cargo &item, TransactionType trans );
238 
239 //Make sure the info in the transaction lists is gone.
240  void resetTransactionLists( void );
241 
242 //Load the controls for the CARGO display.
243  void loadCargoControls( void );
244 
245 //Buy some items from the Cargo list. Use -1 for quantity to buy all of the item.
246  bool buySelectedCargo( int requestedQuantity );
247 
248 //The max number of a particular item this player can buy. Limits by price, cargo space, etc.
249  int maxQuantityForPlayer( const Cargo &item, int suggestedQuantity );
250 
251 //Sell some items from the Cargo list. Use -1 for quantity to buy all of the item.
252  bool sellSelectedCargo( int requestedQuantity );
253 
254 //Load the controls for the NEWS display.
255  void loadNewsControls( void );
256 
257  void loadLoadSaveControls( void );
258 
259  void loadNetworkControls( void );
260 
261 //Load the controls for the MISSIONS display.
262  void loadMissionsControls( void );
263 
264 //Load the controls for the UPGRADE display.
265  void loadUpgradeControls( void );
266  void loadBuyUpgradeControls( void );
267  void loadSellUpgradeControls( void );
268 
269 //Return a pointer to the selected Cargo struct.
270  Cargo * selectedItem( void );
271 
272 //Switch to the set of controls used for the specified mode.
273  void switchToControls( DisplayMode mode );
274 
275 //Create the mode buttons.
276  void createModeButtons( void );
277 
278 //Create the controls that will be used for this window.
279  void createControls( void );
280 
281 //Contruct the controls in code.
282  void constructControls( void );
283 
284  GFXColor getColorForGroup( std::string id );
285 
286 //Get a filtered list of items from a unit.
287  void loadMasterList( Unit *un,
288  const vector< string > &filterthis,
289  const vector< string > &invfilterthis,
290  bool removezero,
291  TransactionList &list );
292 
293 //Load a master list with missions.
295 
296 //VARIABLES
297  vector< DisplayMode >m_displayModes; //List of diaplays to provide.
298 public:
299 
300  UnitContainer m_player; //Ship info, etc.
301  UnitContainer m_base; //The base we are in.
302 protected:
303  DisplayMode m_currentDisplay; //The current display mode.
304  TransactionList m_transList1; //The commonly-used list/picker.
305  TransactionList m_transList2; //If there are two pickers, the second one.
306  TransactionList *m_selectedList; //Which transaction list has the selection. NULL = none.
307  Control *m_modeGroups[DISPLAY_MODE_COUNT]; //Array of GroupControls, one for each mode.
308  bool m_playingMuzak; //True = We are playing muzak for some mode.
309 
310 //INTERNAL CLASSES.
311  class UpgradeOperation;
312  class BuyUpgradeOperation;
314 
315  friend class UpgradeOperation;
316  friend class BuyUpgradeOperation;
317  friend class SellUpgradeOperation;
318 };
319 bool buyShip( Unit *base, Unit *player, std::string, bool myfleet, bool force_base_inventory, BaseComputer* );
320 bool sellShip( Unit *base, Unit *player, std::string, BaseComputer* );
321 
322 #endif //__BASECOMPUTER_H__
323