568 } |
568 } |
569 |
569 |
570 return 0; |
570 return 0; |
571 } |
571 } |
572 |
572 |
573 /** |
573 /** Clone/share/copy an order-list of an other vehicle. |
574 * |
574 * @param p1 various bitstuffed elements |
575 * Clone/share/copy an order-list of an other vehicle |
575 * - p1 = (bit 0-15) - destination vehicle to clone orders to (p1 & 0xFFFF) |
576 * |
576 * - p1 = (bit 16-31) - source vehicle to clone orders from, if any (none for CO_UNSHARE) |
577 * @param veh1_veh2 First 16 bits are of destination vehicle, last 16 of source vehicle |
577 * @param p2 mode of cloning: CO_SHARE, CO_COPY, or CO_UNSHARE |
578 * @param mode Mode of cloning (CO_SHARE, CO_COPY, CO_UNSHARE) |
578 */ |
579 * |
579 int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
580 */ |
580 { |
581 int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 veh1_veh2, uint32 mode) |
581 Vehicle *dst; |
582 { |
582 VehicleID veh_src = (p1 >> 16) & 0xFFFF; |
583 Vehicle *dst = GetVehicle(veh1_veh2 & 0xFFFF); |
583 VehicleID veh_dst = p1 & 0xFFFF; |
584 |
584 |
585 if (dst->type == 0 || dst->owner != _current_player) |
585 if (!IsVehicleIndex(veh_dst)) return CMD_ERROR; |
586 return CMD_ERROR; |
586 |
587 |
587 dst = GetVehicle(veh_dst); |
588 switch(mode) { |
588 |
|
589 if (dst->type == 0 || !CheckOwnership(dst->owner)) return CMD_ERROR; |
|
590 |
|
591 switch (p2) { |
589 case CO_SHARE: { |
592 case CO_SHARE: { |
590 Vehicle *src = GetVehicle(veh1_veh2 >> 16); |
593 Vehicle *src; |
|
594 |
|
595 if (!IsVehicleIndex(veh_src)) return CMD_ERROR; |
|
596 |
|
597 src = GetVehicle(veh_src); |
591 |
598 |
592 /* Sanity checks */ |
599 /* Sanity checks */ |
593 if (src->type == 0 || src->owner != _current_player || dst->type != src->type || dst == src) |
600 if (src->type == 0 || !CheckOwnership(src->owner) || dst->type != src->type || dst == src) |
594 return CMD_ERROR; |
601 return CMD_ERROR; |
595 |
602 |
596 /* Trucks can't share orders with busses (and visa versa) */ |
603 /* Trucks can't share orders with busses (and visa versa) */ |
597 if (src->type == VEH_Road) { |
604 if (src->type == VEH_Road) { |
598 if (src->cargo_type != dst->cargo_type && (src->cargo_type == CT_PASSENGERS || dst->cargo_type == CT_PASSENGERS)) |
605 if (src->cargo_type != dst->cargo_type && (src->cargo_type == CT_PASSENGERS || dst->cargo_type == CT_PASSENGERS)) |
629 RebuildVehicleLists(); |
636 RebuildVehicleLists(); |
630 } |
637 } |
631 } break; |
638 } break; |
632 |
639 |
633 case CO_COPY: { |
640 case CO_COPY: { |
634 Vehicle *src = GetVehicle(veh1_veh2 >> 16); |
641 Vehicle *src; |
635 int delta; |
642 int delta; |
636 |
643 |
|
644 if (!IsVehicleIndex(veh_src)) return CMD_ERROR; |
|
645 |
|
646 src = GetVehicle(veh_src); |
|
647 |
637 /* Sanity checks */ |
648 /* Sanity checks */ |
638 if (src->type == 0 || src->owner != _current_player || dst->type != src->type || dst == src) |
649 if (src->type == 0 || !CheckOwnership(src->owner) || dst->type != src->type || dst == src) |
639 return CMD_ERROR; |
650 return CMD_ERROR; |
640 |
651 |
641 /* Trucks can't copy all the orders from busses (and visa versa) */ |
652 /* Trucks can't copy all the orders from busses (and visa versa) */ |
642 if (src->type == VEH_Road) { |
653 if (src->type == VEH_Road) { |
643 const Order *order; |
654 const Order *order; |