804 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
804 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
805 */ |
805 */ |
806 CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
806 CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
807 { |
807 { |
808 CommandCost value; |
808 CommandCost value; |
809 Vehicle *v; |
|
810 UnitID unit_num; |
809 UnitID unit_num; |
811 Engine *e; |
810 Engine *e; |
812 |
811 |
813 if (!IsEngineBuildable(p1, VEH_SHIP, _current_player)) return_cmd_error(STR_SHIP_NOT_AVAILABLE); |
812 if (!IsEngineBuildable(p1, VEH_SHIP, _current_player)) return_cmd_error(STR_SHIP_NOT_AVAILABLE); |
814 |
813 |
820 /* The ai_new queries the vehicle cost before building the route, |
819 /* The ai_new queries the vehicle cost before building the route, |
821 * so we must check against cheaters no sooner than now. --pasky */ |
820 * so we must check against cheaters no sooner than now. --pasky */ |
822 if (!IsTileDepotType(tile, TRANSPORT_WATER)) return CMD_ERROR; |
821 if (!IsTileDepotType(tile, TRANSPORT_WATER)) return CMD_ERROR; |
823 if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
822 if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
824 |
823 |
825 v = new Ship(); |
|
826 unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_SHIP); |
824 unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_SHIP); |
827 AutoPtrT<Vehicle> v_auto_delete = v; |
825 |
828 |
826 if (!Vehicle::AllocateList(NULL, 1) || unit_num > _patches.max_ships) |
829 if (v == NULL || unit_num > _patches.max_ships) |
|
830 return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
827 return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
831 |
828 |
832 if (flags & DC_EXEC) { |
829 if (flags & DC_EXEC) { |
833 int x; |
830 int x; |
834 int y; |
831 int y; |
835 |
832 |
836 const ShipVehicleInfo *svi = ShipVehInfo(p1); |
833 const ShipVehicleInfo *svi = ShipVehInfo(p1); |
837 |
834 |
838 v = new (v) Ship(); |
835 Vehicle *v = new Ship(); |
839 v->unitnumber = unit_num; |
836 v->unitnumber = unit_num; |
840 |
837 |
841 v->owner = _current_player; |
838 v->owner = _current_player; |
842 v->tile = tile; |
839 v->tile = tile; |
843 x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
840 x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |