src/command.cpp
branchgamebalance
changeset 9911 0b8b245a2391
parent 9910 0b2aebc8283e
child 9912 1ac8aac92385
equal deleted inserted replaced
9910:0b2aebc8283e 9911:0b8b245a2391
   165 
   165 
   166 DEF_COMMAND(CmdCloneVehicle);
   166 DEF_COMMAND(CmdCloneVehicle);
   167 DEF_COMMAND(CmdMassStartStopVehicle);
   167 DEF_COMMAND(CmdMassStartStopVehicle);
   168 DEF_COMMAND(CmdDepotSellAllVehicles);
   168 DEF_COMMAND(CmdDepotSellAllVehicles);
   169 DEF_COMMAND(CmdDepotMassAutoReplace);
   169 DEF_COMMAND(CmdDepotMassAutoReplace);
       
   170 
       
   171 DEF_COMMAND(CmdCreateGroup);
       
   172 DEF_COMMAND(CmdRenameGroup);
       
   173 DEF_COMMAND(CmdDeleteGroup);
       
   174 DEF_COMMAND(CmdAddVehicleGroup);
       
   175 DEF_COMMAND(CmdAddSharedVehicleGroup);
       
   176 DEF_COMMAND(CmdRemoveAllVehiclesGroup);
       
   177 DEF_COMMAND(CmdSetGroupReplaceProtection);
   170 
   178 
   171 /* The master command table */
   179 /* The master command table */
   172 static const Command _command_proc_table[] = {
   180 static const Command _command_proc_table[] = {
   173 	{CmdBuildRailroadTrack,                  0}, /*   0 */
   181 	{CmdBuildRailroadTrack,                  0}, /*   0 */
   174 	{CmdRemoveRailroadTrack,                 0}, /*   1 */
   182 	{CmdRemoveRailroadTrack,                 0}, /*   1 */
   311 	{CmdSetAutoReplace,                      0}, /* 115 */
   319 	{CmdSetAutoReplace,                      0}, /* 115 */
   312 	{CmdCloneVehicle,                        0}, /* 116 */
   320 	{CmdCloneVehicle,                        0}, /* 116 */
   313 	{CmdMassStartStopVehicle,                0}, /* 117 */
   321 	{CmdMassStartStopVehicle,                0}, /* 117 */
   314 	{CmdDepotSellAllVehicles,                0}, /* 118 */
   322 	{CmdDepotSellAllVehicles,                0}, /* 118 */
   315 	{CmdDepotMassAutoReplace,                0}, /* 119 */
   323 	{CmdDepotMassAutoReplace,                0}, /* 119 */
       
   324 	{CmdCreateGroup,                         0}, /* 120 */
       
   325 	{CmdDeleteGroup,                         0}, /* 121 */
       
   326 	{CmdRenameGroup,                         0}, /* 122 */
       
   327 	{CmdAddVehicleGroup,                     0}, /* 123 */
       
   328 	{CmdAddSharedVehicleGroup,               0}, /* 124 */
       
   329 	{CmdRemoveAllVehiclesGroup,              0}, /* 125 */
       
   330 	{CmdSetGroupReplaceProtection,           0}, /* 126 */
   316 };
   331 };
   317 
   332 
   318 /* This function range-checks a cmd, and checks if the cmd is not NULL */
   333 /* This function range-checks a cmd, and checks if the cmd is not NULL */
   319 bool IsValidCommand(uint cmd)
   334 bool IsValidCommand(uint cmd)
   320 {
   335 {
   337 {
   352 {
   338 	int32 res;
   353 	int32 res;
   339 	CommandProc *proc;
   354 	CommandProc *proc;
   340 
   355 
   341 	/* Do not even think about executing out-of-bounds tile-commands */
   356 	/* Do not even think about executing out-of-bounds tile-commands */
   342 	if (tile >= MapSize()) {
   357 	if (tile >= MapSize() || IsTileType(tile, MP_VOID)) {
   343 		_cmd_text = NULL;
   358 		_cmd_text = NULL;
   344 		return CMD_ERROR;
   359 		return CMD_ERROR;
   345 	}
   360 	}
   346 
   361 
   347 	proc = _command_proc_table[procc].proc;
   362 	proc = _command_proc_table[procc].proc;
   415 
   430 
   416 	int x = TileX(tile) * TILE_SIZE;
   431 	int x = TileX(tile) * TILE_SIZE;
   417 	int y = TileY(tile) * TILE_SIZE;
   432 	int y = TileY(tile) * TILE_SIZE;
   418 
   433 
   419 	/* Do not even think about executing out-of-bounds tile-commands */
   434 	/* Do not even think about executing out-of-bounds tile-commands */
   420 	if (tile >= MapSize()) {
   435 	if (tile >= MapSize() || IsTileType(tile, MP_VOID)) {
   421 		_cmd_text = NULL;
   436 		_cmd_text = NULL;
   422 		return false;
   437 		return false;
   423 	}
   438 	}
   424 
   439 
   425 	assert(_docommand_recursive == 0);
   440 	assert(_docommand_recursive == 0);
   454 	 *  it will fail. so res and res2 are different
   469 	 *  it will fail. so res and res2 are different
   455 	 * CMD_REMOVE_ROAD: This command has special local authority
   470 	 * CMD_REMOVE_ROAD: This command has special local authority
   456 	 * restrictions which may cause the test run to fail (the previous
   471 	 * restrictions which may cause the test run to fail (the previous
   457 	 * road fragments still stay there and the town won't let you
   472 	 * road fragments still stay there and the town won't let you
   458 	 * disconnect the road system), but the exec will succeed and this
   473 	 * disconnect the road system), but the exec will succeed and this
   459 	 * fact will trigger an assertion failure. --pasky */
   474 	 * fact will trigger an assertion failure. --pasky
       
   475 	 * CMD_CLONE_VEHICLE: Both building new vehicles and refitting them can be
       
   476 	 * influenced by newgrf callbacks, which makes it impossible to accurately
       
   477 	 * estimate the cost of cloning a vehicle. */
   460 	notest =
   478 	notest =
   461 		(cmd & 0xFF) == CMD_CLEAR_AREA ||
   479 		(cmd & 0xFF) == CMD_CLEAR_AREA ||
   462 		(cmd & 0xFF) == CMD_CONVERT_RAIL ||
   480 		(cmd & 0xFF) == CMD_CONVERT_RAIL ||
   463 		(cmd & 0xFF) == CMD_LEVEL_LAND ||
   481 		(cmd & 0xFF) == CMD_LEVEL_LAND ||
   464 		(cmd & 0xFF) == CMD_REMOVE_ROAD ||
   482 		(cmd & 0xFF) == CMD_REMOVE_ROAD ||
   465 		(cmd & 0xFF) == CMD_REMOVE_LONG_ROAD;
   483 		(cmd & 0xFF) == CMD_REMOVE_LONG_ROAD ||
       
   484 		(cmd & 0xFF) == CMD_CLONE_VEHICLE;
   466 
   485 
   467 	_docommand_recursive = 1;
   486 	_docommand_recursive = 1;
   468 
   487 
   469 	/* cost estimation only? */
   488 	/* cost estimation only? */
   470 	if (!IsGeneratingWorld() &&
   489 	if (!IsGeneratingWorld() &&