1568 uint16 engine_list_length = 0; |
1568 uint16 engine_list_length = 0; |
1569 uint16 engine_count = 0; |
1569 uint16 engine_count = 0; |
1570 int32 return_value = CMD_ERROR; |
1570 int32 return_value = CMD_ERROR; |
1571 uint i; |
1571 uint i; |
1572 uint stop_command; |
1572 uint stop_command; |
1573 byte vehicle_type = p1; |
1573 byte vehicle_type = GB(p1, 0, 8); |
1574 byte start_stop = p2; |
1574 bool start_stop = HASBIT(p2, 0); |
1575 |
1575 |
1576 switch (vehicle_type) { |
1576 switch (vehicle_type) { |
1577 case VEH_Train: stop_command = CMD_START_STOP_TRAIN; break; |
1577 case VEH_Train: stop_command = CMD_START_STOP_TRAIN; break; |
1578 case VEH_Road: stop_command = CMD_START_STOP_ROADVEH; break; |
1578 case VEH_Road: stop_command = CMD_START_STOP_ROADVEH; break; |
1579 case VEH_Ship: stop_command = CMD_START_STOP_SHIP; break; |
1579 case VEH_Ship: stop_command = CMD_START_STOP_SHIP; break; |
1587 for (i = 0; i < engine_count; i++) { |
1587 for (i = 0; i < engine_count; i++) { |
1588 const Vehicle *v = vl[i]; |
1588 const Vehicle *v = vl[i]; |
1589 int32 ret; |
1589 int32 ret; |
1590 |
1590 |
1591 if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue; |
1591 if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue; |
1592 if (!(v->vehstatus & VS_HIDDEN)) continue; |
1592 if (vehicle_type == VEH_Train) { |
1593 if (p1 == VEH_Train && !IsWholeTrainInDepot(v)) continue; |
1593 if (CheckTrainInDepot(v, false) == -1) continue; |
|
1594 } else { |
|
1595 if (!(v->vehstatus & VS_HIDDEN)) continue; |
|
1596 } |
|
1597 |
1594 ret = DoCommand(tile, v->index, 0, flags, stop_command); |
1598 ret = DoCommand(tile, v->index, 0, flags, stop_command); |
1595 |
1599 |
1596 if (!CmdFailed(ret)) { |
1600 if (!CmdFailed(ret)) { |
1597 return_value = 0; |
1601 return_value = 0; |
1598 /* We know that the command is valid for at least one vehicle. |
1602 /* We know that the command is valid for at least one vehicle. |
1599 * If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */ |
1603 * If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */ |
1600 if (!(flags & DC_EXEC)) break; |
1604 if (!(flags & DC_EXEC)) break; |
1601 } |
1605 } |
1602 } |
1606 } |
1603 |
1607 |
1604 free((void*)vl); |
1608 free(vl); |
1605 return return_value; |
1609 return return_value; |
1606 } |
1610 } |
1607 |
1611 |
1608 /** Clone a vehicle. If it is a train, it will clone all the cars too |
1612 /** Clone a vehicle. If it is a train, it will clone all the cars too |
1609 * @param tile tile of the depot where the cloned vehicle is build |
1613 * @param tile tile of the depot where the cloned vehicle is build |