00001
00002
00003
00004
00005
00006
00007
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 uint textref_stack_size;
00029
00030 static uint32 textref_stack[16];
00031
00032 public:
00036 CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_size(0) {}
00037
00041 explicit CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false), textref_stack_size(0) {}
00042
00047 explicit CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_size(0) {}
00048
00054 CommandCost(ExpensesType ex_t, const Money &cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true), textref_stack_size(0) {}
00055
00056
00061 FORCEINLINE void AddCost(const Money &cost)
00062 {
00063 this->cost += cost;
00064 }
00065
00066 void AddCost(const CommandCost &cmd_cost);
00067
00072 FORCEINLINE void MultiplyCost(int factor)
00073 {
00074 this->cost *= factor;
00075 }
00076
00081 FORCEINLINE Money GetCost() const
00082 {
00083 return this->cost;
00084 }
00085
00090 FORCEINLINE ExpensesType GetExpensesType() const
00091 {
00092 return this->expense_type;
00093 }
00094
00099 void MakeError(StringID message)
00100 {
00101 assert(message != INVALID_STRING_ID);
00102 this->success = false;
00103 this->message = message;
00104 }
00105
00106 void UseTextRefStack(uint num_registers);
00107
00112 uint GetTextRefStackSize() const
00113 {
00114 return this->textref_stack_size;
00115 }
00116
00121 const uint32 *GetTextRefStack() const
00122 {
00123 return textref_stack;
00124 }
00125
00130 StringID GetErrorMessage() const
00131 {
00132 if (this->success) return INVALID_STRING_ID;
00133 return this->message;
00134 }
00135
00140 FORCEINLINE bool Succeeded() const
00141 {
00142 return this->success;
00143 }
00144
00149 FORCEINLINE bool Failed() const
00150 {
00151 return !this->success;
00152 }
00153 };
00154
00165 enum Commands {
00166 CMD_BUILD_RAILROAD_TRACK,
00167 CMD_REMOVE_RAILROAD_TRACK,
00168 CMD_BUILD_SINGLE_RAIL,
00169 CMD_REMOVE_SINGLE_RAIL,
00170 CMD_LANDSCAPE_CLEAR,
00171 CMD_BUILD_BRIDGE,
00172 CMD_BUILD_RAIL_STATION,
00173 CMD_BUILD_TRAIN_DEPOT,
00174 CMD_BUILD_SIGNALS,
00175 CMD_REMOVE_SIGNALS,
00176 CMD_TERRAFORM_LAND,
00177 CMD_BUILD_OBJECT,
00178 CMD_BUILD_TUNNEL,
00179
00180 CMD_REMOVE_FROM_RAIL_STATION,
00181 CMD_CONVERT_RAIL,
00182
00183 CMD_BUILD_RAIL_WAYPOINT,
00184 CMD_RENAME_WAYPOINT,
00185 CMD_REMOVE_FROM_RAIL_WAYPOINT,
00186
00187 CMD_BUILD_ROAD_STOP,
00188 CMD_REMOVE_ROAD_STOP,
00189 CMD_BUILD_LONG_ROAD,
00190 CMD_REMOVE_LONG_ROAD,
00191 CMD_BUILD_ROAD,
00192 CMD_BUILD_ROAD_DEPOT,
00193
00194 CMD_BUILD_AIRPORT,
00195
00196 CMD_BUILD_DOCK,
00197
00198 CMD_BUILD_SHIP_DEPOT,
00199 CMD_BUILD_BUOY,
00200
00201 CMD_PLANT_TREE,
00202
00203 CMD_BUILD_VEHICLE,
00204 CMD_SELL_VEHICLE,
00205 CMD_REFIT_VEHICLE,
00206 CMD_SEND_VEHICLE_TO_DEPOT,
00207
00208 CMD_MOVE_RAIL_VEHICLE,
00209 CMD_FORCE_TRAIN_PROCEED,
00210 CMD_REVERSE_TRAIN_DIRECTION,
00211
00212 CMD_CLEAR_ORDER_BACKUP,
00213 CMD_MODIFY_ORDER,
00214 CMD_SKIP_TO_ORDER,
00215 CMD_DELETE_ORDER,
00216 CMD_INSERT_ORDER,
00217
00218 CMD_CHANGE_SERVICE_INT,
00219
00220 CMD_BUILD_INDUSTRY,
00221
00222 CMD_SET_COMPANY_MANAGER_FACE,
00223 CMD_SET_COMPANY_COLOUR,
00224
00225 CMD_INCREASE_LOAN,
00226 CMD_DECREASE_LOAN,
00227
00228 CMD_WANT_ENGINE_PREVIEW,
00229
00230 CMD_RENAME_VEHICLE,
00231 CMD_RENAME_ENGINE,
00232 CMD_RENAME_COMPANY,
00233 CMD_RENAME_PRESIDENT,
00234 CMD_RENAME_STATION,
00235 CMD_RENAME_DEPOT,
00236
00237 CMD_PLACE_SIGN,
00238 CMD_RENAME_SIGN,
00239
00240 CMD_TURN_ROADVEH,
00241
00242 CMD_PAUSE,
00243
00244 CMD_BUY_SHARE_IN_COMPANY,
00245 CMD_SELL_SHARE_IN_COMPANY,
00246 CMD_BUY_COMPANY,
00247
00248 CMD_FOUND_TOWN,
00249 CMD_RENAME_TOWN,
00250 CMD_DO_TOWN_ACTION,
00251 CMD_EXPAND_TOWN,
00252 CMD_DELETE_TOWN,
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_BUILD_LOCK,
00265
00266 CMD_BUILD_SIGNAL_TRACK,
00267 CMD_REMOVE_SIGNAL_TRACK,
00268
00269 CMD_GIVE_MONEY,
00270 CMD_CHANGE_SETTING,
00271 CMD_CHANGE_COMPANY_SETTING,
00272
00273 CMD_SET_AUTOREPLACE,
00274
00275 CMD_CLONE_VEHICLE,
00276 CMD_START_STOP_VEHICLE,
00277 CMD_MASS_START_STOP,
00278 CMD_AUTOREPLACE_VEHICLE,
00279 CMD_DEPOT_SELL_ALL_VEHICLES,
00280 CMD_DEPOT_MASS_AUTOREPLACE,
00281
00282 CMD_CREATE_GROUP,
00283 CMD_DELETE_GROUP,
00284 CMD_RENAME_GROUP,
00285 CMD_ADD_VEHICLE_GROUP,
00286 CMD_ADD_SHARED_VEHICLE_GROUP,
00287 CMD_REMOVE_ALL_VEHICLES_GROUP,
00288 CMD_SET_GROUP_REPLACE_PROTECTION,
00289
00290 CMD_MOVE_ORDER,
00291 CMD_CHANGE_TIMETABLE,
00292 CMD_SET_VEHICLE_ON_TIME,
00293 CMD_AUTOFILL_TIMETABLE,
00294 CMD_SET_TIMETABLE_START,
00295
00296 CMD_END
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 DC_FORCE_CLEAR_TILE = 0x400,
00317 };
00318 DECLARE_ENUM_AS_BIT_SET(DoCommandFlag)
00319
00320
00329 #define CMD_MSG(x) ((x) << 16)
00330
00336 enum FlaggedCommands {
00337 CMD_NETWORK_COMMAND = 0x0100,
00338 CMD_NO_TEST_IF_IN_NETWORK = 0x0200,
00339 CMD_FLAGS_MASK = 0xFF00,
00340 CMD_ID_MASK = 0x00FF,
00341 };
00342
00348 enum CommandFlags {
00349 CMD_SERVER = 0x01,
00350 CMD_SPECTATOR = 0x02,
00351 CMD_OFFLINE = 0x04,
00352 CMD_AUTO = 0x08,
00353 CMD_ALL_TILES = 0x10,
00354 CMD_NO_TEST = 0x20,
00355 CMD_NO_WATER = 0x40,
00356 CMD_CLIENT_ID = 0x80,
00357 };
00358 DECLARE_ENUM_AS_BIT_SET(CommandFlags)
00359
00360
00361 enum CommandType {
00362 CMDT_LANDSCAPE_CONSTRUCTION,
00363 CMDT_VEHICLE_CONSTRUCTION,
00364 CMDT_MONEY_MANAGEMENT,
00365 CMDT_VEHICLE_MANAGEMENT,
00366 CMDT_ROUTE_MANAGEMENT,
00367 CMDT_OTHER_MANAGEMENT,
00368 CMDT_COMPANY_SETTING,
00369 CMDT_SERVER_SETTING,
00370 CMDT_CHEAT,
00371
00372 CMDT_END,
00373 };
00374
00376 enum CommandPauseLevel {
00377 CMDPL_NO_ACTIONS,
00378 CMDPL_NO_CONSTRUCTION,
00379 CMDPL_NO_LANDSCAPING,
00380 CMDPL_ALL_ACTIONS,
00381 };
00382
00401 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
00402
00409 struct Command {
00410 CommandProc *proc;
00411 const char *name;
00412 CommandFlags flags;
00413 CommandType type;
00414 };
00415
00429 typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
00430
00434 struct CommandContainer {
00435 TileIndex tile;
00436 uint32 p1;
00437 uint32 p2;
00438 uint32 cmd;
00439 CommandCallback *callback;
00440 char text[32 * MAX_CHAR_LENGTH];
00441 };
00442
00443 #endif