NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.48k stars 12.97k forks source link

Package request: boswars #241255

Open febdoctor opened 1 year ago

febdoctor commented 1 year ago

Project description

Bos Wars is a futuristic real time strategy game (RTS). In a RTS game, the player has to combat his enemies while developing his war economy. Everything runs in real-time, as opposed to turn-based games where the player always has to wait for his turn. The trick is to balance the effort put into building his economy and building an army to defend and attack the enemies.

Bos Wars has a dynamic rate based economy. Energy is produced by power plants and magma gets pumped from hot spots. Buildings and mobile units are also built at a continuous rate. Control of larger parts of the map creates the potential to increase your economy throughput. Holding key points like roads and passages allow for different strategies.

Metadata

TomaSajt commented 1 year ago

I tried building it from the git repo, however, it has a really convoluted, custom way of doing it.

This autoPatchelfHook-ed solution is the best I could come up with. It seems to work, however I don't know enough about the game to say whether or not it's working as intended. I'll leave this here, if anyone wants to try it out and/or continue working on it.

{ lib
, stdenv
, fetchurl
, autoPatchelfHook
, makeWrapper
, zlib
, libGL
, SDL
}:
let
  pname = "boswars";
  version = "2.8";
in
stdenv.mkDerivation {
  inherit pname version;
  src = fetchurl {
    url = "https://www.boswars.org/dist/releases/boswars-${version}-linux.tar.gz";
    sha256 = "sha256-YY+9pJjyMd+PEYVPbeiryKB5rZr4z94ntlYzRTHJAdg=";
  };

  nativeBuildInputs = [ autoPatchelfHook makeWrapper ];
  buildInputs = [ zlib libGL SDL ];

  installPhase = ''
    mkdir -p $out
    cp -r * $out
    makeWrapper $out/boswars $out/bin/${pname} \
          --add-flags "-d $out"
  '';
}
Rampoina commented 12 months ago

The game builds without issues in a shell with:

nix-shell -p python311Full zlib libGLU SDL2 pkg-config lua5_1 libpng

and then calling ./make.py which generates the binary ./fbuild/release/boswars

It should be possible to make a package that calls the python script in the buildPhase and creates the outputs. The AUR package can serve as a reference: https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=boswars

Rampoina commented 12 months ago

Initial working package:

{ lib
, stdenv
, makeWrapper
, fetchpatch
, fetchFromGitea
, python3
, zlib
, libGLU
, SDL
, pkg-config
, lua5_1
, libpng
}:

stdenv.mkDerivation rec {
  pname = "boswars";
  version = "2.8";

  src = fetchFromGitea {
    domain = "codeberg.org";
    owner = pname;
    repo = pname;
    rev = "${pname}-${version}";
    hash = "sha256-UXPHDwuAoBK862slmQdWWXuu8odlpfGwe40HvUzm42c=";
  };

  patches = [
    # This patch is needed in order to build, it should be unneeded after a new release
    #
    # Since Python 2.5, stat times use floats and we require at least
    # Python 2.7. os.stat_float_times() is deprecated since Python
    # 3.1 and has been completely removed in Python 3.7.
    (fetchpatch {
    url = "https://codeberg.org/boswars/boswars/commit/5cb645f8c55b536f0027314aac9216a200315708.patch";
    hash = "sha256-FdKwH3njaZh89T7lGALx+r2yfygC1lnC1SDPJBPNAKk=";
    })
  ];

  nativeBuildInputs =
    [ makeWrapper python3 pkg-config zlib libGLU SDL lua5_1 libpng ];

  buildPhase = ''
    python make.py release
  '';

  installPhase = ''
    mkdir -p $out/bin
    mkdir -p $out/share

    # data
    install -d "$out"/share/${pname}/languages
    python make.py install_data datadir=$out/share/${pname}

    # binary
    install -Dm755 fbuild/release/${pname} $out/bin/${pname}
    wrapProgram $out/bin/${pname} --add-flags "-d $out/share/${pname}"
  '';

  meta = {
    description =
      "A futuristic real-time strategy game featuring a dynamic rate-based economy.";
    longDescription = ''
      Bos Wars is a futuristic real-time strategy game featuring a dynamic rate-based economy. Resources are continuously produced while also being consumed by creating buildings and training new units. Bos Wars aims to create a completely original and fun open source RTS game.
    '';
    homepage = "www.boswars.com";
    license = lib.licenses.gpl2;
    maintainers = with lib.maintainers; [ rampoina ];
    platforms = lib.platforms.linux;
  };
}
andy5995 commented 12 months ago

The game builds without issues in a shell with:

nix-shell -p python311Full zlib libGLU SDL2 pkg-config lua5_1 libpng

and then calling ./make.py which generates the binary ./fbuild/release/boswars

It should be possible to make a package that calls the python script in the buildPhase and creates the outputs. The AUR package can serve as a reference: https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=boswars

It's also already packaged for many other distros. https://repology.org/project/boswars/versions

@febdoctor expects to release within the next few weeks, now that he's migrated the code to use sdl2.

@Rampoina @TomaSajt thanks for working on this.

Rampoina commented 12 months ago

I submitted the PR: #242488 Please test it and review it.

dufresnep commented 11 months ago

From doc install.html:

libsdl liblua5.1 libtheora libogg libpng12 libsdl1.2 libvorbis libgl1-mesa

I think we could add some facultative: libtheora, libogg and libvorbis (they might not be used up to now, but could be used in future changes).

Actually, I took that doc from HEAD rather than latest released... also this wrongly stlil say libsdl1.2, where it have been changed to use libsdl2.

dufresnep commented 11 months ago

I think we should add a comment next to SDL to say next version will use SDL2.