# Hikou no mizu

![Hikou no mizu playable characters](/datasrc/gfx/characters/reduced.svg)

**Hikou no mizu** is a libre software anime-inspired fighting game.  
The characters fight using natural powers, e.g., water :ocean:, lightning :zap:,
or fire :fire:.  
All the graphics are free (various free software licenses) and drawn with a
vectorized style.

The dependencies of Hikou no mizu are:
- SDL2, SDL2_Image
- OpenGL (1.1 +)
- Freetype2
- OpenAL, libogg, libvorbis, libvorbisfile
- enet
- pugixml

Additionally, to regenerate the data from data source files, the following
extra dependencies should be installed:
- getopt
- synfig
- inkscape
- imagemagick
- pngquant
- xz

Many thanks to the contributors of all these libraries!

### Project website

<https://hikounomizu.org>

### License

See [`COPYING`](COPYING).


## Installation

Hikou no mizu uses CMake as a building system.

### Data build

In order to function properly,
Hikou no mizu needs to access its `data/` folder.  
Hikou no mizu is likely to come with a pre-built `data/` folder in its root.  
If not, or if you wish to rebuild the data from source, you may use the
`datasrc/` directory as follows:

```shell
$ cmake -S . -B databuild
$ cmake --build databuild --target data # Invoke the data building script (datasrc/databuild.sh)
```

To speed up data building, animation spritesheets may be rendered in parallel
instead of sequentially.  
The number of spritesheet rendering tasks to run in parallel can be passed
through the `HNM_PARALLEL` environment variable:

```shell
$ HNM_PARALLEL=4 cmake --build databuild --target data # Render the data using four parallel processes
```

> **Note:** Before proceeding to the installation, do ensure that
> the `data/` folder was generated.

> **Note:** For server-only builds, not all
> the data generated by `make data` is required.  
> The server only needs access to some
> data description files to work properly.  
> The [`datasrc/filterdata.sh`](datasrc/filterdata.sh) shell
> script can be used to filter out the unnecessary data.

### Source code build & installation

To build and install the project, you may type,
from the same directory where this `README` is located:

```shell
$ cmake -S . -B build \ # Build both the game and the game server
    -DCMAKE_INSTALL_PREFIX=prefix/path/to/installation \
    -DCMAKE_INSTALL_DATADIR=where/data/should/be/installed
$ cmake --build build
$ cmake --install build
```

Example for a unix system-wide installation:

```shell
$ cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr
$ cmake --build build
$ cmake --install build
$ hikounomizu  # Start the game
$ hikounomizud # Start the game server
```

Example for a standalone installation:  
*(installation of the executables in the project directory, with a relative
reference path to data)*

```shell
$ cmake -S . -B build -DHNM_STANDALONE=1
$ cmake --build build
$ cmake --install build
$ ./hikounomizu  # Start the game locally
$ ./hikounomizud # Start the game server locally
```

Example for a development build to run the game without installation:  
*(will break if the data directory is moved)*

```shell
$ cmake -S . -B build -DHNM_NOINSTALL=1
$ cmake --build build
$ ./build/hikounomizu  # Start the game locally
$ ./build/hikounomizud # Start the game server locally
```

> **Note:** The `-DHNM_NOCLIENT` option can be set to build only the server,
> which does not require the graphical and audio dependencies.  
> Similarly, the `-DHNM_NOSERVER` option can be set
> to build only the game client.
>
>```shell
>$ cmake -S . -B serverbuild -DHNM_NOCLIENT=1
>$ cmake --build serverbuild
>$ cmake --install serverbuild
>$ hikounomizud # Start the game server
>```


## Game server

### Usage

The game server can be started without arguments, it will use a default server
configuration and start listening on port `16026`.

```shell
$ hikounomizud
```

A default configuration file can be exported using
the `-e/--export-conf` options and a filename:

```shell
$ hikounomizud -e server.cfg # Create a ./server.cfg configuration file
```

In turn, a configuration file can be loaded with
the `-c/--conf` option when starting the server:

```shell
$ hikounomizud -c server.cfg
```

The server port can be configured in `server.cfg`.
Alternatively, the `-p/--port` option can be used and
takes precedence over the configuration file:

```shell
$ hikounomizud -c server.cfg -p 1234 # Will use port 1234
```

### Configuration

The following options are available to configure
a game server in a `server.cfg` file:

Name                        | Possible values                   | Comment
--------------------------- | --------------------------------- | ----------------
`port`                      | [1 - 65535]                       | Overriden by `-p/--port`
`matchmaking`               | [stack, random, challenger]       | See _matchmaking note_
`mode`                      | [default, versus]                 | Default or versus mode
`rounds_to_win`             | [1 - 255]                         | Rounds that a single player must win to win a game
`player_count`              | [2 - 255]                         | Number of players in each game
`arenas`                    | arena_name_1, arena_name_2, ...   | List of arenas enabled in the server, randomly changed at the end of each game
`spectator_limit`           | [0 - 3839 to 4092]                | Number of spectators that may join a server in addition to `player_count`
`inactivity_timeout_lobby`  | [0 - 4294967295]                  | Inactivity kick timeout in seconds for players while in game, KO time does not count
`inactivity_timeout_ingame` | [0 - 4294967295]                  | Inactivity kick timeout in seconds for players while in lobby, KO time does not count
`welcome_message`           | Free utf8 text                    | Welcome message which will be displayed to clients upon connection

### Description

The server waits for incoming connections until
the required number of players has been reached.  
When the number of connected players is less than the `player_count`
required to start a game, the server is in **lobby** mode.

> **Note:** This means players can join and move around in the arena
>   as well as fight, but they will be revived instantly when KO.

When the number of connected players reaches `player_count`,
a game is queued to start shortly.  
During a game:
- If a player leaves, the game will continue until finished except
    if only one player is left.
- If a peer joins, they are added as spectators.

When the game is completed with a winner, the server either:
- Goes back to lobby if too many peers left
    (less than `player_count` remaining).
- Performs **matchmaking** and queues a new game to start shortly.

> **Matchmaking note:** Several algorithms are available to perform matchmaking
> at the end of a game.
>
> - `stack`: The first connected players will always play, if a player leaves,
        the first connected spectator will replace them.
> - `random`: All peers are shuffled randomly to playing and spectating spots.
> - `challenger`: The player that won the last game is guaranteed to play again,
>       the rest of the peers are shuffled randomly.
