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
00019 struct GRFFile;
00020
00025 class CommandCost {
00026 ExpensesType expense_type;
00027 Money cost;
00028 StringID message;
00029 bool success;
00030 const GRFFile *textref_stack_grffile;
00031 uint textref_stack_size;
00032
00033 static uint32 textref_stack[16];
00034
00035 public:
00039 CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
00040
00044 explicit CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false), textref_stack_grffile(NULL), textref_stack_size(0) {}
00045
00050 explicit CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
00051
00057 CommandCost(ExpensesType ex_t, const Money &cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
00058
00059
00064 inline void AddCost(const Money &cost)
00065 {
00066 this->cost += cost;
00067 }
00068
00069 void AddCost(const CommandCost &cmd_cost);
00070
00075 inline void MultiplyCost(int factor)
00076 {
00077 this->cost *= factor;
00078 }
00079
00084 inline Money GetCost() const
00085 {
00086 return this->cost;
00087 }
00088
00093 inline ExpensesType GetExpensesType() const
00094 {
00095 return this->expense_type;
00096 }
00097
00102 void MakeError(StringID message)
00103 {
00104 assert(message != INVALID_STRING_ID);
00105 this->success = false;
00106 this->message = message;
00107 }
00108
00109 void UseTextRefStack(const GRFFile *grffile, uint num_registers);
00110
00115 const GRFFile *GetTextRefStackGRF() const
00116 {
00117 return this->textref_stack_grffile;
00118 }
00119
00124 uint GetTextRefStackSize() const
00125 {
00126 return this->textref_stack_size;
00127 }
00128
00133 const uint32 *GetTextRefStack() const
00134 {
00135 return textref_stack;
00136 }
00137
00142 StringID GetErrorMessage() const
00143 {
00144 if (this->success) return INVALID_STRING_ID;
00145 return this->message;
00146 }
00147
00152 inline bool Succeeded() const
00153 {
00154 return this->success;
00155 }
00156
00161 inline bool Failed() const
00162 {
00163 return !this->success;
00164 }
00165 };
00166
00177 enum Commands {
00178 CMD_BUILD_RAILROAD_TRACK,
00179 CMD_REMOVE_RAILROAD_TRACK,
00180 CMD_BUILD_SINGLE_RAIL,
00181 CMD_REMOVE_SINGLE_RAIL,
00182 CMD_LANDSCAPE_CLEAR,
00183 CMD_BUILD_BRIDGE,
00184 CMD_BUILD_RAIL_STATION,
00185 CMD_BUILD_TRAIN_DEPOT,
00186 CMD_BUILD_SIGNALS,
00187 CMD_REMOVE_SIGNALS,
00188 CMD_TERRAFORM_LAND,
00189 CMD_BUILD_OBJECT,
00190 CMD_BUILD_TUNNEL,
00191
00192 CMD_REMOVE_FROM_RAIL_STATION,
00193 CMD_CONVERT_RAIL,
00194
00195 CMD_BUILD_RAIL_WAYPOINT,
00196 CMD_RENAME_WAYPOINT,
00197 CMD_REMOVE_FROM_RAIL_WAYPOINT,
00198
00199 CMD_BUILD_ROAD_STOP,
00200 CMD_REMOVE_ROAD_STOP,
00201 CMD_BUILD_LONG_ROAD,
00202 CMD_REMOVE_LONG_ROAD,
00203 CMD_BUILD_ROAD,
00204 CMD_BUILD_ROAD_DEPOT,
00205
00206 CMD_BUILD_AIRPORT,
00207
00208 CMD_BUILD_DOCK,
00209
00210 CMD_BUILD_SHIP_DEPOT,
00211 CMD_BUILD_BUOY,
00212
00213 CMD_PLANT_TREE,
00214
00215 CMD_BUILD_VEHICLE,
00216 CMD_SELL_VEHICLE,
00217 CMD_REFIT_VEHICLE,
00218 CMD_SEND_VEHICLE_TO_DEPOT,
00219
00220 CMD_MOVE_RAIL_VEHICLE,
00221 CMD_FORCE_TRAIN_PROCEED,
00222 CMD_REVERSE_TRAIN_DIRECTION,
00223
00224 CMD_CLEAR_ORDER_BACKUP,
00225 CMD_MODIFY_ORDER,
00226 CMD_SKIP_TO_ORDER,
00227 CMD_DELETE_ORDER,
00228 CMD_INSERT_ORDER,
00229
00230 CMD_CHANGE_SERVICE_INT,
00231
00232 CMD_BUILD_INDUSTRY,
00233
00234 CMD_SET_COMPANY_MANAGER_FACE,
00235 CMD_SET_COMPANY_COLOUR,
00236
00237 CMD_INCREASE_LOAN,
00238 CMD_DECREASE_LOAN,
00239
00240 CMD_WANT_ENGINE_PREVIEW,
00241
00242 CMD_RENAME_VEHICLE,
00243 CMD_RENAME_ENGINE,
00244 CMD_RENAME_COMPANY,
00245 CMD_RENAME_PRESIDENT,
00246 CMD_RENAME_STATION,
00247 CMD_RENAME_DEPOT,
00248
00249 CMD_PLACE_SIGN,
00250 CMD_RENAME_SIGN,
00251
00252 CMD_TURN_ROADVEH,
00253
00254 CMD_PAUSE,
00255
00256 CMD_BUY_SHARE_IN_COMPANY,
00257 CMD_SELL_SHARE_IN_COMPANY,
00258 CMD_BUY_COMPANY,
00259
00260 CMD_FOUND_TOWN,
00261 CMD_RENAME_TOWN,
00262 CMD_DO_TOWN_ACTION,
00263 CMD_TOWN_CARGO_GOAL,
00264 CMD_TOWN_GROWTH_RATE,
00265 CMD_TOWN_SET_TEXT,
00266 CMD_EXPAND_TOWN,
00267 CMD_DELETE_TOWN,
00268
00269 CMD_ORDER_REFIT,
00270 CMD_CLONE_ORDER,
00271 CMD_CLEAR_AREA,
00272
00273 CMD_MONEY_CHEAT,
00274 CMD_CHANGE_BANK_BALANCE,
00275 CMD_BUILD_CANAL,
00276
00277 CMD_CREATE_SUBSIDY,
00278 CMD_COMPANY_CTRL,
00279 CMD_CUSTOM_NEWS_ITEM,
00280 CMD_CREATE_GOAL,
00281 CMD_REMOVE_GOAL,
00282 CMD_SET_GOAL_TEXT,
00283 CMD_SET_GOAL_PROGRESS,
00284 CMD_SET_GOAL_COMPLETED,
00285 CMD_GOAL_QUESTION,
00286 CMD_GOAL_QUESTION_ANSWER,
00287 CMD_CREATE_STORY_PAGE,
00288 CMD_CREATE_STORY_PAGE_ELEMENT,
00289 CMD_UPDATE_STORY_PAGE_ELEMENT,
00290 CMD_SET_STORY_PAGE_TITLE,
00291 CMD_SET_STORY_PAGE_DATE,
00292 CMD_SHOW_STORY_PAGE,
00293 CMD_REMOVE_STORY_PAGE,
00294 CMD_REMOVE_STORY_PAGE_ELEMENT,
00295 CMD_LEVEL_LAND,
00296
00297 CMD_BUILD_LOCK,
00298
00299 CMD_BUILD_SIGNAL_TRACK,
00300 CMD_REMOVE_SIGNAL_TRACK,
00301
00302 CMD_GIVE_MONEY,
00303 CMD_CHANGE_SETTING,
00304 CMD_CHANGE_COMPANY_SETTING,
00305
00306 CMD_SET_AUTOREPLACE,
00307
00308 CMD_CLONE_VEHICLE,
00309 CMD_START_STOP_VEHICLE,
00310 CMD_MASS_START_STOP,
00311 CMD_AUTOREPLACE_VEHICLE,
00312 CMD_DEPOT_SELL_ALL_VEHICLES,
00313 CMD_DEPOT_MASS_AUTOREPLACE,
00314
00315 CMD_CREATE_GROUP,
00316 CMD_DELETE_GROUP,
00317 CMD_RENAME_GROUP,
00318 CMD_ADD_VEHICLE_GROUP,
00319 CMD_ADD_SHARED_VEHICLE_GROUP,
00320 CMD_REMOVE_ALL_VEHICLES_GROUP,
00321 CMD_SET_GROUP_REPLACE_PROTECTION,
00322
00323 CMD_MOVE_ORDER,
00324 CMD_CHANGE_TIMETABLE,
00325 CMD_SET_VEHICLE_ON_TIME,
00326 CMD_AUTOFILL_TIMETABLE,
00327 CMD_SET_TIMETABLE_START,
00328
00329 CMD_OPEN_CLOSE_AIRPORT,
00330
00331 CMD_END,
00332 };
00333
00339 enum DoCommandFlag {
00340 DC_NONE = 0x000,
00341 DC_EXEC = 0x001,
00342 DC_AUTO = 0x002,
00343 DC_QUERY_COST = 0x004,
00344 DC_NO_WATER = 0x008,
00345 DC_NO_RAIL_OVERLAP = 0x010,
00346 DC_NO_TEST_TOWN_RATING = 0x020,
00347 DC_BANKRUPT = 0x040,
00348 DC_AUTOREPLACE = 0x080,
00349 DC_NO_CARGO_CAP_CHECK = 0x100,
00350 DC_ALL_TILES = 0x200,
00351 DC_NO_MODIFY_TOWN_RATING = 0x400,
00352 DC_FORCE_CLEAR_TILE = 0x800,
00353 };
00354 DECLARE_ENUM_AS_BIT_SET(DoCommandFlag)
00355
00356
00365 #define CMD_MSG(x) ((x) << 16)
00366
00372 enum FlaggedCommands {
00373 CMD_NETWORK_COMMAND = 0x0100,
00374 CMD_FLAGS_MASK = 0xFF00,
00375 CMD_ID_MASK = 0x00FF,
00376 };
00377
00383 enum CommandFlags {
00384 CMD_SERVER = 0x001,
00385 CMD_SPECTATOR = 0x002,
00386 CMD_OFFLINE = 0x004,
00387 CMD_AUTO = 0x008,
00388 CMD_ALL_TILES = 0x010,
00389 CMD_NO_TEST = 0x020,
00390 CMD_NO_WATER = 0x040,
00391 CMD_CLIENT_ID = 0x080,
00392 CMD_DEITY = 0x100,
00393 CMD_STR_CTRL = 0x200,
00394 };
00395 DECLARE_ENUM_AS_BIT_SET(CommandFlags)
00396
00397
00398 enum CommandType {
00399 CMDT_LANDSCAPE_CONSTRUCTION,
00400 CMDT_VEHICLE_CONSTRUCTION,
00401 CMDT_MONEY_MANAGEMENT,
00402 CMDT_VEHICLE_MANAGEMENT,
00403 CMDT_ROUTE_MANAGEMENT,
00404 CMDT_OTHER_MANAGEMENT,
00405 CMDT_COMPANY_SETTING,
00406 CMDT_SERVER_SETTING,
00407 CMDT_CHEAT,
00408
00409 CMDT_END,
00410 };
00411
00413 enum CommandPauseLevel {
00414 CMDPL_NO_ACTIONS,
00415 CMDPL_NO_CONSTRUCTION,
00416 CMDPL_NO_LANDSCAPING,
00417 CMDPL_ALL_ACTIONS,
00418 };
00419
00438 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
00439
00446 struct Command {
00447 CommandProc *proc;
00448 const char *name;
00449 CommandFlags flags;
00450 CommandType type;
00451 };
00452
00466 typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
00467
00471 struct CommandContainer {
00472 TileIndex tile;
00473 uint32 p1;
00474 uint32 p2;
00475 uint32 cmd;
00476 CommandCallback *callback;
00477 char text[32 * MAX_CHAR_LENGTH];
00478 };
00479
00480 #endif