303 }; |
303 }; |
304 |
304 |
305 int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc) |
305 int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc) |
306 { |
306 { |
307 return DoCommand(GET_TILE_X(tile)*16, GET_TILE_Y(tile)*16, p1, p2, flags, procc); |
307 return DoCommand(GET_TILE_X(tile)*16, GET_TILE_Y(tile)*16, p1, p2, flags, procc); |
308 } |
308 } |
309 |
309 |
310 |
310 |
311 //extern void _stdcall Sleep(int s); |
311 //extern void _stdcall Sleep(int s); |
312 |
312 |
313 int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc) |
313 int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc) |
314 { |
314 { |
315 int32 res; |
315 int32 res; |
316 CommandProc *proc; |
316 CommandProc *proc; |
317 |
317 |
318 proc = _command_proc_table[procc]; |
318 proc = _command_proc_table[procc]; |
319 |
319 |
320 if (_docommand_recursive == 0) { |
320 if (_docommand_recursive == 0) { |
321 _error_message = INVALID_STRING_ID; |
321 _error_message = INVALID_STRING_ID; |
322 // update last build coord of player |
322 // update last build coord of player |
381 bool notest; |
381 bool notest; |
382 |
382 |
383 int x = GET_TILE_X(tile)*16; |
383 int x = GET_TILE_X(tile)*16; |
384 int y = GET_TILE_Y(tile)*16; |
384 int y = GET_TILE_Y(tile)*16; |
385 |
385 |
386 assert(_docommand_recursive == 0); |
386 assert(_docommand_recursive == 0); |
387 |
387 |
388 _error_message = INVALID_STRING_ID; |
388 _error_message = INVALID_STRING_ID; |
389 _error_message_2 = cmd >> 16; |
389 _error_message_2 = cmd >> 16; |
390 _additional_cash_required = 0; |
390 _additional_cash_required = 0; |
391 |
391 |
402 // get pointer to command handler |
402 // get pointer to command handler |
403 assert((cmd & 0xFF) < lengthof(_command_proc_table)); |
403 assert((cmd & 0xFF) < lengthof(_command_proc_table)); |
404 proc = _command_proc_table[cmd & 0xFF]; |
404 proc = _command_proc_table[cmd & 0xFF]; |
405 |
405 |
406 // this command is a notest command? |
406 // this command is a notest command? |
407 notest = |
407 notest = |
408 (cmd & 0xFF) == CMD_CLEAR_AREA || |
408 (cmd & 0xFF) == CMD_CLEAR_AREA || |
409 (cmd & 0xFF) == CMD_CONVERT_RAIL || |
409 (cmd & 0xFF) == CMD_CONVERT_RAIL || |
410 (cmd & 0xFF) == CMD_LEVEL_LAND || |
410 (cmd & 0xFF) == CMD_LEVEL_LAND || |
411 (cmd & 0xFF) == CMD_TRAIN_GOTO_DEPOT; |
411 (cmd & 0xFF) == CMD_TRAIN_GOTO_DEPOT; |
412 |
412 |
413 if (_networking && (cmd & CMD_ASYNC)) notest = true; |
413 if (_networking && (cmd & CMD_ASYNC)) notest = true; |
414 |
414 |
427 |
427 |
428 _docommand_recursive = 0; |
428 _docommand_recursive = 0; |
429 return false; |
429 return false; |
430 } |
430 } |
431 |
431 |
432 |
432 |
433 |
433 |
434 // unless the command is a notest command, check if it can be executed. |
434 // unless the command is a notest command, check if it can be executed. |
435 if (!notest) { |
435 if (!notest) { |
436 // first test if the command can be executed. |
436 // first test if the command can be executed. |
437 res = proc(x,y, flags, p1, p2); |
437 res = proc(x,y, flags, p1, p2); |
454 if ( tile != 0 && _current_player < MAX_PLAYERS) DEREF_PLAYER(_current_player)->last_build_coordinate = tile; |
454 if ( tile != 0 && _current_player < MAX_PLAYERS) DEREF_PLAYER(_current_player)->last_build_coordinate = tile; |
455 |
455 |
456 // actually try and execute the command. |
456 // actually try and execute the command. |
457 _yearly_expenses_type = 0; |
457 _yearly_expenses_type = 0; |
458 res2 = proc(x,y, flags|DC_EXEC, p1, p2); |
458 res2 = proc(x,y, flags|DC_EXEC, p1, p2); |
459 |
459 |
460 if (!notest) { |
460 if (!notest) { |
461 assert(res == res2); // sanity check |
461 assert(res == res2); // sanity check |
462 } else { |
462 } else { |
463 if ((uint32)res2 >> 16 == 0x8000) { |
463 if ((uint32)res2 >> 16 == 0x8000) { |
464 if (res2 & 0xFFFF) _error_message = res2 & 0xFFFF; |
464 if (res2 & 0xFFFF) _error_message = res2 & 0xFFFF; |
477 if (res2 == 0) goto callb_err; |
477 if (res2 == 0) goto callb_err; |
478 } |
478 } |
479 } |
479 } |
480 |
480 |
481 _docommand_recursive = 0; |
481 _docommand_recursive = 0; |
482 |
482 |
483 if (callback) callback(true, tile, p1, p2); |
483 if (callback) callback(true, tile, p1, p2); |
484 return true; |
484 return true; |
485 |
485 |
486 show_error: |
486 show_error: |
487 // show error message if the command fails? |
487 // show error message if the command fails? |
488 if (_current_player == _local_player && _error_message_2 != 0) |
488 if (_current_player == _local_player && _error_message_2 != 0) |
489 ShowErrorMessage(_error_message, _error_message_2, x,y); |
489 ShowErrorMessage(_error_message, _error_message_2, x,y); |
490 |
490 |
491 callb_err: |
491 callb_err: |
492 _docommand_recursive = 0; |
492 _docommand_recursive = 0; |
493 |
493 |
494 if (callback) callback(false, tile, p1, p2); |
494 if (callback) callback(false, tile, p1, p2); |
495 return false; |
495 return false; |
496 } |
496 } |