# command_type.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD 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, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #ifndef COMMAND_TYPE_H
    00013 #define COMMAND_TYPE_H
    00014
    00015 #include "economy_type.h"
    00016 #include "strings_type.h"
    00017 #include "tile_type.h"
    00018
    00023 class CommandCost {
    00024   ExpensesType expense_type;
    00025   Money cost;
    00026   StringID message;
    00027   bool success;
    00028
    00029 public:
    00033   CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true) {}
    00034
    00038   CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false) {}
    00039
    00044   CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true) {}
    00045
    00051   CommandCost(ExpensesType ex_t, Money cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true) {}
    00052
    00059   CommandCost AddCost(CommandCost ret);
    00060
    00066   CommandCost AddCost(Money cost)
    00067   {
    00068     this->cost += cost;
    00069     return *this;
    00070   }
    00071
    00077   CommandCost MultiplyCost(int factor)
    00078   {
    00079     this->cost *= factor;
    00080     return *this;
    00081   }
    00082
    00087   Money GetCost() const
    00088   {
    00089     return this->cost;
    00090   }
    00091
    00096   ExpensesType GetExpensesType() const
    00097   {
    00098     return this->expense_type;
    00099   }
    00100
    00104   void SetGlobalErrorMessage() const
    00105   {
    00106     extern StringID _error_message;
    00107     if (this->message != INVALID_STRING_ID) _error_message = this->message;
    00108   }
    00109
    00114   StringID GetErrorMessage() const
    00115   {
    00116     extern StringID _error_message;
    00117
    00118     if (this->success) return INVALID_STRING_ID;
    00119     if (this->message != INVALID_STRING_ID) return this->message;
    00120     return _error_message;
    00121   }
    00122
    00127   bool Succeeded() const
    00128   {
    00129     return this->success;
    00130   }
    00131
    00136   bool Failed() const
    00137   {
    00138     return !this->success;
    00139   }
    00140 };
    00141
    00152 enum {
    00153   CMD_BUILD_RAILROAD_TRACK,
    00154   CMD_REMOVE_RAILROAD_TRACK,
    00155   CMD_BUILD_SINGLE_RAIL,
    00156   CMD_REMOVE_SINGLE_RAIL,
    00157   CMD_LANDSCAPE_CLEAR,
    00158   CMD_BUILD_BRIDGE,
    00159   CMD_BUILD_RAIL_STATION,
    00160   CMD_BUILD_TRAIN_DEPOT,
    00161   CMD_BUILD_SIGNALS,
    00162   CMD_REMOVE_SIGNALS,
    00163   CMD_TERRAFORM_LAND,
    00164   CMD_PURCHASE_LAND_AREA,
    00165   CMD_SELL_LAND_AREA,
    00166   CMD_BUILD_TUNNEL,
    00167
    00168   CMD_REMOVE_FROM_RAIL_STATION,
    00169   CMD_CONVERT_RAIL,
    00170
    00171   CMD_BUILD_RAIL_WAYPOINT,
    00172   CMD_RENAME_WAYPOINT,
    00173   CMD_REMOVE_FROM_RAIL_WAYPOINT,
    00174
    00175   CMD_BUILD_ROAD_STOP,
    00176   CMD_REMOVE_ROAD_STOP,
    00177   CMD_BUILD_LONG_ROAD,
    00178   CMD_REMOVE_LONG_ROAD,
    00179   CMD_BUILD_ROAD,
    00180   CMD_REMOVE_ROAD,
    00181   CMD_BUILD_ROAD_DEPOT,
    00182
    00183   CMD_BUILD_AIRPORT,
    00184
    00185   CMD_BUILD_DOCK,
    00186
    00187   CMD_BUILD_SHIP_DEPOT,
    00188   CMD_BUILD_BUOY,
    00189
    00190   CMD_PLANT_TREE,
    00191
    00192   CMD_BUILD_RAIL_VEHICLE,
    00193   CMD_MOVE_RAIL_VEHICLE,
    00194
    00195   CMD_SELL_RAIL_WAGON,
    00196
    00197   CMD_SEND_TRAIN_TO_DEPOT,
    00198   CMD_FORCE_TRAIN_PROCEED,
    00199   CMD_REVERSE_TRAIN_DIRECTION,
    00200
    00201   CMD_MODIFY_ORDER,
    00202   CMD_SKIP_TO_ORDER,
    00203   CMD_DELETE_ORDER,
    00204   CMD_INSERT_ORDER,
    00205
    00206   CMD_CHANGE_SERVICE_INT,
    00207
    00208   CMD_BUILD_INDUSTRY,
    00209
    00210   CMD_BUILD_COMPANY_HQ,
    00211   CMD_SET_COMPANY_MANAGER_FACE,
    00212   CMD_SET_COMPANY_COLOUR,
    00213
    00214   CMD_INCREASE_LOAN,
    00215   CMD_DECREASE_LOAN,
    00216
    00217   CMD_WANT_ENGINE_PREVIEW,
    00218
    00219   CMD_RENAME_VEHICLE,
    00220   CMD_RENAME_ENGINE,
    00221   CMD_RENAME_COMPANY,
    00222   CMD_RENAME_PRESIDENT,
    00223   CMD_RENAME_STATION,
    00224
    00225   CMD_SELL_AIRCRAFT,
    00226   CMD_BUILD_AIRCRAFT,
    00227   CMD_SEND_AIRCRAFT_TO_HANGAR,
    00228   CMD_REFIT_AIRCRAFT,
    00229
    00230   CMD_PLACE_SIGN,
    00231   CMD_RENAME_SIGN,
    00232
    00233   CMD_BUILD_ROAD_VEH,
    00234   CMD_SELL_ROAD_VEH,
    00235   CMD_SEND_ROADVEH_TO_DEPOT,
    00236   CMD_TURN_ROADVEH,
    00237   CMD_REFIT_ROAD_VEH,
    00238
    00239   CMD_PAUSE,
    00240
    00241   CMD_BUY_SHARE_IN_COMPANY,
    00242   CMD_SELL_SHARE_IN_COMPANY,
    00243   CMD_BUY_COMPANY,
    00244
    00245   CMD_FOUND_TOWN,
    00246   CMD_RENAME_TOWN,
    00247   CMD_DO_TOWN_ACTION,
    00248
    00249   CMD_SELL_SHIP,
    00250   CMD_BUILD_SHIP,
    00251   CMD_SEND_SHIP_TO_DEPOT,
    00252   CMD_REFIT_SHIP,
    00253
    00254   CMD_ORDER_REFIT,
    00255   CMD_CLONE_ORDER,
    00256   CMD_CLEAR_AREA,
    00257
    00258   CMD_MONEY_CHEAT,
    00259   CMD_BUILD_CANAL,
    00260
    00261   CMD_COMPANY_CTRL,
    00262   CMD_LEVEL_LAND,
    00263
    00264   CMD_REFIT_RAIL_VEHICLE,
    00265   CMD_RESTORE_ORDER_INDEX,
    00266   CMD_BUILD_LOCK,
    00267
    00268   CMD_BUILD_SIGNAL_TRACK,
    00269   CMD_REMOVE_SIGNAL_TRACK,
    00270
    00271   CMD_GIVE_MONEY,
    00272   CMD_CHANGE_SETTING,
    00273   CMD_CHANGE_COMPANY_SETTING,
    00274
    00275   CMD_SET_AUTOREPLACE,
    00276
    00277   CMD_CLONE_VEHICLE,
    00278   CMD_START_STOP_VEHICLE,
    00279   CMD_MASS_START_STOP,
    00280   CMD_AUTOREPLACE_VEHICLE,
    00281   CMD_DEPOT_SELL_ALL_VEHICLES,
    00282   CMD_DEPOT_MASS_AUTOREPLACE,
    00283
    00284   CMD_CREATE_GROUP,
    00285   CMD_DELETE_GROUP,
    00286   CMD_RENAME_GROUP,
    00287   CMD_ADD_VEHICLE_GROUP,
    00288   CMD_ADD_SHARED_VEHICLE_GROUP,
    00289   CMD_REMOVE_ALL_VEHICLES_GROUP,
    00290   CMD_SET_GROUP_REPLACE_PROTECTION,
    00291
    00292   CMD_MOVE_ORDER,
    00293   CMD_CHANGE_TIMETABLE,
    00294   CMD_SET_VEHICLE_ON_TIME,
    00295   CMD_AUTOFILL_TIMETABLE,
    00296   CMD_SET_TIMETABLE_START,
    00297 };
    00298
    00304 enum DoCommandFlag {
    00305   DC_NONE                  = 0x000,
    00306   DC_EXEC                  = 0x001,
    00307   DC_AUTO                  = 0x002,
    00308   DC_QUERY_COST            = 0x004,
    00309   DC_NO_WATER              = 0x008,
    00310   DC_NO_RAIL_OVERLAP       = 0x010,
    00311   DC_NO_TEST_TOWN_RATING   = 0x020,
    00312   DC_BANKRUPT              = 0x040,
    00313   DC_AUTOREPLACE           = 0x080,
    00314   DC_ALL_TILES             = 0x100,
    00315   DC_NO_MODIFY_TOWN_RATING = 0x200,
    00316 };
    00317 DECLARE_ENUM_AS_BIT_SET(DoCommandFlag);
    00318
    00328 #define CMD_MSG(x) ((x) << 16)
    00329
    00335 enum {
    00336   CMD_NETWORK_COMMAND       = 0x0100,
    00337   CMD_NO_TEST_IF_IN_NETWORK = 0x0200,
    00338   CMD_FLAGS_MASK            = 0xFF00,
    00339   CMD_ID_MASK               = 0x00FF,
    00340 };
    00341
    00347 enum {
    00348   CMD_SERVER    = 0x01,
    00349   CMD_SPECTATOR = 0x02,
    00350   CMD_OFFLINE   = 0x04,
    00351   CMD_AUTO      = 0x08,
    00352   CMD_ALL_TILES = 0x10,
    00353   CMD_NO_TEST   = 0x20,
    00354   CMD_NO_WATER  = 0x40,
    00355 };
    00356
    00375 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
    00376
    00383 struct Command {
    00384   CommandProc *proc;
    00385   byte flags;
    00386 };
    00387
    00401 typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
    00402
    00406 struct CommandContainer {
    00407   TileIndex tile;
    00408   uint32 p1;
    00409   uint32 p2;
    00410   uint32 cmd;
    00411   CommandCallback *callback;
    00412   char text[80];
    00413 };
    00414
    00415 #endif /* COMMAND_TYPE_H */